;*********************************************************************
;	mario kart << sprite shadow >>
;					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
;----------------------------------------------------------------------
		EXT	subst,disp_A_shadow,disp_B_shadow
		EXT	magna,ret,zoom_size
		EXT	magna_shadowA,magna_shadowB
		EXT	tetre16,tetre16_v,tetre8,tetre8_v
		EXT	monon16,monon16_v,monon8,monon8_v
		EXT	shadow_limit
		EXT	param_screenA,param_screenB
		EXT	H_center,V_mycar
		GLB	Set_shadow,Init_shadow
		EXT	Call_bank1
		ext	Set_objcountX
;
		ext	max_distance
;----------------------------------------------------------------------
		EXTEND
objprog	SECT	REL
		mem16
		idx16
;*********************************************************************
;		Initial shadow
;*********************************************************************
Init_shadow	
		ldx	#0	
		ldy	#big_shadow		; デカシャドウセット
		lda	#00h
		jsr	init_set_shadow
		lda	#7000h
		ldy	#big_shadow
		jsr	init_set_shadow
		ldy	#mini_shadow		; チビシャドウセット
		lda	#0
		jsr	init_set_shadow
		ldy	#mini_shadow
		lda	#07000h	
		jmp	init_set_shadow

;----------------------------------------------------------------------
big_shadow	dw	5f70h,3aebh	; でかい影
		dw	5f78h,3aech
		dw	5f80h,3aech
		dw	5f88h,6aebh
		dw	0		; end code
;- - - - - - - - - - - - - - - - - - - 
mini_shadow	DW	05c78H,03AEBH	; チビの影
		DW	05c80H,07AEBH
		DW	0e000h,0
		DW	0e000h,0
		dw	0		; end code
;- - - - - - - - - - - - - - - - - - - - - - 
init_set_shadow	sta	<0			; screen offset V
loop$		lda	!0,y			; H,V position
		beq	exit$
		clc
		adc	<0
		sta	>mykart_shadow1+0,x
		lda	!2,y			; character
		sta	>mykart_shadow1+2,x
		iny
		iny
		iny
		iny
		inx
		inx
		inx
		inx
		bra	loop$
exit$		rts





;*********************************************************************
;	ふまれたときのカゲ
;*********************************************************************
	if	0
humare_shadow

		SEP	#00100001B
		MEM8
		lda	<_posH_A,x
		cpx	#player_r0
		beq	skip$
		lda	<_posV_B,x
skip$		sbc	#80h
		sta	<0

		ldx	!mykart_buffer,y
		ldy	<sprite_count
;- - - - - - - - - - - - - - - - - - - - - - - - 
		lda	>7f0000h+00,x
		clc
		adc	<0
		sta	!sprite_H+00h,y
		lda	>7f0000h+04,x
		clc
		adc	<0
		sta	!sprite_H+04h,y
		lda	>7f0000h+08,x
		clc
		adc	<0
		sta	!sprite_H+08h,y
		lda	>7f0000h+12,x
		clc
		adc	<0
		sta	!sprite_H+12h,y

		lda	>7f0000h+01,x
		sta	!sprite_V+0,y
		lda	>7f0000h+05,x
		sta	!sprite_V+4,y
		lda	>7f0000h+09,x
		sta	!sprite_V+8,y
		lda	>7f0000h+13,x
		sta	!sprite_V+12,y
		REP	#00100000B
		MEM16
;- - - - - - - - - - - - - - - - - - - - - - - - 
		lda	>7f0000h+2+00,x
		sta	!sprite_C+0,y
		lda	>7f0000h+2+04,x
		sta	!sprite_C+4,y
		lda	>7f0000h+2+08,x
		sta	!sprite_C+8,y
		lda	>7f0000h+2+12,x
		sta	!sprite_C+12,y
;- - - - - - - - - - - - - - - - - - - - - - - - 
		tya
		clc
		adc	#10h
		sta	<sprite_count
		rts

		endif

;*********************************************************************
;		Set shadow
;*********************************************************************
mykart_buffer	dw	mykart_shadow1,mykart_shadow2
		dw	mykart_shadow1s,mykart_shadow2s
prog_shadow	DW	shadow_Ascr,shadow_Bscr
FR_select	DW	FR_0,FR_1,FR_2,FR_3
FR_0		DW	player_r0,player_r1,0
FR_1		DW	player_r2,player_r3,0
FR_2		DW	player_r4,player_r5,0
FR_3		DW	player_r6,player_r7,0
;--------------------------------------------------------------------
;		可変の影　
;--------------------------------------------------------------------
exit_shadow	rts
;- - - - - - 
Set_shadow	lda	!over_timer
		bne	exit_shadow
		ldy	<screen_register
		lda	!obj_count_A,y		;ラップ表示か？
		cmp	#20h
		bcs	exit_shadow
		lda	!player_index,y		;マップモードか？
		bpl	mykart_shadow
		bit	#04000h
		bne	exit_shadow
		beq	enemy_shadow
;- - - - - - - - - - - - - - - - - - - - - - -
;マイカー用影セット
;- - - - - - - - - - - - - - - - - - - - - - -
mykart_shadow
		cpy	!frame_part		;２フレームに１回
		bne	enemy_shadow
		tax
;- - - - - - - - - - - - - - - - - - - - - - -
		lda	!ending_flag		; エンディング？
		bne	enemy_shadow
;- - - - - - - - - - - - - - - - - - - - - - -
		lda	<_fall,x
		bne	enemy_shadow
;- - - - - - - - - - - - - - - - - - - - - - -
	;	lda	<_dmindex,x		; ふまれチェック
	;	beq	hight$
	;	jsr	humare_shadow
	;	bra	enemy_shadow
;- - - - - - - - - - - - - - - - - - - - - - -
hight$		lda	<_situationZL+1,x	; 高さチェック
		beq	enemy_shadow
		cmp	#1800h
		bcs	enemy_shadow		; 1< Z <1800H ON
;- - - - - - - - - - - - - - - - - - - - - - -
		lda	<_sunder_timer,x
		beq	skip$
		iny				; チビセット
		iny
		iny
		iny
skip$		ldx	!mykart_buffer,y	; ＯＡＭセット
		ldy	<sprite_count
		lda	#10h-1
		mvn	#dbank_7f,#dbank_00	; 0bank restore
		sty	<sprite_count
;- - - - - - - - - - - - - - - - - - - - - - -
;敵車用影セット
;- - - - - - - - - - - - - - - - - - - - - - -
enemy_shadow	LDA	<frame_counter
		AND	#00011B
		ASL	A
		TAY
		LDX	!FR_select,Y
		LDA	!0,X
loop_shadow	STA	<register
		STZ	<attribute
		PHX			;>>
		ldx	<screen_register
		cmp	<player_index,x	; player r0,player_r1 <check>
		BEQ	skip_shadow
;- - - - - - - - - - - - - - - - - - - - - - -
calc_shadow	TXY
		LDX	!prog_shadow,Y
		JSR	(!0,X)
;- - - - - - - - - - - - - - - - - - - - - - -
skip_shadow	PLX			;<<
		INX
		INX
		LDA	!0,X
		BNE	loop_shadow
;- - - - - - - - - - - - - - - - - - - - - - -
;ジュゲム用影コピー
;- - - - - - - - - - - - - - - - - - - - - - -
jugem_shadow_copy
;- - - - - - - - - - - - - - - - - - - - - - -
		lda	!course_type		;おばけ谷？
		bne	exit$
;- - - - - - - - - - - - - - - - - - - - - - -
		ldy	<screen_register	;フレームわり
		cpy	!frame_part
		bne	exit$
;- - - - - - - - - - - - - - - - - - - - - - -
		ldx	!jugem_switch,y		;表示中？
		lda	<0,x
		and	#00ffh
		cmp	#0055h
		beq	exit$
;- - - - - - - - - - - - - - - - - - - - - - -
		ldx	!jugem_shadow,y		;コピー表示！
		ldy	<sprite_count
		lda	#10h-1
		mvn	#dbank_00,#dbank_00
		sty	<sprite_count
;- - - - - - - - - - - - - - - - - - - - - - -
exit$	
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;障害物用 影
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
		ldx	!course_type
		jmp	(!course_shadow,x)
no_shadow	rts
;- - - - - - - - - - - - - - - - - - - - - - -
ds_shadow	ldx	<SEQ_register
		jmp	(!SEQ_shadow,x)
;- - - - - - - - - - - - - - - - - - - - - - -
ds_1p		lda	#11B			; ( カゲ４つ ) ＧＰ用
		bra	ds_skip

		
ds_2p		
		ldx	<screen_register	; フレームわり！
		cpx	!frame_part		
		beq	ds_entry
		rts
ds_entry	lda	<frame_counter
		and	#10B
		bra	ds_kage	
ds_skip		and	<frame_counter
		asl	a
ds_kage		tax
		lda	!zusin_index,x
		ldx	<screen_register
		clc
		adc	!register_add,x
		sta	<register
		ldx	#prog_zusin
		jmp	(!0,x)
;- - - - - - - - - - - - - - - - - - - - - - -
ds_TM						; VS / タイムアタック用
ds_VS
		ldy	!frame_part		; ２フレームに１回
loop$		lda	!zusin_index,y
		beq	exit$
		ldx	<screen_register
		clc
		adc	!register_add,x
		sta	<register
		ldx	#prog_zusin
		phy			;>>
		jsr	(!0,x)
		ply			;<<
		iny
		iny
		iny
		iny
		bra	loop$
;- - - - - - - - - - - - - - - - - - - - - - -
exit$		rts
;- - - - - - - - - - - - - - - - - - - - - - -

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
register_add	dw	0,40h
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
zusin_index	dw	pole_r0,pole_r1
		dw	pole_r2,pole_r3
		dw	0,0
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
prog_zusin	dw	disp_check,magna,zoom_size
		dw	shadow_3,shadow_5,shadow_5,shadow_6
		dw	shadow_8,shadow_9,shadow_9,shadow_A
		dw	shadow_A,shadow_A,shadow_A,shadow_A
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
course_shadow	dw	no_shadow,no_shadow,no_shadow,no_shadow
		dw	no_shadow,no_shadow,ds_shadow,no_shadow	

SEQ_shadow	dw	ds_2p
		dw	ds_1p
		dw	ds_1p
		dw	ds_VS
		dw	ds_TM
		dw	ds_TM
		dw	no_shadow
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
disp_check	phx
;- - - - - - - - - - - - - - - - - - - - - - - -
		ldx	<register
;高さチェック
		lda	<_situationZL+1,x
		beq	clear$
;- - - - - - - - - - - - - - - - - - - - - - - -
;距離範囲オーバーチェック
		ldy	<screen_register
		bne	Bscreen_skip
		lda	<_distance_A,x
		cmp	#max_distance
		bcs	clear$		;clc
		sta	<size
		lda	<_shadow_A,x
		ldy	<_posH_A,x
		bra	skip$
;画面範囲オーバーチェック
skip$		sta	<position_V	;W 0FEE0 < Y < FFA0
		adc	#00120H
		cmp	#000C0H
		bcs	clear$		;clc
		tya
		sta	<position_H	; 0FEF0 < X < 0010
		adc	#00110H
		cmp	#00120H
		bcs	clear$
		plx
exit$		INX
		INX
		JMP	(!0,X)
clear$		plx
		rts
;- - - - - - - - - - - - - - - - - - - - - - - -
Bscreen_skip
		lda	<_distance_B,x
		cmp	#max_distance
		bcs	clear$		;clc
		sta	<size
		lda	<_shadow_BX,x
		ldy	<_posH_BX,x
;- - - - - - - - - - - - - - - - - - - - - - - -
;画面範囲オーバーチェック
skip$		sta	<position_V	;W 0FEE0 < Y < FFA0
		adc	#00120H-70H
		cmp	#000C0H
		bcs	clear$		;clc
		tya
		sta	<position_H	; 0FEF0 < X < 0010
		adc	#00110H
		cmp	#00120H
		bcs	clear$
		plx
exit$		INX
		INX
		JMP	(!0,X)
clear$		plx
		rts
;======================================================================
jugem_shadow	dw	200h+1f0h,420h+1f0h
jugem_switch	dw	400h+1fh,620h+1fh
;======================================================================


;#####################################################################
;		影
;#####################################################################
;*********************************************************************
;		影データ
;*********************************************************************
shadow_Ascr	DW	disp_A_shadow,magna_shadowA,shadow_char
shadow_Bscr	DW	disp_B_shadow,magna_shadowB,shadow_char
;--------------------------------------------------------------------
shadow_char	DW	shadow_0,shadow_1,shadow_2,shadow_3
		DW	shadow_4,shadow_5,shadow_6,shadow_7
		DW	shadow_8,shadow_9,shadow_A,shadow_0
;--------------------------------------------------------------------
shadow_0	DW	tetre8_v	; (0) OBJ address pointer
		DW	position_0	; (2) OBJ position pointer
		DW	shadow_c0	; (4) OBJ character
		DW	1
shadow_1	DW	tetre8_v	; (0) OBJ address pointer
		DW	position_1	; (2) OBJ position pointer
		DW	shadow_c1	; (4) OBJ character
		DW	0
shadow_2	DW	tetre8_v	; (0) OBJ address pointer
		DW	position_2	; (2) OBJ position pointer
		DW	shadow_c2	; (4) OBJ character
		DW	-1
shadow_3	DW	tetre8_v	; (0) OBJ address pointer
		DW	position_3	; (2) OBJ position pointer
		DW	shadow_c3	; (4) OBJ character
		DW	-1
;--------------------------------------------------------------------
shadow_4	DW	tetre8_v	; (0) OBJ address pointer
		DW	position_4	; (2) OBJ position pointer
		DW	shadow_c4	; (4) OBJ character
		DW	-3
shadow_5	DW	tetre8_v	; (0) OBJ address pointer
		DW	position_5	; (2) OBJ position pointer
		DW	shadow_c5	; (4) OBJ character
		DW	-2
shadow_6	DW	tetre8_v	; (0) OBJ address pointer
		DW	position_6	; (2) OBJ position pointer
		DW	shadow_c6	; (4) OBJ character
		DW	-1
shadow_7	DW	monon8_v,3AEDH,0
shadow_8	DW	monon8_v,3AEDH,0
shadow_9	DW	monon8_v,3AEDH,0
shadow_A	DW	ret			; erase shadow
shadow_B	DW	ret
;--------------------------------------------------------------------
shadow_c0	
shadow_c1
shadow_c2	DW	3AEBH,3AECH,3AECH,6AEBH
shadow_c3
shadow_c4
		DW	3AEBH,3AECH,6AEBH,6AEBH
shadow_c5
shadow_c6
shadow_c7
shadow_c8	DW	3AEBH,6AEBH,6AEBH,6AEBH
;--------------------------------------------------------------------
		;-------(posV)-(posH)-
position_0	DW	0FFF8H,0FFF0H
		DW	0FFF8H,0FFF8H
		DW	0FFF8H,00000H
		DW	0FFF8H,00008H
position_1	DW	0FFF8H,0FFF2H
		DW	0FFF8H,0FFFAH
		DW	0FFF8H,0FFFEH
		DW	0FFF8H,00006H
position_2	DW	0FFF8H,0FFF3H
		DW	0FFF8H,0FFFAH
		DW	0FFF8H,0FFFEH
		DW	0FFF8H,00005H
position_3	DW	0FFF8H,0FFF4H
		DW	0FFF8H,0FFFCH
		DW	0FFF8H,00004H
		DW	0FFF8H,00004H
position_4	DW	0FFF8H,0FFF7H
		DW	0FFF8H,0FFFCH
		DW	0FFF8H,00001H
		DW	0FFF8H,00001H
position_5	
position_6	DW	0FFF8H,0FFF8H
		DW	0FFF8H,00000H
		DW	0FFF8H,00000H
		DW	0FFF8H,00000H
position_7	
position_8	DW	0FFF8H,0FFF9H
		DW	0FFF8H,0FFFFH
		DW	0FFF8H,0FFFFH
		DW	0FFF8H,0FFFFH
;--------------------------------------------------------------------
		END
