Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gameboy emulator testing strategies?

I'm writing a gameboy emulator, and am struggling with making sure opcodes are emulated correctly. Certain operations set flag registers, and it can be hard to track whether the flag is set correctly, and where.

I want to write some sort of testing framework, but thought it'd be worth asking here for some help. Currently I see a few options:

Unit test each and every opcode with several test cases. Issues are there are 256 8 bit opcodes and 50+ (can't remember exact number) 16 bit opcodes. This would take a long time to do properly.

Write some sort of logging framework that logs a stacktrace at each operation and compares it to other established emulators. This would be pretty quick to do, and allows a fairly rapid overview of what exactly went wrong. The log file would look a bit like this:

...
PC = 212 Just executed opcode 7c - Register: AF: 5 30 BC: 0 13 HL: 5 ce DE: 1 cd SP: ffad
PC = 213 Just executed opcode 12 - Register: AF: 5 30 BC: 0 13 HL: 5 ce DE: 1 cd SP: ffad
...

Cons are I need to modify the source of another emulator to output the same form. And there's no guarantee the opcode is correct as it assumes the other emulator is.

What else should I consider?

Here is my code if it helps: https://github.com/dbousamra/scalagb

like image 217
Dominic Bou-Samra Avatar asked Aug 05 '11 08:08

Dominic Bou-Samra


2 Answers

You could use already established test roms. I would recommend Blargg's test roms. You can get them from here: http://gbdev.gg8.se/files/roms/blargg-gb-tests/.

like image 64
nijoakim Avatar answered Nov 06 '22 02:11

nijoakim


To me the best idea is the one you already mentioned:

  • take an existing emulator that is well known and you have the source code. let's call it master emulator
  • take some ROM that you can use to test
  • test these ROMs in the emulator that is known to work well.
  • modify the master emulator so it produces log while it is running for each opcode that it executes.
  • do the same in your own emulator
  • compare the output

I think this one has more advantage:

  • you will have the log file from a good emulator
  • the outcome of the test can be evaluated much faster
  • you can use more than one emulator
  • you can go deeper later like putting memory to the log and see the differences between the two implementations.
like image 34
gyurisc Avatar answered Nov 06 '22 00:11

gyurisc