;************************************************************************
;*									*
;*	title name	: "yossy"					*
;*	proccess	: enemy sub.1					*
;*	file name	: ys_enmy8					*
;*									*
;************************************************************************
;
;
		SALL
;
		include		ys_header.inc
		include		ys_unit.h
		include		ys_pld.h
		include		ys_color.h
		include		ys_ename.h
		include		../union/ys_bgcheck.h
;
		XALL
;
;
;------------------------------------------------------------------------
;-		global symbol						-
;------------------------------------------------------------------------
		GLB	GURU1IN,GURU2IN,GHEIHIN,HOMOLIN,HOMORIN
		GLB	DOSUNIN,DHEIHIN
		GLB	TRBOXIN
		GLB	MAKI0IN,MAKI1IN
		GLB	QCHANIN,QCHN2IN,FLIPPIN,FLIPHIN
		GLB	AWANHIN,RBLKGIN,RBLKYIN,RFLSGIN,RFLSYIN
		GLB	RFLLGIN,SPRKLIN,SPRKRIN,PPCKLIN,PPCKRIN
		GLB	HINAQIN,RMARUIN
		GLB	HINQ2IN,TRBX2IN,TTUBOIN,KINTOIN
		GLB	KATI0IN,KATI1IN,KATI2IN,MARUTIN
;
		GLB	GURU1MV,GURU2MV,GHEIHMV,HOMOLMV,HOMORMV
		GLB	DOSUNMV,DHEIHMV
		GLB	TRBOXMV
		GLB	MAKI0MV,MAKI1MV
		GLB	QCHANMV,QCHN2MV,FLIPPMV,FLIPHMV
		GLB	AWANHMV,RBLKGMV,RBLKYMV,RFLSGMV,RFLSYMV
		GLB	RFLLGMV,SPRKLMV,SPRKRMV,PPCKLMV,PPCKRMV
		GLB	HINAQMV,RMARUMV
		GLB	HINQ2MV,TRBX2MV,TTUBOMV,KINTOMV
		GLB	KATI0MV,KATI1MV,KATI2MV,MARUTMV
;
		GLB	AWANH_BGBR0_SET,TRBOX_BREAK
		GLB	TRBOX_COIN_SET,TRBOX_TIME_SET,TRBOX_SMK0_SET
		GLB	SHOT_EN_KILL_SP,SHOT_EN_KILL_S2
;
		GLB	BGBR0_SET
;
;------------------------------------------------------------------------
;-		extern symbol						-
;------------------------------------------------------------------------
;
;-------------< ys_main >------------------------------------------------
		EXT	D_00,GMIN
		EXT	SOUND_3_ON
;
;-------------< ys_rpro >------------------------------------------------
		EXT	JSRSUB
		EXT	CHIPON
		EXT	CHIPON_RAM_READ
;
;-------------< ys_play >------------------------------------------------
		EXT	EBSTAT
		EXT	PFAL,PSTP,PMOV
		EXT	PFLP,PSHT,PDEM,PGOL
		EXT	PUSHTM,PUSHPT
		EXT	BERO_CANCEL
;
;-------------< ys_bgsc >------------------------------------------------
		EXT	BGCG,BLK0
;
		EXT	UNITCHG
;
;-------------< ys_enmy >------------------------------------------------
		EXT	ENEMY,ENINSB
		EXT	ENCLEAR,ENCLEAR_NORETN
		EXT	DISPCK0,DISPCK1,DISPCK2,DISPCK3,DISPCK4
		EXT	ENINSR,ENINSR_I,ENINSR2,EEXCHK,EEYCHK,EEXYCK,ESTATST
		EXT	SCOREST
		EXT	ENMDCK,XSDOWN,EPCRCK,MUKEOR,XSPEOR,MKEOR2,PLFLST
		EXT	PLFLST_2,ENRINT
		EXT	POBBGCR,BOBBGCR,POBBGCR_H
		EXT	SHOT_EN_KILL,SHOT_EN_KILL_S
		EXT	EXIST_CHECK2,EXIST_CHECK_S2,NON_EXIST_SET,NON_EXIST_SET2
;
		EXT	ENDEATH_SET,ENDEATH_SET_4,EGGKILL_ALL
;
		EXT	PL_1UP_SET,PL_3UP_SET
;
		EXT	EINIT,EFAIL,ECHNG,EMOVE,EEATM,ENOSE,EBABL,EFALL,EFIRE
;
		EXT	EATMXS,NOSWT
;
		EXT	ENFAIL0
;
		EXT	EN_XYMOVE,EN_TIMER
;
		EXT	FSMK0_SET2,FSMK0_SET3,FSMK0_SET
		EXT	COIN1_END_SET
;
		EXT	TROBJ_CANCEL
		EXT	TROBJ_SR_2x2,TROBJ_SR_4x4,TROBJ_SR_8x8,TROBJ_SR_8x4
		EXT	TROBJ_SR_2x2_CL,TROBJ_SR_4x4_CL,TROBJ_SR_8x8_CL
		EXT	TROBJ_SR_8x4_CL
		EXT	TROBJ_OAM_8x4
		EXT	TROBJ_OAM_2x2,TROBJ_OAM_4x4,TROBJ_OAM_8x8,TROBJ_OAM_8H8
		EXT	TROBJ_OAM_2x2_I,TROBJ_OAM_4x4_I,TROBJ_OAM_8x8_I
		EXT	TROBJ_CLEAR
		EXT	TROBJ_PLOT_X,TROBJ_PLOT_Y,TROBJ_CHAR_NO
;
;-------------< ys_enmy2 >------------------------------------------------
		EXT	NLFLRIN,NLFUDIN
;
		EXT	NRLF0_BGCHK,DOROB_SET
;
		EXT	HEIH0_DEATH_CHK
;
;-------------< ys_enmy3 >------------------------------------------------
		EXT	BSCLW_SET_M
		EXT	TO_COIN_CHANGE
;
;-------------< ys_enmy4 >------------------------------------------------
		EXT	ZOOM_PLCHK,ANGCAL_SPD
;
		EXT	NMZ_HOSEI
;
;-------------< ys_enmy5 >------------------------------------------------
		EXT	COURSE_CHECK
;
;-------------< ys_enmy6 >------------------------------------------------
		EXT	MBALL_ENCHK
;
		EXT	MATO0_DEATH_CHK
;
;-------------< ys_enmy9 >------------------------------------------------
		EXT	COIN_CATCH
;
;-------------< ys_dorobo >------------------------------------------------
		EXT	DOROB_RMODE6
;
;-------------< ys_hajime-chan >------------------------------------------------
		EXT	BABYM_RMODE00
		EXT	BABYM_RMODE10
		EXT	BABYM_RMODE38
		EXT	BABYM_RMODE40
		EXT	BABYM_RMODE50
		EXT	BABYM_RMODE51
		EXT	BABYM_RMODE52
		EXT	BABYM_RMODE60
		EXT	BABYM_RMODE61
		EXT	BABYM_RMODE70
		EXT	BABYM_RMODE71
;
		EXT	B_SP_RMODE20
;
		EXT	BABYM_PLCHECK
		EXT	BABYM_MDCHECK
		EXT	BABYM_SHABON
		EXT	BABYM_SHABON2
;
		EXT	BABYM_SHABN_BRK
		EXT	BABYM_SHABN_C2
		EXT	BABYM_SHABN_C3
;
;-------------< ys_exst >------------------------------------------------
		EXT	EXINSR
;
;-------------< ys_play >------------------------------------------------
		EXT	PCLR
		EXT	TIMEUP_SET
;
;-------------< ys_unit >------------------------------------------------
		EXT	UNDTADD,UNDATA,RUTDATA
;
;-------------< ys_data >------------------------------------------------
		EXT	SIN,COS
;
;------------------------------------------------------------------------
;-		define symbol						-
;------------------------------------------------------------------------
BABY_INDEX	EQU	00H
;
;
;
;************************************************************************
;*									*
;*		program start						*
;*									*
;************************************************************************
;
		EXTEND
;
		MEM16
		IDX8
;
		DPAGE	EN0RAM
;
Group_D		GROUP	Enemy8_pro
Enemy8_pro	SECT	REL
;
;************************************************************************
;*		dummy subroutine					*
;************************************************************************
DUMMY_SUB	EQU	$
		TYX
		RTS
;
;************************************************************************
;*		initial ( guru_guru bar	 )				*
;************************************************************************
GURU1IN		EQU	$			;-- guru1in --
GURU2IN		EQU	$			;-- guru2in --
		JSL	>TROBJ_SR_4x4_CL

		LDA	ENTROB,X
		STA	ENWRKC,X

		JSL	>TROBJ_SR_4x4		;回転エリア確保できた ?
		BCS	GURU1IN0100		; yes: GURU1IN0100

		LDA	ENWRKC,X
		STA	ENTROB,X
		JMP	>ENCLEAR

GURU1IN0100	EQU	$
		LDA	ENXPSL,X
		AND	#00010H
		LSR	A
		LSR	A
		LSR	A
		STA	ENMUKI,X
		DEC	A
		ASL	A
		STA	ENWRKA,X

		JSR	GURU1_ROT_SET_I

		RTL
;
;************************************************************************
;*		move	( guru_guru bar )				*
;************************************************************************
;		ENWRK0	USE
;		ENWRK2	USE
;		ENWRK4	USE
;		ENWRK6	USE
;		ENWRK8	回転角
;		ENWRKA	回転方向
;		ENWRKC	もう一つ（軸）の ENTROB
;
;		ENTIM0	サウンドＯＮタイマー
;
GURU1MV		EQU	$			;-- guru1mv --
GURU2MV		EQU	$			;-- guru2mv --
		STZ	ENMUKI,X

		JSR	GURU1_OAM_SET

		JSL	>ENMDCK

		JSL	>DISPCK1		;画面内 ?
		BCC	GURU1MV0100		; yes: GURU1MV0100

		LDA	ENWRKC,X
		STA	ENTROB,X
		JSL	>TROBJ_CLEAR

		RTL

GURU1MV0100	EQU	$
		JSR	GURU1_PLCHK

		JSR	GURU1_ROT_SET

		LDA	ENTIM0,X
		BNE	GURU1MV0800

		LDA	#00008H
		STA	ENTIM0,X
		LDA	#0001BH			;［Ｓ］
		JSL	>SOUND_3_ON
;;;;;;;;		LDA	#0001BH			;［Ｓ］
;;;;;;;;		STA	SOUND0

GURU1MV0800	EQU	$

		RTL
;
GURU1_OAM_SET	EQU	$
		JSL	>TROBJ_OAM_4x4

		LDA	ENTROB,X
		PHA
		LDA	ENWRKC,X
		STA	ENTROB,X
		I16
		LDA	ENOAML,X
		CLC
		ADC	#00008*4
		TAY
		JSL	>TROBJ_OAM_4x4_I
		IDX8
		PLA
		STA	ENTROB,X
		I16
		LDY	ENOAML,X
		LDA	SOAM_DX+4+8*4,Y
		STA	SOAM_DX+4+8*8,Y
		LDA	SOAM_DX+4+8*5,Y
		STA	SOAM_DX+4+8*9,Y
		LDA	SOAM_DX+4+8*6,Y
		STA	SOAM_DX+4+8*10,Y
		LDA	SOAM_DX+4+8*7,Y
		STA	SOAM_DX+4+8*11,Y
		I8

		LDA	#-00017H
		STA	<EWORK0
		LDA	ENWRK8,X
		EOR	#0FFFFH
		INC	A
		AND	#001FEH
		STA	<EWORK2
		LDX	#00000
		LDY	#00002

GURU1_O_SET0100 EQU	$
		LDA	<EWORK0
		STA	R6
		LDA	<EWORK2
		STA	R1
		PHX
		PHY
		M_CHIP	M_ENMY_1P_ROT
		PLY
		PLX
		LDA	R0
		STA	<EWORK4,X
		LDA	R1
		STA	<EWORK8,X

		LDA	<EWORK0
		CLC
		ADC	#-0001CH*2
		STA	<EWORK0

		INX
		INX

		DEY
		BNE	GURU1_O_SET0100

		LDX	<ENINDX
		LDA	<EWORK4
		STA	<ENWRK0,X
		LDA	<EWORK6
		STA	<ENWRK2,X
		LDA	<EWORK8
		STA	<ENWRK4,X
		LDA	<EWORKA
		STA	ENWRK6,X

		I16
		LDY	ENOAML,X
		LDA	ECENTX,X
		SEC
		SBC	ESCCH1
		STA	<EWORK0
		LDA	ECENTY,X
		SEC
		SBC	ESCCV1
		STA	<EWORK2

		LDX	#002

GURU1_O_SET0200 EQU	$
		LDA	<EWORK4,X
		STA	<EWORKC
		LDA	<EWORK8,X
		STA	<EWORKE

		JSR	ROT_OAM_SET

		TYA
		CLC
		ADC	#008*4
		TAY

		DEX
		DEX
		BPL	GURU1_O_SET0200

		LDA	<EWORK4
		CLC
		ADC	<EWORK6
		CMP	#08000H
		ROR	A
		STA	<EWORKC
		LDA	<EWORK8
		CLC
		ADC	<EWORKA
		CMP	#08000H
		ROR	A
		STA	<EWORKE

		JSR	ROT_OAM_SET

		I8
		LDX	<ENINDX
		LDA	ENMYNO,X
		CMP	#GURU1
		BNE	GURU1_O_SET0500

		RTS

GURU1_O_SET0500 EQU	$
		I16
		LDY	ENOAML,X
		LDA	SOAM_DX+4+8*0,Y
		ORA	#0C000H
		STA	SOAM_DX+4+8*23,Y
		LDA	SOAM_DX+4+8*1,Y
		ORA	#0C000H
		STA	SOAM_DX+4+8*22,Y
		LDA	SOAM_DX+4+8*2,Y
		ORA	#0C000H
		STA	SOAM_DX+4+8*21,Y
		LDA	SOAM_DX+4+8*3,Y
		ORA	#0C000H
		STA	SOAM_DX+4+8*20,Y
		LDA	SOAM_DX+4+8*4,Y
		ORA	#0C000H
		STA	SOAM_DX+4+8*15,Y
		STA	SOAM_DX+4+8*19,Y
		LDA	SOAM_DX+4+8*5,Y
		ORA	#0C000H
		STA	SOAM_DX+4+8*14,Y
		STA	SOAM_DX+4+8*18,Y
		LDA	SOAM_DX+4+8*6,Y
		ORA	#0C000H
		STA	SOAM_DX+4+8*13,Y
		STA	SOAM_DX+4+8*17,Y
		LDA	SOAM_DX+4+8*7,Y
		ORA	#0C000H
		STA	SOAM_DX+4+8*12,Y
		STA	SOAM_DX+4+8*16,Y

		LDX	#003*2

GURU1_O_SET0600 EQU	$
		LDA	<EWORK4,X
		EOR	#0FFFFH
		INC	A
		STA	<EWORK4,X

		DEX
		DEX
		BPL	GURU1_O_SET0600

		TYA
		CLC
		ADC	#008*4*5
		TAY

		LDX	#002

GURU1_O_SET0700 EQU	$
		LDA	<EWORK4,X
		STA	<EWORKC
		LDA	<EWORK8,X
		STA	<EWORKE

		JSR	ROT_OAM_SET

		TYA
		SEC
		SBC	#008*4
		TAY

		DEX
		DEX
		BPL	GURU1_O_SET0700

		LDA	<EWORK4
		CLC
		ADC	<EWORK6
		CMP	#08000H
		ROR	A
		STA	<EWORKC
		LDA	<EWORK8
		CLC
		ADC	<EWORKA
		CMP	#08000H
		ROR	A
		STA	<EWORKE

		JSR	ROT_OAM_SET

		I8
		LDX	<ENINDX

		RTS
;
ROT_OAM_SET	EQU	$
		LDA	<EWORK0
		CLC
		ADC	<EWORKE
		STA	SOAM_DX+0+8*1,Y
		STA	SOAM_DX+0+8*3,Y
		SEC
		SBC	#00010H
		STA	SOAM_DX+0+8*0,Y
		STA	SOAM_DX+0+8*2,Y
		LDA	<EWORK2
		CLC
		ADC	<EWORKC
		STA	SOAM_DX+2+8*2,Y
		STA	SOAM_DX+2+8*3,Y
		SEC
		SBC	#00010H
		STA	SOAM_DX+2+8*0,Y
		STA	SOAM_DX+2+8*1,Y

		RTS
;
GURU1_PLCHK	EQU	$
		LDA	<ENWRK0,X
		STA	<EWORK0
		LDA	<ENWRK2,X
		STA	<EWORK2
		CLC
		ADC	<EWORK0
		CMP	#08000H
		ROR	A
		STA	<EWORK4
		LDA	<ENWRK4,X
		STA	<EWORK6
		LDA	ENWRK6,X
		STA	<EWORK8
		CLC
		ADC	<EWORK6
		CMP	#08000H
		ROR	A
		STA	<EWORKA

		LDA	EPWIDX,X
		STA	<EWORKC
		LDA	EPWIDY,X
		STA	<EWORKE

		LDA	PWIDEX
		CLC
		ADC	#0000AH
		STA	R0
		ASL	A
		STA	R1
		LDA	PWIDEY
		CLC
		ADC	#0000AH
		STA	R2
		ASL	A
		STA	R3

		JSR	GURU1_PLCHK_S

		LDA	ENMYNO,X
		CMP	#GURU1
		BEQ	GURU1_PLCHK0800

		LDX	#003*2*2-2

GURU1_PLCHK0300 EQU	$
		LDA	<EWORK0,X
		EOR	#0FFFFH
		INC	A
		STA	<EWORK0,X

		DEX
		DEX
		BPL	GURU1_PLCHK0300

		JSR	GURU1_PLCHK_S

GURU1_PLCHK0800 EQU	$

		RTS
;
GURU1_PLCHK_S	EQU	$
		LDX	#003*2-2

GURU1_PCHK_S010 EQU	$
		LDA	<EWORK6,X
		CLC
		ADC	<EWORKC
		CLC
		ADC	R0
		CMP	R1
		BCS	GURU1_PCHK_S020

		LDA	<EWORK0,X
		CLC
		ADC	<EWORKE
		CLC
		ADC	R2
		CMP	R3
		BCC	GURU1_PCHK_S030

GURU1_PCHK_S020 EQU	$
		DEX
		DEX
		BPL	GURU1_PCHK_S010

		LDX	<ENINDX

		RTS

GURU1_PCHK_S030 EQU	$
		LDX	<ENINDX

		JSL	>PLFLST

		PLA				;直接ＲＴＳ
		RTS
;
GURU1_ROT_SET	EQU	$
		TROBJ_CHK_2
		BNE	GURU1_R_SET0800

GURU1_ROT_SET_I EQU	$
		LDA	ENWRK8,X
		CLC
		ADC	ENWRKA,X
		AND	#001FEH
		STA	ENWRK8,X

;＊＊＊＊＊＊＊＊＜　ビットマップエリアセット　＞＊＊＊＊＊＊＊＊＊＊
		LDA	#CIPCHD3+00A0H+000	;(R12) <-- 転送元アドレスセット
		STA	R12			;
		LDA	#BANK CIPCHD3+00A0H+000 ;(R13) <-- 転送元バンクセット
		STA	R13			;

		LDA	ENWRK8,X		;(R5) <- 回転角セット
		LSR	A			;
		STA	R5			;

		LDA	#00100H			;(R6) <- 倍率セット
		STA	R6			;

		LDY	ENTROB,X
		TYX
		LDA	>TROBJ_PLOT_X,X		;(R3) <- ビットマップ座標＿Ｘセット
		STA	R3			;
		LDA	>TROBJ_PLOT_Y,X		;(R2) <- ビットマップ座標＿Ｙセット
		STA	R2			;
;
;-------------- OBJ mode 7 set ----------------------------------
		M_CHIP	C_32_ROTZOM

		LDX	<ENINDX
		LDA	#CIPCHD3+00C0H+000	;(R12) <-- 転送元アドレスセット
		STA	R12			;
		LDA	#BANK CIPCHD3+00C0H+000 ;(R13) <-- 転送元バンクセット
		STA	R13			;

		LDA	ENWRK8,X		;(R5) <- 回転角セット
		LSR	A			;
		STA	R5			;

		LDA	#00100H			;(R6) <- 倍率セット
		STA	R6			;

		LDY	ENWRKC,X
		TYX
		LDA	>TROBJ_PLOT_X,X		;(R3) <- ビットマップ座標＿Ｘセット
		STA	R3			;
		LDA	>TROBJ_PLOT_Y,X		;(R2) <- ビットマップ座標＿Ｙセット
		STA	R2			;
;
;-------------- OBJ mode 7 set ----------------------------------
		M_CHIP	C_32_ROTZOM

		LDX	<ENINDX

		INC	OBM7WF		;mode 7 OBJ chara DMA "ON"

GURU1_R_SET0800 EQU	$

		RTS
;
;************************************************************************
;*		initial ( guru_guru heiho- )				*
;************************************************************************
GHEIHIN		EQU	$			;-- gheihin --
		LDA	ENXPSL,X
		AND	#00010H
		LSR	A
		LSR	A
		LSR	A
		STA	ENMUKI,X

		RTL
;
;************************************************************************
;*		move	( guru_guru heiho- )				*
;************************************************************************
GHEIHMV		EQU	$			;-- gheihmv --
		JSL	>ENMDCK

		LDA	ENTIM1,X
		BNE	GHEIHMV0500

		LDA	#00008
		STA	ENTIM1,X

		LDA	ENCHPT,X
		INC	A
		CMP	#00005
		BMI	GHEIHMV0300

		LDA	#00000

GHEIHMV0300	EQU	$
		STA	ENCHPT,X

GHEIHMV0500	EQU	$

		RTL
;
;************************************************************************
;*		initial ( リレーへいほー )				*
;************************************************************************
HOMOL_BGSR_WIDE EQU	$
		WORD	0FFE0H,00020H
HOMOL_BGSR_STRT EQU	$
		WORD	0FFF0H,00020H,0FFE0H,00010H
HOMOL_SIDE_CHK	EQU	$
		WORD	0FFF0H,00010H
;
HOMOLIN		EQU	$			;-- homolin --
		LDA	#00000
		BRA	HOMOLIN0010

HOMORIN		EQU	$			;-- homorin --
		LDA	#00002

HOMOLIN0010	EQU	$
		STA	ENMUKI,X
		STA	ENWRK6,X
		ASL	A
		TAY
		LDA	ENXPSL,X
		AND	#00010H
		BEQ	HOMOLIN0020

		INY
		INY

HOMOLIN0020	EQU	$
		LDA	HOMOLFLG,Y
		BEQ	HOMOLIN0030

		JMP	>ENCLEAR

HOMOLIN0030	EQU	$
		LDA	#00001
		STA	HOMOLFLG,Y

		TYA
		ASL	A
		ASL	A
		ASL	A
		TAY
		STY	<ENWRK4,X

		LDA	#0FFFFH
		STA	HOMOLID0+0,Y
		STA	HOMOLID0+2,Y
		STA	HOMOLID0+4,Y
		STA	HOMOLID0+6,Y
		STA	HOMOLID0+8,Y
		STA	HOMOLID0+0AH,Y
		STA	HOMOLID0+0CH,Y
		STA	HOMOLID0+0EH,Y
		INC	A
		STA	HOMOLCH0+0,Y
		STA	HOMOLCH0+2,Y
		STA	HOMOLCH0+4,Y
		STA	HOMOLCH0+6,Y
		STA	HOMOLCH0+8,Y
		STA	HOMOLCH0+0AH,Y
		STA	HOMOLCH0+0CH,Y
		STA	HOMOLCH0+0EH,Y

		LDY	ENMUKI,X
		LDA	!HOMOL_SIDE_CHK,Y
		CLC
		ADC	ECENTX,X
		STA	R8
		LDA	ECENTY,X
		STA	R0
		M_CHIPR M_BGUNIT_READ
		LDY	#002
		LDA	R6
		CMP	#UT00C9
		BMI	HOMOLIN0140
		CMP	#UT00CD+1
		BMI	HOMOLIN0180

HOMOLIN0140	EQU	$
		LDY	#000

HOMOLIN0180	EQU	$
		LDX	<ENINDX
		TYA
		EOR	ENMUKI,X
		TAY
		LDA	!HOMOL_BGSR_WIDE,Y
		STA	<EWORK6

		LDA	ENMUKI,X		;HOMOL ?
		BEQ	HOMOLIN0200		; yes: HOMOLIN0200

		TYA
		CLC
		ADC	#00004
		TAY

HOMOLIN0200	EQU	$
		LDA	!HOMOL_BGSR_STRT,Y
		CLC
		ADC	ECENTX,X
		STA	<EWORK4
		STA	<EWORKA
		STZ	<EWORK8
		LDA	ECENTY,X
		STA	<EWORK2

HOMOLIN0300	EQU	$
		LDA	<EWORK2
		STA	R0
		LDA	<EWORK4
		STA	R8
		M_CHIPR M_BGUNIT_READ
		LDA	R6
		CMP	#UT00C9
		BMI	HOMOLIN0400
		CMP	#UT00CD+1
		BMI	HOMOLIN0500

HOMOLIN0400	EQU	$
		LDA	<EWORK4
		CLC
		ADC	<EWORK6
		STA	<EWORK4

		INC	<EWORK8
		BRA	HOMOLIN0300

HOMOLIN0500	EQU	$
		LDX	<ENINDX
		LDY	<EWORK8			;人数-1セット
		STY	<ENWRK0,X		;

		TYA				;ＭＡＸ２０人＋バクダン８個
		CLC				;
		ADC	#00009			;+1
		ASL	A
		ASL	A
		ASL	A
		XBA
		ORA	ENMOD2,X
		STA	ENMOD2,X

		LDA	<EWORK4
		SEC
		SBC	<EWORKA
		STA	<EWORK0
		LDA	ENMUKI,X
		DEC	A
		EOR	<EWORK0
		BPL	HOMOLIN0580

		LDA	ENXPSL,X
		CLC
		ADC	<EWORK0
		STA	ENXPSL,X
		LDA	<EWORK0
		EOR	#0FFFFH
		INC	A
		STA	<EWORK0

HOMOLIN0580	EQU	$
		LDA	<EWORK0
		EOR	#0FFFFH
		INC	A
		BMI	HOMOLIN0600

		CLC
		ADC	#00140H
		STA	ENWRKC,X
		LDA	#0FFC0H
		STA	ENWRKA,X
		BRA	HOMOLIN0700

HOMOLIN0600	EQU	$
		SEC
		SBC	#00040H
		STA	ENWRKA,X
		LDA	#00140H
		STA	ENWRKC,X

HOMOLIN0700	EQU	$
		LDY	BG1TYP			;壁コース ?
		CPY	#006H			;
		BEQ	HOMOLIN0800		;
		CPY	#00EH			;
		BNE	HOMOLIN0900		;  no: HOMOLIN0900

HOMOLIN0800	EQU	$
		LDA	ENYPSL,X
		SEC
		SBC	#00008
		STA	ENYPSL,X

HOMOLIN0900	EQU	$
		LDY	#010H
		STY	<ENCONT,X

		RTL
;
;************************************************************************
;*		move	( リレーへいほー )				*
;************************************************************************
;		ENWRK0	人数-1
;		ENWRK2	ROUTINE MODE INDEX
;		ENWRK4	HOMOLID0 のインデックス
;		ENWRK6	キャラパターンチェンジ方向
;		ENWRK8	イニシャル向き
;		ENWRKA	左範囲クリアチェックポイント
;		ENWRKC	右		”
;
;		ENCONT	ばくだん持ってないやつのキャラパターン
;
;		ENTIM0
;		ENTIM1
;		ENTIM2
;		ENTIM3
;
;ＯＡＭセット領域．．．へいほー２０匹、ばくだん８個
;			（内．．．ばくだん８個、ばくだん持ってるへいほー８匹）
;
;
HOMOL_SUB	EQU	$
		WORD	HOMOL_SUB0		;のうまる
		WORD	HOMOL_SUB1		;ばくだん落とす
		WORD	HOMOL_SUB2		;おぅおぅおお
;
HOMOLMV		EQU	$			;-- homolmv --
HOMORMV		EQU	$			;-- homormv --
;		ldy	#004h
;		sty	2100h

		JSR	HOMOL_OAM_SET

		JSL	>ENMDCK

		JSR	HOMOL_DISPCK

		TXY
		LDA	<ENWRK2,X
		ASL	A
		TAX
		JSR	(HOMOL_SUB,X)

		JSR	HOMOL_TIM_CALC

		LDA	TILTCT
		BEQ	HOMOLMV0800

		LDY	<ENWRK2,X
		BNE	HOMOLMV0800

		LDY	#016H
		STY	<ENCONT,X

		INC	<ENWRK2,X

HOMOLMV0800	EQU	$
;		ldy	#00fh
;		sty	2100h

		RTL
;
HOMOL_O_CHPT	EQU	$
;HOMOLCH0 =		 [0]	[1]    [2]    [3]    [4]    [5]	   [6]	  [7]
		WORD	00000H,00000H,00002H,00002H,00002H,00004H,00004H,00004H
;			 [8]	[9]    [A]    [B]    [C]    [D]	   [E]	  [F]
		WORD	00004H,00004H,00004H,00002H,00002H,00002H,00002H,00000H
;			 [10]	[11]   [12]   [13]   [14]   [15]   [16]	  [17]
		WORD	00000H,00006H,00006H,00006H,00006H,00006H,00006H,00008H
;			 [18]	[19]   [1A]   [1B]   [1C]
		WORD	0000AH,0000CH,0000CH,0000AH,0000EH
;
HOMOL_O_HFLIP	EQU	$
;HOMOLCH0 =		 [0]	[1]    [2]    [3]    [4]    [5]	   [6]	  [7]
		WORD	04000H,04000H,04000H,04000H,04000H,04000H,04000H,04000H
;			 [8]	[9]    [A]    [B]    [C]    [D]	   [E]	  [F]
		WORD	00000H,00000H,00000H,00000H,00000H,00000H,00000H,00000H
;			 [10]	[11]   [12]   [13]   [14]   [15]   [16]	  [17]
		WORD	00000H,00000H,00000H,00000H,00000H,00000H,00000H,00000H
;			 [18]	[19]   [1A]   [1B]   [1C]
		WORD	04000H,04000H,00000H,00000H,00000H
;
HOMOL_BOMB_X	EQU	$
;HOMOLCH0 =		 [0]	[1]    [2]    [3]    [4]    [5]	   [6]	  [7]
		WORD	08000H,00010H,00010H,00010H,0000FH,0000DH,0000AH,00006H
;			 [8]	[9]    [A]    [B]    [C]    [D]	   [E]	  [F]
		WORD	00000H,0FFFAH,0FFF6H,0FFF3H,0FFF1H,0FFF0H,0FFF0H,0FFF0H
;			 [10]	[11]   [12]   [13]   [14]   [15]   [16]	  [17]
		WORD	08000H,00000H,00000H,00000H,00000H,00000H,08000H,08000H
;			 [18]	[19]   [1A]   [1B]   [1C]
		WORD	08000H,08000H,08000H,08000H,08000H
;
HOMOL_BOMB_Y	EQU	$
;HOMOLCH0 =		 [0]	[1]    [2]    [3]    [4]    [5]	   [6]	  [7]
		WORD	08000H,00000H,00000H,00000H,0FFFFH,0FFFEH,0FFFDH,0FFFDH
;			 [8]	[9]    [A]    [B]    [C]    [D]	   [E]	  [F]
		WORD	0FFFDH,0FFFDH,0FFFDH,0FFFEH,0FFFFH,00000H,00000H,00000H
;			 [10]	[11]   [12]   [13]   [14]   [15]   [16]	  [17]
		WORD	08000H,0FFF9H,0FFF6H,0FFF4H,0FFF3H,0FFF2H,08000H,08000H
;			 [18]	[19]   [1A]   [1B]   [1C]
		WORD	08000H,08000H,08000H,08000H,08000H
;
HOMOL_OAM_SET	EQU	$
		LDA	ENXPSL,X
		SEC
		SBC	ESCCH1
		STA	<EWORK0
		LDA	ENYPSL,X
		SEC
		SBC	ESCCV1
		STA	<EWORK2

		LDY	#000
		LDA	ENMYNO,X
		CMP	#HOMOL
		BEQ	HOMOL_O_SET0200

		INY
		INY

HOMOL_O_SET0200 EQU	$
		LDA	!HOMOL_BGSR_WIDE,Y
		STA	<EWORK4

		LDA	<ENWRK0,X		;人数-1セット
		STA	<EWORKE			;
		STA	R1

		I16
		LDY	ENOAML,X
		STY	<EWORK6
		LDA	#08000H				;ばくだん消去
		STA	SOAM_DX+0+8*0,Y			;
		STA	SOAM_DX+0+8*1,Y			;
		STA	SOAM_DX+0+8*2,Y			;
		STA	SOAM_DX+0+8*3,Y			;
		STA	SOAM_DX+0+8*4,Y			;
		STA	SOAM_DX+0+8*5,Y			;
		STA	SOAM_DX+0+8*6,Y			;
		STA	SOAM_DX+0+8*7,Y			;
		TYA					;へいほーのＯＡＭセットインデックス計算
		CLC					;
		ADC	#008*8				;
		STA	<EWORKC				;
		TAY					;

		PHY
		LDA	<ENCONT,X
		ASL	A
		TAY
		LDA	!HOMOL_O_CHPT,Y
		STA	<EWORK8
		LDA	!HOMOL_O_HFLIP,Y
		STA	<EWORKA
		PLY

HOMOL_O_SET0280 EQU	$
		LDA	<EWORK0			;へいほーセット
		CLC				;
		ADC	#00040H			;
		CMP	#00100H+40H*2		;	;画面外 ?
		BCC	HOMOL_O_SET0300		;	;  no: HOMOL_O_SET0300
						;
		LDA	#08000H			;
		BRA	HOMOL_O_SET0400		;
						;
HOMOL_O_SET0300 EQU	$			;
		LDA	<EWORK0			;
						;
HOMOL_O_SET0400 EQU	$			;
		STA	SOAM_DX+0+8*0,Y		;
						;
		LDA	<EWORK2			;
		STA	SOAM_DX+2+8*0,Y		;
						;
		LDA	SOAM_DX+4+8*0,Y		;
		ORA	<EWORK8			;
		EOR	<EWORKA			;
		STA	SOAM_DX+4+8*0,Y		;
						;
		LDA	<EWORK0			;
		CLC				;
		ADC	<EWORK4			;
		STA	<EWORK0			;
		TYA				;
		CLC				;
		ADC	#00008			;
		TAY				;
						;
		DEC	<EWORKE			;
		BPL	HOMOL_O_SET0280		;

		LDY	<EWORK8			;プレイヤーのどすんで全員びっくり ?
		CPY	#006			;
		BNE	HOMOL_O_SET0480		;  no: HOMOL_O_SET0480

		I8

		RTS

		IDX16
HOMOL_O_SET0480 EQU	$
		LDA	ENMUKI,X
		STA	<EWORKA
		XBA
		ASL	A
		ASL	A
		ASL	A
		ASL	A
		ASL	A
		STA	<EWORK8

		LDA	<ENCONT,X		;
		SEC				;
		SBC	#00010H			;
		STA	R10			;

		STZ	<EWORK0
		LDA	#00007			;ノーマルでないへいほーのキャラナンバーセット
		STA	<EWORKE			;
		ASL	A		;[ LDA	#0000EH ]
		CLC				;
		ADC	<ENWRK4,X		;
		TAX				;
						;
HOMOL_O_SET0500 EQU	$			;
		LDA	HOMOLID0,X		;	;爆弾もってるやつもういない ?
		BPL	HOMOL_O_SET0501		;	;  no: HOMOL_O_SET0501
		JMP	HOMOL_O_SET0600		;	; yes: HOMOL_O_SET0600
						;
HOMOL_O_SET0501 EQU	$			;	;セットインデックス計算
		STA	R0			;	;
		ASL	A			;	;
		ASL	A			;	;
		ASL	A			;	;
		CLC				;	;
		ADC	<EWORKC			;	;
		TAY				;	;
						;
		PHX				;
		LDA	HOMOLCH0,X		;
		PHA				;
		LDA	R10			;	;プレイヤーのどすんでおぅおぅおお中 ?
		BEQ	HOMOL_O_SET0504		;	;  no: HOMOL_O_SET0504
						;
		LDA	#08000H			;	;ばくだんセットなし
		STA	<EWORK2			;	;
		PLA				;
		PHA				;
		CMP	#0001CH			;	;がっくりポーズ ?
		BNE	HOMOL_O_SET0506		;	;  no: HOMOL_O_SET0506
						;
HOMOL_O_SET0504 EQU	$			;
		PLA				;
		PHA				;
		ASL	A			;
		TAX				;
		LDA	!HOMOL_O_CHPT,X		;
		ORA	SOAM_DX+4+8*0,Y		;
		AND	#0BFFFH			;
		ORA	<EWORK8			;
		EOR	!HOMOL_O_HFLIP,X	;
		STA	SOAM_DX+4+8*0,Y		;

		LDA	!HOMOL_BOMB_Y,X		;ばくだんのセットＹ計算
		CLC				;
		ADC	SOAM_DX+2+8*0,Y		;
		STA	<EWORK4			;
		LDA	!HOMOL_BOMB_X,X		;ばくだんのセットＸ計算
		LDX	<EWORKA			;	;左にばくだんを流してる ?
		BEQ	HOMOL_O_SET0505		;	; yes: HOMOL_O_SET0505
						;
		EOR	#0FFFFH			;
		INC	A			;
						;
HOMOL_O_SET0505 EQU	$			;
		CLC				;
		ADC	SOAM_DX+0+8*0,Y		;
		STA	<EWORK2			;

HOMOL_O_SET0506 EQU	$
		LDA	R0			;一番先端のへいほー ?
		CMP	R1			;
		BNE	HOMOL_O_SET0509		;  no: HOMOL_O_SET0509

		PLA
		BRA	HOMOL_O_SET0530		; yes: HOMOL_O_SET0530

HOMOL_O_SET0509 EQU	$
		TYA				;次のへいほーのＯＡＭセットインデックス計算
		CLC				;
		ADC	#00008			;
		TAY				;
		PLA				;
		SEC				;プレイヤーのどすんでおぅおぅおお中 ?
		SBC	#0000CH			;
		BMI	HOMOL_O_SET0510		;  no: HOMOL_O_SET0510
		CMP	#00004			;
		BMI	HOMOL_O_SET0520		;
						;
HOMOL_O_SET0510 EQU	$			;
		LDA	#00000			;次のへいほーこっちを見てる
						;
HOMOL_O_SET0520 EQU	$			;
		ASL	A			;
		TAX				;
		LDA	SOAM_DX+4+8*0,Y		;次のへいほーＨフリップ＆キャラ変更
		EOR	#04000H			;
		ORA	!HOMOL_O_CHPT,X		;
		STA	SOAM_DX+4+8*0,Y		;

HOMOL_O_SET0530 EQU	$
		LDA	<EWORK6			;ばくだんＯＡＭセットインデックス計算
		CLC				;
		ADC	<EWORK0			;
		TAY				;

		LDA	<EWORK4			;ばくだんのＹセット
		STA	SOAM_DX+2+8*0,Y		;
		LDA	<EWORK2			;ばくだんのＸセット
		STA	SOAM_DX+0+8*0,Y		;
		LDA	<EWORK0			;次のばくだんＯＡＭセットインデックス計算
		CLC				;
		ADC	#00008			;
		STA	<EWORK0			;
		PLX				;

HOMOL_O_SET0600 EQU	$			;
		DEX				;
		DEX				;
						;
		DEC	<EWORKE			;のーまるでないへいほーのセット終わり ?
		BMI	HOMOL_O_SET0700		; yes: HOMOL_O_SET0700
		JMP	HOMOL_O_SET0500		;

HOMOL_O_SET0700 EQU	$
		LDX	<ENINDX

		I8

		RTS
;
HOMOL_DISPCK	EQU	$
		LDA	ENDSXL,X		;クリアする ?
		CMP	ENWRKA,X		;
		BMI	HOMOL_DISPCK010		; yes: HOMOL_DISPCK010
						;
		CMP	ENWRKC,X		;
		BMI	HOMOL_DISPCK080		;  no: HOMOL_DISPCK080

HOMOL_DISPCK010 EQU	$
		JSL	>ENCLEAR

		LDY	#000			;フラグクリア
		LDA	ENMYNO,X		;
		CMP	#HOMOL			;
		BEQ	HOMOL_DISPCK020		;
						;
		LDY	#004			;
						;
HOMOL_DISPCK020 EQU	$			;
		LDA	ENXPSL,X		;
		AND	#00010H			;
		BEQ	HOMOL_DISPCK030		;
						;
		INY				;
		INY				;
						;
HOMOL_DISPCK030 EQU	$			;
		LDA	#00000			;
		STA	HOMOLFLG,Y		;

HOMOL_DISPCK080 EQU	$

		RTS
;
HOMOL_TIM_CALC	EQU	$
		LDY	#007				;ノーマルでないへいほーセット
		TYA
		ASL	A		;[ LDA	#0000EH ]
		CLC					;
		ADC	<ENWRK4,X			;
		TAX					;

HOMOL_T_CALC020 EQU	$
		LDA	HOMOLTM0,X
		BEQ	HOMOL_T_CALC050

		DEC	HOMOLTM0,X

HOMOL_T_CALC050 EQU	$
		DEX
		DEX
		DEY
		BPL	HOMOL_T_CALC020

		LDX	<ENINDX

		RTS
;
HOMOL_S0_TIM	EQU	$
;HOMOLCH0 =		[0]  [1]  [2]  [3]  [4]	 [5]  [6]  [7]
		HEX	002, 002, 003, 003, 002, 002, 002, 002
;			[8]  [9]  [A]  [B]  [C]	 [D]  [E]  [F]
		HEX	002, 002, 002, 002, 002, 003, 003, 002
;			[10] [11] [12] [13] [14] [15] [16] [17]
		HEX	002, 002, 002, 002, 002, 002, 008, 010
;
HOMOL_SUB0	EQU	$
		TYX

		LDA	ENTIM0,X		;ばくだん出す ?
		BNE	HOMOL_SUB0300		; yes: HOMOL_SUB0300

		LDA	#00100H			;ばくだんセットタイマーセット
		STA	ENTIM0,X		;

		LDY	#007			;
		TYA				;
		ASL	A		;[ LDA	#0000EH ]
		CLC				;このチームのHOMOLID0のオフセットインデックス計算
		ADC	<ENWRK4,X		;
		TAX				;

HOMOL_SUB0100	EQU	$
		LDA	HOMOLID0,X		;HOMOLID0の空き ?
		BMI	HOMOL_SUB0200		; yes: HOMOL_SUB0200

		DEX
		DEX
		DEY
		BPL	HOMOL_SUB0100		;
		BRA	HOMOL_SUB0300		;空きなし ?
						; yes: HOMOL_SUB0300

HOMOL_SUB0200	EQU	$
		STZ	HOMOLID0,X		;ばくだん持ってるやつのインデックスクリア
		STZ	HOMOLCH0,X		;ばくだん持ってるやつのキャラパターンクリア
		LDA	#00003			;キャラパターンチェンジタイマーセット
		STA	HOMOLTM0,X		;
		LDX	<ENINDX

HOMOL_SUB0300	EQU	$
		LDA	<ENWRK0,X
		STA	<EWORK0
		LDA	EPWIDX,X
		STA	<EWORK2
		LDA	ENMUKI,X
		STA	<EWORK4

		LDY	#007			;
		TYA				;
		ASL	A		;[ LDA	#0000EH ]
		CLC				;このチームのHOMOLID0のオフセットインデックス計算
		ADC	<ENWRK4,X		;
		TAX				;

HOMOL_SUB0400	EQU	$
		LDA	HOMOLID0,X		;HOMOLID0の空き ?
		BMI	HOMOL_SUB0600		; yes: HOMOL_SUB0600

		LDA	HOMOLCH0,X		;ばくだん運び中ポーズ ?
		CMP	#00011H			;
		BMI	HOMOL_SUB0500		; yes: HOMOL_SUB0500

		JSR	HOMOL_S0_CCHG2
		BRA	HOMOL_SUB0600

HOMOL_SUB0500	EQU	$
		JSR	HOMOL_S0_CCHG

HOMOL_SUB0600	EQU	$
		DEX
		DEX
		DEY
		BPL	HOMOL_SUB0400

		LDX	<ENINDX

HOMOL_S0_C2000	EQU	$

		RTS
;
HOMOL_S0_CCHG2	EQU	$
		LDA	HOMOLTM0,X		;キャラパターンチェンジ ?
		BNE	HOMOL_S0_C2000		;  no: HOMOL_S0_C2000

		INC	HOMOLCH0,X
		PHY
		LDA	HOMOLCH0,X		;いよいよ投げる ?
		CMP	#00016H			;
		BNE	HOMOL_S0_C2600		;  no: HOMOL_S0_C2600

		LDA	HOMOLID0,X
		STA	<EWORK0
		PHX
		LDX	<ENINDX
		LDA	#BOMBX
		JSL	>ENINSR
		BCC	HOMOL_S0_C2500

		LDA	<EWORK0
		ASL	A
		ASL	A
		ASL	A
		ASL	A
		ASL	A
		PHY
		LDY	ENMUKI,X
		BNE	HOMOL_S0_C2400

		EOR	#0FFFFH
		INC	A

HOMOL_S0_C2400	EQU	$
		PLY
		CLC
		ADC	ENXPSL,X
		STA	ENXPSL,Y
		LDA	ENYPSL,X
		SEC
		SBC	#0000AH
		STA	ENYPSL,Y
		LDA	#0001CH
		STA	ENTIM0,Y
		LDA	ENMUKI,X
		STA	ENMUKI,Y
;		LDA	#0110100000100000B	;食えるようにする
;		STA	ENMOD0,Y
		LDA	<RANDM0
		AND	#0001FH
		CLC
		ADC	#00030H
		STA	ENCONT,Y
		M8
		LDA	#07FH
		STA	ENWTSP,Y
		M16
		PLX
		LDA	#00016H
		BRA	HOMOL_S0_C0500

HOMOL_S0_C2500	EQU	$
		PLX				;リトライ
		DEC	HOMOLCH0,X		;
		LDA	#00015H			;
		BRA	HOMOL_S0_C0500		;

HOMOL_S0_C2600	EQU	$
		CMP	#00018H			;爆弾投げ終わり ?
		BNE	HOMOL_S0_C0500		;  no: HOMOL_S0_C0500

		LDA	#0FFFFH			;空きに
		STA	HOMOLID0,X		;
		PLY

HOMOL_S0_C2800	EQU	$

		RTS
;
HOMOL_S0_CCHG	EQU	$
		LDA	HOMOLTM0,X		;キャラパターンチェンジ ?
		BNE	HOMOL_S0_C0800		;  no: HOMOL_S0_C0800

		INC	HOMOLCH0,X
		PHY
		LDA	HOMOLCH0,X		;ばくだん調度からだの前にあるひとつ手前 ?
		CMP	#00009			;
		BNE	HOMOL_S0_C0300		;  no: HOMOL_S0_C0300

		LDA	HOMOLID0,X		;ほしっこのやつ ?
		CMP	<EWORK0			;
		BEQ	HOMOL_S0_C0200		; yes: HOMOL_S0_C0200

		ASL	A			;プレイヤー近くにいる ?
		ASL	A			;
		ASL	A			;
		ASL	A			;
		ASL	A			;
		LDY	<EWORK4			;	;左にばくだん運ぶ ?
		BNE	HOMOL_S0_C0100		;	;  no: HOMOL_S0_C0100
						;
		EOR	#0FFFFH			;
		INC	A			;
						;
HOMOL_S0_C0100	EQU	$			;
		CLC				;
		ADC	<EWORK2			;
		CLC				;
		ADC	#00040H			;
		CMP	#00080H			;
		BCC	HOMOL_S0_C0200		; yes: HOMOL_S0_C0200

		LDA	#00009
		BRA	HOMOL_S0_C0500

HOMOL_S0_C0200	EQU	$
		LDA	#00011H
		STA	HOMOLCH0,X
		BRA	HOMOL_S0_C0500

HOMOL_S0_C0300	EQU	$
		CMP	#0000EH			;サウンド立てる ?
		BNE	HOMOL_S0_C0400		;  no: HOMOL_S0_C0400

		PHA
		LDA	#00055H			;［Ｓ］
		JSL	>SOUND_3_ON
		PLA

HOMOL_S0_C0400	EQU	$
		AND	#0000FH			;受け渡す ?
		BNE	HOMOL_S0_C0500		;  no: HOMOL_S0_C0500

		INC	HOMOLID0,X		;インデックスを次のへいほーのものにする
		LDA	#00004			;
		STA	HOMOLCH0,X		;

HOMOL_S0_C0500	EQU	$
		TAY
		LDA	!HOMOL_S0_TIM,Y
		AND	#000FFH
		STA	HOMOLTM0,X
		PLY

HOMOL_S0_C0800	EQU	$

		RTS
;
HOMOL_SUB1	EQU	$
		TYX

		LDA	ENXPSL,X
		STA	<EWORK0
		LDA	ENMUKI,X
		STA	<EWORK2
		LDA	ENYPSL,X
		STA	<EWORK6
		LDY	#007
		TYA
		ASL	A		;[ LDA	#0000EH ]
		CLC
		ADC	<ENWRK4,X
		TAX

HOMOL_SUB1100	EQU	$
		LDA	HOMOLID0,X
		BPL	HOMOL_SUB1180
		JMP	HOMOL_SUB1800

HOMOL_SUB1180	EQU	$
		PHX
		PHY
		ASL	A
		ASL	A
		ASL	A
		ASL	A
		ASL	A
		LDY	<EWORK2
		BNE	HOMOL_SUB1200

		EOR	#0FFFFH
		INC	A

HOMOL_SUB1200	EQU	$
		CLC
		ADC	<EWORK0
		STA	<EWORK4

		LDA	HOMOLCH0,X		;ばくだん持ってるポーズ ?
		BIT	#0000FH			;
		BEQ	HOMOL_SUB1700		;
		CMP	#00016H			;
		BPL	HOMOL_SUB1700		;  no: HOMOL_SUB1700

		ASL	A
		TAY
		LDA	!HOMOL_BOMB_Y,Y
		CLC
		ADC	<EWORK6
		STA	<EWORK8
		LDA	!HOMOL_BOMB_X,Y
		LDY	<EWORK2			;左にばくだんを流してる ?
		BEQ	HOMOL_SUB1300		; yes: HOMOL_SUB1300

		EOR	#0FFFFH
		INC	A

HOMOL_SUB1300	EQU	$
		CLC
		ADC	<EWORK4
		STA	<EWORK4

		LDX	<ENINDX
		LDA	#BOMBX
		JSL	>ENINSR
		BCS	HOMOL_SUB1400

		PLY
		PLX
		LDX	<ENINDX
		RTS

HOMOL_SUB1400	EQU	$
		LDA	<EWORK4
		STA	ENXPSL,Y
		LDA	<EWORK8
		STA	ENYPSL,Y
		LDA	#00020H
		STA	ENTIM0,Y
		LDA	ENMUKI,X
		STA	ENMUKI,Y
;		LDA	#0110100000100000B	;食えるようにする
;		STA	ENMOD0,Y
		LDA	<RANDM0
		AND	#0001FH
		CLC
		ADC	#00030H
		STA	ENCONT,Y
		M8
		LDA	#07FH
		STA	ENWTSP,Y
		M16
		PLY
		PLX

		LDA	#0001CH
		STA	HOMOLCH0,X
		BRA	HOMOL_SUB1800

HOMOL_SUB1700	EQU	$
		PLY
		PLX

HOMOL_SUB1800	EQU	$
		DEX
		DEX
		DEY
		BMI	HOMOL_SUB1900
		JMP	HOMOL_SUB1100

HOMOL_SUB1900	EQU	$
		LDX	<ENINDX
		LDA	#000C0H
		STA	ENTIM0,X
		LDA	#00044H
		STA	ENTIM1,X
		LDA	#00040H
		STA	ENTIM2,X
		LDA	#00001
		STA	ENWRK6,X
		INC	<ENWRK2,X

		RTS
;
HOMOL_SUB2	EQU	$
		TYX

		LDA	ENTIM2,X
		BNE	HOMOL_SUB2800

		LDY	<ENCONT,X
		CPY	#016H
		BNE	HOMOL_SUB2010

		LDY	#018H
		STY	<ENCONT,X

HOMOL_SUB2010	EQU	$
		LDA	ENTIM0,X
		BNE	HOMOL_SUB2300

		LDY	#007
		TYA
		ASL	A		;[ LDA	#0000EH ]
		CLC
		ADC	<ENWRK4,X
		TAX

HOMOL_SUB2100	EQU	$
		LDA	HOMOLID0,X
		BMI	HOMOL_SUB2200

		LDA	#0FFFFH
		STA	HOMOLID0,X

HOMOL_SUB2200	EQU	$
		DEX
		DEX
		DEY
		BPL	HOMOL_SUB2100

		LDX	<ENINDX
		LDY	#010H
		STY	<ENCONT,X
		STZ	<ENWRK2,X

		RTS

HOMOL_SUB2300	EQU	$
		LDA	ENTIM1,X
		BNE	HOMOL_SUB2800

		LDA	#00004
		STA	ENTIM1,X

		LDA	<ENCONT,X
		CLC
		ADC	ENWRK6,X
		CMP	#00017H
		BEQ	HOMOL_SUB2400
		CMP	#0001CH
		BNE	HOMOL_SUB2600

		LDA	#0001AH
		BRA	HOMOL_SUB2500

HOMOL_SUB2400	EQU	$
		LDA	#00019H

HOMOL_SUB2500	EQU	$
		PHA
		LDA	ENWRK6,X
		EOR	#0FFFFH
		INC	A
		STA	ENWRK6,X
		PLA

HOMOL_SUB2600	EQU	$
		STA	<ENCONT,X

HOMOL_SUB2800	EQU	$

		RTS
;
;************************************************************************
;*		initial ( 鉄球ドスン )					*
;************************************************************************
;
DOSUNIN		EQU	$			;-- dosunin --
		LDA	DOSUNFLG
		BEQ	DOSUNIN0040

		CPX	DOSUNFLG
		BMI	DOSUNIN0020

		STX	DOSUNFLG

DOSUNIN0020	EQU	$
		LDA	DOSUNTRO
		STA	ENTROB,X
		BRA	DOSUNIN0080

DOSUNIN0040	EQU	$
		JSL	>TROBJ_SR_4x4_CL

		STX	DOSUNFLG
		LDA	ENTROB,X
		STA	DOSUNTRO

DOSUNIN0080	EQU	$
		INC	DOSUNSUM
		LDA	#DHEIH
		JSL	>ENINSR
		BCS	DOSUNIN0100

		DEC	DOSUNSUM
		BNE	DOSUNIN0090

		STZ	DOSUNFLG

DOSUNIN0090	EQU	$
		JMP	>ENCLEAR

DOSUNIN0100	EQU	$
		STY	<ENWRK0,X
		LDA	ENYPSL,X
		STA	ENYPSL,Y
		STA	ENWRKC,X
		LDA	#00004
		STA	ENTIM1,Y
		CLC
		ADC	ENXPSL,X
		STA	ENXPSL,Y
		CLC
		ADC	#00008-4
		STA	ENXPSL,X
		STA	R1		;R1 <- スタートＸ　ＰＯＳ．

		LDA	ENYPSL,X	;R2 <- スタートＹ　ＰＯＳ．
		CLC
		ADC	#00030H-10H
		STA	R2
		STZ	R3		;R3 <- Ｘ方向加算値
		LDA	#00010H		;R4 <- Ｙ    ”
		STA	R4

		M_CHIPR KAID_DSPSCK

		LDX	<ENINDX
		LDY	R12
;		CPY	#009H
		CPY	#00BH
		BPL	DOSUNIN0200

		LDA	#08000H
		BRA	DOSUNIN0500

DOSUNIN0200	EQU	$
		LDA	#00010H+03
		SEC
		SBC	R12
		ASL	A
		ASL	A
		ASL	A
		ASL	A

DOSUNIN0500	EQU	$
		STA	ENWRK6,X
		STZ	ENMUKI,X
		LDA	ENYPSL,X
		CLC
		ADC	#00030H
		STA	ENYPSL,X

		CPX	DOSUNFLG
		BNE	DOSUNIN0800

;＊＊＊＊＊＊＊＊＜　ビットマップエリアセット　＞＊＊＊＊＊＊＊＊＊＊
		LDA	#CIPCHD3+00A0H+000	;(R12) <-- 転送元アドレスセット
		STA	R12			;
		LDA	#BANK CIPCHD3+00A0H+000 ;(R13) <-- 転送元バンクセット
		STA	R13			;

		LDA	#00100H			;(R6) <- 倍率セット
		STA	R6			;

		LDA	#00010H
		STA	R8
		STA	R9

		LDY	ENTROB,X
		TYX
		LDA	>TROBJ_PLOT_X,X		;(R3) <- ビットマップ座標＿Ｘセット
		STA	R3			;
		LDA	>TROBJ_PLOT_Y,X		;(R2) <- ビットマップ座標＿Ｙセット
		STA	R2			;

		M_CHIP	C_32_ZOOM

		LDX	<ENINDX

		INC	OBM7WF		;mode 7 OBJ chara DMA "ON"

DOSUNIN0800	EQU	$
		LDA	#00008
		STA	ENBGYP,X

		RTL
;
;************************************************************************
;*		move	( 鉄球ドスン )					*
;************************************************************************
;		ENWRK0	へいほー(DHEIH)の ROUTINE INDEX
;		ENWRK2	ROUTINE MODE INDEX
;		ENWRK4	くさりのたるみ
;		ENWRK6	マスクオフセットＹ　ＰＯＳ．
;		ENWRK8	跳ね返りフラグ
;		ENWRKA	着地フラグ
;		ENWRKC	へいほーのＹ　ＰＯＳ．
;
;		ENTIM0	ストップタイマー
;		ENTIM1	キャラパターンチェンジタイマー
;		ENTIM2	くさり”びびび”タイマー
;
DOSUN_SUB	EQU	$
		WORD	DOSUN_SUB0		;上り初期セット
		WORD	DOSUN_SUB1		;上りチェック
		WORD	DOSUN_SUB2		;下りチェック
		WORD	DOSUN_SUB3		;下り後処理
		WORD	DOSUN_SUB4
;
DOSUNMV		EQU	$			;-- dosunmv --
		JSR	DOSUN_MASK_CALC

		JSR	DOSUN_OAM_SET

		JSL	>ENMDCK

		LDY	ECRSFG,X
		BPL	DOSUNMV0100

		JSL	>PLFLST
		BRA	DOSUNMV0200

DOSUNMV0100	EQU	$
		JSL	>EPCRCK

DOSUNMV0200	EQU	$
		JSL	>DISPCK2		;画面外 ?
		BCC	DOSUNMV0500		;  no: DOSUNMV0500

		LDA	<ENWRK0,X		;へいほー(DHEIH)を消す
		TAX				;
		JSL	>ENCLEAR		;
		LDX	<ENINDX			;

		DEC	DOSUNSUM		;最後の一匹 ?
		BNE	DOSUNMV0300		;  no: DOSUNMV0300

		STZ	DOSUNFLG
		JSL	>TROBJ_CLEAR

DOSUNMV0300	EQU	$
		LDA	#0FFFFH
		STA	ENTROB,X
		JSL	>ENCLEAR

DOSUNMV0500	EQU	$
		JSR	DOSUN_CHAIN_CHK

		TXY
		LDA	<ENWRK2,X
		ASL	A
		TAX
		JSR	(DOSUN_SUB,X)

DOSUNMV0800	EQU	$

		RTL
;
DOSUN_MASK_CALC EQU	$
		LDA	ENSTFG
		ORA	BIRIBIRI
		ORA	ITEMNO
		BNE	DOSUN_M_C0800

		LDY	<ENWRK0,X
		LDA	ENXPSL,Y
		CLC
		ADC	#00008-4
		STA	R1		;R1 <- スタートＸ　ＰＯＳ．

		LDA	ENYPSL,Y	;R2 <- スタートＹ　ＰＯＳ．
		CLC
		ADC	#00030H-10H
		STA	R2
		STZ	R3		;R3 <- Ｘ方向加算値
		LDA	#00010H		;R4 <- Ｙ    ”
		STA	R4

		M_CHIPR KAID_DSPSCK

		LDX	<ENINDX
		LDY	R12
;		CPY	#009H
		CPY	#00BH
		BPL	DOSUNMV1000

		LDA	#08000H
		BRA	DOSUNMV1800

DOSUNMV1000	EQU	$
		LDA	#00010H+03
		SEC
		SBC	R12
		ASL	A
		ASL	A
		ASL	A
		ASL	A

DOSUNMV1800	EQU	$
		STA	ENWRK6,X

DOSUN_M_C0800	EQU	$

		RTS
;
DOSUN_OAM_SET	EQU	$
		LDY	<ENWRK0,X
		LDA	ENYPSL,Y
		SEC
		SBC	ESCCV1
		STA	<EWORK4

		I16
		LDY	ENOAML,X		;マスクＯＡＭセット
		LDA	ENWRK6,X		;
		BPL	DOSUN_O_SET0100		;
						;
		LDA	#08000H			;
		STA	SOAM_DX+0+8*0,Y		;
		STA	SOAM_DX+0+8*1,Y		;
		BRA	DOSUN_O_SET0200		;
						;
DOSUN_O_SET0100 EQU	$			;
		CLC				;
		ADC	<EWORK4			;
		STA	SOAM_DX+2+8*0,Y		;
		STA	SOAM_DX+2+8*1,Y		;
		LDA	SOAM_DX+4+8*0,Y
		AND	#0FE00H
		ORA	#000C0H
		STA	SOAM_DX+4+8*0,Y
		STA	SOAM_DX+4+8*1,Y

DOSUN_O_SET0200 EQU	$
		TYA
		CLC
		ADC	#008*2
		PHA
		TAY
		JSL	>TROBJ_OAM_4x4_I
		IDX8

		I16
		PLA
		CLC
		ADC	#008*4
		TAY

		LDA	ENWRK8,X		;跳ね返り ?
		BEQ	DOSUN_O_SET0240		;  no: DOSUN_O_SET0240

		LDA	<EWORK4
		CLC
		ADC	#0007AH
		BRA	DOSUN_O_SET0260

DOSUN_O_SET0240 EQU	$
		LDA	ENYPSL,X
		SEC
		SBC	ESCCV1

DOSUN_O_SET0260 EQU	$
		STA	<EWORK0
		CLC
		ADC	<ENWRK4,X
		SEC
		SBC	#006+008-00AH
		STA	<EWORK2

		STZ	<EWORK6
		STZ	<EWORK8
		LDA	ENTIM2,X
		BEQ	DOSUN_O_SET0270

		INC	<EWORK6
		LDA	<RANDM0
		STA	<EWORK8

DOSUN_O_SET0270 EQU	$
		LDA	#0000BH
		STA	<EWORKE

DOSUN_O_SET0280 EQU	$
		LDA	<EWORK2
		SEC
		SBC	#0000AH
		STA	<EWORK2
		CMP	<EWORK0
		BPL	DOSUN_O_SET0290
		CMP	<EWORK4
		BPL	DOSUN_O_SET0300

DOSUN_O_SET0290 EQU	$
		LDA	#08000H
		STA	SOAM_DX+0+8*0,Y
		BRA	DOSUN_O_SET0400

DOSUN_O_SET0300 EQU	$
		LDA	<EWORK8
		AND	#00003
		SEC
		SBC	<EWORK6
		STA	<EWORKA
		ADC	<EWORK2
		STA	SOAM_DX+2+8*0,Y
		LDA	SOAM_DX+0+8*0,Y
		CLC
		ADC	<EWORKA
		STA	SOAM_DX+0+8*0,Y

		LDA	<EWORK8
		ROR	A
		STA	<EWORK8

DOSUN_O_SET0400 EQU	$
		TYA
		CLC
		ADC	#00008
		TAY

		DEC	<EWORKE
		BNE	DOSUN_O_SET0280

		I8

		RTS
;
DOSUN_CHAIN_CHK EQU	$
		LDA	ENYPSL,X
		SEC
		SBC	ENWRKC,X
		LSR	A
		STA	<EWORK0
		CLC
		ADC	ENWRKC,X
		STA	<EWORK2
		LDA	PWIDEX
		CLC
		ADC	#00008H
		STA	<EWORK4
		ASL	A
		STA	<EWORK6

		LDA	ENXPSL,X
		CLC
		ADC	#00009
		SEC
		SBC	PCENTX
		STA	<EWORKC
		CLC
		ADC	<EWORK4
		CMP	<EWORK6
		BCS	DOSUN_C_CHK0800

		LDA	PWIDEY
		CLC
		ADC	<EWORK0
		STA	<EWORK8
		ASL	A
		STA	<EWORKA

		LDA	<EWORK2
		SEC
		SBC	PCENTY
		CLC
		ADC	<EWORK8
		CMP	<EWORKA
		BCS	DOSUN_C_CHK0800

		LDA	<EWORK4
		LDY	<EWORKC+1
		BMI	DOSUN_C_CHK0200

		EOR	#0FFFFH
		INC	A

DOSUN_C_CHK0200 EQU	$
		CLC
		ADC	ENXPSL,X
		CLC
		ADC	#00008
		SEC
		SBC	PCENTX
		CLC
		ADC	PLXPSL
		STA	PLXPSL

		JSL	>PLFLST

DOSUN_C_CHK0800 EQU	$

		RTS
;
;
DOSUN_SUB0	EQU	$
		TYX

		LDA	<ENWRK4,X
		BEQ	DOSUN_SUB0500

		LDY	ENWRKA,X		;地面に着いてる ?
		BEQ	DOSUN_SUB0100		;  no: DOSUN_SUB0100

		LDA	ENCBFG,X
		AND	#00001
		BNE	DOSUN_SUB0100

		LDY	<ENWRK0,X
		LDA	#0000CH
		STA	ENCHPT,Y
		LDA	#00005
		STA	ENTIM1,Y
		LDA	#00001
		STA	ENWRK2,Y
		STZ	ENWRKA,X		;着地フラグクリア
		LDY	#002
		STY	<ENWRK2,X

		RTS

DOSUN_SUB0100	EQU	$
		LDA	FRCNT2
		AND	#00001
		BNE	DOSUN_SUB0300

		DEC	<ENWRK4,X

DOSUN_SUB0300	EQU	$

		RTS

DOSUN_SUB0500	EQU	$
		LDA	#0FF80H
		STA	ENYSPD,X

		STZ	ENWRKA,X		;着地フラグクリア
		INC	<ENWRK2,X

		RTS
;
DOSUN_SUB1	EQU	$
		TYX

		LDA	FRCNT2
		AND	#00003
		BNE	DOSUN_SUB1100

		LDA	#0002FH			;［Ｓ］
		JSL	>SOUND_3_ON
;;;;;;;;		LDA	#0001AH			;［Ｓ］
;;;;;;;;		STA	SOUND0

DOSUN_SUB1100	EQU	$
		LDY	<ENWRK0,X
		LDA	ENYPSL,X
		SEC
		SBC	ENYPSL,Y
		CMP	#00028H
		BPL	DOSUN_SUB1800

		STZ	ENYSPD,X
		LDA	#0000CH
		STA	ENCHPT,Y
		LDA	#00005
		STA	ENTIM1,Y
		LDA	#00001
		STA	ENWRK2,Y

		LDA	#00008H
		STA	ENGPOW,X

		INC	<ENWRK2,X

DOSUN_SUB1800	EQU	$

		RTS
;
DOSUN_SUB2	EQU	$
		TYX

		INC	ENGPOW,X
		LDA	#00040H
		CMP	ENGPOW,X
		BPL	DOSUN_SUB2100

		STA	ENGPOW,X

DOSUN_SUB2100	EQU	$
		LDY	<ENWRK0,X
		LDA	#0007AH
		SEC
		SBC	ENYPSL,X
		CLC
		ADC	ENYPSL,Y
		BPL	DOSUN_SUB2200

		CLC
		ADC	ENYPSL,X
		STA	ENYPSL,X

		LDA	#0001BH			;［Ｓ］
		JSL	>SOUND_3_ON
;;;;;;;;		LDA	#00026H			;［Ｓ］
;;;;;;;;		STA	SOUND3

		LDA	ENWRK8,X		;２回目 ?
		BNE	DOSUN_SUB2500		; yes: DOSUN_SUB2500

		INC	ENWRK8,X		;跳ね返りフラグセット
		LDA	#0FF00H
		STA	ENYSPD,X
		LDA	#00010H			;くさり”びびび”タイマーセット
		STA	ENTIM2,X		;

		RTS

DOSUN_SUB2200	EQU	$
		LDA	ENCBFG,X		;地面に着いた ?
		AND	#00001			;
		BEQ	DOSUN_SUB2800		;  no: DOSUN_SUB2800

		INC	ENWRKA,X		;着地フラグセット

		LDA	#DSMK2
		JSL	>EXINSR
		LDA	ECENTX,X
		STA	EXXPSL,Y
		LDA	ENYPSL,X
		CLC
		ADC	#00010H
		STA	EXYPSL,Y
		LDA	#00005
		STA	EXCHPT,Y
		LDA	#00002
		STA	EXTIM0,Y
		LDA	#00020H
		STA	TILTCT
		LDA	#00047H			;［Ｓ］
		JSL	>SOUND_3_ON
;;;;;;;;		LDA	#0001AH			;［Ｓ］
;;;;;;;;		STA	SOUND3

DOSUN_SUB2500	EQU	$
		STZ	ENWRK8,X		;跳ね返りフラグクリア
		STZ	ENYSPD,X
		STZ	ENGPOW,X
		LDA	#00010H			;くさり”びびび”タイマーセット
		STA	ENTIM2,X		;
		INC	<ENWRK2,X

DOSUN_SUB2800	EQU	$

		RTS
;
DOSUN_SUB3	EQU	$
		TYX

		LDY	ENWRKA,X		;地面に着いてる ?
		BEQ	DOSUN_SUB3100		;  no: DOSUN_SUB3100

		LDA	ENCBFG,X
		AND	#00001
		BNE	DOSUN_SUB3100

		STZ	ENWRKA,X		;着地フラグクリア
		DEC	<ENWRK2,X

		RTS

DOSUN_SUB3100	EQU	$
		LDA	<ENWRK4,X
		CLC
		ADC	#00004
		STA	<ENWRK4,X

		LDY	<ENWRK0,X
		LDA	#0007AH
		SEC
		SBC	ENYPSL,X
		CLC
		ADC	ENYPSL,Y
		SEC
		SBC	<ENWRK4,X
		BPL	DOSUN_SUB3800

		CLC
		ADC	<ENWRK4,X
		STA	<ENWRK4,X

		LDA	#00003
		STA	ENWRK2,Y

		LDA	#00020H
		STA	ENTIM0,X

		INC	<ENWRK2,X

DOSUN_SUB3800	EQU	$

		RTS
;
DOSUN_SUB4	EQU	$
		TYX

		LDY	ENWRKA,X		;地面に着いてる ?
		BEQ	DOSUN_SUB4100		;  no: DOSUN_SUB4100

		LDA	ENCBFG,X
		AND	#00001
		BNE	DOSUN_SUB4100

		LDY	<ENWRK0,X
		LDA	#0000CH
		STA	ENCHPT,Y
		LDA	#00005
		STA	ENTIM1,Y
		LDA	#00001
		STA	ENWRK2,Y
		STZ	ENWRKA,X		;着地フラグクリア
		LDY	#002
		STY	<ENWRK2,X

		RTS

DOSUN_SUB4100	EQU	$
		LDA	ENTIM0,X
		BNE	DOSUN_SUB4800

		LDY	<ENWRK0,X
		LDA	ENWRK2,Y
		CMP	#00003
		BEQ	DOSUN_SUB4300
		CMP	#00005
		BNE	DOSUN_SUB4800

		STZ	<ENWRK2,X

		RTS

DOSUN_SUB4300	EQU	$
		LDA	#00005
		STA	ENCONT,Y
		LDA	#00014H
		STA	ENCHPT,Y
		LDA	#00010H
		STA	ENTIM1,Y
		LDA	#00004
		STA	ENWRK2,Y

DOSUN_SUB4800	EQU	$

		RTS
;
;************************************************************************
;*		initial ( 鉄球ドスンへいほー )				*
;************************************************************************
DHEIHIN		EQU	$			;-- dheihin --
		LDA	ENXPSL,X
		AND	#00010H
		LSR	A
		LSR	A
		LSR	A
		STA	ENMUKI,X

		LDA	#0001100010000101B	;範囲クリア有り
		STA	ENMOD2,X

		RTL
;
;************************************************************************
;*		move	( 鉄球ドスンへいほー )				*
;************************************************************************
;		ENWRK2	ROUTINE MODE INDEX
;
;		ENCONT	キャラパターンカウンター
;
;		ENTIM1	キャラパターンチェンジタイマー
;
DHEIH_SUB	EQU	$
		WORD	DHEIH_SUB0		;上げてる
		WORD	DHEIH_SUB1		;落ち始め
		WORD	DHEIH_SUB2		;落ちてる
		WORD	DUMMY_SUB		;
		WORD	DHEIH_SUB4		;上げ始め１
		WORD	DHEIH_SUB5		;上げ始め２
;
DHEIHMV		EQU	$			;-- dheihmv --
		JSL	>ENMDCK

		TXY
		LDA	<ENWRK2,X
		ASL	A
		TAX
		JSR	(DHEIH_SUB,X)

		LDY	<ENWRK2,X
		BEQ	DHEIHMV0300
		CPY	#005
		BMI	DHEIHMV0500

DHEIHMV0300	EQU	$
		LDA	FRCNT2
		AND	#00003
		BNE	DHEIHMV0500

		LDA	#0005AH			;［Ｓ］
		JSL	>SOUND_3_ON

DHEIHMV0500	EQU	$

		RTL
;
DHEIH_SUB0	EQU	$
		TYX

		LDA	ENTIM1,X
		BNE	DHEIH_SUB0800

		LDA	#00004H
		STA	ENTIM1,X

		INC	ENCHPT,X
		LDY	ENCHPT,X
		CPY	#0000CH
		BNE	DHEIH_SUB0800

		STZ	ENCHPT,X

DHEIH_SUB0800	EQU	$

		RTS
;
DHEIH_S1_TIM1	EQU	$-0DH
;ENCHPT =		[0D] [0E] [0F] [10] [11] [12] [13]
		HEX	004, 003, 002, 001, 001, 001, 001
;
;CHPT <- 00CH TIM1 <- 009
DHEIH_SUB1	EQU	$
		TYX

		LDA	ENTIM1,X
		BNE	DHEIH_SUB1800

		INC	ENCHPT,X
		LDY	ENCHPT,X
		CPY	#014H
		BNE	DHEIH_SUB1500

		LDA	#00010H
		STA	ENCHPT,X
		INC	<ENWRK2,X

		RTS

DHEIH_SUB1500	EQU	$
		LDA	!DHEIH_S1_TIM1,Y
		AND	#000FFH
		STA	ENTIM1,X

DHEIH_SUB1800	EQU	$

		RTS
;
DHEIH_SUB2	EQU	$
		TYX

		LDA	ENCHPT,X
		INC	A
		AND	#00003
		ORA	#00010H
		STA	ENCHPT,X

		RTS
;
DHEIH_S4_TIM1	EQU	$-1
		HEX	020,004,004,004
;
;CONT <- 005 CHPT <- 014H TIM1 <- 010H
DHEIH_SUB4	EQU	$
		TYX

		LDA	ENTIM1,X
		BNE	DHEIH_SUB4800

		DEC	<ENCONT,X
		BNE	DHEIH_SUB4100

		LDA	#00008
		STA	ENTIM1,X
		LDY	#00BH
		STY	<ENCONT,X
		STZ	ENCHPT,X
		INC	<ENWRK2,X

		RTS

DHEIH_SUB4100	EQU	$
		LDY	<ENCONT,X
		LDA	!DHEIH_S4_TIM1,Y
		AND	#000FFH
		STA	ENTIM1,X
		LDA	ENCHPT,X
		EOR	#00007
		STA	ENCHPT,X

DHEIH_SUB4800	EQU	$

		RTS
;
DHEIH_S5_TIM1	EQU	$-1
		HEX	004,005,006,007,008,008,008,008,008,008
;
DHEIH_SUB5	EQU	$
		TYX

		LDA	ENTIM1,X
		BNE	DHEIH_SUB5800

		DEC	<ENCONT,X
		BNE	DHEIH_SUB5100

		LDA	#00004
		STA	ENTIM1,X
		STZ	ENCHPT,X
		STZ	<ENWRK2,X

		RTS

DHEIH_SUB5100	EQU	$
		LDY	<ENCONT,X
		LDA	!DHEIH_S5_TIM1,Y
		AND	#000FFH
		STA	ENTIM1,X
		INC	ENCHPT,X

DHEIH_SUB5800	EQU	$

		RTS
;
;************************************************************************
;*		initial ( 宝箱 )					*
;************************************************************************
TRBOXIN		EQU	$			;-- trboxin --
TRBX2IN		EQU	$			;-- trbx2in --
		JSL	>TROBJ_SR_4x4_CL

		LDA	#00100H			;初期倍率セット
		STA	ENWRK6,X		;

		LDY	<ENCONT,X		;中身を絶対出す ?
		BNE	TRBOXIN0100		; yes: TRBOXIN0100

		LDA	ENXPSL,X
		STA	ENWRKA,X
		STA	<EWORK4
		LDA	ENYPSL,X
		STA	ENWRKC,X
		JSL	>EXIST_CHECK_S2		;中身ある ?
		BEQ	TRBOXIN0100		; yes: TRBOXIN0400

		INC	<ENWRK5,X		;中身なしフラグセット

TRBOXIN0100	EQU	$
		LDA	#0FFFAH
		STA	ENBGYP,X

		LDY	BG1TYP			;ふかんコース ?
		CPY	#003			;
		BEQ	TRBOXIN0200		; yes: TRBOXIN0200
		CPY	#00DH			;
		BNE	TRBOXIN0300		;  no: TRBOXIN0300

TRBOXIN0200	EQU	$
		LDY	#004
		STY	<ENWRK1,X
		LDA	#0FFF2H
		STA	ENBGYP,X
		LDA	ENYPSL,X
		CLC
		ADC	#00008
		STA	ENYPSL,X

TRBOXIN0300	EQU	$
		STZ	ENMUKI,X		;向き固定

		JSR	TRBOX_ROT_SET

		RTL
;
;************************************************************************
;*		move	( 宝箱 )					*
;************************************************************************
;B		ENWRK0	プレイヤーＯＮフラグ
;B		ENWRK1	ふかんコースフラグ
;		ENWRK2	ROUTNE MODE INDEX
;B		ENWRK4	ブレークフラグ
;B		ENWRK5	中身なしフラグ
;		ENWRK6	縦倍率
;		ENWRK8	縮小率
;		ENWRKA	セットＸ　ＰＯＳ．
;		ENWRKC	セットＹ　ＰＯＳ．
;
;		ENCONT	中身を絶対出すフラグ
;
;		ENTIM1
;
TRBOX_SUB	EQU	$
		WORD	DUMMY_SUB	;だみ
		WORD	TRBOX_SUB1	;ちぢみ
		WORD	TRBOX_SUB2	;ちょっとのび
		WORD	TRBOX_SUB3	;もとどおり
		WORD	TRBOX_SUB4	;おおちぢみ
		WORD	TRBOX_SUB5	;クリア待ち
		WORD	TRBOX_SUB6	;爆発湧きだし
;
TRBOXMV		EQU	$			;-- trboxmv --
TRBX2MV		EQU	$			;-- trbx2mv --
		JSR	TRBOX_OAM_SET

		JSL	>ENMDCK

		STZ	ENXSPD,X

		JSR	TRBOX_PLCHK

		TXY
		LDA	<ENWRK2,X
		ASL	A
		TAX
		JSR	(TRBOX_SUB,X)

		JSR	TRBOX_ROT_SET

		RTL
;
;EWORK0 <- X POS.
;EWORK2 <- Y POS.
TRBOX_BREAK	EQU	$
		PHX
		PHB
		PHK
		PLB
		LDA	#TRBOX
		JSL	>ENINSR
		BCC	TRBOX_BR0800

		LDA	<EWORK0
		STA	ENXPSL,Y
		LDA	<EWORK2
		STA	ENYPSL,Y

		TYX
		JSL	>TROBJ_SR_4x4
		BCC	TRBOX_BR0700

		LDY	#006
		STY	<ENWRK2,X
		LDA	#00010H+050H
		STA	ENTIM0,X
		LDY	#002			;ブレークフラグセット
		STY	<ENWRK4,X		;
		LDA	#00100H
		STA	ENWRK6,X
		LDA	#0FFFFH
		STA	ENYUSN,X
		LDA	#0010000010000001B	;範囲外クリアなし
		STA	ENMOD2,X		;
		STZ	ENGPOW,X
;
		JSR	TRBOX_ROT_SET

		PLB
		PLX
		SEC
		RTL

TRBOX_BR0700	EQU	$
		JSL	>ENCLEAR

TRBOX_BR0800	EQU	$
		PLB
		PLX
		CLC
		RTL
;
TRBOX_OAM_SET	EQU	$
		LDY	<ENWRK4,X		;本体ある ?
		BNE	TRBOX_O_SET0100		;  no: TRBOX_O_SET0100

		JSL	>TROBJ_OAM_4x4

TRBOX_O_SET0100 EQU	$
TRBOX_PLCHK0000 EQU	$

		RTS
;
TRBOX_PUSH_XSPD EQU	$
		WORD	00040H,0FFC0H
TRBOX_CHK_YWIDE EQU	$
		WORD	00018H,0001CH
;
TRBOX_PLCHK	EQU	$
		LDY	<ENWRK4,X		;本体ある ?
		BNE	TRBOX_PLCHK0000		;  no: TRBOX_PLCHK0000

		LDY	<ENWRK1,X
		TYA
		LSR	A
		TAY
		LDA	!TRBOX_CHK_YWIDE,Y
		STA	R0
		LDA	ENWRK6,X
		STA	R6

		M_CHIP	MULTIPLY

		LDX	<ENINDX
		LDY	<ENWRK0,X		;プレイヤー乗ってる ?
		BEQ	TRBOX_PLCHK1100		;  no: TRBOX_PLCHK1100

		LDA	PLDOSN
		BNE	TRBOX_PLCHK0300

		LDY	PLYSPD+1
		BMI	TRBOX_PLCHK0800

		LDA	EWIDEX,X		;
		CLC				;
		ADC	PWIDEX			;
		ASL	A			;
		STA	<EWORK2			;
		LSR	A
		CLC
		ADC	EPWIDX,X		;
		CMP	<EWORK2			;
		BCS	TRBOX_PLCHK0800		;

		INC	ONLFFG

TRBOX_PLCHK0300 EQU	$
		LDA	PLBGCR			;プレイヤーの足がついてる ?
		AND	#0000000000000111B	;
		BNE	TRBOX_PLCHK0900		; yes: TRBOX_PLCHK0900

		LDA	ENYPSL,X
		CLC
		ADC	#00010H
		SEC
		SBC	R0
		SEC
		SBC	#0001EH
		STA	PLYPSL

		RTS

TRBOX_PLCHK0800 EQU	$
		LDY	#000
		STY	<ENWRK0,X		;プレイヤーＯＮフラグクリア

		LDY	#003
		STY	<ENWRK2,X

		LDY	ECRSFG,X
		BMI	TRBOX_PLCHK0900

		PLA
		STA	<EWORK0
		JSL	>EPCRCK
		LDA	<EWORK0
		PHA

TRBOX_PLCHK0900 EQU	$

		RTS

TRBOX_PLCHK1100 EQU	$
		LDA	EWIDEX,X		;プレイヤー乗ってきた ?
		CLC				;
		ADC	PWIDEX			;
		STA	<EWORK0			;
		ASL	A			;
		STA	<EWORK2			;
		LDA	EPWIDX,X		;
		CLC				;
		ADC	<EWORK0			;
		CMP	<EWORK2			;
		BCC	TRBOX_PLCHK1200		;
						;
TRBOX_PLCHK1180 EQU	$			;
		JMP	TRBOX_PLCHK1800		;
						;
TRBOX_PLCHK1200 EQU	$			;
		LDA	R0			;
		CLC				;
		ADC	#00020H			;
		STA	<EWORK4			;
		SEC				;
		SBC	#00008			;
		STA	<EWORK6			;
						;
		LDA	ENYPSL,X		;
		CLC				;
		ADC	#00010H			;
		SEC				;
		SBC	PLYPSL			;
		BMI	TRBOX_PLCHK1180		;
						;
		CMP	<EWORK4			;
		BPL	TRBOX_PLCHK1180		;  no: TRBOX_PLCHK1800
		CMP	<EWORK6			;
		BMI	TRBOX_PLCHK1700		;
						;
		LDA	PLBGCR			;	;地面についてる ?
		AND	#0000000000000111B	;	;
		BNE	TRBOX_PLCHK1180		;

		LDY	PLYSPD+1		;
		BMI	TRBOX_PLCHK1180

		LDY	PLDOSN			;どすん ?
		BNE	TRBOX_PLCHK1300		; yes: TRBOX_PLCHK1300

		INC	ONLFFG
		LDY	#001
		BRA	TRBOX_PLCHK1500

TRBOX_PLCHK1300 EQU	$
		LDA	#00020H			;縮小率セット
		STA	ENWRK8,X
		LDY	#004

TRBOX_PLCHK1500 EQU	$
		STY	<ENWRK2,X

		STZ	PLYSPD
		LDA	ENYPSL,X
		CLC
		ADC	#00010H-1EH
		SEC
		SBC	R0
;		SEC
;		SBC	#0001EH
		STA	PLYPSL

		INC	<ENWRK0,X		;プレイヤーＯＮフラグセット
		BRA	TRBOX_PLCHK1180

TRBOX_PLCHK1700 EQU	$
		JSR	TRBOX_PUSH

TRBOX_PLCHK1800 EQU	$
		LDY	ECRSFG,X		;敵と接触した ?
		BMI	TRBOX_PLCHK1900		;  no: TRBOX_PLCHK1900

		PLA
		STA	<EWORK0
		JSL	>EPCRCK
		LDA	<EWORK0
		PHA

TRBOX_PLCHK1900 EQU	$
TRBOX_PUSH0000	EQU	$

		RTS
;
TRBOX_PUSH	EQU	$
		LDA	PLXSPD
		BEQ	TRBOX_PUSH0000

		EOR	EPWIDX,X		;プレイヤー向かってきてる ?
		BMI	TRBOX_PUSH0000		;  no: TRBOX_PUSH0000

		LDA	#00160H
		STA	EGOPSP

		LDA	EWIDEX,X		;プレイヤー横補正 ?
		CLC				;
		ADC	PWIDEX			;
		DEC	A			;
		DEC	A			;
		LDY	EPXMUK,X		;
		BNE	TRBOX_PUSH0300		;

		EOR	#0FFFFH
		INC	A

TRBOX_PUSH0300	EQU	$
		CLC
		ADC	EPWIDX,X
		CLC
		ADC	PLXPSL
		STA	PLXPSL

		STZ	PLXSPD
		STZ	PLMVSP

		LDA	KEYC1L+1
		AND	#00003H
		BEQ	TRBOX_PUSH0800
		AND	#00001
		DEC	A
		EOR	EPWIDX,X		;プレイヤー向かってきてる ?
		BMI	TRBOX_PUSH0800		;  no: TRBOX_PUSH0800

		LDA	PLNAGE			;プレイヤー投げてる ?
		ORA	BERFLG			;プレイヤー舌を出してる ?
		BNE	TRBOX_PUSH0800		; yes: TRBOX_PUSH0800

		INC	PUSHFG			;敵押しフラグ”ＯＮ”

		LDY	EPXMUK,X
		LDA	!TRBOX_PUSH_XSPD,Y
		STA	ENXSPD,X
		STA	PLXSPD
		STA	PLMVSP

		JSL	>TRBOX_SMK0_SET

		INC	PSPUSH			;押しカウンターセット

TRBOX_PUSH0800	EQU	$

		RTS
;
SMK01_XSPD	EQU	$
		WORD	0FFC0H,00040H
;
TRBOX_SMK0_SET	EQU	$
		LDA	FRCNT2
		AND	#0000FH
		BNE	TRBOX_S_SET0800

		PHB
		PHK
		PLB
;		LDA	#0001FH			;［Ｓ］
		LDA	#00059H			;［Ｓ］
		JSL	>SOUND_3_ON

		LDY	EPXMUK,X
		LDA	!SMK01_XSPD,Y
		STA	<EWORK0

		LDA	#SMK01
		JSL	>EXINSR
;
		LDA	<RANDM0
		AND	#00007H
		SEC
		SBC	#00004H
		CLC
		ADC	ENXPSL,X
		STA	EXXPSL,Y
		LDA	ENYPSL,X
		CLC
		ADC	#00004H
		STA	EXYPSL,Y
		LDA	#00008
		STA	EXTIM0,Y
		LDA	#00003
		STA	EXWRK0,Y
;;;;;;;;		LDA	#00004
;;;;;;;;		STA	EXTIM0,Y
;;;;;;;;		STA	EXWRK0,Y
		LDA	<EWORK0
		STA	EXXSPD,Y
		LDA	#0FF80H
		STA	EXYSPD,Y
		LDA	EPXMUK,X
		AND	#000FFH
		EOR	#00002
		STA	EXMUKI,Y
		PLB

TRBOX_S_SET0800 EQU	$

		RTL
;
TRBOX_CHAR_BNK	EQU	$
		WORD	BANK CIPCHD3+2080H+000
		WORD	BANK CIPCHD3+20A0H+000
		WORD	BANK CIPCHD2+6060H+000
		WORD	BANK CIPCHD3+20A0H+000
TRBOX_CHAR	EQU	$
		WORD	CIPCHD3+2080H+000
		WORD	CIPCHD3+20A0H+000
		WORD	CIPCHD2+6060H+000
		WORD	CIPCHD3+20A0H+000
;
TRBOX_ROT_SET	EQU	$
		LDA	ENMODE,X
		BEQ	TRBOX_R_SET0800

		LDA	ENWRK6,X		;(R11) <- 縦倍率セット
		STA	R11			;

		LDA	#00200H			;(R6) <- 横倍率セット
		SEC				;
		SBC	ENWRK6,X		;
		LSR	A			;
		LSR	A			;
		LSR	A			;
		LSR	A			;
		CLC				;
		ADC	#00100H			;
		STA	R6			;

		M8
		LDA	<ENWRK1,X
		CLC
		ADC	<ENWRK4,X
		TAY
		M16
		TYA
		BIT	#00002
		BEQ	TRBOX_R_SET0200

		LDA	#00100H
		STA	R6

TRBOX_R_SET0200 EQU	$
		LDA	!TRBOX_CHAR_BNK,Y	;chara data bank set
		STA	R13
		LDA	!TRBOX_CHAR,Y		;chara data address set
		STA	R12

		LDA	#00010H			;(R8) <- 中心Ｘ　ＰＯＳ．
		STA	R8			;
		ASL	A
		STA	R9			;(R9) <- 中心Ｙ　ＰＯＳ．

		LDY	ENTROB,X
		TYX
		LDA	>TROBJ_PLOT_X,X		;回転エリアＸ　ＰＯＳ．セット
		STA	R3			;
		LDA	>TROBJ_PLOT_Y,X		;回転エリアＹ　ＰＯＳ．セット
		STA	R2			;

		M_CHIP	C_32_ZOOM_XY

		LDX	<ENINDX

		INC	OBM7WF			;mode 7 OBJ chara DMA "ON"

TRBOX_R_SET0800 EQU	$

		RTS
;
TRBOX_SUB1	EQU	$
		TYX

		LDA	ENWRK6,X
		SEC
		SBC	#00010H
		CMP	#000F0H
		BPL	TRBOX_SUB2500

		INC	<ENWRK2,X
		LDA	#000F0H
		BRA	TRBOX_SUB2500
;
TRBOX_SUB2	EQU	$
		TYX

		LDA	ENWRK6,X
		CLC
		ADC	#00008H
		CMP	#000E0H
		BMI	TRBOX_SUB2500

		LDA	#000E0H

TRBOX_SUB2500	EQU	$
		STA	ENWRK6,X

		RTS
;
TRBOX_SUB3	EQU	$
		TYX

		LDA	ENWRK6,X
		CLC
		ADC	#00004
		CMP	#00100H
		BMI	TRBOX_SUB2500

		STZ	<ENWRK2,X

		LDA	#00100H
		BRA	TRBOX_SUB2500
;
TRBOX_SUB4	EQU	$
		TYX

		LDA	ENWRK8,X
		DEC	A
		BEQ	TRBOX_SUB4100

		STA	ENWRK8,X

TRBOX_SUB4100	EQU	$
		LDA	ENWRK6,X
		SEC
		SBC	ENWRK8,X
		CMP	#00080H
		BMI	TRBOX_SUB4500

		STA	ENWRK6,X

TRBOX_SUB4300	EQU	$

		RTS

TRBOX_SUB4500	EQU	$
		JSR	TRBBR_SET

		INC	<ENWRK2,X

		LDY	<ENWRK5,X		;中身はいってる ?
		BNE	TRBOX_SUB4300		;  no: TRBOX_SUB4300

		LDA	ENMYNO,X		;鍵を出す ?
		CMP	#TRBOX			;
		BNE	TRBOX_SUB4700		; yes: TRBOX_SUB4700

		LDY	<ENCONT,X		;中身を絶対出す ?
		BNE	TRBOX_SUB4600		; yes: TRBOX_SUB4600

		LDA	ENWRKA,X
		STA	<EWORK4
		LDA	ENWRKC,X
		JSL	>NON_EXIST_SET2

TRBOX_SUB4600	EQU	$
		JSL	>TRBOX_TIME_SET

		RTS

TRBOX_SUB4700	EQU	$
		JMP	TRBOX_KEY_SET
;
TRBOX_BR_XPOS	EQU	$
		WORD	0FFF2H,0FFF4H,00000H,0000AH,0000DH,00000H
TRBOX_BR_YPOS	EQU	$
		WORD	00000H,0FFF4H,0FFF2H,0FFF4H,00000H,00000H
TRBOX_BR_CHPT	EQU	$
		WORD	00000H,0000EH,0000CH,0000EH,00012H,0000CH
TRBOX_BR_XSPD	EQU	$
		WORD	0FC00H,0FE00H,00000H,00200H,00400H,00000H
TRBOX_BR_YSPD	EQU	$
		WORD	0FF00H,0FE00H,0FC80H,0FE00H,0FF00H,00000H
;
TRBBR_SET	EQU	$
		PHX
		LDA	ENTROB,X
		TAX
		LDA	>TROBJ_CHAR_NO,X
		PLX
		AND	#0000FH
		STA	<EWORKE
		LDA	<RANDM0
		STA	<EWORKC

		LDY	#00AH

TRBOX_SET0100	EQU	$
		LDA	TRBOX_BR_XPOS,Y
		STA	<EWORK0
		LDA	TRBOX_BR_YPOS,Y
		STA	<EWORK2
		LDA	TRBOX_BR_CHPT,Y
		STA	<EWORK4
		LDA	TRBOX_BR_XSPD,Y
		STA	<EWORK6
		LDA	TRBOX_BR_YSPD,Y
		STA	<EWORK8
		PHY

		LDA	#TRBBR
		JSL	>EXINSR
		LDA	ENXPSL,X
		CLC
		ADC	<EWORK0
		STA	EXXPSL,Y
		LDA	ENYPSL,X
		CLC
		ADC	<EWORK2
		STA	EXYPSL,Y

		LDA	<EWORK4
		STA	EXWRK2,Y

		LDA	#00050H
		STA	EXTIM0,Y

		LDA	#00003
		STA	EXTIM1,Y
		STA	EXWRKA,Y

		LDA	<EWORKE
		STA	EXWRK4,Y

		LDA	<EWORK6
		STA	EXXSPD,Y

		LDA	<EWORK8
		STA	EXYSPD,Y

		LDA	#00040H
		STA	EXXPOW,Y
		LDA	<EWORKC
		AND	#00002
		STA	EXMUKI,Y

		LDA	<EWORKC
		ROR	A
		STA	<EWORKC

		PLY
		DEY
		DEY
		BPL	TRBOX_SET0100

		LDY	#002			;ブレークフラグセット
		STY	<ENWRK4,X		;
		LDA	#00100H
		STA	ENWRK6,X
		LDA	#00060H
		STA	ENTIM0,X
		LDA	#0FFFFH
		STA	ENYUSN,X
		LDA	#0010000010000001B	;範囲外クリアなし
		STA	ENMOD2,X		;

		RTS
;
TRBOX_COIN1_XSP EQU	$
		WORD	00241H,0FDBFH,00195H,0FE6BH,0009BH,0FF65H
TRBOX_COIN1_YSP EQU	$
		WORD	0FEEFH,0FEEFH,0FE11H,0FE11H,0FD94H,0FD94H
;
TRBOX_COIN_SET	EQU	$
		PHB
		PHK
		PLB
		LDY	#00AH

TRBOX_C_SET0100 EQU	$
		LDA	!TRBOX_COIN1_XSP,Y
		STA	<EWORK0
		LDA	!TRBOX_COIN1_YSP,Y
		STA	<EWORK2
		PHY

		LDA	#COIN1
		JSL	>ENINSR_I
		BCC	TRBOX_C_SET0200

		LDA	ENXPSL,X
		STA	ENXPSL,Y
		LDA	ENYPSL,X
		DEC	A
		DEC	A
		STA	ENYPSL,Y
		LDA	<EWORK0
		STA	ENXSPD,Y
		LDA	<EWORK2
		STA	ENYSPD,Y

		PLY
		DEY
		DEY
		BPL	TRBOX_C_SET0100

		PLB

		RTL

TRBOX_C_SET0200 EQU	$
TRBOX_T_SET0200 EQU	$
		PLB
		PLY
		RTL
;
TRBOX_TIME_SET	EQU	$
		PHB
		PHK
		PLB
		LDA	TIMER
		STA	<EWORK4

		LDY	#00AH

TRBOX_T_SET0100 EQU	$
		LDA	<EWORK4			;３０秒分ある ?
		CLC				;
		ADC	#0000AH			;
		CMP	#(01EH+1)*0AH		;
		BPL	TRBOX_C_SET0100		; yes: TRBOX_C_SET0100

		STA	<EWORK4

		LDA	!TRBOX_COIN1_XSP,Y
		STA	<EWORK0
		LDA	!TRBOX_COIN1_YSP,Y
		STA	<EWORK2
		PHY

		LDA	#TIMKN
		JSL	>ENINSR_I
		BCC	TRBOX_T_SET0200

		LDA	ENXPSL,X
		STA	ENXPSL,Y
		LDA	ENYPSL,X
		DEC	A
		DEC	A
		STA	ENYPSL,Y
		LDA	<EWORK0
		STA	ENXSPD,Y
		LDA	<EWORK2
		STA	ENYSPD,Y

		LDA	#040H*6
		STA	ENTIM0,Y
		LDA	#00020H
		STA	ENTIM2,Y

		PLY
		DEY
		DEY
		BPL	TRBOX_T_SET0100

		PLB

		RTL
;
TRBOX_KEY_XSPD	EQU	$
		WORD	00200H,0FE00H
;
TRBOX_KEY_SET	EQU	$
		LDY	PLCMKI
		LDA	!TRBOX_KEY_XSPD,Y
		STA	<EWORK0

		LDA	#DRKEY
		JSL	>ENINSR_I
		BCC	TRBOX_K_SET0800

		LDA	ENXPSL,X
		STA	ENXPSL,Y
		LDA	ENYPSL,X
		STA	ENYPSL,Y
		LDA	<EWORK0
		STA	ENXSPD,Y
		LDA	#0FB00H
		STA	ENYSPD,Y
		LDA	#00001
		STA	ENSHOT,Y
		LDA	ENWRKA,X		;存在ビットクリアポジションセット
		STA	ENWRKA,Y		;
		LDA	ENWRKC,X		;
		STA	ENWRKC,Y		;

TRBOX_K_SET0800 EQU	$

		RTS
;
TRBOX_SUB5	EQU	$
		TYX

		LDA	ENTIM0,X
		BNE	TRBOX_SUB5800

TRBOX_SUB6000	EQU	$
		JSL	>ENCLEAR_NORETN

TRBOX_SUB5800	EQU	$

		RTS
;
TRBOX_SUB6	EQU	$
		TYX

		LDA	ENTIM0,X
		BEQ	TRBOX_SUB6000

		CMP	#00050H
		BMI	TRBOX_SUB6800

		LDA	#TRBBR
		JSL	>EXINSR

		LDA	<RANDM0
		AND	#00078H
		SEC
		SBC	#00040H
		CLC
		ADC	ENXPSL,X
		STA	EXXPSL,Y
		LDA	ENYPSL,X
		STA	EXYPSL,Y

		LDA	#00050H
		STA	EXTIM0,Y

		PHX
		LDA	ENTROB,X
		TAX
		LDA	>TROBJ_CHAR_NO,X
		PLX
		AND	#0000FH
		STA	EXWRK4,Y

		LDA	<RANDM0
		AND	#007FFH
		SEC
		SBC	#00400H
		STA	EXXSPD,Y

		LDA	<RANDM0-1
		AND	#003FFH
		CLC
		ADC	#00600H
		EOR	#0FFFFH
		INC	A
		STA	EXYSPD,Y

		LDA	<RANDM0
		AND	#00007H
		CLC
		ADC	#00002
		STA	EXWRKA,Y
		STA	EXTIM1,Y

		LDA	#00004H
		STA	EXXPOW,Y

TRBOX_SUB6800	EQU	$

		RTS
;
;************************************************************************
;*		initial ( 巻き上げお邪魔どすん（本体）)			*
;************************************************************************
MAKI0IN		EQU	$			;-- maki0in --
		LDA	#MAKI1
		JSL	>ENINSR
		BCC	MAKI0IN0100

		TYX
		JSL	>TROBJ_SR_4x4
		BCS	MAKI0IN0300

		JSL	>ENCLEAR

		LDX	<ENINDX

MAKI0IN0100	EQU	$
		JMP	>ENCLEAR

MAKI0IN0300	EQU	$
		PHX
		JSR	MAKI1_ROT_SET_I
		PLY
		LDX	<ENINDX
		LDA	ENXPSL,X
		STA	ENXPSL,Y
		LDA	ENYPSL,X
		STA	ENYPSL,Y
		STA	ENWRKC,X
		TXA
		STA	ENWRK0,Y
		STY	<ENWRK0,X

		STZ	ENMUKI,X		;向き固定

		LDA	#00007
		STA	ENBGYP,X

		LDA	ENXPSL,X	;R1 <- スタートＸ　ＰＯＳ．
		CLC
		ADC	#0000EH
		STA	R1		;
		SEC
		SBC	#00008
		STA	ENXPSL,X

		LDA	ENYPSL,X	;R2 <- スタートＹ　ＰＯＳ．
		CLC
		ADC	#00040H-10h
		STA	R2

		STZ	R3		;R3 <- Ｘ方向加算値
		LDA	#00010H		;R4 <- Ｙ    ”
		STA	R4

		M_CHIPR KAID_DSPSCK

		LDX	<ENINDX
		LDY	R12
		CPY	#00CH
		BPL	MAKI0IN0200

		LDA	#08000H
		STA	ENWRK6,X

		XBA	;[ LDA	#00080H ]
		BRA	MAKI0IN0600

MAKI0IN0200	EQU	$
		LDA	#00010H+00040H/10H
		SEC
		SBC	R12
		ASL	A
		ASL	A
		ASL	A
		ASL	A

MAKI0IN0500	EQU	$
		STA	ENWRK6,X

MAKI0IN0600	EQU	$
		CLC
		ADC	ENYPSL,X
		SEC
		SBC	#00010H
		STA	ENYPSL,X
		LDY	<ENWRK0,X
		STA	ENWRK6,Y
		STA	<ENWRK4,X		;巻き上げチェックＹ　ＰＯＳ．セット
		STZ	ENMUKI,X

		LDA	#0000FH			;ダメージカウンター初期セット
		SEC				;
		SBC	R12			;
		CMP	#003			;
		BMI	MAKI0IN0700		;
						;
		LDA	#00003			;
						;
MAKI0IN0700	EQU	$			;
		STA	ENWRKA,X		;

		RTL
;
;************************************************************************
;*		move	( 巻き上げお邪魔どすん（本体）)			*
;************************************************************************
;		ENWRK0	滑車(MAKI1)の ROUTINE INDEX
;		ENWRK2	ROUTINE MODE INDEX
;		ENWRK4	巻き上げチェックＹ　ＰＯＳ．
;		ENWRK6	マスクオフセットＹ　ＰＯＳ．
;		ENWRK8	Ｇ　ＰＯＷＥＲ加算値
;		ENWRKA	ダメージカウンター
;		ENWRKC	滑車のＹ　ＰＯＳ．
;
;		ENCONT
;
;		ENTIM0
;		ENTIM1
;		ENTIM2	くさり”びびび”タイマー
;
MAKI0_SUB	EQU	$
		WORD	DUMMY_SUB		;
		WORD	MAKI0_SUB1		;上りチェック
		WORD	MAKI0_SUB2		;巻きストップ
		WORD	MAKI0_SUB3		;下りチェック
;
MAKI0MV		EQU	$			;-- maki0mv --
		JSR	MAKI0_OAM_SET

		JSL	>ENMDCK

		JSR	MAKI0_CHAIN_CHK

		JSL	>DISPCK4		;画面内 ?
		BCC	MAKI0MV0100		; yes: MAKI0MV0100

		LDA	<ENWRK0,X		;滑車(MAKI1)を消す
		TAX				;
		JSL	>ENCLEAR		;
		LDX	<ENINDX			;

		JMP	>ENCLEAR

MAKI0MV0100	EQU	$
		TXY
		LDA	<ENWRK2,X
		ASL	A
		TAX
		JSR	(MAKI0_SUB,X)

		JSL	>POBBGCR

		LDY	ECRSFG,X		;赤ちゃんと衝突した ?
		DEY				;
		BNE	MAKI0MV0700		;  no: MAKI0MV0700

		LDA	ECENTX+BABY_INDEX	;赤ちゃん向かってきてる ?
		SEC				;
		SBC	ECENTX,X		;
		STA	<EWORK0			;
		EOR	ENXSPD+BABY_INDEX	;
		BPL	MAKI0MV0600		;  no: MAKI0MV0600

		LDA	EWIDEX,X

MAKI0MV0400	EQU	$
		CLC
		ADC	EWIDEX+BABY_INDEX
		LDY	<EWORK0+1
		BPL	MAKI0MV0500

		EOR	#0FFFFH
		INC	A

MAKI0MV0500	EQU	$
		CLC
		ADC	ECENTX,X
		SEC
		SBC	ECENTX+BABY_INDEX
		CLC
		ADC	ENXPSL+BABY_INDEX
		STA	ENXPSL+BABY_INDEX

		LDA	ENXSPD+BABY_INDEX
		EOR	#0FFFFH
		INC	A
		STA	ENXSPD+BABY_INDEX

MAKI0MV0600	EQU	$

		RTL

MAKI0MV0700	EQU	$
		JSL	>EPCRCK

		RTL
;
MAKI0_OAM_SET	EQU	$
		LDY	<ENWRK0,X
		LDA	ENYPSL,Y
		SEC
		SBC	ESCCV1
		STA	<EWORK4

		I16
		LDY	ENOAML,X		;マスクＯＡＭセット
		LDA	ENWRK6,X		;
		BPL	MAKI0_O_SET0100		;
						;
		LDA	#08000H			;
		STA	SOAM_DX+0+8*0,Y		;
		STA	SOAM_DX+0+8*1,Y		;
		BRA	MAKI0_O_SET0200		;
						;
MAKI0_O_SET0100 EQU	$			;
		CLC				;
		ADC	<EWORK4			;
		STA	SOAM_DX+2+8*0,Y		;
		STA	SOAM_DX+2+8*1,Y		;

MAKI0_O_SET0200 EQU	$
		TYA
		CLC
		ADC	#008*09H
		TAY

		LDA	ENYPSL,X
		SEC
		SBC	#00018H+2
		SEC
		SBC	ESCCV1
		STA	<EWORK2

		STZ	<EWORK6
		STZ	<EWORK8
		LDA	ENTIM2,X		;ゆらす ?
		BEQ	MAKI0_O_SET0270		;  no: MAKI0_O_SET0270

		INC	<EWORK6
		LDA	<RANDM0
		STA	<EWORK8

MAKI0_O_SET0270 EQU	$
		LDA	#00005H
		STA	<EWORKE

MAKI0_O_SET0280 EQU	$
		LDA	<EWORK2
		SEC
		SBC	#00010H
		STA	<EWORK2
		CMP	<EWORK4
		BPL	MAKI0_O_SET0300

MAKI0_O_SET0290 EQU	$
		LDA	#08000H
		STA	SOAM_DX+0+8*0,Y
		BRA	MAKI0_O_SET0400

MAKI0_O_SET0300 EQU	$
		LDA	<EWORK8
		AND	#00003
		SEC
		SBC	<EWORK6
		STA	<EWORKA
		ADC	<EWORK2
		STA	SOAM_DX+2+8*0,Y
		LDA	SOAM_DX+0+8*0,Y
		CLC
		ADC	<EWORKA
		STA	SOAM_DX+0+8*0,Y

		LDA	<EWORK8
		ROR	A
		STA	<EWORK8

MAKI0_O_SET0400 EQU	$
		TYA
		CLC
		ADC	#00008
		TAY

		DEC	<EWORKE
		BNE	MAKI0_O_SET0280

		I8

		RTS
;
MAKI0_CHAIN_CHK EQU	$
		LDA	PWIDEX
		STA	R0
		LDA	PCENTX
		STA	R1
		LDA	PWIDEY
		STA	R2
		LDA	PCENTY
		STA	R3
		JSR	MAKI0_C_CHK_SB
		BCS	MAKI0_C_CHK0800

		LDA	<EWORK4
		LDY	<EWORKC+1
		BMI	MAKI0_C_CHK0200

		EOR	#0FFFFH
		INC	A

MAKI0_C_CHK0200 EQU	$
		CLC
		ADC	ENXPSL,X
		CLC
		ADC	#00008
		SEC
		SBC	PCENTX
		CLC
		ADC	PLXPSL
		STA	PLXPSL

		JSL	>PLFLST

MAKI0_C_CHK0800 EQU	$
		LDA	EWIDEX+BABY_INDEX
		STA	R0
		LDA	ECENTX+BABY_INDEX
		STA	R1
		LDA	EWIDEY+BABY_INDEX
		STA	R2
		LDA	ECENTY+BABY_INDEX
		STA	R3
		JSR	MAKI0_C_CHK_SB
		BCS	MAKI0_C_CHK1800

		LDA	<EWORKC			;近づいてる ?
		EOR	#0FFFFH			;
		INC	A			;
		STA	<EWORK0			;
		EOR	ENXSPD+BABY_INDEX	;
		BPL	MAKI0_C_CHK1800		;  no: MAKI0_C_CHK1800

		LDA	#00008
		JSL	>MAKI0MV0400

MAKI0_C_CHK1800 EQU	$

		RTS
;
MAKI0_C_CHK_SB	EQU	$
		LDA	ENYPSL,X
		SEC
		SBC	ENWRKC,X
		LSR	A
		STA	<EWORK0
		CLC
		ADC	ENWRKC,X
		STA	<EWORK2
		LDA	R0
		CLC
		ADC	#00008H
		STA	<EWORK4
		ASL	A
		STA	<EWORK6

		LDA	ENXPSL,X
		CLC
		ADC	#00009
		SEC
		SBC	R1
		STA	<EWORKC
		CLC
		ADC	<EWORK4
		CMP	<EWORK6
		BCS	MAKI0_C_C_S0800

		LDA	R2
		CLC
		ADC	<EWORK0
		STA	<EWORK8
		ASL	A
		STA	<EWORKA

		LDA	<EWORK2
		SEC
		SBC	R3
		CLC
		ADC	<EWORK8
		CMP	<EWORKA

MAKI0_C_C_S0800 EQU	$

		RTS
;
MAKI0_SUB1	EQU	$
		TYX

		LDA	<ENWRK4,X		;巻き上げ切った ?
		CMP	ENYPSL,X		;
		BMI	MAKI0_SUB1800		;  no: MAKI0_SUB1800

		STA	ENYPSL,X
		STZ	ENYSPD,X
		LDA	#00040H*2		;ストップタイマーセット
		STA	ENTIM0,X		;
		INC	<ENWRK2,X

MAKI0_SUB1800	EQU	$

		RTS
;
MAKI0_SUB2	EQU	$
		TYX

		LDA	ENTIM0,X		;ストップ ?
		BNE	MAKI0_SUB2800		; yes: MAKI0_SUB2800

		LDA	#00010H
		STA	ENYSPD,X

		LDA	#00016H
		CLC
		ADC	<ENWRK4,X
		STA	<ENWRK4,X

		INC	ENWRKA,X

		LDA	#00040H*2
		STA	ENTIM0,X

		STZ	ENWRK8,X
		INC	<ENWRK2,X

MAKI0_SUB2800	EQU	$
MAKI0_SUB3000	EQU	$

		RTS
;
MAKI0_SUB3	EQU	$
		TYX

		LDA	ENTIM0,X
		BNE	MAKI0_SUB3000

		LDA	ENWRK8,X
		CLC
		ADC	#00020H
		CMP	#04000H
		BMI	MAKI0_SUB3080

		LDA	#04000H

MAKI0_SUB3080	EQU	$
		STA	ENWRK8,X

		AND	#0FF00H
		XBA
		STA	ENGPOW,X

		LDA	ENCBFG,X
		AND	#00001
		BEQ	MAKI0_SUB3300

		LDA	#DSMK2
		JSL	>EXINSR
		LDA	<ENWRK4,X
		STA	ENYPSL,X
		CLC
		ADC	#00010H
		STA	EXYPSL,Y
		LDA	ENXPSL,X
		CLC
		ADC	#00008
		STA	EXXPSL,Y
		LDA	#00002
		STA	EXTIM0,Y
		LDA	#00005
		STA	EXCHPT,Y
		LDA	#00020H
		STA	TILTCT
		LDA	#00047H			;［Ｓ］
		JSL	>SOUND_3_ON
;;;;;;;;		LDA	#0001AH			;［Ｓ］
;;;;;;;;		STA	SOUND3

		LDA	#00010H			;くさり”びびび”タイマーセット
		STA	ENTIM2,X		;
		BRA	MAKI0_SUB3400

MAKI0_SUB3300	EQU	$
		LDA	<ENWRK4,X
		CMP	ENYPSL,X
		BPL	MAKI0_SUB3800

		LDY	ENWRKA,X		;下まで落ち切った ?
		CPY	#003			;
		BMI	MAKI0_SUB3500		;  no: MAKI0_SUB3500

		STA	ENYPSL,X

		LDA	#00010H			;くさり”びびび”タイマーセット
		STA	ENTIM2,X		;

MAKI0_SUB3400	EQU	$
		STZ	ENYSPD,X
		STZ	ENGPOW,X
		STZ	<ENWRK2,X

		RTS

MAKI0_SUB3500	EQU	$
		INC	ENWRKA,X

		LDA	<ENWRK4,X		;次のチェックＰＯＳ．計算
		CLC				;
		ADC	#00010H+6		;
		STA	<ENWRK4,X		;

MAKI0_SUB3800	EQU	$

		RTS
;
;************************************************************************
;*		initial ( 巻き上げお邪魔どすん（滑車）)			*
;************************************************************************
MAKI1IN		EQU	$			;-- maki1in --
		RTL
;
;************************************************************************
;*		move	( 巻き上げお邪魔どすん（滑車）)			*
;************************************************************************
;		ENWRK0	本体の ROUITNE INDEX
;		ENWRK2
;		ENWRK4	回転角加算値
;		ENWRK6	本体のＹ　ＰＯＳ．
;		ENWRK8	回転角
;		ENWRKA
;		ENWRKC
;
;		ENCONT
;
;		ENTIM0
;		ENTIM1
;
MAKI1MV		EQU	$			;-- maki1mv --
		JSL	>TROBJ_OAM_4x4

		JSL	>ENMDCK

		LDY	ECRSFG,X
		BEQ	MAKI1MV0300
		DEY
		BPL	MAKI1MV0100

		JSL	>PLFLST
		BRA	MAKI1MV0300

MAKI1MV0100	EQU	$
		LDA	ENMODE,Y
		CMP	#EMOVE
		BNE	MAKI1MV0300
		LDA	ENSHOT,Y
		BEQ	MAKI1MV0300

		TYX
		JSL	>ENDEATH_SET_4

		LDY	<ENWRK0,X
		LDA	ENYSPD,Y
		BMI	MAKI1MV0300

		LDA	ENWRKA,Y
		DEC	A
		BMI	MAKI1MV0300

		STA	ENWRKA,Y

		LDA	ENWRK4,Y		;巻き上げチェックＹ　ＰＯＳ．セット
		SEC				;
		SBC	#00010H+6		;
		STA	ENWRK4,Y		;

		LDA	#0FFC0H
		STA	ENYSPD,Y
		LDA	#00000
		STA	ENGPOW,Y
		INC	A		;[ LDA	#00001 ]
		STA	ENWRK2,Y

MAKI1MV0300	EQU	$
		LDY	<ENWRK0,X		;本体動いてる ?
		LDA	ENYSPD,Y		;
		BEQ	MAKI1MV0400		;  no: MAKI1MV0400

		LDA	ENYPSL,Y
		AND	#00002H
		BNE	MAKI1MV0400

		PHY
		LDA	#0005AH			;［Ｓ］
		JSL	>SOUND_3_ON
		PLY

MAKI1MV0400	EQU	$
		LDA	ENWRK6,X
		SEC
		SBC	ENYPSL,Y
		STA	R0
		LDA	#00C00H
		STA	R6
		M_CHIP	MULTIPLY
		LDX	<ENINDX
		LDA	R0
		AND	#001FEH
		STA	ENWRK8,X

MAKI1MV0500	EQU	$
		JSR	MAKI1_ROT_SET

		RTL
;
MAKI1_ROT_SET	EQU	$
MAKI1_ROT_SET_I EQU	$
		LDA	#CIPCHD3+20E0H+000	;(R12) <-- 転送元アドレスセット
		STA	R12			;
		LDA	#BANK CIPCHD3+20E0H+000 ;(R13) <-- 転送元バンクセット
		STA	R13			;

		LDA	ENWRK8,X		;(R5) <- 回転角セット
		LSR	A			;
		STA	R5			;

		LDA	#00100H			;(R6) <- 倍率セット
		STA	R6			;

		LDY	ENTROB,X
		TYX
		LDA	>TROBJ_PLOT_X,X		;(R3) <- ビットマップ座標＿Ｘセット
		STA	R3			;
		LDA	>TROBJ_PLOT_Y,X		;(R2) <- ビットマップ座標＿Ｙセット
		STA	R2			;
;
;-------------- OBJ mode 7 set ----------------------------------
		M_CHIP	C_32_ROTZOM

		LDX	<ENINDX

		INC	OBM7WF		;mode 7 OBJ chara DMA "ON"

MAKI1_R_SET0800 EQU	$

		RTS
;
;************************************************************************
;*		initial ( Ｑちゃん )					*
;************************************************************************
QCHANIN		EQU	$			;-- qchanin --
QCHN2IN		EQU	$			;-- qchn2in --
		JSL	>TROBJ_SR_4x4_CL

		LDY	#000
		LDA	ENXPSL,X
		SEC
		SBC	#00008
		STA	ENWRKA,X
		AND	#00010H
		BNE	QCHANIN0100

		INY
		INY

QCHANIN0100	EQU	$
		TYA
		STA	ENMUKI,X
		STY	<ENWRK4,X
		LDA	ENYPSL,X
		SEC
		SBC	#00008
		STA	ENWRKC,X

		LDA	ENMYNO,X
		CMP	#QCHAN
		BEQ	QCHANIN0200

		LDA	#00080H
		STA	<ENWRK0,X

QCHANIN0200	EQU	$
		JSR	QCHAN_ROT_SET

		RTL
;
;************************************************************************
;*		move	( Ｑちゃん )					*
;************************************************************************
;		ENWRK0	目標回転角
;B		ENWRK2	ROUTINE MODE INDEX
;B		ENWRK3	キャラパターンフラグ
;B		ENWRK4	向きセーブ
;		ENWRK6	回転角加算値
;		ENWRK8	回転角
;		ENWRKA	回転中心Ｘ　ＰＯＳ．
;		ENWRKC	　 ”　 Ｙ　ＰＯＳ．
;
;		ENCONT	振り返り回数
;
QCHAN_SUB	EQU	$
		WORD	QCHAN_SUB0		;まわってるＱちゃん
		WORD	QCHAN_SUB1		;きょろきょろＱちゃん
;
QCHANMV		EQU	$			;-- qchanmv --
QCHN2MV		EQU	$			;-- qchn2mv --
		JSL	>TROBJ_OAM_4x4

		JSL	>ENMDCK

		JSR	QCHAN_ANG_CALC

		JSR	QCHAN_ROT_SET

		JSR	QCHAN_POS_CALC

		JSR	QCHAN_CHAR_CHG

		TXY
		LDA	<ENWRK2,X
		ASL	A
		TAX
		JSR	(QCHAN_SUB,X)

		LDY	ECRSFG,X		;プレイヤーと衝突した ?
		BEQ	QCHANMV0800
		BPL	QCHANMV0700		;  no: QCHANMV0700

		LDA	EPWIDY,X		;プレイヤーに踏まれた ?
		SEC				;
		SBC	PWIDEY			;
		SEC				;
		SBC	EWIDEY,X		;
		CMP	#0FFF6H			;
		BCC	QCHANMV0300		;  no: QCHANMV0300

		LDY	ENYSPD+1,X		;プレイヤー上昇中 ?
		BMI	QCHANMV0300		; yes: QCHANMV0300
		LDY	PLJUMP			;プレイヤージャンプ中 ?
		BNE	QCHANMV0500		; yes: QCHANMV0500

QCHANMV0300	EQU	$
		JSL	>PLFLST
		BRA	QCHANMV0800

QCHANMV0500	EQU	$
		JSL	>EPCRCK
		RTL

QCHANMV0700	EQU	$
		JSL	>SHOT_EN_KILL_S2

QCHANMV0800	EQU	$

		RTL
;
QCHAN_ANG_ADD	EQU	$
		WORD	00100H,00400H
;
QCHAN_ANG_CALC	EQU	$
		LDY	<ENWRK2,X
		BNE	QCHAN_A_CALC080

		LDA	ENMYNO,X
		SEC
		SBC	#QCHAN
		ASL	A
		TAY
		LDA	ENWRK6,X
		CLC
		ADC	!QCHAN_ANG_ADD,Y
		PHA
		AND	#001FFH
		STA	ENWRK6,X
		PLA
		AND	#0FE00H
		BPL	QCHAN_A_CALC010

		ORA	#000FFH

QCHAN_A_CALC010 EQU	$
		XBA
		CLC
		ADC	ENWRK8,X
		STA	ENWRK8,X

QCHAN_A_CALC080 EQU	$

		RTS
;
QCHAN_CHAR	EQU	$
		WORD	CIPCHD3+4080H+000
		WORD	CIPCHD3+40A0H+000
;
QCHAN_ROT_SET	EQU	$
		LDY	<ENWRK3,X
		LDA	!QCHAN_CHAR,Y		;(R12) <-- 転送元アドレスセット
		STA	R12			;
		LDA	#BANK CIPCHD3+4080H+000 ;(R13) <-- 転送元バンクセット
		STA	R13			;

		LDY	<ENWRK4,X
		STY	<EWORK0
		LDA	ENWRK8,X		;(R5) <- 回転角セット
		LDY	ENMUKI,X
		CPY	<EWORK0
		BEQ	QCHAN_R_SET0100

		BIT	#00080H
		BEQ	QCHAN_R_SET0100

		CLC
		ADC	#00100H

QCHAN_R_SET0100 EQU	$
		AND	#001FEH
		LSR	A			;
		STA	R5			;

		LDA	#00100H			;(R6) <- 倍率セット
		STA	R6			;

		LDY	ENTROB,X
		TYX
		LDA	>TROBJ_PLOT_X,X		;(R3) <- ビットマップ座標＿Ｘセット
		STA	R3			;
		LDA	>TROBJ_PLOT_Y,X		;(R2) <- ビットマップ座標＿Ｙセット
		STA	R2			;
;
;-------------- OBJ mode 7 set ----------------------------------
		M_CHIP	C_32_ROTZOM

		LDX	<ENINDX

		INC	OBM7WF		;mode 7 OBJ chara DMA "ON"

		RTS
;
QCHAN_POS_CALC	EQU	$
		LDY	ENMUKI,X
		STY	<EWORK0
		PHP

		LDA	ENWRK8,X
		LDY	<ENWRK4,X
		CPY	<EWORK0
		BEQ	QCHAN_P_CALC010

		BIT	#00080H
		BEQ	QCHAN_P_CALC010

		PLP
		BRA	QCHAN_P_CALC020

QCHAN_P_CALC010 EQU	$
		PLP
		BEQ	QCHAN_P_CALC030

QCHAN_P_CALC020 EQU	$
		EOR	#0FFFFH
		INC	A

QCHAN_P_CALC030 EQU	$
		AND	#001FEH
		STA	R1
		LDA	#00018H
		STA	R6
		M_CHIP	M_ENMY_1P_ROT
		LDX	<ENINDX
		LDA	ENWRKA,X
		CLC
		ADC	R1
		STA	ENXPSL,X
		LDA	ENWRKC,X
		SEC
		SBC	R0
		STA	ENYPSL,X

		RTS
;
QCHAN_CHAR_CHG	EQU	$
		LDY	<ENWRK2,X
		BNE	QCHAN_C_CHG0800

		LDA	ENTIM1,X
		BNE	QCHAN_C_CHG0800

		LDA	#00004H
		STA	ENTIM1,X

		LDA	<ENWRK3,X
		EOR	#00002
		STA	<ENWRK3,X

QCHAN_C_CHG0800 EQU	$

		RTS
;
QCHAN_SUB0	EQU	$
		TYX

		LDA	ENMYNO,X
		CMP	#QCHAN
		BEQ	QCHAN_SUB0800

		LDA	ENWRK8,X
		SEC
		SBC	<ENWRK0,X
		BMI	QCHAN_SUB0800

		INC	<ENWRK2,X

		LDA	<ENWRK0,X
		STA	ENWRK8,X
		AND	#001FFH
		BEQ	QCHAN_SUB0500

		LDA	<RANDM0
		AND	#0001FH
		CLC
		ADC	#00004H
		STA	ENTIM0,X

		LDY	#001
		STY	<ENCONT,X

		RTS

QCHAN_SUB0500	EQU	$
		LDA	#00010H			;ストップタイマーセット
		STA	ENTIM0,X		;

		LDA	<RANDM0
		AND	#00003
		CLC
		ADC	#00003
		STA	<ENCONT,X

QCHAN_SUB0800	EQU	$

		RTS
;
QCHAN_SUB1	EQU	$
		TYX

		LDA	ENTIM0,X
		BNE	QCHAN_SUB1800

		DEC	<ENCONT,X
		BNE	QCHAN_SUB1500

		LDY	ENMUKI,X
		STY	<ENWRK4,X

		LDA	ENWRK8,X
		CLC
		ADC	#00080H
		STA	<ENWRK0,X

		DEC	<ENWRK2,X

		RTS

QCHAN_SUB1500	EQU	$
		LDA	#00008
		STA	ENTIM0,X

		LDA	ENMUKI,X
		EOR	#00002
		STA	ENMUKI,X

QCHAN_SUB1800	EQU	$

		RTS
;
;************************************************************************
;*		initial ( フリッパー )					*
;************************************************************************
FLIPPIN		EQU	$			;-- flippin --
		JSL	>TROBJ_SR_4x4_CL

		STZ	ENMUKI,X

		JSR	FLIPP_ROT_SET

		RTL
;
;************************************************************************
;*		move	( フリッパー )					*
;************************************************************************
;		ENWRK0	開閉フラグ 0...閉 2...開
;		ENWRK2
;		ENWRK4	回転セットロックフラグ
;		ENWRK6	回転角補正値
;		ENWRK8	回転角
;		ENWRKA	ショックフラグ
;		ENWRKC
;
;		ENCONT
;
;		ENTIM0
;
FLIPPMV		EQU	$			;-- flippmv --
		JSR	FLIPP_OAM_SET

		JSL	>ENMDCK

		JSR	FLIPP_OBJ_CHK

		JSR	FLIPP_ROT_SET

		LDA	#0000010010110100B	;舌ダメージ
		LDY	<ENWRK0,X		;開いてる ?
		BEQ	FLIPPMV0800		;  no: FLIPPMV0800

		LDA	#0000010001110100B	;食えない

FLIPPMV0800	EQU	$
		STA	ENMOD0,X

		RTL
;
FLIPP_OAM_SET	EQU	$
		JSL	>TROBJ_OAM_4x4

		LDA	ENWRK8,X
		AND	#001FEH
		STA	R1
		LDA	#00008H
		STA	R6
		M_CHIP	M_ENMY_1P_ROT
		LDX	<ENINDX
		LDA	ECENTX,X
		SEC
		SBC	#00018H
		CLC
		ADC	R0
		SEC
		SBC	ESCCH1
		STA	<EWORK0
		LDA	ECENTX,X
		CLC
		ADC	#00018H
		SEC
		SBC	R0
		SEC
		SBC	ESCCH1
		STA	<EWORK2
		LDA	ECENTY,X
		CLC
		ADC	R1
		SEC
		SBC	ESCCV1
		STA	<EWORK4

		I16
		LDY	ENOAML,X
		LDA	<EWORK0
		STA	SOAM_DX+0+8*1,Y
		STA	SOAM_DX+0+8*3,Y
		SEC
		SBC	#00010H
		STA	SOAM_DX+0+8*0,Y
		STA	SOAM_DX+0+8*2,Y

		LDA	<EWORK2
		STA	SOAM_DX+0+8*4,Y
		STA	SOAM_DX+0+8*6,Y
		SEC
		SBC	#00010H
		STA	SOAM_DX+0+8*5,Y
		STA	SOAM_DX+0+8*7,Y

		LDA	<EWORK4
		STA	SOAM_DX+2+8*2,Y
		STA	SOAM_DX+2+8*3,Y
		STA	SOAM_DX+2+8*6,Y
		STA	SOAM_DX+2+8*7,Y
		SEC
		SBC	#00010H
		STA	SOAM_DX+2+8*0,Y
		STA	SOAM_DX+2+8*1,Y
		STA	SOAM_DX+2+8*4,Y
		STA	SOAM_DX+2+8*5,Y
;
		LDA	SOAM_DX+4+8*0,Y
		EOR	#04000H
		STA	SOAM_DX+4+8*4,Y
		LDA	SOAM_DX+4+8*1,Y
		EOR	#04000H
		STA	SOAM_DX+4+8*5,Y
		LDA	SOAM_DX+4+8*2,Y
		EOR	#04000H
		STA	SOAM_DX+4+8*6,Y
		LDA	SOAM_DX+4+8*3,Y
		EOR	#04000H
		STA	SOAM_DX+4+8*7,Y
;
		LDA	SOAM_DX+6+8*0,Y
		STA	SOAM_DX+6+8*4,Y
		LDA	SOAM_DX+6+8*1,Y
		STA	SOAM_DX+6+8*5,Y
		LDA	SOAM_DX+6+8*2,Y
		STA	SOAM_DX+6+8*6,Y
		LDA	SOAM_DX+6+8*3,Y
		STA	SOAM_DX+6+8*7,Y
		I8

		RTS
;
FLIPP_OBJ_CHK	EQU	$
		STZ	<EWORK2
		LDY	ECRSFG,X
		BPL	FLIPP_O_CHK0800

		LDA	EPWIDY,X		;プレイヤー上から来た ?
		EOR	#0FFFFH			;
		INC	A			;
		SEC				;
		SBC	PWIDEY			;
		SEC				;
		SBC	EWIDEY,X		;
		STA	<EWORK0			;
		DEC	A			;
		CMP	#0FFF7H			;
		BCC	FLIPP_O_CHK0500		; yes: FLIPP_O_CHK0500

		LDA	ENWRK8,X		;開いてる ?
		CMP	#0FFE0H			;
		BMI	FLIPP_O_CHK0800		; yes: FLIPP_O_CHK0800

		LDY	PLYSPD+1		;プレイヤー下降中 ?
		BPL	FLIPP_O_CHK0800		; yes: FLIPP_O_CHK0800

		LDA	<EWORK0			;プレイヤーＹ　ＰＯＳ．補正
		SEC				;
		ADC	ECENTY,X		;
		INC	A			;
		STA	PLYPSL			;

		LDA	#0001CH			;［Ｓ］
		JSL	>SOUND_3_ON

		LDA	PLYSPD
		CMP	#0FF40H
		BPL	FLIPP_O_CHK0400

		LDY	ENWRKA,X		;ショックリアクションする ?
		BNE	FLIPP_O_CHK0400		;  no: FLIPP_O_CHK0400

		LDA	#00004
		STA	ENWRKA,X
		STA	ENTIM2,X
		STZ	<ENWRK4,X		;回転ロックフラグクリア

FLIPP_O_CHK0400 EQU	$
		STZ	PLSPJP			;ふんばりフラグクリア
		STZ	PLYSPD
		BRA	FLIPP_O_CHK0800

FLIPP_O_CHK0500 EQU	$
		LDY	<ENWRK0,X		;開いてる ?
		BNE	FLIPP_O_CHK0600		; yes: FLIPP_O_CHK0600

		LDY	#002
		STY	<ENWRK0,X
		STZ	<ENWRK4,X	;回転ロックフラグクリア
		LDA	#0000EH		;［Ｓ］
		JSL	>SOUND_3_ON

FLIPP_O_CHK0600 EQU	$
		LDA	#00010H
		STA	ENTIM2,X

FLIPP_O_CHK0800 EQU	$
		TXA
		STA	R1

		M_CHIP	MY_ENCROS2

FLIPP_O_CHK0880 EQU	$
		LDX	<ENINDX			;
		LDY	R14			;
		BMI	FLIPP_O_CHK0888		;
		BNE	FLIPP_O_CHK0890

		LDA	BABYNO			;赤ちゃん、プレイヤーに乗ってるｏｒどろぼーに捕られてる ?
		ORA	DEATHCT0		;死神に連れ去られてる ?
		BEQ	FLIPP_O_CHK0890		;  no: FLIPP_O_CHK0890

FLIPP_O_CHK0888 EQU	$
		JMP	FLIPP_O_CHK2000

FLIPP_O_CHK0890 EQU	$
		LDA	ENMYNO,Y		;死神だった ?
		CMP	#DEATH			;
		BEQ	FLIPP_O_CHK0888		; yes: FLIPP_O_CHK0888

		INC	<EWORK2
		BRA	FLIPP_O_CHK1000

FLIPP_O_CHK0900 EQU	$
		LDX	#BANK MY_ENCROS2
		LDA	R15
		JSL	>CHIPON
		BRA	FLIPP_O_CHK0880

FLIPP_O_CHK1000 EQU	$
		LDA	ENMYNO,Y		;
		CMP	#COLDX			;氷息 ?
		BEQ	FLIPP_O_CHK1080		; yes: FLIPP_O_CHK1080
		CMP	#FIREX			;炎息 ?
		BEQ	FLIPP_O_CHK1080		; yes: FLIPP_O_CHK1080
		CMP	#EGG00			;タマゴだった ?
		BCC	FLIPP_O_CHK1008		;
		CMP	#EGG09+1		;
		BCS	FLIPP_O_CHK1008		;  no: FLIPP_O_CHK1008

		LDA	ENWRK4,Y		;オプションモード ?
		BNE	FLIPP_O_CHK1080		; yes: FLIPP_O_CHK1080

FLIPP_O_CHK1008 EQU	$
		LDA	ECENTY,Y		;通過していい ?
		SEC				;
		SBC	ECENTY,X		;
		STA	<EWORK0			;
		BPL	FLIPP_O_CHK1010		;  no: FLIPP_O_CHK1010

		LDA	ENYSPD,Y		;下降中ｏｒ停止中 ?
		DEC	A			;
		BMI	FLIPP_O_CHK1010		;  no: FLIPP_O_CHK1010
		JMP	FLIPP_O_CHK1500		; yes: FLIPP_O_CHK1500

FLIPP_O_CHK1010 EQU	$
		LDA	ENWRK8,X		;開いてる ?
		CMP	#0FFE0H			;
		BPL	FLIPP_O_CHK1100		;  no: FLIPP_O_CHK1100

FLIPP_O_CHK1080 EQU	$
		JMP	FLIPP_O_CHK1800		; yes: FLIPP_O_CHK1800

FLIPP_O_CHK1100 EQU	$
		LDA	<EWORK0			;Ｙ　ＰＯＳ．補正
		SEC				;
		SBC	EWIDEY,Y		;
		SEC				;
		SBC	EWIDEY,X		;
		EOR	#0FFFFH			;
		SEC				;
		ADC	ENYPSL,Y		;
		INC	A			;
		INC	A			;
		STA	ENYPSL,Y		;
		LDA	#00000
		STA	ENYSPD,Y

		CPY	#BABY_INDEX		;赤ちゃん ?
		BNE	FLIPP_O_CHK1200		;  no: FLIPP_O_CHK1200

		LDY	#002
		STY	BABYBGCHK

		LDA	ENWRKA,X		;ショックリアクションする ?
		BNE	FLIPP_O_CHK1800		;  no: FLIPP_O_CHK1800

		LDA	#00004
		STA	ENWRKA,X
		STA	ENTIM2,X
		STZ	<ENWRK4,X		;回転ロックフラグクリア
		BRA	FLIPP_O_CHK1800

FLIPP_O_CHK1200 EQU	$
		LDA	ENYSPD,Y
		CMP	#0FF40H
		BPL	FLIPP_O_CHK1400

FLIPP_O_CHK1300 EQU	$
		LDA	ENWRKA,X		;ショックリアクションする ?
		BNE	FLIPP_O_CHK1400		;  no: FLIPP_O_CHK1400

		LDA	#00004
		STA	ENWRKA,X
		STA	ENTIM2,X
		STZ	<ENWRK4,X		;回転ロックフラグクリア

FLIPP_O_CHK1400 EQU	$
		LDA	ENSHOT,Y
		BEQ	FLIPP_O_CHK1800

		TYX
		PHY
		JSL	>ENDEATH_SET_4
		PLY
		LDA	#00000
		STA	ENYSPD,Y
		STA	ENTIM0,Y		;タマゴで変になるから！！
		BRA	FLIPP_O_CHK1800

FLIPP_O_CHK1500 EQU	$
		LDA	ENYSPD,Y
		BMI	FLIPP_O_CHK1010

		LDY	<ENWRK0,X
		BNE	FLIPP_O_CHK1600

		LDY	#002
		STY	<ENWRK0,X
		STZ	<ENWRK4,X	;回転ロックフラグクリア
		LDA	#0000EH		;［Ｓ］
		JSL	>SOUND_3_ON
;;;;;;;;		LDA	#00015H		;［Ｓ］
;;;;;;;;		STA	SOUND0

FLIPP_O_CHK1600 EQU	$
		LDA	#00010H
		STA	ENTIM2,X

FLIPP_O_CHK1800 EQU	$
		LDA	<EWORK2
		BEQ	FLIPP_O_CHK1900
		JMP	FLIPP_O_CHK0900

FLIPP_O_CHK1900 EQU	$
		JMP	FLIPP_O_CHK0800
;
FLIPP_O_CHK2000 EQU	$
		LDA	ENTIM2,X
		BNE	FLIPP_O_CHK2800

		LDY	<ENWRK0,X
		BEQ	FLIPP_O_CHK2800

		STZ	<ENWRK0,X
		STZ	<ENWRK4,X	;回転ロックフラグクリア

FLIPP_O_CHK2800 EQU	$

		RTS
;
FLIPP_ROT_SET	EQU	$
		LDY	<ENWRK4,X		;回転セットする ?
		BEQ	FLIPP_R_SET0100		; yes: FLIPP_R_SET0100

		RTS

FLIPP_R_SET0100 EQU	$
		LDY	ENWRKA,X		;ショックリアクション ?
		BNE	FLIPP_R_SET0200		; yes: FLIPP_R_SET0200

		LDA	ENWRK8,X
		LDY	<ENWRK0,X		;開いてる ?
		BNE	FLIPP_R_SET1000		; yes: FLIPP_R_SET1000
		BRA	FLIPP_R_SET0500

FLIPP_R_SET0200 EQU	$
		LDY	ENTIM2,X
		BNE	FLIPP_R_SET0400

		LDA	ENWRK8,X
		BPL	FLIPP_R_SET0300

		STZ	ENWRK8,X
		STZ	ENWRKA,X		;ショックリアクションフラグクリア
		BRA	FLIPP_R_SET0800

FLIPP_R_SET0300 EQU	$
		SEC
		SBC	#00008
		BRA	FLIPP_R_SET2000

FLIPP_R_SET0400 EQU	$
		CLC
		ADC	#00008H
		BRA	FLIPP_R_SET2000

FLIPP_R_SET0500 EQU	$
		CMP	#00000
		BPL	FLIPP_R_SET0800

		CLC
		ADC	#00010H
		BRA	FLIPP_R_SET2000

FLIPP_R_SET0800 EQU	$
		INC	<ENWRK4,X
		LDA	#00000
		BRA	FLIPP_R_SET2000

FLIPP_R_SET1000 EQU	$
		CMP	#0FFA1H
		BMI	FLIPP_R_SET1800

		SEC
		SBC	#00018H
		BRA	FLIPP_R_SET2000

FLIPP_R_SET1800 EQU	$
		INC	<ENWRK4,X
		LDA	#0FFA0H

FLIPP_R_SET2000 EQU	$
		STA	ENWRK8,X

		LDA	#CIPCHD3+4060H+000	;(R12) <-- 転送元アドレスセット
		STA	R12			;
		LDA	#BANK CIPCHD3+4060H+000 ;(R13) <-- 転送元バンクセット
		STA	R13			;

		LDA	ENWRK8,X		;(R5) <- 回転角セット
		CLC				;
		ADC	ENWRK6,X		;
		AND	#001FEH			;
		LSR	A			;
		STA	R5			;

		LDA	#00100H			;(R6) <- 倍率セット
		STA	R6			;

		LDY	ENTROB,X
		TYX
		LDA	>TROBJ_PLOT_X,X		;(R3) <- ビットマップ座標＿Ｘセット
		STA	R3			;
		LDA	>TROBJ_PLOT_Y,X		;(R2) <- ビットマップ座標＿Ｙセット
		STA	R2			;
;
;-------------- OBJ mode 7 set ----------------------------------
		M_CHIP	C_32_ROTZOM

		LDX	<ENINDX

		INC	OBM7WF		;mode 7 OBJ chara DMA "ON"

		RTS
;
;************************************************************************
;*		initial ( 横フリッパー )				*
;************************************************************************
FLIPH_ANG_REV	EQU	$
		WORD	00080H,0FF80H
;
FLIPHIN		EQU	$			;-- fliphin --
		JSL	>TROBJ_SR_4x4_CL

		LDA	ENXPSL,X
		AND	#00010H
		LSR	A
		LSR	A
		LSR	A
		TAY
		LDA	!FLIPH_ANG_REV,Y	;回転角補正地セット
		STA	ENWRK6,X		;

		STZ	ENMUKI,X

		JSR	FLIPP_ROT_SET

		RTL
;
;************************************************************************
;*		move	( 横フリッパー )				*
;************************************************************************
;		ENWRK0	開閉フラグ 0...閉 2...開
;		ENWRK2
;		ENWRK4	回転セットロックフラグ
;		ENWRK6	回転角補正値
;		ENWRK8	回転角
;		ENWRKA	ショックリアクションフラグ
;		ENWRKC
;
;		ENCONT
;
;		ENTIM0
;
FLIPHMV		EQU	$			;-- fliphmv --
		JSR	FLIPH_OAM_SET

		JSL	>ENMDCK

		JSR	FLIPH_OBJ_CHK

		JSR	FLIPP_ROT_SET

		LDA	#0000010010110101B	;舌ダメージ
		LDY	<ENWRK0,X		;開いてる ?
		BEQ	FLIPHMV0800		;  no: FLIPHMV0800

		LDA	#0000010001110101B	;食えない

FLIPHMV0800	EQU	$
		STA	ENMOD0,X

		RTL
;
FLIPH_OAM_SET	EQU	$
		JSL	>TROBJ_OAM_4x4

		LDA	ENWRK8,X
		AND	#001FEH
		STA	R1
		LDA	#00008H
		STA	R6
		M_CHIP	M_ENMY_1P_ROT
		LDX	<ENINDX
		LDA	ENXPSL,X
		AND	#00010H
		BNE	FLIPH_O_SET0300

		LDA	ECENTX,X
		CLC
		ADC	R1
		SEC
		SBC	ESCCH1
		STA	<EWORK0

		LDA	ECENTY,X
		CLC
		ADC	#00018H
		SEC
		SBC	R0
		SEC
		SBC	ESCCV1
		STA	<EWORK2

		LDA	ECENTY,X
		SEC
		SBC	#00018H
		CLC
		ADC	R0
		SEC
		SBC	ESCCV1
		STA	<EWORK4
		BRA	FLIPH_O_SET0500

FLIPH_O_SET0300 EQU	$
		LDA	ECENTX,X
		SEC
		SBC	R1
		SEC
		SBC	ESCCH1
		STA	<EWORK0

		LDA	ECENTY,X
		SEC
		SBC	#00018H
		CLC
		ADC	R0
		SEC
		SBC	ESCCV1
		STA	<EWORK2

		LDA	ECENTY,X
		CLC
		ADC	#00018H
		SEC
		SBC	R0
		SEC
		SBC	ESCCV1
		STA	<EWORK4

FLIPH_O_SET0500 EQU	$
		I16
		LDY	ENOAML,X
		LDA	<EWORK0
		STA	SOAM_DX+0+8*1,Y
		STA	SOAM_DX+0+8*3,Y
		STA	SOAM_DX+0+8*5,Y
		STA	SOAM_DX+0+8*7,Y
		SEC
		SBC	#00010H
		STA	SOAM_DX+0+8*0,Y
		STA	SOAM_DX+0+8*2,Y
		STA	SOAM_DX+0+8*4,Y
		STA	SOAM_DX+0+8*6,Y

		LDA	<EWORK2
		STA	SOAM_DX+2+8*2,Y
		STA	SOAM_DX+2+8*3,Y
		SEC
		SBC	#00010H
		STA	SOAM_DX+2+8*0,Y
		STA	SOAM_DX+2+8*1,Y

		LDA	<EWORK4
		STA	SOAM_DX+2+8*4,Y
		STA	SOAM_DX+2+8*5,Y
		SEC
		SBC	#00010H
		STA	SOAM_DX+2+8*6,Y
		STA	SOAM_DX+2+8*7,Y
;
		LDA	SOAM_DX+4+8*0,Y
		EOR	#08000H
		STA	SOAM_DX+4+8*4,Y
		LDA	SOAM_DX+4+8*1,Y
		EOR	#08000H
		STA	SOAM_DX+4+8*5,Y
		LDA	SOAM_DX+4+8*2,Y
		EOR	#08000H
		STA	SOAM_DX+4+8*6,Y
		LDA	SOAM_DX+4+8*3,Y
		EOR	#08000H
		STA	SOAM_DX+4+8*7,Y
;
		LDA	SOAM_DX+6+8*0,Y
		STA	SOAM_DX+6+8*4,Y
		LDA	SOAM_DX+6+8*1,Y
		STA	SOAM_DX+6+8*5,Y
		LDA	SOAM_DX+6+8*2,Y
		STA	SOAM_DX+6+8*6,Y
		LDA	SOAM_DX+6+8*3,Y
		STA	SOAM_DX+6+8*7,Y
		I8

		RTS
;
FLIPH_OBJ_CHK	EQU	$
		LDA	ENXPSL,X
		AND	#00010H
		DEC	A
		STA	<EWORKE

		STZ	<EWORK2
		LDY	ECRSFG,X		;プレイヤーとあたった ?
		BMI	FLIPH_O_CHK0100		; yes: FLIPH_O_CHK0100

FLIPH_O_CHK0000 EQU	$
		JMP	FLIPH_O_CHK0800

FLIPH_O_CHK0100 EQU	$
		LDY	<ENWRK0,X		;通過中 ?
		BNE	FLIPH_O_CHK0150		; yes: FLIPH_O_CHK0150

		LDA	EPWIDX,X		;通過できる ?
		EOR	<EWORKE			;
		BPL	FLIPH_O_CHK0180		;  no: FLIPH_O_CHK0180

FLIPH_O_CHK0150 EQU	$
		JMP	FLIPH_O_CHK0500		; yes: FLIPH_O_CHK0500

FLIPH_O_CHK0180 EQU	$
		LDA	ENWRK8,X		;開いてる ?
		CMP	#0FFE0H			;
		BMI	FLIPH_O_CHK0000		; yes: FLIPH_O_CHK0000

		LDA	PLXSPD			;動いてる ?
		BNE	FLIPH_O_CHK0200		; yes: FLIPH_O_CHK0200

		LDA	KEYC1L			;左右キー入力あり ?
		AND	#00300H			;
		BEQ	FLIPH_O_CHK0000		;  no: FLIPH_O_CHK0000

		AND	#00100H			;
		DEC	A			;

FLIPH_O_CHK0200 EQU	$
		EOR	<EWORKE			;向かってきてる ?
		BMI	FLIPH_O_CHK0000		;  no: FLIPH_O_CHK0000

		LDA	PLXSPD
		CLC
		ADC	#000C0H
		CMP	#000C0H*2
		BCC	FLIPH_O_CHK0280

		LDY	ENWRKA,X
		BNE	FLIPH_O_CHK0280

		LDA	#00004
		STA	ENWRKA,X
		STA	ENTIM2,X
		STZ	<ENWRK4,X		;回転ロックフラグクリア

FLIPH_O_CHK0280 EQU	$
		LDA	PWIDEX
		CLC
		ADC	EWIDEX,X
		DEC	A
		DEC	A
		LDY	<EWORKE
		BMI	FLIPH_O_CHK0300

		EOR	#0FFFFH
		INC	A

FLIPH_O_CHK0300 EQU	$
		CLC
		ADC	ECENTX,X
		SEC
		SBC	PCENTX
		CLC
		ADC	PLXPSL
		STA	PLXPSL

		LDA	PLXSPD			;ダッシュ ?
		CLC				;
		ADC	#00280H			;
		CMP	#00500H			;
		BCC	FLIPH_O_CHK0380		;  no: FLIPH_O_CHK0380

		LDA	PLXSPD
		PHA
		CMP	#08000H
		ROR	A
		CMP	#08000H
		ROR	A
		EOR	#0FFFFH
		INC	A
		STA	PLXSPD
		STA	PLMVSP
		PLA
		BMI	FLIPH_O_CHK0320

		EOR	#0FFFFH
		INC	A

FLIPH_O_CHK0320 EQU	$
		STA	PLYSPD
		LDA	#P006
		STA	PLJUMP

		LDA	#00034H			;［Ｓ］
		JSL	>SOUND_3_ON

		BRA	FLIPH_O_CHK0800

FLIPH_O_CHK0380 EQU	$
		STZ	PLXSPD
		STZ	PLMVSP

		LDY	PLJUMP
		BNE	FLIPH_O_CHK0800

		INC	PUSHFG			;敵押しフラグ”ＯＮ”
		INC	PSPUSH			;押しカウンターセット
		BRA	FLIPH_O_CHK0800

FLIPH_O_CHK0500 EQU	$
		LDY	<ENWRK0,X
		BNE	FLIPH_O_CHK0600

		LDA	#00010H			;チェックＷＩＤＥ　Ｘを大きく
		STA	EWIDEX,X
		LDY	#002
		STY	<ENWRK0,X
		STZ	<ENWRK4,X		;回転セットロックフラグクリア
		LDA	#0000EH		;［Ｓ］
		JSL	>SOUND_3_ON

FLIPH_O_CHK0600 EQU	$
		LDA	#00010H
		STA	ENTIM2,X

FLIPH_O_CHK0800 EQU	$
		TXA
		STA	R1

		M_CHIP	MY_ENCROS2

FLIPH_O_CHK0880 EQU	$
		LDX	<ENINDX			;チェック終わり ?
		LDY	R14			;
		BMI	FLIPH_O_CHK0980		; yes: FLIPH_O_CHK0980
		BNE	FLIPH_O_CHK0890		;赤ちゃん ?
						;  no: FLIPH_O_CHK0890

		LDA	BABYNO			;赤ちゃんプレイヤーに乗ってる ?
		ORA	DEATHCT0		;赤ちゃん死神に連れ去られてる ?
		BMI	FLIPH_O_CHK0980		; yes: FLIPH_O_CHK0980

FLIPH_O_CHK0890 EQU	$
		LDA	ENMYNO,Y		;死神だった ?
		CMP	#DEATH			;
		BEQ	FLIPH_O_CHK0900		; yes: FLIPH_O_CHK0900

		INC	<EWORK2
		BRA	FLIPH_O_CHK1000

FLIPH_O_CHK0900 EQU	$
		LDX	#BANK MY_ENCROS2
		LDA	R15
		JSL	>CHIPON
		BRA	FLIPH_O_CHK0880

FLIPH_O_CHK0980 EQU	$
		LDA	ENTIM2,X		;オープンロック ?
		BNE	FLIPH_O_CHK0990		; yes: FLIPH_O_CHK0990

		LDY	<ENWRK0,X
		BEQ	FLIPH_O_CHK0990

		LDA	#00008			;チェックＷＩＤＥ　Ｘを元通りに
		STA	EWIDEX,X
		STZ	<ENWRK0,X		;閉じる
		STZ	<ENWRK4,X		;回転セットロックフラグクリア

FLIPH_O_CHK0990 EQU	$

		RTS

FLIPH_O_CHK1000 EQU	$
		LDA	ENXSPD,Y		;通過できる ?
		EOR	<EWORKE			;
		BPL	FLIPH_O_CHK1100		;  no: FLIPH_O_CHK1100

		LDA	ECENTX,X		;通過できる ?
		SEC				;
		SBC	ECENTX,Y		;
		EOR	<EWORKE			;
		BPL	FLIPH_O_CHK1100		;  no: FLIPH_O_CHK1100
		JMP	FLIPH_O_CHK1500		; yes: FLIPH_O_CHK1500

FLIPH_O_CHK1100 EQU	$
		LDA	ENWRK8,X		;開いてる ?
		CMP	#0FFE0H			;
		BMI	FLIPH_O_CHK1380		; yes: FLIPH_O_CHK1380

		LDA	ENMOD1,X		;リフトかアイテム ?
		AND	#0100000000000000B	;
		BEQ	FLIPH_O_CHK1180		;  no: FLIPH_O_CHK1180
		JMP	FLIPH_O_CHK1400

FLIPH_O_CHK1180 EQU	$
		LDA	ENXSPD,Y		;止まってる ?
		BEQ	FLIPH_O_CHK1380		; yes: FLIPH_O_CHK1380
		EOR	<EWORKE			;向かってきてる ?
		BMI	FLIPH_O_CHK1380		;  no: FLIPH_O_CHK1380

		LDA	ENSHOT,Y		;ショットされてる ?
		BEQ	FLIPH_O_CHK1400		;  no: FLIPH_O_CHK1400

		PHY
		LDA	EWIDEX,Y
		SEC
		ADC	EWIDEX,X
		INC	A
		INC	A
		LDY	<EWORKE
		BMI	FLIPH_O_CHK1300

		EOR	#0FFFFH
		INC	A

FLIPH_O_CHK1300 EQU	$
		PLY

		CLC
		ADC	ECENTX,X
		SEC
		SBC	ECENTX,Y
		CLC
		ADC	ENXPSL,Y
		STA	ENXPSL,Y

		LDA	ENXSPD,Y
		CLC
		ADC	#000C0H
		CMP	#000C0H*2
		BCC	FLIPH_O_CHK1350

		LDA	ENWRKA,X
		BNE	FLIPH_O_CHK1350

		LDA	#00004
		STA	ENWRKA,X
		STA	ENTIM2,X
		STZ	<ENWRK4,X		;回転ロックフラグクリア

FLIPH_O_CHK1350 EQU	$
		LDA	#00000
		STA	ENXSPD,Y

		LDA	ENMOD1,Y		;アイテム ?
		AND	#0110000000000000B	;
		CMP	#0110000000000000B	;
		BEQ	FLIPH_O_CHK1800		; yes: FLIPH_O_CHK1800

		TYX
		JSL	>ENDEATH_SET_4

FLIPH_O_CHK1380 EQU	$
		BRA	FLIPH_O_CHK1800

FLIPH_O_CHK1400 EQU	$
		LDA	ENXSPD,Y
		BEQ	FLIPH_O_CHK1800

		EOR	<EWORKE			;向かってきてる ?
		BMI	FLIPH_O_CHK1800		;  no: FLIPH_O_CHK1800

		LDA	ENXSPD,Y
		EOR	#0FFFFH
		INC	A
		STA	ENXSPD,Y
		LDA	ENMUKI,Y
		EOR	#00002
		STA	ENMUKI,Y
		LDA	ENXMAX,Y
		EOR	#0FFFFH
		INC	A
		STA	ENXMAX,Y
		LDA	ENXPSL,Y
		SEC
		SBC	ENMOVX,Y
		STA	ENXPSL,Y
		BRA	FLIPH_O_CHK1800

FLIPH_O_CHK1500 EQU	$
		LDA	ENMYNO,Y
		CMP	#MBALL
		BEQ	FLIPH_O_CHK1580

		LDA	ENSHOT,Y
		BEQ	FLIPH_O_CHK1400

FLIPH_O_CHK1580 EQU	$
		LDA	<ENWRK0,X		;開いてる ?
		BNE	FLIPH_O_CHK1600		; yes: FLIPH_O_CHK1600

		LDA	ENXSPD,Y		;開く方向に向かってきてる ?
		EOR	<EWORKE			;
		BPL	FLIPH_O_CHK1400		;  no: FLIPH_O_CHK1400

		LDA	#00010H			;チェックＷＩＤＥ　Ｘを大きく
		STA	EWIDEX,X
		LDY	#002
		STY	<ENWRK0,X
		STZ	<ENWRK4,X		;回転セットロックフラグクリア
		LDA	#0000EH			;［Ｓ］
		JSL	>SOUND_3_ON
;;;;;;;;		LDA	#00015H		;［Ｓ］
;;;;;;;;		STA	SOUND0

FLIPH_O_CHK1600 EQU	$
		LDA	#00010H
		STA	ENTIM2,X

FLIPH_O_CHK1800 EQU	$
		LDA	<EWORK2			;はじめてチップルーチンを通す ?
		BEQ	FLIPH_O_CHK1900		; yes: FLIPH_O_CHK1900
		JMP	FLIPH_O_CHK0900		;  no: FLIPH_O_CHK0900

FLIPH_O_CHK1900 EQU	$
		JMP	FLIPH_O_CHK0800

;
;************************************************************************
;*		initial ( 穴ほりわんわん（横型） )			*
;************************************************************************
AWANHIN		EQU	$			;-- awanhin --
		LDA	ENXPSL,X
		SEC
		SBC	SCCH1
		CMP	#0FFB0H
		BMI	AWANHIN0100

		LDA	#000FFH
		STA	ENYUSN,X
		LDA	#EINIT
		STA	ENMODE,X

		RTL

AWANHIN0100	EQU	$
		JSR	AWANH_BG3_TRANS

;;;;;;;;		JSL	>TROBJ_CANCEL

		STZ	ENMUKI,X
		LDA	#0FFE8H
		STA	ENWRKC,X
		LDA	#00007
		STA	ENYUSN,X

		LDA	#00008H
		STA	ENXPOW,X
		LDA	#00400H
		STA	ENWRKA,X

		LDY	#015H
		STY	MANSEL

		LDA	ESCCH1
		SEC
		SBC	ENXPSL,X
		CLC
		ADC	#00040H
		STA	SCCH3
		LDA	ESCCV1
		SEC
		SBC	ENYPSL,X
		CLC
		ADC	#00040H
		STA	SCCV3

		RTL
;
;************************************************************************
;*		move	( 穴ほりわんわん（横型） )			*
;************************************************************************
;B		ENWRK0	キャラパターンフラグ
;B		ENWRK1	ダメージフラグ
;		ENWRK2	ROUTINE MODE INDEX
;		ENWRK4	目標Ｘ　ＰＯＳ．／なみだのＹスピード
;		ENWRK6	キャラパターンチェンジカウンター／なみだのＹ　ＰＯＳ．
;		ENWRK8	データインデックス（オートスクロール）
;		ENWRKA	ENXMAX セーブ
;		ENWRKC	ＢＧチェックＹ　ＰＯＳ．
;
;		ENCONT	なみだ上下カウンター
;
;		ENTIM0	ストップタイマー
;
AWANH_SUB	EQU	$
		WORD	AWANH_SUB0		;初期ダッシュ
		WORD	AWANH_SUB1		;チェイス（後退）
		WORD	AWANH_SUB2		;チェイス（前進）
		WORD	AWANH_SUB3		;チェイス（後退　オートスクロール）
		WORD	AWANH_SUB4		;チェイス（前進　オートスクロール）
;
		WORD	AWANH_SUB5		;泣いてる
		WORD	AWANH_SUB6		;退場チェック
;
AWANHMV		EQU	$			;-- awanhmv --
		JSR	AWANH_OAM_SET

		LDA	ENMODE,X
		CMP	#EMOVE
		BEQ	AWANHMV0300

		LDA	MANSEL				;ＢＧ３　ｎｏ　ｕｓｅ．．．
		AND	#01313H				;
		STA	MANSEL				;

		RTL

AWANHMV0300	EQU	$
		JSL	>ENMDCK

		TXY
		LDA	<ENWRK2,X
		ASL	A
		TAX
		JSR	(AWANH_SUB,X)

		LDY	<ENWRK2,X
		CPY	#005
		BPL	AWANHMV0900

		JSR	AWANH_CHAR_CHG

		JSR	AWANH_PLCHK
		JSR	AWANH_BGCHG

		LDA	#00008
		STA	ENXPOW,X

		LDA	ENDSXL,X
		CMP	#0FFC0H
		BPL	AWANHMV0700

		LDA	#00380H
		BRA	AWANHMV0800

AWANHMV0700	EQU	$
		LDA	ENWRKA,X

AWANHMV0800	EQU	$
		STA	ENXMAX,X

		SEC				;スピード遅れてる ?
		SBC	ENXSPD,X		;
		CLC				;
		ADC	#00100H			;
		CMP	#00200H			;
		BCC	AWANHMV0900		;  no: AWANHMV0900

		LDA	#00010H
		STA	ENXPOW,X

AWANHMV0900	EQU	$

		RTL
;
AWANH_EYE_XPOS	EQU	$
		WORD	0FFF0H,0FFEEH,0FFEDH
AWANH_EYE_YPOS	EQU	$
		WORD	0FFD1H,0FFCEH,0FFCCH
;
AWANH_OAM_SET	EQU	$
		LDY	<ENWRK0,X
		LDA	!AWANH_EYE_XPOS,Y
		CLC
		ADC	ENDSXL,X
		STA	<EWORK0
		LDA	!AWANH_EYE_YPOS,Y
		CLC
		ADC	ENDSYL,X
		STA	<EWORK2

		I16
		LDY	ENOAML,X
		LDA	<EWORK0
		STA	SOAM_DX+0+8*1,Y
		STA	SOAM_DX+0+8*2,Y
		CLC
		ADC	#00008
		STA	SOAM_DX+0+8*3,Y
		CLC
		ADC	#00008
		STA	SOAM_DX+0+8*0,Y

		LDA	<EWORK2
		STA	SOAM_DX+2+8*1,Y
		STA	SOAM_DX+2+8*3,Y
		CLC
		ADC	#00008
		STA	SOAM_DX+2+8*2,Y
		CLC
		ADC	#00008
		STA	SOAM_DX+2+8*0,Y
		I8

		LDA	ESCCH1
		SEC
		SBC	ENXPSL,X
		CLC
		ADC	#00040H
		STA	SCCH3
		CLC
		ADC	#00100H
		CMP	#00200H
		BCC	AWANH_O_SET0600

		LDA	#00100H
		STA	SCCH3

AWANH_O_SET0600 EQU	$
		LDY	<ENWRK1,X		;ダメージ受けてる ?
		BEQ	AWANH_O_SET0700		; no: AWANH_O_SET0700

		LDA	ENWRK6,X		;なみだのＹ　ＰＯＳ．セット
		AND	#0FF00H			;
		XBA				;
		STA	<EWORK0			;
		I16				;
		LDY	ENOAML,X		;
		LDA	SOAM_DX+2+8*09H,Y	;
		CLC				;
		ADC	<EWORK0			;
		STA	SOAM_DX+2+8*09H,Y	;
		LDA	SOAM_DX+2+8*0AH,Y	;
		CLC				;
		ADC	<EWORK0			;
		STA	SOAM_DX+2+8*0AH,Y	;
		I8
		LDA	#00000
		BRA	AWANH_O_SET0800

AWANH_O_SET0700 EQU	$
		LDA	<RANDM0
		AND	#00003
		SEC
		SBC	#00002

AWANH_O_SET0800 EQU	$
		CLC
		ADC	ESCCV1
		SEC
		SBC	ENYPSL,X
		CLC
		ADC	#00040H
		STA	SCCV3
		CLC
		ADC	#00100H
		CMP	#00200H
		BCC	AWANH_O_SET0900

		LDA	#00100H
		STA	SCCV3

AWANH_O_SET0900 EQU	$

		RTS
;
AWANH_SUB0	EQU	$
		TYX

		LDA	ENDSXL,X
		CMP	#00000H
		BMI	AWANH_SUB0500

		LDA	#00020H
		STA	ENWRKA,X
		LDY	#001
		LDA	ATSCRL_FLAG		;オートスクロール ?
		BEQ	AWANH_SUB0300		;  no: AWANH_SUB0300

		LDA	ENXPSL,X		;最初の目標Ｘ　ＰＯＳ．セット
		CLC				;
		ADC	#00080H			;
		STA	<ENWRK4,X		;

		LDY	#003

AWANH_SUB0300	EQU	$
		STY	<ENWRK2,X

AWANH_SUB0500	EQU	$

		RTS
;
AWANH_S1_XMAX	EQU	$
;		WORD	00100H,00180H,00200H,00280H
		WORD	00220H,00260H,00280H,002C0H
;
AWANH_SUB1	EQU	$
		TYX

		LDA	ENDSXL,X
		CMP	<ENWRK4,X
		BPL	AWANH_SUB1800

		LDA	<RANDM0
		AND	#0001FH
		STA	<ENWRK4,X

		LDA	<RANDM0
		AND	#00006
		TAY
		LDA	!AWANH_S1_XMAX,Y
		STA	ENWRKA,X

		INC	<ENWRK2,X

AWANH_SUB1800	EQU	$

		RTS
;
AWANH_S2_XMAX	EQU	$
;		WORD	00000H,00020H,00040H,00080H
		WORD	00080H,000A0H,000C0H,00100H
;
AWANH_SUB2	EQU	$
		TYX

		LDA	ENDSXL,X
		CMP	<ENWRK4,X
		BMI	AWANH_SUB2800

		LDA	<RANDM0
		AND	#0003FH
		CLC
		ADC	#0FFC0H
		STA	<ENWRK4,X

		LDA	<RANDM0
		AND	#00006
		TAY
		LDA	!AWANH_S2_XMAX,Y
		STA	ENWRKA,X

		DEC	<ENWRK2,X

AWANH_SUB2800	EQU	$

		RTS
;
AWANH_S3_IDX	EQU	$
		HEX	00,00,00,02,00,00,00,02
AWANH_S3_XMAX	EQU	$
		WORD	00200H,00400H
;
AWANH_SUB3	EQU	4
		TYX

		LDA	ENXPSL,X
		CMP	<ENWRK4,X
		BMI	AWANH_SUB3800

		LDA	<ENWRK4,X		;次の目標Ｘ　ＰＯＳ．セット
		CLC				;
		ADC	#00100H			;
		STA	<ENWRK4,X		;

		LDY	ENWRK8,X
		LDA	!AWANH_S3_IDX,Y
		TAY
		LDA	!AWANH_S3_XMAX,Y
		STA	ENWRKA,X

		INC	<ENWRK2,X

AWANH_SUB3800	EQU	$

		RTS
;
AWANH_S4_IDX	EQU	$
		HEX	02,00,00,00,00,02,00,00
AWANH_S4_XMAX	EQU	$
		WORD	00020H,00060H
AWANH_SUB4	EQU	4
		TYX

		LDA	ENXPSL,X
		CMP	<ENWRK4,X
		BMI	AWANH_SUB4800

		LDA	<ENWRK4,X
		CLC
		ADC	#00080H
		STA	<ENWRK4,X

		LDY	ENWRK8,X
		LDA	!AWANH_S4_IDX,Y
		TAY
		LDA	!AWANH_S4_XMAX,Y
		STA	ENWRKA,X

		LDA	ENWRK8,X
		INC	A
		AND	#00007
		STA	ENWRK8,X

		DEC	<ENWRK2,X

AWANH_SUB4800	EQU	$

		RTS
;
AWANH_SUB5	EQU	$
		TYX

		LDA	ENTIM0,X		;ストップ ?
		BNE	AWANH_SUB5800		; yes: AWANH_SUB5800

		LDA	<ENWRK4,X
		CLC
		ADC	#00008H
		CMP	#00200H
		BMI	AWANH_SUB5100

		LDA	#00200H

AWANH_SUB5100	EQU	$
		STA	<ENWRK4,X

		CLC
		ADC	ENWRK6,X
		CMP	#01400H
		BMI	AWANH_SUB5300

		LDA	#0FF00H
		STA	<ENWRK4,X
		LDA	#00056H			;［Ｓ］
		JSL	>SOUND_3_ON

		DEC	<ENCONT,X
		BNE	AWANH_SUB5200

		LDA	#00040H			;ストップタイマーセット
		STA	ENTIM0,X
		INC	<ENWRK2,X

AWANH_SUB5200	EQU	$
		LDA	#01400H

AWANH_SUB5300	EQU	$
		STA	ENWRK6,X

AWANH_SUB5800	EQU	$

		RTS
;
AWANH_SUB6	EQU	$
		TYX

		LDA	ENTIM0,X		;ストップ ?
		BNE	AWANH_SUB6100		; yes: AWANH_SUB6100

		LDA	#00040H
		CMP	ENGPOW,X
		BEQ	AWANH_SUB6100

		STA	ENGPOW,X

		LDA	#00400H
		STA	ENGMAX,X
		LDA	#00082H			;［Ｓ］
		JSL	>SOUND_3_ON

AWANH_SUB6100	EQU	$
		LDA	ENDSYL,X			;画面外 ?
		CMP	#00140H				;
		BMI	AWANH_SUB6800			;  no: AWANH_SUB6800

;;;;;;;;		JSL	>DISPCK3		;画面外 ?
;;;;;;;;		BCC	AWANH_SUB6800		;  no: AWANH_SUB6800

		STZ	TROBJ_ARIA

		JSL	>ENCLEAR_NORETN

		LDA	MANSEL				;ＢＧ３　ｎｏ　ｕｓｅ．．．
		AND	#01313H				;
		STA	MANSEL				;

AWANH_SUB6800	EQU	$

		RTS
;
AWANH_PLCHK	EQU	$
		LDA	EPWIDX,X
		CLC
		ADC	#00018H
		CMP	#00030H
		BCS	AWANH_PLCHK0800

		LDA	EPWIDY,X
		CLC
		ADC	#00030H
		CMP	#00060H
		BCS	AWANH_PLCHK0800

		JSL	>PLFLST

AWANH_PLCHK0800 EQU	$
		RTS
;
AWANH_BGCHG	EQU	$
		LDA	#00002
		STA	<EWORKE

AWANH_BGCHG0100 EQU	$
		LDA	ENXPSL,X
		CLC
		ADC	#00030H
		STA	R8
		STA	BGXPS1
		LDA	ENYPSL,X
		CLC
		ADC	ENWRKC,X
		STA	R0
		STA	BGYPS1
		M_CHIPR M_BGUNIT_READ
		LDX	<ENINDX

		LDA	R7			;食べれるＢＧ ?
		AND	#1111100000000000B	;
		CMP	#ET			;
		BNE	AWANH_BGCHG0300		;  no: AWANH_BGCHG0300

		JSL	>AWANH_BGBR0_ST2
		BRA	AWANH_BGCHG0400

AWANH_BGCHG0300 EQU	$
		LDA	R5			;ＢＧにあたった ?
		BEQ	AWANH_BGCHG0400		;  no: AWANH_BGCHG0400

		STZ	ENXSPD,X
		STZ	ENXPOW,X

		LDY	<ENWRK0,X		;大口開けてる ?
		CPY	#004			;
		BNE	AWANH_BGCHG0390		;  no: AWANH_BGCHG0390

		LDA	#00084H			;［Ｓ］
		JSL	>SOUND_3_ON

		LDA	#00040H
		STA	TILTCT2

		INC	<ENWRK1,X		;ダメージフラグセット
		STZ	<ENWRK4,X		;なみだのＹ　スピードクリア
		STZ	ENWRK6,X		;なみだのＹ　ＰＯＳ．クリア
		LDY	#003
		STY	<ENCONT,X		;なみだ上下カウンターセット
		LDA	#00040H
		STA	ENTIM0,X
		LDA	#0101110000000001B	;ＯＡＭ４ー＞１１（なみだ、歯にひびを出す）
		STA	ENMOD2,X
		LDY	#005
		STY	<ENWRK2,X

AWANH_BGCHG0390 EQU	$
		PLA
		RTL

AWANH_BGCHG0400 EQU	$
		LDA	ENWRKC,X		;次のチェックＹ　ＰＯＳ．計算
		CLC				;
		ADC	#00010H			;
		CMP	#00028H			;
		BMI	AWANH_BGCHG0500		;
						;
		LDA	#0FFE8H			;
						;
AWANH_BGCHG0500 EQU	$			;
		STA	ENWRKC,X		;

		DEC	<EWORKE
		BEQ	AWANH_BGCHG0800
		JMP	AWANH_BGCHG0100

AWANH_BGCHG0800 EQU	$

		RTS
;
AWANH_CHAR_CHG	EQU	$
		LDA	ENMOVX,X
		CLC
		ADC	ENWRK6,X
		CMP	#00008H
		BMI	AWANH_C_CHG0300

		SEC
		SBC	#00008
		PHA

		LDY	<ENWRK0,X		;ＢＧ３キャラパターンインデックスセット
		INY				;
		INY				;
		CPY	#006			;
		BNE	AWANH_C_CHG0200		;
						;
		LDY	#000			;
						;
AWANH_C_CHG0200 EQU	$			;
		STY	<ENWRK0,X		;

		JSR	AWANH_BG3_TRANS

		LDA	#00008H
		STA	ENTIM1,X

		PLA

AWANH_C_CHG0300 EQU	$
		STA	ENWRK6,X

		LDA	ENTIM1,X
		BNE	AWANH_C_CHG0800

		LDA	#00008H
		STA	ENTIM1,X
		STZ	ENWRK6,X

		LDY	<ENWRK0,X		;ＢＧ３キャラパターンインデックスセット
		INY				;
		INY				;
		CPY	#006			;
		BNE	AWANH_C_CHG0500		;
						;
		LDY	#000			;
						;
AWANH_C_CHG0500 EQU	$			;
		STY	<ENWRK0,X		;

		JSR	AWANH_BG3_TRANS

AWANH_C_CHG0800 EQU	$
		LDY	<ENWRK0,X
		CPY	#004
		BNE	AWANH_C_CHG0900

		LDA	#00064H		;［Ｓ］
		JSL	>SOUND_3_ON

AWANH_C_CHG0900	EQU	$

		RTS
;
;----------------------------------------------------------------
;-								-
;-		食べれるＢＧを壊す				-
;-								-
;-	BGXPS1	Ｘ座標						-
;-	BGYPS1	Ｙ座標						-
;-								-
;----------------------------------------------------------------
AWANH_BGBR0_ST2 EQU	$
		LDA	#BLK0
		STA	BGCGNO
		JSL	>UNITCHG

		LDX	<ENINDX
		BRA	BGBR0_SET0200

AWANH_BGBR0_SET EQU	$
		LDA	#BLK0
		STA	BGCGNO
		JSL	>UNITCHG

		LDX	<ENINDX

BGBR0_SET	EQU	$
		LDA	#0000AH		;［Ｓ］

BGBR0_SET0100	EQU	$
		JSL	>SOUND_3_ON
;
BGBR0_SET0200	EQU	$
		LDA	#BRBG0
		JSL	>EXINSR

		LDA	BGXPS1		;Ｘ座標セット
		AND	#0FFF0H
		STA	EXXPSL,Y
		LDA	BGYPS1		;Ｙ座標セット
		AND	#0FFF0H
		STA	EXYPSL,Y
;;;;;;;;		LDA	#0FF80H		;Ｘスピードセット
;;;;;;;;		STA	EXXSPD,Y
		LDA	#0FF80H		;Ｙスピードセット
		STA	EXYSPD,Y
		LDA	#0000AH		;初期パターンＮｏ．セット
		STA	EXCHPT,Y
		LDA	#00002		;初期タイマーセット
		STA	EXTIM0,Y
		LDA	#00008H		;重力セット
		STA	EXGPOW,Y
		LDA	#00400H		;最大重力セット
		STA	EXGMAX,Y

;;;;;;;;		LDA	#00007		;［Ｓ］
;;;;;;;;		STA	SOUND3

		RTL
;
AWANH_CHAR	EQU	$
		WORD	CHRSVBF+2
		WORD	CHRSVBF+2+20H*2*8
		WORD	CHRSVBF+2+20H*2*8*2
;
AWANH_BG3_TRANS EQU	$
		LDY	<ENWRK0,X
		LDA	!AWANH_CHAR,Y
		STA	<EWORK0

		PHX
		PHB
		M8
		LDA	#BANK VRAMDX
		PHA
		PLB

		MI16
		LDX	#VRAMDX
		INX
		INX

		LDA	#03400H+1		;Vram addr. set
		STA	00H,X			;

		LDA	#00180H			;inc. mode & DMA para. set
		STA	02H,X			; 2115h & 43*0h

		LDA	#00018H			;DMA B_bus addr. set ( 0021**H )
		STA	04H,X			;

		LDA	<EWORK0			;DMA A_bus addr. set
		STA	05H,X			;

		LDA	#BANK CHRSVBF		;DMA A_bus bank set
		STA	07H,X			;

		LDA	#(1FH+20H*6+7)*2	;DMA trans. data sum. set
		STA	08H,X			;

		TXA				;next data addr. calc.
		CLC				;
		ADC	#0000CH			;
		STA	0AH,X			;next data addr. set
		STA	VRAMDX			;last data addr. set

		I8

		PLB
		PLX

		RTS
;
;************************************************************************
;*		initial ( 回転床（スイッチブロック） )			*
;************************************************************************
RBLKGIN		EQU	$			;-- rblkgin --
RBLKYIN		EQU	$			;-- rblkyin --
		LDA	ENMYNO,X
		SEC
		SBC	#RBLKG
		ASL	A
		STA	<ENWRK4,X

		STZ	ENMUKI,X
		LDA	ENYPSL,X
		STA	ENWRKC,X

		RTL
;
;************************************************************************
;*		move	( 回転床（スイッチブロック） )			*
;************************************************************************
;		ENWRK0
;		ENWRK2
;		ENWRK4	DATA INDEX
;		ENWRK6
;		ENWRK8
;		ENWRKA
;		ENWRKC	セットＹ　ＰＯＳ．
;
;		ENCONT
;
;		ENTIM0
;
RBLKGMV		EQU	$			;-- rblkgmv --
RBLKYMV		EQU	$			;-- rblkymv --
		JSL	>ENMDCK

		LDY	<ENWRK4,X
		LDA	RFLSGANG,Y		;停止中 ?
		CMP	RFLSGCMP,Y		;
		BNE	RBLKGMV0700		;  no: RBLKGMV0700

		JSR	RFLLG_OBJ_SUB
;		 BRA	 RBLKGMV0800

RBLKGMV0700	EQU	$
;		 I16
;		 LDY	 ENOAML,X
;		 LDA	 SOAM_DX+4+8*0,Y
;		 AND	 #0F1FFH
;		 ORA	 #00800H
;		 STA	 SOAM_DX+4+8*0,Y
;		 I8

RBLKGMV0800	EQU	$
		JSL	>BOBBGCR
		JSL	>POBBGCR

		LDA	ENGPOW,X		;跳ね上がってる ?
		BEQ	RBLKGMV0900		;  no: RBLKGMV0900

		LDA	ENWRKC,X		;元の位置に戻った ?
		CMP	ENYPSL,X		;
		BPL	RBLKGMV0900		;  no: RBLKGMV0900

		STA	ENYPSL,X
		STZ	ENYSPD,X
		STZ	ENGPOW,X

RBLKGMV0900	EQU	$
		LDA	ENMOD2,X		;範囲クリアは絶対になし！！
		AND	#1111111111110011B	;
		STA	ENMOD2,X		;

		RTL
;
;************************************************************************
;*		initial ( 回転床 )					*
;************************************************************************
RFLSGIN		EQU	$			;-- rflsgin --
RFLSYIN		EQU	$			;-- rflsyin --
		LDA	ENMYNO,X
		SEC
		SBC	#RFLSG
		ASL	A
		STA	<ENWRK4,X

		TAY
		LDA	RFLSGTR0,Y
		BNE	RFLSGIN0500

		JSL	>TROBJ_SR_4x4_CL

		LDY	<ENWRK4,X
		LDA	ENTROB,X
		INC	A
		STA	RFLSGTR0,Y

		JSL	>TROBJ_SR_4x4
		BCS	RFLSGIN0300

		LDY	<ENWRK4,X
		LDA	#00000
		STA	RFLSGTR0,Y

		JMP	>ENCLEAR

RFLSGIN0300	EQU	$
		LDY	<ENWRK4,X
		LDA	ENTROB,X
		INC	A
		STA	RFLSGTR1,Y

		LDA	#0FFFFH
		STA	ENTROB,X

		JSR	RFLSG_ROT_SUB

RFLSGIN0500	EQU	$
		LDY	<ENWRK4,X
		LDA	RFLSGSUM,Y
		INC	A
		STA	RFLSGSUM,Y

		STZ	ENMUKI,X
		LDA	#0001DH-004
		STA	EWIDEX,X
		LDA	#00008-1
		STA	EWIDEY,X

		RTL
;
;************************************************************************
;*		move	( 回転床 )					*
;************************************************************************
;		ENWRK0
;		ENWRK2
;		ENWRK4	DATA INDEX
;		ENWRK6
;		ENWRK8
;		ENWRKA
;		ENWRKC
;
;		ENCONT
;
;		ENTIM0
;
;		RFLSGFLG セットフラグ
;		RFLSGTR0 ＥＮＴＲＯＢ0 + 1
;		RFLSGTR1 ＥＮＴＲＯＢ1 + 1
;		RFLSGSUM 総数
;		RFLSGANG 回転角
;		RFLSGCMP 目標回転角
;
RFLSGMV		EQU	$			;-- rflsgmv --
RFLSYMV		EQU	$			;-- rflsymv --
		JSR	RFLSG_OAM_SET

		JSL	>ENMDCK

		JSR	RFLSG_DISP_CHK

		JSR	RFLSG_PLCHK

		JSR	RFLSG_BBCHK

		JSR	RFLSG_ROT_SET

		LDA	ENMOD2,X			;範囲クリアは絶対になし！！
		AND	#1111111111110011B		;
		STA	ENMOD2,X			;

		RTL
;
RFLSG_OAM_SET	EQU	$
		LDA	ENOAML,X
		BPL	RFLSG_O_SET0100

RFLSG_O_SET0000 EQU	$

		RTS

RFLSG_O_SET0100 EQU	$
		LDY	<ENWRK4,X
		LDA	RFLSGTR0,Y
		DEC	A
		STA	ENTROB,X

		JSL	>TROBJ_OAM_4x4

		LDY	<ENWRK4,X
		LDA	RFLSGTR1,Y
		DEC	A
		STA	ENTROB,X

		I16
		LDA	ENOAML,X
		CLC
		ADC	#00008*4
		TAY

		JSL	>TROBJ_OAM_4x4_I
		IDX8

		LDA	#0FFFFH
		STA	ENTROB,X

		LDA	ENSTFG
		ORA	BIRIBIRI
		ORA	ITEMNO
		BNE	RFLSG_OAM_SET2

		LDY	<ENWRK4,X
		LDA	RFLSGFLG,Y		;ビットマップを描く ?
		CMP	FRCNT2			;
		BNE	RFLSG_O_SET0000		; yes: RFLSG_O_SET0000

RFLSG_OAM_SET2	EQU	$
		LDY	<ENWRK4,X
		LDA	RFLSGXPS,Y
		STA	<EWORK0
		LDA	RFLSGYPS,Y
		STA	<EWORK2
		LDA	RFLSGXP2,Y
		STA	<EWORK4
		LDA	RFLSGYP2,Y
		STA	<EWORK6

		I16
		LDY	ENOAML,X
		BMI	RFLSG_O_SET0800

		LDA	SOAM_DX+0+8*0,Y
		SEC
		SBC	<EWORK0
		STA	SOAM_DX+0+8*0,Y
		STA	SOAM_DX+0+8*2,Y
		LDA	SOAM_DX+0+8*1,Y
		SEC
		SBC	<EWORK0
		STA	SOAM_DX+0+8*1,Y
		STA	SOAM_DX+0+8*3,Y

		LDA	SOAM_DX+2+8*0,Y
		SEC
		SBC	<EWORK2
		STA	SOAM_DX+2+8*0,Y
		STA	SOAM_DX+2+8*1,Y
		LDA	SOAM_DX+2+8*2,Y
		SEC
		SBC	<EWORK2
		STA	SOAM_DX+2+8*2,Y
		STA	SOAM_DX+2+8*3,Y

		LDA	SOAM_DX+0+8*4,Y
		CLC
		ADC	<EWORK4
		STA	SOAM_DX+0+8*4,Y
		STA	SOAM_DX+0+8*6,Y
		LDA	SOAM_DX+0+8*5,Y
		CLC
		ADC	<EWORK4
		STA	SOAM_DX+0+8*5,Y
		STA	SOAM_DX+0+8*7,Y

		LDA	SOAM_DX+2+8*4,Y
		CLC
		ADC	<EWORK6
		STA	SOAM_DX+2+8*4,Y
		STA	SOAM_DX+2+8*5,Y
		LDA	SOAM_DX+2+8*6,Y
		CLC
		ADC	<EWORK6
		STA	SOAM_DX+2+8*6,Y
		STA	SOAM_DX+2+8*7,Y

RFLSG_O_SET0800 EQU	$
		I8

RFLSG_D_CHK0000 EQU	$

		RTS
;
RFLSG_DISP_CHK	EQU	$
		JSL	>DISPCK2		;画面外 ?
		BCC	RFLSG_D_CHK0000		;  no: RFLSG_D_CHK0000

		LDY	<ENWRK4,X
		LDA	RFLSGSUM,Y		;最後の一匹 ?
		DEC	A			;
		STA	RFLSGSUM,Y		;
		BNE	RFLSG_D_CHK0800		;  no: RFLSG_D_CHK0800

		LDA	RFLSGTR0,Y
		DEC	A
		STA	ENTROB,X
		LDA	#00000
		STA	RFLSGTR0,Y
		JSL	>TROBJ_CLEAR

		LDY	<ENWRK4,X
		LDA	RFLSGTR1,Y
		DEC	A
		STA	ENTROB,X
		LDA	#00000
		STA	RFLSGTR1,Y
		JSL	>TROBJ_CLEAR

RFLSG_D_CHK0800 EQU	$
		LDA	#0FFFFH
		STA	ENTROB,X

		PLA
		JMP	>ENCLEAR
;
RFLSG_ROT_SET	EQU	$
		LDY	<ENWRK4,X
		LDA	FRCNT2			;ビットマップ描くやつ ?
		CMP	RFLSGFLG,Y		;
		BEQ	RFLSG_R_SET0800		;  no: RFLSG_R_SET0800

		STA	RFLSGFLG,Y

		LDA	RFLSGANG,Y		;停止中 ?
		CMP	RFLSGCMP,Y		;
;;;;;;;;		BNE	RFLSG_R_SET0200
		BEQ	RFLSG_R_SET0500		; yes: RFLSG_R_SET0500

RFLSG_R_SET0200 EQU	$
		SEC
		SBC	#00020H
		STA	RFLSGANG,Y
		SEC
		SBC	RFLSGCMP,Y
		CLC
		ADC	#0000FH
		CMP	#0001EH
		BCS	RFLSG_R_SET0300

		LDA	RFLSGCMP,Y
		STA	RFLSGANG,Y

RFLSG_R_SET0300 EQU	$
		JSR	RFLSG_ROT_SUB

RFLSG_R_SET0500 EQU	$
		JSR	RFLSG_OAM_SET2

RFLSG_R_SET0800 EQU	$

		RTS
;
RFLSG_ROT_SUB	EQU	$
;＊＊＊＊＊＊＊＊＜　ビットマップエリアセット　＞＊＊＊＊＊＊＊＊＊＊
		LDA	#CIPCHD3+40C0H+000	;(R12) <-- 転送元アドレスセット
		STA	R12			;
		LDA	#BANK CIPCHD3+40C0H+000 ;(R13) <-- 転送元バンクセット
		STA	R13			;

		LDY	<ENWRK4,X
		LDA	RFLSGANG,Y		;(R5) <- 回転角セット
		AND	#001FEH			;
		LSR	A			;
		STA	<EWORK0			;
		STA	R5			;

		LDA	#00100H			;(R6) <- 倍率セット
		STA	R6			;

		LDA	RFLSGTR0,Y
		TAX
		DEX
		LDA	>TROBJ_PLOT_X,X		;(R3) <- ビットマップ座標＿Ｘセット
		STA	R3			;
		LDA	>TROBJ_PLOT_Y,X		;(R2) <- ビットマップ座標＿Ｙセット
		STA	R2			;
;
;-------------- OBJ mode 7 set ----------------------------------
		M_CHIP	C_32_ROTZOM

		LDX	<ENINDX

;＊＊＊＊＊＊＊＊＜　ビットマップエリアセット　＞＊＊＊＊＊＊＊＊＊＊
		LDA	#CIPCHD3+40C0H+000	;(R12) <-- 転送元アドレスセット
		STA	R12			;
		LDA	#BANK CIPCHD3+40C0H+000 ;(R13) <-- 転送元バンクセット
		STA	R13			;

		LDA	<EWORK0			;(R5) <- 回転角セット
		EOR	#0FFFFH			;
		INC	A			;
		AND	#000FFH			;
		STA	R5			;

		LDA	#00100H			;(R6) <- 倍率セット
		STA	R6			;

		LDY	<ENWRK4,X
		LDA	RFLSGTR1,Y
		TAX
		DEX
		LDA	>TROBJ_PLOT_X,X		;(R3) <- ビットマップ座標＿Ｘセット
		STA	R3			;
		LDA	>TROBJ_PLOT_Y,X		;(R2) <- ビットマップ座標＿Ｙセット
		STA	R2			;
;
;-------------- OBJ mode 7 set ----------------------------------
		M_CHIP	C_32_ROTZOM

		LDX	<ENINDX

		INC	OBM7WF		;mode 7 OBJ chara DMA "ON"

		LDA	#0000DH
		STA	R6
		LDY	<ENWRK4,X
		LDA	RFLSGANG,Y
		AND	#001FEH
		STA	R1
		M_CHIP	M_ENMY_1P_ROT
		LDX	<ENINDX
		LDY	<ENWRK4,X
		LDA	R0
		STA	RFLSGXPS,Y
		LDA	R1
		STA	RFLSGYPS,Y
		LDA	#0000CH
		STA	R6
		LDY	<ENWRK4,X
		LDA	RFLSGANG,Y
		AND	#001FEH
		STA	R1
		M_CHIP	M_ENMY_1P_ROT
		LDX	<ENINDX
		LDY	<ENWRK4,X
		LDA	R0
		STA	RFLSGXP2,Y
		LDA	R1
		STA	RFLSGYP2,Y

		RTS
;
RFLSG_PLCHK	EQU	$
		LDY	<ENWRK4,X
		LDA	RFLSGANG,Y		;回転中 ?
		CMP	RFLSGCMP,Y		;
		BNE	RFLSG_PLCHK1000		; yes: RFLSG_PLCHK1000

		JSL	>POBBGCR		;縦方向からあたった ?
		BCC	RFLSG_PLCHK0800		;  no: RFLSG_PLCHK0800

		DEC	<EWORKE			;トゲの面にあたった ?
		LDY	<ENWRK4,X		;
		LDA	RFLSGSW0,Y		;
		DEC	A			;
		EOR	<EWORKE			;
		BPL	RFLSG_PLCHK0800		;  no: RFLSG_PLCHK0800

		JSL	>PLFLST

RFLSG_PLCHK0800 EQU	$

		RTS

RFLSG_PLCHK1000 EQU	$
		LDA	EPWIDX,X
		CLC
		ADC	#0001DH-04+8
		CMP	#(0001DH-04+8)*2
		BCS	RFLSG_PLCHK0800

		LDA	EPWIDY,X
		CLC
		ADC	#00008-1+0CH
		CMP	#(00008-1+0CH)*2
		BCS	RFLSG_PLCHK0800

		LDA	EPWIDX,X
		STA	R1
		LDA	EPWIDY,X
		STA	R2
		M_CHIP	M_RAD_GET
		LDX	<ENINDX

		LDA	R0
		STA	<EWORK0
		CLC
		ADC	#00080H
		AND	#001FEH
		STA	R1
		LDA	#00400H
		STA	R6
		M_CHIP	M_ENMY_1P_ROT
		LDX	<ENINDX
		LDA	PLBGCR
		AND	#0000000111100000B
		BEQ	RFLSG_PLCHK1100

		AND	#0000000110000000B
		DEC	A
		EOR	R0
		BPL	RFLSG_PLCHK1300

RFLSG_PLCHK1100 EQU	$
		LDA	R0

RFLSG_PLCHK1200 EQU	$
		STA	PLXSPD
		STA	PLMVSP

RFLSG_PLCHK1300 EQU	$
		LDA	R1
		EOR	#0FFFFH
		INC	A
		STA	<EWORK0
		LDA	PLBGCR
		AND	#0000000000011111B
		BEQ	RFLSG_PLCHK1400

		AND	#0000000000011000B
		DEC	A
		EOR	<EWORK0
		BMI	RFLSG_PLCHK1700

RFLSG_PLCHK1400 EQU	$
		LDA	<EWORK0
		BPL	RFLSG_PLCHK1600

		PHA
		LDA	#P006
		STA	PLJUMP
		LDA	#001+8000H
		STA	PLSPJP
		PLA
		ASL	A

RFLSG_PLCHK1600 EQU	$
		STA	PLYSPD

RFLSG_PLCHK1700 EQU	$
		LDY	<ENWRK4,X
		LDA	RFLSGANG,Y
		AND	#001FEH
		SEC
		SBC	<EWORK0
		CLC
		ADC	#00100H
		CMP	#00200H
		BCC	RFLSG_PLCHK1800

		JSL	>PLFLST

RFLSG_PLCHK1800 EQU	$
RFLSG_P_SB0000	EQU	$

		RTS
;
RFLSG_BBCHK	EQU	$
		LDY	<ENWRK4,X
		LDA	RFLSGANG,Y		;回転中 ?
		CMP	RFLSGCMP,Y		;
		BNE	RFLSG_BBCHK0800		; yes: RFLSG_BBCHK0800

		JSL	>BOBBGCR		;縦方向からあたった ?
;;;;;;;;		BCC	RFLSG_BBCHK0800		;  no: RFLSG_BBCHK0800
;;;;;;;;
;;;;;;;;		LDY	<EWORKE			;赤ちゃん下にあたった ?
;;;;;;;;		BEQ	RFLSG_BBCHK0800		; yes: RFLSG_BBCHK0800
;;;;;;;;
;;;;;;;;		LDY	<ENWRK4,X		;トゲの面にあたった ?
;;;;;;;;		LDA	RFLSGSW0,Y		;
;;;;;;;;		BNE	RFLSG_BBCHK0800		;  no: RFLSG_BBCHK0800
;;;;;;;;
;;;;;;;;		LDY	<ENWRK2+BABY_INDEX	;シャボン防御 ?
;;;;;;;;		CPY	#BABYM_SHABON2		;
;;;;;;;;		BPL	RFLSG_BBCHK0800		; yes: RFLSG_BBCHK0800
;;;;;;;;
;;;;;;;;		JSL	>BABYM_SHABN_C2
;;;;;;;;
RFLSG_BBCHK0800 EQU	$

		RTS
;
;************************************************************************
;*		initial ( 回転床 )					*
;************************************************************************
RFLLGIN		EQU	$			;-- rfllgin --
		JSL	>TROBJ_SR_4x4_CL

		LDA	ENTROB,X
		STA	ENWRKC,X

		JSL	>TROBJ_SR_4x4
		BCS	RFLLGIN0100

		LDA	ENWRKC,X
		STA	ENTROB,X
		JMP	>ENCLEAR

RFLLGIN0100	EQU	$
		JSR	RFLLG_ROT_SUB

		STZ	ENWRKA,X		;目標回転角セット
		STZ	ENMUKI,X

		LDA	#00008
		STA	EWIDEY,X

		RTL
;
;************************************************************************
;*		move	( 回転床 )					*
;************************************************************************
;		ENWRK0	左セットＸ　ＰＯＳ．
;		ENWRK2	左セットＹ　ＰＯＳ．
;		ENWRK4	右セットＸ　ＰＯＳ．
;		ENWRK6	右セットＹ　ＰＯＳ．
;		ENWRK8	回転角
;		ENWRKA	目標回転角
;		ENWRKC	ENTROB セーブ
;
;		ENCONT	スイッチ
;
;		ENTIM0
;
RFLLGMV		EQU	$			;-- rfllgmv --
		JSR	RFLLG_OAM_SET

		JSL	>ENMDCK

		JSR	RFLLG_DISP_CHK

		JSR	RFLLG_OBJ_CHK

		JSR	RFLLG_PLCHK

		JSR	RFLLG_BBCHK

		JSR	RFLLG_ROT_SET

		LDA	ENMOD2,X			;範囲クリアは絶対になし！！
		AND	#1111111111110011B		;
		STA	ENMOD2,X			;

		RTL
;
RFLLG_OAM_SET	EQU	$
		LDA	ENOAML,X
		BPL	RFLLG_O_SET0100

RFLLG_O_SET0000 EQU	$

		RTS

RFLLG_O_SET0100 EQU	$
		LDA	ENSTFG
		ORA	BIRIBIRI
		ORA	ITEMNO
		BEQ	RFLLG_O_SET0000

RFLLG_OAM_SET2	EQU	$
		JSL	>TROBJ_OAM_4x4

		I16
		LDA	ENOAML,X
		CLC
		ADC	#00008*(4*2)
		TAY

		JSL	>TROBJ_OAM_4x4_I
		IDX8

		LDA	ENTROB,X
		PHA
		LDA	ENWRKC,X
		STA	ENTROB,X

		I16
		LDA	ENOAML,X
		CLC
		ADC	#00008*(4*1)
		TAY

		JSL	>TROBJ_OAM_4x4_I
		IDX8

		I16
		LDA	ENOAML,X
		CLC
		ADC	#00008*(4*3)
		TAY

		JSL	>TROBJ_OAM_4x4_I
		IDX8

		PLA
		STA	ENTROB,X

		LDA	<ENWRK0,X
		STA	<EWORK0
		LDA	<ENWRK2,X
		STA	<EWORK2
		LDA	<ENWRK4,X
		STA	<EWORK4
		LDA	ENWRK6,X
		STA	<EWORK6

		I16
		LDY	ENOAML,X
		BMI	RFLLG_O_SET0000

		LDA	SOAM_DX+0+8*0,Y
		SEC
		SBC	<EWORK0
		STA	SOAM_DX+0+8*0,Y
		STA	SOAM_DX+0+8*2,Y
		LDA	SOAM_DX+0+8*1,Y
		SEC
		SBC	<EWORK0
		STA	SOAM_DX+0+8*1,Y
		STA	SOAM_DX+0+8*3,Y

		LDA	SOAM_DX+2+8*0,Y
		SEC
		SBC	<EWORK2
		STA	SOAM_DX+2+8*0,Y
		STA	SOAM_DX+2+8*1,Y
		LDA	SOAM_DX+2+8*2,Y
		SEC
		SBC	<EWORK2
		STA	SOAM_DX+2+8*2,Y
		STA	SOAM_DX+2+8*3,Y

		LDA	SOAM_DX+0+8*4,Y
		SEC
		SBC	<EWORK4
		STA	SOAM_DX+0+8*4,Y
		STA	SOAM_DX+0+8*6,Y
		LDA	SOAM_DX+0+8*5,Y
		SEC
		SBC	<EWORK4
		STA	SOAM_DX+0+8*5,Y
		STA	SOAM_DX+0+8*7,Y

		LDA	SOAM_DX+2+8*4,Y
		SEC
		SBC	<EWORK6
		STA	SOAM_DX+2+8*4,Y
		STA	SOAM_DX+2+8*5,Y
		LDA	SOAM_DX+2+8*6,Y
		SEC
		SBC	<EWORK6
		STA	SOAM_DX+2+8*6,Y
		STA	SOAM_DX+2+8*7,Y
;
;
		LDA	SOAM_DX+0+8*08H,Y
		CLC
		ADC	<EWORK4
		STA	SOAM_DX+0+8*08H,Y
		STA	SOAM_DX+0+8*0AH,Y
		LDA	SOAM_DX+0+8*09H,Y
		CLC
		ADC	<EWORK4
		STA	SOAM_DX+0+8*09H,Y
		STA	SOAM_DX+0+8*0BH,Y

		LDA	SOAM_DX+2+8*08H,Y
		CLC
		ADC	<EWORK6
		STA	SOAM_DX+2+8*08H,Y
		STA	SOAM_DX+2+8*09H,Y
		LDA	SOAM_DX+2+8*0AH,Y
		CLC
		ADC	<EWORK6
		STA	SOAM_DX+2+8*0AH,Y
		STA	SOAM_DX+2+8*0BH,Y

		LDA	SOAM_DX+0+8*0CH,Y
		CLC
		ADC	<EWORK0
		STA	SOAM_DX+0+8*0CH,Y
		STA	SOAM_DX+0+8*0EH,Y
		LDA	SOAM_DX+0+8*0DH,Y
		CLC
		ADC	<EWORK0
		STA	SOAM_DX+0+8*0DH,Y
		STA	SOAM_DX+0+8*0FH,Y

		LDA	SOAM_DX+2+8*0CH,Y
		CLC
		ADC	<EWORK2
		STA	SOAM_DX+2+8*0CH,Y
		STA	SOAM_DX+2+8*0DH,Y
		LDA	SOAM_DX+2+8*0EH,Y
		CLC
		ADC	<EWORK2
		STA	SOAM_DX+2+8*0EH,Y
		STA	SOAM_DX+2+8*0FH,Y

		LDA	ENTIM1,X
		BNE	RFLLG_O_SET1000

		LDA	ENWRK8,X
		CMP	ENWRKA,X
		BEQ	RFLLG_O_SET1800

RFLLG_O_SET1000 EQU	$
		LDA	SOAM_DX+4+8*10H,Y
		AND	#0F1FFH
		ORA	#0F800H
		STA	SOAM_DX+4+8*10H,Y

RFLLG_O_SET1800 EQU	$
		I8

		RTS
;
RFLLG_OBJ_CHK	EQU	$
		LDA	ENWRK8,X		;停止中 ?
		CMP	ENWRKA,X		;
		BNE	RFLLG_O_CHK0800		; yes: RFLLG_O_CHK0800

		JSR	RFLLG_OBJ_SUB

RFLLG_O_CHK0800 EQU	$
		JSL	>POBBGCR		;横からあたった ?
		BCS	RFLLG_O_CHK0900		;  no: RFLLG_O_CHK0900

		STZ	ECRSFG,X

RFLLG_O_CHK0900 EQU	$
		JSL	>BOBBGCR

		RTS
;
RFLLG_OBJ_SUB	EQU	$
		LDY	PLYSPD+1
		BPL	RFLLG_O_SUB0500

		LDY	PLJUMP
		BEQ	RFLLG_O_SUB0500

		LDA	EPWIDX,X
		CLC
		ADC	#00010H
		CMP	#00020H
		BCS	RFLLG_O_SUB0500

		LDA	EPWIDY,X
		CMP	#0FFE8H
		BMI	RFLLG_O_SUB0500
		CMP	#0FFF0H
		BPL	RFLLG_O_SUB0500

		STZ	PLYSPD
		STZ	PLSPJP			;ふんばりフラグクリア
		BRA	RFLLG_O_SUB0700

RFLLG_O_SUB0500 EQU	$
		LDY	ECRSFG,X
		DEY
		BMI	RFLLG_O_SUB0800

		LDA	ENMODE,Y
		CMP	#EMOVE
		BNE	RFLLG_O_SUB0800

		LDA	ENSHOT,Y
		BEQ	RFLLG_O_SUB0800

		TYX
		JSL	>ENDEATH_SET_4

RFLLG_O_SUB0700 EQU	$
		LDA	#00032H			;［Ｓ］
		JSL	>SOUND_3_ON
;;;;;;;;		LDA	#00029H			;［Ｓ］
;;;;;;;;		STA	SOUND3

		LDA	ENMYNO,X
		CMP	#RFLLG
		BEQ	RFLLG_O_SUB0780

		LDY	<ENWRK4,X
		LDA	RFLSGSW0,Y
		EOR	#00002H
		STA	RFLSGSW0,Y
		LDA	RFLSGCMP,Y
		SEC
		SBC	#00500H
		STA	RFLSGCMP,Y

		LDA	ENYSPD,X
		BMI	RFLLG_O_SUB0740

		LDA	#0FD00H
		STA	ENYSPD,X
		LDA	#00040H
		STA	ENGPOW,X

RFLLG_O_SUB0740 EQU	$

		RTS

RFLLG_O_SUB0780 EQU	$
		LDA	ENWRKA,X
		SEC
		SBC	#00100H
		STA	ENWRKA,X

		LDA	#00020H
		STA	ENTIM1,X

RFLLG_O_SUB0800 EQU	$

		RTS
;
RFLLG_ROT_SET	EQU	$
		LDA	ENTIM1,X
		BEQ	RFLLG_R_SET0100
		DEC	A
		BNE	RFLLG_R_SET0500

		LDA	<ENCONT,X
		EOR	#00002H
		STA	<ENCONT,X
		LDA	#00040H			;［Ｓ］
		JSL	>SOUND_3_ON
;;;;;;;;		LDA	#0000FH		;［Ｓ］
;;;;;;;;		STA	SOUND3
		BRA	RFLLG_R_SET0500

RFLLG_R_SET0100 EQU	$
		LDA	ENWRK8,X		;停止中 ?
		CMP	ENWRKA,X		;
		BEQ	RFLLG_R_SET0500		; yes: RFLLG_R_SET0500

		AND	#000FEH
		SEC
		SBC	#00080H-2
		CMP	#00004H
		BCS	RFLLG_R_SET0200

		LDA	ENTIM0,X
		BEQ	RFLLG_R_SET0700
		DEC	A
		BNE	RFLLG_R_SET0500

		LDA	#00040H			;［Ｓ］
		JSL	>SOUND_3_ON
;;;;;;;;		LDA	#0000FH		;［Ｓ］
;;;;;;;;		STA	SOUND3

RFLLG_R_SET0200 EQU	$
		LDA	ENWRK8,X
		SEC
		SBC	#00004H
		STA	ENWRK8,X
		SEC
		SBC	ENWRKA,X
		CLC
		ADC	#00002H
		CMP	#00004H
		BCS	RFLLG_R_SET0300

		LDA	ENWRKA,X
		STA	ENWRK8,X

		LDA	#00041H			;［Ｓ］
		JSL	>SOUND_3_ON
;;;;;;;;		LDA	#00010H		;［Ｓ］
;;;;;;;;		STA	SOUND3

RFLLG_R_SET0300 EQU	$
		JSR	RFLLG_ROT_SUB

RFLLG_R_SET0500 EQU	$
		JSR	RFLLG_OAM_SET2

		RTS

RFLLG_R_SET0700 EQU	$
		LDA	#00040H
		STA	ENTIM0,X

		LDA	#00041H			;［Ｓ］
		JSL	>SOUND_3_ON
;;;;;;;;		LDA	#00010H		;［Ｓ］
;;;;;;;;		STA	SOUND3

		BRA	RFLLG_R_SET0500
;
RFLLG_ROT_SUB	EQU	$
;＊＊＊＊＊＊＊＊＜　ビットマップエリアセット　＞＊＊＊＊＊＊＊＊＊＊
		LDA	#CIPCHD3+40C0H+000	;(R12) <-- 転送元アドレスセット
		STA	R12			;
		LDA	#BANK CIPCHD3+40C0H+000 ;(R13) <-- 転送元バンクセット
		STA	R13			;

		LDA	ENWRK8,X		;(R5) <- 回転角セット
		AND	#001FEH			;
		LSR	A			;
		STA	R5			;

		LDA	#00100H			;(R6) <- 倍率セット
		STA	R6			;

		LDY	ENTROB,X
		TYX
		LDA	>TROBJ_PLOT_X,X		;(R3) <- ビットマップ座標＿Ｘセット
		STA	R3			;
		LDA	>TROBJ_PLOT_Y,X		;(R2) <- ビットマップ座標＿Ｙセット
		STA	R2			;
;
;-------------- OBJ mode 7 set ----------------------------------
		M_CHIP	C_32_ROTZOM

		LDX	<ENINDX

;＊＊＊＊＊＊＊＊＜　ビットマップエリアセット　＞＊＊＊＊＊＊＊＊＊＊
		LDA	#CIPCHD3+40C0H+000	;(R12) <-- 転送元アドレスセット
		STA	R12			;
		LDA	#BANK CIPCHD3+40C0H+000 ;(R13) <-- 転送元バンクセット
		STA	R13			;

		LDA	ENWRK8,X		;(R5) <- 回転角セット
		EOR	#0FFFFH			;
		INC	A			;
		AND	#001FEH			;
		LSR	A			;
		STA	R5			;

		LDA	#00100H			;(R6) <- 倍率セット
		STA	R6			;

		LDY	ENWRKC,X
		TYX
		LDA	>TROBJ_PLOT_X,X		;(R3) <- ビットマップ座標＿Ｘセット
		STA	R3			;
		LDA	>TROBJ_PLOT_Y,X		;(R2) <- ビットマップ座標＿Ｙセット
		STA	R2			;
;
;-------------- OBJ mode 7 set ----------------------------------
		M_CHIP	C_32_ROTZOM

		LDX	<ENINDX

		INC	OBM7WF		;mode 7 OBJ chara DMA "ON"

		LDA	#0002EH
		STA	R6
		LDA	ENWRK8,X
		AND	#001FEH
		STA	R1
		M_CHIP	M_ENMY_1P_ROT
		LDX	<ENINDX
		LDA	R0
		STA	<ENWRK0,X
		LDA	R1
		STA	<ENWRK2,X
		LDA	#00016H
		STA	R6
		LDA	ENWRK8,X
		AND	#001FEH
		STA	R1
		M_CHIP	M_ENMY_1P_ROT
		LDX	<ENINDX
		LDA	R0
		STA	<ENWRK4,X
		LDA	R1
		STA	ENWRK6,X

RFLLG_D_CHK0000 EQU	$

		RTS
;
RFLLG_DISP_CHK	EQU	$
		JSL	>DISPCK1		;画面外 ?
		BCC	RFLLG_D_CHK0000		;  no: RFLLG_D_CHK0000

		JSL	>TROBJ_CLEAR

		LDA	ENWRKC,X
		STA	ENTROB,X
		JSL	>TROBJ_CLEAR

		PLA
		RTL
;
RFLLG_PLCHK	EQU	$
		LDA	ENTIM1,X		;回転中 ?
		BNE	RFLLG_PLCHK0600		;  no: RFLLG_PLCHK0600

		LDA	ENTIM0,X		;回転中 ?
		BEQ	RFLLG_PLCHK0500		; yes: RFLLG_PLCHK0500

		LDA	#00008-1
		STA	<EWORKC
		LDA	#00038H
		STA	<EWORKE
		JSR	RFLLG_PLCHK_SUB		;横からあたった ?
		BCS	RFLLG_PLCHK0100		;  no: RFLLG_PLCHK0100

		LDA	<ENCONT,X		;トゲの面にあたった ?
		DEC	A			;
		EOR	EPWIDX,X		;
		BPL	RFLLG_PLCHK0100		;  no: RFLLG_PLCHK0100

		JSL	>PLFLST

RFLLG_PLCHK0100 EQU	$

		RTS

RFLLG_PLCHK0500 EQU	$
		LDA	ENWRK8,X		;回転中 ?
		CMP	ENWRKA,X		;
		BNE	RFLLG_PLCHK1000		; yes: RFLLG_PLCHK1000

RFLLG_PLCHK0600 EQU	$
		LDY	ECRSFG,X
		BMI	RFLLG_PLCHK0800

		LDA	#00038H
		STA	<EWORKC
		LDA	#00008-1
		STA	<EWORKE

		JSR	RFLLG_PLCHK_SUB		;横からあたった ?
		BCC	RFLLG_PLCHK0800		; yes: RFLLG_PLCHK0800

		DEC	<EWORKE			;トゲの面にあたった ?
		LDA	<ENCONT,X		;
		DEC	A			;
		EOR	<EWORKE			;
		BPL	RFLLG_PLCHK0800		;  no: RFLLG_PLCHK0800

		LDY	ECRSFG,X		;プレイヤー本当に衝突した ?
		BPL	RFLLG_PLCHK0800		;  no: RFLLG_PLCHK0800

		JSL	>PLFLST

RFLLG_PLCHK0800 EQU	$

		RTS

RFLLG_PLCHK1000 EQU	$
		JSR	RFLLG_PLCHK_SB2

		RTS
;
RFLLG_PLCHK_SUB EQU	$
		STZ	ECRSFG,X

		LDA	PWIDEX
		CLC
		ADC	<EWORKC
		ASL	A
		STA	<EWORK0
		LSR	A

		CLC
		ADC	EPWIDX,X
		CMP	<EWORK0
		BCS	RFLLG_P_SUB0800

		LDA	PWIDEY
		CLC
		ADC	<EWORKE
		ASL	A
		STA	<EWORK0
		LSR	A

		CLC
		ADC	EPWIDY,X
		CMP	<EWORK0
		BCS	RFLLG_P_SUB0800

		LDA	#000FFH
		STA	ECRSFG,X

		LDA	EWIDEX,X
		STA	R0
		LDA	EWIDEY,X
		STA	R1

		LDA	<EWORKC
		STA	EWIDEX,X
		LDA	<EWORKE
		STA	EWIDEY,X

		JSL	>POBBGCR
		PHP

		LDA	R0
		STA	EWIDEX,X
		LDA	R1
		STA	EWIDEY,X

		PLP

RFLLG_P_SUB0800 EQU	$

		RTS
;
RFLLG_PLCHK_SB2 EQU	$
		LDA	ENWRK8,X
		CLC
		ADC	#00080H
		AND	#000FEH
		STA	R1
		LDA	#00006
		STA	R6
		M_CHIP	M_ENMY_1P_ROT
		LDX	<ENINDX
		LDA	R0
		BMI	RFLLG_P_SB20000

		EOR	#0FFFFH
		INC	A

RFLLG_P_SB20000 EQU	$
		SEC
		SBC	PWIDEX
		STA	<EWORK8
		LDA	R1
		SEC
		SBC	PWIDEY
		STA	<EWORKA

		LDA	EPWIDX,X
		STA	R1
		LDA	EPWIDY,X
		STA	R2
		M_CHIP	M_RAD_GET
		LDX	<ENINDX
		LDA	R0
		CLC
		ADC	#00100H
		AND	#001FEH
		STA	<EWORK6

		STZ	CCWORK0
		STZ	CCWORK1
		STZ	CCWORK2

		LDA	ENWRK8,X		;チェック半径計算
		AND	#001FEH			;
		STA	R1			;
		STA	<EWORKC			;
		AND	#000FEH			;
		STA	<EWORK2			;
		ORA	#00100H			;
		STA	<EWORK4			;
		LDA	#00040H			;
		STA	R6			;
		M_CHIP	M_ENMY_1P_ROT		;
		LDX	<ENINDX			;
		LDA	R1
		STA	CCWORK1F
		LDA	R0
		BPL	RFLLG_P_SB20100

		EOR	#0FFFFH
		INC	A

RFLLG_P_SB20100 EQU	$
		ASL	A
		STA	<EWORK0
		LSR	A			;プレイヤーチェック範囲内 ?
		CLC				;
		ADC	EPWIDX,X		;
		CMP	<EWORK0			;
		BCS	RFLLG_P_SB20500		;  no: RFLLG_P_SB20500

		LDA	EPWIDX,X		;EWORKE <- チェックＹ　ＰＯＳ．
		STA	R0			;
		I16				;
		LDA	<EWORKC			;
		AND	#000FEH			;
		TAX				;
		LDA	>TAN,X			;
		STA	R6			;
		I8				;
		M_CHIP	MULTIPLY		;
		LDX	<ENINDX			;
		LDA	R0			;
		CLC				;
		ADC	EPWIDY,X		;
		STA	<EWORKE			;

		LDA	<EWORK6
		STA	R0

		JSR	RFLLG_PL_VREV

		LDA	PLBGCR			;補正方向にＢＧがある ?
		AND	#0000000000011111B	;
		BEQ	RFLLG_P_SB20500		;
						;
		AND	#0000000000011000B	;
		DEC	A			;
		EOR	CCWORK0			;
		BPL	RFLLG_P_SB20500		;  no: RFLLG_P_SB20500

		STZ	CCWORK0

RFLLG_P_SB20500 EQU	$
		LDA	CCWORK1F
		BPL	RFLLG_P_SB20600

		EOR	#0FFFFH
		INC	A

RFLLG_P_SB20600 EQU	$
		ASL	A
		STA	<EWORK0
		LSR	A			;プレイヤーチェック範囲内 ?
		CLC				;( PLFTLN は考慮せず )
		ADC	EPWIDY,X		;
		CMP	<EWORK0			;
		BCS	RFLLG_P_SB20800		;  no: RFLLG_P_SB20800

		LDA	EPWIDY,X		;EWORKE <- チェックＸ　ＰＯＳ．
		STA	R0			;
		I16				;
		LDA	#00080H			;
		SEC				;
		SBC	<EWORKC			;
		AND	#000FEH			;
		TAX				;
		LDA	>TAN,X			;
		STA	R6			;
		I8				;
		M_CHIP	MULTIPLY		;
		LDX	<ENINDX			;
		LDA	R0			;
		CLC				;
		ADC	EPWIDX,X		;
		STA	<EWORKE			;

		LDA	<EWORK6
		STA	R0

		JSR	RFLLG_PL_HREV

		LDA	PLBGCR			;補正方向にＢＧがある ?
		AND	#0000000111100000B	;
		BEQ	RFLLG_P_SB20800		;
						;
		AND	#0000000110000000B	;
		EOR	CCWORK1			;
		BPL	RFLLG_P_SB20800		;  no: RFLLG_P_SB20800

		STZ	CCWORK1

RFLLG_P_SB20800 EQU	$
		LDY	CCWORK2			;プレイヤーを補正する ?
		BNE	RFLLG_P_SB20900		; yes: RFLLG_P_SB20900

		RTS

RFLLG_P_SB20900 EQU	$
		LDA	CCWORK0
		BPL	RFLLG_P_SB21000

		EOR	#0FFFFH
		INC	A

RFLLG_P_SB21000 EQU	$
		STA	<EWORK0

		LDA	CCWORK1
		BPL	RFLLG_P_SB21100

		EOR	#0FFFFH
		INC	A

RFLLG_P_SB21100 EQU	$
		CMP	<EWORK0			;縦で補正する ?
		BPL	RFLLG_P_SB21200		;  no: RFLLG_P_SB21200

		LDA	CCWORK0
		CLC
		ADC	PLYPSL
		STA	PLYPSL

		LDY	CCWORK0+1		;上に乗った ?
		BPL	RFLLG_P_SB21140		;  no: RFLLG_P_SB21140

		INC	ONLFFG

		BRA	RFLLG_P_SB21300

RFLLG_P_SB21140 EQU	$
		STZ	PLYSPD
		STZ	PLSPJP

		BRA	RFLLG_P_SB21300

RFLLG_P_SB21200 EQU	$
		LDA	PLXPSL
		CLC
		ADC	CCWORK1
		STA	PLXPSL

RFLLG_P_SB21300 EQU	$
		LDA	<EWORK6
		LDY	<EWORKC+1
		BEQ	RFLLG_P_SB21500

		CMP	<EWORK2
		BMI	RFLLG_P_SB21800
		CMP	<EWORK4
		BPL	RFLLG_P_SB21800
		BRA	RFLLG_P_SB21600

RFLLG_P_SB21500 EQU	$
		CMP	<EWORK2
		BMI	RFLLG_P_SB21600
		CMP	<EWORK4
		BMI	RFLLG_P_SB21800

RFLLG_P_SB21600 EQU	$
		JSL	>PLFLST

RFLLG_P_SB21800 EQU	$

		RTS
;
RFLLG_PL_VREV	EQU	$
		LDA	R0
		LDY	<EWORKC			;左に傾いてる ?
		BMI	RFLLG_P_VREV010		; yes: RFLLG_P_VREV010

		CMP	<EWORK2
		BMI	RFLLG_P_VREV070
		CMP	<EWORK4
		BPL	RFLLG_P_VREV070
		BRA	RFLLG_P_VREV020

RFLLG_P_VREV010 EQU	$
		CMP	<EWORK2
		BMI	RFLLG_P_VREV020
		CMP	<EWORK4
		BMI	RFLLG_P_VREV070

RFLLG_P_VREV020 EQU	$
		LDA	<EWORKE
		SEC
		SBC	<EWORKA
		CMP	#00008H
		BCS	RFLLG_P_VREV080

;;;;;;;;		LDY	PLYSPD+1
;;;;;;;;		BPL	RFLLG_P_VREV080

		STA	CCWORK0
		INC	CCWORK2

		RTS

RFLLG_P_VREV070 EQU	$
		LDA	<EWORKE			;足あたってる ?
		SEC				;
		SBC	PLFTLN			;
		CLC				;
		ADC	<EWORKA			;
		CMP	#0FFF8H			;
		BCC	RFLLG_P_VREV080		;  no: RFLLG_P_VREV080

;;;;;;;;		LDY	PLYSPD+1
;;;;;;;;		BMI	RFLLG_P_VREV080

		STA	CCWORK0
		INC	CCWORK2

RFLLG_P_VREV080 EQU	$

		RTS
;
RFLLG_PL_HREV	EQU	$
		LDA	R0
		LDY	<EWORKC			;左に傾いてる ?
		BMI	RFLLG_P_HREV010		; yes: RFLLG_P_HREV010

		CMP	<EWORK2			;右チェック ?
		BMI	RFLLG_P_HREV070		; yes: RFLLG_P_HREV020
		CMP	<EWORK4			;  no: RFLLG_P_HREV070
		BPL	RFLLG_P_HREV070		;
		BRA	RFLLG_P_HREV020		;

RFLLG_P_HREV010 EQU	$
		CMP	<EWORK2			;右チェック ?
		BMI	RFLLG_P_HREV070		; yes: RFLLG_P_HREV020
		CMP	<EWORK4			;  no: RFLLG_P_HREV070
		BPL	RFLLG_P_HREV070		;

RFLLG_P_HREV020 EQU	$
		LDA	<EWORKE
		SEC
		SBC	<EWORK8
		CMP	#00008H
		BCS	RFLLG_P_HREV080

		STA	CCWORK1
		INC	CCWORK2

		RTS

RFLLG_P_HREV070 EQU	$
		LDA	<EWORKE			;左あたってる ?
		CLC
		ADC	<EWORK8
		CMP	#0FFF8H			;
		BCC	RFLLG_P_HREV080		;  no: RFLLG_P_HREV080

		STA	CCWORK1
		INC	CCWORK2

RFLLG_P_HREV080 EQU	$

		RTS
;
RFLLG_BBCHK	EQU	$
		LDA	ENTIM1,X		;回転中 ?
		BNE	RFLLG_BBCHK0600		;  no: RFLLG_BBCHK0600

		LDA	ENWRK8,X		;回転中 ?
		CMP	ENWRKA,X		;
		BNE	RFLLG_BBCHK0800		; yes: RFLLG_BBCHK0800

RFLLG_BBCHK0600 EQU	$
		LDA	EWIDEX,X
		STA	R0
		LDA	EWIDEY,X
		STA	R1

		LDA	#00038H
		STA	EWIDEX,X
		LDA	#00008-1
		STA	EWIDEY,X

		JSL	>BOBBGCR
;;;;;;;;		PHP

		LDA	R0
		STA	EWIDEX,X
		LDA	R1
		STA	EWIDEY,X

;;;;;;;;		PLP				;横からあたった ?
;;;;;;;;		BCC	RFLLG_BBCHK0800		; yes: RFLLG_BBCHK0800
;;;;;;;;
;;;;;;;;		LDY	<EWORKE			;赤ちゃん下にあたった ?
;;;;;;;;		BEQ	RFLLG_BBCHK0800		; yes: RFLLG_BBCHK0800
;;;;;;;;
;;;;;;;;		LDA	<ENCONT,X		;トゲの面にあたった ?
;;;;;;;;		BNE	RFLLG_BBCHK0800		;  no: RFLLG_BBCHK0800
;;;;;;;;
;;;;;;;;		LDY	<ENWRK2+BABY_INDEX	;シャボン防御 ?
;;;;;;;;		CPY	#BABYM_SHABON2		;
;;;;;;;;		BPL	RFLLG_BBCHK0800		; yes: RFLLG_BBCHK0800
;;;;;;;;
;;;;;;;;		JSL	>BABYM_SHABN_C2
;;;;;;;;
RFLLG_BBCHK0800 EQU	$

		RTS
;
;************************************************************************
;*		initial ( spark body )					*
;************************************************************************
SPRKRIN		EQU	$			;-- sprkrin --
		LDY	#00AH
		STY	<ENWRK5,X

SPRKLIN		EQU	$			;-- sprklin --
		LDA	#00001H
		STA	ENWRKA,X		;ビットマップエリアＵＳＥフラグクリア
		XBA		;[ LDA	#00100H ]			;初期倍率セット
		STA	ENWRK6,X

		STZ	ENMUKI,X		;向きを固定しとかんとフリップが変になるから
		LDA	#00040H
		STA	ENGPOW,X

		LDY	#004H
		STY	<ENWRK2,X

		RTL
;
;************************************************************************
;*		move	( spark body )					*
;************************************************************************
;B		ENWRK0	ズームフラグ
;B		ENWRK1	ＢＧチェックフラグ
;B		ENWRK2	ROUTINE MODE INDEX
;B		ENWRK3	坂チェックフラグ
;B		ENWRK4	FLIP INDEX
;B		ENWRK5	チェックインデックス加算値
;		ENWRK6	倍率
;		ENWRK8	回転角
;		ENWRKA	ビットマップエリアＵＳＥフラグ
;		ENWRKC	進行方向フラグ
;
;		ENCONT	ズーム回数
;
;		<SPRKL> 右手を壁にあてる
;		<SPRKR> 左手を壁にあてる
;
SPARK_SUB	EQU	$
		WORD	SPARK_SUB0		;small
		WORD	SPARK_SUB1		;small to big
		WORD	SPARK_SUB2		;big
		WORD	SPARK_SUB3		;big to small
		WORD	SPARK_SUB4		;first frame
		WORD	SPARK_SUB5		;動かない SUB0
		WORD	SPARK_SUB6		;   ”	  SUB1
		WORD	SPARK_SUB7		;   ”	  SUB2
		WORD	SPARK_SUB8		;   ”	  SUB3
;
SPARK_FLIP	EQU	$
		HEX	000,080,040,0C0
;
SPRKLMV		EQU	$			;-- sprklmv --
SPRKRMV		EQU	$			;-- sprkrmv --
		LDA	ENCOLD,X
		BNE	SPARKMV0080

		JSR	SPARK_BGCHK

SPARKMV0080	EQU	$
		I16				;
		LDA	ENOAML,X		;
		CLC				;
		ADC	#00010H			;008H * 2
		TAY				;

		LDA	ENWRKA,X
		BNE	SPARKMV0100

		LDA	#0FFF8H			;
		CLC				;
		ADC	ENDSXL,X		;
		STA	SOAM_DX+0,Y		;
		STA	SOAM_DX+0+10H,Y		;
		CLC				;
		ADC	#00010H			;
		STA	SOAM_DX+0+08H,Y		;
		STA	SOAM_DX+0+18H,Y		;
						;
		LDA	#0FFF8H			;
		CLC				;
		ADC	ENDSYL,X		;
		STA	SOAM_DX+2+00H,Y		;
		STA	SOAM_DX+2+08H,Y		;
		CLC				;
		ADC	#00010H			;
		STA	SOAM_DX+2+10H,Y		;
		STA	SOAM_DX+2+18H,Y		;

		JSL	>TROBJ_OAM_4x4_I

		BRA	SPARKMV0200

SPARKMV0100	EQU	$
		PHX
		LDA	<ENWRK4,X
		AND	#000FFH
		TAX

		M8
		LDA	SOAM_DX+5+00H,Y
		ORA	!SPARK_FLIP,X
		STA	SOAM_DX+5+00H,Y
		STA	SOAM_DX+5+08H,Y
		STA	SOAM_DX+5+10H,Y
		STA	SOAM_DX+5+18H,Y
		M16

		PLX
		I8

SPARKMV0200	EQU	$
		JSL	>ENMDCK

		LDY	ENWRKA,X		;ビットマップエリアＵＳＥ ?
		BEQ	SPARKMV0300		; yes: SPARKMV0300

		JSL	>EPCRCK

SPARKMV0300	EQU	$
		TXY
		LDA	<ENWRK2,X
		AND	#000FFH
		ASL	A
		TAX
		JSR	(SPARK_SUB,X)

SPARKMV0800	EQU	$
		LDA	ENTIM0,X
		BNE	SPARKMV0900

		LDA	#00004H
		STA	ENTIM0,X

		LDA	ENWRK8,X		;回転角計算
		CLC				;
		ADC	#00080H			;
		AND	#001FEH			;
		STA	ENWRK8,X		;

		LDA	ENCHPT,X		;キャラパターンを変える
		INC	A			;
		AND	#00003H			;
		STA	ENCHPT,X		;

		LDA	<ENWRK4,X		;フリップフラグを変える
		INC	A			;
		AND	#00003H			;
		TAY				;
		STY	<ENWRK4,X		;

SPARKMV0900	EQU	$

		RTL
;
SPARK_SUB0	EQU	$
SPARK_SUB5	EQU	$
		TYX

		LDA	ENTIM1,X
		BNE	SPARK_SUB0800

		JSL	>TROBJ_SR_4x4
		BCC	SPARK_SUB0800

		LDY	#004
		STY	<ENCONT,X

		INC	<ENWRK2,X

SPARK_SUB0800	EQU	$

		RTS
;
SPARK_SUB1	EQU	$
SPARK_SUB6	EQU	$
		TYX

		STZ	ENWRKA,X		;ビットマップエリアＵＳＥフラグセット

		LDA	ENWRK6,X
		INC	A
		INC	A
		CMP	#00124H
		BMI	SPARK_SUB1500

		LDY	#000
		STY	<ENWRK0,X

		INC	<ENWRK2,X		;routine mode index set

		LDA	#000E0H

SPARK_SUB1500	EQU	$
		STA	ENWRK6,X

		JSR	SPARK_SET

SPARK_SUB1800	EQU	$

		RTS
;
SPARK_ZOOM	EQU	$
		WORD	00002H,0FFFEH
;
SPARK_SUB2	EQU	$
SPARK_SUB7	EQU	$
		TYX

		STZ	ENWRKA,X

		LDY	<ENWRK0,X
		LDA	ENWRK6,X
		CLC
		ADC	!SPARK_ZOOM,Y
		CMP	#00124H
		BPL	SPARK_SUB2200

		DEC	<ENCONT,X
		BNE	SPARK_SUB2100

		INC	<ENWRK2,X		;routine mode index inc.

SPARK_SUB2100	EQU	$
		LDA	<ENWRK0,X
		EOR	#00002H
		STA	<ENWRK0,X

		LDA	#00124H
		BRA	SPARK_SUB2300

SPARK_SUB2200	EQU	$
		CMP	#001FFH
		BMI	SPARK_SUB2300

		LDA	<ENWRK0,X
		EOR	#00002H
		STA	<ENWRK0,X

		LDA	#001FFH

SPARK_SUB2300	EQU	$
		STA	ENWRK6,X

		JSR	SPARK_SET

SPARK_SUB2500	EQU	$

		RTS
;
SPARK_SUB3	EQU	$
SPARK_SUB8	EQU	$
		TYX

		LDA	ENWRK6,X
		DEC	A
		DEC	A
		CMP	#00100H
		BPL	SPARK_SUB3500

		LDA	#00040H
		STA	ENTIM1,X

		LDY	<ENWRK2,X
		CPY	#005
		PHP
		LDY	#000
		PLP
		BMI	SPARK_SUB3100

		LDY	#005

SPARK_SUB3100	EQU	$
		STY	<ENWRK2,X		;routine mode index set

		LDA	#00100H
		STA	ENWRKA,X		;ビットマップエリアＵＳＥフラグクリア
		STA	ENWRK6,X

		JSL	>TROBJ_CLEAR

		RTS

SPARK_SUB3500	EQU	$
		STA	ENWRK6,X

		JSR	SPARK_SET

SPARK_SUB3800	EQU	$

		RTS
;
		HEX	04,02,00,00,00,08
SPARK_BGCKDT	EQU	$-5
		HEX	00,04,00,00,08,02
SPARK_BGCKDT2	EQU	$-5
		HEX	04,02,00,00,00,08
;
;SPARK_I_XSPD	EQU	$
;		WORD	0FFC2H,0003EH,0FFC2H,0003EH
;SPARK_I_YSPD	EQU	$
;		WORD	0003EH,0FFC2H,0FFC2H,0003EH
SPARK_I_XSPD	EQU	$
		WORD	0FF00H,00100H,0FF00H,00100H
SPARK_I_YSPD	EQU	$
		WORD	00100H,0FF00H,0FF00H,00100H
SPARK_I_NEXT	EQU	$
		WORD	00008H,00008H,00000H,00000H
SPARK_I_ANG	EQU	$
		WORD	00040H,00140H,001C0H,000C0H
;
SPARK_SUB4	EQU	$
PPCKL_SUB0	EQU	$
HINAQ_SUB0	EQU	$
		TYX

		LDA	ENMOD1,X		;BG CHECK SIZE CHANGE
		AND	#0FFE0H
		ORA	#0000BH
		STA	ENMOD1,X

		LDY	ENCBFG,X		;ＢＧにくっついてる ?
		BEQ	SPARK_SUB4010		;  no: SPARK_SUB4010
		JMP	SPARK_SUB4200		; yes: SPARK_SUB4200

SPARK_SUB4010	EQU	$
		LDA	ENXPSL,X
		CLC
		ADC	#00008
		STA	R8
		LDA	ENYPSL,X
		CLC
		ADC	#00010H
		STA	R0
		M_CHIPR M_BGUNIT_READ

		LDX	<ENINDX
		LDA	R7			;坂 ?
		AND	#SK			;
		BNE	SPARK_SUB4020		; yes: SPARK_SUB4020

		RTS

SPARK_SUB4020	EQU	$
		LDY	#000
		LDA	ENXPSL,X		;右上がり ?
		AND	#00010H			;
		BNE	SPARK_SUB4080		; yes: SPARK_SUB4080

		LDY	#004

SPARK_SUB4080	EQU	$
		LDA	<ENWRK5,X		;左手をつけてる ?
		AND	#000FFH			;
		BNE	SPARK_SUB4100		; yes: SPARK_SUB4100

		INY
		INY

SPARK_SUB4100	EQU	$
		LDA	!SPARK_I_XSPD,Y
		STA	ENXSPD,X
		LDA	!SPARK_I_YSPD,Y
		STA	ENYSPD,X
		LDA	!SPARK_I_NEXT,Y
		STA	ENWRKC,X
		LDA	!SPARK_I_ANG,Y
		STA	<EWORKC
		LDA	#0000AH+1		;坂フラグセット
		STA	<ENWRK3,X
		LDA	ENYPSL,X
		AND	#0FFF0H
		INC	A
		STA	ENYPSL,X
		M8
		STZ	ENXSDR,X
		STZ	ENYSDR,X
		LDA	#0FFH
		LDY	ENXSPD+1,X
		BPL	SPARK_SUB4110

		STA	ENXSDR,X

SPARK_SUB4110	EQU	$
		LDY	ENYSPD+1,X
		BPL	SPARK_SUB4120

		STA	ENYSDR,X

SPARK_SUB4120	EQU	$
		M16
		BRA	SPARK_SUB4380

SPARK_SUB4200	EQU	$
		LDA	<ENWRK5,X		;右回り ?
		AND	#000FFH			;
		BEQ	SPARK_SUB4300		;  no: SPARK_SUB4300

		PHA
		TYA
		CLC
		ADC	#00005+1
		TAY
		PLA

SPARK_SUB4300	EQU	$
		CLC
		ADC	!SPARK_BGCKDT,Y
		AND	#000FFH
		LSR	A
		STA	R4
		TXA
		STA	R10

;;;;;;;;		JSR	SPARK_BGCHK1100
		M_CHIP	M_SPARK_BGCHK_I
		LDX	<ENINDX
		LDA	CCWORKC
		STA	<EWORKC

SPARK_SUB4380	EQU	$
		STZ	ENGPOW,X
		INC	<ENWRK1,X		;ＢＧチェックフラグセット
		INC	<ENCONT,X		;口ぱく回数セット( PPCKL&PPCKR )
		INC	<ENWRK2,X

		LDA	ENMYNO,X
		CMP	#HINAQ
		BEQ	SPARK_SUB4390
		CMP	#HINQ2
		BNE	SPARK_SUB4400

SPARK_SUB4390	EQU	$
		LDA	<EWORKC
		STA	ENWRKA,X
		BRA	SPARK_SUB4700

SPARK_SUB4400	EQU	$
		CMP	#PPCKL
		BEQ	SPARK_SUB4500
		CMP	#PPCKR
		BNE	SPARK_SUB4600

SPARK_SUB4500	EQU	$
		LDA	<EWORKC
		STA	ENWRKA,X
		JSR	PPCKL_R_SET0500

		RTS

SPARK_SUB4600	EQU	$
		LDA	ENTROB,X		;すでに膨らんでる ?
		BMI	SPARK_SUB4680		;  no: SPARK_SUB4680

		LDY	#003
		STY	<ENWRK2,X
		RTS

SPARK_SUB4680	EQU	$
		LDA	#00040H
		STA	ENTIM1,X
		LDY	#000
		STY	<ENWRK2,X

SPARK_SUB4700	EQU	$

		RTS
;
SPARK_BGCHK	EQU	$
		LDA	ENSTFG
		ORA	BIRIBIRI
		ORA	ITEMNO
		BNE	SPARK_BGCHK1200

		LDY	<ENWRK1,X		;ＢＧチェックする ?
		BEQ	SPARK_BGCHK1200		;  no: SPARK_BGCHK1200

		LDY	<ENWRK3,X
		TYA
		STA	R3
		LDY	<ENWRK5,X
		TYA
		CLC
		ADC	ENWRKC,X
		LSR	A
		STA	R4
		LDA	ENWRKC,X
		STA	R7
		TXA
		STA	R10
		LDA	<EWORKC
		STA	CCWORKC

		M_CHIPR M_SPARK_BGCHK
		LDX	<ENINDX
		LDA	CCWORKC
		STA	<EWORKC

SPARK_BGCHK1200 EQU	$

		RTS
;
SPARK_SET	EQU	$
		LDA	#CIPCHD+6030H+000H	;(R12) <-- 転送元アドレスセット
		STA	R12			;
		LDA	#BANK CIPCHD+6030H+000H ;(R13) <-- 転送元バンクセット
		STA	R13			;

		LDA	ENWRK8,X		;(R5) <- 回転角セット
		LSR	A			;
		STA	R5			;

		LDA	ENWRK6,X		;(R4) <- 倍率セット
		STA	R4			;

		STZ	R6			;(R6) <-- 軌道半径

		LDA	#00600H			;(R10) <-- あたり半径 * 100H
		STA	R10			;

		LDA	PWIDEX			;(R1) <-- プレイヤーあたりＸ半径
		STA	R1			;

		LDA	PWIDEY			;(R8) <-- プレイヤーあたりＹ半径
		STA	R8			;

		LDA	ENMUKI,X
		STA	R7

		LDY	ENTROB,X
		TYX
		LDA	>TROBJ_PLOT_X,X		;(R3) <- ビットマップ座標＿Ｘセット
		STA	R3			;
		LDA	>TROBJ_PLOT_Y,X		;(R2) <- ビットマップ座標＿Ｙセット
		STA	R2			;
;
;-------------- OBJ mode 7 set ----------------------------------
;		M_CHIP	C_32_ROTZOM_16
		M_CHIP	M_GABNB_SET

		LDX	<ENINDX

		TROBJ_CHK_4
		BNE	SPARK_SET0700

		INC	OBM7WF			;mode 7 OBJ chara DMA "ON"

SPARK_SET0700	EQU	$
		LDA	ENXPSL,X		;ｖｓプレイヤーチェック
		CLC				;	;プレイヤーと接触した ?
		ADC	#00008			;	;
		SEC				;	;
		SBC	PCENTX			;	;
		CLC				;	;
		ADC	CCWORK12		;	;
		CMP	CCWORK13		;	;
		BCS	SPARK_SET0900		;	;
						;	;
		LDA	ENYPSL,X		;	;
		CLC				;	;
		ADC	#00008			;	;
		SEC				;	;
		SBC	PCENTY			;	;
		CLC				;	;
		ADC	CCWORK14		;	;
		CMP	CCWORK15		;	;
		BCS	SPARK_SET0900		;	;  no: SPARK_SET0900
						;
		LDA	PLFLSH			;	;プレイヤーはダメージを受けている ?
		BNE	SPARK_SET0900		;	; yes: SPARK_SET0900
						;
		LDA	ENXSPD,X		;
		STA	PLXSPD			;
		STA	PLMVSP			;
						;
		JSL	>PLFLST

SPARK_SET0900	EQU	$

		RTS
;
;************************************************************************
;*		initial ( 土管パックン )				*
;************************************************************************
PPCKRIN		EQU	$			;-- ppckrin --
		LDY	#00AH
		STY	<ENWRK5,X
		BRA	PPCKLIN0100

PPCKLIN		EQU	$			;-- ppcklin --
		LDA	#00100H			;初期回転角セット
		STA	ENWRK8,X

PPCKLIN0100	EQU	$
		JSL	>TROBJ_SR_4x4_CL

		INC	<ENWRK0,X		;キャラパターンインデックスＣＭＰ用セット

		LDA	#00080H			;初期倍率セット
		STA	ENWRK6,X

		STZ	ENMUKI,X

		JSR	PPCKL_ROT_SET

		RTL
;
;************************************************************************
;*		move	( 土管パックン )				*
;************************************************************************
;B		ENWRK0	キャラパターンインデックスＣＭＰ用
;B		ENWRK1	ＢＧチェックフラグ
;B		ENWRK2	ROUTINE MODE INDEX
;B		ENWRK3	坂チェックフラグ
;B		ENWRK4	キャラパターンインデックス
;B		ENWRK5	データインデックス
;B		ENWRK6	倍率
;B		ENWRK7	再始動用進行方向インデックス
;		ENWRK8	回転角
;		ENWRKA	目標回転角
;B		ENWRKC	ＢＧチェックデータ／プレイヤー補正値(SUB2-)
;B		ENWRKD	ＢＧチェックデータ／プレイヤー補正値(SUB2-)
;
;		ENCONT	口ぱく回数／目標回転角(SUB6)
;
;		ENTIM0	ストップタイマー
;		ENTIM1	キャラパターンチェンジタイマー
;		ENTIM2
;		ENTIM3
;
;		<PPCKL> 右手を壁にあてる
;		<PPCKR> 左手を壁にあてる
;
PPCKL_SUB	EQU	$
		WORD	PPCKL_SUB0		;はじめて
		WORD	PPCKL_SUB1		;のうまる
		WORD	PPCKL_SUB2		;プレイヤー吸い込み補正
		WORD	PPCKL_SUB3		;むぐむぐ
		WORD	PPCKL_SUB4		;ぺっ
		WORD	PPCKL_SUB5		;むぐむぐ２
		WORD	PPCKL_SUB6		;ぐるぐる
;
PPCKLMV		EQU	$			;-- ppcklmv --
PPCKRMV		EQU	$			;-- ppckrmv --
;		ldy	#004h
;		sty	2100h

		LDY	<ENWRK2,X
		CPY	#006
		BEQ	PPCKLMV0080

		LDA	ENMODE,X		;燃えてる ?
		CMP	#EFIRE			;
		BEQ	PPCKLMV0080		; yes: PPCKLMV0080
		LDA	ENCOLD,X		;凍ってる ?
		BNE	PPCKLMV0080		; yes: PPCKLMV0080

		LDA	ENWRKA,X
		STA	<EWORKC
		JSR	SPARK_BGCHK
		LDA	<EWORKC
		STA	ENWRKA,X

PPCKLMV0080	EQU	$
		LDY	<ENWRK2,X
		CPY	#006
		BNE	PPCKLMV0090

		STZ	ENXSPD,X
		STZ	ENYSPD,X

PPCKLMV0090	EQU	$
		JSR	PPCKL_OAM_SET

		LDY	<ENWRK2,X		;プレイヤー口の中 ?
		CPY	#004			;
		BNE	PPCKLMV0100		;
						;
		LDY	ENWRKC,X		;
		BEQ	PPCKLMV0300		;
		BRA	PPCKLMV0200		; yes: PPCKLMV0200
						;
PPCKLMV0100	EQU	$			;
		CPY	#003			;
		BMI	PPCKLMV0300		;
		CPY	#005+1			;
		BPL	PPCKLMV0300		;  no: PPCKLMV0300

PPCKLMV0200	EQU	$
		STZ	PLYUSN

PPCKLMV0300	EQU	$
		JSL	>ENMDCK

		TXY
		LDA	<ENWRK2,X
		ASL	A
		TAX
		JSR	(PPCKL_SUB,X)

		JSR	PPCKL_ROT_SET

		LDY	ECRSFG,X
		DEY
		BMI	PPCKLMV0800

		LDA	ENMODE,Y
		CMP	#EMOVE
		BNE	PPCKLMV0800
		LDA	ENSHOT,Y
		BEQ	PPCKLMV0800

		TYX
		JSL	>ENDEATH_SET_4

		LDY	<ENWRK2,X
		CPY	#006
		BEQ	PPCKLMV0800

		STZ	ENXSPD,X
		STZ	ENYSPD,X
		LDA	ENWRK8,X
		STA	<ENCONT,X
		INC	A
		INC	A
		AND	#001FEH
		STA	ENWRK8,X
		LDY	#006
		STY	<ENWRK2,X

		LDY	#000			;ＢＧチェックフラグクリア
		STY	<ENWRK1,X

		LDY	<ENWRK5,X		;再始動用進行方向インデックスセット
		TYA				;
		CLC				;
		ADC	ENWRKC,X		;
		LSR	A			;
		TAY				;
		LDA	!PPCKL_RESET_IDX,Y	;
		M8				;
		STA	ENWRK7,X		;
		M16				;

;		ldy	#00fh
;		sty	2100h

PPCKLMV0800	EQU	$

		RTL
;
PPCKL_OAM_SET	EQU	$
		JSL	>TROBJ_OAM_4x4

		LDA	#0FFF8H
		LDY	<ENWRK5,X
		BEQ	PPCKL_O_SET0100

		LDA	#00008H

PPCKL_O_SET0100 EQU	$
		STA	R6
		LDA	ENWRK8,X
		LDY	<ENWRK2,X		;その場で回ってる ?
		CPY	#006			;
		BNE	PPCKL_O_SET0300		;  no: PPCKL_O_SET0300

		LDA	<ENCONT,X

PPCKL_O_SET0300 EQU	$
		CLC
		ADC	#00080H
		AND	#001FEH
		STA	R1
		M_CHIP	M_ENMY_1P_ROT
		LDX	<ENINDX
		I16
		LDY	ENOAML,X
		LDA	SOAM_DX+0+8*0,Y
		CLC
		ADC	R0
		STA	SOAM_DX+0+8*0,Y
		STA	SOAM_DX+0+8*2,Y
		LDA	SOAM_DX+0+8*1,Y
		CLC
		ADC	R0
		STA	SOAM_DX+0+8*1,Y
		STA	SOAM_DX+0+8*3,Y
		LDA	SOAM_DX+2+8*0,Y
		CLC
		ADC	R1
		STA	SOAM_DX+2+8*0,Y
		STA	SOAM_DX+2+8*1,Y
		LDA	SOAM_DX+2+8*2,Y
		CLC
		ADC	R1
		STA	SOAM_DX+2+8*2,Y
		STA	SOAM_DX+2+8*3,Y
		I8

		LDA	#00008
		CLC
		ADC	R0
		STA	ECNTXW,X
		LDA	#00008
		CLC
		ADC	R1
		STA	ECNTYW,X

		RTS
;
PPCKL_CHAR	EQU	$
		WORD	CIPCHD+4040H+001H	;口とじ
		WORD	CIPCHD+4060H+001H	;口あけ
;
PPCKL_ROT_SET	EQU	$
		LDY	<ENWRK2,X		;プレイヤーをお召し上がり中 ?
		CPY	#002			;
		BPL	PPCKL_R_SET0500		; yes: PPCKL_R_SET0500

		LDA	ENWRK8,X
		SEC
		SBC	ENWRKA,X
		BNE	PPCKL_R_SET0000

		LDY	<ENWRK0,X
		STY	<EWORK0
		LDY	<ENWRK4,X
		CPY	<EWORK0
		BEQ	PPCKL_R_SET0800

		STY	<ENWRK0,X
		BRA	PPCKL_R_SET0500

PPCKL_R_SET0000 EQU	$
		PHP
		CLC
		ADC	#00100H
		CMP	#00200H
		BCC	PPCKL_R_SET0100
		PLP
		BPL	PPCKL_R_SET0200
		BRA	PPCKL_R_SET0300

PPCKL_R_SET0100 EQU	$
		PLP
		BPL	PPCKL_R_SET0300

PPCKL_R_SET0200 EQU	$
		LDA	#00004
		BRA	PPCKL_R_SET0400

PPCKL_R_SET0300 EQU	$
		LDA	#0FFFCH

PPCKL_R_SET0400 EQU	$
		CLC
		ADC	ENWRK8,X
		AND	#001FEH
		STA	ENWRK8,X

PPCKL_R_SET0500 EQU	$
		LDA	ENWRK8,X		;(R5) <- 回転角セット
		LSR	A			;
		STA	R5			;
;
		LDY	<ENWRK4,X		;転送元アドレス＆バンクセット
		LDA	!PPCKL_CHAR,Y		;(R12) <-- 転送元アドレスセット
		STA	R12			;(R13) <-- 転送元バンクセット
		LDA	#BANK CIPCHD+4040H+001H ;chara data bank set
		STA	R13			;

		LDY	ENWRK6,X		;(R6) <- 倍率セット
		TYA				;
		ASL	A			;
		STA	R6			;

		LDY	ENTROB,X
		TYX
		LDA	>TROBJ_PLOT_X,X		;(R3) <- ビットマップ座標＿Ｘセット
		STA	R3			;
		LDA	>TROBJ_PLOT_Y,X		;(R2) <- ビットマップ座標＿Ｙセット
		STA	R2			;
;
;-------------- OBJ mode 7 set ----------------------------------
;
		M_CHIP	C_32_ROTZOM

		LDX	<ENINDX

		INC	OBM7WF			;mode 7 OBJ chara DMA "ON"

PPCKL_R_SET0800 EQU	$

		RTS
;
PPCKL_SUB1	EQU	$
		TYX

		LDA	ENTIM0,X		;ストップ
		ORA	ENTIM1,X		;キャラパターンチェンジしない ?
		BNE	PPCKL_SUB1800		; yes: PPCKL_SUB1800

		LDA	#00008
		STA	ENTIM1,X

		LDA	<ENWRK4,X		;キャラパターンインデックスチェンジ
		EOR	#00002
		STA	<ENWRK4,X

		DEC	<ENCONT,X
		BPL	PPCKL_SUB1800

		LDA	EPWIDX,X
		CLC
		ADC	#00020H
		CMP	#00040H
		BCS	PPCKL_SUB1500

		LDA	EPWIDY,X
		CLC
		ADC	#00020H
		CMP	#00040H
		BCS	PPCKL_SUB1500

		LDA	#00001
		STA	<ENCONT,X
		BRA	PPCKL_SUB1800

PPCKL_SUB1500	EQU	$
		LDA	#00007
		STA	<ENCONT,X

		LDA	#00040H
		STA	ENTIM0,X

PPCKL_SUB1800	EQU	$
		JMP	PPCKL_PLCHK
;
PPCKL_SUB2	EQU	$
		TYX

		STX	PONLFFG			;強制！！

		LDA	ECENTX,X
		SEC
		SBC	#00008
		STA	<EWORK0
		LDA	ECENTY,X
		SEC
		SBC	#00008
		STA	<EWORK2

		LDA	ENWRKC,X
		PHA
		XBA
		AND	#000FFH
		TAY
		BPL	PPCKL_SUB2100

		ORA	#0FF00H

PPCKL_SUB2100	EQU	$
		STA	<EWORK4

		PLA
		AND	#000FFH
		TAY
		BPL	PPCKL_SUB2200

		ORA	#0FF00H

PPCKL_SUB2200	EQU	$
		STA	<EWORK6

		JSL	>NMZ_HOSEI
		PHA

		LDY	<EWORK4
		TYA
		XBA
		STA	<EWORK4
		LDY	<EWORK6
		TYA
		ORA	<EWORK4
		STA	ENWRKC,X

		LDA	<EWORK8
		STA	PLXPSL
		LDA	<EWORKA
		STA	PLYPSL
		PLA				;補正終了 ?
		BNE	PPCKL_SUB2500		;  no: PPCKL_SUB1500

		STZ	ENWRKC,X

		LDY	#005
		STY	<ENWRK2,X

;		LDA	#00040H			;むぐむぐ回数 * 16セット
		LDA	#00020H			;むぐむぐ回数 * 16セット
		STA	<ENCONT,X		;
;
		STZ	PLYUSN			;プレイヤー消す
		LDY	NOSEIDX			;プレイヤーに何か乗ってる ?
		BMI	PPCKL_SUB2400		;  no: PPCKL_SUB2400

		STA	ENYUSN,Y		;乗せてるやつの消す

		DEC	<ENWRK2,X
		DEC	<ENWRK2,X
		INC	ENWRKC,X
		LDA	#00004H			;むぐむぐ回数 * 4セット
		STA	<ENCONT,X		;

		LDA	#00014H			;［Ｓ］
		JSL	>SOUND_3_ON
;;;;;;;;		LDA	#00006			;[Ｓ]
;;;;;;;;		STA	SOUND0

PPCKL_SUB2400	EQU	$
		LDY	#000
		STY	<ENWRK4,X		;口開けフラグクリア

PPCKL_SUB2500	EQU	$
PPCKL_SUB3_RTS	EQU	$

		RTS
;
PPCKL_ZADD	EQU	$
		WORD	00004H,0FFFCH
PPCKL_ZLIM	EQU	$
		WORD	00088H,00080H
;
PPCKL_SUB5	EQU	$
		TYX

;		LDA	KEYC1L
;		AND	#0CFF0H
;		CMP	KEYWORK
;		BEQ	PPCKL_SUB5000
;
;		STA	KEYWORK
;
;		LDA	<ENCONT,X
;		SEC
;		SBC	#00004
;		CMP	#00002
;		BMI	PPCKL_SUB5000
;
;		STA	<ENCONT,X
;
;PPCKL_SUB5000	EQU	$
;		STZ	PLYUSN
;		BRA	PPCKL_SUB3000
;
;
		LDA	ENCLOR,X
		AND	#0FFE0H
		ORA	#00022H
		STA	ENCLOR,X
		LDY	ENWRK6,X		;ノーマルのサイズ ?
		BPL	PPCKL_SUB3000		;  no: PPCKL_SUB3000

		LDA	ENCLOR,X
		AND	#0FFE0H
		ORA	#00024H
		STA	ENCLOR,X

		LDA	KEYC1L			;キー入力があった ?
		AND	#0CFF0H			;
		CMP	KEYWORK			;
		BEQ	PPCKL_SUB3000		;  no: PPCKL_SUB3000
		STA	KEYWORK			;
		CMP	#00000			;
		BEQ	PPCKL_SUB3000		;  no: PPCKL_SUB3000

		LDA	<ENCONT,X		;残り少ない ?
		CMP	#00004+1		;
		BMI	PPCKL_SUB3000		; yes: PPCKL_SUB3000

		SEC
		SBC	#00010H
		CMP	#00004
		BPL	PPCKL_SUB5080

		LDA	#00004

PPCKL_SUB5080	EQU	$
		AND	#0FFFCH
		STA	<ENCONT,X
		M8
		LDA	#060H
		STA	ENWRK6,X
		M16
		BRA	PPCKL_SUB3000

PPCKL_SUB3	EQU	$
		TYX

		LDY	NOSEIDX
		CPY	#000
		BMI	PPCKL_SUB3000

		LDA	#0FF00H
		STA	ENYUSN,Y		;乗せてるやつの消す

PPCKL_SUB3000	EQU	$
		TROBJ_CHK_4
		BNE	PPCKL_SUB3_RTS

		LDA	<ENCONT,X
		AND	#00002H
		TAY
		LDA	ENWRK6,X
		AND	#000FFH
		CLC
		ADC	!PPCKL_ZADD,Y
		CMP	!PPCKL_ZLIM,Y
		BEQ	PPCKL_SUB3100
		JMP	PPCKL_SUB3800

PPCKL_SUB3100	EQU	$
		DEC	<ENCONT,X		;口ぱく終わり ?
		DEC	<ENCONT,X		;
		BEQ	PPCKL_SUB3200		; yes: PPCKL_SUB3200
		JMP	PPCKL_SUB3700

PPCKL_SUB3200	EQU	$
		PHY

		LDY	<ENWRK2,X
		CPY	#005
		BNE	PPCKL_SUB3300
		JMP	PPCKL_SUB3500

PPCKL_SUB3300	EQU	$
		LDA	#0FC00H
		STA	R6
		LDA	ENWRK8,X
		STA	R1

		M_CHIP	M_ENMY_1P_ROT

		LDX	<ENINDX

		LDY	NOSEIDX
		LDA	ECENTX,X
		SEC
		SBC	#00008
		STA	ENXPSL,Y
		LDA	ECENTY,X
		SEC
		SBC	#00008
		STA	ENYPSL,Y
		LDA	#EMOVE
		STA	ENMODE,Y

		LDA	R0
		STA	ENXSPD,Y
		LDA	R1
		STA	ENYSPD,Y

		CPY	#BABY_INDEX		;赤ちゃん ?
		BNE	PPCKL_SUB3400		;  no: PPCKL_SUB3400

		TYA
		STA	ENCONT+BABY_INDEX	;キャラパターンカウンタークリア
		STA	ENWRKC+BABY_INDEX	;乗ってるフラグクリア

		LDA	ENXSPD+BABY_INDEX
;		CMP	#08000H
;		ROR	A
		STA	R0
		LDA	#000C0H
		STA	R6
		M_CHIP	MULTIPLY
		LDX	<ENINDX
		LDA	R0
		STA	ENXSPD+BABY_INDEX
		LDA	ENYSPD+BABY_INDEX
		STA	R0
		M_CHIP	MULTIPLY
		LDX	<ENINDX
		LDA	R0
;		CMP	#08000H
;		ROR	A
		STA	ENYSPD+BABY_INDEX

		LDA	#00010H			;プレイヤーチェックロックタイマーセット
		STA	ENTIM3+BABY_INDEX	;

		LDA	BABYNO			;CLEAR 8000H
		AND	#00FFFH			;
		STA	BABYNO			;

		PHY
		LDA	#0003CH			;［Ｓ］
		JSL	>SOUND_3_ON
		PLY

PPCKL_SUB3400	EQU	$
		STZ	ENMYNSFG		;敵のせ情報フラグクリア

		PHX
		LDA	ENMYNO,Y
		ASL	A
		TAX
		LDA	>ENDATA0,X
		AND	#000FFH
		STA	ENYUSN,Y
		PLX

		LDA	#0FFFFH
		STA	NOSEIDX
		STA	ENEATFG

		BRA	PPCKL_SUB3600

PPCKL_SUB3500	EQU	$
		LDA	#PMOV
		STA	PLMODE

		LDA	#0FC00H
		STA	R6
		LDA	ENWRK8,X
		STA	R1

		M_CHIP	M_ENMY_1P_ROT

		LDX	<ENINDX
		LDA	R0
		STA	PLXSPD
		STA	PLMVSP
		LDA	R1
		STA	PLYSPD
		LDA	#P006
		STA	PLJUMP
		LDA	#001+8000H
		STA	PLSPJP

		LDA	ECENTX,X
		SEC
		SBC	#00010H
		STA	PLXPSL
		LDA	ECENTY,X
		SEC
		SBC	#00010H
		STA	PLYPSL

		STZ	PONLFFG
		STZ	PLEATFG

		LDA	#00060H			;プレイヤーチェックロックタイマーセット
		STA	ENTIM3,X		;
		LDA	#0000000001001011B	;敵に戻す
		STA	ENMOD1,X
		LDA	#0010000101010101B	;凍る、燃える
		STA	ENMOD2,X

PPCKL_SUB3600	EQU	$
		LDA	#0003BH			;［Ｓ］
		JSL	>SOUND_3_ON
		LDA	#00020H
		STA	ENTIM0,X

		LDY	#002
		STY	<ENWRK4,X

		LDY	#004H
		STY	<ENWRK2,X

		PLY

PPCKL_SUB3700	EQU	$
		LDA	!PPCKL_ZLIM,Y

PPCKL_SUB3800	EQU	$
		M8
		STA	ENWRK6,X
		M16

		RTS
;
PPCKL_SUB4	EQU	$
		TYX

		LDA	ENTIM0,X		;ストップ ?
		BNE	PPCKL_SUB4800		; yes: PPCKL_SUB4800

		LDY	ENWRKC,X		;
;;;;;;;		CPY	#000			;プレイヤー何か背負ってた ?
		BNE	PPCKL_SUB4500		; yes: PPCKL_SUB4500

		STY	<ENWRK4,X		;口閉じパターン

PPCKL_REMOVE	EQU	$
		LDA	#0000000001001011B	;敵に戻す
		STA	ENMOD1,X
		LDY	#001
		STY	<ENWRK2,X		;routine mode index set
		STY	<ENCONT,X		;口ぱく回数セット

		LDY	ENWRK7,X
		TYA
		LSR	A
		STA	R4
		TXA
		STA	R10

		LDY	<ENWRK3,X		;坂の上にいた ?
		BEQ	PPCKL_SUB4300		;  no: PPCKL_SUB4300

		M_CHIP	M_PPACK_SKCHK_I

;		LDY	ENWRK7,X
;		LDA	!SPARK_NEXT,Y
;		STA	ENWRKC,X
;		AND	#0FFFEH
;		TAY
;		LDA	!SPARK_XSPD3,Y
;		STA	ENXSPD,X
;		LDA	!SPARK_YSPD3,Y
;		STA	ENYSPD,X
;		LDA	!SPARK_ANG3,Y
;		STA	<EWORKC
		BRA	PPCKL_SUB4400

PPCKL_SUB4300	EQU	$
;		JSR	SPARK_BGCHK1100

		M_CHIP	M_SPARK_BGCHK_I

PPCKL_SUB4400	EQU	$
		LDX	<ENINDX
		LDA	CCWORKC
		STA	<EWORKC

		LDA	<EWORKC
		STA	ENWRK8,X
		STA	ENWRKA,X

		INC	<ENWRK1,X		;ＢＧチェックフラグセット

		RTS

PPCKL_SUB4500	EQU	$
		DEC	ENWRKC,X

		LDA	#00020H			;口ぱく回数 * 32セット
;		LDA	#00080H			;口ぱく回数 * 32セット
		STA	<ENCONT,X		;

		LDY	#000			;口閉じパターン
		STY	<ENWRK4,X		;

		LDY	#005H
		STY	<ENWRK2,X

PPCKL_SUB4800	EQU	$

		RTS
;
PPCKL_SUB6	EQU	$
		TYX

		LDA	ENWRK8,X
		SEC
		SBC	<ENCONT,X
		AND	#001FEH
		CMP	#001F8H
		BCC	PPCKL_SUB6500

		LDA	<ENCONT,X
		STA	ENWRK8,X
		STZ	<ENCONT,X
		LDA	ENXPSL,X
		PHA
		LDA	ENYPSL,X
		PHA
		JSR	PPCKL_REMOVE
		PLA
		STA	ENYPSL,X
		PLA
		STA	ENXPSL,X
		RTS

PPCKL_SUB6500	EQU	$
		LDA	ENWRK8,X
		CLC
		ADC	#00008
		AND	#001FEH
		STA	ENWRK8,X

PPCKL_PLCHK0000 EQU	$

		RTS
;
PPCKL_RESET_IDX EQU	$
		HEX	004,008,002,000,000
		HEX	012,00E,00A,000,00C
;
PPCKL_PLCHK	EQU	$
		LDA	FUFUFU			;デバッグモード ?
		ORA	ENTIM3,X		;プレイヤーチェックロック ?
		BNE	PPCKL_PLCHK0000		; yes: PPCKL_PLCHK0000

		LDA	ENWRK8,X
		STA	R1
		LDA	#0FFF4H
		STA	R6
		M_CHIP	M_ENMY_1P_ROT
		LDX	<ENINDX
		LDA	PWIDEX			;プレイヤー唇に触れた ?
		ASL	A			;
		STA	<EWORK0			;
		LSR	A			;
		CLC				;
		ADC	R0			;
		CLC				;
		ADC	EPWIDX,X		;
		CMP	<EWORK0			;
		BCC	PPCKL_PLCHK0100		;
						;
PPCKL_PLCHK0080 EQU	$			;
;		JMP	PPCKL_PLCHK0800		;
		RTS
						;
PPCKL_PLCHK0100 EQU	$			;
		LDA	PWIDEY			;
		ASL	A			;
		STA	<EWORK0			;
		LSR	A			;
		CLC				;
		ADC	R1			;
		CLC				;
		ADC	EPWIDY,X		;
		CMP	<EWORK0			;
		BCS	PPCKL_PLCHK0080		;  no: PPCKL_PLCHK0080

		LDA	PLEATFG			;プレイヤー誰かに食べられてる ?
		BNE	PPCKL_PLCHK0800		; yes: PPCKL_PLCHK0800

		LDY	#000			;ＢＧチェックフラグクリア
		STY	<ENWRK1,X

		LDY	<ENWRK5,X		;再始動用進行方向インデックスセット
		TYA				;
		CLC				;
		ADC	ENWRKC,X		;
		LSR	A			;
		TAY				;
		LDA	!PPCKL_RESET_IDX,Y	;
		M8				;
		STA	ENWRK7,X		;
		M16				;

		JSL	>EGGKILL_ALL

;;;;;;;;		STX	PONLFFG
		INC	PLEATFG

		LDY	NOSEIDX
		BMI	PPCKL_PLCHK0600

		TYA
		STA	ENEATFG

PPCKL_PLCHK0600 EQU	$
		LDA	ENXPSL,X		;(ENXPSL - 0) - PLXPSL
		SEC				;
		SBC	PLXPSL			;
		AND	#000FFH			;
		XBA				;
		STA	<EWORK0			;

		LDA	ENYPSL,X		;(ENYPSL - 0) - PLYPSL
		SEC				;
		SBC	PLYPSL			;
		AND	#000FFH			;
		ORA	<EWORK0			;
		STA	ENWRKC,X		;

		STZ	PLDOSN			;プレイヤーどすんカウンタークリア

;		LDA	BERFLG			;プレイヤーの舌が出てる ?
;		BEQ	PPCKL_PLCHK0700		;  no: PPCKL_PLCHK0700
;;
;		STZ	BERFLG			;bero flag cancel !!
;		STZ	BERXPS
;		STZ	BERYPS
;		STZ	EATFLG
;		STZ	EATSTP
;		STZ	EATSPF
;
		JSL	>BERO_CANCEL

PPCKL_PLCHK0700 EQU	$
		LDA	#PSTP			;player stop mode set
		STA	PLMODE
		LDA	#PD09			;damage pattern no. set
		STA	PLPATN

		STZ	ENXSPD,X
		STZ	ENYSPD,X

		LDA	#0100000001001011B	;敵でなくす
		STA	ENMOD1,X
		LDA	#0010000100000101B	;凍らない、燃えない
		STA	ENMOD2,X

		LDY	#002
		STY	<ENWRK4,X		;口開けフラグ

		INC	<ENWRK2,X
		PLA
		RTL

PPCKL_PLCHK0800 EQU	$
;		LDY	ECRSFG,X
;		DEY
;		BPL	PPCKL_PLCHK0900
;
;		LDA	ENMODE,Y
;		CMP	#EMOVE
;		BNE	PPCKL_PLCHK0A00
;		LDA	ENSHOT,Y
;		BEQ	PPCKL_PLCHK0A00
;
;		TYX
;		JSL	>ENDEATH_SET_4
;		RTS
;
;PPCKL_PLCHK0900 EQU	$
;		JSL	>EPCRCK
;
;PPCKL_PLCHK0A00 EQU	$

		RTS
;
;************************************************************************
;*		initial ( ひなＱ )					*
;************************************************************************
HINAQ_I_WRK5	EQU	$
		WORD	00A00H,00000H
HINAQ_I_TIM2	EQU	$
		WORD	00050H,00030H
HINAQIN		EQU	$			;-- hinaqin --
HINQ2IN		EQU	$			;-- hinq2in --
		LDA	ENTIM2,X		;オプションセットされたやつ ?
		BNE	HINAQIN0500		; yes: HINAQIN0500

		LDY	ENMUKI,X
		LDA	!HINAQ_I_WRK5,Y
		STA	<ENWRK4,X

		STZ	ENMUKI,X

		LDA	ENMYNO,X
		CMP	#HINAQ
		BNE	HINAQIN0500

		LDA	#00002
		STA	<EWORK2

HINAQIN0100	EQU	$
		LDY	<EWORK2
		LDA	!HINAQ_I_TIM2,Y
		STA	<EWORK0

		LDA	#HINAQ
		JSL	>ENINSR_I
		BCC	HINAQIN0500

		LDA	ENXPSL,X
		STA	ENXPSL,Y
		LDA	ENYPSL,X
		STA	ENYPSL,Y
		LDA	<ENWRK4,X
		STA	ENWRK4,Y

		LDA	<EWORK0
		STA	ENTIM2,Y

		DEC	<EWORK2
		DEC	<EWORK2
		BPL	HINAQIN0100

HINAQIN0500	EQU	$

		RTL
;
;************************************************************************
;*		move	( ひなＱ )					*
;************************************************************************
;B		ENWRK0
;B		ENWRK1	ＢＧチェックフラグ
;B		ENWRK2	ROUTINE MODE INDEX
;B		ENWRK3	坂チェックフラグ
;B		ENWRK4	キャラパターンインデックス
;B		ENWRK5	データインデックス
;		ENWRK6	キャラパターンベースインデックス
;		ENWRK8	回転角
;		ENWRKA	目標回転角
;		ENWRKC	ＢＧチェックデータ
;
;		ENCONT	口ぱく回数
;
;		ENTIM0	ストップタイマー
;		ENTIM1	キャラパターンチェンジタイマー
;		ENTIM2
;		ENTIM3
;
HINAQ_SUB	EQU	$
		WORD	HINAQ_SUB0
		WORD	DUMMY_SUB
;
HINAQMV		EQU	$			;-- hinaqmv --
HINQ2MV		EQU	$			;-- hinq2mv --
;		ldy	#004h
;		sty	2100h

		LDA	ENOAML,X
		BMI	HINAQMV0800

		LDA	ENMODE,X
		CMP	#EFIRE
		BEQ	HINAQMV0300

		LDA	ENCOLD,X
		BNE	HINAQMV0300

		LDA	ENWRKA,X
		STA	<EWORKC
		JSR	SPARK_BGCHK
		LDA	<EWORKC
		STA	ENWRKA,X

		LDA	ENTIM2,X		;じっとしてる ?
		BEQ	HINAQMV0300		;  no: HINAQMV0300

		LDA	ENCBFG,X		;ＢＧにくっついてる ?
		BNE	HINAQMV0100		; yes: HINAQMV0100

		LDY	<ENWRK3,X		;坂 ?
		BEQ	HINAQMV0300		;  no: HINAQMV0300

HINAQMV0100	EQU	$
		LDA	ENXPSL,X
		SEC
		SBC	ENMOVX,X
		STA	ENXPSL,X
		LDA	ENYPSL,X
		SEC
		SBC	ENMOVY,X
		STA	ENYPSL,X

HINAQMV0300	EQU	$
		JSL	>ENMDCK

		TXY
		LDA	<ENWRK2,X
		ASL	A
		TAX
		JSR	(HINAQ_SUB,X)

		JSR	HINAQ_PAT_SET

		LDA	ENXSPD,X
		JSR	HINAQ_SPD_CHK
		STA	ENXSPD,X
		LDA	ENYSPD,X
		JSR	HINAQ_SPD_CHK
		STA	ENYSPD,X

		LDY	ECRSFG,X
		DEY
		BMI	HINAQMV0500

		JMP	>SHOT_EN_KILL_SP

HINAQMV0500	EQU	$
		JSL	>EPCRCK

HINAQMV0800	EQU	$
;		ldy	#00fh
;		sty	2100h

		RTL
;
HINAQ_SPD_CHK	EQU	$
		CMP	#00059H
		BNE	HINAQ_S_CHK0100

		LDA	#00100H

HINAQ_S_CHK0100 EQU	$
		CMP	#0FFA7H
		BNE	HINAQ_S_CHK0200

		LDA	#0FF00H

HINAQ_S_CHK0200 EQU	$
		CMP	#0003EH
		BNE	HINAQ_S_CHK0300

		LDA	#000B5H

HINAQ_S_CHK0300 EQU	$
		CMP	#0FFC2H
		BNE	HINAQ_S_CHK0400

		LDA	#0FF4BH

HINAQ_S_CHK0400 EQU	$

		RTS
;
HINAQ_CHAR	EQU	$
		HEX	000,004,002,006,000,004,002,006
		HEX	000,006,002,004,000,006,002,004
HINAQ_CLOR	EQU	$
		HEX	0A0,0A0,060,060,060,060,0A0,0A0
		HEX	020,020,020,0E0,0E0,0E0,0E0,020
;
HINAQ_PAT_SET	EQU	$
		LDA	ENTIM1,X
		BNE	HINAQ_P_SET0100

		LDA	#00003
		STA	ENTIM1,X

		LDA	<ENWRK4,X
		EOR	#00001
		STA	<ENWRK4,X

HINAQ_P_SET0100 EQU	$
		LDA	ENWRKA,X
		CMP	ENWRK8,X
		BEQ	HINAQ_P_SET0800

		STA	ENWRK8,X
		ASL	A
		ASL	A
		XBA
		LDY	<ENWRK5,X
		BEQ	HINAQ_P_SET0300

		CLC
		ADC	#00008

HINAQ_P_SET0300 EQU	$
		TAY
		M8
		LDA	!HINAQ_CLOR,Y
		STA	ENCLOR,X
		LDA	!HINAQ_CHAR,Y
		AND	#000FFH
		STA	ENWRK6,X
		M16

HINAQ_P_SET0800 EQU	$
		LDA	<ENWRK4,X
		AND	#000FFH
		ORA	ENWRK6,X
		STA	ENCHPT,X

		RTS
;
;************************************************************************
;*		initial ( 回転丸太 )					*
;************************************************************************
RMARUIN		EQU	$			;-- rmaruin --
		JSL	>TROBJ_SR_4x4_CL

		STZ	ENMUKI,X

		JSR	RMARU_ROT_SET

		LDA	#0000CH
		STA	EWIDEX,X

		RTL
;
;************************************************************************
;*		move	 ( 回転丸太 )					*
;************************************************************************
;		ENWRK0
;		ENWRK2	ROUTINE MODE INDEX
;		ENWRK4	回転エリア書き換えフラグ
;		ENWRK6
;		ENWRK8	回転角
;		ENWRKA
;		ENWRKC
;
;		ENTIM0	回転待ちタイマー
;
RMARU_SUB	EQU	$
		WORD	RMARU_SUB0		;待ち
		WORD	RMARU_SUB1		;回転
;
RMARUMV		EQU	$			;-- rmarumv --
		JSL	>TROBJ_OAM_4x4

		JSL	>ENMDCK

		TXY
		LDA	<ENWRK2,X
		ASL	A
		TAX
		JSR	(RMARU_SUB,X)

		JSR	RMARU_PLCHK

		JSR	RMARU_ROT_SET

		RTL
;
RMARU_ROT_SET	EQU	$
		LDY	<ENWRK4,X		;回転エリア書き換える ?
		BNE	RMARU_R_SET0800		;  no: RMARU_R_SET0800

		INC	<ENWRK4,X

		LDA	#CIPCHD+4060H+000	;(R12) <-- 転送元アドレスセット
		STA	R12			;
		LDA	#BANK CIPCHD+4060H+000	;(R13) <-- 転送元バンクセット
		STA	R13			;

		LDY	ENWRK8,X		;(R5) <- 回転角セット
		TYA
		STA	R5			;

		LDA	#00100H			;(R6) <- 倍率セット
		STA	R6			;

		LDY	ENTROB,X
		TYX
		LDA	>TROBJ_PLOT_X,X		;(R3) <- ビットマップ座標＿Ｘセット
		STA	R3			;
		LDA	>TROBJ_PLOT_Y,X		;(R2) <- ビットマップ座標＿Ｙセット
		STA	R2			;
;
;-------------- OBJ mode 7 set ----------------------------------
		M_CHIP	C_32_ROTZOM

		LDX	<ENINDX

		INC	OBM7WF		;mode 7 OBJ chara DMA "ON"

RMARU_R_SET0800 EQU	$

		RTS
;
RMARU_PLCHK	EQU	$
		LDY	<ENWRK2,X		;回転中 ?
		BNE	RMARU_PLCHK1000		; yes: RMARU_PLCHK1000

		JSL	>POBBGCR		;縦方向からあたった ?

RMARU_PLCHK0800 EQU	$

		RTS

RMARU_PLCHK1000 EQU	$
		LDA	EPWIDX,X
		CLC
		ADC	#00014H-02+8
		CMP	#(00014H-02+8)*2
		BCS	RMARU_PLCHK0800

		LDA	EPWIDY,X
		CLC
		ADC	#00008-1+0CH
		CMP	#(00008-1+0CH)*2
		BCS	RMARU_PLCHK0800

		LDA	EPWIDX,X
		STA	R1
		LDA	EPWIDY,X
		STA	R2
		M_CHIP	M_RAD_GET
		LDX	<ENINDX

		LDA	R0
		STA	<EWORK0
		CLC
		ADC	#00080H
		AND	#001FEH
		STA	R1
		LDA	#00400H
		STA	R6
		M_CHIP	M_ENMY_1P_ROT
		LDX	<ENINDX
		LDA	PLBGCR
		AND	#0000000111100000B
		BEQ	RMARU_PLCHK1100

		AND	#0000000110000000B
		DEC	A
		EOR	R0
		BPL	RMARU_PLCHK1300

RMARU_PLCHK1100 EQU	$
		LDA	R0

RMARU_PLCHK1200 EQU	$
		STA	PLXSPD
		STA	PLMVSP

RMARU_PLCHK1300 EQU	$
		LDA	R1
		EOR	#0FFFFH
		INC	A
		STA	<EWORK0
		LDA	PLBGCR
		AND	#0000000000011111B
		BEQ	RMARU_PLCHK1400

		AND	#0000000000011000B
		DEC	A
		EOR	<EWORK0
		BMI	RMARU_PLCHK1700

RMARU_PLCHK1400 EQU	$
		LDA	<EWORK0
		BPL	RMARU_PLCHK1600

		PHA
		LDA	#P006
		STA	PLJUMP
		LDA	#001+8000H
		STA	PLSPJP
		PLA
		ASL	A

RMARU_PLCHK1600 EQU	$
		STA	PLYSPD

RMARU_PLCHK1700 EQU	$
RMARU_P_SB0000	EQU	$

		RTS
;
RMARU_SUB0	EQU	$
		TYX

		LDA	ENTIM0,X		;ストップ ?
		BNE	RMARU_SUB0800		; yes: RMARU_SUB0800

		LDA	#00040H*2
		STA	ENTIM0,X
		INC	<ENWRK2,X

RMARU_SUB0800	EQU	$

		RTS
;
RMARU_SUB1	EQU	$
		TYX

		LDA	ENTIM0,X		;まわる ?
		BNE	RMARU_SUB1500		; yes: RMARU_SUB1500

		LDA	ENWRK8,X		;平行になってる ?
		AND	#0007FH			;
		BNE	RMARU_SUB1500		;  no: RMARU_SUB1500

		DEC	<ENWRK2,X
		LDA	#00040H*2
		STA	ENTIM0,X

		RTS

RMARU_SUB1500	EQU	$
		LDA	ENWRK8,X
		CLC
		ADC	#00010H
		STA	ENWRK8,X

		STZ	<ENWRK4,X		;回転エリア書き換えフラグクリア

		RTS
;
;************************************************************************
;*		initial ( 宝のつぼ )					*
;************************************************************************
TTUBOIN		EQU	$			;-- ttuboin --
		LDA	ENXPSL,X
		STA	ENWRKA,X
		STA	<EWORK4
		LDA	ENYPSL,X
		STA	ENWRKC,X
		JSL	>EXIST_CHECK_S2		;中身ある ?
		BEQ	TTUBOIN0100		; yes: TTUBOIN0400

		INC	<ENWRK5,X		;中身なしフラグセット

TTUBOIN0100	EQU	$
		STZ	ENMUKI,X		;向き固定

		LDA	#00004
		STA	ECNTYW,X
		ASL	A		;[ LDA	#00008H ]
		STA	EWIDEX,X
		LDA	#0000CH
		STA	EWIDEY,X

		RTL
;
;************************************************************************
;*		move	( 宝のつぼ )					*
;************************************************************************
;B		ENWRK0	プレイヤーＯＮフラグ
;B		ENWRK1	床を離れたフラグ
;		ENWRK2	ROUTNE MODE INDEX
;B		ENWRK4	敵にあたって跳ね上がったフラグ
;B		ENWRK5	中身なしフラグ
;		ENWRK6	初期着地チェックフラグ
;		ENWRK8	ジャンプしたときのＹ　ＰＯＳ．
;		ENWRKA	セットＸ　ＰＯＳ．
;		ENWRKC	セットＹ　ＰＯＳ．
;
;		ENCONT	潰れフラグ
;
TTUBO_SUB	EQU	$
		WORD	DUMMY_SUB	;だみ
		WORD	TTUBO_SUB1	;潰れ
;
TTUBOMV		EQU	$			;-- ttubomv --
		JSL	>ENMDCK

		LDY	<ENWRK4,X
		BNE	TTUBOMV0100

		STZ	ENXSPD,X

TTUBOMV0100	EQU	$
		STZ	ENMUKI,X

		JSR	TTUBO_BGCHK
		JSR	TTUBO_OBJ_CHK

		TXY
		LDA	<ENWRK2,X
		ASL	A
		TAX
		JSR	(TTUBO_SUB,X)

		LDY	<ENWRK0,X		;プレイヤー乗ってる ?
		BEQ	TTUBOMV0800		;  no: TTUBOMV0800

		LDY	ENYSPD+1,X		;上昇中 ?
		BPL	TTUBOMV0800		;  no: TTUBOMV0800

		LDA	PLBGCR			;プレイヤー頭があたってる ?
		AND	#0000000000011000B	;
		BEQ	TTUBOMV0800		;  no: TTUBOMV0800

		STZ	ENYSPD,X

TTUBOMV0800	EQU	$

		RTL
;
TTUBO_OBJ_CHK	EQU	$
		LDY	<ENWRK2,X		;本体ある ?
		BNE	TTUBO_O_CHK0800		;  no: TTUBO_O_CHK0800

		LDY	ECRSFG,X		;プレイヤーと衝突した ?
		BPL	TTUBO_O_CHK0100		;  no: TTUBO_O_CHK0100

		JSR	TTUBO_PLCHK
		RTS

TTUBO_O_CHK0100 EQU	$
		DEY
		BMI	TTUBO_O_CHK0800

		JSR	TTUBO_ENCHK

TTUBO_O_CHK0800 EQU	$
		LDY	#000
		STY	<ENWRK0,X		;プレイヤーＯＮフラグクリア

		RTS
;
TTUBO_XSPD	EQU	$
		WORD	0FFC0H,00040H
		WORD	0FF80H,00080H
;
TTUBO_ENCHK	EQU	$
		LDA	ENMODE,Y
		CMP	#EMOVE
		BNE	TTUBO_ENCHK0800
		LDA	ENSHOT,Y
		BEQ	TTUBO_ENCHK0800

		LDA	ENGPOW,Y
		STA	<EWORK0
		LDA	ENXSPD,Y
		STA	<EWORK2
		LDA	ECENTX,Y
		SEC
		SBC	ECENTX,X
		TYX
		JSL	>ENDEATH_SET_4

		LDA	#0FD00H
		STA	ENYSPD,X
		LDY	#000
		LDA	<EWORK0			;マックス投げ ?
		BNE	TTUBO_ENCHK0200		;  no: TTUBO_ENCHK0200

		LDY	#004

TTUBO_ENCHK0200 EQU	$
		LDA	<EWORK2
		BMI	TTUBO_ENCHK0400

		INY
		INY

TTUBO_ENCHK0400 EQU	$
		LDA	!TTUBO_XSPD,Y
		STA	ENXSPD,X
		LDY	#001			;敵にあたって跳ね上がったフラグセット
		STY	<ENWRK4,X		;

TTUBO_ENCHK0800 EQU	$

		RTS
;
TTUBO_PUSH_XSPD EQU	$
		WORD	00040H,0FFC0H
TTUBO_CHK_YWIDE EQU	$
		WORD	00018H,0001CH
;
TTUBO_PLCHK	EQU	$
		LDA	EPWIDY,X
		SEC
		SBC	PWIDEY
		SEC
		SBC	EWIDEY,X
		STA	<EWORK4
		LDY	<ENWRK0,X		;プレイヤーすでに乗ってる ?
		BEQ	TTUBO_PLCHK1000		;  no: TTUBO_PLCHK1000

		LDY	PLYSPD+1		;プレイヤー上昇中 ?
		BMI	TTUBO_PLCHK0800		; yes: TTUBO_PLCHK0800

TTUBO_PLCHK0200 EQU	$
		INC	ONLFFG
		LDA	PLYPSL			;プレイヤーＹ　ＰＯＳ．補正
		CLC				;
		ADC	<EWORK4			;
		CLC				;
		ADC	#00002			;
		STA	PLYPSL			;

		RTS

TTUBO_PLCHK0800 EQU	$
		LDY	#000
		STY	<ENWRK0,X		;プレイヤーＯＮフラグクリア
		RTS

TTUBO_PLCHK1000 EQU	$
		CMP	#0FFF8H			;プレイヤーに踏まれた ?
		BCC	TTUBO_PLCHK2000		;  no: TTUBO_PLCHK2000

		LDY	PLJUMP			;プレイヤージャンプ中 ?
		BEQ	TTUBO_PLCHK3000		;  no: TTUBO_PLCHK3000
		LDY	PLYSPD+1		;プレイヤー上昇中 ?
		BMI	TTUBO_PLCHK3000		; yes: TTUBO_PLCHK3000

		INC	<ENWRK0,X		;プレイヤーＯＮフラグセット
		STZ	PLYSPD
		BRA	TTUBO_PLCHK0200

TTUBO_PLCHK2000 EQU	$
		JSR	TRBOX_PUSH

TTUBO_PLCHK3000 EQU	$

		RTS
;
TTUBO_BOUND	EQU	$-2
		WORD	0FE00H,0FF00H
;
TTUBO_BGCHK	EQU	$
		LDA	ENCBFG,X		;地面に着いてる ?
		AND	#00001			;
		BNE	TTUBO_BGCHK1000		; yes: TTUBO_BGCHK1000

		LDY	ENWRK6,X		;一度地面に着いてる ?
		BEQ	TTUBO_BGCHK0800		;  no: TTUBO_BGCHK0800

		LDY	<ENWRK4,X		;敵にあたって跳ね上がってる ?
		BNE	TTUBO_BGCHK0800		; yes: TTUBO_BGCHK0800

		INY				;床を離れたフラグセット
		STY	<ENWRK1,X		;

TTUBO_BGCHK0800 EQU	$

		RTS

TTUBO_BGCHK1000 EQU	$
		STA	ENWRK6,X		;初期着地チェックフラグセット

		LDY	<ENWRK4,X		;敵にあたって跳ね上がってる ?
		BEQ	TTUBO_BGCHK1200		;  no: TTUBO_BGCHK1200

		LDA	ENYPSL,X		;つぼ、高いところから落ちた ?
		SEC				;
		SBC	ENWRK8,X		;
		CMP	#00010H			;
		BMI	TTUBO_BGCHK1080		;  no: TTUBO_BGCHK1080

		LDY	#000			;敵にあたって跳ね上がったフラグクリア
		STY	<ENWRK4,X		;
		BRA	TTUBO_BGCHK1280		;

TTUBO_BGCHK1080 EQU	$
		CPY	#003			;バウンド終わり ?
		BPL	TTUBO_BGCHK1100		; yes: TTUBO_BGCHK1100

		TYA
		ASL	A
		TAY
		LDA	!TTUBO_BOUND,Y
		STA	ENYSPD,X
		INC	<ENWRK4,X
		RTS

TTUBO_BGCHK1100 EQU	$
		LDY	#000			;敵にあたって跳ね上がったフラグクリア
		STY	<ENWRK4,X		;
		RTS

TTUBO_BGCHK1200 EQU	$
		LDY	<ENWRK1,X		;床から滑り落ちてる ?
		BNE	TTUBO_BGCHK1280		; yes: TTUBO_BGCHK1280

		LDA	ENYPSL,X
		STA	ENWRK8,X

		RTS

TTUBO_BGCHK1280 EQU	$
		LDY	<ENWRK2,X
		BNE	TTUBO_BGCHK0800

		LDA	ENMOD2,X		;範囲クリアなし
		AND	#1111111111110011B	;
		STA	ENMOD2,X		;
		LDA	#00002
		STA	ENTIM1,X
		STZ	<ENCONT,X		;潰れフラグクリア
		LDA	#00066H			;［Ｓ］
		JSL	>SOUND_3_ON
		INC	<ENWRK2,X

		LDY	<ENWRK5,X		;中身はいってる ?
		BNE	TTUBO_BGCHK0800		;  no: TTUBO_BGCHK0800

		LDY	#000
		LDA	ENWRKA,X
		AND	#00010H
		BEQ	TTUBO_BGCHK1300

		INY

TTUBO_BGCHK1300 EQU	$
		LDA	ENWRKC,X
		AND	#00010H
		BEQ	TTUBO_BGCHK1400

		INY
		INY

TTUBO_BGCHK1400 EQU	$
		CPY	#003			;空 ?
		BEQ	TTUBO_BGCHK1700		; yes: TTUBO_BGCHK1700
		CPY	#002			;コイン ?
		BNE	TTUBO_BGCHK1500		;  no: TTUBO_BGCHK1500

		JSL	>TRBOX_COIN_SET
		BRA	TTUBO_BGCHK1580

TTUBO_BGCHK1500 EQU	$
		CPY	#001			;タイムくん ?
		BNE	TTUBO_BGCHK1600		;  no: TTUBO_BGCHK1600

		JSL	>TRBOX_TIME_SET

TTUBO_BGCHK1580 EQU	$
		LDA	ENWRKA,X
		STA	<EWORK4
		LDA	ENWRKC,X
		JSL	>NON_EXIST_SET2
		RTS

TTUBO_BGCHK1600 EQU	$
		JSR	TRBOX_KEY_SET

TTUBO_BGCHK1700 EQU	$
TTUBO_SUB1000	EQU	$

		RTS
;
TTUBO_SUB1	EQU	$
		TYX

		LDA	ENTIM1,X		;キャラパターンチェンジ ?
		BNE	TTUBO_SUB1000		;  no: TTUBO_SUB1000

		LDA	#00004
		STA	ENTIM1,X

		INC	ENCHPT,X		;潰れパターン終わり ?
		LDY	ENCHPT,X		;
		CPY	#006			;
		BMI	TTUBO_SUB1000		;  no: TTUBO_SUB1000

		LDY	<ENCONT,X		;初めて ?
		BNE	TTUBO_SUB1300		;  no: TTUBO_SUB1300

		INC	<ENCONT,X

TTUBO_SUB1300	EQU	$
		DEC	ENCHPT,X
		JSL	>DISPCK2		;画面外 ?
		BCC	TTUBO_SUB1800		;  no; TTUBO_SUB1800

		JSL	>ENCLEAR_NORETN

TTUBO_SUB1800	EQU	$

		RTS
;
;************************************************************************
;*		initial ( ジュゲムの金斗雲 )				*
;************************************************************************
KINTOIN		EQU	$			;-- kintoin --
		LDA	#00040H*5*3-060H	;フラッシング開始タイマーセット
		STA	ENTIM0,X		;
		LDA	#00040H*5*3		;寿命タイマーセット
		STA	ENTIM2,X		;

		RTL
;
;************************************************************************
;*		move	( ジュゲムの金斗雲 )				*
;************************************************************************
;		ENWRK0
;
;		ENCONT	ジュゲムの ROUTINE INDEX
;
;		ENTIM0	フラッシング開始タイマー
;		ENTIM1	キャラパターンチェンジタイマー
;		ENTIM2	寿命タイマー
;
KINTO_DSLIM	EQU	$
		WORD	LEFT_X,RIGHT_X
;
KINTO_BGCKPS	EQU	$
		WORD	00010H,0FFF0H
;
KINTOMV		EQU	$			;-- kintomv --
		LDY	ENSHOT,X
		BEQ	KINTOMV0100

		JSL	>DISPCK0

		RTL

KINTOMV0100	EQU	$
		CPX	PONLFFG			;プレイヤー乗ってる ?
		BEQ	KINTOMV0110		; yes: KINTOMV0110
		JMP	KINTOMV0800		;  no: KINTOMV0800

KINTOMV0110	EQU	$
		LDA	ENDSXL,X		;
		SEC				;
		SBC	#00080H			;
		STA	<EWORK0			;

		LDA	ENXSPD,X		;チェックする ?
		BEQ	KINTOMV0180		; yes: KINTOMV0180
		EOR	<EWORK0			;
		BMI	KINTOMV0300		;  no: KINTOMV0300

KINTOMV0180	EQU	$
		LDA	ENDSXL,X
		CMP	#000F0H
		BCC	KINTOMV0300

;		LDY	#000			;コース外 ?
;		LDA	<EWORK0			;
;		BPL	KINTOMV0200		;
;						;
;		INY				;
;		INY				;
;						;
;KINTOMV0200	EQU	$			;
;		LDA	!KINTO_BGCKPS,Y		;
;		CLC				;
;		ADC	PCENTX			;
;		STA	<EWORK0			;
;		LDA	PCENTY			;
;		STA	<EWORK2			;
;		JSL	>COURSE_CHECK		;
;		BPL	KINTOMV0300		; yes: KINTOMV0300

		STZ	ENXSPD,X
		STZ	ENXPOW,X
		LDA	ENXPSL,X
		SEC
		SBC	ENMOVX,X
		STA	ENXPSL,X
		LDA	EPWIDX,X
		SEC
		SBC	ENMOVX,X
		STA	EPWIDX,X

KINTOMV0300	EQU	$
		LDA	ENDSYL,X
		SEC
		SBC	#00080H
		STA	<EWORK0

		LDA	ENYSPD,X		;チェックする ?
		BEQ	KINTOMV0380		; yes: KINTOMV0380
		EOR	<EWORK0			;
		BMI	KINTOMV1000		;  no: KINTOMV1000

KINTOMV0380	EQU	$
		LDA	ENDSYL,X
		SEC
		SBC	#00020H
		CMP	#000D0H-20H
		BCC	KINTOMV1000

;		LDY	#000			;コース外 ?
;		LDA	<EWORK0			;
;		BPL	KINTOMV0400		;
;						;
;		INY				;
;		INY				;
;						;
;KINTOMV0400	EQU	$			;
;		LDA	PCENTX			;
;		STA	<EWORK0			;
;		LDA	!KINTO_BGCKPS,Y		;
;		CLC				;
;		ADC	PCENTY			;
;		STA	<EWORK2			;
;		JSL	>COURSE_CHECK		;
;		BPL	KINTOMV1000		; yes: KINTOMV1000

		STZ	ENYSPD,X
		STZ	ENGPOW,X
		LDA	ENYPSL,X
		SEC
		SBC	ENMOVY,X
		STA	ENYPSL,X
		LDA	EPWIDY,X
		SEC
		SBC	ENMOVY,X
		STA	EPWIDY,X
		BRA	KINTOMV1000

KINTOMV0800	EQU	$
		JSL	>DISPCK2		;範囲外 ?
		BCC	KINTOMV1000		;  no: KINTOMV1000

		JMP	>ENCLEAR

KINTOMV1000	EQU	$
		LDA	ATSCRL_FLAG		;オートスクロール ?
		BEQ	KINTOMV1200		;  no: KINTOMV1200

		CPX	PONLFFG			;プレイヤー乗ってる ?
		BNE	KINTOMV1200		;  no: KINTOMV1200

		LDY	#000
		LDA	ENXPSL,X		;画面右端 ?
		SEC				;
		SBC	ESCCH1			;
		SEC				;
		SBC	#LEFT_X			;
		BMI	KINTOMV1100		; yes: KINTOMV1100
		INY
		INY
		SEC				;画面左端 ?
		SBC	#RIGHT_X-LEFT_X		;
		BMI	KINTOMV1200		; no: KINTOMV1200

KINTOMV1100	EQU	$
		LDA	ENXSPD,X		;画面外に出ようとしてる ?
		BEQ	KINTOMV1180		;
		SEC				;
		SBC	SCRL_XSPD		;
		EOR	ENXSPD,X		;
		BMI	KINTOMV1200		;  no: KINTOMV1200

KINTOMV1180	EQU	$
		LDA	SCRL_XSPD		;スピードセット
		STA	ENXSPD,X		;
		LDA	ENXPSL,X		;ポジション補正
		SEC				;
		SBC	ENMOVX,X		;
		STA	ENXPSL,X		;
		LDA	EPWIDX,X
		SEC
		SBC	ENMOVX,X
		STA	EPWIDX,X
		STZ	ENMOVX,X
		LDA	ESCCH1
		CLC
		ADC	!KINTO_DSLIM,Y
		STA	ENXPSL,X
		M8
		LDA	SCRL_XSDR+1
		STA	ENXSDR,X
		M16

KINTOMV1200	EQU	$
		JSL	>ENMDCK

		JSR	KINTO_PLCHK

		LDA	ENXMAX,X
		BNE	KINTOMV1300

		LDA	ENXSPD,X
		CLC
		ADC	#00040H
		CMP	#00080H
		BCS	KINTOMV1300

		STZ	ENXSPD,X
		STZ	ENXPOW,X

KINTOMV1300	EQU	$
		LDA	ENGMAX,X
		BNE	KINTOMV1500

		LDA	ENYSPD,X
		CLC
		ADC	#00040H
		CMP	#00080H
		BCS	KINTOMV1500

		STZ	ENYSPD,X
		STZ	ENGPOW,X

KINTOMV1500	EQU	$
;＊＊＊＊＊＊＊＊＜　キャラパターンチェンジ　＞＊＊＊＊＊＊＊＊
		LDA	ENTIM1,X
		BNE	KINTOMV3000

		LDA	ENCHPT,X
		EOR	#00001
		STA	ENCHPT,X

		LDA	#KINTS
		JSL	>EXINSR

		LDA	#00002
		STA	EXCHPT,Y
		LDA	<RANDM0
		AND	#00003
		SEC
		SBC	#00002+8
		CLC
		ADC	ECENTX,X
		STA	EXXPSL,Y
		LDA	<RANDM0
		AND	#00007
		SEC
		SBC	#00004+8
		CLC
		ADC	ECENTY,X
		STA	EXYPSL,Y
		LDA	#00008
		STA	EXTIM0,Y
		STA	ENTIM1,X

KINTOMV3000	EQU	$
;＊＊＊＊＊＊＊＊＜　じゅげむ再セットチェック用　＞＊＊＊＊＊＊＊＊
		LDY	<ENCONT,X		;じゅげむはいる ?
		BEQ	KINTOMV3300		;  no: KINTOMV3300

		LDA	#00080H
		STA	ENTIM3-1,Y

KINTOMV3300	EQU	$
;＊＊＊＊＊＊＊＊＜　フラッシング　＞＊＊＊＊＊＊＊＊
		LDA	GOAL_IN
		BEQ	KINTOMV3400

		LDA	ENTIM0,X
		BEQ	KINTOMV3350

		STZ	ENTIM0,X

KINTOMV3350	EQU	$
		LDA	#00020H
		CMP	ENTIM2,X
		BPL	KINTOMV3450

		STA	ENTIM2,X
		BRA	KINTOMV3450

KINTOMV3400	EQU	$
		LDA	ENTIM0,X
		BNE	KINTOMV3800

KINTOMV3450	EQU	$
		LDA	ENTIM2,X
		BNE	KINTOMV3500

		JSR	KINTO_TO_FREE

		JMP	>ENCLEAR

KINTOMV3500	EQU	$
		LDY	#0FFH
		LDA	FRCNT2
		AND	#00001
		BNE	KINTOMV3700

		LDY	#005

KINTOMV3700	EQU	$
		TYA
		STA	ENYUSN,X

KINTOMV3800	EQU	$
;		CPX	PONLFFG
;		BNE	KINTOMV3980
;
;		LDY	BERFLG
;		BNE	KINTOMV3980
;
;		LDY	#000
;		LDA	ENXSPD,X
;		BNE	KINTOMV3830
;
;		LDA	PLCMKI
;		BNE	KINTOMV3900
;
;KINTOMV3830	EQU	$
;		BMI	KINTOMV3900
;
;		INY
;		INY
;
;KINTOMV3900	EQU	$
;		TYA
;		STA	ENMUKI,X

KINTOMV3980	EQU	$

		RTL
;
KINTO_XMAX	EQU	$
;KEYC1L+1 =		 [0]	[1]    [2]    [3]    [4]    [5]	   [6]	  [7]
;		WORD	00000H,00180H,0FE80H,00000H,00000H,00100H,0FF00H,00000H
		WORD	00000H,00300H,0FD00H,00000H,00000H,00200H,0FE00H,00000H
;KEYC1L+1 =		 [8]	[9]    [A]    [B]    [C]    [D]	   [E]	  [F]
;		WORD	00000H,00100H,0FF00H,00000H,00000H,00100H,0FF00H,00000H
		WORD	00000H,00200H,0FE00H,00000H,00000H,00200H,0FE00H,00000H
KINTO_GMAX	EQU	$
;KEYC1L+1 =		 [0]	[1]    [2]    [3]    [4]    [5]	   [6]	  [7]
;		WORD	00000H,00000H,00000H,00000H,00180H,00100H,00100H,00100H
		WORD	00000H,00000H,00000H,00000H,00300H,00200H,00200H,00200H
;KEYC1L+1 =		 [8]	[9]    [A]    [B]    [C]    [D]	   [E]	  [F]
;		WORD	0FE80H,0FF00H,0FF00H,0FF00H,00000H,00000H,00000H,00000H
		WORD	0FD00H,0FE00H,0FE00H,0FE00H,00000H,00000H,00000H,00000H
;
KINTO_PLCHK	EQU	$
		LDA	GOAL_IN			;ゴールした ?
		BNE	KINTO_TO_FREE		; yes: KINTO_TO_FREE

		LDY	PLYSPD+1		;プレイヤー上昇中 ?
		BMI	KINTO_TO_FREE		; yes: KINTO_TO_FREE

		LDY	PLEATFG			;プレイヤー食われてる ?
		BEQ	KINTO_PLCHK0200		;  no: KINTO_PLCHK0200

KINTO_PLCHK0100 EQU	$
KINTO_TO_FREE	EQU	$
		CPX	PONLFFG			;前まで乗ってた ?
		BNE	KINTO_PLCHK0120		;  no: KINTO_PLCHK0120

		STZ	PONLFFG
		STZ	<ENWRK0,X
		STZ	ENXMAX,X
		STZ	ENGMAX,X
		LDA	#0000011000000000B	;食われる、衝突する
		STA	ENMOD0,X

		LDA	PLMODE			;ゴールしてる ?
		CMP	#PGOL			;
		BEQ	KINTO_PLCHK0120		; yes: KINTO_PLCHK0120

;;;;;;;;		LDY	#PMOV
		STZ	PLMODE

KINTO_PLCHK0120 EQU	$

		RTS

KINTO_PLCHK0200 EQU	$
		CPX	PONLFFG			;前まで乗ってた ?
		BNE	KINTO_PLCHK0300		;  no: KINTO_PLCHK0300

		LDA	PLBGCR			;進行方向の壁にあたった ?
		AND	#0000000111100000B	;
		BEQ	KINTO_PLCHK0280		;
						;
		AND	#0000000110000000B	;
		DEC	A			;
		EOR	ENXSPD,X		;
		BPL	KINTO_PLCHK0250		;  no: KINTO_PLCHK0250

		LDA	ENXPSL,X
		SEC
		SBC	ENMOVX,X
		STA	ENXPSL,X
		LDA	EPWIDX,X
		SEC
		SBC	ENMOVX,X
		STA	EPWIDX,X
		STZ	ENMOVX,X

KINTO_PLCHK0250 EQU	$
		LDA	PLBGCR			;進行方向の足、頭があたった ?
		AND	#0000000000011111B	;
		BEQ	KINTO_PLCHK0280		;
						;
		AND	#0000000000011000B	;
		DEC	A			;
		EOR	ENYSPD,X		;
		BPL	KINTO_PLCHK0280		;  no: KINTO_PLCHK0280

		LDA	ENYPSL,X
		SEC
		SBC	ENMOVY,X
		STA	ENYPSL,X
		LDA	EPWIDY,X
		SEC
		SBC	ENMOVY,X
		STA	EPWIDY,X
		STZ	ENMOVY,X

KINTO_PLCHK0280 EQU	$
		LDA	EPWIDX,X
		SEC
		SBC	ENMOVX,X
		STA	EPWIDX,X
		LDA	EPWIDY,X
		SEC
		SBC	ENMOVY,X
		STA	EPWIDY,X
		BRA	KINTO_PLCHK0330

KINTO_PLCHK0300 EQU	$
		LDY	PLJUMP			;プレイヤージャンプ中 ?
		BNE	KINTO_PLCHK0330
		JMP	KINTO_TO_FREE		;  no: KINTO_TO_FREE

KINTO_PLCHK0330 EQU	$
		LDA	GOAL_IN			;ゴールした ?
		BNE	KINTO_PLCHK0350		; yes: KINTO_PLCHK0350

		LDA	EPWIDX,X
		CLC
		ADC	#00010H
		CMP	#00020H
		BCS	KINTO_PLCHK0350

		LDA	EPWIDY,X		;プレイヤー上から乗ってきた ?
		SEC				;
		SBC	PWIDEY			;
		SEC				;
		SBC	EWIDEY,X		;
		BPL	KINTO_PLCHK0350		;
		CMP	#0FFF8H			;
		BPL	KINTO_PLCHK0380		; yes: KINTO_PLCHK0380

KINTO_PLCHK0350 EQU	$
		JMP	KINTO_PLCHK0100		;  no: KINTO_PLCHK0100

KINTO_PLCHK0380 EQU	$
		STA	<EWORK0

		LDY	PONLFFG			;プレイヤー何かに乗ってる ?
		BNE	KINTO_PLCHK0400		; yes: KINTO_PLCHK0400

		LDA	PLBGCR
		AND	#0000000000011111B
		BEQ	KINTO_PLCHK0390
		JMP	KINTO_TO_FREE

KINTO_PLCHK0390 EQU	$
		STX	PONLFFG
		LDA	EPWIDX,X
		STA	<ENWRK0,X
		LDY	#PDEM
		STY	PLMODE
		LDA	PLXSPD
		CMP	#08000H
		ROR	A
		STA	ENXSPD,X
		LDA	#0000000001100000B	;食われない、衝突しない
		STA	ENMOD0,X

KINTO_PLCHK0400 EQU	$
		CPX	PONLFFG			;自分に乗ってる ?
		BEQ	KINTO_PLCHK0402		; yes: KINTO_PLCHK0402

		RTS

KINTO_PLCHK0402 EQU	$
		LDA	BERFLG
		BNE	KINTO_PLCHK0404

		LDA	KEYC1L
		AND	#0FCFFH
		STA	P_KEYC1L
		LDA	KEYC2L
		AND	#0FCFFH
		STA	P_KEYC2L

KINTO_PLCHK0404 EQU	$
		LDA	PLBGCR
		AND	#0000000000011000B
		BNE	KINTO_PLCHK0408

		LDA	<EWORK0			;プレイヤーＹ　ＰＯＳ．補正
;		CLC				;
;		ADC	#00002			;
		SEC				;
		ADC	PLYPSL			;
		SEC				;
		ADC	ENMOVY,X		;
		STA	PLYPSL			;
		INC	ONLFFG			;プレイヤーＯＮフラグセット

KINTO_PLCHK0408 EQU	$
		LDA	<ENWRK0,X
		CMP	#0FFFDH
		BEQ	KINTO_PLCHK0430
		BPL	KINTO_PLCHK0410

		INC	<ENWRK0,X
		BRA	KINTO_PLCHK0430

KINTO_PLCHK0410 EQU	$
		DEC	<ENWRK0,X

KINTO_PLCHK0430 EQU	$
		LDA	PLBGCR			;プレイヤー横ＢＧあたり ?
		AND	#0000000111100000B	;
		BNE	KINTO_PLCHK0480		; yes: KINTO_PLCHK0480

		LDA	EPWIDX,X
		SEC
		SBC	<ENWRK0,X
		CLC
		ADC	PLXPSL
		STA	PLXPSL

KINTO_PLCHK0480 EQU	$
		LDA	PLDOSN			;どすん中 ?
		BEQ	KINTO_PLCHK0500		;  no: KINTO_PLCHK0500

		LDA	#00500H
		CLC
		ADC	ENYSPD,X
		STA	ENYSPD,X
		BRA	KINTO_PLCHK0580

KINTO_PLCHK0500 EQU	$
		LDA	KEYC1L+1
		AND	#0000FH
		ASL	A
		TAY
		LDA	!KINTO_XMAX,Y
		STA	ENXMAX,X
		BEQ	KINTO_PLCHK0504

		LDA	BERFLG			;舌が出てる ?
		ORA	PLNAGE			;プレイヤー投げようとしてる ?
		BNE	KINTO_PLCHK0504		; yes: KINTO_PLCHK0504

		LDA	KEYC1L+1
		AND	#00002H
		STA	PLCMKI

KINTO_PLCHK0504 EQU	$
		LDA	!KINTO_GMAX,Y
		STA	ENGMAX,X

		LDA	#00008H
		STA	ENXPOW,X
		STA	ENGPOW,X

KINTO_PLCHK0580 EQU	$
		STZ	PLXSPD
		STZ	PLMVSP
		STZ	PLYSPD
		STZ	PLXSDR
		STZ	PLYSDR
		STZ	PLDOSN			;

KINTO_PLCHK0600 EQU	$

		RTS
;
;
;
;
;
;
;
;
SHOT_EN_KILL_SP EQU	$
		LDY	ECRSFG,X		;敵と衝突した ?
		DEY				;
		BMI	S_E_K_SP0800		;  no: S_E_K_SP0800

		LDA	ENMODE,Y
		CMP	#EMOVE
		BNE	S_E_K_SP0700

		TYX				;特別処理の敵 ?
		JSL	>HEIH0_DEATH_CHK	;
		BEQ	S_E_K_SP0100		; yes: S_E_K_SP0100
		JSL	>MATO0_DEATH_CHK	;
		BNE	S_E_K_SP0200		;  no: S_E_K_SP0200

S_E_K_SP0100	EQU	$
		LDX	<ENINDX
		LDA	ENMOD0,X		;衝突チェックされる
		ORA	#0000001000000000B	;
		STA	ENMOD0,X		;
		SEC
		RTL

S_E_K_SP0200	EQU	$
		LDA	ENSHOT,X		;ショットされてる ?
		BEQ	S_E_K_SP0700		;  no: S_E_K_SP0700

		LDA	ENMYNO,X
		CMP	#EGG00
		BCC	S_E_K_SP0400
		CMP	#EGG09+1
		BCS	S_E_K_SP0500

S_E_K_SP0400	EQU	$
		LDA	ENGPOW,X		;マックス投げ ?
		CMP	#00040H			;
		BCC	S_E_K_SP0600		; yes: S_E_K_SP0600

S_E_K_SP0500	EQU	$
		JSL	>ENDEATH_SET_4

S_E_K_SP0600	EQU	$
		LDX	<ENINDX
		JSL	>ENDEATH_SET_4
		SEC
		RTL

S_E_K_SP0700	EQU	$
		LDX	<ENINDX
		PLA
		STA	<EWORK0
		JSL	>EPCRCK
		LDA	<EWORK0
		PHA

S_E_K_SP0800	EQU	$
		CLC
		RTL
;
SHOT_EN_KILL_S2 EQU	$
		LDY	ECRSFG,X		;敵と衝突した ?
		DEY				;
		BMI	S_E_K_SP0800		;  no: S_E_K_SP0800

		LDA	ENMODE,Y
		CMP	#EMOVE
		BNE	S_E_K_SP0800
		LDA	ENSHOT,Y
		BEQ	S_E_K_SP0800

		TYX
		JSL	>SHOT_EN_KILL		;衝突処理した ?
		BCC	S_E_K_SP0600		; yes: GHOSTMV0880

		LDA	ENMOD0,X		;衝突チェックされる
		ORA	#0000001000000000B	;
		STA	ENMOD0,X		;
		SEC
		RTL
;
;************************************************************************
;*		initial ( kachi )					*
;************************************************************************
KATI0IN		EQU	$			;-- kati0in --
KATI1IN		EQU	$			;-- kati1in --
KATI2IN		EQU	$			;-- kati2in --
		LDA	ENMOD1,X
		STA	ENWRKA,X

		LDA	ENMYNO,X
		CMP	#KATI2
		BNE	KATI0IN0800

		LDA	#0000DH
		STA	ENCHPT,X
		INC	ENWRK6,X

KATI0IN0800	EQU	$

		RTL
;
;************************************************************************
;*		move	( kachi )					*
;************************************************************************
;		ENWRK0	着地フラグ( for stop kachi )
;		ENWRK2	ROUTINE MODE INDEX
;		ENWRK4	敵のあたってきた方向 0...左 2...右
;		ENWRK6	カチカチフラグ 0...move kachi 1...stop kachi
;		ENWRK8	回転角
;		ENWRKA	ENMOD1 のセーブ
;		ENWRKC	マックス転がりフラグ
;
;		ENCONT	キャラパターンチェンジカウンター
;
;		ENTIM1	キャラパターンチェンジタイマー
;
KATI0_SUB	EQU	$
		WORD	KATI0_SUB0		;とまってる
		WORD	KATI0_SUB1		;うごいてる
		WORD	KATI0_SUB2		;ころがってる
		WORD	KATI0_SUB3		;ふっかつ
		WORD	KATI0_SUB4		;ずずず
		WORD	KATI0_SUB5		;ぽぉーん
;
KATI0_R_XSPD	EQU	$
		WORD	0FE88H,00178H
		WORD	0FE00H,00200H
KATI0_EAT_XSPD	EQU	$
		WORD	00180H,0FE80H
KATI0_SMK_XSPD	EQU	$
		WORD	0FF80H,00080H
;
KATI0MV		EQU	$			;-- kati0mv --
KATI1MV		EQU	$			;-- kati1mv --
KATI2MV		EQU	$			;-- kati2mv --
		LDY	ENCHPT,X		;回転してる ?
		CPY	#00EH			;
		BNE	KATI0MV0100		;  no: KATI0MV0100

		JSL	>TROBJ_OAM_2x2

		I16
		LDY	ENOAML,X
		LDA	#08000H
		STA	SOAM_DX+0+8*1,Y
		STA	SOAM_DX+0+8*2,Y
		STA	SOAM_DX+0+8*3,Y
		STA	SOAM_DX+0+8*4,Y
		I8

KATI0MV0100	EQU	$
		LDA	ENMODE,X
		CMP	#EEATM
		BEQ	KATI0MV0120
		JMP	KATI0MV0190

KATI0MV0120	EQU	$
		LDA	#EMOVE
		STA	ENMODE,X
		STZ	EATSTP
		LDA	#00005
		STA	ENYUSN,X

		LDA	ENCLOR,X		;#EDOWN の時、ひっくり返ってるのを元に戻すため
		AND	#0FF3FH
		STA	ENCLOR,X

		LDY	#002
		LDA	BERFLG
		CMP	#003
		BMI	KATI0MV0130

		INY
		INY

KATI0MV0130	EQU	$
		STY	BERFLG

		LDA	ENMOD2,X		;範囲クリアＯＮ
		ORA	#000000000100B		;
		STA	ENMOD2,X		;

		CPY	#002			;横から食われた ?
		BEQ	KATI0MV0140		; yes: KATI0MV0140

		LDY	EPYMUK,X		;上から食われた ?
		BEQ	KATI0MV0140		; yes: KATI0MV0140

		LDA	#0FD00H
		STA	ENYSPD,X
		LDY	#005
		LDA	#0000AH
		BRA	KATI0MV0160

KATI0MV0140	EQU	$
		LDY	EPXMUK,X
		TYA
		STA	ENMUKI,X
		LDA	#00020H
		STA	ENXPOW,X
		LDA	!KATI0_EAT_XSPD,Y
		STA	ENXSPD,X
		LDA	!KATI0_SMK_XSPD,Y
		STA	<EWORK0
		LDA	#DSMK1
		JSL	>EXINSR
;
		LDA	ENXPSL,X
		STA	EXXPSL,Y
		LDA	ENYPSL,X
		CLC
		ADC	#0000CH
		STA	EXYPSL,Y
		LDA	#00004
		STA	EXTIM0,Y
		STA	EXWRK0,Y
		LDA	<EWORK0
		STA	EXXSPD,Y
		LDA	#0FF80H
		STA	EXYSPD,Y
		LDA	ENMUKI,X
		EOR	#00002H
		STA	EXMUKI,Y

		LDY	#004
		LDA	#00006

KATI0MV0160	EQU	$
		STY	<ENWRK2,X
		STA	ENCHPT,X
		STZ	ENTIM1,X

		PLA
		PLY
		RTL
;
KATI0MV0190	EQU	$
		JSL	>ENMDCK

		LDY	ECRSFG,X		;何かにあたった ?
		BNE	KATI0MV019000		;  no: KATI0MV019000

KATI0MV01900	EQU	$
		JMP	KATI0MV0400

KATI0MV019000	EQU	$
		DEY				;敵にあたった ?
		BPL	KATI0MV0191		; yes: KATI0MV0191
		JMP	KATI0MV0300		;  no: KATI0MV0300

KATI0MV0191	EQU	$
		LDA	ENMODE,Y
		CMP	#EMOVE
		BNE	KATI0MV01900

		LDA	ENSHOT,Y		;ショットされてた ?
		BEQ	KATI0MV01900		;  no: KATI0MV01900

		STZ	ENWRKC,X		;マックス転がりフラグクリア
		LDA	#00008H
		STA	ENXPOW,X
		LDA	ENGPOW,Y		;マックスショット ?
		CMP	#00040H			;
		BPL	KATI0MV0198		;  no: KATI0MV0198

		INC	ENWRKC,X		;マックス転がりフラグセット

		LDA	#0FD00H
		STA	ENYSPD,X

KATI0MV0198	EQU	$
		LDA	ENXSPD,Y
		PHP

		TYX
		JSL	>ENDEATH_SET_4

		LDY	#000
		PLP
		BMI	KATI0MV0200

		INY
		INY

KATI0MV0200	EQU	$
		STY	<ENWRK4,X
		TYA
		LDY	ENWRKC,X
		BEQ	KATI0MV0210

		CLC
		ADC	#00004

KATI0MV0210	EQU	$
		TAY
		LDA	!KATI0_R_XSPD,Y
		STA	ENXSPD,X

		LDA	#0002EH			;［Ｓ］
		JSL	>SOUND_3_ON

		LDA	#KACHB
		JSL	>EXINSR
		LDA	ECENTX,X
		STA	EXXPSL,Y
		LDA	ECENTY,X
		STA	EXYPSL,Y
		LDA	#00005
		STA	EXCHPT,Y
		ASL	A		;[ LDA	#0000AH ]
		STA	ENCHPT,X

		LDA	#00002
		STA	EXTIM0,Y
;[ LDA	#00002 ]
		STA	<ENWRK2,X

		LDA	ENTROB,X
		BPL	KATI0MV0400

		JSL	>TROBJ_SR_2x2
;;;;;;;;		BCC	KATI0MV0300
		BCC	KATI0MV0400

		STZ	ENWRK8,X		;回転角クリア
		LDA	#0000EH
		STA	ENCHPT,X

		BRA	KATI0MV0400

KATI0MV0300	EQU	$
;;;;;;;;		JSL	>EPCRCK
		JSL	>PLFLST

KATI0MV0400	EQU	$
		TXY
		LDA	<ENWRK2,X
		ASL	A
		TAX
		JSR	(KATI0_SUB,X)

		LDA	ENWRKA,X
		LDY	<ENWRK2,X		;のーまるむーぶ ?
		CPY	#002			;
		BMI	KATI0MV0500		; yes: KATI0MV0500

		LDA	#0000100001000001B	;行ったり来たりしない

KATI0MV0500	EQU	$
		STA	ENMOD1,X		;

		JSR	KATI0_ROT_SET

		RTL
;
KATI0_ROT_SET	EQU	$
		LDY	ENCHPT,X		;回転エリアを使ってる ?
		CPY	#00EH			;
		BEQ	KATI0_R_SET0300		; yes: KATI0_R_SET0300

		LDA	ENTROB,X
		BMI	KATI0_R_SET0800

		JSL	>TROBJ_CLEAR
		RTS

KATI0_R_SET0300 EQU	$
;＊＊＊＊＊＊＊＊＜　ビットマップエリアセット　＞＊＊＊＊＊＊＊＊＊＊
		LDA	#CIPCHD+5000H+000	;(R12) <-- 転送元アドレスセット
		STA	R12			;
		LDA	#BANK CIPCHD+5000H+000	;(R13) <-- 転送元バンクセット
		STA	R13			;

		LDA	ENWRK8,X		;(R5) <- 回転角セット
		LSR	A			;
		STA	R5			;

		LDA	#00100H			;(R6) <- 倍率セット
		STA	R6			;

		LDY	ENTROB,X
		TYX
		LDA	>TROBJ_PLOT_X,X		;(R3) <- ビットマップ座標＿Ｘセット
		STA	R3			;
		LDA	>TROBJ_PLOT_Y,X		;(R2) <- ビットマップ座標＿Ｙセット
		STA	R2			;
;
;-------------- OBJ mode 7 set ----------------------------------
		M_CHIP	C_16_ROTZOM

		LDX	<ENINDX

		INC	OBM7WF		;mode 7 OBJ chara DMA "ON"

KATI0_R_SET0800 EQU	$

		RTS
;
KATI0_S0_XSPD	EQU	$
		WORD	0FF80H,000C0H
KATI0_S0_TIM0	EQU	$
		HEX	01,02,01,02,01
KATI0_S0_CHPT	EQU	$
		HEX	0F,11,0F,11,0F
;
KATI0_SUB0	EQU	$
		TYX

		LDY	ENWRK6,X		;ストップカチカチ ?
		BEQ	KATI0_SUB0500		;  no: KATI0_SUB0500

		LDA	ENCBFG,X		;地面に着いてる ?
		AND	#00001			;
		BEQ	KATI0_SUB0800		;  no: KATI0_SUB0800

		LDA	ENTIM1,X		;キャラパターンチェンジ ?
		BNE	KATI0_SUB0800		;  no: KATI0_SUB0800

		DEC	<ENWRK0,X		;ジャンプする ?
		BPL	KATI0_SUB0100		;  no: KATI0_SUB0100

		LDA	#00005
		STA	<ENWRK0,X
		LDA	#0FC00H
		STA	ENYSPD,X
		LDA	#00010H
		STA	ENCHPT,X

		RTS

KATI0_SUB0100	EQU	$
		LDY	<ENWRK0,X
		LDA	!KATI0_S0_TIM0,Y
		AND	#000FFH
		STA	ENTIM1,X
		LDA	!KATI0_S0_CHPT,Y
		AND	#000FFH
		STA	ENCHPT,X

		RTS

KATI0_SUB0500	EQU	$
		INC	ENCHPT,X
		LDY	ENCHPT,X
		CPY	#004
		BNE	KATI0_SUB0800

		TYA
		LSR	A		;[ LDA	#00002 ]
		STA	ENTIM1,X
		LDY	ENMUKI,X
		LDA	!KATI0_S0_XSPD,Y
		STA	ENXSPD,X

		INC	<ENWRK2,X

		RTS

KATI0_SUB0800	EQU	$
		CPY	#002
		BNE	KATI0_SUB0900

		LDA	#00026H			;［Ｓ］
		JSL	>SOUND_3_ON

KATI0_SUB0900	EQU	$

		RTS
;
KATI0_SUB1	EQU	$
		TYX

		LDA	ENTIM1,X
		BNE	KATI0_SUB1800

		LDA	#00002
		STA	ENTIM1,X

		INC	ENCHPT,X
		LDY	ENCHPT,X
		CPY	#00AH
		BMI	KATI0_SUB1800

		ASL	A		;[ LDA	#00004H ]
		STA	ENTIM1,X
		STZ	ENCHPT,X
		LDY	ENWRK6,X		;ストップカチカチ ?
		BEQ	KATI0_SUB1700		;  no: KATI0_SUB1700

		LDA	#0000DH
		STA	ENCHPT,X
		STZ	<ENWRK0,X

KATI0_SUB1700	EQU	$
		STZ	ENXSPD,X
		STZ	<ENWRK2,X

KATI0_SUB1800	EQU	$

		RTS
;
KATI0_SUB2	EQU	$
		TYX

		LDA	ENXSPD,X		;止まりかけている ?
		CLC				;
		ADC	#00020H			;
		CMP	#00040H			;
		BCS	KATI0_SUB2300		;  no: KATI0_SUB2300

		STZ	ENXSPD,X
		STZ	ENXPOW,X

		LDY	ENCHPT,X
		CPY	#00EH
		BNE	KATI0_SUB2200

		JSL	>TROBJ_CLEAR

KATI0_SUB2200	EQU	$
		STZ	ENWRK8,X
		LDA	#0000AH
		STA	ENCHPT,X
		LDA	#00060H			;ストップタイマーセット
		STA	ENTIM1,X		;
		LDY	#006
		STY	<ENCONT,X
		INC	<ENWRK2,X

		RTS

KATI0_SUB2300	EQU	$
		LDA	ENXSPD,X
		BPL	KATI0_SUB2400

		EOR	#0FFFFH
		INC	A

KATI0_SUB2400	EQU	$
		CLC
		ADC	#00080H
		AND	#0FF00H
		ASL	A
		ASL	A
		ASL	A
		ASL	A
		ASL	A
		XBA
		STA	<EWORK0

		LDA	ENMUKI,X
		EOR	<ENWRK4,X
		BEQ	KATI0_SUB2700

		LDA	<EWORK0
		EOR	#0FFFFH
		INC	A
		STA	<EWORK0

KATI0_SUB2700	EQU	$
		LDA	<EWORK0
		CLC
		ADC	ENWRK8,X
		AND	#001FEH
		STA	ENWRK8,X

		JSL	>MBALL_ENCHK

		RTS
;
KATI0_S3_CHPT	EQU	$-1
		HEX	00D,00C,00A,00B,00A,00B
KATI0_S3_TIM1	EQU	$-1
		HEX	012,002,010,004,008,004
;
KATI0_SUB3	EQU	$
		TYX

		LDA	ENTIM1,X
		BNE	KATI0_SUB3800

		DEC	<ENCONT,X
		BNE	KATI0_SUB3500

		LDA	#00004
		STA	ENTIM1,X
		STZ	ENCHPT,X
		LDY	ENWRK6,X		;ストップカチカチ ?
		BEQ	KATI0_SUB3400		;  no: KATI0_SUB3400

		LDA	#0000DH
		STA	ENCHPT,X
		STZ	<ENWRK0,X

KATI0_SUB3400	EQU	$
		STZ	<ENWRK2,X

		RTS

KATI0_SUB3500	EQU	$
		LDY	<ENCONT,X
		LDA	!KATI0_S3_CHPT,Y
		AND	#000FFH
		STA	ENCHPT,X
		LDA	!KATI0_S3_TIM1,Y
		AND	#000FFH
		STA	ENTIM1,X

KATI0_SUB3800	EQU	$

		RTS
;
KATI0_SUB4	EQU	$
		TYX

		LDA	ENXSPD,X
		BNE	KATI0_SUB4800

KATI0_SUB4100	EQU	$
		LDA	ENTIM1,X
		BNE	KATI0_SUB4200

		STZ	ENXPOW,X
		LDA	#00010H
		STA	ENTIM0,X
		INC	A
		STA	ENTIM1,X

KATI0_SUB4200	EQU	$
		LDA	ENTIM0,X
		BNE	KATI0_SUB4800

		LDA	#00004
		STA	ENTIM1,X
		STZ	ENCHPT,X
		LDA	ENMYNO,X		;ストップカチカチ ?
		CMP	#KATI2			;
		BNE	KATI0_SUB4700		;  no: KATI0_SUB4700

		LDA	#0000DH
		STA	ENCHPT,X

KATI0_SUB4700	EQU	$
		STZ	<ENWRK2,X

KATI0_SUB4800	EQU	$

		RTS
;
KATI0_SUB5	EQU	$
		TYX

		LDA	ENCBFG,X
		BNE	KATI0_SUB4100

		RTS
;
;************************************************************************
;*		initial ( maruta bashi )				*
;************************************************************************
MARUTIN		EQU	$			;-- marutin --
		STZ	ENMUKI,X

		RTL
;
;************************************************************************
;*		move	( maruta bashi )				*
;************************************************************************
;		ENWRK0	プレイヤーＯＮフラグ 0...no OTHER...on player
;		ENWRK2	ROUTINE MODE INDEX
;		ENWRK4	プレイヤーＹ　ＳＰＥＥＤ
;		ENWRK6	丸太　その１　オフセットＹ　ＰＯＳ．
;		ENWRK8	丸太　その２　オフセットＹ　ＰＯＳ．
;		ENWRKA	丸太　その３　オフセットＹ　ＰＯＳ．
;		ENWRKC	丸太　その４　オフセットＹ　ＰＯＳ．
;
MARUTMV		EQU	$			;-- marutmv --
;＊＊＊＊＊＊＊＊＜　ＯＡＭセット　＞＊＊＊＊＊＊＊＊
		I16				;
		LDY	ENOAML,X		;
		LDA	ENDSYL,X
		STA	<EWORK0

		LDA	ENWRK6,X
		AND	#000FFH
		CLC
		ADC	<EWORK0
		STA	SOAM_DX+2+8*0,Y
		LDA	ENWRK7,X
		AND	#000FFH
		CLC
		ADC	<EWORK0
		STA	SOAM_DX+2+8*1,Y
		LDA	ENWRK8,X
		AND	#000FFH
		CLC
		ADC	<EWORK0
		STA	SOAM_DX+2+8*2,Y
		LDA	ENWRK9,X
		AND	#000FFH
		CLC
		ADC	<EWORK0
		STA	SOAM_DX+2+8*3,Y
		LDA	ENWRKA,X
		AND	#000FFH
		CLC
		ADC	<EWORK0
		STA	SOAM_DX+2+8*4,Y
		LDA	ENWRKB,X
		AND	#000FFH
		CLC
		ADC	<EWORK0
		STA	SOAM_DX+2+8*5,Y
		LDA	ENWRKC,X
		AND	#000FFH
		CLC
		ADC	<EWORK0
		STA	SOAM_DX+2+8*6,Y
		LDA	ENWRKD,X
		AND	#000FFH
		CLC
		ADC	<EWORK0
		STA	SOAM_DX+2+8*7,Y
		I8

;＊＊＊＊＊＊＊＊＜　プレイヤーチェック　＞＊＊＊＊＊＊＊＊
		LDA	PLBGCR			;プレイヤー地面に着いてる ?
		AND	#00003			;
		BNE	MARUTMV0001		; yes: MARUTMV0001

		LDA	PLYPSL
		CLC
		ADC	<ENWRK0,X
		STA	PLYPSL

MARUTMV0001	EQU	$
		LDA	ENWRK6,X
		AND	#000FFH
		STA	CCWORK0
		STA	<EWORK0
		LDA	ENWRK7,X
		AND	#000FFH
		STA	CCWORK1
		STA	<EWORK2
		LDA	ENWRK8,X
		AND	#000FFH
		STA	CCWORK2
		STA	<EWORK4
		LDA	ENWRK9,X
		AND	#000FFH
		STA	CCWORK3
		STA	<EWORK6
		LDA	ENWRKA,X
		AND	#000FFH
		STA	CCWORK4
		STA	<EWORK8
		LDA	ENWRKB,X
		AND	#000FFH
		STA	CCWORK5
		STA	<EWORKA
		LDA	ENWRKC,X
		AND	#000FFH
		STA	CCWORK6
		STA	<EWORKC
		LDA	ENWRKD,X
		AND	#000FFH
		STA	CCWORK7
		STA	<EWORKE

		STZ	R1
		LDY	PLYSPD+1
		BPL	MARUTMV0002

		LDY	PLJUMP
		BNE	MARUTMV0080

MARUTMV0002	EQU	$
		LDA	PCENTX
		SEC
		SBC	ENXPSL,X
		CLC
		ADC	#00020H			;20H
		CMP	#00040H
		BCS	MARUTMV0100

		STA	R2
		LDA	ENXPSL,X		;(R3) <- 丸太のＸ　ＰＯＳ．と対象物との距離
		SEC
		SBC	#00018H			;-18H
		SEC
		SBC	PCENTX
		STA	R3
		LDA	#00046H			;WRK1F <- 丸太のＭＡＸ下げ幅　（中用）
		CLC				;
		ADC	<ENWRK4,X		;
		STA	CCWORK1F		;

		LSR	A			;WRK1E <- 丸太のＭＡＸ下げ幅　（両端用）
		STA	CCWORK1E		;
		STA	R6

		LDA	PCENTY
		CLC
		ADC	PLFTLN
		STA	R8
		LDA	PWIDEY
		STA	R9
		LDA	ENYPSL,X
		STA	R10

		M_CHIP	M_MARUT_CHK

		LDX	<ENINDX

		LDY	R1			;プレイヤー乗ってる ?
		BNE	MARUTMV0200		; yes: BARUTMV0200

MARUTMV0080	EQU	$
		LDA	ENYSPD,X
		BEQ	MARUTMV0100

		JMP	MARUTMV0900

MARUTMV0100	EQU	$
		LDY	#00EH

MARUTMV0110	EQU	$
		LDA	EWORK0,Y
		BEQ	MARUTMV0130
		CMP	#00008
		BPL	MARUTMV0120

		LDA	#00008

MARUTMV0120	EQU	$
		LSR	A
		LSR	A
		LSR	A
		EOR	#0FFFFH
		INC	A
		CLC
		ADC	EWORK0,Y
		STA	EWORK0,Y

MARUTMV0130	EQU	$
		DEY
		DEY
		BPL	MARUTMV0110

MARUTMV0180	EQU	$
		STZ	<ENWRK0,X

		JMP	MARUTMV0500

MARUTMV0200	EQU	$
		LDA	ENYSPD,X
		BEQ	MARUTMV0300

		LDY	#00EH

MARUTMV0210	EQU	$
		LDA	CCWORK0,Y
		SEC
		SBC	EWORK0,Y
		BMI	MARUTMV0220

		CMP	#08000H
		ROR	A
		CMP	#08000H
		ROR	A
		CLC
		ADC	EWORK0,Y
		STA	EWORK0,Y

MARUTMV0220	EQU	$
		DEY
		DEY
		BPL	MARUTMV0210
		BRA	MARUTMV0320

MARUTMV0300	EQU	$
		LDY	#00EH

MARUTMV0310	EQU	$
		LDA	CCWORK0,Y
		SEC
		SBC	EWORK0,Y
		CMP	#08000H
		ROR	A
		CMP	#08000H
		ROR	A
		CLC
		ADC	EWORK0,Y
		STA	EWORK0,Y

		DEY
		DEY
		BPL	MARUTMV0310

MARUTMV0320	EQU	$
		LDY	<ENWRK0,X		;前のフレームに乗ってた ?
		BNE	MARUTMV0400		; yes: MARUTMV0400

		LDA	PLYSPD
		LSR	A
		LSR	A
		LSR	A
		LSR	A
		STA	<ENWRK4,X

		LDY	PLDOSN			;ずしん ?
		BEQ	MARUTMV0400

		LDA	PLYSPD
		LSR	A
		STA	ENYSPD,X

MARUTMV0400	EQU	$
		LDA	PLBGCR			;プレイヤー地面に着いてる ?
		AND	#00003			;
		BNE	MARUTMV0500		; yes: MARUTMV0500

		LDA	CCWORK10
		AND	#0FFFEH
		TAY
		LDA	EWORK0,Y
		CLC
		ADC	ENYPSL,X
		SEC
		SBC	#0001EH			;20H-2
		SEC
		SBC	PLFTLN
		STA	PLYPSL

		STZ	PLYSPD

		INC	ONLFFG

		LDY	#002
		STY	<ENWRK0,X

		LDA	ENYSPD,X
		BEQ	MARUTMV0500

		LDA	#00800H
		STA	PLYSPD

MARUTMV0500	EQU	$
		LDA	ENYSPD,X
		BEQ	MARUTMV0600

		LDA	<ENWRK4,X
		CLC
		ADC	#00004
		BRA	MARUTMV0800

MARUTMV0600	EQU	$
		LDA	<ENWRK4,X
		SEC
		SBC	#00008H
		BPL	MARUTMV0800

		LDA	#00000

MARUTMV0800	EQU	$
		STA	<ENWRK4,X

MARUTMV0900	EQU	$
		M8
		LDA	<EWORK0
		STA	ENWRK6,X
		LDA	<EWORK2
		STA	ENWRK7,X
		LDA	<EWORK4
		STA	ENWRK8,X
		LDA	<EWORK6
		STA	ENWRK9,X
		LDA	<EWORK8
		STA	ENWRKA,X
		LDA	<EWORKA
		STA	ENWRKB,X
		LDA	<EWORKC
		STA	ENWRKC,X
		LDA	<EWORKE
		STA	ENWRKD,X
		M16

		RTL
;
;
;
;
;
		END
;
