To add 8bit $FF as a signed number to a 16bit number, I need to create a high byte of $FF.
To add 8bit $00 as a signed number to a 16bit number, I need to create a high byte of $00.
So instead of
Code: Select all
lda (reserved4),y;X Position
clc
adc tempLo
sta OAM+3,x
lda tempHi
adc #$00
bne spriteOffscreen
Code: Select all
lda (reserved4),y;X Position
clc
bpl positivehighbyte;If the number is positive, 0 is needed to make the result correct
;If the number is negative, FF is needed to make the result correct.
adc tempLo
sta OAM+3,x
lda tempHi
adc #$FF
bne spriteOffscreen
beq nextsprite
positivehighbyte:
adc tempLo
sta OAM+3,x
lda tempHi
adc #$00
bne spriteOffscreen
nextsprite:
Edit:
Not always. Imagine a sprite partially offscreen on the left. The leftmost sprites will be offscreen and have a high byte of $FF, the rightmost sprites will be onscreen with a high byte of $00.But wouldn't it suffice to assume that while on-screen, the high byte is 0?
Edit2: Like this:
Edit3: To express that slightly better, the main position of the metasprite can have a high byte of $FF and still be partially on screen. But yes, each individual sprite that is on screen will have a high byte of $00.
Another optimization is verifying the all sprites in the metasprite will on onscreen using the maxoffsets I mentioned before drawing, and then your sprite draw code is just this:
Code: Select all
lda (reserved4),y;X Position
clc
adc tempLo
sta OAM+3,x