Page 1 of 1
Emulator CPU tests
Posted: Sat Jan 15, 2011 5:30 am
by DParrott
I've recently started my own GB emulator and I'm currently trying to nail down the CPU.
I'm using Blaarg's cpu instructions test from this thread and I've got some that come back as passed but others that are failing, I'm not sure how to interpret the output of the failed tests to try and see where I'm going wrong.
The multi test craps out on test 4:
Code: Select all
cpu_instrs
01:ok 02:ok 03:01 04:01
Failed 2 tests.
It's test 3 and 4 I'm not sure where to start with, the output from them is:
Test 03:
Test 04:
I'm not sure what the error codes printed from these individual tests mean.
Any clues as to where to start appreciated.
Posted: Sat Jan 15, 2011 6:51 am
by Dwedit
Is it the flags register (F) output of what those instructions do? I think the hl,sp instructions did unexpected things to compute the flags. Maybe read the source code to Gambatte's CPU core, and see what it does.
Posted: Sat Jan 15, 2011 7:36 am
by DParrott
Do you mean that the 09 and 0E 0E have something to do with the flags?
I've been through my instructions and compared to the gb programming reference I have and I think the instructions are doing as they should and setting/resetting the right flags.
I was hoping the number output would help me try and identify which instruction the test says is failing.
Posted: Sat Jan 15, 2011 9:19 am
by DParrott
Ok, I fixed test 3 and got that passing now.
I wasn't calculating the H flag correctly in my 16 bit add. 09 was in fact ADD HL, BC.
I don't understand the error for test 4 though as 0E is LD C,n and I can't see any problems with that, it's just doing what all the other immediate loads are doing.
Anyone know what the 0E 0E from test 4 means.
The other question is that when I run the test in other emulators it goes through more tests but I only have it run the 4 then fail. Is it because the other tests rely on something that the first 4 test so bail out at the point?
Posted: Sat Jan 15, 2011 9:32 am
by mic_
Well are you sure 0E is the opcode? It might be something else, like an index into the table of values that it's testing the instructions with.
Posted: Sat Jan 15, 2011 9:39 am
by DParrott
mic_ wrote:Well are you sure 0E is the opcode? It might be something else, like an index into the table of values that it's testing the instructions with.
No
That's where I'm unsure, don't know if it's the opcode or an index into the table etc.
Posted: Sat Jan 15, 2011 10:55 am
by DParrott
I think I have narrowed it down to my SBC opcode and the H flag.
What should be happening to the H flag during SBC?
Posted: Sat Jan 15, 2011 11:08 am
by mic_
IIRC, it should be set for SBC if the low 4 bits of the second operand (including the carry) are greater than the low 4 bits of the first operand.
Posted: Sun Jan 16, 2011 4:36 am
by DParrott
mic_ wrote:IIRC, it should be set for SBC if the low 4 bits of the second operand (including the carry) are greater than the low 4 bits of the first operand.
Thanks.
After fixing that and some of my shifts and rotates I now get the following:
Code: Select all
cpu_instrs
01:ok 02:ok 03:ok 04:ok
Passed all tests
Not sure why I'm only getting 4 tests run though. If I run the test on another emulator I see it run 11 tests. Would it be dependent on some features I'm missing? I've run all these tests so far before doing any LCD emulation, the output I'm getting from the serial IO.
Posted: Sun Jan 16, 2011 10:10 am
by DParrott
OK, after playing a game of spot the muppet and fixing my ROM banking I'm there:
Code: Select all
cpu_instrs
01:ok 02:ok 03:ok 04:ok 05:ok 06:ok 07:ok 08:ok 09:ok 10:ok 11:ok
Passed all tests
Now onto the next bits.