mohanson / gameboy

Full featured Cross-platform GameBoy emulator by Rust. Forever boys!.
MIT License
1.35k stars 79 forks source link

SUB A, r8/d8 command to set flag C #34

Open hcoderLee opened 2 years ago

hcoderLee commented 2 years ago

According to the GBCPUmanC - Set if no borrow. In my opinion, the code should be:

self.reg.set_flag(Flag::C, a >= n);

when the value of register A is greater then the number n, a-n is not borrowed. But in the project, the code is:

self.reg.set_flag(C, u16::from(a) < u16::from(n));

Which I couldn't understand.

mohanson commented 2 years ago

The substract in i8080/z80 is 'unintuitive' behaviour, See https://retrocomputing.stackexchange.com/questions/12558/the-behavior-of-the-auxiliary-carry-flag-in-subtraction-on-intel-8080