diff --git a/src/bios.rs b/src/bios.rs index ce01862..175446f 100644 --- a/src/bios.rs +++ b/src/bios.rs @@ -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)] diff --git a/src/io/background.rs b/src/io/background.rs index c5df78b..493fb59 100644 --- a/src/io/background.rs +++ b/src/io/background.rs @@ -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 { diff --git a/src/io/display.rs b/src/io/display.rs index b5e52ae..ded95a5 100644 --- a/src/io/display.rs +++ b/src/io/display.rs @@ -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 = 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 { diff --git a/src/io/dma.rs b/src/io/dma.rs index 7dca8de..bea9669 100644 --- a/src/io/dma.rs +++ b/src/io/dma.rs @@ -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)] diff --git a/src/io/keypad.rs b/src/io/keypad.rs index ec24995..bbbbf3a 100644 --- a/src/io/keypad.rs +++ b/src/io/keypad.rs @@ -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)] diff --git a/src/io/timers.rs b/src/io/timers.rs index 6086ebe..25cc516 100644 --- a/src/io/timers.rs +++ b/src/io/timers.rs @@ -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 { diff --git a/src/lib.rs b/src/lib.rs index 9361a12..82b9286 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 } diff --git a/src/oam.rs b/src/oam.rs index 958158b..897e76e 100644 --- a/src/oam.rs +++ b/src/oam.rs @@ -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 { diff --git a/src/rom.rs b/src/rom.rs new file mode 100644 index 0000000..2414747 --- /dev/null +++ b/src/rom.rs @@ -0,0 +1 @@ +//! Module for things related to ROM. diff --git a/src/sram.rs b/src/sram.rs new file mode 100644 index 0000000..a294d5f --- /dev/null +++ b/src/sram.rs @@ -0,0 +1 @@ +//! Module for things related to SRAM. diff --git a/src/vram/affine.rs b/src/vram/affine.rs index 57293a0..6b1f556 100644 --- a/src/vram/affine.rs +++ b/src/vram/affine.rs @@ -4,7 +4,6 @@ use super::*; newtype! { /// A screenblock entry for use in Affine mode. - #[derive(Debug, Clone, Copy, Default)] AffineScreenblockEntry, u8 } diff --git a/src/vram/text.rs b/src/vram/text.rs index 44a07d0..07db59b 100644 --- a/src/vram/text.rs +++ b/src/vram/text.rs @@ -4,7 +4,6 @@ use super::*; newtype! { /// A screenblock entry for use in Text mode. - #[derive(Debug, Clone, Copy, Default)] TextScreenblockEntry, u16 } impl TextScreenblockEntry { diff --git a/src/wram.rs b/src/wram.rs new file mode 100644 index 0000000..405d022 --- /dev/null +++ b/src/wram.rs @@ -0,0 +1 @@ +//! Module for things related to WRAM.