robert / gameboy-doctor

Debug and fix your gameboy emulator
https://robertheaton.com/gameboy-doctor/
MIT License
195 stars 27 forks source link

Possible bug in cpu_instrs 11 #13

Closed elmarsan closed 1 year ago

elmarsan commented 1 year ago

Hey!

I'm stuck with cpu_instrs 11. I think I've found a bug in the log files.

After executing 0x34 INC (HL) the value is not incremented. (Ignore flags)

============== ERROR ==============

Mismatch in CPU state at line 2602508:

MINE:   A:00 F:-H-- B:DE C:F4 D:DE E:F5 H:DE L:F6 SP:DFF1 PC:DEF9 PCMEM:00,00,C3,CD
YOURS:  A:00 F:---- B:DE C:F4 D:DE E:F5 H:DE L:F7 SP:DFF1 PC:DEF9 PCMEM:00,00,C3,CD

The CPU state before this (at line 2602507) was:

    A:00 F:---- B:DE C:F4 D:DE E:F5 H:DE L:F6 SP:DFF1 PC:DEF8 PCMEM:34,00,00,C3

The last operation executed (in between lines 2602507 and 2602508) was:

    0x34 INC (HL)

Perhaps the problem is with this opcode, or with your interrupt handling?
Seb-King commented 1 year ago

Hey elmarsan, the issue is in your implementation. Operations with (HL) in their name like INC (HL), DEC (HL), etc. are actually referring to the byte at the memory address HL instead of the value of HL itself.

From the logs you've given the value of HL is $DEF6 so the operation should increment the byte at that address.

The rgbds docs have helped me understand what operations are supposed to do.