;
;***********************maped4.asm**********************
			extend
;
		include 	label
		include		label_1
		include     ../join/work.def
;------------------------------------------------------
;
		ext			SAVE_FILE2,LOAD_FILE2,DAT_SET
		ext			disk_file2,SUM_CHECK,error_disp
		ext			YAKI_NO,PTADAT,file_number2
;
		glb			CG1_SET2
		glb			FADEIN_SET1,KASOL_FLASH
		glb			NOW_DSP1,DISK_SAVE,DISK_LOAD
		glb			DSFN_SET2,SUM_CHECK2
		glb			BTTLE_SET,BATTLE_ERASE,BATTLE_SAVE
		glb			BATTLE_LOAD,CG1_SET2
;
;------------------------------------------------------
editer      sect    rel
			mem8
			idx8
;*****************************************
;			COLOR TENSOU
;****************************************
CG1_SET2	equ		$
			idx16		        ;8bit mode.
			mem8
			rep		#00010000b
;
			lda		#00000000b	;BG1 color data.
			sta		CGadd

; 
			ldx		#0
loop4		lda		>7e3a80h,x
			sta		CGdata
			inx
        	lda     >7e3a80h,x
			sta     CGdata
			inx
			cpx		#200h
			bne		loop4
			
			idx8		        ;8bit mode.
			mem8
			sep		#00010000b
;
			rts

					
;-----------------------------------------------
;=======================================================
;*******************************************************
;			MAIN ROUTINE (select display)
;*******************************************************
;=======================================================
;
;
;************************************************
;		FADE IN SET
;************************************************
FADEIN_SET1	equ		$
			lda		fade_flg
			inc		a
			sta		fade_flg
			cmp		#02
			bne		owari_020

;
;
			stz		fade_flg
			lda		blankck
			cmp		#0fh
			beq		owari_505
;
			inc		a		
			sta		blankck
			ldx		#01
			sta		cwiddat1,x
			ldx		#05
			sta		cwiddat1,x
;
owari_020	rts				
;
owari_505	ldx		#02
			stx		fade_mode
			rts	
;**********************************************
;			DISK FILE NAME SET
;*********************************************
DSFN_SET2	equ		$
			ldy		#0beh
			lda		map_number
			asl		a
			asl		a
			asl		a
			tax
loop_218	lda		disk_file2,x
			sta		oamdat,y
			inx
			iny
			iny
			iny
			iny
			cpy		#0d6h
			bne		loop_218
			rts
;
;=================================================
;***********************************************
;			MAIN ROUTINE SUBSUB
;***********************************************
;=================================================
;
;***************************************
;			KASOL FLASH
;***************************************
KASOL_FLASH	equ		$
			lda		flash_flg
			cmp		#08h
			beq		flash_on
;
			inc		a
			sta		flash_flg
;
			ldx		#09				;on
			lda		#54h
			sta		msbdat,x
;
			ldx		#0dfh
			lda		#2ah
loop_930	sta		oamdat,x
			inx
			inx
			inx
			inx
			cpx		#0ffh
			bne		loop_930
;
			idx16
			rep		#00010000b
			ldx		#0ffh
			lda		#2ah
loop_931	sta		oamdat,x
			inx
			inx
			inx
			inx
			cpx		#11bh
			bne		loop_931
			idx8
			sep		#00010000b
			rts
;
flash_on	stz		flash_flg	 	;off
			ldx		#09
			lda		#55h
			sta		msbdat,x
;
			ldx		#0dfh
			lda		#24h
loop_M5		sta		oamdat,x
			inx
			inx
			inx
			inx
			cpx		#0ffh
			bne		loop_M5
;
			idx16
			rep		#00010000b
			ldx		#0ffh
			lda		#24h
loop_932	sta		oamdat,x
			inx
			inx
			inx
			inx
			cpx		#11bh
			bne		loop_932
			idx8
			sep		#00010000b
			rts
;**************************************
;			NOW SAVE display
;**************************************
NOW_DSP1		equ		$
			lda		#01					;NMI disenable.
			sta		NMItimen
;----------------------------------
			idx16						;display timer.
			rep		#00010000b	
			ldx		#0
loop_29		inx
			cpx		#0f000h
			bne		loop_29
			idx8
			mem8
			sep		#00110000b
;
			ldx		#03					;display erase set.
			lda		#40h
loop_28		sta		msbdat,x
			lda		#55h
			inx
			cpx		#06
			bne		loop_28
;------------------------------------
			lda		#81h				;NMI enable.
			sta		NMItimen
;
			lda		#02					;mode set.
			sta		fade_mode
owari_30	rts
;
;*****************************************
;			DISK SAVE SET
;*****************************************
DISK_SAVE	equ		$
			lda		modeflg
			cmp		#01
			bne		owari_30
;----------------------------------
			lda		s.l_set
			cmp		#01
			bne		owari_30
;----------------------------------
;
			lda		save_disp
			bne		save_now3
;
			lda		trg_button1
			cmp		#80h
			bne		owari_30
;-------------------------------------
			lda		save_flg
			cmp		#0
			beq		owari_30
;--------------------------------------
			ldx		#03				;now save display set.
			lda		#0
			sta     msbdat,x
			inx
			lda		#0
			sta		msbdat,x
			inx
			lda		#50h
			sta     msbdat,x
;
			lda		#01
			sta		save_disp
			rts
;-----------------------------------
										;save address set
save_now3	lda		map_number
			cmp		#14h
			bne		set_ram
			JSR		BATTLE_SDISK
			rts
;-------------------------------
set_ram		stz     save_disp
			ldy		#0				
			lda		#0ffh
loop_301	sta		1c00h,y
			iny
			cpy		#0a0h
			bne		loop_301
;-----------------------------------
			ldy		#0
			ldx		#0
setdat4		lda		>7f8000h,x
			cmp		#0
			beq		jmpdat4	
;
			inx
			inx
			inx
			lda		>7f8000h,x
			sta		1c00h,y
			iny
;
			dex
			dex
loop_223	lda		>7f8000h,x
			sta		1c00h,y
			inx
			iny
;
			lda		savecnt
			inc		a
			sta		savecnt
			cmp		#02
			bne		loop_223
			inx
			cpx		#0a0h
			beq		owari_229
			stz		savecnt
			jmp		setdat4
;
jmpdat4		inx
			inx
			inx
			inx
			cpx		#0a0h
			beq		owari_229
			jmp		setdat4

owari_229	stz     savecnt
			idx8
			sep		#00010000b
;---------------------------------
			JSR		SAVE_FILE2
;
			lda		error_code1			;disk set?:yes-->set_vini
			beq		sav		
;
			asl		a
			tax			
			idx16
			mem16
			rep		#00110000b
			lda		error_disp,x
			sta		<error
			mem8
			sep		#00100000b
;
			ldy		#0
			ldx		#102h	
loop_314	lda		(<error),y
			sta		oamdat,x
			iny
			inx
			inx
			inx
			inx
			cpy		#06
			bne		loop_314
			idx8
			sep		#00110000b
;
			ldx		#10h				;error message display set.
			stz		msbdat,x
			inx
			stz     msbdat,x
			jmp		notsave

;----------------------------------
sav			ldx		#10h			;error message erase set.
			lda		#55h
			sta		msbdat,x
			inx
			sta     msbdat,x
;
notsave		ldx		#03					;display erase set.
			lda		#40h
loop_287	sta		msbdat,x
			lda		#55h
			inx
			cpx		#06
			bne		loop_287
;----------------------------------
owari_347	rts
;
;***************************************
;		    DISK LOAD SET
;***************************************
DISK_LOAD	equ		$
			lda		modeflg
			cmp		#01
			bne		owari_347
;----------------------------------
			lda		s.l_set
			cmp		#03
			bne		owari_347
;----------------------------------
			ldx		#01
			lda		cwiddat1,x
			cmp		#8fh
			beq		vramset6
;----------------------------------
			lda		trg_button1
			cmp		#80h
			bne		owari_347
;-----------------------------------
;
			lda		#10001111b		;blanking on.
			sta		blankck
			ldx		#01
			sta		cwiddat1,x
			ldx		#05
			sta		cwiddat1,x
			rts
;------------------------------------
vramset6	lda		map_number
			cmp		#14h
			bne		set_ram4
			JSR		BATTLE_LDISK
			rts
;-------------------------------
set_ram4	JSR		LOAD_FILE2			;disk load set.
;
			lda		error_code1			;disk set?:yes-->set_vini
			beq		set_vini
;
			asl		a
			tax			
			idx16
			mem16
			rep		#00110000b
			lda		error_disp,x
			sta		<error
			mem8
			sep		#00100000b
;
			ldy		#0
			ldx		#102h	
loop_313	lda		(<error),y
			sta		oamdat,x
			iny
			inx
			inx
			inx
			inx
			cpy		#06
			bne		loop_313
			idx8
			sep		#00110000b
;
			ldx		#0					;disk buffer clare.
			lda		#0ffh
loop_M6		sta		1c00h,x
			inx
			cpx		#80h				;80h?:no-->loop_M6
			bne		loop_M6
;
			ldx		#10h				;error message display set.
			stz		msbdat,x
			inx
			stz     msbdat,x
			stz		error_code1
			jmp		set_vini1
;-------------------------------------			
set_vini	ldx		#10h			;error message erase set.
			lda		#55h
			sta		msbdat,x
			inx
			sta     msbdat,x
;
set_vini1	lda		#00000h
			mem8
			sep		#00100000b
;
	        lda 	#00h			;(VRAM INICHAL SET)
    	    sta    	VMAinc
; 
	    	lda		#0		;Vram adrr low.
		    sta	    VMAaddl
		    lda		#0		;Vram adrr hi.
		    sta	    VMAaddh
;
			idx16
			rep		#00010000b
;
	    	ldx		#0000h				;character data.
loop_312	lda		>7f4000h,x
			sta		VMAdatal
			inx
			cpx		#4000h					;4000? :no-->lopp1.
			bne		loop_312
;------------------------------------
			ldx		#0				;(7f8000H ZERO SET)
			lda		#0
loop_324	sta		>7f8000h,x
			inx
			cpx		#0a0h
			bne		loop_324
;-------------------------------------
			ldx		#0				;(from 70BANK to 7f8000H)
			ldy		#0
buff4		lda		1c00h,y
			cmp		#0ffh
			beq		setvram4
;	
			lda		#01
			sta		>7f8000h,x
			inx
			inx
			inx
			lda		1c00h,y
			sta		>7f8000h,x
			iny
			dex
			dex

;	
loop_344	lda		1c00h,y
			sta		>7f8000h,x
			iny
			inx
			lda		loadcnt
			inc		a
			sta     loadcnt
			cmp		#02
			bne		loop_344
			inx
			stz		loadcnt
			jmp		buff4
;-------------------------------------
setvram4	ldy		s.l_bup				;(VRAM SET)
			iny
			lda		1c00h,y
			cmp		#0ffh
			beq		owari_335
			sta		vradd
			sta		vraddr

			iny
			lda     1c00h,y
			sta		vradd+1
			sta		vraddr+1
;
			dey
			dey		
			lda     1c00h,y
			sta		yakidat
			iny
			iny
			iny
			sty		s.l_bup
;
			jsr		DAT_SET
;
			idx16
			rep		#00010000b
;
setyki11   	lda		vraddr				;Vram adrr low.
		    sta	    VMAaddl
		    lda		vraddr+1			;Vram adrr hi.
		    sta	    VMAaddh
;
			ldy		#0
	    	ldx		yakicnt				;character data.
loop356		lda		>7f0000h,x
			sta		VMAdatal
			inx
			iny
			stx		yakicnt
			cpy		witcnt		
			bne		loop356
;
			lda		dmacnt
			clc
			adc		#01h
			cmp		lthcnt
			beq		owari_342
			sta		dmacnt
;
			lda		vraddr
			clc
			adc		#80h
			sta		vraddr
;
			lda		vraddr+1
			adc		#0
			sta		vraddr+1
			jmp		setyki11
owari_335	jmp		owari_332

owari_342	stz		yakiflg
			stz		yakicnt
			stz		dmacnt
			lda		vradd
			sta		vraddr
			lda		vradd+1
			sta		vraddr+1 
			jmp		setvram4
;		
owari_332	stz		yakiflg
			stz		yakicnt
			stz		dmacnt
			stz     s.l_bup
			stz		yakidat
			lda		vradd
			sta		vraddr
			lda		vradd+1
			sta		vraddr+1 
		
			idx8		       		 ;8bit mode.
			mem8
			sep		#00010000b
;-------------------------------------
						
			lda		#0				;blanking off.
			sta		blankck
			ldx		#01
			sta		cwiddat1,x
			ldx		#05
			sta		cwiddat1,x

;
			stz		fade_mode		;fade in set.
			rts
;======================================================
;******************************************************
;			SUM_CHECK ROUTINE	
;******************************************************
;======================================================
SUM_CHECK2	equ		$			;(WHEN INICTIAL SUMCHECK[YAKI EDITER])
			mem16
			idx16
			rep		#00110000b
;-----------------------------------------
;(BG SUM CHECK)
			stz		sum_data1
			ldx		#0
loop_9684	lda		>701000h,x
			inx
			inx
			cmp		#0ffffh
			beq		offset_set4		
;
			clc
			adc		sum_data1
			sta		sum_data1
offset_set4	cpx		#1000h
			bne		loop_9684
;
;-----------------------------------------
;(RUN SUM CHECK)
			ldx		#0
loop_9284	lda		>702000h,x
			inx
			inx
			cmp		#0ffffh
			beq		offset_set5		
;
			clc
			adc		sum_data1
			sta		sum_data1
offset_set5	cpx		#6000h
			bne		loop_9284
;
			lda		sum_data1
			cmp		>700ffeh
			bne		set_mess1
;-----------------------------------------
			mem8
			idx8
			sep		#00110000b
;
			ldx		#0dh
			lda		#50h
			sta		msbdat,x
			inx
			lda		#55h
			sta     msbdat,x
			inx
			sta		msbdat,x
			rts
;
set_mess1	equ		$				;ram erooer display set.
			mem8
			idx8
			sep		#00110000b
;
			ldx		#0dh
			stz		msbdat,x
			inx
			stz     msbdat,x
			lda		#40h
			inx
			sta		msbdat,x
			rts
;
;=====================================================
;****************************************************
;			BATTLE MODE ROUTINE
;****************************************************
;=====================================================
BTTLE_SET		equ		$
			idx8
			mem8
			sep		#00010000b
			ldx		#0				;character data set.
			lda		yakidat		;(QUES,KINO,NIKO,FLW)
			and		#00111111b
			tay
;
			lda		yakidat
			and		#00111100b
			cmp		#20h
			beq		Water_Set11
;
			lda		YAKI_NO,y
loop_51		sta		>7f0000h,x
			inc		a
			inx
			cpx		#05
			bne		loop_51
;
;---------------------------------------------
									;(PATERN SET)
ptaset3		lda		yakidat		;patern data set.
			and		#11000000b
			lsr		a
			lsr		a
			lsr		a
			lsr		a
			lsr		a
			lsr		a
			asl		a
			tay
			lda		PTADAT,y
			sta		witcnt
			iny
			lda     PTADAT,y
			sta		lthcnt
;
			lda		modeflg
			cmp		#01
			beq		owari_976
;----------------------------------

			idx16
			mem16
			rep		#00110000b
;----------------------------------
			ldx		#01h				;(SAME ADDRESS CHECK)
loop_392	lda		>7f8200h,x
			cmp		bgadd
			beq		owari_371			;same address?:yes-->owari_37
			inx
			inx
			inx
			inx
			cpx		#1001h				;a1?:no-->loop_39
			bne		loop_392
;
			idx16
			mem8
			sep		#00100000b

;--------------------------------------
			ldx		#0					;(BG DATA SET TO 7f8000h)
flgck2		lda		>7f8200h,x
			cmp		#0
			bne		adcx2
;
			lda		#01
			sta		>7f8200h,x	
			inx
			lda		bgadd
			sta		>7f8200h,x
			inx
			lda		bgadd1
			sta		>7f8200h,x
			inx
yakiset12	lda		yakidat
			sta		>7f8200h,x
			mem8
			idx8
			sep		#00110000b
			rts
;
adcx2		idx16
			mem8
			inx
			inx
			inx
			inx
			cpx		#1000h
			beq		z_flg2
			jmp		flgck2
Water_Set11	jmp		Water_Set1
;
z_flg2		stz		yakiflg
;
owari_976	mem8
			idx8
			sep		#00110000b
			rts		
;----------------------------------------
owari_371	idx16						;(BG CHANGE)
			mem8
			sep		#00100000b
;
			inx
			inx
			lda		>7f8200h,x
			cmp		yakidat
			beq		z_flg2
			jmp		yakiset12
			jmp		owari_976
;

Water_Set1	equ		$				;(WATER)
			idx8
			mem8
			lda		#073h			;character data set.
linset		sta		>7f0000h,x	
			inx
			cpx		#04
			bne		linset
			jmp		ptaset3
;

;---------------------------------------------
;*****************************************
;			ERASE SET
;*****************************************
BATTLE_ERASE	equ		$
;
			idx16
			mem16
			rep		#00110000b
;---------------------------------
			ldx		#01h				;(SAME ADDRESS CHECK)
rechk2		lda		>7f8200h,x
			cmp		bgadd
			beq		noset2				;same address?:yes-->noset
			inx
			inx
			inx
			inx
			cpx		#1001h
			beq		noers2				;a1?:yes-->noers
			jmp		rechk2		
;--------------------------------
noset2		dex							;(ERASE BG SET)
			lda		#0
			sta		>7f8200h,x
;
			mem8
			sep		#00100000b
;
			inx
			inx
			inx
			lda		>7f8200h,x
			sta		erasedat
			dex
			lda		#0
			sta		>7f8200h,x
			inx
			sta     >7f8200h,x
			idx8
			mem8
			sep		#00110000b
			jmp		set_erase2
;------------------------------------
noers2  	mem8					;(NO ERASE SET)
			idx8
			sep		#00110000b
		    stz     eraseflg
;----------------------------------------
set_erase2	lda		erasedat		;patern data set.
			and		#11000000b
			lsr		a
			lsr		a
			lsr		a
			lsr		a
			lsr		a
			lsr		a
			asl		a
			tay
			lda		PTADAT,y
			sta		witcnt
			iny
			lda     PTADAT,y
			sta		lthcnt
			rts
;*****************************************
;			SAVE SET
;*****************************************
BATTLE_SAVE	equ		$
			idx16
			mem16
			rep		#00110000b
;
			lda		#08200h
			sta		<addr
			mem8
			sep		#00100000b
			lda		#11h
			sta		<addr+2
;-----------------------------------
			ldy		#0				;FF(end) set.
			ldx		#0
			lda		#0ffh
loop_302	sta		[<addr],y
			iny
			inx
			cpx		#0c00h
			bne		loop_302
;-----------------------------------
			ldy		#0
			ldx		#0
setdat3		lda		>7f8200h,x
			cmp		#0
			beq		jmpdat3	
;
			inx
			inx
			inx
			lda		>7f8200h,x
			sta		[<addr],y
			iny
;
			dex
			dex
loop_2231	lda		>7f8200h,x
			sta		[<addr],y
			inx
			iny
;
			lda		savecnt
			inc		a
			sta		savecnt
			cmp		#02
			bne		loop_2231
			inx
			cpx		#1000h
			beq		owari_221
			stz		savecnt
			jmp		setdat3
;
jmpdat3		inx
			inx
			inx
			inx
			cpx		#1000h
			beq		owari_221
			jmp		setdat3

owari_221	stz     savecnt
			idx8
			sep		#00010000b
;
			ldx		#03					;display erase set.
			lda		#40h
loop_283	sta		msbdat,x
			lda		#55h
			inx
			cpx		#06
			bne		loop_283
;
			mem8
			idx8
			sep		#00110000b
			rts
;******************************************
;			BATTLE LOAD SET
;******************************************
BATTLE_LOAD	equ		$
			mem16
			rep		#00100000b
			lda		#08200h
			sta		<addr
			lda		#00000h
			mem8
			sep		#00100000b
			lda		#11h
			sta		<addr+2
;----------------------------------------
	        lda 	#00h			;(VRAM INICHAL SET)
    	    sta    	VMAinc
; 
	    	lda		#0		;Vram adrr low.
		    sta	    VMAaddl
		    lda		#0		;Vram adrr hi.
		    sta	    VMAaddh
;
			idx16
			rep		#00010000b
;
	    	ldx		#0000h				;character data.
loop_331	lda		>7f4000h,x
			sta		VMAdatal
			inx
			cpx		#4000h					;4000? :no-->lopp1.
			bne		loop_331
;------------------------------------
			ldx		#0				;(7f8000H ZERO SET)
			lda		#0
loop_323	sta		>7f8200h,x
			inx
			cpx		#1000h
			bne		loop_323
;-------------------------------------
			ldx		#0				;(from 70BANK to 7f8000H)
			ldy		s.l_bup
buff3		lda		[<addr],y
			cmp		#0ffh
			beq		setvram3
;	
			lda		#01
			sta		>7f8200h,x
			inx
			inx
			inx
			lda		[<addr],y
			sta		>7f8200h,x
			iny
			dex
			dex
;	
loop_364	lda		[<addr],y
			sta		>7f8200h,x
			iny
			inx
  			lda		loadcnt
			inc		a
			sta     loadcnt
			cmp		#02
			bne		loop_364
			inx
			stz		loadcnt
			jmp		buff3
;-------------------------------------
setvram3	ldy		s.l_bup		;(VRAM SET)
			iny
			lda		[<addr],y
			cmp		#0ffh
			beq		owari_339
			sta		vradd
			sta		vraddr

			iny
			lda     [<addr],y
			sta		vradd+1
			sta		vraddr+1
;
			dey
			dey		
			lda     [<addr],y
			sta		yakidat
			iny
			iny
			iny
			sty		s.l_bup
;
			jsr		BTTLE_SET
			idx16
			rep		#00010000b
;
setyki113  	lda		vraddr				;Vram adrr low.
		    sta	    VMAaddl
		    lda		vraddr+1			;Vram adrr hi.
		    sta	    VMAaddh
;
			ldy		#0
	    	ldx		yakicnt				;character data.
loop353		lda		>7f0000h,x
			sta		VMAdatal
			inx
			iny
			stx		yakicnt
			cpy		witcnt		
			bne		loop353
;
			lda		dmacnt
			clc
			adc		#01h
			cmp		lthcnt
			beq		owari_346
			sta		dmacnt
;
			lda		vraddr
			clc
			adc		#80h
			sta		vraddr
;
			lda		vraddr+1
			adc		#0
			sta		vraddr+1
			jmp		setyki113
;
owari_346	stz		yakiflg
			stz		yakicnt
			stz		dmacnt
			lda		vradd
			sta		vraddr
			lda		vradd+1
			sta		vraddr+1 
			jmp		setvram3
;		
owari_339	stz		yakiflg
			stz		yakicnt
			stz		dmacnt
			stz     s.l_bup
			stz     s.l_bup+1
			stz		yakidat
			lda		vradd
			sta		vraddr
			lda		vradd+1
			sta		vraddr+1 
;
			idx8		       		 ;8bit mode.
			mem8
			sep		#00010000b
;
			lda		#0				;blanking off.
			sta		blankck
			ldx		#01
			sta		cwiddat1,x
			ldx		#05
			sta		cwiddat1,x
			rts
;********************************************
;			BATTLE DISK SAVE SET
;********************************************
BATTLE_SDISK	equ		$
			idx16
			mem16
			rep		#00110000b
;		
			lda		#9300h
			sta		<addr
;
			mem8
			sep		#00100000b
			lda		#7fh
			sta		<addr+2
;------------------------------------------
			stz     save_disp
			ldy		#0				
			lda		#0ffh
loop_3011	sta		[<addr],y
			iny
			cpy		#0c00h
			bne		loop_3011
;------------------------------------------
			ldy		#0
			ldx		#0
setdat6		lda		>7f8200h,x
			cmp		#0
			beq		jmpdat6	
;
			inx
			inx
			inx
			lda		>7f8200h,x
			sta		[<addr],y
			iny
;
			dex
			dex
loop_2233	lda		>7f8200h,x
			sta		[<addr],y
			inx
			iny
;
			lda		savecnt
			inc		a
			sta		savecnt
			cmp		#02
			bne		loop_2233
			inx
			cpx		#1000h
			beq		owari_225
			stz		savecnt
			jmp		setdat6
;
jmpdat6		inx
			inx
			inx
			inx
			cpx		#1000h
			beq		owari_225
			jmp		setdat6

owari_225	stz     savecnt
			idx8
			sep		#00010000b
;----------------------------------------------------
			lda		#0
			sta		hdmsw
;
			lda		NMItimen
			sta		1e00h
;----------------------  ---------------------
									;(FILE NAME SET)
			lda		map_number
			asl		a
			tax
			mem16
			rep		#00100000b
			lda		file_number2,x
			sta		<file
			mem8
			sep		#00100000b
;
			lda		file_cnt		
			asl		a
			asl		a
			asl		a
			tay
			ldx		#0
loop_0896	lda		(<file),y
			sta		1ee0h,x
			inx
			iny
			cpx		#08
			bne		loop_0896
;----------------------------
									;(SPACE SET)
			lda		#20h			
loop_0781	sta		1ee0h,x
			inx
			cpx		#0bh
			bne		loop_0781
;-------------------------------------------
			ldx		#0
			lda		#0				;address set.
			sta		1ef0h,x
;
			inx
			lda		#93h
			sta     1ef0h,x
;
			inx		
			lda		#07fh
			sta     1ef0h,x			
;--------------------------------------------
			ldx		#0				;count
			lda		#0
			sta		1ef4h,x
;
			lda		#00ch
			inx
			sta     1ef4h,x
			inx	
			lda		#0	
			sta     1ef4h,x
;--------------------------------------------	
			cop		16h				;save call
			sta     error_code1
;
			mem8
			idx8
			sep		#30h

			lda		#81h
			sta		>4200h
			lda		#00111110b
			sta		hdmsw
;------------------------------------------------
			lda		error_code1			;disk set?:yes-->set_vini
			beq		sav4		
;
			asl		a
			tax			
			idx16
			mem16
			rep		#00110000b
			lda		error_disp,x
			sta		<error
			mem8
			sep		#00100000b
;
			ldy		#0
			ldx		#102h	
loop_3144	lda		(<error),y
			sta		oamdat,x
			iny
			inx
			inx
			inx
			inx
			cpy		#06
			bne		loop_3144
			idx8
			sep		#00110000b
;
			ldx		#10h				;error message display set.
			stz		msbdat,x
			inx
			stz     msbdat,x
			jmp		notsave4

;----------------------------------
sav4		ldx		#10h			;error message erase set.
			lda		#55h
			sta		msbdat,x
			inx
			sta     msbdat,x
;
notsave4	ldx		#03					;display erase set.
			lda		#40h
loop_2874	sta		msbdat,x
			lda		#55h
			inx
			cpx		#06
			bne		loop_2874
;----------------------------------
			rts
;*********************************************
;			BATTLE DISK LOAD SET
;*********************************************
BATTLE_LDISK	equ		$
			lda		#0
			sta		hdmsw
;
			lda		NMItimen
			sta		1e00h
;-------------------------------------------
									;(FILE NAME SET)
			lda		map_number
			asl		a
			tax
			mem16
			rep		#00100000b
			lda		file_number2,x
			sta		<file
			mem8
			sep		#00100000b
;
			lda		file_cnt		
			asl		a
			asl		a
			asl		a
			tay
			ldx		#0
loop_0369	lda		(<file),y
			sta		1ee0h,x
			inx
			iny
			cpx		#08
			bne		loop_0369
;----------------------------
									;(SPACE SET)
			lda		#20h			
loop_068	sta		1ee0h,x
			inx
			cpx		#0bh
			bne		loop_068
;-------------------------------------------
			ldx		#0
			lda		#0				;address set.
			sta		1ef0h,x
;
			inx
			lda		#93h
			sta     1ef0h,x
;
			inx		
			lda		#07fh
			sta     1ef0h,x			
;--------------------------------------------
			ldx		#0				;count
			lda		#0
			sta		1ef4h,x
;
			lda		#00ch
			inx
			sta     1ef4h,x
			inx		
			stz     1ef4h,x
;--------------------------------------------	
			cop		15h				;load call
			sta		error_code1		
;
			lda		#81h
			sta		>4200h
			lda		#00111110b
			sta		hdmsw
;-----------------------------------------------
;
			lda		error_code1			;disk set?:yes-->set_vini
			beq		set_vini8
;
			asl		a
			tax			
			idx16
			mem16
			rep		#00110000b
			lda		error_disp,x
			sta		<error
			mem8
			sep		#00100000b
;
			ldy		#0
			ldx		#102h	
loop_3123	lda		(<error),y
			sta		oamdat,x
			iny
			inx
			inx
			inx
			inx
			cpy		#06
			bne		loop_3123
			idx8
			sep		#00110000b
;
			ldx		#0					;disk buffer clare.
			lda		#0ffh
loop_M1		sta		1c00h,x
			inx
			cpx		#80h				;80h?:no-->loop_M6
			bne		loop_M1
;
			ldx		#10h				;error message display set.
			stz		msbdat,x
			inx
			stz     msbdat,x
			stz		error_code1
			jmp		set_vini4
;-------------------------------------			
set_vini8	ldx		#10h			;error message erase set.
			lda		#55h
			sta		msbdat,x
			inx
			sta     msbdat,x
;-----------------------------------------
set_vini4	idx16
			mem16
			rep		#00110000b
;		
			lda		#9300h
			sta		<addr
;
			mem8
			sep		#00100000b
			lda		#7fh
			sta		<addr+2
;------------------------------------------

			lda		#00000h
			mem8
			sep		#00100000b
;
	        lda 	#00h			;(VRAM INICHAL SET)
    	    sta    	VMAinc
; 
	    	lda		#0		;Vram adrr low.
		    sta	    VMAaddl
		    lda		#0		;Vram adrr hi.
		    sta	    VMAaddh
;
			idx16
			rep		#00010000b
;
	    	ldx		#0000h				;character data.
loop_3124	lda		>7f4000h,x
			sta		VMAdatal
			inx
			cpx		#4000h					;4000? :no-->lopp1.
			bne		loop_3124
;------------------------------------
			ldx		#0				;(7f8000H ZERO SET)
			lda		#0
loop_3244	sta		>7f8200h,x
			inx
			cpx		#1000h
			bne		loop_3244
;-------------------------------------
			ldx		#0				;(from 70BANK to 7f8000H)
			ldy		#0
buff7		lda		[<addr],y
			cmp		#0ffh
			beq		setvram7
;	
			lda		#01
			sta		>7f8200h,x
			inx
			inx
			inx
			lda		[<addr],y
			sta		>7f8200h,x
			iny
			dex
			dex

;	
loop_3474	lda		[<addr],y
			sta		>7f8200h,x
			iny
			inx
			lda		loadcnt
			inc		a
			sta     loadcnt
			cmp		#02
			bne		loop_3474
			inx
			stz		loadcnt
			jmp		buff7
;-------------------------------------
setvram7	ldy		s.l_bup				;(VRAM SET)
			iny
			lda		[<addr],y
			cmp		#0ffh
			beq		owari_3357
			sta		vradd
			sta		vraddr

			iny
			lda     [<addr],y
			sta		vradd+1
			sta		vraddr+1
;
			dey
			dey		
			lda     [<addr],y
			sta		yakidat
			iny
			iny
			iny
			sty		s.l_bup
;
			jsr		BTTLE_SET
;
			idx16
			rep		#00010000b
;
setyki117  	lda		vraddr				;Vram adrr low.
		    sta	    VMAaddl
		    lda		vraddr+1			;Vram adrr hi.
		    sta	    VMAaddh
;
			ldy		#0
	    	ldx		yakicnt				;character data.
loop3567	lda		>7f0000h,x
			sta		VMAdatal
			inx
			iny
			stx		yakicnt
			cpy		witcnt		
			bne		loop3567
;
			lda		dmacnt
			clc
			adc		#01h
			cmp		lthcnt
			beq		owari_3427
			sta		dmacnt
;
			lda		vraddr
			clc
			adc		#80h
			sta		vraddr
;
			lda		vraddr+1
			adc		#0
			sta		vraddr+1
			jmp		setyki117
owari_3357	jmp		owari_3327

owari_3427	stz		yakiflg
			stz		yakicnt
			stz		dmacnt
			lda		vradd
			sta		vraddr
			lda		vradd+1
			sta		vraddr+1 
			jmp		setvram7
;		
owari_3327	stz		yakiflg
			stz		yakicnt
			stz		dmacnt
			stz     s.l_bup
			stz     s.l_bup+1
			stz		yakidat
			lda		vradd
			sta		vraddr
			lda		vradd+1
			sta		vraddr+1 
		
			idx8		       		 ;8bit mode.
			mem8
			sep		#00010000b
;-------------------------------------
						
			lda		#0				;blanking off.
			sta		blankck
			ldx		#01
			sta		cwiddat1,x
			ldx		#05
			sta		cwiddat1,x

;
			stz		fade_mode		;fade in set.
			rts

			END









