feat: stub 0xff40 and 0xff47

This commit is contained in:
2021-01-17 19:25:53 -06:00
parent 92218a227d
commit 70de3b9142
2 changed files with 81 additions and 3 deletions

View File

@@ -1,20 +1,27 @@
#[derive(Debug, Clone)]
pub struct PPU {
lcdc: LCDControl,
pub lcd_control: LCDControl,
pub monochrome: Monochrome,
pub vram: Box<[u8]>,
}
impl Default for PPU {
fn default() -> Self {
Self {
lcdc: Default::default(),
lcd_control: Default::default(),
monochrome: Default::default(),
vram: vec![0; 8192].into_boxed_slice(),
}
}
}
#[derive(Debug, Clone, Copy, Default)]
pub struct Monochrome {
pub bg_palette: BackgroundPalette,
}
#[derive(Debug, Default, Clone, Copy)]
struct LCDControl {
pub struct LCDControl {
lcd_enable: bool, // Bit 7
window_tile_map_select: bool,
window_enable: bool,
@@ -52,3 +59,70 @@ impl From<LCDControl> for u8 {
| lcdc.display_priority as u8
}
}
#[derive(Debug, Clone, Copy)]
enum GrayShade {
White,
LightGray,
DarkGray,
Black,
}
impl Default for GrayShade {
fn default() -> Self {
Self::White
}
}
impl From<u8> for GrayShade {
fn from(byte: u8) -> Self {
match byte {
0b00 => GrayShade::White,
0b01 => GrayShade::LightGray,
0b10 => GrayShade::DarkGray,
0b11 => GrayShade::Black,
_ => unreachable!("{:#04X} is not a valid Shade of Gray", byte),
}
}
}
impl From<GrayShade> for u8 {
fn from(shade: GrayShade) -> Self {
match shade {
GrayShade::White => 0b00,
GrayShade::LightGray => 0b01,
GrayShade::DarkGray => 0b10,
GrayShade::Black => 0b11,
}
}
}
#[derive(Debug, Clone, Copy, Default)]
pub struct BackgroundPalette {
color3: GrayShade,
color2: GrayShade,
color1: GrayShade,
color0: GrayShade,
}
impl From<u8> for BackgroundPalette {
fn from(byte: u8) -> Self {
Self {
color3: (byte >> 6).into(),
color2: ((byte >> 4) & 0x03).into(),
color1: ((byte >> 2) & 0x03).into(),
color0: (byte & 0x03).into(),
}
}
}
impl From<BackgroundPalette> for u8 {
fn from(palette: BackgroundPalette) -> Self {
let color0: u8 = palette.color0.into();
let color1: u8 = palette.color1.into();
let color2: u8 = palette.color2.into();
let color3: u8 = palette.color0.into();
color3 << 6 | color2 << 4 | color1 << 2 | color0
}
}