2023-02-28 17:17:43 +00:00
|
|
|
; Compile a stamp into a compilation cache
|
2023-03-01 19:18:37 +00:00
|
|
|
;
|
|
|
|
; A = vbuff address
|
|
|
|
; X = width (in bytes)
|
|
|
|
; Y = height (in scanlines)
|
2023-02-28 17:17:43 +00:00
|
|
|
|
2023-03-01 19:18:37 +00:00
|
|
|
_CompileStamp
|
|
|
|
:lines equ tmp0
|
|
|
|
:sprwidth equ tmp1
|
|
|
|
:cntwidth equ tmp2
|
|
|
|
:baseAddr equ tmp3
|
|
|
|
:destAddr equ tmp4
|
|
|
|
:vbuffAddr equ tmp5
|
|
|
|
:rtnval equ tmp6
|
|
|
|
|
|
|
|
LDA_IMM_OPCODE equ $A9
|
|
|
|
LDA_ABS_X_OPCODE equ $BD
|
|
|
|
AND_IMM_OPCODE equ $29
|
|
|
|
ORA_IMM_OPCODE equ $09
|
|
|
|
STA_ABS_X_OPCODE equ $9D
|
|
|
|
STZ_ABS_X_OPCODE equ $9E
|
|
|
|
RTL_OPCODE equ $6B
|
|
|
|
|
|
|
|
sta :vbuffAddr
|
|
|
|
sty :lines
|
|
|
|
txa
|
2023-02-28 17:17:43 +00:00
|
|
|
lsr
|
2023-03-01 19:18:37 +00:00
|
|
|
sta :sprwidth
|
2023-02-28 17:17:43 +00:00
|
|
|
|
2023-03-01 19:18:37 +00:00
|
|
|
; Get ready to build the sprite
|
2023-02-28 17:17:43 +00:00
|
|
|
|
|
|
|
ldy CompileBankTop ; First free byte in the compilation bank
|
2023-03-01 19:18:37 +00:00
|
|
|
sty :rtnval ; Save it as the return value
|
2023-02-28 17:17:43 +00:00
|
|
|
|
|
|
|
phb
|
|
|
|
pei CompileBank
|
|
|
|
plb ; Set the bank to the compilation cache
|
|
|
|
|
2023-03-01 19:18:37 +00:00
|
|
|
stz :baseAddr
|
|
|
|
stz :destAddr
|
2023-02-28 17:17:43 +00:00
|
|
|
|
|
|
|
:oloop
|
2023-03-01 19:18:37 +00:00
|
|
|
lda :sprwidth
|
|
|
|
sta :cntwidth
|
|
|
|
ldx :vbuffAddr
|
2023-02-28 17:17:43 +00:00
|
|
|
|
|
|
|
:iloop
|
|
|
|
ldal spritemask,x
|
|
|
|
beq :no_mask ; If Mask == $0000, then it's a solid word
|
|
|
|
cmp #$FFFF
|
|
|
|
beq :next ; If Mask == $FFFF, then it's transparent
|
|
|
|
|
|
|
|
; Mask with the screen data
|
|
|
|
lda #LDA_ABS_X_OPCODE
|
|
|
|
sta: 0,y
|
2023-03-01 19:18:37 +00:00
|
|
|
lda :destAddr
|
2023-02-28 17:17:43 +00:00
|
|
|
sta: 1,y
|
|
|
|
lda #AND_IMM_OPCODE
|
|
|
|
sta: 3,y
|
|
|
|
ldal spritemask,x
|
|
|
|
sta: 4,y
|
|
|
|
lda #ORA_IMM_OPCODE
|
|
|
|
sta: 6,y
|
|
|
|
ldal spritedata,x
|
|
|
|
sta: 7,y
|
|
|
|
lda #STA_ABS_X_OPCODE
|
|
|
|
sta: 9,y
|
2023-03-01 19:18:37 +00:00
|
|
|
lda :destAddr
|
|
|
|
sta: 10,y
|
2023-02-28 17:17:43 +00:00
|
|
|
|
|
|
|
tya
|
2023-03-01 19:18:37 +00:00
|
|
|
clc
|
2023-02-28 17:17:43 +00:00
|
|
|
adc #12
|
|
|
|
tay
|
|
|
|
bra :next
|
|
|
|
|
|
|
|
; Just store the data
|
|
|
|
:no_mask lda #LDA_IMM_OPCODE
|
|
|
|
sta: 0,y
|
|
|
|
ldal spritedata,x
|
2023-03-01 19:18:37 +00:00
|
|
|
beq :zero
|
2023-02-28 17:17:43 +00:00
|
|
|
sta: 1,y
|
|
|
|
|
|
|
|
lda #STA_ABS_X_OPCODE
|
|
|
|
sta: 3,y
|
2023-03-01 19:18:37 +00:00
|
|
|
lda :destAddr
|
2023-02-28 17:17:43 +00:00
|
|
|
sta: 4,y
|
|
|
|
|
|
|
|
tya
|
2023-03-01 19:18:37 +00:00
|
|
|
clc
|
2023-02-28 17:17:43 +00:00
|
|
|
adc #6
|
|
|
|
tay
|
2023-03-01 19:18:37 +00:00
|
|
|
bra :next
|
|
|
|
|
|
|
|
:zero lda #STZ_ABS_X_OPCODE
|
|
|
|
sta: 0,y
|
|
|
|
lda :destAddr
|
|
|
|
sta: 1,y
|
|
|
|
|
|
|
|
iny
|
|
|
|
iny
|
|
|
|
iny
|
2023-02-28 17:17:43 +00:00
|
|
|
|
|
|
|
:next
|
|
|
|
inx
|
|
|
|
inx
|
|
|
|
|
2023-03-01 19:18:37 +00:00
|
|
|
inc :destAddr ; Move to the next word
|
|
|
|
inc :destAddr
|
2023-02-28 17:17:43 +00:00
|
|
|
|
2023-03-01 19:18:37 +00:00
|
|
|
dec :cntwidth
|
2023-02-28 17:17:43 +00:00
|
|
|
bne :iloop
|
|
|
|
|
2023-03-01 19:18:37 +00:00
|
|
|
lda :vbuffAddr
|
|
|
|
clc
|
2023-02-28 17:17:43 +00:00
|
|
|
adc #SPRITE_PLANE_SPAN
|
2023-03-01 19:18:37 +00:00
|
|
|
sta :vbuffAddr
|
2023-02-28 17:17:43 +00:00
|
|
|
|
2023-03-01 19:18:37 +00:00
|
|
|
lda :baseAddr ; Move to the next line
|
|
|
|
clc
|
2023-02-28 17:17:43 +00:00
|
|
|
adc #160
|
2023-03-01 19:18:37 +00:00
|
|
|
sta :baseAddr
|
|
|
|
sta :destAddr
|
2023-02-28 17:17:43 +00:00
|
|
|
|
2023-03-01 19:18:37 +00:00
|
|
|
dec :lines
|
|
|
|
beq :out
|
|
|
|
brl :oloop
|
2023-02-28 17:17:43 +00:00
|
|
|
|
2023-03-01 19:18:37 +00:00
|
|
|
:out
|
2023-02-28 17:17:43 +00:00
|
|
|
lda #RTL_OPCODE ; Finish up the subroutine
|
|
|
|
sta: 0,y
|
|
|
|
iny
|
|
|
|
sty CompileBankTop
|
|
|
|
|
|
|
|
plb
|
2023-03-01 19:18:37 +00:00
|
|
|
plb
|
|
|
|
lda :rtnval ; Address in the compile memory
|
2023-02-28 17:17:43 +00:00
|
|
|
rts
|
|
|
|
|
2023-05-17 03:38:54 +00:00
|
|
|
; 4 palettes for the sprite data. Converts 4 pixels at a time from 0000 0000w wxxy yzz0 -> gggg hhhh iiii jjjj
|
|
|
|
; each swizzle table is 512 bytes long, 2048 bytes for all four. They need to be prec
|
|
|
|
swizzle
|
2023-05-16 17:34:18 +00:00
|
|
|
; Draw a tile directly to the graphics screen as a sprite
|
|
|
|
;
|
|
|
|
; Y = screen address
|
|
|
|
; X = tile address
|
|
|
|
; A = $0001 = ignore mask
|
2023-05-17 03:38:54 +00:00
|
|
|
; = $0080 = vflip
|
|
|
|
; = $0600 = palette select
|
|
|
|
* _DrawSwizzleTileToScreen
|
|
|
|
* :palette equ 240
|
|
|
|
* ; Tile data must be 0000 000w wxxy yzz0
|
|
|
|
* ; Tile mask is normal pixel data
|
|
|
|
|
|
|
|
* and #$0600
|
|
|
|
* sta :palette ; cache the palette bits
|
|
|
|
|
|
|
|
* lda #^swizzle
|
|
|
|
* sta tmp+2
|
|
|
|
|
|
|
|
* ldal tiledata+{]line*4},x
|
|
|
|
* ora :palette
|
|
|
|
* sta tmp
|
|
|
|
* lda: {]line*SHR_LINE_WIDTH},y
|
|
|
|
* andl tiledata+{]line*4}+32,x
|
|
|
|
* ora [tmp]
|
|
|
|
* sta: {]line*SHR_LINE_WIDTH},y
|
|
|
|
|
|
|
|
* tay
|
|
|
|
* lda swizzle,y
|
|
|
|
|
|
|
|
|
|
|
|
* phb
|
|
|
|
* pea $0101
|
|
|
|
* plb
|
|
|
|
* plb
|
|
|
|
|
|
|
|
|
|
|
|
* ]line equ 0
|
|
|
|
* lup 8
|
|
|
|
* lda: {]line*SHR_LINE_WIDTH}+2,y
|
|
|
|
* andl tiledata+{]line*4}+32+2,x
|
|
|
|
* oral tiledata+{]line*4}+2,x
|
|
|
|
* sta: {]line*SHR_LINE_WIDTH}+2,y
|
|
|
|
* lda: {]line*SHR_LINE_WIDTH},y
|
|
|
|
* andl tiledata+{]line*4}+32,x
|
|
|
|
* oral tiledata+{]line*4},x
|
|
|
|
* sta: {]line*SHR_LINE_WIDTH},y
|
|
|
|
* ]line equ ]line+1
|
|
|
|
* --^
|
|
|
|
* plb
|
|
|
|
* rtl ; special exit
|
2023-05-16 17:34:18 +00:00
|
|
|
|
2023-05-17 17:59:07 +00:00
|
|
|
pal_select dw $3333,$6666,$9999,$CCCC
|
|
|
|
|
2023-05-16 17:34:18 +00:00
|
|
|
_DrawTileToScreen
|
2023-05-17 17:59:07 +00:00
|
|
|
:palette equ 248
|
2023-05-22 18:55:56 +00:00
|
|
|
|
2023-05-16 17:34:18 +00:00
|
|
|
phb
|
|
|
|
pea $0101
|
|
|
|
plb
|
|
|
|
plb
|
|
|
|
|
2023-05-22 18:55:56 +00:00
|
|
|
bit #$0040
|
|
|
|
beq :no_prio
|
|
|
|
bit #$0100
|
|
|
|
jeq _DrawPriorityToScreen
|
|
|
|
jmp _DrawPriorityToScreenV
|
|
|
|
|
|
|
|
:no_prio
|
2023-05-17 17:59:07 +00:00
|
|
|
bit #$0100
|
2023-05-17 03:38:54 +00:00
|
|
|
jne _DrawTileToScreenV
|
|
|
|
|
2023-05-17 17:59:07 +00:00
|
|
|
phx
|
|
|
|
and #$0006
|
|
|
|
tax
|
|
|
|
ldal pal_select,x
|
|
|
|
sta :palette
|
|
|
|
plx
|
|
|
|
clc
|
|
|
|
|
2023-05-16 17:34:18 +00:00
|
|
|
]line equ 0
|
|
|
|
lup 8
|
2023-05-17 17:59:07 +00:00
|
|
|
ldal tiledata+{]line*4}+2,x
|
|
|
|
adc :palette
|
|
|
|
eor: {]line*SHR_LINE_WIDTH}+2,y
|
2023-05-16 17:34:18 +00:00
|
|
|
andl tiledata+{]line*4}+32+2,x
|
2023-05-17 03:38:54 +00:00
|
|
|
eor: {]line*SHR_LINE_WIDTH}+2,y
|
2023-05-16 17:34:18 +00:00
|
|
|
sta: {]line*SHR_LINE_WIDTH}+2,y
|
2023-05-17 03:38:54 +00:00
|
|
|
|
2023-05-17 17:59:07 +00:00
|
|
|
ldal tiledata+{]line*4},x
|
|
|
|
adc :palette
|
|
|
|
eor: {]line*SHR_LINE_WIDTH},y
|
2023-05-16 17:34:18 +00:00
|
|
|
andl tiledata+{]line*4}+32,x
|
2023-05-17 03:38:54 +00:00
|
|
|
eor: {]line*SHR_LINE_WIDTH},y
|
|
|
|
sta: {]line*SHR_LINE_WIDTH},y
|
|
|
|
]line equ ]line+1
|
|
|
|
--^
|
|
|
|
plb
|
|
|
|
rtl ; special exit
|
|
|
|
|
2023-05-22 18:55:56 +00:00
|
|
|
_DrawPriorityToScreen
|
|
|
|
:palette equ 248
|
|
|
|
:p_tmp equ 144
|
|
|
|
|
|
|
|
phx
|
|
|
|
and #$0006
|
|
|
|
tax
|
|
|
|
ldal pal_select,x
|
|
|
|
sta :palette
|
|
|
|
plx
|
|
|
|
clc
|
|
|
|
|
|
|
|
]line equ 0
|
|
|
|
lup 8
|
|
|
|
ldal tiledata+{]line*4}+2,x
|
|
|
|
adc :palette
|
|
|
|
eor: {]line*SHR_LINE_WIDTH}+2,y
|
|
|
|
sta :p_tmp
|
|
|
|
|
|
|
|
; Convert the screen data to a mask. Zero in screen = zero in mask, else $F
|
|
|
|
lda: {]line*SHR_LINE_WIDTH}+2,y
|
|
|
|
bit #$F000
|
|
|
|
beq *+5
|
|
|
|
ora #$F000
|
|
|
|
bit #$0F00
|
|
|
|
beq *+5
|
|
|
|
ora #$0F00
|
|
|
|
bit #$00F0
|
|
|
|
beq *+5
|
|
|
|
ora #$00F0
|
|
|
|
bit #$000F
|
|
|
|
beq *+5
|
|
|
|
ora #$000F
|
|
|
|
eor #$FFFF
|
|
|
|
and :p_tmp
|
|
|
|
andl tiledata+{]line*4}+32+2,x
|
|
|
|
eor: {]line*SHR_LINE_WIDTH}+2,y
|
|
|
|
sta: {]line*SHR_LINE_WIDTH}+2,y
|
|
|
|
|
|
|
|
ldal tiledata+{]line*4},x
|
|
|
|
adc :palette
|
|
|
|
eor: {]line*SHR_LINE_WIDTH},y
|
|
|
|
sta :p_tmp
|
|
|
|
|
|
|
|
lda: {]line*SHR_LINE_WIDTH},y
|
|
|
|
bit #$F000
|
|
|
|
beq *+5
|
|
|
|
ora #$F000
|
|
|
|
bit #$0F00
|
|
|
|
beq *+5
|
|
|
|
ora #$0F00
|
|
|
|
bit #$00F0
|
|
|
|
beq *+5
|
|
|
|
ora #$00F0
|
|
|
|
bit #$000F
|
|
|
|
beq *+5
|
|
|
|
ora #$000F
|
|
|
|
eor #$FFFF
|
|
|
|
and :p_tmp
|
|
|
|
andl tiledata+{]line*4}+32,x
|
|
|
|
eor: {]line*SHR_LINE_WIDTH},y
|
|
|
|
sta: {]line*SHR_LINE_WIDTH},y
|
|
|
|
]line equ ]line+1
|
|
|
|
--^
|
|
|
|
plb
|
|
|
|
rtl ; special exit
|
|
|
|
|
2023-05-17 03:38:54 +00:00
|
|
|
_DrawTileToScreenV
|
2023-05-17 17:59:07 +00:00
|
|
|
:palette equ 248
|
|
|
|
phx
|
|
|
|
and #$0006
|
|
|
|
tax
|
|
|
|
ldal pal_select,x
|
|
|
|
sta :palette
|
|
|
|
plx
|
|
|
|
clc
|
|
|
|
|
2023-05-17 03:38:54 +00:00
|
|
|
]line equ 0
|
|
|
|
lup 8
|
2023-05-17 17:59:07 +00:00
|
|
|
ldal tiledata+{{7-]line}*4}+2,x
|
|
|
|
eor :palette
|
|
|
|
eor: {]line*SHR_LINE_WIDTH}+2,y
|
2023-05-17 03:38:54 +00:00
|
|
|
andl tiledata+{{7-]line}*4}+32+2,x
|
|
|
|
eor: {]line*SHR_LINE_WIDTH}+2,y
|
|
|
|
sta: {]line*SHR_LINE_WIDTH}+2,y
|
|
|
|
|
2023-05-17 17:59:07 +00:00
|
|
|
ldal tiledata+{{7-]line}*4},x
|
|
|
|
eor :palette
|
|
|
|
eor: {]line*SHR_LINE_WIDTH},y
|
2023-05-17 03:38:54 +00:00
|
|
|
andl tiledata+{{7-]line}*4}+32,x
|
|
|
|
eor: {]line*SHR_LINE_WIDTH},y
|
2023-05-16 17:34:18 +00:00
|
|
|
sta: {]line*SHR_LINE_WIDTH},y
|
|
|
|
]line equ ]line+1
|
|
|
|
--^
|
|
|
|
plb
|
|
|
|
rtl ; special exit
|
|
|
|
|
2023-05-22 18:55:56 +00:00
|
|
|
_DrawPriorityToScreenV
|
|
|
|
:palette equ 248
|
|
|
|
:p_tmp equ 144
|
|
|
|
|
|
|
|
phx
|
|
|
|
and #$0006
|
|
|
|
tax
|
|
|
|
ldal pal_select,x
|
|
|
|
sta :palette
|
|
|
|
plx
|
|
|
|
clc
|
|
|
|
|
|
|
|
]line equ 0
|
|
|
|
lup 8
|
|
|
|
ldal tiledata+{{7-]line}*4}+2,x
|
|
|
|
adc :palette
|
|
|
|
eor: {]line*SHR_LINE_WIDTH}+2,y
|
|
|
|
sta :p_tmp
|
|
|
|
|
|
|
|
; Convert the screen data to a mask
|
|
|
|
lda: {]line*SHR_LINE_WIDTH}+2,y
|
|
|
|
bit #$F000
|
|
|
|
beq *+5
|
|
|
|
ora #$F000
|
|
|
|
bit #$0F00
|
|
|
|
beq *+5
|
|
|
|
ora #$0F00
|
|
|
|
bit #$00F0
|
|
|
|
beq *+5
|
|
|
|
ora #$00F0
|
|
|
|
bit #$000F
|
|
|
|
beq *+5
|
|
|
|
ora #$000F
|
|
|
|
eor #$FFFF
|
|
|
|
and :p_tmp
|
|
|
|
andl tiledata+{{7-]line}*4}+32+2,x
|
|
|
|
eor: {]line*SHR_LINE_WIDTH}+2,y
|
|
|
|
sta: {]line*SHR_LINE_WIDTH}+2,y
|
|
|
|
|
|
|
|
ldal tiledata+{{7-]line}*4},x
|
|
|
|
adc :palette
|
|
|
|
eor: {]line*SHR_LINE_WIDTH},y
|
|
|
|
sta :p_tmp
|
|
|
|
|
|
|
|
lda: {]line*SHR_LINE_WIDTH},y
|
|
|
|
bit #$F000
|
|
|
|
beq *+5
|
|
|
|
ora #$F000
|
|
|
|
bit #$0F00
|
|
|
|
beq *+5
|
|
|
|
ora #$0F00
|
|
|
|
bit #$00F0
|
|
|
|
beq *+5
|
|
|
|
ora #$00F0
|
|
|
|
bit #$000F
|
|
|
|
beq *+5
|
|
|
|
ora #$000F
|
|
|
|
eor #$FFFF
|
|
|
|
and :p_tmp
|
|
|
|
andl tiledata+{{7-]line}*4}+32,x
|
|
|
|
eor: {]line*SHR_LINE_WIDTH},y
|
|
|
|
sta: {]line*SHR_LINE_WIDTH},y
|
|
|
|
]line equ ]line+1
|
|
|
|
--^
|
|
|
|
plb
|
|
|
|
rtl ; special exit
|
|
|
|
|
2023-02-28 17:17:43 +00:00
|
|
|
; Draw a sprite directly to the graphics screen. If sprite is clipped at all, do not draw.
|
2023-02-27 21:30:56 +00:00
|
|
|
;
|
|
|
|
; X = sprite record index
|
2023-02-28 17:17:43 +00:00
|
|
|
_DSTSOut
|
|
|
|
rts
|
|
|
|
|
2023-02-27 21:30:56 +00:00
|
|
|
_DrawStampToScreen
|
2023-02-28 17:17:43 +00:00
|
|
|
lda _Sprites+IS_OFF_SCREEN,x ; If the sprite is off-screen, don't draw it
|
|
|
|
bne _DSTSOut
|
|
|
|
|
2023-04-26 05:41:17 +00:00
|
|
|
lda _Sprites+SPRITE_ID,x ; If the sprite is hidden or an overlay, don't draw it
|
|
|
|
bit #SPRITE_OVERLAY+SPRITE_HIDE
|
|
|
|
bne _DSTSOut
|
|
|
|
|
2023-02-28 17:17:43 +00:00
|
|
|
lda _Sprites+SPRITE_CLIP_WIDTH,x ; If the sprite is clipped to the playfield, don't draw it
|
|
|
|
cmp _Sprites+SPRITE_WIDTH,x
|
|
|
|
bne _DSTSOut
|
|
|
|
lda _Sprites+SPRITE_CLIP_HEIGHT,x
|
|
|
|
cmp _Sprites+SPRITE_HEIGHT,x
|
|
|
|
bne _DSTSOut
|
|
|
|
|
2023-02-27 21:30:56 +00:00
|
|
|
clc
|
|
|
|
lda _Sprites+SPRITE_Y,x
|
|
|
|
adc ScreenY0
|
|
|
|
asl
|
|
|
|
asl
|
|
|
|
asl
|
|
|
|
asl
|
|
|
|
asl
|
|
|
|
sta tmp0
|
|
|
|
asl
|
|
|
|
asl
|
|
|
|
clc
|
|
|
|
adc tmp0
|
|
|
|
clc
|
|
|
|
adc #$2000
|
|
|
|
clc
|
|
|
|
adc ScreenX0
|
|
|
|
adc _Sprites+SPRITE_X,x ; Move to the horizontal address
|
|
|
|
tay ; This is the on-screen address
|
|
|
|
|
2023-03-01 19:18:37 +00:00
|
|
|
lda _Sprites+SPRITE_ID,x ; If this is a compiled sprite, call the routine in the compilation bank
|
|
|
|
bit #SPRITE_COMPILED
|
|
|
|
beq *+5
|
|
|
|
brl :compiled
|
|
|
|
|
2023-02-27 21:30:56 +00:00
|
|
|
lda _Sprites+SPRITE_HEIGHT,x
|
|
|
|
sta tmp0
|
|
|
|
|
|
|
|
; Sprite is either 8 or 16 pixels wide, so select the entry point
|
|
|
|
lda _Sprites+SPRITE_WIDTH,x
|
|
|
|
cmp #4
|
|
|
|
beq :skinny
|
|
|
|
|
|
|
|
lda _Sprites+SPRITE_DISP,x ; This is the VBUFF address with the correct sprite frame
|
|
|
|
tax
|
|
|
|
phb
|
|
|
|
pea $0101
|
|
|
|
plb
|
|
|
|
plb
|
|
|
|
bra :entry16
|
|
|
|
:loop16
|
|
|
|
clc
|
|
|
|
txa
|
|
|
|
adc #SPRITE_PLANE_SPAN
|
|
|
|
tax
|
|
|
|
tya
|
|
|
|
adc #SHR_LINE_WIDTH
|
|
|
|
tay
|
|
|
|
:entry16
|
|
|
|
lda: 6,y
|
|
|
|
andl spritemask+6,x
|
|
|
|
oral spritedata+6,x
|
|
|
|
sta: 6,y
|
|
|
|
lda: 4,y
|
|
|
|
andl spritemask+4,x
|
|
|
|
oral spritedata+4,x
|
|
|
|
sta: 4,y
|
|
|
|
lda: 2,y
|
|
|
|
andl spritemask+2,x
|
|
|
|
oral spritedata+2,x
|
|
|
|
sta: 2,y
|
|
|
|
lda: 0,y
|
|
|
|
andl spritemask+0,x
|
|
|
|
oral spritedata+0,x
|
|
|
|
sta: 0,y
|
|
|
|
|
|
|
|
dec tmp0
|
|
|
|
bne :loop16
|
|
|
|
|
|
|
|
plb
|
|
|
|
rts
|
|
|
|
|
|
|
|
:skinny
|
|
|
|
lda _Sprites+SPRITE_DISP,x ; This is the VBUFF address with the correct sprite frame
|
|
|
|
tax
|
|
|
|
phb
|
|
|
|
pea $0101
|
|
|
|
plb
|
|
|
|
plb
|
|
|
|
bra :entry8
|
|
|
|
:loop8
|
|
|
|
clc
|
|
|
|
txa
|
|
|
|
adc #SPRITE_PLANE_SPAN
|
|
|
|
tax
|
|
|
|
tya
|
|
|
|
adc #SHR_LINE_WIDTH
|
|
|
|
tay
|
|
|
|
:entry8
|
|
|
|
lda: 2,y
|
|
|
|
andl spritemask+2,x
|
|
|
|
oral spritedata+2,x
|
|
|
|
sta: 2,y
|
|
|
|
lda: 0,y
|
|
|
|
andl spritemask+0,x
|
|
|
|
oral spritedata+0,x
|
|
|
|
sta: 0,y
|
|
|
|
|
|
|
|
dec tmp0
|
|
|
|
bne :loop8
|
|
|
|
|
|
|
|
plb
|
|
|
|
rts
|
2023-03-01 19:18:37 +00:00
|
|
|
|
|
|
|
:compiled
|
|
|
|
lda CompileBank-1 ; Load the bank into the high byte
|
|
|
|
stal :patch+2 ; Put it into the 3rd address bytes (2nd byte is garbage)
|
|
|
|
lda _Sprites+SPRITE_DISP,x ; Address in the compile bank
|
|
|
|
stal :patch+1 ; Set 1st and 2nd address bytes
|
|
|
|
|
|
|
|
tyx ; Put on-screen address in X-register
|
|
|
|
phb ; Compiled sprites assume bank register is $01
|
|
|
|
pea $0101
|
|
|
|
plb
|
|
|
|
plb
|
|
|
|
:patch jsl $000000 ; Dispatch
|
|
|
|
plb
|
|
|
|
rts
|
|
|
|
|
2022-04-20 12:43:16 +00:00
|
|
|
; Alternate entry point that takes arguments in registers instead of using a _Sprite
|
|
|
|
; record
|
|
|
|
;
|
|
|
|
; Y = VBUFF address
|
|
|
|
; X = Tile Data address
|
|
|
|
; A = Sprite Flags
|
2022-06-01 03:53:33 +00:00
|
|
|
DISP_VFLIP equ $0004 ; hard code these because they are internal values
|
|
|
|
DISP_HFLIP equ $0002
|
|
|
|
DISP_MASK equ $0018 ; Preserve the size bits
|
|
|
|
|
2022-04-20 12:43:16 +00:00
|
|
|
_DrawSpriteStamp
|
|
|
|
sty tmp1
|
|
|
|
stx tmp2
|
2022-06-01 03:53:33 +00:00
|
|
|
xba
|
2022-04-20 12:43:16 +00:00
|
|
|
and #DISP_MASK ; dispatch to all of the different orientations
|
|
|
|
sta tmp3
|
2022-02-18 18:12:32 +00:00
|
|
|
|
|
|
|
phb
|
|
|
|
pea #^tiledata ; Set the bank to the tile data
|
|
|
|
plb
|
|
|
|
|
2022-06-01 03:53:33 +00:00
|
|
|
; X = sprite ID
|
|
|
|
; Y = Tile Data
|
|
|
|
; A = VBUFF address
|
2022-02-18 18:12:32 +00:00
|
|
|
ldx tmp3
|
|
|
|
ldy tmp2
|
|
|
|
lda tmp1
|
|
|
|
jsr _DrawSprite
|
|
|
|
|
|
|
|
lda tmp3
|
2022-02-21 21:45:11 +00:00
|
|
|
ora #DISP_HFLIP
|
2022-02-18 18:12:32 +00:00
|
|
|
tax
|
|
|
|
ldy tmp2
|
|
|
|
lda tmp1
|
|
|
|
clc
|
2022-06-01 03:53:33 +00:00
|
|
|
adc #3*4
|
2022-02-18 18:12:32 +00:00
|
|
|
jsr _DrawSprite
|
|
|
|
|
|
|
|
lda tmp3
|
2022-02-21 21:45:11 +00:00
|
|
|
ora #DISP_VFLIP
|
2022-02-18 18:12:32 +00:00
|
|
|
tax
|
|
|
|
ldy tmp2
|
|
|
|
lda tmp1
|
|
|
|
clc
|
2022-06-01 03:53:33 +00:00
|
|
|
adc #6*4
|
2022-02-18 18:12:32 +00:00
|
|
|
jsr _DrawSprite
|
|
|
|
|
|
|
|
lda tmp3
|
2022-02-18 22:20:07 +00:00
|
|
|
ora #DISP_HFLIP+DISP_VFLIP
|
2022-02-18 18:12:32 +00:00
|
|
|
tax
|
|
|
|
ldy tmp2
|
|
|
|
lda tmp1
|
|
|
|
clc
|
2022-06-01 03:53:33 +00:00
|
|
|
adc #9*4
|
2022-02-18 18:12:32 +00:00
|
|
|
jsr _DrawSprite
|
|
|
|
|
|
|
|
; Restore bank
|
|
|
|
plb ; pop extra byte
|
|
|
|
plb
|
|
|
|
rts
|
|
|
|
;
|
|
|
|
; X = _Sprites array offset
|
|
|
|
_DrawSprite
|
|
|
|
jmp (draw_sprite,x)
|
|
|
|
|
2022-07-22 03:51:25 +00:00
|
|
|
draw_sprite dw draw_8x8,draw_8x8h,draw_8x8v,draw_8x8hv ; 8 wide x 8 tall
|
|
|
|
dw draw_8x16,draw_8x16h,draw_8x16v,draw_8x16hv ; 8 wide x 16 tall
|
|
|
|
dw draw_16x8,draw_16x8h,draw_16x8v,draw_16x8hv ; 16 wide by 8 tall
|
|
|
|
dw draw_16x16,draw_16x16h,draw_16x16v,draw_16x16hv ; 16 wide by 16 tall
|
2022-02-18 18:12:32 +00:00
|
|
|
|
|
|
|
dw :rtn,:rtn,:rtn,:rtn ; hidden bit is set
|
|
|
|
dw :rtn,:rtn,:rtn,:rtn
|
|
|
|
dw :rtn,:rtn,:rtn,:rtn
|
|
|
|
dw :rtn,:rtn,:rtn,:rtn
|
|
|
|
:rtn rts
|
|
|
|
|
|
|
|
draw_8x8
|
2022-07-22 03:51:25 +00:00
|
|
|
tax
|
|
|
|
jmp _DrawTile8x8
|
|
|
|
|
2022-02-18 18:12:32 +00:00
|
|
|
draw_8x8h
|
|
|
|
tax
|
2022-07-22 03:51:25 +00:00
|
|
|
clc
|
|
|
|
tya
|
|
|
|
adc #64
|
|
|
|
tay
|
2022-02-18 18:12:32 +00:00
|
|
|
jmp _DrawTile8x8
|
|
|
|
|
|
|
|
draw_8x8v
|
2022-07-22 03:51:25 +00:00
|
|
|
tax
|
|
|
|
jmp _DrawTile8x8V
|
|
|
|
|
2022-02-18 18:12:32 +00:00
|
|
|
draw_8x8hv
|
|
|
|
tax
|
2022-07-22 03:51:25 +00:00
|
|
|
clc
|
|
|
|
tya
|
|
|
|
adc #64
|
|
|
|
tay
|
2022-02-18 18:12:32 +00:00
|
|
|
jmp _DrawTile8x8V
|
|
|
|
|
|
|
|
draw_8x16
|
2022-07-22 03:51:25 +00:00
|
|
|
tax
|
|
|
|
jsr _DrawTile8x8
|
|
|
|
clc
|
|
|
|
txa
|
|
|
|
adc #{8*SPRITE_PLANE_SPAN}
|
|
|
|
tax
|
|
|
|
tya
|
|
|
|
adc #{128*32} ; 32 tiles to the next vertical one, each tile is 128 bytes
|
|
|
|
tay
|
|
|
|
jmp _DrawTile8x8
|
|
|
|
|
2022-02-18 18:12:32 +00:00
|
|
|
draw_8x16h
|
|
|
|
tax
|
2022-07-22 03:51:25 +00:00
|
|
|
clc
|
|
|
|
tya
|
|
|
|
adc #64
|
|
|
|
tay
|
2022-02-18 18:12:32 +00:00
|
|
|
jsr _DrawTile8x8
|
|
|
|
clc
|
|
|
|
txa
|
|
|
|
adc #{8*SPRITE_PLANE_SPAN}
|
|
|
|
tax
|
|
|
|
tya
|
|
|
|
adc #{128*32} ; 32 tiles to the next vertical one, each tile is 128 bytes
|
|
|
|
tay
|
|
|
|
jmp _DrawTile8x8
|
|
|
|
|
|
|
|
draw_8x16v
|
2022-07-22 03:51:25 +00:00
|
|
|
clc
|
2022-02-18 18:12:32 +00:00
|
|
|
tax
|
2022-07-22 03:51:25 +00:00
|
|
|
tya
|
|
|
|
pha
|
|
|
|
adc #{128*32}
|
|
|
|
tay
|
2022-02-18 18:12:32 +00:00
|
|
|
jsr _DrawTile8x8V
|
|
|
|
clc
|
|
|
|
txa
|
|
|
|
adc #{8*SPRITE_PLANE_SPAN}
|
|
|
|
tax
|
2022-07-22 03:51:25 +00:00
|
|
|
ply
|
|
|
|
jmp _DrawTile8x8V
|
|
|
|
|
|
|
|
draw_8x16hv
|
|
|
|
clc
|
|
|
|
tax
|
2022-02-18 18:12:32 +00:00
|
|
|
tya
|
2022-07-22 03:51:25 +00:00
|
|
|
adc #64
|
|
|
|
pha
|
2022-02-18 18:12:32 +00:00
|
|
|
adc #{128*32}
|
|
|
|
tay
|
2022-07-22 03:51:25 +00:00
|
|
|
jsr _DrawTile8x8V
|
|
|
|
clc
|
|
|
|
txa
|
|
|
|
adc #{8*SPRITE_PLANE_SPAN}
|
|
|
|
tax
|
|
|
|
ply
|
2022-02-18 18:12:32 +00:00
|
|
|
jmp _DrawTile8x8V
|
|
|
|
|
|
|
|
draw_16x8
|
|
|
|
tax
|
|
|
|
jsr _DrawTile8x8
|
|
|
|
clc
|
|
|
|
txa
|
|
|
|
adc #4
|
|
|
|
tax
|
|
|
|
tya
|
|
|
|
adc #128 ; Next tile is 128 bytes away
|
|
|
|
tay
|
|
|
|
jmp _DrawTile8x8
|
|
|
|
|
|
|
|
draw_16x8h
|
|
|
|
clc
|
|
|
|
tax
|
|
|
|
tya
|
2022-07-22 03:51:25 +00:00
|
|
|
adc #64
|
2022-02-18 18:12:32 +00:00
|
|
|
pha
|
|
|
|
adc #128
|
|
|
|
tay
|
|
|
|
jsr _DrawTile8x8
|
|
|
|
txa
|
|
|
|
adc #4
|
|
|
|
tax
|
|
|
|
ply
|
|
|
|
jmp _DrawTile8x8
|
|
|
|
|
|
|
|
draw_16x8v
|
|
|
|
tax
|
|
|
|
jsr _DrawTile8x8V
|
|
|
|
clc
|
|
|
|
txa
|
|
|
|
adc #4
|
|
|
|
tax
|
|
|
|
tya
|
|
|
|
adc #128
|
|
|
|
tay
|
|
|
|
jmp _DrawTile8x8V
|
|
|
|
|
|
|
|
draw_16x8hv
|
|
|
|
clc
|
|
|
|
tax
|
|
|
|
tya
|
2022-07-22 03:51:25 +00:00
|
|
|
adc #64
|
2022-02-18 18:12:32 +00:00
|
|
|
pha
|
|
|
|
adc #128
|
|
|
|
tay
|
|
|
|
jsr _DrawTile8x8V
|
|
|
|
txa
|
|
|
|
adc #4
|
|
|
|
tax
|
|
|
|
ply
|
|
|
|
jmp _DrawTile8x8V
|
|
|
|
|
2022-06-01 03:53:33 +00:00
|
|
|
; X = sprite ID
|
|
|
|
; Y = Tile Data
|
|
|
|
; A = VBUFF address
|
2022-02-18 18:12:32 +00:00
|
|
|
draw_16x16
|
|
|
|
clc
|
|
|
|
tax
|
|
|
|
jsr _DrawTile8x8
|
|
|
|
txa
|
|
|
|
adc #4
|
|
|
|
tax
|
|
|
|
tya
|
|
|
|
adc #128
|
|
|
|
tay
|
|
|
|
jsr _DrawTile8x8
|
|
|
|
txa
|
|
|
|
adc #{8*SPRITE_PLANE_SPAN}-4
|
|
|
|
tax
|
|
|
|
tya
|
|
|
|
adc #{128*{32-1}}
|
|
|
|
tay
|
|
|
|
jsr _DrawTile8x8
|
|
|
|
txa
|
|
|
|
adc #4
|
|
|
|
tax
|
|
|
|
tya
|
|
|
|
adc #128
|
|
|
|
tay
|
|
|
|
jmp _DrawTile8x8
|
|
|
|
|
|
|
|
draw_16x16h
|
|
|
|
clc
|
|
|
|
tax
|
|
|
|
tya
|
2022-02-21 21:45:11 +00:00
|
|
|
adc #64
|
2022-02-18 18:12:32 +00:00
|
|
|
pha
|
|
|
|
adc #128
|
|
|
|
tay
|
|
|
|
jsr _DrawTile8x8
|
|
|
|
|
|
|
|
txa
|
|
|
|
adc #4
|
|
|
|
tax
|
|
|
|
ply
|
|
|
|
jsr _DrawTile8x8
|
|
|
|
|
|
|
|
txa
|
|
|
|
adc #{8*SPRITE_PLANE_SPAN}-4
|
|
|
|
tax
|
|
|
|
tya
|
|
|
|
adc #{128*32}
|
|
|
|
pha
|
|
|
|
adc #128
|
|
|
|
tay
|
|
|
|
jsr _DrawTile8x8
|
|
|
|
|
|
|
|
txa
|
|
|
|
adc #4
|
|
|
|
tax
|
|
|
|
ply
|
|
|
|
jmp _DrawTile8x8
|
|
|
|
|
|
|
|
draw_16x16v
|
|
|
|
clc
|
|
|
|
tax
|
|
|
|
tya
|
|
|
|
pha ; store some copies
|
|
|
|
phx
|
|
|
|
pha
|
|
|
|
adc #{128*32}
|
|
|
|
tay
|
|
|
|
jsr _DrawTile8x8V
|
|
|
|
|
|
|
|
txa
|
|
|
|
adc #{8*SPRITE_PLANE_SPAN}
|
|
|
|
tax
|
|
|
|
ply
|
|
|
|
jsr _DrawTile8x8V
|
|
|
|
|
|
|
|
pla
|
|
|
|
adc #4
|
|
|
|
tax
|
|
|
|
lda 1,s
|
|
|
|
adc #{128*{32+1}}
|
|
|
|
tay
|
|
|
|
jsr _DrawTile8x8V
|
|
|
|
|
|
|
|
txa
|
|
|
|
adc #{8*SPRITE_PLANE_SPAN}
|
|
|
|
tax
|
|
|
|
pla
|
|
|
|
adc #128
|
|
|
|
tay
|
|
|
|
jmp _DrawTile8x8V
|
|
|
|
|
|
|
|
draw_16x16hv
|
|
|
|
clc
|
|
|
|
tax
|
|
|
|
tya
|
|
|
|
pha
|
2022-06-08 22:17:28 +00:00
|
|
|
adc #{128*{32+1}}+64 ; Bottom-right source to top-left
|
2022-02-18 18:12:32 +00:00
|
|
|
tay
|
|
|
|
jsr _DrawTile8x8V
|
|
|
|
|
|
|
|
txa
|
|
|
|
adc #4
|
|
|
|
tax
|
|
|
|
lda 1,s
|
2022-06-08 22:17:28 +00:00
|
|
|
adc #{128*32}+64
|
2022-02-18 18:12:32 +00:00
|
|
|
tay
|
|
|
|
jsr _DrawTile8x8V
|
|
|
|
|
|
|
|
txa
|
|
|
|
adc #{8*SPRITE_PLANE_SPAN}-4
|
|
|
|
tax
|
|
|
|
lda 1,s
|
2022-06-08 22:17:28 +00:00
|
|
|
adc #128+64
|
2022-02-18 18:12:32 +00:00
|
|
|
tay
|
|
|
|
jsr _DrawTile8x8V
|
|
|
|
|
|
|
|
txa
|
|
|
|
adc #4
|
|
|
|
tax
|
2022-06-08 22:17:28 +00:00
|
|
|
pla
|
|
|
|
adc #64
|
|
|
|
tay
|
2022-02-18 18:12:32 +00:00
|
|
|
jmp _DrawTile8x8V
|
|
|
|
|
|
|
|
|
|
|
|
; X = sprite vbuff address
|
|
|
|
; Y = tile data pointer
|
|
|
|
_DrawTile8x8
|
|
|
|
_CopyTile8x8
|
|
|
|
]line equ 0
|
|
|
|
lup 8
|
|
|
|
lda: tiledata+32+{]line*4},y
|
|
|
|
stal spritemask+{]line*SPRITE_PLANE_SPAN},x
|
|
|
|
lda: tiledata+{]line*4},y
|
|
|
|
stal spritedata+{]line*SPRITE_PLANE_SPAN},x
|
|
|
|
|
|
|
|
lda: tiledata+32+{]line*4}+2,y
|
|
|
|
stal spritemask+{]line*SPRITE_PLANE_SPAN}+2,x
|
|
|
|
lda: tiledata+{]line*4}+2,y
|
|
|
|
stal spritedata+{]line*SPRITE_PLANE_SPAN}+2,x
|
|
|
|
]line equ ]line+1
|
|
|
|
--^
|
|
|
|
rts
|
|
|
|
|
|
|
|
_DrawTile8x8V
|
|
|
|
_CopyTile8x8V
|
|
|
|
]line equ 0
|
|
|
|
lup 8
|
|
|
|
lda: tiledata+32+{{7-]line}*4},y
|
|
|
|
stal spritemask+{]line*SPRITE_PLANE_SPAN},x
|
|
|
|
lda: tiledata+{{7-]line}*4},y
|
|
|
|
stal spritedata+{]line*SPRITE_PLANE_SPAN},x
|
|
|
|
|
|
|
|
lda: tiledata+32+{{7-]line}*4}+2,y
|
|
|
|
stal spritemask+{]line*SPRITE_PLANE_SPAN}+2,x
|
|
|
|
lda: tiledata+{{7-]line}*4}+2,y
|
|
|
|
stal spritedata+{]line*SPRITE_PLANE_SPAN}+2,x
|
|
|
|
]line equ ]line+1
|
|
|
|
--^
|
|
|
|
rts
|