Debug Window & PPU class rewirte#100
Merged
Merged
Conversation
Owner
Author
There was a problem hiding this comment.
Pull request overview
This PR refactors the emulator core to route ROM/RAM and interrupt/timer behavior through new Cartridge and InterruptController components, while expanding the PPU into a debug/feature UI that supports runtime controls and savestates.
Changes:
- Introduces
InterruptControllerand rewires CPU/PPU/Timer/MMU interrupt signaling through it. - Adds
Cartridgeand updatesMMUto delegate ROM/RAM banking and expose basic runtime stats + memory dump/load for savestates. - Implements a new PPU debug window (breakpoints, opcode trace, virtual gamepad, savestate load/save) and adds helper scripts/files for debugging workflows.
Reviewed changes
Copilot reviewed 17 out of 19 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| utility_scripts/run_debug.sh | Adds a helper script to launch the emulator with --debug. |
| utility_scripts/make_cb_opcode_skeleton.sh | Adds a generator script for CB-prefixed opcode declarations/stubs. |
| utility_scripts/clean_savestates.sh | Adds a helper script for clearing savestate .bin files. |
| utility_scripts/breakpoints.txt | Adds a breakpoint list file consumed by the debug UI. |
| tests/CMakeLists.txt | Links SFML targets to the test binary. |
| src/main.cpp | Adds CLI flags (--debug, --fullscreen) and wires up Cartridge/IC/Timer/PPU/MMU construction + debug loop. |
| src/core/timer.cpp | Refactors Timer to request interrupts via InterruptController and adds reset(). |
| src/core/ppu.cpp | Major PPU rewrite: interrupt requests via IC + debug window/UI + breakpoints + opcode trace + savestates. |
| src/core/memory/mmu.cpp | Refactors MMU to delegate to Cartridge/PPU/Timer/IC; adds bus stats, reset, and dump/load for savestates. |
| src/core/cpu/ProcessingUnit.cpp | Masks pending interrupts to lower 5 bits. |
| src/core/cartridge.cpp | Adds Cartridge implementation with basic MBC handling and RAM support. |
| include/timer.hpp | Updates Timer API to use InterruptController and adds reset/serialization helpers. |
| include/ppu.hpp | Expands PPU API for debug window/controls/savestates; stores pointers to CPU/MMU. |
| include/mmu.hpp | Refactors MMU interface to use Cartridge/PPU/Timer/IC and adds stats + serialization. |
| include/interrupt_controller.hpp | Adds new InterruptController abstraction for IF/IE and interrupt requests. |
| include/common.hpp | Moves JoypadState to a common header. |
| include/cartridge.hpp | Updates ROM header title field and introduces Cartridge class interface/state. |
| CMakeLists.txt | Adjusts SFML discovery to use the config package and components. |
| .gitignore | Ignores the savestates/ directory. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+13
to
+24
| # Get ROM files | ||
| ROM_FILES=("$PROJECT_ROOT"/roms/*) | ||
|
|
||
| # Check if any ROM exists | ||
| if [ ${#ROM_FILES[@]} -gt 0 ]; then | ||
| FIRST_ROM="${ROM_FILES[0]}" | ||
| echo "Launching: $FIRST_ROM --debug" | ||
|
|
||
| "$BUILD_DIR"/bin/gb_emu "$FIRST_ROM" --debug | ||
| else | ||
| echo "No ROM files found in $PROJECT_ROOT/roms" | ||
| fi |
Comment on lines
9
to
13
| @@ -10,12 +12,6 @@ | |||
| #include <iterator> | |||
| #include <SFML/Graphics.hpp> | |||
Comment on lines
1
to
+9
| #include "../../include/ppu.hpp" | ||
| #include "../../include/mmu.hpp" | ||
| #include "../../include/cartridge.hpp" | ||
| #include <filesystem> | ||
| #include <sstream> | ||
| #include <iomanip> | ||
| #include <fstream> | ||
| #include <iostream> | ||
| #include <algorithm> |
Comment on lines
+691
to
+697
| u32 size{}; | ||
| in.read(reinterpret_cast<char*>(&size), sizeof(size)); | ||
| std::vector<u8> dump(size); | ||
| in.read(reinterpret_cast<char*>(dump.data()), size); | ||
| mmu->load_memory(dump); | ||
|
|
||
| return true; |
Comment on lines
+212
to
+214
| std::vector<u8> MMU::dump_memory() const { | ||
| std::vector<u8> dump(0x10000, 0); | ||
|
|
Comment on lines
+239
to
+243
| dump[0x04] = ic->get_if(); | ||
| dump[0x05] = ic->get_ie(); | ||
|
|
||
| return dump; | ||
| } |
Comment on lines
+66
to
+72
| current_rom_bank = 1; | ||
| current_ram_bank = 0; | ||
| ram_enabled = false; | ||
| banking_mode = 0; | ||
| rom_bank_low = 1; | ||
| rom_bank_high = 0; | ||
| return true; |
Comment on lines
+124
to
+130
| } else if (mbc_type == MBCType::MBC5) { | ||
| if (address <= 0x2FFF) { | ||
| rom_bank_low = value; | ||
| } else { | ||
| rom_bank_high = value & 0x01; | ||
| } | ||
| current_rom_bank = (rom_bank_high << 8) | rom_bank_low; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.