From 2929076e55b80b653de1e1409d2f8212201922fb Mon Sep 17 00:00:00 2001 From: Lokathor Date: Tue, 12 Feb 2019 09:42:17 -0700 Subject: [PATCH] jump to 120 Picking this because it makes the `hello_magic.rs` lines all stay on one line. --- examples/hello_magic.rs | 12 +++--------- rustfmt.toml | 2 +- src/io/sound.rs | 6 ++---- src/oam.rs | 6 +----- src/vram.rs | 3 +-- src/vram/bitmap.rs | 43 ++++++++++------------------------------- 6 files changed, 18 insertions(+), 54 deletions(-) diff --git a/examples/hello_magic.rs b/examples/hello_magic.rs index 5f90871..75eb6bc 100644 --- a/examples/hello_magic.rs +++ b/examples/hello_magic.rs @@ -10,15 +10,9 @@ fn panic(_info: &core::panic::PanicInfo) -> ! { fn main(_argc: isize, _argv: *const *const u8) -> isize { unsafe { (0x400_0000 as *mut u16).write_volatile(0x0403); - (0x600_0000 as *mut u16) - .offset(120 + 80 * 240) - .write_volatile(0x001F); - (0x600_0000 as *mut u16) - .offset(136 + 80 * 240) - .write_volatile(0x03E0); - (0x600_0000 as *mut u16) - .offset(120 + 96 * 240) - .write_volatile(0x7C00); + (0x600_0000 as *mut u16).offset(120 + 80 * 240).write_volatile(0x001F); + (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 {} } } diff --git a/rustfmt.toml b/rustfmt.toml index e1f494c..ad60708 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -4,5 +4,5 @@ merge_imports = true reorder_imports = true use_try_shorthand = true tab_spaces = 2 -max_width = 100 +max_width = 120 color = "Never" diff --git a/src/io/sound.rs b/src/io/sound.rs index 7d3e98e..6b6101f 100644 --- a/src/io/sound.rs +++ b/src/io/sound.rs @@ -60,8 +60,7 @@ pub const SOUND2CNT_L: VolAddress = unsafe { VolAddress: pub const SOUND2CNT_H: VolAddress = unsafe { VolAddress::new(0x400_006C) }; /// Sound Channel 3 Stop/Wave RAM select (`NR23`, `NR24`). Read/Write. -pub const SOUND3CNT_L: VolAddress = - unsafe { VolAddress::new(0x400_0070) }; +pub const SOUND3CNT_L: VolAddress = unsafe { VolAddress::new(0x400_0070) }; newtype! { StopWaveRAMSelectSetting, u16 @@ -159,8 +158,7 @@ pub const FIFO_B_L: VolAddress = unsafe { VolAddress::new(0x400_00A4) }; pub const FIFO_B_H: VolAddress = unsafe { VolAddress::new(0x400_00A6) }; /// Channel L/R Volume/Enable (`NR50`, `NR51`). Read/Write. -pub const SOUNDCNT_L: VolAddress = - unsafe { VolAddress::new(0x400_0080) }; +pub const SOUNDCNT_L: VolAddress = unsafe { VolAddress::new(0x400_0080) }; newtype! { NonWaveVolumeEnableSetting, u16 diff --git a/src/oam.rs b/src/oam.rs index 83d960e..82b3f58 100644 --- a/src/oam.rs +++ b/src/oam.rs @@ -157,11 +157,7 @@ pub fn read_obj_attributes(slot: usize) -> Option { let attr0 = va_u16.cast::().read(); let attr1 = va_u16.offset(1).cast::().read(); let attr2 = va_u16.offset(2).cast::().read(); - ObjectAttributes { - attr0, - attr1, - attr2, - } + ObjectAttributes { attr0, attr1, attr2 } }) } diff --git a/src/vram.rs b/src/vram.rs index 55fbd55..35138ef 100644 --- a/src/vram.rs +++ b/src/vram.rs @@ -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) }; /// The screen entry base blocks. -pub const SCREEN_BASE_BLOCKS: VolBlock<[u8; 0x800], U32> = - unsafe { VolBlock::new(VRAM_BASE_USIZE) }; +pub const SCREEN_BASE_BLOCKS: VolBlock<[u8; 0x800], U32> = unsafe { VolBlock::new(VRAM_BASE_USIZE) }; newtype! { /// An 8x8 tile with 4bpp, packed as `u32` values for proper alignment. diff --git a/src/vram/bitmap.rs b/src/vram/bitmap.rs index e0b490e..7e70f98 100644 --- a/src/vram/bitmap.rs +++ b/src/vram/bitmap.rs @@ -30,8 +30,7 @@ impl Mode3 { /// /// Use `col + row * SCREEN_WIDTH` to get the address of an individual pixel, /// or use the helpers provided in this module. - pub const VRAM: VolBlock>::Output> = - unsafe { VolBlock::new(VRAM_BASE_USIZE) }; + pub const VRAM: VolBlock>::Output> = unsafe { VolBlock::new(VRAM_BASE_USIZE) }; /// private iterator over the pixels, two at a time const VRAM_BULK: VolBlock>::Output as Div>::Output> = @@ -43,9 +42,7 @@ impl Mode3 { /// /// Gives `None` if out of bounds. pub fn read_pixel(col: usize, row: usize) -> Option { - Self::VRAM - .get(col + row * Self::SCREEN_WIDTH) - .map(VolAddress::read) + Self::VRAM.get(col + row * Self::SCREEN_WIDTH).map(VolAddress::read) } /// Writes the pixel at the given (col,row). @@ -54,9 +51,7 @@ impl Mode3 { /// /// Gives `None` if out of bounds. pub fn write_pixel(col: usize, row: usize, color: Color) -> Option<()> { - Self::VRAM - .get(col + row * Self::SCREEN_WIDTH) - .map(|va| va.write(color)) + Self::VRAM.get(col + row * Self::SCREEN_WIDTH).map(|va| va.write(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; // TODO: newtype this? - const PAGE0_BLOCK8: VolBlock>::Output> = - unsafe { VolBlock::new(VRAM_BASE_USIZE) }; + const PAGE0_BLOCK8: VolBlock>::Output> = unsafe { VolBlock::new(VRAM_BASE_USIZE) }; // TODO: newtype this? - const PAGE1_BLOCK8: VolBlock>::Output> = - unsafe { VolBlock::new(VRAM_BASE_USIZE + 0xA000) }; + const PAGE1_BLOCK8: VolBlock>::Output> = unsafe { VolBlock::new(VRAM_BASE_USIZE + 0xA000) }; // TODO: newtype this? const PAGE0_BLOCK16: VolBlock>::Output as Div>::Output> = @@ -193,9 +186,7 @@ impl Mode4 { /// 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 /// write operation. - pub fn write_wide_pixel( - page1: bool, wide_col: usize, row: usize, wide_pal8bpp: u16, - ) -> Option<()> { + pub fn write_wide_pixel(page1: bool, wide_col: usize, row: usize, wide_pal8bpp: u16) -> Option<()> { if wide_col < Self::SCREEN_WIDTH / 2 && row < Self::SCREEN_HEIGHT { let wide_index = wide_col + row * Self::SCREEN_WIDTH / 2; let address: VolAddress = if page1 { @@ -213,13 +204,7 @@ impl Mode4 { pub fn clear_page_to(page1: bool, pal8bpp: u8) { let pal8bpp_32 = pal8bpp as u32; let bulk_color = (pal8bpp_32 << 24) | (pal8bpp_32 << 16) | (pal8bpp_32 << 8) | pal8bpp_32; - for va in (if page1 { - Self::PAGE1_BULK32 - } else { - Self::PAGE0_BULK32 - }) - .iter() - { + for va in (if page1 { Self::PAGE1_BULK32 } else { Self::PAGE0_BULK32 }).iter() { va.write(bulk_color) } } @@ -267,12 +252,10 @@ impl Mode5 { const SCREEN_U32_COUNT: usize = Self::SCREEN_PIXEL_COUNT / 2; // TODO: newtype this? - const PAGE0_BLOCK: VolBlock>::Output> = - unsafe { VolBlock::new(VRAM_BASE_USIZE) }; + const PAGE0_BLOCK: VolBlock>::Output> = unsafe { VolBlock::new(VRAM_BASE_USIZE) }; // TODO: newtype this? - const PAGE1_BLOCK: VolBlock>::Output> = - unsafe { VolBlock::new(VRAM_BASE_USIZE + 0xA000) }; + const PAGE1_BLOCK: VolBlock>::Output> = unsafe { VolBlock::new(VRAM_BASE_USIZE + 0xA000) }; /// private iterator over the page0 pixels, four at a time const PAGE0_BULK32: VolBlock>::Output as Div>::Output> = @@ -320,13 +303,7 @@ impl Mode5 { pub fn clear_page_to(page1: bool, color: Color) { let color32 = color.0 as u32; let bulk_color = color32 << 16 | color32; - for va in (if page1 { - Self::PAGE1_BULK32 - } else { - Self::PAGE0_BULK32 - }) - .iter() - { + for va in (if page1 { Self::PAGE1_BULK32 } else { Self::PAGE0_BULK32 }).iter() { va.write(bulk_color) } }