move video and vblank to own files

This commit is contained in:
Corwin Kuiper 2021-03-08 03:48:28 +00:00
parent b05c339cbf
commit f1941729ca
4 changed files with 75 additions and 73 deletions

View file

@ -24,7 +24,7 @@ fn main(_argc: isize, _argv: *const *const u8) -> isize {
fn bitmap3_mode( fn bitmap3_mode(
bitmap: &mut display::bitmap3::Bitmap3, bitmap: &mut display::bitmap3::Bitmap3,
vblank: &mut display::VBlank, vblank: &mut display::vblank::VBlank,
input: &mut gba::input::ButtonController, input: &mut gba::input::ButtonController,
) { ) {
let mut pos = Vector2D { let mut pos = Vector2D {
@ -51,7 +51,7 @@ fn bitmap3_mode(
fn bitmap4_mode( fn bitmap4_mode(
bitmap: &mut display::bitmap4::Bitmap4, bitmap: &mut display::bitmap4::Bitmap4,
vblank: &mut display::VBlank, vblank: &mut display::vblank::VBlank,
input: &mut gba::input::ButtonController, input: &mut gba::input::ButtonController,
) { ) {
bitmap.set_palette_entry(1, 0x001F); bitmap.set_palette_entry(1, 0x001F);

View file

@ -1,15 +1,14 @@
use crate::{ use crate::memory_mapped::MemoryMapped;
memory_mapped::MemoryMapped,
single::{Single, SingleToken},
};
use bitflags::bitflags; use bitflags::bitflags;
use bitmap3::Bitmap3; use vblank::VBlankGiver;
use bitmap4::Bitmap4; use video::Video;
pub mod bitmap3; pub mod bitmap3;
pub mod bitmap4; pub mod bitmap4;
pub mod tiled0; pub mod tiled0;
pub mod vblank;
pub mod video;
const DISPLAY_CONTROL: MemoryMapped<u16> = unsafe { MemoryMapped::new(0x0400_0000) }; const DISPLAY_CONTROL: MemoryMapped<u16> = unsafe { MemoryMapped::new(0x0400_0000) };
const DISPLAY_STATUS: MemoryMapped<u16> = unsafe { MemoryMapped::new(0x0400_0004) }; const DISPLAY_STATUS: MemoryMapped<u16> = unsafe { MemoryMapped::new(0x0400_0004) };
@ -52,30 +51,6 @@ pub struct Display {
pub video: Video, pub video: Video,
pub vblank: VBlankGiver, 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 { impl Display {
pub(crate) const unsafe fn new() -> Self { 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 {}
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);
}

52
src/display/vblank.rs Normal file
View file

@ -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);
}

16
src/display/video.rs Normal file
View file

@ -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() }
}
}