diff --git a/examples/web/index.ts b/examples/web/index.ts index 75de6736cc0d727da11779a0d06ea922d77b5890..f8f1cb19f1d8e70c1bc2767ed98e40a5afc30ee1 100644 --- a/examples/web/index.ts +++ b/examples/web/index.ts @@ -539,7 +539,6 @@ class GameboyEmulator extends EmulatorBase implements Emulator { }; } - // @todo move this out of here get registers(): Record<string, string | number> { const registers = this.gameBoy?.registers(); if (!registers) return {}; @@ -552,7 +551,9 @@ class GameboyEmulator extends EmulatorBase implements Emulator { d: registers.d, e: registers.e, h: registers.h, - l: registers.l + l: registers.l, + ly: registers.ly, + lyc: registers.lyc }; } } diff --git a/examples/web/react/components/registers-gb/registers-gb.tsx b/examples/web/react/components/registers-gb/registers-gb.tsx index 11843d27156ec1989ae585810b1c1a6cf1e0a8d6..804494dfb2d57bc972f688b03f12952bca6751a9 100644 --- a/examples/web/react/components/registers-gb/registers-gb.tsx +++ b/examples/web/react/components/registers-gb/registers-gb.tsx @@ -10,7 +10,7 @@ type RegistersGBProps = { export const RegistersGB: FC<RegistersGBProps> = ({ getRegisters, - interval = 100, + interval = 50, style = [] }) => { const classes = () => ["registers-gb", ...style].join(" "); @@ -65,8 +65,8 @@ export const RegistersGB: FC<RegistersGBProps> = ({ </div> <div className="section"> <h4>PPU</h4> - {renderRegister("LY", registers.l as number)} - {renderRegister("LYC", registers.l as number)} + {renderRegister("LY", registers.ly as number)} + {renderRegister("LYC", registers.lyc as number)} </div> </div> ); diff --git a/src/gb.rs b/src/gb.rs index 1680c971a6a465a5840665115fc518a20720dea8..ad846604b772569ecff0dab736d1c9fa9f9a34ed 100644 --- a/src/gb.rs +++ b/src/gb.rs @@ -34,6 +34,8 @@ pub struct Registers { pub e: u8, pub h: u8, pub l: u8, + pub ly: u8, + pub lyc: u8, } #[cfg_attr(feature = "wasm", wasm_bindgen)] @@ -127,6 +129,7 @@ impl GameBoy { } pub fn registers(&mut self) -> Registers { + let ppu_registers = self.ppu().registers(); Registers { pc: self.cpu.pc, sp: self.cpu.sp, @@ -136,7 +139,9 @@ impl GameBoy { d: self.cpu.d, e: self.cpu.e, h: self.cpu.h, - l: self.cpu.l + l: self.cpu.l, + ly: ppu_registers.ly, + lyc: ppu_registers.lyc, } } diff --git a/src/ppu.rs b/src/ppu.rs index df6b83acedf529b7428bfa5b86db1005bfd39d60..e10f891398e5bf0c76071278ab8180a47e29e3a0 100644 --- a/src/ppu.rs +++ b/src/ppu.rs @@ -122,6 +122,11 @@ impl Display for ObjectData { } } +pub struct PpuRegisters { + pub ly: u8, + pub lyc: u8, +} + /// Represents the Game Boy PPU (Pixel Processing Unit) and controls /// all of the logic behind the graphics processing and presentation. /// Should store both the VRAM and HRAM together with the internal @@ -673,6 +678,13 @@ impl Ppu { } } + pub fn registers(&self) -> PpuRegisters { + PpuRegisters { + ly: self.ly, + lyc: self.lyc, + } + } + fn render_line(&mut self) { if self.first_frame { return;