;*********************************************************************
;	mario kart << Battle test >>
;					Programed by H.Yajima
;*********************************************************************
		INCLUDE	../../SFX/RP5C77
		INCLUDE	../../SFX/RP5A22
		INCLUDE	../../DSP/D77C25
		INCLUDE	../../../kimura/join/work.def
		INCLUDE	../../../kimura/join/buffer.def
		INCLUDE	../DEF/object.def
		glb	Init_BTmode
		glb	Set_BTmode_A,Set_BTmode_B
		ext	sound_balloon
;---------------------------------------------------------------------
;
;	_status		xx** xxxx xxxx xxxx
;			  |+-------------------	消去ビット
;			  +-------------------- 存在ビット
;---------------------------------------------------------------------
		COMN
work		DS	2
		EXTEND
objdata	SECT	REL
		mem16
		idx16
;#####################################################################
;		バトルモード
;#####################################################################
Init_BTmode	lda	#1
		sta	!battle_HP+0
		sta	!battle_HP+2
		rts
;----------------------------------------------------------------------
Set_BTmode_A	jmp	Check_spin
Set_BTmode_B	jmp	Check_spin
;*********************************************************************
;		スピン回数チェック
;*********************************************************************
Check_spin	ldx	<screen_register
		ldy	<player_index,x
		lda	!_effect_flag,y
;- - - - - - - - - - - - - - - - - - - - - - - - 
;	スピンサウンドのセット
;- - - - - - - - - - - - - - - - - - - - - - - - 
		bit	#effect_spinSE
		beq	skip$
		and	#(effect_spinSE^0ffffh)
		sta	!_effect_flag,y
		txa	
		jsl	>sound_balloon
		bra	exit$
;- - - - - - - - - - - - - - - - - - - - - - - - 
;	スピン回数のチェック
;- - - - - - - - - - - - - - - - - - - - - - - - 
skip$		bit	#effect_spin
		beq	exit$
		and	#(effect_spin^0ffffh)
		sta	!_effect_flag,y
;- - - - - - - - - - - - - - - - - - - - - - - -
		phy
		jsr	check_HP
		plx
		bcc	exit$
		lda	#effect_spinSE		; スピンサウンドセット
		ora	<_effect_flag,x
		sta	<_effect_flag,x
;- - - - - - - - - - - - - - - - - - - - - - - -
exit$		rts



;----------------------------------------------------------------------
check_HP	ldy	!test_data,x
		lda	#2
		sta	<0
loop$		ldx	!0,y
		beq	exit$
		iny
		iny
		lda	<_status,x
		and	#02000h			; 存在ビット
		beq	skip$
		stx	<2
		bra	loop$
skip$		dec	<0
		bra	loop$
;- - - - - - - - - - - - - - - - - - - - - - - -
exit$		lda	<0
		bmi	end$
		ldx	<2
		lda	#01000h			; erase!
		sta	<_status,x
;	
		lda	<0
		ldx	<screen_register
		sta	!battle_HP,x
		sec				; <- 風船がわれた！
		rts
end$		clc				; <- 風船はわれない!
		rts
;----------------------------------------------------------------------
test_data	dw	HP_p1,HP_p2
HP_p1		dw	pole_r0,pole_r1,pole_r2,0
HP_p2		dw	pole_r3,pole_r4,pole_r5,0
;----------------------------------------------------------------------
;*********************************************************************
;		? ブロックのかきかえ！
;*********************************************************************
		glb	Init_question,DMA_question
;----------------------------------------------------------------------
Init_question	
		stz	!question_pointer
		stz	!question_flag
		rts
;----------------------------------------------------------------------
question_char	db	0c0h,0cch,0c8h,0c4h
;----------------------------------------------------------------------
DMA_question	lda	!question_flag
		cmp	#30
		bcc	exit$
		ldx	!question_pointer
		lda	>Question_buffer+0,x
		cmp	#0ffffh
		beq	end$
		and	#00ffh
		tax
		lda	>question_char,x
		tay
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - 
		ldx	!question_pointer
		lda	>Question_buffer+1,x
		inx
		inx
		inx
		stx	!question_pointer
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - 
		stz	!Screen_step
		sta	!Screen_address+0
		tax
		clc
		adc	#080h
		pha				;>>
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - 
		SEP	#00100000B
		MEM8
		tya
		sta	>BGcheck_buffer+00H,x
		sta	!Screen_write
		inc	a
		sta	>BGcheck_buffer+01H,x
		sta	!Screen_write
		inc	a
		ply				;<<
		sty	!Screen_address
		sta	>BGcheck_buffer+80H,x	
		sta	!Screen_write
		inc	a
		sta	>BGcheck_buffer+81H,x
		sta	!Screen_write
		REP	#00100000B
		MEM16		
exit$		rtl
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - 
end$		stz	!question_flag
		stz	!question_pointer
		rtl
;----------------------------------------------------------------------
		END
