Wrong HalfCarry check on add16-instruction
MartinJohns opened this issue · 2 comments
Hey, I'm working on an GB emulator in F#.
While studying (or peeking ;)) your implementation I noticed a bug in this line:
https://github.com/Gekkio/mooneye-gb/blob/master/src/cpu/mod.rs#L902
According to the most known Game Boy CPU Manual, as well as the official GB programming manual the half-carry flag is set when there's a carry from bit 11. This would mean a check for 0x0FFF
, and not 0x07FF
(bit 10).
A test case from the official developer manual (page 97):
When HL = 0x8A23
ADD HL, HL ; HL <- 0x1446, H <- 1, N <- 0, CY <- 1
Wow, nice catch! Indeed looks like there's an off-by-one error in the bit I chose. Carry from bit 10 (0x07FF) passes all my tests and blargg's cpu_instr tests, but it is clearly wrong and fails the second example in the official manual. I guess I trusted cpu_instr a bit too much to reveal these kind of errors.
Thanks! Feel free to study more code ;) And try some of my test ROMs once you've got the basic stuff in place in your emulator.
I have to ask out of curiosity: are you planning to release the source code of your F#-based emulator at some point? I'd love to see an implementation in an ML-family language. I actually started this project with OCaml, but soon got really interested in Rust and changed the language.
Yes, I'm planning to release it as open source once it's ready. But I do this also to learn F#, so I wouldn't expect the best F# code there can be. :-) I'll let you know once it happens (don't expect it soon).
Looking at your code makes me interested in Rust. It will probably be the next language on my list.