SparkyNZ wrote: ↑Wed Oct 04, 2023 8:32 pm
Code: Select all
lda SRC_PTR_LO ; Starts off at $22 in my case
clc
adc PIXEL_ROW_COUNT ; This is $60 (96) in my case, result becomes $82 (bit 7 and overflow are set after execution)
Overflow is set in this case because you're adding two positive numbers, but the sign has apparently changed to negative. Basically, a single signed byte isn't long enough to hold a number that big. Since you don't care about signed arithmetic when dealing with 16-bit pointers, you don't care about the overflow flag.
I see that the overflow bit gets set whenever bit 7 of A register is set (because +127 is exceeded).
No, when an instruction sets bit 7, the
Negative flag is set, which is tested with BMI (set) and BPL (clear). One useful application of the Negative flag in counters is when you want to include the zeroth index in your operation:
Code: Select all
ldy #8
@@ lda src,y
sta dest,y
dey
bpl @@
When you use Negative in a counter in this way, your starting index needs to be $80 or less, otherwise your loop ends prematurely. This takes advantage of the fact that lots of things affect Negative, while comparatively few things affect Carry. Fewer things still affect Overflow, only ADC and SBC*.
* This is a lie. There are other things that affect it, obviously CLV. Also PLP. Also--for a totally different reason--BIT. But it's basically true that Overflow is set because of signed arithmetic.