Do all the video modes

This commit is contained in:
Gwilym Kuiper 2023-02-23 20:42:48 +00:00
parent ce5641f5ef
commit 5ac408d414
6 changed files with 44 additions and 28 deletions

View file

@ -4,19 +4,23 @@ use super::{
set_graphics_mode, set_graphics_settings, DisplayMode, GraphicsSettings, HEIGHT, WIDTH, 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<u16, { WIDTH as usize }, { HEIGHT as usize }> = const BITMAP_MODE_3: MemoryMapped2DArray<u16, { WIDTH as usize }, { HEIGHT as usize }> =
unsafe { MemoryMapped2DArray::new(0x600_0000) }; unsafe { MemoryMapped2DArray::new(0x600_0000) };
#[non_exhaustive] #[non_exhaustive]
pub struct Bitmap3 {} pub struct Bitmap3<'gba> {
phantom: PhantomData<&'gba ()>,
}
impl Bitmap3 { impl Bitmap3<'_> {
pub(crate) unsafe fn new() -> Self { pub(crate) unsafe fn new() -> Self {
set_graphics_mode(DisplayMode::Bitmap3); set_graphics_mode(DisplayMode::Bitmap3);
set_graphics_settings(GraphicsSettings::LAYER_BG2); set_graphics_settings(GraphicsSettings::LAYER_BG2);
Bitmap3 {} Bitmap3 {
phantom: PhantomData,
}
} }
/// Draws point to screen at (x, y) coordinates with colour and panics if /// Draws point to screen at (x, y) coordinates with colour and panics if

View file

@ -1,3 +1,5 @@
use core::marker::PhantomData;
use crate::memory_mapped::{MemoryMapped1DArray, MemoryMapped2DArray}; use crate::memory_mapped::{MemoryMapped1DArray, MemoryMapped2DArray};
use super::{ use super::{
@ -25,13 +27,17 @@ pub enum Page {
} }
#[non_exhaustive] #[non_exhaustive]
pub struct Bitmap4 {} pub struct Bitmap4<'gba> {
phantom: PhantomData<&'gba ()>,
}
impl Bitmap4 { impl Bitmap4<'_> {
pub(crate) unsafe fn new() -> Self { pub(crate) unsafe fn new() -> Self {
set_graphics_mode(DisplayMode::Bitmap4); set_graphics_mode(DisplayMode::Bitmap4);
set_graphics_settings(GraphicsSettings::LAYER_BG2); set_graphics_settings(GraphicsSettings::LAYER_BG2);
Bitmap4 {} Bitmap4 {
phantom: PhantomData,
}
} }
/// Draws point on specified page at (x, y) coordinates with colour index /// Draws point on specified page at (x, y) coordinates with colour index

View file

@ -1,4 +1,4 @@
use core::cell::RefCell; use core::{cell::RefCell, marker::PhantomData};
use super::{ use super::{
CreatableRegularTiledMode, MapLoan, RegularBackgroundSize, RegularMap, RegularTiledMode, CreatableRegularTiledMode, MapLoan, RegularBackgroundSize, RegularMap, RegularTiledMode,
@ -9,18 +9,20 @@ use crate::{
display::{set_graphics_mode, DisplayMode, Priority}, display::{set_graphics_mode, DisplayMode, Priority},
}; };
pub struct Tiled0 { pub struct Tiled0<'gba> {
regular: RefCell<Bitarray<1>>, regular: RefCell<Bitarray<1>>,
screenblocks: RefCell<Bitarray<1>>, screenblocks: RefCell<Bitarray<1>>,
phantom: PhantomData<&'gba ()>,
} }
impl Tiled0 { impl Tiled0<'_> {
pub(crate) unsafe fn new() -> Self { pub(crate) unsafe fn new() -> Self {
set_graphics_mode(DisplayMode::Tiled0); set_graphics_mode(DisplayMode::Tiled0);
Self { Self {
regular: Default::default(), regular: Default::default(),
screenblocks: 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<Bitarray<1>> { fn screenblocks(&self) -> &RefCell<Bitarray<1>> {
&self.screenblocks &self.screenblocks
} }
} }
impl CreatableRegularTiledMode for Tiled0 { impl CreatableRegularTiledMode for Tiled0<'_> {
const REGULAR_BACKGROUNDS: usize = 4; const REGULAR_BACKGROUNDS: usize = 4;
fn regular(&self) -> &RefCell<Bitarray<1>> { fn regular(&self) -> &RefCell<Bitarray<1>> {

View file

@ -1,4 +1,4 @@
use core::cell::RefCell; use core::{cell::RefCell, marker::PhantomData};
use super::{ use super::{
AffineBackgroundSize, AffineMap, AffineTiledMode, CreatableAffineTiledMode, AffineBackgroundSize, AffineMap, AffineTiledMode, CreatableAffineTiledMode,
@ -10,13 +10,14 @@ use crate::{
display::{set_graphics_mode, tiled::AFFINE_BG_ID_OFFSET, DisplayMode, Priority}, display::{set_graphics_mode, tiled::AFFINE_BG_ID_OFFSET, DisplayMode, Priority},
}; };
pub struct Tiled1 { pub struct Tiled1<'gba> {
regular: RefCell<Bitarray<1>>, regular: RefCell<Bitarray<1>>,
affine: RefCell<Bitarray<1>>, affine: RefCell<Bitarray<1>>,
screenblocks: RefCell<Bitarray<1>>, screenblocks: RefCell<Bitarray<1>>,
phantom: PhantomData<&'gba ()>,
} }
impl Tiled1 { impl Tiled1<'_> {
pub(crate) unsafe fn new() -> Self { pub(crate) unsafe fn new() -> Self {
set_graphics_mode(DisplayMode::Tiled1); set_graphics_mode(DisplayMode::Tiled1);
@ -29,6 +30,7 @@ impl Tiled1 {
regular: Default::default(), regular: Default::default(),
affine, affine,
screenblocks: Default::default(), screenblocks: Default::default(),
phantom: PhantomData,
} }
} }
@ -45,13 +47,13 @@ impl Tiled1 {
} }
} }
impl TiledMode for Tiled1 { impl TiledMode for Tiled1<'_> {
fn screenblocks(&self) -> &RefCell<Bitarray<1>> { fn screenblocks(&self) -> &RefCell<Bitarray<1>> {
&self.screenblocks &self.screenblocks
} }
} }
impl CreatableRegularTiledMode for Tiled1 { impl CreatableRegularTiledMode for Tiled1<'_> {
const REGULAR_BACKGROUNDS: usize = 2; const REGULAR_BACKGROUNDS: usize = 2;
fn regular(&self) -> &RefCell<Bitarray<1>> { fn regular(&self) -> &RefCell<Bitarray<1>> {
@ -59,7 +61,7 @@ impl CreatableRegularTiledMode for Tiled1 {
} }
} }
impl CreatableAffineTiledMode for Tiled1 { impl CreatableAffineTiledMode for Tiled1<'_> {
const AFFINE_BACKGROUNDS: usize = 1; const AFFINE_BACKGROUNDS: usize = 1;
fn affine(&self) -> &RefCell<Bitarray<1>> { fn affine(&self) -> &RefCell<Bitarray<1>> {

View file

@ -1,4 +1,4 @@
use core::cell::RefCell; use core::{cell::RefCell, marker::PhantomData};
use super::{ use super::{
AffineBackgroundSize, AffineMap, AffineTiledMode, CreatableAffineTiledMode, MapLoan, TiledMode, AffineBackgroundSize, AffineMap, AffineTiledMode, CreatableAffineTiledMode, MapLoan, TiledMode,
@ -8,12 +8,13 @@ use crate::{
display::{set_graphics_mode, tiled::AFFINE_BG_ID_OFFSET, DisplayMode, Priority}, display::{set_graphics_mode, tiled::AFFINE_BG_ID_OFFSET, DisplayMode, Priority},
}; };
pub struct Tiled2 { pub struct Tiled2<'gba> {
affine: RefCell<Bitarray<1>>, affine: RefCell<Bitarray<1>>,
screenblocks: RefCell<Bitarray<1>>, screenblocks: RefCell<Bitarray<1>>,
phantom: PhantomData<&'gba ()>,
} }
impl Tiled2 { impl Tiled2<'_> {
pub(crate) unsafe fn new() -> Self { pub(crate) unsafe fn new() -> Self {
set_graphics_mode(DisplayMode::Tiled2); set_graphics_mode(DisplayMode::Tiled2);
@ -25,6 +26,7 @@ impl Tiled2 {
Self { Self {
affine, affine,
screenblocks: Default::default(), screenblocks: Default::default(),
phantom: PhantomData,
} }
} }
@ -37,13 +39,13 @@ impl Tiled2 {
} }
} }
impl TiledMode for Tiled2 { impl TiledMode for Tiled2<'_> {
fn screenblocks(&self) -> &RefCell<Bitarray<1>> { fn screenblocks(&self) -> &RefCell<Bitarray<1>> {
&self.screenblocks &self.screenblocks
} }
} }
impl CreatableAffineTiledMode for Tiled2 { impl CreatableAffineTiledMode for Tiled2<'_> {
const AFFINE_BACKGROUNDS: usize = 2; const AFFINE_BACKGROUNDS: usize = 2;
fn affine(&self) -> &RefCell<Bitarray<1>> { fn affine(&self) -> &RefCell<Bitarray<1>> {

View file

@ -13,27 +13,27 @@ pub struct Video;
impl Video { impl Video {
/// Bitmap mode that provides a 16-bit colour framebuffer /// Bitmap mode that provides a 16-bit colour framebuffer
pub fn bitmap3(&mut self) -> Bitmap3 { pub fn bitmap3(&mut self) -> Bitmap3<'_> {
unsafe { Bitmap3::new() } unsafe { Bitmap3::new() }
} }
/// Bitmap 4 provides two 8-bit paletted framebuffers with page switching /// 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() } unsafe { Bitmap4::new() }
} }
/// Tiled 0 mode provides 4 regular, tiled backgrounds /// 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()) (unsafe { Tiled0::new() }, VRamManager::new())
} }
/// Tiled 1 mode provides 2 regular tiled backgrounds and 1 affine tiled background /// 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()) (unsafe { Tiled1::new() }, VRamManager::new())
} }
/// Tiled 2 mode provides 2 affine tiled backgrounds /// 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()) (unsafe { Tiled2::new() }, VRamManager::new())
} }
} }