
incsrc subroutinedefs_xkas.asm

TILEMAP:	
	db $22,$26
	db $24,$28

print "INIT ", pc
	RTL

Return:
	RTS

print "MAIN ", pc
	PHB
	PHK
	PLB
	JSR Run
	PLB
	RTL
	
Retun:
	RTS
	
Run:
	JSR GFX
	JSL !SubOffscreenX0
	LDA $14C8,x		;If the sprite is dead..
	CMP #$08
	BNE Return		;..return
	LDA $9D
	BNE Return		;Also return if sprites are locked.
	JSR SHOOTING_STARS	
	
	JSL $81A7DC
	BCC Return
	JSL $80F5B7
	
	RTS

XSPD:
	db $E0,$20,$E0,$20,$00,$20,$00,$E0		; x speed of fireballs ;; add more values if you
YSPD:
	db $E0,$E0,$20,$20,$20,$00,$E0,$00		; y speed of fireballs ;; spawn more fireballs!!

SHOOTING_STARS:
	LDA $163E,x
	BNE NOSPAWN
	JSR SPAWNM
	LDA #$50
	STA $163E,x
NOSPAWN:
	RTS

SPAWNM:	
	PHX		; jump to this label
	LDX #$07	; load times to go through loop -1
LOOPM:	
	JSR CHKFREE
	DEX
	BPL LOOPM
	PLX
	RTS
CHKFREE:	
	LDY #$07
LOOPFRE:	
	LDA $170B,Y
	BEQ SPAWNEX
	DEY
	BPL LOOPFRE
	RTS
SPAWNEX:
	LDA #$02	; extended sprite number
	STA $170B,y
	PHX
	LDX $15E9
	LDA $D8,X
	CLC
	ADC #$04	; y offset of fireballs
	STA $1715,Y
	LDA $14D4,X
	ADC #$00
	STA $1729,Y
	LDA $E4,X
	CLC
	ADC #$04	; x offset of fireballs
	STA $171F,Y
	LDA $14E0,X
	ADC #$00
	STA $1733,Y
	PLX
	LDA XSPD,X
	STA $1747,Y
	LDA YSPD,X
	STA $173D,Y
	RTS	

;Sprite Routines
	
XDISP:	
	db $00,$10
	db $00,$10
	
YDISP:	
	db $00,$00
	db $10,$10
	
GFX:
	JSL !GetDrawInfo
	LDA $157C,x
	STA $02
	
	LDA $15F6,x
	STA $04
	
	LDX #$00
	
OAM_Loop:
	LDA $00
	CLC
	ADC XDISP,x
	STA $0300,y
	
	LDA $01
	CLC
	ADC YDISP,x
	STA $0301,y
	
	LDA TILEMAP,x
	STA $0302,y
	
	LDA $04
	ORA $64
	STA $0303,y
	
	INY
	INY
	INY
	INY
	
	INX
	CPX #$04
	BNE OAM_Loop
	
	LDX $15E9
	LDY #$02
	LDA #$03
	JSL $81B7B3
	RTS

