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 »

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: 49
Joined: Fri Oct 16, 2015 6:18 am

Re: Gamboy Emulator giving strange output on test rom

Post by gekkio »

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 »

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: 252
Joined: Sat Aug 28, 2010 9:01 am

Re: Gamboy Emulator giving strange output on test rom

Post by nitro2k01 »

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 »

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 »

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 »

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 »

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 »

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