Skip to content

Commit

Permalink
ditch the mmio module
Browse files Browse the repository at this point in the history
  • Loading branch information
Lokathor committed Jun 3, 2024
1 parent 2092429 commit 57f5f3a
Show file tree
Hide file tree
Showing 22 changed files with 918 additions and 954 deletions.
8 changes: 5 additions & 3 deletions examples/basic_keyinput.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ use core::ptr::{addr_of, addr_of_mut};
use gba::{
asm_runtime::USER_IRQ_HANDLER,
bios::VBlankIntrWait,
irq::{IrqBits, IE, IME},
keys::KEYINPUT,
mgba::{MgbaLogLevel, MgbaLogger},
mmio::{BACKDROP_COLOR, DISPCNT, DISPSTAT, IE, IME, KEYINPUT},
video::{Color, DisplayControl, DisplayStatus},
IrqBits,
video::{
Color, DisplayControl, DisplayStatus, BACKDROP_COLOR, DISPCNT, DISPSTAT,
},
};

gba::panic_handler!(mgba_log_err);
Expand Down
8 changes: 5 additions & 3 deletions examples/mode0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@

use gba::{
bios::VBlankIntrWait,
mmio::{BG_PALRAM, DISPCNT, DISPSTAT, IE, IME, VRAM_BG_TILE4},
irq::{IrqBits, IE, IME},
sample_art::decompress_cga_face_to_vram_4bpp,
video::{Color, DisplayControl, DisplayStatus},
IrqBits,
video::{
Color, DisplayControl, DisplayStatus, BG_PALRAM, DISPCNT, DISPSTAT,
VRAM_BG_TILE4,
},
};

gba::panic_handler!(empty_loop);
Expand Down
8 changes: 5 additions & 3 deletions examples/mode3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

use gba::{
bios::VBlankIntrWait,
mmio::{DISPCNT, DISPSTAT, IE, IME, KEYINPUT, MODE3_VRAM},
video::{Color, DisplayControl, DisplayStatus},
IrqBits,
irq::{IrqBits, IE, IME},
keys::KEYINPUT,
video::{
Color, DisplayControl, DisplayStatus, DISPCNT, DISPSTAT, MODE3_VRAM,
},
};

gba::panic_handler!(empty_loop);
Expand Down
9 changes: 6 additions & 3 deletions examples/mode4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@

use gba::{
bios::VBlankIntrWait,
mmio::{BG_PALRAM, DISPCNT, DISPSTAT, IE, IME, KEYINPUT, MODE4_VRAM},
video::{Color, DisplayControl, DisplayStatus},
IrqBits,
irq::{IrqBits, IE, IME},
keys::KEYINPUT,
video::{
Color, DisplayControl, DisplayStatus, BG_PALRAM, DISPCNT, DISPSTAT,
MODE4_VRAM,
},
};

gba::panic_handler!(empty_loop);
Expand Down
8 changes: 5 additions & 3 deletions examples/mode5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

use gba::{
bios::VBlankIntrWait,
mmio::{DISPCNT, DISPSTAT, IE, IME, KEYINPUT, MODE5_VRAM},
video::{Color, DisplayControl, DisplayStatus},
IrqBits,
irq::{IrqBits, IE, IME},
keys::KEYINPUT,
video::{
Color, DisplayControl, DisplayStatus, DISPCNT, DISPSTAT, MODE5_VRAM,
},
};

gba::panic_handler!(empty_loop);
Expand Down
15 changes: 8 additions & 7 deletions examples/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ use gba::{
asm_runtime::USER_IRQ_HANDLER,
bios::VBlankIntrWait,
gba_cell::GbaCell,
mmio::{
obj_palbank, BG0CNT, BG_PALRAM, DISPCNT, DISPSTAT, IE, IME, KEYINPUT,
OBJ_ATTR0, OBJ_ATTR_ALL, TEXT_SCREENBLOCKS, VRAM_BG_TILE4, VRAM_OBJ_TILE4,
},
obj::{ObjAttr, ObjAttr0, ObjDisplayStyle},
irq::{IrqBits, IE, IME},
keys::KEYINPUT,
sample_art::{decompress_cga_face_to_vram_4bpp, Cga},
video::{BackgroundControl, Color, DisplayControl, DisplayStatus, TextEntry},
IrqBits,
video::{
obj_palbank, BackgroundControl, Color, DisplayControl, DisplayStatus,
ObjAttr, ObjAttr0, ObjDisplayStyle, TextEntry, BG0CNT, BG_PALRAM, DISPCNT,
DISPSTAT, OBJ_ATTR0, OBJ_ATTR_ALL, TEXT_SCREENBLOCKS, VRAM_BG_TILE4,
VRAM_OBJ_TILE4,
},
};

gba::panic_handler!(mgba_log_err);
Expand Down
6 changes: 3 additions & 3 deletions examples/paddle_ball.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use gba::{
asm_runtime::USER_IRQ_HANDLER,
bios::VBlankIntrWait,
gba_cell::GbaCell,
mmio::{DISPCNT, DISPSTAT, IE, IME, KEYINPUT},
video::{Color, DisplayControl, DisplayStatus, Mode3},
IrqBits, KeyInput,
irq::{IrqBits, IE, IME},
keys::{KeyInput, KEYINPUT},
video::{Color, DisplayControl, DisplayStatus, Mode3, DISPCNT, DISPSTAT},
};

const SCREEN_WIDTH: u16 = 240;
Expand Down
9 changes: 5 additions & 4 deletions examples/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ use gba::{
asm_runtime::USER_IRQ_HANDLER,
bios::VBlankIntrWait,
gba_cell::GbaCell,
mmio::{BACKDROP_COLOR, DISPCNT, DISPSTAT, IE, IME, TIMER0_CONTROL},
timers::{CpusPerTick, TimerControl},
video::{Color, DisplayControl, DisplayStatus},
IrqBits,
irq::{IrqBits, IE, IME},
timers::{CpusPerTick, TimerControl, TIMER0_CONTROL},
video::{
Color, DisplayControl, DisplayStatus, BACKDROP_COLOR, DISPCNT, DISPSTAT,
},
};

static OVERFLOWS: GbaCell<u32> = GbaCell::new(0);
Expand Down
8 changes: 5 additions & 3 deletions src/asm_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
// cargo feature enabled, and so they should all have the `track_caller`
// attribute set whenever the `on_gba` feature is *disabled*

use crate::{gba_cell::GbaCell, IrqBits};
use crate::gba_cell::GbaCell;

use bracer::*;

/// Inserts a `nop` instruction.
Expand Down Expand Up @@ -215,5 +216,6 @@ core::arch::global_asm! {

/// The user-provided interrupt request handler function.
#[cfg(feature = "on_gba")]
pub static USER_IRQ_HANDLER: GbaCell<Option<unsafe extern "C" fn(IrqBits)>> =
GbaCell::new(None);
pub static USER_IRQ_HANDLER: GbaCell<
Option<unsafe extern "C" fn(crate::irq::IrqBits)>,
> = GbaCell::new(None);
2 changes: 1 addition & 1 deletion src/bios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//! BIOS functions have a rather high calls overhead compared to a normal
//! foreign function.

use crate::IrqBits;
use crate::irq::IrqBits;

/// `0x04`: Waits for a specific interrupt type(s) to happen.
///
Expand Down
98 changes: 93 additions & 5 deletions src/dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@
//! Using the DMA units is equivalent to playing around with raw pointers. It
//! must be handled very carefully, or memory corruption can occur.

use core::ffi::c_void;

use bitfrob::{u16_with_bit, u16_with_region};
use voladdress::{Safe, VolRegion};
use video::Tile4;
use voladdress::{Safe, Unsafe, VolRegion};

use crate::{
mmio::{DMA3_CONTROL, DMA3_DESTINATION, DMA3_SOURCE, DMA3_TRANSFER_COUNT},
video::Tile4,
};
use super::*;

/// Controls the activity of a DMA unit.
#[derive(Debug, Clone, Copy, Default)]
Expand Down Expand Up @@ -214,3 +214,91 @@ pub fn dma3_copy_tile4(src: &[Tile4], dest: VolRegion<Tile4, Safe, Safe>) {
dma3_copy_u32(src.as_ptr().cast(), dest.as_mut_ptr().cast(), src.len() * 8)
};
}

/// Source address for DMA3.
///
/// The correct pointer type depends on the transfer mode used.
pub const DMA0_SOURCE: VolAddress<*const c_void, (), Unsafe> =
unsafe { VolAddress::new(0x0400_00B0) };

/// Destination address for DMA3.
///
/// The correct pointer type depends on the transfer mode used.
pub const DMA0_DESTINATION: VolAddress<*mut c_void, (), Unsafe> =
unsafe { VolAddress::new(0x0400_00B4) };

/// The number of transfers desired.
///
/// A value of 0 indicates the maximum number of transfers: `0x4000`
pub const DMA0_TRANSFER_COUNT: VolAddress<u16, (), Unsafe> =
unsafe { VolAddress::new(0x0400_00B8) };

/// DMA3 Control Bits.
pub const DMA0_CONTROL: VolAddress<DmaControl, SOGBA, Unsafe> =
unsafe { VolAddress::new(0x0400_00BA) };

/// Source address for DMA3.
///
/// The correct pointer type depends on the transfer mode used.
pub const DMA1_SOURCE: VolAddress<*const c_void, (), Unsafe> =
unsafe { VolAddress::new(0x0400_00BC) };

/// Destination address for DMA3.
///
/// The correct pointer type depends on the transfer mode used.
pub const DMA1_DESTINATION: VolAddress<*mut c_void, (), Unsafe> =
unsafe { VolAddress::new(0x0400_00C0) };

/// The number of transfers desired.
///
/// A value of 0 indicates the maximum number of transfers: `0x4000`
pub const DMA1_TRANSFER_COUNT: VolAddress<u16, (), Unsafe> =
unsafe { VolAddress::new(0x0400_00C4) };

/// DMA3 Control Bits.
pub const DMA1_CONTROL: VolAddress<DmaControl, SOGBA, Unsafe> =
unsafe { VolAddress::new(0x0400_00C6) };

/// Source address for DMA3.
///
/// The correct pointer type depends on the transfer mode used.
pub const DMA2_SOURCE: VolAddress<*const c_void, (), Unsafe> =
unsafe { VolAddress::new(0x0400_00C8) };

/// Destination address for DMA3.
///
/// The correct pointer type depends on the transfer mode used.
pub const DMA2_DESTINATION: VolAddress<*mut c_void, (), Unsafe> =
unsafe { VolAddress::new(0x0400_00CC) };

/// The number of transfers desired.
///
/// A value of 0 indicates the maximum number of transfers: `0x4000`
pub const DMA2_TRANSFER_COUNT: VolAddress<u16, (), Unsafe> =
unsafe { VolAddress::new(0x0400_00D0) };

/// DMA3 Control Bits.
pub const DMA2_CONTROL: VolAddress<DmaControl, SOGBA, Unsafe> =
unsafe { VolAddress::new(0x0400_00D2) };

/// Source address for DMA3.
///
/// The correct pointer type depends on the transfer mode used.
pub const DMA3_SOURCE: VolAddress<*const c_void, (), Unsafe> =
unsafe { VolAddress::new(0x0400_00D4) };

/// Destination address for DMA3.
///
/// The correct pointer type depends on the transfer mode used.
pub const DMA3_DESTINATION: VolAddress<*mut c_void, (), Unsafe> =
unsafe { VolAddress::new(0x0400_00D8) };

/// The number of transfers desired.
///
/// A value of 0 indicates the maximum number of transfers: `0x1_0000`
pub const DMA3_TRANSFER_COUNT: VolAddress<u16, (), Unsafe> =
unsafe { VolAddress::new(0x0400_00DC) };

/// DMA3 Control Bits.
pub const DMA3_CONTROL: VolAddress<DmaControl, SOGBA, Unsafe> =
unsafe { VolAddress::new(0x0400_00DE) };
2 changes: 1 addition & 1 deletion src/gba_cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use core::{
ptr::NonNull,
};

use crate::{video::Color, IrqBits, KeyInput};
use crate::{irq::IrqBits, keys::KeyInput, video::Color};

/// Marker trait bound for the methods of [`GbaCell`].
///
Expand Down
Loading

0 comments on commit 57f5f3a

Please sign in to comment.