mirror of
https://github.com/italicsjenga/gba.git
synced 2024-12-23 19:01:30 +11:00
Modules and newtypes, joy!
This commit is contained in:
parent
6466a53475
commit
4c7ec468d0
|
@ -104,7 +104,6 @@ pub unsafe fn register_ram_reset(flags: RegisterRAMResetFlags) {
|
||||||
}
|
}
|
||||||
newtype! {
|
newtype! {
|
||||||
/// Flags for use with `register_ram_reset`.
|
/// Flags for use with `register_ram_reset`.
|
||||||
#[derive(Debug, Copy, Clone, Default, PartialEq, Eq)]
|
|
||||||
RegisterRAMResetFlags, u8
|
RegisterRAMResetFlags, u8
|
||||||
}
|
}
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
|
|
|
@ -21,7 +21,6 @@ newtype! {
|
||||||
/// Bit 8-12: Screen Base Block (0 through 31, 2k each)
|
/// Bit 8-12: Screen Base Block (0 through 31, 2k each)
|
||||||
/// Bit 13: Display area overflow wraps (otherwise transparent, affine BG only)
|
/// Bit 13: Display area overflow wraps (otherwise transparent, affine BG only)
|
||||||
/// Bit 14-15: Screen Size
|
/// Bit 14-15: Screen Size
|
||||||
#[derive(Debug, Copy, Clone, Default, PartialEq, Eq)]
|
|
||||||
BackgroundControlSetting, u16
|
BackgroundControlSetting, u16
|
||||||
}
|
}
|
||||||
impl BackgroundControlSetting {
|
impl BackgroundControlSetting {
|
||||||
|
|
|
@ -24,7 +24,6 @@ newtype!(
|
||||||
/// * 13: Window 0 display
|
/// * 13: Window 0 display
|
||||||
/// * 14: Window 1 display
|
/// * 14: Window 1 display
|
||||||
/// * 15: Object window
|
/// * 15: Object window
|
||||||
#[derive(Debug, Copy, Clone, Default, PartialEq, Eq)]
|
|
||||||
DisplayControlSetting,
|
DisplayControlSetting,
|
||||||
u16
|
u16
|
||||||
);
|
);
|
||||||
|
@ -103,12 +102,10 @@ pub const DISPSTAT: VolAddress<DisplayStatusSetting> = unsafe { VolAddress::new_
|
||||||
|
|
||||||
newtype!(
|
newtype!(
|
||||||
/// A newtype over display status and interrupt control values.
|
/// A newtype over display status and interrupt control values.
|
||||||
#[derive(Debug, Copy, Clone, Default, PartialEq, Eq)]
|
|
||||||
DisplayStatusSetting,
|
DisplayStatusSetting,
|
||||||
u16
|
u16
|
||||||
);
|
);
|
||||||
|
|
||||||
#[allow(missing_docs)]
|
|
||||||
impl DisplayStatusSetting {
|
impl DisplayStatusSetting {
|
||||||
phantom_fields! {
|
phantom_fields! {
|
||||||
self.0: u16,
|
self.0: u16,
|
||||||
|
@ -168,7 +165,6 @@ newtype! {
|
||||||
/// * Bits 4-7: BG mosaic vertical increase
|
/// * Bits 4-7: BG mosaic vertical increase
|
||||||
/// * Bits 8-11: Object mosaic horizontal increase
|
/// * Bits 8-11: Object mosaic horizontal increase
|
||||||
/// * Bits 12-15: Object mosaic vertical increase
|
/// * Bits 12-15: Object mosaic vertical increase
|
||||||
#[derive(Debug, Copy, Clone, Default, PartialEq, Eq)]
|
|
||||||
MosaicSetting, u16
|
MosaicSetting, u16
|
||||||
}
|
}
|
||||||
impl MosaicSetting {
|
impl MosaicSetting {
|
||||||
|
|
|
@ -63,7 +63,6 @@ use super::*;
|
||||||
|
|
||||||
newtype! {
|
newtype! {
|
||||||
/// Allows you to configure a DMA unit.
|
/// Allows you to configure a DMA unit.
|
||||||
#[derive(Debug, Copy, Clone, Default, PartialEq, Eq)]
|
|
||||||
DMAControlSetting, u16
|
DMAControlSetting, u16
|
||||||
}
|
}
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
|
|
|
@ -27,7 +27,6 @@ newtype! {
|
||||||
///
|
///
|
||||||
/// Methods here follow the "high-active" convention, where a bit is enabled
|
/// Methods here follow the "high-active" convention, where a bit is enabled
|
||||||
/// when it's part of the set.
|
/// when it's part of the set.
|
||||||
#[derive(Debug, Copy, Clone, Default, PartialEq, Eq)]
|
|
||||||
KeyInput, u16
|
KeyInput, u16
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,7 +99,6 @@ newtype! {
|
||||||
/// NOTE: This _only_ configures the operation of when keypad interrupts can
|
/// 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
|
/// fire. You must still set the `IME` to have interrupts at all, and you must
|
||||||
/// further set `IE` for keypad interrupts to be possible.
|
/// further set `IE` for keypad interrupts to be possible.
|
||||||
#[derive(Debug, Copy, Clone, Default, PartialEq, Eq)]
|
|
||||||
KeyInterruptSetting, u16
|
KeyInterruptSetting, u16
|
||||||
}
|
}
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
|
|
|
@ -61,7 +61,6 @@ newtype! {
|
||||||
/// mode naturally does nothing when used with Timer 0.
|
/// mode naturally does nothing when used with Timer 0.
|
||||||
/// * Bit 6: Raise a timer interrupt upon overflow.
|
/// * Bit 6: Raise a timer interrupt upon overflow.
|
||||||
/// * Bit 7: Enable the timer.
|
/// * Bit 7: Enable the timer.
|
||||||
#[derive(Debug, Copy, Clone, Default, PartialEq, Eq)]
|
|
||||||
TimerControlSetting, u16
|
TimerControlSetting, u16
|
||||||
}
|
}
|
||||||
impl TimerControlSetting {
|
impl TimerControlSetting {
|
||||||
|
|
61
src/lib.rs
61
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
|
/// 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.
|
/// 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,
|
/// The macro _assumes_ that you'll be using it to wrap numeric types and that
|
||||||
/// so it automatically provides a `const fn` method for `new` that just wraps
|
/// it's safe to have a `0` value, so it automatically provides a `const fn`
|
||||||
/// `0`. If this is not desired you can add `, no frills` to the invocation.
|
/// 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:
|
/// Example:
|
||||||
/// ```
|
/// ```
|
||||||
/// newtype! {
|
/// newtype! {
|
||||||
/// /// Records a particular key press combination.
|
/// /// Records a particular key press combination.
|
||||||
/// #[derive(Debug, Copy, Clone, Default, PartialEq, Eq)]
|
|
||||||
/// KeyInput, u16
|
/// 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_export]
|
||||||
macro_rules! newtype {
|
macro_rules! newtype {
|
||||||
($(#[$attr:meta])* $new_name:ident, $v:vis $old_name:ty) => {
|
($(#[$attr:meta])* $new_name:ident, $v:vis $old_name:ty) => {
|
||||||
$(#[$attr])*
|
$(#[$attr])*
|
||||||
|
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
pub struct $new_name($v $old_name);
|
pub struct $new_name($v $old_name);
|
||||||
impl $new_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 mod base;
|
||||||
pub(crate) use self::base::*;
|
pub(crate) use self::base::*;
|
||||||
|
|
||||||
pub mod bios;
|
pub mod bios;
|
||||||
|
|
||||||
|
pub mod wram;
|
||||||
|
|
||||||
pub mod io;
|
pub mod io;
|
||||||
pub mod mgba;
|
|
||||||
pub mod oam;
|
|
||||||
pub mod palram;
|
pub mod palram;
|
||||||
|
|
||||||
pub mod vram;
|
pub mod vram;
|
||||||
|
|
||||||
|
pub mod oam;
|
||||||
|
|
||||||
|
pub mod rom;
|
||||||
|
|
||||||
|
pub mod sram;
|
||||||
|
|
||||||
|
pub mod mgba;
|
||||||
|
|
||||||
newtype! {
|
newtype! {
|
||||||
/// A color on the GBA is an RGB 5.5.5 within a `u16`
|
/// 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
|
Color, u16
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,6 @@ newtype! {
|
||||||
/// * Bit 12: Mosaic
|
/// * Bit 12: Mosaic
|
||||||
/// * Bit 13: is 8bpp
|
/// * Bit 13: is 8bpp
|
||||||
/// * Bits 14-15: Object Shape: Square, Horizontal, Vertical
|
/// * Bits 14-15: Object Shape: Square, Horizontal, Vertical
|
||||||
#[derive(Debug, Copy, Clone, Default, PartialEq, Eq)]
|
|
||||||
OBJAttr0, u16
|
OBJAttr0, u16
|
||||||
}
|
}
|
||||||
impl OBJAttr0 {
|
impl OBJAttr0 {
|
||||||
|
@ -75,7 +74,6 @@ newtype! {
|
||||||
/// * Normal render: Bit 12 holds hflip and 13 holds vflip.
|
/// * Normal render: Bit 12 holds hflip and 13 holds vflip.
|
||||||
/// * Affine render: The affine parameter selection.
|
/// * Affine render: The affine parameter selection.
|
||||||
/// * Bits 14-15: Object Size
|
/// * Bits 14-15: Object Size
|
||||||
#[derive(Debug, Copy, Clone, Default, PartialEq, Eq)]
|
|
||||||
OBJAttr1, u16
|
OBJAttr1, u16
|
||||||
}
|
}
|
||||||
impl OBJAttr1 {
|
impl OBJAttr1 {
|
||||||
|
@ -119,7 +117,6 @@ newtype! {
|
||||||
/// * Bits 0-9: Base Tile Index (tile offset from CBB4)
|
/// * Bits 0-9: Base Tile Index (tile offset from CBB4)
|
||||||
/// * Bits 10-11: Priority
|
/// * Bits 10-11: Priority
|
||||||
/// * Bits 12-15: Palbank (if using 4bpp)
|
/// * Bits 12-15: Palbank (if using 4bpp)
|
||||||
#[derive(Debug, Copy, Clone, Default, PartialEq, Eq)]
|
|
||||||
OBJAttr2, u16
|
OBJAttr2, u16
|
||||||
}
|
}
|
||||||
impl OBJAttr2 {
|
impl OBJAttr2 {
|
||||||
|
|
1
src/rom.rs
Normal file
1
src/rom.rs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
//! Module for things related to ROM.
|
1
src/sram.rs
Normal file
1
src/sram.rs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
//! Module for things related to SRAM.
|
|
@ -4,7 +4,6 @@ use super::*;
|
||||||
|
|
||||||
newtype! {
|
newtype! {
|
||||||
/// A screenblock entry for use in Affine mode.
|
/// A screenblock entry for use in Affine mode.
|
||||||
#[derive(Debug, Clone, Copy, Default)]
|
|
||||||
AffineScreenblockEntry, u8
|
AffineScreenblockEntry, u8
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ use super::*;
|
||||||
|
|
||||||
newtype! {
|
newtype! {
|
||||||
/// A screenblock entry for use in Text mode.
|
/// A screenblock entry for use in Text mode.
|
||||||
#[derive(Debug, Clone, Copy, Default)]
|
|
||||||
TextScreenblockEntry, u16
|
TextScreenblockEntry, u16
|
||||||
}
|
}
|
||||||
impl TextScreenblockEntry {
|
impl TextScreenblockEntry {
|
||||||
|
|
1
src/wram.rs
Normal file
1
src/wram.rs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
//! Module for things related to WRAM.
|
Loading…
Reference in a new issue