I know my code is still unreadeable. I've tried to clean it up for posting and this is the best I can do.
during v-blank
Code:
rep #$10
sep #$20
lda $0700
bne frame_0
lda #$80
sta $2115
ldx #$3000
stx $2116
ldx #$1801
stx $4300
ldx #$0000
stx $4302
lda #$7f
sta $4304
ldx #$1000
stx $4305
lda #$01
sta $420b
lda #$60
sta $2101
frame_0:
lda $0700
cmp #$01
bne frame_1
lda #$80
sta $2115
ldx #$3800
stx $2116
ldx #$1801
stx $4300
ldx #$0000
stx $4302
lda #$7f
sta $4304
ldx #$1000
stx $4305
lda #$01
sta $420b
lda #$70
sta $2101
frame_1:
lda $0700
cmp #$02
bne frame_2
lda #$80
sta $2115
ldx #$1000
stx $2116
ldx #$1801
stx $4300
ldx #$0000
stx $4302
lda #$7f
sta $4304
ldx #$1000
stx $4305
lda #$01
sta $420b
lda #$70
sta $2101
frame_2:
lda $0700
cmp #$03
bne frame_3
lda #$80
sta $2115
ldx #$1800
stx $2116
ldx #$1801
stx $4300
ldx #$0000
stx $4302
lda #$7f
sta $4304
ldx #$1000
stx $4305
lda #$01
sta $420b
lda #$60
sta $2101
frame_3:
during active display
Code:
macro process_row_sprites(a,b,c)
%process_sprite(0+<a>,0+<b>,0+<c>)
%process_sprite(8+<a>,4+<b>,2+<c>)
%process_sprite(16+<a>,8+<b>,4+<c>)
%process_sprite(24+<a>,12+<b>,6+<c>)
%process_sprite(32+<a>,16+<b>,8+<c>)
%process_sprite(40+<a>,20+<b>,10+<c>)
%process_sprite(48+<a>,24+<b>,12+<c>)
%process_sprite(56+<a>,28+<b>,14+<c>)
endmacro
macro process_row_sprites2(a,b)
%process_sprite2(0+<a>,0+<b>)
%process_sprite2(8+<a>,4+<b>)
%process_sprite2(16+<a>,8+<b>)
%process_sprite2(24+<a>,12+<b>)
%process_sprite2(32+<a>,16+<b>)
%process_sprite2(40+<a>,20+<b>)
%process_sprite2(48+<a>,24+<b>)
%process_sprite2(56+<a>,28+<b>)
endmacro
macro move_row_sprite_patterns(a,b)
%move_16x16_sprite_pattern(0+<a>,0+<b>)
%move_16x16_sprite_pattern(8+<a>,64+<b>)
%move_16x16_sprite_pattern(16+<a>,128+<b>)
%move_16x16_sprite_pattern(24+<a>,192+<b>)
%move_16x16_sprite_pattern(32+<a>,256+<b>)
%move_16x16_sprite_pattern(40+<a>,320+<b>)
%move_16x16_sprite_pattern(48+<a>,384+<b>)
%move_16x16_sprite_pattern(56+<a>,448+<b>)
endmacro
macro process_sprite(a,c,d)
lda $7f8000+<a>
sta $7f8400+<c>
lda $7f8002+<a>
cmp #$0100
bmi ?off_screen
lda #$0000
?off_screen:
!sub #$0020
sta $7f8401+<c>
lda $7f8006+<a>
and #$fe00
ora #$0000+<d>
sta $7f8402+<c>
endmacro
macro process_sprite2(a,c)
lda $7f8000+<a>
sta $7f8400+<c>
lda $7f8002+<a>
cmp #$0100
bmi ?off_screen
lda #$0000
?off_screen:
!sub #$0020
sta $7f8401+<c>
lda $7f8006+<a>
sta $7f8402+<c>
endmacro
macro move_16x16_sprite_pattern(a,b)
lda $7e0042
bne ?over
jmp last_sprite
?over:
dec
sta $7e0042
lda $7f8005+<a>
pha
plb
plb
lda $7f8004+<a>
tay
ldx #$0000+<b>
jsr move_sprite_pattern
endmacro
macro move_sprite_pattern(a)
lda $0000+<a>,y
sta $7f0000+<a>,x
lda $0002+<a>,y
sta $7f0002+<a>,x
lda $0004+<a>,y
sta $7f0004+<a>,x
lda $0006+<a>,y
sta $7f0006+<a>,x
lda $0008+<a>,y
sta $7f0008+<a>,x
lda $000a+<a>,y
sta $7f000a+<a>,x
lda $000c+<a>,y
sta $7f000c+<a>,x
lda $000e+<a>,y
sta $7f000e+<a>,x
lda $0010+<a>,y
sta $7f0010+<a>,x
lda $0012+<a>,y
sta $7f0012+<a>,x
lda $0014+<a>,y
sta $7f0014+<a>,x
lda $0016+<a>,y
sta $7f0016+<a>,x
lda $0018+<a>,y
sta $7f0018+<a>,x
lda $001a+<a>,y
sta $7f001a+<a>,x
lda $001c+<a>,y
sta $7f001c+<a>,x
lda $001e+<a>,y
sta $7f001e+<a>,x
endmacro
rep #$30
lda $0700 ;;counts to 4 and loops
inc
and #$0003
sta $0700
%process_row_sprites(0,0,256)
%process_row_sprites(64,32,288)
%process_row_sprites(128,64,320)
%process_row_sprites(192,96,352)
%process_row_sprites(256,128,384)
%process_row_sprites(320,160,416)
%process_row_sprites(384,192,448)
%process_row_sprites(448,224,480)
%process_row_sprites2(512,256)
%process_row_sprites2(576,288)
%process_row_sprites2(640,320)
%process_row_sprites2(704,352)
%process_row_sprites2(768,384)
%process_row_sprites2(832,416)
%process_row_sprites2(896,448)
%process_row_sprites2(960,480)
sep #$20 ;;this part does last 32 bytes of oam
lda $7f8019
asl
asl
ora $7f8011
asl
asl
ora $7f8009
asl
asl
ora $7f8001
sta $7f8600
lda $7f8039
asl
asl
ora $7f8031
asl
asl
ora $7f8029
asl
asl
ora $7f8021
sta $7f8601
lda $7f8059
asl
asl
ora $7f8051
asl
asl
ora $7f8049
asl
asl
ora $7f8041
sta $7f8602
lda $7f8079
asl
asl
ora $7f8071
asl
asl
ora $7f8069
asl
asl
ora $7f8061
sta $7f8603
lda $7f8099
asl
asl
ora $7f8091
asl
asl
ora $7f8089
asl
asl
ora $7f8081
sta $7f8604
lda $7f80b9
asl
asl
ora $7f80b1
asl
asl
ora $7f80a9
asl
asl
ora $7f80a1
sta $7f8605
lda $7f80d9
asl
asl
ora $7f80d1
asl
asl
ora $7f80c9
asl
asl
ora $7f80c1
sta $7f8606
lda $7f80f9
asl
asl
ora $7f80f1
asl
asl
ora $7f80e9
asl
asl
ora $7f80e1
sta $7f8607
lda $7f8119
asl
asl
ora $7f8111
asl
asl
ora $7f8109
asl
asl
ora $7f8101
sta $7f8608
lda $7f8139
asl
asl
ora $7f8131
asl
asl
ora $7f8129
asl
asl
ora $7f8121
sta $7f8609
lda $7f8159
asl
asl
ora $7f8151
asl
asl
ora $7f8149
asl
asl
ora $7f8141
sta $7f860a
lda $7f8179
asl
asl
ora $7f8171
asl
asl
ora $7f8169
asl
asl
ora $7f8161
sta $7f860b
lda $7f8199
asl
asl
ora $7f8191
asl
asl
ora $7f8189
asl
asl
ora $7f8181
sta $7f860c
lda $7f81b9
asl
asl
ora $7f81b1
asl
asl
ora $7f81a9
asl
asl
ora $7f81a1
sta $7f860d
lda $7f81d9
asl
asl
ora $7f81d1
asl
asl
ora $7f81c9
asl
asl
ora $7f81c1
sta $7f860e
lda $7f81f9
asl
asl
ora $7f81f1
asl
asl
ora $7f81e9
asl
asl
ora $7f81e1
sta $7f860f
lda $7f8219
asl
asl
ora $7f8211
asl
asl
ora $7f8209
asl
asl
ora $7f8201
sta $7f8610
lda $7f8239
asl
asl
ora $7f8231
asl
asl
ora $7f8229
asl
asl
ora $7f8221
sta $7f8611
lda $7f8259
asl
asl
ora $7f8251
asl
asl
ora $7f8249
asl
asl
ora $7f8241
sta $7f8612
lda $7f8279
asl
asl
ora $7f8271
asl
asl
ora $7f8269
asl
asl
ora $7f8261
sta $7f8613
lda $7f8299
asl
asl
ora $7f8291
asl
asl
ora $7f8289
asl
asl
ora $7f8281
sta $7f8614
lda $7f82b9
asl
asl
ora $7f82b1
asl
asl
ora $7f82a9
asl
asl
ora $7f82a1
sta $7f8615
lda $7f82d9
asl
asl
ora $7f82d1
asl
asl
ora $7f82c9
asl
asl
ora $7f82c1
sta $7f8616
lda $7f82f9
asl
asl
ora $7f82f1
asl
asl
ora $7f82e9
asl
asl
ora $7f82e1
sta $7f8617
lda $7f8319
asl
asl
ora $7f8311
asl
asl
ora $7f8309
asl
asl
ora $7f8301
sta $7f8618
lda $7f8339
asl
asl
ora $7f8331
asl
asl
ora $7f8329
asl
asl
ora $7f8321
sta $7f8619
lda $7f8359
asl
asl
ora $7f8351
asl
asl
ora $7f8349
asl
asl
ora $7f8341
sta $7f861a
lda $7f8379
asl
asl
ora $7f8371
asl
asl
ora $7f8369
asl
asl
ora $7f8361
sta $7f861b
lda $7f8399
asl
asl
ora $7f8391
asl
asl
ora $7f8389
asl
asl
ora $7f8381
sta $7f861c
lda $7f83b9
asl
asl
ora $7f83b1
asl
asl
ora $7f83a9
asl
asl
ora $7f83a1
sta $7f861d
lda $7f83d9
asl
asl
ora $7f83d1
asl
asl
ora $7f83c9
asl
asl
ora $7f83c1
sta $7f861e
lda $7f83f9
asl
asl
ora $7f83f1
asl
asl
ora $7f83e9
asl
asl
ora $7f83e1
sta $7f861f
rep #$30
ldx $0040 ;;$0040 is sprite oam counter
I_love_bratwurst:
lda #$0000
sta $7f8802,x
txa
!add #$0008
tax
cpx #$0400
bmi I_love_bratwurst
lda #$7f00
pha
plb
plb
lda #$0000
sta $7e0044
sta $7e0046
tax
sprite_organizer: ;;this part of code separates
txa ;;dynamic sprites from
cmp $7e0040 ;;standard sprites
beq sprite_organizer_done
cpx #$0400
beq sprite_organizer_done
lda $8804,x
beq standard_sprite
lda $7e0044
cmp #$0200
bpl dynamic_sprite
tay
lda $8800,x ;;$7f8800 is sprite table
sta $8000,y ;;$7f8000 is dynamic sprite table
lda $8802,x
sta $8002,y
lda $8804,x
sta $8004,y
lda $8806,x
sta $8006,y
tya
!add #$0008
sta $7e0044
bra dynamic_sprite
standard_sprite:
lda $7e0046
cmp #$0200
bpl dynamic_sprite
tay
lda $8800,x
sta $8200,y ;;$7f8200 is standard sprite table
lda $8802,x
sta $8202,y
lda $8804,x
sta $8204,y
lda $8806,x
sta $8206,y
tya
!add #$0008
sta $7e0046
dynamic_sprite:
txa
!add #$0008
tax
bra sprite_organizer
sprite_organizer_done:
lda #$8000
pha
plb
plb
lda $0044
tax
clear_oam:
lda #$0000
sta $7f8002,x
txa
!add #$0008
tax
cpx #$0200
bmi clear_oam
lda $0046
tax
clear_oam_again:
lda #$0000
sta $7f8202,x
txa
!add #$0008
tax
cpx #$0200
bmi clear_oam_again
lda $0700
and #$0001
beq im_an_idiot
jmp odd_frame
im_an_idiot:
lda $0044
lsr #3
sta $0042
%move_row_sprite_patterns(0,0)
%move_row_sprite_patterns(64,1024)
%move_row_sprite_patterns(128,2048)
%move_row_sprite_patterns(192,3072)
jmp last_sprite
odd_frame:
lda $0044
lsr #3
!sub #$0020
sta $0042
bpl more_than_32_sprites
jmp last_sprite
more_than_32_sprites:
%move_row_sprite_patterns(256,4096)
%move_row_sprite_patterns(320,5120)
%move_row_sprite_patterns(384,6144)
%move_row_sprite_patterns(448,7168)
last_sprite:
lda #$8000
pha
plb
plb
jmp jump_over_this
move_sprite_pattern:
%move_sprite_pattern(0)
%move_sprite_pattern(32)
%move_sprite_pattern(512)
%move_sprite_pattern(544)
rts
jump_over_this: