Emulator CPU tests

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
Emulator CPU tests
by on (#72745)
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:
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:
Code:
03-op sp,hl

09
Failed


Test 04:
Code:
04-op r,imm

0E 0E
Failed


I'm not sure what the error codes printed from these individual tests mean.

Any clues as to where to start appreciated.

by on (#72747)
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.

by on (#72748)
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.

by on (#72749)
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?

by on (#72750)
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.

by on (#72751)
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.

by on (#72752)
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?

by on (#72753)
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.

by on (#72772)
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:
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.

by on (#72779)
OK, after playing a game of spot the muppet and fixing my ROM banking I'm there:

Code:
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.