diff --git a/agb/examples/bitmap3.rs b/agb/examples/bitmap3.rs deleted file mode 100644 index fb4c41f58..000000000 --- a/agb/examples/bitmap3.rs +++ /dev/null @@ -1,33 +0,0 @@ -#![no_std] -#![no_main] - -use agb::display; - -struct Vector2D { - x: i32, - y: i32, -} - -#[agb::entry] -fn main(mut gba: agb::Gba) -> ! { - let mut bitmap = gba.display.video.bitmap3(); - let vblank = agb::interrupt::VBlank::get(); - - let mut input = agb::input::ButtonController::new(); - let mut pos = Vector2D { - x: display::WIDTH / 2, - y: display::HEIGHT / 2, - }; - - loop { - vblank.wait_for_vblank(); - - input.update(); - pos.x += input.x_tri() as i32; - pos.y += input.y_tri() as i32; - - pos.x = pos.x.clamp(0, display::WIDTH - 1); - pos.y = pos.y.clamp(0, display::HEIGHT - 1); - bitmap.draw_point(pos.x, pos.y, 0x001F); - } -} diff --git a/agb/examples/bitmap4.rs b/agb/examples/bitmap4.rs deleted file mode 100644 index 3084cfa47..000000000 --- a/agb/examples/bitmap4.rs +++ /dev/null @@ -1,33 +0,0 @@ -#![no_std] -#![no_main] - -use agb::display::{self, HEIGHT, WIDTH}; - -#[agb::entry] -fn main(mut gba: agb::Gba) -> ! { - let mut bitmap = gba.display.video.bitmap4(); - let vblank = agb::interrupt::VBlank::get(); - - bitmap.set_palette_entry(1, 0x001F); - bitmap.set_palette_entry(2, 0x03E0); - - for y in 0..HEIGHT { - for x in 0..WIDTH { - bitmap.draw_point_page(x, y, 0xF, display::bitmap4::Page::Front); - bitmap.draw_point_page(x, y, 1, display::bitmap4::Page::Front); - bitmap.draw_point_page(x, y, 0xFF, display::bitmap4::Page::Back); - bitmap.draw_point_page(x, y, 2, display::bitmap4::Page::Back); - } - } - - let mut input = agb::input::ButtonController::new(); - - loop { - vblank.wait_for_vblank(); - input.update(); - - if input.is_just_pressed(agb::input::Button::A) { - bitmap.flip_page(); - } - } -} diff --git a/agb/examples/multiple_video.rs b/agb/examples/multiple_video.rs deleted file mode 100644 index f37c69c4a..000000000 --- a/agb/examples/multiple_video.rs +++ /dev/null @@ -1,84 +0,0 @@ -#![no_std] -#![no_main] - -use agb::display; - -struct Vector2D { - x: i32, - y: i32, -} - -#[agb::entry] -fn main(mut gba: agb::Gba) -> ! { - let vblank = agb::interrupt::VBlank::get(); - let mut input = agb::input::ButtonController::new(); - - loop { - bitmap3_mode(&mut gba.display.video.bitmap3(), &vblank, &mut input); - bitmap4_mode(&mut gba.display.video.bitmap4(), &vblank, &mut input); - } -} - -fn bitmap3_mode( - bitmap: &mut display::bitmap3::Bitmap3, - vblank: &agb::interrupt::VBlank, - input: &mut agb::input::ButtonController, -) { - let mut pos = Vector2D { - x: display::WIDTH / 2, - y: display::HEIGHT / 2, - }; - - loop { - vblank.wait_for_vblank(); - - input.update(); - if input.is_just_pressed(agb::input::Button::B) { - break; - } - - pos.x += input.x_tri() as i32; - pos.y += input.y_tri() as i32; - - pos.x = pos.x.clamp(0, display::WIDTH - 1); - pos.y = pos.y.clamp(0, display::HEIGHT - 1); - bitmap.draw_point(pos.x, pos.y, 0x001F); - } -} - -fn bitmap4_mode( - bitmap: &mut display::bitmap4::Bitmap4, - vblank: &agb::interrupt::VBlank, - input: &mut agb::input::ButtonController, -) { - bitmap.set_palette_entry(1, 0x001F); - bitmap.set_palette_entry(2, 0x03E0); - - bitmap.draw_point_page( - display::WIDTH / 2, - display::HEIGHT / 2, - 1, - display::bitmap4::Page::Front, - ); - bitmap.draw_point_page( - display::WIDTH / 2 + 5, - display::HEIGHT / 2, - 2, - display::bitmap4::Page::Back, - ); - - let mut count = 0; - loop { - vblank.wait_for_vblank(); - - input.update(); - if input.is_just_pressed(agb::input::Button::B) { - break; - } - - count += 1; - if count % 6 == 0 { - bitmap.flip_page(); - } - } -} diff --git a/agb/examples/panic.rs b/agb/examples/panic.rs deleted file mode 100644 index 71ff6e8c6..000000000 --- a/agb/examples/panic.rs +++ /dev/null @@ -1,22 +0,0 @@ -#![no_std] -#![no_main] - -use agb::display; - -#[agb::entry] -fn main(mut gba: agb::Gba) -> ! { - let mut bitmap = gba.display.video.bitmap3(); - let mut input = agb::input::ButtonController::new(); - - loop { - input.update(); - // if A is pressed, draw out of range - if input.is_just_pressed(agb::input::Button::A) { - bitmap.draw_point(display::WIDTH, 0, 0x05); - } - if input.is_just_pressed(agb::input::Button::B) { - #[allow(arithmetic_overflow)] - let _p = core::i32::MAX + 1; - } - } -} diff --git a/agb/examples/syscall.rs b/agb/examples/syscall.rs deleted file mode 100644 index 4650f3ef0..000000000 --- a/agb/examples/syscall.rs +++ /dev/null @@ -1,19 +0,0 @@ -#![no_std] -#![no_main] - -use agb::{display, syscall}; - -#[agb::entry] -fn main(mut gba: agb::Gba) -> ! { - let mut bitmap = gba.display.video.bitmap3(); - - for x in 0..display::WIDTH { - let y = syscall::sqrt(x << 6); - let y = (display::HEIGHT - y).clamp(0, display::HEIGHT - 1); - bitmap.draw_point(x, y, 0x001F); - } - - loop { - syscall::halt(); - } -} diff --git a/agb/src/display/bitmap3.rs b/agb/src/display/bitmap3.rs deleted file mode 100644 index b29b31779..000000000 --- a/agb/src/display/bitmap3.rs +++ /dev/null @@ -1,48 +0,0 @@ -use crate::memory_mapped::MemoryMapped2DArray; - -use super::{ - set_graphics_mode, set_graphics_settings, DisplayMode, GraphicsSettings, HEIGHT, WIDTH, -}; - -use core::{convert::TryInto, marker::PhantomData}; - -const BITMAP_MODE_3: MemoryMapped2DArray = - unsafe { MemoryMapped2DArray::new(0x600_0000) }; - -#[non_exhaustive] -pub struct Bitmap3<'gba> { - phantom: PhantomData<&'gba ()>, -} - -impl Bitmap3<'_> { - pub(crate) unsafe fn new() -> Self { - set_graphics_mode(DisplayMode::Bitmap3); - set_graphics_settings(GraphicsSettings::LAYER_BG2); - Bitmap3 { - phantom: PhantomData, - } - } - - /// Draws point to screen at (x, y) coordinates with colour and panics if - /// (x, y) is out of the bounds of the screen. - pub fn draw_point(&mut self, x: i32, y: i32, colour: u16) { - let x = x.try_into().unwrap(); - let y = y.try_into().unwrap(); - BITMAP_MODE_3.set(x, y, colour); - } - - #[must_use] - pub fn read_point(&self, x: i32, y: i32) -> u16 { - let x = x.try_into().unwrap(); - let y = y.try_into().unwrap(); - BITMAP_MODE_3.get(x, y) - } - - pub fn clear(&mut self, colour: u16) { - for y in 0..(HEIGHT as usize) { - for x in 0..(WIDTH as usize) { - BITMAP_MODE_3.set(x, y, colour); - } - } - } -} diff --git a/agb/src/display/bitmap4.rs b/agb/src/display/bitmap4.rs deleted file mode 100644 index c0e05a7ff..000000000 --- a/agb/src/display/bitmap4.rs +++ /dev/null @@ -1,91 +0,0 @@ -use core::marker::PhantomData; - -use crate::memory_mapped::{MemoryMapped1DArray, MemoryMapped2DArray}; - -use super::{ - set_graphics_mode, set_graphics_settings, DisplayMode, GraphicsSettings, DISPLAY_CONTROL, - HEIGHT, WIDTH, -}; - -const BITMAP_PAGE_FRONT_MODE_4: MemoryMapped2DArray< - u16, - { (WIDTH / 2) as usize }, - { HEIGHT as usize }, -> = unsafe { MemoryMapped2DArray::new(0x600_0000) }; -const BITMAP_PAGE_BACK_MODE_4: MemoryMapped2DArray< - u16, - { (WIDTH / 2) as usize }, - { HEIGHT as usize }, -> = unsafe { MemoryMapped2DArray::new(0x600_A000) }; -const PALETTE_BACKGROUND: MemoryMapped1DArray = - unsafe { MemoryMapped1DArray::new(0x0500_0000) }; - -#[derive(Clone, Copy)] -pub enum Page { - Front = 0, - Back = 1, -} - -#[non_exhaustive] -pub struct Bitmap4<'gba> { - phantom: PhantomData<&'gba ()>, -} - -impl Bitmap4<'_> { - pub(crate) unsafe fn new() -> Self { - set_graphics_mode(DisplayMode::Bitmap4); - set_graphics_settings(GraphicsSettings::LAYER_BG2); - Bitmap4 { - phantom: PhantomData, - } - } - - /// Draws point on specified page at (x, y) coordinates with colour index - /// whose colour is specified in the background palette. Panics if (x, y) is - /// out of the bounds of the screen. - pub fn draw_point_page(&mut self, x: i32, y: i32, colour: u8, page: Page) { - let addr = match page { - Page::Front => BITMAP_PAGE_FRONT_MODE_4, - Page::Back => BITMAP_PAGE_BACK_MODE_4, - }; - - let x_in_screen = (x / 2) as usize; - let y_in_screen = y as usize; - - let c = addr.get(x_in_screen, y_in_screen); - if x & 0b1 != 0 { - addr.set(x_in_screen, y_in_screen, c & 0xff | u16::from(colour) << 8); - } else { - addr.set(x_in_screen, y_in_screen, c & 0xff00 | u16::from(colour)); - } - } - - /// Draws point on the non-current page at (x, y) coordinates with colour - /// index whose colour is specified in the background palette. Panics if (x, - /// y) is out of the bounds of the screen. - pub fn draw_point(&mut self, x: i32, y: i32, colour: u8) { - let display = DISPLAY_CONTROL.get(); - - // get other page - let page = if display & GraphicsSettings::PAGE_SELECT.bits() != 0 { - Page::Front - } else { - Page::Back - }; - - self.draw_point_page(x, y, colour, page); - } - - /// Sets the colour of colour index in the background palette. - pub fn set_palette_entry(&mut self, entry: u32, colour: u16) { - PALETTE_BACKGROUND.set(entry as usize, colour); - } - - /// Flips page, changing the Gameboy advance to draw the contents of the - /// other page - pub fn flip_page(&mut self) { - let display = DISPLAY_CONTROL.get(); - let swapped = display ^ GraphicsSettings::PAGE_SELECT.bits(); - DISPLAY_CONTROL.set(swapped); - } -} diff --git a/agb/src/display/mod.rs b/agb/src/display/mod.rs index 516f39f3f..ab52d09a0 100644 --- a/agb/src/display/mod.rs +++ b/agb/src/display/mod.rs @@ -11,10 +11,6 @@ use self::{ window::Windows, }; -/// Graphics mode 3. Bitmap mode that provides a 16-bit colour framebuffer. -pub mod bitmap3; -/// Graphics mode 4. Bitmap 4 provides two 8-bit paletted framebuffers with page switching. -pub mod bitmap4; /// Test logo of agb. pub mod example_logo; pub mod object; @@ -142,15 +138,6 @@ unsafe fn set_graphics_mode(mode: DisplayMode) { DISPLAY_CONTROL.set(s); } -unsafe fn set_graphics_settings(settings: GraphicsSettings) { - let current = DISPLAY_CONTROL.get(); - // preserve display mode - let current = current & 0b111; - let s = settings.bits() | current; - - DISPLAY_CONTROL.set(s); -} - /// Waits until vblank using a busy wait loop, this should almost never be used. /// I only say almost because whilst I don't believe there to be a reason to use /// this I can't rule it out. diff --git a/agb/src/display/video.rs b/agb/src/display/video.rs index 32c6147f2..eb617c13b 100644 --- a/agb/src/display/video.rs +++ b/agb/src/display/video.rs @@ -1,8 +1,4 @@ -use super::{ - bitmap3::Bitmap3, - bitmap4::Bitmap4, - tiled::{Tiled0, Tiled1, Tiled2, VRamManager}, -}; +use super::tiled::{Tiled0, Tiled1, Tiled2, VRamManager}; /// The video struct controls access to the video hardware. /// It ensures that only one video mode is active at a time. @@ -12,16 +8,6 @@ use super::{ 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() } - } - /// Tiled 0 mode provides 4 regular, tiled backgrounds pub fn tiled0(&mut self) -> (Tiled0<'_>, VRamManager) { (unsafe { Tiled0::new() }, VRamManager::new()) diff --git a/agb/src/memory_mapped.rs b/agb/src/memory_mapped.rs index 617dc48df..c0db7b22c 100644 --- a/agb/src/memory_mapped.rs +++ b/agb/src/memory_mapped.rs @@ -79,21 +79,3 @@ impl MemoryMapped1DArray { self.array.cast() } } - -pub struct MemoryMapped2DArray { - array: *mut [[T; X]; Y], -} - -impl MemoryMapped2DArray { - pub const unsafe fn new(address: usize) -> Self { - MemoryMapped2DArray { - array: address as *mut [[T; X]; Y], - } - } - pub fn get(&self, x: usize, y: usize) -> T { - unsafe { (&mut (*self.array)[y][x] as *mut T).read_volatile() } - } - pub fn set(&self, x: usize, y: usize, val: T) { - unsafe { (&mut (*self.array)[y][x] as *mut T).write_volatile(val) } - } -}