diff --git a/examples/multiple_video.rs b/examples/multiple_video.rs index f663d37b..7321e384 100644 --- a/examples/multiple_video.rs +++ b/examples/multiple_video.rs @@ -24,7 +24,7 @@ fn main(_argc: isize, _argv: *const *const u8) -> isize { fn bitmap3_mode( bitmap: &mut display::bitmap3::Bitmap3, - vblank: &mut display::VBlank, + vblank: &mut display::vblank::VBlank, input: &mut gba::input::ButtonController, ) { let mut pos = Vector2D { @@ -51,7 +51,7 @@ fn bitmap3_mode( fn bitmap4_mode( bitmap: &mut display::bitmap4::Bitmap4, - vblank: &mut display::VBlank, + vblank: &mut display::vblank::VBlank, input: &mut gba::input::ButtonController, ) { bitmap.set_palette_entry(1, 0x001F); diff --git a/src/display/mod.rs b/src/display/mod.rs index 49ebade0..9265b2de 100644 --- a/src/display/mod.rs +++ b/src/display/mod.rs @@ -1,15 +1,14 @@ -use crate::{ - memory_mapped::MemoryMapped, - single::{Single, SingleToken}, -}; +use crate::memory_mapped::MemoryMapped; use bitflags::bitflags; -use bitmap3::Bitmap3; -use bitmap4::Bitmap4; +use vblank::VBlankGiver; +use video::Video; pub mod bitmap3; pub mod bitmap4; pub mod tiled0; +pub mod vblank; +pub mod video; const DISPLAY_CONTROL: MemoryMapped = unsafe { MemoryMapped::new(0x0400_0000) }; const DISPLAY_STATUS: MemoryMapped = unsafe { MemoryMapped::new(0x0400_0004) }; @@ -52,30 +51,6 @@ pub struct Display { pub video: Video, pub vblank: VBlankGiver, } -#[non_exhaustive] -pub struct Video {} - -#[non_exhaustive] -pub struct VBlankGiver {} - -impl Video { - /// Bitmap mode that provides a 16-bit colour framebuffer - pub fn bitmap3(&mut self) -> Bitmap3 { - unsafe { Bitmap3::new() } - } - - /// Bitmap 4 provides two 8-bit paletted framebuffers with page switching - pub fn bitmap4(&mut self) -> Bitmap4 { - unsafe { bitmap4::Bitmap4::new() } - } -} - -impl VBlankGiver { - /// Gets a vblank handle where only one can be obtained at a time - pub fn get(&mut self) -> VBlank { - unsafe { VBlank::new() } - } -} impl Display { pub(crate) const unsafe fn new() -> Self { @@ -111,44 +86,3 @@ pub fn busy_wait_for_VBlank() { while VCOUNT.get() >= 160 {} while VCOUNT.get() < 160 {} } - -/// Once obtained, this guarentees that interrupts are enabled and set up to -/// allow for waiting for vblank -pub struct VBlank {} - -impl VBlank { - unsafe fn new() -> Self { - crate::interrupt::enable_interrupts(); - crate::interrupt::enable(crate::interrupt::Interrupt::VBlank); - enable_VBlank_interrupt(); - VBlank {} - } - - #[allow(non_snake_case)] - /// Waits for VBlank using interrupts. This is the preferred method for - /// waiting until the next frame. - pub fn wait_for_VBlank(&self) { - crate::syscall::wait_for_VBlank(); - } -} - -impl Drop for VBlank { - fn drop(&mut self) { - unsafe { - disable_VBlank_interrupt(); - crate::interrupt::disable(crate::interrupt::Interrupt::VBlank); - } - } -} - -#[allow(non_snake_case)] -unsafe fn enable_VBlank_interrupt() { - let status = DISPLAY_STATUS.get() | (1 << 3); - DISPLAY_STATUS.set(status); -} - -#[allow(non_snake_case)] -unsafe fn disable_VBlank_interrupt() { - let status = DISPLAY_STATUS.get() & !(1 << 3); - DISPLAY_STATUS.set(status); -} diff --git a/src/display/vblank.rs b/src/display/vblank.rs new file mode 100644 index 00000000..6a8bae03 --- /dev/null +++ b/src/display/vblank.rs @@ -0,0 +1,52 @@ +use super::DISPLAY_STATUS; + +#[non_exhaustive] +pub struct VBlankGiver {} + +impl VBlankGiver { + /// Gets a vblank handle where only one can be obtained at a time + pub fn get(&mut self) -> VBlank { + unsafe { VBlank::new() } + } +} + +/// Once obtained, this guarentees that interrupts are enabled and set up to +/// allow for waiting for vblank +pub struct VBlank {} + +impl VBlank { + unsafe fn new() -> Self { + crate::interrupt::enable_interrupts(); + crate::interrupt::enable(crate::interrupt::Interrupt::VBlank); + enable_VBlank_interrupt(); + VBlank {} + } + + #[allow(non_snake_case)] + /// Waits for VBlank using interrupts. This is the preferred method for + /// waiting until the next frame. + pub fn wait_for_VBlank(&self) { + crate::syscall::wait_for_VBlank(); + } +} + +impl Drop for VBlank { + fn drop(&mut self) { + unsafe { + disable_VBlank_interrupt(); + crate::interrupt::disable(crate::interrupt::Interrupt::VBlank); + } + } +} + +#[allow(non_snake_case)] +unsafe fn enable_VBlank_interrupt() { + let status = DISPLAY_STATUS.get() | (1 << 3); + DISPLAY_STATUS.set(status); +} + +#[allow(non_snake_case)] +unsafe fn disable_VBlank_interrupt() { + let status = DISPLAY_STATUS.get() & !(1 << 3); + DISPLAY_STATUS.set(status); +} diff --git a/src/display/video.rs b/src/display/video.rs new file mode 100644 index 00000000..2006379b --- /dev/null +++ b/src/display/video.rs @@ -0,0 +1,16 @@ +use super::{bitmap3::Bitmap3, bitmap4::Bitmap4}; + +#[non_exhaustive] +pub struct Video {} + +impl Video { + /// Bitmap mode that provides a 16-bit colour framebuffer + pub fn bitmap3(&mut self) -> Bitmap3 { + unsafe { Bitmap3::new() } + } + + /// Bitmap 4 provides two 8-bit paletted framebuffers with page switching + pub fn bitmap4(&mut self) -> Bitmap4 { + unsafe { Bitmap4::new() } + } +}