;Blue Paratroopa
;by Alcaro
;based off a disassembly of the vertical red paratroopa

incsrc subroutinedefs_xkas.asm

print "INIT ",pc
Init:
JSL $81ACF9
STA $1570,x
JSL !SubHorizPos
TYA
STA $157C,x
LDA #$10
STA $AA,x
RTL


print "MAIN ",pc
PHB
PHK
PLB
JSR Main
PLB
RTL

Main:
JSL !SubOffscreenX0

LDA $9D
BNE .Return
LDA $157C,x
PHA
JSR UpdateDirection
PLA
CMP $157C,x
BEQ +
LDA #$08
STA $15AC,x
+
JSR SetAnimationFrame
JSL $81801A
JSL $818022

LDA $1540,x
BNE .Interact
INC $C2,x
LDA $C2,x
AND #$03
BNE .Interact
LDA $AA,x
BEQ +
LDA $B6,x
BEQ +
LDA $151C,x
INC A
AND #$3F
STA $151C,x
+
LDA $151C,x
LSR #4
TAY
LDA $AA,x
CLC
ADC .YBoost,y
STA $AA,x
LDA $B6,x
CLC
ADC .XBoost,y
STA $B6,x
.Interact

LDA $AA,x
PHA
JSL $81803A
PLA
CMP $AA,x
BEQ .Return
LDA #$00
STA $7FAB10,x

.Return
JMP Graphics;yes, it actually does this. pretty backwards, but I don't care...

.XBoost
db $01,$FF,$FF,$01
.YBoost
db $FF,$FF,$01,$01

Graphics:
LDA $157C,x
PHA
LDY $15AC,x
BEQ ++
LDA #$02
STA $1602,x
LDA #$00
CPY #$05
BCC +
INC A
+
EOR $157C,x
STA $157C,x
++
LDA $1602,x
LSR
LDA $D8,x
PHA
SBC #$0F
STA $D8,x
LDA $14D4,x
PHA
SBC #$00
STA $14D4,x
JSL $819D5F
PLA
STA $14D4,x
PLA
STA $D8,x
JSR Wing
PLA
STA $157C,x
RTS

Wing:
LDA $1602,x
AND #$02
STA $01
LDA $186C,x
BNE .Return
LDA $E4,x
STA $00
LDA $14E0,x
STA $04
LDA $D8,x
STA $01
LDY $15EA,x
PHX
LDA $157C,x
ASL
ADC $02
TAX
LDA $00
CLC
ADC .DispXLo,x
STA $00
LDA $04
ADC .DispXHi,x
PHA
LDA $00
SEC
SBC $1A
STA $0300,y
PLA
SBC $1B
BNE .PullAndReturn
LDA $01
SEC
SBC $1C
CLC
ADC .DispY,x
STA $0301,y
LDA .Tiles,x
STA $0302,y
LDA $64
ORA .Prop,x
STA $0303,y
TYA
LSR
LSR
TAY
LDA .Size,x
STA $0460,y
.PullAndReturn
PLX
.Return
RTS

.DispXLo
db $FF,$F7,$09,$09
.DispXHi
db $FF,$FF,$00,$00
.DispY
db $FC,$F4,$FC,$F4
.Tiles
db $5D,$C6,$5D,$C6
.Prop
db $46,$46,$06,$06
.Size
db $00,$02,$00,$02

;half of those are shared between a bunch of sprites
SubHorizPos:
LDY #$00
LDA $D1
SEC
SBC $E4,x
STA $0F
LDA $D2
SBC $14E0,x
BPL .Return
INY
.Return
RTS


UpdateDirection:
LDA #$00
LDY $B6,x
BEQ .Return
BPL +
INC A
+
STA $157C,x
.Return
RTS

SetAnimationFrame:
INC $1570,x
LDA $1570,x
LSR #3
AND #$01
STA $1602,x
RTS

