From 8d2d32b5fee994fdce37476995d8c29430980a6c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jo=C3=A3o=20Magalh=C3=A3es?= <joamag@gmail.com>
Date: Sat, 6 Jul 2024 11:06:20 +0100
Subject: [PATCH] chore: add WX and WY register to const

Making it possible to indirectly access the registers via constants.
---
 src/consts.rs |  2 ++
 src/ppu.rs    | 15 ++++++++++-----
 src/test.rs   |  5 ++++-
 3 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/src/consts.rs b/src/consts.rs
index 7a719e99..9de8f30b 100644
--- a/src/consts.rs
+++ b/src/consts.rs
@@ -17,6 +17,8 @@ pub const LYC_ADDR: u16 = 0xff45;
 pub const BGP_ADDR: u16 = 0xff47;
 pub const OBP0_ADDR: u16 = 0xff48;
 pub const OBP1_ADDR: u16 = 0xff49;
+pub const WX_ADDR: u16 = 0xff4a;
+pub const WY_ADDR: u16 = 0xff4b;
 
 // DMA registers
 pub const DMA_ADDR: u16 = 0xff46;
diff --git a/src/ppu.rs b/src/ppu.rs
index 9f673410..a69bd019 100644
--- a/src/ppu.rs
+++ b/src/ppu.rs
@@ -16,7 +16,8 @@ use crate::{
         XRGB8888_SIZE,
     },
     consts::{
-        BGP_ADDR, LCDC_ADDR, LYC_ADDR, LY_ADDR, OBP0_ADDR, OBP1_ADDR, SCX_ADDR, SCY_ADDR, STAT_ADDR,
+        BGP_ADDR, LCDC_ADDR, LYC_ADDR, LY_ADDR, OBP0_ADDR, OBP1_ADDR, SCX_ADDR, SCY_ADDR,
+        STAT_ADDR, WX_ADDR, WY_ADDR,
     },
     gb::{GameBoyConfig, GameBoyMode},
     mmu::BusComponent,
@@ -817,8 +818,10 @@ impl Ppu {
             OBP0_ADDR => self.palettes[1],
             // 0xFF49 — OBP1 (Non-CGB Mode only)
             OBP1_ADDR => self.palettes[2],
-            0xff4a => self.wy,
-            0xff4b => self.wx,
+            // 0xFF4A — WX
+            WX_ADDR => self.wy,
+            // 0xFF4B — WY
+            WY_ADDR => self.wx,
             // 0xFF4F — VBK (CGB only)
             0xff4f => self.vram_bank | 0xfe,
             // 0xFF68 — BCPS/BGPI (CGB only)
@@ -941,8 +944,10 @@ impl Ppu {
                 }
                 self.palettes[2] = value;
             }
-            0xff4a => self.wy = value,
-            0xff4b => self.wx = value,
+            // 0xFF4A — WX
+            WX_ADDR => self.wy = value,
+            // 0xFF4B — WY
+            WY_ADDR => self.wx = value,
             // 0xFF4F — VBK (CGB only)
             0xff4f => {
                 self.vram_bank = value & 0x01;
diff --git a/src/test.rs b/src/test.rs
index 3837f1fd..b308ac5c 100644
--- a/src/test.rs
+++ b/src/test.rs
@@ -80,7 +80,8 @@ mod tests {
     use crate::{
         consts::{
             BGP_ADDR, DIV_ADDR, DMA_ADDR, IF_ADDR, LCDC_ADDR, LYC_ADDR, LY_ADDR, OBP0_ADDR,
-            OBP1_ADDR, SCX_ADDR, SCY_ADDR, STAT_ADDR, TAC_ADDR, TIMA_ADDR, TMA_ADDR,
+            OBP1_ADDR, SCX_ADDR, SCY_ADDR, STAT_ADDR, TAC_ADDR, TIMA_ADDR, TMA_ADDR, WX_ADDR,
+            WY_ADDR,
         },
         data::BootRom,
     };
@@ -122,6 +123,8 @@ mod tests {
         assert_eq!(result.ppu().read(BGP_ADDR), 0xfc);
         assert_eq!(result.ppu().read(OBP0_ADDR), 0x00);
         assert_eq!(result.ppu().read(OBP1_ADDR), 0x00);
+        assert_eq!(result.ppu().read(WX_ADDR), 0x00);
+        assert_eq!(result.ppu().read(WY_ADDR), 0x00);
 
         assert_eq!(result.ppu().read(DMA_ADDR), 0xff);
     }
-- 
GitLab