small cleanups

This commit is contained in:
Lokathor 2018-12-27 11:51:53 -07:00
parent 147a2bc45c
commit e475253dcf
6 changed files with 18 additions and 20 deletions

View file

@ -7,10 +7,9 @@ use gba::{
display::{DisplayControlSetting, DISPCNT}, display::{DisplayControlSetting, DISPCNT},
}, },
palram::index_palram_bg_4bpp, palram::index_palram_bg_4bpp,
vram::text::{TextScreenblockEntry}, vram::{text::TextScreenblockEntry, Tile4bpp, CHAR_BASE_BLOCKS, SCREEN_BASE_BLOCKS},
Color, Color,
}; };
use gba::vram::{Tile4bpp, CHAR_BASE_BLOCKS, SCREEN_BASE_BLOCKS};
#[panic_handler] #[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! { 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); let dark_entry = TextScreenblockEntry::from_tile_index(1);
checker_screenblock(8, light_entry, dark_entry); checker_screenblock(8, light_entry, dark_entry);
// bg0 control // bg0 control
BG0CNT.write(BackgroundControlSetting::from_screen_base_block(8)); BG0CNT.write(BackgroundControlSetting::new().with_screen_base_block(8));
// Display Control // Display Control
DISPCNT.write(DisplayControlSetting::new().with_bg0(true)); DISPCNT.write(DisplayControlSetting::new().with_bg0(true));
loop { loop {

View file

@ -25,12 +25,6 @@ newtype! {
BackgroundControlSetting, u16 BackgroundControlSetting, u16
} }
impl BackgroundControlSetting { 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)]); bool_bits!(u16, [(6, mosaic), (7, is_8bpp), (13, display_overflow_wrapping)]);
multi_bits!( multi_bits!(
@ -73,24 +67,24 @@ pub enum BGSize {
Three = 3, 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<u16> = unsafe { VolAddress::new_unchecked(0x400_0010) }; pub const BG0HOFS: VolAddress<u16> = 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<u16> = unsafe { VolAddress::new_unchecked(0x400_0012) }; pub const BG0VOFS: VolAddress<u16> = 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<u16> = unsafe { VolAddress::new_unchecked(0x400_0012) }; pub const BG1HOFS: VolAddress<u16> = 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<u16> = unsafe { VolAddress::new_unchecked(0x400_0012) }; pub const BG1VOFS: VolAddress<u16> = 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<u16> = unsafe { VolAddress::new_unchecked(0x400_0018) }; pub const BG2HOFS: VolAddress<u16> = 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<u16> = unsafe { VolAddress::new_unchecked(0x400_001A) }; pub const BG2VOFS: VolAddress<u16> = 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<u16> = unsafe { VolAddress::new_unchecked(0x400_001C) }; pub const BG3HOFS: VolAddress<u16> = 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<u16> = unsafe { VolAddress::new_unchecked(0x400_001E) }; pub const BG3VOFS: VolAddress<u16> = unsafe { VolAddress::new_unchecked(0x400_001E) };
// TODO: affine backgrounds // TODO: affine backgrounds

View file

@ -25,6 +25,8 @@
use super::*; use super::*;
// TODO: striding blocks?
/// Timer 0 Counter/Reload. Special (see module). /// Timer 0 Counter/Reload. Special (see module).
pub const TM0CNT_L: VolAddress<u16> = unsafe { VolAddress::new_unchecked(0x400_0100) }; pub const TM0CNT_L: VolAddress<u16> = unsafe { VolAddress::new_unchecked(0x400_0100) };

View file

@ -1,3 +1,5 @@
//! Module for affine things.
use super::*; use super::*;
newtype! { newtype! {

View file

@ -8,13 +8,14 @@ newtype! {
TextScreenblockEntry, u16 TextScreenblockEntry, u16
} }
impl TextScreenblockEntry { impl TextScreenblockEntry {
/// Generates a default entry with the specified tile index.
pub const fn from_tile_index(index: u16) -> Self { 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)]); 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! { newtype! {