Modules and newtypes, joy!

This commit is contained in:
Lokathor 2018-12-29 20:17:48 -07:00
parent 6466a53475
commit 4c7ec468d0
13 changed files with 57 additions and 22 deletions

View file

@ -104,7 +104,6 @@ pub unsafe fn register_ram_reset(flags: RegisterRAMResetFlags) {
}
newtype! {
/// Flags for use with `register_ram_reset`.
#[derive(Debug, Copy, Clone, Default, PartialEq, Eq)]
RegisterRAMResetFlags, u8
}
#[allow(missing_docs)]

View file

@ -21,7 +21,6 @@ newtype! {
/// Bit 8-12: Screen Base Block (0 through 31, 2k each)
/// Bit 13: Display area overflow wraps (otherwise transparent, affine BG only)
/// Bit 14-15: Screen Size
#[derive(Debug, Copy, Clone, Default, PartialEq, Eq)]
BackgroundControlSetting, u16
}
impl BackgroundControlSetting {

View file

@ -24,7 +24,6 @@ newtype!(
/// * 13: Window 0 display
/// * 14: Window 1 display
/// * 15: Object window
#[derive(Debug, Copy, Clone, Default, PartialEq, Eq)]
DisplayControlSetting,
u16
);
@ -103,12 +102,10 @@ pub const DISPSTAT: VolAddress<DisplayStatusSetting> = unsafe { VolAddress::new_
newtype!(
/// A newtype over display status and interrupt control values.
#[derive(Debug, Copy, Clone, Default, PartialEq, Eq)]
DisplayStatusSetting,
u16
);
#[allow(missing_docs)]
impl DisplayStatusSetting {
phantom_fields! {
self.0: u16,
@ -168,7 +165,6 @@ newtype! {
/// * Bits 4-7: BG mosaic vertical increase
/// * Bits 8-11: Object mosaic horizontal increase
/// * Bits 12-15: Object mosaic vertical increase
#[derive(Debug, Copy, Clone, Default, PartialEq, Eq)]
MosaicSetting, u16
}
impl MosaicSetting {

View file

@ -63,7 +63,6 @@ use super::*;
newtype! {
/// Allows you to configure a DMA unit.
#[derive(Debug, Copy, Clone, Default, PartialEq, Eq)]
DMAControlSetting, u16
}
#[allow(missing_docs)]

View file

@ -27,7 +27,6 @@ newtype! {
///
/// Methods here follow the "high-active" convention, where a bit is enabled
/// when it's part of the set.
#[derive(Debug, Copy, Clone, Default, PartialEq, Eq)]
KeyInput, u16
}
@ -100,7 +99,6 @@ newtype! {
/// NOTE: This _only_ configures the operation of when keypad interrupts can
/// fire. You must still set the `IME` to have interrupts at all, and you must
/// further set `IE` for keypad interrupts to be possible.
#[derive(Debug, Copy, Clone, Default, PartialEq, Eq)]
KeyInterruptSetting, u16
}
#[allow(missing_docs)]

View file

@ -61,7 +61,6 @@ newtype! {
/// mode naturally does nothing when used with Timer 0.
/// * Bit 6: Raise a timer interrupt upon overflow.
/// * Bit 7: Enable the timer.
#[derive(Debug, Copy, Clone, Default, PartialEq, Eq)]
TimerControlSetting, u16
}
impl TimerControlSetting {

View file

@ -28,22 +28,29 @@ pub(crate) use gba_proc_macro::phantom_fields;
/// of your docs and derives in front of your newtype in the same way you would
/// for a normal struct. Then the inner type to be wrapped it name.
///
/// The macro _assumes_ that you'll be using it to wrap zero safe numeric types,
/// so it automatically provides a `const fn` method for `new` that just wraps
/// `0`. If this is not desired you can add `, no frills` to the invocation.
/// The macro _assumes_ that you'll be using it to wrap numeric types and that
/// it's safe to have a `0` value, so it automatically provides a `const fn`
/// method for `new` that just wraps `0`. Also, it derives Debug, Clone, Copy,
/// Default, PartialEq, and Eq. If all this is not desired you can add `, no
/// frills` to the invocation.
///
/// Example:
/// ```
/// newtype! {
/// /// Records a particular key press combination.
/// #[derive(Debug, Copy, Clone, Default, PartialEq, Eq)]
/// KeyInput, u16
/// }
/// newtype! {
/// /// You can't derive most stuff above array size 32, so we add
/// /// the `, no frills` modifier.
/// BigArray, [u8; 200], no frills
/// }
/// ```
#[macro_export]
macro_rules! newtype {
($(#[$attr:meta])* $new_name:ident, $v:vis $old_name:ty) => {
$(#[$attr])*
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
#[repr(transparent)]
pub struct $new_name($v $old_name);
impl $new_name {
@ -60,18 +67,58 @@ macro_rules! newtype {
};
}
#[macro_export]
macro_rules! newtype_enum {
(
$(#[$struct_attr:meta])*
$new_name:ident = $old_name:ident,
$($(#[$tag_attr:meta])* $tag_name:ident = $base_value:expr,)*
) => {
$(#[$struct_attr])*
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr($old_name)]
pub enum $new_name {
$(
$(#[$tag_attr])*
$tag_name = $base_value,
)*
}
};
}
newtype_enum! {
/// the Foo
Foo = u16,
/// the Bar
Bar = 0,
/// The Zap
Zap = 1,
}
pub mod base;
pub(crate) use self::base::*;
pub mod bios;
pub mod wram;
pub mod io;
pub mod mgba;
pub mod oam;
pub mod palram;
pub mod vram;
pub mod oam;
pub mod rom;
pub mod sram;
pub mod mgba;
newtype! {
/// A color on the GBA is an RGB 5.5.5 within a `u16`
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(PartialOrd, Ord, Hash)]
Color, u16
}

View file

@ -11,7 +11,6 @@ newtype! {
/// * Bit 12: Mosaic
/// * Bit 13: is 8bpp
/// * Bits 14-15: Object Shape: Square, Horizontal, Vertical
#[derive(Debug, Copy, Clone, Default, PartialEq, Eq)]
OBJAttr0, u16
}
impl OBJAttr0 {
@ -75,7 +74,6 @@ newtype! {
/// * Normal render: Bit 12 holds hflip and 13 holds vflip.
/// * Affine render: The affine parameter selection.
/// * Bits 14-15: Object Size
#[derive(Debug, Copy, Clone, Default, PartialEq, Eq)]
OBJAttr1, u16
}
impl OBJAttr1 {
@ -119,7 +117,6 @@ newtype! {
/// * Bits 0-9: Base Tile Index (tile offset from CBB4)
/// * Bits 10-11: Priority
/// * Bits 12-15: Palbank (if using 4bpp)
#[derive(Debug, Copy, Clone, Default, PartialEq, Eq)]
OBJAttr2, u16
}
impl OBJAttr2 {

1
src/rom.rs Normal file
View file

@ -0,0 +1 @@
//! Module for things related to ROM.

1
src/sram.rs Normal file
View file

@ -0,0 +1 @@
//! Module for things related to SRAM.

View file

@ -4,7 +4,6 @@ use super::*;
newtype! {
/// A screenblock entry for use in Affine mode.
#[derive(Debug, Clone, Copy, Default)]
AffineScreenblockEntry, u8
}

View file

@ -4,7 +4,6 @@ use super::*;
newtype! {
/// A screenblock entry for use in Text mode.
#[derive(Debug, Clone, Copy, Default)]
TextScreenblockEntry, u16
}
impl TextScreenblockEntry {

1
src/wram.rs Normal file
View file

@ -0,0 +1 @@
//! Module for things related to WRAM.