Skip to content

Commit

Permalink
chore: add WX and WY register to const
Browse files Browse the repository at this point in the history
Making it possible to indirectly access the registers via constants.
  • Loading branch information
joamag committed Jul 6, 2024
1 parent 105f654 commit 8d2d32b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 10 additions & 5 deletions src/ppu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 8d2d32b

Please sign in to comment.