I have been modifying my game engine to use 16 bits for Y coordinates even though I am constraining my game to be horizontal side scrolling. This is so I can allow the character to jump beyond the top of the screen, and to allow for bottomless pits and proper meta sprite clipping.
In doing so, I encountered some subtle bugs involving the carry bit. I had a few places in my code where I would have a couple of adc's or sbc's right in a row next to each other:
adc something
adc something
etc.
This is fine for 8 bits, but once you enter the 16 bit realm, you may accumulate a +1 in that second adc that you didn't want. So, you have to do the adds in steps, clear the carry, or in my case I was adding several constants together so I just allowed the assembler to add them for me and turned it into a single adc.
I had known to clear the carry before most adds in my code for a while---however I guess I overlooked the "accumulation" factor that could occur if you use multiple adc's or sbc's.
In doing so, I encountered some subtle bugs involving the carry bit. I had a few places in my code where I would have a couple of adc's or sbc's right in a row next to each other:
adc something
adc something
etc.
This is fine for 8 bits, but once you enter the 16 bit realm, you may accumulate a +1 in that second adc that you didn't want. So, you have to do the adds in steps, clear the carry, or in my case I was adding several constants together so I just allowed the assembler to add them for me and turned it into a single adc.
I had known to clear the carry before most adds in my code for a while---however I guess I overlooked the "accumulation" factor that could occur if you use multiple adc's or sbc's.