diff --git a/src/consts.rs b/src/consts.rs index 5e2da56977e489b27fbc654a5303fe04cf1bc9c1..7bc34758d5fa1095c7af916a2c32951bbd4e026d 100644 --- a/src/consts.rs +++ b/src/consts.rs @@ -7,6 +7,13 @@ pub const TMA_ADDR: u16 = 0xff06; pub const TAC_ADDR: u16 = 0xff07; pub const IF_ADDR: u16 = 0xff0f; +// PPU registers +pub const LCDC_ADDR: u16 = 0xff40; +pub const STAT_ADDR: u16 = 0xff41; +pub const SCY_ADDR: u16 = 0xff42; +pub const SCX_ADDR: u16 = 0xff43; +pub const LY_ADDR: u16 = 0xff44; + // DMA registers pub const DMA_ADDR: u16 = 0xff46; pub const HDMA1_ADDR: u16 = 0xff51; diff --git a/src/ppu.rs b/src/ppu.rs index f58bd59067f5d6b6d0f942f8559b1f33ecf6478b..a4ab64aac6437bc07311468bb860d93dccb435b0 100644 --- a/src/ppu.rs +++ b/src/ppu.rs @@ -15,6 +15,7 @@ use crate::{ rgb888_to_rgb565_u16, Pixel, PixelAlpha, RGB1555_SIZE, RGB565_SIZE, RGB888_SIZE, RGB_SIZE, XRGB8888_SIZE, }, + consts::{LCDC_ADDR, LY_ADDR, SCX_ADDR, SCY_ADDR, STAT_ADDR}, gb::{GameBoyConfig, GameBoyMode}, mmu::BusComponent, util::SharedThread, @@ -782,7 +783,7 @@ impl Ppu { // Not Usable 0xfea0..=0xfeff => 0xff, 0xff80..=0xfffe => self.hram[(addr & 0x007f) as usize], - 0xff40 => + LCDC_ADDR => { #[allow(clippy::bool_to_int_with_if)] (if self.switch_bg { 0x01 } else { 0x00 } @@ -794,17 +795,18 @@ impl Ppu { | if self.window_map { 0x40 } else { 0x00 } | if self.switch_lcd { 0x80 } else { 0x00 }) } - 0xff41 => { + STAT_ADDR => { (if self.stat_hblank { 0x08 } else { 0x00 } | if self.stat_vblank { 0x10 } else { 0x00 } | if self.stat_oam { 0x20 } else { 0x00 } | if self.stat_lyc { 0x40 } else { 0x00 } | if self.lyc == self.ly { 0x04 } else { 0x00 } - | (self.mode as u8 & 0x03)) + | (self.mode as u8 & 0x03) + | 0x80) } - 0xff42 => self.scy, - 0xff43 => self.scx, - 0xff44 => self.ly, + SCY_ADDR => self.scy, + SCX_ADDR => self.scx, + LY_ADDR => self.ly, 0xff45 => self.lyc, 0xff47 => self.palettes[0], 0xff48 => self.palettes[1], @@ -855,7 +857,7 @@ impl Ppu { // Not Usable 0xfea0..=0xfeff => (), 0xff80..=0xfffe => self.hram[(addr & 0x007f) as usize] = value, - 0xff40 => { + LCDC_ADDR => { self.switch_bg = value & 0x01 == 0x01; self.switch_obj = value & 0x02 == 0x02; self.obj_size = value & 0x04 == 0x04; @@ -879,14 +881,14 @@ impl Ppu { self.clear_frame_buffer(); } } - 0xff41 => { + STAT_ADDR => { self.stat_hblank = value & 0x08 == 0x08; self.stat_vblank = value & 0x10 == 0x10; self.stat_oam = value & 0x20 == 0x20; self.stat_lyc = value & 0x40 == 0x40; } - 0xff42 => self.scy = value, - 0xff43 => self.scx = value, + SCY_ADDR => self.scy = value, + SCX_ADDR => self.scx = value, 0xff45 => self.lyc = value, 0xff47 => { if value == self.palettes[0] { diff --git a/src/test.rs b/src/test.rs index 6d581d1d4955dff98b5f011b346c420ce4729c7c..a47f15d6c4e811cf94424a93b051f2d59c224f22 100644 --- a/src/test.rs +++ b/src/test.rs @@ -74,7 +74,10 @@ pub fn run_image_test( #[cfg(test)] mod tests { - use crate::consts::{DIV_ADDR, IF_ADDR, TAC_ADDR, TIMA_ADDR, TMA_ADDR}; + use crate::consts::{ + DIV_ADDR, IF_ADDR, LCDC_ADDR, LY_ADDR, SCX_ADDR, SCY_ADDR, STAT_ADDR, TAC_ADDR, TIMA_ADDR, + TMA_ADDR, + }; use super::{run_serial_test, run_step_test, TestOptions}; @@ -100,6 +103,12 @@ mod tests { assert_eq!(result.mmu().read(TMA_ADDR), 0x00); assert_eq!(result.mmu().read(TAC_ADDR), 0xf8); assert_eq!(result.mmu().read(IF_ADDR), 0xe1); + + assert_eq!(result.ppu().read(LCDC_ADDR), 0x91); + assert_eq!(result.ppu().read(STAT_ADDR), 0x81); + assert_eq!(result.ppu().read(SCY_ADDR), 0x00); + assert_eq!(result.ppu().read(SCX_ADDR), 0x00); + assert_eq!(result.ppu().read(LY_ADDR), 0x91); } #[test]