From f8d40b1029298932b07314db245fab23a24648e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Magalh=C3=A3es?= <joamag@gmail.com> Date: Thu, 10 Nov 2022 22:57:02 +0000 Subject: [PATCH] feat new ppu regfisters --- examples/web/index.ts | 5 +++-- .../react/components/registers-gb/registers-gb.tsx | 6 +++--- src/gb.rs | 7 ++++++- src/ppu.rs | 12 ++++++++++++ 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/examples/web/index.ts b/examples/web/index.ts index 75de6736..f8f1cb19 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 11843d27..804494df 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 1680c971..ad846604 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 df6b83ac..e10f8913 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; -- GitLab