;
;
;****************************************************************
;*								*
;*	title name  ; yossy enmy data set			*
;*	proccess    ; enmy edit proccess			*
;*	file name   ; yst_en_edit				*
;*								*
;****************************************************************
;
;
		SALL
;
		include yst_header.inc
;
		XALL
;
;
;---------------------------------------------------------------
;
;		Supar_Y enmy-edit-tool
;
;---------------------------------------------------------------
;
;
;=============================================== yst_en_edit ====
		GLB	ENPLAY,PLDWNMN
		GLB	MSTEST,HNKNST
		GLB	ENALLCLS,BGDTMOVE
;
;=============================================== ys_init =======
		EXT	VRAMDX_ST
;
;=============================================== yst_init =======
		EXT	BGSET,ERR0,GAME,PSST,PLMD
		EXT	ITSB
		EXT	ENPLMD,ENMDSL,ENFILE
		EXT	BGMV,MSTST
;
;=============================================== yst_edit =======
		EXT	MSSC,UPSL,DWSL,LFSL,RISL,STIN
		EXT	DTDS
		EXT	PSCTDT1
		EXT	ENBGMV
		EXT	MSSCRMD
		EXT	UNDR_ITCOL,UNDR_COL
;
;=============================================== yst_stat ========
		EXT	OBJTP,EALMV
;
;=============================================== yst_en_file =====
		EXT	ENBFCLS
;
;=============================================== yst_bgsc0 =======
		EXT	KAHNSB
;
;===============================================================
;
;
;
;************************************************************************
;*									*
;*		program start						*
;*									*
;************************************************************************
;
;
		EXTEND
;
;
		MEM8
		IDX8
;
Group_17	GROUP	En_edit_pro
En_edit_pro	SECT	REL
;
;
;****************************************************************
;*								*
;*	enmy data set editer					*
;*								*
;****************************************************************
ENPLAY		EQU	$
		LDA	!MOUSEBT
		AND	#11000000B
		BEQ	ENPLAY_0000
		STZ	!ENNOFLS
;
ENPLAY_0000	EQU	$
		JSL	>UNDR_COL	;マウス ダブルクリック チェック
		LDA	!MODENO
		CMP	#MSSC
		BNE	ENPL000_PAS
		LDX	!MODESV
		LDA	!PLDWMNFG
		STA	!MODESV
		STX	!PLDWMNFG
		JMP	ENPL999		; goto RTL
;
ENPL000_PAS	EQU	$
		STZ	ENMDOBJ
		LDA	MOUSEBT
		AND	#10000000B	; mouse right ON ?
		BEQ	ENPL000		;	NO -> ENPL000
		LDX	!MODESV
		LDA	!PLDWMNFG
		STA	!MODESV
		STX	!PLDWMNFG
		STZ	!MOUSWK0
		STZ	!ENDELFG
		STZ	!ENDSPFG
		M16			; memory 16bit mode
		STZ	!SRCPOS
		LDA	#00000H
		STA	>ENMYDTBF
		STZ	!ENMSLMD
		M8			; memory 8bit mode
		LDA	#ENMDSL
		STA	MODENO
;
;------------ マウス ダブルクリック イニシャル チェック ---------
		JSL	>UNDR_ITCOL
		JMP	ENPL999		; goto RTL
;
ENPL000		EQU	$
		LDA	INKEY
		CMP	#L_U		; inkey [U] ON ?
		BNE	ENPL000_000	;	NO -> ENPL000_000
		LDA	#ITSB		; ＢＧツールへ・・・
		STA	!MODENO
		LDA	#002
		STA	!ENBGFLG
		M16			; memory 16bit mode
		LDA	!ENDTPT
		STA	>ENMYDTBF
		M8			; memory 8bit mode
		JMP	ENPL999
;
ENPL000_000	EQU	$
		CMP	#L_Z		; inkey [Z] ON ?
		BNE	ENPL00		;	NO -> ENPL00
		JSR	ENSCINT		; mouse auto scroll initial set
		JMP	ENPL999
;
ENPL00		EQU	$
		CMP	#RIS		; player pos set ?
		BNE	ENPL002		;	YES -> ENPL002
;
		LDA	#PSST
		STA	MODENO
		STZ	!TIMSTFG
		RTL
;
ENPL002
		LDA	INKEY3
		CMP	#UPS		; up scroll ?
		BEQ	ENPL005		;	YES -> ENPL005
		CMP	#L_O		;	NO  -> ENPL10
		BNE	ENPL10
ENPL005		EQU	$
		LDX	#UPSL
		JSR	UPSCRCK		; up scroll check
		JMP	ENPL999		; goto RTL
;
ENPL10		EQU	$
		CMP	#DWS		; down scroll ?
		BEQ	ENPL105		;	YES -> ENPL105
		CMP	#L_c		;	NO  -> ENPL20
		BNE	ENPL20
ENPL105		EQU	$
		LDX	#DWSL
		JSR	DWNSCRCK	; down scroll check
		JMP	ENPL999		; goto RTL
;
ENPL20		EQU	$
;;;;		    CMP	    #LFS	    ; left scroll ?
;;;;		    BEQ	    ENPL205	    ;	    YES -> ENPL205
		CMP	#L_K		;	NO  -> ENPL30
		BNE	ENPL30
ENPL205		EQU	$
		LDX	#LFSL
		JSR	LFSCRCK		; left scroll check
		JMP	ENPL999		; goto RTL
;
ENPL30		EQU	$
;;;;		    CMP	    #RIS	    ; right scroll ?
;;;;		    BEQ	    ENPL305	    ;	    YES -> ENPL305
		CMP	#L_L		;	NO  -> ENPL40
		BNE	ENPL40
ENPL305		EQU	$
		LDX	#RISL
		JSR	RTSCRCK		; right scroll check
		JMP	ENPL999
;
ENPL40		EQU	$
		LDA	INKEY
		CMP	#F_1		; [F1] ON ?
		BNE	ENPL50		;	NO -> ENPL50
		LDA	#ENFILE
		STA	MODENO
		JMP	ENPL999
;
ENPL50		EQU	$
		CMP	#RTN		; push return key ?
		BNE	ENPL60		;	NO -> ENPL60
		CMP	!ENINKYBF
		BEQ	ENPL60
		STA	!ENINKYBF
		JSR	ENUND		; undo mode (push return key)
		JMP	ENPL999
;
ENPL60		EQU	$
		CMP	#F_0		; [F10] ON ?
		BNE	ENPL70		;	NO -> ENPL70
		LDA	#GAME
		STA	MODENO
		LDA	#01H
		STA	FADMK
		M16			; memory 16bit mode
		LDA	!ENDTPT
		STA	>ENMYDTBF
		M8			; memory 8bit mode
		JMP	ENPL999
;
ENPL70		EQU	$
		CMP	#L_P		; [P] ON ?
		BNE	ENPL80		;	NO -> ENPL80
		JSR	ENSCINT		; mouse auto scroll initial set
		LDA	#MSTST
		STA	MODENO
		JMP	ENPL999
;
ENPL80		EQU	$
		CMP	#F_7		; [F7] ON ?
		BNE	ENPL90		;	NO -> ENPL90
		LDA	#STIN
		STA	!MODENO
		STZ	!STINFG
		M16			; memory 16bit mode
		LDA	!ENDTPT
		STA	>ENMYDTBF
		M8			; memory 8bit mode
		JMP	ENPL999
;
ENPL90		EQU	$
		CMP	#F_6		; [F6] ON ?
		BNE	ENPL100		;	NO -> ENPL100
		LDA	#DTDS
		STA	!MODENO
		STZ	!MPDSFG
		M16			; memory 16bit mode
		LDA	!ENDTPT
		STA	>ENMYDTBF
		M8			; memory 8bit mode
		JMP	ENPL999
;
ENPL100		EQU	$
		CMP	#F_8		; [F8] ON ?
		BNE	ENPL110		;	NO -> ENPL110
		LDA	!MANSEL
		EOR	#004H
		AND	#017H
		STA	!MANSEL
		LDA	!BG3CLSFG
		EOR	#004H
		AND	#004H
		STA	!BG3CLSFG
		JMP	ENPL999
;
ENPL110		EQU	$
		CMP	#F_3		; [F3] ON ?
		BNE	ENPL120		;	NO -> ENPL120
		LDA	#STIN
		STA	!MODENO
		LDA	#OBJTP
		STA	!STINFG
		M16			; memory 16bit mode
		LDA	!ENDTPT		; 敵データ ポインターを
		STA	>ENMYDTBF	;	バッファに セット
		M8			; memory 8bit mode
		JMP	ENPL999
;
ENPL120		EQU	$
		CMP	#F_4		;[F4] ON ?
		BNE	ENPL130		;	NO -> ENPL130
		LDA	#BGMV
		STA	!MODENO
		STZ	!PLDWMNFG
		JMP	ENPL999
;
ENPL130		EQU	$
		CMP	#L_I		;[I] ON ?
		BNE	ENPL140		;	NO -> ENPL140
		LDA	#STIN
		STA	!MODENO
		LDA	#EALMV
		STA	!STINFG
		STZ	!UNTMVMD
		M16			; memory 16bit mode
		LDA	!ENDTPT
		STA	>ENMYDTBF
		M8			; memory 8bit mode
		JMP	ENPL999
;
ENPL140		EQU	$
		PHB
		PHK
		PLB
		LDA	PLDWMNFG
		ASL	A
		TAX
		JSR	(MDJSRSB,X)
		PLB
;
		LDA	INKEY
		STA	!ENINKYBF
		JSL	>ENBGMV		; BG. move
		JSR	MSMVST		; mouse cursol move
		JSR	ENDTSCR		; enmy edit data screen set
		JSL	>BGSET		; BG. set
;
ENPL999		EQU	$
		RTL
;
;
MDJSRSB		EQU	$
		WORD	ENEDT		; edit
		WORD	ENUND		; undo
		WORD	ENMOV		; move
		WORD	ENDEL		; delete
		WORD	ENREN		; rename
		WORD	ENSRC		; search
;
;
;****************************************************************
;*								*
;*	right scroll check					*
;*								*
;****************************************************************
RTSCRCK		EQU	$
		STZ	!SCHMK1
		M16			; memory 16bit mode
		LDA	<SCCH1
		CMP	#00F08H		; scroll OK ?
		BEQ	LFCK009		;	NO -> LFCK009
		CLC
		ADC	#00100H
		CMP	#00F08H+1	; limit over ?
		BCC	LFCK005		;	NO -> LFCK005
		LDA	#00F08H
		BRA	LFCK005
		MEM8
;
;
;****************************************************************
;*								*
;*	left scroll check					*
;*								*
;****************************************************************
LFSCRCK		EQU	$
		LDA	#002H
		STA	!SCHMK1
		M16			; memory 16bit mode
		LDA	<SCCH1
		CMP	#0FFF8H		; scroll OK ?
		BEQ	LFCK009		;	NO -> LFCK009
		SEC
		SBC	#00100H
		CMP	#0FFF8H		; limit over ?
		BPL	LFCK005		;	NO -> LFCK005
		LDA	#0FFF8H
LFCK005		EQU	$
		STA	MVSCH1
		STX	MODENO
LFCK009		EQU	$
		M8			; memory 8bit mode
		RTS
;
;
;****************************************************************
;*								*
;*	down scroll check					*
;*								*
;****************************************************************
DWNSCRCK	EQU	$
		STZ	!SCVMK1
		M16			; memory 16bit mode
		LDA	<SCCV1
		CMP	#00758H		; scroll OK ?
		BEQ	UPCK009		;	NO -> UPCK009
		CLC
		ADC	#00100H
		CMP	#00758H+1	; limit over ?
		BCC	UPCK005		;	NO -> UPCK005
		LDA	#00758H
		BRA	UPCK005
		MEM8
;
;
;****************************************************************
;*								*
;*	up scroll check						*
;*								*
;****************************************************************
UPSCRCK		EQU	$
		LDA	#002H
		STA	!SCVMK1
		M16			; memory 16bit mode
		LDA	<SCCV1
		CMP	#0FFF8H		; scroll OK ?
		BEQ	UPCK009		;	NO -> UPCK009
		SEC
		SBC	#00100H
		CMP	#0FFF8H		; limit over ?
		BPL	UPCK005		;	NO -> UPCK005
		LDA	#0FFF8H
UPCK005		EQU	$
		STA	MVSCV1
		STX	MODENO
UPCK009		EQU	$
		M8			; memory 8bit mode
		RTS
;
;
;****************************************************************
;*								*
;*	mouse auto scroll initial set				*
;*								*
;****************************************************************
ENSCINT		EQU	$
		LDA	#MSSC
		STA	MODENO
		STZ	!WIDEX
		STZ	!WIDEY
		LDX	SIFTFG
		LDA	#080H
		STA	CRXPSL1,X
		LDA	#060H
		STA	CRYPSL1,X
		M16			; memory 16bit mode
		LDA	CRXPSL1,X
		STA	MSSCRX
		LDA	CRYPSL1,X
		STA	MSSCRY
		M8			; memory 8bit mode
;
		RTS
;
;
;****************************************************************
;*								*
;*	enmy edit mouse move set				*
;*								*
;****************************************************************
MSMVST		EQU	$
;-------------- mouse pos check --------------
		LDA	MOUSEBX	       ; mouse X move ?
		BEQ	MSMV100		;	NO -> MSMV100
		BMI	MSMV050		; X<0 move ?
;					;	YES -> MSMV050
;-------------- mouse right move --------------
		M16			; memory 16bit mode
		AND	#0007FH
		STA	<WORK0
;
		CLC
		ADC	CRXPSL1
		CMP	#01000H		;  right scroll limit ?
		BCC	MSMV010		;	NO -> MSMV010
		LDA	#00FFFH
MSMV010		EQU	$
		STA	CRXPSL1
		SEC
		SBC	<SCCH1
		SEC
		SBC	#000F8H-1	; 1 disp limit ?
		BMI	MSMV080		;	NO -> MSMV080
;
		CMP	#010H+1		; 8 dot over ?
		BCC	MSMV012		;	NO -> CRM0112
;
		LDA	<SCCH1
		CLC
		ADC	#000F8H+10H
		STA	CRXPSL1
		LDA	#10H
MSMV012		EQU	$
		CLC
		ADC	<SCCH1
		LDY	#000H
		BRA	MSMV070
;
;-------------- mouse left move -----------------
MSMV050		EQU	$
		M16			; memory 16bit mode
		ORA	#0FF00H
		STA	<WORK0
;
		CLC
		ADC	CRXPSL1	       ; left scroll limit ?
		BPL	MSMV060		;	NO -> MSMV060
		LDA	#00000H
MSMV060		EQU	$
		STA	CRXPSL1
		SEC
		SBC	<SCCH1
		SEC
		SBC	#00008H		; 1 disp limit ?
		BPL	MSMV080		;	NO -> MSMV080
;
		CMP	#0FFF0H		; 8 dot over ?
		BCS	MSMV065		;	NO -> MSMV065
;
		LDA	<SCCH1
		CLC
		ADC	#00008H-10H
		STA	CRXPSL1
		LDA	#0FFF0H
MSMV065		EQU	$
		CLC
		ADC	<SCCH1
		LDY	#002H
;
MSMV070		EQU	$
		STA	<SCCH1
		STA	<SCCH2
		STA	<SCCH3
		STY	<SCHMK1
;
MSMV080		EQU	$
		M8			; memory 8bit mode
;
MSMV100		EQU	$
		LDA	MOUSEBY	       ; mouse Y move ?
		BEQ	MSMV200		;	NO -> MSMV200
		BMI	MSMV150		; down move ?
;					;	NO -> MSMV150
;-------------- mouse down move -----------------
		M16			; memory 16bit mode
		AND	#0007FH
;
		CLC
		ADC	CRYPSL1
		CMP	#00800H		; down scroll limit ?
		BCC	MSMV110		;	NO -> MSMV110
		LDA	#007FFH
MSMV110		EQU	$
		STA	CRYPSL1
		SEC
		SBC	<SCCV1
		SEC
		SBC	#000A8H-1	; 1 disp limit ?
		BMI	MSMV180		;	NO -> MSMV180
;
		CMP	#10H+1		; 8 dot over ?
		BCC	MSMV115		;	NO -> MSMV115
;
		LDA	<SCCV1
		CLC
		ADC	#000A8H+10H
		STA	CRYPSL1
		LDA	#010H
MSMV115		EQU	$
		CLC
		ADC	<SCCV1
		LDY	#000H
		BRA	MSMV170
;
;-------------- mouse up move -------------------
MSMV150		EQU	$
		M16			; memory 16bit mode
		ORA	#0FF00H
		CLC
		ADC	CRYPSL1	       ; up scroll limit ?
		BPL	MSMV155		;	NO -> MSMV155
		LDA	#00000H
MSMV155		EQU	$
		STA	CRYPSL1
		SEC
		SBC	<SCCV1
		SEC
		SBC	#00008H		; 1 disp limit ?
		BPL	MSMV180		;	NO -> MSMV180
;
		CMP	#0FFF0H		; 8 dot over ?
		BCS	MSMV1555	;	NO -> MSMV1555
;
		LDA	<SCCV1
		CLC
		ADC	#00008H-10H
		STA	CRYPSL1
		LDA	#0FFF0H
MSMV1555	EQU	$
		CLC
		ADC	<SCCV1
		LDY	#002H
;
MSMV170		EQU	$
		STA	<SCCV1
		STA	<SCCV2
		STA	<SCCV3
		STY	<SCVMK1
;
MSMV180		EQU	$
		M8			; memory 8bit mode
;
MSMV200		EQU	$
		M16
;
		LDA	CRXPSL1
		SEC
		SBC	<SCCH1
		STA	<WORK0
		LDA	CRYPSL1
		SEC
		SBC	<SCCV1
		STA	<WORK2
;
		M8
;
		LDA	<WORK0
		STA	!ARROAM		; x-pos. set
		LDA	<WORK2
		STA	!ARROAM+1	; y-pos. set
		LDA	#088H
		STA	!ARROAM+2	; char. no. set
		LDA	#034H
		STA	!ARROAM+3	; attribute set
;
		LDA	#00001010B	; ( + last input data cursol )
		STA	!OAMSUB
;
;------------- mode obj set  --------------------
		LDA	ENMDOBJ
		BEQ	MSMV250
;
		DEC	A
		DEC	A
		STA	!OAM+6
		LDA	#033H
		STA	!OAM+7
		LDA	XTAIHI
		SEC
		SBC	<SCCH1
		STA	!OAM+4
		LDA	YTAIHI
		SEC
		SBC	<SCCV1
		STA	!OAM+5
;
MSMV250		EQU	$
;
;------------- keyboard input -------------------
		LDA	INKEY
		CMP	#030H
		BCC	MSMV320
		CMP	#03AH
		BCC	MSMV300
		CMP	#041H
		BCC	MSMV320
		CMP	#047H
		BCS	MSMV320
;
MSMV300		EQU	$		; enmy NO. ram set
		SEC
		SBC	#030H
		TAX
		JSR	ENNOWKST	; enmy NO. work set
;
		LDA	!ENNOFLS
		LSR	A
		LSR	A
		TAY
		LDA	>ENNODT,X
		STA	!WORK0,Y
		LDA	!ENNOFLS
		CLC
		ADC	#004H
		AND	#00FH
		STA	!ENNOFLS
		CMP	#009H
		BCC	MSMV310
		STZ	!ENNOFLS
;
MSMV310		EQU	$
		LDA	<WORK1
		ASL	A
		ASL	A
		ASL	A
		ASL	A
		ORA	<WORK2
		STA	!ENEMYNO
		LDA	<WORK0
		STA	!ENEMYNO+1
;
		M16			; memory 16bit mode
		LDA	!ENEMYNO
		CMP	!ENNAMCT
		BCC	MSMV318
		LDA	!ENNAMCT
		DEC	A
		STA	!ENEMYNO
MSMV318		EQU	$
		M8			; memory 8bit mode
		JMP	MSMV400
;
MSMV320		EQU	$
		CMP	#L_H		; 10 point dec.
		BEQ	MSMV330		;	YES -> MSMV330
		CMP	#L_J		; 1 point dec.
		BEQ	MSMV340		;	YES -> MSMV340
		CMP	#L_M		; 1 point inc.
		BEQ	MSMV350		;	YES -> MSMV350
		CMP	#L_N		; 10 point inc.
		BNE	MSMV400		;	NO  -> MSMV400
;
		JSR	ENNOWKST	; enmy NO. work set
		BRA	MSMV355
;
MSMV330		EQU	$		; 10 point dec.
		JSR	ENNOWKST	; enmy NO. work set
		BRA	MSMV345
;
MSMV340		EQU	$		; 1 point dec.
		JSR	ENNOWKST	; enmy NO. work set
		LDA	<WORK2
		DEC	A
		AND	#00FH
		STA	<WORK2
		CMP	#00FH
		BNE	MSMV390
MSMV345		EQU	$
		LDA	<WORK1
		DEC	A
		AND	#00FH
		STA	<WORK1
		CMP	#00FH
		BNE	MSMV390
		DEC	<WORK0
		BRA	MSMV390
;
MSMV350		EQU	$		; 1 point inc.
		JSR	ENNOWKST	; enmy NO. work set
		LDA	<WORK2
		INC	A
		AND	#00FH
		STA	<WORK2
		BNE	MSMV390
MSMV355		EQU	$
		LDA	<WORK1
		INC	A
		AND	#00FH
		STA	<WORK1
		BNE	MSMV390
		INC	<WORK0
;
MSMV390		EQU	$
		LDA	<WORK1
		ASL	A
		ASL	A
		ASL	A
		ASL	A
		ORA	<WORK2
		STA	!ENEMYNO
		LDA	<WORK0
;;K;;		AND	#00FH
		STA	!ENEMYNO+1
;
		M16			; memory 16bit mode
		LDA	!ENEMYNO
		BMI	MSMV393
		CMP	!ENNAMCT
		BCC	MSMV398
		STZ	!ENEMYNO
		BRA	MSMV398
MSMV393		EQU	$
		LDA	!ENNAMCT
		DEC	A
		STA	!ENEMYNO
MSMV398		EQU	$
		M8			; memory 8bit mode
;
MSMV400		EQU	$
		RTS
;
;
;++++++++++++++++++++++++++++++++++++++++++++++++
;+						+
;+	enmy NO. work set			+
;+				work0 <- high	+
;+				    1 <- mid	+
;+				    2 <- low	+
;++++++++++++++++++++++++++++++++++++++++++++++++
ENNOWKST	EQU	$
		LDA	!ENEMYNO	 ; enmy NO. low set
		AND	#00FH
		STA	<WORK2
		LDA	!ENEMYNO	 ; enmy NO. mid set
		AND	#0F0H
		LSR	A
		LSR	A
		LSR	A
		LSR	A
		STA	<WORK1
		LDA	!ENEMYNO+1	 ; enmy NO. high set
		AND	#00FH
		STA	<WORK0
		RTS
;
;
ENNODT		EQU	$
		BYTE	000H,001H,002H,003H,004H,005H,006H,007H
		BYTE	008H,009H,000H,000H,000H,000H,000H,000H
		BYTE	000H,00AH,00BH,00CH,00DH,00EH,00FH
;
ENOBJ		EQU	$
		BYTE	000H,002H,004H
;
;
;****************************************************************
;*								*
;*	enmy edit data screen set				*
;*								*
;****************************************************************
ENDTSCR		EQU	$
		PHB
		PHK
		PLB
;
		MI16			; memory , index 16bit mode
		LDX	#00000H
ENDTLOP		EQU	$		; disp set
		LDA	ENSCRD0,X
		STA	!OAM+100H,X
		INX
		INX
		CPX	#ENSCRD5-ENSCRD0
		BNE	ENDTLOP
		STX	<WORK0
		MI8			; memory , index 8bit mode
;
;--------------------------------------- put count set
		M16			; memory 16bit mode
		LDA	!ENDTPT
		BEQ	ENDT200
		M8			; memory 8bit mode
		AND	#00FH
		TAX
		LDA	ENDSPFG
		BEQ	ENDT110
		M16			; memory 16bit mode
		LDA	>ENMYDTBF
		STA	<WORKA
		M8			; memory 8bit mode
		AND	#00FH
		TAX
ENDT110		EQU	$
		LDA	>PSCTDT1,X
		STA	!OAM+100H+012H
		LDA	!ENDTPT
		AND	#0F0H
		LSR	A
		LSR	A
		LSR	A
		LSR	A
		TAX
		LDA	ENDSPFG
		BEQ	ENDT120
		LDA	<WORKA
		AND	#0F0H
		LSR	A
		LSR	A
		LSR	A
		LSR	A
		TAX
ENDT120		EQU	$
		LDA	>PSCTDT1,X
		STA	!OAM+100H+00EH
		LDA	!ENDTPT+1
		AND	#00FH
		TAX
		LDA	ENDSPFG
		BEQ	ENDT130
		LDA	<WORKB
		AND	#00FH
		TAX
ENDT130		EQU	$
		LDA	>PSCTDT1,X
		STA	!OAM+100H+00AH
;
;--------------------------------------- enmy NO. set
ENDT200		EQU	$
		M16			; memory 16bit mode
		LDA	!ENEMYNO
		AND	#00FFFH
		BEQ	ENDT290
		STA	<WORKA
		M8			; memory 8bit mode
		AND	#00FH
		TAX
		LDA	>PSCTDT1,X
		STA	!OAM+100H+(ENSCRD1-ENSCRD0)+026H	; low
		LDA	<WORKA
		AND	#0F0H
		LSR	A
		LSR	A
		LSR	A
		LSR	A
		TAX
		LDA	>PSCTDT1,X
		STA	!OAM+100H+(ENSCRD1-ENSCRD0)+022H	; mid
		LDX	<WORKB
		LDA	>PSCTDT1,X
		STA	!OAM+100H+(ENSCRD1-ENSCRD0)+01EH	; high
;
ENDT290		EQU	$
		M8			; memory 8bit mode
		LDA	<FRCNT
		AND	#010H
		BEQ	ENDT300
		LDX	!ENNOFLS
		LDA	!OAM+100H+(ENSCRD1-ENSCRD0)+01FH,X
		AND	#0F0H
		STA	!OAM+100H+(ENSCRD1-ENSCRD0)+01FH,X
;
;--------------------------------------- enmy name
ENDT300		EQU	$
		MI16			; memory , index 16bit mode
		LDA	!ENEMYNO
		ASL	A
		ASL	A
		CLC
		ADC	!ENEMYNO
		TAX
		M8			; memory 8bit mode
		LDA	>ENNAMBF+0,X
		STA	!OAM+100H+(ENSCRD2-ENSCRD0)+002H
		STA	!ENNAM0
		LDA	>ENNAMBF+1,X
		STA	!OAM+100H+(ENSCRD2-ENSCRD0)+006H
		STA	!ENNAM1
		LDA	>ENNAMBF+2,X
		STA	!OAM+100H+(ENSCRD2-ENSCRD0)+00AH
		STA	!ENNAM2
		LDA	>ENNAMBF+3,X
		STA	!OAM+100H+(ENSCRD2-ENSCRD0)+00EH
		STA	!ENNAM3
		LDA	>ENNAMBF+4,X
		STA	!OAM+100H+(ENSCRD2-ENSCRD0)+012H
		STA	!ENNAM4
		I8			; index 8bit mode
;
;--------------------------------------- X point set
ENDT400		EQU	$
		LDA	CRXPSL1
		LSR	A
		LSR	A
		LSR	A
		LSR	A
		TAX
		LDA	>PSCTDT1,X
		STA	!OAM+100H+(ENSCRD3-ENSCRD0)+0EH
		LDX	CRXPSH1
		LDA	>PSCTDT1,X
		STA	!OAM+100H+(ENSCRD3-ENSCRD0)+0AH
;
;--------------------------------------- Y point set
		LDA	CRYPSL1
		LSR	A
		LSR	A
		LSR	A
		LSR	A
		TAX
		LDA	>PSCTDT1,X
		STA	!OAM+100H+(ENSCRD3-ENSCRD0)+1EH
		LDX	CRYPSH1
		LDA	>PSCTDT1,X
		STA	!OAM+100H+(ENSCRD3-ENSCRD0)+1AH
;
;--------------------------------------- file name set
		LDA	!MJIDX0
		BEQ	ENDT500
		LDY	#000H
		TYX
ENDT505		EQU	$		; 敵データ ファイル
		LDA	!MOJBF0,Y
		STA	!OAM+100H+(ENSCRD4-ENSCRD0)+2,X
		INX
		INX
		INX
		INX
		INY
		CPY	#008H
		BNE	ENDT505
;
ENDT500		EQU	$
		LDY	#000H
		TYX
ENDT510_00	EQU	$
		LDA	!MOJBF1,Y
		BEQ	ENDT510_05
		CMP	#020H
		BEQ	ENDT510_05
		INX
ENDT510_05	EQU	$
		INY
		CPY	#008H
		BCC	ENDT510_00
		STX	!MJIDX1
		TXA
		BEQ	ENDT600
		LDY	#000H
		TYX
ENDT515		EQU	$		; コースデータ ファイル
		LDA	!MOJBF1,Y
		STA	!OAM+100H+(ENSCRD45-ENSCRD0)+2,X
		INX
		INX
		INX
		INX
		INY
		CPY	#008H
		BNE	ENDT515
;
;--------------------------------------- edit mode set
ENDT600		EQU	$
		LDX	<WORK0
		M16			; memory 16bit mode
		LDA	PLDWMNFG
		AND	#000FFH
		ASL	A
		TAY
		LDA	ENSCRD5,Y
		STA	<WORK2
		LDY	#000H
ENDT610		EQU	$
		LDA	(<WORK2),Y
		STA	!OAM+100H,X
		INX
		INX
		INY
		INY
		CPY	#(PLDWDT1-PLDWDT0)
		BNE	ENDT610
		M8			; memory 8bit mode
		PHX
		LDX	<WORK0
		LDA	#010H
		STA	!OAM+100H+01H,X
		STA	!OAM+100H+05H,X
		STA	!OAM+100H+09H,X
		STA	!OAM+100H+0DH,X
		STA	!OAM+100H+11H,X
		STA	!OAM+100H+15H,X
		PLX
;
ENDT99		EQU	$
		PLB
		RTS
;
;
ENSCRD0		EQU	$
		BYTE	020H,0BAH,C_P,032H	; P
		BYTE	028H,0BAH,C_T,032H	; T
		BYTE	028H,0C2H,C_0,032H	; 0
		BYTE	030H,0C2H,C_0,032H	; 0
		BYTE	038H,0C2H,C_0,032H	; 0
;
ENSCRD1		EQU	$
		BYTE	048H,0BAH,C_E,03AH	; E
		BYTE	050H,0BAH,C_N,03AH	; N
		BYTE	058H,0BAH,C_M,03AH	; M
		BYTE	060H,0BAH,C_Y,03AH	; Y
;
		BYTE	050H,0C2H,C_N,03AH	; N
		BYTE	058H,0C2H,C_O,03AH	; O
		BYTE	060H,0C2H,L_p,03AH	; .
		BYTE	068H,0C2H,C_0,03AH	; 0
		BYTE	070H,0C2H,C_0,03AH	; 0
		BYTE	078H,0C2H,C_0,03AH	; 0
;
ENSCRD2		EQU	$			; enmy name
		BYTE	088H,0BAH,C_HI,032H	; -
		BYTE	090H,0BAH,C_HI,032H	; -
		BYTE	098H,0BAH,C_HI,032H	; -
		BYTE	0A0H,0BAH,C_HI,032H	; -
		BYTE	0A8H,0BAH,C_HI,032H	; -
;
ENSCRD3		EQU	$			; X,Y point
		BYTE	0B8H,0BAH,C_X,032H	; X
		BYTE	0C0H,0BAH,C_HI,032H	; -
		BYTE	0C8H,0BAH,C_0,032H	; 0
		BYTE	0D0H,0BAH,C_0,032H	; 0
;
		BYTE	0B8H,0C2H,C_Y,032H	; Y
		BYTE	0C0H,0C2H,C_HI,032H	; -
		BYTE	0C8H,0C2H,C_0,032H	; 0
		BYTE	0D0H,0C2H,C_0,032H	; 0
;
ENSCRD4		EQU	$
		BYTE	020H,0AAH,02DH,032H	; enmy file name set
		BYTE	028H,0AAH,02DH,032H
		BYTE	030H,0AAH,02DH,032H
		BYTE	038H,0AAH,02DH,032H
		BYTE	040H,0AAH,02DH,032H
		BYTE	048H,0AAH,02DH,032H
		BYTE	050H,0AAH,02DH,032H
		BYTE	058H,0AAH,02DH,032H
		BYTE	060H,0AAH,02EH,032H
		BYTE	068H,0AAH,045H,032H
		BYTE	070H,0AAH,04EH,032H
		BYTE	078H,0AAH,044H,032H
ENSCRD45	EQU	$
		BYTE	088H,0AAH,02DH,032H	; corse data name set
		BYTE	090H,0AAH,02DH,032H
		BYTE	098H,0AAH,02DH,032H
		BYTE	0A0H,0AAH,02DH,032H
		BYTE	0A8H,0AAH,02DH,032H
		BYTE	0B0H,0AAH,02DH,032H
		BYTE	0B8H,0AAH,02DH,032H
		BYTE	0C0H,0AAH,02DH,032H
		BYTE	0C8H,0AAH,02EH,032H
		BYTE	0D0H,0AAH,044H,032H
		BYTE	0D8H,0AAH,041H,032H
		BYTE	0E0H,0AAH,054H,032H
;
ENSCRD5		EQU	$
		WORD	PLDWDT0,PLDWDT1,PLDWDT2
		WORD	PLDWDT3,PLDWDT4,PLDWDT5
;
ENSCRD6		EQU	$
;
;
;****************************************************************
;*								*
;*	pull down menuw						*
;*								*
;****************************************************************
ENAME_SLECT_ADR	EQU	$
		WORD	ENAME_SLCT_INT
		WORD	ENAME_SELECT
;
;
PLDWNMN		EQU	$
		LDA	#10000000B
		STA	!HD420C		; H-DMA ch"ON"
		LDA	!MOUSEBB
		AND	#10000000B	; mouse right ON ?
		BNE	PLDWN00		;	YES -> PLDWN00
		LDA	#ENPLMD
		STA	MODENO
		JMP	PLDWN99
;
PLDWN00		EQU	$
		LDA	!MOUSEBB
		AND	#01000000B	; mouse left ON ?
		BEQ	PLDWN00_50	;	NO -> PLDWN00_50
		LDA	#01000000B
		STA	!HD420C		; H-DMA ch"ON"
		LDX	!ENMSLMD
		JSR	(ENAME_SLECT_ADR,X)
		JMP	PLDWN99_99
;
PLDWN00_50	EQU	$
		PHB
		PHK
		PLB
		MI16			; memory , index 16bit mode
;
		LDX	#00000H
PLDWN05		EQU	$
		LDA	PLDWDT0,X
		STA	!OAM+100H,X
		INX
		INX
		CPX	#(PLDWDTE-PLDWDT0)
		BNE	PLDWN05
;
		M8			; memory 8bit mode
		LDA	MOUSEBY	       ; mouse move ?
		BEQ	PLDWN20		;	NO -> PLDWN20
		BMI	PLDWN10
		INC	MOUSWK0
		BRA	PLDWN105
PLDWN10		EQU	$
		DEC	MOUSWK0
;
PLDWN105	EQU	$
		LDA	MOUSWK0	       ; mouse up move ?
		BMI	PLDWN15		;	YES -> PLDWN15
		CMP	#004H
		BCC	PLDWN20
		STZ	MOUSWK0
		INC	PLDWMNFG
		LDA	PLDWMNFG
		CMP	#006H
		BCC	PLDWN20
		STZ	PLDWMNFG
		BRA	PLDWN20
PLDWN15		EQU	$
		CMP	#0FCH
		BCS	PLDWN20
		STZ	MOUSWK0
		DEC	PLDWMNFG
		BPL	PLDWN20
		LDA	#005H
		STA	PLDWMNFG
;
PLDWN20		EQU	$
		LDA	#000H
		XBA
		LDA	PLDWMNFG
		TAX
		LDA	PLDWDT,X
		TAX
		LDA	#03AH
		STA	!OAM+100H+03H,X
		STA	!OAM+100H+07H,X
		STA	!OAM+100H+0BH,X
		STA	!OAM+100H+0FH,X
		STA	!OAM+100H+13H,X
		STA	!OAM+100H+17H,X
;
		I8			; index 8bit mode
		PLB
PLDWN99		EQU	$
		LDA	!ENMSLMD
		BEQ	PLDWN99_99
		STZ	<WORK0
		LDA	#00000010B
		STA	!WIND24
		MI16			; memory , index 16bit mode
		LDA	!EN_SCH3
		STA	<SCCH3
		LDA	!EN_SCV3
		STA	<SCCV3
		STZ	!ENMSLMD
		LDA	#BANK 14A000H
		STA	<WORK1
		LDY	#03400H
		LDA	#00800H
		LDX	#14A000H
		JSL	>VRAMDX_ST
		MI8			; memory , index 8bit mode
;
PLDWN99_99	EQU	$
		RTL
;
;
PLDWDT		EQU	$
		BYTE	PLDWDT0-PLDWDT0 ; 0
		BYTE	PLDWDT1-PLDWDT0 ; 1
		BYTE	PLDWDT2-PLDWDT0 ; 2
		BYTE	PLDWDT3-PLDWDT0 ; 3
		BYTE	PLDWDT4-PLDWDT0 ; 4
		BYTE	PLDWDT5-PLDWDT0 ; 5
;
PLDWDT0		EQU	$
		BYTE	0C8H,010H,C_E,032H	; E
		BYTE	0D0H,010H,C_D,032H	; D
		BYTE	0D8H,010H,C_I,032H	; I
		BYTE	0E0H,010H,C_T,032H	; T
		BYTE	0D8H,010H,C_I,032H	;
		BYTE	0E0H,010H,C_T,032H	;
;
PLDWDT1		EQU	$
		BYTE	0C8H,018H,C_U,032H	; U
		BYTE	0D0H,018H,C_N,032H	; N
		BYTE	0D8H,018H,C_D,032H	; D
		BYTE	0E0H,018H,C_O,032H	; O
		BYTE	0D8H,018H,C_D,032H	;
		BYTE	0E0H,018H,C_O,032H	;
;
PLDWDT2		EQU	$
		BYTE	0C8H,020H,C_M,032H	; M
		BYTE	0D0H,020H,C_O,032H	; O
		BYTE	0D8H,020H,C_V,032H	; V
		BYTE	0E0H,020H,C_E,032H	; E
		BYTE	0D8H,020H,C_V,032H	;
		BYTE	0E0H,020H,C_E,032H	;
;
PLDWDT3		EQU	$
		BYTE	0C8H,028H,C_D,032H	; D
		BYTE	0D0H,028H,C_E,032H	; E
		BYTE	0D8H,028H,C_L,032H	; L
		BYTE	0E0H,028H,C_E,032H	; E
		BYTE	0E8H,028H,C_T,032H	; T
		BYTE	0F0H,028H,C_E,032H	; E
;
PLDWDT4		EQU	$
		BYTE	0C8H,030H,C_R,032H	; R
		BYTE	0D0H,030H,C_E,032H	; E
		BYTE	0D8H,030H,C_N,032H	; N
		BYTE	0E0H,030H,C_A,032H	; A
		BYTE	0E8H,030H,C_M,032H	; M
		BYTE	0F0H,030H,C_E,032H	; E
;
PLDWDT5		EQU	$
		BYTE	0C8H,038H,C_S,032H	; S
		BYTE	0D0H,038H,C_E,032H	; E
		BYTE	0D8H,038H,C_A,032H	; A
		BYTE	0E0H,038H,C_R,032H	; R
		BYTE	0E8H,038H,C_C,032H	; C
		BYTE	0F0H,038H,C_H,032H	; H
;
PLDWDTE		EQU	$
;
;
;****************************************************************
;*								*
;*		敵セレクト イニシャル セット			*
;*								*
;****************************************************************
ENAME_SLCT_INT	EQU	$
		LDA	#BANK ENMDSPBUF
		STA	<WORK12
		MI16			; memory , index 16bit mode
		LDA	>ENNAMCT_SB
		BEQ	ENM_SLCT_INT_50
		INC	A
		STA	<WORK0
		LDA	<SCCH3
		STA	!EN_SCH3
		STZ	<SCCH3
		LDA	<SCCV3
		STA	!EN_SCV3
		STZ	<SCCV3
		LDA	#ENMDSPBUF
		CLC
		ADC	#00008H
		STA	<WORK10
;
		STZ	!EN_DP_XCT
		STZ	!EN_DP_YCT
		STZ	!ENDSP_PG
;
		M8			; memory 8bit mode
		LDX	#00000H
ENM_SLCT_INT_20	EQU	$
		LDY	#00000H
ENM_SLCT_INT_25	EQU	$
		DEC	<WORK0
		BNE	ENM_SLCT_INT_26
		LDA	<WORK0+1
		BEQ	ENM_SLCT_INT_50
		DEC	<WORK0+1
ENM_SLCT_INT_26	EQU	$
		LDA	>ENNAMBF,X
		STA	[<WORK10],Y
		INX
		INY
		INY
		LDA	>ENNAMBF,X
		STA	[<WORK10],Y
		INX
		INY
		INY
		LDA	>ENNAMBF,X
		STA	[<WORK10],Y
		INX
		INY
		INY
		LDA	>ENNAMBF,X
		STA	[<WORK10],Y
		INX
		INY
		INY
		LDA	>ENNAMBF,X
		STA	[<WORK10],Y
		INX
		INY
		INY
		INY
		INY
		CPY	#00004H*2*5
		BCC	ENM_SLCT_INT_25
		M16			; memory 16bit mode
		LDA	<WORK10
		CLC
		ADC	#00040H
		STA	<WORK10
		M8			; memory 8bit mode
		BRA	ENM_SLCT_INT_20
;
ENM_SLCT_INT_50	EQU	$
		M16			; memory 16bit mode
		LDX	#00000H
		LDA	!ENEMYNO
ENM_SLCT_INT_60	EQU	$
		CMP	>ENM_SLCT_PAGE+2,X
		BCC	ENM_SLCT_INT_70
		INX
		INX
		CPX	#ENM_SLCT_BUF-ENM_SLCT_PAGE
		BCC	ENM_SLCT_INT_60
;
ENM_SLCT_INT_70	EQU	$
		STX	!ENDSP_PG
		LDA	#BANK ENMDSPBUF
		STA	<WORK1
		LDA	>ENM_SLCT_BUF,X
		TAX
		LDY	#03440H
		LDA	#00700H
		JSL	>VRAMDX_ST
		MI8			; memory , index 8bit mode
		INC	!WIND24
		INC	!ENMSLMD
		INC	!ENMSLMD
		RTS
;
;
;****************************************************************
;*								*
;*		敵セレクト					*
;*								*
;****************************************************************
ENM_SLCT_INC_X	EQU	$
		WORD	00001H,0FFFFH
;
ENM_SLCT_INC_Y	EQU	$
		WORD	00004H,0FFFCH
;
ENM_SLCT_PAGE	EQU	$
		WORD	00060H*0,00060H*1,00060H*2,00060H*3
		WORD	00060H*4,00060H*5,00060H*6,00060H*7
;
ENM_SLCT_BUF	EQU	$
		WORD	ENMDSPBUF+(((020H*4)*6)*2)*0
		WORD	ENMDSPBUF+(((020H*4)*6)*2)*1
		WORD	ENMDSPBUF+(((020H*4)*6)*2)*2
		WORD	ENMDSPBUF+(((020H*4)*6)*2)*3
		WORD	ENMDSPBUF+(((020H*4)*6)*2)*4
		WORD	ENMDSPBUF+(((020H*4)*6)*2)*5
		WORD	ENMDSPBUF+(((020H*4)*6)*2)*6
		WORD	ENMDSPBUF+(((020H*4)*6)*2)*7
;
;
ENAME_SELECT	EQU	$
		PHB
		PHK
		PLB
		M16			; memory 16bit mode
		LDX	#000H
		LDY	!MOUSEBX
		BEQ	ENM_SLCT_200
		BPL	ENM_SLCT_150
		INX
		INX
ENM_SLCT_150	EQU	$
		INC	!EN_DP_XCT
		LDA	!EN_DP_XCT
		AND	#00007
		STA	!EN_DP_XCT
		BNE	ENM_SLCT_200
		LDA	!ENEMYNO
		CLC
		ADC	ENM_SLCT_INC_X,X
		BMI	ENM_SLCT_200
		CMP	>ENNAMCT_SB
		BCS	ENM_SLCT_200
		STA	!ENEMYNO
;
ENM_SLCT_200	EQU	$
		LDX	#000H
		LDY	!MOUSEBY
		BEQ	ENM_SLCT_400
		BPL	ENM_SLCT_250
		INX
		INX
ENM_SLCT_250	EQU	$
		INC	!EN_DP_YCT
		LDA	!EN_DP_YCT
		AND	#00003
		STA	!EN_DP_YCT
		BNE	ENM_SLCT_400
		LDA	!ENEMYNO
		CLC
		ADC	ENM_SLCT_INC_Y,X
		BMI	ENM_SLCT_400
		CMP	>ENNAMCT_SB
		BCS	ENM_SLCT_400
		STA	!ENEMYNO
;
;
ENM_SLCT_400	EQU	$
		LDX	#000H
		LDA	!ENEMYNO
ENM_SLCT_420	EQU	$
		CMP	ENM_SLCT_PAGE+2,X
		BCC	ENM_SLCT_500
		INX
		INX
		CPX	#ENM_SLCT_BUF-ENM_SLCT_PAGE
		BCC	ENM_SLCT_420
;
ENM_SLCT_500	EQU	$
		STX	!ENDSP_PG
		LDA	#BANK ENMDSPBUF
		STA	<WORK1
		LDA	ENM_SLCT_BUF,X
		I16			; index 16bit mode
		TAX
		LDY	#03440H
		LDA	#00700H
		JSL	>VRAMDX_ST
		I8			; index 8bit mode
;
		LDX	!ENDSP_PG
		LDA	!ENEMYNO
		SEC
		SBC	ENM_SLCT_PAGE,X
		STA	<WORK10
;
		LDA	<WORK10
		AND	#00003
		STA	<WORK0
		ASL	A
;;;;K;;;;		CLC
		ADC	<WORK0
		ASL	A
		ASL	A
		ASL	A
		ASL	A
		STA	<WORK0
		LDA	<WORK10
		AND	#0FFFCH
		ASL	A
		STA	<WORK1
;
		LDA	#00A1CH
		CLC
		ADC	<WORK0
		STA	!OAM+000H
		CLC
		ADC	#00010H
		STA	!OAM+004H
		CLC
		ADC	#00010H
		STA	!OAM+008H
		LDA	#03011H
		STA	!OAM+002H
		LDA	#03013H
		STA	!OAM+006H
		LDA	#03015H
		STA	!OAM+00AH
		M8			; memory 8bit mode
		LDA	#02AH
		STA	!OAMSUB
		PLB
		RTS
;
;
;****************************************************************
;*								*
;*	edit mode						*
;*								*
;****************************************************************
ENEDT		EQU	$
		LDA	MOUSEBT
		AND	#01000000B	; mouse left ON ?
		BNE	ENEDT00		;	YES -> ENEDT00
		JMP	ENEDT99		;	NO  -> ENEDT99
ENEDT00		EQU	$
		LDA	!ENDTPT
		CMP	#0FFH
		BEQ	ENEDT99
;
		JSR	ENBFAD		; enmy buffer address set
;
		LDA	[<WORK0]	; buffer inc.
		INC	A		;
		STA	[<WORK0]	;
;
		MI16			; memory , index 16bit mode
		JSR	ENNOIDX		; enmy NO. set index
		LDA	!ENEMYNO	 ;
		AND	#001FFH		; ENEMYNO * 5 --> X
		STA	<WORK0		;
		ASL	A		;
		ASL	A		;
		ADC	<WORK0		;
		TAY			;
;
		M8			; memory 8bit mode
		PHB			; bank <- 7e
		LDA	#BANK ENNAMBF	;
		PHA			;
		PLB			;
		M16			; memory 16bit mode
;
		LDA	!ENNAMBF,Y	; enmy name set
		STA	!ENDTBF,X	;
		LDA	!ENNAMBF+2,Y	;
		STA	!ENDTBF+2,X	;
		LDA	!ENNAMBF+3,Y	;
		STA	!ENDTBF+3,X	;
;
		PLB
;
		LDA	CRYPSL1	       ; address set
		AND	#007F0H		;
		LSR	A		;
		LSR	A		;
		LSR	A		;
		STA	<WORK0		;
		LDA	CRXPSL1	       ;
		AND	#00FF0H		;
		ASL	A		;
		ASL	A		;
		ASL	A		;
		ASL	A		;
		ORA	<WORK0		;
		STA	>ENDTBF+5,X	;
		MI8			; memory , index 8bit mode
;
		M16			; memory 16bit mode
		LDA	#02480H
		STA	<WORK0
		JSR	ENVMST
		M8			; memory 8bit mode
;
		STZ	VRFLG
;
		MI16			; memory , index 16bit mode
		INC	!ENDTPT
;
		JSR	ENNOIDX		; enmy NO. set index
		LDA	#0FFFFH
		STA	>ENDTBF,X
		MI8			; memory , index 16bit mode
;
ENEDT99		EQU	$
		RTS
;
;;;;K;;;;;
;;;;K;;;;		MI16			; memory , index 16bit mode
;;;;K;;;;		JSR	ENNOIDX		; enmy NO. set index
;;;;K;;;;		LDA	CRYPSL1	       ;
;;;;K;;;;		AND	#007F0H		; 00000000 00000000 00000000 B
;;;;K;;;;		LSR	A		; |------| |-----||--------|
;;;;K;;;;		LSR	A		;    |	      |	  enmy unit NO
;;;;K;;;;		LSR	A		;    |	    Y point
;;;;K;;;;		XBA			;  X point
;;;;K;;;;		ORA	!ENEMYNO	 ;
;;;;K;;;;		STA	>ENDTBF,X	;
;;;;K;;;;		LDA	CRXPSL1	       ;
;;;;K;;;;		LSR	A		;
;;;;K;;;;		LSR	A		;
;;;;K;;;;		LSR	A		;
;;;;K;;;;		LSR	A		;
;;;;K;;;;		M8			; memory 8bit mode
;;;;K;;;;		STA	>ENDTBF+2,X	;
;;;;K;;;;		I8			; index 8bit mode
;;;;K;;;;;
;
;****************************************************************
;*								*
;*	undo mode						*
;*								*
;****************************************************************
ENUND		EQU	$
		LDA	!ALL_UDFG
		BEQ	ENUND_PAS
		PHB
		MI16			; memory , index 16bit mode
		LDA	>UNDO_ENDATA
		INC	A
		STA	<WORK0
		ASL	A
		ASL	A
		ASL	A
		CLC
		SBC	<WORK0
		LDX	#UNDO_ENDATA
		LDY	#ENMYDTBF
		MVN	#BANK UNDO_ENDATA,#BANK ENMYDTBF
		MI8			; memory , index 8bit mode
		PLB
		STZ	!ALL_UDFG
		LDA	#ITSB
		STA	MODENO
		BRA	ENUND_END
;
ENUND_PAS	EQU	$
		LDA	!ENUNDBF
		ASL	A
		TAX
		JSR	(RTNDAT,X)
ENUND_END	EQU	$
		RTS
;
RTNDAT		EQU	$
		WORD	UNDERR	; 0
		WORD	UNDERR	; 1
		WORD	UNDMOV	; 2
		WORD	UNDDEL	; 3
		WORD	UNDREN	; 4
;
;
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;+							+
;+	undo move					+
;+							+
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++
UNDMOV		EQU	$
		MI16			; memory , index 16bit mode
		LDX	!ENUNDBF+1
		LDA	>ENDTBF+5,X
		STA	<WORKA
		JSR	UNDBFAD		; enmy buffer data address
		M8			; memory 8bit mode
		LDA	[<WORK0]
		DEC	A
		STA	[<WORK0]
;
UNDMV00		EQU	$
		M16			; memory 16bit mode
		LDA	!ENUNDBF+8
		STA	<WORKA
		JSR	UNDBFAD		; enmy buffer data address
		MI8			; memory , index 8bit mode
		LDA	[<WORK0]
		INC	A
		STA	[<WORK0]
;
		M16			; memory 16bit mode
		LDA	!ENUNDBF+8
		AND	#000FEH
		ASL	A
		ASL	A
		ASL	A
		STA	CRYPSL1
		SEC
		SBC	#00040H
		BMI	UNDPOS0
		CMP	#00758H
		BCC	UNDPOS1
		LDA	#00760H
		BRA	UNDPOS1
UNDPOS0		EQU	$
		LDA	#00000H
UNDPOS1		EQU	$
		AND	#007F0H
		SEC
		SBC	#00008H
		STA	<SCCV1
		STA	<SCCV2
		STA	<SCCV3
;
		LDA	!ENUNDBF+8
		AND	#0FF00H
		LSR	A
		LSR	A
		LSR	A
		LSR	A
		STA	CRXPSL1
		SEC
		SBC	#00080H
		BMI	UNDPOS2
		CMP	#00F01H
		BCC	UNDPOS3
		LDA	#00F00H
		BRA	UNDPOS3
UNDPOS2		EQU	$
		LDA	#00000H
UNDPOS3		EQU	$
		AND	#00FF0H
		SEC
		SBC	#00008H
		STA	<SCCH1
		STA	<SCCH2
		STA	<SCCH3
;
		LDA	!ENDTPT
		STA	>ENMYDTBF
		M8			; memory 8bit mode
;
		JSR	UNDREN
		LDA	#ITSB
		STA	MODENO
		STZ	PLDWMNFG
		RTS
;
;
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;+							+
;+	undo delete					+
;+							+
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++
UNDDEL		EQU	$
		STZ	!ENUNDBF
		PHB
		MI16			; memory , index 16bit mode
		LDA	!ENDTPT
		AND	#000FFH
		STA	<WORK4
		ASL	A
		ASL	A
		ASL	A
		SEC
		SBC	<WORK4
		PHA
		SEC
		SBC	!ENUNDBF+1
		STA	<WORK4
		PLA
		CLC
		ADC	#ENDTBF
		STA	<WORK0
		CLC
		ADC	#00007H
		STA	<WORK2
;
		LDX	<WORK0
		LDY	<WORK2
		LDA	<WORK4
		MVP	#BANK ENDTBF,#BANK ENDTBF
		MI8			; memory , index 8bit mode
		PLB
;
		JMP	UNDMV00
;
;
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;+							+
;+	undo rename					+
;+							+
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++
UNDREN		EQU	$
		MI16			; memory , index 16bit mode
		LDX	!ENUNDBF+1
;
		LDA	>ENDTBF,X
		PHA
		LDA	!ENUNDBF+3
		STA	>ENDTBF,X
		PLA
		STA	!ENUNDBF+3
;
		LDA	>ENDTBF+2,X
		PHA
		LDA	!ENUNDBF+5
		STA	>ENDTBF+2,X
		PLA
		STA	!ENUNDBF+5
;
		LDA	>ENDTBF+4,X
		PHA
		LDA	!ENUNDBF+7
		STA	>ENDTBF+4,X
		PLA
		STA	!ENUNDBF+7
;
		M8			; memory 8bit mode
		LDA	>ENDTBF+6,X
		PHA
		LDA	!ENUNDBF+9
		STA	>ENDTBF+6,X
		PLA
		STA	!ENUNDBF+9
		I8			; index 8bit mode
		RTS
;
;
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;+							+
;+	undo error					+
;+							+
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++
UNDERR		EQU	$
		LDA	#03FH
		STA	ERRFLG
		LDA	#ERR0
		STA	MODENO
		STZ	PLDWMNFG
		RTS
;
		RTS
;
;
;++++++++++++++++++++++++++++++++++++++++++++++++
;+						+
;+	enmy buffer data address		+
;+						+
;++++++++++++++++++++++++++++++++++++++++++++++++
		MEM16
		IDX16
;
UNDBFAD		EQU	$
		STZ	<WORK1
		LDA	<WORKA
		XBA
		LSR	A
		AND	#07000H
		STA	<WORK0
		LDA	<WORKA
		AND	#0F000H
		LSR	A
		LSR	A
		LSR	A
		LSR	A
		ORA	<WORK0
		STA	<WORK0		; high set
		LDA	<WORKA
		AND	#0001EH
		ASL	A
		ASL	A
		ASL	A
		ORA	<WORK0
		STA	<WORK0
		LDA	<WORKA
		AND	#00F00H
		XBA
		ORA	<WORK0
		STA	<WORK0		; low set
		LDA	<WORK1
		ORA	#ENBGDTBF/100H
		STA	<WORK1
		RTS
;
		MEM8
		IDX8
;
;
;****************************************************************
;*								*
;*	move mode						*
;*								*
;****************************************************************
ENMOV		EQU	$
		LDA	MOUSEBB
		AND	#01000000B	; mouse left ON ?
		BEQ	ENMOVPS		;	NO -> ENMOVPS
		LDX	#002H
		JSR	MDOBJAD		;  mode obj cursol set
ENMOVPS		EQU	$
		LDA	ENDELFG
		ASL	A
		TAX
		JSR	(ENMOVMD,X)
		RTS
;
ENMOVMD		EQU	$
		WORD	MOV000,MOV100
;
;
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;+	move mode  (search)				+
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MOV000		EQU	$
		JSR	REN000
		LDA	ENDELFG
		BEQ	MOV090
;
		JSR	ENBFAD		; enmy buffer address set
		M16			; memory 16bit mode
		LDA	[<WORK0]	; buffer dec.
		DEC	A
		STA	[<WORK0]
		BNE	MOV030
;
		LDA	#00482H
		STA	<WORK0
		JSR	ENVMST		; enmy sinbol disp set
MOV030		EQU	$
		M8			; memory 8bit mode
;
MOV090		EQU	$
		RTS
;
;
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;+	move mode  (move)				+
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MOV100		EQU	$
		LDA	MOUSEBB
		AND	#01000000B	; mouse left ON ?
		BNE	MOV190		;	YES -> MOV190
		MI16			; memory , index 16bit mode
		JSR	ENDTBFAD	; enmy data buffer address set
;
		JSR	UNDBFST		; undo buffer data set
;
		LDX	!SRCPOS
		LDA	>ENDTBF+5,X
		AND	#001H
		ORA	<WORK0
		STA	>ENDTBF+5,X
		MI8			; memory , index 8bit mode
;
		JSR	ENBFAD		; enmy buffer address set
		M16			; memory 16bit mode
		LDA	[<WORK0]	; buffer dec.
		INC	A
		STA	[<WORK0]
;
		LDA	#02480H
		STA	<WORK0
		JSR	ENVMST		; enmy sinbol disp set
		M8			; memory 8bit mode
;
		STZ	ENDELFG
MOV190		EQU	$
		RTS
;
;
;****************************************************************
;*								*
;*	delete mode						*
;*								*
;****************************************************************
ENDEL		EQU	$
		LDA	MOUSEBB
		AND	#01000000B	; mouse left ON ?
		BEQ	ENDELPS		;	NO -> ENDELPS
		LDX	#004H
		JSR	MDOBJAD		;  mode obj cursol set
ENDELPS		EQU	$
		LDA	ENDELFG
		ASL	A
		TAX
		JSR	(ENDELMD,X)
		RTS
;
ENDELMD		EQU	$
		WORD	DEL000,DEL100
;
;
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;+	delete mode  (delete)				+
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++
DEL100		EQU	$
		LDA	MOUSEBB
		AND	#01000000B	; mouse left ON ?
		BEQ	DEL110		;	YES -> DEL110
		JMP	ENDEL99		;	NO  -> ENDEL99
DEL110		EQU	$
		MI16			; memory , index 16bit mode
		JSR	ENDTBFAD	; enmy data buffer address set
		LDX	!SRCPOS
		LDA	>ENDTBF+5,X
		AND	#0FFFEH
		CMP	<WORK0
		BEQ	ENDEL90
;
		JSR	KAERU		; mouse cursol move ram change
		PHP
		JSR	ENBFAD		; enmy buffer address set
		PLP
		LDA	[<WORK0]	; buffer dec.
		DEC	A		;
		STA	[<WORK0]	;
		AND	#000FFH
		BNE	ENDEL70
;
		I8			; index 8bit mode
		LDA	#00482H
		STA	<WORK0
		JSR	ENVMST		; enmy sinbol disp set
		I16			; index 16bit mode
;
ENDEL70		EQU	$
		PHB
		MI16			; memory ,index 16bit mode
;
		JSR	UNDBFST		; undo buffer data set
;
		LDA	!SRCPOS		; enmy data ma-e tu-me-ru
		CLC
		ADC	#ENDTBF
		STA	<WORKA
		CLC
		ADC	#00007H
		STA	<WORKC
		LDA	!ENDTPT
		ASL	A
		ASL	A
		ASL	A
		SEC
		SBC	!ENDTPT
		SEC
		SBC	!SRCPOS
		DEC	A
		STA	<WORKE
		I16			; index 16bit mode
		LDX	<WORKC
		LDY	<WORKA
		LDA	<WORKE
		MVN	#BANK ENDTBF,#BANK ENDTBF
		PLB
;
		JSR	KAERU		; mouse cursol move ram change
		STZ	!SRCPOS
		DEC	!ENDTPT
		LDA	!ENDTPT
		STA	>ENMYDTBF
		MI8			; memory , index 8bit mode
		STZ	VRFLG
;
ENDEL90		EQU	$
		MI8			; memory , index 8bit mode
		STZ	ENDELFG
;
ENDEL99		EQU	$
		RTS
;
;
;****************************************************************
;*								*
;*	rename mode						*
;*								*
;****************************************************************
ENREN		EQU	$
		LDA	ENDELFG
		ASL	A
		TAX
		JSR	(ENRENMD,X)
		RTS
;
ENRENMD		EQU	$
		WORD	REN000,REN100,REN200
;
;
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;+	rename mode  (search)				+
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++
REN000		EQU	$
DEL000		EQU	$
		LDA	MOUSEBT
		AND	#01000000B	; mouse left ON ?
		BEQ	REN090		;	NO -> REN090
		LDA	#001H
		STA	ENDELFG
		JSR	ENSRC		; enmy data buffer search
REN090		EQU	$
		RTS
;
;
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;+	rename mode  (move)				+
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++
REN100		EQU	$
		LDX	#006H
		JSR	MDOBJAD		;  mode obj cursol set
		LDA	MOUSEBB
		AND	#01000000B	; mouse left ON ?
		BNE	REN190		;	YES -> REN190
		MI16			; memory , index 16bit mode
		JSR	ENDTBFAD	; enmy data buffer address set
		LDX	!SRCPOS
		LDA	>ENDTBF+5,X
		AND	#0FFFEH
		CMP	<WORK0
		BNE	REN180
		MI8			; memory , index 8bit mode
		STZ	ENDELFG
		BRA	REN190
;
REN180		EQU	$
		MI8			; memory , index 8bit mode
		LDA	#002H
		STA	ENDELFG
;
REN190		EQU	$
		RTS
;
;
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;+	rename mode  (enmy NO. change)			+
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++
REN200		EQU	$
		LDA	#006H
		STA	ENMDOBJ
		LDA	MOUSEBT
		AND	#01000000B	; mouse left ON ?
		BEQ	REN290		;	NO -> REN290
		MI16			; memory , index 16bit mode
		JSR	ENDTBFAD	; enmy data buffer address set
		MI8			; memory , index 8bit mode
		LDA	CRXPSL1
		AND	#0F0H
		CMP	XTAIHI
		BNE	REN250
		LDA	CRYPSL1
		AND	#0F0H
		CMP	YTAIHI
		BNE	REN250
;
		MI16			; memory , index 16bit mode
		JSR	UNDBFST		; undo buffer data set
;
		LDX	!SRCPOS
		LDA	!ENNAM0		; enmy name change
		STA	>ENDTBF,X	;
		LDA	!ENNAM2		;
		STA	>ENDTBF+2,X	;
		LDA	!ENNAM3		;
		STA	>ENDTBF+3,X	;
		MI8			; memory , index 8bit mode
REN250		EQU	$
		STZ	ENDELFG
;
REN290		EQU	$
		RTS
;
;
;****************************************************************
;*								*
;*	search mode						*
;*								*
;****************************************************************
ENSRC		EQU	$
		LDA	#001H
		STA	ENDSPFG
		LDA	MOUSEBT
		AND	#01000000B	; mouse left ON ?
		BNE	ENSRC00		;	YES -> ENSRC00
		JMP	ENSRC99		;	NO  -> ENSRC99
ENSRC00		EQU	$
		M16			; memory 16bit mode
		LDA	CRXPSL1
		AND	#00FF0H
		CMP	CRXPSL2
		BNE	ENSRC20
		LDA	CRYPSL1
		AND	#00FF0H
		CMP	CRYPSL2
		BEQ	ENSRC25
ENSRC20		EQU	$
		LDA	#08000H
		STA	!SRCPOS
		LDA	#00000H
		STA	>ENMYDTBF
ENSRC25		EQU	$
		M8			; memory 8bit mode
		JSR	ENDTSRC		; enmy data buffer search
;
		M16			; memory 16bit mode
		LDA	CRXPSL1
		AND	#00FF0H
		STA	CRXPSL2
		LDA	CRYPSL1
		AND	#00FF0H
		STA	CRYPSL2
		M8			; memory 8bit mode
;
ENSRC99		EQU	$
		RTS
;
;
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;+							+
;+	undo buffer data set				+
;+							+
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		MEM16
		IDX16
;
UNDBFST		EQU	$
		LDX	!SRCPOS
		LDA	PLDWMNFG       ; mode set
		AND	#000FFH		;
		STA	!ENUNDBF	;
;
		LDA	!SRCPOS		; count set
		STA	!ENUNDBF+1	;
;
		LDA	>ENDTBF,X	; data set
		STA	!ENUNDBF+3	; data set
		LDA	>ENDTBF+2,X	;
		STA	!ENUNDBF+5	;
		LDA	>ENDTBF+4,X	;
		STA	!ENUNDBF+7	;
		LDA	>ENDTBF+5,X	;
		STA	!ENUNDBF+8	;
		RTS
;
		MEM8
		IDX8
;
;
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;+							+
;+	enmy data buffer address set			+
;+							+
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		MEM16
		IDX16
ENDTBFAD	EQU	$
		LDA	CRXPSL1
		AND	#00FF0H
		ASL	A
		ASL	A
		ASL	A
		ASL	A
		STA	<WORK0
		LDA	CRYPSL1
		AND	#007F0H
		LSR	A
		LSR	A
		LSR	A
		ORA	<WORK0
		STA	<WORK0
		RTS
;
		MEM8
		IDX8
;
;
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;+							+
;+	mouse cursol move ram change			+
;+							+
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		MEM16
		IDX16
KAERU		EQU	$
		LDA	CRXPSL1
		PHA
		LDA	CRXPSL2
		STA	CRXPSL1
		PLA
		STA	CRXPSL2
		LDA	CRYPSL1
		PHA
		LDA	CRYPSL2
		STA	CRYPSL1
		PLA
		STA	CRYPSL2
		RTS
		MEM8
		IDX8
;
;
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;+							+
;+	enmy sinbol disp set				+
;+				in			+
;+				  work 0,1 <- unit NO.	+
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		MEM16
ENVMST		EQU	$
		LDA	>VRAMD
		TAX
		LDA	CRXPSL1
		AND	#001F0H
		LSR	A
		LSR	A
		LSR	A
		LSR	A
		STA	<WORKA
		LDA	CRYPSL1
		AND	#001F0H
		ASL	A
		ORA	#03800H
		ORA	<WORKA
;
		STA	>VRAMD+2,X
		LDA	#00001H
		STA	>VRAMD+4,X
		LDA	<WORK0
		STA	>VRAMD+6,X
		LDA	#0FFFFH
		STA	>VRAMD+8,X
		TXA
		CLC
		ADC	#00006H
		STA	>VRAMD
		RTS
		MEM8
;
;
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;+							+
;+	enmy data buffer search				+
;+		     work 0,1 <- enmy data buffer point +
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ENDTSRC		EQU	$
		MI16			; memory , index 16bit mode
;
		LDA	>ENMYDTBF
		STA	<WORK6
		LDA	!SRCPOS
		BMI	SRC005
		INC	<WORK6
		CLC
		ADC	#00007H
SRC005		EQU	$
		AND	#07FFFH
		TAX
		JSR	ENDTBFAD	; enmy data buffer address set
;
SRC000		EQU	$
		LDA	>ENDTBF,X
		CMP	#0FFFFH
		BEQ	SRC995
		LDA	>ENDTBF+5,X
		AND	#0FFFEH
		CMP	<WORK0
		BEQ	SRC990
		INC	<WORK6
		TXA
		CLC
		ADC	#00007H
		TAX
		BRA	SRC000
;
SRC990		EQU	$
		LDA	<WORK6
		STA	>ENMYDTBF
		LDA	>ENDTBF,X
		STA	!ENNAM0
		LDA	>ENDTBF+2,X
		STA	!ENNAM2
		LDA	>ENDTBF+3,X
		STA	!ENNAM3
		STX	!SRCPOS
		JSR	ENMNO		; enmy name -> enmy NO.
		MI8			; memory , index 8bit mode
		BRA	SRC999
;
		MEM16
		IDX16
SRC995		EQU	$
		LDA	#00000H
		STA	>ENMYDTBF
		LDA	#08000H
		STA	!SRCPOS
		MI8			; memory , index 8bit mode
		STZ	ENDELFG
		STZ	ENDSPFG
		LDA	#03FH
		STA	ERRFLG
		LDA	#ERR0
		STA	MODENO
SRC999		EQU	$
		RTS
;
;
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;+							+
;+	enmy name -> enmy NO.				+
;+							+
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		IDX16
ENMNO		EQU	$
;;;;K;;;;		LDA	>ENNAMCT
		LDA	>ENNAMCT_SB
		STA	<WORK0
		ASL	A
		ASL	A
		CLC
		ADC	<WORK0
		STA	<WORK0
		STZ	<WORK4
		M8			; memory 8bit mode
;
		PHB			; bank <- 7e
		LDA	#BANK ENNAMBF	;
		PHA			;
		PLB			;
;
		LDY	#00000H
ENMNO00		EQU	$
		LDA	!ENDTBF,X
		CMP	!ENNAMBF,Y
		BNE	ENMNO50
		LDA	!ENDTBF+1,X
		CMP	!ENNAMBF+1,Y
		BNE	ENMNO50
		LDA	!ENDTBF+2,X
		CMP	!ENNAMBF+2,Y
		BNE	ENMNO50
		LDA	!ENDTBF+3,X
		CMP	!ENNAMBF+3,Y
		BNE	ENMNO50
		LDA	!ENDTBF+4,X
		CMP	!ENNAMBF+4,Y
		BEQ	ENMNO60
ENMNO50		EQU	$
		M16			; memory 16bit mode
		INC	<WORK4
		M8			; memory 8bit mode
		INY
		INY
		INY
		INY
		INY
		CPY	<WORK0
		BCC	ENMNO00
;
ENMNO60		EQU	$
		PLB
		M16			; memory 16bit mode
		LDA	<WORK4
		STA	>ENEMYNO
		RTS
		MEM8
		IDX8
;
;
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;+							+
;+	enmy NO. set index				+
;+				!ENDTPT*7 -> X		+
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		MEM16
		IDX16
;
ENNOIDX		EQU	$
		LDA	!ENDTPT
		ASL	A
		ASL	A
		ASL	A
		SEC
		SBC	!ENDTPT
		TAX
		RTS
;
		MEM8
		IDX8
;
;
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;+							+
;+	enmy buffer address set				+
;+							+
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ENBFAD		EQU	$
		M16			; memory 16bit mode
		STZ	<WORK0
		LDA	CRXPSL1
		AND	#00F00H
		XBA
		ORA	#ENBGDTBF/100H
		STA	<WORK1
		LDA	CRYPSL1
		AND	#00700H
		ASL	A
		ASL	A
		ASL	A
		ASL	A
		XBA
		ORA	<WORK1
		STA	<WORK1		; bank & high address set
		M8			; memory 8bit mode
;
		LDA	CRXPSL1
		AND	#0F0H
		LSR	A
		LSR	A
		LSR	A
		LSR	A
		STA	<WORK0
		LDA	CRYPSL1
		AND	#0F0H
		ORA	<WORK0
		STA	<WORK0		; low address set
		RTS
;
;
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;+							+
;+	mode obj cursol set				+
;+				X <- obj index		+
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MDOBJAD		EQU	$
		STX	ENMDOBJ
		LDA	CRXPSL1
		AND	#0F0H
		STA	XTAIHI
		LDA	CRYPSL1
		AND	#0F0H
		STA	YTAIHI
		RTS
;
;
;****************************************************************
;*								*
;*	mouse auto scroll mode (test)				*
;*								*
;****************************************************************
MSTEST		EQU	$
		JSL	>MSSCRMD
;
		LDA	!OAM+4		; X pos
		PHA
		SEC
		SBC	!OAM
		CLC
		ADC	!OAM+4
		STA	!OAM+4
		PLA
		STA	!OAM
;
		LDA	!OAM+5		; Y pos
		PHA
		SEC
		SBC	!OAM+1
		CLC
		ADC	!OAM+5
		STA	!OAM+5
		PLA
		STA	!OAM+1
;
		RTL
;
;
;SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
;S								S
;S	7byte data -> 3byte data 変換				S
;S								S
;SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
;
		MEM8
		IDX8
;
HNKNST		EQU	$
		PHB			;(DBR) save
		LDA	#BANK ENDTBF	;(DBR) <-- (PBR)
		PHA
		PLB
;
		MI16			; memory , index 16bit mode
		LDY	#00000H
		STZ	<WORKA
		LDA	!ENMYDTBF
		BEQ	HNKN90
		STA	<WORKC
HNKN00		EQU	$
		TYX
		JSR	ENMNO		; enmy name -> enmy NO.
		TXY
		LDX	<WORKA
		LDA	!ENDTBF+5,Y
		STA	!M_ENDTBF+1,X
		LDA	!ENDTBF+4,Y
		AND	#0FE00H
		ORA	>ENEMYNO
		STA	!M_ENDTBF,X
		INC	<WORKA
		INC	<WORKA
		INC	<WORKA
		INY
		INY
		INY
		INY
		INY
		INY
		INY
		DEC	<WORKC
		BNE	HNKN00
HNKN90		EQU	$
		LDX	<WORKA
		LDA	#0FFFFH
		STA	!M_ENDTBF,X
		MI8			; memory , index 8bit mode
;
		PLB
		RTL
;
;
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
;X								X
;X	敵 データ オールクリア					X
;X								X
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ENALLCLS	EQU	$
		PHB
		LDA	#BANK ENALLCLS
		PHA
		PLB
		MI16			; memoey , index 16bit mode
		LDX	#00000H
ENALLCLS_000	EQU	$
		LDA	ENALLCLS_DAT,X
		STA	!OAM+100H,X
		INX
		INX
		CPX	#ENALLCLS_DATA-ENALLCLS_DAT
		BNE	ENALLCLS_000
		MI8			; memoey , index 8bit mode
		LDA	!INKEY
		CMP	#L_Y
		BEQ	ENALLCLS_100
		CMP	#L_N
		BEQ	ENALLCLS_500
		BRA	ENALLCLS_900
ENALLCLS_100	EQU	$
		M16			; memoey 16bit mode
		LDA	#00000H
		STA	>ENMYDTBF
		STA	!ENDTPT
		DEC	A
		STA	>ENDTBF
		M8			; memoey 8bit mode
		JSL	>ENBFCLS
		STZ	!MODENO
		BRA	ENALLCLS_900
ENALLCLS_500	EQU	$
		LDA	#PLMD
		STA	!MODENO
;
ENALLCLS_900	EQU	$
		PLB
		RTL
;
ENALLCLS_DAT	EQU	$
		BYTE	030H,0B0H,C_E,03CH	; E
		BYTE	038H,0B0H,C_N,03CH	; N
		BYTE	040H,0B0H,C_M,03CH	; M
		BYTE	048H,0B0H,C_Y,03CH	; Y
;
		BYTE	058H,0B0H,C_D,03CH	; D
		BYTE	060H,0B0H,C_A,03CH	; A
		BYTE	068H,0B0H,C_D,03CH	; D
		BYTE	070H,0B0H,C_A,03CH	; A
;
		BYTE	060H,0B9H,C_A,03CH	; A
		BYTE	068H,0B9H,C_L,03CH	; L
		BYTE	070H,0B9H,C_L,03CH	; L
;
		BYTE	080H,0B9H,C_C,03CH	; C
		BYTE	088H,0B9H,C_L,03CH	; L
		BYTE	090H,0B9H,C_E,03CH	; E
		BYTE	098H,0B9H,C_A,03CH	; A
		BYTE	0A0H,0B9H,C_R,03CH	; R
		BYTE	0A8H,0B9H,03FH,03CH	; ?
;
		BYTE	0C0H,0B9H,C_Y,03CH	; Y
		BYTE	0C8H,0B9H,02FH,03CH	; /
		BYTE	0D0H,0B9H,C_N,03CH	; N
ENALLCLS_DATA	EQU	$
;
;
;****************************************************************
;*								*
;*		ＢＧデータ 移動モード				*
;*								*
;****************************************************************
BGDTMOVE_ADR	EQU	$
		WORD	BDMV_SRCH	;データ サーチ
		WORD	BDMV_MOVE	;サーチした データの移動
		WORD	BDMV_SET	;移動したデータの セット
;
;
BGDTMOVE	EQU	$
		LDA	!MOUSEBT
		AND	#10000000B	;マウス右クリック ?
		BNE	BGDTMOVE_STOP	;	YES -> BGDTMOVE_STOP
		LDA	!INKEY
		CMP	#F_4		;[F4] ON ?
		BNE	BGDTMOVE_GO
BGDTMOVE_STOP	EQU	$
		LDA	#PLMD
		STA	!MODENO
		STZ	!PLDWMNFG
		STZ	!SRCPOS
		JMP	BGDTMOVE_END
;
BGDTMOVE_GO	EQU	$
		STZ	!ENMDOBJ
		PHB
		PHK
		PLB
		LDX	!PLDWMNFG
		JSR	(BGDTMOVE_ADR,X)
		PLB
;
		JSL	>ENBGMV		; BG. move
		JSR	MSMVST		; mouse cursol move
		JSR	ENDTSCR		; enmy edit data screen set
		JSR	BMMDISPST
		JSL	>BGSET		; BG. set
;
BGDTMOVE_END	EQU	$
		RTL
;
;
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;+		データ サーチ				+
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++
BDMV_SRCH_DT	EQU	$
		BYTE	004,004,005
;
;
BDMV_SRCH	EQU	$
		LDA	!MOUSEBT
		AND	#01000000B	;mouse left ON ?
		BNE	BDMV_SRCH_100
		JMP	BDMV_SRCH_900
BDMV_SRCH_100	EQU	$
		JSR	BDMV_SUB
;
		M16			; memory 16bit mode
		LDA	#DTBUFF
		STA	<WORKD
		INC	A
		STA	<WORKA
		LDX	#BANK DTBUFF
		STX	<WORKF
		STX	<WORKC
		M8			; memory 8bit mode
;
BDMV_SRCH_200	EQU	$
		M16			; memory 16bit mode
		LDA	[<WORKA]
		CMP	<WORK0
		BEQ	BDMV_SRCH_300
		M8			; memory 8bit mode
		LDA	[<WORKD]
		CMP	#0FFH		;データ おわり ?
		BNE	BDMV_SRCH_250	;	NO -> BDMV_SRCH_250
		LDA	#ERCT
		STA	!ERRFLG		;エラー !!
		BRA	BDMV_SRCH_900
BDMV_SRCH_250	EQU	$
		TAX
		BEQ	BDMV_SRCH_260
		LDA	>KAHNSB,X
		AND	#00FH
		TAX
BDMV_SRCH_260	EQU	$
		M16			; memory 16bit mode
		LDA	BDMV_SRCH_DT,X
		AND	#000FFH
		PHA
		CLC
		ADC	<WORKA
		STA	<WORKA
		PLA
		CLC
		ADC	<WORKD
		STA	<WORKD
		M8			; memory 8bit mode
		BRA	BDMV_SRCH_200
;
		MEM16
BDMV_SRCH_300	EQU	$
		LDA	<WORKA
		STA	!SRCPOS
		M8			; memory 8bit mode
BDMV_SRCH_800	EQU	$
		INC	!PLDWMNFG
		INC	!PLDWMNFG
;
BDMV_SRCH_900	EQU	$
		RTS
;
;
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;+		サーチした データの移動			+
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++
BDMV_MOVE	EQU	$
		LDA	!MOUSEBB
		AND	#01000000B	; mouse left ON ?
		BEQ	BDMV_SRCH_800
		LDA	#002
		JSR	MDOBJAD		;mode obj cursol set
		RTS
;
;
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;+		移動したデータの セット			+
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++
BDMV_SET	EQU	$
		JSR	BDMV_SUB
		LDA	#BANK DTBUFF
		STA	<WORKF
		M16			; memory 16bit mode
		LDA	!SRCPOS
		STA	<WORKD
;
		LDA	[<WORKD]
		CMP	<WORK0
		BNE	BDMV_SET_200
		M8			; memory 8bit mode
		BRA	BDMV_SET_300
;
		MEM16
BDMV_SET_200	EQU	$
		LDA	<WORK0
		STA	[<WORKD]
		LDA	!ENDTPT
		STA	>ENMYDTBF
		M8			; memory 8bit mode
		LDA	#ITSB
		STA	!MODENO
BDMV_SET_300	EQU	$
		STZ	!PLDWMNFG
		STZ	!SRCPOS
		RTS
;
;
;++++++++++++++++++++++++++++++++++++++++++++++++
;+	カーソル位置 →	データ アドレス		+
;+			out			+
;+			work0,1 ← アドレス	+
;++++++++++++++++++++++++++++++++++++++++++++++++
BDMV_SUB	EQU	$
		LDA	!CRYPSL1+1
		AND	#00FH
		ASL	A
		ASL	A
		ASL	A
		ASL	A
		STA	<WORK0
		LDA	!CRXPSL1+1
		AND	#00FH
		ORA	<WORK0
		STA	<WORK0
		LDA	!CRXPSL1
		AND	#0F0H
		LSR	A
		LSR	A
		LSR	A
		LSR	A
		STA	<WORK1
		LDA	!CRYPSL1
		AND	#0F0H
		ORA	<WORK1
		STA	<WORK1
		RTS
;
;
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;+							+
;+	"ＢＧ ＭＯＶＥ ＭＯＤＥ" 画面表示		+
;+							+
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;
ERCT	EQU	70H		;エラー カウント数
;
BMMDISPST_DT0	EQU	$
		BYTE	0C8H,018H,C_B,032H
		BYTE	0D0H,018H,C_G,032H
;
		BYTE	0D0H,020H,C_M,032H
		BYTE	0D8H,020H,C_O,032H
		BYTE	0E0H,020H,C_V,032H
		BYTE	0E8H,020H,C_E,032H
;
		BYTE	0D8H,028H,C_M,032H
		BYTE	0E0H,028H,C_O,032H
		BYTE	0E8H,028H,C_D,032H
		BYTE	0F0H,028H,C_E,032H
;
BMMDISPST_DT1	EQU	$
		BYTE	0C8H,020H,C_E,03AH
		BYTE	0D0H,020H,C_R,03AH
		BYTE	0D8H,020H,C_R,03AH
		BYTE	0E0H,020H,C_O,03AH
		BYTE	0E8H,020H,C_R,03AH
;
;
BMMDISPST	EQU	$
		PHB
		PHK
		PLB
		M16			; memory 16bit mode
		LDX	#000H
		LDA	#0F000H
BMMDISPST_CLS	EQU	$
		STA	!OAM+1D0H,X
		STZ	!OAM+1D2H,X
		INX
		INX
		INX
		INX
		CPX	#030H
		BCC	BMMDISPST_CLS
;
		LDX	#000H
		LDA	!ERRFLG
		BEQ	BMMDISPST_200
		AND	#00008
		BEQ	BMMDISPST_150
BMMDISPST_100	EQU	$
		LDA	BMMDISPST_DT1,X
		STA	!OAM+01D0H,X
		INX
		INX
		CPX	#BMMDISPST-BMMDISPST_DT1
		BCC	BMMDISPST_100
BMMDISPST_150	EQU	$
		DEC	!ERRFLG
		BRA	BMMDISPST_300
;
BMMDISPST_200	EQU	$
		LDA	BMMDISPST_DT0,X
		STA	!OAM+1D0H,X
		INX
		INX
		CPX	#BMMDISPST_DT1-BMMDISPST_DT0
		BCC	BMMDISPST_200
;
BMMDISPST_300	EQU	$
		M8			; memory 8bit mode
;
		PLB
		RTS
;
;
;
;
;
		MEM8
		IDX8
;
;
		END
