;******************* name.asm *************************
			extend
;-----------------------------------------------------
			include		../join/rp5c77
			include		../join/buffer.def
			include		../join/rp5a22
			include     ../join/work.def
			include		../join/label.def
;-----------------------------------------------------
			glb		W_SL_init,W_SL_main,W_SL_nmi
			glb		Back_up_set,Backup_Sam_Check
			glb		Back_up_clear,Set_4bit_mode1
;
			ext		Set_DMA,PPU_INT_SET
			ext		KEY_CHECK,Trigger_sound_1
			ext		BGM_fade_out,X_inx,Y_iny
			ext		Set_DMA,Rank_Check_sum
			ext		OBJ_ERASE_SET
;---------------------------------------------------
address			equ		60h			;3byte
Color_set		equ		63h			;2byte
waku_counter	equ		67h			;2byte
button_TG       equ     6ah         ;4byte
Old_world_number	equ		6eh
Back_address	equ		70h
;
move_counter	equ		80h			;3byte
;
Game_select.flag	equ		85h
erase_set_flag		equ		7bh
;----------------------------------------------------
msbdat			equ		400h
oamdat			equ		200h	
;----------------------------------------------------
back_up_address	equ		3067f2h
Back_up_Sum		equ		3067f0h
Kinoko_Cup		equ		3067f2h
Flower_Cup		equ		3067f3h
Star_Cup		equ		3067f4h
Special_Cup		equ		3067f5h
Back_up_zero	equ		306000h
;
Rank_cmp		equ		19fch
Sum_cmp			equ		19feh
;-----------------------------------------------------
bank85      		sect    rel         ;(PBR=85)
;========================================================
;********************************************************
;				INITIAL ROUTINE
;********************************************************
;========================================================
W_SL_init		equ		$
				phb
				phk
				plb
				mem8
				idx8
				sep		#00110000b
;
				JSL		>PPU_INT_SET			;ppu&oam initial set.
				JSR		WORLD_PPU
				JSR		WORLD_TENSOU
;
				mem16
				idx16
				rep		#00110000b
				plb
				RTL
;========================================================
;********************************************************
;				MAINE ROUNTINE
;********************************************************
;========================================================
W_SL_main		equ		$
				phb
				phk
				plb
;
				JSR     KEY_CHECK
				JSL		>WAKU_MOVE.SET
				JSL		>Cup_change.set
				JSL		>NEXT_SET
;
				plb
				RTL
;========================================================
;********************************************************
;				NMI wari komi.			  
;********************************************************
;========================================================
W_SL_nmi		equ		$
				phb
				phk
				plb
;<<<<<<<<<<<<<< カラーイレースセット >>>>>>>>>>>>>>>>>>
;
				ldy		#0
				lda     Old_world_number
				asl		a
				tax
				JSL		>MOJI_Set_1
;<<<<<<<<<<<<<<<<< カラーセット >>>>>>>>>>>>>>>>>>>>>>>
				ldy		#0002
				lda     world_number
				asl		a
				tax
				JSL		>MOJI_Set_1
;
				plb
				rtl
;========================================================
;********************************************************
;				INITIAL ROUTINE
;********************************************************
;========================================================
WORLD_TENSOU   	equ		$
;<<<<<<<<<<<<<<< BG_1　ＣＧＸ>>>>>>>>>>>>>>>>>>>>>>
				mem8
				idx8
				ldx		#24h
				JSR		Set_DMA
;<<<<<<<<<<<<<<< イニシャル転送 >>>>>>>>>>>>>>>>>>>>
				JSL		>WORLD_TENSOU_1
				rts
;***********************************************************
;					PPU&WORK INITIAL SET
;***********************************************************
WORLD_PPU		equ		$
;<<<<<<<<<<<<<<< ゼロページクリアー >>>>>>>>>>>>>>>>>>
				mem8	
				idx8
;
				lda		world_number
				sta		<Old_world_number
;<<<<<<<<<<<<<<<<<< PPU SET >>>>>>>>>>>>>>>>>>>>>>>>>
				lda		#00000001b
				sta		Screen_size		;BG mode1 set.
;
				lda		#00010001b
				sta		Through_screen		;TM
;
				stz     Sprite_size
;
				lda		#00100100b
				sta		Screen_bank
;
				lda		#00000000b
				sta		Screen_segment
;
				lda     #10000000b
				sta     Screen_step
				rts
;==========================================================
bank84			sect		rel
;==========================================================
;***********************************************************
;					イニシャルセット
;***********************************************************
WORLD_TENSOU_1	equ		$
				phb
				phk
				plb
;<<<<<<<<<<<<<<<<<<<<<< CG_SET >>>>>>>>>>>>>>>>>>>>>>>>>
			 	idx16		        		;8bit mode.
			 	rep		#00010000b
;
			 	lda		#00000000b			
				sta		Color_address
;
      		 	ldx		#0
loop_col	 	lda		>W_select_col,x
			 	sta		Color_write
			 	inx
        	 	lda     >W_select_col,x
			 	sta     Color_write
			 	inx
			 	cpx		#200h
			 	bne		loop_col
;<<<<<<<<<<<<<<<<<< SC_1 >>>>>>>>>>>>>>>>>>>>>>>>>
				mem16
       			idx16
				rep		#00110000b
;<<<<<<<<<<<<<< 4 BIT データーに変換 >>>>>>>>>>>>>>
				lda     #00000000b				;address set.
				sta     Screen_address
				ldx		#0
				JSR		Set_4bit_mode
;
;<<<<<< ５０ｃｃの時スペシャルかどうかのチェック >>>>>
				lda		game_level
				bne		Check_adlut				;100ccクラス?;yes-->Set_msb
				lda		world_number
				cmp		#0003
				bne		Moji_set
				stz		world_number
				stz		<Old_world_number
				jmp		Moji_set
;<< １００ｃｃの時総てゴールドではない時スペシャルノ時 >>>>>
Check_adlut		lda		world_number
				cmp		#0003
				bne		Moji_set
;-----(総てのゴールドカップチェック)----
				lda		>Kinoko_Cup
				and		#0003h
				cmp		#0001
				bne		Reset_world
				lda		>Flower_Cup
				and		#0003h
				cmp		#0001
				bne		Reset_world
				lda		>Star_Cup
				and		#0003h
				cmp		#0001
				bne		Reset_world
				jmp		Moji_set
Reset_world		stz		world_number
				stz		<Old_world_number
;<<<<<<<<<<<<<<< 文字データーセット >>>>>>>>>>>>>>>>>
Moji_set		ldx		#0
				lda		#2400h
				sta     Screen_address
;
loop_back		lda		>7fef00h,x
				clc
				adc		#0f440h
back_set		sta     Screen_write
				inx
				inx
				cpx		#0800h
				bne		loop_back
;
				ldy		#0000
				ldx		#0000					;kinoko cup
				JSR		MOJI_Set
;
				ldy		#0000
				ldx		#0002					;kinoko cup
				JSR		MOJI_Set
;
				ldy		#0000
				ldx		#0004					;kinoko cup
				JSR		MOJI_Set
;------(スペシャルのチェック、セット)----
				lda		game_level
				beq		WAKU_set				;５０ccクラス?;yes-->Set_msb
;
;-----(総てのゴールドカップチェック)----
				lda		>Kinoko_Cup
				and		#0003h
				cmp		#0001
				bne		Stop_special
				lda		>Flower_Cup
				and		#0003h
				cmp		#0001
				bne		Stop_special
				lda		>Star_Cup
				and		#0003h
				cmp		#0001
				bne		Stop_special
;
				ldy		#0000
				jmp		Clare_special
Stop_special	ldy     #0004
Clare_special	ldx		#0006					;special cup
				JSR		MOJI_Set
;<<<<<<<<<<<<<<<<< ワクデーターセット >>>>>>>>>>>>>>>>
WAKU_set		ldy		#0000
				ldx		#0000
				mem16
				rep		#00100000b
loop_waku_0		lda		WAKU,x
				cmp		#0ffffh
				beq		Check_waku
				sta		oamdat,y
				JSR		Y_iny_set
				inx
				inx
				jmp		loop_waku_0
;
Check_waku		JSR		WAKU_change_set
;<<<<<<<<<<<<< トロフィーデーターセット >>>>>>>>>>>>>>>>
Trophy_setdata	lda		game_level
				bne		Set_special				;５０ccクラス?;yes-->Set_msb
;
				ldx		#0
				ldy		#00a0h
trophy_posi_set	lda		trophy_place,x				;トロフィーポジションセット.
				sta		oamdat,y
				inx
				inx
				JSR     Y_iny_set
				cpy		#00ach
				bne		trophy_posi_set
;
				ldx		#0
				ldy		#00a2h
Loop_50cc_cup	phx
				JSR		Check_Cup
				jsr		Trophy_set				;kinoko cup
				plx
				inx
				JSR     Y_iny_set
				cpx		#0003h
				bne		Loop_50cc_cup			
				jmp		color_set
;------(スペシャルのチェック、セット)----
Set_special		ldy		#00a0h
				ldx		#0
trophy_posiset1	lda		trophy_place1,x				;トロフィーポジションセット.
				sta		oamdat,y
				inx
				inx
				JSR     Y_iny_set
				cpy		#00b0h
				bne		trophy_posiset1
;
				lda		game_level
				cmp		#0004
				beq		Set_150cc_trophy
;
				ldx		#0
				ldy		#00a2h
Loop_100cc_cup	phx
				JSR		Check_Cup1
				jsr		Trophy_set1				;kinoko cup
				plx
				inx
				JSR     Y_iny_set
				cpx		#0004h
				bne		Loop_100cc_cup	
				jmp     color_set		
;
Set_150cc_trophy
;
				ldx		#0
				ldy		#00a2h
Loop_150cc_cup	phx
				JSR		Check_Cup2
				jsr		Trophy_set2				;kinoko cup
				plx
				inx
				JSR     Y_iny_set
				cpx		#0004h
				bne		Loop_150cc_cup	
;<<<<<<<<<<<<<<<<< モジ　カラー書き換え >>>>>>>>>>>>>>>>
color_set		ldy     #0002
				lda     world_number
				asl		a
				tax
				JSR		MOJI_Set
;<<<<<<<<<<<<<<<<<< クラスセット >>>>>>>>>>>>>>>>>>>>>>> 
				lda		#1870h
				sta		oamdat+180h
				lda		#366ah
				sta     oamdat+182h
;
				lda		game_level
				tax
				ldy		#0
				lda		Class_select,x
				tax
loop_class		lda		!0,x
				inx
				inx
				sta		oamdat+186h,y
				JSR     Y_iny_set
				cmp		#00e5h
				beq		no_inc
				inc		a
no_inc			sta		oamdat+186h,y
				JSR     Y_iny_set
				cpy		#0050h
				bne		loop_class
;
				ldy		#0			
				lda		#1058h
loop_class1		sta		oamdat+184h,y
				pha
				JSR     Y_iny_set
				clc
				adc		#0800h
				sta		oamdat+184h,y
				pla
				clc
				adc		#0008h
				JSR     Y_iny_set
				cpy		#0050h
				bne		loop_class1
;<<<<<<<<<<<<<<<<<<< MSB DATA SET >>>>>>>>>>>>>>>>>>>>>>
Set_msb			ldx		#0		
loop_msb		lda		#0aaaah
				sta		msbdat,x
				inx
				inx
				cpx		#0018h
				bne		loop_msb
loop_msb1		stz		msbdat,x
				inx
				inx
				cpx		#0020h
				bne		loop_msb1
				plb
				rtl
;==============================================================
;**************************************************************
;					データー
;**************************************************************
;==============================================================
WAKU_select		DW		3646h,344ah,3448h
;
trophy_place	DW		4630h,6630h,8630h			;50cc
trophy_place1   DW      3f2bh,572bh,6f2bh,8f2bh		;100cc
;					----- 3 --- 2 --- 1 --- 0 ----
trophy_color1	DW		3a44h,3c44h,3844h,0e44h		;50cc
trophy_color	DW		3a4ch,3c4ch,384ch,0e4dh		;100cc
trophy_color2	DW		3a4eh,3c4eh,384eh,0e4eh		;150cc		
;
Color_data_set	DW		0000h,1400h,0c00h
;
;- - - - - - - - - - - - - -- - - - -- - - - -- - - -- - -
Address_data	DW		2528h,25a8h,2628h
Address_data1	DW		2508h,2568h,25c8h,2648h
;
Cup_select		DW		KINOKO_CUP,FLAWER_CUP,STAR_CUP
				DW		SPECIAL_CUP
;
KINOKO_CUP		DW		1498h,14a8h,14a4h,148eh,14a2h
				DW		149ch,149ch,1498h
				DW		00e5h,1484h,14a8h,149eh
				DW		00e5h,14a2h,1480h,1484h,1488h,0ffffh
;
FLAWER_CUP		DW		148ah,1496h,149ch,14ach,1488h
				DW		14a2h,00e5h,1484h,14a8h,149eh
				DW		00e5h,14a2h,1480h,1484h,1488h,0ffffh
;
STAR_CUP		DW		14a4h,14a6h,1480h,14a2h,00e5h
				DW		1484h,14a8h,149eh,00e5h,14a2h
				DW		1480h,1484h,1488h,0ffffh
;
SPECIAL_CUP		DW		14a4h,149eh,1488h,1484h,1490h
				DW		1480h,1496h,00e5h,1484h,14a8h
				DW		149eh,00e5h,14a2h,1480h,1484h
				DW		1488h,0ffffh
;
Class_select	DW		Class_50,Class_100,Class_150
Class_50		DW		00e5h,3712h,3708h,00e5h,00e5h,3684h
				DW		3696h,3680h,36a4h,36a4h
;
Class_100		DW		370ah,3708h,3708h,00e5h,00e5h,3684h
				DW		3696h,3680h,36a4h,36a4h
;
Class_150		DW		370ah,3712h,3708h,00e5h,00e5h,3684h
				DW		3696h,3680h,36a4h,36a4h

;- - - - - - - - - - - - - - - - - - - - - - -
WAKU			DW		2818h,2828h,2838h,2848h,2858h,2868h,2878h
				DW		2888h,2898h,28a8h,28b8h,28c8h
				DW		28d8h
;
				DW		3818h,38d8h,4818h,48d8h,5818h
				DW		58d8h,6818h,68d8h,7818h,78d8h
				DW		8818h,88d8h,9818h,98d8h
;
				DW		0a818h,0a828h,0a838h,0a848h,0a858h
				DW		0a868h,0a878h,0a888h,0a898h
				DW		0a8a8h,0a8b8h,0a8c8h,0a8d8h,0ffffh
;============================================================
;************************************************************
;					サブルーチン集
;************************************************************
;============================================================
;<<<<<<<<<<<<<<<<<<<< 文字セット >>>>>>>>>>>>>>>>>>>>>
MOJI_Set		equ		$
				mem16
				idx16
				lda		Color_data_set,y
				sta		Color_set
				phx
;------(クラス別文字アドレスセット)------
				lda		game_level
				beq		Set_norm					;５０ccクラス?;yes-->Set_msb
;
				lda		Address_data1,x
				jmp		Set_v_address
;
Set_norm		lda     Address_data,x
Set_v_address	sta     Screen_address
;-----(文字の上側セット)---------
				lda		Cup_select,x
				tax
loop_moji_set	lda		!0,x
				cmp		#0ffffh
				beq		Set_under_moji
				sec
				sbc		Color_set
				sta     Screen_write
				inx
				inx
				jmp		loop_moji_set
;------(クラス別文字アドレスセット)------
Set_under_moji	plx
				lda		game_level
				beq		Set_norm1					;５０ccクラス?;yes-->Set_msb
;
				lda		Address_data1,x
				jmp		Set_v_address1
;
Set_norm1		lda     Address_data,x
Set_v_address1	clc
				adc		#0020h
				sta     Screen_address
;------(文字の下側セット)---------
				lda		Cup_select,x
				tax
loop_moji_set1	lda		!0,x
				cmp		#0ffffh
				beq		owari_moji_set
				cmp		#00e5h
				beq		nuki_set
				inc		a		
				sec		
				sbc		Color_set	
nuki_set		sta     Screen_write
				inx
				inx
				jmp		loop_moji_set1
owari_moji_set	rts
;
MOJI_Set_1		equ		$
				phb
				phk
				plb
				JSR		MOJI_Set
				plb
				rtl
;<<<<<<<<<<<<< トロフィーセットのサブルーチン >>>>>>>>>>
				mem16
				idx16
;		
Trophy_set		lda		trophy_color,x
				sta		oamdat,y				;カラーとキャラクターセット
				rts
;
Trophy_set1		lda		trophy_color1,x
				sta     oamdat,y
				rts
;
Trophy_set2		lda		trophy_color2,x
				sta     oamdat,y
				rts
;<<<<<<<<<<<<<<< ワク セットルーチン >>>>>>>>>>>>>>>>
WAKU_change_set	equ		$
				lda		world_number
				cmp		#03
				beq		special_cup					;world number 3?:yes-->special_cup
;
Set_waku_data	lda		world_number
				asl		a
				tax
				lda		WAKU_select,x
				ldx		#0000
loop_waku_1		sta		oamdat+2,x
				inx
				inx
				inx
				inx
				cpx		#00a0h
				bne		loop_waku_1
				jmp		owari_change_set
;-------(スペシャルセット)-------------
special_cup		ldy		#0000
				ldx		#04							;waku change set.
				stx		<waku_counter
;
loop_special	ldx		<waku_counter
				lda		WAKU_select,x
				sta		oamdat+2,y
				dec		<waku_counter
				dec		<waku_counter
				lda		<waku_counter
				bmi		Reset_counter
Set_next_data	JSR     Y_iny_set
				cpy		#00a0h
				beq		owari_change_set
				jmp		loop_special
Reset_counter	lda		#0004
				sta		<waku_counter
				jmp		Set_next_data
owari_change_set
				rts
;
Y_iny_set		iny
				iny
				iny
				iny
				rts
;<<<<<<<<<<<<< ４ｂｉｔモード変換ルーチン >>>>>>>>>>>>>>
Set_4bit_mode	equ		$
										;hi2bit set.
loop_4bit3		ldy		#0						;(zero set).
loop_4bt1		lda		>W_select_chr,x
				sta		Screen_write
				inx
				inx
				iny
				cpy		#08
				bne		loop_4bt1
;------------------------------------------------ 

				ldy		#0						;low2bit set.
loop_4bit2		lda		#0
				sta		Screen_write
				iny
				cpy		#08
				bne		loop_4bit2
				cpx		#0600h
				bne		loop_4bit3
				rts
;
Set_4bit_mode1	equ		$
				phb
				phk
				plb
				JSR		Set_4bit_mode
				plb
				rtl
;==========================================================
;**********************************************************
;				MAIN ROURATINE
;**********************************************************
;==========================================================
;*****************************************************
;					ワールドせんたく
;*****************************************************
Cup_change.set	equ		$
				phb
				phk
				plb
				mem16
				idx16
				lda		<button_TG
				ora		<button_TG+2
				and		#2c00h
				cmp		#0400h
				beq		cup_inc
				cmp		#0800h
				beq		cup_dec
				cmp		#2000h
				beq     cup_inc
				jmp		owari_change
;<<<<<<<<<<<< ワールドチェンジ　セット >>>>>>>>>>>>
cup_inc			
;----------(クラスチェック)---------
				lda		game_level
				beq		Set_50cc
;-----(１００ｃｃ総てのゴールドカップチェック)----
				lda		>Kinoko_Cup
				and		#0003h
				cmp		#0001
				bne		Set_50cc
				lda		>Flower_Cup
				and		#0003h
				cmp		#0001
				bne		Set_50cc
				lda		>Star_Cup
				and		#0003h
				cmp		#0001
				bne		Set_50cc
;--(１００ｃｃワールドチェンジセット)--
				lda     world_number
				sta		<Old_world_number
				inc		a
				cmp		#04
				beq		reset_world
				sta     world_number
				jmp		SE_set
;--(5０ｃｃワールドチェンジセット)--
Set_50cc		lda     world_number
				sta		<Old_world_number
				inc		a
				cmp		#03
				beq		reset_world
				sta     world_number
				jmp     SE_set
;------(オールドワールドナンバーセット)----
cup_dec			lda		world_number
				sta		<Old_world_number
				beq		under_world
				dec		a
				sta		world_number
SE_set			lda		#002ch
				JSL		>Trigger_sound_1
;<<<<<<<<<<<<<<< ワク　セット >>>>>>>>>>>>>>>>>>>>
change_waku		JSR		WAKU_change_set
owari_change	plb
				rtl				
;<<<<<<<<<<<<<<< ボタン　ループ >>>>>>>>>>>>>>>>>>>
reset_world		stz		world_number
				jmp     SE_set
;
under_world		lda		game_level
				bne		World_3
;
World_2			lda		#0002
				sta     world_number
				jmp     SE_set
;
World_3			lda		>Kinoko_Cup
				and		#0003h
				cmp		#0001
				bne		World_2
				lda		>Flower_Cup
				and		#0003h
				cmp		#0001
				bne		World_2
				lda		>Star_Cup
				and		#0003h
				cmp		#0001
				bne		World_2
;
				lda		#0003
				sta		world_number
				jmp     SE_set	
;*******************************************************
;					次のがめんセット
;*******************************************************
NEXT_SET		equ		$
				phb
				phk
				plb
				mem16
				idx16
				lda		<button_TG
				ora		<button_TG+2
				and		#9000h
				beq		owari_check
;<<<<<<<<<<<<<<< 次　セット >>>>>>>>>>>>>>>>>>>>>
				stz     race_init
;
				lda		#002eh
				JSL		>Trigger_sound_1
;
				lda     #02					;race mode set.
				sta     <game_selecta
;
				JSL		>BGM_fade_out
;
				lda     #8f00h
				sta     <fade_control		;fade set.
owari_check		plb
				rtl
;
;*******************************************************
;					ワク回転セット
;*******************************************************
WAKU_MOVE.SET	equ		$
				phb
				phk
				plb
				mem8
				sep		#00100000b
				lda		<move_counter
				clc
				adc		#0c0h
				sta		<move_counter
				lda		<move_counter+1
				adc		#0
				sta		<move_counter+1
				beq		owari_waku1				;counter 2?:no-->owari_waku1
				stz		<move_counter+1
				mem16
				rep		#00100000b				
;<<<<<<<<<<<<<<<<< 回転チェック >>>>>>>>>>>>>>>>>>
;
				ldx		#0
loop_waku		lda		oamdat,x
				cmp		#28d8h
				beq		down_move
;
				cmp		#0a818h
				beq		up_move
;
				and		#0ff00h
				cmp		#2800h
				beq		right_move
;
				cmp		#0a800h
				beq		left_move
;
				lda		oamdat,x
				and		#00ffh
				cmp		#0018h
				beq		up_move
;
				cmp		#000d8h
				beq		down_move
				jmp		next_set
;<<<<<<<<<<<<<<<< 右方向セット >>>>>>>>>>>>>>>>>>>>
right_move			lda     oamdat,x
				clc
				adc		#0001
				cmp		#28d8h
				beq		set_down		
				sta		oamdat,x
				jmp		next_set
;<<<<<<<<<<<<<<<< 下方向セット >>>>>>>>>>>>>>>>>>>>				
down_move		lda		oamdat,x
				clc
				adc		#0100h
				cmp		#0a8d8h
				bcs		set_left		
				sta		oamdat,x
				jmp		next_set
loop_waku1		jmp		loop_waku
owari_waku1		jmp		owari_waku
;<<<<<<<<<<<<<<<<< 左方向セット >>>>>>>>>>>>>>>>>>>>
left_move		lda		oamdat,x
				sec
				sbc		#0001h
				cmp		#0a818h
				bcc		set_up		
				sta		oamdat,x
				jmp		next_set
;<<<<<<<<<<<<<<<<< 上方向セット >>>>>>>>>>>>>>>>>>>
up_move		lda		oamdat,x
				sec
				sbc		#0100h
				cmp		#02818h
				bcc		set_right		
				sta		oamdat,x
;----------------------------------------------
next_set		inx
				inx
				inx
				inx
				cpx		#00a0h
				bne		loop_waku1
owari_waku		mem16
				rep		#00100000b
				plb	
				rtl
;----------------------------------------------
				mem16 
set_down		lda		#028d8h
				sta		oamdat,x
				jmp		next_set
;
set_left		lda		#0a8d8h
				sta		oamdat,x
				jmp		next_set
;
set_up			lda		#0a818h
				sta		oamdat,x
				jmp		next_set
;
set_right		lda		#02818h
				sta		oamdat,x
				jmp		next_set

;*******************************************************
;				バックアップセット
;*******************************************************	
;
;***************************************************
;				Ｆｉｎａｌ−ｅ．ａｓｍ用
;***************************************************
;<<<<<<<<<<<<<<<< バックアップセット >>>>>>>>>>>>>>>>>>
Back_up_set		equ		$
				phb
				phk
				plb
;-------(ワールドナンバーセット)-----------
				lda		world_number
				tax
				phx
;----------(クラスチェック)---------------
				lda		game_level
				beq		kids_back_up
				cmp		#0004
				beq		Special_back_up
;------(１００ｃｃバックアップセット)-----
				plx
				phx
				JSR		Set_Rank_Check
				sta		Rank_cmp
;
				plx
				JSR		Set_back_up
				jmp    	Owari_back_up_set
;--------(５０ｃｃバックアップセット)-----
kids_back_up	plx
				phx
				JSR     Set_Rank_Check
				asl		a
				asl		a
				sta		Rank_cmp
				plx
				JSR     Set_back_up
				jmp     Owari_back_up_set
;--------(15０ｃｃバックアップセット)-----
Special_back_up	plx
				phx
				JSR		Set_Rank_Check
				asl		a
				asl		a
				asl		a
				asl		a
				sta		Rank_cmp
;
				plx
				JSR     Set_back_up
Owari_back_up_set
				plb
				rtl
;
;
Set_Rank_Check
				JSL		>Rank_Check_sum
				txa
				lsr		a
				tax
				mem8
				sep		#00100000b
				lda		Select_cup,x
				rts
;
Set_back_up		equ		$
				cmp		#0
				beq		SUM_set
				lda		game_level
				lsr		a
				tay
				lda		>back_up_address,x
				and		Select_check,y
				beq		Rank_back_up
;
				cmp		Rank_cmp
				bcc		owari_Set_back_up
;
Rank_back_up	lda     >back_up_address,x
				and		Select_rank,y
				ora		Rank_cmp
				sta		>back_up_address,x		
;
SUM_set			mem16
				rep		#00100000b	
				lda		#0
				sta		>Back_up_Sum
				ldx		#0
loop_Sum		lda		>back_up_address,x
				clc
				adc		>Back_up_Sum
				sta		>Back_up_Sum
				inx
				inx
				cpx		#0004
				bne		loop_Sum
owari_Set_back_up
				mem16
				rep		#00110000b
				rts
;
Select_check	DB		0ch,03h,030h
Select_rank		DB		33h,3ch,00fh
;
;***************************************************
;				ｗ−ｓｅｌｅｃｔ．ａｓｍ用
;***************************************************									
;<<<<<<<<<<< ５０ｃｃトロフィーセット >>>>>>>>>>>
Check_Cup		equ		$
				mem16
				lda		>back_up_address,x
				and		#00ffh
				mem8
				sep		#00100000b
				and		#0ch
				lsr		a
				jmp		Set_rank_trophy
;<<<<<<<<<< １００ｃｃトロフィーセット >>>>>>>>>>
Check_Cup1		equ		$
				mem16
				lda		>back_up_address,x
				and		#00ffh
				mem8
				sep		#00100000b
				and		#03h
				asl		a
				jmp     Set_rank_trophy
;<<<<<<<<<< １5０ｃｃトロフィーセット >>>>>>>>>>
Check_Cup2		equ		$
				mem16
				lda		>back_up_address,x
				and		#00ffh
				mem8
				sep		#00100000b
				and		#30h
				lsr		a
				lsr		a
				lsr		a
Set_rank_trophy	mem16
				rep		#00100000b
				tax
				lda		Kind_Cup,x
				tax
				rts
;****************************************************
;				ｔｉｔｌｅ−ｅ．ａｓｍ用
;****************************************************
;<<<<<<<<<<<<<<<<< サム　チェック >>>>>>>>>>>>>>>>>
Backup_Sam_Check
				phb
				phk
				plb
;
				stz		Sum_cmp
;------(サム　チェック)---------
				ldx		#0
loop_sum_check	lda		Sum_cmp
				clc
				adc		>back_up_address,x
				sta		Sum_cmp
				inx
				inx
				cpx		#0004
				bne		loop_sum_check
				cmp		>Back_up_Sum
				beq		owari_sum_check
;------(ゼロクリアー)-----------
				ldx		#0
				lda		#0
loop_sum_zero	sta		>Back_up_Sum,x
				inx
				inx
				cpx		#0006
				bne		loop_sum_zero
owari_sum_check	plb
				rtl
;
;<<<<<<<<< バックアップオールクリアー >>>>>>>>>>
Back_up_clear	equ		$
				phb
				phk
				plb
;----------(表示中かのチェック)--------
				lda		<erase_set_flag
				bne		Set_erase_check
;----(イレース表示のボタンチェック)------
				lda     button_status
				ora     button_status+2
				cmp     #40b0h
				bne     nothing_button_1
;
				JSL		>OBJ_ERASE_SET			;title-e.asmにあります
;-----------(イレース文字表示)---------
				inc		<erase_set_flag
				ldx		#0
Loop_Earse		lda		Erase_moji_data,x
				sta		oamdat+1d0h,x
				inx
				inx
				cpx		#0030h
				bne		Loop_Earse
nothing_button_1
				jmp     nothing_button
;-----(Ｙｅｓ，Ｎｏチェックボタン)-----
Set_erase_check	lda		<button_TG
				ora		<button_TG+2
				and		#0300h
				cmp		#0100h
				beq		NO_set
				cmp		#0200h
				beq		YES_set
				lda		<button_TG
				ora		<button_TG+2
				and		#9000h
				bne		Set_decide
				jmp		nothing_button
;-----(Ｎｏフラグセット)-------
NO_set			lda		<erase_set_flag
				dec		a
				beq		nothing_button
				sta		<erase_set_flag
				lda		#70b0h
				sta		oamdat+1fch
				lda		#002ch
				JSL		>Trigger_sound_1
				jmp     nothing_button
;-----(Ｙｅｓフラグセット)-------
YES_set			lda		<erase_set_flag
				inc		a
				cmp		#0003
				beq		nothing_button
				sta		<erase_set_flag
				lda		#7088h
				sta     oamdat+1fch
				lda		#002ch
				JSL		>Trigger_sound_1
				jmp     nothing_button
;----(イレースかイレースでないかのチェック)----
Set_decide		lda		<erase_set_flag
				cmp		#0002
				bne		erase_check_moji
;
				JSR		Check_150cc
;------(バックアップを消す)------
				ldx		#0
				lda		#0
loop_sum_zero_1	sta		>Back_up_zero,x
				inx
				inx
				cpx		#0800h
				bne		loop_sum_zero_1
;
				lda		#0029h
				JSL		>Trigger_sound_1
erase_check_moji
				JSR		moji_erase_set
;
nothing_button	plb
				rtl
;
;------(文字を消す)---------------
moji_erase_set	lda		#0f080h
				ldx		#0
loop_moji_erase	sta		oamdat+1d0h,x
				inx
				inx
				cpx		#0030h
				bne		loop_moji_erase
				stz		<erase_set_flag

;
Check_150cc
;----(５０ｃｃに戻す)-----------
				mem8
				sep		#00100000b
				lda		<Game_select.flag	
				and		#06
				cmp		#04
				bne		No_set_50cc
				lda		<Game_select.flag
				and		#0f9h
				sta		<Game_select.flag
No_set_50cc		mem16
				rep		#00100000b
				rts

Erase_moji_data	DW		7030h,380eh,7038h,381bh
				DW		7040h,380ah,7048h,381ch
				DW		7050h,380eh,7058h,3824h
				DW		7090h,3822h,7098h,380eh	
				DW		70a0h,381ch,70b8h,3817h
				DW		70c0h,3818h,70b0h,3ae5h
;
Kind_Cup		DW		0006h,0004h,0002h,0000h
	
Select_cup		DB		01h,02h,03h,00h,00h,00h,00h,00h
				END

