Code:
animation:
lda {graphics_address_request}
cmp {graphics_address}
bne +
lda {metasprite_request}
cmp {metasprite}
beq no_metasprite_pattern
+;
lda #$0000
ldy {metasprite_request}
beq no_animation_slot
lda $0008,y
beq no_animation_slot
sep #$20
lda $000a,y
sta $4202
lda $000c,y
sta $4203
nop #3
rep #$20
lda $4216
+;
sta {vram_size}
clc
adc {total_dma_legnth}
cmp #$0060
bcc yes_metasprite_pattern
lda {first_object_to_dma}
bne +
tdc
sta {first_object_to_dma}
+;
no_metasprite_pattern:
rts
yes_metasprite_pattern:
jsr clear_vram_slot
ldy {metasprite_request}
lda $000a,y
asl #5
sta {vram_width}
lda $000c,y
sta {vram_height}
bra dynamic_animation
no_animation_slot:
jsr clear_vram_slot
ldy {metasprite_request}
sty {metasprite}
tdc
tax
-;
lda $000e,y
sta {metasprite_table},x
beq +
lda $0010,y
sta {metasprite_table}+24,x
lda $0012,y
sta {metasprite_table}+48,x
lda $0014,y
sta {metasprite_table}+72,x
inx #2
tya
clc
adc #$0008
tay
bra -
+;
rts
dynamic_animation:
lda {graphics_address_request}
sta {graphics_address}
lda {metasprite_request}
sta {metasprite}
tay
lda $0006,y
clc
adc {graphics_address}
sta {temp3}
lda $0008,y
sta {temp2}
tdc
tax
-;
lda $000e,y
sta {metasprite_table},x
beq +
lda $0010,y
sta {metasprite_table}+24,x
lda $0012,y
sta {metasprite_table}+48,x
lda $0014,y
sta {metasprite_table}+96,x
jsr find_vram_slot
inx #2
tya
clc
adc #$0008
tay
bra -
+;
lda {vram_size}
clc
adc {total_dma_legnth}
sta {total_dma_legnth}
jmp no_metasprite_pattern
find_vram_slot:
phx
lda {metasprite_table},x
cmp #$0002
bne +
jmp large_slot
+;
phy
ldy #$0000
sep #$20
ldx #$0000
lda {vram_slot_table},x
cmp #$0f
bne +
-;
inx
lda {vram_slot_table},x
cmp #$0f
beq -
+;
-;
lsr
bcc +
iny
bra -
+;
cpx #$0020
bne +
ply
rep #$20
plx
dex #2
rts
+;
lda slot_to_name3,y
ora {vram_slot_table},x
sta {vram_slot_table},x
rep #$20
lda slot_to_name,x
ora slot_to_name2,y
and #$00ff
asl
sta {temp}
ply
plx
lda $0014,y
and #$fe00
ora {temp}
sta {metasprite_table}+72,x
phy
ldy {dma_updates}
lda #$0002
sta {dma_rows},y
lda #$0040
sta {dma_legnth},y
lda {vram_width}
sta {dma_increment},y
lda {metasprite_table}+96,x
and #$01ff
asl #5
clc
adc {temp3}
sta {dma_address},y
lda {temp2}
sta {dma_bank},y
lda {metasprite_table}+72,x
and #$01ff
asl #4
sta {dma_destination},y
iny #2
lda #$0000
sta {dma_legnth},y
sty {dma_updates}
ply
rts
large_slot:
sep #$20
ldx #$0000
lda {vram_slot_table},x
beq +
-;
inx
lda {vram_slot_table},x
bne -
+;
cpx #$0020
bne +
rep #$20
plx
dex #2
rts
+;
lda #$0f
sta {vram_slot_table},x
rep #$20
lda slot_to_name,x
and #$00ff
asl
sta {temp}
plx
lda $0014,y
and #$fe00
ora {temp}
sta {metasprite_table}+72,x
phy
ldy {dma_updates}
lda #$0004
sta {dma_rows},y
lda #$0080
sta {dma_legnth},y
lda {vram_width}
sta {dma_increment},y
lda {metasprite_table}+96,x
and #$01ff
asl #5
clc
adc {temp3}
sta {dma_address},y
lda {temp2}
sta {dma_bank},y
lda {metasprite_table}+72,x
and #$01ff
asl #4
sta {dma_destination},y
iny #2
lda #$0000
sta {dma_legnth},y
sty {dma_updates}
ply
rts
clear_vram_slot:
php
ldy {metasprite}
beq no_slot_to_clear
lda $0008,y
beq no_slot_to_clear
tdc
tax
-;
lda {metasprite_table},x
beq no_slot_to_clear
tay
phx
lda {metasprite_table}+72,x
and #$01ff
tax
lda name_to_slot2,x
sta {temp}
lda name_to_slot,x
tax
cpy #$0002
beq +
sep #$20
lda {temp}
eor #$ff
and {vram_slot_table},x
sta {vram_slot_table},x
rep #$20
bra ++
+;
sep #$20
lda #$00
sta {vram_slot_table},x
rep #$20
+;
plx
inx #2
jmp -
no_slot_to_clear:
tdc
tax
lda #$0000
sta {metasprite_table},x
plp
rts
slot_to_name:
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
slot_to_name2:
db $00
db $01
db $10
db $11
slot_to_name3:
db $01
db $02
db $04
db $08
name_to_slot:
dw $0000,$0000,$0001,$0001,$0002,$0002,$0003,$0003
dw $0000,$0000,$0001,$0001,$0002,$0002,$0003,$0003
dw $0000,$0000,$0001,$0001,$0002,$0002,$0003,$0003
dw $0000,$0000,$0001,$0001,$0002,$0002,$0003,$0003
dw $0004,$0004,$0005,$0005,$0006,$0006,$0007,$0007
dw $0004,$0004,$0005,$0005,$0006,$0006,$0007,$0007
dw $0004,$0004,$0005,$0005,$0006,$0006,$0007,$0007
dw $0004,$0004,$0005,$0005,$0006,$0006,$0007,$0007
dw $0008,$0008,$0009,$0009,$000a,$000a,$000b,$000b
dw $0008,$0008,$0009,$0009,$000a,$000a,$000b,$000b
dw $0008,$0008,$0009,$0009,$000a,$000a,$000b,$000b
dw $0008,$0008,$0009,$0009,$000a,$000a,$000b,$000b
dw $000c,$000c,$000d,$000d,$000e,$000e,$000f,$000f
dw $000c,$000c,$000d,$000d,$000e,$000e,$000f,$000f
dw $000c,$000c,$000d,$000d,$000e,$000e,$000f,$000f
dw $000c,$000c,$000d,$000d,$000e,$000e,$000f,$000f
dw $0010,$0010,$0011,$0011,$0012,$0012,$0013,$0013
dw $0010,$0010,$0011,$0011,$0012,$0012,$0013,$0013
dw $0010,$0010,$0011,$0011,$0012,$0012,$0013,$0013
dw $0010,$0010,$0011,$0011,$0012,$0012,$0013,$0013
dw $0014,$0014,$0015,$0015,$0016,$0016,$0017,$0017
dw $0014,$0014,$0015,$0015,$0016,$0016,$0017,$0017
dw $0014,$0014,$0015,$0015,$0016,$0016,$0017,$0017
dw $0014,$0014,$0015,$0015,$0016,$0016,$0017,$0017
dw $0018,$0018,$0019,$0019,$001a,$001a,$001b,$001b
dw $0018,$0018,$0019,$0019,$001a,$001a,$001b,$001b
dw $0018,$0018,$0019,$0019,$001a,$001a,$001b,$001b
dw $0018,$0018,$0019,$0019,$001a,$001a,$001b,$001b
dw $001c,$001c,$001d,$001d,$001e,$001e,$001f,$001f
dw $001c,$001c,$001d,$001d,$001e,$001e,$001f,$001f
dw $001c,$001c,$001d,$001d,$001e,$001e,$001f,$001f
dw $001c,$001c,$001d,$001d,$001e,$001e,$001f,$001f
name_to_slot2:
dw $0001,$0002,$0001,$0002,$0001,$0002,$0001,$0002
dw $0001,$0002,$0001,$0002,$0001,$0002,$0001,$0002
dw $0004,$0008,$0004,$0008,$0004,$0008,$0004,$0008
dw $0004,$0008,$0004,$0008,$0004,$0008,$0004,$0008
dw $0001,$0002,$0001,$0002,$0001,$0002,$0001,$0002
dw $0001,$0002,$0001,$0002,$0001,$0002,$0001,$0002
dw $0004,$0008,$0004,$0008,$0004,$0008,$0004,$0008
dw $0004,$0008,$0004,$0008,$0004,$0008,$0004,$0008
dw $0001,$0002,$0001,$0002,$0001,$0002,$0001,$0002
dw $0001,$0002,$0001,$0002,$0001,$0002,$0001,$0002
dw $0004,$0008,$0004,$0008,$0004,$0008,$0004,$0008
dw $0004,$0008,$0004,$0008,$0004,$0008,$0004,$0008
dw $0001,$0002,$0001,$0002,$0001,$0002,$0001,$0002
dw $0001,$0002,$0001,$0002,$0001,$0002,$0001,$0002
dw $0004,$0008,$0004,$0008,$0004,$0008,$0004,$0008
dw $0004,$0008,$0004,$0008,$0004,$0008,$0004,$0008
dw $0001,$0002,$0001,$0002,$0001,$0002,$0001,$0002
dw $0001,$0002,$0001,$0002,$0001,$0002,$0001,$0002
dw $0004,$0008,$0004,$0008,$0004,$0008,$0004,$0008
dw $0004,$0008,$0004,$0008,$0004,$0008,$0004,$0008
dw $0001,$0002,$0001,$0002,$0001,$0002,$0001,$0002
dw $0001,$0002,$0001,$0002,$0001,$0002,$0001,$0002
dw $0004,$0008,$0004,$0008,$0004,$0008,$0004,$0008
dw $0004,$0008,$0004,$0008,$0004,$0008,$0004,$0008
dw $0001,$0002,$0001,$0002,$0001,$0002,$0001,$0002
dw $0001,$0002,$0001,$0002,$0001,$0002,$0001,$0002
dw $0004,$0008,$0004,$0008,$0004,$0008,$0004,$0008
dw $0004,$0008,$0004,$0008,$0004,$0008,$0004,$0008
dw $0001,$0002,$0001,$0002,$0001,$0002,$0001,$0002
dw $0001,$0002,$0001,$0002,$0001,$0002,$0001,$0002
dw $0004,$0008,$0004,$0008,$0004,$0008,$0004,$0008
dw $0004,$0008,$0004,$0008,$0004,$0008,$0004,$0008
This works fast enough. This makes me wonder how fast the Genesis would be if it had the same PPU as the SNES, and needed to do all this shit in order to have good animation, and vice-versa. If this was the Genesis, I would've used 80 equally sized 32x32 slots.