Gamboy Emulator giving strange output on test rom

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
Gamboy Emulator giving strange output on test rom
by on (#167502)
Hello,

I've just started writing my own gb emulator. After finishing implementing all opcodes, I wanted to see if it's actually working by running Blargg's cpu_instr rom. As I have no working lcd emulation atm I'm printing the output by reading from the SB port. Now running the rom I got some strange output, I can't get to fix.

Code:
cpu_instrs

C8


Does anybody know, what the C8 stand for. Is it a wrong opcode? Or is it reading some wrong value, because of wrong PC?

Any help would be kindly appreciated!

PS: You can check out the code at: https://github.com/TheCodez/RetroGB
Re: Gamboy Emulator giving strange output on test rom
by on (#167584)
Maybe that means opcode C8 (= RET Z) is not correct?
Try running the individual test ROMs (e.g. 01-special.gb), which might give better error messages.
Re: Gamboy Emulator giving strange output on test rom
by on (#167591)
Thanks for the suggestion, I double checked the RET Z opcode and it seems correct. Also I tried running the individual tests and they give me no output at all.

Code:
/* RET Z */
void Processor::RET_Z() // 0xC8
{
   if (IsFlagSet(FLAG_ZERO))
   {
      condition = true;
      StackPop(PC);
   }
}


Code:
void Processor::StackPop(uint16& reg)
{
    reg = memory->ReadWord(SP);
    SP += 2;
}


any other ideas?
Re: Gamboy Emulator giving strange output on test rom
by on (#167595)
Could you please provide a compiled binary for Windows, for testing?
Re: Gamboy Emulator giving strange output on test rom
by on (#167600)
I'll do, I just add passing the rom name from the commandline, so you can test.

[EDIT] Don't have time anymore today. Could you build it from my Github repository and change the rom name inside main.cpp
Re: Gamboy Emulator giving strange output on test rom
by on (#167790)
Found the bug in my generated code, the CP n opcode.

Code:
/* CP n */
void Processor::CP_n() // 0xFE
{
   SetFlag(FLAG_SUB);
   if (A < memory->ReadByte(PC++)) EnableFlag(FLAG_CARRY);
   if (A == memory->ReadByte(PC++)) EnableFlag(FLAG_ZERO);
   if (((A - memory->ReadByte(PC++)) & 0xF) > (A & 0xF)) EnableFlag(FLAG_HALFCARRY);
}


I was incrementing PC on every check :oops:. Atleast it's running now, but it's running to many tests, and none passes.
Re: Gamboy Emulator giving strange output on test rom
by on (#168073)
If all tests fail to execute successful, altough they are most likely correct, that means some flags are wrong?

Running test 06-ld r,r outputs this:
Code:
06-ld r,r

40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F 50 51 52 53 54 55 56 57 58 59 5A
 5B 5C 5D 5E 5F 60 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F 70 71 72 73 74 7
5 77 78 79 7A 7B 7C 7D 7E 7F
Failed


Those listed are all ld opcodes, and most of them if not all should be correct. Any ideas?
Re: Gamboy Emulator giving strange output on test rom
by on (#168173)
The LD r,r' instructions do not set any flags.

I can only assume that these are being reported as failures due to a problem with some of the other instructions that the test code is using to verify the result.
Re: Gamboy Emulator giving strange output on test rom
by on (#168217)
That's what i meant, too. Some flags wrong in other opcodes, which are causing wrong program flow.