Gamboy Emulator giving strange output on test rom

Discussion of programming and development for the original Game Boy and Game Boy Color.
Post Reply
TheCodez
Posts: 6
Joined: Sat Apr 02, 2016 11:06 am
Location: Germany

Gamboy Emulator giving strange output on test rom

Post by TheCodez » Sat Apr 02, 2016 4:42 pm

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: Select all

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

gekkio
Posts: 48
Joined: Fri Oct 16, 2015 6:18 am

Re: Gamboy Emulator giving strange output on test rom

Post by gekkio » Sun Apr 03, 2016 1:33 pm

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.

TheCodez
Posts: 6
Joined: Sat Apr 02, 2016 11:06 am
Location: Germany

Re: Gamboy Emulator giving strange output on test rom

Post by TheCodez » Sun Apr 03, 2016 2:28 pm

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: Select all

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

Code: Select all

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

nitro2k01
Posts: 228
Joined: Sat Aug 28, 2010 9:01 am

Re: Gamboy Emulator giving strange output on test rom

Post by nitro2k01 » Sun Apr 03, 2016 2:37 pm

Could you please provide a compiled binary for Windows, for testing?

TheCodez
Posts: 6
Joined: Sat Apr 02, 2016 11:06 am
Location: Germany

Re: Gamboy Emulator giving strange output on test rom

Post by TheCodez » Sun Apr 03, 2016 3:09 pm

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

TheCodez
Posts: 6
Joined: Sat Apr 02, 2016 11:06 am
Location: Germany

Re: Gamboy Emulator giving strange output on test rom

Post by TheCodez » Wed Apr 06, 2016 2:13 pm

Found the bug in my generated code, the CP n opcode.

Code: Select all

/* 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.

TheCodez
Posts: 6
Joined: Sat Apr 02, 2016 11:06 am
Location: Germany

Re: Gamboy Emulator giving strange output on test rom

Post by TheCodez » Mon Apr 11, 2016 10:51 am

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: Select all

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?

DParrott
Posts: 25
Joined: Thu Jul 29, 2010 4:39 am

Re: Gamboy Emulator giving strange output on test rom

Post by DParrott » Tue Apr 12, 2016 4:58 am

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.

TheCodez
Posts: 6
Joined: Sat Apr 02, 2016 11:06 am
Location: Germany

Re: Gamboy Emulator giving strange output on test rom

Post by TheCodez » Tue Apr 12, 2016 1:08 pm

That's what i meant, too. Some flags wrong in other opcodes, which are causing wrong program flow.

Post Reply