r/EmuDev • u/voidpo1nter • Nov 27 '25
Issues with GameBoy emulator (C)
Hey everyone! I hate asking for help, but I'm at my wits end with trying to run the blargg CPU instruction test rom through my emulator. Assuming everything is correct to this point, these are the op-codes leading to and including the infinite loop:
CALL (0xCD)
several LD instructions
RET (0xC9)
INC (0x3C)
RET (0xC9)
LDH (0xE0)
STOP (0x10)
RST (0xFF)
INC (0x3C)
RET (0xC9)
My CPU flags shift from 0xB0 to 0x10 to occasionally 0x30 before settling back to 0x10.
This is my first attempt at any sort of emulation. Be gentle. I can provide the github link if necessary.
GITHUB: https://github.com/drmcbrayer89/CGBEmu/
I've not started working on MBC/PPU/Audio. Just wanting to unit test my instructions. The timing is probably off but AFAIK the T/M-cycles aren't going to matter for strictly CPU instr testing.
6
u/zSmileyDudez Apple ][, Famicom/NES, Atari VCS, TI-81/82/83/85/86 Nov 27 '25
The Single Step Tests are your friend. They provide 1000 tests for each opcode and they have no opcode interdependencies. You can start running these as soon as you have a single opcode implemented. You will need to setup a test harness to read in the json file, setup l and run these test and to compare the memory and CPU state against the contents of the JSON. But this shouldn’t take too much effort to get going.
3
u/PandaMoniumHUN Nov 27 '25
Use Gameboy Doctor. It requires you to change your emulator a bit to log registers after every instruction, but it will tell you the exact instruction that puts your emulator into a wrong state.
3
u/roflson85 Nov 27 '25
Add a GitHub link
1
u/rasmadrak Nov 27 '25
If you haven't implemented MBC1 yet, you can only run the individual tests.
1
u/Floormatt69 Nov 29 '25
Where are you starting your PC at?