I am trying to write a MOS 6502 8-bit emulator to better learn about CPUs.
I have implemented my ADC (add with carry) instruction thanks to a lot of help from this question. My output was exactly as the question’s answer’s example output.
The problem is, I’m now not sure if there is a bug in that answer since I thought 255 + 1 would cause both a carry and an overflow (since 255 + 1 = 256, not 0). With the approach taken in the answered question above, I only get a carry, not an overflow.
Which is correct?
No. According to linked answer, overflow flag is set when you would have overflow with signed interpretation of numbers. (unsigned)255 = 0xff = (signed)-1 . And -1 + 1 = 0 has no overflow.