I don't think anybody has updated wiki.superfamicom.org in a while, and so I had an idea. Since animation is something that pulls people's hair out, I decided to take the most important part of my animation engine (the part that calculates where in VRAM to place sprite cells) and modify it to be used as example code for wiki.superfamicom.org.
Before I post it on wiki.superfamicom.org, can anybody find anything else I can simplify for beginners (other than adding notes), or find any mistakes?
Before I post it on wiki.superfamicom.org, can anybody find anything else I can simplify for beginners (other than adding notes), or find any mistakes?
Code:
find_32x32_slot:
sep #$20
ldx #$0000
lda {vram_slot_table},x
beq +
-;
inx
lda {vram_slot_table},x
bne -
+;
cpx #$0020
bne +
rep #$20
lda #$0200
rts
+;
lda #$0f
sta {vram_slot_table},x
rep #$20
lda large_slot_vram_location,x
and #$00ff
asl
rts
find_16x16_slot:
ldy #$0000
tyx
lda #$0f0f
cmp {vram_slot_table},x
bne +
-;
inx #2
cmp {vram_slot_table},x
beq -
+;
lda {vram_slot_table},x
sep #$20
cmp #$0f
bne +
inx
xba
+;
cpx #$0020
bne +
rep #$20
lda #$0200
rts
+;
tay
ora vram_slot_table_bit_set,y
sta {vram_slot_table},x
rep #$20
lda large_slot_vram_location,x
ora small_slot_vram_location,y
and #$00ff
asl
rts
large_slot_vram_location:
db $00
db $02
db $04
db $06
db $20
db $22
db $24
db $26
db $40
db $42
db $44
db $46
db $60
db $62
db $64
db $66
db $80
db $82
db $84
db $86
db $a0
db $a2
db $a4
db $a6
db $c0
db $c2
db $c4
db $c6
db $e0
db $e2
db $e4
db $e6
small_slot_vram_location:
db $00
db $01
db $00
db $10
db $00
db $01
db $00
db $11
db $00
db $01
db $00
db $10
db $00
db $01
db $00
vram_slot_table_bit_set:
db $01
db $02
db $01
db $04
db $01
db $02
db $01
db $08
db $01
db $02
db $01
db $04
db $01
db $02
db $01
sep #$20
ldx #$0000
lda {vram_slot_table},x
beq +
-;
inx
lda {vram_slot_table},x
bne -
+;
cpx #$0020
bne +
rep #$20
lda #$0200
rts
+;
lda #$0f
sta {vram_slot_table},x
rep #$20
lda large_slot_vram_location,x
and #$00ff
asl
rts
find_16x16_slot:
ldy #$0000
tyx
lda #$0f0f
cmp {vram_slot_table},x
bne +
-;
inx #2
cmp {vram_slot_table},x
beq -
+;
lda {vram_slot_table},x
sep #$20
cmp #$0f
bne +
inx
xba
+;
cpx #$0020
bne +
rep #$20
lda #$0200
rts
+;
tay
ora vram_slot_table_bit_set,y
sta {vram_slot_table},x
rep #$20
lda large_slot_vram_location,x
ora small_slot_vram_location,y
and #$00ff
asl
rts
large_slot_vram_location:
db $00
db $02
db $04
db $06
db $20
db $22
db $24
db $26
db $40
db $42
db $44
db $46
db $60
db $62
db $64
db $66
db $80
db $82
db $84
db $86
db $a0
db $a2
db $a4
db $a6
db $c0
db $c2
db $c4
db $c6
db $e0
db $e2
db $e4
db $e6
small_slot_vram_location:
db $00
db $01
db $00
db $10
db $00
db $01
db $00
db $11
db $00
db $01
db $00
db $10
db $00
db $01
db $00
vram_slot_table_bit_set:
db $01
db $02
db $01
db $04
db $01
db $02
db $01
db $08
db $01
db $02
db $01
db $04
db $01
db $02
db $01