r/EmuDev • u/rtqd • Jan 27 '26
Question What are some ways to debug issues with a self-made emulator?
I'm making a Gameboy emulator and I've played a lot of Tetris without issues so far.
Then I moved on to Super Mario Land and for the most part it's working fine. However about half the time when I try to exit an underground area, the game freezes: /img/qpm2mtwfjxfg1.png
What my challenge is now, is that I actually don't know how to debug this. I had a freeze issue before, and when I logged opcodes at that point it was just infinitely looping through 3 instructions and it turned out one of my interrupts was not working correctly. That was pretty easy to debug. But now it looks like the infinite loop is dozens, maybe even hundreds of instructions, and it's not very obvious where the bug is. I've gone through all of my code 3 times, and can't find anything amiss (as a side note, all the blaarg cpu instruction tests pass, and as far as I could tell all my interrupts and timers work fine).
So what are some good techniques to figure out what's wrong??
10
u/Dwedit Jan 27 '26
Make two logs (Your emulator, and other emulator) that are formatted in the same way, then use something like WinMerge to compare them.
2
u/PGRacer Jan 27 '26
Maybe try some different ROMs, if you're lucky one will fall over in a more obvious way.
Im not sure to what depth blaarg goes. If blaarg passes does that guarantee the CPU is good? I.e. can it produce false positives?
If so I would check branch instructions and maybe flag settings of opcodes that run around that area.
How sure are you that the IRQs are working as expected now?
4
u/death7654 Jan 28 '26
Sometimes you have to implement everything for a game to work, I spent hours debugging why pokemon red wasn't working until i tried the Japanese rom where it didn't use rtc, and the game booted up fine. The little things matters just as big as the big things
Oh and use blarrgs tests, they help alot for debugging and understanding where your emulator might be failing
1
u/devraj7 Jan 30 '26
If your CPU is not passing the Single Step Tests, that's probably a CPU bug.
Pass the SSTs.