Skip to content
Snippets Groups Projects
Verified Commit 55bffbd9 authored by João Magalhães's avatar João Magalhães :rocket:
Browse files

chore: initial PPU registers testing

parent 87023326
No related branches found
No related tags found
No related merge requests found
Pipeline #4456 failed
......@@ -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;
......
......@@ -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] {
......
......@@ -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]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment