incsrc subroutinedefs_xkas.asm

!ram = $18A6
!sprnumber = $BA ;insert number
!hp = $05
!sfx = $28 ;when boss is hit/hurt
!bank = $1DFC

print "INIT ",pc
Init:
	phb : phk : plb
	;lda $7F1234 ;/\/\/\/\/\\\/\///\/\/\/\/\\/\/\/\/\\
	;lda $E4,x : lda $14E0,x : lda $D8,x : lda $14D4,x
	stz $157C,x ;not direction
	stz $C2,x
	lda $1686
	ora #$09
	sta $1686 ;tweaker
	lda $166E,x
	ora #$30
	sta $166E,x
	lda $167A,x
	ora #$02
	sta $167A,x
	lda $7FAB10,x
	and #$04
	beq .notset
	;lda $1602,x
	;bne .monty_init
	;lda #$2B
	;sta $1662,x
	JSL $81ACF9
	lda $148D
	and #$03
	sta $1FD6,x
	lda !ram
	ora #$80
	sta !ram
	lda #$30
	sta $163E,x
	plb : rtl
.notset
	lda #$70
	sta $1504,x ;bobombs?
	lda #$70 ;78
	sta $E4,x
	stz $14E0,x
	lda #$20
	sta $D8,x
	lda #$01
	sta $14D4,x
	plb : rtl
.monty_init
	lda #$40
	sta $1540,x
	plb : rtl
	
print "MAIN ",pc
Main:
	phb : phk : plb
	lda $7FAB10,x
	and #$04
	bne .sub
	lda $1504,x
	beq +
	dec $1504,x
	+ jsr Code
	- plb : rtl
.sub
;	lda $1602,x
;	bne +
	jsr SubCode
	bra -
;	+ jsr MontyMain
;	bra -
Code:
	jsl !SubOffscreenX0
	jsr Graphics
	lda $9D
	bne +
	;lda $7FFFFF
	stz $B6,x
	stz $AA,x
	JSL $81802A
	lda $1528,x
	cmp #!hp
	bcs .kill
	jsr HurtTree
	;jsr Full_Monty
	jsr SpawnBomb
	lda $14
	bne +
	lda !ram ;d7 set = dont spawn vine
	bmi + ;bmi?
	jsr Spawn
	;JSL $81A7DC ;changed, tweaker disable interaction with mario?
	;bcc +
	;JSL $80F606
	.end
	+ rts
.kill 
	lda #$3F
	sta $1887 ;shake ground ?
	lda #$18 ;thunder sfx
	sta !bank
	;jsl $80FA80
	phx
	ldx #$0C ;what the shit man fuck so indie
	- stz $14C8,x
	dex
	bpl -
	plx
	inc $13C6
	lda #$FF
	sta $1493
	lda #$03
	sta $1DFB ;boss defeated music
	rts
Graphics:
	JSL !GetDrawInfo
	lda $154C,x
	bne .hurt
	lda $D1
	and #$F0 ;useless?
	lsr #4
	phx
	tax
	lda .xdisp,x
	plx
	sta $03
	
	;lda $9D ;delete?
	;bne + ;
	phx
	lda $D3
	and #$F0
	lsr #4
	tax
	lda .ydisp1,x
	plx
	sta $04
	lda $D4
	bne +
	lda #$04
	sta $04
	+
	
;lda $7F1234 ;avdhjvahdahd kah dkha kdhda k aha haa
	lda $00
	clc
	adc $03
	sta $0300,y
	lda $01
	clc
	adc $04
	sta $0301,y
.branch
	lda #$04
	sta $0302,y
	lda #$03
	ora $64
	sta $0303,y
	ldy #$00
	lda #$00
	JSL $81B7B3
	rts
.hurt
	lda $14
	lsr #2
	and #$07
	phx
	tax
	lda .movex,x
	clc
	adc $00
	sta $0300,y
	lda .movey,x
	plx
	clc
	adc $01
	adc #$10
	sta $0301,y
	bra .branch
	
.xdisp
db $04,$04,$05,$06
db $08,$08,$09,$0B
db $0C,$0E,$0F,$10
db $12,$13,$14,$14
.ydisp1
db $08,$0A,$0C,$0E
db $10,$10,$10,$10
db $10,$10,$10,$10
db $10,$10,$10,$10

.movex
db $0C,$04,$04,$04
db $0C,$14,$14,$14
.movey
db $00,$00,$FC,$F8
db $F6,$F8,$FC,$00

SubCode: ;vines/wires
	jsl !SubOffscreenX0
	;lda $7F1234
	lda $163E,x
	bne Notyet
	jsr WireGraphics
	lda $9D
	bne +
	lda $C2,x
	cmp #$04
	beq .kill
	;lda $C2,x
	and #$03
	tay
	lda $1540,x
	beq .changestate
	lda .speed,y
	sta $AA,x
	JSL $81801A
	jsr CustomContact
	+ rts
.changestate
	lda .time,y
	sta $1540,x
	inc $C2,x
	rts
.kill
	stz $14C8,x
	lda !ram
	and #$7F
	sta !ram
	rts
.time
db $55,$30,$20,$30
.speed
db $00,$10,$00,$D0 ;changed $d0-->$c0
Notyet:
	jsr .notyetgraphics ;fuck get draw info
;	lda $7F1234
	stz $AA,x
	JSL $81801A
	rts
.notyetgraphics
	JSL !GetDrawInfo
	lda $14
	lsr #2
	and #$03
	phx
	tax
	lda $00
	clc
	adc .xdisp,x
	sta $0300,y ;sta $0240,y
	lda $01
	clc
	adc .ydisp,x
	sec
	sbc #$10 ;changed, because the vine length
	sta $0301,y ;sta $0241,y
	lda .tiles,x
	plx
	sta $0302,y ;sta $0242,y
	lda #$29
	ora $64
	sta $0303,y ;sta $0243,y
	ldy #$00
	tya
	JSL $81B7B3
	rts
.xdisp
db $04,$FE,$06,$F9
.ydisp
db $70,$7D,$86,$71
.tiles
db $2E,$2F,$2E,$2F

WireGraphics:
	JSL !GetDrawInfo
	lda $1FD6,x
	and #$03
	phx
	tax
	lda .offset,x
	sta $04
	lda $14
	lsr #2
	and #$03
	sta $03
	ldx #$05
.loop
	lda $00
	sta $0300,y
	lda $01
	sec
	sbc #$04 ;clipping
	clc
	adc .ydisp,x
	sta $0301,y

	lda $04
	clc
	adc $03
	phx
	tax
	lda.w .tiles,x
	plx
	
	sta $0302,y
	lda #$0F
	ora $64
	sta $0303,y
	iny #4
	dex
	bpl .loop
	lda $03
	and #$01
	tax
	lda $00
	sta $0300,y
	lda $01
	clc
	adc #$5C
	sta $0301,y
	lda .tiles2,x
	plx
	sta $0302,y
	lda #$2F
	sta $0303,y
	ldy #$02
	lda #$06
	JSL $81B7B3
	rts
.ydisp
db $00,$10,$20,$30,$40,$50
.tiles
db $48,$68,$68,$48,$68,$48
db $68,$48,$68,$68,$48,$68
db $68,$48,$48,$68,$48,$48
db $48,$68,$48,$48,$68,$68
.tiles2
db $6A,$6C
.offset
db $00,$06,$0C,$12

Spawn:
	stz $C2,x
	phy
	JSL $81ACF9
	lda $148D
	and #$07 ;changed #$03
	asl #2
	sta $C2,x
	lda $1528,x
	and #$07
	asl A
	phx
	tax
	rep #$20
	lda.w .tablething,x
	sta $00
	sep #$20
	plx
	jmp ($0000)
	
	.four
	jsr .subroutine ;oh shit nigger what are you doin
	inc $C2,x
	.three
	jsr .subroutine
	inc $C2,x
	.two
	jsr .subroutine
	inc $C2,x
	.one
	jsr .subroutine
	ply
	rts
.tablething
dw Spawn_one,Spawn_two,Spawn_three,Spawn_four
dw Spawn_four,Spawn_four,Spawn_four,Spawn_four
.subroutine
	phx
	JSL $82A9DE ;spr=y, main=x
	bmi +
	lda #$01
	sta $14C8,y
	phx
	tyx
	lda #!sprnumber
	sta $7FAB9E,x
	plx
	;lda $7F1234
	lda $C2,x
	phx
	tax
	lda .xlo,x
	sta $00E4,y
	;lda .xhi
	lda #$00
	sta $14E0,y
	plx
	lda #$B0 ;$a0 changed ;possibly draw another tile on each vine and move back up?
	sta $00D8,y
	lda #$00
	sta $14D4,y
	sta $1602,y
	phx
	tyx
	JSL $87F7D2
	JSL $8187A7
	lda #$0C ;8|4
	sta $7FAB10,x
	plx
	+ plx : rts
.xlo ;10-e0
db $40,$60,$80,$A0
db $60,$C0,$D0,$E0
db $50,$70,$B0,$C0
db $30,$90,$B0,$D0

db $C0,$80,$50,$A0
db $90,$40,$B0,$E0
db $A0,$D0,$30,$40
db $D0,$B0,$50,$20

.xhi
db $00

CustomContact:
.clipping
	stz $0F
	lda #$00 ;xdisp
	bpl +
	dec $0F
	+ clc
	adc $E4,x
	sta $04
	lda $14E0,x
	adc $0F
	sta $0A
	lda #$10 ;width
	sta $06
	stz $0F
	lda #$00 ;ydisp
	bpl +
	dec $0F
	+ clc
	adc $D8,x
	sta $05
	lda $14D4,x
	adc $0F
	sta $0B
	lda #$70 ;length
	sta $07
	JSL $83B664 ;mario clipping
	JSL $83B72B ;check
	bcc .no_contact
	JSL $80F5B7
.no_contact
	rts
HurtTree:
	phx
	JSL $83B6E5
	phx
	ldx #$0C
.loop
	dex
	bmi .done
	lda $14C8,x
	beq .loop
	txa
	cmp $01,s
	beq .loop
	JSL $83B69F
	JSL $83B72B
	bcc .loop
	lda $14C8,x
	cmp #$09
	bcc .loop
	txy ;new spr
	plx ;tree
	lda #$00
	sta $14C8,y ;kill bobomb
	inc $1528,x
	lda #$3F
	sta $1887 ;shake ground ?
	sta $154C,x ;hurtframe counter
	lda #!sfx
	sta !bank
	phx
	;lda $7F1234 ;avdhjvahdahd kah dkha kdhda k aha haa
	.done
	plx
	
	
	
	
	
	plx
	rts
SpawnBomb:
	phx
	lda $1504,x
	bne .return
	lda $14
	and #$FF ;change? 3f
	ora $9D
	bne .return
	lda $7F1234
	lda #$70
	sta $1504,x
	JSL $82A9DE
	bmi .return
	tyx
	lda #$01
	sta $14C8,x
	lda #$0D ;bobomb
	sta $9E,x
	JSL $87F7D2
	phx
	JSL $81ACF9
	lda $148D
	and #$01
	tax
	lda .table,x
	plx
	sta $E4,x
	lda #$00
	sta $14E0,x
	sta $14D4,x
	lda #$E0 ;changed?
	sta $D8,x
;	lda $7F1234
	;lda $D1 ;change ;delete ;$7f1234 etc etc
.return
	plx
	rts
.table
db $20,$E0

Full_Monty:
	pha ;
;	lda $7F1234 ;delete
	lda !ram ;
	pla ;
SpawnMonty:
;	lda $7F1234
	bit !ram
	bvs .return
	lda !ram
	ora #$40
	sta !ram
;spawn monty sprite

	rts
.return
	rts
MontyMain:
	jsl !SubOffscreenX0

