;
        	INCLUDE	zel_ram.asm
;
;--------------------------------------------------------------------
;
;		PAL_ZELDA-3 (FRANCE)		1991.09.28(SAT)
;
;--------------------------------------------------------------------
;
		ORG	1AF500H
;
;=============================================== (zel_enmy5) ===========
		GLB	PLCHKST,PLCHKMV,RYOKICS,RNTAMST,ASZNZST,GRITMCK
		GLB	BABA1CS,OOISUMV,BIGKOCS,R100,BABACK,ANAHOIT
		GLB	MTEST 
;========================================= (zel_char) =========
		EXT     spoj5,spoj0,prnc1
;=============================================== (zel_enmy4) ===========
		EXT	ENIDSH
;=============================================== (zel_enmy3) ===========
		EXT	ICEFLST,ENALFL,TKTAMST,ASMZST,ENPLATR,KEMRIST
;=============================================== (zel_enmy2) ===========
		EXT	EVCHCKE,ENXSDN,ENYSDN,ENMSG2L,ENMSGEL,ENMSGSL
		EXT	SETOAML,SETOAML2,ENMKIST,BSITEM,EFLCHK,ENMDST
		EXT	HEIS0CS2,ASIMZST,Z2TMSTL,SETOAML22,H0SER00L
;=============================================== (zel_enmy) ============
		EXT	EPXYCK2,EPXCHK2,EPYCHK2,PLFLSTL,PSSAVE2,PSERC2L,PKNCRS2
                EXT     EBAKU,EMOVE,RNDSET,BGDTRD2,ENDMST2,CROJCK2,ENCRST2,BIKRST2
		EXT	ENBGCKL,CRENPLL,CRKNKNL,CRKNENL,OCHECKL,ENCLER,ENMAINL
		EXT	ALOMCKL,SADWSTL,SADWS2L,CRENPL2L,OAMENT3,OAMENT1
		EXT	PSERCHL,EN1CSTL,ESERCHL,SSERCH2,CACHCKL,ENBDSBL
		EXT	ENENSET,EN1CSSL,OAMENT2,EFLSST,ENDMST3,ENDMST4,EHOLE,OAMCHKL
		EXT	CRENPL3L,MSGSET,BOMBST,EEXYCKL,ITGSDT,ENFLIS2,ENMVCLL
;--- enmyno --
		EXT	GAYK0,GAYK1,GAYK2,GAYK3,USAG0,HYUUU
		EXT	SKHED,SHTAM,HBTAM,BAAR0,BABUL,TEKI0,TEKI1,AMEBA,MDARM
		EXT	OCTA1,OCTA2,OCTA3,NYORO,OCTBL,OCTSS,CHFIR,BIGKO,TEKTA
		EXT	TARUH,TARUV,SKEL2,PATA0,PATA1,SDEMO,KAMBS,KAMBR,KAMBB
		EXT	KWAUS,KWAU1,SHIGE,SEKZ4,PONPK,EYEBS,EYETM,EYEBM
		EXT	REBA1,ZOOL1,ENMY4,NAMAZ,CTBOS,DOOMO
		EXT	JIJII,BABAA,HEITI,PENKI,NOKOG,KUTUU,GAKII,GAKI1
		EXT	NOPPO,ONNAA,HIGEE,MAJOO,JIJI2,KIANA,BUBUU
		EXT	YATAM,MURON,MURYA,MURMK,LINE0,LINE1,LINE2,LINE3,BABA1,ESW03,HEIS0
		EXT	TAIHO,HEIS1,HEYA0,HEYA1,HEYA2,KTOBJ,HEIS2,NEZU0,HEBI0
		EXT	KOMO0,HEBO0,OYAGI,ZAKO0,HEIS1,PLCHK
		EXT	HEIS3,SUNA0,USAG0,HEYA3,HANA0,HANA1,TAMA0,DOZOO
		EXT	BOUSI,SYOBY,HELP0,ESW12,RANEM,ZORAS,NOMOS,KINOK
		EXT	SUKAS,MJSY1,JITON,ESW04,ZORA2,MEDUS,UTUWA,ARI00,ARI01
		EXT	JOHBB,ENMY3,HACHI,POLIW,RINGO,BABU2,HELP1,BKFIR,HARI0,D_0_9
		EXT	MOTAM,MEMER,MAGIC,ICBOS,DOKN0,DOKN1,DOKN2,DOKN3,BEE00,ABATA
		EXT	SEKBN,TAKAR,BAKDN,SARKK,TEKBB,DARUM,IZUMI,GANON,GANO2
		EXT	WOOD1,IWAGO
;--------------
		EXT	HEIT1,RINEL
;-------------- item
                EXT     HART1,RUPYR,RUPYY,RUPYB,BOMB1,BOMB2,BOMB3 
                EXT     TUBO1,TUBO2,UTUBK
                EXT     YAAA1,YAAA2,YOSEI
;--------------
		EXT	HART1,PORT1,PORT2,ICTAM
		EXT	ESET0,ESET1,ESET2
		EXT	EFAIL,ECACH,EWATR,EICE,EICFL
;=============================================== (zel_endt) ============
									
		EXT	EXSTRA,ENEMY2,ENBTON,EFLCHK2,ENCLST,ENIDPS
		EXT	SINDT2,BADBRST
;=============================================== (zel_main) ============
;		EXT	DTSAVE
		EXT	TGBLKWT
		EXT	GDCHCK,JSRSUB,MGMCGRS2,MGMCGCNG
;
		EXT	MD_title,MD_djint,MD_djply,MD_gdint,MD_gdply
		EXT	MD_fdout,MD_fdin,MD_etcpl
		EXT	MD_wpout,MD_wpin
;=============================================== (zel_play) ============
		EXT 	DASCLR1,DASHON,PLOTCK
		EXT 	EATSET
		EXT 	YAMOV
		EXT	YAIMIT,ITMCBFST
		EXT	ATMSIT
		EXT	OMS000
		EXT	PLOTCK1
		EXT	WPMSCK
;///////		EXT	RDCHCK
;=============================================== (zel_bg3) =============
		EXT	MTRSUB,ITEM0ST,ICECGCNG,LAMPOFF0,LAMPOFF1
;=============================================== (grnd) =============
		EXT	MKDRPLY,PRMDHST
;=============================================== (zel_init) =============
		EXT	p3_msge,DJEXTCK,PLRSET,RESTTST,THCGCN0,THCGCN1,THCGCN2
		EXT	KMBBCG0,KMBRCG0
		EXT	KMBBCG1,KMBRCG1
;================================================(end2)=================
		EXT	GRNDCHK,KURORCS,SDLRCE,SDLRCP,MAGICCS,ICMANCS,TEKI0CS,SKEL2CS
		EXT	MGTAMCS,PBBANCS,PATA0CS,CRHCEN,LIKE0CS,ICBOSCS
		EXT	SDLRE1,SDLRE2,SDLRE3
;================================================(endt)=================
		EXT 	GRENST,EST0SB
;================================================(char)=================
		EXT 	OPTCBFST,PWTRCGS2
;================================================(bms1)=================
		EXT	PLKTINT
;================================================(exst)=================
                EXT     BEAM1,BEAM2,BUME1,BOMBM,YAMOV,DTMOV     ;;;;,BOMBR
                EXT     DTMV1,DTMV2,OPMOV,WTMV0,HIBA2,SCPMV,DTMV3
                EXT     RAOPIT,BOGN,KNSP,TPHDIT
		EXT	nashi,prnce,jjmov,jjwat,jjsmv,mesmv,babaa,bbwat
		EXT	kajya,hnoji
;================================================(POLYGON)=================
		GLB	OOTSUCK,OOTSUC2
;-----< obj_poly >-------------------------------------------------------

		extern		INITIAL_POLYGON

;------------------------------------------------------------------------
		extern		polygon_flag
		extern		shading_switch
		extern		object_size
		extern		object_type
		extern		rotate_angle_x
		extern		rotate_angle_y
		extern		center_point_x
		extern		center_point_y
		extern		center_point_z
		extern		stack_pointer
		extern		transfer_flag
;
;================================================(msge)=================
;---------------MSGE NO.-----------------
		EXT	MS_0490,MS_0491,MS_04D0,MS_04D1,MS_04D2,MS_04D3
		EXT	MS_0530,MS_0560,MS_0561,MS_05B7
		EXT	MS_0461,MS_0590,MS_05B0
		EXT	MS_00E0,MS_00E1,MS_00E2,MS_00E3,MS_00E4,MS_00E5
		EXT	MS_05F4,MS_05F5,MS_05F6,MS_05F7,MS_05F8
;
		EXTEND
		MEM8
		IDX8
		EXTEND
		MEM8
		IDX8
;
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;%	PLCHK move	                    		  %
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;---------------------------------------- BAT CHAR
PCHKC00		EQU	$
		WORD	00000,00000
		BYTE	04BH,004H,000H,000H
PCHKC01		EQU	$
		WORD	00005,-0004
		BYTE	05BH,004H,000H,000H
PCHKC10		EQU	$
		WORD	-0002,-0004
		BYTE	064H,004H,000H,002H
PCHKC11		EQU	$
		WORD	-0002,-0004
		BYTE	049H,004H,000H,002H
PCHKC20		EQU	$
		WORD	-0008,-0008-1
		BYTE	06CH,004H,000H,002H
		WORD	00008,-0008-1
		BYTE	06CH,044H,000H,002H
PCHKC21		EQU	$
		WORD	-0008,-0008+1
		BYTE	04CH,004H,000H,002H
		WORD	00008,-0008+1
		BYTE	04CH,044H,000H,002H
PCHKC30		EQU	$
		WORD	-0008,-0008-1
		BYTE	044H,004H,000H,002H
		WORD	00008,-0008-1
		BYTE	044H,044H,000H,002H
PCHKC31		EQU	$
		WORD	-0008,-0008
		BYTE	062H,004H,000H,002H
		WORD	00008,-0008
		BYTE	062H,044H,000H,002H
PCHKC32		EQU	$
		WORD	-0008,-0008+1
		BYTE	060H,004H,000H,002H
		WORD	00008,-0008+1
		BYTE	060H,044H,000H,002H
PCHKC40		EQU	$
		WORD	00000,00000
		BYTE	04EH,004H,000H,002H
		WORD	00016,00000
		BYTE	04EH,044H,000H,002H
		WORD	00000,00016
		BYTE	06EH,004H,000H,002H
		WORD	00016,00016
		BYTE	06EH,044H,000H,002H
;----------------------------------------BAT CHAR
;
;
PCK1SPX		EQU	$
		WORD	007DCH,007F0H,00820H,00818H
PCK1SPY		EQU	$
		WORD	0062EH,00636H,00630H,005E0H
;
BATCTIM		EQU	$
		BYTE	004,003,004,006,000
;
PLCHKMV		EQU	$
		PHB
		PHK
		PLB
		JSR	PLCHK_M
		PLB
		RTL
PLCHK_M		EQU	$
		LDA	ENCONT,X
		JSL	>JSRSUB
		WORD	PLCHKM0		;MIZU
		WORD	PLCHKM1		;BAT
;========================================
PLCHKM0		EQU	$
		JSR	ENSTCK		; scroll : not return !
;
		JSL	>CRENPL2L	;PL. BODY CHK
		BCC	PCKM010
		LDA	<MPDTNO
		CMP	#043H
		BEQ	PCKM020
		PHX
		JSL	>TPHDIT
		PLX
PCKM010		EQU	$
		RTS
PCKM020		EQU	$
		PHX			;END TOU 
		JSL	>PLKTINT
		PLX
;		STZ	ENMODE,X
		RTS
;========================================
PK1M0SX		EQU	$
PK1M0SY		EQU	$
;;		BYTE	1,-1
NZTLDT		EQU	$
		HEX	01,FF
		HEX	00,FF
;
PLCHKM1		EQU	$
		JSR	PLCHKCS
		JSR	ENSTCK		; scroll : not return !
		JSL	>ENMVCLL
;
		JSR	PLCHKKB		;CLS OBJ SET
;
		STZ	YUREYD
		STZ	YUREYD+1
;
		LDA	ENTUTM,X
		BEQ	PC1010
;
		DEC	A
		BNE	PC1008
;
		LDY	#05H
		STY	SOUND1	;(S) BGM ckear !
PC1008		EQU	$
		AND     #01H
                TAY
                LDA     NZTLDT,Y
                STA     YUREYD
                LDA     NZTLDT+2,Y
                STA     YUREYD+1
;
PC1010		EQU	$
		LDA	ENTIM0,X
		BNE	PCKM110
		LDA	ENCHPT,X
		INC	A
		AND	#003H
		STA	ENCHPT,X
		BNE	PCKM120
;
		LDA	ENSTAT,X
		CMP	#002H
		BCS	PCKM120
;
;;		JSL	>SDLRCE		;OTO
;;		ORA	#003H
;;		STA	SOUND2
		LDA	#03H
		JSL	>SDLRE2	;(S)
;
PCKM120		EQU	$
		LDY	ENMUKI,X
		LDA	BATCTIM,Y
		STA	ENTIM0,X
PCKM110		EQU	$
;
		LDA	ENSTAT,X
		JSL	>JSRSUB
		WORD	PCKM1M0
		WORD	PCKM1M1
		WORD	PCKM1M2
		WORD	PCKM1M3
;----------------------------------------
;
PCKM1M0		EQU	$
		LDA	ENWRK0,X	;SEACH POINT INDEX
		ASL	A
		TAY
		MEM16
		IDX8
		REP	#00100000B
		LDA	PCK1SPX,Y
		CMP	ENXP2L
		MEM8
		IDX8
		SEP	#00110000B
		BCS	PK1M010
		CPY	#002H*2
		BCC	PK1M020
		INC	ENSTAT,X	;NEXT MOVE
		LDA	#0D0H
		STA	ENTIM1,X
PK1M020		EQU	$
		INC	ENWRK0,X	;NEXT INDEX
		INC	ENMUKI,X
PK1M010		EQU	$
;
		LDA	<FRCNT
		AND	#007H
		BNE	PK1M050
		MEM16
		IDX8
		REP	#00100000B
		LDA	PCK1SPY,Y
		CMP	ENYP2L
		MEM8
		IDX8
		SEP	#00110000B
		BCC	PK1M040
		INC	ENYSPD,X
		BRA	PK1M050
PK1M040		EQU	$
		DEC	ENYSPD,X
PK1M050		EQU	$
;
		LDA	<FRCNT
		AND	#00FH
		BNE	PK1M030
		INC	ENXSPD,X	;SERCH SPEED
PK1M030		EQU	$
		RTS
;----------------------------------------
PCKM1M1		EQU	$
		LDA	ENTIM1,X
		BNE	PK1M110
		INC	ENSTAT,X
;;		JSL	>SDLRCE		;OTO
;;		ORA	#026H
;;		STA	SOUND3
		LDA	#26H
		JSL	>SDLRE3	;(S)
;
		INC	ENMUKI,X
;
		LDA	#0E8H
		STA	ENXPSL,X
		LDA	#007H
		STA	ENXPSH,X
;
		LDA	#0E0H
		STA	ENYPSL,X
		LDA	#005H
		STA	ENYPSH,X
;
		STZ	ENXSPD,X
		LDA	#040H
		STA	ENYSPD,X
;
		LDA	#02DH
		STA	ENTIM1,X
;
		RTS
;
PK1M110		EQU	$
		LDA	<FRCNT
		AND	#003H
		BNE	PK1M120
		DEC	ENXSPD,X
PK1M120		EQU	$
;
		LDA	ENWRK0,X	;SEACH POINT INDEX
		ASL	A
		TAY
		JMP	PK1M010
;----------------------------------------
PCKM1M2		EQU	$
		LDA	ENTIM1,X
		BNE	PK1M210
		STZ	ENYSPD,X
		LDA	#030H		;#060H
		STA	ENTIM1,X
		INC	ENSTAT,X
PK1M210		EQU	$
		LDA	ENTIM1,X
		CMP	#009H
		BNE	PK1M220
		JSR	PLCHKBK
		PHX
		JSL	>PRMDHST
		PLX
PK1M220		EQU	$
		RTS
;----------------------------------------
PCKM1M3		EQU	$
;		LDA	<KEYA2
;		BEQ	PK1M310
;		STZ	ENMODE,X
;		JSL	>PLCHKST
;		RTS
;
;
;
		LDA	ENTIM1,X
		BNE	PK1M310
		STZ	ENMODE,X
		INC	!MAPDMD
PK1M310		EQU	$
		RTS
;----------------------------------------
PLCHKST		EQU	$
		LDA	#PLCHK
		JSL	>ENIDSH
;
		LDA	#000H
		STA	ENYSPD,Y
		STA	ENWRK1,Y
		STA	ENMUKI,Y
		STA	ENKAIF,Y
		INC	A
		STA	ENCONT,Y
		STA	ENMOD0,Y
		STA	ENMOD2,Y
		STA	ENCLOR,Y
;
		LDA	#0CCH
		STA	ENXPSL,Y
		LDA	#007H
		STA	ENXPSH,Y
;
		LDA	#032H
		STA	ENYPSL,Y
		LDA	#006H
		STA	ENYPSH,Y
;
		LDA	#080H
		STA	ENMOD5,Y
;
		RTL
;
;----------------------------------------
PCKKBDT		EQU	$
		BYTE	068H,097H,057H,001H
		BYTE	078H,097H,057H,001H
		BYTE	088H,097H,057H,001H
		BYTE	068H,0A7H,057H,001H
		BYTE	078H,0A7H,057H,001H
		BYTE	088H,0A7H,057H,001H
		BYTE	065H,090H,057H,001H
		BYTE	08BH,090H,057H,001H
PCKKBKZ		EQU	8*4
PLCHKKB		EQU	$
		MEM16
		IDX8
		REP	#00100000B
;
		LDY	#PCKKBKZ
PCKKB10		EQU	$
		LDA	PCKKBDT-2,Y
		STA	OAM+130H-2,Y
		DEY
		DEY
		BNE	PCKKB10
;
		LDY	#((PCKKBKZ/4)/2)*2
		LDA	#00202H
PCKKB20		EQU	$
		STA	OAMSB+0130H/4,Y
		DEY
		DEY
		BPL	PCKKB20
;
		MEM8
		IDX8
		SEP	#00110000B
		RTS
;----------------------------------------
PCKBKXP		EQU	$
		BYTE	0F8H,000H,008H,010H,018H,020H
		BYTE	0F8H,000H,008H,010H,018H,020H
		BYTE	0F8H,000H,008H,010H,018H,020H
		BYTE	0F8H,000H,008H,010H,018H,020H
		BYTE	0F8H,000H,008H,010H,018H,020H
PCKBKYP		EQU	$
		BYTE	030H,030H,030H,030H,030H,030H
		BYTE	028H,028H,028H,028H,028H,028H
		BYTE	020H,020H,020H,020H,020H,020H
		BYTE	018H,018H,018H,018H,018H,018H
		BYTE	010H,010H,010H,010H,010H,010H
PCKBKXS		EQU	$
		BYTE	-030,-025,-008,0008,0025,0030
		BYTE	-050,-045,-020,0020,0045,0050
		BYTE	-050,-035,-025,0025,0035,0050
		BYTE	-045,-050,-060,0060,0050,0045
		BYTE	-030,-035,-040,0040,0035,0030
PCKBKYS		EQU	$
		BYTE	0002,0005,0010,0010,0005,0002
		BYTE	0005,0020,0030,0030,0020,0005
		BYTE	0010,0030,0040,0040,0030,0010
		BYTE	-020,-040,-060,-060,-040,-020
		BYTE	-010,-020,-040,-040,-020,-010
;
;
PLCHKBK		EQU	$
		LDY	#030-1
PCKBK10		EQU	$
		LDA	PCKBKXP,Y
		STA	<WORK0
		LDA	PCKBKYP,Y
		STA	<WORK1
		LDA	PCKBKXS,Y
		STA	<WORK2
		LDA	PCKBKYS,Y
		STA	<WORK3
		PHY
		JSL	>BADBRST
		PLY
		DEY
		BPL	PCKBK10
;
		LDA	#20H
		STA	ENTUTM,X
		RTS
;----------------------------------------
PLCHKAL		EQU	$
		BYTE	LOW  PCHKC00
		BYTE	LOW  PCHKC00
		BYTE	LOW  PCHKC01
		BYTE	LOW  PCHKC01
		BYTE	LOW  PCHKC10
		BYTE	LOW  PCHKC10
		BYTE	LOW  PCHKC11
		BYTE	LOW  PCHKC11
		BYTE	LOW  PCHKC20
		BYTE	LOW  PCHKC20
		BYTE	LOW  PCHKC21
		BYTE	LOW  PCHKC21
		BYTE	LOW  PCHKC30
		BYTE	LOW  PCHKC31
		BYTE	LOW  PCHKC32
		BYTE	LOW  PCHKC31
		BYTE	LOW  PCHKC40
		BYTE	LOW  PCHKC40
		BYTE	LOW  PCHKC40
		BYTE	LOW  PCHKC40
PLCHKAH		EQU	$
		BYTE	HIGH PCHKC00
;		BYTE	HIGH PCHKC00
;		BYTE	HIGH PCHKC01
;		BYTE	HIGH PCHKC01
;		BYTE	HIGH PCHKC10
;		BYTE	HIGH PCHKC10
;		BYTE	HIGH PCHKC11
;		BYTE	HIGH PCHKC11
;		BYTE	HIGH PCHKC20
;		BYTE	HIGH PCHKC20
;		BYTE	HIGH PCHKC21
;		BYTE	HIGH PCHKC21
;		BYTE	HIGH PCHKC30
;		BYTE	HIGH PCHKC31
;		BYTE	HIGH PCHKC32
;		BYTE	HIGH PCHKC31
;		BYTE	HIGH PCHKC40
;		BYTE	HIGH PCHKC40
;		BYTE	HIGH PCHKC40
;		BYTE	HIGH PCHKC40
;
;
PLCHKKZ		EQU	$
		BYTE	001,001,001,001
		BYTE	001,001,001,001
		BYTE	002,002,002,002
		BYTE	002,002,002,002
		BYTE	004,004,004,004
;
;
PLCHKCS		EQU	$
		MEM16
		REP	#20H
		LDA	#OAM+160H
		STA	<OAMADR
		LDA	#OAMSB+160H/4
		STA	<OSBADR
		MEM8
		SEP	#20H
;
		LDA	ENMUKI,X
		ASL	A
		ASL	A
		ADC	ENCHPT,X
		TAY			;CHAR NO.
;
		LDA	PLCHKAL,Y
		STA	<WORK8
		LDA	PLCHKAH		;PLCHKAH,Y
		STA	<WORK9
;
		LDA	PLCHKKZ,Y	;KAZU
;;		STA	<WORK6
;;		STZ	<WORK7
;
		JSL	>SETOAML22
		RTS
;========================================
;========================================
RYOKICD		EQU	$
		WORD	00008,00002
		BYTE	0AEH,000H,000H,000H
		WORD	00000,-0009
		BYTE	022H,008H,000H,002H
		WORD	00000,00000
		BYTE	006H,000H,000H,002H
;
		WORD	00007,00000
		BYTE	0AFH,000H,000H,000H
		WORD	00000,-0009
		BYTE	022H,008H,000H,002H
		WORD	00000,00000
		BYTE	006H,000H,000H,002H
;
RYOKICS		EQU	$
		PHB
		PHK
		PLB
		LDA	ENCHPT,X
		ASL	A
		ADC	ENCHPT,X
		ASL	A
		ASL	A
		ASL	A
		ADC	#LOW  RYOKICD
		STA	<WORK8
		LDA	#HIGH RYOKICD
		ADC	#000H
		STA	<WORK9
;
		LDA	#003H
		STA	<WORK6
		STZ	<WORK7
;
		JMP	SETOSW
;;		JSL	>SETOAML
;;		JSL	>SADWSTL
;;		PLB
;;		RTL
;========================================
BABA1CD		EQU	$
		WORD	00000,-0008		;0
		BYTE	0E0H,000H,000H,002H
		WORD	00000,00000
		BYTE	0E8H,000H,000H,002H
		WORD	00000,-0007
		BYTE	0E0H,000H,000H,002H
		WORD	00000,00001
		BYTE	0E8H,040H,000H,002H
;
		WORD	00000,-0008		;1
		BYTE	0C0H,000H,000H,002H
		WORD	00000,00000
		BYTE	0C2H,000H,000H,002H
		WORD	00000,-0007
		BYTE	0C0H,000H,000H,002H
		WORD	00000,00001
		BYTE	0C2H,040H,000H,002H
;
		WORD	00000,-0008		;2
		BYTE	0E2H,000H,000H,002H
		WORD	00000,00000
		BYTE	0E4H,000H,000H,002H
		WORD	00000,-0007
		BYTE	0E2H,000H,000H,002H
		WORD	00000,00001
		BYTE	0E6H,000H,000H,002H
;
		WORD	00000,-0008		;3
		BYTE	0E2H,040H,000H,002H
		WORD	00000,00000
		BYTE	0E4H,040H,000H,002H
		WORD	00000,-0007
		BYTE	0E2H,040H,000H,002H
		WORD	00000,00001
		BYTE	0E6H,040H,000H,002H
;
BABA1CS		EQU	$
		PHB
		PHK
		PLB
		LDA	#002H
		STA	<WORK6
		STZ	<WORK7
;
		LDA	ENMUKI,X
		ASL	A
		ADC	ENCHPT,X
		ASL	A
		ASL	A
		ASL	A
		ASL	A
		ADC	#LOW BABA1CD
		STA	<WORK8
		LDA	#HIGH BABA1CD
		ADC	#000H
		STA	<WORK9
;
SETOSW		EQU	$
		JSL	>SETOAML
;
		JSL	>SADWSTL
		PLB
		RTL
;===========================================
ENSTCK		EQU	$
		LDA	ENMODE,X
		CMP	#EMOVE
		BNE	ESTC08
ENSTCK2		EQU	$
;;		JSR	PLHNCK		; player hani flag set 
;
		LDA	ENSTFG
		BNE	ESTC08		; enemy all stop !
;
		LDA	<GAMEMD
		BNE	ESTC08
;
		LDA	ENMOD5,X
		BMI	ESTC10
;
		LDA	ENDSPL,X
		BEQ	ESTC10		; game stop ?
;
ESTC08		EQU	$
		PLA			; yes ! don't sub return 
		PLA
ESTC10		EQU	$
		RTS
;======================================================
RISTYS		EQU	$
		HEX	1C,E4,1C,E4
		HEX	00,24,00,DC
;LL		HEX	F0,F4  ;;,00,0C,10,0C,00,F4
RISTXS		EQU	$
		HEX	E4,E4,1C,1C
		HEX	DC,00,24,00
;LL		HEX	00,0C,10,0C,00,F4,F0,F4
;
RNTAMST		EQU	$
;;		AND	#07H
;;		BNE	RNTS10 
;
		LDY	#03H
		LDA	ENMODE+0
		CLC
		ADC	ENMODE+1
		ADC	ENMODE+2
		CMP	#09H+1
		BCS	RTS008	; Last 1 ?
;				; yes !
		LDY	#07H
RTS008		EQU	$
		STY	ENHELP
RTS010		EQU	$
		LDA	#IWAGO
		JSL	>ENIDSH
		BMI	RNTS10 
;
		JSL	>ENIDPS
;
		LDA	<WORK0
		ADC	#04H
		STA	ENXPSL,Y
		LDA	<WORK2
		ADC	#04H
		STA	ENYPSL,Y
;
		LDA	#01H
		STA	ENNOCR,Y
		STA	ENMOD6,Y
		STA	ENMOD3,Y
		DEC	A
		STA	ENZPSL,Y
		LDA	#20H
		STA	ENMOD0,Y
;
		PHX
;;		JSL	>RNDSET
;;		AND	#07H
;;		TAX
		LDX	ENHELP
		LDA	>RISTXS,X
		STA	ENXSPD,Y
		LDA	>RISTYS,X
		STA	ENYSPD,Y
;
		JSL	>RNDSET
;;		AND	#07H
;;		ADC	#20H
;;		STA	ENZSPD,Y
		AND	#01H
		STA	ENCHPT,Y
		PLX
RNTS10		EQU	$
		DEC	ENHELP
		BPL	RTS010
		RTL
;
;=======================================================
OOTSUC2		EQU	$
		LDY	#00H
		CMP	#00H
		BPL	OTCK10
		DEY
OTCK10		EQU	$
		CLC
		ADC	ENYP2L
		STA	ENYP2L
		TYA
		ADC	ENYP2H
		STA	ENYP2H
;
		LDA	ENCLOR,X
		PHA
		JSL	>OOTSUCK
		PLA
		STA	ENCLOR,X
;
		JSL	>PSSAVE2
		RTL
;
OOTSUCK		EQU	$
		LDA	ENKBMK,X
		BEQ	OCK010R
;
		LDA	ENMODE,X
		CMP	#EMOVE
		BNE	O20010
;
		LDA	<GAMEMD
		ORA	ENSTFG
		BNE	O20010
;
		MEM16
		REP	#20H
		LDA	ENXP2L
		SEC
		SBC	<PLXPS1
		CLC
		ADC	#18H
		CMP	#30H
		BCS	O20010
		LDA	<PLYPS1
		SEC
		SBC	ENYP2L
		CLC
		ADC	#18H+8
		CMP	#030H
		BCS	O20010
		MEM8
		SEP	#20H
;
		LDA	<KEYA2L
		BPL	O20010
;
		LDA	HEMODE,X
		INC	HEMODE,X
		AND	#01H
		CLC  
                ADC     #MS_05B0+4
                STA     MSGENOL
                LDA     #HIGH MS_05B0+4   ; Minnani naishyo !!
                STA     MSGENOH
                JSL     >MSGSET
O20010		EQU	$
		MEM8
		SEP	#20H
;
OOTSUC0		EQU	$
		PHB
		PHK
		PLB
;
		LDA	ENCLOR,X
		AND	#11110000B
		PHA
		ORA	#08H
		STA	ENCLOR,X
;
		JSR	OOTSUCS
;
		PLA
		ORA	#0DH 
		STA	ENCLOR,X
;
		LDA	#04H*4
		JSL	>OAMENT1
		PLB
OCK010		EQU	$
		RTL
OCK010R		EQU	$
		RTL
;=================================================================
OOTSUCD		EQU	$
		WORD	00000H,00000H
		HEX	F3,01,00,00
		WORD	00007H,00000H
		HEX	F3,41,00,00
		WORD	00004H,00007H
		HEX	E0,07,00,00
;
		WORD	0FFFFH,00002H
		HEX	F3,01,00,00
		WORD	00006H,00001H
		HEX	F3,41,00,00
		WORD	00004H,00008H
		HEX	E0,07,00,00
;
		WORD	00001H,00001H
		HEX	F3,01,00,00
		WORD	00008H,00002H
		HEX	F3,41,00,00
		WORD	00004H,00008H
		HEX	E0,07,00,00
;-
 		WORD	0FFFEH,00000H
		HEX	F3,01,00,00
		WORD	0000AH,00000H
		HEX	F3,41,00,00
		WORD	00004H,00007H
		HEX	E0,07,00,00
;
		WORD	00000H,00000H
		HEX	F3,01,00,00
		WORD	00008H,00000H
		HEX	F3,41,00,00
		WORD	00004H,00006H
		HEX	E0,07,00,00
;
		WORD	0FFFBH,00000H
		HEX	F3,01,00,00
		WORD	00010H,00000H
		HEX	F3,41,00,00
		WORD	00004H,00008H
		HEX	E0,07,00,00
;
OOTSUCS		EQU	$
		LDA	#00H
		XBA
		LDA	ENCHPT,X
		MEM16
		REP	#20H
		ASL	A
		ASL	A
		ASL	A
;
		STA	<WORK0
		ASL	A
		ADC	<WORK0
;;	
		ADC	#OOTSUCD
		STA	<WORK8
		MEM8
		SEP	#20H
		LDA	#03H
		JSL	>SETOAML22
		RTS
;---------------------------------------------------
;---------------------------------------------------
;---------------------------------------------------
;---------------------------------------------------
;---------------------------------------------------
;---------------------------------------------------
;---------------------------------------------------
ASZNZST		EQU	$
		INC	KAGIFG,X
		LDA	KAGIFG,X
		AND	#0FH
		BNE	ASZS90
;
		PHX
		TXY
		LDX	#E2NO-1
ASZS08		EQU	$
		LDA	>E2MODE,X
		BEQ	ASZS10
		DEX
		BPL	ASZS08
		INX
;- - - - - - - - - - - - - - - - - -
ASZS10		EQU	$
		LDA	#14H
		STA	>E2MODE,X
		STA	EN2FLG
                LDA     ENXPSL,Y
		CLC
		ADC	#04H
                STA     >E2XPSL,X
                LDA     ENXPSH,Y
		ADC	#00H
                STA     >E2XPSH,X
                LDA     ENYPSL,Y
                CLC
                ADC     #10H+8+4
                STA     >E2YPSL,X
                LDA     ENYPSH,Y
                ADC     #00H
                STA     >E2YPSH,X
;
;;              LDA     #0FFH
                LDA     #007H+3
                STA     >E2TIM0,X
		PLX
ASZS90		EQU	$
		RTL
;---------------------------------------------------
GRICDT		EQU	$
		BYTE	0000B,0000B,0000B,0000B,0000B,0000B,0000B,0100B
		BYTE	0000B,0000B,0000B,0000B,0000B,0000B,0000B,0000B
		BYTE	0100B,0100B,0110B,0100B,0100B,0110B,0000B,0000B
		BYTE	1111B,1111B,0100B,0101B,0101B,0100B,0110B,0110B
		BYTE	1111B,1111B,0100B,0101B,0101B,0111B,0110B,0110B
		BYTE	11111B,11111B,0100B,0111B,0111B,0100B,0110B,0110B
		BYTE	0110B,0111B,0010B,0000B,0000B,0000B,0000B,0000B
		BYTE	0110B,0110B,0010B,0000B,0000B,0000B,0000B,0000B
GRICNO		EQU	$
;;		BYTE	ISHI0,RUPYR,RUPYR,RUPYR,HEIS0,RUPYR,RUPYR,ZIRAI
;;		BYTE	ABATA,RUPYR,RUPYR,RUPYR,HEIS1,RUPYR,RUPYR,HACHI
		BYTE	001H,001H,001H,001H,00FH,001H,001H,012H
		BYTE	010H,001H,001H,001H,011H,001H,001H,003H
GRICBT		EQU	$
		BYTE	0000B,0000B,0000B,0000B,0010B,0000B,0000B,1000B
		BYTE	10000B,0000B,0000B,0000B,0001B,0000B,0000B,0000B
;
GRITMCK		EQU	$
		PHB
		PHK
		PLB
;
		JSL	>RNDSET
		AND	#01H
		BNE	GIS030
;
		STZ	<WORKD
		LDY	#ENNO-1
GIS010		EQU	$
		LDA	ENMODE,Y
		BEQ	GIS020
		LDA	ENMYNO,Y
		CMP	#HYUUU
		BEQ	GIS020
		INC	<WORKD
GIS020		EQU	$
		DEY
		BPL	GIS010
;
		LDA	<WORKD
		CMP	#04H
		BCS	GIS030		; Now enemy 5 over?
;					; no !
		LDA	>MODTBL0
		CMP	#02H
		BCC	GIS030		; Cyuuban !
;
;;		JSL	>RNDSET
;;		AND	#07H
		LDA	ITRNDCT
		INC	ITRNDCT
		AND	#07H
		LDY	URAFLG
		BEQ	GIS028
		ORA	#08H
GIS028		EQU	$
		TAY
		PHX
		LDA	GRNDNO
		AND	#3FH
		TAX
		LDA	GRICDT,X
		AND	GRICBT,Y
		BNE	GIS02A		; Set ok ?
;					; yes !
		LDA	GRICNO,Y
		STA	OSETFG
GIS02A		EQU	$
		PLX
GIS030		EQU	$
		PLB
		RTL
;---------------------------------------------------
;***********************************************************************
OOISUMV		EQU	$
		PHB
		PHK
		PLB
		JSR	OO000
		PLB
		RTL
;--------------------------------------------------------
OO000		EQU	$
;;		JSR	OCHECK
		JSR	OOISUCS
;
		JSR	ENSTCK
;
		JSL	>CRENPL2L
		BCC	OIM008
;
;;		MEM16
;;		REP	#00100000B
;;		LDA	PLSVX1
;;		STA	<PLXPS1
;;		LDA	PLSVY1
;;		STA	<PLYPS1
;;		MEM8
;;		SEP	#00100000B
		JSL	>PLOTCK
;
		JSL	>DASHON		; Player dash reset !
;
		LDA	>OPMODE
		CMP	#01H
		BNE	OIM008		; Hime with ?
;					; yes !
;;		LDA	ENSTAT,X
;;		BNE	OIM008
;
		LDA	>ITEMR11	; Kantera have !!
		BEQ	OIM008
;
		LDA	DASHFG
		BNE	OIM008
;
		LDA	ENCTCT,X
		CMP	#090H
		BEQ	OIM008
;
		LDA	<PLXSPD
		CMP	#18H
		BMI	OIM008
;
;;		INC	ENSTAT,X
;
		LDA	#04H
		STA	>MODTBL3
;
;;		LDA	<FRCNT
		INC	ENCONT,X
		LDA	ENCONT,X
		AND	#01H
		BNE	OIM085
;
		INC	ENCTCT,X
;
OIM085		EQU	$
		LDA	ENCTCT,X
		CMP	#08H
		BCC	OIM009
;
;;L		INC	ENSTAT,X
;
;;L		LDA	#1BH
;;L		STA	SOUND3	;(S)	; Fanfale !
;
		LDA	SOUND2	
		BNE	OIM007		
;
		LDA	#22H
		STA	SOUND2	;(S)
OIM007		EQU	$
		LDA	#02H
		STA	ENXSPD,X
;;		JSR	ENXCLC
		JSL	>ENMVCLL ;ENXCLC
OIM008		EQU	$
;;L		STZ	ENCTCT,X
OIM009		EQU	$
		RTS
;--- move ---
;
;;L		LDA	ENSTAT,X
;;L		BEQ	OIM030		 ;move ?
;;L		CMP	#02H
;;L		BEQ	OIM030
;;L;;;		EOR	#01H
;;L		STA	PYALSP
;;L;
;;L;;		LDA	>MODTBL1	 ; yes !
;;L;;		ORA	#00000001B
;;L;;		STA	>MODTBL1
;;L;
;;L		LDY	ENCONT,X
;;L		CPY	#090H
;;L		BEQ	OIM020
;;L;
;;L		LDA	<FRCNT
;;L		LSR	A
;;L		BCC	OIM010
;;L		INC	ENCONT,X
;;L;
;;L		CPY	#02H
;;L		BNE	OIM010
;;L;		
;;L		LDA	#18H
;;L		STA	SOUND3	;(S)	Gogogogo
;;L;
;;LOIM010		EQU	$
;;L		LDA	#02H
;;L		STA	ENXSPD,X
;;L		JMP	ENXCLC
;;LOIM020		EQU	$
;;L		INC	ENSTAT,X	; Move end !
;;L		STZ	PYALSP
;;L;
;;L		LDA	#04H
;;L		STA	>MODTBL3
;;LOIM030		EQU	$
;;L		RTS
;
;
;= = = = = = = = = = = = = = = = = =
OISCXA		EQU	$
		HEX	00,10,20,00,10,20
OISCYA		EQU	$
		HEX	00,00,00,10,10,10
OISCCD		EQU	$
		HEX	0C,0E,0C,2C,2E,2C
OISCAD		EQU	$
		HEX	31,31,71,31,31,71
;============================================
OOISUCS		EQU	$
		LDA	#08H*4
		JSL	>OAMENT2
;;		JSR	OCHECK2
		JSL	>OAMCHKL
		BCS	OICS90
;
		PHX
		LDX	#05H
OICS10		EQU	$
		LDA	<WORK0
		CLC
		ADC	OISCXA,X
		STA	(<OAMADR),Y
		LDA	<WORK2
		CLC
		ADC	OISCYA,X
		INY
		STA	(<OAMADR),Y
		LDA	OISCCD,X
		INY
		STA	(<OAMADR),Y
		LDA	OISCAD,X
		INY
		STA	(<OAMADR),Y
		INY
		DEX
		BPL	OICS10
		PLX
		LDY	#02H
		LDA	#05H
		JSL	>ALOMCKL
OICS90		EQU	$
		RTS
;---------------------------------------------------
;==========================================================
BIGKOCD		EQU	$
;0
		WORD	0FFE8H,0FFF8H
		HEX	80,00,00,02
		WORD	0FFF8H,0FFF8H
		HEX	82,00,00,02
		WORD	00008H,0FFF8H
		HEX	82,40,00,02
		WORD	00018H,0FFF8H
		HEX	80,40,00,02
;
		WORD	0FFE8H,00008H
		HEX	A0,00,00,02
		WORD	0FFF8H,00008H
		HEX	A2,00,00,02
		WORD	00008H,00008H
		HEX	A2,40,00,02
		WORD	00018H,00008H
		HEX	A0,40,00,02	
;1
		WORD	0FFE8H,0FFF8H
		HEX	84,00,00,02
		WORD	0FFF8H,0FFF8H
		HEX	86,00,00,02
		WORD	00008H,0FFF8H
		HEX	86,40,00,02
		WORD	00018H,0FFF8H
		HEX	84,40,00,02
;
		WORD	0FFE8H,00008H
		HEX	A4,00,00,02
		WORD	0FFF8H,00008H
		HEX	A6,00,00,02
		WORD	00008H,00008H
		HEX	A6,40,00,02
		WORD	00018H,00008H
		HEX	A4,40,00,02	
;2
		WORD	0FFF8H,0FFF8H
		HEX	88,00,00,02
		WORD	0FFF8H,0FFF8H
		HEX	88,00,00,02
		WORD	00008H,0FFF8H
		HEX	88,40,00,02
		WORD	00008H,0FFF8H
		HEX	88,40,00,02
;
		WORD	0FFF8H,00008H
		HEX	A8,00,00,02
		WORD	0FFF8H,00008H
		HEX	A8,00,00,02
		WORD	00008H,00008H
		HEX	A8,40,00,02
		WORD	00008H,00008H
		HEX	A8,40,00,02	
;;-0
;		WORD	00000H,00008H
;		HEX	8B,00,00,00
;		WORD	00008H,00008H
;		HEX	8B,40,00,00
;;
;;		WORD	0FFE8H,0FFF8H
;		HEX	80,00,00,02
;		WORD	0FFF8H,0FFF8H
;		HEX	82,00,00,02
;		WORD	00008H,0FFF8H
;		HEX	82,40,00,02
;;		WORD	00018H,0FFF8H
;		HEX	80,40,00,02
;;
;		WORD	0FFE8H,00008H
;		HEX	A0,00,00,02
;		WORD	0FFF8H,00008H
;		HEX	A2,00,00,02
;;		WORD	00008H,00008H
;		HEX	A2,40,00,02
;		WORD	00018H,00008H
;		HEX	A0,40,00,02	
;;-1
;		WORD	00000H,00008H
;		HEX	8B,00,00,00
;		WORD	00008H,00008H
;		HEX	8B,40,00,00
;;
;		WORD	0FFE8H,0FFF8H
;		HEX	84,00,00,02
;		WORD	0FFF8H,0FFF8H
;		HEX	86,00,00,02
;		WORD	00008H,0FFF8H
;		HEX	86,40,00,02
;		WORD	00018H,0FFF8H
;		HEX	84,40,00,02
;;
;		WORD	0FFE8H,00008H
;		HEX	A4,00,00,02
;;		WORD	0FFF8H,00008H
;		HEX	A6,00,00,02
;		WORD	00008H,00008H
;		HEX	A6,40,00,02
;		WORD	00018H,00008H
;		HEX	A4,40,00,02	
;;-2
;		WORD	0FFF8H,0FFF8H
;		HEX	88,00,00,02
;		WORD	0FFF8H,0FFF8H
;		HEX	88,00,00,02
;		WORD	0FFF8H,0FFF8H
;		HEX	88,00,00,02
;		WORD	0FFF8H,0FFF8H
;		HEX	88,00,00,02
;		WORD	0FFF8H,0FFF8H
;		HEX	88,00,00,02
;		WORD	0FFF8H,0FFF8H
;		HEX	88,00,00,02
;;
;		WORD	0FFF8H,0FFF8H
;		HEX	88,00,00,02
;		WORD	00008H,0FFF8H
;		HEX	88,40,00,02
;;
;		WORD	0FFF8H,00008H
;		HEX	A8,00,00,02
;		WORD	00008H,00008H
;		HEX	A8,40,00,02
;;- - - - - - - - - - - - - - - - - - - - - - - - -
BIGKOCS		EQU	$
		PHB
		PHK
		PLB
		JSR	BKC000
		PLB
		RTL
; - - - - - - - - - - - - - - - - - - - -
BKC000		EQU	$
		LDA	#00H
		XBA
		LDA	ENCHPT,X
		MEM16
		REP	#00100000B
		ASL	A
		ASL	A
		ASL	A
;
		ASL	A		
		ASL	A
		ASL	A
		ADC	#BIGKOCD
		STA	<WORK8
;
		LDA	#OAM+0120H
		STA	<OAMADR		; OAM adress kotei !
		LDA	#OAMSB+0120H/4
		STA	<OSBADR
;
		MEM8
		SEP	#00100000B
;
;;		LDA	#0AH
		LDA	#08H
;;		STA	<WORK6
;;		STZ	<WORK7
;
		JSL	>SETOAML22
;
;;		LDA	ENTIM2,X
;;		BNE	BKC090		; Kuchi toshi ?
;;;					; yes !
;;		LDY	#01H
;;		LDA	#0F0H
;;		STA	(<OAMADR),Y
;;		LDY	#05H
;;		STA	(<OAMADR),Y
;;BKC090		EQU	$
;- Kage set --
		LDA	ENDSPL,X
		BNE	BKC0A0
;
		PHX
		LDA	ENCHPT,X
		ASL	A
		ASL	A
		ASL	A
		ADC	ENCHPT,X
		STA	<WORK6
;
		LDA	<WORK2
		CLC
		ADC	ENZPSL,X
		STA	<WORK2
		LDA	<WORK3
		ADC	#00H
		STA	<WORK3
;
		LDY	#10*4
		LDX	#08H
BKC098		EQU	$
		PHX
		TXA
		CLC
		ADC	<WORK6
		ASL	A
		TAX
		MEM16
		REP	#00100000B
		LDA	<WORK0
		CLC
		ADC	BKSWXL,X
		STA	(<OAMADR),Y
		AND	#0100H
		STA	<WORKE
		INY
		LDA	<WORK2
		CLC
		ADC	#10H
		STA	(<OAMADR),Y
		CLC
		ADC	#0010H
		CMP	#0100H
		MEM8
		SEP	#00100000B
		BCC	BKC09C
		LDA	#0F0H
		STA	(<OAMADR),Y
BKC09C		EQU	$	
		INY	
		LDA	#6CH
		STA	(<OAMADR),Y
		INY
		LDA	#24H
		STA	(<OAMADR),Y
;
		PHY
		TYA
		LSR	A
		LSR	A
		TAY
		LDA	#02H
		ORA	<WORKF
		STA	(<OSBADR),Y
		PLY
;
		INY
		PLX
		DEX
		BPL	BKC098
		PLX
BKC0A0		EQU	$																		
		RTS
;- - - - - - - - - - - - - - - - - -
BKSWXL		EQU	$
		WORD	00H,03H,06H,09H,0CH
		WORD	0FFFDH,0FFFAH,0FFF7H,0FFF4H
;
		WORD	00H,02H,04H,06H,08H
		WORD	0FFFEH,0FFFCH,0FFFAH,0FFF8H
;
		WORD	00H,01H,02H,03H,04H
		WORD	0FFFFH,0FFFEH,0FFFDH,0FFFCH
;---------------------------------------------------
R1XSDT		EQU	$
		HEX	FA,FD,00,04,07
R1YSDT		EQU	$
		HEX	0B,0E,10,0E,0B
;
R100		EQU	$
		PHB
		PHK
		PLB
;
		LDA	#13H
		JSL	>SDLRE3	;(S)
;
		LDA	#04H
		STA	ENHELP
R1100		EQU	$
		LDA	#RUPYB
		JSL	>ENIDSH
		BMI	R1120
;
		JSL	>ENIDPS
		LDA	<WORK0
		CLC
		ADC	#04H
		STA	ENXPSL,Y
;
		LDA	#0FFH
		STA	ENSTTM,Y
;	
		PHX
		LDX	ENHELP
		LDA	R1XSDT,X
		STA	ENXSPD,Y
		LDA	R1YSDT,X
		STA	ENYSPD,Y
		LDA	#20H
		STA	ENZSPD,Y
		STA	ENTIM3,Y
		PLX
R1120		EQU	$
		DEC	ENHELP
		BPL	R1100
		PLB
		RTL
;---------------------------------------------------
BABACK		EQU	$
		JSR	BBCK00
		RTL
BBCK00		EQU	$
		LDA	#01H
		STA	ENMUKI,X	(1)
;
		JSL	>BABA1CS
		JSR	ENSTCK
		LDA	ENTIM0,X
		CMP	#01H
		BNE	BB0F00
;
		LDA	#MS_05B7
		STA	MSGENOL
		LDA	#HIGH MS_05B7
		STA     MSGENOH		
		JSL	>MSGSET
BB0F00		EQU	$
		LDA	<FRCNT
		LSR	A
		LSR	A
		LSR	A
		LSR	A
		AND	#01H
		STA	ENCHPT,X
		RTS
;---------------------------------------------------
;=====================================
ANAHOIT		EQU	$
		LDA	ENYPSL,X
		STA	<WORK0
		LDA	ENYPSH,X
		STA	<WORK1
		MEM16
		IDX8
		REP	#00100000B
		LDA	<PLYPS1
		CMP	<WORK0
		MEM8
		IDX8
		SEP	#00110000B
		BCS	AAOIT10
		LDA	#005H
		STA	ENSTAT,X
		LDA	ENXPSL,X
		SEC
		SBC	#009H
		STA	ENXPSL,X
		LDA	#001H
		STA	ENCHPT,X
AAOIT10		EQU	$
		INC	ENNOCR,X	; beem thru
		RTL
;---------------------------------------------------
;=======Heishi serch beam BG check ==================================================
HMMZXL		EQU	$
		WORD	00H,0CH,-08H,18H
HMMZYL		EQU	$
		WORD	08H,20H,18H,18H
;;HMBGCK		EQU	$
MTRTL		EQU	$
		RTL
;
MTEST		EQU	$
;;		RTL
;;		NOP
;
		LDA	<GAMEMD
		ORA	PYALSP
		ORA	ENSTFG
		BNE	MTRTL
;
		PHX
		PHY
;
		LDX	<PLMKCH
;
		MEM16
		REP	#20H
		LDA	<PLXPS1
		CLC
		ADC	>HMMZXL,X
		STA	<WORK0
		LDA	<PLYPS1
		CLC
		ADC	>HMMZYL,X
		STA	<WORK2
		MEM8
		SEP	#20H
;
		LDA	<PLBGCKF 
		CMP	#01H
		MEM16
		IDX16
		REP	#00110000B
		STZ	<WORK5
		BCC	BGR002		; Another BG ?
;					; Yes !
		LDA	#1000H
		STA	<WORK5
BGR002		EQU	$
		MEM8
		SEP	#00100000B
		LDA	<DJFLG
		MEM16
		REP	#00100000B
		BEQ	BGDCIK
;
		LDA	<WORK0
   		AND	#01FFH
		LSR	A
		LSR	A
		LSR	A
		STA	<WORK4
		LDA	<WORK2
		AND	#01F8H
		ASL	A
		ASL	A
		ASL	A
         	CLC
		ADC	<WORK4
		CLC
		ADC	<WORK5
		TAX
		LDA	>READBF,X
		BRA	SBC090
;---------------------------------------
BGDCIK		EQU	$		; chijoo BG no set ----> A
		MEM16
		IDX16
		LDA	<WORK2
		PHA
		LDA	<WORK0		; x-pos / 8
		LSR	A
		LSR	A
		LSR	A
		STA	<WORK2
;
;;		LDA	ENYP2L
		PLA
		STA	<WORK0
		MEM8
		IDX8
		SEP	#00110000B
		JSL	>EVCHCKE		; chijoo 
		MEM8
		IDX16
		REP	#00010000B
SBC090		EQU	$
		MEM8
		IDX8
		SEP	#00110000B
		CMP	#08H
		BEQ	HMB010
		CMP	#09H
		BNE	SBC0A0		; Mizu in ?
HMB010		EQU	$
;					; yes !
		JSL	>ASMZST
		BMI	SBC0A0
;
		LDX	<PLMKCH
;
		LDA	<PLYPS1
		CLC
		ADC	>HMMZYL,X
		PHP
		SEC
		SBC	#10H
		STA	ENYPSL,Y
		LDA	<PLYPS0
		SBC	#00H
		PLP
		ADC	>HMMZYL+1,X
		STA	ENYPSH,Y
;
		LDA	<PLXPS1
		CLC
		ADC	>HMMZXL,X
		PHP
		SEC
		SBC	#08H
		STA	ENXPSL,Y
		LDA	<PLXPS0
		SBC	#00H
		PLP
		ADC	>HMMZXL+1,X
		STA	ENXPSH,Y
;
		LDA	<PLBGCKF
		STA	ENKAIF,Y
		LDA	#00H
		STA	ENZPSL,Y
SBC0A0		EQU	$
		PLX
		PLY
		RTL	
;---------------------------------------------------
;---------------------------------------------------
		END
