incsrc subroutinedefs_xkas.asm

!value = $FF
!yxppccct = $03

print "INIT ",pc
	stz $C2,x
	stz $1540,x
	lda.b #!value
	sta $1558,x
	rtl
print "MAIN ",pc
	phb
	phk
	plb
	;lda #$01 : sta $19
	jsr Code
	plb
	rtl
Code:
	jsl !SubOffscreenX0
	jsr Graphics
	lda $9D
	bne .return
	;lda $7f1235
	lda $1558,x
	beq Move
	cmp.b #!value/8
	bcc .return
	lda $94
	sta $E4,x
	lda $95
	sta $14E0,x
	lda #$80
	sta $D8,x
	lda #$01
	sta $14D4,x
.return
	rts
CheckThingy:
	lda $D8,x
	cmp #$8C
	bcc +
	stz $AA,x
	+ rts
Move:
	jsr CheckThingy
	lda $C2,x
	cmp #$03
	beq .done
	;and #$03
	tay
	lda $1540,x
	beq .changestate
	lda .speed,y
	sta $AA,x
	jsr CheckThingy
	JSL $81801A
	JSL $81A7DC|$800000
	bcc +
	JSL $80F5B7|$800000
	+ rts
.done
	stz $C2,x
	lda $7F1236
	lda.b #!value
	sta $1558,x
	;stz $1540,x
	rts
.changestate
	lda .time,y
	sta $1540,x
	inc $C2,x
	rts
.time
db $10,$20,$10,$20
.speed
db $20,$E0,$20,$E0
Graphics:
	JSL !GetDrawInfo
	lda $1558,x
	beq +++
	;bcc  +
	cmp.b #!value/6
	bcc .drawdirt
;draw blank tile ??
	;+
	-- lda #$28
	bra .label
+++ 
	lda $AA,x
	beq --
	jmp .drawroot
.tile
db $4E,$6E
.drawdirt
	lda $14
	lsr #3
	and #$01
	sta $03
	phx
	tax
	lda .tile,x
	plx
.label
	sta $0302,y
	lda $00
	sta $0300,y
	lda $01
	sta $0301,y
	lda #!yxppccct
	ora $64
	sta $0303,y
	lda #$00
.thispart
	ldy #$02
	JSL $81B7B3|$800000
	rts
.drawroot
	phx
	ldx #$01
.loop
	lda $00
	sta $0300,y
	lda $01
	clc
	adc .ydisp,x
	sta $0301,y
	lda .tiles,x
	sta $0302,y
	lda #!yxppccct
	ora $64
	sta $0303,y
	iny #4
	dex
	bpl .loop
	plx
	lda #$01
	bra .thispart
.tiles
db $2A,$2C
.ydisp
db $00,$10

