;
;		INCLUDE hp_mr3ram.asm
		INCLUDE mn_hp_mr3ram.asm
;
;<MR3MAIN>===========================================================
;
	 EXT	  JSRSUB,KEYCNG
;
;========BG Unit No.=================================================
	 EXT	BLOK0,YKDK2,BLK3D3,HASGO,GCIND3
;========MR3PLAY2====================================================
	 GLB	BATTLE_GAME
;
;<MR3MAN1>==========================================================
	 EXT	PCHCST
;<MR3DATA0>==========================================================
;--------------------------------------------------- battle new unit read data
	EXT	BBGCKDT
; ----------------------------------------------------------------------UPCHEK
	EXT	WHATUP,WHATSD,WHATMD,UPCKD0,UPDCDL,UPDCDR,UPDOMD
; ----------------------------------------------------------------------SCDISP
	EXT	SCDVDT,SCDLA,ITOMXD,ITOMCD
; ---------------------------------------------------------Mario 3 Bonus stage
	EXT	CLCOXD,CLCOYD,BCOXPD,BCOYPD
; -------------------------------------------------------------Item check sub.
	EXT	ITITYD,BPLITX,BPLITM,BPLWKT,PLSBXD,PLSBGD,PLINYS
; -----------------------------------------------------------Bonus player Fail
	EXT	BBCKXD,BBCKYD,BBCKBD,BBCKB2
; ---------------------------------------------------------------Cion BG clear
	EXT	BPLCDT
; ----------------------------------------------------------Bonus player C set
	EXT	BPLATD
; --------------------------------------------------------------Mario vs Luigi
	EXT	MLCRSD,MLCJPD,MLCSTD,MLCSDD
; ---------------------------------------------------------Bonus enemy initail
	EXT	BENIXD,BENIXS,BFIIXD,BFIIXS
; -----------------------------------------------------------------Bonus enemy
	EXT	BEOMAD
; -------------------------------------------------------------------Coin move
	EXT	COCDT,COCHMD					; Bunus coin
	EXT	BTENXB,BTENXD,ENDKXS				; End point
; ---------------------------------------------------------Enemy character set
	EXT	BENATD,BENCAD,BENCHM,ENCD00,BENCD0,BTOGD0,BTOGD2
	EXT	BKAND0,BFIRD0,BHAED0,BCOIND,BMUSHD,BFLWRD,BSTARD
	EXT	BBLCCD,BSTRCD,BBALCD,BFIFLD,BPLKSD,BTELD0
	EXT	BENCDPL,BALCDPL
; ----------------------------------------------------------------Enemy move 1
	EXT	XRVSDT,ENNXSD
; -------------------------------------------------------------------Bonus POW
	EXT	BPSVDT,BPWCDT,BPWYAD
; ----------------------------------------------------------------------Fire 3
	EXT	BFIYSD,BFIYLM,BFIENX
; --------------------------------------------------------------------
	GLB	TG,HE,KN
;
;========================================================================
		EXT	B_PCHCST,BRANDM
		EXT	jtcr000,jtcr001,jtcr002,jtcr003,jtcr004,jtcr005,jtcr005
		EXT	jtcr006,jtcr007,jtcr008,jtcr009,jtcr00A
		EXT	jtcr010,jtcr011,jtcr012,jtcr013,jtcr014,jtcr015,jtcr015
		EXT	jtcr016,jtcr017,jtcr018
;========================================================================
;
;
;*************************************************************************:
;	  EXT	 ITMNO
;*************************************************************************:
;-----------------------------------------------------------------------
;	 OAM map
;
;
;	1000---100F : Flash
;	1010---101F :	"
;	1020---102F : POW
;	1040---104F : Player1
;	1050---105F : Player2
;	1060---107F : 1UP
;	10A0---10FF : Item Panel
;	1100---11DF : Enemy & Block
;
	 ORG	  023E000H
		EXTEND
		IDX8
		MEM8
;
ALCNT	 EQU	0CH	     ; All obj move count
ENCNT	 EQU	05H	     ; Enemy set count
;
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;%	 UPCHEK					   %
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;---------------------------------------
UPCHEK	 EQU	$
	 JSR	UPDISP
;==========================================
	 LDX	#00H
	 LDY	#00H
	 JSR	UPCK00
;
	 LDX	#ITMNO
	 LDY	#01H
UPCK00	 EQU	$
	 STY	<WORK0	      ; 0 or 1	(For PLAYCT)
	 STX	<WORK1	      ; 0 or #ITMNO (For GMITEM)
;
	 LDA	!GMITEM+0,X
	 BEQ	UPCKRT
	 LDA	!GMITEM+1,X
	 BEQ	UPCKRT
	 LDA	!GMITEM+2,X
	 BNE	UPCK10
UPCKRT	 EQU	$
	 RTS
;--------------------------------------
;;k;;UPCKD0   EQU    $
;;k;;	      BIN    00000000
;;k;;	      BIN    00000001
;;k;;	      BIN    00000010
;;k;;	      BIN    00000100
;
UPCK10	 EQU	$
;
	 LDY	!GMITEM+0,X
	 LDA	UPCKD0,Y
	 LDY	!GMITEM+1,X
	 ORA	UPCKD0,Y
	 LDY	!GMITEM+2,X
	 ORA	UPCKD0,Y
	 TAY
;
	 LDX	<WORK0	      ; Which player .
;;;;;;;;	 LDA	04F2H
;;;;;;;;	 ORA	WHATSD,Y
;;;;;;;;	 STA	04F2H	     ; ? Sound (S)
	 ORA	WHATSD,Y
		STA	!SOUND3
;
	 LDA	WHATMD,Y
	 STA	SCTIME1,X     ; ? OBJ set
;
	 LDA	BPLXPS,X
	 STA	SCXPOS,X
;
	 LDA	BPLYPS,X
	 SEC
	 SBC	#08H
	 STA	SCYPOS,X
;
	 LDA	WHATUP,Y
	 PHA
	 STA	SCMODE1,X
	 CLC
	 ADC	!PLAYCT,X
	 STA	!PLAYCT,X    ; ? UP
	 PLA
	 BEQ	UPCK80	     ; Atari ?
;
	 LDX	<WORK1	      ; Yes ! RAM clear !!
	 LDA	#00H
	 STA	!GMITEM+0,X
	 STA	!GMITEM+1,X
	 STA	!GMITEM+2,X
UPCK80	 EQU	$
	 RTS
;======================================
UPDISP	 EQU	$
	 LDX	#01H
UPD000	 EQU	$
	 STX	<WORK0
	 JSR	UPD100
	 DEX
	 BPL	UPD000
	 RTS
;
UPD100	 EQU	$
	 LDA	SCTIME1,X
	 BEQ	UPDRTS
	 CMP	#20H
	 BCC	UPD110
;
	 LDA	#00H
	 STA	SCTIME1,X
UPDRTS	 EQU	$
	 RTS
;
UPD110	 EQU	$
	 LDA	BPSFLG
	 BNE	UPD120	; Pause ?
;
	 LDA	<FRCNT	 ; No.
	 LSR	A
	 BCC	UPD120
;
	 INC	!SCTIME1,X
;
UPD120	 EQU	$
  ;
	 LDY	UPDOMD,X
	 LDA	SCYPOS,X
	 SEC
	 SBC	SCTIME1,X
	 STA	!OAM+01,Y
;
	 LDA	SCXPOS,X
	 STA	!OAM+00,Y
;
	 LDA	#022H
	 STA	!OAM+03,Y
;
	 LDA	SCMODE1,X
	 TAX
	 LDA	UPDCDL-1,X
	 STA	!OAM+02,Y
;
;
	 LDA	SCXPOS,X
	 SEC
	 SBC	#008H		;player center point minus
	 CMP	#0F1H
	 BCC	UPD200		;max left charcter right set?
;				;yes
	 LDA	!OAM+00,Y
	 STA	!OAM+04,Y
	 LDA	!OAM+01,Y
	 STA	!OAM+05,Y
	 LDA	!OAM+02,Y
	 STA	!OAM+06,Y
	 LDA	!OAM+03,Y
	 STA	!OAM+07,Y
;
	 TYA
	 LSR	A
	 LSR	A
	 TAY
	 LDA	#003H
	 STA	!OAMSB+01H,Y
	 BRA	UPD210
UPD200	 EQU	$
	 TYA
	 LSR	A
	 LSR	A
	 TAY
UPD210	 EQU	$
	 LDA	#002H
	 STA	!OAMSB+00H,Y		;!OAM (00H+60H or 70H)/04H
;
	 LDX	<WORK0
	 RTS
;
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;%	 SCDISP	      item Panel set		   %
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ITDISP		EQU	$
		STZ	<WORK0
		LDA	#02H
IT9		EQU	$
		STA	<WORK1
;
;;;;;;;;;;IT9		EQU	$
		LDX	#02H
IT2		EQU	$
		LDY	<WORK1
		STX	<WORK3
;
		LDA	!GMITEM,Y
		BEQ	IT3
		TAY
;
		LDA	ITOMCD-1,Y
		LDY	<WORK0
;;;NOM;;;	  STA	 !OAM+0A2H,Y
		STA	!OAM+01E2H,Y
;
		LDA	#0D0H
;;;NOM;;;	  STA	 !OAM+0A1H,Y
		STA	!OAM+01E1H,Y
;
		LDX	#00H
		CPY	#004H
		BEQ	ITCS50		;No.1 set?
;
		INX
		CPY	#00CH
		BNE	ITCS60		;No.3 set?
;
ITCS50		EQU	$
		LDA	ITGTTM,X
		BEQ	ITCS60
;
		LSR	A
		LSR	A
		LSR	A
		AND	#00EH
		BRA	ITCS70
;
ITCS60		EQU	$
		LDA	#00100100B	;atribute data
ITCS70		EQU	$
;;;NOM;;;	  STA	 !OAM+0A3H,Y
		STA	!OAM+01E3H,Y
;
		LDX	<WORK3
		LDA	#10H
		CPY	#00CH		;No.3 data?
		BCC	IT4
;
		LDA	#0C0H
IT4		EQU	$
		CLC
		ADC	ITOMXD,X
;;;NOM;;;	  STA	 !OAM+0A0H,Y
		STA	!OAM+01E0H,Y
;
		TYA
		LSR	A
		LSR	A
		TAY
		LDA	#002H
;;;NOM;;;	 STA	!OAMSB+28H,Y	;!OAM (00H+A0H or B0H or C0H)/04H
		STA	!OAMSB+78H,Y	;!OAM (00H+1E4H,1E8H or 1F0H,1F4H)/04H
IT3		EQU	$
		LDA	<WORK0
		CLC
		ADC	#004H		;next oam index comp
		STA	<WORK0
		DEC	<WORK1
		DEX
		BMI	JP0010
;
		BRA	IT2
;
JP0010		EQU	$
		LDA	#00CH
		STA	<WORK0
		LDA	#ITMNO+2
		LDY	<WORK1
		BMI	IT9			;
;						;
		RTS
;;;;;;;;		LDY	<WORK1
;;;;;;;;		BPL	IT6
;;;;;;;;;
;;;;;;;;		LDA	#00CH
;;;;;;;;		STA	<WORK0
;;;;;;;;;
;;;;;;;;		LDY	#ITMNO+2
;;;;;;;;		STY	<WORK1
;;;;;;;;		JMP	IT9
;;;;;;;;;
;;;;;;;;IT6		EQU	$
;;;;;;;;		RTS









;;;;;;;;ITDISP	 EQU	$
;;;;;;;;	 LDA	#00H
;;;;;;;;	 STA	<WORK0
;;;;;;;;	 LDA	#02H
;;;;;;;;	 STA	<WORK1
;;;;;;;;;
;;;;;;;;IT9	 EQU	$
;;;;;;;;	 LDX	#02H
;;;;;;;;IT2	 EQU	$
;;;;;;;;	 LDY	<WORK1
;;;;;;;;	 STX	<WORK3
;;;;;;;;;
;;;;;;;;	 LDA	!GMITEM,Y
;;;;;;;;	 BEQ	IT3
;;;;;;;;	 TAY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;;;;;	 DEX
;;;;;;;;	 BMI	JP0010
;;;;;;;;;
;;;;;;;;	 JMP	IT2
;;;;;;;;JP0010	 EQU	$
;;;;;;;;	 LDY	<WORK1
;;;;;;;;	 BPL	IT6
;;;;;;;;;
;;;;;;;;	 LDA	#00CH
;;;;;;;;	 STA	<WORK0
;;;;;;;;;
;;;;;;;;	 LDY	#ITMNO+2
;;;;;;;;	 STY	<WORK1
;;;;;;;;	 JMP	IT9
;;;;;;;;;
;;;;;;;;IT6	 EQU	$
;;;;;;;;	 RTS
;
;=====================================-
SCDISP	 EQU	$
	 TXA
	 PHA
;
	 MEM16
	 IDX16
	 REP	#00110000B	;memory,index 16bit mode
;
	 LDY	#00H
	 LDX	!VRAMD
SCD000	 EQU	$
	 LDA	SCDVDT,Y
	 STA	!VRAMD+2,X
	 INX
	 INX
	 INY
	 INY
	 CPY	#008H
	 BNE	SCD000
;
	 MEM8
	 IDX8
	 SEP	#00110000B	;memory,index 8bit mode
;
	 LDY	<WORKF	      ; Player index
;
	 LDA	SCDLA,Y
	 CLC
	 ADC	BPLKCT,Y
	 STA	!VRAMD+003H-008H,X
;
	 DEX
	 DEX
	 STX	!VRAMD
;
	 PLA
	 TAX
	 RTS
;
;
;
;;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;;%	  Mario 3 Bonus stage			    %
;;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
BATTLE_GAME   EQU    $
BMARIO	 EQU	$
;
;===== Pause check ==========
;;;;	 LDA	04E7H	     ; (S)
;;;;	 BNE	PAS5	     ; Sound off ?
;
		LDA	BPLEND
		BNE	PAS5

	 LDA	<KEYA2	      ; Yes !
	 ORA	<KEYB2	      ; Yes !
	 AND	#00010000B
	 BEQ	PAS5	     ; Start on ?
;
	 LDA	BPSFLG	     ; Yes !
	 EOR	#01H
	 STA	BPSFLG
	 BNE	PAS1	     ; Pause reset ?
;
;;;;;;;;	 LDA	#02H
;;;;;;;;	 STA	04F7H	     ; (S)
;		LDA	#012H
;		STA	!SOUND0

		LDA	#0F2H		;S.E.(pause)
		STA	!SOUND2
		LDA	#043H		;S.E.(pause)
		STA	!SOUND0
;
	 LDX	#14	     ; Yes !
PAS9	 EQU	$
	 LDA	WBPLSTF,X    ; Timer revise
	 STA	BPLSTF,X
	 DEX
	 BPL	PAS9
	 BMI	PAS5
;
;--------------------------
PAS1	 EQU	$	     ; Now stop timer save!!!
;;;;;;;;	 LDA	#01H
;;;;;;;;	 STA	04F7H	     ; (S)
;		LDA	#011H
;		STA	!SOUND0
		LDA	#0F1H		;S.E.(pause)
		STA	!SOUND2
		LDA	#043H		;S.E.(pause)
		STA	!SOUND0
;
	 LDX	#14
PAS2	 EQU	$
	 LDA	BPLSTF,X
	 STA	WBPLSTF,X
	 DEX
	 BPL	PAS2
;
PAS5	 EQU	$
	 LDA	BPSFLG
	 BEQ	PAS8	     ;Pause ?
;
	 LDX	#14	     ; Yes !
	 LDA	#0FFH
PAS7	 EQU	$
	 STA	BPLSTF,X     ; All stop !!!
	 DEX
	 BPL	PAS7
;======================
PAS8	 EQU	$
	 JSR	 PAS10
	 RTL
;
PAS10	 EQU	$
	 LDA	!BSMODE
	 JSL	>JSRSUB
	 WORD	BSINIT
	 WORD	BSPLAY
;
;======= Init ===============
TGMDDT		EQU	$
;			  0  1	2  3  4	 5  6  7  8  9	A  B
		HEX	00,01,02,00,03,04,05,00,00,01,05,00
;
;
BSINIT	 EQU	$
;
	 MEM16
	 IDX16
	 REP	#00110000B	;memory,index 16bit mode
;
		LDA	#jtcr010
		STA	<CRMOD
		STA	<CRMOD+1

;	 STZ	BPLCHD
;	 STZ	BPLCHD+1
	 LDY	#0200H
	 LDA	#00000H
BSI0F0	 EQU	$
	 STA	BPLCMD,Y
	 DEY
	 DEY
	 BPL	BSI0F0
;
	 MEM8
	 IDX8
	 SEP	#00110000B	;memory,index 8bit mode
;
;--- RAM clear ---
	 LDA	<FRCNT
	 ORA	#10010001B
	 STA	!NRND1	     : Randam initial
;---------------------
	 INC	!BSMODE
;
	 LDX	!TWODSP
	 LDA	>TGMDDT,X
	 STA	TGMODE	     ; "POW" game mode set !!
;
	 TXA
	 JSL	>JSRSUB
	 WORD	BSI00	  ;0 ; "POW" game
	 WORD	BSI00	  ;1 ; "POW" game
	 WORD	BSI00	  ;2 ; "POW" game
;
	 WORD	BSI04	  ;3 ; Obj coin
;
	 WORD	BSI00	  ;4 ; "POW" game
	 WORD	BSI00	  ;5 ; "POW" game
	 WORD	BSI00	  ;6 ; "POW" game
;
	 WORD	BSI03	  ;7 ; Dokan game
;
	 WORD	BSI00	  ;8 ; "POW" game
	 WORD	BSI00	  ;9 ; "POW" game
	 WORD	BSI00	  ;A ; "POW" game
;
	 WORD	BSI02	  ;B ; "?" game
;
;=================================
BSI03	 EQU	$
		LDA	#001H		;coin sound effect counter set
		STA	BCSECT

BSI00	 EQU	$

	 RTS
;========"?" game ===============
BSI02	 EQU	$
	 LDX	#0DH
BI2010	 EQU	$
	 TXA
	 STA	<WORK0,X
	 DEX
	 BPL	BI2010
;
	 LDA	#0FFH
	 STA	<WORKE
	 STA	<WORKF
;
	 LDX	#4	     ; 5 of Coin set !!
BI2000	 EQU	$
	 JSR	RD0TOD
;
	 TAY
	 LDA	CLCOXD,Y
	 STA	BENXPS,X
	 LDA	CLCOYD,Y
	 STA	BENYPS,X
;
	 LDA	#EMOVE
	 STA	BENCMD,X
;
	 LDA	#BCOIN
	 STA	BENMYN,X
	 DEX
	 BPL	BI2000
	 RTS
;
;-------------------------
RD0TOD	 EQU	$	     ; Randam 0 to 0DH
RDTD00	 EQU	$
	 JSL	>BRANDM
	 AND	#0FH
	 TAY
	 LDA	WORK0,Y
	 BMI	RDTD00
;
	 PHA
	 LDA	#0FFH
	 STA	WORK0,Y	     ; Protect Set !!
	 PLA
	 RTS
;
;
;--------Coin initial-----------------------
;--------Init pos.------
BSI04	 EQU	$
	 LDX	#04H
BSI400	 EQU	$
	 INC	BENCMD,X
	 LDA	#BCOIN
	 STA	BENMYN,X
;
	 LDA	BCOYPD,X
	 STA	BENYPS,X
	 LDA	BCOXPD,X
	 STA	BENXPS,X
;
	 JSR	BERMIT
	 DEX
	 BPL	BSI400
	 RTS
;
;
;========Game============================
BSPLAY	 EQU	$
	 JSR	ITDISP	     ; Panel Display !!
	 JSR	UPCHEK	     ; ? UP check !
;
	 LDA	!TWODSP
	 JSL	>JSRSUB
	 WORD	BSP00	  ;0 ; "POW" game
	 WORD	BSP00	  ;1 ; "POW" game
	 WORD	BSP00	  ;2 ; "POW" game
;
	 WORD	BSP04	  ;3 ; Obj coin
;
	 WORD	BSP00	  ;4 ; "POW" game
	 WORD	BSP00	  ;5 ; "POW" game
	 WORD	BSP00	  ;6 ; "POW" game
;
	 WORD	BSP03	  ;7 ; Dokan game
;
	 WORD	BSP00	  ;8 ; "POW" game
	 WORD	BSP00	  ;9 ; "POW" game
	 WORD	BSP00	  ;A ; "POW" game
;
	 WORD	BSP02	  ;B ; "?" game
;
;========POW============
BSP00	 EQU	$
	 JSR	BPLAY	     ;Mario & Luigi
	 JSR	BENINT
	 JSR	BENEMY
	 JSR	BBLOCK
	 JSR	BPOW
		JSR	PAUSE_SET	;"PAUSE" set
	 RTS
;========Hashigo========
BSP02	 EQU	$
	 JSR	BPLAY	     ;Mario & Luigi
;
	 JSR	BENEMY
;
		JSR	PAUSE_SET	;"PAUSE" set
	 RTS
;========Dokan==========
BSP03	 EQU	$
	 JSR	BPLAY	     ;Mario & Luigi
;
	 JSR	COJUMP	     ; From Dakan Coin jump !!
	 JSR	BENEMY
;
		JSR	PAUSE_SET	;"PAUSE" set
	 RTS
;	 JSR	TMCHEK
;	 RTS
;
;========Obj coin ======
BSP04	 EQU	$
	 JSR	BPLAY
	 JSR	BENEMY
	 JSR	BBLOCK
		JSR	PAUSE_SET	;"PAUSE" set
	 RTS
;
;------------------------
TMCHEK	 EQU	$
	 LDA	<FRCNT
	 AND	#07H
	 BNE	TMC000
;
	 INC	BSTIME
	 BNE	TMC000
;
	 LDA	#01
	 STA	!PLOTNO	     :	TEST TEST TEST TEST TEST
;
	 JMP	BSCLER
TMC000	 EQU	$
	 RTS
;
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
COJUMP	 EQU	$
	 LDA	BPLSTF
	 ORA	BPLSTF+1
	 ORA	BPLEND
	 ORA	BPSFLG
	 BNE	COJS10	     ; Game stop ?
;
		DEC	BCSECT
		BNE	COJS000

		LDA	#020H
		STA	BCSECT

		LDA	#01CH
		STA	!SOUND0

COJS000		EQU	$
		LDA	<FRCNT
		AND	#007H
		BNE	COJS10

	 LDX	#09H	     ; No.
COJS00	 EQU	$
	 LDA	BENCMD,X
	 BEQ	COJS20
	 DEX
	 BPL	COJS00
;
COJS10	 EQU	$
	 RTS
;
;-- Set --
COJS20	 EQU	$
	 INC	BENCMD,X
;
	 LDY	#BCOIN
	 LDA	BRND
	 AND	#00011100B
	 BNE	COJP10
;
	 LDY	#BFIR3
COJP10	 EQU	$
	 TYA
	 STA	BENMYN,X
;
	 LDA	#0B0H
	 STA	BENYPS,X
	 LDA	#78H+4
	 STA	BENXPS,X
;
	 JSL	>BRANDM
	 AND	#0FH
	 ADC	#0A8H
	 STA	BENYSD,X     ; D0~B0
;
	 JSL	>BRANDM
	 AND	#1FH
	 SBC	#10H
	 STA	BENXSD,X     ; F0~10
;
	 JSR	BERMIT
	 INC	BENSTT,X     ; Moving flag on !
;
	 LDA	#30H
	 STA	BENOBJ,X
	 RTS
;
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;%	 Item check sub.			%
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ITEMCK	 EQU	$
	 LDX	#02H
;
	 LDY	#02H
	 LDA	BPLIND
	 BEQ	ITCK00	     ; Luigi ?
;
	 LDY	#ITMNO+2     ; Yes !
ITCK00	 EQU	$
	 STY	<WORK0
	 LDA	!GMITEM,Y
	 BNE	ITCK01
;
	 DEY
	 DEX
	 BPL	ITCK00
;
	 LDX	!BPLIND
	 RTS
;
ITCK01	 EQU	$
	 LDX	#0BH
ITCK02	 EQU	$
	 LDA	!BENCMD,X
	 BEQ	ITCK03
	 DEX
	 CPX	#0AH	     ; Only One set !
	 BNE	ITCK02
;
	 LDX	!BPLIND
	 RTS
;
ITCK03	 EQU	$
		LDA	#00FH		;S.E.(item card)
		STA	!SOUND0

	 LDA	!GMITEM,Y
	 TAY
	 CLC
	 ADC	#BITEM-1
	 STA	BENMYN,X
;
	 LDA	ITITYD-1,Y
	 STA	BENYSD,X
;
	 INC	BENCMD,X
;
	 LDY	<WORK0
	 LDA	#00H
	 STA	!GMITEM,Y    : Data clear !!!!!!
;
	 JSR	BERMIT
;
	 LDY	BPLIND
	 LDA	BPLXPS,Y
	 STA	BENXPS,X
;
	 ASL	A
	 LDA	#06H
	 BCC	ITCK55
;
	 LDA	#0FAH
ITCK55	 EQU	$
	 STA	BENXSD,X
;
	 LDA	BPLYPS,Y
	 STA	BENYPS,X
;
	 LDA	#00H
	 STA	BENYPH,X
;
	 LDA	#20H
	 STA	BENTIM,X     ; No. cross timer !!!
	 LDX	!BPLIND
	 RTS



;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
BPLAY	 EQU	$
		JSL	>KEYCNG
;
		LDA	BPLEND
		BEQ	BPLPF00

		STZ	!BPSFLG		;pause off

		STZ	<KEYA1		;key clear
		STZ	<KEYA1+1		;key clear

BPLPF00		EQU	$
	 LDX	#1
BPLPF0	 EQU	$
	 STX	BPLIND		;Mario or Luigi flag
;
		LDA	<KEYA1,X	;key = right & left ?
		AND	#00000011B	;
		CMP	#00000011B	;
		BNE	BPLPF1		;  no: BPLPF1

		DEC	<KEYA1,X	;right cansel

BPLPF1		EQU	$
		LDA	<KEYA1,X	;key = up & down ?
		AND	#00001100B	;
		CMP	#00001100B	;
		BNE	BPLPF2		;  no: BPLPF2

		LDA	<KEYA1,X	;up cansel
		AND	#11110111B	;
		STA	<KEYA1,X	;

BPLPF2		EQU	$
;
	 LDA	!BPSFLG		;pause ?
	 BNE	BPL0FA		; yes: BPL0FA
;
	 LDA	BPLTIM,X	;player (damage) stop counter = 0 (No.)
	 BEQ	BPL0F8		; yes: BPL0F8
;
	 DEC	BPLTIM,X	;player stop counter dec.
BPL0F8	 EQU	$
	 LDA	ITGTTM,X	;item get stop counter = 0 ?
	 BEQ	BPL0FA		; yes: BPL0FA
;
	 DEC	ITGTTM,X	;item get stop counter dec.
BPL0FA	 EQU	$
	 JSR	BPL00
;
	 STZ	BPLYRV,X     ; On BG revise clear !!
;
	 DEX			;Mario tern ?
	 BPL	BPLPF0		; yes: BPLPF0

	 LDA	!BPSFLG		;pause ?
	 BNE	BPL0FB		; yes: BPL0FB
;------ VS cross ------
	 JSR	MRVSLG		;
;
BPL0FB		EQU	$
		JSL	>B_PCHCST		; character ram set

	 RTS
;
;********Player move *********
BPL00	 EQU	$
		LDA	BPLEND		;game end ?
		BEQ	BPL001		;  no: BPL180
		JMP	BPL180

BPL001		EQU	$
		LDA	BPLSTF,X	;player pause ?
		BEQ	BPL0F		;  no: BPL0F
;
		DEC	BPLSTF,X
		BEQ	BPL0F
		JMP	BPLE8
;
BPL0F		EQU	$



BPL18		EQU	$
		LDY	BPLEND		;battle play end (coin sum = 5)?
		BEQ	BPLF0		;  no: BPLF0
;
BPL180		EQU	$
		TXA		;Mario turn ?
		BEQ	BPL19	; yes: BPL19
;
		LDA	BPLCMD+1	;Luigi fail ?
		CMP	#BFAIL		;
		BEQ	BPLF0		; yes: BPLF0
		BRA	BPLE8		;  no: BPLE8

BPL19		EQU	$

		LDA	!BPSFLG		;pause ?
		BNE	BPL190		; yes: BPL190

		DEC	BPLEND

BPL190		EQU	$
		LDA	BPLCMD		;Mario fail ?
		CMP	#BFAIL		;
		BEQ	BPLF0		; yes: BPLF0

	 LDA	BPLEND		;battle play end ?
	 BNE	BPLE8		;
;				;  no: BPLE8
;	 JSR	BPLCST		;char. set

		INC	BPLEND		;enemy & effect lock

		JSR	CHRMD_SET	;char. mode set
;
BSCLER	 EQU	$
	 LDA	#1		;screen clear
	 STA	!GMMODE		;
	 STZ	!BSMODE		;
;
;;N;;	      PLA
;;N;;	      PLA
BPLE6		EQU	$
		RTS
;
BPLE8		EQU	$
		LDA	BPLCMD,X
		BEQ	BPLE6
;
;	  JMP	 BPLCST		;char. set

BPL0F0		EQU	$
		LDA	!BPSFLG		;stop ?
		ORA	BPLEND		;
		BEQ	BPL0F00		;  no: BPL0F00

BPL0F01		EQU	$
		LDA	BPLYRV,X	;y revise = 0 ?
		BEQ	BPL0F00		; yes: BPL0F00

		LDA	BPLYPS,X	;y pos. adjustment
		AND	#0F8H		;
		CLC			;
		ADC	BPLYRV,X	;
		STA	BPLYPS,X	;

BPL0F00		EQU	$
		LDA	BPLCMD,X	;player crimb ?
		CMP	#003H		;
		BNE	BPL0F02		;

		LDA	BPLEND
		BEQ	BPL0F03

		LDA	BPLCRB,X
		ORA	#00000100B
		STA	BPLCRB,X
		BRA	BPL0F02

BPL0F03		EQU	$
		JMP	SS

BPL0F02		EQU	$
		JSR	CHRMD_SET	;char. mode set

		RTS
;
;----------------------------------
BPLF0	 EQU	$
		LDA	BPLCMD,X
	 JSL	>JSRSUB
BP00	 WORD	BPLINT
BP01	 WORD	BPLMOV
BP02	 WORD	BPLFIL
BP03	 WORD	BPLCRM
;
BINIT	 EQU	(BP00-BP00)/2
BMOVE	 EQU	(BP01-BP00)/2
BFAIL	 EQU	(BP02-BP00)/2
BCRIM	 EQU	(BP03-BP00)/2
;;;;;











;
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;;;;;BPLAY	 EQU	$
;;;;;	 LDX	#1
;;;;;BPLPF0	 EQU	$
;;;;;	 STX	BPLIND
;;;;;;
;;;;;	 LDA	!BPSFLG
;;;;;	 BNE	BPL0FA	     ; Pause ?
;;;;;;
;;;;;	 LDA	BPLTIM,X     ; No.
;;;;;	 BEQ	BPL0F8
;;;;;;
;;;;;	 DEC	BPLTIM,X
;;;;;BPL0F8	 EQU	$
;;;;;	 LDA	ITGTTM,X
;;;;;	 BEQ	BPL0FA
;;;;;;
;;;;;	 DEC	ITGTTM,X
;;;;;BPL0FA	 EQU	$
;;;;;	 JSR	BPL00
;;;;;;
;;;;;	 LDA	#00
;;;;;	 STA	BPLYRV,X     ; On BG revise clear !!
;;;;;;
;;;;;	 DEX
;;;;;	 BPL	BPLPF0
;;;;;;------ VS cross ------
;;;;;	 JSR	MRVSLG
;;;;;;
;;;;;		JSL	>B_PCHCST		; character ram set
;;;;;	 RTS
;;;;;;
;;;;;;********Player move *********
;;;;;BPL00	 EQU	$
;;;;;	 LDA	BPLSTF,X
;;;;;	 BEQ	BPL0F	     ; Player pause !!
;;;;;;
;;;;;	 DEC	BPLSTF,X
;;;;;	 BNE	BPLE8
;;;;;;
;;;;;BPL0F	 EQU	$
;;;;;	 LDY	BPLEND
;;;;;	 BEQ	BPLF0
;;;;;;
;;;;;	 TXA
;;;;;	 BNE	BPLE8
;;;;;;
;;;;;	 DEC	BPLEND
;;;;;	 BNE	BPLE8
;;;;;;
;;;;;;	 JSR	BPLCST
;;;;;		JSR	CHRMD_SET	;char. mode set
;;;;;;
;;;;;BSCLER	 EQU	$
;;;;;	 LDA	#1
;;;;;	 STA	!GMMODE
;;;;;	 STZ	!BSMODE
;;;;;;
;;;;;;;N;;	      PLA
;;;;;;;N;;	      PLA
;;;;;BPLE6	 EQU	$
;;;;;	 RTS
;;;;;;
;;;;;BPLE8	 EQU	$
;;;;;	 LDA	BPLCMD,X
;;;;;	 BEQ	BPLE6
;;;;;;
;;;;;;	 JMP	BPLCST
;;;;;		JMP	CHRMD_SET	;char. mode set
;;;;;;
;;;;;;----------------------------------
;;;;;BPLF0	 EQU	$
;;;;;	 LDA	BPLCMD,X
;;;;;	 JSL	>JSRSUB
;;;;;BP00	 WORD	BPLINT
;;;;;BP01	 WORD	BPLMOV
;;;;;BP02	 WORD	BP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	 CMP	#08H
	 BNE	BPL0D5
;
	 JSR	ITEMCK
;			     : No.
BPL0D5	 EQU	$
	 LDA	#0
	 STA	<KEYA1,X
	 STA	<KEYA2,X
BPL0D6	 EQU	$
;========Key controle===========
	 LDA	<KEYA1,X
	 AND	#00000011B
	 BEQ	BPL0600
;
	 STA	BPLMKI,X
;
	 LSR	A
	 BCC	BPL030
;			     : Right
	 LDA	<KEYA1,X
	 AND	#01000000B
	 BEQ	RM40
;
	 LDA	BPLXSD,X
	 CMP	#18H
	 BPL	RM20
	 CLC
	 ADC	#01H
RM20	 EQU	$
	 JMP	BPL060
;-------------------------------
RM40	 EQU	$
	 LDA	BPLXSD,X
	 CMP	#0CH
	 BEQ	RM50
	 BPL	RM48
	 CLC
	 ADC	#01H
	 JMP	BPL060
;-------------------------------
RM48	 EQU	$
	 SEC
	 SBC	#01H
RM50	 EQU	$
	 JMP	BPL060
;=== Left ===================-
BPL030	 EQU	$
	 LDA	<KEYA1,X
	 AND	#01000000B
	 BEQ	LM40
;
	 LDA	BPLXSD,X
	 CMP	#0E8H+1
	 BMI	LM20
	 SEC
	 SBC	#01H
LM20	 EQU	$
	 JMP	BPL060
;-------------------------------
LM40	 EQU	$
	 LDA	BPLXSD,X
	 CMP	#0F4H	;+1
	 BEQ	LM50
	 BMI	LM48
	 SEC
	 SBC	#01H
	 JMP	BPL060
;-------------------------------
LM48	 EQU	$
	 CLC
	 ADC	#01H
LM50	 EQU	$
BPL060	 EQU	$	     ; No key
	 STA	BPLXSD,X
BPL0600	 EQU	$
	 LDA	BPLCRB,X
	 AND	#00000100B
	 BEQ	BPL0610	     ; On flor ?
;			     : Yes!
	 LDA	BPLYSD,X
	 BPL	BPL0611
;
BPL0610	 EQU	$
	 JMP	BPL068
;
BPL0611	 EQU	$
	 LDA	BPLYPS,X
	 AND	#0F8H
	 CLC
	 ADC	BPLYRV,X
	 STA	BPLYPS,X
;
	 LDA	#00H
	 STA	BPLYSD,X
	 STA	BPLJPF,X
;
;========Block jump up check==================
	 LDY	FRBGNO1,X
	 CPY	#BLK3D3
	 BNE	BPL053	     ; Block check
;
	 LDA	BPLCRB,X
	 AND	#11000000B
	 LDY	#08H		;
	 CMP	#11000000B
	 BEQ	BPL048
	 CMP	#10000000B
	 BEQ	BPL043
;
	 LDY	#0F8H		;
BPL043	 EQU	$
	 TYA
	 STA	BPLXSD,X
;
BPL048	 EQU	$
	 JMP	BPL049
;
BPL053	 EQU	$
	 LDY	BPOWTM
	 BEQ	BPL054	     ; "POW" check
;
BPL049	 EQU	$
	 LDA	#12H
	 STA	BPLSTM,X
;
;;;;;;;;	 LDA	04F1H
;;;;;;;;	 ORA	#04H
;;;;;;;;	 STA	04F1H	     ; (S)
		LDA	#002H
		STA	!SOUND0
;
	 LDA	#0C8H
	 JMP	BPL061
;------------------------------------------
BPL054	 EQU	$
	 LDA	<KEYA2,X      ; "A" Bottun on ?
	 BPL	BPL062
;			     : yes ! Jump
;;;;;;;;	 LDA	04F1H
;;;;;;;;	 ORA	#01H
;;;;;;;;	 STA	04F1H	     ; (S)
		LDA	#001H		;S.E.(jump)
		STA	!SOUND1
;
	 LDA	#1
	 STA	BPLJPF,X
;
	 LDA	BPLXSD,X
	 BPL	JPS000
	 EOR	#0FFH
	 CLC
	 ADC	#01H
JPS000	 EQU	$
	 LSR	A
	 LSR	A
	 TAY
	 LDA	PLINYS,Y
BPL061	 EQU	$
	 STA	BPLYSD,X
BPL062	 EQU	$
	 LDA	<KEYA1,X
	 AND	#00000011B
JMPB68	 EQU	$
	 BNE	BPL068
;
	 LDA	BPLXSD,X
	 BEQ	BPL068
	 BPL	BPL063
;
	 CLC
	 ADC	#01H
	 STA	BPLXSD,X
	 JMP	BPL068
;
BPL063	 EQU	$
	 SEC
	 SBC	#01H
	 STA	BPLXSD,X
BPL068	 EQU	$
;========Move calc==============
	 LDY	!TWODSP
	 LDA	PLSBGD,Y
	 BEQ	BPL069	     ; Side BG. Check ok ?
;
	 LDA	#01H	     ; Yes !
	 LDY	BPLXSD,X
	 BPL	BPL06H
	 ASL	A
BPL06H	 EQU	$
	 AND	BPLCRB,X     ; PLayer Side BG. ?
	 BEQ	BPL069
;			     : Yes!
	 AND	<KEYA1,X
	 BEQ	BPL073	     ; Key on ?
;
	 TAY		     ; Yes !
	 LDA	PLSBXD-1,Y   ; Character chenge
BPL073	 EQU	$
	 STA	BPLXSD,X
	 JMP	BPL06A
;
BPL069	 EQU	$
	 JSR	BXCALC	     ; (x) move calc.
;
BPL06A	 EQU	$
	 LDA	BPLSLD,X
	 BEQ	BHD002	     ; Hed slide ?
;
	 DEC	BPLSLD,X     ; yes !
	 BNE	BPL070
;
BHD002	 EQU	$
	 LDY	BPLYSD,X
	 BPL	BHD008
;
	 LDA	BPLCRB,X
	 AND	#00001000B
	 BEQ	BHD008	     ; Hed cross ?
;
	 TYA
	 EOR	#0FFH
	 LSR	A
	 LSR	A
	 LSR	A
	 ADC	#4
	 STA	BPLSLD,X
;
	 LDA	#0
	 STA	BPLYSD,X
;
	 LDA	BPLYPS,X
	 AND	#0F0H
	 CLC
	 ADC	#0EH
	 STA	BPLYPS,X
;
BHD008	 EQU	$
	 JSR	BYCALC
;
BHD010	 EQU	$
	 LDA	BPLYSD,X
	 BMI	BPL06E
;
	 CMP	#40H
	 BCS	BPL070
;
BPL06E	 EQU	$
	 LDA	BPLYSD,X
	 BPL	BPL06E0
;
	 LDY	<KEYA1,X
	 BMI	BPL06F
;
BPL06E0	 EQU	$
	 CLC
	 ADC	#03H
BPL06F	 EQU	$
	 CLC
	 ADC	#02H
	 STA	!BPLYSD,X
BPL070	 EQU	$
	 RTS
;--- Character mode set --------
CHRMD_SET	EQU	$
		LDA	BPLEND		;game end ?
		BEQ	CHRMD_SET0200	;  no: CHRMD_SET0200

		TXA			;This player = winner ?
		EOR	!PLOTNO		;
		AND	#001H		;
		BNE	CHRMD_SET0200	;  no: CHRMD_SET0200

		LDA	BPLCRB,X	;foot BG = floor ?
		BIT	#0000100B	;
		BEQ	CHRMD_SET0110	;  no: CHRMD_SET0110

		LDA	<CRMOD,X
		CMP	#jtcr018
		BEQ	CHRMD_SET0010
		CMP	#jtcr010
		BNE	CHRMD_SET0110
;		BCC	CHRMD_SET0110
;		CMP	#jtcr011
;		BCS	CHRMD_SET0110

CHRMD_SET0010	EQU	$
		LDA	#jtcr018
		STA	<CRMOD,X

CHRMD_SET0100	EQU	$
		JSR	BPLOST		;char. set

		RTS

CHRMD_SET0110	EQU	$
		JSR	BPLMOV2

CHRMD_SET0200	EQU	$
		LDY	#jtcr010		;stop

		LDA	BPLXSD,X	;x speed = 0 ?
		BNE	BPCCKF		;  no : BPCCKF
;
		STA	BPLCNT,X	;player crimb ladder ?
		BEQ	BPCCST		; yes: BPCCST
;
BPCCKF		EQU	$
		LDY	#01H
		ASL	A
		BCC	BPCCK0

		INY
;		LDY	#2
BPCCK0		EQU	$
		TYA
		LDY	#jtcr012		;player pose = slip ?
		CMP	BPLMKI,X	;
		BNE	BPCCST		; yes: BPCCST
;
BPCC01		EQU	$
		LDA	BPLSTF		;player stop ?
		ORA	BPLSTF+1	;
		ORA	BPLEND		;
		BNE	BPCCK11		; yes: BPCCK11

		LDA	BPLXSD,X	;player pose change ?
		BPL	BPCCK1		;  no: BPCCK11
					;
		EOR	#0FFH		;
		INC	A		;
					;
BPCCK1		EQU	$		;
		LSR	A		;
		LSR	A		;
		TAY			;
		LDA	PLWKCT,X	;
		CLC			;
		ADC	BPLWKT,Y	;
		STA	PLWKCT,X	;
		BCC	BPCCK11		;
;
		INC	PLWKMD,X	;player walk pose pattern flag inc.

BPCCK11		EQU	$
		LDA	PLWKMD,X
		TAY

		TYA			;player pose...
		BEQ	BPCCK11S	;
		BIT	#001H		; walk: BPCCK11S0
		BNE	BPCCK11S0	; stop: BPCCK11S

		STZ	PLWKMD,X	;player walk pose pattern flag clear

BPCCK11S	EQU	$
		LDY	#jtcr010
		BRA	BPCCK110

BPCCK11S0	EQU	$
		LDY	#jtcr011

BPCCK110	EQU	$
BPCCST		EQU	$
		LDA	BPLCRB,X	;foot BG = floor ?
		AND	#00000100B	;
		BNE	BPL_CCHECK0100	; yes: BPL_CCHECK0100
;
		LDA	BPLJPF,X	;player fall or jump ?
		BNE	BPLJPST		; jump: BPLJPST

		LDY	#jtcr011
		JMP	BPL_CCHECK0800	;

BPLJPST		EQU	$
		LDY	#jtcr013

		JMP	BPL_CCHECK0800	;

BPL_CCHECK0100	EQU	$
		LDA	BPLSTM,X	;player sit ? (cruch)
		BEQ	BPL_CCHECK0200	;  no: BPL_CCHECK0200

		DEC	BPLSTM,X	;player sit timer dec.

		LDY	#jtcr014

		BRA	BPL_CCHECK0800

BPL_CCHECK0200	EQU	$
		LDA	BPLKTM,X	;player kick ?
		BEQ	BPL_CCHECK0300	;  no: BPL_CCHECK0300

		DEC	BPLKTM,X	;player kick timer dec.

		LDY	#jtcr015

		BRA	BPL_CCHECK0800

BPL_CCHECK0300	EQU	$

BPL_CCHECK0400	EQU	$
BPL_CCHECK0800	EQU	$
		TYA
		STA	<CRMOD,X	;player slip ?
		CMP	#jtcr012	;  no: BPL_CCHECK0A00
		BNE	BPL_CCHECK0A00	;

BPL_CCHECK0900	EQU	$
		LDA	!SOUND1
		BNE	BPL_CCHECK0A00

		LDA	#004H		;Sound Effect(slip)
		STA	!SOUND1		;

BPL_CCHECK0A00	EQU	$
;==== Character set ====

		JSR	BPLOST		;char. set

BPL_CCHECK0B00	EQU	$
;==== BG Check==========
		JSR	BPLBGC		;

		RTS
;
;;;;
;;;;
;;;;
;;;;
;;;;	 LDY	#00H	     ; Stop
;;;;;
;;;;	 LDA	BPLXSD,X
;;;;	 BNE	BPCCKF
;;;;;
;;;;	 STA	BPLCNT,X
;;;;	 BEQ	BPCCST
;;;;;
;;;;BPCCKF	 EQU	$
;;;;	 LDY	#01H
;;;;	 ASL	A
;;;;	 BCC	BPCCK0
;;;;	 LDY	#2
;;;;BPCCK0	 EQU	$
;;;;	 TYA
;;;;	 LDY	#02H
;;;;	 CMP	BPLMKI,X
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,X
;
	 JSR	BPLBGC
;
	 LDA	BPLCNT,X
	 AND	#00000100B
	 LSR	A
	 LSR	A
	 ADC	#1
	 STA	BPLMKI,X
;
;	 JMP	BPLCST
	 JMP	BPLOST
;
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;%	 Bonus player Fail		     %
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
BPLFIL	 EQU	$
		LDA	#jtcr017
		STA	<CRMOD,X

;	 LDA	#06H
;	 STA	BPLCHD,X
;	 JSR	BPLCST
	 JSR	BPLOST
;
	 LDA	BPLTIM,X
	 BNE	BPF080
;
;---------------------------------
	 JSR	BYCALC
;
	 LDA	BPLYSD,X
	 BMI	BPF06E
;
	 CMP	#40H
	 BCS	BPF070
;
BPF06E	 EQU	$
	 INC	BPLYSD,X
	 INC	BPLYSD,X
BPF070	 EQU	$
	 LDA	BPLYPS,X
	 CMP	#0EFH
	 BCC	BPF080
;
	 LDA	BPLYPH,X
	 BNE	BPF080	     ; In Display ?
;			     : Yes !
	 LDA	#40H
	 STA	BPLTIM,X
	 STA	BPLSET,X
;
	 LDA	#BINIT
	 STA	BPLCMD,X
BPF080	 EQU	$
	 RTS
;
;==== BG check ====
BPLBGC	 EQU	$
	 LDA	#00
	 STA	BPLCRB,X
	 STA	FRBGNO1,X
	 STA	HDBGNO,X
;
	 LDY	#05H
BPBC00	 EQU	$
	 STY	<WORKF
;
	 LDA	BPLYPS,X
	 CLC
	 ADC	BBCKYD,Y
	 AND	#0F0H
	 STA	<WORK0
;
	 CPX	#2
	 BCC	COBG00
;
	 LDA	BENMYN-2,X
	 CMP	#BCOIN
	 BNE	COBG00
;
	 TYA
	 CLC
	 ADC	#06H
	 TAY
COBG00	 EQU	$
	 LDA	BPLXPS,X
	 CLC
	 ADC	BBCKXD,Y
	 STA	<WORK1
;
	 JSR	BBGCHK
	 LDY	<WORKF
	 BCS	BPBC20
;
	 JMP	BPBC10
;
BPBC20	 EQU	$
	 CPY	#2
	 BCS	BPBC06	     ; Hed ?
;			     : yes!
	 LDA	BPLYPS,X
	 CMP	#0D0H
	 BCS	BPBC12
;
	 AND	#0FH
	 CMP	#09H
;
	 BCS	BPBC33
;
	 JMP	BPBC10
;
BPBC33	 EQU	$
	 CPX	#2
	 BCS	BPBC12
;
	 LDA	BPLYSD,X
	 BPL	BPBC12	     ; Player up ?
;			     : Yes!
	 LDA	BBLTIM,X
	 BNE	BPBC12
;------------------------------------
	 LDA	!TWODSP
	 CMP	#0BH
	 BEQ	BPBC12	     ; Power Block set ok
;
	 LDA	#LOW BGTABL	;KANSETU DATA SET
	 STA	<BUFFNO
	 LDA	#HIGH BGTABL
	 STA	<BUFFNO+1
	 LDA	#BANK BGTABL
	 STA	<BUFFNO+2
;
	 LDY	<WORK2	      ; Block set !!
	 LDA	#BLK3D3
	 STA	[<BUFFNO],Y
;
	 TYA
	 STA	BBLBGD,X
;
	 LDA	BPLYPS,X
	 AND	#0F0H
	 STA	BBLYPS,X
;
	 LDA	BPLXPS,X
	 CLC
	 ADC	#08H
	 AND	#0F0H
	 STA	BBLXPS,X
;
	 LDA	#0EH
	 STA	BBLTIM,X
;
	 LDA	#0E0H
	 STA	BBLYSD,X
BPBC12	 EQU	$
	 JMP	BPBC08	     ; Limit over Check
;
BPBC06	 EQU	$
	 CPY	#04H
	 BCS	BPFT00
;			     : Yes !!
	 CPX	#02
	 BCS	BPBC08S	     ; PLayer ?
;=== Side cross =====
;
	CMP	#050H		;BLOCK YUKA?
	BEQ	BPBC08S		;Yes !
	 LDA	!TWODSP
	 CMP	#0BH
	 BNE	BPBC08S	     ; "?" BG ?
;			     : Yes !
	 LDA	<KEYA2,X
	 AND	#01000000B
	 BEQ	BPBC08S
;
	 LDA	#0CH
	 STA	BPLKTM,X     ; Kick pause set !!!!
;
;;;;;;;;	 LDA	04F1H
;;;;;;;;	 ORA	#08H
;;;;;;;;	 STA	04F1H	     ; (S)
		LDA	#003H
		STA	!SOUND0
;
	 LDA	#LOW BGTABL	;KANSETU DATA SET
	 STA	<BUFFNO
	 LDA	#HIGH BGTABL
	 STA	<BUFFNO+1
	 LDA	#BANK BGTABL
	 STA	<BUFFNO+2
;
	 LDY	<WORK2
	 LDA	#00	     ; yes !!
	 STA	[<BUFFNO],Y
;
	 JSR	COCLER	     ; BG Clear
;
	 LDX	#06H
QBCK00	 EQU	$
	 LDA	BENCMD,X
	 BEQ	QBCK10
	 DEX
	 BPL	QBCK00
;
	 LDX	#06H
;
QBCK10	 EQU	$
	 STX	<WORK0
	 JSR	BERMIT
;
	 INC	BENCMD,X
	 LDA	#BBLCK
	 STA	BENMYN,X
	 LDA	<WORK2
	 AND	#0F0H
	 STA	BENYPS,X
;
	 LDA	<WORK2
	 ASL	A
	 ASL	A
	 ASL	A
	 ASL	A
	 STA	BENXPS,X
;
	 LDA	#0C0H
	 STA	BENYSD,X
;
	 LDY	#010H
	 LDA	BENXPS,X
	 LDX	BPLIND
	 CMP	BPLXPS,X
	 BCS	QBCK20
;
	 LDY	#0F0H
QBCK20	 EQU	$
	 LDX	<WORK0
	 TYA
	 STA	BENXSD,X
	 LDX	!BPLIND
BPBC08S	 EQU	$
	 JMP	BPBC08
;
;
;
;
BPFT00	 EQU	$
;====Foot cross !!!	     : yes!
	 LDA	BPLYPS,X
	 AND	#0FH
	 CMP	#06H
	 BCS	BPBC10	     ; Limit in	 ?
;
	 LDA	BPLYSD,X
	 BMI	BPBC10
;
	 LDY	<WORK2
	 LDA	FRBGNO1,X
	 CMP	#BLK3D3
	 BEQ	BPBC08	     ; Up block allready set ?
;
		LDA	#LOW BGTABL	;KANSETU DATA LOAD
		STA	<BUFFNO
		LDA	#HIGH BGTABL
		STA	<BUFFNO+1
		LDA	#BANK BGTABL
		STA	<BUFFNO+2
;
		LDA	[<BUFFNO],Y
;
		CMP	#0FEH
		BCC	BBGCK10
		AND	#001H
		TAY
		LDA	BBGCKDT,Y
;
BBGCK10		EQU	$
;
		STA	FRBGNO1,X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3,Y
	 CLC
	 ADC	#20H
	 STA	!VRAMD+9,Y
;
	 LDA	<WORK3
	 AND	#11011111B	;Hi 20H clear
	 STA	!VRAMD+2,Y
	 STA	!VRAMD+8,Y
;
	 MEM16
	 REP	#00100000B	;memory 16bit mode
;
;
	 LDA	#00240H
	 STA	!VRAMD+4,Y
	 STA	!VRAMD+10,Y
;
;
	 LDA	#01CFFH
	 STA	!VRAMD+6,Y
	 STA	!VRAMD+12,Y
;
;
	 LDA	#0FFFFH
	 STA	!VRAMD+14,Y
;
	 MEM8
	 SEP	#00100000B	;memory 8bit mode
;
	 TYA
	 CLC
	 ADC	#00CH
	 STA	!VRAMD
	 RTS
;
;======= BG data read =====
BBGCHK	 EQU	$
	 LDA	<WORK1
	 LSR	A
	 LSR	A
	 LSR	A
	 LSR	A
	 ORA	<WORK0
	 TAY
	 STY	<WORK2
;
		LDA	#LOW BGTABL	;KANSETU DATA SET
		STA	<BUFFNO
		LDA	#HIGH BGTABL
		STA	<BUFFNO+1
		LDA	#BANK BGTABL
		STA	<BUFFNO+2
;
		LDA	[<BUFFNO],Y
;
		CMP	#0FEH
		BCC	BBGCK50
		AND	#001H
		TAY
		LDA	BBGCKDT,Y
;
BBGCK50		EQU	$
		PHA
;
	 ASL	A
	 ROL	<WORKE
	 ASL	A
	 ROL	<WORKE
	 LDA	<WORKE
	 AND	#00000011B
	 TAY
	 PLA
	 CMP	!CRCKRM,Y
	 RTS
;
;===== Enemy BG check ======
BENBGC	 EQU	$
	 TXA
	 CLC
	 ADC	#BENCRB-BPLCRB
	 TAX
	 JSR	BPLBGC
	 LDX	BENIND
	 RTS
;
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;%	 Bonus player C set		     %
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
BPLOST		EQU	$
		LDA	BPLYPH,X	;player = up screen ? (out of display)
		BPL	BPLSET050		;  no: BPLSET050
;
		LDA	BPLYPS,X	;player in sight range ?
		CMP	#0F0H		;
		BCS	BPLSET060	; yes: BPLSET060
;
		RTS

BPLSET050	EQU	$
		BEQ	BPLSET060	;player = down screen ?
;					;  no: BPLSET060
		RTS

BPLSET060	EQU    $
		LDA    BPLSET,X
		BEQ    BPLSET070
;
		LDA    <FRCNT
		AND    #00000010B
		BEQ    BPLSET070
;
		RTS

BPLSET070	EQU    $
		TXA			;oam set adr. culc.
		ASL	A		;
		ASL	A		;
		ASL	A		;
		ASL	A		;
		ASL	A
		TAY			;

		LDA    BPLXPS,X		;player obj. x pos. set
		STA    !OAM+00+80H,Y	;
;
		LDA    BPLYPS,X		;player obj. y pos. set
		STA    !OAM+01+80H,Y	;
;
		LDA	#00EH
		STA	<WORKA		;Mario color set
		LDA	BPLIND
		BEQ	BPLSET080
;
		LDA	#00AH
		STA	<WORKA		;Luige color set

BPLSET080	EQU	$
		LDA    BPLMKI,X		;player obj. attribute set
		TAX			;
		LDA    BPLATD-1,X	;
		ORA    <WORKA		;
		STA    !OAM+03+80H,Y	;
;
		LDX    BPLIND		;load player index to X_reg
		LDA    BPLCMD,X		;player mode = fail ?
		CMP    #BFAIL		; yes: BPLSET090
		BEQ    BPLSET090	;  no: BPLSET0A0

		LDA	BPLMKI,X	;player muki = left ?
		BIT	#001H		;
		BNE	BPLSET0A0	;  no: BPLSET0A0

;		JMP    BPLSET0A0	;  no: BPLSET0A0
BPLSET090	EQU	$
;
		LDA    !OAM+03+80H,Y	;H flip to void
		AND    #10111111B	;
		STA    !OAM+03+80H,Y	;

BPLSET0A0	EQU    $
		LDA	BPLCMD,X
		CMP	#BFAIL
		BEQ	BPLSET0A1

		LDA	BPLMKI,X	;player muki = left ?
		BIT	#001H		;
		BEQ	BPLSET0A1	; yes: BPLSET0A1

		LDA	BPLEND		;game end ?
		BEQ	BPLSET0A3	;  no: BPLSET0A3

		TXA			;This player = winner ?
		EOR	!PLOTNO		;
		AND	#001H		;
		BNE	BPLSET0A3	;  no: BPLSET0A3

		LDA	<CRMOD,X
		CMP	#jtcr018
		BNE	BPLSET0A3

BPLSET0A5	EQU	$
		LDA    !OAM+03+80H,Y	;H flip to void
		AND    #10111111B	;
		STA    !OAM+03+80H,Y	;
		BRA	BPLSET0A1

BPLSET0A3	EQU	$
BPLSET0A4	EQU	$
		LDA	!OAM+00+80H+00H,Y
		CLC
		ADC	#008H
		STA	!OAM+00+80H+00H,Y

		LDA	#0F8H
		BRA	BPLSET0A2

BPLSET0A1	EQU	$
		LDA	#008H

BPLSET0A2	EQU	$
		STA	WORK0

		LDA	#004H
		STA	!OAM+02+80H+00H,Y

		CPX	#000H
		BEQ	BPLSET0A8

		LDA	#014H
		STA	!OAM+02+80H+00H,Y

BPLSET0A8	EQU	$
		LDA	!OAM+00+80H+00H,Y
		STA	!OAM+00+80H+08H,Y
;		STA	!OAM+00+80H+10H,Y
;		STA	!OAM+00+80H+18H,Y
		CLC
		ADC	WORK0
		STA	!OAM+00+80H+04H,Y
		STA	!OAM+00+80H+0CH,Y
;		STA	!OAM+00+80H+14H,Y
;		STA	!OAM+00+80H+1CH,Y

		LDA	!OAM+01+80H+00H,Y
		STA	!OAM+01+80H+04H,Y
		CLC
		ADC	#008H
		STA	!OAM+01+80H+08H,Y
		STA	!OAM+01+80H+0CH,Y
;		CLC
;		ADC	#008H
;		STA	!OAM+01+80H+10H,Y
;		STA	!OAM+01+80H+14H,Y
;		CLC
;		ADC	#008H
;		STA	!OAM+01+80H+18H,Y
;		STA	!OAM+01+80H+1CH,Y

		LDA	!OAM+02+80H+00H,Y
		INC	A
		STA	!OAM+02+80H+04H,Y
		INC	A
		STA	!OAM+02+80H+08H,Y
		INC	A
		STA	!OAM+02+80H+0CH,Y
;		INC	A
;		STA	!OAM+02+80H+10H,Y
;		INC	A
;		STA	!OAM+02+80H+14H,Y
;		INC	A
;		STA	!OAM+02+80H+18H,Y
;		INC	A
;		STA	!OAM+02+80H+1CH,Y

		LDA	!OAM+03+80H+00H,Y
		STA	!OAM+03+80H+04H,Y
		STA	!OAM+03+80H+08H,Y
		STA	!OAM+03+80H+0CH,Y
;		STA	!OAM+03+80H+10H,Y
;		STA	!OAM+03+80H+14H,Y
;		STA	!OAM+03+80H+18H,Y
;		STA	!OAM+03+80H+1CH,Y
		STA	<WORK0

		LDA	BPLXPS,X
		CMP	#0F1H
		BCC	BPLSET0B0	;max left charcter right set?
;					;yes
		PHY
		LDA	#008H
		STA	<WORK0

BPLSETAB0	EQU	$
		LDA	!OAM+00+080H,Y
		STA	!OAM+00+0C0H,Y
		LDA	!OAM+01+080H,Y
		STA	!OAM+01+0C0H,Y
		LDA	!OAM+02+080H,Y
		STA	!OAM+02+0C0H,Y
		LDA	!OAM+03+080H,Y
		STA	!OAM+03+0C0H,Y

		TYA
		CLC
		ADC	#004H
		TAY

		DEC	<WORK0
		BNE	BPLSETAB0

		PLA
		LSR	A
		LSR	A
		TAY


;		LDA	BPLMKI,X	;player muki = 'right' ?
;		BIT	#002H		;
;		BEQ	BPLSET0AC	; yes: BPLSET0AC
;
;		LDA	BPLXPS,X
;		CMP	#0F9H
;		BCS	BPLSET0AC0
;
;BPLSET0AB1	EQU	$
		LDA	#001H
		STA	!OAMSB+30H,Y	;!OAM (00+C0H or E0H)/04H
		STA	!OAMSB+32H,Y	;!OAM (00+C8H or E8H)/04H
;		STA	!OAMSB+34H,Y	;!OAM (00+D0H or F0H)/04H
;		STA	!OAMSB+36H,Y	;!OAM (00+D8H or F8H)/04H
;
;		BRA	BPLSET0C0
;
;BPLSET0AC	EQU	$
;		LDA	BPLXPS,X
;		CMP	#0F9H
;		BCS	BPLSET0AB1
;
;BPLSET0AC0	EQU	$
;		LDA	#001H
		STA	!OAMSB+31H,Y	;!OAM (00+C4H or E4H)/04H
		STA	!OAMSB+33H,Y	;!OAM (00+CCH or ECH)/04H
;		STA	!OAMSB+35H,Y	;!OAM (00+D4H or F4H)/04H
;		STA	!OAMSB+37H,Y	;!OAM (00+DCH or FCH)/04H
;
		BRA	BPLSET0C0

BPLSET0B0	EQU    $
		TYA
		LSR	A
		LSR	A
		TAY

BPLSET0C0	EQU    $
		LDA	#000H
		STA	!OAMSB+20H,Y	;!OAM (00+80H or A0H)/04H
		STA	!OAMSB+21H,Y	;!OAM (00+84H or A4H)/04H
		STA	!OAMSB+22H,Y	;!OAM (00+88H or A8H)/04H
		STA	!OAMSB+23H,Y	;!OAM (00+8CH or ACH)/04H
;		STA	!OAMSB+24H,Y	;!OAM (00+90H or B0H)/04H
;		STA	!OAMSB+25H,Y	;!OAM (00+94H or B4H)/04H
;		STA	!OAMSB+26H,Y	;!OAM (00+98H or B8H)/04H
;		STA	!OAMSB+27H,Y	;!OAM (00+9CH or BCH)/04H
;
		RTS
;
;
;;;;
;;;;BPLCST	 EQU	$
;;;;;
;;;;	 LDA	BPLYPH,X
;;;;	 BPL	BPC050
;;;;;
;;;;	 LDA	BPLYPS,X
;;;;	 CMP	#0F0H
;;;;	 BCS	BPC060
;;;;;
;;;;	 RTS
;;;;BPC050	 EQU	$
;;;;	 BEQ	BPC060
;;;;;
;;;;	 RTS
;;;;BPC060	 EQU	$
;;;;	 LDA	BPLSET,X
;;;;	 BEQ	BPC070
;;;;;
;;;;	 LDA	<FRCNT
;;;;	 AND	#00000010B
;;;;	 BEQ	BPC070
;;;;;
;;;;	 RTS
;;;;BPC070	 EQU	$
;;;;	 TXA
;;;;	 ASL	A
;;;;	 ASL	A
;;;;	 ASL	A
;;;;	 ASL	A
;;;;	 TAY
;;;;;
;;;;	 LDA	BPLXPS,X
;;;;	 STA	!OAM+00+40H,Y
;;;;;
;;;;	 LDA	BPLYPS,X
;;;;	 STA	!OAM+01+40H,Y
;;;;;
;;;;	 LDA	#00EH
;;;;	 STA	<WORKA		;Mario color set
;;;;	 LDA	BPLIND
;;;;	 BEQ	BPC080
;;;;
;;;;	 LDA	#00AH
;;;;	 STA	<WORKA		;Luige color set
;;;;BPC080	 EQU	$
;;;;	 LDA	BPLMKI,X
;;;;	 TAX
;;;;	 PHA
;;;;	 LDA	BPLATD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bonus enemy initail		     %
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ENINOD		EQU	$
		BYTE	TG,TG,TG,TG,TG
		BYTE	HE,HE,HE,HE,HE
		BYTE	TG,HE,TG,HE,TG
		BYTE	TG,KN,TG,KN,TG
		BYTE	HE,KN,HE,KN,HE
		BYTE	KN,KN,KN,KN,KN
;
;
;-- Fire --
BENINT	 EQU	$
	 LDA	BPLSTF
	 ORA	BPLSTF+1
	 ORA	BPLEND	     ; 8/31
	 BNE	BEIRTS	     ; Game Pause ?
;
	 INC	<PL2CNT1      ; No.
	 LDA	<PL2CNT1      ; No.
	 AND	#1FH
	 BNE	BEI0E0
;
	 INC	BF2ICT
	 BNE	BEI0E0	     ; Fire 2 set ok ?
;
	 JSR	FIRSET	     ; Yes!
	 TXA
	 BMI	BEI0E0
;
	 LDA	#10H
	 STA	BENYSD,X
;
	 LDA	#BFIR2
	 STA	BENMYN,X
BEIRTS	 EQU	$
	 RTS
;
BEI0E0	 EQU	$
	 LDA	<PL2CNT1
	 CMP	#80H
	 BNE	BEI000
;
	 INC	BFIICT
	 LDA	BFIICT
	 AND	#00000111B
	 BNE	BEI000
;---- Fire initial -----
FIRSET	 EQU	$
	 LDX	#06H
	 JSR	BENSET
	 TXA
	 BMI	BFII00	     ; Full area ?
;
	 DEC	BENICT	     ; No.
;
	 CPX	#05H
	 BCS	FST010	     ; Fire Area ?
;			     : No.
	 JMP	BENCLR
;
FST010	 EQU	$
	 LDA	BFIICT
	 LSR	A
	 AND	#1
	 TAY
	 LDA	BFIIXS,Y
	 STA	BENXSD,X
	 LDA	BFIIXD,Y
	 STA	BENXPS,X
;
	 JSL	>BRANDM
;
	 LDA	!BRND
	 AND	#1
	 TAY
	 LDA	BPLYPS,Y
	 STA	BENYPS,X
;
	 LDA	#BFIRE
	 STA	BENMYN,X
;
	 LDA	#00H
	 STA	BENYSD,X
	 STA	BENSTT,X
;
	 JSR	BERMIT
	 LDA	#20H
	 STA	BENTIM,X
;
		LDA	#017H		;S.E.(fire appear)
		STA	!SOUND3		;

	 RTS
;
BERMIT	 EQU	$
	 LDA	#0
	 STA	BENYPH,X
	 STA	BENSTT,X
	 STA	EFRBGN,X
	 STA	!BENEND,X
	 STA	BKNPCT,X
	 STA	BENOBJ,X
	 STA	BENSTF,X
	 STA	BENCTM,X
	 STA	BENSF2,X
	 STA	BENTIM,X
	 STA	BENWSD,X
;
BFII00	 EQU	$
	 RTS
;
BEI000	 EQU	$
	 LDA	BENICT
	 CMP	#ENCNT	     ; Now #05H
	 BEQ	BFII00	     ; All end ?
;			     : No.
;;;; Toge Check
	 LDA	<PL2CNT1
	 AND	#0FFH
	 BNE	BFII00
;
		PHX				; (X) push
	 LDA	TGMODE
	 ASL	A
	 ASL	A
	 ADC	TGMODE
	 ADC	BENICT
	 TAX
	 LDA	>ENINOD,X
		PLX				; (X) pull
;
	 JSL	>JSRSUB
TGD	 WORD	TOGEST	     ; Toge
HED	 WORD	HAE0ST	     ; Hae
KND	 WORD	KANIST	     ; Kani
;
TG	 EQU	(TGD-TGD)/2
HE	 EQU	(HED-TGD)/2
KN	 EQU	(KND-TGD)/2
;
;
;
;
;
;---------------------------------
KANIST	 EQU	$
	 JSR	TOGEST
	 TXA
	 BMI	KST000
;
	 LDA	#BKANI
	 STA	BENMYN,X
;
	 LDA	BKNKCT
	 BEQ	KST000
;
	 DEC	BKNKCT
	 LDA	#01H
	 STA	BKNPCT,X
;
	 JSR	BENIS0	     ; Hi speed set !!
KST000	 EQU	$
	 RTS
;
;---------------------------------
HAE0ST	 EQU	$
	 JSR	TOGEST
	 TXA
	 BMI	BHEI00
;
	 LDA	#BHAE0
	 STA	BENMYN,X
BHEI00	 EQU	$
	 RTS
;
;---------------------------------
TOGEST	 EQU	$
	 LDX	#04H
BENSET	 EQU	$
BENI10	 EQU	$
	 LDA	BENCMD,X
	 BEQ	BENI20
	 DEX
	 BPL	BENI10
;
BENI18	 EQU	$
	 RTS
;
BENI20	 EQU	$
	 INC	BENICT
;
BENST2	 EQU	$
	 LDA	#BMOVE
	 STA	BENCMD,X
;
	 LDA	#20H
	 STA	BENYPS,X
;
	 LDA	#0
	 STA	BENYSD,X
	 LDA	#BTOGE
	 STA	BENMYN,X
	 JSR	BERMIT
;
	 LDA	#30H
	 STA	BENOBJ,X
;
BENIS0	 EQU	$
	 LDA	BENICT
	 AND	#01H
	 TAY
	 LDA	BENIXD,Y
	 STA	BENXPS,X
;
BENISD	 EQU	$
	 LDA	BENICT
	 CMP	#05H
	 BNE	BSST00
;
	 LDA	!LASTFG1
	 BEQ	BSST00	     ; Last ?
;			     : Yes !
	 STA	!BENEND,X
;
	 INY
	 INY
	 INY
BSST00	 EQU	$
	 LDA	BENIXS,Y
	 STA	BENXSD,X
BENI80	 EQU	$
	 RTS
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;%	 Bonus enemy			     %
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
BENEMY	 EQU	$
	 DEC	BENOMC
	 BPL	BEN0F0
;
	 LDA	#0DH
	 STA	BENOMC
BEN0F0	 EQU	$
;
	 LDX	#ALCNT-1     ; Now #0CH
BEN000	 EQU	$
	 STX	BENIND
;
	 TXA
	 CLC
	 ADC	BENOMC
	 TAY
	 LDA	BEOMAD,Y
	 STA	BENOMD
;
	 JSL	>BRANDM	      ; Randam calc
;
	 JSR	BEMAIN	     ; Controle main
	 DEX
	 BPL	BEN000
;
BENRTS	 EQU	$
	 RTS
;
BEMAIN	 EQU	$
	 LDA	BENSTF,X     ; Timer DEC
	 BEQ	BEMA00
;
	 DEC	BENSTF,X
BEMA00	 EQU	$
	 LDA	BENSF2,X
	 BEQ	BE0MFA
;
	 DEC	BENSF2,X
BE0MFA	 EQU	$
	 LDA	BENCMD,X
	 BEQ	BENRTS
;
	 JSL	>JSRSUB
BM0	 WORD	BENRTS
BM1	 WORD	BENMV0	     ; Normal move
BM2	 WORD	BENMV1	     ; Ball
BM3	 WORD	BENFIL	     ; Fail
;
EINIT	 EQU	(BM0-BM0)/2
EMOVE	 EQU	(BM1-BM0)/2
ESTOP	 EQU	(BM2-BM0)/2
EFAIL	 EQU	(BM3-BM0)/2
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;%	 Enemy move			     %
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
BENMV0	 EQU	$
	 LDA	BENSTF,X
	 ORA	BENSF2,X
	 ORA	BPLEND
	 BEQ	BE0MF0	     ; Stop ?
;
	 JSR	BENBGC	     ; BG check
	 JSR	BPOWCK	     ; POW fail check !!
;
	 LDA	BENMYN,X
	 CMP	#BCOIN
	 BEQ	BEMA13	     ; Coin is Anather !!
;
		JMP	BENCST
;		JMP	BENCSR	     ; Only Display & cross
;
BE0MF0	 EQU	$
	 LDA	BENCTM,X
	 BEQ	BE0MF8
;
	 DEC	BENCTM,X
BE0MF8	 EQU	$
	 LDA	!BENOBJ,X
	 BEQ	BEMA13
;
	 DEC	!BENOBJ,X
BEMA13	 EQU	$
	 LDA	BENTIM,X
	 BEQ	BEMA10
;
	 DEC	BENTIM,X
BEMA10	 EQU	$
;
BEMM00	 EQU	$
	 LDA	#00000001B   ; Muki set !
	 LDY	BENXSD,X
	 BPL	BE0M00
	 LDA	#00000010B
BE0M00	 EQU	$
	 STA	BENMKI,X
;
	 LDA	#00000100B
	 LDY	BENYSD,X
	 BPL	BE0M10
	 LDA	#00001000B
BE0M10	 EQU	$
	 STA	BENYMK,X
;
;---------------------------
	 LDA	BENMYN,X
	 JSL	>JSRSUB
BEN00	 WORD	BTOGMV	     ; Toge
BEN01	 WORD	BTO2MV	     ; Toge 2
BEN02	 WORD	BKANMV	     ; Kani
BEN03	 WORD	BHAEMV	     ; Hae
BEN04	 WORD	BFIRMV	     ; Fire
BEN05	 WORD	BFI2MV	     ; Fire 2
BEN06	 WORD	BFI3MV	     ; Fire 3
DAM01	 WORD	BFIRMV	     ; Dummy
DAM02	 WORD	BFI2MV	     ; Dummy 2
DAM03	 WORD	BFI3MV	     ; dummy 3
BEN07	 WORD	BKAMMV	     ; Kame
BEN08	 WORD	BCONMV	     ;7Coin
;--- Item --
BEN10	 WORD	BMUSMV	     ;8	 Mush
BEN11	 WORD	BFLWMV	     ;9	 Flower
BEN12	 WORD	BSTRMV	     ;A	 Star
;--- Jumping Block ----
BEN13	 WORD	BBLCMV	     ;B	 Block
;
;-- Enemy No. ----
BTOGE	 EQU	(BEN00-BEN00)/2
BTOG2	 EQU	(BEN01-BEN00)/2
BKANI	 EQU	(BEN02-BEN00)/2
BHAE0	 EQU	(BEN03-BEN00)/2
BFIRE	 EQU	(BEN04-BEN00)/2
BFIR2	 EQU	(BEN05-BEN00)/2
BFIR3	 EQU	(BEN06-BEN00)/2
BCOIN	 EQU	(BEN08-BEN00)/2
;-- Item No.--
BITEM	 EQU	(BEN10-BEN00)/2
BMUSH	 EQU	BITEM
BFLWR	 EQU	BMUSH+1
BSTAR	 EQU	BFLWR+1
;-- Block No.--
BBLCK	 EQU	BSTAR+1
;
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;%	 Jumping "?" Block		     %
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
BBLCMV	 EQU	$
	 JSR	BEXCLC
	 JSR	BEYCLC
;
	 LDA	BENYSD,X
	 BMI	BBCM18
;
	 CMP	#7DH
	 BCS	BBCM20
;
BBCM18	 EQU	$
	 INC	BENYSD,X
	 INC	BENYSD,X
	 INC	BENYSD,X
;
BBCM20	 EQU	$
	 LDA	BENYPS,X
	 CMP	#0E0H
	 BCC	BBCM00		;block display out?
;
	     LDA    BENYPH,X
	     BNE    BBCM00
;				;yes
	 JMP	BENCLR
BBCM00	 EQU	$
	 JSR	BENCST
BKAMMV	 EQU	$
	 RTS
;
;
;
;
;
;
;
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;%	 Item move			     %
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;========Flowr=====================
BFLWMV	 EQU	$
	 LDA	#00H
	 STA	BENXSD,X
;========Mushroom==================
BMUSMV	 EQU	$
;========Star======================
BSTRMV	 EQU	$
	 JSR	BEXCLC
	 JSR	BEYCLC
	 JSR	BENBGC
;
	 INC	BENYSD,X
;
	 LDA	BENMYN,X
	 CMP	#BSTAR
	 BEQ	BSTM00
;
	 INC	BENYSD,X
;
	 LDA	BENCRB,X
	 AND	#00000011B
	 AND	BENMKI,X
	 BEQ	BMSH10	     ; LR BG Check  !!
;
	 JSR	BENTUR
;
BMSH10	 EQU	$
BSTM00	 EQU	$
	 LDA	BENYPH,X		;out of display ?
;	 BNE	STMV90			;
		BEQ	BMSH01		;  no: BMSH01

		LDA	BENYPS,X	;our of display ?
		CMP	#0F0H		;
		BCC	STMV90		; yes: STMV90
;
BMSH01		EQU	$
	 LDA	BENCRB,X
	 AND	#00000100B
	 BEQ	BMSH00
;
	 JSR	BYPSRV
;
	 LDA	BENMYN,X
	 CMP	#BSTAR
	 BNE	BMSH05
;
	 LDA	BENYSD,X
	 BMI	BMSH05
;
	 LDA	#0DCH
	 STA	BENYSD,X     ; Star jumping
BMSH05	 EQU	$
	 JSR	BPOWCK
;
BMSH00	 EQU	$
	 LDY	BENMYN,X
	 LDX	!BENCAD,Y
	 LDA	<FRCNT
	 LSR	A
	 LSR	A
	 LSR	A
	 AND	#00000110B   ; Flashing (color 4-7 nothing)
;
	 JSR	BENCS0
;
	 JSR	BENPLC
STMV90	 EQU	$
	 RTS
;
;
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;%	 Coin move			     %
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;********* Bunus coin *************
BCONMV	 EQU	$
;
	 LDY	BENTIM,X
	 BEQ	BCOM00
;
	 DEY
	 BNE	BCOCST
;
	 JMP	BENCLR
;
BCOM00	 EQU	$
	 LDA	!BPLEND
	 ORA	!BPSFLG
	 ORA	BENSTF,X     ; 8/30
	 BNE	BCOCST	     ; Game Stop ?
;
	 JSR	BENBGC	     ; No.
;
	 LDA	BENSTT,X
	 BEQ	BCMV50	     ; Jumping move ?
;
	 JSR	BEXCLC	     ; Yes !!
	 JSR	BEYCLC
;
	 INC	BENYSD,X
	 INC	BENYSD,X
;
	 LDA	BENYPS,X
	 CMP	#0E0H
	 BCC	COMV25
;
	 LDA	#00H
	 STA	BENCMD,X     ; End
	 RTS
;
COMV25	 EQU	$
BCMV50	 EQU	$
	 JSR	BENPLC		; Cross player !
	 INC	BENCNT,X
;
BCOCST	 EQU	$
	 MEM16
	 IDX16
	 REP	#00110000B	;memory,index 16bit mode
;
	 LDA	BENOMD
	 AND	#00FFH
	 CLC
	 ADC	#0100H
	 TAY
;
	 MEM8
	 SEP	#00100000B	;memory 8bit mode
;
	 LDA	BENTIM,X
	 BEQ	COCS23	     ; Flashing ? (obj set 00-10 chenge)
;
	 LDA	!OAM+01H     ; Yes !!
	 CMP	#0F0H
	 BEQ	COCS25	     ; oam no set? (ypos = F0?)
;
	 LDA	!OAM+11H
	 CMP	#0F0H
	 BNE	COCS23	     ; First OAM Use Ok ?
;
	 LDY	#0010H	       ; Yes! 1100H or 1110H index Use. !!
	 BNE	COCS23
;
COCS25	 EQU	$
	 LDY	#0000H
COCS23	 EQU	$
	 LDA	!TWODSP
	 CMP	#0BH
	 BNE	COCS28	     ; "?" Game ?
;
	 LDA	BENCRB,X     ; Yes !
	 AND	#00000011B
	 BEQ	COCS28
;
	 IDX8
	 SEP	#00010000B	;index 8bit mode
;
	 RTS		     ;no set
;
COCS28	 EQU	$
	 LDA	#00H	     ; No.
	 CMP	BENOBJ,X
;
	 LDA	#00100010B   ;dokan wakidashi coin check
	 BCS	COCS13	     ; ENOBJ=0?
;
COCS26	 EQU	$
	 LDA	#00010010B   ; Non 0 !!
COCS13	 EQU	$
	 STA	!OAM+03,Y
;
	 LDA	BENYPS,X
	 STA	!OAM+01,Y
	 LDA	BENXPS,X
	 SEC
	 SBC	#004H	     ;oam 4charmode hosei
	 STA	!OAM+00,Y
;
	 LDA	BENTIM,X
	 BEQ	BCC020	     ; Flash ?
;			     : Yes !
	 IDX8
	 SEP	#00010000B	;index 8bit mode
;
	 LSR	A
	 AND	#7
	 TAX
;
	 LDA	COCHMD,X
	 STA	!OAM+02,Y
;
	 LDX	BENIND
;
;
	 LDA	#00000010B	;coin get flashing atribute set
	 STA	!OAM+03,Y
;
	 IDX16
	 REP	#00010000B	;index 16bit mode
;
	 BRA	BCC050
;
BCC020	 EQU	$
	 PHY
;
	 IDX8
	 SEP	#00010000B	;index 8bit mode
;
	 LDA	BENCNT,X
	 LSR	A
	 LSR	A
	 CLC
	 ADC	BENIND
	 AND	#0003H
	 TAY
	 LDA	COCDT,Y
;
	 IDX16
	 REP	#00010000B	;index 16bit mode
;
	 PLY
	 STA	!OAM+02,Y
BCC050	 EQU	$
;
	 MEM16
	 REP	#00100000B	;memory 16bit mode
;
	 TYA
	 LSR	A
	 LSR	A
	 TAY
	 LDA	#002H
	 STA	!OAMSB+00H,Y	;!OAM (00+00H or 10H or BEOMAD)/04H
;
	 MEM8
	 IDX8
	 SEP	#00110000B	;memory,index 8bit mode
;
	 RTS
;
;
;========Toge 2=========Fole turn============
BTO2MV	 EQU	$
;===============================
ENXCL0	 EQU	$
	 LDA	BENXSD,X
	 PHA
;
	 LDA	BENOBJ,X
	 BEQ	EXC000
;
	 LDY	BENMKI,X
	 LDA	ENDKXS-1,Y
	 STA	BENXSD,X
EXC000	 EQU	$
	 JSR	BEXCLC
	 PLA
	 STA	BENXSD,X
	 RTS
;
;
;========Hae ================
BHAEMV	 EQU	$
	 JSR	ENCLCK	     ; Clear check !!
;--- Move Main --
	 LDY	BENTIM,X
	 BEQ	BHMV00	     ; Flor Stop ?
;
	 DEY		     ; Yes !
	 BNE	BHMV20	     ; End ?
;
	 LDA	#0E4H	     ; Yes ! Jump
	 STA	BENYSD,X
;
BHMV00	 EQU	$
;;	 JSR	BEXCLC
	 JSR	ENXCL0
	 JSR	BEYCLC
;
	 LDA	BENYSD,X
	 BMI	BHMV10
;
	 CMP	#40H
	 BCS	BHMV20
;
BHMV10	 EQU	$
	 INC	BENYSD,X
;
BHMV20	 EQU	$
	 JSR	BENBGC
;
	 LDA	BENCRB,X
	 AND	#00000100B
	 BNE	BHMV30	     ; On floor ?
;
	 LDA	BENCNT,X
	 CLC
	 ADC	#04H
	 STA	BENCNT,X
	 JMP	BHMV50
;
;--------On floor pros---------
BHMV30	 EQU	$
	 ASL	A
	 STA	BENCNT,X     ; #08H
;
	 LDA	BENTIM,X
	 BNE	BHMV38
;
	 LDA	#010H
	 STA	BENTIM,X     ; Stop time set !!
BHMV38	 EQU	$
;
	 JSR	BYPSRV
;-------
	 JSR	BPOWCK	     ; POW & block Check
;-------
	 LDA	!BENOBJ,X
	 BEQ	BHMV50
;
	 LDA	#00H
	 STA	BENTIM,X
	 STA	BENYSD,X
;
	 LDA	<FRCNT
	 STA	BENCNT,X
BHMV50	 EQU	$
;
	 JMP	BENCSR
;
;
;===== In Dakan End check !! ====
ENCLCK	 EQU	$
	 LDA	BENYPS,X
	 CMP	#0A0H
	 BCC	BENME0
;
	 LDY	BENMKI,X
	 LDA	BENXPS,X
	 CMP	BTENXB-1,Y
	 BNE	BTM000
;
	 LDA	#060H
	 STA	!BENOBJ,X
	 BNE	BENME0
;
BTM000	 EQU	$
	 CMP	BTENXD-1,Y
	 BNE	BENME0
;
	 LDA	#20H
	 STA	BENYPS,X
;
	 LDA	!RANDAM
	 AND	#01H
	 TAY
	 LDA	BENIXD,Y
	 STA	BENXPS,X
	 EOR	BENXSD,X
	 BPL	BENMD0
;
	 JSR	BENTUR
BENMD0	 EQU	$
	 PLA
	 PLA
;
BENME0	 EQU	$
	 RTS
;
;========Toge 1===============================
BTOGMV	 EQU	$
;========Kani==============================
BKANMV	 EQU	$
	 JSR	ENCLCK	     ; Out check !!
;
	 JSR	ENXCL0
	 JSR	BEYCLC
;
	 LDA	BENYSD,X
	 BMI	BENM00
;
	 CMP	#40H
	 BCS	BENM10
;
BENM00	 EQU	$
	 INC	BENYSD,X
	 INC	BENYSD,X
BENM10	 EQU	$
	 JSR	BENBGC
;
	 LDA	BENCRB,X
	 AND	#00000100B
	 BNE	BENM18	     ; On floor ?
;
	 STA	BENCNT,X     ; No.
	 JMP	BENM20	     ; Don't character chenge
;
;--------On floor pros---------
BENM18	 EQU	$
	 LDA	BENYSD,X
	 PHA
	 JSR	BYPSRV
;-------
	 JSR	BPOWCK	     ; POW & block Check
;-------
	 LDA	BENMYN,X
	 CMP	#BKANI
	 BNE	BENM19
;
	 INC	BENCNT,X
BENM19	 EQU	$
	 LDA	!BENEND,X
	 ORA	!BKNPCT,X
	 BEQ	BENM1A	     ; Hi speed ?
;
	 INC	BENCNT,X
BENM1A	 EQU	$
	 INC	BENCNT,X
;
BENM1B	 EQU	$
	 LDA	!BENOBJ,X
	 BEQ	BENM1C
;
	 INC	BENCNT,X
BENM1C	 EQU	$
	 PLA
	 CMP	#10H
	 BCC	BENM20
;
	 LDA	BENWSD,X
	 BEQ	BENM20	     ; Block jumped ?
;
	 STA	BENXSD,X     ; Yes !! Before speed set !!
;
	 LDA	#00H
	 STA	BENWSD,X
BENM20	 EQU	$
;
;--- Character set & Cross check
BENCSR	 EQU	$
	 JSR	BENCST	     ; Oam set
	 JSR	BENENC	     ; Vs enemy
	 JSR	BENPLC	     ; Vs player

	 RTS
;
;=============================================
BYPSRV	 EQU	$	     ; Enemy Y position revise
	 LDA	BENYPS,X
	 AND	#0F0H
	 STA	BENYPS,X
;
	 LDA	#0
	 STA	BENYSD,X
BYRSRT	 EQU	$
	 RTS
;
;====Enemy POW Check=====
BPOWCK	 EQU	$
	 LDA	BENYSD,X
	 BMI	BYRSRT
;
	 LDA	BENOBJ,X
	 BNE	BYRSRT
;
	 LDA	EFRBGN,X
	 CMP	#BLK3D3
	 BEQ	BPCKE0	     ; Up Block check
;
	 LDA	BPOWTM
	 BEQ	BPCK00	     ; POW Block check
;
BPCKE0	 EQU	$
;;;;;;;;	 LDA	04F1H
;;;;;;;;	 ORA	#04H
;;;;;;;;	 STA	04F1H	     ; (S)
		LDA	#002H
		STA	!SOUND0
;
	 LDA	#00H
	 STA	BENSTF,X
	 STA	BENSF2,X
;
	 LDA	BENMYN,X
	 CMP	#BITEM
	 BCS	BPCK22	     ; Item ?
;
	 CMP	#BKANI	     ; No..
	 BNE	BPCKE8	     ; Kani ?
;
	 LDA	BENCMD,X
	 CMP	#2		;(BSTOP)
	 BEQ	BPCKE8
;
	 LDA	BKNPCT,X     ; Yes ! Kick counter check !
	 BNE	BPCKE8
;
	 LDA	#01H
	 STA	BKNPCT,X
;
	 LDA	BENXSD,X
	 JSR	NXSDS0	     ; Next Speed up
	 JMP	BPCK20
;
BPCKE8	 EQU	$
	 LDA	BENCMD,X
	 EOR	#3
	 STA	BENCMD,X     ;Fail up
;
	 CMP	#1
	 BNE	BPCK20	     ; Return ?
;
BPCK18	 EQU	$	     ; Yes !
	 LDY	BENMKI,X
	 DEY
	 JSR	BENISD
	 LDA	#00H
	 BEQ	BPCK21
;
BPCK20	 EQU	$
	 LDA	#0FFH	     ; Stop Time set !!
BPCK21	 EQU	$
	 STA	BENTIM,X
BPCK22	 EQU	$
	 LDA	EFRBGN,X
	 CMP	#BLK3D3
	 BNE	BPCK28	     ; Block cross ?
;
	 LDA	BENCRB,X
	 AND	#11000000B
	 CMP	#11000000B
	 BEQ	EPCK25	     ; Center ?
;
	 LDY	#1	     ; No.
	 ASL	A
	 BCC	EPCK26	     ; Which speed set
;
	 DEY
EPCK26	 EQU	$
	 LDA	BENXSD,X
	 STA	BENWSD,X     ; Now speed save !!
;
	 JSR	BENISD
;
EPCK25	 EQU	$
;
BPCK28	 EQU	$
	 LDA	#0E0H
	 STA	BENYSD,X
;
BPCK00	 EQU	$
	 RTS
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;%	 Enemy character set		     %
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
;
BENCST	 EQU	$
	 LDY	BENMYN,X
	 CPY	#BFIRE
	 BEQ	ENCS08
	 CPY	#BFIR2
	 BNE	ENCS00
;
ENCS08	 EQU	$
	 LDA	BENTIM,X
	 BEQ	ENCS00
;
	 LSR	A
	 LSR	A
	 AND	#0FH
	 TAY
	 LDA	BFIFLD,Y
	 STA	BENCNT,X
;
;;k;;	      LDX    #BSTRCD-BENCD0  ; C data index
	LDX	#BENCDPL
	 LDA	#00000110B   ; Color
	 JMP	BENCS0
;
ENCS00	 EQU	$
	 LDX	!BENCAD,Y
	 LDA	!BENATD,Y
BENCS0	 EQU	$
	 STA	<WORK0	      ; Color
	 STX	<WORK1	      ; Chr no.index
;
	 LDX	BENIND
;
	 LDA	BENYPH,X
	 BEQ	ENCS10	     ; Display out ?
;
		LDA	BENYPS,X
		CMP	#0F0H
		BCS	ENCS10

	 RTS		     ; Yes!
;
ENCS10	 EQU	$
	 LDY	BENMYN,X
;
	 LDA	!BENEND,X
	 BEQ	BECF08	     ; Last enemy ?
;
	 LDA	#00001100B   ; Yes !!
	 STA	<WORK0	      ; Color revise
BECF08	 EQU	$
	 LDA	BENYPS,X
	 STA	<WORK3
;
	 LDY	#00100000B   ;priority set
;
	 LDA	BENCMD,X
	 CMP	#ESTOP
	 BCC	BECF09
;
	 LDA	BENMYN,X
	 CMP	#BHAE0
	 BEQ	BECF09
;
	 CMP	#BTOG2+1
	 BCS	BECF07
;
	 INC	<WORK3
	 INC	<WORK3
;
;;k;;	      LDA    #BBALCD-ENCD00
	LDA	#BALCDPL
	 STA	<WORK1
BECF07	 EQU	$
	 LDY	#10100000B
BECF09	 EQU	$
;
	 LDA	!BENOBJ,X	;dokan in obj?
	 BEQ	BECF10
;
	 DEC	<WORK3
	 DEC	<WORK3
	 DEC	<WORK3
;
	 LDY	#00010000B   ; yes !
BECF10	 EQU	$
	 LDA	BENCMD,X
	 CMP	#EMOVE
	 BEQ	BECF11	     ; Fail ?
;
	 LDA	BENMYN,X
	 CMP	#BTOGE
	 BEQ	BECF11
;
	 TYA		     ; Yes !!
	 ORA	#10000000B
	 TAY
BECF11	 EQU	$
	 STY	<WORK2	      ; BG>OBJ
;
	 LDY	BENOMD
;
	 LDA	BENXPS,X
	 CLC
	 ADC	ENXRVS
	 STA	!OAM+00+100H,Y
;
	 LDA	#00H
	 STA	ENXRVS	     ; X revise clear !!
;
	 LDA	<WORK3
	 STA	!OAM+01+100H,Y
;
	 LDA	BENMYN,X
	 CMP	#BKANI
	 BNE	BECF28	     ; kani set?(LR Flip chenging?)
;
	 LDA	BENCNT,X     ; Yes !
	 LDY	#00000000B
	 AND	#00001000B
	 BEQ	BECF25
;
	 LDY	#01000000B
BECF25	 EQU	$
	 TYA
	 LDY	BENOMD
	 JMP	BECS00
;==
BECF28	 EQU	$
	 LDA	BENMKI,X
	 LSR	A
;
	 LDA	#00000000B
	 BCC	BECS00
	 LDA	#01000000B
BECS00	 EQU	$
	 ORA	<WORK0	      ; Color
	 ORA	<WORK2	      ; Bg>Obj , V flip
	 STA	!OAM+03+100H,Y
;
	 LDA	BENMYN,X
	 CMP	#BKANI
	 BNE	BECS06
;
	 LDA	BKNPCT,X
	 LDX	<WORK1
	 AND	#1
	 BNE	BECS08	     ; kani 2of !!
	 BEQ	BECS10	     ; Kani 2of Kicked ?
;
	 LDA	#000H
	 BRA	BECS07
BECS06	 EQU	$
	 LDA	BENCNT,X     ; Yes !
BECS07	 EQU	$
	 LDX	<WORK1
	 AND	#00001000B
	 BEQ	BECS10
;
BECS08	 EQU	$
	 INX
BECS10	 EQU	$
;
	 LDA	BENCD0,X
	 STA	!OAM+02+100H,Y
;
;
	 LDA	!OAM+00+100H,Y
	 CMP	#0F1H
	 BCC	BECS20			;max left charcter right set?
;					;yes
	 LDA	!OAM+00+100H,Y
	 STA	!OAM+04+100H,Y
	 LDA	!OAM+01+100H,Y
	 STA	!OAM+05+100H,Y
	 LDA	!OAM+02+100H,Y
	 STA	!OAM+06+100H,Y
	 LDA	!OAM+03+100H,Y
	 STA	!OAM+07+100H,Y
;
	 TYA
	 LSR	A
	 LSR	A
	 TAY
	 LDA	#003H
	 STA	!OAMSB+01+040H,Y
	 BRA	BECS30
BECS20	 EQU	$
	 TYA
	 LSR	A
	 LSR	A
	 TAY
BECS30	 EQU	$
	 LDA	#002H
	 STA	!OAMSB+00H+040H,Y	;!OAM (00+040H+BEOMAD)/04H
;
BECS80	 EQU	$
	 LDX	BENIND
	 RTS
;
;========Cross vs enemy========================
BENENC	 EQU	$
	 CPX	#0
	 BEQ	BEE090
;
	 TXA
	 CLC
	 ADC	<FRCNT
	 LSR	A
	 BCC	BEE090	     ; 8/22 Test !!
;
	 TXA
	 TAY
	 DEY
	 STY	<WORKF
BEE080	 EQU	$
	 JSR	BEEC00
	 DEC	<WORKF
	 BPL	BEE080
BEE090	 EQU	$
	 RTS
;
BEEC00	 EQU	$
	 LDY	<WORKF
	 LDA	BENMYN,Y
	 CMP	#BFIRE
	 BEQ	BECS80
	 CMP	#BFIR2
	 BEQ	BECS80
;
	 LDA	BENCMD,Y
	 BEQ	BECS80		; LDX BENIND  RTS
;
	 CMP	#EFAIL
	 BCS	JPEC90	     ; Moving ?
;
	 LDA	BENOBJ,X     ; Yes !
	 ORA	BENOBJ,Y
	 BEQ	BEEC06	     ; Seting ?
;
JPEC90	 EQU	$
	 JMP	BEEC90
;
BEEC06	 EQU	$
	 LDA	BENCTM,X     ; No.
	 BEQ	BEEC08
;
	 LDA	BENCTM,Y
	 BNE	BEEC90
BEEC08	 EQU	$
	 LDX	<WORKF
	 LDY	#4
	 JSR	BECRST
	 LDX	BENIND
;
	 LDY	#0
	 JSR	BECRST
;
	 JSR	CROJCK
	 BCC	BEEC90
;
	 LDY	<WORKF
	 LDA	BENCRB,X
	 AND	BENCRB,Y
	 AND	#00000100B
	 BEQ	BEEC90	     ; Walking ?
;			     : Yes!
	 LDA	BENSTF,X
	 BNE	BEEC10
;
	 LDA	#28H
	 STA	BENCTM,X
;
	 LDA	BENCMD,X
	 CMP	#EMOVE
	 BNE	BEEC12
;
	 LDA	#10H
	 STA	BENSTF,X
	 LDA	#08H
	 STA	BENCNT,X
;
BEEC12	 EQU	$
	 LDA	BENXPS,X
	 CMP	BENXPS,Y
	 ROR	A
	 EOR	BENXSD,X
	 BMI	BEEC13
;
	 JSR	BENTUR
BEEC13	 EQU	$
BEEC10	 EQU	$
	 LDA	BENSTF,Y
	 BNE	BEEC20
;
	 LDA	#28H
	 STA	BENCTM,Y
;
	 LDA	BENCMD,Y
	 CMP	#EMOVE
	 BNE	BEEC21
;
	 LDA	#10H
	 STA	BENSTF,Y
	 LDA	#08H
	 STA	BENCNT,Y
;
BEEC21	 EQU	$
	 LDA	BENXPS,Y
	 CMP	BENXPS,X
	 ROR	A
	 EOR	BENXSD,Y
	 BMI	BEEC22
;
	 LDX	<WORKF
	 JSR	BENTUR
BEEC22	 EQU	$
	 LDY	<WORKF
	 LDX	BENIND
;
BEEC20	 EQU	$
BEEC90	 EQU	$
	 LDX	BENIND
	 RTS
;
;=============================
BENTUR	 EQU	$
	 LDA	BENXSD,X
	 EOR	#0FFH
	 CLC
	 ADC	#1
	 STA	BENXSD,X
	 RTS
;
;====(Y)->Player muki=======
BEPXCH	 EQU	  $
	 LDA	BPLXPS,Y
	 LDY	#0
	 SBC	BENXPS,X
	 BPL	EPX20
	 INY
EPX20	 EQU	  $
	 RTS
;
;
;========Enemy cross data set=====
BECRST	 EQU	$
	 LDA	BENYPS,X
	 CLC
	 ADC	#06H
	 STA	WORK0,Y
;
	 LDA	#04H
	 STA	WORK2,Y
;
	 LDA	BENXPS,X
	 CLC
	 ADC	#2
	 STA	WORK1,Y
;
	 LDA	BENMYN,X
	 CMP	#BCOIN
;
	 LDA	#0CH
	 BCC	ECRS00	     ; Coin ?
;
	 LDA	#05H	     ; Small size !!
ECRS00	 EQU	$
	 STA	WORK3,Y
BPLRTS	 EQU	$
	 RTS
;
;========Cross vs Player ======================
BENPLC	 EQU	$
	 LDA	BPLCMD
	 CMP	#BCRIM
	 BEQ	BEPCFF
	 CMP	#BMOVE
	 BNE	BPLRTS
BEPCFF	 EQU	$
	 LDA	BPLCMD+1
	 CMP	#BCRIM
	 BEQ	BEPCFE
	 CMP	#BMOVE
	 BNE	BPLRTS	  ;Move ?  ; 8/28
;
BEPCFE	 EQU	$
	 TXA		  ; Yes !
	 CLC
	 ADC	<FRCNT
	 LSR	A
	 BCS	BPLRTS
;
	 LDA	!BENMYN,X
	 CMP	#BFIR3
	 BEQ	ENVP00
;
	 LDA	!BENOBJ,X
	 BNE	BPLRTS
;
ENVP00	 EQU	$
	 LDA	#1
	 STA	<WORKF
BEPC00	 EQU	$
	 LDX	<WORKF
;
	 LDA	BPLCMD,X	  ; 8/28
	 CMP	#BMOVE
	 BNE	BEPCD0
;
	 LDA	BPLSET,X
	 BEQ	BEPCD8
;
BEPCD0	 EQU	$
	 JMP	BEPC30
;----------------------------------------
BEPCD8	 EQU	$
	 LDY	#4
	 JSR	BPCRST
	 LDY	#0
	 LDX	BENIND
	 JSR	BECRST
;
	 JSR	CROJCK
	 LDY	<WORKF
	 BCC	BEPCD0	     ; Cross ?
;			     : Yes !!!!
	 LDA	BENMYN,X
	 CMP	#BITEM
	 BCC	BEPC23	     ; Item ?
;			     : Yes !
;--------Vs Item---------------------
	 JMP	ITEMGT	     ; Item get !!
;--------Vs Coin---------------------
BEPC23	 EQU	$
	 CMP	#BCOIN
	 BNE	BEPC0E
;
;;;;;;;;	 LDA	04F2H
;;;;;;;;	 ORA	#01H
;;;;;;;;	 STA	04F2H	     ;(S)
		LDA	#001H
		STA	!SOUND3
;
	 LDA	#0FH
	 STA	BENTIM,X
;
	 LDA	BPLKCT,Y
	 CLC
	 ADC	#01H
	 STA	BPLKCT,Y
;
	 LDA	BPLKCT
	 CLC
	 ADC	BPLKCT+1     ; ,Y
	 CMP	#05H
	 BNE	PLCO00
;;;
;= = = = = = = = = = = = = = = = = = = =
PLCTED	 EQU	$
	 LDY	#ALCNT-1
	 LDA	#0FFH	     ; All enemy stop !!
PLCE10	 EQU	$
	 STA	BENSTF,Y
	 DEY
	 BPL	PLCE10
;
	 LDY	#01H
	 LDA	BPLKCT
	 CMP	BPLKCT+1
	 BCC	PLCO10
	 INY
PLCO10	 EQU	$
	 STY	!PLOTNO
;
	 LDA	#0C0H
	 STA	BPLEND
;
		LDA	#007H		;S.E.(game end)
		STA	!SOUND2

PLCO00	 EQU	$
	 JSR	SCDISP
	 RTS
;
;--------Vs Enemy---------------------
BEPC0E	 EQU	$
	 LDA	BENCMD,X
	 CMP	#EMOVE
	 BNE	BEPC18	     ; Ball ?
;
BEPC10	 EQU	$
	 LDY	#ALCNT-1
	 LDA	#0FFH	     ; All enemy stop !!
BEPC1E	 EQU	$
	 STA	BENSTF,Y
	 DEY
	 BPL	BEPC1E
;
	 LDA	<WORKF
	 EOR	#01H
	 TAY
;
;	 LDA	#0FFH
	 LDA	#0FEH
;	 STA	BPLSTF,Y
		STA	BPLEND
;
	 LDY	<WORKF

		LDA	#002H
		STA	PLOTNO

		CPY	#001H
		BEQ	BEPC1E0

		LDA	#001H
		STA	PLOTNO

BEPC1E0		EQU	$
;
	 LDA	#20H
	 STA	BENCNT,X
;
	 STA	BPLTIM,Y
;
;;;;;;;;	 LDA	04F4H
;;;;;;;;	 ORA	#01H
;;;;;;;;	 STA	04F4H	     ; (S)
		LDA	#009H
		STA	!SOUND2
;
	 LDA	#BFAIL
	 STA	BPLCMD,Y
;
	 LDA	#0D0H
	 STA	BPLYSD,Y
;
	 LDA	BENMYN,X
	 CMP	#BFIRE
	 BEQ	BEPC29	     ; 8/31
	 CMP	#BFIR2
	 BEQ	BEPC29
;
	 JSR	BEPXCH	     ; Speed -! Player
;
	 INY
	 TYA
	 STA	BENMKI,X
;
BEPC29	 EQU	$
	 LDX	BENIND
	 RTS		; 8/29
	 DEY
;
	 JSR	BENISD
BEPC30	 EQU	$
	 DEC	<WORKF
	 BMI	BEPC05
;
	 JMP	BEPC00
;
BEPC05	 EQU	$
	 LDX	BENIND
	 RTS
;
;--- Kick ----
BEPC18	 EQU	$
;;;;;;;;	 LDA	04F1H
;;;;;;;;	 ORA	#08H
;;;;;;;;	 STA	04F1H	     ; (S)
		LDA	#003H
		STA	!SOUND0
;
	 LDA	BPLXSD,Y
	 LDY	#00H
	 CMP	#00H
	 BMI	BPKK00
	 INY
BPKK00	 EQU	$
	 LDA	BPLKSD,Y
	 STA	BENXSD,X
;
	 LDY	<WORKF
	 LDA	#EFAIL	     ; Fail
	 STA	BENCMD,X
	 LDA	#0E0H
	 STA	BENYSD,X
;
	 LDA	#0CH
	 STA	BPLKTM,Y     ; Player Kick
;
	 LDA	BPLKCT,Y
	 CLC
	 ADC	#1
	 STA	BPLKCT,Y
;
	 LDA	BPLKCT
	 CLC
	 ADC	BPLKCT+1  ; ,Y
	 CMP	#ENCNT	 ;5
	 BEQ	BEPCED	     ; All enemy Kicked ?
;
	 CMP	#ENCNT-1 ;4  ; No.
	 BNE	BEPCRT	     ; Last one ?
;
	 INC	LASTFG1	     ; Last flag on !
;
	 LDX	#4	     ; Yes!!
BEPCE0	 EQU	$
	 LDA	BENCMD,X
	 BEQ	BEPCE1
	 CMP	#EFAIL
	 BCC	BEPCE2	     ; Last enemy surch !
;
BEPCE1	 EQU	$
	 DEX
	 BPL	BEPCE0
	 BMI	BEPCRT
;
BEPCE2	 EQU	$
	 LDA	BENXSD,X
	 JSR	NXSDS0	     ; Next Speed set !!
;
	 LDA	#1
	 STA	BENEND,X     ; High speed set !!!
	 BNE	BEPCRT
;
BEPCED	 EQU	$
	 JSR	PLCTED	     ; Game end & Winner set !!
;
BEPCRT	 EQU	$
;
	 LDX	BENIND
	 LDY	<WORKF
;
	 LDA	#5
	 STA	BPLCHD,Y     ; Kick character set !!
;
	 JSR	SCDISP	     ; Coin count BG dispay !!
BEP090	 EQU	$
	 RTS
;
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;%	 Item  Catch			     %
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ITEMGT	 EQU	$
	 LDA	!BENTIM,X
	 BNE	ITGT90
;
	 JSR	BENCLR
;
;;;;;;;;	 LDA	04F6H
;;;;;;;;	 ORA	#10H
;;;;;;;;	 STA	04F6H	     ; (S)
		LDA	#005H
		STA	!SOUND0
;
	 LDY	<WORKF
	 LDA	#40H
	 STA	ITGTTM,Y
;
	 LDY	#00H
	 LDA	<WORKF
	 BEQ	ITGT00	     ; Luigi ?
;
	 LDY	#ITMNO	     ; Yes !
ITGT00	 EQU	$
	 LDA	!GMITEM+1,Y
	 STA	!GMITEM+2,Y  : Data roteit !!
	 LDA	!GMITEM+0,Y
	 STA	!GMITEM+1,Y  : Data roteit !!
;
	 LDA	!BENMYN,X
	 SEC
	 SBC	#BITEM-1
	 STA	!GMITEM+0,Y


ITGT90	 EQU	$
	 RTS
;
;;
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;%	 Enemy move 1	:Ball		     %
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
BENMV1	 EQU	$
	 LDA	BENSTF,X
	 BNE	BEM160	     ; Pause ?
;
	 LDA	#00H
	 STA	BENCNT,X
;
	 LDA	BENTIM,X     ; No.
	 BNE	BEM1F0	     ; Return ?
;
	 JSR	BENCST	     ; C set
;
	 LDA	#EMOVE
	 STA	BENCMD,X     ; yes !
;
	 LDA	BENWSD,X     ; Next move speed set !!
	 PHA
	 LDA	#00H
	 STA	BENWSD,X
	 PLA
NXSDS0	 EQU	$
	 PHP
	 BPL	NXSS00
	 EOR	#0FFH
	 CLC
	 ADC	#01H
NXSS00	 EQU	$
	 LDY	#00H
	 CMP	#0AH
	 BCC	NXSS10
	 INY
	 INY
NXSS10	 EQU	$
	 CMP	#0CH
	 BCC	NXSS20
	 INY
	 INY
NXSS20	 EQU	$
	 PLP
	 BPL	NXSS30
	 INY
NXSS30	 EQU	$
	 LDA	ENNXSD,Y
	 STA	BENXSD,X
	 RTS
;
;-------------------------------
;
BEM1F0	 EQU	$
	 LDA	<FRCNT
	 AND	#01H
	 BNE	BEM1F5
;
	 DEC	BENTIM,X
BEM1F5	 EQU	$
	 LDA	BENTIM,X
	 CMP	#60H
	 BCS	BEM1F1
;
	 LSR	A
	 LSR	A
	 LSR	A
	 LSR	A
	 LSR	A
	 TAY
	 LDA	<FRCNT
	 AND	XRVSDT,Y
	 BEQ	BEM1F1
;
	 INC	ENXRVS
;
	 LDA	#08H
	 STA	BENCNT,X
BEM1F1	 EQU	$
	 JSR	BENBGC
	 LDA	BENCRB,X
	 AND	#00000100B
	 BEQ	BEM130
;
	 JSR	BYPSRV
	 LDA	#0
	 STA	BENXSD,X
;
	 JSR	BPOWCK
;
BEM130	 EQU	$
	 JSR	BEXGCL
BEM160	 EQU	$
	 JMP	BENCSR	     ; C set & cross
;
;========G calc=============
BEXGCL	 EQU	$
	 JSR	BEXCLC
	 JSR	BEYCLC
;
	 LDA	BENYSD,X
	 BMI	BEM100
;
	 CMP	#40H
	 BCS	BEM110
;
BEM100	 EQU	$
	 INC	BENYSD,X
	 INC	BENYSD,X
BEM110	 EQU	$
	 RTS
;
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;%	 Enemy Fail			     %
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
BENFIL	 EQU	$
	 LDA	BENEND,X
	 BNE	BEMFF0	     ; Last ?
;
	 LDA	BENSTF,X     ; No.
	 BNE	BEMF00	     ; Pause ?
;
BEMFF0	 EQU	$	     ; No.
	 LDA	BENYPS,X
	 CMP	#0E0H
	 BCC	BEM000
;
	 LDA	BENYPH,X
	 BNE	BEM000	     ; In Display ?
;			     : Yes !
BENCLR	 EQU	$
	 LDA	#0
	 STA	BENCMD,X
	 RTS
;
BEM000	 EQU	$
	 JSR	BEXGCL
	 INC	BENYSD,X
;
	 LDA	<FRCNT
	 AND	#1
	 BNE	BEMF00
;
	 LDA	BENXSD,X
	 BEQ	BEMF00
	 BMI	BEMF10
;
	 DEC	BENXSD,X
	 DEC	BENXSD,X
BEMF10	 EQU	$
	 INC	BENXSD,X
;
BEMF00	 EQU	$
	 JMP	BENCST
;
BPW090	 EQU	$
	 RTS
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;%	 Bonus POW			     %
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
BPOW	 EQU	$
;
	 LDA	BPOWTM
	 STA	<WORK0
	 BEQ	BPWCF0
;
	 DEC	BPOWTM
;
	 LSR	A
	 AND	#3
	 TAY
;
	 LDA	BPSVDT,Y
	 STA	!SCCV1
;
BPWCF0	 EQU	$
	 LDA	BPOWCT
	 CMP	#3
	 BEQ	BPW090
;
	 LDA	#98H
	 SEC
	 SBC	!SCCV1
	 STA	OAM+21H
	 LDA	#78H
	 STA	OAM+20H
;
	 LDA	BPOWCT
	 TAY
;
	 LDA	BPWCDT,Y
	 STA	OAM+22H
;
	 LDA	#00000100B
	 STA	OAM+23H
;
	 LDA	#002H
	 STA	!OAMSB+08H		;!OAM (00H+20H)/04H
;
;---- Cross check ----
	 LDX	#1
BPWC00	 EQU	$
	 LDA	BPOWCT
	 CMP	#3
	 BEQ	BPWC10
;
	 LDA	BPLCMD,X
	 CMP	#BMOVE
	 BNE	BPWC10
;
	 LDY	#0
	 JSR	BPCRST
;
	 LDA	#98H
	 STA	<WORK4
	 LDA	#78H
	 STA	<WORK5
;
	 LDA	#10H
	 STA	<WORK7
;
	 LDY	BPOWCT
	 SEC
	 SBC	BPWYAD,Y
	 STA	<WORK6
;
	 JSR	CROJCK
	 BCC	BPWC10
;
	 LDY	BPOWCT
	 LDA	BPWYAD,Y
	 STA	BPLYRV,X     ; Player on Y pos revise !
;
	 LDA	BPLYPS,X
	 SEC
	 SBC	BPLYRV,X     ; Player on Y pos revise !
	 CMP	#8DH
	 BCS	BPWC08
;
	 LDA	BPLYSD,X
	 BMI	BPWC10
;
	 LDA	#00000100B
	 STA	BPLCRB,X
	 BEQ	BPWC10
;
BPWC08	 EQU	$
	 LDA	BPLYPS,X
	 CLC
	 ADC	BPLYRV,X     ; Player on Y pos revise !
	 CMP	#0A1H
	 BCC	BPWC10
;
	 LDA	BPLYSD,X
	 BPL	BPWC10
;
;--- "POW" on !!!!
;;;;;;;;	 LDA	04F2H
;;;;;;;;	 ORA	#08H
;;;;;;;;	 STA	04F2H	     ; (S)
;		LDA	#003H
;		STA	!SOUND0
		LDA	#009H
		STA	!SOUND3
;
	 INC	BPOWCT
;
	 LDA	#0
	 STA	BPLYSD,X
;
	 LDA	#0A9H
	 SEC
	 SBC	BPLYRV,X
	 STA	BPLYPS,X
;
	 LDA	#08H
	 STA	BPLSLD,X
;
	 LDA	#10H
	 STA	BPOWTM
BPWC10	 EQU	$
	 DEX
	 BMI	BPWRTS
	 JMP	BPWC00
BPWRTS	 EQU	$
	 RTS
;
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;%	 Fire 3				     %
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;%	 Fire				     %
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
BFIRMV	 EQU	$
BFI2MV	 EQU	$
BFI3MV	 EQU	$
	 LDA	BENTIM,X
	 BEQ	BFIM10
;---- Star -----------
	 CMP	#20H
	 BNE	BFIM09
;
	 JMP	BENCLR
;
BFIM09	 EQU	$
	 JMP	BENCST
;
;--- Move main---------
BFIM10	 EQU	$
	 JSR	BENCST	     ; C set
;
	 LDY	BENOMD
	 LDA	BENCNT,X
;	 AND	#00011000B
;	 CMP	#002H
;	 BCC	BFIM90
	 AND	#00010000B
	 BEQ	BFIM90

	 LDA	!OAM+03+100H,Y
	 EOR	#11000000B
	 STA	!OAM+03+100H,Y

;	 LSR	A
;	 LSR	A
;	 CLC
;	 ADC	#044H
;	 STA	!OAM+02+100H,Y
;;;;	     AND    #00010000B
;;;;	     BEQ    BFIM90
;
BFIM90	 EQU	$
	 INC	BENCNT,X
	 INC	BENCNT,X
;
	 LDY	BENMKI,X
	 LDA	BENXPS,X
	 CMP	BFIENX-1,Y
	 BNE	BFIMA0	     ; End ?
;
	 LDA	BENMYN,X     ; Yes !!
	 CMP	#BFIRE
	 BNE	BFIMA0	     ; Fire 1 ?
;
	 LDA	#40H	     ; yes!
	 STA	BENTIM,X
BFIMA0	 EQU	$
	 JSR	BENPLC	     ; Vs player
	 JSR	BENBGC
;
	 LDA	BPOWTM
	 BNE	BFIMA3	     ; "POW" block fail !!
;
	 LDA	EFRBGN,X
	 CMP	#BLK3D3
	 BNE	BFIMA8	     ; Up block cross ?
;
BFIMA3	 EQU	$
	 LDA	#40H	     ; yes ! Fail !!!!
	 STA	BENTIM,X
BFIMA8	 EQU	$
	 LDA	BENMYN,X
	 CMP	#BFIRE
	 BNE	BF2000
;
	 JSR	BEXCLC
	 JSR	BEYCLC
;
	 LDA	BENSTT,X
	 AND	#1
	 TAY
;
	 LDA	BENYSD,X
	 CLC
	 ADC	BFIYSD,Y
	 STA	BENYSD,X
	 CMP	BFIYLM,Y
	 BNE	BFIM60
;
	 INC	BENSTT,X
BFIM60	 EQU	$
	 RTS
;--------Fire 2---------
BF2000	 EQU	$
	 CMP	#BFIR3
	 BEQ	BF3000
;
	 LDA	BENCRB,X
	 AND	#00000011B
	 AND	BENMKI,X
	 BEQ	BF2080
;
	 JSR	BENTUR
BF2080	 EQU	$
	 LDA	BENCRB,X
	 AND	#00001100B
	 AND	BENYMK,X
	 BEQ	BF2090
;
	 LDA	BENYSD,X
	 EOR	#0FFH
	 CLC
	 ADC	#01H
	 STA	BENYSD,X
;
BF2090	 EQU	$
	 JSR	BEXCLC
	 JSR	BEYCLC
	 RTS
;
BF3000	 EQU	$
	 JSR	BF2090
	 INC	BENYSD,X     ; G Downing !!
	 INC	BENYSD,X
;
	 LDA	BENYPS,X
	 CMP	#0E0H
	 BCC	BF3010	     ; End ??
;
	 LDA	#00H	     ; Yes!
	 STA	BENCMD,X
BF3010	 EQU	$
	 RTS
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;%	 JSR	BBLOCK						     %
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
BBLOCK	 EQU	$
	 LDX	#1
BBL000	 EQU	$
	 STX	BENIND
	 TXA
	 CLC
	 ADC	BENOMC
	 TAY
	 LDA	BEOMAD+0CH,Y
	 STA	BENOMD
;
	 LDA	BBLTIM,X
	 BEQ	BBL010
;
	 PHA
	 CMP	#0EH
	 BNE	BBL002
;
	 JSR	BLSET1	     ; Space BG set !
BBL002	 EQU	$
	 PLA
	 CMP	#01H
	 BNE	BBL008	     ; Erase data ?
;
	 JSR	BLSET0	     ;	BG revise !
;
	 LDA	#LOW BGTABL	;KANSETU DATA SET
	 STA	<BUFFNO
	 LDA	#HIGH BGTABL
	 STA	<BUFFNO+1
	 LDA	#BANK BGTABL
	 STA	<BUFFNO+2
;
	 LDY	BBLBGD,X     ; yes !
	 LDA	#BLOK0
	 STA	[<BUFFNO],Y
;
BBL008	 EQU	$
;
	 JSR	BBLM00
BBL010	 EQU	$
	 DEX
	 BPL	BBL000
	 RTS
;
BBLM00	 EQU	$
	 LDA	BPSFLG
	 ORA	BPLSTF
	 ORA	BPLSTF+1
	 ORA	BPLEND
	 BNE	BBLM20	     ; Game stop ?
;
	 DEC	BBLTIM,X
BBLM18	 EQU	$
	 JSR	BBYCLC
	 LDA	BBLYSD,X
	 CLC
	 ADC	#05H
	 STA	BBLYSD,X
;
BBLM20	 EQU	$
	 LDY	BENOMD
;
	 LDA	BBLXPS,X
	 STA	!OAM+00H+100H,Y
;
	 LDA	BBLYPS,X
	 STA	!OAM+01H+100H,Y
;
	 LDA	#02CH
	 STA	!OAM+03H+100H,Y
;
	 LDA	#080H
	 STA	!OAM+02H+100H,Y
;
	 TYA
	 LSR	A
	 LSR	A
	 TAY
	 LDA	#002H
	 STA	!OAMSB+00H+040H,Y	;!OAM (00+040H+BEOMAD)/04H
;
	 RTS
;
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;%	 Cion BG clear			     %
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
BLSET0	 EQU	$
	 LDA	#02H
	 STA	<WORKC
	 LDA	#03H
	 STA	<WORKD
	 LDA	#12H
	 STA	<WORKE
	 LDA	#13H
	 STA	<WORKF
	 JMP	BLST00
;- - - - - - - - - - - - - - - - - - - -
BLSET1	 EQU	$
	 LDA	#0FFH
	 STA	<WORKC
	 STA	<WORKD
	 STA	<WORKE
	 STA	<WORKF
BLST00	 EQU	$
	 LDY	!VRAMD
;
	 LDA	#08H
	 STA	<WORK3
	 LDA	BBLBGD,X     ; yes !
	 PHA
	 AND	#11110000B
	 ASL	A
	 ROL	<WORK3
	 ASL	A
	 ROL	<WORK3
	 STA	<WORK4
;
	 PLA
	 ASL	A
	 AND	#1FH
	 CLC
	 ADC	<WORK4
	 STA	!VRAMD+3,Y
	 CLC
	 ADC	#20H
	 STA	!VRAMD+11,Y
;
	 LDA	<WORK3		;recover block set
	 AND	#11011111B
	 STA	!VRAMD+2,Y
	 STA	!VRAMD+10,Y
;
	 LDA	#000H
	 STA	!VRAMD+4,Y
	 STA	!VRAMD+12,Y
	 LDA	#003H
	 STA	!VRAMD+5,Y
	 STA	!VRAMD+13,Y
;
	 LDA	<WORKC
	 STA	!VRAMD+6,Y
	 LDA	<WORKD
	 STA	!VRAMD+8,Y
	 LDA	<WORKE
	 STA	!VRAMD+14,Y
	 LDA	<WORKF
	 STA	!VRAMD+16,Y
;
	 LDA	#018H
	 STA	!VRAMD+7,Y
	 STA	!VRAMD+9,Y
	 STA	!VRAMD+15,Y
	 STA	!VRAMD+17,Y
;
	 LDA	#0FFH
	 STA	!VRAMD+18,Y
	 STA	!VRAMD+19,Y
;
	 TYA
	 CLC
	 ADC	#010H
	 STA	!VRAMD
	 RTS
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;%	 JSR	  BXCALC    [  (X) pos calc ] :Morita only use	     %
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;=============================
BBYCLC	 EQU	$
	 TXA
	 CLC
	 ADC	#BBLYSD-BPLYSD
	 BPL	BENCLC
;=============================
BEXCLC	 EQU	$
	 TXA
	 CLC
	 ADC	#BENXSD-BPLYSD
	 BPL	BENCLC
;===========================-
BEYCLC	 EQU	$
	 TXA
	 CLC
	 ADC	#BENYSD-BPLYSD
BENCLC	 EQU	$
	 TAX
	 JSR	BYCALC
	 LDX	BENIND
	 RTS
;
BXCALC	 EQU	$
	 TXA
	 CLC
	 ADC	#BPLXSD-BPLYSD
	 TAX
	 JSR	BYCALC
	 LDX	BPLIND
	 RTS
;
;===========================-
BYCALC	 EQU	$
	 LDA	BPLYSD,X
	 ASL	A
	 ASL	A
	 ASL	A
	 ASL	A
	 CLC
	 ADC	BPLYCL,X   < Calc  New (x) position !
	 STA	BPLYCL,X
	 PHP
;
	 LDY	#0
	 LDA	BPLYSD,X
	 LSR	A
	 LSR	A
	 LSR	A
	 LSR	A
	 CMP	#8
	 BCC	CALX60
;
	 ORA	#11110000B
	 DEY
CALX60	 EQU	  $
	 PLP
	 ADC	BPLYPS,X
	 STA	BPLYPS,X
	 ROL	A
;
	 CPX	#BPLXSD-BPLYSD
	 BCS	CALX68
;
	 ROR	A
	 TYA
	 ADC	BPLYPH,X
	 STA	BPLYPH,X
CALX68	 EQU	$
	 RTS
;
PAUSE_SET	EQU	$
		LDA	BPSFLG
		BEQ	PAUSE_SET0100

		PHB
		PHK
		PLB

		LDY	#000H

		MEM16
		IDX16
		REP	#00110000B

		LDA	#PAUPOS
		STA	WORK0

		LDA	#PAUDAT
		STA	WORK2

		LDA	#PAULP_END
		STA	WORK4

		JSR	MOJI_MOJI

		MEM8
		IDX8
		SEP	#00110000B

		PLB

PAUSE_SET0100	EQU	$

		RTS
;
;
		MEM16
		IDX16
MOJI_MOJI	EQU	$
		LDA	(WORK0)
		STA	!OAM+00H+30H,Y
		LDA	(WORK2)
		STA	!OAM+02H+30H,Y

		INC	WORK0
		INC	WORK0

		INC	WORK2
		INC	WORK2

		PHY

		TYA
		LSR	A
		LSR	A
		TAY

		MEM8
		IDX8
		SEP	#00110000B

		LDA	#000H
;		STA	!OAMSB+60H,Y
		STA	!OAMSB+0CH,Y

		MEM16
		IDX16
		REP	#00110000B

		PLY

		INY
		INY
		INY
		INY

		CPY	WORK4
		BNE	MOJI_MOJI

		RTS

		MEM8
		IDX8
;
PAUPOS		EQU	$
		HEX	6C,80
		HEX	74,80
		HEX	7C,80
		HEX	84,80
		HEX	8C,80

		HEX	6C,88
		HEX	74,88
		HEX	7C,88
		HEX	84,88
		HEX	8C,88
;
PAUDAT		EQU	$
		HEX	2D,23
		HEX	C6,22
		HEX	C2,22
		HEX	2E,23
		HEX	2F,23
		HEX	3D,23
		HEX	D6,22
		HEX	D2,22
		HEX	3E,23
		HEX	3F,23
PAUDTE		EQU	$
;
PAULP_END	EQU	(PAUDTE-PAUDAT)*2
;
		END
