From 5ac408d4142b73bcdeec76505f554a0c8b60b732 Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Thu, 23 Feb 2023 20:42:48 +0000 Subject: [PATCH] Do all the video modes --- agb/src/display/bitmap3.rs | 12 ++++++++---- agb/src/display/bitmap4.rs | 12 +++++++++--- agb/src/display/tiled/tiled0.rs | 12 +++++++----- agb/src/display/tiled/tiled1.rs | 14 ++++++++------ agb/src/display/tiled/tiled2.rs | 12 +++++++----- agb/src/display/video.rs | 10 +++++----- 6 files changed, 44 insertions(+), 28 deletions(-) diff --git a/agb/src/display/bitmap3.rs b/agb/src/display/bitmap3.rs index 01a69e11..2674d47e 100644 --- a/agb/src/display/bitmap3.rs +++ b/agb/src/display/bitmap3.rs @@ -4,19 +4,23 @@ use super::{ set_graphics_mode, set_graphics_settings, DisplayMode, GraphicsSettings, HEIGHT, WIDTH, }; -use core::convert::TryInto; +use core::{convert::TryInto, marker::PhantomData}; const BITMAP_MODE_3: MemoryMapped2DArray = unsafe { MemoryMapped2DArray::new(0x600_0000) }; #[non_exhaustive] -pub struct Bitmap3 {} +pub struct Bitmap3<'gba> { + phantom: PhantomData<&'gba ()>, +} -impl Bitmap3 { +impl Bitmap3<'_> { pub(crate) unsafe fn new() -> Self { set_graphics_mode(DisplayMode::Bitmap3); set_graphics_settings(GraphicsSettings::LAYER_BG2); - Bitmap3 {} + Bitmap3 { + phantom: PhantomData, + } } /// Draws point to screen at (x, y) coordinates with colour and panics if diff --git a/agb/src/display/bitmap4.rs b/agb/src/display/bitmap4.rs index b40eff9c..b225bce1 100644 --- a/agb/src/display/bitmap4.rs +++ b/agb/src/display/bitmap4.rs @@ -1,3 +1,5 @@ +use core::marker::PhantomData; + use crate::memory_mapped::{MemoryMapped1DArray, MemoryMapped2DArray}; use super::{ @@ -25,13 +27,17 @@ pub enum Page { } #[non_exhaustive] -pub struct Bitmap4 {} +pub struct Bitmap4<'gba> { + phantom: PhantomData<&'gba ()>, +} -impl Bitmap4 { +impl Bitmap4<'_> { pub(crate) unsafe fn new() -> Self { set_graphics_mode(DisplayMode::Bitmap4); set_graphics_settings(GraphicsSettings::LAYER_BG2); - Bitmap4 {} + Bitmap4 { + phantom: PhantomData, + } } /// Draws point on specified page at (x, y) coordinates with colour index diff --git a/agb/src/display/tiled/tiled0.rs b/agb/src/display/tiled/tiled0.rs index 66ff0054..a0e0dfa4 100644 --- a/agb/src/display/tiled/tiled0.rs +++ b/agb/src/display/tiled/tiled0.rs @@ -1,4 +1,4 @@ -use core::cell::RefCell; +use core::{cell::RefCell, marker::PhantomData}; use super::{ CreatableRegularTiledMode, MapLoan, RegularBackgroundSize, RegularMap, RegularTiledMode, @@ -9,18 +9,20 @@ use crate::{ display::{set_graphics_mode, DisplayMode, Priority}, }; -pub struct Tiled0 { +pub struct Tiled0<'gba> { regular: RefCell>, screenblocks: RefCell>, + phantom: PhantomData<&'gba ()>, } -impl Tiled0 { +impl Tiled0<'_> { pub(crate) unsafe fn new() -> Self { set_graphics_mode(DisplayMode::Tiled0); Self { regular: Default::default(), screenblocks: Default::default(), + phantom: PhantomData, } } @@ -33,13 +35,13 @@ impl Tiled0 { } } -impl TiledMode for Tiled0 { +impl TiledMode for Tiled0<'_> { fn screenblocks(&self) -> &RefCell> { &self.screenblocks } } -impl CreatableRegularTiledMode for Tiled0 { +impl CreatableRegularTiledMode for Tiled0<'_> { const REGULAR_BACKGROUNDS: usize = 4; fn regular(&self) -> &RefCell> { diff --git a/agb/src/display/tiled/tiled1.rs b/agb/src/display/tiled/tiled1.rs index 6126e46a..b65b6df4 100644 --- a/agb/src/display/tiled/tiled1.rs +++ b/agb/src/display/tiled/tiled1.rs @@ -1,4 +1,4 @@ -use core::cell::RefCell; +use core::{cell::RefCell, marker::PhantomData}; use super::{ AffineBackgroundSize, AffineMap, AffineTiledMode, CreatableAffineTiledMode, @@ -10,13 +10,14 @@ use crate::{ display::{set_graphics_mode, tiled::AFFINE_BG_ID_OFFSET, DisplayMode, Priority}, }; -pub struct Tiled1 { +pub struct Tiled1<'gba> { regular: RefCell>, affine: RefCell>, screenblocks: RefCell>, + phantom: PhantomData<&'gba ()>, } -impl Tiled1 { +impl Tiled1<'_> { pub(crate) unsafe fn new() -> Self { set_graphics_mode(DisplayMode::Tiled1); @@ -29,6 +30,7 @@ impl Tiled1 { regular: Default::default(), affine, screenblocks: Default::default(), + phantom: PhantomData, } } @@ -45,13 +47,13 @@ impl Tiled1 { } } -impl TiledMode for Tiled1 { +impl TiledMode for Tiled1<'_> { fn screenblocks(&self) -> &RefCell> { &self.screenblocks } } -impl CreatableRegularTiledMode for Tiled1 { +impl CreatableRegularTiledMode for Tiled1<'_> { const REGULAR_BACKGROUNDS: usize = 2; fn regular(&self) -> &RefCell> { @@ -59,7 +61,7 @@ impl CreatableRegularTiledMode for Tiled1 { } } -impl CreatableAffineTiledMode for Tiled1 { +impl CreatableAffineTiledMode for Tiled1<'_> { const AFFINE_BACKGROUNDS: usize = 1; fn affine(&self) -> &RefCell> { diff --git a/agb/src/display/tiled/tiled2.rs b/agb/src/display/tiled/tiled2.rs index bcef9f31..c4874ac6 100644 --- a/agb/src/display/tiled/tiled2.rs +++ b/agb/src/display/tiled/tiled2.rs @@ -1,4 +1,4 @@ -use core::cell::RefCell; +use core::{cell::RefCell, marker::PhantomData}; use super::{ AffineBackgroundSize, AffineMap, AffineTiledMode, CreatableAffineTiledMode, MapLoan, TiledMode, @@ -8,12 +8,13 @@ use crate::{ display::{set_graphics_mode, tiled::AFFINE_BG_ID_OFFSET, DisplayMode, Priority}, }; -pub struct Tiled2 { +pub struct Tiled2<'gba> { affine: RefCell>, screenblocks: RefCell>, + phantom: PhantomData<&'gba ()>, } -impl Tiled2 { +impl Tiled2<'_> { pub(crate) unsafe fn new() -> Self { set_graphics_mode(DisplayMode::Tiled2); @@ -25,6 +26,7 @@ impl Tiled2 { Self { affine, screenblocks: Default::default(), + phantom: PhantomData, } } @@ -37,13 +39,13 @@ impl Tiled2 { } } -impl TiledMode for Tiled2 { +impl TiledMode for Tiled2<'_> { fn screenblocks(&self) -> &RefCell> { &self.screenblocks } } -impl CreatableAffineTiledMode for Tiled2 { +impl CreatableAffineTiledMode for Tiled2<'_> { const AFFINE_BACKGROUNDS: usize = 2; fn affine(&self) -> &RefCell> { diff --git a/agb/src/display/video.rs b/agb/src/display/video.rs index d0edf2e1..32c6147f 100644 --- a/agb/src/display/video.rs +++ b/agb/src/display/video.rs @@ -13,27 +13,27 @@ pub struct Video; impl Video { /// Bitmap mode that provides a 16-bit colour framebuffer - pub fn bitmap3(&mut self) -> Bitmap3 { + 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 { + pub fn bitmap4(&mut self) -> Bitmap4<'_> { unsafe { Bitmap4::new() } } /// Tiled 0 mode provides 4 regular, tiled backgrounds - pub fn tiled0(&mut self) -> (Tiled0, VRamManager) { + pub fn tiled0(&mut self) -> (Tiled0<'_>, VRamManager) { (unsafe { Tiled0::new() }, VRamManager::new()) } /// Tiled 1 mode provides 2 regular tiled backgrounds and 1 affine tiled background - pub fn tiled1(&mut self) -> (Tiled1, VRamManager) { + pub fn tiled1(&mut self) -> (Tiled1<'_>, VRamManager) { (unsafe { Tiled1::new() }, VRamManager::new()) } /// Tiled 2 mode provides 2 affine tiled backgrounds - pub fn tiled2(&mut self) -> (Tiled2, VRamManager) { + pub fn tiled2(&mut self) -> (Tiled2<'_>, VRamManager) { (unsafe { Tiled2::new() }, VRamManager::new()) } }