Last active
October 28, 2018 23:19
-
-
Save nurpax/f53cf7e3fc7e993824796ab1aced0cc8 to your computer and use it in GitHub Desktop.
sprite array clear loop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Note: optimized to rely on dst ptr to be 64-byte aligned (as sprites are) | |
clear_writer_sprite_row: { | |
+mov16($30, zp_sprite_dst) | |
ldx #num_writer_sprites | |
sprite_loop: | |
lda $31 | |
sta dstp0-1 | |
sta dstp1-1 | |
sta dstp2-1 | |
sta dstp3-1 | |
clc | |
lda $30 ; these 4 adds are ok without ADC'ing | |
sta dstp0-2 ; the upper byte, since the input is 64-byte | |
adc #$10 ; aligned | |
sta dstp1-2 | |
adc #$10 | |
sta dstp2-2 | |
adc #$10 | |
sta dstp3-2 | |
adc #$10 | |
sta $30 | |
lda $31 | |
adc #0 | |
sta $31 | |
lda #0 | |
ldy #15 | |
clear_loop: | |
sta $1110, y | |
dstp0: | |
sta $1111, y | |
dstp1: | |
sta $1112, y | |
dstp2: | |
sta $1113, y | |
dstp3: | |
dey | |
bpl clear_loop | |
dex | |
bne sprite_loop | |
rts | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
clear_writer_sprite_row: { | |
+mov16($30, zp_sprite_dst) | |
ldx #0 | |
sprite_loop: | |
ldy #0 | |
lda #0 | |
clear_loop: | |
sta ($30), y | |
iny | |
sta ($30), y | |
iny | |
sta ($30), y | |
iny | |
cpy #21*3 | |
bne clear_loop | |
+add16_imm8($30, 64) | |
inx | |
cpx #num_writer_sprites | |
bne sprite_loop | |
rts | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Unoptimized is (7*3+2+3)*21-1 (e.g., 545) cycles per sprite.
Optimized is 335 cycles (innerloop) + 59 (for setup). So about 394 cycles per sprite.
These count the cost of clearing a single sprite, there's a few extra additional cycles to loop over all the sprites.