;************************************************************************
;*									*
;*	title name	: "yossy"					*
;*	proccess	: course BG write sub.1				*
;*	file name	: ys_bgsc0					*
;*									*
;************************************************************************
;
;
		SALL
;
;;;;		include		ys_header.inc
;;;;		include		ys_unit.h
;
;
;
;
		include		yst_header.inc
		include 	../../../JPN/sfc/ys_unit.h
;
		XALL
;
;
;------------------------------------------------------------------------
;-		global symbol						-
;------------------------------------------------------------------------
		GLB	KOTEISB,KAHENSB
		GLB	KOTESB,KAHNSB
;
;
;
;------------------------------------------------------------------------
;-		extern symbol						-
;------------------------------------------------------------------------
;
;------------------------------------------------------------------------
;-		define symbol						-
;------------------------------------------------------------------------
;;;;		EQU
;
;
;************************************************************************
;*									*
;*		program start						*									*
;*									*
;************************************************************************
;
;
;;;;		ORG	158000H
		ORG	038000H
;
;
		EXTEND
;
;
		MEM8
		IDX8
;
;
;************************************************************************
;*		course BG write sub table				*
;************************************************************************
;
;--------------	kotei data --------------------------------------
KOTEISB		EQU	$
		LWORD	HILIGHT_RD1-1	;[0]
		LWORD	HILIGHT_BD1-1	;[1]
		LWORD	HILIGHT_RD2-1	;[2]
		LWORD	HILIGHT_BD2-1	;[3]

		LWORD	HILIGHT_RD3-1	;[4]
		LWORD	HILIGHT_BD3-1	;[5]
		LWORD	HILIGHT_RD4-1	;[6]
		LWORD	HILIGHT_BD4-1	;[7]

		LWORD	HILIGHT_RHL1-1	;[8]
		LWORD	HILIGHT_BHL1-1	;[9]
		LWORD	HILIGHT_RHL2-1	;[A]
		LWORD	HILIGHT_BHL2-1	;[B]

		LWORD	HILIGHT_RLL1-1	;[C]
		LWORD	HILIGHT_BLL1-1	;[D]
		LWORD	HILIGHT_RLL2-1	;[E]
		LWORD	HILIGHT_BLL2-1	;[F]

		LWORD	HILIGHT_RHR1-1	;[10]
		LWORD	HILIGHT_BHR1-1	;[11]
		LWORD	HILIGHT_RHR2-1	;[12]
		LWORD	HILIGHT_BHR2-1	;[13]

		LWORD	HILIGHT_RLR1-1	;[14]
		LWORD	HILIGHT_BLR1-1	;[15]
		LWORD	HILIGHT_RLR2-1	;[16]
		LWORD	HILIGHT_BLR2-1	;[17]

		LWORD	HILIGHT_RHL21-1	;[18]
		LWORD	HILIGHT_BHL21-1	;[19]
		LWORD	HILIGHT_RHL22-1	;[1A]
		LWORD	HILIGHT_BHL22-1	;[1B]

		LWORD	HILIGHT_RLL21-1	;[1C]
		LWORD	HILIGHT_BLL21-1	;[1D]
		LWORD	HILIGHT_RLL22-1	;[1E]
		LWORD	HILIGHT_BLL22-1	;[1F]

		LWORD	HILIGHT_RHR21-1	;[20]
		LWORD	HILIGHT_BHR21-1	;[21]
		LWORD	HILIGHT_RHR22-1	;[22]
		LWORD	HILIGHT_BHR22-1	;[23]

		LWORD	HILIGHT_RLR21-1	;[24]
		LWORD	HILIGHT_BLR21-1	;[25]
		LWORD	HILIGHT_RLR22-1	;[26]
		LWORD	HILIGHT_BLR22-1	;[27]

		LWORD	HILIGHT_RS11-1	;[28]
		LWORD	HILIGHT_BS11-1	;[29]
		LWORD	HILIGHT_RS12-1	;[2A]
		LWORD	HILIGHT_BS12-1	;[2B]

		LWORD	HILIGHT_RS21-1	;[2C]
		LWORD	HILIGHT_BS21-1	;[2D]
		LWORD	HILIGHT_RS22-1	;[2E]
		LWORD	HILIGHT_BS22-1	;[2F]

		LWORD	KABE_HOLE-1	;[30]
		LWORD	KABE_MOVE-1	;[31]

		LWORD	SENRO00-1	;[32]
		LWORD	SENRO01-1	;[33]
		LWORD	SENRO02-1	;[34]
		LWORD	SENRO03-1	;[35]
		LWORD	SENRO04-1	;[36]
		LWORD	SENRO05-1	;[37]
		LWORD	SENRO06-1	;[38]
		LWORD	SENRO07-1	;[39]
		LWORD	SENRO08-1	;[3A]

		LWORD	RAKUGAKI00-1	;[3B]
		LWORD	RAKUGAKI01-1	;[3C]
		LWORD	RAKUGAKI02-1	;[3D]
		LWORD	RAKUGAKI03-1	;[3E]
		LWORD	RAKUGAKI04-1	;[3F]
		LWORD	RAKUGAKI05-1	;[40]
		LWORD	RAKUGAKI06-1	;[41]
		LWORD	RAKUGAKI07-1	;[42]
		LWORD	RAKUGAKI08-1	;[43]
		LWORD	RAKUGAKI09-1	;[44]
		LWORD	RAKUGAKI10-1	;[45]
;
;--------------	kahen data --------------------------------------	
KAHENSB		EQU	$-3
		LWORD	BGSUB-1		;[1]
		LWORD	BGSUB_EL-1	;[2]
		LWORD	BGSUB_ER-1	;[3]
		LWORD	BGSUB_SLL30-1	;[4]
		LWORD	BGSUB_SLR30-1	;[5]
		LWORD	BGSUB_SLL45-1	;[6]
		LWORD	BGSUB_SLR45-1	;[7]
		LWORD	BGSUB_SLL60-1	;[8]
		LWORD	BGSUB_SLR60-1	;[9]
		LWORD	BGSUB_KABE_L-1	;[A]
		LWORD	BGSUB_KABE_R-1	;[B]
		LWORD	BGSUB_BOU-1	;[C]
		LWORD	BGSUB_SFLOOR-1	;[D]
		LWORD	BGSUB_BOU_SL-1	;[E]
		LWORD	BGSUB_BOU_SR-1	;[F]
		LWORD	BGSUB_RP30-1	;[10]
		LWORD	BGSUB_RP45-1	;[11]
		LWORD	BGSUB_RP60-1	;[12]
		LWORD	BGSUB_RPST-1	;[13]
		LWORD	BGSUB_CABE-1	;[14]
		LWORD	BGSUB_DOOR-1	;[15]
;
		LWORD	BGSUB_WATER-1	;[16]
		LWORD	BGSUB_WGL-1	;[17]
		LWORD	BGSUB_WLAND-1	;[18]
		LWORD	BGSUB_WROCK-1	;[19]
		LWORD	BGSUB_BRIDGEH-1	;[1A]
		LWORD	BGSUB_BRIDGEV-1	;[1B]
		LWORD	BGSUB_WLIFT-1	;[1C]
		LWORD	BGSUB_KINOKO-1	;[1D]
		LWORD	BGSUB_HANA-1	;[1E]
;
		LWORD	BGSUB_YOGAN-1	;[1F]
		LWORD	BGSUB_BLOCK-1	;[20]
;
		LWORD	BGSUB_BABULE_R1-1	;[21]
		LWORD	BGSUB_BABULE_B1-1	;[22]
		LWORD	BGSUB_BABULE_R2-1	;[23]
		LWORD	BGSUB_BABULE_B2-1	;[24]
		LWORD	BGSUB_BABULE_R3-1	;[25]
		LWORD	BGSUB_BABULE_B3-1	;[26]
		LWORD	BGSUB_BABULE_R4-1	;[27]
		LWORD	BGSUB_BABULE_B4-1	;[28]
		LWORD	BGSUB_BABS_R1-1	;[29]
		LWORD	BGSUB_BABS_B1-1	;[2A]
		LWORD	BGSUB_BABS_R2-1	;[2B]
		LWORD	BGSUB_BABS_B2-1	;[2C]
		LWORD	BGSUB_BABS_R3-1	;[2D]
		LWORD	BGSUB_BABS_B3-1	;[2E]
		LWORD	BGSUB_BABS_R4-1	;[2F]
		LWORD	BGSUB_BABS_B4-1	;[30]
		LWORD	BGSUB_HILIGHT_R1-1	;[31]
		LWORD	BGSUB_HILIGHT_B1-1	;[32]
		LWORD	BGSUB_HILIGHT_R2-1	;[33]
		LWORD	BGSUB_HILIGHT_B2-1	;[34]
		LWORD	BGSUB_SOAP1_R1-1	;[35]
		LWORD	BGSUB_SOAP1_B1-1	;[36]
		LWORD	BGSUB_SOAP1_R2-1	;[37]
		LWORD	BGSUB_SOAP1_B2-1	;[38]
		LWORD	BGSUB_SOAP2-1	;[39]
		LWORD	BGSUB_SOAP3-1	;[3A]
		LWORD	BGSUB_SOAP-1	;[3B]
		LWORD	BGSUB_AWAAWA-1	;[3C]
;
		LWORD	BGSUB_KUMO-1	;[3D]
		LWORD	BGSUB_BOU_SD-1	;[3E]
		LWORD	BGSUB_HARI_L-1	;[3F]
		LWORD	BGSUB_HARI_R-1	;[40]
;
		LWORD	BGSUB_KABEH-1	;[41]
		LWORD	BGSUB_KABEV-1	;[42]
		LWORD	BGSUB_KABEV2-1	;[43]

		LWORD	BGSUB_KABEB-1	;[44]
		LWORD	BGSUB_KBSLL-1	;[45]
		LWORD	BGSUB_KBSLR-1	;[46]
		LWORD	BGSUB_KBWTR-1	;[47]
;
		LWORD	BGSUB_KYUKA-1	;[48]
		LWORD	BGSUB_WINDOW-1	;[49]
		LWORD	BGSUB_POST-1	;[4A]
;
		LWORD	BGSUB_BLKSLM4-1	;[4B]
		LWORD	BGSUB_BLKSLM6-1	;[4C]
		LWORD	BGSUB_BLKSLM8-1	;[4D]
;;K;;		LWORD	BGSUB_EAT-1	;[4E]
		LWORD	BGSUB_KSETABG-1	;[4E]
;
		LWORD	BGSUB_BLKBG-1	;[4F]
;
		LWORD	BGSUB_SENROV-1	;[50]
		LWORD	BGSUB_SENROH-1	;[51]
		LWORD	BGSUB_SENROS-1	;[52]
;
		LWORD	BGSUB_KABEYUKA-1 ;[53]
		LWORD	BGSUB_SAKA30-1	;[54]
		LWORD	BGSUB_SAKA45-1	;[55]
		LWORD	BGSUB_SAKA60-1	;[56]
;
		LWORD	BGSUB_HANHAS-1	;[57]
		LWORD	BGSUB_OVHANG-1	;[58]
		LWORD	BGSUB_ANARD30-1	;[59]
		LWORD	BGSUB_ANARD45-1	;[5A]
		LWORD	BGSUB_ANARD60-1	;[5B]
		LWORD	BGSUB_ANARU30-1	;[5C]
		LWORD	BGSUB_ANARU45-1	;[5D]
		LWORD	BGSUB_ANARU60-1	;[5E]
		LWORD	000000H		;[5F]
;
		LWORD	000000H		;[60]
		LWORD	BGSUB_KSETABG-1	;[61]
;
;
;************************************************************************
;*		course BG write sub status data				* 
;************************************************************************
;
;--------------	kotei data --------------------------------------
KOTESB		EQU	$
;	     00:ok
;	     FF:error
;
;			 0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F
		HEX	00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00	;[00-0F]
		HEX	00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00	;[10-1F]
		HEX	00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00	;[20-2F]
		HEX	00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00	;[30-3F]
		HEX	00,00,00,00,00,00,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF	;[40-4F]
		HEX	FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF	;[50-5F]
		HEX	FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF	;[60-6F]
		HEX	FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF	;[70-7F]
		HEX	FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF	;[80-8F]
		HEX	FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF	;[90-9F]
		HEX	FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF	;[A0-AF]
		HEX	FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF	;[B0-BF]
		HEX	FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF	;[C0-CF]
		HEX	FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF	;[D0-DF]
		HEX	FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF	;[E0-EF]
		HEX	FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF	;[F0-FF]
;
;--------------	kahen data --------------------------------------
KAHNSB		EQU	$
;	     00:normal [ 4 byte : (type no.),(X),(Y),(X wide) ]
;	     01:       [ 4 byte : (type no.),(X),(Y),(Y wide) ]
;	     02:       [ 5 byte : (type no.),(X),(Y),(X wide),(Y wide) ]
;	     FF:error
;
;	     top  bit:  x_fugou
;	     next bit:  y_fugou
;
;			 0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F
		HEX	FF						;[00] not use !!
		HEX	   02,01,01,02,02,02,02,02,02,01,01,01,00,01,01	;[01-0F]
		HEX	C2,C2,C2,00,02,01,02,02,02,02,00,01,01,00,00,02	;[10-1F]
		HEX	02,C2,C2,C2,C2,C2,C2,C2,C2,C2,C2,C2,C2,C2,C2,C2	;[20-2F]
		HEX	C2,C2,C2,C2,C2,02,02,02,02,02,02,02,00,00,01,01	;[30-3F]
		HEX	01,00,01,01,02,02,02,02,02,01,01,01,01,01,02,02	;[40-4F]
		HEX	01,00,C2,00,C2,C2,C2,00,02,02,02,02,02,02,02,FF	;[50-5F]
		HEX	FF,02,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF	;[60-6F]
		HEX	FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF	;[70-7F]
		HEX	FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF	;[80-8F]
		HEX	FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF	;[90-9F]
		HEX	FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF	;[A0-AF]
		HEX	FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF	;[B0-BF]
		HEX	FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF	;[C0-CF]
		HEX	FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF	;[D0-DF]
		HEX	FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF	;[E0-EF]
		HEX	FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF,FF	;[F0-FE]
		HEX	FF						;[FF] not use !!
;

;
;************************************************************************
;*		MAIN    LOOP    ROUTINE					*	
;************************************************************************
;
;
;		-IN-	WORK2,WORK3	CMP DATA FOR X
;			WORK4,WORK5	NORMAL DATA SELECT ROUTINE ADDR
;			WORK6,WORK7	RANDOM DATA SELECT ROUTINE ADDR
;			WORKA,WORKB	NORMAL DATA SELECT ROUTINE ADDR
;			WORKE,WORKF	ADDITION DATA FOR H_POS
;			WORK12,WORK13	CMP DATA FOR Y
;			WORK14,WORK15	NORMAL DATA SUM
;			WORK1A,WORK1B	CHANGE DATA SUM
;			WORK1D		Y_POS , X_POS HIGH
;			WORK1E		Y_POS , X_POS LOW
;			WORK1F		X_HABA OR Y_HABA
;
;
XWIDECP		EQU	WORK2
XWIDE		EQU	WORK1F
YWIDECP		EQU	WORK12
ROUTNR1		EQU	WORK4
ROUTRND		EQU	WORK6
ROUTNR2		EQU	WORKA
NDATSUM		EQU	WORK14
;
;
		MEM8
		IDX16
;
BG_YOKO		EQU	$

		LDA	<WORK1D		;SAVE X_POS(HIGH) & Y_POS(HIGH)
		PHA

		PHX			;SAVE SET INDEX

		LDY	#00000H		;LINE POINTER CLEAR

		JSR	BG_TATE
		MEM16
		IDX16

		PLX			;LOAD SET INDEX

		M8

		PLA
		STA	<WORK1D		;LOAD X_POS(HIGH) & Y_POS(HIGH)

		DEC	<XWIDE		;x wide counter dec.
		BNE	BGBFPT_CHK	; ALL LINE SET ?
					;  no: BGBFPT_CHK
BG_YOKO_RTL	EQU	$
		MI8

		RTL
;
;
;		BGBFPT CHECK ROUTINE
;
;
		MEM16
		IDX16
BGBFPT_CHK	EQU	$
		M16

		TXA			;NEXT SET POINTER GET
		CLC			;
		ADC	<WORKE		;
		TAX			;

		LDA	<WORKE		;ADD DATA FOR H IS MINUS ?
		BMI	BG_YOKO300	; YES BG_YOKO300

		JSR	RIGHT_CHECK	;RIGHT BGBFPT CHECK
		MEM16
		IDX16
		BRA	BG_YOKO400

BG_YOKO300	EQU	$
		JSR	LEFT_CHECK	;LEFT  BGBFPT CHECK
		MEM16
		IDX16

BG_YOKO400	EQU	$
		LDA	LKFLG		;set lock ?
		BNE	BG_YOKO_RTL	; yes: BG_YOKO_RTL

		LDA	<WORK16		;ADD FLAG FOR V IS ZERO ?
		BEQ	BG_YOKO600	; YES BG_YOKO600

		LDA	<WORK8		;ADD DATA FOR_V IS MINUS ?
		BMI	BG_YOKO450	; YES BG_YOKO450
					;
		LSR	A		;CALCULATE COMPARE DATA FOR V
		LSR	A		;
		LSR	A		;
		LSR	A		;
		LSR	A		;
		BRA	BG_YOKO480	;
					;
BG_YOKO450	EQU	$		;
		ASL	A
		ASL	A
		ASL	A
		XBA
		ORA	#0FF00H
;;;;K;;;;		XBA
;;;;K;;;;		LSR	A
;;;;K;;;;		ORA	#0FF80H
					;
BG_YOKO480	EQU	$		;
		STA	<WORK0		;
					;
		LDA	<YWIDECP	;
		SEC			;
		SBC	<WORK0		;
		BEQ	BG_YOKO_RTL	;NEW COMPARE DATA FOR V IS ZERO OR MINUS ( SHORI END )?
		BMI	BG_YOKO_RTL	; YES BG_YOKO_RTL

		STA	<YWIDECP	;

		LDA	<NDATSUM		;NORMAL DATA SUM IS 0FFFFH ?
		CMP	#0FFFFH		;
		BEQ	BG_YOKO600	; YES BG_YOKO600

		STZ	<WORK16		;ADD FLAG FOR V CLEAR

		TXA			;SET POINTER SHUUSEI
		CLC			;
		ADC	<WORK8		;
		TAX			;

		LDA	<WORK8		;ADDITION DATA FOR_V IS MINUS ?
		BMI	BG_YOKO500	; YES BG_YOKO500

		JSR	LOW_CHECK	;BGBFPT LOW CHECK
		MEM16
		IDX16

		LDA	LKFLG		;set lock ?
		BNE	BG_YOKO_RTL	; yes: BG_YOKO_RTL

		BRA	BG_YOKO600

BG_YOKO500	EQU	$
		JSR	HIGH_CHECK
		MEM16
		IDX16

BG_YOKO600	EQU	$
		M8
		BRA	BG_YOKO
;
;
;
;
;		-IN-	WORK2,WORK3	CMP DATA FOR X
;			WORK4,WORK5	NORMAL DATA SELECT ROUTINE ADDR
;			WORK6,WORK7	RANDOM DATA SELECT ROUTINE ADDR
;			WORKA,WORKB	NORMAL DATA SELECT ROUTINE ADDR
;			WORKE,WORKF	ADDITION DATA FOR H_POS
;			WORK12,WORK13	CMP DATA FOR Y
;			WORK14,WORK15	NORMAL DATA SUM
;			WORK1A,WORK1B	CHANGE DATA SUM
;			WORK1D		Y_POS , X_POS HIGH
;			WORK1E		Y_POS , X_POS LOW
;			WORK1F		X_HABA OR Y_HABA
;
;
;
;
		MEM8
		IDX16
BG_TATE_NXT	EQU	$
		M8
;
BG_TATE		EQU	$
;		LDA	<WORK2		;KISUU ME LINE ?
		LDA	<XWIDECP	;KISUU ME LINE ?
		SEC			;
		SBC	<XWIDE		;
		AND	#001H		;
		BNE	BG_TATE050	; NO BG_TATE050

		JMP	(ROUTNR1)		; READ NORMAL DATA
		MEM16
		IDX16

BG_TATE050	EQU	$
		JMP	(ROUTNR2)		; READ NORMAL2 DATA
		MEM16
		IDX16

BG_TATE100	EQU	$
		STA	>BGUNIT,X	; SET DATA TO BGUNIT

BG_TATE200	EQU	$
		TXA
		CLC			; SET ADR-INDEX ADDITION
		ADC	#00020H		;
		TAX

BG_TATE300	EQU	$
		INY
		CPY	<YWIDECP		; Y-COUNTER OK?
		BEQ	BG_TATE_RTS	; YES

		JSR	LOW2_CHECK
		MEM16
		IDX16

		LDA	LKFLG		;set lock ?
		BNE	BG_TATE_RTS	; yes: BG_TATE_RTS

		CPY	<NDATSUM		; Y-COUNTER : NORMAL DATA SUMMARY
		BCC	BG_TATE_NXT	; <

		M8
		JMP	(ROUTRND)		; READ RANDOM DATA
		MEM16
		IDX16
BG_TATE_RTS	EQU	$

		RTS
;
;
;
;
;************************************************************************
;*									*
;*              BGSUB                                     (BGYUKA)      *
;*									*
;*		-IN-	WORK1D(POS(H)),WORK1E(POS(L)),WORK1F(X_HABA)	*
;*									*
;************************************************************************
;
;
FLOOR_DATA	EQU	$
		WORD	BG_FLOOR_1		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		WORD	BG_FLOOR_RND		; SET ROUTINE ADR(RANDOM DATA ROUTINE)
		WORD	BG_FLOOR_2		; SET ROUTINE ADR(NORMAL2 DATA ROUTINE)
		WORD	00002H,00000H,00003H	;BGSUB
FLOOR_DTE	EQU	$
;
;++++++++++++++++++++++++++++++++++++++++++++++++
;+		NANAME	DATA			+
;++++++++++++++++++++++++++++++++++++++++++++++++
SLOPE_DATA	EQU	$
		WORD	BG_SLL30_1
		WORD	BG_FLOOR_RND
		WORD	BG_SLL30_2
		WORD	00002H,00020H,00004H	;SLL30
SLOPE_DTE0	EQU	$
		WORD	BG_SLL45_1
		WORD	BG_FLOOR_RND
		WORD	BG_SLL45_1
		WORD	00002H,00020H,00004H	;SLL45
SLOPE_DTE1	EQU	$
		WORD	BG_SLL60_1
		WORD	BG_FLOOR_RND
		WORD	BG_SLL60_1
		WORD	00002H,00040H,00005H	;SLL60
KBSLL_DATA	EQU	$
		WORD	BG_KBSLL_1
		WORD	BG_KABEB
		WORD	BG_KBSLL_1
		WORD	00002H,00020H,00004H	;KBSLL45
KBSLL_DTE	EQU	$
SLOPE_DTE2	EQU	$
		WORD	BG_SLR30_1
		WORD	BG_FLOOR_RND
		WORD	BG_SLR30_2
		WORD	00002H,0FFE0H,00004H	;SLR30
SLOPE_DTE3	EQU	$
		WORD	BG_SLR45_1
		WORD	BG_FLOOR_RND
		WORD	BG_SLR45_1
		WORD	00002H,0FFE0H,00004H	;SLR45
SLOPE_DTE4	EQU	$
		WORD	BG_SLR60_1
		WORD	BG_FLOOR_RND
		WORD	BG_SLR60_1
		WORD	00002H,0FFC0H,00005H	;SLR60
SLOPE_DTE5	EQU	$
KBSLR_DATA	EQU	$
		WORD	BG_KBSLR_1
		WORD	BG_KABEB
		WORD	BG_KBSLR_1
		WORD	00002H,0FFE0H,00004H	;KBSLR45
KBSLR_DTE	EQU	$
;
ROPE_DATA	EQU	$
		WORD	BG_RPL30_1		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		WORD	BG_RPL30_2		; SET ROUTINE ADR(NORMAL2 DATA ROUTINE)
		WORD	BG_RPL30_3		; SET ROUTINE ADR(NORMAL3 DATA ROUTINE)
		WORD	00002H,00020H,00001H	;RPL30
ROPE_DTE0	EQU	$
		WORD	BG_RPR30_1		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		WORD	BG_RPR30_2		; SET ROUTINE ADR(NORMAL2 DATA ROUTINE)
		WORD	BG_RPR30_3		; SET ROUTINE ADR(NORMAL3 DATA ROUTINE)
		WORD	0FFFEH,00020H,00001H	;RPR30
ROPE_DTE1	EQU	$
		WORD	BG_RPL45_1		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		WORD	BG_RPL45_1		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		WORD	BG_RPL45_1		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		WORD	00002H,00020H,00002H	;RPL45
ROPE_DTE2	EQU	$
		WORD	BG_RPR45_1		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		WORD	BG_RPR45_1		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		WORD	BG_RPR45_1		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		WORD	0FFFEH,00020H,00002H	;RPR45
ROPE_DTE3	EQU	$
		WORD	BG_RPL60_1		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		WORD	BG_RPL60_1		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		WORD	BG_RPL60_1		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		WORD	00002H,00040H,00003H	;RPL60
ROPE_DTE4	EQU	$
		WORD	BG_RPR60_1		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		WORD	BG_RPR60_1		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		WORD	BG_RPR60_1		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		WORD	0FFFEH,00040H,00003H	;RPR60
ROPE_DTE5	EQU	$
;
SENROS_DATA	EQU	$
		WORD	BG_SENROS_L		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		WORD	BG_SENROS_L		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		WORD	BG_SENROS_L		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		WORD	00002H,00020H,00002H	;SENROS_L
SENROS_DTE0	EQU	$
		WORD	BG_SENROS_R		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		WORD	BG_SENROS_R		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		WORD	BG_SENROS_R		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		WORD	0FFFEH,00020H,00002H	;SENROS_R
SENROS_DTE1
;
SAKA_DATA	EQU	$
		WORD	BG_SAKAL30_1		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		WORD	BG_SAKAL30_1		; SET ROUTINE ADR(NORMAL2 DATA ROUTINE)
		WORD	BG_SAKAL30_2		; SET ROUTINE ADR(NORMAL3 DATA ROUTINE)
		WORD	00002H,00020H,00002H	;SAKAL30
SAKA_DTE0	EQU	$
		WORD	BG_SAKAR30_1		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		WORD	BG_SAKAR30_1		; SET ROUTINE ADR(NORMAL2 DATA ROUTINE)
		WORD	BG_SAKAR30_2		; SET ROUTINE ADR(NORMAL3 DATA ROUTINE)
		WORD	0FFFEH,00020H,00002H	;SAKAR30
SAKA_DTE1	EQU	$
		WORD	BG_SAKAL45_1		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		WORD	BG_SAKAL45_1		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		WORD	BG_SAKAL45_1		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		WORD	00002H,00020H,00002H	;SAKAL45
SAKA_DTE2	EQU	$
		WORD	BG_SAKAR45_1		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		WORD	BG_SAKAR45_1		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		WORD	BG_SAKAR45_1		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		WORD	0FFFEH,00020H,00002H	;SAKAR45
SAKA_DTE3	EQU	$
		WORD	BG_SAKAL60_1		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		WORD	BG_SAKAL60_1		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		WORD	BG_SAKAL60_1		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		WORD	00002H,00040H,00003H	;SAKAL60
SAKA_DTE4	EQU	$
		WORD	BG_SAKAR60_1		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		WORD	BG_SAKAR60_1		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		WORD	BG_SAKAR60_1		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		WORD	0FFFEH,00040H,00003H	;SAKAR60
SAKA_DTE5	EQU	$
;
;
;++++++++++++++++++++++++++++++++++++++++++++++++
;+		TATEYOKO DATA			+
;++++++++++++++++++++++++++++++++++++++++++++++++
YOGAN_DATA12	EQU	$
		WORD	BG_YOGAN1		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		WORD	BG_YOGAN2		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		WORD	BG_YOGAN2		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		WORD	00002H,00000H,0FFFFH	;YOGAN (YOUGAN)
YOGAN_DT12E0	EQU	$
;
WATER_GL_DATA	EQU	$
		WORD	BG_WGRASS1		; SET ROUTINE ADR(NORMAL1 DATA ROUTINE)
		WORD	BG_WGRASS_LOW		; SET ROUTINE ADR(NORMAL2 DATA ROUTINE)
		WORD	BG_WGRASS2		; SET ROUTINE ADR(NORMAL3 DATA ROUTINE)
		WORD	00002H,00000H,00002H	;GRASS & LAND (WATER)
WATER_GL_DTE0	EQU	$
;
;
;++++++++++++++++++++++++++++++++++++++++++++++++
;+		INDEX	CHECKER			+
;++++++++++++++++++++++++++++++++++++++++++++++++
LSLOPE_DTE	EQU	KBSLL_DTE-FLOOR_DATA
RSLOPE_DTE	EQU	KBSLR_DTE-FLOOR_DATA
YOGAN_DT12E	EQU	YOGAN_DATA12-FLOOR_DATA
WATER_GL_DTE	EQU	WATER_GL_DATA-FLOOR_DATA
;
;++++++++++++++++++++++++++++++++++++++++++++++++
;+		NANAME	INDEX			+
;++++++++++++++++++++++++++++++++++++++++++++++++
NANAME_INDEX	EQU	$
;;;;;		BYTE	00CH			;[4]
		WORD	SLOPE_DATA-FLOOR_DATA	;[4]

;;;;;		BYTE	030H			;[5]
		WORD	SLOPE_DTE2-FLOOR_DATA	;[5]

;;;;;		BYTE	018H			;[6]
		WORD	SLOPE_DTE0-FLOOR_DATA	;[6]

;;;;;		BYTE	03CH			;[7]
		WORD	SLOPE_DTE3-FLOOR_DATA	;[7]

;;;;;		BYTE	024H			;[8]
		WORD	SLOPE_DTE1-FLOOR_DATA	;[8]

;;;;;		BYTE	048H			;[9]
		WORD	SLOPE_DTE4-FLOOR_DATA	;[9]

;;;;;		BYTE	054H			;[10]
		WORD	ROPE_DATA-FLOOR_DATA	;[10]

;;;;;		BYTE	06CH			;[11]
		WORD	ROPE_DTE1-FLOOR_DATA	;[11]

;;;;;		BYTE	084H			;[12]
		WORD	ROPE_DTE3-FLOOR_DATA	;[12]

		WORD	SENROS_DATA-FLOOR_DATA	;[52]

		WORD	SAKA_DATA-FLOOR_DATA	;[54]

		WORD	SAKA_DTE1-FLOOR_DATA	;[55]

		WORD	SAKA_DTE3-FLOOR_DATA	;[56]
;
;++++++++++++++++++++++++++++++++++++++++++++++++
;+		TATEYOKO INDEX			+
;++++++++++++++++++++++++++++++++++++++++++++++++
FLOOR_INDEX	EQU	FLOOR_DATA-FLOOR_DATA
WATER_GL_INDEX	EQU	WATER_GL_DATA-FLOOR_DATA
YOGAN_12_INDEX	EQU	YOGAN_DATA12-FLOOR_DATA
;
;
		MEM8
		IDX8
GET_RPOINT	EQU	$

		LDA	<WORK1D			;GET X_POS & Y_POS
		PHA				;
		AND	#0F0H			;
		STA	<WORK1			;
						;
		PLA				;
		ASL	A			;
		ASL	A			;
		ASL	A			;
		ASL	A			;
		STA	<WORK0			;
						;
		LDA	<WORK1E			;
		PHA				;
		LSR	A			;
		LSR	A			;
		LSR	A			;
		LSR	A			;
		ORA	<WORK1			;
		STA	<WORK1			;
						;
		PLA				;
		AND	#00FH			;
		ORA	<WORK0			;
		STA	<WORK0			;
						;
		RTS				;
;
		MEM8
		IDX8
GET_RPOINT_X	EQU	$

		LDA	<WORK0			;X_POS SHUUSEI
		CLC				;
		ADC	<WORK4			;

		PHA				;SEPARATE X_POS & Y_POS
		LSR	A			;
		LSR	A			;
		LSR	A			;
		LSR	A			;
		STA	<WORK1D			;
						;
		PLA				;
		AND	#00FH			;
		STA	<WORK1E			;
						;
		LDA	<WORK1			;
						;
		PHA				;
		AND	#0F0H			;
		ORA	<WORK1D			;
		STA	<WORK1D			;
						;
		PLA				;
		ASL	A			;
		ASL	A			;
		ASL	A			;
		ASL	A			;
		ORA	<WORK1E			;
		STA	<WORK1E			;

		LDA	#000H			;COMPARE DATA FOR X SHUUSEI
		SEC				;
		SBC	<XWIDE			;
		STA	<XWIDE			;

		RTS

		MEM8
		IDX8
GET_RPOINT_Y	EQU	$

		LDA	<WORK0			;SEPARATE X_POS(LOW)
						;
		PHA				;
		LSR	A			;
		LSR	A			;
		LSR	A			;
		LSR	A			;
		STA	<WORK1D			;
						;
		PLA				;
		AND	#00FH			;
		STA	<WORK1E			;

		LDA	<WORK1			;Y_POS SHUUSEI
		CLC				;
		ADC	<WORK5			;
						;
		PHA				;
		AND	#0F0H			;
		ORA	<WORK1D			;
		STA	<WORK1D			;
						;
		PLA				;
		ASL	A			;
		ASL	A			;
		ASL	A			;
		ASL	A			;
		ORA	<WORK1E			;
		STA	<WORK1E			;

		RTS
;
		MEM8
		IDX8
BGSUB_KBSLL	EQU	$
		I16
		LDX	#(KBSLL_DATA-FLOOR_DATA+00000H)
		BRA	BGSUB_SLOPE
;
		MEM8
		IDX8
BGSUB_KBSLR	EQU	$
		I16
		LDX	#(KBSLR_DATA-FLOOR_DATA+00000H)
		BRA	BGSUB_SLOPE
;
		MEM8
		IDX8
BGSUB_SAKA30	EQU	$
		LDA	#00AH
		BRA	NANAME100
;
		MEM8
		IDX8
BGSUB_SAKA45	EQU	$
		LDA	#00BH
		BRA	NANAME100
;
		MEM8
		IDX8
BGSUB_SAKA60	EQU	$
		LDA	#00CH
		BRA	NANAME100
;
		MEM8
		IDX8
BGSUB_SENROS	EQU	$
		LDA	#009H
		BRA	NANAME100
;
		MEM8
		IDX8
BGSUB_SLL30	EQU	$
BGSUB_SLR30	EQU	$
BGSUB_SLL45	EQU	$
BGSUB_SLR45	EQU	$
BGSUB_SLL60	EQU	$
BGSUB_SLR60	EQU	$
BGSUB_RP30	EQU	$
BGSUB_RP45	EQU	$
BGSUB_RP60	EQU	$
;;;;;
;;;;;		NANAME BG INDEX GET
;;;;;
		LDA	WORK1C
		SEC
		SBC	#004H
		CMP	#006H
		BCC	NANAME100

		SEC
		SBC	#006H
NANAME100	EQU	$
		ASL	A
		TAY

		I16

		LDX	NANAME_INDEX,Y

		CPY	#006H			;slope ?
		BCC	BGSUB_SLOPE		; yes: BGSUB_SLOPE

		LDA	<XWIDE			;left rope ?
		BPL	BGSUB_ROPE		; yes: BGSUB_ROPE

		TXA				;index adjust
		CLC				;
		ADC	#00CH			;
		TAX				;
;
		MEM8
		IDX8
BGSUB_ROPE2	EQU	$
		I16
		LDA	#000H			;x_wide reverse
		SEC				;
		SBC	<XWIDE			;
		STA	<XWIDE			;

BGSUB_FLOOR	EQU	$
BGSUB_SLOPE	EQU	$
BGSUB_ROPE	EQU	$
		M16
		LDA	FLOOR_DATA,X		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		STA	<ROUTNR1			;

		INX
		INX
		LDA	FLOOR_DATA,X		; SET ROUTINE ADR(RANDOM DATA ROUTINE)
		STA	<ROUTRND			;

		INX
		INX
		LDA	FLOOR_DATA,X		; SET ROUTINE ADR(NORMAL2 DATA ROUTINE)
		STA	<ROUTNR2			;

		INX
		INX
		LDA	FLOOR_DATA,X	;ADDITION DATA FOR H_POS
		STA	<WORKE

		INX
		INX
		LDA	FLOOR_DATA,X	; ADDITION DATA FOR V_POS
		STA	<WORK8

		INX
		INX
		LDA	FLOOR_DATA,X	; NORMAL DATA SUMMARY
		STA	<NDATSUM

		STZ	<WORK16		; ADDITION FLAG CLEAR

		CPX	#LSLOPE_DTE	; CHR IS FLOOR or LEFT SLOPE ?
		BCC	BG_FLOOR_S	;  YES BG_FLOOR_S
		CPX	#RSLOPE_DTE	; CHR IS RIGHT SLOPE ?
		BCC	BG_SLOPE	;  YES BG_SLOPE
		CPX	#WATER_GL_DTE	; CHR IS WATER GLASS & LAND ?
		BCS	BG_WGL_S	;  YES BG_WGL_S

		STZ	<WORK0

		CPX	#YOGAN_DT12E	; CHR IS YOGAN ?
		BCS	BG_WLAND_S	;  YES BG_WLAND_S

		LDA	#002H
		BRA	BG_SLPWLND
BG_WLAND_S	EQU	$
		LDA	#001H
BG_SLPWLND	EQU	$
		I8

		JSR	UNPT_GET20
		MEM16
		IDX16
		BRA	BG_ROPE

BG_SLOPE	EQU	$
		LDA	#00002H
		STA	<WORK0

;		LDA	#003H
		INC	A
		BRA	BG_SLPWLND
;
BG_FLOOR_S	EQU	$
		I8
		JSR	UNPT_GET2
		MEM16
		IDX16

BG_ROPE		EQU	$
		M8
		LDA	<XWIDE		;SET COMPARE DATA ( x wide )
		STA	<XWIDECP	;
		STZ	<WORK3		;

		JMP	BG_YOKO
BG_WGL_S	EQU	$
		I8
		RTS
;
;
;
;
		MEM8
		IDX8
BGSUB		EQU	$

		I16
		LDX	#FLOOR_INDEX
		BRA	BGSUB_FLOOR
;
		MEM8
		IDX8
BGSUB_WGRSS_LOW	EQU	$

		I16
		LDX	#WATER_GL_INDEX
		BRA	BGSUB_FLOOR
;
		MEM8
		IDX8
BGSUB_YOGAN	EQU	$

		I16
		LDX	#YOGAN_12_INDEX
		JMP	BGSUB_FLOOR
;
;
;
;
;
;
;
KOTEI_RT	EQU	$
;
		WORD	BG_HILIGHT_RD1		;[0]
		WORD	BG_HILIGHT_BD1		;[1]
		WORD	BG_HILIGHT_RD2		;[2]
		WORD	BG_HILIGHT_BD2		;[3]
;
		WORD	BG_HILIGHT_RD3		;[4]
		WORD	BG_HILIGHT_BD3		;[5]
		WORD	BG_HILIGHT_RD4		;[6]
		WORD	BG_HILIGHT_BD4		;[7]
;
		WORD	BG_HILIGHT_RHL1		;[8]
		WORD	BG_HILIGHT_BHL1		;[9]
		WORD	BG_HILIGHT_RHL2		;[A]
		WORD	BG_HILIGHT_BHL2		;[B]
;
		WORD	BG_HILIGHT_RLL1		;[C]
		WORD	BG_HILIGHT_BLL1		;[D]
		WORD	BG_HILIGHT_RLL2		;[E]
		WORD	BG_HILIGHT_BLL2		;[F]
;
		WORD	BG_HILIGHT_RHR1		;[10]
		WORD	BG_HILIGHT_BHR1		;[11]
		WORD	BG_HILIGHT_RHR2		;[12]
		WORD	BG_HILIGHT_BHR2		;[13]
;
		WORD	BG_HILIGHT_RLR1		;[14]
		WORD	BG_HILIGHT_BLR1		;[15]
		WORD	BG_HILIGHT_RLR2		;[16]
		WORD	BG_HILIGHT_BLR2		;[17]
;
		WORD	BG_HILIGHT_RHL21	;[18]
		WORD	BG_HILIGHT_BHL21	;[19]
		WORD	BG_HILIGHT_RHL22	;[1A]
		WORD	BG_HILIGHT_BHL22	;[1B]
;
		WORD	BG_HILIGHT_RLL21	;[1C]
		WORD	BG_HILIGHT_BLL21	;[1D]
		WORD	BG_HILIGHT_RLL22	;[1E]
		WORD	BG_HILIGHT_BLL22	;[1F]
;
		WORD	BG_HILIGHT_RHR21	;[20]
		WORD	BG_HILIGHT_BHR21	;[21]
		WORD	BG_HILIGHT_RHR22	;[22]
		WORD	BG_HILIGHT_BHR22	;[23]
;
		WORD	BG_HILIGHT_RLR21	;[24]
		WORD	BG_HILIGHT_BLR21	;[25]
		WORD	BG_HILIGHT_RLR22	;[26]
		WORD	BG_HILIGHT_BLR22	;[27]
;
		WORD	BG_HILIGHT_RS11		;[28]
		WORD	BG_HILIGHT_BS11		;[29]
		WORD	BG_HILIGHT_RS12		;[2A]
		WORD	BG_HILIGHT_BS12		;[2B]
;
		WORD	BG_HILIGHT_RS21		;[2C]
		WORD	BG_HILIGHT_BS21		;[2D]
		WORD	BG_HILIGHT_RS22		;[2E]
		WORD	BG_HILIGHT_BS22		;[2F]
;
		WORD	BG_KABE_HOLE		;[30]
		WORD	BG_KABE_MOVE		;[31]
;
		WORD	BG_SENRO00		;[32]
		WORD	BG_SENRO01		;[33]
		WORD	BG_SENRO02		;[34]
		WORD	BG_SENRO03		;[35]
		WORD	BG_SENRO04		;[36]
		WORD	BG_SENRO05		;[37]
		WORD	BG_SENRO06		;[38]
		WORD	BG_SENRO07		;[39]
		WORD	BG_SENRO08		;[3A]
;
		WORD	BG_RAKUGAKI00		;[3B]
		WORD	BG_RAKUGAKI01		;[3C]
		WORD	BG_RAKUGAKI02		;[3D]
		WORD	BG_RAKUGAKI03		;[3E]
		WORD	BG_RAKUGAKI04		;[3F]
		WORD	BG_RAKUGAKI05		;[40]
		WORD	BG_RAKUGAKI06		;[41]
		WORD	BG_RAKUGAKI07		;[42]
		WORD	BG_RAKUGAKI08		;[43]
		WORD	BG_RAKUGAKI09		;[44]
		WORD	BG_RAKUGAKI10		;[45]
;
		MEM8
		IDX8
BGSUB_BLKSLM8	EQU	$
		M16

		LDA	#BG_BLKSLM
		JSR	BGSUB_TATEYOKO
		JMP	BGSUB_TTYOKO04
;
		MEM8
		IDX8
BGSUB_BLKSLM6	EQU	$
		M16

		LDA	#BG_BLKSLM
		JSR	BGSUB_TATEYOKO
		JMP	BGSUB_TTYOKO03
;
		MEM8
		IDX8
BGSUB_BLKSLM4	EQU	$
		M16

		LDA	#BG_BLKSLM
		JSR	BGSUB_TATEYOKO
		BRA	BGSUB_TTYOKO02
;
		MEM8
		IDX8
BGSUB_WINDOW	EQU	$
		M16

		LDA	#BG_WINDOW
		JSR	BGSUB_TATEYOKO
		BRA	BGSUB_TTYOKO01
;
		MEM8
		IDX8
BGSUB_POST	EQU	$
		M16

		LDA	#BG_POST
		JSR	BGSUB_TATEYOKO
		BRA	BGSUB_TTYOKO01
;
		MEM8
		IDX8
BGSUB_DOOR	EQU	$
		M16

		LDA	#BG_DOOR
		JSR	BGSUB_TATEYOKO
		BRA	BGSUB_TTYOKO01
;
		MEM8
		IDX8
HILIGHT_RD1	EQU	$
HILIGHT_BD1	EQU	$
HILIGHT_RD2	EQU	$
HILIGHT_BD2	EQU	$
HILIGHT_RD3	EQU	$
HILIGHT_BD3	EQU	$
HILIGHT_RD4	EQU	$
HILIGHT_BD4	EQU	$
HILIGHT_RHL1	EQU	$
HILIGHT_RHL2	EQU	$
HILIGHT_BHL1	EQU	$
HILIGHT_BHL2	EQU	$
HILIGHT_RLL1	EQU	$
HILIGHT_RLL2	EQU	$
HILIGHT_BLL1	EQU	$
HILIGHT_BLL2	EQU	$
HILIGHT_RHR1	EQU	$
HILIGHT_RHR2	EQU	$
HILIGHT_BHR1	EQU	$
HILIGHT_BHR2	EQU	$
HILIGHT_RLR1	EQU	$
HILIGHT_RLR2	EQU	$
HILIGHT_BLR1	EQU	$
HILIGHT_BLR2	EQU	$
HILIGHT_RHL21	EQU	$
HILIGHT_RHL22	EQU	$
HILIGHT_BHL21	EQU	$
HILIGHT_BHL22	EQU	$
HILIGHT_RLL21	EQU	$
HILIGHT_RLL22	EQU	$
HILIGHT_BLL21	EQU	$
HILIGHT_BLL22	EQU	$
HILIGHT_RHR21	EQU	$
HILIGHT_RHR22	EQU	$
HILIGHT_BHR21	EQU	$
HILIGHT_BHR22	EQU	$
HILIGHT_RLR21	EQU	$
HILIGHT_RLR22	EQU	$
HILIGHT_BLR21	EQU	$
HILIGHT_BLR22	EQU	$
HILIGHT_RS11	EQU	$
HILIGHT_RS12	EQU	$
HILIGHT_BS11	EQU	$
HILIGHT_BS12	EQU	$
HILIGHT_RS21	EQU	$
HILIGHT_RS22	EQU	$
HILIGHT_BS21	EQU	$
HILIGHT_BS22	EQU	$
KABE_HOLE	EQU	$
KABE_MOVE	EQU	$
SENRO00		EQU	$
SENRO01		EQU	$
SENRO02		EQU	$
SENRO03		EQU	$
SENRO04		EQU	$
SENRO05		EQU	$
SENRO06		EQU	$
SENRO07		EQU	$
SENRO08		EQU	$
RAKUGAKI00	EQU	$
RAKUGAKI01	EQU	$
RAKUGAKI02	EQU	$
RAKUGAKI03	EQU	$
RAKUGAKI04	EQU	$
RAKUGAKI05	EQU	$
RAKUGAKI06	EQU	$
RAKUGAKI07	EQU	$
RAKUGAKI08	EQU	$
RAKUGAKI09	EQU	$
RAKUGAKI10	EQU	$
		I16

;		LDX	<BGDTPT
		LDY	<BGDTPT
		DEY

		LDA	[<BGDTADR],Y
;		LDA	>DTBUFF-1,X
		ASL	A
		TAY

		M16
		LDA	KOTEI_RT,Y

		I8

		JSR	BGSUB_TATEYOKO

		LDA	<ROUTNR1
		CMP	#BG_HILIGHT_RD1	; DATA SET ROUTINE IS KIND OF HILIGHT (1CHAR) ?
		BCC	BGSUB_TATEYOKO0	; YES BGSUB_TATEYOKO0

		CMP	#BG_WATER	; DATA SET ROUTINE IS KIND OF HILIGHT (2CHAR) ?
		BCC	BGSUB_TATEYOKO1	; YES BGSUB_TATEYOKO1

					;1 char.
		JMP	BGSUB_TTYOKO00	;  yes: BGSUB_TTYOKO00
;
		MEM16
		IDX8
BGSUB_TATEYOKO	EQU	$
		STA	<ROUTNR1			; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		STA	<ROUTRND			;
		STA	<ROUTNR2			;

BGSUB_HV	EQU	$
		LDA	#00002H		; ADDITION DATA FOR H_POS
		STA	<WORKE

		STZ	<WORK8		; ADDITION DATA FOR V_POS

		LDA	#0FFFFH		; NORMAL DATA SUMMARY
		STA	<NDATSUM

		STZ	<WORK16		; ADDITION FLAG CLEAR

		STZ	<WORK0

		LDA	#001H		; GET UNIT SET POINTER
		JSR	UNPT_GET20	;
		MEM16
		IDX16

		RTS
;
		LDA	<ROUTNR1
;		CMP	#BG_HILIGHT_RD1	; DATA SET ROUTINE IS KIND OF HILIGHT (1CHAR) ?
;		BCC	BGSUB_TATEYOKO0	; YES BGSUB_TATEYOKO0

;		CMP	#BG_WATER	; DATA SET ROUTINE IS KIND OF HILIGHT (2CHAR) ?
;		BCC	BGSUB_TATEYOKO1	; YES BGSUB_TATEYOKO1

;		CMP	#BG_BABULE	; DATA SET ROUTINE IS KIND OF BABULE ?
;		BEQ	BGSUB_TATEYOKO3	; YES BGSUB_TATEYOKO3

;		CMP	#BG_KABE_HOLE	; data set routine is kabe course hole ?
;		BEQ	BGSUB_TATEYOKO0	;  yes: BGSUB_TATEYOKO0

;		CMP	#BG_KABE_MOVE	; data set routine is kabe course moving kabe ?
;		BEQ	BGSUB_TTYOKO00	;  yes: BGSUB_TTYOKO00

;		CMP	#BG_WINDOW	; data set routine is kabe course window ?
;		BEQ	BGSUB_TTYOKO01	;  yes: BGSUB_TTYOKO01

;		CMP	#BG_POST	; data set routine is kabe course post ?
;		BEQ	BGSUB_TTYOKO01	;  yes: BGSUB_TTYOKO01

;		CMP	#BG_BABS	; DATA SET ROUTINE IS KIND OF BABULE ?
		BNE	BGSUB_TATEYOKO4	; NO  BGSUB_TATEYOKO4
;		BRA	BGSUB_TATEYOKO3	; YES BGSUB_TATEYOKO3
;
BGSUB_TTYOKO00	EQU	$
		M8
		LDA	#007H		;X_wide set
		STA	<XWIDE

		BRA	BGSUB_TATEYOKO20

BGSUB_TTYOKO01	EQU	$
		M8
		LDA	<XWIDE
		PHA

		LDA	#002H
		BRA	BGSUB_TTYOKO05

BGSUB_TTYOKO02	EQU	$
		M8
		LDA	<XWIDE
		INC	A
		PHA

		LDA	#004H
		BRA	BGSUB_TTYOKO05

BGSUB_TTYOKO03	EQU	$
		M8
		LDA	<XWIDE
		INC	A
		PHA

		LDA	#006H
		BRA	BGSUB_TTYOKO05

BGSUB_TTYOKO04	EQU	$
		M8
		LDA	<XWIDE
		INC	A
		PHA

		LDA	#008H

BGSUB_TTYOKO05	EQU	$
		STA	<XWIDE

		PLA
		BRA	BGSUB_TATEYOKO20
;
BGSUB_TATEYOKO0	EQU	$
		M8
		LDA	#001H		; Y_WIDE & X_WIDE SET
		BRA	BGSUB_TATEYOKO2	;
					;
BGSUB_TATEYOKO1	EQU	$		;
		M8			;
		LDA	#002H		;
					;
BGSUB_TATEYOKO2	EQU	$		;
		STA	<XWIDE

BGSUB_TATEYOKO20	EQU	$
		STA	<YWIDECP	; Y_WIDE COMP. DATA SET
		STZ	<WORK13		;
		M16
		DEC	<BGDTPT
		BRA	BGSUB_TATEYOKO4
;
BGSUB_TATEYOKO3	EQU	$
		M8
		LDA	<WORK10		; Y_WIDE CHOUSEI
		STA	<YWIDECP	;
		STZ	<WORK13

BGSUB_TATEYOKO4	EQU	$
		M8
		LDA	<XWIDE		;set compare data ( x wide )
		STA	<XWIDECP	;
		STZ	<WORK3		;

		JMP	BG_YOKO
;
		MEM8
		IDX8
BGSUB_WATER	EQU	$
		M16

		LDA	#BG_WATER		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		JSR	BGSUB_TATEYOKO
		JMP	BGSUB_TATEYOKO4
;
		MEM8
		IDX8
BGSUB_WROCK	EQU	$
		M16

		LDA	#BG_WROCK		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		JSR	BGSUB_TATEYOKO
		JMP	BGSUB_TATEYOKO4
;
		MEM8
		IDX8
BGSUB_WLAND	EQU	$
		M16

		LDA	#BG_WLAND		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		JSR	BGSUB_TATEYOKO
		JMP	BGSUB_TATEYOKO4
;
		MEM8
		IDX8
BGSUB_BLOCK	EQU	$
		LDA	<XWIDE			;last v_line ?
		BEQ	BGSUB_BLOCK100		; yes: BGSUB_BLOCK100

		LDA	<WORK1E			; POSITION CHECK
		AND	#011H			;
		BEQ	BGSUB_BLOCK200		;
		CMP	#011H			;
		BEQ	BGSUB_BLOCK200		;

BGSUB_BLOCK100	EQU	$
		M16
		LDA	#BG_BLOCK2		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		JSR	BGSUB_TATEYOKO
		JMP	BGSUB_TATEYOKO4
BGSUB_BLOCK200	EQU	$
		M16
		LDA	#BG_BLOCK1		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		JSR	BGSUB_TATEYOKO
		JMP	BGSUB_TATEYOKO4
;
		MEM8
		IDX8
BGSUB_KYUKA	EQU	$
		LDA	<XWIDE			;last v_line ?
		BEQ	BGSUB_KYUKA100		; yes: BGSUB_KYUKA100

		LDA	<WORK1E			; POSITION CHECK
		AND	#011H			;
		BEQ	BGSUB_KYUKA200		;
		CMP	#011H			;
		BEQ	BGSUB_KYUKA200		;

BGSUB_KYUKA100	EQU	$
;		INC	<XWIDE
		M16
		LDA	#BG_KYUKA1		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		JSR	BGSUB_TATEYOKO
		JMP	BGSUB_TATEYOKO4
BGSUB_KYUKA200	EQU	$
;		INC	<XWIDE
		M16
		LDA	#BG_KYUKA2		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		JSR	BGSUB_TATEYOKO
		JMP	BGSUB_TATEYOKO4
;
		MEM8
		IDX8
BGSUB_EAT	EQU	$
		M16

		LDA	#BG_EAT		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		JSR	BGSUB_TATEYOKO
		JMP	BGSUB_TATEYOKO4
;
		MEM8
		IDX8
BGSUB_SOAP1_R1	EQU	$
		M16

		LDA	#BG_SOAP1_R1	;DATA SET ROUTINE ADR
		JSR	BGSUB_TATEYOKO
		JMP	BGSUB_TATEYOKO4
;
		MEM8
		IDX8
BGSUB_SOAP1_B1	EQU	$
		M16

		LDA	#BG_SOAP1_B1	;DATA SET ROUTINE ADR
		JSR	BGSUB_TATEYOKO
		JMP	BGSUB_TATEYOKO4
;
		MEM8
		IDX8
BGSUB_SOAP1_R2	EQU	$
		M16

		LDA	#BG_SOAP1_R2	;DATA SET ROUTINE ADR
		JSR	BGSUB_TATEYOKO
		JMP	BGSUB_TATEYOKO4
;
		MEM8
		IDX8
BGSUB_SOAP1_B2	EQU	$
		M16

		LDA	#BG_SOAP1_B2	;DATA SET ROUTINE ADR
		JSR	BGSUB_TATEYOKO
		JMP	BGSUB_TATEYOKO4
;
		MEM8
		IDX8
BGSUB_SOAP2	EQU	$
		M16

		LDA	#BG_SOAP2	;DATA SET ROUTINE ADR
		JSR	BGSUB_TATEYOKO
		JMP	BGSUB_TATEYOKO4
;
		MEM8
		IDX8
BGSUB_SOAP3	EQU	$
		M16

		LDA	#BG_SOAP3	;DATA SET ROUTINE ADR
		JSR	BGSUB_TATEYOKO
		JMP	BGSUB_TATEYOKO4
;
		MEM8
		IDX8
BGSUB_SOAP	EQU	$
		M16

		LDA	#BG_SOAP	;DATA SET ROUTINE ADR
		JSR	BGSUB_TATEYOKO
		JMP	BGSUB_TATEYOKO4
;
		MEM8
		IDX8
BGSUB_KABEB	EQU	$
		M16

		LDA	#BG_KABEB	;DATA SET ROUTINE ADR
		JSR	BGSUB_TATEYOKO
		JMP	BGSUB_TATEYOKO4
;
		MEM8
		IDX8
BGSUB_KBWTR	EQU	$
		M16

		LDA	#BG_KBWTR	;DATA SET ROUTINE ADR
		JSR	BGSUB_TATEYOKO
		JMP	BGSUB_TATEYOKO4
;
		MEM8
		IDX8
BGSUB_CABE	EQU	$
		M16

		LDA	#BG_CABE	; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		JSR	BGSUB_HV

		M8
		LDA	<YWIDECP	;v wide is only 1 line ?
		CMP	#001H		;
		BEQ	BGSUB_CABE0100	;

		LDA	<XWIDE		;x wide is only 1 line ?
		CMP	#001H		;
		BEQ	BGSUB_CABE0200	;

		M16
		LDA	#BG_CABE
		BRA	BGSUB_CABE0300

BGSUB_CABE0100	EQU	$
		M16
		LDA	#BG_CABEH
		BRA	BGSUB_CABE0300

BGSUB_CABE0200	EQU	$
		M16
		LDA	#BG_CABEV

BGSUB_CABE0300	EQU	$
		STA	<ROUTNR1			; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		STA	<ROUTRND			;
		STA	<ROUTNR2			;

		JMP	BGSUB_TATEYOKO4
;
;
;
;
;
;
BABULE_INDEX	EQU	$
		WORD	00000H		;[21]

		WORD	00020H		;[22]

		WORD	00040H		;[23]

		WORD	00060H		;[24]

		WORD	00080H		;[25]

		WORD	000A0H		;[26]

		WORD	000C0H		;[27]

		WORD	000E0H		;[28]

		WORD	00180H		;[29]

		WORD	00188H		;[2A]

		WORD	00190H		;[2B]

		WORD	00198H		;[2C]

		WORD	001A0H		;[2D]

		WORD	001A8H		;[2E]

		WORD	001B0H		;[2F]

		WORD	001B8H		;[30]

		WORD	00100H		;[31]

		WORD	00120H		;[32]

		WORD	00140H		;[33]

		WORD	00160H		;[34]
;
		MEM8
		IDX8
BGSUB_BABULE_R1	EQU	$
BGSUB_BABULE_B1	EQU	$
BGSUB_BABULE_R2	EQU	$
BGSUB_BABULE_B2	EQU	$
BGSUB_BABULE_R3	EQU	$
BGSUB_BABULE_B3	EQU	$
BGSUB_BABULE_R4	EQU	$
BGSUB_BABULE_B4	EQU	$
BGSUB_BABS_R1	EQU	$
BGSUB_BABS_B1	EQU	$
BGSUB_BABS_R2	EQU	$
BGSUB_BABS_B2	EQU	$
BGSUB_BABS_R3	EQU	$
BGSUB_BABS_B3	EQU	$
BGSUB_BABS_R4	EQU	$
BGSUB_BABS_B4	EQU	$
BGSUB_HILIGHT_R1	EQU	$
BGSUB_HILIGHT_B1	EQU	$
BGSUB_HILIGHT_R2	EQU	$
BGSUB_HILIGHT_B2	EQU	$

		I16

;		LDX	<BGDTPT

;		LDA	>DTBUFF-4,X
		LDA	WORK1C

		I8
		SEC
		SBC	#021H
		ASL	A
		TAY

		M16
		LDA	BABULE_INDEX,Y

		CPY	#010H		;small babule ?
		BCC	BGSUB_BABBAB	;
		CPY	#020H		;
		BCS	BGSUB_BABBAB	; no: BGSUB_BABBAB
;
		MEM16
		IDX8
BGSUB_BABBAB2	EQU	$
		STA	<WORK18
		M8

		LDA	#001H
		BRA	BGSUB_BABBAB3
;
		MEM16
		IDX8
BGSUB_BABBAB	EQU	$
		STA	<WORK18		;DATA INDEX SET
		M8

		LDA	#000H

BGSUB_BABBAB3	EQU	$
		STA	<WORK1

		STZ	<WORK11

		I16
;		LDX	<BGDTPT		;Y_WIDE GET
		LDY	<BGDTPT		;
					;
		LDA	[<BGDTADR],Y	;
;		LDA	>DTBUFF,X	;
		STA	<WORK10		;
		I8

		BMI	BGSUB_BAB2000	;POSITION IS UNDER COURNER ?
					; YES BGSUB_BAB2000
;
		LDA	<XWIDE
		BMI	BGSUB_BAB1000	;POSITION IS RIGHT COURNER ?
					; YES BGSUB_BAB1000		
;
		LDA	<WORK1		;SMALL BABULE ?
		BEQ	BGSUB_BAB100	;  NO BGSUB_BAB100
		JMP	BGSUB_BAB6000	; YES BGSUB_BAB6000
;
BGSUB_BAB100	EQU	$
		INC	<WORK10		;Y_WIDE CHOUSEI
		JMP	BGSUB_BAB5000
BGSUB_BAB1000	EQU	$
;
					;GET DATA INDEX
		LDA	<WORK1			;GET INDEX FOR GET DATA INDEX
		PHA				;
		PHA				;
		SEC				;
		SBC	<XWIDE			;
		ASL	A			;
		TAX				;
					;
		M16			;
		LDA	BABULEPOS1,X	;
					;
		PLY				;SMALL BABULE ?
		BEQ	BGSUB_BAB1500		; NO BGSUB_BAB1500
					;
		LSR	A		;
BGSUB_BAB1500	EQU	$		;
		CLC			;
		ADC	<WORK18		;
		STA	<WORK18		;
		M8			;
;
		PLA			;SMALL BABULE ?
		BNE	BGSUB_BAB1800	; YES BGSUB_BAB1800
;
		INC	<WORK10
		LDA	<XWIDE
		STA	<WORK4
;
		JMP	BGSUB_BAB4000
;
BGSUB_BAB1800	EQU	$
		LDA	<XWIDE
		INC	A
		STA	<WORK4
		JMP	BGSUB_BAB4000
;
BGSUB_BAB2000	EQU	$
		LDA	<XWIDE
		BMI	BGSUB_BAB2500	;POSITION IS RIGHT COURNER ?
					; YES BGSUB_BAB2500
;
		STZ	<WORK0
;
					;GET DATA INDEX
		LDA	<WORK1			;GET INDEX FOR GET DATA INEX
		PHA				;
		SEC				;
		SBC	<WORK10			;
		ASL	A			;
		TAX				;
					;
		M16			;
		LDA	BABULEPOS2,X	;
		CLC			;
		ADC	<WORK18		;
		STA	<WORK18		;
		M8			;
;
		PLA			;SMALL BABULE ?
		BNE	BGSUB_BAB2300	; YES BGSUB_BAB2300

		LDA	<WORK10
		STA	<WORK5
		BRA	BGSUB_BAB3000
;
BGSUB_BAB2300	EQU	$
		STZ	<WORK5
		BRA	BGSUB_BAB3000
;
;
;
;
BGSUB_BAB2500	EQU	$
		LDA	#001H
		STA	<WORK0
;
					;GET DATA INDEX
		LDA	<WORK1			;GET INDEX FOR GET DATA INDEX
		PHA				;
		PHA				;
		PHA				;
		SEC				;
		SBC	<XWIDE			;
		ASL	A			;
		TAX				;

					;
		M16			;
		LDA	BABULEPOS1,X	;
					;
		PLY				;SMALL BABULE ?
		BEQ	BGSUB_BAB2700		; NO BGSUB_BAB2700
					;
		LSR	A		;
BGSUB_BAB2700	EQU	$		;
		CLC			;
		ADC	<WORK18		;
		STA	<WORK18		;
		M8			;
					;
		PLA				;GET INDEX FOR GET DATA INDEX
BGSUB_BAB2750	EQU	$			;
		SEC				;
		SBC	<WORK10			;
		ASL	A			;
		TAX				;
					;
		M16			;
		LDA	BABULEPOS2,X	;
		CLC			;
		ADC	<WORK18		;
		STA	<WORK18		;
		M8			;
;
		PLA			;SMALL BABULE ?
		BNE	BGSUB_BAB2800	; YES BGSUB_BAB2800

		LDA	<XWIDE
		STA	<WORK4
		LDA	<WORK10
		STA	<WORK5
		BRA	BGSUB_BAB3000
;
BGSUB_BAB2800	EQU	$
		LDA	<XWIDE
		INC	A
		STA	<WORK4
		STZ	<WORK5
;
BGSUB_BAB3000	EQU	$
		LDA	<WORK0
		PHA

		LDA	<WORK1
		PHA

		JSR	GET_RPOINT	;drow start point get
		JSR	GET_RPOINT_Y	;
		MEM8
		IDX8

		PLA
		STA	<WORK1		;SMALL BABULE ?
		EOR	#001H
		PHA
		SEC
		SBC	<WORK10
		STA	<WORK10

		PLA			;SMALL BABULE ?
		BNE	BGSUB_BAB3900	; NO BGSUB_BAB3900

		PLA			;LEFT UNDER COURNER ?
		BEQ	BGSUB_BAB6000	; YES BGSUB_BAB6000
		BRA	BGSUB_BAB4000	; NO  BGSUB_BAB4000

BGSUB_BAB3900	EQU	$
		PLA			;LEFT UNDER COURNER ?
		BEQ	BGSUB_BAB5000	; YES BGSUB_BAB5000

BGSUB_BAB4000	EQU	$
		LDA	<WORK1
		PHA

		JSR	GET_RPOINT	;drow start point get
		JSR	GET_RPOINT_X	;
		MEM8
		IDX8

		PLA			;SMALL BABULE ?
		BNE	BGSUB_BAB6000	; YES BGSUB_BAB6000
BGSUB_BAB5000	EQU	$

		M16

		LDA	#BG_BABULE	;DATA SET ROUTINE ADR
		JSR	BGSUB_TATEYOKO
		JMP	BGSUB_TATEYOKO3
;
		MEM8
		IDX8
BGSUB_BAB6000	EQU	$
		LDA	<XWIDE
		BEQ	BGSUB_BAB7000

		DEC	<XWIDE

BGSUB_BAB7000	EQU	$
		LDA	<WORK10
		BNE	BGSUB_BAB8000

		INC	<WORK10		;Y_WIDE CHOUSEI

BGSUB_BAB8000	EQU	$

		M16

		LDA	#BG_BABS	;DATA SET ROUTINE ADR
		JSR	BGSUB_TATEYOKO
		JMP	BGSUB_TATEYOKO3
;
BABULEPOS1	EQU	$
		WORD	00018H,00010H,00008H,00000H
BABULEPOS2	EQU	$
		WORD	00006H,00004H,00002H,00000H
;
;
;
;
;
;
;
		MEM8
		IDX8
BGSUB_KUMO	EQU	$

		M16
		LDA	#BG_KUMO
		BRA	YOKO_YUKA
;
		MEM8
		IDX8
BGSUB_AWAAWA	EQU	$

		M16
		LDA	#BG_AWAAWA
		BRA	YOKO_YUKA
;
		MEM8
		IDX8
BGSUB_KINOKO	EQU	$

		M16
		LDA	#BG_KINOKO
		BRA	YOKO_YUKA
;
		MEM8
		IDX8
BGSUB_HANA	EQU	$

		M16
		LDA	#BG_HANA
		BRA	YOKO_YUKA
;
		MEM8
		IDX8
BGSUB_BRIDGEH	EQU	$

		M16
		LDA	#BG_BRIDGEH
		BRA	YOKO_YUKA

;
		MEM8
		IDX8
BGSUB_KABEH	EQU	$
		INC	<XWIDE		;x wide revise

		M16
		LDA	#BG_KABEH
		BRA	YOKO_YUKA
;
		MEM8
		IDX8
BGSUB_SENROH	EQU	$

		M16
		LDA	#BG_SENROH
		BRA	YOKO_YUKA
;
		MEM8
		IDX8
BGSUB_HANHAS	EQU	$
		M16			; memory 16bit mode
		LDA	#BG_HANHAS
		BRA	YOKO_YUKA
;
;;;;;;
;;;;;;----------------------------------------------------------------
;;;;;;-		kabe course yoko BG				-
;;;;;;----------------------------------------------------------------
;;;;;;
;;;;;		MEM8
;;;;;		IDX8
;;;;;;
;;;;;BGSUB_KABEH	EQU	$		;[iw]
;;;;;		LDA	<WORK1F
;;;;;;
;;;;;		M16
;;;;;;
;;;;;		BEQ	BGSUB_BABEH_10	;1 unit only ? ( yes:BGSUB_BABEH_10 )
;;;;;;
;;;;;;--------------	>=2 unit set !! -----------------
;;;;;		LDA	#BG_KABEH
;;;;;		BRA	YOKO_YUKA
;;;;;;
;;;;;;--------------	1 unit set !! -------------------
;;;;;BGSUB_BABEH_10	EQU	$
;;;;;		LDA	#BG_KABEH_1UNT
;;;;;		JMP	BGSUB_TATEYOKO		
;;;;;;
;;;;;BG_KABEH_1UNT	EQU	$
;;;;;;
;;;;;		M16
;;;;;;
;;;;;		LDA	#UT0163
;;;;;		JMP	BG_TATE100
;;;;;;		
;;;;;;----------------------------------------------------------------

;
		MEM8
		IDX8
BGSUB_KABEYUKA	EQU	$

		M16
		LDA	#BG_KABEYUKA		; SET ROUTINE ADR(NORMAL DATA ROUTINE)

		BRA	YOKO_YUKA
;
		MEM8
		IDX8
BGSUB_SFLOOR	EQU	$

		M16
		LDA	#BG_SFLOOR		; SET ROUTINE ADR(NORMAL DATA ROUTINE)

YOKO_YUKA	EQU	$
		STA	<ROUTNR1			;
		STA	<ROUTNR2			;
		CMP	#BG_KUMO
		BNE	YOKOYUKA100

		LDA	#00003H
		BRA	YOKOYUKA200
YOKOYUKA100	EQU	$
		LDA	#00001H
YOKOYUKA200	EQU	$
		STA	<NDATSUM	; NORMAL DATA SUMMARY
		STA	<YWIDECP	; COMPARE DATA FOR_Y SET

		STZ	<WORK0

		M8
		STZ	<WORKC
		STZ	<WORK1A

		JSR	UNPT_GET3	;BGUNIT pointer get
		MEM16
		IDX16

		LDA	#00002H		; ADDITION DATA FOR H_POS
		STA	<WORKE		;

		STZ	<WORK16		; ADDITION FLAG CLEAR

		JMP	BG_ROPE
;
		MEM8
		IDX8
BGSUB_RPST	EQU	$
		M16
		LDA	#BG_RPST		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		BRA	YOKO_YUKA
;
EDGE_DATA	EQU	$
		WORD	BG_FLOOR_EL		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		WORD	BG_FLR_ELRND		; SET ROUTINE ADR(RANDOM DATA ROUTINE)
		WORD	BGYUKA_ELL		; READ & SET  FLOOR EDGE DATA
		WORD	0FFFEH
		WORD	BG_FLOOR_ER		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		WORD	BG_FLR_ERRND		; SET ROUTINE ADR(RANDOM DATA ROUTINE)
		WORD	BGYUKA_ERR		; READ & SET  FLOOR EDGE DATA
		WORD	00002H
;
		MEM8
		IDX8
BGSUB_EL	EQU	$

		LDA	<WORK1D
		PHA

		STZ	<WORK1A
		JSR	UNPT_GET	;BGUNIT pointer get
		MEM16
		IDX16

		LDA	RUT3912		;change char. dat.
		STA	<WORK10		;
		LDA	RUT3913		;
		STA	<WORK1A		;
		LDA	#00020H
		STA	<WORKC

		LDA	#BG_FLR_ELCHG		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		STA	<ROUTNR1			;
		STA	<ROUTNR2			;

		LDA	#00003H		; NORMAL DATA SUMMARY
		STA	<NDATSUM		;

		M8
		PLA
		CMP	<WORK1D
		BEQ	BGSUB_EL100

		PHA
		LDA	<WORK1D
		STA	<WORK0
		PLA
		STA	<WORK1D

		LDA	<WORK0
BGSUB_EL100	EQU	$
		PHA
		PHA

		LDA	#002H
		STA	<WORK1
		INC	<XWIDE
		LDA	<XWIDE
		STA	<YWIDECP		; SET COMPARE DATA FOR Y-COUNTER
		STZ	<WORK13		;

		JSR	BG_CHANGE
		MEM16
		IDX16

		LDA	#00003H		; NORMAL DATA SUMMARY
		STA	<NDATSUM		;

		M8
		PLA
		STA	<WORK1D
		M16


		PHX
		PHX
		LDX	#00000H
BGSUB_EDGE	EQU	$
		LDA	EDGE_DATA,X		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		STA	<ROUTNR1
		STA	<ROUTNR2

		INX
		INX
		LDA	EDGE_DATA,X		; SET ROUTINE ADR(RANDOM DATA ROUTINE)
		STA	<ROUTRND

		INX
		INX
		LDA	EDGE_DATA,X		; SET ROUTINE ADR(EDGE DATA ROUTINE)
		STA	<WORK1A

		INX
		INX
		LDA	EDGE_DATA,X
		STA	<WORK10

		M8

		PLX

		LDY	#0000H		; RESET Y-COUNTER

		JSR	BG_TATE		; READ & SET  GROUND EDGE DATA
		MEM16
		IDX16

		PLX

		M8
		PLA
		STA	<WORK1D
		M16

		TXA
		CLC			; SET ADR-INDEX SUBTRUCTION
		ADC	<WORK10		;
		TAX

		JMP	(WORK1A)	; READ & SET  FLOOR EDGE DATA
;
		MEM8
		IDX8
BGSUB_ER	EQU	$
		LDA	<WORK1D
		PHA

		STZ	<WORK1A

		JSR	UNPT_GET	;BGUNIT pointer get
		MEM16
		IDX16

		LDA	#BG_FLR_ERCHG		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		STA	<ROUTNR1			;
		STA	<ROUTNR2			;

		LDA	#00003H		; NORMAL DATA SUMMARY
		STA	<NDATSUM		;

		M8
		PLA
		CMP	<WORK1D
		BEQ	BGSUB_ER100

		PHA
		LDA	<WORK1D
		STA	<WORK0
		PLA
		STA	<WORK1D

		LDA	<WORK0
BGSUB_ER100	EQU	$
		PHA
		PHA

		LDA	#002H
		STA	<WORK1
		INC	<XWIDE
		LDA	<XWIDE
		STA	<YWIDECP		; SET COMPARE DATA FOR Y-COUNTER
		STZ	<WORK13		;

		JSR	BG_CHANGE
		MEM16
		IDX16

		LDA	#00003H		; NORMAL DATA SUMMARY
		STA	<NDATSUM		;

		M8
		PLA
		STA	<WORK1D
		M16

		PHX
		PHX
		LDX	#00008H

		BRA	BGSUB_EDGE
;
		MEM8
		IDX8
BGSUB_WGL	EQU	$

		STZ	<WORK18

		LDA	<WORK1D
		PHA

		LDA	<XWIDE
		PHA

		JSR	BGSUB_WGRSS_LOW
;

		JSR	UNPT_GET2
		MEM16
		IDX16
		PHX

		PHK
		JSR	BG_ROPE
		MEM8
		IDX8

		I16
		PLX

		LDA	<WORK18
		BNE	WGL200

		PHX

		M16

;		TXA
;		CLC			; SET ADR-INDEX SUBTRUCTION
;		ADC	#0FFFEH		;
;		TAX
		DEX
		DEX

		JSR	LEFT_CHECK
		MEM16
		IDX16
		PHP

		LDA	LKFLG		;set lock ?
		BEQ	WGL050		;  no: WGL050

		PLP
		BRA	WGL080

WGL050		EQU	$
		PLP
		BEQ	WGL080

		JSR	BG_WGRASS_ELL	; READ & SET  WGRASS EDGE DATA
		MEM8
		IDX16

WGL080		EQU	$
		M8
		PLX
		PLA
		INC	A
		STA	<WORK6
		STZ	<WORK7

		PLA
		STA	<WORK1D

		M16

;		ASL	<WORK0
WGL100		EQU	$
;		TXA
;		CLC			; SET ADR-INDEX SUBTRUCTION
;		ADC	#00002H		;
;		TAX
		INX
		INX

		JSR	RIGHT_CHECK
		MEM16
		IDX16
		PHP

		LDA	LKFLG		;set lock ?
		BEQ	WGL150		:  no: WGL150 

		PLP
		BRA	WGL300

WGL150		EQU	$
		PLP
		BEQ	WGL300

		DEC	<WORK6
		BNE	WGL100

		JSR	BG_WGRASS_ERR	; READ & SET  WGRASS EDGE DATA
		MEM8
		IDX16

		I8
		RTL

WGL200		EQU	$
		PLA
		PLA

WGL300		EQU	$
		I8
		RTL
;
		MEM8
		IDX8
BGSUB_WLIFT	EQU	$
		LDA	<WORK1E
		PHA
		LDA	<WORK1D
		PHA
		LDA	<XWIDE
		PHA

		PHK
		JSR	BGSUB_WLIFT1
		MEM8
		IDX8

		PLA
		STA	<XWIDE
		PLA
		STA	<WORK1D
		PLA
		STA	<WORK1E
		AND	#00FH
		CMP	#00FH
		BEQ	BGSUB_WLIFT100

		INC	<WORK1E
		BRA	BGSUB_WLIFT200
BGSUB_WLIFT100	EQU	$
		INC	<WORK1D
BGSUB_WLIFT200	EQU	$
		JMP	BGSUB_WLIFT2
;
KABE_DATA	EQU	$
		WORD	BG_KABE_L		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		WORD	BG_FLR_ELRND		; SET ROUTINE ADR(RANDOM DATA ROUTINE)
		WORD	BG_KABE_R		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		WORD	BG_FLR_ERRND		; SET ROUTINE ADR(RANDOM DATA ROUTINE)
;
		MEM8
		IDX8
BGSUB_KABE_L	EQU	$

		STZ	<WORKC
		STZ	<WORK1A

		M16
		STZ	<WORK0

		JSR	UNPT_GET3	;BGUNIT pointer get
		MEM16
		IDX16

		STZ	<XWIDECP

		LDA	#BG_FLR_ELCHG		; SET ROUTINE ADR(NORMAL DATA ROUTINE)

BGSUB_KABE_LR	EQU	$
		STA	<ROUTNR1			;
		STA	<ROUTNR2			;

		LDA	#00001H		; NORMAL DATA SUMMARY
		PHA			;
		STA	<NDATSUM		;

		M8
		LDA	#002H
		STA	<WORK1
		LDA	<XWIDE
		STA	<YWIDECP		; SET COMPARE DATA FOR Y-COUNTER
		STZ	<WORK13		;

		JSR	BG_CHANGE
		MEM16
		IDX16

		PLA			; NORMAL DATA SUMMARY
		STA	<NDATSUM		;

		PHX

		LDX	<XWIDECP

		LDA	KABE_DATA,X		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		STA	<ROUTNR1			;
		STA	<ROUTNR2			;

		INX
		INX
		LDA	KABE_DATA,X		; SET ROUTINE ADR(RANDOM DATA ROUTINE)
		STA	<ROUTRND			;

		PLX

		M8

		LDY	#0000H		; RESET Y-COUNTER

		JSR	BG_TATE		; READ & SET  GROUND EDGE DATA
		MEM16
		IDX16

		MI8

		RTL
;
		MEM8
		IDX8
BGSUB_KABE_R	EQU	$

		STZ	<WORKC

		M16
		STZ	<WORK0
		STZ	<WORK1A
		JSR	UNPT_GET3	;BGUNIT pointer get
		MEM16
		IDX16

		LDA	#00004H
		STA	<XWIDECP

		LDA	#BG_FLR_ERCHG		; SET ROUTINE ADR(NORMAL DATA ROUTINE)

		BRA	BGSUB_KABE_LR
;
TATEBOU_DATA	EQU	$
BOU_RTDT	EQU	$
		WORD	BG_BOU			; SET ROUTINE ADR(NORMAL DATA ROUTINE)
BOU_SL_RTDT	EQU	$
		WORD	BG_BOU_SL		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
BOU_SR_RTDT	EQU	$
		WORD	BG_BOU_SR		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
BRIDGEV_RTDT	EQU	$
		WORD	BG_BRIDGEV		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
WRIFT1_RTDT	EQU	$
		WORD	BG_WLIFT1		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
WRIFT2_RTDT	EQU	$
		WORD	BG_WLIFT2		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
BOU_SD_RTDT	EQU	$
		WORD	BG_BOU_SD		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
HARI_L_RTDT	EQU	$
		WORD	BG_HARI_L		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
HARI_R_RTDT	EQU	$
		WORD	BG_HARI_R		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
KABEV_RTDT	EQU	$
		WORD	BG_KABEV		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
KABEV2_RTDT	EQU	$
		WORD	BG_KABEV2		; SET ROUTINE ADR(NORMAL DATA ROUTINE)
SENROV_RTDT	EQU	$
		WORD	BG_SENROV
SENROH_RTDT	EQU	$
		WORD	BG_SENROH

;
BOU_INDEX	EQU	BOU_RTDT-BOU_RTDT
BOU_SL_INDEX	EQU	BOU_SL_RTDT-BOU_RTDT
BOU_SR_INDEX	EQU	BOU_SR_RTDT-BOU_RTDT
BRIDGEV_INDEX	EQU	BRIDGEV_RTDT-BOU_RTDT
WRIFT1_INDEX	EQU	WRIFT1_RTDT-BOU_RTDT
WRIFT2_INDEX	EQU	WRIFT2_RTDT-BOU_RTDT
BOU_SD_INDEX	EQU	BOU_SD_RTDT-BOU_RTDT
HARI_L_INDEX	EQU	HARI_L_RTDT-BOU_RTDT
HARI_R_INDEX	EQU	HARI_R_RTDT-BOU_RTDT
KABEV_INDEX	EQU	KABEV_RTDT-BOU_RTDT
KABEV2_INDEX	EQU	KABEV2_RTDT-BOU_RTDT
SENROV_INDEX	EQU	SENROV_RTDT-BOU_RTDT
;
		MEM8
		IDX8
BGSUB_BOU	EQU	$
		LDX	#BOU_INDEX

		BRA	BGSUB_BOU_SLR
;
		MEM8
		IDX8
BGSUB_BOU_SL	EQU	$
		LDX	#BOU_SL_INDEX

		BRA	BGSUB_BOU_SLR
;
		MEM8
		IDX8
BGSUB_BOU_SR	EQU	$
		LDX	#BOU_SR_INDEX

		BRA	BGSUB_BOU_SLR
;
		MEM8
		IDX8
BGSUB_BRIDGEV	EQU	$
		LDX	#BRIDGEV_INDEX

		BRA	BGSUB_BOU_SLR
;
		MEM8
		IDX8
BGSUB_WLIFT1	EQU	$
		LDX	#WRIFT1_INDEX

		BRA	BGSUB_BOU_SLR
;
		MEM8
		IDX8
BGSUB_WLIFT2	EQU	$
		LDX	#WRIFT2_INDEX

		BRA	BGSUB_BOU_SLR
;
		MEM8
		IDX8
BGSUB_BOU_SD	EQU	$
		LDX	#BOU_SD_INDEX

		BRA	BGSUB_BOU_SLR
;
		MEM8
		IDX8
BGSUB_HARI_L	EQU	$
		LDX	#HARI_L_INDEX

		BRA	BGSUB_BOU_SLR
;
		MEM8
		IDX8
BGSUB_HARI_R	EQU	$
		LDX	#HARI_R_INDEX

		BRA	BGSUB_BOU_SLR

		MEM8
		IDX8
BGSUB_KABEV	EQU	$
		LDX	#KABEV_INDEX

		BRA	BGSUB_BOU_SLR

		MEM8
		IDX8
BGSUB_KABEV2	EQU	$
		LDX	#KABEV2_INDEX

		BRA	BGSUB_BOU_SLR

		MEM8
		IDX8
BGSUB_SENROV	EQU	$
		LDX	#SENROV_INDEX

;
;
;
BGSUB_BOU_SLR	EQU	$
		M16

		LDA	TATEBOU_DATA,X
		STA	<ROUTNR1			;
		STA	<ROUTNR2			;

		STZ	<WORK0

		M8
		STZ	<WORK1A
		STZ	<WORKC
		JSR	UNPT_GET3	;BGUNIT pointer get
		MEM16
		IDX16

		LDA	#0FFFFH		; NORMAL DATA SUMMARY
		STA	<NDATSUM		;

		M8
		LDA	<XWIDE
		STA	<YWIDECP		; SET COMPARE DATA FOR Y-COUNTER
		STZ	<WORK13		;

		LDY	#0000H		; RESET Y-COUNTER

		JSR	BG_TATE		; READ & SET  GROUND EDGE DATA
		MEM16
		IDX16

		MI8

		RTL
;
;
;
;
;
;
;
;		CHARACTER  NUMBER  READERS
;
;

;
;		SNOW & GRASS LAND
;
		MEM8
		IDX16
BG_FLOOR_1	EQU	$
		LDA	<XWIDE		;1st v_line ?
		CMP	<XWIDECP	;
		BEQ	BG_FLOOR_1200	; yes: BG_FLOOR_1200

		DEC	A		;last v_line ?
		BEQ	BG_FLOOR_1300	; yes: BG_FLOOR_1300

BG_FLOOR_1001	EQU	$
		M8
		LDA	#000H

BG_FLR		EQU	$

		STA	<WORK0
		STZ	<WORK1

		PHY
		M16

		TYA
		CLC
		ADC	<WORK0

BG_FLR2		EQU	$
		ASL	A
		TAY

		LDA	FLR_DATA1,Y
		STA	<WORK0
		LDA	(<WORK0)
		PLY
		JMP	BG_TATE100
;
FLR_DATA1	EQU	$
		WORD	RUT2A00
		WORD	RUT3912
		WORD	RUT3914
;
FLR_DATA2	EQU	$
		WORD	RUT2A01
		WORD	RUT3913
		WORD	RUT3915
;
FLR_RND_DATA	EQU	$
		WORD	RUT390E
		WORD	RUT390F
		WORD	RUT3910
		WORD	RUT3911
		WORD	RUT392C
		WORD	RUT392D
;
FLR_ELR_DATA	EQU	$
		WORD	RUT2A00
		WORD	RUT3920
		WORD	RUT3922
		WORD	RUT2A01
		WORD	RUT3921
		WORD	RUT3923
;
FLR_ELRND_DATA	EQU	$
		WORD	RUT3926
		WORD	RUT3928
		WORD	RUT3924
;
FLR_ERRND_DATA	EQU	$
		WORD	RUT3927
		WORD	RUT3929
		WORD	RUT3925
;
FLR_ELCHG_DATA	EQU	$
		WORD	RUT392A
		WORD	RUT390B
		WORD	RUT3914
;
FLR_ERCHG_DATA	EQU	$
		WORD	RUT392B
		WORD	RUT390C
		WORD	RUT3915
;
;
BG_FLOOR_1200	EQU	$
		M16
		JSR	BG_FLOOR_S200
		CMP	#00000H
		BEQ	BG_FLOOR_1001		;henkan unit set ?
		JMP	BG_TATE100		; yes: BG_TATE100
;
;
BG_FLOOR_1300	EQU	$
		M16
		JSR	BG_FLOOR_S300
		CMP	#00000H
		BEQ	BG_FLOOR_1001		;henkan unit set ?
		JMP	BG_TATE100		; yes: BG_TATE100
;
;
		MEM16
BG_FLOOR_S200	EQU	$
;		M16
		LDA	>BGUNIT,X
		BEQ	BG_FLOOR_SRTS

BG_FLOOR_S210	EQU	$
		PHY
		M16
		TYA

BG_FLR_S	EQU	$
		ASL	A
		TAY

		LDA	!FLR_S_DATA2,Y
		STA	<WORK0
		LDA	(<WORK0)
		PLY

BG_FLOOR_SRTS	EQU	$

		RTS
;
;
FLR_S_DATA2	EQU	$
		WORD	RUT392B
		WORD	RUT3907
		WORD	RUT3916
;
FLR_S_DATA3	EQU	$
		WORD	RUT392A
		WORD	RUT3908
		WORD	RUT3917
;
;
		MEM16
BG_FLOOR_S300	EQU	$
		LDA	>BGUNIT,X
		BEQ	BG_FLOOR_SRTS

BG_FLOOR_S310	EQU	$
		PHY
		M16
		TYA
		CLC
		ADC	#00003H
		BRA	BG_FLR_S
;
;
		MEM8
		IDX16
BG_FLOOR_2	EQU	$
		LDA	<XWIDE		;1st v_line ?
		CMP	<XWIDECP	;
		BEQ	BG_FLOOR_2200	; yes: BG_FLOOR_2200

		DEC	A		;last v_line ?
		BEQ	BG_FLOOR_2300	: yes: BG_FLOOR_2300

BG_FLOOR_2001	EQU	$

		M8
		LDA	#003H
		JMP	BG_FLR
;
BG_FLOOR_2200	EQU	$
		M16
		JSR	BG_FLOOR_S200
		CMP	#00000H			;( * irunenn !! )
		BEQ	BG_FLOOR_2001		;henkan unit set ?
		JMP	BG_TATE100		; yes: BG_TATE100
;
BG_FLOOR_2300	EQU	$
		M16
		JSR	BG_FLOOR_S300
		CMP	#00000H			;( * irunenn !! )
		BEQ	BG_FLOOR_2001		;henkan unit set ?
		JMP	BG_TATE100		; yes: BG_TATE100
;
;
;
		MEM8
		IDX16
BG_FLOOR_RND	EQU	$
		M16
		TYA
		INC	A
		CMP	<YWIDECP
		BNE	BG_FLOOR_RND008

		LDA	>BGUNIT,X
		CMP	RUT3912
		BEQ	BG_FLOOR_RND005
		CMP	RUT3913
		BNE	BG_FLOOR_RND008

BG_FLOOR_RND005	EQU	$
		LDA	RUT390D
		JMP	BG_TATE100

BG_FLOOR_RND008	EQU	$
		M8
		LDA	<XWIDE		;last v_line ?
		CMP	#001H		;
		BNE	BG_FLOOR_RND010	;  no: BG_FLOOR_RND010

		LDA	<XWIDECP	;v_line summary is only 1 ?
		CMP	#001H		;
		BNE	BG_FLOOR_RND009	;  no: BG_FLOOR_RND009

		JSR	AROUND_CHK_L
		MEM8
		IDX16

BG_FLOOR_RND009	EQU	$
		JSR	AROUND_CHK_R
		MEM8
		IDX16
		BRA	BG_FLOOR_RND080

BG_FLOOR_RND010	EQU	$
		CMP	<XWIDECP	;1st v_line ?
		BNE	BG_FLOOR_RND080	;  no: BG_FLOOR_RND080

		JSR	AROUND_CHK_L
		MEM8
		IDX16

BG_FLOOR_RND080	EQU	$
		LDA	#000H
		XBA
BG_FLOOR_RND00	EQU	$

		JSR	RND_RND
		MEM8
		IDX16
		AND	#007H
		CMP	#006H
		BCS	BG_FLOOR_RND00

		PHY
		M16
		CLC
		ADC	#00006H
		JMP	BG_FLR2
;
;
;
;
		MEM8
		IDX16
BG_FLOOR_EL	EQU	$
		LDA	#00CH
		JMP	BG_FLR
;
		MEM8
		IDX16
BG_FLOOR_ER	EQU	$
		LDA	#00FH
		JMP	BG_FLR
;
;
		MEM8
		IDX16
BG_FLR_RND	EQU	$
BG_FLR_RND080	EQU	$
		LDA	#000H
		XBA
BG_FLR_RND00	EQU	$

		JSR	RND_RND
		MEM8
		IDX16
		AND	#007H
		CMP	#006H
		BCS	BG_FLR_RND00

		M16
		ASL	A

		PHY
		TAY

		LDA	FLR_RND_DATA,Y
		STA	<WORK0
		LDA	(<WORK0)
		PLY
		RTS
;
;
;
		MEM8
		IDX16
BG_FLR_ELRND	EQU	$

		JSR	BG_FLR_ELCHK
		MEM8
		IDX16

		LDA	#000H
		XBA
BG_FLR_ELRND00
		JSR	RND_RND
		MEM8
		IDX16
		AND	#003H
		BEQ	BG_FLR_ELRND00

		PHY
		M16
		CLC
		ADC	#00011H
		JMP	BG_FLR2

BG_FLR_ELRRND	EQU	$
;
		MEM8
		IDX16
BG_FLR_ERRND	EQU	$

		JSR	BG_FLR_ERCHK
		MEM8
		IDX16

		LDA	#000H
		XBA
BG_FLR_ERRND00
		JSR	RND_RND
		MEM8
		IDX16
		AND	#003H
		BEQ	BG_FLR_ERRND00

		PHY
		M16
		CLC
		ADC	#00014H
		JMP	BG_FLR2
;
BG_FLR_ELCHG	EQU	$

		JSR	BG_FLR_ELCHK
		MEM8
		IDX16

		LDA	#018H
		JMP	BG_FLR
;
BG_FLR_ERCHG	EQU	$

		JSR	BG_FLR_ERCHK
		MEM8
		IDX16

		LDA	#01BH
		JMP	BG_FLR
;
		MEM8
		IDX16
BG_FLR_ELCHK	EQU	$

		M16
		PHX
		PHY
		INX
		INX

		JSR	RIGHT2_CHECK
		MEM16
		IDX16

		LDA	LKFLG		;set lock ?
		BNE	BG_FLR_ELCHK03	; yes: BG_FLR_ELCHK03

		LDA	>BGUNIT,X
		CMP	RUT3924
		BEQ	BG_FLR_ELCHK01
		CMP	RUT3926
		BEQ	BG_FLR_ELCHK01
		CMP	RUT3928
		BEQ	BG_FLR_ELCHK01
		CMP	RUT392A
		BEQ	BG_FLR_ELCHK01
		CMP	RUT390B
		BNE	BG_FLR_ELCHK03

		LDA	RUT390D
		BRA	BG_FLR_ELCHK02

BG_FLR_ELCHK01	EQU	$
		M8
		JSR	BG_FLR_RND
		MEM16
		IDX16

BG_FLR_ELCHK02	EQU	$
		STA	>BGUNIT,X

BG_FLR_ELCHK03	EQU	$
		PLY
		PLX

		M8
		RTS
;
		MEM8
		IDX16
BG_FLR_ERCHK	EQU	$

		M16
		PHX
		PHY
		DEX
		DEX

		JSR	LEFT2_CHECK
		MEM16
		IDX16

		LDA	LKFLG		;set lock ?
		BNE	BG_FLR_ELCHK03	; yes: BG_FLR_ELCHK03

		LDA	>BGUNIT,X
		CMP	RUT3925
		BEQ	BG_FLR_ELCHK01
		CMP	RUT3927
		BEQ	BG_FLR_ELCHK01
		CMP	RUT3929
		BEQ	BG_FLR_ELCHK01
		CMP	RUT392B
		BEQ	BG_FLR_ELCHK01
		CMP	RUT390C
		BNE	BG_FLR_ELCHK03

		LDA	RUT390D
		BRA	BG_FLR_ELCHK02
;
SLL30_1_DATA	EQU	$
		WORD	RUT2A02,RUT0F00,RUT1300,RUT391A,RUT391A
;
SLL30_2_DATA	EQU	$
		WORD	RUT2A03,RUT1000,RUT1100,RUT3918,RUT3918
;
SLR30_1_DATA	EQU	$
		WORD	RUT2A05,RUT0D00,RUT1200,RUT391B,RUT391B
;
SLR30_2_DATA	EQU	$
		WORD	RUT2A04,RUT0C00,RUT0E00,RUT3919,RUT3919
;
SLL45_1_DATA	EQU	$
		WORD	RUT2A07,RUT0A00,RUT0B00,RUT3916,RUT3916
;
SLR45_1_DATA	EQU	$
		WORD	RUT2A06,RUT0800,RUT0900,RUT3917,RUT3917
;
SLL60_1_DATA	EQU	$
		WORD	RUT2A08,RUT0500,RUT0600,RUT0700,RUT392E
;
SLR60_1_DATA	EQU	$
		WORD	RUT2A09,RUT0200,RUT0300,RUT0400,RUT392F
;
KBSLL_1_DATA	EQU	$
		WORD	UT00D4,UT00D3,UT00D5,UT00D5,UT00D5
;
KBSLR_1_DATA	EQU	$
		WORD	UT00D1,UT00D2,UT00D5,UT00D5,UT00D5
;
;
		MEM16
		IDX16
BG_SLLR		EQU	$
		LDA	#00001H
		STA	<WORK16

		MEM16
		IDX16
BG_SLLR2	EQU	$
		LDA	<WORK1A		;data index culc.
		ASL	A		;
		STA	<WORK0		;
					;
		TYA			;
		CLC			;
		ADC	<WORK0		;
		TAY			;

		CPY	#(KBSLL_1_DATA-SLL30_1_DATA)	;slope ?
		BCS	BG_SLLR3			;  no: BG_SLLR3

		LDA	SLL30_1_DATA,Y
		STA	<WORK0
		LDA	(<WORK0)
		LDY	<WORK1A
		JMP	BG_TATE100

BG_SLLR3	EQU	$
		LDA	SLL30_1_DATA,Y
		LDY	<WORK1A
		JMP	BG_TATE100
;

		MEM8
		IDX16
BG_SLL30_1	EQU	$
		LDA	<XWIDECP	;v_line summary = kisuu ?
		AND	#001H		;
		BNE	BG_SLL30_20	; yes: BG_SLL30_20

BG_SLL30_10	EQU	$
		M16
		STY	<WORK1A
		LDY	#(SLL30_1_DATA-SLL30_1_DATA)
		BRA	BG_SLLR2
;
		MEM8
		IDX16
BG_SLL30_2	EQU	$
		LDA	<XWIDECP	;v_line summary = kisuu ?
		AND	#001H		;
		BNE	BG_SLL30_10	; yes: BG_SLL30_10

BG_SLL30_20	EQU	$
		M16
		STY	<WORK1A
		LDY	#(SLL30_2_DATA-SLL30_1_DATA)
		BRA	BG_SLLR
;
		MEM8
		IDX16
BG_SLR30_2	EQU	$
		M16
		STY	<WORK1A
		LDY	#(SLR30_1_DATA-SLL30_1_DATA)
		BRA	BG_SLLR
;
		MEM8
		IDX16
BG_SLR30_1	EQU	$
		M16
		STY	<WORK1A
		LDY	#(SLR30_2_DATA-SLL30_1_DATA)
		BRA	BG_SLLR2
;
		MEM8
		IDX16
BG_SLL45_1	EQU	$
		M16
		STY	<WORK1A
		LDY	#(SLL45_1_DATA-SLL30_1_DATA)
		BRA	BG_SLLR
;
		MEM8
		IDX16
BG_SLR45_1	EQU	$
		M16
		STY	<WORK1A
		LDY	#(SLR45_1_DATA-SLL30_1_DATA)
		BRA	BG_SLLR
;
		MEM8
		IDX16
BG_SLL60_1	EQU	$
		M16
		STY	<WORK1A
		LDY	#(SLL60_1_DATA-SLL30_1_DATA)
		BRA	BG_SLLR
;
		MEM8
		IDX16
BG_SLR60_1	EQU	$
		M16
		STY	<WORK1A
		LDY	#(SLR60_1_DATA-SLL30_1_DATA)
		BRA	BG_SLLR
;
		MEM8
		IDX16
BG_KBSLL_1	EQU	$
		M16
		STY	<WORK1A
		LDY	#(KBSLL_1_DATA-SLL30_1_DATA)
		JMP	BG_SLLR
;
		MEM8
		IDX16
BG_KBSLR_1	EQU	$
		M16
		STY	<WORK1A
		LDY	#(KBSLR_1_DATA-SLL30_1_DATA)
		JMP	BG_SLLR
;
		MEM8
		IDX16
BG_KABE_L	EQU	$
		M16
		PHX
		INX
		INX

		JSR	RIGHT2_CHECK
		MEM16
		IDX16

		LDA	LKFLG		;set lock ?
		BNE	BG_KABE_L200	; yes: BG_KABE_L200

		LDA	>BGUNIT,X
		CMP	RUT3924
		BEQ	BG_KABE_L100
		CMP	RUT3926
		BEQ	BG_KABE_L100
		CMP	RUT3928
		BEQ	BG_KABE_L100
		CMP	RUT392A
		BNE	BG_KABE_L200
BG_KABE_L100	EQU	$

		LDA	RUT3905
		STA	>BGUNIT,X
BG_KABE_L200	EQU	$
		PLX

		LDA	RUT3909
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_KABE_R	EQU	$
		M16
		PHX
		DEX
		DEX

		JSR	LEFT2_CHECK
		MEM16
		IDX16

		LDA	LKFLG		;set lock ?
		BNE	BG_KABE_R200	; yes: BG_KABE_R200

		LDA	>BGUNIT,X
		CMP	RUT3925
		BEQ	BG_KABE_R100
		CMP	RUT3927
		BEQ	BG_KABE_R100
		CMP	RUT3929
		BEQ	BG_KABE_R100
		CMP	RUT392B
		BNE	BG_KABE_R200
BG_KABE_R100	EQU	$
		LDA	RUT3906
		STA	>BGUNIT,X
BG_KABE_R200	EQU	$
		PLX

		LDA	RUT390A
		JMP	BG_TATE100
;
BOU_DATA	EQU	$
		WORD	RUT3900,RUT3901,RUT3902
;
BOU_SL_DATA	EQU	$
		WORD	UT00A1,UT00A5,RUT2A0B
;
BOU_SR_DATA	EQU	$
		WORD	UT00A0,UT00A4,RUT2A0A
;
WLIFT1_DATA	EQU	$
		WORD	UT1507,UT0022,UT1503
;
WLIFT2_DATA	EQU	$
		WORD	UT1508,UT0023,UT1504
;
BOU_SD_DATA	EQU	$
		WORD	UT00C3,UT00C4,RUT2A0C
;
		MEM16
		IDX16
BG_VBOU		EQU	$
		LDA	<WORK1A		;1st h_line ?
		BEQ	BG_VBOU200	; yes: BG_VBOU200

		INC	A		;last h_line ?
		CMP	<YWIDECP	;
		BNE	BG_VBOU100	;  no: BG_BOU100

		INY
		INY

BG_VBOU100	EQU	$
		INY
		INY

BG_VBOU200	EQU	$
		CPY	#(BOU_SL_DATA-BOU_DATA+0004H)
		BEQ	BG_VBOU250
		CPY	#(BOU_SR_DATA-BOU_DATA+0004H)
		BEQ	BG_VBOU250
		CPY	#(BOU_SD_DATA-BOU_DATA+0004H)
		BEQ	BG_VBOU250
		CPY	#(BOU_SL_DATA-BOU_DATA)
		BCS	BG_VBOU300

BG_VBOU250	EQU	$
		LDA	BOU_DATA,Y
		STA	<WORK0
		LDA	(<WORK0)
		BRA	BG_VBOU350

BG_VBOU300	EQU	$
		LDA	BOU_DATA,Y

BG_VBOU350	EQU	$
		LDY	<WORK1A
BG_WLIFT12	EQU	$
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_BOU		EQU	$
		M16
		STY	<WORK1A
		LDY	#(BOU_DATA-BOU_DATA)
		BRA	BG_VBOU
;
		MEM8
		IDX16
BG_BOU_SL	EQU	$
		M16
		STY	<WORK1A
		LDY	#(BOU_SL_DATA-BOU_DATA)
		BRA	BG_VBOU
;
		MEM8
		IDX16
BG_BOU_SR	EQU	$
		M16
		STY	<WORK1A
		LDY	#(BOU_SR_DATA-BOU_DATA)
		BRA	BG_VBOU
;
		MEM8
		IDX16
BG_WLIFT1	EQU	$
		M16
		LDA	>BGUNIT,X
		CMP	#UT1503
		BEQ	BG_WLIFT12

		STY	<WORK1A
		LDY	#(WLIFT1_DATA-BOU_DATA)
		BRA	BG_VBOU
;
		MEM8
		IDX16
BG_WLIFT2	EQU	$
		M16
		LDA	>BGUNIT,X
		CMP	#UT1504
		BEQ	BG_WLIFT12

		STY	<WORK1A
		LDY	#(WLIFT2_DATA-BOU_DATA)
		BRA	BG_VBOU
;
		MEM8
		IDX16
BG_BOU_SD	EQU	$
		M16
		STY	<WORK1A
		LDY	#(BOU_SD_DATA-BOU_DATA)
		JMP	BG_VBOU
;
;
;			left    left    center  center  right   right
;				 chenge  gu-su-  kisu-           chenge
;
SFLOOR_DATA	EQU	$
		WORD	RUT3800,RUT3904,RUT3801,RUT3801,RUT3802,RUT3903
;
RPST_DATA	EQU	$
		WORD	UT00A3,UT00A3,UT00B6,UT00B6,UT00A2,UT00A2
;
BRIDGEH_DATA	EQU	$
		WORD	UT1505,UT1505,UT1501,UT1502,UT1506,UT1506
;
KUMO_DATA1	EQU	$
		WORD	UT00C6,UT00B7,UT00B9,UT00B8,UT00BA,UT00BA
;
KUMO_DATA2	EQU	$
		WORD	UT3C00,UT3C00,UT3C02,UT3C01,UT3C03,UT3C03
;
KUMO_DATA3	EQU	$
		WORD	UT00BB,UT00BB,UT00C1,UT00C0,UT00C2,UT00C2
;
KABEYUKA_DATA	EQU	$
		WORD	UT00E4,UT00E4,UT150F,UT1510,UT00E5,UT00E5
;
HANHASI_DATA	EQU	$
		WORD	UT3F00,UT3F00,UT3F01,UT3F01,UT3F02,UT3F02
;
;;;;;KABEH_DATA	EQU	$	;[iw]
;;;;;		WORD	UT0160,UT0160,UT0161,UT0161,UT0162,UT0162
;;;;;;
;;;;;KABEH_DTP	EQU	KABEH_DATA-SFLOOR_DATA	;[iw]
;;;;;;

		MEM8
		IDX16
BG_KUMO		EQU	$
		M16
		STY	<WORK1A

		CPY	#00000H
		BEQ	BG_KUMO100

		INY
		CPY	<YWIDECP
		BEQ	BG_KUMO200

		LDY	#(KUMO_DATA2-SFLOOR_DATA)
		BRA	BG_YOKOYOKO
BG_KUMO100	EQU	$
		LDY	#(KUMO_DATA1-SFLOOR_DATA)
		BRA	BG_YOKOYOKO
BG_KUMO200	EQU	$
		LDY	#(KUMO_DATA3-SFLOOR_DATA)
		BRA	BG_YOKOYOKO
;
		MEM8
		IDX16
BG_SFLOOR	EQU	$
		M16
		STY	<WORK1A
		LDY	#00000H
;
		MEM16
		IDX16
BG_YOKOYOKO	EQU	$
		M8
		LDA	<XWIDE		;1st v_line ?
		CMP	<XWIDECP	;
		BEQ	BG_YOKOYOKO100	; yes: BG_YOKOYOKO0100

		DEC	A		;last v_line ?
		BEQ	BG_YOKOYOKO200	; yes: BG_YOKOYOKO0200

		LDA	<XWIDECP	;v_line = ...
		SEC			;  kisuu: BG_YOKOYOKO280
		SBC	<XWIDE		; gu-suu: BG_YOKOYOKO290
		AND	#001H		;
		BNE	BG_YOKOYOKO280	;
		BRA	BG_YOKOYOKO290	;

BG_YOKOYOKO100	EQU	$
		M16
		LDA	>BGUNIT,X
		BEQ	BG_YOKOYOKO700

		BRA	BG_YOKOYOKO2A0

BG_YOKOYOKO200	EQU	$
		M16
		LDA	>BGUNIT,X
		BEQ	BG_YOKOYOKO270

		INY
		INY

BG_YOKOYOKO270	EQU	$
		INY
		INY

BG_YOKOYOKO280	EQU	$
		INY
		INY

BG_YOKOYOKO290	EQU	$
		INY
		INY

BG_YOKOYOKO2A0	EQU	$
		INY
		INY

BG_YOKOYOKO700	EQU	$
		M16
		CPY	#(RPST_DATA-SFLOOR_DATA)	;sfloor ?
		BCS	BG_YOKOYOKO800			;  no: BG_YOKOYOKO800

		LDA	SFLOOR_DATA,Y
		STA	<WORK0
		LDA	(<WORK0)

BG_YOKOYOKO750	EQU	$
		LDY	<WORK1A
		JMP	BG_TATE100

BG_YOKOYOKO800	EQU	$
		LDA	SFLOOR_DATA,Y
		BRA	BG_YOKOYOKO750

;
		MEM8
		IDX16
BG_RPST		EQU	$
		M16
		STY	<WORK1A
		LDY	#(RPST_DATA-SFLOOR_DATA)
		BRA	BG_YOKOYOKO
;
		MEM8
		IDX16
BG_BRIDGEH	EQU	$
		M16
		STY	<WORK1A
		LDY	#(BRIDGEH_DATA-SFLOOR_DATA)
		BRA	BG_YOKOYOKO
;
		MEM8
		IDX16
BG_KABEYUKA	EQU	$
		M16
		STY	<WORK1A
		LDY	#(KABEYUKA_DATA-SFLOOR_DATA)
		BRA	BG_YOKOYOKO
;
		MEM8
		IDX16
BG_HANHAS	EQU	$
		M16			; memory 16bit mode
		STY	<WORK1A
		LDY	#(HANHASI_DATA-SFLOOR_DATA)
		BRA	BG_YOKOYOKO
;
;
		MEM8
		IDX16
BG_CABE		EQU	$
		M16
		LDA	>BGUNIT,X
		STA	BGUNDT0
		AND	#0FF00H
		STA	BGUNDT1
		M8

		TYA			;1st h_line ?
		BNE	BG_CABE0010	;  no: BG_CABE0010
		JMP	BG_CABE0500	; yes: BG_CABE0500

BG_CABE0010	EQU	$
		INY
		CPY	<YWIDECP	;last h_line ?
		BNE	BG_CABE0020     ;  no: BG_CABE0020
		DEY			;
		JMP	BG_CABE0A00	; yes: BG_CABE0A00

BG_CABE0020	EQU	$
		DEY

		LDA	<XWIDE		;1st v_line ?
		CMP	<XWIDECP	;
		BEQ	BG_CABE0100	; yes: BG_CABE0100

		DEC	A		;last v_line ?
		BEQ	BG_CABE0200	; yes: BG_CABE0200

		M16
		LDA	RUT1D13
		JMP	BG_TATE100

BG_CABE0100	EQU	$
		M16
		LDA 	BGUNDT1
		CMP	RUT1D00
		BNE	BG_CABE0110

		LDA	BGUNDT0
		CMP	RUT1D0E
		BEQ	BG_CABE0120
		CMP	RUT1D10
		BEQ	BG_CABE0120
		CMP	RUT1D12
		BEQ	BG_CABE0120
		CMP	RUT1D13
		BEQ	BG_CABE0120
		CMP	RUT1D0B
;;;;K;;;;		BEQ	BG_CABE0120
		BEQ	BG_CABE0125
		CMP	RUT1D0C
		BEQ	BG_CABE0120

BG_CABE0108	EQU	$
		LDA	RUT1D0D		;normal data
		JMP	BG_TATE100

BG_CABE0110	EQU	$
		CMP	RUT3900
		BNE	BG_CABE0108

		LDA	BGUNDT0
		CMP	RUT3924
		BEQ	BG_CABE0111
		CMP	RUT3926
		BEQ	BG_CABE0111
		CMP	RUT3928
		BEQ	BG_CABE0111
		CMP	RUT392A
		BNE	BG_CABE0108

BG_CABE0111	EQU	$
		LDA	RUT1D18
		JMP	BG_TATE100

BG_CABE0120	EQU	$
		LDA	RUT1D13
		JMP	BG_TATE100
;
BG_CABE0125	EQU	$
		LDA	RUT1D20
		JMP	BG_TATE100
;
BG_CABE0200	EQU	$
		M16
		LDA	BGUNDT1
		CMP	RUT1D00
		BNE	BG_CABE0210

		LDA	BGUNDT0
		CMP	RUT1D0D
		BEQ	BG_CABE0220
		CMP	RUT1D0F
		BEQ	BG_CABE0220
		CMP	RUT1D11
		BEQ	BG_CABE0220
		CMP	RUT1D13
		BEQ	BG_CABE0220
		CMP	RUT1D0B
		BEQ	BG_CABE0220
		CMP	RUT1D0C
		BEQ	BG_CABE0220

BG_CABE0208	EQU	$
		LDA	RUT1D0E		;normal data
		JMP	BG_TATE100

BG_CABE0210	EQU	$
		CMP	RUT3900
		BNE	BG_CABE0208

		LDA	BGUNDT0
		CMP	RUT3925
		BEQ	BG_CABE0211
		CMP	RUT3927
		BEQ	BG_CABE0211
		CMP	RUT3929
		BEQ	BG_CABE0211
		CMP	RUT392B
		BNE	BG_CABE0208

BG_CABE0211	EQU	$
		LDA	RUT1D19
		JMP	BG_TATE100

BG_CABE0220	EQU	$
		LDA	RUT1D13
		JMP	BG_TATE100
;
		MEM8
BG_CABE0500	EQU	$
		LDA	<XWIDE		;1st v_line ?
		CMP	<XWIDECP	;
		BEQ	BG_CABE0600	; yes: BG_CABE0600

		DEC	A		;last v_line ?
		BNE	BG_CABE0510	;  no: BG_CABE0510
		JMP	BG_CABE0700	; yes: BG_CABE0700

BG_CABE0510	EQU	$
		M16
		LDA	BGUNDT1
		CMP	RUT1D00
		BNE	BG_CABE0550

		LDA	BGUNDT0
		CMP	RUT1D0F
		BEQ	BG_CABE0550
		CMP	RUT1D10
		BEQ	BG_CABE0550
		CMP	RUT1D0B
		BEQ	BG_CABE0560

		LDA	RUT1D13
		JMP	BG_TATE100

BG_CABE0545	EQU	$
		PHY
		LDY	#00000H
		JSR	BGUPNUKI	; up character nu-ki set
		PLY
		LDA	RUT1D25
		BRA	BG_CABE0560
;
BG_CABE0550	EQU	$
		LDA	BGUNDT0
		CMP	#UT3912
		BEQ	BG_CABE0545
		CMP	#UT3913
		BEQ	BG_CABE0545
		LDA	RUT1D0B		;normal data

BG_CABE0560	EQU	$
		JMP	BG_TATE100

BG_CABE0600	EQU	$
		M16
		LDA	BGUNDT1
		CMP	RUT1D00
		BNE	BG_CABE0660

		LDA	BGUNDT0
		CMP	RUT1D10
		BEQ	BG_CABE0670
		CMP	RUT1D11
		BEQ	BG_CABE0680
		CMP	RUT1D12
		BEQ	BG_CABE0690
		CMP	RUT1D0E
		BEQ	BG_CABE0690
		CMP	RUT1D0C
		BEQ	BG_CABE0690
		CMP	RUT1D0B
		BEQ	BG_CABE0615

		JMP	BG_TATE100
		
BG_CABE0610	EQU	$
		LDA	RUT1D0F		;normal data
		JMP	BG_TATE100
;
BG_CABE0615	EQU	$
;;;;K;;;;		LDA	RUT1D13
		LDA	RUT1D20
		JMP	BG_TATE100
;

BG_CABE0660	EQU	$
		CMP	RUT3900
		BNE	BG_CABE0665

		LDA	BGUNDT0
		CMP	#UT3912
		BEQ	BG_CABE0663
		CMP	#UT3913
		BEQ	BG_CABE0663
		CMP	RUT3924
		BEQ	BG_CABE0661
		CMP	RUT3926
		BEQ	BG_CABE0661
		CMP	RUT3928
		BEQ	BG_CABE0661
		CMP	RUT392A
		BNE	BG_CABE0610

BG_CABE0661	EQU	$
		LDA	RUT1D1A
		JMP	BG_TATE100

;
BG_CABE0663	EQU	$
		PHY
		LDY	#00002H
		JSR	BGUPNUKI	; up character nu-ki set
		PLY
		LDA	RUT1D24
		JMP	BG_TATE100
;
BG_CABE0665	EQU	$
		LDA	BGUNDT0
		CMP	RUT1D1C
		BNE	BG_CABE0610

		LDA	RUT1D18
		JMP	BG_TATE100

BG_CABE0670	EQU	$
		LDA	RUT1D0B
		JMP	BG_TATE100

BG_CABE0680	EQU	$
		LDA	RUT1D0D
		JMP	BG_TATE100

BG_CABE0690	EQU	$
		LDA	RUT1D13
		JMP	BG_TATE100

BG_CABE0700	EQU	$
		M16

		LDA	BGUNDT1
		CMP	RUT1D00
		BNE	BG_CABE0710

		LDA	BGUNDT0
		CMP	RUT1D0F
		BEQ	BG_CABE0720
		CMP	RUT1D12
		BEQ	BG_CABE0730
		CMP	RUT1D11
		BEQ	BG_CABE0740
		CMP	RUT1D0D
		BEQ	BG_CABE0740
		CMP	RUT1D0C
		BEQ	BG_CABE0740

		JMP	BG_TATE100

BG_CABE0708	EQU	$
		LDA	RUT1D10		;normal data
		JMP	BG_TATE100

BG_CABE0710	EQU	$
		CMP	RUT3900
		BNE	BG_CABE0718

		LDA	BGUNDT0
		CMP	#UT3912
		BEQ	BG_CABE0713
		CMP	#UT3913
		BEQ	BG_CABE0713
		CMP	RUT3925
		BEQ	BG_CABE0711
		CMP	RUT3927
		BEQ	BG_CABE0711
		CMP	RUT3929
		BEQ	BG_CABE0711
		CMP	RUT392B
		BNE	BG_CABE0708

BG_CABE0711	EQU	$
		LDA	RUT1D1B
		JMP	BG_TATE100

;
BG_CABE0713	EQU	$
		PHY
		LDY	#00004H
		JSR	BGUPNUKI	; up character nu-ki set
		PLY
		LDA	RUT1D26
		JMP	BG_TATE100
;
BG_CABE0718	EQU	$
		LDA	BGUNDT0
		CMP	RUT1D1D
		BNE	BG_CABE0708

		LDA	RUT1D19
		JMP	BG_TATE100

BG_CABE0720	EQU	$
		LDA	RUT1D0B
		JMP	BG_TATE100

BG_CABE0730	EQU	$
		LDA	RUT1D0E
		JMP	BG_TATE100

BG_CABE0740	EQU	$
		LDA	RUT1D13
		JMP	BG_TATE100
;
		MEM8
BG_CABE0A00	EQU	$
		LDA	<XWIDE		;1st v_line ?
		CMP	<XWIDECP	;
		BEQ	BG_CABE0B00	; yes: BG_CABE0B00

		DEC	A		;last v_line ?
		BNE	BG_CABE0A08	;  no: BG_CABE0A08
		JMP	BG_CABE0C00	; yes: BG_CABE0C00

BG_CABE0A08	EQU	$
		M16
		LDA	BGUNDT1
		CMP	RUT1D00
		BNE	BG_CABE0A09

		LDA	BGUNDT0
		CMP	RUT1D0F
		BEQ	BG_CABE0A10
		CMP	RUT1D10
		BEQ	BG_CABE0A10
		CMP	RUT1D0B
		BEQ	BG_CABE0A10
		CMP	RUT1D0D
		BEQ	BG_CABE0A10
		CMP	RUT1D0E
		BEQ	BG_CABE0A10
		CMP	RUT1D0C
		BEQ	BG_CABE0A20

BG_CABE0A09	EQU	$
		LDA	<BGUNDT0
		CMP	#UT3931
		BEQ	BG_CABE0A15
		CMP	RUT1D28
		BEQ	BG_CABE0A15
		LDA	RUT1D0C		;normal data
		JMP	BG_TATE100

BG_CABE0A10	EQU	$
		LDA	RUT1D13
		BRA	BG_CABE0A20
;
BG_CABE0A15	EQU	$
		LDA	RUT1D28

BG_CABE0A20	EQU	$
		JMP	BG_TATE100

BG_CABE0B00	EQU	$
		M16
		LDA	BGUNDT1
		CMP	RUT1D00
		BNE	BG_CABE0B10

		LDA	BGUNDT0
		CMP	RUT1D12
		BEQ	BG_CABE0B20
		CMP	RUT1D0F
		BEQ	BG_CABE0B30
		CMP	RUT1D10
		BEQ	BG_CABE0B40
		CMP	RUT1D0B
;;;;K;;;;		BEQ	BG_CABE0B40
		BEQ	BG_CABE0B45
		CMP	RUT1D0E
		BEQ	BG_CABE0B40

		JMP	BG_TATE100
BG_CABE0B08	EQU	$
		LDA	<BGUNDT0
		CMP	#UT3931
		BNE	BG_CABE0B09
		LDA	RUT1D27
		JMP	BG_TATE100
;
BG_CABE0B09
		LDA	RUT1D11		;normal data
		JMP	BG_TATE100

BG_CABE0B10	EQU	$
		CMP	RUT3900
		BNE	BG_CABE0B18

		LDA	BGUNDT0
		CMP	RUT3924
		BEQ	BG_CABE0B11
		CMP	RUT3926
		BEQ	BG_CABE0B11
		CMP	RUT3928
		BEQ	BG_CABE0B11
		CMP	RUT392A
		BNE	BG_CABE0B08

BG_CABE0B11	EQU	$
		LDA	RUT1D1C
		JMP	BG_TATE100

BG_CABE0B18	EQU	$
		LDA	BGUNDT0
		CMP	RUT1D1A
		BNE	BG_CABE0B08

		LDA	RUT1D18
		JMP	BG_TATE100

BG_CABE0B20	EQU	$
		LDA	RUT1D0C
		JMP	BG_TATE100

BG_CABE0B30	EQU	$
		LDA	RUT1D0D
		JMP	BG_TATE100

BG_CABE0B40	EQU	$
		LDA	RUT1D13
		JMP	BG_TATE100
;
BG_CABE0B45	EQU	$
		LDA	RUT1D20
		JMP	BG_TATE100
;

BG_CABE0C00	EQU	$
		M16

		LDA	BGUNDT1
		CMP	RUT1D00
		BNE	BG_CABE0C10

		LDA	BGUNDT0
		CMP	RUT1D11
		BEQ	BG_CABE0C20
		CMP	RUT1D10
		BEQ	BG_CABE0C30
		CMP	RUT1D0F
		BEQ	BG_CABE0C40
		CMP	RUT1D0B
		BEQ	BG_CABE0C40

		JMP	BG_TATE100

BG_CABE0C08	EQU	$
		LDA	<BGUNDT0
		CMP	#UT3931
		BNE	BG_CABE0C09
		LDA	RUT1D29
		JMP	BG_TATE100
;
BG_CABE0C09	EQU	$
		LDA	RUT1D12		;normal data
		JMP	BG_TATE100

BG_CABE0C10	EQU	$
		CMP	RUT3900
		BNE	BG_CABE0C18

		LDA	BGUNDT0
		CMP	RUT3925
		BEQ	BG_CABE0C11
		CMP	RUT3927
		BEQ	BG_CABE0C11
		CMP	RUT3929
		BEQ	BG_CABE0C11
		CMP	RUT392B
		BNE	BG_CABE0C08

BG_CABE0C11	EQU	$
		LDA	RUT1D1D
		JMP	BG_TATE100

BG_CABE0C18	EQU	$
		LDA	BGUNDT0
		CMP	RUT1D1B
		BNE	BG_CABE0C08

		LDA	RUT1D19
		JMP	BG_TATE100

BG_CABE0C20	EQU	$
		LDA	RUT1D0C
		JMP	BG_TATE100

BG_CABE0C30	EQU	$
		LDA	RUT1D0E
		JMP	BG_TATE100

BG_CABE0C40	EQU	$
		LDA	RUT1D13
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_CABEH	EQU	$
		M16
		LDA	>BGUNIT,X
		STA	BGUNDT0
		AND	#0FF00H
		STA	BGUNDT1
		M8

		LDA	<XWIDE		;1st v_line ?
		CMP	<XWIDECP	;
		BEQ	BG_CABEH100	; yes: BG_CABEH100

		DEC	A		;last v_line ?
		BNE	BG_CABEH080	;  no: BG_CABEH080
		JMP	BG_CABEH200	; yes: BG_CABEH200

BG_CABEH080	EQU	$
		M16
		LDA	BGUNDT0
		CMP	RUT1D01
		BEQ	BG_CABEH090
		CMP	RUT1D02
		BEQ	BG_CABEH090

		LDA	RUT1D03

BG_CABEH090	EQU	$
		JMP	BG_TATE100
;
BG_CABEH100	EQU	$
		M16
		LDA	BGUNDT1
		CMP	RUT1D00
		BNE	BG_CABEH150

		LDA	BGUNDT0
		CMP	RUT1D00
		BEQ	BG_CABEH160
		CMP	RUT1D0E
		BEQ	BG_CABEH170
		CMP	RUT1D05
		BEQ	BG_CABEH180
		CMP	RUT1D10
		BEQ	BG_CABEH180
		CMP	RUT1D07
		BEQ	BG_CABEH190
		CMP	RUT1D12
		BEQ	BG_CABEH190
		CMP	RUT1D02
		BEQ	BG_CABEH198
		CMP	RUT1D01
		BEQ	BG_CABEH199

		JMP	BG_TATE100

BG_CABEH150	EQU	$
		LDA	BGUNDT0
		CMP	RUT3924
		BEQ	BG_CABEH110
		CMP	RUT3926
		BEQ	BG_CABEH110
		CMP	RUT3928
		BEQ	BG_CABEH110
		CMP	RUT392A
		BNE	BG_CABEH158

BG_CABEH110	EQU	$
		LDA	RUT1D16
		JMP	BG_TATE100

BG_CABEH158	EQU	$
		LDA	RUT1D09		;normal data
		JMP	BG_TATE100

BG_CABEH160	EQU	$
		LDA	RUT1D09
		JMP	BG_TATE100

BG_CABEH170	EQU	$
		LDA	RUT1D13
		JMP	BG_TATE100

BG_CABEH180	EQU	$
		LDA	RUT1D0B
		JMP	BG_TATE100

BG_CABEH190	EQU	$
		LDA	RUT1D0C
		JMP	BG_TATE100

BG_CABEH198	EQU	$
;		LDA	RUT1D0F
		LDA	RUT1D06
		JMP	BG_TATE100

BG_CABEH199	EQU	$
		LDA	RUT1D11
		JMP	BG_TATE100

BG_CABEH200	EQU	$
		M16
		LDA	BGUNDT1
		CMP	RUT1D00
		BNE	BG_CABEH250

		LDA	BGUNDT0
		CMP	RUT1D00
		BEQ	BG_CABEH260
		CMP	RUT1D0D
		BEQ	BG_CABEH270
		CMP	RUT1D06
		BEQ	BG_CABEH280
		CMP	RUT1D0F
		BEQ	BG_CABEH280
		CMP	RUT1D04
		BEQ	BG_CABEH290
		CMP	RUT1D11
		BEQ	BG_CABEH290
		CMP	RUT1D02
		BEQ	BG_CABEH298
		CMP	RUT1D01
		BEQ	BG_CABEH299

		JMP	BG_TATE100

BG_CABEH250	EQU	$
		LDA	BGUNDT0
		CMP	RUT3925
		BEQ	BG_CABEH210
		CMP	RUT3927
		BEQ	BG_CABEH210
		CMP	RUT3929
		BEQ	BG_CABEH210
		CMP	RUT392B
		BNE	BG_CABEH258

BG_CABEH210	EQU	$
		LDA	RUT1D17
		JMP	BG_TATE100

BG_CABEH258	EQU	$
		LDA	RUT1D08		;normal data
		JMP	BG_TATE100

BG_CABEH260	EQU	$
		LDA	RUT1D08
		JMP	BG_TATE100

BG_CABEH270	EQU	$
		LDA	RUT1D13
		JMP	BG_TATE100

BG_CABEH280	EQU	$
		LDA	RUT1D0B
		JMP	BG_TATE100

BG_CABEH290	EQU	$
		LDA	RUT1D0C
		JMP	BG_TATE100

BG_CABEH298	EQU	$
;		LDA	RUT1D10
		LDA	RUT1D05
		JMP	BG_TATE100

BG_CABEH299	EQU	$
		LDA	RUT1D12
		JMP	BG_TATE100
;
;
;++++++++++++++++++++++++++++++++++++++++++++++++
;+	up character nu-ki set			+
;++++++++++++++++++++++++++++++++++++++++++++++++
		MEM16
		IDX16
BGUPNUKI	EQU	$
		PHX
		TXA
		SEC
		SBC	#00020H
		TAX
		JSR	HIGH3_CHECK
		LDA	UT39DT,Y
		STA	>BGUNIT,X
		PLX
		RTS
		MEM8
		IDX8
;
UT39DT		EQU	$
		WORD	UT0000,UT008C,UT008D
;
;
;
		MEM8
		IDX16
BG_CABEV	EQU	$
		M16
		LDA	>BGUNIT,X
		STA	BGUNDT0
		AND	#0FF00H
		STA	BGUNDT1

		TYA			;1st v_line ?
		BEQ	BG_CABEV100	; yes: BG_CABEV100

		INY

		CPY	<YWIDECP	;last v_line ?
		BEQ	BG_CABEV200	; yes: BG_CABEV200

		DEY
		LDA	BGUNDT0
		CMP	RUT1D08
		BEQ	BG_CABEV020
		CMP	RUT1D09
		BEQ	BG_CABEV020
		CMP	RUT3912
		BEQ	BG_CABEV010
		CMP	RUT3913
		BEQ	BG_CABEV010

		LDA	RUT1D00
		JMP	BG_TATE100
BG_CABEV010	EQU	$
		LDA	RUT1D14
BG_CABEV020	EQU	$
		JMP	BG_TATE100

BG_CABEV100	EQU	$
		LDA	BGUNDT1
		CMP	RUT1D00
		BNE	BG_CABEV108

		LDA	BGUNDT0
		CMP	RUT1D11
		BEQ	BG_CABEV201
		CMP	RUT1D0C
		BEQ	BG_CABEV202
		CMP	RUT1D12
		BEQ	BG_CABEV203
		CMP	RUT1D09
		BEQ	BG_CABEV120
		CMP	RUT1D08
		BEQ	BG_CABEV130
		CMP	RUT1D03
		BEQ	BG_CABEV109
		JMP	BG_TATE100

BG_CABEV108	EQU	$
		LDA	BGUNDT0
		CMP	RUT2A00
		BEQ	BG_CABEV110
		CMP	RUT2A01
		BEQ	BG_CABEV110

BG_CABEV109	EQU	$
		LDA	RUT1D02
		JMP	BG_TATE100

BG_CABEV110	EQU	$
		LDA	#UT008B
		JMP	BG_TATE100
BG_CABEV120	EQU	$
		LDA	RUT1D06
		JMP	BG_TATE100
BG_CABEV130	EQU	$
		LDA	RUT1D05
		JMP	BG_TATE100

BG_CABEV200	EQU	$
		DEY

		LDA	BGUNDT0
		CMP	RUT1D0F
		BEQ	BG_CABEV201
		CMP	RUT1D0B
		BEQ	BG_CABEV202
		CMP	RUT1D10
		BEQ	BG_CABEV203
		CMP	RUT1D09
		BEQ	BG_CABEV210
		CMP	RUT1D08
		BEQ	BG_CABEV220

		LDA	RUT1D01
		JMP	BG_TATE100

BG_CABEV201	EQU	$
		LDA	RUT1D0D
		JMP	BG_TATE100

BG_CABEV202	EQU	$
		LDA	RUT1D13
		JMP	BG_TATE100

BG_CABEV203	EQU	$
		LDA	RUT1D0E
		JMP	BG_TATE100

BG_CABEV210	EQU	$
		LDA	RUT1D04
		JMP	BG_TATE100

BG_CABEV220	EQU	$
		LDA	RUT1D07
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_BRIDGEV	EQU	$
		M16
		TYA
		BEQ	BG_BRIDGEV100

		INY
		CPY	<YWIDECP
		BEQ	BG_BRIDGEV200

		DEY
		LDA	>BGUNIT,X	;BG = NORMAL ?
		BEQ	BG_BRIDGEV050	; yes: BG_BRIDGEV050

		AND	#0FF00H		;BG = WATER ?
		CMP	#UT1600		;
		BNE	BG_BRIDGEV030	; no:  BG_BRIDGEV030

		LDA	#UT1615
		JMP	BG_TATE100
BG_BRIDGEV030	EQU	$
		LDA	#UT1509
		JMP	BG_TATE100
BG_BRIDGEV050	EQU	$
		LDA	#UT0020
		JMP	BG_TATE100
BG_BRIDGEV100	EQU	$
		LDA	>BGUNIT,X	;BG = WATER ?
		AND	#0FF00H		;
		CMP	#UT1600		;
		BEQ	BG_BRIDGEV150	; yes: BG_BRIDGEV150

		LDA	#UT1500
		JMP	BG_TATE100
BG_BRIDGEV150	EQU	$
		LDA	#UT1400
		JMP	BG_TATE100
BG_BRIDGEV200	EQU	$
		DEY

		LDA	>BGUNIT,X	;BG = WATER ?
		AND	#0FF00H		;
		CMP	#UT1600		;
		BEQ	BG_BRIDGEV250	; yes: BG_BRIDGEV250

		LDA	#UT0021
		JMP	BG_TATE100
BG_BRIDGEV250	EQU	$
		LDA	#UT1616
		JMP	BG_TATE100
;
;
		MEM8
		IDX16
BG_HARI_L	EQU	$
		M16
		TYA			;SAISHO ?
		BEQ	BG_HARI_L200	;

		LDA	>BGUNIT,X	;BG = SPACE ?
		BEQ	BG_HARI_L100	; yes: BG_HARI_L100

		LDA	#UT2907
		JMP	BG_TATE100

BG_HARI_L100	EQU	$
		LDA	#UT2905
		JMP	BG_TATE100
BG_HARI_L200	EQU	$
		LDA	#UT011A
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_HARI_R	EQU	$
		M16
		TYA			;SAISHO ?
		BEQ	BG_HARI_R200	;

		LDA	>BGUNIT,X	;BG = SPACE ?
		BEQ	BG_HARI_R100	; yes: BG_HARI_R100

		LDA	#UT2906
		JMP	BG_TATE100

BG_HARI_R100	EQU	$
		LDA	#UT2904
		JMP	BG_TATE100
BG_HARI_R200	EQU	$
		LDA	#UT0119
		JMP	BG_TATE100
;
;
;
;		rope rope ( yuki course )
;
		MEM8
		IDX16
BG_RPL30_1	EQU	$
		LDA	<XWIDE		;1st v_line ?
		CMP	<XWIDECP	;  no: BG_RPL30_1300
		BNE	BG_RPL30_1300	; yes: BG_RPL30_1200
		JMP	BG_RPL30_1200	;
BG_RPL30_1300	EQU	$
		M16
		LDA	#UT00AC
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_RPL30_3	EQU	$
		LDA	<XWIDE		;last v_line ?
		DEC	A		;  no: BG_RPL30_3200
		BNE	BG_RPL30_3200	; yes: BG_RPL30_3100
		JMP	BG_RPL30_3100	;
BG_RPL30_3200	EQU	$
		M16
		LDY	<YWIDECP
		DEY

		LDA	#UT00AB
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_RPL30_2	EQU	$
		M16
		LDY	<YWIDECP
		DEY

		LDA	#001H
		STA	<WORK16

		LDA	#UT00AA
		JMP	BG_TATE100	
;
		MEM8
		IDX16
BG_RPR30_1	EQU	$
		LDA	<XWIDE		;1st v_line ?
		CMP	<XWIDECP	;
		BEQ	BG_RPR30_1200	; yes: BG_RPR30_1200

		M16
		LDA	#UT00AD
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_RPR30_3	EQU	$
		LDA	<XWIDE		;last v_line ?
		DEC	A		;
		BEQ	BG_RPR30_3100	; yes: BG_RPR30_3100

		M16
		LDY	<YWIDECP
		DEY

		LDA	#UT00AE
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_RPR30_2	EQU	$
		M16
		LDY	<YWIDECP
		DEY

		LDA	#001H
		STA	<WORK16

		LDA	#UT00AF
		JMP	BG_TATE100	
;
		MEM8
		IDX16
BG_RPL45_1	EQU	$
		CPY	#000H
		BEQ	BG_RPL45_1100

		M16
		LDY	<YWIDECP
		DEY

		LDA	#001H
		STA	<WORK16

		LDA	#UT00A6
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_RPL45_1100	EQU	$
		LDA	<XWIDE		;1st v_line ?
		CMP	<XWIDECP	;
		BEQ	BG_RPL45_1200	; yes: BG_RPL45_1200

		DEC	A		;last v_line ?
		BEQ	BG_RPL45_1300	; yes: BG_RPL45_1300

		M16

		LDA	#UT00A7
		JMP	BG_TATE100
;
;
;
		MEM8
BG_RPR30_3100	EQU	$
BG_RPR45_1300	EQU	$
BG_RPR60_1300	EQU	$
BG_RPL30_1200	EQU	$
BG_RPL45_1200	EQU	$
BG_RPL60_1200	EQU	$

		M16
		LDY	<YWIDECP
		DEY

		LDA	>BGUNIT,X	;DOUBLE NO BOU ?
		CMP	#UT00C4		;
		BEQ	BG_RP0500	; YES BG_RP0500
		CMP	#UT00B7		;HIMOTUKI DOUBLE NO BOU ?
		BEQ	BG_RP0500	; YES BG_RP0500
		CMP	#UT00A2		;HIMOTUKI NO BOU ?
		BNE	BG_RP1000	; NO  BG_RP1000

BG_RP0500	EQU	$
		LDA	#UT00B7
		JMP	BG_TATE100

BG_RP1000	EQU	$
		LDA	#UT00A3
		JMP	BG_TATE100	
;
		MEM8
BG_RPL30_3100	EQU	$
BG_RPL45_1300	EQU	$
BG_RPL60_1300	EQU	$
BG_RPR30_1200	EQU	$
BG_RPR45_1200	EQU	$
BG_RPR60_1200	EQU	$

		M16
		LDY	<YWIDECP
		DEY

		LDA	>BGUNIT,X	;DOUBLE NO BOU ?
		CMP	#UT00C4		;
		BEQ	BG_RP0500	; YES BG_RP0500
		CMP	#UT00B7		;HIMOTUKI DOUBLE NO BOU ?
		BEQ	BG_RP0500	; YES BG_RP0500
		CMP	#UT00A3		;HIMOTUKI NO BOU ?
		BEQ	BG_RP0500	; YES BG_RP0500

		LDA	#UT00A2
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_RPR45_1	EQU	$
		CPY	#000H
		BEQ	BG_RPR45_1100

		M16
		LDY	<YWIDECP
		DEY

		LDA	#001H
		STA	<WORK16

		LDA	#UT00A9
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_RPR45_1100	EQU	$
		LDA	<XWIDE		;1st v_line ?
		CMP	<XWIDECP	;
		BEQ	BG_RPR45_1200	; yes: BG_RPR45_1200

		DEC	A		;last v_line ?
		BEQ	BG_RPR45_1300	; yes: BG_RPR45_1300

		M16

		LDA	#UT00A8
		JMP	BG_TATE100
;
;
		MEM8
		IDX16
BG_RPL60_1100	EQU	$
		LDA	<XWIDE		;1st v_line ?
		CMP	<XWIDECP	;
		BEQ	BG_RPL60_1200	; yes: BG_RPL60_1200

		DEC	A		;last v_line ?
		BEQ	BG_RPL60_1300	; yes: BG_RPL60_1300

		M16

		LDA	#UT00B5
		JMP	BG_TATE100
BG_RPL60_1400	EQU	$
		M16

		LDA	#UT00B3
		JMP	BG_TATE100	
;
		MEM8
		IDX16
BG_RPL60_1	EQU	$
		CPY	#000H
		BEQ	BG_RPL60_1100
		CPY	#001H
		BEQ	BG_RPL60_1400

		M16
		LDY	<YWIDECP
		DEY

		LDA	#001H
		STA	<WORK16

		LDA	#UT00B4
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_RPR60_1	EQU	$
		CPY	#000H
		BEQ	BG_RPR60_1100
		CPY	#001H
		BEQ	BG_RPR60_1400

		M16
		LDY	<YWIDECP
		DEY

		LDA	#001H
		STA	<WORK16

		LDA	#UT00B1
		JMP	BG_TATE100
		MEM8
BG_RPR60_1100	EQU	$
		LDA	<XWIDE		;1st v_line ?
		CMP	<XWIDECP	;
		BNE	BG_RPR60_1500	;  no: BG_RPR60_1500
		JMP	BG_RPR60_1200	; yes: BG_RPR60_1200
BG_RPR60_1500	EQU	$

		DEC	A		;last v_line ?
		BNE	BG_RPR60_1600	;  no: BG_RPR60_1600
		JMP	BG_RPR60_1300	; yes: BG_RPR60_1300
BG_RPR60_1600	EQU	$
		M16

		LDA	#UT00B0
		JMP	BG_TATE100
BG_RPR60_1400	EQU	$
		M16

		LDA	#UT00B2
		JMP	BG_TATE100
;
;
;
;		saka  ( kabe course )
;
		MEM8
		IDX16
BG_SAKAL30_1	EQU	$
		CPY	#000H		;1st h_line ?
		BEQ	BG_SAKAL30_1100	; yes: BG_SAKAL30_1100

		M16
		LDY	<YWIDECP
		DEY

		LDA	#001H
		STA	<WORK16

		LDA	#UT1140
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_SAKAL30_1100	EQU	$
		LDA	<XWIDE		;1st v_line ?
		CMP	<XWIDECP	;
		BNE	BG_SAKAL30_1300	;

		JMP	BG_SAKAL30_1200	; yes: BG_SAKAL45_1200

BG_SAKAL30_1300	EQU	$
		M16

		LDA	#UT1040
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_SAKAL30_2	EQU	$
		CPY	#000H		;1st h_line ?
		BEQ	BG_SAKAL30_2100	; yes: BG_SAKAL30_2100

		M16
		LDY	<YWIDECP
		DEY

		LDA	#UT1340
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_SAKAL30_2100	EQU	$
		LDA	<XWIDE		;last v_line ?
		DEC	A		;
		BEQ	BG_SAKAL30_2300	; yes: BG_SAKAL30_2300

		M16

		LDA	#UT0F40
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_SAKAR30_1	EQU	$
		CPY	#000H		;1st h_line ?
		BEQ	BG_SAKAR30_1100	; yes: BG_SAKAR30_1100

		M16
		LDY	<YWIDECP
		DEY

		LDA	#001H
		STA	<WORK16

		LDA	#UT0E40
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_SAKAR30_1100	EQU	$
		LDA	<XWIDE		;1st v_line ?
		CMP	<XWIDECP	;
		BEQ	BG_SAKAR30_1200	; yes: BG_SAKAR30_1200

		M16

		LDA	#UT0C40
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_SAKAR30_2	EQU	$
		CPY	#000H		;1st h_line ?
		BEQ	BG_SAKAR30_2100	; yes: BG_SAKAR30_2100

		M16
		LDY	<YWIDECP
		DEY

		LDA	#UT1240
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_SAKAR30_2100	EQU	$
		LDA	<XWIDE		;last v_line ?
		DEC	A		;
		BEQ	BG_SAKAR30_2300	; yes: BG_SAKAR30_2300

		M16

		LDA	#UT0D40
		JMP	BG_TATE100
;
;
		MEM8
		IDX16
BG_SAKAL45_1	EQU	$
		CPY	#000H		;1st h_line ?
		BEQ	BG_SAKAL45_1100	; yes: BG_SAKAL45_1100

		M16
		LDY	<YWIDECP
		DEY

		LDA	#001H
		STA	<WORK16

		LDA	#UT0B40
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_SAKAL45_1100	EQU	$
		LDA	<XWIDE		;1st v_line ?
		CMP	<XWIDECP	;
		BEQ	BG_SAKAL45_1200	; yes: BG_SAKAL45_1200

		DEC	A		;last v_line ?
		BEQ	BG_SAKAL45_1300	; yes: BG_SAKAL45_1300

		M16

		LDA	#UT0A40
		JMP	BG_TATE100
;
;
;
		MEM8
BG_SAKAR30_2300	EQU	$
BG_SAKAR45_1300	EQU	$
BG_SAKAR60_1300	EQU	$
BG_SAKAL30_1200	EQU	$
BG_SAKAL45_1200	EQU	$
BG_SAKAL60_1200	EQU	$

		M16
		LDY	<YWIDECP
		DEY

		LDA	#UT00E4
		JMP	BG_TATE100	
;
		MEM8
BG_SAKAL30_2300	EQU	$
BG_SAKAL45_1300	EQU	$
BG_SAKAL60_1300	EQU	$
BG_SAKAR30_1200	EQU	$
BG_SAKAR45_1200	EQU	$
BG_SAKAR60_1200	EQU	$

		M16
		LDY	<YWIDECP
		DEY

		LDA	#UT00E5
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_SAKAR45_1	EQU	$
		CPY	#000H
		BEQ	BG_SAKAR45_1100

		M16
		LDY	<YWIDECP
		DEY

		LDA	#001H
		STA	<WORK16

		LDA	#UT0940
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_SAKAR45_1100	EQU	$
		LDA	<XWIDE		;1st v_line ?
		CMP	<XWIDECP	;
		BEQ	BG_SAKAR45_1200	; yes: BG_SAKAR45_1200

		DEC	A		;last v_line ?
		BEQ	BG_SAKAR45_1300	; yes: BG_SAKAR45_1300

		M16

		LDA	#UT0840
		JMP	BG_TATE100
;
;
		MEM8
		IDX16
BG_SAKAL60_1100	EQU	$
		LDA	<XWIDE		;1st v_line ?
		CMP	<XWIDECP	;
		BEQ	BG_SAKAL60_1200	; yes: BG_SAKAL60_1200

		DEC	A		;last v_line ?
		BEQ	BG_SAKAL60_1300	; yes: BG_SAKAL60_1300

		M16

		LDA	#UT0540
		JMP	BG_TATE100
BG_SAKAL60_1400	EQU	$
		M16

		LDA	#UT0640
		JMP	BG_TATE100	
;
		MEM8
		IDX16
BG_SAKAL60_1	EQU	$
		CPY	#000H
		BEQ	BG_SAKAL60_1100
		CPY	#001H
		BEQ	BG_SAKAL60_1400

		M16
		LDY	<YWIDECP
		DEY

		LDA	#001H
		STA	<WORK16

		LDA	#UT0740
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_SAKAR60_1	EQU	$
		CPY	#000H
		BEQ	BG_SAKAR60_1100
		CPY	#001H
		BEQ	BG_SAKAR60_1400

		M16
		LDY	<YWIDECP
		DEY

		LDA	#001H
		STA	<WORK16

		LDA	#UT0440
		JMP	BG_TATE100
		MEM8
BG_SAKAR60_1100	EQU	$
		LDA	<XWIDE		;1st v_line ?
		CMP	<XWIDECP	;
		BNE	BG_SAKAR60_1500	;  no: BG_SAKAR60_1500
		JMP	BG_SAKAR60_1200	; yes: BG_SAKAR60_1200
BG_SAKAR60_1500	EQU	$

		DEC	A		;last v_line ?
		BNE	BG_SAKAR60_1600	;  no: BG_SAKAR60_1600
		JMP	BG_SAKAR60_1300	; yes: BG_SAKAR60_1300
BG_SAKAR60_1600	EQU	$
		M16

		LDA	#UT0240
		JMP	BG_TATE100
BG_SAKAR60_1400	EQU	$
		M16

		LDA	#UT0340
		JMP	BG_TATE100
;
;
;		senro ( kabe course )
;
		MEM8
		IDX16
BG_SENROS_L	EQU	$
		CPY	#000H
		BEQ	BG_SENROS_L0100

		M16
		LDY	<YWIDECP
		DEY

		LDA	#001H
		STA	<WORK16

		LDA	#UT2200
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_SENROS_L0100	EQU	$
		M16

		LDA	#UT2300
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_SENROS_R	EQU	$
		CPY	#000H
		BEQ	BG_SENROS_R0100

		M16
		LDY	<YWIDECP
		DEY

		LDA	#001H
		STA	<WORK16

		LDA	#UT2100
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_SENROS_R0100	EQU	$
		M16

		LDA	#UT2000
		JMP	BG_TATE100
;
;
;
;
;
		MEM8
		IDX16
BG_BERL30_1	EQU	$
		LDA	<XWIDE		;1st v_line ?
		CMP	<XWIDECP	;
		BNE	BG_BERL30_1300	;  no: BG_BERL30_1300
		JMP	BG_BERL30_1200
BG_BERL30_1300	EQU	$
		M16
		LDA	#UT00AC
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_BERL30_3	EQU	$
		LDA	<XWIDE		;last v_line ?
		DEC	A		;
		BNE	BG_BERL30_3200	;  no: BG_BERL30_3200
		JMP	BG_BERL30_3100
BG_BERL30_3200	EQU	$
		M16
		LDY	<YWIDECP
		DEY

		LDA	#UT00AB
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_BERL30_2	EQU	$
		M16
		LDY	<YWIDECP
		DEY

		LDA	#001H
		STA	<WORK16

		LDA	#UT00AA
		JMP	BG_TATE100	
;
		MEM8
		IDX16
BG_BERR30_1	EQU	$
		LDA	<XWIDE		;1st v_line ?
		CMP	<XWIDECP	;
		BEQ	BG_BERR30_1200	; yes: BG_BERR30_1200

		M16
		LDA	#UT00AD
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_BERR30_3	EQU	$
		LDA	<XWIDE		;last v_line ?
		DEC	A		;
		BEQ	BG_BERR30_3100	; yes: BG_BERR30_3100

		M16
		LDY	<YWIDECP
		DEY

		LDA	#UT00AE
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_BERR30_2	EQU	$
		M16
		LDY	<YWIDECP
		DEY

		LDA	#001H
		STA	<WORK16

		LDA	#UT00AF
		JMP	BG_TATE100	
;
		MEM8
		IDX16
BG_BERL45_1	EQU	$
		CPY	#000H
		BEQ	BG_BERL45_1100

		M16
		LDY	<YWIDECP
		DEY

		LDA	#001H
		STA	<WORK16

		LDA	#UT0033
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_BERL45_1100	EQU	$
		LDA	<XWIDE		;1st v_line ?
		CMP	<XWIDECP	;
		BEQ	BG_BERL45_1200	; yes: BG_BERL45_1200

		DEC	A		;last v_line ?
		BEQ	BG_BERL45_1300	; yes: BG_BERL45_1300

		M16

		LDA	#UT0001
		JMP	BG_TATE100
;
;
;
		MEM8
BG_BERR30_3100	EQU	$
BG_BERR45_1300	EQU	$
BG_BERR60_1300	EQU	$
BG_BERL30_1200	EQU	$
BG_BERL45_1200	EQU	$
BG_BERL60_1200	EQU	$

		M16
		LDY	<YWIDECP
		DEY

		LDA	#UT00A3		;left end chr.
		JMP	BG_TATE100	;
;
		MEM8
BG_BERL30_3100	EQU	$
BG_BERL45_1300	EQU	$
BG_BERL60_1300	EQU	$
BG_BERR30_1200	EQU	$
BG_BERR45_1200	EQU	$
BG_BERR60_1200	EQU	$

		M16
		LDY	<YWIDECP
		DEY

		LDA	#UT00A2		;right end chr.
		JMP	BG_TATE100	;
;
		MEM8
		IDX16
BG_BERR45_1	EQU	$
		CPY	#000H
		BEQ	BG_BERR45_1100

		M16
		LDY	<YWIDECP
		DEY

		LDA	#001H
		STA	<WORK16

		LDA	#UT00A9
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_BERR45_1100	EQU	$
		LDA	<XWIDE		;1st v_line ?
		CMP	<XWIDECP	;
		BEQ	BG_BERR45_1200	; yes: BG_BERR45_1200

		DEC	A		;last v_line ?
		BEQ	BG_BERR45_1300	; yes: BG_BERR45_1300

		M16

		LDA	#UT00A8
		JMP	BG_TATE100
;
;
		MEM8
		IDX16
BG_BERL60_1100	EQU	$
		LDA	<XWIDE		;1st v_line ?
		CMP	<XWIDECP	;
		BEQ	BG_BERL60_1200	; yes: BG_BERL60_1200

		DEC	A		;last v_line ?
		BEQ	BG_BERL60_1300	; yes: BG_BERL60_1300

		M16

		LDA	#UT00B5
		JMP	BG_TATE100
BG_BERL60_1400	EQU	$
		M16

		LDA	#UT00B3
		JMP	BG_TATE100	
;
		MEM8
		IDX16
BG_BERL60_1	EQU	$
		CPY	#000H
		BEQ	BG_BERL60_1100
		CPY	#001H
		BEQ	BG_BERL60_1400

		M16
		LDY	<YWIDECP
		DEY

		LDA	#001H
		STA	<WORK16

		LDA	#UT00B4
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_BERR60_1	EQU	$
		CPY	#000H
		BEQ	BG_BERR60_1100
		CPY	#001H
		BEQ	BG_BERR60_1400

		M16
		LDY	<YWIDECP
		DEY

		LDA	#001H
		STA	<WORK16

		LDA	#UT00B1
		JMP	BG_TATE100
		MEM8
BG_BERR60_1100	EQU	$
		LDA	<XWIDE		;1st v_line ?
		CMP	<XWIDECP	;
		BNE	BG_BERR60_1500	;  no: BG_BERR60_1500
		JMP	BG_BERR60_1200
BG_BERR60_1500	EQU	$

		DEC	A		;last v_line ?
		BNE	BG_BERR60_1600	;  no: BG_BERR60_1600
		JMP	BG_BERR60_1300
BG_BERR60_1600	EQU	$
		M16

		LDA	#UT00B0
		JMP	BG_TATE100
BG_BERR60_1400	EQU	$
		M16

		LDA	#UT00B2
		JMP	BG_TATE100
;
;
;
;
;
;
;
WROCK_DATA	EQU	$
		WORD	UT1601,UT1605,UT1609,UT160D,UT1611	;1st Line
		WORD	UT1602,UT1606,UT160A,UT160E,UT1612	;2nd Line
		WORD	UT1603,UT1607,UT160B,UT160F,UT1613	;3rd Line
		WORD	UT1604,UT1608,UT160C,UT1610,UT1614	;4th Line
BLOCK_DATA	EQU	$
		WORD	UT0030,UT0100,UT0103,UT0106,UT0108	;1
		WORD	UT0031,UT0101,UT0104,UT0108,UT0109	;2-1,2-6
		WORD	UT0032,UT0102,UT0103,UT0109,UT0108	;3-1,3-6
		WORD	UT0035,UT010A,UT0105,UT0108,UT0106	;6
		WORD	UT0030,UT0100,UT0103,UT0109,UT0108	;1-6
		WORD	UT0031,UT0101,UT0104,UT0106,UT0109	;2-E0
		WORD	UT0031,UT0101,UT0105,UT0109,UT0106	;2-E1
KYUKA_DATA	EQU	$
		WORD	UT0167,UT0169,UT0167,UT0169,UT0167	;1st (X_wide = kisu- ) line
		WORD	UT0169,UT0167,UT0169,UT0167,UT0169	;1st (X_wide = gu-su-) line
		WORD	UT0168,UT0167,UT0168,UT0167,UT0168	;between line1
		WORD	UT0167,UT0168,UT0167,UT0168,UT0167	;between line2
		WORD	UT0169,UT0168,UT0169,UT0168,UT0169	;last (X_wide = kisu- ) line
		WORD	UT0168,UT0169,UT0168,UT0169,UT0168	;last (X_wide = gu-su-) line
;
SOAP_DATA	EQU	$
		WORD	UT3706
SP_DATA		EQU	$
		WORD	UT3700,UT3703,UT3703,UT3703,UT3703,UT3703	;LEFT
		WORD	UT3701,UT3704,UT3704,UT3704,UT3704,UT3704	;CENTER
		WORD	UT3707
SP_DATA2	EQU	$
		WORD	UT3702,UT3705,UT3705,UT3705,UT3705,UT3705	;RIGHT
;
SOAP2_DATA	EQU	$
		WORD	UT1620,UT1621,UT1621,UT1621,UT1621,UT1621
;
SOAP3_DATA	EQU	$
		WORD	UT010C,UT010D,UT010D,UT010D,UT010D,UT010D
;
YOGAN_DATA	EQU	$
		WORD	UT0033,UT002F,UT1618,UT2900,UT2903,UT2902
		WORD	UT0034,UT002F,UT1619,UT2901,UT2903,UT2902
;
KBWTR_DATA	EQU	$
		WORD	UT00E3,UT290A,UT290A,UT290A,UT290A,UT290A
;
BABULE_DATA_R1	EQU	$
		WORD	UT2B04,UT2D04,UT2E04,UT0048
		WORD	UT2C04,UT0040,UT0043,UT0049
		WORD	UT2F04,UT0043,UT0043,UT004A
		WORD	UT3004,UT3104,UT3204,UT004B
;
BABULE_DATA_B1	EQU	$
		WORD	UT2B06,UT2D06,UT2E06,UT0050
		WORD	UT2C06,UT0044,UT0047,UT0051
		WORD	UT2F06,UT0047,UT0047,UT0052
		WORD	UT3006,UT3106,UT3206,UT0053
;
BABULE_DATA_R2	EQU	$
		WORD	UT2B05,UT2D05,UT2E05,UT0068
		WORD	UT2C05,UT0060,UT0063,UT0069
		WORD	UT2F05,UT0063,UT0063,UT006A
		WORD	UT3005,UT3105,UT3205,UT006B
;
BABULE_DATA_B2	EQU	$
		WORD	UT2B07,UT2D07,UT2E07,UT0070
		WORD	UT2C07,UT0064,UT0067,UT0071
		WORD	UT2F07,UT0067,UT0067,UT0072
		WORD	UT3007,UT3107,UT3207,UT0073
;
BABULE_DATA_R3	EQU	$
		WORD	UT2B00,UT2D00,UT2E00,UT004C
		WORD	UT2C00,UT0040,UT0043,UT004D
		WORD	UT2F00,UT0043,UT0043,UT004E
		WORD	UT3000,UT3100,UT3200,UT004F
;
BABULE_DATA_B3	EQU	$
		WORD	UT2B02,UT2D02,UT2E02,UT0054
		WORD	UT2C02,UT0044,UT0047,UT0055
		WORD	UT2F02,UT0047,UT0047,UT0056
		WORD	UT3002,UT3102,UT3202,UT0057
;
BABULE_DATA_R4	EQU	$
		WORD	UT2B01,UT2D01,UT2E01,UT006C
		WORD	UT2C01,UT0060,UT0063,UT006D
		WORD	UT2F01,UT0063,UT0063,UT006E
		WORD	UT3001,UT3101,UT3201,UT006F
;
BABULE_DATA_B4	EQU	$
		WORD	UT2B02,UT2D02,UT2E02,UT0074
		WORD	UT2C02,UT0064,UT0067,UT0075
		WORD	UT2F02,UT0067,UT0067,UT0076
		WORD	UT3002,UT3102,UT3202,UT0077
;
BABULE_HILIGHT	EQU	$
		WORD	UT2E08,UT0043,UT0043,UT0059
		WORD	UT0043,UT0043,UT0043,UT0043
		WORD	UT0043,UT0043,UT0043,UT0043
		WORD	UT3208,UT0043,UT0043,UT0058
;
BABULE_HILIGHT2	EQU	$
		WORD	UT2E0A,UT0047,UT0047,UT005B
		WORD	UT0047,UT0047,UT0047,UT0047
		WORD	UT0047,UT0047,UT0047,UT0047
		WORD	UT320A,UT0047,UT0047,UT005A
;
BABULE_HILIGHT3	EQU	$
		WORD	UT2E09,UT0063,UT0063,UT0079
		WORD	UT0063,UT0063,UT0063,UT0063
		WORD	UT0063,UT0063,UT0063,UT0063
		WORD	UT3209,UT0063,UT0063,UT0078
;
BABULE_HILIGHT4	EQU	$
		WORD	UT2E0B,UT0067,UT0067,UT007B
		WORD	UT0067,UT0067,UT0067,UT0067
		WORD	UT0067,UT0067,UT0067,UT0067
		WORD	UT320B,UT0067,UT0067,UT007A
;
BABS_DATA_R1	EQU	$
		WORD	UT3304,UT3404
		WORD	UT3504,UT3604
;
BABS_DATA_B1	EQU	$
		WORD	UT3306,UT3406
		WORD	UT3506,UT3606
;
BABS_DATA_R2	EQU	$
		WORD	UT3305,UT3405
		WORD	UT3505,UT3605
;
BABS_DATA_B2	EQU	$
		WORD	UT3307,UT3407
		WORD	UT3507,UT3607
;
BABS_DATA_R3	EQU	$
		WORD	UT3300,UT3400
		WORD	UT3500,UT3600
;
BABS_DATA_B3	EQU	$
		WORD	UT3302,UT3402
		WORD	UT3502,UT3602
;
BABS_DATA_R4	EQU	$
		WORD	UT3301,UT3401
		WORD	UT3501,UT3601
;
BABS_DATA_B4	EQU	$
		WORD	UT3303,UT3403
		WORD	UT3503,UT3603
;
KABE_HOLEL	EQU	$
		WORD	UT016B,UT016D
KABE_HOLER	EQU	$
		WORD	UT016A,UT016C
;
ADD_DATA	EQU	$
		WORD	00000H,00008H,00010H,00018H
;
;
;		kotei 1 char.
;
;
		MEM8
		IDX16
BG_HILIGHT_RHL1	EQU	$
		M16
		LDA	#UT2E08
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_HILIGHT_BHL1	EQU	$
		M16
		LDA	#UT2E0A
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_HILIGHT_RHL2	EQU	$
		M16
		LDA	#UT2E09
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_HILIGHT_BHL2	EQU	$
		M16
		LDA	#UT2E0B
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_HILIGHT_RLL1	EQU	$
		M16
		LDA	#UT0059
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_HILIGHT_BLL1	EQU	$
		M16
		LDA	#UT005B
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_HILIGHT_RLL2	EQU	$
		M16
		LDA	#UT0079
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_HILIGHT_BLL2	EQU	$
		M16
		LDA	#UT007B
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_HILIGHT_RHR1	EQU	$
		M16
		LDA	#UT3208
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_HILIGHT_BHR1	EQU	$
		M16
		LDA	#UT320A
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_HILIGHT_RHR2	EQU	$
		M16
		LDA	#UT3209
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_HILIGHT_BHR2	EQU	$
		M16
		LDA	#UT320B
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_HILIGHT_RLR1	EQU	$
		M16
		LDA	#UT0058
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_HILIGHT_BLR1	EQU	$
		M16
		LDA	#UT005A
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_HILIGHT_RLR2	EQU	$
		M16
		LDA	#UT0078
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_HILIGHT_BLR2	EQU	$
		M16
		LDA	#UT007A
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_HILIGHT_RHL21	EQU	$
		M16
		LDA	#UT3408
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_HILIGHT_BHL21	EQU	$
		M16
		LDA	#UT340A
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_HILIGHT_RHL22	EQU	$
		M16
		LDA	#UT3409
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_HILIGHT_BHL22	EQU	$
		M16
		LDA	#UT340B
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_HILIGHT_RLL21	EQU	$
		M16
		LDA	#UT0084
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_HILIGHT_BLL21	EQU	$
		M16
		LDA	#UT0086
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_HILIGHT_RLL22	EQU	$
		M16
		LDA	#UT0085
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_HILIGHT_BLL22	EQU	$
		M16
		LDA	#UT0087
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_HILIGHT_RHR21	EQU	$
		M16
		LDA	#UT3608
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_HILIGHT_BHR21	EQU	$
		M16
		LDA	#UT360A
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_HILIGHT_RHR22	EQU	$
		M16
		LDA	#UT3609
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_HILIGHT_BHR22	EQU	$
		M16
		LDA	#UT360B
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_HILIGHT_RLR21	EQU	$
		M16
		LDA	#UT0080
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_HILIGHT_BLR21	EQU	$
		M16
		LDA	#UT0082
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_HILIGHT_RLR22	EQU	$
		M16
		LDA	#UT0081
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_HILIGHT_BLR22	EQU	$
		M16
		LDA	#UT0083
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_HILIGHT_RS11	EQU	$
		M16
		LDA	#UT0042
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_HILIGHT_BS11	EQU	$
		M16
		LDA	#UT0046
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_HILIGHT_RS12	EQU	$
		M16
		LDA	#UT0062
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_HILIGHT_BS12	EQU	$
		M16
		LDA	#UT0066
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_HILIGHT_RS21	EQU	$
		M16
		LDA	#UT0041
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_HILIGHT_BS21	EQU	$
		M16
		LDA	#UT0045
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_HILIGHT_RS22	EQU	$
		M16
		LDA	#UT0061
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_HILIGHT_BS22	EQU	$
		M16
		LDA	#UT0065
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_SENRO00	EQU	$
		M16
		LDA	#UT1E00
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_SENRO01	EQU	$
		M16
		LDA	#UT2000
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_SENRO02	EQU	$
		M16
		LDA	#UT2100
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_SENRO03	EQU	$
		M16
		LDA	#UT2200
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_SENRO04	EQU	$
		M16
		LDA	#UT2300
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_SENRO05	EQU	$
		M16
		LDA	#UT2500
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_SENRO06	EQU	$
		M16
		LDA	#UT2600
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_SENRO07	EQU	$
		M16
		LDA	#UT2700
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_SENRO08	EQU	$
		M16
		LDA	#UT2800
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_RAKUGAKI00	EQU	$
		M16
		LDA	#UT3D00
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_RAKUGAKI01	EQU	$
		M16
		LDA	#UT3D01
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_RAKUGAKI02	EQU	$
		M16
;;;;K;;;;		LDA	#UT3D02
		LDA	#UT5E00
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_RAKUGAKI03	EQU	$
		M16
;;;;K;;;;		LDA	#UT3D03
		LDA	#UT5E00
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_RAKUGAKI04	EQU	$
		M16
		LDA	#UT3D04
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_RAKUGAKI05	EQU	$
		M16
		LDA	#UT3D05
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_RAKUGAKI06	EQU	$
		M16
		LDA	#UT3D06
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_RAKUGAKI07	EQU	$
		M16
		LDA	#UT3D07
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_RAKUGAKI08	EQU	$
		M16
		LDA	#UT3D08
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_RAKUGAKI09	EQU	$
		M16
		LDA	#UT3D09
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_RAKUGAKI10	EQU	$
		M16
		LDA	#UT3D0A
		JMP	BG_TATE100
;
;
;		kotei 4 char.
;
;
		MEM8
		IDX16
BG_HILIGHT_RD1	EQU	$
		M16
		STY	<WORK1A
		M8

		LDA	<XWIDE		;1st v_line ?
		CMP	<XWIDECP	;
		BEQ	BG_HILIGHT_RD10	;

		LDY	#(BABULE_DATA_B4-WROCK_DATA+0001CH)
		JMP	BG_BABULE_S
;
BG_HILIGHT_RD10	EQU	$
		LDY	#(BABULE_HILIGHT-WROCK_DATA)
		JMP	BG_BABULE_S
;
		MEM8
		IDX16
BG_HILIGHT_BD1	EQU	$
		M16
		STY	<WORK1A
		M8

		LDA	<XWIDE		;1st v_line ?
		CMP	<XWIDECP	;
		BEQ	BG_HILIGHT_BD10	;

		LDY	#(BABULE_HILIGHT2-WROCK_DATA+0001CH)
		JMP	BG_BABULE_S
;
BG_HILIGHT_BD10	EQU	$
		LDY	#(BABULE_HILIGHT2-WROCK_DATA)
		JMP	BG_BABULE_S
;
		MEM8
		IDX16
BG_HILIGHT_RD2	EQU	$
		M16
		STY	<WORK1A
		M8

		LDA	<XWIDE		;1st v_line ?
		CMP	<XWIDECP	;
		BEQ	BG_HILIGHT_RD20	;

		LDY	#(BABULE_HILIGHT3-WROCK_DATA+0001CH)
		JMP	BG_BABULE_S
;
BG_HILIGHT_RD20	EQU	$
		LDY	#(BABULE_HILIGHT3-WROCK_DATA)
		JMP	BG_BABULE_S
;
		MEM8
		IDX16
BG_HILIGHT_BD2	EQU	$
		M16
		STY	<WORK1A
		M8

		LDA	<XWIDE		;1st v_line ?
		CMP	<XWIDECP	;
		BEQ	BG_HILIGHT_BD20	;

		LDY	#(BABULE_HILIGHT4-WROCK_DATA+0001CH)
		JMP	BG_BABULE_S
;
BG_HILIGHT_BD20	EQU	$
		LDY	#(BABULE_HILIGHT4-WROCK_DATA)
		JMP	BG_BABULE_S
;
		MEM8
		IDX16
BG_HILIGHT_RD3	EQU	$
		M16
		STY	<WORK1A
		M8

		LDA	<XWIDE		;1st v_line ?
		CMP	<XWIDECP	;
		BEQ	BG_HILIGHT_RD30	;

		LDY	#(BABULE_HILIGHT-WROCK_DATA+00018H)
		JMP	BG_BABULE_S
;
BG_HILIGHT_RD30	EQU	$
		LDY	#(BABULE_HILIGHT-WROCK_DATA+00004H)
		JMP	BG_BABULE_S
;
		MEM8
		IDX16
BG_HILIGHT_BD3	EQU	$
		M16
		STY	<WORK1A
		M8

		LDA	<XWIDE		;1st v_line ?
		CMP	<XWIDECP	;
		BEQ	BG_HILIGHT_BD30	;

		LDY	#(BABULE_HILIGHT2-WROCK_DATA+00018H)
		JMP	BG_BABULE_S
;
BG_HILIGHT_BD30	EQU	$
		LDY	#(BABULE_HILIGHT2-WROCK_DATA+00004H)
		JMP	BG_BABULE_S
;
		MEM8
		IDX16
BG_HILIGHT_RD4	EQU	$
		M16
		STY	<WORK1A
		M8

		LDA	<XWIDE		;1st v_line ?
		CMP	<XWIDECP	;
		BEQ	BG_HILIGHT_RD40	;

		LDY	#(BABULE_HILIGHT3-WROCK_DATA+00018H)
		JMP	BG_BABULE_S
;
BG_HILIGHT_RD40	EQU	$
		LDY	#(BABULE_HILIGHT3-WROCK_DATA+00004H)
		JMP	BG_BABULE_S
;
		MEM8
		IDX16
BG_HILIGHT_BD4	EQU	$
		M16
		STY	<WORK1A
		M8

		LDA	<XWIDE		;1st v_line ?
		CMP	<XWIDECP	;
		BEQ	BG_HILIGHT_BD40	;

		LDY	#(BABULE_HILIGHT4-WROCK_DATA+00018H)
		JMP	BG_BABULE_S
;
BG_HILIGHT_BD40	EQU	$
		LDY	#(BABULE_HILIGHT4-WROCK_DATA+00004H)
		JMP	BG_BABULE_S
;
		MEM8
		IDX16
BG_KABE_HOLE	EQU	$
		M16
		STY	<WORK1A
		M8

		LDA	<XWIDE		;1st v_line ?
		CMP	<XWIDECP	;
		BEQ	BG_KABE_HOLE020	;

		LDY	#(KABE_HOLEL-WROCK_DATA)
		JMP	BG_KHOLE_S

BG_KABE_HOLE020	EQU	$
		LDY	#(KABE_HOLER-WROCK_DATA)
		JMP	BG_KHOLE_S
;
;
;		full of one char.
;
;
		MEM8
		IDX16
BG_WATER	EQU	$
		M16
		LDA	#UT1600
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_KINOKO	EQU	$
		M16
		LDA	#UT0024
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_HANA		EQU	$
		M16
		LDA	#UT0025
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_SOAP1_R1	EQU	$
		M16
		LDA	#UT0043
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_SOAP1_B1	EQU	$
		M16
		LDA	#UT0047
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_SOAP1_R2	EQU	$
		M16
		LDA	#UT0063
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_SOAP1_B2	EQU	$
		M16
		LDA	#UT0067
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_AWAAWA	EQU	$
		M16
		LDA	#UT0088
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_KABEB	EQU	$
		M16
		LDA	#UT00D5
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_KABE_MOVE	EQU	$
		LDA	<XWIDE		;1st v_line ?
		CMP	<XWIDECP	;
		BNE	BG_KABE_MOVE2	;  no: BG_KABE_MOVE2

		M16
		LDA	#UT00CE
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_KABE_MOVE2	EQU	$
		M16
		LDA	#UT00CF
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_SENROV	EQU	$
		M16
		LDA	#UT1F00
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_SENROH	EQU	$
		M16
		LDA	#UT2400
		JMP	BG_TATE100
;
;
;
;
;
;
;
		MEM8
		IDX16
BG_BABULE	EQU	$
		M16
		LDA	#(BABULE_DATA_R1-WROCK_DATA+00000H)	;BASE INDEX

BG_BABULE100	EQU	$
		STA	<WORK0

		STY	<WORK1A		;SAVE Y_REG
		PHX			;PUSH X_REG
		MI8

		LDA	<XWIDECP
		SEC
		SBC	<XWIDE
		ASL	A
		TAY

		M16

		LDA	<WORK18		;GET DATA INDEX
		CLC			;
		ADC	ADD_DATA,Y	;
		CLC			;
		ADC	<WORK0		;

		I16
		PLX			;PULL X_REG

		TAY			;routine data index set
		BRA	BG_BABULE_S
;
;
		MEM8
		IDX16
BG_BABS		EQU	$
		LDA	<XWIDECP	;v_line = ...
		SEC			;  1st: BG_BABULE
		SBC	<XWIDE		;
		AND	#001H		;
		BEQ	BG_BABULE	;

		M16
		LDA	#(BABULE_DATA_R1-WROCK_DATA-00004H)	;BASE INDEX

		BRA	BG_BABULE100
;
		MEM8
		IDX16
BG_YOGAN1	EQU	$
		PHY

		LDY	#(YOGAN_DATA-WROCK_DATA+00000H)
		BRA	BG_YOGAN

		MEM8
		IDX16
BG_YOGAN2	EQU	$
		PHY

		LDY	#(YOGAN_DATA-WROCK_DATA+0000CH)
BG_YOGAN	EQU	$
		M16
		PLA
		STA	<WORK1A
		BRA	BG_YOGAN_S
;
		MEM8
		IDX16
BG_SOAP		EQU	$
		M16
		STY	<WORK1A
		M8

		LDA	<XWIDE		;1st v_line ?
		CMP	<XWIDECP	;
		BEQ	BG_SOAP000	; yes: BG_SOAP000
		DEC	A		;last V_line ?
		BEQ	BG_SOAP010	; yes: BG_SOAP010

		LDY	#(SP_DATA-WROCK_DATA+0000CH)
		BRA	BG_SOAP_S

BG_SOAP000	EQU	$
		LDY	#(SP_DATA-WROCK_DATA+00000H)
		BRA	BG_SOAP_S

BG_SOAP010	EQU	$
		LDY	#(SP_DATA-WROCK_DATA+0001AH)
		BRA	BG_SOAP_S
;
		MEM8
		IDX16
BG_SOAP2	EQU	$
		M16
		STY	<WORK1A
		M8

		LDY	#(SOAP2_DATA-WROCK_DATA+00000H)
		BRA	BG_SOAP_S
;
		MEM8
		IDX16
BG_SOAP3	EQU	$
		M16
		STY	<WORK1A
		M8

		LDY	#(SOAP3_DATA-WROCK_DATA+00000H)
		BRA	BG_SOAP_S
;
		MEM8
		IDX16
BG_WROCK	EQU	$
		M16
		STY	<WORK1A
		M8

		LDA	<XWIDECP	;v_line = ...
		SEC			;  1st: BG_WROCK000
		SBC	<XWIDE		;  2nd: BG_WROCK100
		AND	#003H		;  3rd: BG_WROCK200
		BEQ	BG_WROCK000	;
		CMP	#001H		;
		BEQ	BG_WROCK100	;
		CMP	#002H		;
		BEQ	BG_WROCK200	;

		LDY	#(WROCK_DATA-WROCK_DATA+0001EH)
		BRA	BG_WROCK300

BG_WROCK000	EQU	$
		LDY	#(WROCK_DATA-WROCK_DATA+00000H)
		BRA	BG_WROCK300

BG_WROCK100	EQU	$
		LDY	#(WROCK_DATA-WROCK_DATA+0000AH)
		BRA	BG_WROCK300

BG_WROCK200	EQU	$
		LDY	#(WROCK_DATA-WROCK_DATA+00014H)
;
;
;
BG_WROCK300	EQU	$
BG_BLOCK	EQU	$
BG_YOGAN_S	EQU	$
BG_SOAP_S	EQU	$
BG_BABULE_S	EQU	$
BG_KBWTR_S	EQU	$
BG_KHOLE_S	EQU	$
BG_KYUKA	EQU	$

		M16
		LDA	<WORK1A		;v_line  = ...
		BEQ	BG_WROCK700	;      1st: BG_WROCK700
		CMP	#00005H		; 4th over: BG_WROCK400
		BCS	BG_WROCK400	;

BG_WROCK350	EQU	$

		ASL	A
		STA	<WORK0

		TYA
		CLC
		ADC	<WORK0
		TAY
		BRA	BG_WROCK800

BG_WROCK400	EQU	$
		CPY	#(SOAP_DATA-WROCK_DATA)
;		CPY	#000AEH
		BCS	BG_WROCK450

		AND	#00001H
		BEQ	BG_WROCK500
		BRA	BG_WROCK600

BG_WROCK450	EQU	$
		CMP	#00006H
		BCC	BG_WROCK350

		INY
		INY

BG_WROCK500	EQU	$
		INY
		INY

BG_WROCK600	EQU	$
		INY
		INY
		INY
		INY
		INY
		INY
		BRA	BG_WROCK800

BG_WROCK700	EQU	$
		CPY	#(SP_DATA-WROCK_DATA)	;soap courner ?
		BEQ	BG_WROCK900		;
		CPY	#(SP_DATA2-WROCK_DATA)	;
		BEQ	BG_WROCK900		; yes: BG_WROCK900

BG_WROCK800	EQU	$
		LDA	WROCK_DATA,Y
		LDY	<WORK1A
		JMP	BG_TATE100

BG_WROCK900	EQU	$
		LDA	>BGUNIT,X
		BEQ	BG_WROCK800

		DEY
		DEY
		BRA	BG_WROCK800
;
;		YOUGAN
;
		MEM8
		IDX16
BG_BLOCK1	EQU	$
		M16
		STY	<WORK1A
		M8

		LDA	<XWIDE		;v_line = ...
		CMP	<XWIDECP	;  1st: BG_BLOCK1100
		BEQ	BG_BLOCK1100	; last: BG_BLOCK1200
		DEC	A		;
		BEQ	BG_BLOCK1200	;

		LDA	<XWIDECP	;v_line = ...
		SEC			;  gu-suu:
		SBC	<XWIDE		;   kisuu: BG_BLOCK1000
		AND	#001H		;
		BNE	BG_BLOCK1000	;

		LDY	#(BLOCK_DATA-WROCK_DATA+00014H)
		BRA	BG_BLOCK

BG_BLOCK1000	EQU	$
		LDY	#(BLOCK_DATA-WROCK_DATA+0000AH)
		BRA	BG_BLOCK

BG_BLOCK1100	EQU	$
		LDY	#(BLOCK_DATA-WROCK_DATA+00000H)
		BRA	BG_BLOCK
BG_BLOCK1200	EQU	$
		LDA	XWIDECP		;v_line summary = ...
		AND	#00001H		;
		BEQ	BG_BLOCK1400	; gu-suu: BG_BLOCK1400

BG_BLOCK1300	EQU	$
		LDY	#(BLOCK_DATA-WROCK_DATA+0003CH)
		JMP	BG_BLOCK

BG_BLOCK1400	EQU	$
		LDY	#(BLOCK_DATA-WROCK_DATA+00032H)
		JMP	BG_BLOCK
;
		MEM8
		IDX16
BG_BLOCK2	EQU	$
		M16
		STY	<WORK1A
		M8

		LDA	<XWIDE		;v_line = ...
		CMP	<XWIDECP	;  1st: BG_BLOCK2100
		BEQ	BG_BLOCK2100	; last: BG_BLOCK2300
		DEC	A		;
		BEQ	BG_BLOCK2300	;

		LDA	<XWIDECP	;v_line = ...
		SEC			; gu-suu: BG_BLOCK2000
		SBC	<XWIDE		;  kisuu:
		BIT	#001H		;
		BEQ	BG_BLOCK2000	;

		LDY	#(BLOCK_DATA-WROCK_DATA+00014H)
		JMP	BG_BLOCK

BG_BLOCK2000	EQU	$
		LDY	#(BLOCK_DATA-WROCK_DATA+0000AH)
		JMP	BG_BLOCK

BG_BLOCK2100	EQU	$
		LDY	#(BLOCK_DATA-WROCK_DATA+0001EH)
		JMP	BG_BLOCK

BG_BLOCK2300	EQU	$
		LDA	<XWIDECP	;V_line sum = ...
		AND	#00001H		;  kisuu: BG_BLOCK1400
		BNE	BG_BLOCK1400	; gu-su-: BG_BLOCK1300
		BRA	BG_BLOCK1300	;
;
;
;		KABE
;
		MEM8
		IDX16
BG_KYUKA1	EQU	$
		M16
		STY	<WORK1A
		M8

		LDA	<XWIDECP	;v_line = only 1 line ?
		DEC	A		;
		BEQ	BG_KYUKA12	; yes: BG_KYUKA12

		LDA	<XWIDE		;v_line = ...
		CMP	<XWIDECP	;         1st: BG_KYUKA1100
		BEQ	BG_KYUKA1100	;        last: BG_KYUKA1200
		DEC	A		;
		BEQ	BG_KYUKA1200	;

		LDA	<XWIDECP	;V_line = ...
		SEC			;  gu-su- line:
		SBC	<XWIDE		;  kisu-  line: BG_KYUKA1000
		AND	#001H		;
		BNE	BG_KYUKA1000	;

		LDY	#(KYUKA_DATA-WROCK_DATA+0001EH)
		JMP	BG_KYUKA

BG_KYUKA1000	EQU	$
		LDY	#(KYUKA_DATA-WROCK_DATA+00014H)
		JMP	BG_KYUKA

BG_KYUKA1100	EQU	$
		LDY	#(KYUKA_DATA-WROCK_DATA+00000H)
		JMP	BG_KYUKA
BG_KYUKA1200	EQU	$
		JSR	KYUKA_SHADOW

		LDA	<XWIDECP	;v_line summary = ...
		AND	#00001H		;
		BNE	BG_KYUKA1400	; gu-suu: BG_KYUKA1400

BG_KYUKA1300	EQU	$
		LDY	#(KYUKA_DATA-WROCK_DATA+00032H)
		JMP	BG_KYUKA

BG_KYUKA1400	EQU	$
		LDY	#(KYUKA_DATA-WROCK_DATA+00028H)
		JMP	BG_KYUKA
;
		MEM8
		IDX16
BG_KYUKA2	EQU	$
		M16
		STY	<WORK1A
		M8

		LDA	<XWIDECP	;v_line = only 1 line ?
		DEC	A		;
		BEQ	BG_KYUKA12	; yes: BG_KYUKA12

		LDA	<XWIDE		;v_line = ...
		CMP	<XWIDECP	;         1st: BG_KYUKA2100
		BEQ	BG_KYUKA2100	;        last: BG_KYUKA2300
		DEC	A		;
		BEQ	BG_KYUKA2300	;

		LDA	<XWIDECP	;V_line = ...
		SEC			;  gu-su- line: BG_KYUKA2000
		SBC	<XWIDE		;  kisu-  line:
		BIT	#001H		;
		BEQ	BG_KYUKA2000	;

		LDY	#(KYUKA_DATA-WROCK_DATA+0001EH)
		JMP	BG_KYUKA

BG_KYUKA2000	EQU	$
		LDY	#(KYUKA_DATA-WROCK_DATA+00014H)
		JMP	BG_KYUKA

BG_KYUKA2100	EQU	$
		LDY	#(KYUKA_DATA-WROCK_DATA+0000AH)
		JMP	BG_KYUKA

BG_KYUKA2300	EQU	$
		JSR	KYUKA_SHADOW

		LDA	<XWIDECP	;V_line sum = ...
		AND	#00001H		;  kisu-: BG_KYUKA1400
		BEQ	BG_KYUKA1400	; gu-su-: BG_KYUKA1300
		BRA	BG_KYUKA1300	;
;
BG_KYUKA12	EQU	$
		M16
		LDA	#UT0169
		JMP	BG_TATE100
;
		MEM8
		IDX16
KYUKA_SHADOW	EQU	$
		M16
		TYA
		BEQ	KYUKA_SHADOW100

		LDA	#UT00D8
		BRA	KYUKA_SHADOW200

KYUKA_SHADOW100	EQU	$
		LDA	#UT00D7

KYUKA_SHADOW200	EQU	$
		JSR	KABEV_SHADOW

		M8
		RTS
;
;BG_KYUKA12	EQU	$
;		M16
;		LDY	<WORK1A
;
;		LDA	>BGUNIT,X	;BG = kabe back ?
;		CMP	#UT00D5		;
;		BNE	BG_KYUKA121	; yes: BG_KYUKA121
;
;		TXA
;		AND	#0001FH
;		BNE	BG_KYUKA122
;
;		JMP	BG_TATE200
;
;BG_KYUKA122	EQU	$
;		CPY	#00000H
;		BEQ	BG_KYUKA120
;
;		LDA	#UT00D8
;		BRA	BG_KYUKA121
;
;BG_KYUKA120	EQU	$
;		LDA	#UT00D7
;
;BG_KYUKA121	EQU	$
;		JMP	BG_TATE100
;
;
;
;
;
		MEM8
		IDX16
BG_KBWTR	EQU	$
		M16
		STY	<WORK1A
		M8

		LDY	#(KBWTR_DATA-WROCK_DATA+00000H)
		JMP	BG_KBWTR_S
;
;
;
;
WGRASS_DATA	EQU	$
		WORD	UT0122,UT0128,UT0144,UT0141	;LEFT
		WORD	UT0123,UT0129,UT0145,UT0142	;CENTER
		WORD	UT0124,UT012A,UT0146,UT0143	;RIGHT
;
WLAND_DATA	EQU	$
		WORD	UT012B,UT0134
		WORD	UT012E,UT0137,UT0131,UT013A	;LEFT
		WORD	UT012C,UT0135
		WORD	UT012F,UT0138,UT0132,UT013B	;CENTER
		WORD	UT012D,UT0136
		WORD	UT0130,UT0139,UT0133,UT0140	;RIGHT
;
BLKSLM_DATA	EQU	$
		WORD	UT0181,UT0000
		WORD	UT0186,UT0000,UT018B,UT0000	;left
		WORD	UT0182,UT0000
		WORD	UT0187,UT0000,UT018C,UT0000	;center
		WORD	UT0183,UT0000
		WORD	UT0188,UT0000,UT018D,UT0000	;2nd right 1
		WORD	UT0184,UT0000
		WORD	UT0189,UT0000,UT018E,UT0000	;2nd right 2
		WORD	UT0185,UT0000
		WORD	UT018A,UT0000,UT018F,UT0000	;right
;
EAT_DATA	EQU	$
		WORD	UT1B00,UT0000			;left
		WORD	UT1B03,UT0000,UT1B06,UT0000
		WORD	UT1B01,UT0000			;center
		WORD	UT1B04,UT0000,UT1B07,UT0000
		WORD	UT1B02,UT0000			;right
		WORD	UT1B05,UT0000,UT1B08,UT0000
		WORD	UT1B0C,UT0000			;only 1 v_line
		WORD	UT1B0D,UT0000,UT1B0E,UT0000
;
;
;

		MEM8
		IDX16
BG_WGRASS_LOW	EQU	$
		M16
		STY	<WORK1A
		M8

		LDA	<XWIDE		;v_line = ...
		CMP	<XWIDECP	;  1st: BG_WGRSS_LOW100
		BEQ	BG_WGRSS_LOW100	; last: BG_WGRSS_LOW200
		DEC	A		;
		BEQ	BG_WGRSS_LOW200	;

		LDY	#(WGRASS_DATA-WGRASS_DATA+00008H)
		BRA	BG_WGRSS_LOW300

BG_WGRSS_LOW100	EQU	$
		LDY	#(WGRASS_DATA-WGRASS_DATA+00000H)
		BRA	BG_WGRSS_LOW300

BG_WGRSS_LOW200	EQU	$
		LDY	#(WGRASS_DATA-WGRASS_DATA+00010H)

BG_WGRSS_LOW300	EQU	$
BG_WLAND300	EQU	$
BG_BLKSLM_S	EQU	$
BG_EAT_S	EQU	$

		M16
		LDA	<WORK1A		;H_line = ...
		BEQ	BG_WGRSS_LOW310	;  1st: BG_WGRSS_LOW310
		INC	A		; last: BG_WGRSS_LOW350
		CMP	<YWIDECP		;
		BEQ	BG_WGRSS_LOW350	;

		LDA	>BGUNIT,X	;BG = WATER ?
		AND	#0FF00H		;
		CMP	#UT1600		;
		BNE	BG_WGRSS_LOW400	; no:  BG_GRSS_LOW400
		BRA	BG_WGRSS_LOW390

BG_WGRSS_LOW310	EQU	$
		LDA	>BGUNIT,X	;BG = WATER ?
		AND	#0FF00H		;
		CMP	#UT1600		;
		BEQ	BG_WGRSS_LOW320	; yes: BG_GRSS_LOW320

		DEY
		DEY

BG_WGRSS_LOW320	EQU	$
		DEY
		DEY
		BRA	BG_WGRSS_LOW400

BG_WGRSS_LOW350	EQU	$
		LDA	>BGUNIT,X	;BG = WATER ?
		AND	#0FF00H		;
		CMP	#UT1600		;
		BNE	BG_WGRSS_LOW380	;  no: BG_GRSS_LOW380

		INY
		INY

BG_WGRSS_LOW380	EQU	$
		INY
		INY

BG_WGRSS_LOW390	EQU	$
		INY
		INY

BG_WGRSS_LOW400	EQU	$
		LDA	<WORK1A
		PHA
		LDA	WGRASS_DATA,Y
		PLY
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_WLAND	EQU	$
		M16
		STY	<WORK1A
		M8

		LDA	<XWIDE		;v_line = ...
		CMP	<XWIDECP	;  1st: BG_WLAND100
		BEQ	BG_WLAND100	; last: BG_WLAND200
		DEC	A		;
		BEQ	BG_WLAND200	;

		LDY	#(WLAND_DATA-WGRASS_DATA+00010H)
		BRA	BG_WLAND300

BG_WLAND100	EQU	$
		LDY	#(WLAND_DATA-WGRASS_DATA+00004H)
		BRA	BG_WLAND300

BG_WLAND200	EQU	$
		LDY	#(WLAND_DATA-WGRASS_DATA+0001CH)
		BRA	BG_WLAND300
;
		MEM8
		IDX16
BG_EAT		EQU	$
		M16
		STY	<WORK1A

		LDA	<YWIDECP	;h_line = only 1 line ?
		DEC	A		;
		BEQ	BG_EAT400	; yes: BG_EAT400

		M8

		LDA	<XWIDECP	;v_line = only 1 line ?
		DEC	A		;
		BEQ	BG_EAT300	; yes: BG_EAT300

		LDA	<XWIDE		;v_line = ...
		CMP	<XWIDECP	;  1st: BG_EAT100
		BEQ	BG_EAT100	; last: BG_EAT200
		DEC	A		;
		BEQ	BG_EAT200	;

		LDY	#(EAT_DATA-WGRASS_DATA+00010H)
		JMP	BG_EAT_S

BG_EAT100	EQU	$
		LDY	#(EAT_DATA-WGRASS_DATA+00004H)
		JMP	BG_EAT_S

BG_EAT200	EQU	$
		LDY	#(EAT_DATA-WGRASS_DATA+0001CH)
		JMP	BG_EAT_S

BG_EAT300	EQU	$
		LDY	#(EAT_DATA-WGRASS_DATA+00028H)
		JMP	BG_EAT_S

BG_EAT400	EQU	$
		M8
		LDA	<XWIDECP	;v_line = only 1 line ?
		DEC	A		;
		BEQ	BG_EAT500	; yes: BG_EAT500

		LDA	<XWIDE		;v_line = ...
		CMP	<XWIDECP	;  1st: BG_EAT410
		BEQ	BG_EAT410	;
		DEC	A		; last: BG_EAT420
		BEQ	BG_EAT420	;

		M16
		LDA	#UT1B0A
		BRA	BG_EAT430

BG_EAT410	EQU	$
		M16
		LDA	#UT1B09
		BRA	BG_EAT430

BG_EAT420	EQU	$
		M16
		LDA	#UT1B0B

BG_EAT430	EQU	$
		LDY	<WORK1A
		JMP	BG_TATE100

BG_EAT500	EQU	$
		M16
		LDA	#UT1B0F
		BRA	BG_EAT430
;
;
;
		MEM8
		IDX16
BG_BLKSLM	EQU	$
		M16
		STY	<WORK1A

		TYA			;last h_line ?
		INC	A		;
		CMP	<YWIDECP	;
		BEQ	BG_BLKSLM0003	; yes: BG_BLKSLM0003
		INC	A		;last 2 h_line ?
		CMP	<YWIDECP	;
		BNE	BG_BLKSLM0005	;  no: BG_BLKSLM0005

		M8
		LDA	<XWIDE		;1st v_line ?
		CMP	<XWIDECP	;
		BEQ	BG_BLKSLM0002	; yes: BG_BLKSLM0002

		M16
		LDA	#UT00D9
		BRA	BG_BLKSLM0004
BG_BLKSLM0002	EQU	$
		M16
		LDA	#UT00D6

BG_BLKSLM0004	EQU	$
		JSR	BLKSLM_SHADOW
		BRA	BG_BLKSLM0005

BG_BLKSLM0003	EQU	$
		M8
		LDA	<XWIDE		;last v_line ?
		DEC	A		;
		BNE	BG_BLKSLM0006	;  no: BG_BLKSLM0006

		M16
		LDA	#UT00DA
		JSR	KABEV_SHADOW
		M8

BG_BLKSLM0006	EQU	$

		JMP	BG_TATE200

BG_BLKSLM0005	EQU	$
		M8
		LDA	<XWIDE		;1st v_line ?
		CMP	<XWIDECP	;
		BEQ	BG_BLKSLM000	; yes: BG_BLKSLM000
		DEC	A		;last V_line ?
		BEQ	BG_BLKSLM010	; yes: BG_BLKSLM010
		DEC	A		;last 2 V_line ?
		BEQ	BG_BLKSLM020	; yes: BG_BLKSLM020
		
BG_BLKSLM0000	EQU	$
		LDY	#(BLKSLM_DATA-WGRASS_DATA+00010H)
		JMP	BG_BLKSLM_S

BG_BLKSLM000	EQU	$
		LDY	#(BLKSLM_DATA-WGRASS_DATA+00004H)
		JMP	BG_BLKSLM_S

BG_BLKSLM010	EQU	$
		M16
		TYA			;h_line = ...
		BEQ	BG_BLKSLM011	;        1st: BG_BLKSLM011

		LDA	#UT00D8
		BRA	BG_BLKSLM012

BG_BLKSLM011	EQU	$
		LDA	#UT00D7

BG_BLKSLM012	EQU	$
		JSR	KABEV_SHADOW
		M8
		LDY	#(BLKSLM_DATA-WGRASS_DATA+00034H)
		JMP	BG_BLKSLM_S

BG_BLKSLM020	EQU	$
		LDA	<XWIDECP	;V line sum. = 8 ?
		CMP	#00008H		; yes: BG_BLKSLM021
		BEQ	BG_BLKSLM021	;V line sum. = 4 ?
		CMP	#00004H		; yeS: BG_BLKSLM0000
		BEQ	BG_BLKSLM0000	;

		LDY	#(BLKSLM_DATA-WGRASS_DATA+0001CH)
		JMP	BG_BLKSLM_S

BG_BLKSLM021	EQU	$
		LDY	#(BLKSLM_DATA-WGRASS_DATA+00028H)
		JMP	BG_BLKSLM_S
;
;
;
;
;
;
		MEM8
		IDX16
BG_WGRASS1	EQU	$
		M16
		TYA			;V_line = ...
		BEQ	BG_WGRASS_1000	; last: BG_WGRASS_1000

		LDA	>BGUNIT,X	;BG = space ?
		BNE	BG_WGRASS_1010	;  no: BG_WGRASS_1010

		LDA	#UT0120
		JMP	BG_TATE100

BG_WGRASS_1010	EQU	$
		M8
		LDA	<XWIDE		;v_line = ...
		STA	<WORK18		;  1st: BG_WGRASS_1011
		CMP	<XWIDECP	; last: BG_WGRASS_1012
		BEQ	BG_WGRASS_1011	;
		DEC	A		;
		BEQ	BG_WGRASS_1012	;

		M16
		LDA	#UT0126
		JMP	BG_TATE100

BG_WGRASS_1011	EQU	$
		M16
		LDA	#UT0125
		JMP	BG_TATE100

BG_WGRASS_1012	EQU	$
		M16
		LDA	#UT0127
		JMP	BG_TATE100


BG_WGRASS_1000	EQU	$
		LDA	>BGUNIT,X	;BG = space ?
		BNE	BG_WGRASS_1020	;  no: BG_WGRASS_1020

		LDA	#UT0028
BG_WGRASS_1020	EQU	$
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_WGRASS2	EQU	$
		M16
		TYA			;V_line = ...
		BEQ	BG_WGRASS_2000	; last: BG_WGRASS_2000

		LDA	>BGUNIT,X	;BG = space ?
		BNE	BG_WGRASS_1010	;  no: BG_WGRASS_1010

		LDA	#UT0121
		JMP	BG_TATE100

BG_WGRASS_2000	EQU	$
		LDA	>BGUNIT,X	;BG = space ?
		BNE	BG_WGRASS_2020	;  no: BG_WGRASS_2020

		LDA	#UT0029
BG_WGRASS_2020	EQU	$
		JMP	BG_TATE100
;
;
		MEM8
		IDX16
BG_KABEH	EQU	$
		LDA	<XWIDECP	;block is only one ?
		CMP	#002H		;
		BNE	BG_KABEH0200	;  no: BG_KABEH0200

		CMP	<XWIDE		;set BG = shadow ?
		BEQ	BG_KABEH0100	;  no: BG_KABEH0100

BG_KABEH0050	EQU	$
		M16
		LDA	#UT00DA		;right under shadow
		JSR	KABEH_SHADOW

		LDA	>BGUNIT,X	;BG = kabe back ?
		CMP	#UT00D5		;
		BNE	BG_KABEH0080	;  no: BG_KABEH0080

		LDA	#UT00D7		;right top shadow
		JMP	BG_TATE100

BG_KABEH0080	EQU	$
		CMP	#UT00D6		;left edge shadow
		BEQ	BG_KABEH0090
		CMP	#UT00D9		;right side shadow
		BEQ	BG_KABEH0090
		CMP	#UT00DA		;right under shadow
		BEQ	BG_KABEH0091

		JMP	BG_TATE200

BG_KABEH0090	EQU	$
		LDA	#UT00E8
		JMP	BG_TATE100

BG_KABEH0091	EQU	$
		LDA	#UT00D8
		JMP	BG_TATE100

BG_KABEH0100	EQU	$
		M16
		LDA	#UT00D6		;left edge shadow
		JSR	KABEH_SHADOW

		LDA	#UT0163
		JMP	BG_TATE100

		MEM8
BG_KABEH0200	EQU	$
		LDA	<XWIDE		;v_line = ...
		CMP	<XWIDECP	;         1st: BG_KABEH0300
		BEQ	BG_KABEH0300	;        last: BG_KABEH0050
		DEC	A		; last 2 line: BG_KABEH0400
		BEQ	BG_KABEH0050	;
		DEC	A		;
		BEQ	BG_KABEH0400	;

		M16
		LDA	#UT00D9		;under side shadow
		JSR	KABEH_SHADOW

		LDA	#UT0161
		JMP	BG_TATE100

BG_KABEH0300	EQU	$
		M16
		LDA	#UT00D6		;left edge shadow
		JSR	KABEH_SHADOW

		LDA	#UT0160
		JMP	BG_TATE100

BG_KABEH0400	EQU	$
		M16
		LDA	#UT00D9		;under side shadow
		JSR	KABEH_SHADOW

		LDA	#UT0162
		JMP	BG_TATE100

;
		MEM8
		IDX16
BG_KABEV	EQU	$
		M16
		LDA	#UT00D8		;right side shadow
		JSR	KABEV_SHADOW

		TYA			;H_line = last 2 lines ?
		SEC			; yes: BG_KABEV0200 
		SBC	<YWIDECP	;
		INC	A		;
		INC	A		;
		BPL	BG_KABEV0200	;

		TYA			;H_line = ...
		BIT	#00001H		;  1st:
		BNE	BG_KABEV0100	;  2nd: BG_KABEV0100

BG_KABEV0050	EQU	$
		LDA	#UT00C9
		JMP	BG_TATE100

BG_KABEV0100	EQU	$
		LDA	#UT00CB
		JMP	BG_TATE100

BG_KABEV0200	EQU	$
					;H_line = last line ?
		BNE	BG_KABEV0300	; yes: BG_KABEV0300

		LDA	#UT00CC
		JMP	BG_TATE100

BG_KABEV0300	EQU	$
		LDA	#UT00CD
		JMP	BG_TATE100

;
		MEM8
		IDX16
BG_KABEV2	EQU	$
		M16
		TYA			;V_line = ...
		BEQ	BG_KABEV2010	;        1st: BG_KABEV2010
		INC	A		;
		CMP	<YWIDECP		;
		BEQ	BG_KABEV2020	;       last: BG_KABEV2020
		INC	A		;
		CMP	<YWIDECP		; last 2line: BG_KABEV2030
		BEQ	BG_KABEV2030	;

		LDA	#UT00D8		;right side shadow
		JSR	KABEV_SHADOW
		LDA	#UT00CA
		JMP	BG_TATE100

BG_KABEV2010	EQU	$
		LDA	#UT00D7		;right top shadow
		JSR	KABEV_SHADOW
		BRA	BG_KABEV0050

BG_KABEV2020	EQU	$
		LDA	#UT00DA		;right under shadow
		JSR	KABEV_SHADOW

		LDA	#UT00D6		;left edge shadow
		JSR	KAGEV_SHADOW2
		LDA	>BGUNIT,X
		JMP	BG_TATE100

BG_KABEV2030	EQU	$
		LDA	#UT00D8		;right side shadow
		JSR	KABEV_SHADOW
		BRA	BG_KABEV0100

;
		MEM16
		IDX16
KABEH_SHADOW	EQU	$

		PHX
		PHY

		PHA

		TXA
		CLC
		ADC	#020H
		TAX

		JSR	LOW3_CHECK
		MEM16
		IDX16

		LDA	LKFLG		;set lock ?
		BEQ	KABE_SHADOW	;  no: KABE_SHADOW

		PLA
		PLY
		PLX
		RTS

KABE_SHADOW	EQU	$
		LDA	>BGUNIT,X	;BG = ...
		CMP	#UT00D5		; space kabe: KABEH_SHADOW010
		BEQ	KABEH_SHADOW010	;

		PLY
		CPY	#UT00D6		;left edge shadow
		BEQ	KABEH_SHADOW070

		CPY	#UT00D7		;right top shadow
		BEQ	KABEH_SHADOW080

		CPY	#UT00D8		;right side shadow
		BEQ	KABEH_SHADOW090

		CPY	#UT00D9		;under side shadow
		BEQ	KABEH_SHADOW0A0

		CPY	#UT00DA		;right under shadow ?
		BEQ	KABEH_SHADOW0B0	; yes: KABEH_SHADOW070

KABEH_SHADOW001	EQU	$
					;BG = ...
		CMP	#UT0167		;       one yuka block: KABEH_SHADOW020
		BEQ	KABEH_SHADOW020	;   left of yuka block: KABEH_SHADOW030
		CMP	#UT0168		;  right of yuka block: KABEH_SHADOW040
		BEQ	KABEH_SHADOW030	;
		CMP	#UT0169		;
		BEQ	KABEH_SHADOW040	;

		BRA	KABEH_SHADOW060

KABEH_SHADOW010	EQU	$
		PLA
		BRA	KABEH_SHADOW050


KABEH_SHADOW020	EQU	$

		LDA	#UT0165
		BRA	KABEH_SHADOW050

KABEH_SHADOW030	EQU	$

		LDA	#UT0166
		BRA	KABEH_SHADOW050

KABEH_SHADOW040	EQU	$

		LDA	#UT0164

KABEH_SHADOW050	EQU	$
		STA	>BGUNIT,X

KABEH_SHADOW060	EQU	$

		PLY
		PLX

		RTS
;
KABEH_SHADOW070	EQU	$
		CMP	#UT00DA		;right under shadow
		BEQ	KABEH_SHADOW0E0

KABEH_SHADOW0A0	EQU	$
		CMP	#UT00D7		;right top shadow
		BEQ	KABEH_SHADOW0C0
		CMP	#UT00D8		;right side shadow
		BEQ	KABEH_SHADOW0C0

		BRA	KABEH_SHADOW001

KABEH_SHADOW080	EQU	$
KABEH_SHADOW090	EQU	$
		CMP	#UT00D6		;left edge shadow
		BEQ	KABEH_SHADOW0C0
		CMP	#UT00D9		;right side shadow
		BEQ	KABEH_SHADOW0C0
		CMP	#UT00DA		;right under shadow
		BEQ	KABEH_SHADOW0D0

		BRA	 KABEH_SHADOW0B8

KABEH_SHADOW0B0	EQU	$
		CMP	#UT00D6		;left edge shadow
		BEQ	KABEH_SHADOW0E0
		CMP	#UT00D7		;right top shadow
		BEQ	KABEH_SHADOW0D0

KABEH_SHADOW0B8	EQU	$
		PLY
		PLX

		RTS


KABEH_SHADOW0C0	EQU	$
		PLY

		LDA	#UT00E8
		BRA	KABEH_SHADOW100

KABEH_SHADOW0D0	EQU	$
		PLY

		LDA	#UT00D8
		BRA	KABEH_SHADOW100

KABEH_SHADOW0E0	EQU	$
		PLY

		LDA	#UT00D9

KABEH_SHADOW100	EQU	$
		STA	>BGUNIT,X

		PLX
		RTS
;
		MEM16
		IDX16
BLKSLM_SHADOW	EQU	$

		PHX
		PHY

		PHA

		TXA
		CLC
		ADC	#020H
		TAX

		JSR	LOW3_CHECK
		MEM16
		IDX16

		LDA	LKFLG		;set lock ?
		BEQ	BLKSLM_SHADOW05	;  no: BLKSLM_SHADOW05

		PLA
		BRA	BLKSLM_SHADOW20

BLKSLM_SHADOW05	EQU	$
		LDA	>BGUNIT,X	;BG = ...
		CMP	#UT00D5		; space kabe: BLKSLM_SHADOW10
		BEQ	BLKSLM_SHADOW10	;

		PLY
		CPY	#UT00D6		;left edge shadow
		BEQ	BLKSLM_SHADOW30

		CPY	#UT00D7		;right top shadow
		BEQ	KABEH_SHADOW080

		CPY	#UT00D8		;right side shadow
		BEQ	KABEH_SHADOW090

		CPY	#UT00D9		;under side shadow
		BEQ	BLKSLM_SHADOW40

		CPY	#UT00DA		;right under shadow ?
		BEQ	KABEH_SHADOW0B0	; yes: KABEH_SHADOW070

		BRA	BLKSLM_SHADOW20

BLKSLM_SHADOW10	EQU	$
		PLA
		STA	>BGUNIT,X

BLKSLM_SHADOW20	EQU	$
		PLY
		PLX

		RTS

BLKSLM_SHADOW30	EQU	$
		CMP	#UT00DA		;right under shadow
		BEQ	KABEH_SHADOW0E0

BLKSLM_SHADOW40	EQU	$
		CMP	#UT00D7		;right upper shadow
		BEQ	KABEH_SHADOW0C0
		CMP	#UT00D8		;right side shadow
		BEQ	KABEH_SHADOW0C0

		BRA	BLKSLM_SHADOW20
;
;
;
		MEM8
		IDX16
KAGEV_SHADOW2	EQU	$
		PHX
		PHY
		PHA

		MI16

		LDA	>BGUNIT,X	;BG = ...
		CMP	#UT00D5		; space kabe: KABEV_SHADOW000
		BNE	KABEV_SHADOW000	;

		JMP	KABEH_SHADOW010	;
;
KABEV_SHADOW000	EQU	$
		PLY
		CMP	#UT00D7		;left edge shadow
		BEQ	KABEH_SHADOW0C0
		CMP	#UT00D8		;under side shadow
		BEQ	KABEV_SHADOW001
		CMP	#UT00DA		;right under shadow
		BEQ	KABEH_SHADOW0E0

		JMP	KABEH_SHADOW0B8

KABEV_SHADOW001	EQU	$
		JMP	KABEH_SHADOW0C0
;
		MEM16
		IDX16
KABEV_SHADOW	EQU	$

		PHX
		PHY
		INX
		INX
		PHA
		LDA	<BGBFPT
		PHA

		JSR	RIGHT2_CHECK
		MEM16
		IDX16

		LDA	LKFLG		;set lock ?
		BEQ	KABEV_SHADOW05	;  no: KABEV_SHADOW05

		PLA
		BRA	KABEV_SHADOW005

KABEV_SHADOW05	EQU	$
		PLA
		CMP	<BGBFPT
		BEQ	KABEV_SHADOW010

		MI8
		LDA	<WORK1D		;BGUNIT pointer get
		CLC
		ADC	<WORKC
		TAX
		LDA	#000H
		STA	>UNBUFAD,X

		DEC	<BGBFPT		;buffer use pointer dec.

KABEV_SHADOW005	EQU	$
		MI16
		PLA
		PLY
		PLX

		RTS

		MEM16
KABEV_SHADOW010	EQU	$
		JMP	KABE_SHADOW
;
;
;
;
;
		MEM8
		IDX16
BG_WINDOW	EQU	$
		LDA	<XWIDE		;1st v_line ?
		CMP	<XWIDECP	; yes: BG_WINDOW0200
		BEQ	BG_WINDOW0200	;

		TYA			;H_line = 1st line ?
		BNE	BG_WINDOW0100	;  no: BG_WINDOW0100

		M16
		LDA	#UT00E0
		JMP	BG_TATE100

BG_WINDOW0100	EQU	$
		M16
		LDA	#UT00E2
		JMP	BG_TATE100

BG_WINDOW0200	EQU	$
		TYA			;H_line = 1st line ?
		BNE	BG_WINDOW0300	;  no: BG_WINDOW0300

		M16
		LDA	#UT00DB
		JMP	BG_TATE100

BG_WINDOW0300	EQU	$
		M16
		LDA	#UT00E1
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_POST		EQU	$
		LDA	<XWIDE		;1st v_line ?
		CMP	<XWIDECP	; yes: BG_POST0200
		BEQ	BG_POST0200	;

		M16
		LDA	#UT00E7
		JMP	BG_TATE100

BG_POST0200	EQU	$
		M16
		LDA	#UT00E6
		JMP	BG_TATE100
;
		MEM8
		IDX16
BG_DOOR		EQU	$
		LDA	<XWIDE		;1st v_line ?
		CMP	<XWIDECP	; yes: BG_DOOR0300
		BEQ	BG_DOOR0300	;

		M16

		TYA			;1st h_line ?
		BEQ	BG_DOOR0100	; yes: BG_DOOR0100

		INY
		CPY	<YWIDECP	;last h_line ?
		BEQ	BG_DOOR0200	; yes: BG_DOOR0200

		DEY

		LDA	RUT1803
		JMP	BG_TATE100

BG_DOOR0100	EQU	$
		LDA	RUT1801
		JMP	BG_TATE100

BG_DOOR0200	EQU	$
		DEY
		LDA	RUT1805
		JMP	BG_TATE100

BG_DOOR0300	EQU	$
		M16

		TYA			;1st h_line ?
		BEQ	BG_DOOR0400	; yes: BG_DOOR0400

		INY
		CPY	<YWIDECP	;last h_line ?
		BEQ	BG_DOOR0500	; yes: BG_DOOR0500

		DEY

		LDA	RUT1802
		JMP	BG_TATE100

BG_DOOR0400	EQU	$
		LDA	RUT1800
		JMP	BG_TATE100

BG_DOOR0500	EQU	$
		DEY
		LDA	RUT1804
		JMP	BG_TATE100
;
;
;
;
;
;
;
;
;		CHARACTER  DATA  READERS(EXCEPTANCIES)
;
;
;

		MEM16
		IDX16
BGYUKA_ELL	EQU	$
		JSR	LEFT_CHECK	;left BG = space ?
		MEM16			; yes: BGYUKA_ELLRR0
		IDX16			;
		PHP
		LDA	LKFLG		;set lock ?
		BEQ	BGYUKA_ELL1	;  no: BGYUKA_ELL1

		PLP
		BRA	BGYUKA_ELLRR0

BGYUKA_ELL1	EQU	$
		PLP
		BEQ	BGYUKA_ELLRR0	;

		LDA	RUT3B00
		STA	>BGUNIT,X

		TXA
		CLC
		ADC	#020H
		TAX

		JSR	LOW2_CHECK
		MEM16
		IDX16

		LDA	LKFLG		;set lock ?
		BNE	BGYUKA_ELLRR0	; yes: BGYUKA_ELLRR0

		LDA	RUT3B02
BGYUKA_ELLRR	EQU	$
		STA	>BGUNIT,X
BGYUKA_ELLRR0	EQU	$
		MI8

		RTL
;
		MEM16
		IDX16
BGYUKA_ERR	EQU	$
		JSR	RIGHT_CHECK	;right BG = space ?
		MEM16			; yes: BGYUKA_ELLRR0
		IDX16			;
		PHP
		LDA	LKFLG
		BEQ	BGYUKA_ERR1

		PLP
		BRA	BGYUKA_ELLRR0

BGYUKA_ERR1	EQU	$
		PLP
		BEQ	BGYUKA_ELLRR0	;

		LDA	RUT3B01
		STA	>BGUNIT,X

		TXA
		CLC
		ADC	#020H
		TAX

		JSR	LOW2_CHECK
		MEM16
		IDX16

		LDA	LKFLG		;set lock ?
		BNE	BGYUKA_ELLRR0	; yes: BGYUKA_ELLRR0

		LDA	RUT3B03
		BRA	BGYUKA_ELLRR
;
		MEM16
		IDX16
BG_WGRASS_ELL	EQU	$
		JSR	LEFT_CHECK	;left BG = space ?
		MEM16			; yes: BG_WGRASS_ELR
		IDX16			;
		PHP
		LDA	LKFLG		;set lock ?
		BEQ	BG_WGRASS_ELL1	;  no: BG_WGRASS_ELL1

		PLP
		BRA	BG_WGRASS_ELR

BG_WGRASS_ELL1	EQU	$
		PLP
		BEQ	BG_WGRASS_ELR	;

		LDA	>BGUNIT,X
		BNE	BG_WGRASS_ELR

		LDA	#UT0027
		STA	>BGUNIT,X

		TXA
		CLC
		ADC	#020H
		TAX

		JSR	LOW_CHECK
		MEM16
		IDX16

		LDA	LKFLG		;set lock ?
		BNE	BG_WGRASS_ELR	; yes: BG_WGRASS_ELR

		LDA	#UT0026
BG_WGRASS_ELLRR	EQU	$
		STA	>BGUNIT,X

BG_WGRASS_ELR	EQU	$
		M8

		RTS
;
		MEM16
		IDX16
BG_WGRASS_ERR	EQU	$
		LDA	>BGUNIT,X
		BNE	BG_WGRASS_ELR

		LDA	#UT002A
		STA	>BGUNIT,X

		TXA
		CLC
		ADC	#020H
		TAX

		JSR	LOW_CHECK
		MEM16
		IDX16

		LDA	LKFLG			;set lock ?
		BNE	BG_WGRASS_ELR		; yes: BG_WGRASS_ELR

BG_WGRASS_ERR1	EQU	$
		LDA	#UT002B
		BRA	BG_WGRASS_ELLRR
;
;
;
;
;
;
;
;
;
;
;
;
;
;		CHARACTER  CHANGE  ROUTINES
;
;
;
;
		IDX16
BG_CHANGE	EQU	$
		PHX

		LDA	<WORK1
		STA	<WORK0

		M16

		LDA	<YWIDECP		; DATA Y SUMARY : NORMAL DATA SUMARY
		CMP	<NDATSUM		;
		BEQ	BG_CHANGE010	; =
		BCS	BG_CHANGE015	; <

BG_CHANGE010	EQU	$

		JMP	BG_CHANGE300	; <=
BG_CHANGE015	EQU	$

		PHA

		LDA	<NDATSUM
		CMP	#00001H
		BEQ	BG_CHANGE020

		DEC	<YWIDECP

BG_CHANGE020	EQU	$
		LDA	<WORK0
		PHA

		MI8

		LDA	<WORK5
		PHA

		LDA	<WORK1D
		PHA

		JSR	GET_RPOINT		;X_POS & Y_POS SHUUSEI
		LDA	<YWIDECP			;
		STA	<WORK5			;
		JSR	GET_RPOINT_Y		;

		LDA	<WORK10
		PHA
		STZ	<WORK10

		JSR	UNPT_GET
		MEM16
		IDX16

		M8

		PLA
		STA	<WORK10

		PLA
		STA	<WORK1D

		PLA
		STA	<WORK5

		M16

		PLA
		STA	<WORK0

		LDA	>BGUNIT,X
		CMP	RUT3912
		BEQ	BG_CHANGE100
		CMP	RUT3913
		BEQ	BG_CHANGE100


		CMP	RUT1000		;10110f13
		BEQ	BG_CHANGE110
		CMP	RUT0E00		;0c0e0d12
		BEQ	BG_CHANGE110
		CMP	RUT0900
		BEQ	BG_CHANGE110
		CMP	RUT0B00
		BEQ	BG_CHANGE110
		CMP	RUT0700
		BEQ	BG_CHANGE110
		CMP	RUT0400
		BNE	BG_CHANGE200

BG_CHANGE110	EQU	$
		INC	<WORK1		; NORMAL DATA SUMMARY CHOUSEI

BG_CHANGE100	EQU	$

		TXA
		SEC
		SBC	#00020H
		TAX

;		JSR	HIGH_CHECK
;		MEM16
;		IDX16

		M8
		LDA	<WORK1		;
		STA	<NDATSUM		; NORMAL DATA SUMMARY
		STA	<YWIDECP		;
		STZ	<WORK15		;

		STZ	<WORK1

		M16
		LDA	<WORK0
		PHA

		LDY	#0000H

		JSR	BG_TATE_NXT
		MEM16
		IDX16

		PLA
		STA	<WORK0

		PLA
		SEC
		SBC	<WORK0
		STA	<YWIDECP
		BRA	BG_CHANGE300
BG_CHANGE200	EQU	$
		PLA
		STA	<YWIDECP
BG_CHANGE300	EQU	$
		PLX
		RTS
;
		MEM8
		IDX16
AROUND_CHK_L	EQU	$
		M16
		PHX
		DEX
		DEX
		LDA	>BGUNIT,X
		CMP	RUT390B
		BEQ	A_CHK_L200
		CMP	RUT3914
		BEQ	A_CHK_L100
		CMP	RUT3915
		BNE	A_CHK_LR300
A_CHK_L100	EQU	$
		LDA	RUT3917
		BRA	A_CHK_LR250
A_CHK_L200	EQU	$
		LDA	RUT3908
		BRA	A_CHK_LR250
;
		MEM8
		IDX16
AROUND_CHK_R	EQU	$
		M16
		PHX
		INX
		INX
		LDA	>BGUNIT,X
		CMP	RUT390C
		BEQ	A_CHK_R200
		CMP	RUT3914
		BEQ	A_CHK_R100
		CMP	RUT3915
		BNE	A_CHK_LR300
A_CHK_R100	EQU	$
		LDA	RUT3916
		BRA	A_CHK_LR250
A_CHK_R200	EQU	$
		LDA	RUT3907
A_CHK_LR250	EQU	$
		STA	>BGUNIT,X
A_CHK_LR300	EQU	$
		PLX
		M8
		RTS
;
;
;
;
;
;		RANDOM  MAKER
;
;
;
;
		MEM8
		IDX16
RND_RND		EQU	$
		LDA	>2137H
		STA	<WORK0
		LDA	>213CH
		STA	<WORK1
		LDA	>213DH
		CLC
		ADC	<WORK0
		ROR	<WORK1
		LDA	<WORK1
		RTS		
;
;
;
;		POINTER GET ROUTINE (BGUNIT)
;
;
		MEM8
UNPT_GET2	EQU	$
		M16
		LDA	#00001H
		STA	<WORK0
		LDA	#002H
UNPT_GET20	EQU	$
		M8
		STA	<WORK1A
		I16

;		LDX	<BGDTPT
		LDY	<BGDTPT

;		LDA	>DTBUFF,X
		LDA	[<BGDTADR],Y
		CLC
		ADC	<WORK1A
		STA	<YWIDECP
		STZ	<WORK13

		M16
		INC	<BGDTPT
		M8

		LDA	<WORK0
		BEQ	UNPT_GET4
		BIT	#001H
		BNE	UNPT_GET

		M16
		LDA	#00020H
		BRA	UNPT_GET5

UNPT_GET	EQU	$
		M16
		LDA	#00010H
UNPT_GET5	EQU	$
		STA	<WORK0
UNPT_GET3	EQU	$
		M8
UNPT_GET4	EQU	$
		STZ	<WORKC
		INC	<XWIDE		;x_wide revise

		LDA	<WORK0
		STA	<WORK1B

		LDA	<WORK1E
		SEC
		SBC	<WORK0
		ASL	A
		STA	<WORK0

		BCC	UNPT_GET100	;SET POINTER CHOUSEI ?
					; NO  UNPT_GET100
		INC	<WORK1

		LDA	<WORK1E		;SCREEN OVER ?
		AND	#0F0H		;
;		BNE	UNPT_GET100	; NO  UNPT_GET100
		BEQ	UNPT_GET050	; YES UNPT_GET050

		LDA	<WORK1A		;RIGHT SLOPE ?
		CMP	#003H		;
		BNE	UNPT_GET100	; NO  UNPT_GET100

		LDA	<WORK0		;SCREEN OVER ?
		CMP	<WORK8		;
		BCC	UNPT_GET100	; NO  UNPT_GET100

UNPT_GET050	EQU	$
		LDA	<WORK1D
		SEC
		SBC	#010H
		STA	<WORK1D

UNPT_GET100	EQU	$
		JMP	CHECK_PT
;
;
;
;		SCREEN  POINT CHECKER
;
;
;
		MEM16
		IDX16
HIGH_CHECK	EQU	$
		STZ	LKFLG		;set lock flag clear

		TXA
		BIT	#00100H		;SCREEN OVER ?
		BEQ	LW2_CHK200	; NO LW2_CHK200
					;
		AND	#001FFH		;
		STA	<WORK0		;
					;
		M8			;
		CMP	<WORK8		;
		BCC	LW2_CHK100	; NO LW2_CHK100

		LDA	<WORK1D		;field over ?
		AND	#0F0H		;
		BNE	HG_CHK400	;  no: HG_CHK400

		INC	LKFLG		;set lock flag set
		MI16
		RTS

		MEM8
HG_CHK400	EQU	$
		LDA	#0F0H
		JMP	LR_CHECK
;
		MEM16
		IDX16
HIGH3_CHECK	EQU	$
		STZ	LKFLG		;set lock flag clear

		TXA
		BIT	#00100H		;SCREEN OVER ?
		BEQ	LW2_CHK200	; NO LW2_CHK200
					;
		AND	#001FFH		;
		STA	<WORK0		;
					;
		M8			;
		CMP	#0E0H		;
		BCC	LW3_CHK100	; NO LW3_CHK100

		LDA	<WORK1D		;field over ?
		AND	#0F0H		;
		BNE	HG3_CHK400	;  no: HG3_CHK400

		INC	LKFLG		;set lock flag set
		MI16
		RTS

		MEM8
HG3_CHK400	EQU	$

		LDA	#0F0H
		BRA	LW3_CHK080
;
;
;
		MEM16
		IDX16
LOW_CHECK	EQU	$
		STZ	LKFLG		;set lock flag clear

		TXA
		BIT	#00100H		;SCREEN OVER ?
		BNE	LW2_CHK200	; NO LW2_CHK200
					;
		AND	#001FFH		;
		STA	<WORK0		;
					;
		M8			;
		CMP	<WORK8		;
		BCS	LW2_CHK100	; NO LW2_CHK100
LW_CHK300	EQU	$
		LDA	<WORK1D		;field over ?
		AND	#0F0H		;
		CMP	#0F0H		;
		BNE	LW_CHK400	;  no: LW_CHK400

		INC	LKFLG		;set lock flag set
		M16
		RTS

		MEM8
LW_CHK400	EQU	$
		LDA	#010H
		JMP	LR_CHECK
;
		MEM16
		IDX16
LOW2_CHECK	EQU	$
		STZ	LKFLG		;set lock flag clear

		TXA
		BIT	#00100H		;SCREEN OVER ?
		BNE	LW2_CHK200	; NO LW2_CHK200
					;
		AND	#001FFH		;
		STA	<WORK0		;
					;
		M8			;
		CMP	#020H		;
		BCC	LW_CHK300	; YES LW_CHK300

LW2_CHK100	EQU	$
		M16
LW2_CHK200	EQU	$
		RTS
;
		MEM16
		IDX16
LOW3_CHECK	EQU	$
		STZ	LKFLG		;set lock flag clear

		TXA
		BIT	#00100H		;SCREEN OVER ?
		BNE	LW3_CHK200	; NO LW3_CHK200
					;
		AND	#001FFH		;
		STA	<WORK0		;
					;
		M8			;
		CMP	#020H		;
		BCS	LW3_CHK100	; NO LW3_CHK100

		LDA	<WORK1D		;field over ?
		AND	#0F0H		;
		CMP	#0F0H		;
		BNE	LW3_CHK010	;  no: LW3_CHK010

		INC	LKFLG		;set lock flag set
		M16
		RTS

		MEM8
LW3_CHK010	EQU	$


		LDA	#010H

LW3_CHK080	EQU	$
		JSR	LR2_CHECK

LW3_CHK100	EQU	$
		M16
LW3_CHK200	EQU	$
		RTS
;
		MEM16
		IDX16
LEFT_CHECK	EQU	$
		STZ	LKFLG		;set lock flag clear

		LDA	<WORK1D		;FIRST LINE ?
		AND	#0000FH		;
		BNE	LEFT_CHECK0	; NO  LEFT_CHECK0

		LDA	<WORK1E		;FIRST LINE ?
		AND	#0000FH		;
		BEQ	LR_CHK200	; YES LR_CHK200

LEFT_CHECK0	EQU	$
		TXA
		AND	#0001EH
		CMP	#0001EH
		BNE	LR_CHK100

		TXA
		
		AND	#001FFH
		CLC
		ADC	#00020H		; ATENTION!!
		STA	<WORK0

		M8
		LDA	<WORK1D		;field over ?
		AND	#00FH		;
		BNE	L_CHK		;  no: L_CHK

		INC	LKFLG		;set lock flag set
		MI16
		RTS

		MEM8
L_CHK		EQU	$

		LDA	#0FEH
		TRB	<WORK1

		LDA	#0FFH		; left
		BRA	LR_CHECK
;
		MEM16
		IDX16
RIGHT_CHECK	EQU	$
		STZ	LKFLG		;set lock flag clear

		LDA	<WORK1D		; LAST LINE ?
		INC	A		;
		AND	#0000FH		;
		BNE	RIGHT_CHECK0	; NO  RIGHT_CHECK0

		LDA	<WORK1E		; LAST LINE ?
		INC	A		;
		AND	#0000FH		;
		BEQ	LR_CHK200	; YES LR_CHK200

RIGHT_CHECK0	EQU	$
		TXA
		BIT	#0001FH
		BNE	LR_CHK100

		AND	#001FFH
		CLC
		ADC	#001E0H		; atention!!
		STA	<WORK0

		M8
		LDA	<WORK1D		;field over ?
		AND	#00FH		;
		CMP	#00FH		;
		BNE	R_CHK		;  no:R2_CHK

		INC	LKFLG		;set lock flag set
		MI16
		RTS

		MEM8
R_CHK		EQU	$
		LDA	#0FEH
		TRB	<WORK1

		LDA	#001H		; right
LR_CHECK	EQU	$
		STA	<WORKC

		JSR	CHECK_PT
		MEM16
		IDX16

		M8
		LDA	<WORK1D
		CLC
		ADC	<WORKC
		STA	<WORK1D

LR_CHK100	EQU	$
		M16
		LDA	#00001H
		RTS

LR_CHK200	EQU	$
		M16
		LDA	#00000H
		RTS
;
		MEM16
		IDX16
LEFT2_CHECK	EQU	$
		STZ	LKFLG		;set lock flag clear

		TXA
		AND	#0001EH
		CMP	#0001EH
		BNE	LR_CHK100

		TXA
		
		AND	#001FFH
		CLC
		ADC	#00020H		; ATENTION!!
		STA	<WORK0

		M8
		LDA	<WORK1D		;field over ?
		AND	#00FH		;
		BNE	L2_CHK		;  no: L2_CHK

		INC	LKFLG		;set lock flag set
		MI16
		RTS

		MEM8
L2_CHK		EQU	$
		LDA	#0FEH
		TRB	<WORK1

		LDA	#0FFH		; left
		BRA	LR2_CHECK
;
		MEM16
		IDX16
RIGHT2_CHECK	EQU	$
		STZ	LKFLG		;set lock flag clear

		TXA
		BIT	#0001FH
		BNE	LR_CHK100

		AND	#001FFH
		CLC
		ADC	#001E0H		; atention!!
		STA	<WORK0

		M8
		LDA	<WORK1D		;field over ?
		AND	#00FH		;
		CMP	#00FH		;
		BNE	R2_CHK		;  no:R2_CHK

		INC	LKFLG		;set lock flag set
		MI16
		RTS

		MEM8
R2_CHK		EQU	$
		LDA	#0FEH
		TRB	<WORK1

		LDA	#001H		; right
LR2_CHECK	EQU	$
		STA	<WORKC

		JSR	CHECK_PT2
		MEM16
		IDX16

LR2_CHK100	EQU	$
		M16
		RTS
;
		MEM8
		IDX16
CHECK_PT	EQU	$

		I8
		LDA	<WORK1D		;BGUNIT pointer get
		CLC
		ADC	<WORKC
		TAX

		LDA	>UNBUFAD,X	;SCREEN IS USED ?
		BNE	CHECK_PT12	; YES CHECK_PT12

CHECK_PT11	EQU	$
		INC	<BGBFPT		; POINTER INC
		LDA	<BGBFPT
		STA	>UNBUFAD,X
CHECK_PT12	EQU	$
		ASL	A
		CLC
		ADC	<WORK1
		STA	<WORK1

		MI16
		LDA	<WORK0
		TAX
		
		RTS
;
		MEM8
		IDX16
CHECK_PT2	EQU	$

		I8
		LDA	<WORK1D		;BGUNIT pointer get
		CLC
		ADC	<WORKC
		TAX

		LDA	>UNBUFAD,X	
		BEQ	CHECK_PT11
		BRA	CHECK_PT12
;
;
;********************************************************
;*							*
;*	a-na sa-ka right down 30 set			*
;*							*
;********************************************************
		MEM8
		IDX8
BGSUB_ANARD30	EQU	$
		M16			; memory 16bit mode
		LDA	#BG_ANARD30_1	; routine address set
		STA	<ROUTNR1
		LDA	#BG_ANARD30_2
		STA	<ROUTNR2
		STA	<ROUTRND
		LDA	#00002H
		STA	<WORKE
		LDA	#00020H
		STA	<WORK8
		LDA	#0FFF0H
		STA	<NDATSUM
		STZ	<WORK16
		JSR	UNPT_GET2
		JMP	BGSUB_TATEYOKO4
;
;
;
		IDX16
BG_ANARD30_1	EQU	$
		M16			; memory 16bit mode
		STZ	<WORK16
		LDA	<WORKA
		PHA
		PHY
		TYA
		BEQ	ANARD3000
		DEC	A
		BEQ	ANARD3010
		JMP	ANADWST
;
;
BG_ANARD30_2	EQU	$
		M16			; memory 16bit mode
		LDA	#00001H
		STA	<WORK16
		LDA	<WORKA
		PHA
		PHY
		TYA
		BEQ	ANARD3000
		DEC	A
		BEQ	ANARD3010
		JMP	ANADWST
;
ANARD3000	EQU	$
		M8			; memory 8bit mode
		JSR	KSGSCHK		; ki-su-u & gu-u-su-u check
		M16			; memory 16bit mode
		AND	#00001H
		ASL	A
		ASL	A
		TAY
		BRA	ANARD3050
;
ANARD3010	EQU	$
		M8			; memory 8bit mode
		JSR	KSGSCHK		; ki-su-u & gu-u-su-u check
		M16			; memory 16bit mode
		AND	#00001H
		ASL	A
		STA	<WORKA
		TYA
		CLC
		ADC	<WORKA
		ASL	A
		TAY
ANARD3050	EQU	$
		LDA	ANADTRD30,Y
		JMP	ANADTST		; goto a-na data set
;
ANADTRD30	EQU	$
		WORD	UT4400,UT4600,UT4500,UT4700
;
;
;********************************************************
;*							*
;*	a-na sa-ka right down 45 set			*
;*							*
;********************************************************
		MEM8
		IDX8
BGSUB_ANARD45	EQU	$
		M16			; memory 16bit mode
;
		LDA	#BG_ANARD45	; routine address set
		STA	<ROUTNR1
		STA	<ROUTNR2
		STA	<ROUTRND
		LDA	#00002H
		STA	<WORKE
		LDA	#00020H
		STA	<WORK8
		LDA	#0FFF0H
		STA	<NDATSUM
		JSR	UNPT_GET2
		JMP	BGSUB_TATEYOKO4
;
;
;
		IDX16
BG_ANARD45	EQU	$
		M16			; memory 16bit mode
		LDA	#00001H
		STA	<WORK16
		LDA	<WORKA
		PHA
		PHY
		TYA
		BEQ	ANARD4500
		DEC	A
		BEQ	ANARD4510
		JMP	ANADWST
;
ANARD4500	EQU	$
		LDA	#UT5000
		JMP	ANADTST
;
ANARD4510	EQU	$
		LDA	#UT5100
		JMP	ANADTST
;
;
;********************************************************
;*							*
;*	a-na sa-ka right down 60 set			*
;*							*
;********************************************************
		MEM8
		IDX8
BGSUB_ANARD60	EQU	$
		M16			; memory 16bit mode
		LDA	#BG_ANARD60	; routine address set
		STA	<ROUTNR1
		STA	<ROUTNR2
		STA	<ROUTRND
		LDA	#00002H
		STA	<WORKE
		LDA	#00040H
		STA	<WORK8
		LDA	#0FFF0H
		STA	<NDATSUM
		LDA	#00001H
		STA	<WORK16
		JSR	UNPT_GET2
		JMP	BGSUB_TATEYOKO4
;
;
;
		IDX16
BG_ANARD60	EQU	$
		M16			; memory 16bit mode
		LDA	#00001H
		STA	<WORK16
		LDA	<WORKA
		PHA
		PHY
		TYA
		BEQ	ANARD6000
		DEC	A
		BEQ	ANARD6010
		DEC	A
		BEQ	ANARD6020
		JMP	ANADWST
;
ANARD6000	EQU	$
		LDA	#UT4B00
		JMP	ANADTST
;
ANARD6010	EQU	$
		LDA	#UT4C00
		JMP	ANADTST
;
ANARD6020	EQU	$
		LDA	#UT4D00
		JMP	ANADTST
;
;
;********************************************************
;*							*
;*	a-na sa-ka right up 30 set			*
;*							*
;********************************************************
		MEM8
		IDX8
BGSUB_ANARU30	EQU	$
		M16			; memory 16bit mode
;
		LDA	#BG_ANARU30_1	; routine address set
		STA	<ROUTNR1
		LDA	#BG_ANARU30_2
		STA	<ROUTNR2
		STA	<ROUTRND
		LDA	#00002H
		STA	<WORKE
		LDA	#0FFE0H
		STA	<WORK8
		STA	<NDATSUM
		STZ	<WORK16
		LDA	#00003H
		JSR	UNPT_GET20
		JMP	BGSUB_TATEYOKO4
;
;
;
		IDX16
BG_ANARU30_1	EQU	$
		M16			; memory 16bit mode
		STZ	<WORK16
		LDA	<WORKA
		PHA
		PHY
		TYA
		BEQ	ANARU3000
		DEC	A
		BEQ	ANARU3010
		JMP	ANADWST
;
;
BG_ANARU30_2	EQU	$
		M16			; memory 16bit mode
		LDA	#00001H
		STA	<WORK16
		LDA	<WORKA
		PHA
		PHY
		TYA
		BEQ	ANARU3000
		DEC	A
		BEQ	ANARU3010
		JMP	ANADWST
;
ANARU3000	EQU	$
		M8			; memory 8bit mode
		JSR	KSGSCHK		; ki-su-u & gu-u-su-u check
		M16			; memory 16bit mode
		AND	#00001H
		ASL	A
		ASL	A
		TAY
		BRA	ANARU3050
;
ANARU3010	EQU	$
		M8			; memory 8bit mode
		JSR	KSGSCHK		; ki-su-u & gu-u-su-u check
		M16			; memory 16bit mode
		AND	#00001H
		ASL	A
		STA	<WORKA
		TYA
		CLC
		ADC	<WORKA
		ASL	A
		TAY
ANARU3050	EQU	$
		LDA	ANADTRU30,Y
		JMP	ANADTST		; goto a-na data set
;
ANADTRU30	EQU	$
		WORD	UT4000,UT4200,UT4100,UT4300
;
;
;********************************************************
;*							*
;*	a-na sa-ka right up 45 set			*
;*							*
;********************************************************
		MEM8
		IDX8
BGSUB_ANARU45	EQU	$
		M16			; memory 16bit mode
;
		LDA	#BG_ANARU45	; routine address set
		STA	<ROUTNR1
		STA	<ROUTNR2
		STA	<ROUTRND
		LDA	#00002H
		STA	<WORKE
		LDA	#0FFE0H
		STA	<WORK8
		STA	<NDATSUM
		LDA	#00001H
		STA	<WORK16
		LDA	#00002H
		JSR	UNPT_GET20
		JMP	BGSUB_TATEYOKO4
;
;
;
		IDX16
BG_ANARU45	EQU	$
		M16			; memory 16bit mode
		LDA	#00001H
		STA	<WORK16
		LDA	<WORKA
		PHA
		PHY
		TYA
		BEQ	ANARU4500
		DEC	A
		BEQ	ANARU4510
		JMP	ANADWST
;
ANARU4500	EQU	$
		LDA	#UT4E00
		JMP	ANADTST
;
ANARU4510	EQU	$
		LDA	#UT4F00
		JMP	ANADTST		; goto a-na data set
;
;
;********************************************************
;*							*
;*	a-na sa-ka right up 60 set			*
;*							*
;********************************************************
		MEM8
		IDX8
BGSUB_ANARU60	EQU	$
		M16			; memory 16bit mode
		LDA	#BG_ANARU60	; routine address set
		STA	<ROUTNR1
		STA	<ROUTNR2
		STA	<ROUTRND
		LDA	#00002H
		STA	<WORKE
		LDA	#0FFC0H
		STA	<WORK8
		STA	<NDATSUM
		LDA	#00001H
		STA	<WORK16
		LDA	#00003H
		JSR	UNPT_GET20
		JMP	BGSUB_TATEYOKO4
;
;
;
		IDX16
BG_ANARU60	EQU	$
		M16			; memory 16bit mode
		LDA	#00001H
		STA	<WORK16
		LDA	<WORKA
		PHA
		PHY
		TYA
		BEQ	ANARU6000
		DEC	A
		BEQ	ANARU6010
		DEC	A
		BEQ	ANARU6020
		JMP	ANADWST
;
ANARU6000	EQU	$
		LDA	#UT4800
		JMP	ANADTST
;
ANARU6010	EQU	$
		LDA	#UT4900
		JMP	ANADTST		; goto a-na data set
;
ANARU6020	EQU	$
		LDA	#UT4A00
		JMP	ANADTST		; goto a-na data set
;
;++++++++++++++++++++++++++++++++++++++++++++++++
;+	a-na data set				+
;++++++++++++++++++++++++++++++++++++++++++++++++
		MEM16
		IDX16
ANADWST		EQU	$
		JSR	ANASIDE		; a-na side check
		PLY
		PLA
		STA	<WORKA
		JMP	BG_FLOOR_RND	
;
;
ANADTST		EQU	$
		STA	>BGUNIT,X
		JSR	ANASIDE		; a-na side check
ANADT99		EQU	$
		PLY
		PLA
		STA	<WORKA
		JMP	BG_TATE200
;
;
;++++++++++++++++++++++++++++++++++++++++++++++++
;+	a-na side check				+
;++++++++++++++++++++++++++++++++++++++++++++++++
		MEM16
		IDX16
ANASIDE		EQU	$
		M8			; memory 8bit mode
		LDA	<XWIDE
		CMP	<XWIDECP	; 1st V-line ?
		BEQ	ANASD00		;	YES -> ANASD00
		DEC	A		; last V-line ?
		BEQ	ANASD50		;	YES -> ANASD50
		JMP	ANASD10		; goto ANASD10
;
ANASD50		EQU	$		; right check
		M16			; memory 16bit mode
		PHX
		LDA	>BGUNIT,X
		CMP	#UT4400		;
		BEQ	ANASD55		; right down character ?
		CMP	#UT4500		;	YES -> ANASD55
		BEQ	ANASD55		;
		CMP	#UT4B00		;
		BEQ	ANASD55		;
		CMP	#UT4C00		;
		BEQ	ANASD55		;
		CMP	#UT5000		;
		BEQ	ANASD55		;
		INX
		INX
		JSR	RIGHT2_CHECK
		LDA	>BGUNIT,X
		CMP	RUT1D13
		BEQ	ANASD53
		CMP	RUT1D0B
		BEQ	ANASD51
		CMP	RUT1D0C
		BNE	ANASD55
		LDA	RUT1D11
		BRA	ANASD54
ANASD51		EQU	$
		LDA	RUT1D0F
		BRA	ANASD54
ANASD53		EQU	$
		LDA	RUT1D0D
ANASD54		EQU	$
		STA	>BGUNIT,X
ANASD55		EQU	$
		PLX
		BRA	ANASD10
;
ANASD00		EQU	$		; left check
		M16			; memory 16bit mode
		PHX
		LDA	>BGUNIT,X
		CMP	#UT4000		;
		BEQ	ANASD05		; right up character ?
		CMP	#UT4100		;	YES -> ANASD05
		BEQ	ANASD05		;
		CMP	#UT4800		;
		BEQ	ANASD05		;
		CMP	#UT4900		;
		BEQ	ANASD05		;
		CMP	#UT4E00		;
		BEQ	ANASD05		;
		DEX
		DEX
		JSR	LEFT2_CHECK
		LDA	>BGUNIT,X
		CMP	RUT1D13
		BEQ	ANASD03
		CMP	RUT1D0B
		BEQ	ANASD01
		CMP	RUT1D0C
		BNE	ANASD05
		LDA	RUT1D12
		BRA	ANASD04
ANASD01		EQU	$
		LDA	RUT1D10
		BRA	ANASD04
ANASD03		EQU	$
		LDA	RUT1D0E
ANASD04		EQU	$
		STA	>BGUNIT,X
ANASD05		EQU	$
		PLX
ANASD10		EQU	$
		M16			; memory 16bit mode
		RTS
;
;
;++++++++++++++++++++++++++++++++++++++++++++++++
;+	ki-su-u & gu-u-su-u check		+
;+				out		+
;+				  A <- 0 or 1	+
;++++++++++++++++++++++++++++++++++++++++++++++++
		MEM8
		IDX16
KSGSCHK		EQU	$
		LDA	<XWIDECP
		SEC
		SBC	<XWIDE
		AND	#001H
		RTS
;
;
;********************************************************
;*							*
;*	over hang set					*
;*							*
;********************************************************
;
		MEM8
		IDX8
BGSUB_OVHANG	EQU	$
		M16			; memory 16bit mode
		LDA	#BG_OVHANG
		JSR	BGSUB_TATEYOKO
		JMP	BGSUB_TATEYOKO4
;
		MEM8
		IDX16
BG_OVHANG	EQU	$
		PHX
		PHY
		M8			; memory 8bit mode
		LDA	<XWIDE
		CMP	<XWIDECP	; 1st v_line ?
		BNE	OVHANG30	;	NO -> OVHANG30
;
		M16			; memory 16bit mode
		LDA	>BGUNIT,X
		AND	#0FF00H
		CMP	#UT3900
		BEQ	OVHANG00
		JMP	OVHANG90
OVHANG00	EQU	$		; left set
		LDY	#00000H
		DEX
		DEX
		JSR	LEFT2_CHECK	; left check
		LDA	>BGUNIT,X
		AND	#0FF00H
		CMP	#UT3900
		BEQ	OVHANG05
		CMP	RUT1D00
		BNE	OVHANG10
OVHANG05	EQU	$
		INY
		INY
		INY
		INY
OVHANG10	EQU	$
		LDA	OVHNGDT,Y	; left character
		PLY
		PHY
		BEQ	OVHANG15
		JSR	OVHNGSUB
OVHANG15	EQU	$
		JMP	OVHANG99
;
;
OVHANG30	EQU	$
		DEC	A		; last v_line ?
		BNE	OVHANG50	;	NO -> OVHANG50
		M16			; memory 16bit mode
		LDA	>BGUNIT,X
		AND	#0FF00H
		CMP	#UT3900
		BEQ	OVHANG33
		JMP	OVHANG90
OVHANG33	EQU	$		; right set
		LDY	#00006H
		INX
		INX
		JSR	RIGHT2_CHECK	; right check
		LDA	>BGUNIT,X
		AND	#0FF00H
		CMP	#UT3900
		BEQ	OVHANG35
		CMP	RUT1D00
		BNE	OVHANG40
OVHANG35	EQU	$
		DEY
		DEY
		DEY
		DEY
OVHANG40	EQU	$
		LDA	OVHNGDT,Y	; right character
		PLY
		PHY
		BEQ	OVHANG45
		JSR	OVHNGSUB
OVHANG45	EQU	$
		BRA	OVHANG99
;
;
OVHANG50	EQU	$
		M16			; memory 16bit mode
		TYA
		BEQ	OVHANG60
		JMP	OVHANG90
OVHANG60	EQU	$		; center set
		LDA	>BGUNIT,X
		CMP	RUT1D27
		BEQ	OVHANG99
		CMP	RUT1D28
		BEQ	OVHANG99
		CMP	RUT1D29
		BEQ	OVHANG99
		CMP	RUT1D11
		BEQ	OVHANG53
		CMP	RUT1D0C
		BEQ	OVHANG55
		CMP	RUT1D12
		BEQ	OVHANG58
;
		LDA	#UT3931
		BRA	OVHANG99
;
OVHANG53	EQU	$
		LDA	RUT1D27		; a-na left
		BRA	OVHANG99
OVHANG55	EQU	$
		LDA	RUT1D28		; a-na center
		BRA	OVHANG99
OVHANG58	EQU	$
		LDA	RUT1D29		; a-na right
		BRA	OVHANG99
;
OVHANG90	EQU	$
		PLY
		PLX
		I16			; index 16bit mode
		JMP	BG_TATE200
;
OVHANG99	EQU	$
		PLY
		PLX
		I16			; index 16bit mode
		JMP	BG_TATE100
;
;
		MEM16
		IDX16
OVHNGSUB	EQU	$
		STA	<XYCPBF
		CMP	#UT3932
		BEQ	OVHG000
		CMP	#UT3933
		BNE	OVHG900
OVHG000		EQU	$
		LDA	<WORK0
		PHA
		M8			; memory 8bit mode
		JSR	RND_RND
		M16			; memory 16bit mode
		AND	#00003H
		ASL	A
		TAY
		PLA
		STA	<WORK0
		LDA	<XYCPBF
		SEC
		SBC	#UT3932
		CLC
		ADC	OVHNGSB,Y
OVHG900		EQU	$
		RTS
		MEM8
		IDX8
;
OVHNGDT		EQU	$
		WORD	UT3930,UT3932,UT3933,UT3935
;			left data	right data
;
OVHNGSB		EQU	$
		WORD	UT3924,UT3926,UT3928,UT3924
;
;
;********************************************************
;*							*
;*	bleak block					*
;*							*
;********************************************************
		MEM8
		IDX8
BGSUB_BLKBG	EQU	$
		M16			; memory 16bit mode
;
		LDA	#BG_BLKBG	; SET ROUTINE ADR(NORMAL DATA ROUTINE)
		JSR	BGSUB_TATEYOKO
		JMP	BGSUB_TATEYOKO4
;
;
;
;
		IDX16
BG_BLKBG	EQU	$
		PHX
		PHY
		M16			; memory 16bit mode
		LDA	<WORKA
		PHA
		LDA	<WORKE
		PHA
		STX	<WORKA
;
		TXA			; up check & set
		SEC
		SBC	#00020H
		TAX
		JSR	HIGH3_CHECK
		LDA	#CHKCHG_DAT0
		STA	<WORKE
		JSR	BLKBK_CHKCHG
;
		LDA	<WORKA		; down check & set
		CLC
		ADC	#00020H
		TAX
		JSR	LOW3_CHECK
		LDA	#CHKCHG_DAT1
		STA	<WORKE
		JSR	BLKBK_CHKCHG
;
		LDX	<WORKA		; right check & set
		INX
		INX
		JSR	RIGHT2_CHECK
		LDA	#CHKCHG_DAT2
		STA	<WORKE
		JSR	BLKBK_CHKCHG
;
		LDX	<WORKA		; left check & set
		DEX
		DEX
		JSR	LEFT2_CHECK
		LDA	#CHKCHG_DAT3
		STA	<WORKE
		JSR	BLKBK_CHKCHG
;
		PLA
		STA	<WORKE
		PLA
		STA	<WORKA
		PLY
		PLX
		LDA	#UT0000
		JMP	BG_TATE100
;
;
;++++++++++++++++++++++++++++++++++++++++++++++++
;+						+
;+	bleak block unit check & change		+
;+						+
;++++++++++++++++++++++++++++++++++++++++++++++++
BLKBK_CHKCHG	EQU	$
		LDY	#00000H
		LDA	>BGUNIT,X
CHKCHG_LOP	EQU	$
		CMP	CHKCHG_DATA,Y
		BEQ	CHKCHG_SET
		INY
		INY
		CPY	#CHKCHG_DAT0-CHKCHG_DATA
		BCC	CHKCHG_LOP
		BRA	CHKCHG_END
;
CHKCHG_SET	EQU	$
		LDA	(<WORKE),Y
		CMP	#UT0000
		BEQ	CHKCHG_END
		STA	>BGUNIT,X
;
CHKCHG_END	EQU	$
		RTS
;
		MEM8
		IDX8
;
;
CHKCHG_DATA	EQU	$
		WORD	UT1B04,UT1B03,UT1B05,UT1B01
		WORD	UT1B07,UT1B0D,UT1B0A,UT1B08
		WORD	UT1B00,UT1B06,UT1B02,UT1B09
		WORD	UT1B0B,UT1B0E,UT1B0C,UT1B0F
;
CHKCHG_DAT0	EQU	$
		WORD	UT1B07,UT1B06,UT1B08,UT1B0A
		WORD	UT0000,UT1B0E,UT0000,UT0000
		WORD	UT1B09,UT0000,UT1B0B,UT0000
		WORD	UT0000,UT0000,UT1B0F
;
CHKCHG_DAT1	EQU	$
		WORD	UT1B01,UT1B00,UT1B02,UT0000
		WORD	UT1B0A,UT1B0C,UT0000,UT1B0B
		WORD	UT0000,UT1B09,UT0000,UT0000
		WORD	UT0000,UT1B0F
;
CHKCHG_DAT2	EQU	$
		WORD	UT1B03,UT0000,UT1B0D,UT1B00
		WORD	UT1B06,UT0000,UT1B09,UT1B0E
		WORD	UT0000,UT0000,UT1B0C,UT0000
		WORD	UT1B0F
;
CHKCHG_DAT3	EQU	$
		WORD	UT1B05,UT1B0D,UT0000,UT1B02
		WORD	UT1B08,UT0000,UT1B0B,UT0000
		WORD	UT1B0C,UT1B0E,UT0000,UT1B0F
;
;
;********************************************************
;*							*
;*	bleak block					*
;*							*
;********************************************************
		MEM8
		IDX8
BGSUB_KSETABG	EQU	$
		M16			; memory 16bit mode
;
		LDA	#BG_KSETABG	; routine address
		JSR	BGSUB_TATEYOKO
		JMP	BGSUB_TATEYOKO4
;
		IDX16
BG_KSETABG	EQU	$
		M16			; memory 16bit mode
		LDA	<WORK0
		PHA
		PHX
		PHY
		STY	<XYCPBF
;
		PHX
		LDY	#00000H		; character check !!
		LDA	>BGUNIT,X	;
		CMP	#UT0000		;
		BEQ	KSETA010	;
		INX			;
		INX			;
KSETA000	EQU	$		;
		CMP	(ETACMP,X)	;
		BEQ	KSETA010	;
		INX			;
		INX			;
		CPX	#ONESTDT-ETACMP	;
		BCC	KSETA000	;
;
KSETA010	EQU	$
		TXY
		PLX
		M8			; memory 8bit mode
		LDA	<XWIDECP
		DEC	A
		BNE	KSETA050
		LDA	<YWIDECP
		DEC	A
		BEQ	KSETA200	; goto 1 point set
		BRA	KSETA400	; goto v-line set
KSETA050	EQU	$
		LDA	<YWIDECP
		DEC	A
		BEQ	KSETA600	; goto h-line set
;
KSETA800	EQU	$
		M16			; memory 16bit mode
		JSR	BOXSET		; box type set
		BRA	KSETA999
;
KSETA200	EQU	$
		M16			; memory 16bit mode
		LDA	ONESTDT,Y	; 1 point set
		STA	<XYCPBF
		BRA	KSETA999
;
KSETA400	EQU	$
		M16			; memory 16bit mode
		JSR	VLINEST		; v-line set
		BRA	KSETA999
;
KSETA600	EQU	$
		M16			; memory 16bit mode
		JSR	HLINEST		; h-line set
;
KSETA999	EQU	$
		PLY
		PLX
		PLA
		STA	<WORK0
		LDA	(<XYCPBF)
		JMP	BG_TATE100
;
;
;++++++++++++++++++++++++++++++++++++++++++++++++
;+	v-line set				+
;++++++++++++++++++++++++++++++++++++++++++++++++
		MEM16
		IDX16
VLINEST		EQU	$
		LDA	<XYCPBF
		BEQ	VLINE00
		INC	A
		CMP	<YWIDECP
		BEQ	VLINE20
;					; center
		JSR	CROSCHK		; character cross check
		BIT	#00001H
		BEQ	VLINE005
		JSR	CRSCHNG		; cross change check
		LDA	<WORK0
		ASL	A
		TAX
		JMP	(VCENTER,X)	; goto box type up line
VLINE005	EQU	$
		LDA	VLINDT1,Y
		BRA	VLINE99
;
VLINE00		EQU	$		; up
		JSR	CROSCHK		; character cross check
		BIT	#00001H
		BEQ	VLINE05
		JSR	CRSCHNG		; cross change check
		LDA	<WORK0
		ASL	A
		TAX
		JMP	(VUP,X)		; goto box type up line
VLINE05		EQU	$
		LDA	VLINDT0,Y
		BRA	VLINE99
;
VLINE20		EQU	$		; down
		JSR	CROSCHK		; character cross check
		BIT	#00001H
		BEQ	VLINE25
		JSR	CRSCHNG		; cross change check
		LDA	<WORK0
		ASL	A
		TAX
		JMP	(VDOWN,X)	; goto box type left down
VLINE25		EQU	$
		LDA	VLINDT2,Y
VLINE99		EQU	$
		STA	<XYCPBF
		RTS
;
;
;++++++++++++++++++++++++++++++++++++++++++++++++
;+	h-line set				+
;++++++++++++++++++++++++++++++++++++++++++++++++
HLINEST		EQU	$
		M8			; memory 8bit mode
		LDA	<XWIDE
		CMP	<XWIDECP
		BEQ	HLINE00
		DEC	A
		BEQ	HLINE20
;
		M16			; memory 16bit mode
		JSR	CROSCHK		; character cross check
		BIT	#00001H
		BEQ	HLINE005
		JSR	CRSCHNG		; cross change check
		LDA	<WORK0
		ASL	A
		TAX
		JMP	(HCENTER,X)	; goto box type up line
HLINE005	EQU	$
		LDA	HLINDT1,Y	; center
		BRA	HLINE99
;
HLINE00		EQU	$
		M16			; memory 16bit mode
		JSR	CROSCHK		; character cross check
		BIT	#00001H
		BEQ	HLINE05
		JSR	CRSCHNG		; cross change check
		LDA	<WORK0
		ASL	A
		TAX
		JMP	(HRIGHT,X)	; goto box type up line
HLINE05		EQU	$
		LDA	HLINDT0,Y	; left side
		BRA	HLINE99
;
HLINE20		EQU	$
		M16			; memory 16bit mode
		JSR	CROSCHK		; character cross check
		BIT	#00001H
		BEQ	HLINE25
		JSR	CRSCHNG		; cross change check
		LDA	<WORK0
		ASL	A
		TAX
		JMP	(HLEFT,X)	; goto box type up line
HLINE25		EQU	$
		LDA	HLINDT2,Y	; right side
HLINE99		EQU	$
		STA	<XYCPBF
		RTS
;
;
;++++++++++++++++++++++++++++++++++++++++++++++++
;+	box type set				+
;++++++++++++++++++++++++++++++++++++++++++++++++
BOXSET		EQU	$
		M8			; memory 8bit mode
		LDA	<XWIDE
		CMP	<XWIDECP
		BNE	BOX000
		LDA	<XYCPBF
		BEQ	BOX100
		INC	A
		CMP	<YWIDECP
		BNE	BOX200
		BRA	BOX300
BOX000		EQU	$
		LDA	<XWIDE
		DEC	A
		BEQ	BOX010
		LDA	<XYCPBF
		BEQ	BOX400
		INC	A
		CMP	<YWIDECP
		BNE	BOX500
		JMP	BOX600
BOX010		EQU	$
		LDA	<XYCPBF
		BNE	BOX020
		JMP	BOX700
BOX020		EQU	$
		INC	A
		CMP	<YWIDECP
		BEQ	BOX030
		JMP	BOX800
BOX030		EQU	$
		JMP	BOX900
;
BOX100		EQU	$		; left up
		M16			; memory 16bit mode
		JSR	CROSCHK		; character cross check
		BIT	#00001H
		BEQ	BOX105
		JSR	CRSCHNG		; cross change check
		LDA	<WORK0
		ASL	A
		TAX
		JMP	(BOXLTUP,X)
BOX105		EQU	$
		LDA	BOXDAT0,Y
		JMP	BOX999
;
BOX200		EQU	$		; left side
		M16			; memory 16bit mode
		JSR	CROSCHK		; character cross check
		BIT	#00001H
		BEQ	BOX205
		JSR	CRSCHNG		; cross change check
		JMP	BOX505
BOX205		EQU	$
		LDA	BOXDAT1,Y
		JMP	BOX999
;
BOX300		EQU	$		; left down
		M16			; memory 16bit mode
		JSR	CROSCHK		; character cross check
		BIT	#00001H
		BEQ	BOX305
		JSR	CRSCHNG		; cross change check
		LDA	<WORK0
		ASL	A
		TAX
		JMP	(BOXLTDN,X)
BOX305		EQU	$
		LDA	BOXDAT2,Y
		JMP	BOX999
;
BOX400		EQU	$		; center up
		M16			; memory 16bit mode
		JSR	CROSCHK		; character cross check
		BIT	#00001H
		BEQ	BOX405
		JSR	CRSCHNG		; cross change check
		JMP	BOX505
BOX405		EQU	$
		LDA	BOXDAT3,Y
		JMP	BOX999
;
BOX500		EQU	$		; center
		M16			; memory 16bit mode
BOX505		EQU	$
		LDA	BOXDAT4,Y
		JMP	BOX999
;
BOX600		EQU	$		; center down
		M16			; memory 16bit mode
		JSR	CROSCHK		; character cross check
		BIT	#00001H
		BEQ	BOX605
		JSR	CRSCHNG		; cross change check
		JMP	BOX505
BOX605		EQU	$
		LDA	BOXDAT5,Y
		JMP	BOX999
;
BOX700		EQU	$		; right up
		M16			; memory 16bit mode
		JSR	CROSCHK		; character cross check
		BIT	#00001H
		BEQ	BOX705
		JSR	CRSCHNG		; cross change check
		LDA	<WORK0
		ASL	A
		TAX
		JMP	(BOXRTUP,X)
BOX705		EQU	$
		LDA	BOXDAT6,Y
		JMP	BOX999
;
BOX800		EQU	$		; right side
		M16			; memory 16bit mode
		JSR	CROSCHK		; character cross check
		BIT	#00001H
		BEQ	BOX805
		JSR	CRSCHNG		; cross change check
		JMP	BOX505
BOX805		EQU	$
		LDA	BOXDAT7,Y
		JMP	BOX999
;
BOX900		EQU	$		; right down
		M16			; memory 16bit mode
		JSR	CROSCHK		; character cross check
		BIT	#00001H
		BEQ	BOX905
		JSR	CRSCHNG		; cross change check
		LDA	<WORK0
		ASL	A
		TAX
		JMP	(BOXRTDN,X)
BOX905		EQU	$
		LDA	BOXDAT8,Y
;
BOX999		EQU	$
		STA	<XYCPBF
		RTS
;
;
;++++++++++++++++++++++++++++++++++++++++
;+	character cross check		+
;+			out		+
;+			ON  -> 1	+
;+			OFF -> 0	+
;++++++++++++++++++++++++++++++++++++++++
		MEM16
		IDX16
CROSCHK		EQU	$
		STZ	<WORK0
		LDA	>BGUNIT,X
		AND	#0FF00H
		CMP	#UT1B00
		BNE	CROSPSS
		INC	<WORK0
CROSPSS		EQU	$
		LDA	<WORK0
		RTS
;
;++++++++++++++++++++++++++++++++++++++++
;+	cross change check		+
;++++++++++++++++++++++++++++++++++++++++
CRSCHNG		EQU	$
		LDA	>BGUNIT,X
		PHX
		LDX	#00000H
CRSLOP		EQU	$
		CMP	(ONESTDT,X)	; unit NO. check !!
		BEQ	CRSPAS
		INX
		INX
		CPX	#BOXDAT9-ONESTDT
		BCC	CRSLOP
;
CRSPAS		EQU	$
		TXY
		PLX
		STZ	<WORK0
CRSPSS		EQU	$		; goto index set !!
		TYA
		CMP	#0002CH
		BCC	CRSEND
		SEC
		SBC	#0002CH
		TAY
		INC	<WORK0
		BRA	CRSPSS
CRSEND		EQU	$
		RTS
;
		MEM8
		IDX8
;
;
ETACMP		EQU	$
		WORD	        RUT1D13,RUT1D0D,RUT1D09,RUT1D0E,RUT1D00
		WORD	RUT1D0B,RUT1D02,RUT1D0C,RUT1D03,RUT1D0F,RUT1D06
		WORD	RUT1D10,RUT1D05,RUT1D11,RUT1D04,RUT1D12,RUT1D21
		WORD	RUT1D01,RUT1D20,RUT1D08,RUT1D07
;;K;;		WORD	UT2400,UT2401
;
ONESTDT		EQU	$
		WORD	RUT1B0F,RUT1B1F,RUT1B25,RUT1BB5,RUT1B35,RUT1B2C
		WORD	RUT1B47,RUT1BC7,RUT1B57,RUT1B3E,RUT1B63,RUT1BBD
		WORD	RUT1B68,RUT1BCD,RUT1B6D,RUT1BDD,RUT1B73,RUT1B79
		WORD	RUT1BD3,RUT1B81,RUT1B95,RUT1B4E
;
VLINDT0		EQU	$		; up side
		WORD	RUT1B0C,RUT1B1C,RUT1B21,RUT1BB1,RUT1B31,RUT1B2B
		WORD	RUT1B46,RUT1BC6,RUT1B00,RUT1B00,RUT1B61,RUT1BBB
		WORD	RUT1B66,RUT1BCB,RUT1B00,RUT1B00,RUT1B00,RUT1B00
		WORD	RUT1B00,RUT1B87,RUT1B91,RUT1B00
;
VLINDT1		EQU	$		; center
		WORD	RUT1B0D,RUT1B1D,RUT1B24,RUT1BB4,RUT1B34,RUT1B2D
		WORD	RUT1B00,RUT1B00,RUT1B00,RUT1B00,RUT1B00,RUT1B00
		WORD	RUT1B00,RUT1B00,RUT1B00,RUT1B00,RUT1B00,RUT1B00
		WORD	RUT1B00,RUT1B00,RUT1B94,RUT1B00
;
VLINDT2		EQU	$		; down side
		WORD	RUT1B0E,RUT1B1E,RUT1B27,RUT1BB7,RUT1B37,RUT1B2E
		WORD	RUT1B00,RUT1B00,RUT1B56,RUT1B00,RUT1B00,RUT1B00
		WORD	RUT1B00,RUT1B00,RUT1B6B,RUT1BDB,RUT1B71,RUT1B7D
		WORD	RUT1BD7,RUT1B86,RUT1B97,RUT1B4C
;
HLINDT0		EQU	$		; left side
		WORD	RUT1B09,RUT1B19,RUT1B22,RUT1BB2,RUT1B00,RUT1B00
		WORD	RUT1B43,RUT1BC3,RUT1B53,RUT1B3B,RUT1B62,RUT1BBC
		WORD	RUT1B00,RUT1B00,RUT1B6C,RUT1BDC,RUT1B00,RUT1B77
		WORD	RUT1BD1,RUT1B00,RUT1B00,RUT1B00
;
HLINDT1		EQU	$		; center
		WORD	RUT1B0A,RUT1B1A,RUT1B00,RUT1B00,RUT1B00,RUT1B00
		WORD	RUT1B44,RUT1BC4,RUT1B54,RUT1B3C,RUT1B00,RUT1B00
		WORD	RUT1B00,RUT1B00,RUT1B00,RUT1B00,RUT1B00,RUT1B7C
		WORD	RUT1BD6,RUT1B00,RUT1B00,RUT1B00
;
HLINDT2		EQU	$		; right side
		WORD	RUT1B0B,RUT1B1B,RUT1B00,RUT1B00,RUT1B32,RUT1B00
		WORD	RUT1B00,RUT1B00,RUT1B00,RUT1B3D,RUT1B00,RUT1B00
		WORD	RUT1B67,RUT1BCC,RUT1B00,RUT1B00,RUT1B72,RUT1B78
		WORD	RUT1BD2,RUT1B00,RUT1B92,RUT1B4D
;
BOXDAT0		EQU	$		; left up
		WORD	RUT1B00,RUT1B10,RUT1B20,RUT1BB0,RUT1B00,RUT1B00
		WORD	RUT1B40,RUT1BC0,RUT1B00,RUT1B00,RUT1B60,RUT1BBA
		WORD	RUT1B00,RUT1B00,RUT1B00,RUT1B00,RUT1B00,RUT1B00
		WORD	RUT1B00,RUT1B82,RUT1B00,RUT1B00
;
BOXDAT1		EQU	$		; left side
		WORD	RUT1B03,RUT1B13,RUT1B23,RUT1BB3,RUT1B00,RUT1B00
		WORD	RUT1B00,RUT1B00,RUT1B00,RUT1B00,RUT1B00,RUT1B00
		WORD	RUT1B00,RUT1B00,RUT1B00,RUT1B00,RUT1B00,RUT1B00
		WORD	RUT1B00,RUT1B84,RUT1B00,RUT1B00
;
BOXDAT2		EQU	$		; left down
		WORD	RUT1B06,RUT1B16,RUT1B26,RUT1BB7,RUT1B00,RUT1B00
		WORD	RUT1B00,RUT1B00,RUT1B50,RUT1B00,RUT1B00,RUT1B00
		WORD	RUT1B00,RUT1B00,RUT1B6A,RUT1BDA,RUT1B00,RUT1B7A
		WORD	RUT1BD4,RUT1B88,RUT1B00,RUT1B00
;
BOXDAT3		EQU	$		; center up
		WORD	RUT1B01,RUT1B11,RUT1B00,RUT1B00,RUT1B00,RUT1B00
		WORD	RUT1B41,RUT1BC1,RUT1B00,RUT1B00,RUT1B00,RUT1B00
		WORD	RUT1B00,RUT1B00,RUT1B00,RUT1B00,RUT1B00,RUT1B00
		WORD	RUT1B00,RUT1B8B,RUT1B00,RUT1B00
;
BOXDAT4		EQU	$		; center
		WORD	RUT1B04,RUT1B14,RUT1B00,RUT1B00,RUT1B00,RUT1B00
		WORD	RUT1B00,RUT1B00,RUT1B00,RUT1B00,RUT1B00,RUT1B00
		WORD	RUT1B00,RUT1B00,RUT1B00,RUT1B00,RUT1B00,RUT1B00
		WORD	RUT1B00,RUT1B80,RUT1B00,RUT1B00
;
BOXDAT5		EQU	$		; center down
		WORD	RUT1B07,RUT1B17,RUT1B00,RUT1B00,RUT1B00,RUT1B00
		WORD	RUT1B00,RUT1B00,RUT1B51,RUT1B00,RUT1B00,RUT1B00
		WORD	RUT1B00,RUT1B00,RUT1B00,RUT1B00,RUT1B00,RUT1B76
		WORD	RUT1BD0,RUT1B00,RUT1B00,RUT1B00
;
BOXDAT6		EQU	$		; right up
		WORD	RUT1B02,RUT1B12,RUT1B00,RUT1B00,RUT1B30,RUT1B00
		WORD	RUT1B42,RUT1BC2,RUT1B00,RUT1B00,RUT1B00,RUT1B00
		WORD	RUT1B65,RUT1BCA,RUT1B00,RUT1B00,RUT1B00,RUT1B00
		WORD	RUT1B00,RUT1B83,RUT1B90,RUT1B00
;
BOXDAT7		EQU	$		; right side
		WORD	RUT1B05,RUT1B15,RUT1B00,RUT1B00,RUT1B33,RUT1B00
		WORD	RUT1B00,RUT1B00,RUT1B00,RUT1B00,RUT1B00,RUT1B00
		WORD	RUT1B00,RUT1B00,RUT1B00,RUT1B00,RUT1B00,RUT1B7B
		WORD	RUT1BD5,RUT1B85,RUT1B93,RUT1B00
;
BOXDAT8		EQU	$		; right down
		WORD	RUT1B08,RUT1B18,RUT1B00,RUT1B00,RUT1B36,RUT1B00
		WORD	RUT1B00,RUT1B00,RUT1B52,RUT1B00,RUT1B00,RUT1B00
		WORD	RUT1B00,RUT1B00,RUT1B00,RUT1B00,RUT1B70,RUT1B7B
		WORD	RUT1BD5,RUT1B89,RUT1B96,RUT1B4B
;
BOXDAT9		EQU	$
;
VUP		EQU	$-8
		WORD	BOX105,BOX405,BOX705,BOX105
		WORD	BOX505,BOX205,BOX505,BOX505
		WORD	BOX505,BOX505,BOX505,BOX805
;
VCENTER		EQU	$-8
		WORD	BOX205,BOX505,BOX805,BOX205
		WORD	BOX205,BOX205
;
VDOWN		EQU	$-8
		WORD	BOX305,BOX605,BOX905,BOX205
		WORD	BOX505,BOX305,BOX505,BOX505
		WORD	BOX605,BOX805,BOX805,BOX905
;
HRIGHT		EQU	$-2
		WORD	       BOX105,BOX205,BOX305
		WORD	BOX505,BOX505,BOX505,BOX505
		WORD	BOX505,BOX505,BOX505,BOX505
		WORD	BOX505,BOX405,BOX505,BOX605
;
HCENTER		EQU	$-2
		WORD	       BOX405,BOX505,BOX605
;
HLEFT		EQU	$-2
		WORD	       BOX705,BOX805,BOX905
		WORD	BOX505,BOX505,BOX505,BOX405
		WORD	BOX505,BOX605
;
BOXLTUP		EQU	$-4
		WORD		      BOX205,BOX205
		WORD	BOX505,BOX505,BOX405,BOX505
		WORD	BOX505,BOX205,BOX505,BOX505
		WORD	BOX505,BOX405,BOX505,BOX505
;
BOXLTDN		EQU	$-2
		WORD	       BOX205,BOX205,BOX305
		WORD	BOX505,BOX505,BOX605,BOX205
		WORD	BOX505,BOX505,BOX505,BOX505
		WORD	BOX505,BOX505,BOX505,BOX605
;
BOXRTUP		EQU	$-6
		WORD			     BOX805
		WORD	BOX405,BOX505,BOX505,BOX405
		WORD	BOX505,BOX505,BOX505,BOX505
		WORD	BOX505,BOX505,BOX505,BOX805
;
BOXRTDN		EQU	$-2
		WORD	       BOX805,BOX505,BOX505
		WORD	BOX605,BOX505,BOX505,BOX505
		WORD	BOX505,BOX605,BOX505,BOX505
		WORD	BOX805
;
		MEM8
		IDX8
;
;
;
;
;
;
;
		END
