gbdev / gb-opcodes

https://gbdev.io/gb-opcodes/optables/
Creative Commons Zero v1.0 Universal
24 stars 10 forks source link

Reflect SBC A Carry behavior in the flags #26

Closed SonoSooS closed 1 year ago

SonoSooS commented 1 year ago

Since other ALU ops with A as both params get "special treatment" in their flags, I thought that it should be made more consistent with the rest.

While technically SBC A does update the Carry flag as well, it gets updated to the same value, and since other instructions reflect the real outcome instead of the designed behavior (I highly doubt there are actual shortcuts in the CPU itself), it's much easier to think of the Carry flag not being updated if it's updated to the same value.

Proof:

SUB A updates Carry to 0 all the time because A - A always results in 0, which does not overflow. However, SBC A is interesting, because regardless of what value the A register holds, the Carry flag being set will eventually decide the real outcome: