From e475253dcfda8fcb6f24d7b9ca045c590c4ffa99 Mon Sep 17 00:00:00 2001 From: Lokathor Date: Thu, 27 Dec 2018 11:51:53 -0700 Subject: [PATCH] small cleanups --- examples/bg_demo.rs | 5 ++--- src/io/background.rs | 22 ++++++++-------------- src/io/display.rs | 2 +- src/io/timers.rs | 2 ++ src/vram/affine.rs | 2 ++ src/vram/text.rs | 5 +++-- 6 files changed, 18 insertions(+), 20 deletions(-) diff --git a/examples/bg_demo.rs b/examples/bg_demo.rs index 7477aa2..d15b0ce 100644 --- a/examples/bg_demo.rs +++ b/examples/bg_demo.rs @@ -7,10 +7,9 @@ use gba::{ display::{DisplayControlSetting, DISPCNT}, }, palram::index_palram_bg_4bpp, - vram::text::{TextScreenblockEntry}, + vram::{text::TextScreenblockEntry, Tile4bpp, CHAR_BASE_BLOCKS, SCREEN_BASE_BLOCKS}, Color, }; -use gba::vram::{Tile4bpp, CHAR_BASE_BLOCKS, SCREEN_BASE_BLOCKS}; #[panic_handler] fn panic(_info: &core::panic::PanicInfo) -> ! { @@ -34,7 +33,7 @@ fn main(_argc: isize, _argv: *const *const u8) -> isize { let dark_entry = TextScreenblockEntry::from_tile_index(1); checker_screenblock(8, light_entry, dark_entry); // bg0 control - BG0CNT.write(BackgroundControlSetting::from_screen_base_block(8)); + BG0CNT.write(BackgroundControlSetting::new().with_screen_base_block(8)); // Display Control DISPCNT.write(DisplayControlSetting::new().with_bg0(true)); loop { diff --git a/src/io/background.rs b/src/io/background.rs index 03de1d7..b4cc9a7 100644 --- a/src/io/background.rs +++ b/src/io/background.rs @@ -25,12 +25,6 @@ newtype! { BackgroundControlSetting, u16 } impl BackgroundControlSetting { - pub const fn from_screen_base_block(screen_base_block: u16) -> Self { - BackgroundControlSetting((screen_base_block & 31) << 8) - } - - // - bool_bits!(u16, [(6, mosaic), (7, is_8bpp), (13, display_overflow_wrapping)]); multi_bits!( @@ -73,24 +67,24 @@ pub enum BGSize { Three = 3, } -// BG0 X-Offset. Write only. Text mode only. 9 bits. +/// BG0 X-Offset. Write only. Text mode only. 9 bits. pub const BG0HOFS: VolAddress = unsafe { VolAddress::new_unchecked(0x400_0010) }; -// BG0 Y-Offset. Write only. Text mode only. 9 bits. +/// BG0 Y-Offset. Write only. Text mode only. 9 bits. pub const BG0VOFS: VolAddress = unsafe { VolAddress::new_unchecked(0x400_0012) }; -// BG1 X-Offset. Write only. Text mode only. 9 bits. +/// BG1 X-Offset. Write only. Text mode only. 9 bits. pub const BG1HOFS: VolAddress = unsafe { VolAddress::new_unchecked(0x400_0012) }; -// BG1 Y-Offset. Write only. Text mode only. 9 bits. +/// BG1 Y-Offset. Write only. Text mode only. 9 bits. pub const BG1VOFS: VolAddress = unsafe { VolAddress::new_unchecked(0x400_0012) }; -// BG2 X-Offset. Write only. Text mode only. 9 bits. +/// BG2 X-Offset. Write only. Text mode only. 9 bits. pub const BG2HOFS: VolAddress = unsafe { VolAddress::new_unchecked(0x400_0018) }; -// BG2 Y-Offset. Write only. Text mode only. 9 bits. +/// BG2 Y-Offset. Write only. Text mode only. 9 bits. pub const BG2VOFS: VolAddress = unsafe { VolAddress::new_unchecked(0x400_001A) }; -// BG3 X-Offset. Write only. Text mode only. 9 bits. +/// BG3 X-Offset. Write only. Text mode only. 9 bits. pub const BG3HOFS: VolAddress = unsafe { VolAddress::new_unchecked(0x400_001C) }; -// BG3 Y-Offset. Write only. Text mode only. 9 bits. +/// BG3 Y-Offset. Write only. Text mode only. 9 bits. pub const BG3VOFS: VolAddress = unsafe { VolAddress::new_unchecked(0x400_001E) }; // TODO: affine backgrounds diff --git a/src/io/display.rs b/src/io/display.rs index 6badf90..421c93b 100644 --- a/src/io/display.rs +++ b/src/io/display.rs @@ -187,4 +187,4 @@ impl MosaicSetting { (12, 4, obj_vertical_inc), ] ); -} \ No newline at end of file +} diff --git a/src/io/timers.rs b/src/io/timers.rs index 127f641..026409e 100644 --- a/src/io/timers.rs +++ b/src/io/timers.rs @@ -25,6 +25,8 @@ use super::*; +// TODO: striding blocks? + /// Timer 0 Counter/Reload. Special (see module). pub const TM0CNT_L: VolAddress = unsafe { VolAddress::new_unchecked(0x400_0100) }; diff --git a/src/vram/affine.rs b/src/vram/affine.rs index a29ccf1..57293a0 100644 --- a/src/vram/affine.rs +++ b/src/vram/affine.rs @@ -1,3 +1,5 @@ +//! Module for affine things. + use super::*; newtype! { diff --git a/src/vram/text.rs b/src/vram/text.rs index 58f5aa4..bb433f5 100644 --- a/src/vram/text.rs +++ b/src/vram/text.rs @@ -8,13 +8,14 @@ newtype! { TextScreenblockEntry, u16 } impl TextScreenblockEntry { + /// Generates a default entry with the specified tile index. pub const fn from_tile_index(index: u16) -> Self { - TextScreenblockEntry(index & Self::TILE_ID_MASK) + Self::new().with_tile_index(index) } bool_bits!(u16, [(10, hflip), (11, vflip)]); - multi_bits!(u16, [(0, 10, tile_id), (12, 4, palbank)]); + multi_bits!(u16, [(0, 10, tile_index), (12, 4, palbank)]); } newtype! {