jump to 120

Picking this because it makes the `hello_magic.rs` lines all stay on one line.
This commit is contained in:
Lokathor 2019-02-12 09:42:17 -07:00
parent b67bdc80a1
commit 2929076e55
6 changed files with 18 additions and 54 deletions

View file

@ -10,15 +10,9 @@ fn panic(_info: &core::panic::PanicInfo) -> ! {
fn main(_argc: isize, _argv: *const *const u8) -> isize { fn main(_argc: isize, _argv: *const *const u8) -> isize {
unsafe { unsafe {
(0x400_0000 as *mut u16).write_volatile(0x0403); (0x400_0000 as *mut u16).write_volatile(0x0403);
(0x600_0000 as *mut u16) (0x600_0000 as *mut u16).offset(120 + 80 * 240).write_volatile(0x001F);
.offset(120 + 80 * 240) (0x600_0000 as *mut u16).offset(136 + 80 * 240).write_volatile(0x03E0);
.write_volatile(0x001F); (0x600_0000 as *mut u16).offset(120 + 96 * 240).write_volatile(0x7C00);
(0x600_0000 as *mut u16)
.offset(136 + 80 * 240)
.write_volatile(0x03E0);
(0x600_0000 as *mut u16)
.offset(120 + 96 * 240)
.write_volatile(0x7C00);
loop {} loop {}
} }
} }

View file

@ -4,5 +4,5 @@ merge_imports = true
reorder_imports = true reorder_imports = true
use_try_shorthand = true use_try_shorthand = true
tab_spaces = 2 tab_spaces = 2
max_width = 100 max_width = 120
color = "Never" color = "Never"

View file

@ -60,8 +60,7 @@ pub const SOUND2CNT_L: VolAddress<DutyLenEnvelopeSetting> = unsafe { VolAddress:
pub const SOUND2CNT_H: VolAddress<FrequencyControlSetting> = unsafe { VolAddress::new(0x400_006C) }; pub const SOUND2CNT_H: VolAddress<FrequencyControlSetting> = unsafe { VolAddress::new(0x400_006C) };
/// Sound Channel 3 Stop/Wave RAM select (`NR23`, `NR24`). Read/Write. /// Sound Channel 3 Stop/Wave RAM select (`NR23`, `NR24`). Read/Write.
pub const SOUND3CNT_L: VolAddress<StopWaveRAMSelectSetting> = pub const SOUND3CNT_L: VolAddress<StopWaveRAMSelectSetting> = unsafe { VolAddress::new(0x400_0070) };
unsafe { VolAddress::new(0x400_0070) };
newtype! { newtype! {
StopWaveRAMSelectSetting, u16 StopWaveRAMSelectSetting, u16
@ -159,8 +158,7 @@ pub const FIFO_B_L: VolAddress<u16> = unsafe { VolAddress::new(0x400_00A4) };
pub const FIFO_B_H: VolAddress<u16> = unsafe { VolAddress::new(0x400_00A6) }; pub const FIFO_B_H: VolAddress<u16> = unsafe { VolAddress::new(0x400_00A6) };
/// Channel L/R Volume/Enable (`NR50`, `NR51`). Read/Write. /// Channel L/R Volume/Enable (`NR50`, `NR51`). Read/Write.
pub const SOUNDCNT_L: VolAddress<NonWaveVolumeEnableSetting> = pub const SOUNDCNT_L: VolAddress<NonWaveVolumeEnableSetting> = unsafe { VolAddress::new(0x400_0080) };
unsafe { VolAddress::new(0x400_0080) };
newtype! { newtype! {
NonWaveVolumeEnableSetting, u16 NonWaveVolumeEnableSetting, u16

View file

@ -157,11 +157,7 @@ pub fn read_obj_attributes(slot: usize) -> Option<ObjectAttributes> {
let attr0 = va_u16.cast::<OBJAttr0>().read(); let attr0 = va_u16.cast::<OBJAttr0>().read();
let attr1 = va_u16.offset(1).cast::<OBJAttr1>().read(); let attr1 = va_u16.offset(1).cast::<OBJAttr1>().read();
let attr2 = va_u16.offset(2).cast::<OBJAttr2>().read(); let attr2 = va_u16.offset(2).cast::<OBJAttr2>().read();
ObjectAttributes { ObjectAttributes { attr0, attr1, attr2 }
attr0,
attr1,
attr2,
}
}) })
} }

View file

@ -33,8 +33,7 @@ pub const VRAM_BASE_USIZE: usize = 0x600_0000;
pub const CHAR_BASE_BLOCKS: VolBlock<[u8; 0x4000], U6> = unsafe { VolBlock::new(VRAM_BASE_USIZE) }; pub const CHAR_BASE_BLOCKS: VolBlock<[u8; 0x4000], U6> = unsafe { VolBlock::new(VRAM_BASE_USIZE) };
/// The screen entry base blocks. /// The screen entry base blocks.
pub const SCREEN_BASE_BLOCKS: VolBlock<[u8; 0x800], U32> = pub const SCREEN_BASE_BLOCKS: VolBlock<[u8; 0x800], U32> = unsafe { VolBlock::new(VRAM_BASE_USIZE) };
unsafe { VolBlock::new(VRAM_BASE_USIZE) };
newtype! { newtype! {
/// An 8x8 tile with 4bpp, packed as `u32` values for proper alignment. /// An 8x8 tile with 4bpp, packed as `u32` values for proper alignment.

View file

@ -30,8 +30,7 @@ impl Mode3 {
/// ///
/// Use `col + row * SCREEN_WIDTH` to get the address of an individual pixel, /// Use `col + row * SCREEN_WIDTH` to get the address of an individual pixel,
/// or use the helpers provided in this module. /// or use the helpers provided in this module.
pub const VRAM: VolBlock<Color, <U256 as Mul<U160>>::Output> = pub const VRAM: VolBlock<Color, <U256 as Mul<U160>>::Output> = unsafe { VolBlock::new(VRAM_BASE_USIZE) };
unsafe { VolBlock::new(VRAM_BASE_USIZE) };
/// private iterator over the pixels, two at a time /// private iterator over the pixels, two at a time
const VRAM_BULK: VolBlock<u32, <<U256 as Mul<U160>>::Output as Div<U2>>::Output> = const VRAM_BULK: VolBlock<u32, <<U256 as Mul<U160>>::Output as Div<U2>>::Output> =
@ -43,9 +42,7 @@ impl Mode3 {
/// ///
/// Gives `None` if out of bounds. /// Gives `None` if out of bounds.
pub fn read_pixel(col: usize, row: usize) -> Option<Color> { pub fn read_pixel(col: usize, row: usize) -> Option<Color> {
Self::VRAM Self::VRAM.get(col + row * Self::SCREEN_WIDTH).map(VolAddress::read)
.get(col + row * Self::SCREEN_WIDTH)
.map(VolAddress::read)
} }
/// Writes the pixel at the given (col,row). /// Writes the pixel at the given (col,row).
@ -54,9 +51,7 @@ impl Mode3 {
/// ///
/// Gives `None` if out of bounds. /// Gives `None` if out of bounds.
pub fn write_pixel(col: usize, row: usize, color: Color) -> Option<()> { pub fn write_pixel(col: usize, row: usize, color: Color) -> Option<()> {
Self::VRAM Self::VRAM.get(col + row * Self::SCREEN_WIDTH).map(|va| va.write(color))
.get(col + row * Self::SCREEN_WIDTH)
.map(|va| va.write(color))
} }
/// Clears the whole screen to the desired color. /// Clears the whole screen to the desired color.
@ -114,12 +109,10 @@ impl Mode4 {
const SCREEN_U32_COUNT: usize = Self::SCREEN_PIXEL_COUNT / 4; const SCREEN_U32_COUNT: usize = Self::SCREEN_PIXEL_COUNT / 4;
// TODO: newtype this? // TODO: newtype this?
const PAGE0_BLOCK8: VolBlock<u8, <U256 as Mul<U160>>::Output> = const PAGE0_BLOCK8: VolBlock<u8, <U256 as Mul<U160>>::Output> = unsafe { VolBlock::new(VRAM_BASE_USIZE) };
unsafe { VolBlock::new(VRAM_BASE_USIZE) };
// TODO: newtype this? // TODO: newtype this?
const PAGE1_BLOCK8: VolBlock<u8, <U256 as Mul<U160>>::Output> = const PAGE1_BLOCK8: VolBlock<u8, <U256 as Mul<U160>>::Output> = unsafe { VolBlock::new(VRAM_BASE_USIZE + 0xA000) };
unsafe { VolBlock::new(VRAM_BASE_USIZE + 0xA000) };
// TODO: newtype this? // TODO: newtype this?
const PAGE0_BLOCK16: VolBlock<u16, <<U256 as Mul<U160>>::Output as Div<U2>>::Output> = const PAGE0_BLOCK16: VolBlock<u16, <<U256 as Mul<U160>>::Output as Div<U2>>::Output> =
@ -193,9 +186,7 @@ impl Mode4 {
/// The page is imagined to be a series of `u16` values rather than `u8` /// The page is imagined to be a series of `u16` values rather than `u8`
/// values, allowing you to write two palette entries side by side as a single /// values, allowing you to write two palette entries side by side as a single
/// write operation. /// write operation.
pub fn write_wide_pixel( pub fn write_wide_pixel(page1: bool, wide_col: usize, row: usize, wide_pal8bpp: u16) -> Option<()> {
page1: bool, wide_col: usize, row: usize, wide_pal8bpp: u16,
) -> Option<()> {
if wide_col < Self::SCREEN_WIDTH / 2 && row < Self::SCREEN_HEIGHT { if wide_col < Self::SCREEN_WIDTH / 2 && row < Self::SCREEN_HEIGHT {
let wide_index = wide_col + row * Self::SCREEN_WIDTH / 2; let wide_index = wide_col + row * Self::SCREEN_WIDTH / 2;
let address: VolAddress<u16> = if page1 { let address: VolAddress<u16> = if page1 {
@ -213,13 +204,7 @@ impl Mode4 {
pub fn clear_page_to(page1: bool, pal8bpp: u8) { pub fn clear_page_to(page1: bool, pal8bpp: u8) {
let pal8bpp_32 = pal8bpp as u32; let pal8bpp_32 = pal8bpp as u32;
let bulk_color = (pal8bpp_32 << 24) | (pal8bpp_32 << 16) | (pal8bpp_32 << 8) | pal8bpp_32; let bulk_color = (pal8bpp_32 << 24) | (pal8bpp_32 << 16) | (pal8bpp_32 << 8) | pal8bpp_32;
for va in (if page1 { for va in (if page1 { Self::PAGE1_BULK32 } else { Self::PAGE0_BULK32 }).iter() {
Self::PAGE1_BULK32
} else {
Self::PAGE0_BULK32
})
.iter()
{
va.write(bulk_color) va.write(bulk_color)
} }
} }
@ -267,12 +252,10 @@ impl Mode5 {
const SCREEN_U32_COUNT: usize = Self::SCREEN_PIXEL_COUNT / 2; const SCREEN_U32_COUNT: usize = Self::SCREEN_PIXEL_COUNT / 2;
// TODO: newtype this? // TODO: newtype this?
const PAGE0_BLOCK: VolBlock<Color, <U160 as Mul<U128>>::Output> = const PAGE0_BLOCK: VolBlock<Color, <U160 as Mul<U128>>::Output> = unsafe { VolBlock::new(VRAM_BASE_USIZE) };
unsafe { VolBlock::new(VRAM_BASE_USIZE) };
// TODO: newtype this? // TODO: newtype this?
const PAGE1_BLOCK: VolBlock<Color, <U160 as Mul<U128>>::Output> = const PAGE1_BLOCK: VolBlock<Color, <U160 as Mul<U128>>::Output> = unsafe { VolBlock::new(VRAM_BASE_USIZE + 0xA000) };
unsafe { VolBlock::new(VRAM_BASE_USIZE + 0xA000) };
/// private iterator over the page0 pixels, four at a time /// private iterator over the page0 pixels, four at a time
const PAGE0_BULK32: VolBlock<u32, <<U160 as Mul<U128>>::Output as Div<U2>>::Output> = const PAGE0_BULK32: VolBlock<u32, <<U160 as Mul<U128>>::Output as Div<U2>>::Output> =
@ -320,13 +303,7 @@ impl Mode5 {
pub fn clear_page_to(page1: bool, color: Color) { pub fn clear_page_to(page1: bool, color: Color) {
let color32 = color.0 as u32; let color32 = color.0 as u32;
let bulk_color = color32 << 16 | color32; let bulk_color = color32 << 16 | color32;
for va in (if page1 { for va in (if page1 { Self::PAGE1_BULK32 } else { Self::PAGE0_BULK32 }).iter() {
Self::PAGE1_BULK32
} else {
Self::PAGE0_BULK32
})
.iter()
{
va.write(bulk_color) va.write(bulk_color)
} }
} }