;
	include		mn_hp_smram.asm
;
         ORG      0DDB80H
		EXTEND
		IDX8
		MEM8
; 
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;        1985. 8.12         V.1.0  Surper Mario 
;                                  File   name : SMCROS 
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;=========================================================== SMMAIN ==
         EXT      BGCOES,CLSET2,SCMOD,MLSLS20
         EXT      SCHEG,CAINC 
;........................................................... ( Dtat ) 
         EXT      CORCDT
;........................................................... ( Block No. )
         EXT      SKY0,HOLE0,HOLE1,GRS0,MT0,WATR0,WATR1,CHM0,WCHM0
         EXT      MUSH0,LND0,CLBK0,BRIK0,BRIK1,CHM1,GRND0,WOOD0 
         EXT      CLD00,POLE0,SPRIG,BKBSW,COIN0,COIN1,STEK0,STBCO,STBMS 
         EXT      STBDM,STBSM
	 EXT	  STRTR,STRST
;........................................................... ( Block etc index )
         EXT      NOBK0,NOBK1,NOBK2,NOBK3 
         EXT      THWR0,THWR1,THWR2,THWR3 
;=========================================================== SMINIT ==
         EXT      FRTADC,CHRCLR
;........................................................... ( Enemy No. )
         EXT      SHTR,BKTR,RDTR,TUTR,EXT0,FTR0,FTR2
         EXT      ENDTR,FIEN,JFS0,FTR7,FTR6,FLWR,BMUS,WTR0,WTR1,FFWR
         EXT      LFT0,LFT1,LFT2,LFT3,LFT4,LFT5,LFT6,ELV0,ELV1
         EXT      ESHP,IKTR,BKM0,YPVS,GSHL,BKF0,FTM0,JPTR 
;=========================================================== SMFRDT ==
         EXT      COURSD,CROSID 
;=========================================================== SMPLAY ==
         EXT      COINUP,BKPINT 
;........................................................... ( Game mode No. )
         EXT      PLSMMD,PLWUMD,PLC0MD,PLC1MD,PLCRMD,PLMDPY 
         EXT      PLSB,PLBS,PLBX,PLTPMD,PLSF,NOCRMD 
;........................................................... ( Statsu ) 
         EXT      BWALK,BJUMP,BDROP,PWIRE 
;........................................................... ( LF & RT move value ) 
         EXT      WKLF,RNLF,WKRT,RNRT 
;=========================================================== SMENMY ==
         EXT      ENCLER,YCLCLR,FIEN10
	EXT	ENCLER2
;........................................................... ( Enmey status ) 
         EXT      WALK,DOWN,JUMP,STOP,TIME,DROP 
;=========================================================== SMCSET ==
         EXT      ENFRCK,ENPSCV,FRMXCK
;==============
	EXT	BOMBST,BKM0ST
;=========================================================== SMCROS ==
         GLB      CRDTST,ENCRDS,CRECMP,CRENPL,CRLFPL,CRELPL,CRPLBG
         GLB      CRENBG,CRFIBG,CRBD00,CRENEN,CREPMS
         GLB      CRFIEN,CRPLCO,CRPLMS,CRPLHM,BRBKCK,CRBGCK,PLONLF
         GLB      PLONEL,FICRDS,COCRDS,HMCRDS,MSCRDS,HEDC10,CRPM80
         GLB      CREB01,CREB03,LFCRDS,HEDC15,ELCRDS
         GLB      SCRSET
;........................................................... ( Cross size No. ) 
         GLB      PBCMD,PSCMD,PDCMD,ENCMD,ELCMD,LFCMD,LFCMD2
         GLB      FICMD,COCMD,ENCMD2,GUCMD,BKCMD,FECMD,FWCMD
;;;;;    GLB      MSCMD 
         GLB      FICMD2
	 GLB	  CRDTST
;........................................................... ( Etc data ) 
         GLB      PCBDY0,PCBDY2 
;=========================================================== SMCROS ==
	 EXT	GLBGST
; 
;#####################################################################
;#                   (X) -- Index                                    #
;#       JSR      CRFIEN    [ Enemy vs fire cross check ]            #
;#####################################################################
CRFIEN   EQU      $ 
         LDA      <FISTAT,X
         BEQ      CREF95
         ASL      A 
         BCS      CREF95
; 
         LDA      <FMCNT 
         LSR      A 
         BCS      CREF95          ;TEST TEST TEST TEST TEST 
; 
         TXA                      ; Yes ! 
         ASL      A 
         ASL      A 
         CLC
         ADC      #FICWOK-CWORK0	;+4;;TAKE;;
         TAY
; 
         LDX      #8
CREF10   EQU      $ 
         STX      <WORK+1
; 
         TYA
         PHA
; 
         LDA      <ENSTAT,X
         AND      #00100000B      ; Filed kame ?
         BNE      CREF90          ; Yes ! No. Check 
; 
         LDA      <ENCMOD,X        ; Clear kame ?
         BEQ      CREF90          ; Yes ! No. Check 
; 
         LDA      <ENMYNO,X
         CMP      #LFT0 
         BCC      POPO
         CMP      #LFT6+1 
         BCC      CREF90
; 
POPO     EQU      $ 
         CMP      #YPVS 
         BNE      CREF20
; 
         LDA      <ENSTAT,X
         CMP      #DOWN+1 
         BCS      CREF90
; 
CREF20   EQU      $ 
         LDA      ENFHFG,X
         BNE      CREF90          ; Display out ? 
;                                 : No. 
	STX	<YWORK
         TXA
         ASL      A               ; Enemy index x 4 --! Xr
         ASL      A 
         CLC
         ADC      #ENCWOK-CWORK0
         TAX
; 
         JSR      CROJCK
; 
         LDX      <INDEX 
         BCC      CREF90          ; Does a fire hit to the enemy ? (YES ; CREF90 )
; 
         LDA      #10000000B
         STA      <FISTAT,X        ; Fire Expl 
; 
         LDX      <WORK+1
; 
         JSR      FIRON 
; 
CREF90   EQU      $ 
         PLA
         TAY
; 
         LDX      <WORK+1
         DEX
         BPL      CREF10
; 
CREF95   EQU      $ 
         LDX      <INDEX 
         RTS
; 
BKDTDT   EQU      $ 
;;;;      WORD No.  1    2    3    4    5    6    7    8
         BYTE     YPVS,SHTR,BKTR,EXT0,ESHP,IKTR,FIEN,BKM0,BKM0
	 BYTE	  RDTR,WTR0,FTM0,BKM0
; 
;-----Fire hit to enemy !! -------
FIRON    EQU      $ 
;;;;;;;; TXA
;;;;;;;; PHA
; 
         JSR      ENPSCV
;;;;	LDA	#3
	LDA	#1		;bug (Ver.up)/H5.7.8/
	STA	!SOUND0
; 
;;;;;;;; PLA
;;;;;;;; TAX
         LDX      <WORK+1
; 
         LDA      <ENCMOD,X
         BPL      FIRON20     ;protect ?
;                             ;yes
         AND      #0FH
         TAX
         LDA      <ENMYNO,X
         CMP      #BKM0 
         BEQ      FIRON40     ;big kame ? 
;                             ;no 
         LDX      <WORK+1
FIRON20  EQU      $ 
         LDA      <ENMYNO,X
         CMP      #BKTR 
         BNE      FIRON25
	JMP	FIHRET
FIRON25	EQU	$
;;;      CMP      #EXT0 
;;;      BEQ      FIHRET
; 
         CMP      #BKM0 
         BNE      FIH010
; 
FIRON40  EQU      $ 
	LDA	#8
	STA	KPCHID
	LDA	#24
	STA	KPCHCT
;
         DEC      FIBSCT
	 BEQ	  BKMDETH
	LDA	FIBSCT
	CMP	#01H
	BEQ	BKMDL1
         JMP      FIHRET
BKMDL1	EQU	$
	STZ	PIYOCT
	LDA	#1
	STA	PIYOFG
	JMP	FIHRET
; 
BKMDETH  EQU      $ 
	LDA	#8
	STA	KPCHID
	LDA	#0FFH
	STA	KPCHCT
;	
         JSR      YCLCLR
         STA      <ENXSD0,X
; 
;;;;;   LDA      #00H
         STZ      ENFALFG         ; big kame fire clear 
; 
         LDA      #0FEH 
         STA      <ENYCL0,X        ;Jump power 
; 
         LDY      CORSNO
         LDA      BKDTDT,Y
         STA      <ENMYNO,X
	STX	KPSTFG
	INC	KPSTFG
	CMP	#2DH
	BEQ	TKEB30
;
	PHX
	LDA	<BG2COS
	CMP	#21H
	BEQ	TKEB20
	STX	KUPAFG
	INC	KUPAFG
	LDX	#8
TKEB10	EQU	$
	LDA	<ENMYNO,X
	DEX
	BMI	TKEB20
	CMP	#2DH
	BNE	TKEB10
	INX
	STZ	<ENCMOD,X
	STZ	<ENMYNO,X
TKEB20	EQU	$
	PLX
TKEB30	EQU	$
; 
         LDA      #00100000B
         CPY      #3
         BCS      BKM010          ; Kame ?
; 
         ORA      #STOP           ; yes ! 
BKM010   EQU      $ 
         STA      <ENSTAT,X
; 
;;         LDA      #80H
;;         STA      0FEH            ; <S! Big kame fail sound 
; 
;;	LDA	#1BH
;;	STA	!SOUND2
         LDX      <WORK+1
         LDA      #9              ; 5000 pts
         BNE      FIRH11
; 
FIH010   EQU      $ 
         CMP      #FTM0 
         BEQ      FIHRET
         CMP      #JPTR 
         BEQ      FIHRET
         CMP      #ENDTR           ; Not kame ? 
         BCS      FIHRET          ; yes ! no check
; 
FIRH10   EQU      $ 
FIRHIT   EQU      $ 
         LDA      <ENMYNO,X
         CMP      #FFWR
         BEQ      FIRH02
         CMP      #FLWR 
         BNE      FIRH01
; 
;;;;     CMP      #BKM0 
;;;;     BEQ      FIRH01
; 
;;;;     CMP      #ENDTR
;;;;     BCC      FIRH01
FIRH02   EQU      $ 
;;;         LDA      ENYPS1,X
;;;         ADC      #18H
;;;         STA      ENYPS1,X
; 
;;;;;;   JSR      ENCLER
; 
         TAY
;
         LDA      ENYPS1,X
         ADC      #18H
         CPY      #FFWR
         BNE      FIRH111
         SBC      #31H
FIRH111  EQU      $
         STA      ENYPS1,X
;
FIRH01   EQU      $ 
         JSR      FIROUT
; 
         LDA      <ENSTAT,X
         AND      #00011111B
         ORA      #00100000B
         STA      <ENSTAT,X        ; Fail
; 
FISCST   EQU      $
         LDA      #2              ;200 pts. ;;;;;;;;;;;;;;; 
         LDY      <ENMYNO,X
         CPY      #FIEN 
         BNE      FIRH00
         LDA      #6              ;1000 pts. ;;;;;;;;;;;;;;;
FIRH00   EQU      $ 
         CPY      #YPVS 
         BNE      FIRH11
         LDA      #1              ;100 pts.;;;;;;;;;;;;;;;;;
FIRH11   EQU      $ 
         JSR      SCRSET
; 
	CMP	#03
	BEQ	FIHRET
         LDA      #03H
         STA      !SOUND0            ; <S! Fire hit sound
FIHRET   EQU      $ 
         RTS
; 
;#####################################################################
;#                   (X) -- Index                                    #
;#       JSR      CRPLCO    [ Coin     vs playe cross check ]        #
;#####################################################################
CRPLCO   EQU      $ 
CRPLHM   EQU      $ 
         LDA      <FMCNT 
         LSR      A 
         BCC      CRCP90
; 
;;;      LDA      <PLCMOD
;;;      CMP      #PLSF 
;;;      BEQ      CRCP90          : Fail
;;TQ         LDA      GMSTTM
;;;;;;;; BNE      CRCP90
;;;;;;;; LDA      HMFMSD
         LDA      FMSIDE
         ORA      GMSTTM
;;TQ
         ORA      HMFMSD
         BNE      CRCP90          ; display out 
; 
         TXA
         ASL      A 
         ASL      A 
         CLC
         ADC      #COCWOK-CWORK0
         TAY
; 
;;;;;;;; LDX      #0
;;;;;;;; JSR      CROJCK
         JSR      CROJCS
; 
         LDX      <INDEX 
         BCC      CRCP95          ; Cross ? 
; 
         LDA      HMCRCT,X        ; Yes ! 
         BNE      CRCP90
; 
         LDA      #1
         STA      HMCRCT,X
;****** Hit !! ******************** 
         LDA      <HMXSD0,X        ; Hammer speed turn 
         EOR      #0FFH 
         CLC
         ADC      #1
         STA      <HMXSD0,X
; 
         LDA      SPMTIM
         BNE      CRCP90          ; Super expless mario ? 
;                                 : Yes ! --> No. Death 
         JMP      HEDC10
; 
CRCP95   EQU      $               ; No. Cross Clear 
         LDA      #0
         STA      HMCRCT,X
; 
CRCP90   EQU      $ 
         RTS
;#####################################################################
;#                   (X) -- Index                                    #
;#       JSR      CRPLMS    [ Mushroom vs player cross check ]       #
;#####################################################################
CRPLMS   EQU      $ 
;         LDA      FMCNT
;         AND      #1 
;         BNE      CRPM90 
;;
;         LDA      MSFMSD 
;         AND      #00000100B      : No. display
;         BNE      CRPM90 
;;
;         LDA      GMSTTM 
;         BNE      CRPM90 
;;
;         LDY      #MSCWOK-CWORK0 
;;
;         LDX      #0 
;         JSR      CROJCK 
;         LDX      INDEX
;         BCC      CRPM90          : Hit ?
;                                 : Yes ! 
MSCROS   EQU      $ 
         JSR      ENCLER2
;
         LDA      MSFLFG
         CMP      #4
         BNE      MSC000      : Death mush ?
         JMP      HEDC12      : Fail !
;
MSC000   EQU      $
         LDA      #6              ; 1000 pts
         JSR      SCRSET2          ;;;;;;;;;;;;;;;;;;;;;;;;; 
; 
         LDA      #0AH
         STA      !SOUND0      ; <S! Mush cross sound
; 
;;       LDA      #0
;;       STA      PLXSD0
; 
         LDA      MSFLFG
         CMP      #2
         BCC      CRPM60
         CMP      #3
         BEQ      CRPM65
; 
CRPM09   EQU      $ 
         LDA      #23H            ; No. Death 
         STA      SPMTIM
; 
         LDA      #0DH
         STA      !SOUND2      ; <S! 
; 
         RTS
; 
CRPM60   EQU      $ 
         LDA      POWLEV
         BEQ      CRPM70
; 
         CMP      #1
         BNE      CRPM90
; 
         LDX      <INDEX 
; 
         LDA      #2
         STA      POWLEV
; 
;;;;;    JSR      MRFIC1          : Mario color chenge
;?? 03.12.03 ??         JSR      CLSET2
		JSL	>CLSET2
         LDX      <INDEX 
;
         LDA      #PLBX 
         BRA      CRPM85          ; Super mario with fire 
;;K;;         JMP      CRPM85          ; Super mario with fire 
; 
CRPM65   EQU      $ 
         LDA      #0BH
         STA      SCFLAG,X        ; "1UP" display 
	LDA	#0
	STA	!SOUND0
; 
;;;      INC      PLCNT           : Existra player
; 
;;;      LDA      #40H            : <S> sound 
;;;      STA      0FEH
; 
         RTS
; 
CRPM70   EQU      $ 
         LDA      #1
         STA      POWLEV
CRPM80   EQU      $ 
         LDA      #PLSB 
CRPM85   EQU      $ 
         LDY      #BWALK
         JSR      HEDCA5          ; Mario Big change
CRPM90   EQU      $ 
         RTS
; 
;------- Mario color chenge ----------------------------
;MRCLUD   EQU      $
;;                  0  1  2  3
;         HEX      22,22,0F,0F
;;
;MRCLDT   EQU      $
;         HEX      3F,10,04,0F,16,27,18,00   : Normal color 
;;
;         HEX      3F,10,04,0F,37,27,16,00   : Fire color 
;;
;MRFIC1   EQU      $
;         LDY      #8 
;         JMP      MRFI05 
;;
;MRFIC2   EQU      $
;         LDY      #0 
;MRFI05   EQU      $
;         LDX      VRAMD
;         LDA      #7 
;         STA      WORK 
;MRFI10   EQU      $
;         LDA      MRCLDT,Y 
;         STA      VRAMD+1,X
;         INX 
;         INY 
;         DEC      WORK 
;         BPL      MRFI10 
;;
;         LDA      VRAMD
;         TAX 
;         CLC 
;         ADC      #7 
;         STA      VRAMD
;;
;         LDY      <ENVRFG 
;         LDA      MRCLUD,Y 
;         STA      VRAMD+4,X
;         RTS 
;;
;#####################################################################
;#                   (X) -- Index                                    #
;#       JSR      CRENPL    [ Enemy vs Player cross check ]          #
;#####################################################################
CRXSPDT  EQU      $ 
         HEX      18,E8 
; 
CSRIDT   EQU      $ 
         HEX      30,D0 
; 
CRESPD   EQU      $ 
         HEX      08,F8 
; 
CRENPL   EQU      $ 
         LDA      <FMCNT 
         LSR      A 
         BCS      CRPM90
; 
         JSR      PLOFCK    ; Player out frame check
         BCS      CREP95
;
	CPX	#09H
	BNE	TKJ010
	LDA	MSOBJX
	BPL	TKJ010
	CMP	#0F4H
	BCS	TKJ020
TKJ010	EQU	$	 
         LDA      ENFHFG,X
         BNE      CREP95
TKJ020	EQU	$
         LDA      <CMODE 
         CMP      #PLMDPY 
         BNE      CREP95
; 
         LDA      <ENSTAT,X
         AND      #00100000B
         BNE      CREP95
; 
         LDA      <ENSTAT,X
         AND      #00100000B
         BNE      CREP95
;
         JSR      ENCCKS          ; CWORK Enemy index calc
; 
;;;;;;;; LDX      #0
;;;;;;;; JSR      CROJCK
         JSR      CROJCS
  
         LDX      <INDEX 
;;;      BCC      CREP90          *- IF  cross player ?  ( NO : CREP90 )
         BCS      CREP0A
; 
;;;;;;;  JMP      CREP90
;------------------------------------ 
CREP90   EQU      $ 
         LDA      ENCRFG,X
         AND      #11111110B
         STA      ENCRFG,X
; 
CREP95   EQU      $ 
         RTS
; 
CREP0A   EQU      $ 
         LDY      <ENMYNO,X
         CPY      #BMUS 
         BNE      CREP0B
; 
         JMP      MSCROS          ; Mush room 
; 
CREP0B   EQU      $ 
         LDA      SPMTIM
         BEQ      CREPAA
; 
         JMP      FIRH10          ; Fail
; 
MISTRY   EQU      $ 
         HEX      0A,06,04           ; Mistery point
; 
CREPAA   EQU      $ 
         LDA      ENCRFG,X
         AND      #00000001B
         ORA      ENFHFG,X
         BNE      CREPRT
; 
         LDA      #00000001B
         ORA      ENCRFG,X
         STA      ENCRFG,X
; 
;;;      LDA      #08H
;;       STA      0FFH      : <S> cross player sound
; 
         CPY      #EXT0 
         BEQ      CREP00    ; Bakudan 
         CPY      #GSHL
         BEQ      CREP00    : Gun
         CPY      #FLWR
	BNE	SKH010
         JMP      HEDHIT    : Deth flower
SKH010	EQU	$
         CPY      #FFWR
	BNE	SK0001
         JMP      HEDHIT    : Deth flower
SK0001	EQU	$
         CPY      #JPTR
	 BNE	  SK0004
         JMP      HEDHIT    : Jump fire
SK0004	 EQU	  $
         CPY      #ENDTR
         BCS      HEDHIT    : Not TR
; 
         LDA      <ENVRFG
         BEQ      HEDHIT    ; Water 
; 
         LDA      <ENSTAT,X
         ASL      A 
         BCS      CREP00
; 
         LDA      <ENSTAT,X
         AND      #00000111B
         CMP      #JUMP 
         BCC      CREP00
; 
         LDA      <ENMYNO,X
         CMP      #YPVS 
         BEQ      CREPRT
; 
         LDA      #03H
         STA      !SOUND0      ; <S! 
	JSL	>BOMBST
; 
	STZ	KAMECT,X
         LDA      <ENSTAT,X
         ORA      #10000000B
         STA      <ENSTAT,X
; 
         JSR      CREPMS
; 
         LDA      CSRIDT,Y
         STA      <ENXSD0,X
; 
;;;      LDA      #0
;;;      STA      TMEL1,X 
; 
; 
         LDA      #3        ; 400 pts 
         CLC
         ADC      HDCRCT
; 
         LDY      TMEL1,X   ; MKJHCVJJJJ... 
         CPY      #3
         BCS      CR010 
         LDA      MISTRY,Y  ; Mistery point 
CR010    EQU      $ 
         JSR      SCRSET    ;;;;;;;;;;;;;;;;;;;;;;;;; 
; 
;;       LDA      #08H
;;       STA      0FFH      : SOUND 
; 
CREPRT   EQU      $ 
         RTS
; 
CREP00   EQU      $ 
;;;;     LDA      PLOBJY
;;;;     CMP      ENOBJY
;;;;     BCS      HEDHIT
; 
;;;;;         LDA      <YCALC0
;;;;;         BMI      CREP02
;;;;     BEQ      CREP01
         LDY      YCALC0
         DEY
; 
         BMI	CREP01
	JMP      UPCRS
;;;;;         BNE      UPCRS           ; Downing 
CREP01   EQU      $ 
; 
CREP02   EQU      $ 
         LDA      <ENMYNO,X
;;       CMP      #JFS0 
;;       BNE      CREP03
         CMP      #YPVS+1 
         BCC      CREP03
; 
         LDA      PLYPS1
         CLC
         ADC      #0CH
         CMP      ENYPS1,X
         BCC      UPCRS 
; 
;CREP02   EQU      $
CREP03   EQU      $ 
         LDA      ENCRTM
         BNE      UPCRS           ; Jumpping croos ?
;                                 : No
         LDA      SFTYTM          ; safety flashing ? 
         BNE      HEDRTS          ; Yes ! No. cross 
; 
         LDA      PLOBJX
         CMP      ENOBJX
         BCC      HEDCRS
; 
         JMP      BAKCRS
; 
HEDCRS   EQU      $ 
         LDA      <ENMMKI,X
         CMP      #1
         BNE      HEDHIT
         JMP      BAKC10
; 
HEDC10   EQU      $ 
HEDHIT   EQU      $ 
;**** Fail ********
HEDC12   EQU      $ 
         LDA      SFTYTM          ; safety flashing ? 
         ORA      SPMTIM          : Muteki ?
         BNE      HEDRTS          ; Yes ! No. cross 
; 
HEDC15   EQU      $ 
;;;      STA      YCALC0
;;;      STA      YCALC1
;;;      STA      YPOS2 
;;;      STA      XSPED0
; 
         LDX      POWLEV
         BEQ      HEDC20          ; Big Mario ? 
; 
         STA      POWLEV
; 
         LDA      #08H            ; Yes ! 
         STA      SFTYTM          ; safety timer set
; 
	LDA	#04
         STA      !SOUND0            ; <S! sound 
; 
;?? 03.12.03 ??         JSR      CLSET2
		JSL	>CLSET2
; 
         LDA      #PLBS           ; Yes !   Big --! Small 
HEDCB5   EQU      $ 
;;;     (LDY      #1) 
         LDY      #BJUMP
; 
HEDCA5   EQU      $ 
         STA      <CMODE
; 
OMNC10	EQU	$
;;;;;;   LDA      #BDROP
         STY      <PLSTAT
; 
         LDY      #0FFH 
         STY      GMSTTM
; 
         INY
         STY      SCRMVL
; 
HEDRTS   EQU      $ 
         LDX      <INDEX 
         RTS
; 
HEDC20   EQU      $ 
;;;;     LDA      #01H
;;;;     STA      0FCH      : <S> fail sound
;;;;     INY    (Yr=0) --> 1
         STX      <XSPED0
; 
	PHX
	LDA	#1
	STA	POWLEV-2
	JSL	>CLSET2
	PLX
;
         INX
	LDA	#20H
        TSB     !SOUND1
	LDA	#09H
	STA	!SOUND2
	STA	ENCLFG
	STA	SRSTFG
;
         LDA      #0FCH 
         STA      <YCALC0
; 
         LDA      #PLSF 
         BNE      HEDCB5
; 
;################################################## 
SCRDT    EQU      $ 
         HEX      02,06,05,06 
; 
UPCRS    EQU      $ 
;;;      LDA      #1
;;;;     INC      ENCRTM    : Cross timer set 
; 
         LDA      <ENMYNO,X
         CMP      #EXT0 
         BEQ      HEDHIT    ; Bakudan 
; 
;;;;     LDY      #0
;;;;     CMP      #8
;;;;     BCS      UPCR10
;;;;     LDY      #1
;UPCR10   EQU      $
;;;;     LDA      CRXSPDT,Y 
;;;;     STA      XSPED0
; 
         LDA      #02H
         STA      !SOUND0      ; <S! 
; 
         LDA      <ENMYNO,X
; 
         LDY      #0
         CMP      #JFS0           ; Fish
         BEQ      UPCR1A  ;Y=0
         CMP      #FTM0 
         BEQ      UPCR1A  ;  0
         CMP      #GSHL 
         BEQ      UPCR1A  ;  0    ; Gun 
         CMP      #JPTR 
         BEQ      UPCR1A  ;  0
         INY
         CMP      #FIEN           ; Tomafork
         BEQ      UPCR1A  ;  1
         INY
         CMP      #ESHP 
         BEQ      UPCR1A  ;  2    ; Cloud 
         INY
         CMP      #IKTR   ;  3    ; Ika 
         BNE      UPCR11
UPCR1A   EQU      $ 
         LDA      SCRDT,Y         ; ???? Pts
         JSR      SCRSET          ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; 
         LDA      <ENMMKI,X
         PHA
         JSR      FIOT10          ; Fail
         PLA
         STA      <ENMMKI,X
         LDA      #00100000B
         STA      <ENSTAT,X
; 
         JSR      YCLCLR
         STZ      <ENXSD0,X
; 
         JMP      SDSET
;
;;;;         LDA      #0FDH           ; Player jump 
;;;;         STA      <YCALC0
;;;;         RTS
; 
UPCR11   EQU      $ 
         CMP      #FTR0 
         BCC      UPCR20          ; Flying kame ? 
; 
;;;      PHA                      : Yes ! 
         JSR      SDSET
         AND      #00000001B
         STA      <ENMYNO,X
; 
;;;      PLA
;;;      CMP      #TUTR 
;;;      BEQ      UPCR20
; 
         LDA      #WALK 
         STA      <ENSTAT,X
; 
         LDA      #3              ; 400 Pts 
         JSR      SCRSET          ;;;;;;;;;;;;;;;;;;
; 
         JSR      YCLCLR
; 
         JSR      CREPMS
; 
         LDA      CRESPD,Y
         STA      <ENXSD0,X
;;;;         JMP      SDSET 
	RTS
; 
TMDT     HEX      10,0B 
; 
UPCR20   EQU      $ 
         LDA      #TIME 
         STA      <ENSTAT,X        ; Timming 
; 
         INC      HDCRCT
; 
         LDA      HDCRCT
         CLC
         ADC      ENCRTM
         JSR      SCRSET          ; Mistery score 
; 
;;;      LDA      #1
         INC      ENCRTM    ; Cross timer set 
; 
         LDY      GMLOOP
         LDA      TMDT,Y
; 
;;;;     LDA      #10H
         STA      TMEL1,X 
; 
SDSET    EQU      $ 
;;       LDA      #0
;;       STA      YCALC1
;;       STA      YPOS2 
; 
         LDY      #0FAH
;
         LDA      ENMYNO,X
         CMP      #FTR6
         BEQ      PLJP0
         CMP      #FTR7
         BNE      PLJP1
;
PLJP0    EQU      $
         LDY      #0F8H
PLJP1    EQU      $
         STY      YCALC0
         RTS
; 
BAKCRS   EQU      $ 
;;;      LDA      SFTYTM          : safety flashing ? 
;;;      BNE      UNDCRS          : Yes ! No. cross 
; 
         LDA      <ENMMKI,X
         CMP      #1
         BNE      BAKC10
         JMP      HEDC10
; 
BAKC10   EQU      $ 
         JSR      ENTURN
         JMP      HEDHIT
; 
;-------------------------
CREPMS   EQU      $ 
         LDY      #1
         JSR      CRECMP
         BPL      CREPL0
         INY
CREPL0   EQU      $ 
         STY      <ENMMKI,X
         DEY
UNDCRS   EQU      $ 
         RTS
; 
;SCRDT2   EQU      $
;          INDEX   0  1  2  3  4  5 
;        HEX      00,08,00,08,00,08 
; 
SCRSET2  EQU      $ 
	 STA      SCFLAG,X
         LDA      #30H
         STA      SCDPTM,X
         LDA      ENYPS1,X
         STA      SCOBJY,X
         LDA      ENOBJX
         STA      SCOBJX,X
	LDA	ENXPS1,X
	STA	<WORKA
	LDA	<ENXPS0,X
	STA	<WORKB
	PHX
	TXA
	ASL	A
	TAX
	MEM16
	REP	#20H
	LDA	<WORKA
	SEC
	SBC	<SCCH1
	STA	SCXPOS,X
	MEM8
	SEP	#20H
	PLX
RETURN   EQU      $
         RTS
;;
SCRSET   EQU      $ 
	CMP	SCFLAG,X
	BCS	SCRST10
	RTS
SCRST10	EQU	$
	 STA      SCFLAG,X
         LDA      #30H
         STA      SCDPTM,X
         LDA      ENYPS1,X
         STA      SCOBJY,X
	PHY
	TXA
	ASL	A
	TAY
	LDA	ENXPS1,X
	STA	<YWORK
	LDA	<ENXPS0,X
	STA	<YWORK1
	MEM16
	REP	#20H
	LDA	<YWORK
	SEC
	SBC	<SCCH1
	STA	SCXPOS,Y
	MEM8
	SEP	#20H
	STA	SCOBJX,X
	PLY
         RTS
;#####################################################################
;#                   (X) -- Index                                    #
;#       JSR      CRENEN    [ Enemy vs Enemy cross check ]           #
;#####################################################################
CREED1   EQU      $ 
         BIN      10000000
         BIN      01000000
         BIN      00100000
         BIN      00010000
         BIN      00001000
         BIN      00000100
         BIN      00000010
; 
CREED2   EQU      $ 
         BIN      01111111
         BIN      10111111
         BIN      11011111
         BIN      11101111
         BIN      11110111
         BIN      11111011
         BIN      11111101
; 
CRENEN   EQU      $ 
         LDA      <FMCNT     ; TEST TEST TEST TEST 
         LSR      A 
         BCC      RETURN
; 
         LDA      <ENVRFG
         BEQ      RETURN    ; Water ? 
; 
         LDA      <ENMYNO,X  ; No. 
         CMP      #ENDTR
         BCS      CREE90    ; Not kame
; 
         CMP      #ESHP 
         BEQ      CREE90
; 
         CMP      #FLWR 
         BEQ      CREE90
         CMP      #FFWR
         BEQ      CREE90
; 
;;;;     CMP      #FIEN 
;;;;     BEQ      CREE90
; 
;;;;     CMP      #EXT0 
;;;;     BEQ      CREE90
; 
;;;;     CMP      #BKTR 
;;;;     BEQ      CREE90
; 
;;       CMP      #EXT0 
;;       BEQ      CREE00
; 
;;       CMP      #FTR2 
;;       BEQ      CREE00
; 
;;       CMP      #FTR0 
;;       BCS      CREE90
; 
CREE00   EQU      $ 
;;       LDA      ENFMSD
;;       AND      #11111000B
         LDA      ENFHFG,X
         BNE      CREE90          ; Display out ? 
;                                 : No. 
         JSR      ENCCKS
; 
         DEX
         BMI      CREE90
;------------------------------------ 
CREE10   EQU      $ 
         STX      <WORK+1
; 
         TYA                      ; Yr; My index
         PHA                      ; Push !
; 
         LDA      <ENCMOD,X
         BEQ      CREE20
; 
         LDA      <ENMYNO,X
         CMP      #ENDTR
         BCS      CREE20    ; Not kame
; 
         CMP      #ESHP 
         BEQ      CREE20
; 
         CMP      #FLWR 
         BEQ      CREE20
         CMP      #FFWR
         BEQ      CREE20
; 
;;;;     CMP      #FIEN 
;;;;     BEQ      CREE20
; 
;;;      CMP      #EXT0 
;;;      BEQ      CREE20
; 
;;;      CMP      #BKTR 
;;;      BEQ      CREE20
; 
;;       CMP      #EXT0 
;;       BEQ      CREE11
; 
;;       CMP      #FTR2 
;;       BEQ      CREE11
; 
;;       CMP      #FTR0 
;;       BCS      CREE20
; 
CREE11   EQU      $ 
;;;;;;;  LDA      ENFMSD
;;;;;;;  AND      #11111000B
         LDA      ENFHFG,X
         BNE      CREE20
; 
         TXA
         ASL      A 
         ASL      A 
         CLC
         ADC      #ENCWOK-CWORK0
         TAX
; 
         JSR      CROJCK
         LDX      <INDEX 
         LDY      <WORK+1
; 
         BCC      CREE15          ; Cross ? 
;                                 : Yes ! 
         LDA      <ENSTAT,X
         ORA      ENSTAT,Y
         AND      #10000000B
         BNE      CREE12
; 
;;	LDA	<ENMYNO,X
;;;	CMP	#FLWR
;;;;	BEQ	CREE20
;;;	CMP	#FFWR
;;	BEQ	CREE20
;	
         LDA      ENCRFG,Y        ; Again cross ? 
;;;;;    AND      #10000000B
         AND      CREED1,X
         BNE      CREE20
;                                 : no
         LDA      ENCRFG,Y
;;;;     ORA      #10000000B
         ORA      CREED1,X
         STA      ENCRFG,Y
; 
CREE12   EQU      $ 
         JSR      ENCRMD
         JMP      CREE20
; 
CREE15   EQU       $
         LDA      ENCRFG,Y
;;;;     AND      #01111111B
         AND      CREED2,X
         STA      ENCRFG,Y
; 
CREE20   EQU      $ 
         PLA                      ; My index pull 
         TAY
; 
         LDX      <WORK+1
         DEX
         BPL      CREE10
;---------------------------------
CREE90   EQU      $ 
         LDX      <INDEX 
         RTS
; 
;---------------------------- 
ENCRMD   EQU      $ 
;                                 : Yes!
         LDA      ENSTAT,Y
         ORA      <ENSTAT,X
         AND      #00100000B
         BNE      ENCRRT
; 
         LDA      <ENMYNO,X
         CMP      #FIEN 
         BNE      ENCR05
	STZ	<ENSTAT,X
ENCR05	EQU	$
;
         LDA      <ENSTAT,X
         CMP      #DROP+1 
         BCC      ENCR01
; 
         LDA      ENSTAT,Y
         ASL      A 
         BCC      ENCR10
; 
         LDA      #06H
         JSR      SCRSET    ;;;;;;;;;;;;;;;;;;
; 
         JSR      FIRHIT
; 
         LDY      <WORK+1
ENCR10   EQU      $ 
         TYA
         TAX
CONTIN   EQU      $ 
         JSR      FIRHIT
; 
         LDX      <INDEX 
         LDA      ENCONT,X
         CLC
         ADC      #4
; 
         LDX      <WORK+1
         JSR      SCRSET    ;;;;;;;;;;;;;;;;;;
; 
         LDX      <INDEX 
         INC      ENCONT,X
	BRA	ENCRSN
; 
ENCRRT   EQU      $ 
         RTS
; 
ENCR01   EQU      $ 
         LDA      ENSTAT,Y
         CMP      #DROP+1 
         BCC      ENCRA0
; 
         LDA      ENMYNO,Y
         CMP      #FIEN 
         BEQ      ENCRRT
; 
ENCRQ0   EQU      $ 
         JSR      FIRHIT
;
	JSL	>BOMBST
; 
         LDY      <WORK+1
         LDA      ENCONT,Y
         CLC
         ADC      #4
; 
         LDX      <INDEX 
         JSR      SCRSET    ;;;;;;;;;;;;;;;;;;;;;;; 
; 
         LDX      <WORK+1
         INC      ENCONT,X
ENCRSN	EQU	$
	LDA	ENCONT,X
	CLC
	ADC	#12H
        CMP     #1AH
        BCC     ENCRSN1
        LDA     #0H
ENCRSN1 EQU     $
	STA	!SOUND0
; 
         RTS
; 
ENCRA0   EQU      $ 
         TYA
         TAX
         JSR      ENTURN
         LDX      <INDEX 
; 
ENTURN   EQU      $ 
         LDA      <ENMYNO,X
         CMP      #FLWR 
         BEQ      ENRTS 
         CMP      #FFWR
         BEQ      ENRTS
         CMP      #ESHP 
         BEQ      ENRTS 
         CMP      #FIEN 
         BEQ      ENRTS 
; 
         CMP      #EXT0 
         BEQ      ENCRA3
         CMP      #FTR2 
         BEQ      ENCRA3
; 
         CMP      #IKTR 
         BCS      ENRTS 
; 
ENCRA3   EQU      $ 
         LDA      <ENXSD0,X
         EOR      #0FFH 
         TAY
         INY
         STY      <ENXSD0,X
; 
         LDA      <ENMMKI,X
         EOR      #00000011B
         STA      <ENMMKI,X
;
ENRTS    EQU      $ 
         RTS
;
;#####################################################################
;#                   (X) -- Index                                    #
;#       JSR      CRLFPL    [ Lift vs Player cross check ]           #
;#####################################################################
CRLFPL   EQU      $ 
         LDA      #0FFH 
         STA      ONLFFG,X        ; Clear   Player on lift flag 
; 
         LDA      GMSTTM
         BNE      CRLL90
; 
         LDA      <ENSTAT,X
         BMI      CRLL90          ;- IF  main lift ?              ( NO ; CRLL90 ) 
; 
         LDA      <ENMYNO,X
         CMP      #LFT0 
         BNE      CRLP50          ;- IF  duble lift ?             ( NO ; CRLP50 ) 
; 
         LDA      <ENSTAT,X
         TAX
         JSR      CRLP50               ; Sub lift cross check 
; 
CRLP50   EQU      $               ; Cross check ! 
         JSR      PLOFCK
         BCS      CRLL90               ;- IF  over frame player ? ( YES ; CRLL90 )
; 
         TXA
         JSR      LFCCKS                    ; Calc  CWORK( cross data ) index 
; 
         LDA      ENYPS1,X
         STA      <WORK                      ; <WORK <-- Lift & Land (y)pos (L) 
; 
         TXA
         PHA
; 
;;;;;;;; LDX      #0
;;;;;;;; JSR      CROJCK                    : Cross check 
         JSR      CROJCS
; 
         PLA
         TAX
         BCC      CRLL90               ;- IF  cross player ?      ( NO ; CRLL90 ) 
; 
         JSR      PLONCK                    ; Player on lift check
; 
CRLL90   EQU      $ 
         LDX      <INDEX 
; 
         RTS
; 
;#####################################################################
;#                   (X) -- Index                                    #
;#       JSR      CRELPL    [ Elevator vs Player cross check ]       #
;#####################################################################
CRELPL   EQU      $ 
         LDA      GMSTTM
         BNE      CREL50
; 
;;;;;;;  LDA      #0
         STA      ONELFG,X        ; Clear  Player on elvator flag 
; 
         JSR      PLOFCK          ; Player out frame check
         BCS      CREL50          ;- IF  out frame player ?    ( YES ; CREL50 ) 
; 
         LDA      #2
         STA      <WORK
; 
CREL10   EQU      $ 
         LDX      <INDEX 
         JSR      ENCCKS          ; CWORK Enemy index calc
         AND      #00000010B
         BNE      CREL50          ;- IF  no display ?          ( YES ; CREL50 ) 
; 
         LDA      CWORK0+1,Y
         CMP      #20H
         BCC      CREL30          ;- IF  out frame elevator ?  ( YES ; CREL30 ) 
; 
;;;;;;;; LDX      #0
;;;;;;;; JSR      CROJCK               : Cross check
         JSR      CROJCS
         BCS      CREL80          ;- IF  cross elevator ?      ( YES ; CREL80 ) 
; 
CREL30   EQU      $ 
         LDA      CWORK0+1,Y
         CLC
         ADC      #80H
         STA      CWORK0+1,Y
; 
         LDA      CWORK0+3,Y
         CLC
         ADC      #80H
         STA      CWORK0+3,Y
; 
         DEC      <WORK
         BNE      CREL10
; 
CREL50   EQU      $ 
         LDX      <INDEX 
; 
         RTS
; 
CREL80   EQU      $ 
         LDX      <INDEX 
; 
;#####################################################################
;#                   (X) -- vs OBJ index                             #
;#                    Yr -- vs OBJ CWORK1 index                      #
;#                  WORK -- Cross elevator No. ( 0 - 1 )             #
;#       JSR      PLONCK    [ El & Lf & Ld on player check ]         #
;#####################################################################
PLONCK   EQU      $ 
         LDA      CWORK0+3,Y      ; Head cross check !
         SEC
         SBC      PLCWOK+1
         CMP      #4
         BCS      PLOC20               ;- IF  head cross ?          ( NO ; PLOC20 ) 
; 
         LDA      <YCALC0
         BPL      PLOC20               ;- IF  now jump down ?       ( YES ; PLOC20 )
; 
         LDA      #1
         STA      <YCALC0                    ; Player down set 
; 
PLOC20   EQU      $               ; Foot check !
         LDA      PLCWOK+3
         SEC
         SBC      CWORK1+1,Y
         CMP      #6
         BCS      PLOC40               ;- IF  foot cross ?          ( NO ; PLOC40 ) 
; 
         LDA      <YCALC0
         BMI      PLOC40               ;- IF  now jump up ?         ( YES ; PLOC20 )
; 
         LDA      <WORK                 ; Take on set !
         LDY      <ENMYNO,X
         CPY      #ELV0 
         BEQ      PLOC30                    ;- IF  up elevator ?    ( YES ; PLOC30 )
; 
         CPY      #ELV1 
         BEQ      PLOC30                    ;- IF  down elevator ?  ( YES ; PLOC30 )
; 
         TXA
; 
PLOC30   EQU      $ 
         LDX      <INDEX 
         STA      ONLFFG,X                  ; Lift take on flag set 
; 
         LDA      #BWALK
         STA      <PLSTAT                    ; <CSTAT <-- Walk set
; 
         RTS
; 
PLOC40   EQU      $               ; Side check !
         LDA      #1
         STA      <WORK
; 
         LDA      PLCWOK+2
         SEC
         SBC      CWORK1,Y
         CMP      #8
         BCC      PLOC60               ;- IF  cross right side ?    ( YES ; PLOC60 )
; 
PLOC50   EQU      $ 
         INC      <WORK
; 
         LDA      CWORK1+2,Y
         CLC
         SBC      PLCWOK
         CMP      #9
         BCS      PLOC80               ;- IF  cross left side ?     ( NO ; PLOC80 ) 
; 
PLOC60   EQU      $ 
         JSR      PLCLRS                    ; Player cross LF & RT side check sub 
; 
PLOC80   EQU      $ 
         LDX      <INDEX 
; 
         RTS
; 
;#####################################################################
;#                    (X) -- Index                                   #
;#                    (Y) -- 1 : Top    elevator                     #
;#                           2 : Bottom                              #
;#       JST      PLONEL    [ Player on Elavator pos set ]           #
;#####################################################################
PLRVPD   EQU      $-1       ; Player elevator on position revice data ! 
         HEX      80,00 
; 
PLONEL   EQU      $ 
         TAY
; 
         LDA      ENYPS1,X
         CLC
         ADC      PLRVPD,Y
	BNE	PLON30
;;;;         BRA	  PLON30	  ; SKIP   (LDA   ENYPS1,X) 
	LDA	#2
	STA	<PLYPS0
	RTS
; 
;#####################################################################
;#                    (X) -- Index                                   #
;#       JST      PLONLF    [ Lift.Elavator.Land on player pos set ] #
;#####################################################################
PLONLF   EQU      $ 
         LDA      ENYPS1,X
; 
PLON30   EQU      $ 
         LDY      <PLCMOD
         CPY      #PLSF 
         BEQ      PLON90          ; Fail --! No set 
; 
         LDY      <ENYPS0,X
         CPY      #1
         BNE      PLON90          ; No. display --! No set
; 
         SEC
         SBC      #20H
         STA      PLYPS1                    ; Revice player (y)pos (L) set
; 
;;;;     LDA      ENYPS0,X
         TYA
         SBC      #0
         STA      <PLYPS0                    ; Revise player (y)pos (H) set
	BNE	PLON50
; 
	STZ	ONLFFG,X
	LDA	#1
	STA	PLSTAT
; 
PLON50	EQU	$
; 
         LDA      #0
         STA      <PLYCL0
         STA      PLYCL1
; 
PLON90   EQU      $ 
         RTS
; 
;#####################################################################
;#       JSR      PLOFCK    [ Player out frame check ]               #
;#                   <C> -- 0 : In  frame                            #
;#                          1 : Out                                  #
;#####################################################################
PLOFCK   EQU      $ 
;;;         LDA      PLFMSD
;;;         CMP      #11110000B
;;;         BCS      POFC80
; 
;;;         LDY      <PLYPS0
;;;         DEY
;;;         BNE      POFC80
; 
;;;         LDA      PLYPS1
;;;         CMP      #0D0H 
; 
         LDA      PLFMSD
         AND      #11110000B
         CLC
         BEQ      POFC80
;
         SEC
;
POFC80   EQU      $ 
; 
         RTS
; 
;#####################################################################
;#       JSR      ENCCKS    [ Enemy cross check sub ]                #
;#                    Yr -- Index CWORK0                             #
;#                   <Z> -- 0 : Display    enemy                     #
;#                          1 : No display   "                       #
;#####################################################################
ENCCKS   EQU      $ 
         LDA      <INDEX 
; 
;#####################################################################
;#                    Ar -- Index                                    #
;#       JSR      LFCCKS    [ Lift cross check sub ]                 #
;#                    Yr -- Index CWORK0                             #
;#####################################################################
LFCCKS   EQU      $ 
         ASL      A 
         ASL      A 
         CLC
         ADC      #ENCWOK-CWORK0
         TAY
; 
         LDA      ENFMSD
         AND      #0FH
         CMP      #0FH
; 
         RTS
; 
;#####################################################################
;#       JSR      CRPLBG    [ Cross player vs BG block ]             #
;#                 CRFLG -- xx00xxxx                                 #
;#                          ||  |||+ 0 : Right cross                 #
;#                          ||  ||+- 0 : Left    "                   #
;#                          ||  |+-- 0 : Up      "                   #
;#                          ||  +--- 0 : Dw      "                   #
;#                          ||                                       #
;#                          |+------ 0 :                             #
;#                          +------- 0 : Jump up "                   #
;#####################################################################
TPFOPD   EQU      $         ; Top frame out pos data !
         HEX      20              ; Big   mario 
         HEX      10              ; Small 
; 
CRPLBG   EQU      $         ;< Initial > 
         LDA      BGCROF
         BNE      CPB035          ;- IF  BG cross check OFF ?   ( YES ; CPB035 )
; 
         LDA      <PLCMOD
         CMP      #PLSF 
         BEQ      CPB035          ;- IF  drop ( fail ) ?        ( YES ; CPB035 )
; 
         CMP      #NOCRMD+1 
         BCC      CPB035          ;- IF  no cross check mode ?  ( YES ; CPB035 )
; 
         LDA      #BJUMP
         LDY      PLSMFG
         BNE      CPB020          ; IF  in water ?             ( YES ; CPB020 )
; 
         LDA      <CSTAT 
         BEQ      CPB010          ;- IF  now walk ?             ( YES ; CPB010 )
; 
         CMP      #PWIRE
         BNE      CPB030          ;- IF  tuch wire ?            ( NO ; CPB030 ) 
; 
CPB010   EQU      $ 
         LDA      #BDROP               ; <CSTAT <-- Drop set 
; 
CPB020   EQU      $ 
         STA      <PLSTAT
; 
CPB030   EQU      $ 
         LDA      <PLYPS0
         CMP      #1
         BNE      CPB035          ;- IF  in frame ?                       ( NO ; CPB035 ) 
; 
         LDA      #11111111B
         STA      CRFLG                ; Cross flag init
; 
         LDA      PLYPS1
         CMP      #0CFH 
         BCC      CPB038
; 
CPB035   EQU      $ 
; 
         RTS
; 
CPB038   EQU      $         ;< Cross check > 
         LDY      #2
         LDA      PLSDFG
         BNE      CPB040          ;- IF  sit down player ?                ( YES ; CPB040 )
; 
         LDA      PLSIZE
         BNE      CPB040          ;- IF  small player ?                   ( YES ; CPB040 )
; 
         DEY
; 
         LDA      PLSMFG
         BNE      CPB040          ;- IF  swim player ?                    ( YES ; CPB040 )
; 
         DEY
; 
CPB040   EQU      $               ; Head check !
         LDA      CRSDID,Y
         STA      <WORK8 
         TAY
; 
         LDX      PLSIZE
         LDA      PLSDFG
         BEQ      CPB050               ;- IF  sit down mario ?            ( YES ; CPB050 )
; 
         INX
; 
CPB050   EQU      $ 
         LDA      PLYPS1
         CMP      TPFOPD,X
         BCC      CPB090               ;- IF  top out of frame table ?    ( YES ; CPB090 )
; 
;;;;;;;;;LDA      #0
;;;;;;;;;JSR      PLCBCK               : Head check 
	LDA	#1
	STA	<YWORK
         JSR      PLCBCKB 
         BEQ      CPB090               ;- IF  head cross ?                ( NO ; CPB090 ) 
; 
         JSR      COINCK               ; UP cross pros !
         BCS      CPB160                    ;- IF  catch coin ?           ( YES ; CPB160 )
; 
         LDY      <PLYCL0
         BPL      CPB090                    ;- IF  now jump down ?        ( YES ; CPB090 )
; 
         LDY      <WORK+4
         CPY      #04H
         BCC      CPB090                    ;- IF  cross volume ! 8 ?     ( YES : CPB090 )
; 
         JSR      BRBKCK                    ; Break block check 
         BCS      CPB070                    ;- IF  break block ?          ( NO ; CPB070 ) 
; 
         LDY      <ENVRFG
         BEQ      CPB080                    ;- IF  underwater ?           ( YES ; CPB080 )
; 
         LDY      TMES3 
         BNE      CPB080                    ;- IF  break next block OK ?  ( NO ; CPB080 ) 
; 
         JSR      BKPINT                         ; Block pros init
         BRA      CPB090
;;K;;         JMP      CPB090
; 
CPB070   EQU      $ 
         CMP      #WOOD0
         BEQ      CPB080                    ;- IF  wood ?                 ( YES ; CPB080 )
; 
         LDA      #1
         STA      !SOUND0                           ; Sound no break block  @@@@@@@@ 
; 
CPB080   EQU      $ 
         LDA      #1
         STA      <YCALC0                         ; Player down set
; 
CPB090   EQU      $               ; Foot check !
         LDY      <WORK8 
         LDA      PLYPS1
         CMP      #0CFH 
         BCS      CPB300               ;- IF  bottom out of frame ?       ( YES ; CPB300 )
; 
;;;;;;;;;INY
;;;;;;;;;LDA      #0
;;;;;;;;;JSR      PLCBCK               : LF foot check
	STZ	<YWORK
         JSR      PLCBCKA 
; 
         JSR      COINCK               ; Bonus coin check 
         BCS      CPB160               ;- IF  touch coin LF foot ?        ( YES ; CPB160 )
; 
         PHA
; 
;;;;;;;;;INY
;;;;;;;;;LDA      #0
;;;;;;;;;JSR      PLCBCK               : RT foot check
	STZ	<YWORK
         JSR      PLCBCKA 
; 
         STA      <WORK                 ; <WORK   <-- Right foot cross block No.
; 
         PLA
         STA      <WORK+1
         BNE      CPB180               ;- IF  cross LF foot ?             ( YES ; CPB180 )
; 
         LDA      <WORK
         BEQ      CPB300               ;- IF  cross RT foot ?             ( NO ; CPB300 ) 
; 
;                                      ; DOWN cross pros >
         JSR      COINCK                    ; Bonus coin check
         BCC      CPB180                    ;- IF  touch coin RT foot ?        ( NO ; CPB180 )
; 
CPB160   EQU      $ 
         JMP      PLTHCO                         ; Touch coin pros
; 
CPB180   EQU      $ 
         JSR      THWRCK
         BCS      CPB300                    ;- IF  tuch wire ?                 ( YES ; CPB300 ) 
; 
         LDY      <PLYCL0
         BMI      CPB300                    ;- IF  now jump up ?               ( YES ; CPB300 ) 
; 
         CMP      #STEK0
         BNE      CPB200                    ;- IF  touch steck ?               ( NO ; CPB200 )
         JMP      PLSKCR                    ; Touch last steck clear pros 
; 
CPB200   EQU      $ 
         JSR      STBKCK                    ; See thru block check
         BEQ      CPB300                    ;- IF  see thru block ?            ( YES ; CPB090 ) 
; 
         LDY      PLSPON
         BNE      CPB290                    ;- IF  on spring now ?             ( YES ; CPB290 ) 
; 
         LDY      <WORK+4
         CPY      #5
         BCC      CPB230                    ;- IF  cross volume < 5 ?          ( YES ; CPB230 ) 
; 
         LDA      <PLMMKI
         STA      <WORK
         JMP      PLCLRS
;
CPB230   EQU      $                         ; Take on ! 
         JSR      ONSPCK                         ; On spring bord check 
; 
         LDA      #0F0H 
         AND      PLYPS1
         STA      PLYPS1                         ; (y) pos hosei
; 
         JSR      INCMCK                         ; In chimney check 
; 
	 STZ	  <PLYCL0			; On ground set !
	 STZ	  PLYCL1
;
	 STZ	  HDCRCT                         ; Enemy hed cross counter clear
;
;;K;;         LDA      #0                        ; On ground set ! 
;;K;;         STA      <PLYCL0
;;K;;         STA      PLYCL1
;;K;;; 
;;K;;         STA      HDCRCT                         ; Enemy hed cross counter clear
;;K;;; 
CPB290   EQU      $ 
         LDA      #BWALK
         STA      <PLSTAT                         ; <CSTAT <-- Walk set 
; 
CPB300   EQU      $               ; Side check !
         LDY      <WORK8 
         INY
         INY
; 
         LDA      #2
         STA      <WORK
; 
CPB330   EQU      $ 
         INY
         STY      <WORK8 
; 
         LDA      PLYPS1
         CMP      #20H
         BCC      CPB350               ;- IF  top out of frame ?            ( YES ; CPB350 )
; 
         CMP      #0E4H 
         BCS      CPB380               ;- IF  bottom out of frame ?         ( YES ; CPB380 )
; 
;;;;;;;;;LDA      #1
;;;;;;;;;JSR      PLCBCK                    : LF & RT up side check 
	STZ	<YWORK
         JSR      PLCBCKC 
; 
         BEQ      CPB350               ;- IF  no cross ?                    ( YES ; CPB400 )
; 
         CMP      #CHM1 
         BEQ      CPB350               ;- IF  L-chimney ?                   ( YES ; CPB350 )
; 
         CMP      #WCHM0
         BEQ      CPB350               ;- IF  exit chimney in water ?       ( YES ; CPB350 )
; 
         JSR      THWRCK
         BCC      CPB400               ;- IF  touch wire ?                  ( NO ; CPB400 ) 
; 
CPB350   EQU      $ 
         LDY      <WORK8 
         INY
; 
         LDA      PLYPS1
         CMP      #08 
         BCC      CPB380               ;- IF  top out of frame ?            ( YES ; CPB380 )
; 
         CMP      #0D0H 
         BCS      CPB380               ;- IF  bottom out of frame ?         ( YES ; CPB380 )
; 
;;;;;;;;;LDA      #1
;;;;;;;;;JSR      PLCBCK                    : LF & RT down side check 
	STZ	<YWORK
         JSR      PLCBCKC 
; 
         BNE      CPB400               ;- IF  corss ?                       ( YES ; CPB400 )
; 
         DEC      <WORK
         BNE      CPB330               ;- IF  all side check end ?          ( NO ; CPB330 ) 
; 
CPB380   EQU      $ 
; 
         RTS
; 
CPB400   EQU      $                    ; Cross block No. check kind ! 
         JSR      STBKCK                    ; See thru block check
         BEQ      CPB480                    ;- IF  see thru block ?         ( YES ; CPB480 )
; 
         JSR      THWRCK                    ; Tuch wire check 
         BCC      CPB405                    ;- IF  touch wire ?             ( NO ; PLTHWR ) 
         JMP      PLTHWR
; 
CPB405   EQU      $ 
         JSR      COINCK                    ; Bonus coin check
         BCS      PLTHCO                    ;- IF  touch coin ?             ( YES ; PLTHCO )
; 
         JSR      SPONCK
         BCC      CPB420                    ;- IF  spring bord ?            ( NO ; CPB420 ) 
; 
CPB410   EQU      $ 
         LDA      PLSPON
         BNE      CPB480                    ;- IF  on spring now ?          ( YES ; CPB480 )
         JMP      CPB450
; 
CPB420   EQU      $                    ; In L-chimney check ! 
         LDY      <PLSTAT
         CPY      #BWALK
         BNE      CPB450                    ;- IF  walk player ?            ( NO ; CPB450 ) 
; 
         LDY      PLCMKI
         DEY
         BNE      CPB450                    ;- IF  player muki=right ?      ( NO ; CPB450 ) 
; 
         CMP      #WCHM0+1
         BEQ      CPB440                    ;- IF  exit chimney in water ?  ( YES ; CPB440 )
; 
         CMP      #CHM1+3 
         BNE      CPB450                    ;- IF  L-chimney ?              ( NO; CPB450 )
; 
CPB440   EQU      $                         ; In L-chimney flag set ! 
         LDA      PLOJBG
         BEQ      CPB442
; 
	LDY	<ICHFLG
	BNE	CPB442
         LDY      #4H				;DOKAN IN OUT
         STY      !SOUND0                                ; Ground <--! Underground sound set  @@@@@@ 
	STY	<ICHFLG
	STZ	SPMTIM
; 
CPB442   EQU      $
	 AND	  #11001111B 
;;;         ORA      #00010000B
         STA      PLOJBG                              ; Priority  OBJ < BG
; 
         LDA      PLXPS1
         AND      #0FH
         BEQ      CPB445                         ;- IF  all in chimney ?    ( NO ; CPB480 ) 
; 
         LDY      #0
         LDA      DSXP00
         BEQ      CPB443                         ;- IF  first frame ?       ( YES ; CPB443 )
; 
         INY
; 
CPB443   EQU      $ 
         LDA      PLICTD,Y
         STA      PLICCT                              ; Set  In L-chimney counter 
; 
CPB445   EQU      $ 
         LDA      <PLCMOD
         CMP      #PLSMMD 
         BEQ      CPB480                         ;- IF  start move mode ?   ( YES ; CPB480 )
; 
         CMP      #PLMDPY 
         BNE      CPB480                         ;- IF  play mode ?         ( NO ; CPB480 ) 
; 
         LDA      #PLC1MD 
         STA      <PLCMOD                              ; In L-chimney mode set 
; 
         RTS
; 
CPB450   EQU      $ 
         JSR      PLCLRS
; 
CPB480   EQU      $ 
; 
         RTS
; 
PLICTD   EQU      $         ; Player in L-chimney time data ! 
         HEX      34,34	;;T;; A0,34 
; 
;#####################################################################
;#                   (A) -- Cross block No.                          #
;#       JSR      PLTHCO    [ Player touch coin pros ]               #
;#####################################################################
PLTHCO   EQU      $ 
         JSR      PLSR60               ; Clear BG coin
; 
         INC      SCOCNT               ; INC  Secret coin count 
         JMP      COINUP               ; Coin count up
; 
;#####################################################################
;#                   (A) -- Cross block No.                          #
;#       JSR      PLSKCR    [ Player gorl steck clear ]              #
;#####################################################################
PLSKCR   EQU      $
	 STZ      GMMODE
;;K;;         LDA      #0
;;K;;         STA      GMMODE
;
         LDA      #SCMOD
         STA      SYMODE               ; Set score calc mode
;
        LDA     2142H
        CMP     #0BH
        BEQ     PLSK10
        LDA     #0F0H
        STA     !SOUND2
PLSK10  EQU     $
; 
;;cn         JSR      MLSLS20         ;mario,luigi slip data reset
;
         LDA      #18H
         STA      <PLXSD0
	PHX
	LDX	#0
PLSR61	EQU	$
	LDA	<ENMYNO,X
	CMP	#2DH
	BNE	PLSR63
	LDA	<ENCMOD,X
	CMP	#01H
	BNE	PLSR63
	LDA	ENXPS1,X
	SEC
	SBC	SCCH
	STA	ENOBJX
	LDA	ENYPS1,X
	STA	ENOBJY
	JSL	>BKM0ST
PLSR63	EQU	$
	INX
	CPX	#09
	BNE	PLSR61
	PLX
; 
PLSR60   EQU      $               ; Clear BG block 2x2 !
         LDY      <WORK+2
         LDA      #0
         STA      (<WORK+6),Y           ; Clera  coin data 
         JMP      BGCOES               ; Erase BG coin
; 
;#####################################################################
;#                   (A) -- Cross block No.                          #
;#                WORK+6 -- Tach wire frame address (L)              #
;#       JSR      PLTHWR    [ Player touch wire pros ]               #
;#####################################################################
PLWRVD   EQU      $-1             ; Tuch wire player (x)pos revice data ! 
         HEX      F9,07                ; Revice data (L)
         HEX      FF,00                ;             (H)
; 
PLYCKD   EQU      $               ; Gorl pole touch (y)pos check data ! 
         HEX      18,22,50,68 
PYCD     HEX      90
; 
PLTHWR   EQU      $ 
         LDY      <WORK+4
         CPY      #6
         BCC      PLW010          ;- IF  touch wire ?                     ( NO ; PLW190 ) 
; 
         CPY      #0AH
         BCC      PLW001          ;- IF  touch wire ?                     ( NO ; PLW190 ) 
PLW010   EQU      $ 
         RTS
; 
PLW001   EQU      $ 
         CMP      #POLE0
         BEQ      PLW020          ;- IF  gorl pole top ball ?            ( YES ; PLW020 ) 
; 
         CMP      #POLE0+1
         BNE      PLW060          ;- IF  gole pole ?                     ( NO ; PLW060 )
; 
PLW020   EQU      $               ; Touch gorl pole pros !
         LDA      <PLCMOD
         CMP      #PLCRMD 
         BEQ      PLW100               ;- IF  game clear mode ?          ( YES ; PLW100 ) 
; 
;	LDA	PLOBJX
;	CMP	#10H
;	BCS	PLW025
;	LDA	#02
;	BRA	PLW028
;PLW025	EQU	$
;         LDA      #00000001B
;PLW028	EQU	$
;         STA      PLCMKI                    ; Muki right set
; 
         INC      SRSTFG                    ; Scroll stop flag ON 
; 
         LDA      <PLCMOD
         CMP      #PLTPMD 
         BEQ      PLW040               ;- IF  player touch pole mode ?   ( YES ; PLW040 ) 
; 
         LDA      #GSHL                ; Touch gorl pole score clac ! 
         JSR      CHRCLR                    ; Clear  Gun shell
;
	 JSL	>GLBGST			; ;;K;;
;
        LDA     #0F0H           ; BGM STOP
        STA     !SOUND2
         LDA      #46H
         STA      !SOUND0                      ; Clear  BGM  @@@@@ 
         LSR      A 
         STA      GPSDFG                    ; Sound  up on small score @@@@@
; 
         LDX      #PYCD-PLYCKD
         LDA      PLYPS1
         STA      GLPTYP                    ; Set player first touch (y)
; 
PLW035   EQU      $ 
         CMP      PLYCKD,X
         BCS      PLW038
; 
         DEX
         BNE      PLW035
; 
PLW038   EQU      $ 
         STX      GLSCRE
; 
         LDA      COINCT1+1
         CMP      COINCT1+2
         BNE      PLW040
;
         CMP      PLYTM1
         BNE      PLW040
;
         LDA      #5
         STA      GLSCRE
;
PLW040   EQU      $ 
         LDA      #PLTPMD 
         STA      <PLCMOD                    ; Player mode set 
         BRA      PLW100
;;K;;         JMP      PLW100
; 
PLW060   EQU      $               ; Touch wood pros ! 
         CMP      #WOOD0
         BNE      PLW100               ;- IF  wood ?                     ( NO ; PLW100 )
; 
;;TR	LDA	MSOBJX
;;TR	BMI	PLW190
         LDA      PLYPS1
         CMP      #20H
         BCS      PLW100               ;- IF  must top on wood ?         ( NO ; PLW100 )
; 
         LDA      #PLWUMD 
         STA      <PLCMOD                    ; Set auto move ( next sky )
; 
PLW100   EQU      $               ; Touch wire revice & flag set !
         LDA      #PWIRE
         STA      <PLSTAT               ; Player status <-- Touch wire 
;
	 STZ	  <PLXSD0               ; Clear  player (x)speed
	 STZ	  PLXSD1
;;K;;         LDA      #0
;;K;;         STA      <PLXSD0               ; Clear  player (x)speed 
;;K;;         STA      PLXSD1
;;TR
	LDA	WDPONT
	BEQ	PLW105
	LDA	MSOBJX
	BPL	PLW105
	CMP	#0F8H
	BCC	PLW105
WDR010	EQU	$
	LDA	WDXPS0
	STA	<YWORK1
	LDA	WDXPS1
	STA	<YWORK
	MEM16
	REP	#20H
	LDA	<YWORK
	CLC
	ADC	#07H
	STA	<YWORK
	MEM8
	SEP	#20H
	LDA	<YWORK
	STA	PLXPS1
	LDA	<YWORK1
	STA	<PLXPS0
	LDA	#2
	STA	PLCMKI
	BRA	PLW190
PLW105	EQU	$
; 
         LDA      PLXPS1               ; Touch wire player (x)pos revice value calc ! 
         SEC
         SBC      DSXP01
         CMP      #10H
         BCS      PLW140                    ;- IF  must left side ?      ( YES ; PLW140 ) 
; 
         LDA      #00000010B
         STA      PLCMKI
; 
PLW140   EQU      $                         ; (x)pos revice ! 
         LDY      PLCMKI
         LDA      <WORK+6
         ASL      A 
         ASL      A 
         ASL      A 
         ASL      A 
         CLC
         ADC      PLWRVD,Y
         STA      PLXPS1
; 
         LDA      <WORK+6
         BNE      PLW190
; 
         LDA      DSXP10
         CLC
         ADC      PLWRVD+2,Y
         STA      <PLXPS0
; 
PLW190   EQU      $ 
; 
         RTS
; 
;#####################################################################
;#                   (A) -- Cross block No.                          #
;#       JSR      STBKCK    [ See thru block check ]                 #
;#                   <Z> -- 0 : Not see thru block                   #
;#                          1 : See thru block                       #
;#####################################################################
STBKCK   EQU      $ 
         CMP      #STBCO
         BEQ      STBC90    ;- IF  see thru coin block ?       ( YES ; STBC90 ) 
; 
         CMP      #STBMS    ;- IF  see thru mushroom block ?   ( YES ; STBC90 ) 
         BEQ      STBC90    ;- IF  see thru Special mushroom ? ( Y;
;
         CMP      #STBDM
         BEQ      STBC90    ;- IF  see thru Death mushroom ?   ( Y;
;
	CMP	#STRTR		; IF  see thru wood ( YES ; STBC90 )
	BEQ	STBC90
;
	CMP	#STRST		; IF  see thru star ( YES ; STBC90 )
	BEQ	STBC90
;
         CMP      #STBSM
;
;
STBC90   EQU      $ 
; 
         RTS
; 
;#####################################################################
;#       JSR      ONSPCK    [ On spring bord check ]                 #
;#####################################################################
ONSPCK   EQU      $ 
         JSR      SPONCK          ; Spring bord on check                   #
         BCC      ONSC90          ;- IF  spring bord ?          ( NO ; ONSC90 ) 
; 
         LDA      #70H
         STA      PLGPWR               ; On spring G-power set
         STA      WGPOWR
; 
         LDA      #0F9H 
         STA      SPGPWR
; 
         LDA      #3
         STA      TMES5                ; Jumping timer
; 
;;;;;;   LDA      #1
         LSR      A                    ; A <-- #1 
         STA      PLSPON               ; Spring on flag ON
; 
ONSC90   EQU      $ 
; 
         RTS
; 
;#####################################################################
;#       JSR      SPONCK    [ Spring bord on check ]                 #
;#                   <C> -- 0 : No                                   #
;#                          1 : On spring bord                       #
;#####################################################################
SPONCK   EQU      $ 
         CMP      #SPRIG
         BEQ      SPOC80    ;- IF  spring bord ?          ( YES ; SPOC80 )
; 
         CMP      #SPRIG+1
         CLC
         BNE      SPOC90    ;- IF  spring bord ?          ( NO ; SPOC80 ) 
; 
SPOC80   EQU      $ 
         SEC
; 
SPOC90   EQU      $ 
; 
         RTS
; 
;#####################################################################
;#       JSR      INCMCK    [ In I-chimney check ]                   #
;#####################################################################
INCMCK   EQU      $ 
         LDA      <KEYUD 
         AND      #00000100B
         BEQ      IMCC90          ;- IF  in key down ?            ( NO ; IMCC90 ) 
; 
         LDA      <WORK
         CMP      #CHM0+1 
         BNE      IMCC90          ;- IF  left foot on chimney  ?  ( NO ; IMCC90 ) 
; 
         LDA      <WORK+1
         CMP      #CHM0 
         BNE      IMCC90          ;- IF  right foot on chimney ?  ( NO ; IMCC90 ) 
; 
         LDA      #030H 
         STA      PLICCT               ; In I-chimney counter 
; 
         LDA      #PLC0MD 
         STA      <PLCMOD               ; Player in chimney mode set 
; 
         LDA      #4H
	STA	SFTYTM
	STZ	SPMTIM
; 
         LDA      #00000000B
         STA      PLOJBG               ; Priority  OBJ < BG 
; 
         LDA      CMSLFG
         BEQ      IMCC80          ;- IF  select chimney ?         ( NO ; IMCC90 ) 
; 
         AND      #00001111B      ; In selelct chimney !
         TAX
	LDA	!CORSNO
	CMP	#08H
	BCS	IMCC60
	LDA	#1
	STA	WARPCT
; 
IMCC60   EQU      $ 
         LDA      !CORCDT,X 
;;;         LDY      URAFLG
;;;         BEQ      IMCC70          ;ura-world ?
;                                 ;yes
;;;         SEC
;;;         SBC      #09H
IMCC70   EQU      $
         TAY
         DEY
         STY      CORSNO               ; Cours No.
;
         LDX      !CROSID,Y 
	TYX
	LDA	>CROSID,X
	TAX
         LDA      >COURSD,X 
         STA      TRNPT0               ; Turning point data 
; 
         LDA      #80H
         STA      !SOUND2                 ; BGM clear
; 
         LDA      #0
         STA      NXFPT0               ; Next frame No. 
         STA      CORSID               ; Course index 
         STA      GOALCT               ; Gorl count 
         STA      CHEVFG               ; Change environment flag OFF
; 
         INC      SEMSFG               ; See thru mushroom flag ON
         INC      PLFSFG               ; Player first start flag ON 
	LDA	#0F3H
	STA	!SOUND2
	STA	SVCKFG
;
IMCC80	EQU	$
         LDA      #4H
         STA      !SOUND0                 ; Next ground  sound set  @@@@@@ 
	RTS
; 
IMCC90   EQU      $ 
; 
         RTS
; 
;#####################################################################
;#                  WORK -- 01 : Cross right side                    #
;#                          02 :   "   left   "                      #
;#       JSR      PLCLRS    [ Player cross left & right sub ]        #
;#####################################################################
PLCLRS   EQU      $ 
         LDA      #0
         LDY      <PLXSD0
         LDX      <WORK
         DEX
         BNE      PCLR40          ;- IF  left side cross ?        ( YES ; PCLR40 )
; 
;;;;;;;  LDX      #00000001B      < Right > 
         INX                      ;(X <-- #1)
         CPY      #0
         BMI      PCLR90               ;- IF  now right move ?    ( NO ; PCLR90 ) 
; 
         LDA      #0FFH 
         JMP      PCLR50
; 
PCLR40   EQU      $               ; Left !
         LDX      #00000010B
         CPY      #1
         BPL      PCLR90               ;- IF  now left move ?     ( NO ; PCLR90 ) 
; 
         LDA      #1
; 
PCLR50   EQU      $ 
         LDY      #10H
         STY      TMES4                ; Cross wall wait time set 
; 
         LDY      #0
         STY      <PLXSD0               ; (x) speed <-- 0
; 
         CMP      #0
         BPL      PCLR80
; 
         DEY
; 
PCLR80   EQU      $ 
         STY      <WORK
; 
         CLC
         ADC      PLXPS1
         STA      PLXPS1
; 
         LDA      <PLXPS0
         ADC      <WORK
         STA      <PLXPS0
; 
PCLR90   EQU      $ 
         TXA
         EOR      #11111111B
         AND      PLCRFG
         STA      PLCRFG               ; Cross muki set 
; 
         RTS
; 
;#####################################################################
;#                   (A) -- Block No.                                #
;#       JSR      BRBKCK    [ Break block check ]                    #
;#                   <C> -- 0 : Break block                          #
;#                          1 : No break block                       #
;#####################################################################
NOBKID   EQU      $         ; No break block index data ! 
         BYTE     NOBK0           ; Color-00 block
         BYTE     NOBK1           ;      -01
         BYTE     NOBK2           ;      -02
         BYTE     NOBK3           ;      -03
; 
BRBKCK   EQU      $ 
         JSR      BKCKSB
         CMP      NOBKID,X
; 
         RTS
; 
;#####################################################################
;#                   (A) -- Block No.                                #
;#       JSR      THWRCK    [ Tuch wire check ]                      #
;#                   <C> -- 0 : Break block                          #
;#                          1 : No break block                       #
;#####################################################################
THWBID   EQU      $         ; Tuch wire block index data !
         BYTE     THWR0           ; Color-00 block
         BYTE     THWR1           ;      -01
         BYTE     THWR2           ;      -02
         BYTE     THWR3           ;      -03
; 
THWRCK   EQU      $ 
         JSR      BKCKSB
         CMP      THWBID,X
; 
         RTS
; 
;#####################################################################
;#                   (A) -- Block No.                                #
;#       JSR      COINCK    [ Bonus coin check ]                     #
;#                   (C) -- 0 : No catch coin                        #
;#                          1 : Catch coin                           #
;#####################################################################
COINCK   EQU      $ 
         CMP      #COIN0
         BEQ      COCK90
; 
         CMP      #COIN1
         BEQ      COCK90
; 
         CLC
; 
         RTS
; 
COCK90   EQU      $ 
         LDA      #01 
         STA      !SOUND3      ; Sound catch coin @@@@@@@@@@ 
; 
         RTS
; 
;#####################################################################
;#                   (A) -- Block No.                                #
;#       JSR      BKCKSB    [ Block No. check sub ]                  #
;#####################################################################
BKCKSB   EQU      $ 
         TAY
; 
         AND      #11000000B
         ASL      A 
         ROL      A 
         ROL      A 
         TAX
; 
         TYA
; 
RT1      EQU      $ 
         RTS
; 
;#####################################################################
;#                   (X) -- Index                                    #
;#       JSR      CRENBG    [ Cross enemy vs BG check ]              #
;#####################################################################
CRDWDT   EQU      $    ;   Downinig stat 
         BYTE     DOWN      ; as WALK 
         BYTE     DOWN      ;    DOWN 
         BYTE     JUMP      ;    JUMP 
         BYTE     JUMP      ;    STOP 
         BYTE     JUMP      ;    TIME 
         BYTE     DROP      ;    DROP 
; 
CRXSDT   EQU      $ 
         HEX      10,F0 
; 
;---- Take off ceack ---
CRENBG   EQU      $ 
;;;;     LDA      FMCNT     :TEST TEST TEST TEST TEST TEST
;;;;     AND      #1
;;;;     BNE      RT1 
; 
         LDA      <ENSTAT,X
         AND      #00100000B
         BNE      RT1   (RETURN)  ; Kame yarare (No BG. check)
; 
;BGYCMP   EQU      $
;        LDA      ENYPS1,X        : No. 
;;;;;    CMP      #08H
;;;;;    BCC      RT1 
;;;;;;   CMP      #0D0H 
;;;;;;   BCS      RT1 
;        ADC      #38H            : BG. cross  limit check
;        CMP      #3FH
; 
         JSR      BGYCMP
         BCC      RT1 
; 
         LDY      <ENMYNO,X
         CPY      #EXT0 
         BNE      CRENBB
         LDA      ENYPS1,X
         CMP      #25H
         BCC      RT1 
CRENBB   EQU      $ 
         CPY      #FTR2 
         BNE      CRENB0
         JMP      CREB01
; 
CRENB0   EQU      $ 
         CPY      #FIEN 
         BNE      CRENC0
         JMP      CRFEBG
; 
CRETURN  EQU      $
         RTS
;
CRENC0   EQU      $ 
         CPY      #EXT0 
         BEQ      CRENA0
         CPY      #BMUS           ; Walk mosh 
         BEQ      CRENA0
; 
         CPY      #FFWR
         BEQ      CRETURN         ; Flower      ?
         CPY      #IKTR 
         BCS      CRETURN          ; Flying Kame ? 
; 
CRENA0   EQU      $ 
         JSR      ENBGCK
         BNE      CRENA1          ; Cross ? 
; 
CRENA2   EQU      $ 
         JMP      CREN10          ; No cross
; 
CRENA1   EQU      $ 
;;;      CMP      #WOOD0          : Wood
;;;      BEQ      CRENA2
;;;      CMP      #COIN0                     : No. Cheack 
;;;      BEQ      CRENA2          : Coin
         JSR      BGCMP 
         BEQ      CRENA2
; 
         CMP      #BKBSW
         BNE      CREN01          ; Tumble ?
; 
;;;         LDY      <WORK+2
;;;         LDA      #0
;;;         STA      (<WORK+6),Y      ; Clear 
; 
         LDA      <ENMYNO,X
         CMP      #ENDTR
         BCS      FIR000
; 
         CMP      #YPVS 
         BNE      CRENA3
         JSR      BGFAIL
; 
CRENA3   EQU      $ 
         LDA      #1              ; 100 pts 
         JSR      SCRSET          ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; 
FIR000   EQU      $ 
FIROUT   EQU      $               ; **  Fire hitted to Enemy ** 
         LDA      ENMYNO,X
;;;;     CMP      #TUTR 
;;;;     BEQ      FIOT05
         CMP      #FTR0 
         BCC      FIOT10          ; Flying  ? 
         CMP      #FTR7+1 
         BCS      FIOT10
         CMP      #FLWR 
         BEQ      FIOT10
         CMP      #FFWR
         BEQ      FIOT10
;;;;;    CMP      #EXT0 
;;;;;    BEQ      FIOT10
;;;;;    CMP      #JFS0 
;;;;;;   BEQ      FIOT10
         CMP      #WTR0 
         BCC      FIOT05
         CMP      #JPTR+1 
         BCC      FIOT10
; 
FIOT05   EQU      $ 
         AND      #00000001B      ; Yes ! 
         STA      <ENMYNO,X
; 
FIOT10   EQU      $ 
         CMP      #BMUS
         BEQ      FIOT11
         CMP      #YPVS
         BEQ      FIOT11
;
;;;         LDA      <ENSTAT,X
;;;         AND      #11110000B
;;;         ORA      #JUMP 
         LDA      #JUMP
         STA      <ENSTAT,X
; 
FIOT11   EQU      $
         DEC      ENYPS1,X
         DEC      ENYPS1,X
; 
         LDA      <ENMYNO,X
         CMP      #IKTR 
         BEQ      PK1 
; 
         LDA      #0FDH 
         LDY      <ENVRFG
         BNE      CREN22    ; In water ?
; 
PK1      EQU      $ 
         LDA      #0FFH 
CREN22   EQU      $ 
         STA      <ENYCL0,X
; 
         LDY      #1
         JSR      CRECMP          ; Player ; Enemy ?
         BPL      CREN00          ; 
         INY
CREN00   EQU      $               ;  < ; Right jump 
         LDA      <ENMYNO,X
         CMP      #GSHL 
         BEQ      PLO1
         CMP      #FTM0 
         BEQ      PLO1
         STY      <ENMMKI,X
PLO1     EQU      $ 
         DEY
         LDA      CRXSDT,Y
         STA      <ENXSD0,X
CRRETN   EQU      $ 
         RTS
; 
CREN01   EQU      $ 
         LDA      <WORK+4
         SEC
         SBC      #8
         CMP      #5              ; "4" dot crossing ?
         BCS      CREN10
;                                 : No !
         LDA      <ENSTAT,X
         AND      #01000000B
         BNE      CREN08
; 
         LDA      <ENSTAT,X
         ASL      A 
         BCC      CREN011 
CREN010  EQU      $ 
         JMP      CREN90
CREN011  EQU      $ 
; 
         LDA      <ENSTAT,X
         BEQ      CREN010 
         CMP      #DROP 
         BEQ      CREN06
         CMP      #STOP 
         BCS      CRERET
; 
         LDA      <ENSTAT,X
         CMP      #JUMP 
         BNE      CREN06
; 
         LDA      #10H
         LDY      <ENMYNO,X
;;;;     CPY      #YPVS 
;;;;     BEQ      CREN08
         CPY      #EXT0 
         BNE      CREN02          ; Bakudan ? 
         LDA      #0              ; No. Stopping
CREN02   EQU      $ 
         STA      TMEL1,X 
; 
         LDA      #STOP 
         STA      <ENSTAT,X
; 
         JSR      FLORON
CRERET   EQU      $ 
         RTS
; 
CREN06   EQU      $ 
         LDA      <ENMYNO,X
         CMP      #YPVS           ; Mush enemy
         BEQ      CREN08
         CMP      #EXT0           ; Bakudan ? 
         BNE      CREN061 
; 
         LDA      #1              ; Walk speed set
         STA      <ENMMKI,X
         LDA      #8
         STA      <ENXSD0,X
; 
         LDA      <FMCNT 
         AND      #00000111B
         BEQ      CREN08          ; <<Tamani aho>
; 
CREN061  EQU      $ 
         LDY      #1
         JSR      CRECMP
         BPL      CREN07
         INY
CREN07   EQU      $ 
         TYA
;;;      LDX      SPMTIM
;;;      BEQ      CREN075 
;;;      EOR      #00000011B
;CREN075  EQU      $
;;;      LDX      INDEX 
         CMP      <ENMMKI,X
         BNE      CREN08
;                                 :        Surch
         JSR      CREP20          ; Enemy ------! Player
CREN08   EQU      $ 
         JSR      FLORON
; 
;;;;;;   STA      ENYCL0,X
;;;;;;   STA      ENYCL1,X
; 
;;;;;;   LDA      ENYPS1,X
;;;;;;   AND      #0F0H 
;;;;;;   ORA      #00001000B
;;;;;;   STA      ENYPS1,X
; 
         LDA      <ENSTAT,X
         AND      #80H
         BNE      CREN09
; 
         LDA      #WALK 
         STA      <ENSTAT,X
         RTS
; 
CREN09   EQU      $ 
         LDA      <ENSTAT,X
         AND      #10111111B
         STA      <ENSTAT,X
         RTS
; 
CREN10   EQU      $ 
         LDA      <ENMYNO,X
         CMP      #TUTR           ;right left walk ?
         BNE      CREN2A          ; yes --! Muki turn 
; 
         LDA      <ENSTAT,X
         BEQ      CREP20
;;;;     RTS
; 
CREN2A   EQU      $ 
         LDA      <ENSTAT,X
         TAY
         ASL      A 
         BCC      CREN1A
         LDA      <ENSTAT,X
         ORA      #01000000B
         BRA      CREN11
;;K;;         JMP      CREN11
;
CREN1A   EQU      $ 
         LDA      CRDWDT,Y
CREN11   EQU      $ 
         STA      <ENSTAT,X
; 
;;;;;    LDA      ENSTAT,X
;;;;;    BNE      CREN90
;;;;;    LDA      #DOWN 
;CREN11   EQU      $
;;;;;    STA      ENSTAT,X
; 
CREN90   EQU      $ 
         LDA      ENYPS1,X
         CMP      #20H
         BCC      CREP18
; 
;----- Pole cross check --- 
;;;;;;   LDA      ENFMSD
;;;;;;   AND      #00001100B
;;;;;;   BNE      CREP18       : Displaying ?  [No. Not checking] 
; 
         LDY      #CRBD01-CRBD00+1     ; Yes !
         LDA      #2
         STA      <WORK8 
CREP10   EQU      $ 
;;;;;;   LDA      ENSTAT,X
;;;;;;   AND      #10000000B
;;;;;;   BNE      CREP11          : Hi speed ?
; 
         LDA      <WORK8           ; No. Muki check
         CMP      <ENMMKI,X
         BNE      CREP15
; 
CREP11   EQU      $ 
         LDA      #1
         JSR      ENCBCK
         BEQ      CREP15
;;;;     CMP      #WOOD0          : Wood & coin no cheak
;;;;     BEQ      CREP15
;;;;     CMP      #COIN0
;;;;     BNE      CREP20
         JSR      BGCMP 
         BNE      CREP20
; 
CREP15   EQU      $ 
         DEC      <WORK8 
         INY
         CPY      #CRBD01-CRBD00+3
         BCC      CREP10
CREP18   EQU      $ 
         RTS
; 
CREP20   EQU      $ 
         CPX      #9
         BEQ      CREP21          ; Mushroom
; 
         LDA      <ENSTAT,X
         ASL      A 
         BCC      CREP21          ; Hi spead ?
; 
;;         LDA      #02H            ; Yes ! 
;;         STA      0FFH            ; <S! 
	CPX	#9
	BEQ	CREP21
	LDA	#1
	STA	!SOUND0
	JSL	>BOMBST
CREP21   EQU      $ 
         LDA      <ENMYNO,X
         CMP      #FIEN 
         BNE      CREP22
; 
         LDA      #0
         STA      <WORK
; 
         LDY      #0FAH 
         JMP      FIEN10
; 
CREP22   EQU      $ 
         JMP      ENCRA3
; 
;;;;;;;  LDA      ENXSD0,X        : Muki & Speed  turn
;;;;;;;  EOR      #0FFH 
;;;;;;   TAY
;;;;;;;  INY
;;;;;;;; STY      ENXSD0,X
; 
;;;;;;;  LDA      ENMMKI,X
;;;;;;   EOR      #00000011B
;;;;;;   STA      ENMMKI,X
;;;;;;;  RTS
; 
CRECMP   EQU      $ 
         LDA      ENXPS1,X
         SEC
         SBC      XPOS1 
         STA      <WORK
; 
         LDA      <ENXPS0,X
         SBC      <XPOS0 
         RTS
; 
FLORON   EQU      $ 
;;;;;    LDA      #0
;;;;;    STA      ENYCL0,X
;;;;;    STA      ENYCL1,X
         JSR      YCLCLR
; 
         LDA      ENYPS1,X
         AND      #0F0H 
         ORA      #00001000B
         STA      ENYPS1,X
         RTS
; 
BGYCMP   EQU      $ 
         LDA      ENYPS1,X        ; No. 
         CLC
         ADC      #3EH            ; BG. cross  limit check
         CMP      #44H
R1       EQU      $ 
         RTS
; 
;#####################################################################
;#                    (X) -- Index                                   #
;#       JSR      CREB01    [ Cross Pyon kame vs BG. cheack ]        #
;#       JSR      CREB03    [ Cross Bunus star vs BG. cheack ]       #
;#####################################################################
CREB03   EQU      $ 
CREB01   EQU      $ 
;;;;;;   LDA      #0FDH 
;CREB02   EQU      $
;;;;     STA      WORK8           : Jump power
; 
         JSR      BGYCMP
         BCC      CREB10
; 
         LDA      <ENYCL0,X
         CLC
         ADC      #2
         CMP      #3
         BCC      CREB10
; 
         JSR      ENBGCK
         BEQ      CREB10          ; Cross ? 
; 
;;;      CMP      #COIN0
         JSR      BGCMP 
         BEQ      CREB10          ; Coin -! No cross
; 
         JSR      FLORON
; 
;;;      LDY      WORK8           : Yes!
;;;;     LDA      WORK8 
;;;;;    CMP      #BKBSW
;;;;;    BNE      CREB05          : Tumble ?
; 
;;;;;    LDY      WORK+2
;;;;;    LDA      #0
;;;;;    STA      [WORK+6],Y      : Clear 
; 
;;;;;    LDA      #SHTR 
; 
;;;;;    LDA      #DOWN 
;;;;;    STA      ENSTAT,X
; 
;;;;;    LDY      #0FCH 
;CREB05   EQU      $
;;;;;;   TYA
         LDA      #0FDH 
         STA      <ENYCL0,X
CREB10   EQU      $ 
         JMP      CREN90          ; Pole check
;#####################################################################
;#                    (X) -- Index                                   #
;#       JSR      CRFEBG    [ Fire enemy      vs BG. cheack ]        #
;#####################################################################
CRFEBG   EQU      $ 
         JSR      ENBGCK
         BEQ      CRFE60          ; Cross ? 
; 
         CMP      #BKBSW          ; Bleak Block ? 
         BNE      CRFE01
; 
BGFAIL   EQU      $ 
         JSR      FIRH10          ; Yes   Fail
         LDA      #0FCH 
         STA      <ENYCL0,X
         RTS
; 
CRFE01   EQU      $ 
         LDA      ETMS01,X
         BNE      CRFE60
;                                 : Foot on ok ?
         LDA      <ENSTAT,X        ; yes!
         AND      #10001000B
;;;;;   (ORA      #WALK)
         STA      <ENSTAT,X
; 
         JSR      FLORON          ; Foot on ! 
; 
         JMP      CREN90          ; Pole check
; 
CRFE60   EQU      $ 
         LDA      <ENSTAT,X
         ORA      #DOWN 
         STA      <ENSTAT,X
CRFE50   EQU      $ 
         RTS
; 
;-------------------------------
ENBGCK   EQU      $ 
         LDA      #0
         LDY      #CRBD01-CRBD00
         JMP      ENCBCK
; 
;-----------------------------------------------------
BGCMP    EQU      $ 
         CMP      #WOOD0          ; Wood
         BEQ      BGC10 
         CMP      #COIN0          ; Coin
         BEQ      BGC10 
         CMP      #COIN1          ; Coin (in water) 
         BEQ      BGC10 
         CMP      #STBCO          ; See thru coin 
         BEQ      BGC10 
         CMP      #STBMS          ; See thru mushroom 
         BEQ      BGC10
         CMP      #STBDM          : See thru death mushroom
         BEQ      BGC10
	CMP	#STRTR		; IF  see thru wood
	BEQ	BGC10
	CMP	#STRST		; IF  see thru star
	BEQ	BGC10
         CMP      #STBSM          : See thru bouns mushroom
BGC10    EQU      $ 
         RTS
; 
;#####################################################################
;#                    (X) -- Index                                   #
;#       JSR      CRFIBG    [ Cross Fire  vs BG check ]              #
;#####################################################################
CRFIBG   EQU      $ 
;;;      LDA      FMCNT 
;;;      AND      #1
;;;;     BEQ      CRFIA0
; 
         LDA      FIYPS1,X
         CMP      #18H
         BCC      CRFI10
; 
         JSR      FICBCK          ; Up & down check 
         BEQ      CRFI10
; 
;;;      CMP      #COIN0
;;;      BEQ      CRFI10
; 
;;;      CMP      #COIN1
;;;      BEQ      CRFI10
         JSR      BGCMP 
         BEQ      CRFI10
; 
         LDA      <FIYCL0,X
         BMI      CRFI90
; 
         LDA      FICRFG,X
         BNE      CRFI90          ; Next cross --! Expl 
; 
         LDA      #0FDH           ; Cross --! jump
         STA      <FIYCL0,X
; 
         LDA      #1
         STA      FICRFG,X        ; Cross flag on 
; 
         LDA      FIYPS1,X
         AND      #0F8H 
         STA      FIYPS1,X
         RTS
; 
CRFI10   EQU      $ 
         LDA      #0
         STA      FICRFG,X
         RTS
; 
CRFI90   EQU      $ 
         LDA      #80H
         STA      <FISTAT,X        ; Expl clear
; 
         LDA      #01H
         STA      !SOUND0            ; <S! 
CRFIA0   EQU      $ 
         RTS
;---------------------------------------------------------------------<< Cross common routine 
; 
;#####################################################################
;#       Cross OBJ size data                                         #
;#####################################################################
CRJSZD   EQU      $ 
;                 X1 Y1 X2 Y2 
CRS00    HEX      02,08,0E,20     ; Mode 0 - Player big 
CRS10    HEX      03,14,0D,20     ;   "  1 - Player small 
CRS15    HEX      02,14,0E,20     ;   "  2 - Player sit down
CRS20    HEX      02,09,0E,15     ;   "  3 - Enemy ; 1
CRS30    HEX      00,00,18,06     ;   "  4 - Elevator 
CRS40    HEX      00,00,20,0D     ;   "  5 - Lift  1  4chr's
CRS50    HEX      00,00,30,0D     ;   "  6 - Lift  2  6chr's
CRS60    HEX      00,00,08,08     ;   "  7 - Fire 
CRS80    HEX      06,04,0A,0C     ;   "  9 - Big kame fire
CRS90    HEX      03,0E,0D,14     ;   "  A - Enemy ; 2
CRSB0    HEX      04,04,1C,1C     ;   "  C - Boss enemy 
CRSC0    HEX      04,04,0C,1C     ;   "  D - Karugary 
CRSD0    HEX      03,07,0D,16     ;   "  A - Enemy ; 2
; 
PBCMD    EQU      (CRS00-CRJSZD)/4
PSCMD    EQU      (CRS10-CRJSZD)/4
PDCMD    EQU      (CRS15-CRJSZD)/4
ENCMD    EQU      (CRS20-CRJSZD)/4
ELCMD    EQU      (CRS30-CRJSZD)/4
LFCMD    EQU      (CRS40-CRJSZD)/4
LFCMD2   EQU      (CRS50-CRJSZD)/4
FICMD    EQU      (CRS60-CRJSZD)/4
COCMD    EQU      (CRS60-CRJSZD)/4
FICMD2   EQU      (CRS80-CRJSZD)/4
ENCMD2   EQU      (CRS90-CRJSZD)/4
GUCMD    EQU      (CRS90-CRJSZD)/4
BKCMD    EQU      (CRSB0-CRJSZD)/4
FECMD    EQU      (CRSC0-CRJSZD)/4
FWCMD    EQU      (CRSD0-CRJSZD)/4
; 
;#####################################################################
;#                    (X) -- Index                                   #
;#       JSR      FICRDS    [ Fire cross data set ]                  #
;#                CWORK0 ~ 4 byte                                    #
;#                    Asolute cross data                             #
;#####################################################################
FICRDS   EQU      $ 
         TXA
         CLC
         ADC      #FICSMD-CRSZMD
         TAX
         LDY      #FIOBJX-OBJXPS
; 
         BNE      HMCR10
; 
;;;      JSR      CRDTST
;M;      LDX      INDEX 
;;;      RTS
; 
;#####################################################################
;#                    (X) -- Index                                   #
;#       JSR      COCRDS    [ Coin cross data set ]                  #
;#                CWORK0 ~ 4 byte                                    #
;#                    Asolute cross data                             #
;#####################################################################
COCRDS   EQU      $ 
HMCRDS   EQU      $ 
         TXA
         CLC
         ADC      #COCSMD-CRSZMD
         TAX
         LDY      #COOBJX-OBJXPS
HMCR10   EQU      $ 
         JSR      CRDTST          ; Cross data set
         JMP      CSDRVS          ; Revice cross data 
; 
;#####################################################################
;#       JSR      MSCRDS    [ Mushroom cross data set ]              #
;#                CWORK0 ~ 4 byte                                    #
;#                    Asolute cross data                             #
;#####################################################################
MSCRDS   EQU      $ 
;#####################################################################
;#                    (X) -- Index                                   #
;#       JSR      ENCRDS    [ Enemy cross data set ]                 #
;#                CWORK0 ~ 4 byte                                    #
;#                    Asolute cross data                             #
;#####################################################################
ENCRDS   EQU      $ 
         LDY      #01001000B
         STY      <WORK
; 
         LDY      #01000100B
         JMP      ECDS20
; 
;#####################################################################
;#                    (X) -- Index                                   #
;#       JSR      ELCRDS    [ Elevetor cross data set ]              #
;#                CWORK0 ~ 4 byte                                    #
;#                    Asolute cross data                             #
;#####################################################################
ELCRDS   EQU      $ 
         LDY      #00001000B
         STY      <WORK
; 
         LDY      #00000100B
; 
ECDS20   EQU      $ 
         LDA      ENXPS1,X
         SEC
         SBC      DSXP01
         STA      <WORK+1
; 
         LDA      <ENXPS0,X
         SBC      DSXP00
         BMI      ECDS30
; 
         ORA      <WORK+1
         BEQ      ECDS30
; 
         LDY      <WORK
; 
ECDS30   EQU      $ 
         TYA
         AND      ENFMSD
         STA      ENFHFG,X
;;MS
	CPX	#09H
	BEQ	ECDS70
	LDA	ENFHFG,X
         BNE      ECDS90          ;- IF  hide frame ?  ( YES ; ECDS90 ) 
         JMP      ECDS70
; 
;#####################################################################
;#                    (X) -- Index                                   #
;#       JSR      LFCRDS    [ Lift cross data set ]                  #
;#                CWORK0 ~ 4 byte                                    #
;#                    Asolute cross data                             #
;#####################################################################
LFCRDS   EQU      $ 
         INX
         JSR      FRMXCK          ; Frame (x)hide check 
         DEX
; 
         CMP      #11111110B
         BCS      ECDS90          ;- IF  all hide ?  ( YES ; ECDS90 ) 
; 
ECDS70   EQU      $               ; Enemy & Lift Elevetor cross data set !
         TXA
         CLC
         ADC      #ENCSMD-CRSZMD
         TAX
; 
         LDY      #ENOBJX-OBJXPS
         JSR      CRDTST               ; Set cross data 
         JMP      CSDRVS               ; Revice cross data
; 
ECDS90   EQU      $               ; Clera  cross data area !
         TXA
         ASL      A 
         ASL      A 
         TAY
; 
         LDA      #0FFH 
         STA      CWORK0+4,Y
         STA      CWORK0+5,Y
         STA      CWORK0+6,Y
         STA      CWORK0+7,Y
; 
         RTS
; 
;#####################################################################
;#                   (X) -- Absolute Index                           #
;#                   (Y) -- CWORK index                              #
;#                CRSZMD -- Cross check data mode                    #
;#       JSR      CRDTST    [ Cross check data set ]                 #
;#                   (X) -- Absolute Index                           #
;#                CWORK0 ~ 4 byte                                    #
;#                    Asolute cross data                             #
;#####################################################################
CRDTST   EQU      $ 
         STX      <WORK            ; <WORK <-- Absolute index 
; 
         LDA      OBJYPS,Y
         STA      <WORK+2          ; <WORK+2 <-- OBJ (y) pos
; 
         LDA      OBJXPS,Y
         STA      <WORK+1          ; <WORK+1 <-- OBJ (x) pos
; 
         TXA
         ASL      A 
         ASL      A 
; 
         PHA
         TAY
; 
         LDA      CRSZMD,X
         ASL      A 
         ASL      A 
         TAX
; 
         LDA      <WORK+1          ; (x) data calc ! 
         CLC
         ADC      CRJSZD,X
         STA      CWORK0,Y
; 
         LDA      <WORK+1
         CLC
         ADC      CRJSZD+2,X
         STA      CWORK0+2,Y
; 
         INX
; 
         INY
; 
         LDA      <WORK+2          ; (y) cross data calc ! 
         CLC
         ADC      CRJSZD,X
         STA      CWORK0,Y
; 
         LDA      <WORK+2
         CLC
         ADC      CRJSZD+2,X
         STA      CWORK0+2,Y
; 
         PLA
         TAY
; 
         LDX      <WORK
; 
         RTS
; 
;#####################################################################
;#                   (X) -- Absolute index                           #
;#                   (Y) -- CWORK index                              #
;#       JSR      CSDRVS    [ Cross data revice calc ]               #
;#####################################################################
CSDRVS   EQU      $ 
         LDA      DSXP01
         CLC
         ADC      #080H 
         STA      <WORK+2
; 
         LDA      DSXP00
         ADC      #0
         STA      <WORK+1
; 
         LDA      XPOS1,X 
         CMP      <WORK+2
         LDA      <XPOS0,X 
         SBC      <WORK+1
         BCC      CDRV60          ;- IF  left side chara ?                  ( YES ; CDRV60 )
; 
         LDA      CWORK0+2,Y      ; Right side check !
         BMI      CDRV50               ;- IF  cross data right side over ?  ( NO ; CDRV50 ) 
; 
         LDA      #0FFH 
         LDX      CWORK0,Y
         BMI      CDRV40
; 
         STA      CWORK0,Y
; 
CDRV40   EQU      $ 
         STA      CWORK0+2,Y
; 
CDRV50   EQU      $ 
         LDX      <INDEX 
; 
         RTS
; 
CDRV60   EQU      $               ; Left side check ! 
         LDA      CWORK0,Y
         BPL      CDRV90               ;- IF  cross data right side over ?  ( NO ; CDRV90 ) 
; 
         CMP      #0A0H 
         BCC      CDRV90
; 
         LDA      #0
         LDX      CWORK0+2,Y
         BPL      CDRV80
; 
         STA      CWORK0+2,Y
; 
CDRV80   EQU      $ 
         STA      CWORK0,Y
; 
CDRV90   EQU      $ 
         LDX      <INDEX 
; 
         RTS
; 
;#####################################################################
;#                   (X) -- Cross data table-0 index                 #
;#                    Yr -- Cross data table-1 index                 #
;#       JSR      CROJCK    [ Cross OBJ check ]                      #
;#                   <C> -- 0 : No cross                             #
;#                          1 : Cross                                #
;#####################################################################
CROJCS   EQU      $ 
         LDX      #00H
; 
CROJCK   EQU      $ 
         STY      <WORK+6
; 
         LDA      #1
         STA      <WORK+7
; 
CSCK10   EQU      $ 
         LDA      CWORK1,Y
         CMP      CWORK0,X
         BCS      CSCK40          ;- IF  X3 != X1 ?  ( YES : CSCK40 ) 
; 
         CMP      CWORK0+2,X
         BCC      CSCK30          ;- IF  X3 < X2 ?   ( YES ; CSCK30 ) 
         BEQ      CSCK60          ;- IF  X3 = X2 ?   ( YES ; CSCK60 ) 
; 
         LDA      CWORK1+2,Y
         CMP      CWORK1,Y
         BCC      CSCK60          ;- IF  X4 < X3 ?   ( YES ; CSCK60 ) 
; 
         CMP      CWORK0,X
         BCS      CSCK60          ;- IF  X4 != X1 ?  ( YES : CSCK60 ) 
; 
         LDY      <WORK+6
; 
         RTS
; 
CSCK30   EQU      $ 
         LDA      CWORK0+2,X
         CMP      CWORK0,X
         BCC      CSCK60          ;- IF  X2 < X1 ?   ( YES ; CSCK60 ) 
; 
         LDA      CWORK1+2,Y
         CMP      CWORK0,X
         BCS      CSCK60          ;- IF  X4 != X1 ?  ( YES : CSCK60 ) 
; 
         LDY      <WORK+6
; 
         RTS
; 
CSCK40   EQU      $ 
         CMP      CWORK0,X
         BEQ      CSCK60          ;- IF  X3 = X1 ?   ( YES ; CSCK60 ) 
; 
         CMP      CWORK0+2,X
         BCC      CSCK60
         BEQ      CSCK60          ;- IF  X3 <= X2 ?  ( YES ; CSCK60 ) 
; 
         CMP      CWORK1+2,Y
         BCC      CSCK50          ;- IF  X3 < X4 ?   ( YES ; CSCK50 ) 
         BEQ      CSCK50          ;- IF  X3 = X4 ?   ( YES ; CSCK50 ) 
; 
         LDA      CWORK1+2,Y
         CMP      CWORK0,X
         BCS      CSCK60          ;- IF  X4 != X1 ?  ( YES : CSCK60 ) 
; 
CSCK50   EQU      $ 
         CLC
         LDY      <WORK+6
; 
         RTS
; 
CSCK60   EQU      $ 
         INX
; 
         INY
; 
         DEC      <WORK+7
         BPL      CSCK10          ;- IF  (x) & (y) check ?  ( YES ; CSCK10 )
; 
         SEC
         LDY      <WORK+6
; 
         RTS
; 
; 
;#####################################################################
;#                   (X) -- Index ( Enmey )                          #
;#                    Ar -- 0 : UP & DW check                        #
;#                          1 : LF & RT   "                          #
;#                    Yr -- BG Cross size data table index           #
;#                  WORK --                                          #
;#       JSR      ENCBCK    [ Enemy cross BG check ]                 #
;#                    Ar -- Cross block No.                          #
;#                WORK+3 --   "     "                                #
;#                WORK+4 --   "   volume                             #
;#                WORK+2 -- Frame table index                        #
;#####################################################################
ENCBCK   EQU      $ 
         PHA
; 
         TXA
         CLC
         ADC      #ENXPS0-XPOS0 
         TAX
; 
         PLA
         JMP      FICB30
; 
;;;;;;;; JSR      CRBGCK
;;;;;;;; LDX      INDEX 
;;;;;;;; CMP      #0
;;;;;;;; RTS
; 
;#####################################################################
;#                   (X) -- Index ( Coin )                           #
;#                    Ar -- 0 : UP & DW check                        #
;#                          1 : LF & RT   "                          #
;#                    Yr -- BG Cross size data table index           #
;#                  WORK --                                          #
;#       JSR      COCBCK    [ Coin cross BG check ]                  #
;#                    Ar -- Cross block No.                          #
;#                WORK+3 --   "     "                                #
;#                WORK+4 --   "   volume                             #
;#                WORK+2 -- Frame table index                        #
;;##################################################################### 
COCBCK   EQU      $ 
         TXA
         CLC
         ADC      #COXPS0-XPOS0 
         TAX
; 
         LDY      #CRBD04-CRBD00
         JMP      FICB10
; 
;#####################################################################
;#                   (X) -- Index ( Fire )                           #
;#                    Ar -- 0 : UP & DW check                        #
;#                          1 : LF & RT   "                          #
;#                    Yr -- BG Cross size data table index           #
;#                  WORK --                                          #
;#       JSR      FICBCK    [ Fire cross BG check ]                  #
;#                    Ar -- Cross block No.                          #
;#                WORK+3 --   "     "                                #
;#                WORK+4 --   "   volume                             #
;#                WORK+2 -- Frame table index                        #
;#####################################################################
FICBCK   EQU      $ 
         LDY      #CRBD03-CRBD00
; 
         TXA
         CLC
         ADC      #FIXPS0-XPOS0 
         TAX
; 
FICB10   EQU      $ 
         LDA      #0
FICB30   EQU      $ 
         JSR      CRBGCK
; 
         LDX      <INDEX 
         CMP      #0
         RTS
; 
;#####################################################################
;#                   (X) -- Index                                    #
;#                    Ar -- 0 : UP & DW check                        #
;#                          1 : LF & RT   "                          #
;#                    Yr -- BG Cross size data table index           #
;#                  WORK --                                          #
;#       JSR      CRBGCK    [ Cross BG check ]                       #
;#                    Ar -- Cross block No.                          #
;#                WORK+3 --   "     "                                #
;#                WORK+4 --   "   volume                             #
;#                WORK+2 -- Frame table index                        #
;#####################################################################
CRSDID   EQU      $         ; Cross size data index table ! 
         HEX      00,07,0E                  ; Player
; 
CRBD00   EQU      $         ; Cross check data (x) !
         HEX      08,03,0C,02,02,0D,0D      ; Big   mario 
         HEX      08,03,0C,02,02,0D,0D      ; Water   " 
         HEX      08,03,0C,02,02,0D,0D      ; Small   " 
CRBD01   EQU      $ 
         HEX      08,00,10                  ; Enemy 
CRBD02   EQU      $ 
         HEX      04,14                     ; Cloud 
CRBD03   EQU      $ 
         HEX      04                        ; Fire
CRBD04   EQU      $ 
         HEX      04                        ; Coin
;---------------------------------------------------------- 
PCBDY0   EQU      04H       ; Player cross(y) BG data ; Head !
PCBDY1   EQU      02H 
PCBDY2   EQU      12H 
; 
CRBD10   EQU      $         ; Cross check data (y) !
         BYTE     PCBDY0,020H,020H,008H,018H,008H,018H
         BYTE     PCBDY1,020H,020H,008H,018H,008H,018H
         BYTE     PCBDY2,020H,020H,018H,018H,018H,018H
CRBD11   EQU      $ 
         HEX      18,14,14
CRBD12   EQU      $ 
         HEX      06,06 
CRBD13   EQU      $ 
         HEX      08
CRBD14   EQU      $ 
         HEX      10
; 
; 
;#####################################################################
;#                    Ar -- 0 : UP & DW check                        #
;#                          1 : LF & RT   "                          #
;#                    Yr -- BG Cross size data table index           #
;#                  WORK --                                          #
;#       JSR      PLCBCK    [ Player cross BG check ]                #
;#                    Ar -- Cross block No.                          #
;#                WORK+3 --   "     "                                #
;#                WORK+4 --   "   volume                             #
;#                WORK+2 -- Frame table index                        #
;#####################################################################
PLCBCKA  EQU      $ 
         INY
; 
PLCBCKB  EQU      $ 
         LDA      #00H
	 BRA	  PLCBCK
; 
PLCBCKC  EQU      $ 
         LDA      #01H
; 
PLCBCK   EQU      $ 
         LDX      #0
;;;;;;;; JMP      CRBGCK
; 
CRBGCK   EQU      $ 
         PHA
         STY      <WORK+4
; 
         LDA      CRBD00,Y        ; Cross check table position calc ! 
         CLC
         ADC      XPOS1,X 
         STA      <WORK+5
; 
         LDA      <XPOS0,X 
         ADC      #0
         AND      #00000001B
         LSR      A 
; 
         ORA      <WORK+5
         ROR      A 
         LSR      A 
         LSR      A 
         LSR      A 
; 
         JSR      FRTADC
; 
         LDY      <WORK+4
         LDA      YPOS1,X 
         CLC
         ADC      CRBD10,Y
         AND      #0F0H 
         SEC
         SBC      #20H
         STA      <WORK+2
         TAY
; 
         LDA      (<WORK+6),Y      ; Cross block No. set ! 
         STA      <WORK+3
; 
         LDY      <WORK+4
         PLA
         BNE      CRBC80          ;- IF  (x) check ?  ( YES ; CRBC80 )
; 
         LDA      YPOS1,X         ; (y) cross volume set !
         JMP      CRBC90
; 
CRBC80   EQU      $               ; (x) cross volume set !
         LDA      XPOS1,X 
; 
CRBC90   EQU      $ 
         AND      #0FH
         STA      <WORK+4               ; Cross volume 
; 
	LDA	<YWORK
	BNE	CRBC95
	LDA	<WORK3
	CMP	#5CH
	BCC	CRBC95
	CMP	#62H
	BCS	CRBC95
	STZ	<WORK3
CRBC95	EQU	$
         LDA      <WORK+3               ;   "   block No.
; 
         RTS
; 
;#####################################################################
;#                   (X) -- Index                                    #
;#                    Ar -- Hosei value                              #
;#       JSR      TBLPSC    [ Table line pos calc ]                  #
;#                    Ar -- Table line pos                           #
;#####################################################################
;;;;TBLPSC   EQU      $ 
;;;;     RTS
; 
         END
