mirror of
https://github.com/italicsjenga/gba.git
synced 2024-12-23 19:01:30 +11:00
More tiled data types
This commit is contained in:
parent
c440be7467
commit
0f1fa8269f
|
@ -2,40 +2,102 @@
|
|||
|
||||
use super::*;
|
||||
|
||||
/// An 8x8 tile with 4bpp
|
||||
// Note(Lokathor): We've got several newtypes here that don't use the `newtype!`
|
||||
// macro because it's insufficient at parsing array types being wrapped.
|
||||
|
||||
newtype! {
|
||||
/// An 8x8 tile with 4bpp, packed as `u32` values for proper alignment.
|
||||
#[derive(Debug, Clone, Copy, Default)]
|
||||
#[repr(transparent)]
|
||||
pub struct Tile4bpp {
|
||||
pub data: [u32; 8],
|
||||
Tile4bpp, pub [u32; 8], no frills
|
||||
}
|
||||
|
||||
/// An 8x8 tile with 8bpp
|
||||
newtype! {
|
||||
/// An 8x8 tile with 8bpp, packed as `u32` values for proper alignment.
|
||||
#[derive(Debug, Clone, Copy, Default)]
|
||||
#[repr(transparent)]
|
||||
pub struct Tile8bpp {
|
||||
pub data: [u32; 16],
|
||||
Tile8bpp, pub [u32; 16], no frills
|
||||
}
|
||||
|
||||
/// A charblock of 4bpp tiles
|
||||
newtype! {
|
||||
/// A 4bpp charblock has 512 tiles in it
|
||||
#[derive(Clone, Copy)]
|
||||
#[repr(transparent)]
|
||||
pub struct Charblock4bpp {
|
||||
pub data: [Tile4bpp; 512],
|
||||
Charblock4bpp, pub [Tile4bpp; 512], no frills
|
||||
}
|
||||
|
||||
/// A charblock of 8bpp tiles
|
||||
newtype! {
|
||||
/// An 8bpp charblock has 256 tiles in it
|
||||
#[derive(Clone, Copy)]
|
||||
#[repr(transparent)]
|
||||
pub struct Charblock8bpp {
|
||||
pub data: [Tile8bpp; 256],
|
||||
Charblock8bpp, pub [Tile4bpp; 256], no frills
|
||||
}
|
||||
|
||||
newtype! {
|
||||
/// A screenblock entry for use in Text mode.
|
||||
#[derive(Debug, Clone, Copy, Default)]
|
||||
#[repr(transparent)]
|
||||
pub struct TextScreenblockEntry(u16);
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
#[repr(transparent)]
|
||||
pub struct TextScreenblock {
|
||||
pub data: [TextScreenblockEntry; 32 * 32],
|
||||
TextScreenblockEntry, u16
|
||||
}
|
||||
impl TextScreenblockEntry {
|
||||
pub const fn from_tile_index(index: u16) -> Self {
|
||||
TextScreenblockEntry(index & Self::TILE_INDEX_MASK)
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
pub const TILE_INDEX_MASK: u16 = 0xA - 1;
|
||||
pub const fn tile_index(self) -> u16 {
|
||||
self.0 & Self::TILE_INDEX_MASK
|
||||
}
|
||||
pub const fn with_tile_index(self, index: u16) -> Self {
|
||||
TextScreenblockEntry((self.0 & !Self::TILE_INDEX_MASK) | (index & Self::TILE_INDEX_MASK))
|
||||
}
|
||||
|
||||
register_bit!(HFLIP_BIT, u16, 1 << 0xA, hflip);
|
||||
register_bit!(VFLIP_BIT, u16, 1 << 0xB, vflip);
|
||||
|
||||
pub const PALBANK_MASK: u16 = 0b1111 << 0xC;
|
||||
pub const fn palbank(self) -> u16 {
|
||||
(self.0 & Self::TILE_INDEX_MASK) >> 0xC
|
||||
}
|
||||
pub const fn with_palbank(self, palbank: u16) -> Self {
|
||||
TextScreenblockEntry((self.0 & !Self::PALBANK_MASK) | (palbank << 0xC))
|
||||
}
|
||||
}
|
||||
|
||||
newtype! {
|
||||
/// A screenblock for use in Text mode.
|
||||
#[derive(Clone, Copy)]
|
||||
TextScreenblock, [TextScreenblockEntry; 32 * 32], no frills
|
||||
}
|
||||
|
||||
newtype! {
|
||||
/// A screenblock entry for use in Affine mode.
|
||||
#[derive(Debug, Clone, Copy, Default)]
|
||||
AffineScreenblockEntry, u8
|
||||
}
|
||||
|
||||
newtype! {
|
||||
/// A screenblock for use in Affine mode.
|
||||
#[derive(Clone, Copy)]
|
||||
AffineScreenblock_16x16, [AffineScreenblockEntry; 16*16], no frills
|
||||
}
|
||||
|
||||
newtype! {
|
||||
/// A screenblock for use in Affine mode.
|
||||
#[derive(Clone, Copy)]
|
||||
AffineScreenblock_32x32, [AffineScreenblockEntry; 32*32], no frills
|
||||
}
|
||||
|
||||
newtype! {
|
||||
/// A screenblock for use in Affine mode.
|
||||
#[derive(Clone, Copy)]
|
||||
AffineScreenblock_64x64, [AffineScreenblockEntry; 64*64], no frills
|
||||
}
|
||||
|
||||
newtype! {
|
||||
/// A screenblock for use in Affine mode.
|
||||
#[derive(Clone, Copy)]
|
||||
AffineScreenblock_128x128, [AffineScreenblockEntry; 128*128], no frills
|
||||
}
|
||||
|
||||
pub const VRAM_CHARBLOCKS: VolAddressBlock<Charblock4bpp> = unsafe { VolAddressBlock::new_unchecked(VolAddress::new_unchecked(VRAM_BASE_USIZE), 6) };
|
||||
|
||||
pub const VRAM_TEXT_SCREENBLOCKS: VolAddressBlock<TextScreenblock> =
|
||||
unsafe { VolAddressBlock::new_unchecked(VolAddress::new_unchecked(VRAM_BASE_USIZE), 32) };
|
||||
|
|
Loading…
Reference in a new issue