Pardon if this is a stupid question...
I've come across a strange thing (I'm using the Z26 emulator, if it makes any difference). At first, I had my VBlank loop look like this:
ldx #37
VBlankLoop
sta WSYNC
dex
bne VBlankLoop
(It's a slighly modified form of what was in one of Andrew Davie's tutorials.) I was using the X register, and needed X to be 0 later on anyway, so I just looped by decrementing from 37 to 0.
But then, I wanted to switch it to use A. So I changed it to this, but this now makes the screen go blank:
lda #37
VBlankLoop
sta WSYNC
adc #$FF; Decrement, by adding the two's complement of 1
bne VBlankLoop
(This was before I remembered there was a subtract instruction )
But then it worked again when I changed it to this:
lda #37
VBlankLoop
sta WSYNC
adc #$FE; Decrement, by adding the one's complement of 1 (aka the two's complement of 2)
bne VBlankLoop
Which seems to tell me one of three things:
1. I've run into a strange bug in either Z26 or the 6502/6507 (doubtful)
2. The 6502 (or at least the 6507 variant) uses one's compliment arithmetic instead of two's complement (which I would find very surprising, since I didn't think one's complement was ever used in something this common)
3. I screwed up something somewhere else (entirely plausable )
But this other variant I made seems to make #1 or #2 more likely than #3:
lda #37
VBlankLoop
sta WSYNC
sbc #1; Decrement, by subtracting 1
bne VBlankLoop
That code does work, unlike adding $FF.
So what do the experts think? Am I nuts for not realizing that the Atari 2600 is a one's complement machine, or have I probably just screwed up something else? (Or is there some other thing going on?)
EDIT: I guess this board doesn't like bold within a code block.