From 660f22955d8292f401893307cd1e88ceb7e52cdc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jo=C3=A3o=20Magalh=C3=A3es?= <joamag@gmail.com>
Date: Thu, 4 Jul 2024 09:24:25 +0100
Subject: [PATCH] chore: new register comparison

---
 src/consts.rs |  1 +
 src/ppu.rs    | 10 ++++++----
 src/test.rs   |  5 +++--
 3 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/src/consts.rs b/src/consts.rs
index 8005c52d..46875497 100644
--- a/src/consts.rs
+++ b/src/consts.rs
@@ -14,6 +14,7 @@ pub const SCY_ADDR: u16 = 0xff42;
 pub const SCX_ADDR: u16 = 0xff43;
 pub const LY_ADDR: u16 = 0xff44;
 pub const LYC_ADDR: u16 = 0xff45;
+pub const BGP_ADDR: u16 = 0xff47;
 
 // DMA registers
 pub const DMA_ADDR: u16 = 0xff46;
diff --git a/src/ppu.rs b/src/ppu.rs
index df9bfb92..74727e48 100644
--- a/src/ppu.rs
+++ b/src/ppu.rs
@@ -15,7 +15,7 @@ use crate::{
         rgb888_to_rgb565_u16, Pixel, PixelAlpha, RGB1555_SIZE, RGB565_SIZE, RGB888_SIZE, RGB_SIZE,
         XRGB8888_SIZE,
     },
-    consts::{LCDC_ADDR, LYC_ADDR, LY_ADDR, SCX_ADDR, SCY_ADDR, STAT_ADDR},
+    consts::{BGP_ADDR, LCDC_ADDR, LYC_ADDR, LY_ADDR, SCX_ADDR, SCY_ADDR, STAT_ADDR},
     gb::{GameBoyConfig, GameBoyMode},
     mmu::BusComponent,
     util::SharedThread,
@@ -807,9 +807,10 @@ impl Ppu {
             SCY_ADDR => self.scy,
             SCX_ADDR => self.scx,
             LY_ADDR => self.ly,
-            // 0xFF45 — LYC: LY compare
+            // 0xFF45 — LYC
             LYC_ADDR => self.lyc,
-            0xff47 => self.palettes[0],
+            // 0xFF47 — BGP: BG palette data (Non-CGB Mode only)
+            BGP_ADDR => self.palettes[0],
             0xff48 => self.palettes[1],
             0xff49 => self.palettes[2],
             0xff4a => self.wy,
@@ -892,7 +893,8 @@ impl Ppu {
             SCX_ADDR => self.scx = value,
             // 0xFF45 — LYC: LY compare
             LYC_ADDR => self.lyc = value,
-            0xff47 => {
+            // 0xFF47 — BGP: BG palette data (Non-CGB Mode only)
+            BGP_ADDR => {
                 if value == self.palettes[0] {
                     return;
                 }
diff --git a/src/test.rs b/src/test.rs
index 136009be..4c064b0c 100644
--- a/src/test.rs
+++ b/src/test.rs
@@ -79,8 +79,8 @@ pub fn run_image_test(
 mod tests {
     use crate::{
         consts::{
-            DIV_ADDR, DMA_ADDR, IF_ADDR, LCDC_ADDR, LYC_ADDR, LY_ADDR, SCX_ADDR, SCY_ADDR,
-            STAT_ADDR, TAC_ADDR, TIMA_ADDR, TMA_ADDR,
+            BGP_ADDR, DIV_ADDR, DMA_ADDR, IF_ADDR, LCDC_ADDR, LYC_ADDR, LY_ADDR, SCX_ADDR,
+            SCY_ADDR, STAT_ADDR, TAC_ADDR, TIMA_ADDR, TMA_ADDR,
         },
         data::BootRom,
     };
@@ -119,6 +119,7 @@ mod tests {
         assert_eq!(result.ppu().read(SCX_ADDR), 0x00);
         assert_eq!(result.ppu().read(LY_ADDR), 0x99);
         assert_eq!(result.ppu().read(LYC_ADDR), 0x00);
+        assert_eq!(result.ppu().read(BGP_ADDR), 0xfc);
 
         assert_eq!(result.ppu().read(DMA_ADDR), 0xff);
     }
-- 
GitLab