;
	include		mn_hp_smram.asm
;
	 ORG	  0DEB58H
		EXTEND

		IDX8
		MEM8
;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;	 1985. 8.12	    V.1.0  Super Mario
;				   File	 name : SMCSET
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	EXT	FKMOVE,PCHMOV,PLCHCH
;=========================================================== SMMAIN ==
	 EXT	  JSRSUB,BRIK2,OAMC15
;=========================================================== SMINIT ==
;=========================================================== SMSUB0 ==
	 EXT	  SETSMK,KAMECK,KINPST,BKM0ST,KMLFST,FTMOST,GFCSET
;=========================================================== SMPLAY ==
;........................................................... ( Mode No. )
	 EXT	  PLC0MD,PLSF,PLCRMD,PLSB
;........................................................... ( Statsu )
	 EXT	  BWALK,BJUMP,BDROP,PWIRE
;........................................................... ( LF & RT move value )
	 EXT	  WKLF,RNLF,WKRT,RNRT,WKSLW
	EXT	PLOUT
;=========================================================== SMENMY ==
;........................................................... ( Statsu )
	 EXT	  WALK,DOWN,JUMP,STOP,TIME,DROP,FIRE
;........................................................... ( Enemy kind No. )
	 EXT	  SHTR,BKTR,RDTR,TUTR,FIEN,FLWR,YPVS,FTM0,SPRG,JPTR
	 EXT	  FTR0,WTR0,WTR1,FTR2,FTR6,FTR7,GSHL,FFWR
	 EXT	  EXT0,EXT1,EXFF,GFLG,ESHP,ENDTR,IKTR,JFS0,GIAL
;=========================================================== SMCROS ==
	 EXT	  LFCMD
;=========================================================== SMINIT ==
	 EXT	  HMCSET
;=========================================================== SMCSET ==
	 GLB	  PLCSET,FICST1,FICST2,FICST4X,FICS99,FICS99X
	 GLB	  ENCSET,ELCSET,LFCSET,OAMST280
	 GLB	  BKCST1,BKCST2,MSCSET
	 GLB	  FRMCHK,FRMXCK,FRMYCK,MSPLCS
	 GLB	  PLFRCK,ENFRCK,FIFRCK,BLFRCK,BKFRCK,COFRCK
	 GLB	  PLPSCV,ENPSCV,FIPSCV,BLPSCV,BKPSCV,COPSCV
	 GLB	  MSPSCV,MSFRCK,HMFRCK,HMPSCV
	 GLB	  OAMST2A
	GLB	FLWRATB
;=========================================================== SMENMY ==
	 EXT	  ENCLER,JPTRST,ENOPDT,ENOPD2
	EXT	NXCODT,NXBGDT
;---------------------------------------------------------------------
;
OAMST1	 EQU	  $
	 LDX	  #6
OAMST120 EQU	  $
	 STA	  OAM+00,Y	;Y
	 CLC
	 ADC	  #8
	 INY
	 INY
	 INY
	 INY
	 DEX
	 BNE	  OAMST120
;
	 LDY	  <WORK+2
	 RTS
;;
OAM2ST1	 EQU	  $
	 LDX	  #6
OAMST122 EQU	  $
	 STA	  OAM2+00,Y	;Y
	 CLC
	 ADC	  #8
	 INY
	 INY
	 INY
	 INY
	 DEX
	 BNE	  OAMST122
;
	 LDY	  <WORK+2
	 RTS
;;;;;;;;;;;;;;;;;;;;;
;
OAMST2A	 EQU	  $
	 LDA	  #0F0H	    ;<M!
OAMST2	 EQU	  $
	 STA	  OAM+21,Y	;Y
OAMST220 EQU	  $
	 STA	  OAM+17,Y	;Y
OAMST240 EQU	  $
	 STA	  OAM+13,Y	;Y
OAMST260 EQU	  $
	 STA	  OAM+09,Y	;Y
OAMST280 EQU	  $
	 STA	  OAM+05,Y	;Y
	 STA	  OAM+01,Y	;Y
GFCRET	 EQU	  $
	 RTS
;
OAM2ST2A EQU	  $
	 LDA	  #0F0H	    ;<M!
OAM2ST2	 EQU	  $
	 STA	  OAM2+21,Y	;Y
OAMST222 EQU	  $
	 STA	  OAM2+17,Y	;Y
OAMST242 EQU	  $
	 STA	  OAM2+13,Y	;Y
OAMST262 EQU	  $
	 STA	  OAM2+09,Y	;Y
OAMST282 EQU	  $
	 STA	  OAM2+05,Y	;Y
	 STA	  OAM2+01,Y	;Y
GFCRET2	 EQU	  $
	 RTS
;
;#####################################################################
;#		      Xr -- Index     ( 0 ~ 4 )			     #
;#	 JSR	  LFCSET    [ Lift chara set ]			     #
;#####################################################################
LFCSET	 EQU	  $
	LDA	SKYFLG
	BEQ	LIFTST
	JMP	LFCT70
LIFTST	EQU	$
	 LDY	  !OAMEN,X
;
	 STY	  <WORK+2    ;<M!
;
	 LDA	  ENOBJX
	 JSR	  OAM2ST1	; 6 of xpos set !
	 LDX	  <INDEX
;
	 LDA	  ENYPS1,X
	 JSR	  OAMST242	  ;<M!
;

	 LDY	  <ENVRFG
	 CPY	  #3
	 BEQ	  LFCS05
;
	 LDY	  ENLVFG
	 BEQ	  LFCS10	  ; Easy game ?
;
LFCS05	 EQU	  $
	 LDA	  #0F0H		  ; No.
LFCS10	 EQU	  $
	 LDY	  !OAMEN,X
;
	 STA	  OAM2+17,Y	;Y
	 STA	  OAM2+21,Y	;Y
;
	 LDA	  #87H
;;;	    LDX	     SKYFLG
;;;	    BEQ	     LL1
;;;	    LDA	     #75H
LL1	 EQU	  $
	 LDX	  <INDEX
;
	 INY
	 JSR	  OAM2ST2
;
	 LDA	  #00101100B
	 INY
	 JSR	  OAM2ST2
;
	 JSR	  FRMXCK
;
	 LDY	  !OAMEN,X
	JSR	FMXCV
	JSR	FMXCK2
LFCS11	 EQU	  $
	PHY
	JSR	FMPLS
	JSR	FMXCK2
LFCS12	 EQU	  $
	JSR	FMPLS
	JSR	FMXCK2
LFCS13	 EQU	  $
	JSR	FMPLS
	JSR	FMXCK2
LFCS14	 EQU	  $
	JSR	FMPLS
	JSR	FMXCK2
LFCS15	 EQU	  $
	JSR	FMPLS
	JSR	FMXCK2
LFCS16	 EQU	  $
	PLY
;
LFCT50	 EQU	  $
	 LDA	  ENFMSD
	ASL	A
	BCC	LFCT60
;
;;;	LDA	ENOBJY
;;;	BEQ	LFCT60
;;;	CMP	#0F0H
;;;	BCS	LFCT60
	LDA	<ENMYNO,X
	CMP	#27H
	BEQ	LFCT60
	CMP	#26H
	BEQ	LFCT60
	LDA	<ENYPS0,X
	CMP	#01H
	BNE	LFCT55
	LDA	ENOBJY
	CMP	#0F0H
	BCC	LFCT60
LFCT55	EQU	$
	 JSR	  OAM2ST2A	   ;<M!
;
LFCT60	 EQU	  $
	 RTS			  ;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;
LFCT70	EQU	$
	JSL	>KMLFST
	RTS
;
;#####################################################################
;#		      Xr -- Index				     #
;#	 JSR	  MSCSET    [ Mushroom chara set ]		     #
;#####################################################################
MSCHDT	 EQU	  $	    ; Mush room
	 HEX	  E9,EA
	 HEX	  78,79
;
FLCHDT	 EQU	  $	    ; Flower
	 HEX	  D6,D6
	 HEX	  D9,D9
;
STCHDT	 EQU	  $	    ; Star
	 HEX	  8D,8D
	 HEX	  E4,E4
;
MSCHD2	 EQU	  $	    ; Mush room 2
	 HEX	  E9,EA
	 HEX	  78,79
;
	 HEX	  7E,7F
	 HEX	  85,86
;
;FLWRDT	  EQU	   $
;
MSCLDT	 EQU	  $
	 BIN	  00101100	  ; Red
	 BIN	  00101000	  ; Flower
	 BIN	  00101000	  ; Star
	 BIN	  00101010	  ; Green
	 BIN	  00101100	  ; sample
;
MSCSET	 EQU	  $
	 LDA	  !OAMMS
	 CLC
	 ADC	  #08H
	 TAY
;
	 LDA	  MSOBJY
	 CLC
	 ADC	  #8
	 STA	  <WORK+2	   ; y pos.
;
	 LDA	  MSOBJX	  ; x pos.
	 STA	  <WORK+5
;
	 LDX	  MSFLFG
	 LDA	  MSCLDT,X
	 EOR	  MSOJBG
	 STA	  <WORK+4
;
	 TXA
	 PHA
;
	 ASL	  A
	 ASL	  A
	 TAX
;
	 LDA	  #1
	 STA	  <WORK+7
	 STA	  <WORK+3	   ; Muki.
;
MSC010	 EQU	  $
	 LDA	  MSCHDT,X
	 STA	  <WORK
	 LDA	  MSCHDT+1,X
	 JSR	  OAMSTW2
;
	 DEC	  <WORK+7
	 BPL	  MSC010
;
	 LDA	  !OAMMS
	 CLC
	 ADC	  #08H
	 TAY
	 PLA
	 BEQ	  MSC020	  ; Flower & Star ?
	 CMP	  #3
	 BEQ	  MSC020
	 CMP	  #4
	 BEQ	  MSC020	  : Death mush
;				  : yes !
MSCS21	 EQU	  $
	 STA	  <WORK
	 LDA	  <FMCNT	   ; Character checnge
	 AND	  #00000110B
	CMP	#6
	BNE	MSCS13
	LDA	#0EH
MSCS13	EQU	$
	 ORA	  MSOJBG
	 EOR	  #28H
	 STA	  OAM2+03,Y	;A
	 STA	  OAM2+07,Y	;A
	 STA	  OAM2+11,Y	;A
	 STA	  OAM2+15,Y	;A
	 LDX	  <WORK
	 DEX
	 BEQ	  MSCS15
	 STA	  OAM2+11,Y	;A
	 STA	  OAM2+15,Y	;A
;
MSCS15	 EQU	  $
;				  : yes !
	 LDA	  OAM2+07,Y	;A	  ; H Flip
	 ORA	  #01000000B
	 STA	  OAM2+07,Y	;A
;
	 LDA	  OAM2+15,Y	;A
	 ORA	  #01000000B
	 STA	  OAM2+15,Y	;A
;
MSC020	 EQU	  $
	 LDA	  !OAMMS
	CLC
	ADC	#08H
	TAY
	 JMP	  ENC109
;
;#####################################################################
;#		      Xr -- Index     ( 0 ~ 4 )			     #
;#	 JSR	  ENCSET    [ Enemy chara set	]		     #
;#####################################################################
ENCN00	 EQU	  $	    ; Data sart
ENCN01	 EQU	  $	    ; Black Talot 1
	 HEX	  FC,FC
	 HEX	  AA,AB
	 HEX	  AC,AD
;
ENCEND	 EQU	  $
	 HEX	  FC,FC
	 HEX	  AE,AF
	 HEX	  B0,B1
;
ENCN0S	 EQU	  $	    ; Normal Tatol 1
	 HEX	  FC,A5
	 HEX	  A6,A7
	 HEX	  A8,A9
;
	 HEX	  FC,A0
	 HEX	  A1,A2
	 HEX	  A3,A4
;
ENCN03	 EQU	  $	    ; Fling  Talot
	 HEX	  69,A5
	 HEX	  6A,A7
	 HEX	  A8,A9
;
	 HEX	  6B,A0
	 HEX	  6C,A2
	 HEX	  A3,A4
;
ENCN04	 EQU	  $	    ; Bakudan Talot walk
	 HEX	  FC,FC
	 HEX	  96,97
	 HEX	  98,99
;
	 HEX	  FC,FC
	 HEX	  9A,9B
	 HEX	  9C,9D
;
ENCN05	 EQU	  $	    ; Bakudan Tarot Down
	 HEX	  FC,FC
	 HEX	  8F,8E
	 HEX	  8E,8F
;
	 HEX	  FC,FC
	 HEX	  95,94
	 HEX	  94,95
;
ENCN06	 EQU	  $	    ; Ika
	 HEX	  FC,FC	    ; Stop
	 HEX	  DC,DC
	 HEX	  DF,DF
;
	 HEX	  DC,DC
	 HEX	  DD,DD
	 HEX	  DE,DE	    ; Go
;
ENCNFS	 EQU	  $	    ; Fish
	 HEX	  FC,FC
	 HEX	  B2,B3
	 HEX	  B4,B5
;
	 HEX	  FC,FC
	 HEX	  B6,B3
	 HEX	  B7,B5
;---- mush enemy --------------
YPVSD1	 EQU	  $
	 HEX	  FC,FC
	 HEX	  C6,C7
	 HEX	  C8,C9	    ;???????????????????
;
;---- Down character ---------
ENCD00	 EQU	  $	    ; Tatol Down
	 HEX	  FC,FC
	 HEX	  6E,6E
	 HEX	  6F,6F
;
	 HEX	  FC,FC
	 HEX	  6D,6D
	 HEX	  6F,6F
;-----------------------------
ENCDA0	 EQU	  $	    ; timing
	 HEX	  FC,FC
	 HEX	  6F,6F
	 HEX	  6E,6E
;
	 HEX	  FC,FC
	 HEX	  6F,6F
	 HEX	  6D,6D
;-----------------------------
ENCBK1	 EQU	  $
	 HEX	  FC,FC
	 HEX	  F4,F4
	 HEX	  F5,F5
;
	 HEX	  FC,FC
	 HEX	  F4,F4
	 HEX	  F5,F5
;
ENCBK2	 EQU	  $
	 HEX	  FC,FC
	 HEX	  F5,F5
	 HEX	  F4,F4
;
	 HEX	  FC,FC
	 HEX	  F5,F5
	 HEX	  F4,F4
;
;---- Mush enemy down ---------
YPVSD2	 EQU	  $
	 HEX	  FC,FC
	 HEX	  FC,FC
	 HEX	  EF,EF
;
;-----------------------------
ENCNCL	 EQU	  $	    ; Cloud Enwmy
	 HEX	  B9,B8
	 HEX	  BB,BA
	 HEX	  BC,BC
;
ENCDC2	 EQU	  $
	 HEX	  FC,FC
	 HEX	  BD,BD
	 HEX	  BC,BC
;------------------------------
GIALDT	 EQU	  $		  ; Queen
	 HEX	  7A,7B
	 HEX	  DA,DB
	 HEX	  D8,9E
;
GIALDT2	 EQU	  $		  ; Omuthu kozo
	 HEX	  CD,CD
	 HEX	  CE,CE
	 HEX	  CF,CF
;
;----------------------------
FIEND1	 EQU	  $	    ; Fire enemy
;
	 HEX	  7D,7C
	 HEX	  D1,8C
	 HEX	  D3,D2
;
FIEND2	 EQU	  $
;
	 HEX	  7D,7C
	 HEX	  89,88
	 HEX	  8B,8A
;
FIEND3	 EQU	  $
;
	 HEX	  D5,D4
	 HEX	  E3,E2
	 HEX	  D3,D2
;
	 HEX	  D5,D4
	 HEX	  E3,E2
	 HEX	  8B,8A
;
ENCNFL	 EQU	  $
	 HEX	  E5,E5
	 HEX	  E6,E6
	 HEX	  EB,EB
;
	 HEX	  EC,EC
	 HEX	  ED,ED
	 HEX	  EB,EB
;
ENJPTR	 EQU	  $		  ;Jump from water
	 HEX	  FC,FC
	 HEX	  D0,D0
	 HEX	  D7,D7
;
;---- Big Kame -------------
BKMDT1	 EQU	  $		  ; Normal hed
	 HEX	  C8,C9
	 HEX	  D8,D9
	 HEX	  E8,E9
;
BKMDT2	 EQU	  $		  ; Normal body
	 HEX	  D6,D7
	 HEX	  E6,E7
	 HEX	  F8,F7
;
BKMDTFI	 EQU	  $		  ; Fire hed
	 HEX	  EE,EF
	 HEX	  FE,FF
	 HEX	  E2,E3
;
BKMDTWK	 EQU	  $		  ; Walk chenge
	 HEX	  DA,DB
	 HEX	  EA,EB
	 HEX	  FA,FB
;
GUNDT	 EQU	  $
	 HEX	  FC,FC		  ; Gun
	 HEX	  64,65
	 HEX	  74,75
;
SPCHD1	 EQU	  $
	 HEX	  F2,F2
	 HEX	  F3,F3
	 HEX	  F2,F2
;
SPCHD2	 EQU	  $
	 HEX	  F1,F1
	 HEX	  F1,F1
	 HEX	  FC,FC
;
SPCHD3	 EQU	  $
	 HEX	  F0,F0
	 HEX	  FC,FC
	 HEX	  FC,FC
;
;;-----------------------------
ENCNAD	 EQU	  $
	 BYTE	  ENCN0S-ENCN00	  ; SHTR    0
	 BYTE	  ENCN0S-ENCN00	  ; RDTR    1
	 BYTE	  ENCN01-ENCN00	  ; BKTR    2
	 BYTE	  ENCN0S-ENCN00	  ; TUTR    3
	 BYTE	  ENCNFL-ENCN00	  : FFWR    4
	 BYTE	  FIEND1-ENCN00	  ; FIEN    5
;
	 BYTE	  YPVSD1-ENCN00	  ; YPVS    6
;
	 BYTE	  ENCN06-ENCN00	  ; IKTR    7
	 BYTE	  GUNDT-ENCN00	  ; FTM0    8
;
	 BYTE	  ENCN03-ENCN00	  ; FTR0    9
;
	 BYTE	  ENCNFS-ENCN00	  ; WTR0    A
	 BYTE	  ENCNFS-ENCN00	  ;  " 1    B
	 BYTE	  ENJPTR-ENCN00	  ; JPTR    C
	 BYTE	  ENCNFL-ENCN00	  ; FLWR    D
	 BYTE	  ENCN03-ENCN00	  ; FTR2    E	 M
	 BYTE	  ENCN03-ENCN00	  ;  " 6    F    M
	 BYTE	  ENCN03-ENCN00	  ;  " 7   10    M
	 BYTE	  ENCNCL-ENCN00	  ; ESHP   11
	 BYTE	  ENCN04-ENCN00	  ; EXT0   12 ;
	 BYTE	  0FFH		  ; ????????????????
	 BYTE	  ENCNFS-ENCN00	  ; JFS0   14
;
	 BYTE	  GIALDT-ENCN00	  ; GIAL   15
	 BYTE	  BKMDT1-ENCN00	  ; Big kame Hed      16
	 BYTE	  BKMDT2-ENCN00	  ; Big kame body     17
;
	 BYTE	  SPCHD1-ENCN00	  ; SPRING  1	      18
	 BYTE	  SPCHD2-ENCN00	  ;	    2	      19
	 BYTE	  SPCHD3-ENCN00	  ;	    3	      1A
;
;-----------------------------
ENCLDT	 EQU	  $
	 BYTE	  00AH		  ; SHTR    0
	 BYTE	  00CH		  ; RDTR    1
	 BYTE	  00AH		  ; BKTR    2
	 BYTE	  00CH		  ; TUTR    3
	 BYTE	  02CH		  : FFWR    4
	 BYTE	  00AH		  ; FIEN    5
	 BYTE	  002H		  ; YPVS    6
	 BYTE	  008H		  ; IKTR    7
	 BYTE	  00AH		  ; FTM0    8
;
	 BYTE	  008H		  ; FTR0    9
;
	 BYTE	  00AH		  ; WTR0    A
	 BYTE	  00CH		  ;  " 1    B
	 BYTE	  008H		  ; JPTR    C
FLWRATB	 EQU	  $
	 BYTE	  02AH		  ; FLWR    D
	 BYTE	  00AH		  ; FTR2    E	M
	 BYTE	  00CH		  ;  " 6    F   M
	 BYTE	  00AH		  ;  " 7   10   M
	 BYTE	  00AH		  ; ESHP   11
	 BYTE	  00CH		  ; EXT0   12	 ;
	 BYTE	  0FFH		  ; ??????????????????????
	 BYTE	  00CH		  ; JFS0   14	 ;
;
	 BYTE	  00CH		  ; GIAL   15
	 BYTE	  000H		  ; Big kame Hed   16
	 BYTE	  000H		  ; Big kamr Body  17
;
	 BYTE	  02CH		  ; SPRING 1	   18
	 BYTE	  02CH		  ;	   2	   19
	 BYTE	  02CH		  ;	   3	   1A
;
CHEGDT	 EQU	  $
	 HEX	  08,18
;
SPA   EQU      $
	 HEX	  18
	 HEX	  19
	 HEX	  1A
	 HEX	  19
	 HEX	  18
;
FICHIX	EQU	$
	HEX	0,0,0,0,0,0,6,6,6,6,6,6,0C,0C,0C,0C,0C,0C
;
FICHDT	EQU	$
	HEX	FC,FC
	HEX	D0,D0
	HEX	D7,D7
;
	HEX	FC,FC
	HEX	7E,7E
	HEX	7F,7F
;
	HEX	FC,FC
	HEX	E0,E0
	HEX	E1,E1
;
;-----------------------------
;-----------------------------
ENCSET	 EQU	  $
	LDA	<ENMYNO,X
	CMP	#JPTR
	BNE	ENCS10
	JSL	>JPTRST
	RTS
ENCS10	EQU	$
	CMP	#08H		;KILLER
	BNE	ENCS20
	LDA	<ENYPS0,X
	CMP	#02H
	BNE	ENCS13
	JSR	ENCLER
ENCS13	EQU	$
	JSL	>FTMOST
	RTS
ENCS20	EQU	$
	CMP	#33H		;KILLER
	BNE	ENCS30
	LDA	<ENYPS0,X
	CMP	#02H
	BNE	ENCS23
	JSR	ENCLER
ENCS23	EQU	$
	JSL	>FTMOST
	RTS
ENCS30	EQU	$
	CMP	#2DH		;KUPPA
	BNE	ENCS35
	JSL	>BKM0ST
	RTS
ENCS35	EQU	$
	CMP	#35H
	BNE	ENCS38
	LDA	!CORSNO
	CMP	#07H
	BEQ	ENCS37
	CMP	#0CH
	BEQ	ENCS37
	JSL	>FKMOVE
	RTS
ENCS37	EQU	$
	JSL	>PCHMOV		;PEACH MOVE
	RTS
ENCS38	EQU	$
;
	 LDA	  #2
;
	 LDY	  CORSNO
	 CPY	  #1
	 BEQ	  ENFFF	       ;(W-2) super high jump ?
;			       ;no
	 CPY	  #2
	 BEQ	  ENFFF	       ;(W-3) super high jump ?
;			       ;no
	 CPY	  #6
	 BEQ	  ENFFF	       ;(W-7) super high jump ?
;			       ;no
	 CPY	  #0BH
	 BNE	  ENCCCCC      :(W-C) Super high jump ?
;
ENFFF	 EQU	  $
	 LSR	  A	       : yes ! RED color
ENCCCCC	 EQU	  $
	 STA	  JPCLDT       : Jump spring color set
	 STA	  JPCLDT+1
	 STA	  JPCLDT+2
;
	 LDA	  ENYPS1,X	  ; y pos.
	 STA	  <WORK+2
;
	 LDA	  ENOBJX	  ; x pos.
	 STA	  <WORK+5
;
	 LDY	  !OAMEN,X
	 STY	  <WORK8	   ;  OAM2 index
;
	 LDA	  #0
	 STA	  <WORKD	   ; V flip mode
;
	 LDA	  <ENMMKI,X	   ; Muki.
	 STA	  <WORK+3
;
	 LDA	  ENOJBG,X	  ; BG Vs OBJ
	 STA	  <WORK+4
;
	 LDA	  <ENMYNO,X
;
	 CMP	  #FLWR
	 BNE	  SSS30		  ;dokan flwoor ?
;				  ;yes
	 LDY	  <FWRFLG1,X
	 BMI	  SSS30		  ;in dokan ?
;				  ;yes
	 LDY	  ETMS01,X
	 BEQ	  SSS30		  ;timer = 0 ?
;				  ;no
	 RTS
;
SSS30	 EQU	  $
	 LDA	  <ENSTAT,X
	 STA	  <WORKA
	 AND	  #00011111B
	 TAY
;
	 LDA	  <ENMYNO,X
	 CMP	  #GIAL
	 BNE	  PP2
	 LDY	  #0
;
	 LDA	  #1
	 STA	  <WORK+3
;
	 LDA	  #ENDTR    ; Girl
PP2	 EQU	  $
	 CMP	  #GSHL
	 BNE	  PP3
;
	 DEC	  <WORK+2
;
	 LDA	  #00100000B
;
	 LDY	  ETMS01,X
	 BEQ	  PP12		  ; On gun ?
;
	 EOR	  #00110000B	  ; BG!OBJ
PP12	 EQU	  $
	 STA	  <WORK+4
;
	 LDY	  #0
	 STY	  <WORKA
	 LDA	  #FTM0	    ; Gun
PP3	 EQU	  $
	 CMP	  #SPRG
	 BNE	  PP4
;
	 LDY	  #STOP
;
	 LDX	  PLSPON
	 LDA	  SPA,X
;
PP4	 EQU	  $
	 STA	  <WORKC
	 STY	  <WORK9
	 LDX	  <INDEX
;
	 CMP	  #JPTR
	 BNE	  OK1
;
	 LDA	  <ENYCL0,X
	 BMI	  OK1
;
	 INC	  <WORKD
OK1	 EQU	  $
;---- Big kame set -------
	 LDA	  BKCHFG
	 BEQ	  BK1
;
	 LDY	  #16H	    ; Hed
;
	 CMP	  #1
	 BEQ	  BK2
;
	 INY		    ; Body
BK2	 EQU	  $
	 STY	  <WORKC
;
BK1	 EQU	  $
	 LDY	  <WORKC	   ;<M!	 Enmy no.
;
	 CPY	  #YPVS
	 BNE	  ENCYPVS
;
	 LDA	  <ENSTAT,X
	 CMP	  #DOWN+1
	 BCC	  PO1
;
	 LDX	  #TIME
	 STX	  <WORK9
PO1	 EQU	  $
;
	 AND	  #00100000B
	 ORA	  GMSTTM
	 BNE	  ENCYPVS
;
	 LDA	  <FMCNT
	 AND	  #00001000B
	 BNE	  ENCYPVS
	 LDA	  <WORK+3
	 EOR	  #3
	 STA	  <WORK+3
ENCYPVS	 EQU	  $
;
	CPY	#FLWR
	BNE	FWCL10
	LDA	FLWATB
	BRA	FWCL20
FWCL10	EQU	$
	 LDA	  ENCLDT,Y
	CPY	#14H
	BNE	FWCL11
	LDA	#3CH
	BRA	FWCL25
FWCL11	EQU	$
	CPY	#16H
	BEQ	FWCL12
	CPY	#17H
	BNE	FWCL20
FWCL12	EQU	$
	LDA	KPACNT
	LSR	A
	BCC	FWCL18
	LDA	#6
	BRA	FWCL20
FWCL18	EQU	$
	LDA	#0
FWCL20	EQU	$
	 EOR	  <WORK+4
FWCL25	EQU	$
	 STA	  <WORK+4
	CPY	#15H
	BNE	EBIJ2
	LDA	CORSNO
	CMP	#07H
	BEQ	EBIJ3
	CMP	#0CH
	BNE	EBIJ2
EBIJ3	EQU	$
	LDA	<WORK+4
	AND	#0F0H
	ORA	#04H
	STA	<WORK+4
EBIJ2	EQU	$
;
	LDA	OPTFLG
	BEQ	EBIJ10
	 LDA	  ENCNAD,Y
	CLC
	ADC	#6
	 TAX
	BRA	EBIJ20
EBIJ10	EQU	$
	 LDA	  ENCNAD,Y
	 TAX
EBIJ20	EQU	$
;
	 LDY	  <WORK9
;--- Big kame set 2 ---------
	 LDA	  BKCHFG
	 BEQ	  Y0
;
	 CMP	  #1
	 BNE	  Y1
;
	 LDA	  BKMFLG
	 BPL	  Y3
;
	 LDX	  #BKMDTFI-ENCN00  ; Fire hed
;
Y3	 EQU	  $
	 LDA	  <WORKA     ; Stat
	 AND	  #00100000B
	 BEQ	  Y4
;
Y35	 EQU	  $
	 STX	  <WORKD     ; V flip
Y4	 EQU	  $
	 JMP	  LL5
;
Y1	 EQU	  $
	 LDA	  BKMFLG
	 AND	  #1
	 BEQ	  X1
;
	 LDX	  #BKMDTWK-ENCN00 ; Walk chenge
;
X1	 EQU	  $
	 LDA	  <WORKA     ; Stat
	 AND	  #00100000B
	 BEQ	  Y4
;
	 LDA	  <WORK+2
	 SEC
	 SBC	  #10H
	 STA	  <WORK+2
	BRA	Y35
;
;--- Big kame end -----
Y0	 EQU	  $
	 CPX	  #ENCN04-ENCN00       ; Bakudan ?
	 BNE	  ENCS011
KR1	 EQU	  $
	 CPY	  #DROP		       ; Yes!
	 BNE	  ENCS01	       ; Droping
	 LDX	  #ENCN05-ENCN00      ; Yes !
ENC001	 EQU	  $
	 LDA	  #2
	 STA	  <WORK+3
	 LDA	  #DROP
	 STA	  <WORK9
ENCS01	 EQU	  $
	 BRA	  ENC021
;
ENCS011	 EQU	  $
	 CPX	  #ENCNCL-ENCN00
	 BNE	  ENCS015
;
	 LDA	  <WORKA
	 AND	  #00100000B
	 BNE	  ENCS012	  ; Fail ?
;
	 LDA	  EFCKTM	  ; No.
	 CMP	  #10H
	 BCS	  ENCS012
;
	 LDX	  #ENCDC2-ENCN00
ENCS012	 EQU	  $
	 JMP	  ENC020	  ; Set ok
;
ENCS015	 EQU	  $
	 LDA	  <WORKC
	 CMP	  #TUTR+1
	 BCS	  ENCS016
;
	 CPY	  #JUMP
	 BCC	  ENCS15
;
	 LDX	  #ENCD00-ENCN00  ; Tumbling
	 LDY	  <WORKC
	 CPY	  #BKTR
	 BNE	  ENCS016
	 LDX	  #ENCBK2-ENCN00
	 INC	  <WORK+2
ENCS016	 EQU	  $
ENCS15	 EQU	  $
	 LDA	  <WORK9
	 CMP	  #TIME
	 BNE	  ENC021
	 LDX	  #ENCBK1-ENCN00
	 INC	  <WORK+2
	 LDY	  <WORKC
	 CPY	  #BKTR
	 BEQ	  ENC02F
	 LDX	  #ENCDA0-ENCN00
	 INC	  <WORK+2
ENC02F	 EQU	  $
	 CPY	  #YPVS
	 BNE	  ENC021
;
	 LDX	  #YPVSD1-ENCN00
	 LDA	  <WORKA
	 AND	  #00100000B
	 BNE	  ENC021
;
	 LDX	  #YPVSD2-ENCN00
	 DEC	  <WORK+2
ENC021	 EQU	  $
	 LDY	  <INDEX
;
	 LDA	  <WORKC
	 CMP	  #FIEN
	 BNE	  ENC02W
;
;-------------------------
	 LDA	  <WORKA
;	(CMP	  #WALK)
	 BEQ	  ENC022
;
	 AND	  #00001000B
	 BEQ	  ENC020
	 LDX	  #FIEND3-ENCN00  ; Yes !
	 BNE	  ENC022
;
ENC02W	 EQU	  $
;
	 CPX	  #ENCNFS-ENCN00
	 BEQ	  ENC022
;
	 LDA	  TMEL1,Y
	 CMP	  #5
	 BCS	  ENC020	  ; Foot batabata  start ?
;--------------------------	  : yes !
	 CPX	  #ENCN06-ENCN00  ; Ika ?
	 BNE	  ENC022
	 CMP	  #1		  ; YES !
	 BEQ	  ENC020
	 INC	  <WORK+2
	 INC	  <WORK+2
	 INC	  <WORK+2
	 BRA	  ENC023
;
ENC022	 EQU	  $
;
	 LDA	  <WORKC
	 CMP	  #YPVS		  ; Mush enemy ; no chenge
	 BEQ	  ENC020
	 CMP	  #FTM0		  ; Gun
	 BEQ	  ENC020
	 CMP	  #JPTR
	 BEQ	  ENC020
	 CMP	  #18H		  ; Spring
	 BCS	  ENC020
;
	 LDY	  #0
	 CMP	  #ENDTR    ; Girl
	 BNE	  ENC024
	 INY
;
	LDA	CORSNO
	CMP	#07H
	 BEQ	  ENC020
	CMP	#0CH
	BEQ	ENC020
;
	 LDX	  #GIALDT2-ENCN00 ; Smorl girl
	 LDA	  #STOP
	 STA	  <WORK9
	 BNE	  ENC020
;
ENC024	 EQU	  $
	 LDA	  <FMCNT	   ; Character chenge time ?
	 AND	  CHEGDT,Y
	 BNE	  ENC020
ENC023	 EQU	  $
	 LDA	  <WORKA
	 AND	  #10100000B
	 ORA	  GMSTTM
	 BNE	  ENC020
;
	 TXA			  ; Yes !
	 CLC
	 ADC	  #ENCEND-ENCN00
	 TAX
ENC020	 EQU	  $
	 LDA	  WORKC	       :   TEST
	 CMP	  #FFWR	       :
	 BEQ	  ENCD000      :
;
	 LDA	  <WORKA
	 AND	  #00100000B
	 BEQ	  LL5		  ; V flip ?
;---- Fail Check-----------
	 LDA	  <WORKC
	 CMP	  #TUTR+1
	 BCC	  LL5		  ; Ok ?
;
ENCD000	 EQU	  $
	 LDY	  #1		  ; Yes !
	 STY	  <WORKD	   ; V flip data .
;
	 DEY
	 STY	  <WORK9
;
LL5	 EQU	  $
;
	 LDY	  <WORK8     ; OAM2 index
;-- OAM2 set -----
	JSL	>KAMECK
	BCS	OPF005
	 JSR	  ENOMST	  ; 3 lined set
	 JSR	  ENOMST
	 JSR	  ENOMST
	JSL	>KINPST
OPF005	EQU	$
;
	 LDX	  <INDEX
	 LDY	  !OAMEN,X
;
	LDA	<ENMYNO,X
	CMP	#0CH
	BNE	OPF099
	INC	FIENCT,X
	LDA	FIENCT,X
	CMP	#12H
	BCC	OPF010
	STZ	FIENCT,X
	LDA	FIENCT,X
OPF010	EQU	$
	TAX
	LDA	FICHIX,X
	TAX
	LDA	FICHDT,X
	STA	OAM2+2,Y
;
	LDA	FICHDT+1,X
	STA	OAM2+6,Y
;
	LDA	FICHDT+2,X
	STA	OAM2+10,Y
;
	LDA	FICHDT+3,X
	STA	OAM2+14,Y
;
	LDA	FICHDT+4,X
	STA	OAM2+18,Y
;
	LDA	FICHDT+5,X
	STA	OAM2+22,Y
;
	LDX	<INDEX
;
;----- One part flip -----------
OPF099	EQU	$
	 LDA	  <WORKC
	 CMP	  #FTM0
	 BNE	  LLL
;
OO2	 EQU	  $
	 JMP	  ENC105
;
LLL	 EQU	  $
	 LDA	  <WORKD
	 BEQ	  LL6		  ; All V flip ?
;
	 LDA	  OAM2+03,Y	;A	  ; Yes !
	 ORA	  #10000000B
	 INY
	 INY
	 JSR	  OAM2ST2	   ;<M!
	 DEY
	 DEY
;
;NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW
;-- V flip calc ------------
	 TYA
	 TAX
	 LDA	  <WORKC
	 CMP	  #FIEN
	 BEQ	  PL1
	 CMP	  #FFWR
	 BEQ	  PL1
	 CMP	  #ESHP
	 BEQ	  PL1
	 CMP	  #ENDTR
	 BCS	  PL1
;
	 TXA
	 CLC
	 ADC	  #8
	 TAX
PL1	 EQU	  $
	 LDA	  OAM2+02,X	;C
	 PHA
	 LDA	  OAM2+06,X	;C
	 PHA
	 LDA	  OAM2+18,Y	;C
	 STA	  OAM2+02,X	;C
	 LDA	  OAM2+22,Y	;C
	 STA	  OAM2+06,X	;C
;
	 PLA
	 STA	  OAM2+22,Y	;C
	 PLA
	 STA	  OAM2+18,Y	;C
;
LL6	 EQU	  $
	 LDA	  BKCHFG
	 BNE	  OO2
;
	 LDA	  <WORKC
	 LDX	  <WORK9
	 CMP	  #FIEN
	 BNE	  LL7
	 JMP	  ENC105
LL7	 EQU	  $
	 CMP	  #IKTR
	 BEQ	  ENC090
;
	 CMP	  #FLWR
	 BEQ	  ENC090
	 CMP	  #FFWR
	 BEQ	  ENC090
	 CMP	  #JPTR
	 BEQ	  ENC090
;
	 CMP	  #EXT0
	 BNE	  ENC080
	 CPX	  #DROP
	 BNE	  ENC100
ENC080	 EQU	  $
;
;;	   CMP	    #ENDTR
;;	   BNE	    ENC081
;;	   LDA	    #01101000B
;;	   STA	    OAM2+23,Y	;A
;;ENC081   EQU	    $
;
	 CPX	  #JUMP
	 BCC	  ENC100
;
ENC090	 EQU	  $
	 LDA	  BKCHFG
	 BNE	  ENC100
;
	LDA	KAMEFG
	BNE	ENC100
	 LDA	  OAM2+03,Y	;A
	 AND	  #10111110B
	 STA	  OAM2+03,Y	;A
	 STA	  OAM2+11,Y	;A
	 STA	  OAM2+19,Y	;A
	 ORA	  #01000000B
	 CPX	  #DROP
	 BNE	  ENC095
	 ORA	  #10000000B
ENC095	 EQU	  $
	 STA	  OAM2+07,Y	;A
	 STA	  OAM2+15,Y	;A
	 STA	  OAM2+23,Y	;A
;
	 CPX	  #TIME
	 BNE	  ENC100
;
	 LDA	  OAM2+11,Y	;A
	 ORA	  #10000000B
	 STA	  OAM2+11,Y	;A
	 STA	  OAM2+19,Y	;A
	 ORA	  #01000000B
	 STA	  OAM2+15,Y	;A
	 STA	  OAM2+23,Y	;A
ENC100	 EQU	  $
	 LDA	  <WORKC
	 CMP	  #ESHP
	 BNE	  ENC104
;
	 LDA	  <WORKD
	 BNE	  ENC102
;
	 LDA	  OAM2+19,Y	;A
	 AND	  #10111111B
	 STA	  OAM2+19,Y	;A
;
	 LDA	  OAM2+23,Y	;A
	 ORA	  #01000000B
	 STA	  OAM2+23,Y	;A
;
	 LDX	  EFCKTM
	 CPX	  #10H
	 BCS	  ENC105
;
	 STA	  OAM2+15,Y	;A
	 AND	  #10111111B
	 STA	  OAM2+11,Y	;A
	 BCC	  ENC105
;
ENC102	 EQU	  $
	 LDA	  OAM2+03,Y	;A
	 AND	  #10111111B
	 STA	  OAM2+03,Y	;A
;
	 LDA	  OAM2+07,Y	;A
	 ORA	  #01000000B
	 STA	  OAM2+07,Y	;A
;
ENC104	 EQU	  $
	 LDA	  <WORKC
	 CMP	  #18H
	 BCC	  ENC105    ; Spring ?
;			    : Yes !
	LDA	JPCLDT
	LSR	A
	BCC	ENNM10
	LDA	#0AAH
	BRA	ENNM20
ENNM10	EQU	$
	LDA	#0ACH
ENNM20	EQU	$
	 STA	  OAM2+11,Y	;A
	 STA	  OAM2+19,Y	;A
	 ORA	  #01000000B
	 STA	  OAM2+15,Y	;A
	 STA	  OAM2+23,Y	;A
	AND	 #00111111B
	STA	 OAM2+03,Y	;A;
	ORA	  #01000000B
	STA	 OAM2+07,Y	;A

ENC105	 EQU	  $
	LDX	<INDEX
	 LDA	  <WORKC
	 CMP	  #FLWR
	 BNE	  ENC107
	LDA	<ENSTAT,X
	AND	#20H
	BNE	ENC108
	 LDA	  OAM2+19,Y
	 AND	  #0F0H
	 ORA	  #08H
	 STA	  OAM2+19,Y
	 LDA	  OAM2+23,Y
	 AND	  #0F0H
	 ORA	  #08H
	 STA	  OAM2+23,Y
	 BRA	  ENC109
ENC107	 EQU	  $
	 CMP	  #FFWR
	 BNE	  ENC109
	LDA	<ENSTAT,X
	AND	#20H
	BNE	ENC108
	 LDA	  OAM2+03,Y
	 AND	  #0F0H
	 ORA	  #08H
	 STA	  OAM2+03,Y
	 LDA	  OAM2+07,Y
	 AND	  #0F0H
	 ORA	  #08H
	 STA	  OAM2+07,Y
	BRA	ENC109
ENC108	EQU	$
	LDA	#0F0H
	STA	OAM2+01,Y
	STA	OAM2+05,Y
	STA	OAM2+09,Y
	STA	OAM2+13,Y
	STA	OAM2+17,Y
	STA	OAM2+21,Y
ENC109	 EQU	  $
	 LDX	  <INDEX
;---- Clear check ------
;---- x check ---
	JSR	FMXCV
	STZ	<WORK4
	JSR	FMXCK
	JSR	FMPLS
	STZ	<WORK4
	JSR	FMXCK
	DEY
	DEY
	DEY
	DEY
;;T;;
	 LDA	  ENFMSD
	 LSR	  A
	 LSR	  A
	 LSR	  A
;	  PHA
;	  BCC	   ENCS20
;
;	  LDA	   #4
;	  JSR	   ENXCLR
;ENCS20	  EQU	   $
;	  PLA
	 LSR	  A
;	  PHA
;	  BCC	   ENCS30
;	  LDA	   #0
;	  JSR	   ENXCLR
;
;ENCS30	  EQU	   $
;---- y check ---
;	  PLA
	 LSR	  A
	 LSR	  A
	 PHA
	 BCC	  ENCS40
;
	 LDA	  #10H
	 JSR	  ENYCLR
ENCS40	 EQU	  $
	 PLA
	 LSR	  A
	 PHA
	 BCC	  ENCS50
	 LDA	  #8
	 JSR	  ENYCLR
ENCS50	 EQU	  $
	 PLA
	 LSR	  A
	 BCC	  ENCS60    ; All Clear ?
;
	 JSR	  ENYCLR
;
	 LDA	  <ENMYNO,X
	 CMP	  #JPTR
	 BEQ	  ENCS60
;
ENCS59	 EQU	  $
	 LDA	  <ENYPS0,X
	 CMP	  #2
	 BNE	  ENCS60    ; Down clear ?
;			    : Yes !
	 JSR	  ENCLER
;
;;	 JSR	  MSCLER    : Yes !
ENCS60	 EQU	  $
;
	 RTS
;
;
;-OAM2 setting sub----
ENOMST	 EQU	  $
	 LDA	  ENCN00,X
	 STA	  <WORK
	 LDA	  ENCN00+1,X
OAMSTW2	 EQU	  $
	 STA	  <WORK+1
	LDA	<WORK2
	CMP	#0F9H
	BNE	EMS010
	LDA	#0F0H
	STA	<WORK2
EMS010	EQU	$
;
	 JMP	  OAMSET2	  ; Oam set
;
OAMSTW	 EQU	  $
	 STA	  <WORK+1
;
	 JMP	  OAMSET	  ; Oam set
;
;#####################################################################
;#		      Ar -- Clear obj No.  [ 0,8,16 ]		     #
;#		      Xr -- Index				     #
;#	 JSR	  ENYCLR    [ Enemy obj V clear ]		     #
;#####################################################################
ENYCLR	 EQU	  $
	STX	<INDEX
	CPX	#0AH
	BNE	ENXJY
	DEX
ENXJY	EQU	$
	 CLC
	 ADC	  !OAMEN,X
	 TAY
;
	 LDA	  #0F0H
	LDX	<INDEX
	 JMP	  OAMST282
;
;#####################################################################
;#		      Ar -- Clear obj No.  [ 0,4 ]		     #
;#		      Xr -- Index				     #
;#	 JSR	  ENXCLR    [ Enemy obj H clear ]		     #
;#####################################################################
ENXCLR	 EQU	  $
	STX	<INDEX
	CPX	#0AH
	BNE	ENXJ1
	DEX
ENXJ1	EQU	$
	 CLC
	 ADC	  !OAMEN,X
	 TAY
;
;;	   JSR	    BKCR30
;;	   STA	    OAM+17,Y	;Y
	LDA	#0F0H
	STA	OAM2+01,Y
	STA	OAM2+09,Y
	STA	OAM2+17,Y
	LDX	<INDEX
	 RTS
;
LECLR	EQU	$
	LDA	#01H
	STA	OAMSB+100H,Y
	STA	OAMSB+108H,Y
	STA	OAMSB+110H,Y
	RTS
;
RICLR	EQU	$
	LDA	#01H
	STA	OAMSB+104H,Y
	STA	OAMSB+10CH,Y
	STA	OAMSB+114H,Y
	RTS

;
;#####################################################################
;#		      Xr -- Index				     #
;#	 JSR	  BKCST1    [ Block chara set 2 ]		     #
;#####################################################################
;
BKCST1	 EQU	  $
;
	LDY	!OAMBK,X
	LDA	BKOBJX
	STA	OAM+00,Y
	LDA	BKOBJY
	STA	OAM+01,Y
	LDA	#2BH
	STA	OAM+03,Y
	LDA	#2
	STA	OAMSB,Y
;
	 LDA	  AGBKD2,X
	 CMP	  #BRIK2
	 BNE	  BKCRET	  ; Bounus block ?
;
	 LDA	  #00H
	BRA	BKCRT2
BKCRET	 EQU	  $		  ; <M!
	LDA	#02
BKCRT2	EQU	$
	 STA	  OAM+02,Y	;C
;
	LDA	<BKXPS0,X
	STA	<YWORK1
	LDA	BKXPS1,X
	STA	<YWORK
	MEM16
	REP	#20H
	LDA	<YWORK
	SEC
	SBC	<SCCH1
	STA	<YWORK
	MEM8
	SEP	#20H
	LDA	<YWORK1
	BEQ	BKCRT3
	LDA	#3
	STA	OAMSB,Y
BKCRT3	EQU	$
	RTS
;;
BKCR20	 EQU	  $
	 AND	  #00001000B
	 BEQ	  BKCR40
BKCR30	 EQU	  $
	 LDA	  #0F0H
	 STA	  OAM+01,Y	;Y
	 STA	  OAM+09,Y	;Y
BKCR40	 EQU	  $
	 RTS
;
;#####################################################################
;#		      Xr -- Index				     #
;#	 JSR	  BKCST2    [ Block chara set 3 ]		     #
;#####################################################################
BKCST2	 EQU	  $
;--- Chara No. -----
	 LDA	  #2CH
	 STA	  <WORK		   ; Color
	 LDA	  #75H		  ;	    (Cloud)
;
	 LDY	  <PLCMOD
	 CPY	  #PLCRMD
	 BEQ	  BKC210	  ; Goul	 Yes --! BKC210
;
	 LDA	  #2AH
	 STA	  <WORK		   ; Color
	 LDA	  #84H		  ;
BKC210	 EQU	  $
	 LDY	  !OAMBK,X
;
	 INY
	 JSR	  OAMST240
;--- Atr. -----
	 LDA	  <FMCNT
	 ASL	  A
	 ASL	  A
	 ASL	  A
	 ASL	  A
	 AND	  #11000000B
	 ORA	  <WORK
	 INY
	 JSR	  OAMST240
	 DEY
	 DEY
;
;--- Mian -----------
;
;--- x.y set----
;
;--- [Big loop ]------
;
;BKCS20	  EQU	   $
;
BKCS00	 EQU	  $
	 LDA	  BKOBJY
	CMP	#0F0H
	BCC	BKCS01
	LDA	#0F0H
BKCS01	EQU	$
	 JSR	  OAMST280  ; <M!
;
	 LDA	  BKOBJX
	 STA	  OAM+00,Y	;X
;
	 LDA	  BKCTPS,X
	 SEC
	 SBC	  DSXP01
	 STA	  <WORK
;
	 SEC
	 SBC	  BKOBJX
	 ADC	  <WORK
	 ADC	  #6
	 STA	  OAM+04,Y	;X
;
;----[Small loop ]----
;
	 LDA	  BKOBJY+1
	CMP	#0F0H
	BCC	BKSP10
	LDA	#0F0H
BKSP10	EQU	$
	 STA	  OAM+09,Y	;Y
	 STA	  OAM+13,Y	;Y
;
	 LDA	  BKOBJX+1
	 STA	  OAM+08,Y	;X
;
	 LDA	  <WORK
	 SEC
	 SBC	  BKOBJX+1
	 ADC	  <WORK
	 ADC	  #6
	 STA	  OAM+12,Y	;X
;
;---- Block spining ----------
;
;----- Clear Check ---------
BKCS10	 EQU	  $
	 LDA	  BKFMSD	  ; Y check
	 ASL	  A
	 BCC	  BKCS30
	 LDA	  #0F0H
	 JSR	  OAMST280
BKCS30	 EQU	  $
	LDA	BKFMSD
	BEQ	BKCS40
	LDA	#1
	 STA	  OAMSB+00,Y	;Y
	 STA	  OAMSB+08,Y	;Y
BKCS40	 EQU	  $
	LDA	BKFMSD+1
	BEQ	BKCS50
	LDA	#1
	 STA	  OAMSB+04,Y	;Y
	 STA	  OAMSB+12,Y	;Y
BKCS50	EQU	$
	 RTS
;
;#####################################################################
;#	 JSR	  FICST1    [ FIRE Chr. set 1 (Moving) ]	     #
;#####################################################################
FICST1	 EQU	  $
	 LDY	  !OAMFI,X
;
	 LDA	  FIOBJY	  ; y pos.
	 STA	  OAM+01,Y	;Y
;
	 LDA	  FIOBJX	  ; x pos.
FICS05	 EQU	  $
	 STA	  OAM+00,Y	;X
;
FICS99	 EQU	  $
	 LDA	  <FMCNT
	 LSR	  A
	 LSR	  A
	 PHA
	 AND	  #1
	 EOR	  #0BEH		   ; Chr. No.
	 STA	  OAM+02,Y	;C
;
	 PLA
	 LSR	  A
	 LSR	  A
	 LDA	  #28H		  ; Color
	 BCC	  FICS10
;
	 ORA	  #0C0H		  ; Flip
FICS10	 EQU	  $
	 STA	  OAM+03,Y	;A
;
	LDA	FIXSD0,X
	BPL	FICS30
	LDA	FIOBJX
	CMP	#0F8H
	BCC	FICS30
	LDA	#01
	STA	OAMSB,Y
FICS30	EQU	$
	 RTS
;
;#####################################################################
;#	 JSR	  FICST1    [ FIRE Chr. set 1 (Moving) ]	     #
;#####################################################################
FICST1X	 EQU	  $
	 LDY	  !OAMFI,X
;
	 LDA	  FIOBJY	  ; y pos.
	 STA	  OAM2+01,Y	;Y
;
	 LDA	  FIOBJX	  ; x pos.
FICS05X	 EQU	  $
	 STA	  OAM2+00,Y	;X
;
FICS99X	 EQU	  $
	 LDA	  <FMCNT
	 LSR	  A
	 LSR	  A
	 PHA
	 AND	  #1
	 EOR	  #0BEH		   ; Chr. No.
	 STA	  OAM2+02,Y	;C
;
	 PLA
	 LSR	  A
	 LSR	  A
	 LDA	  #38H		  ; Color
	 BCC	  FICS10X
;
	 ORA	  #0C0H		  ; Flip
FICS10X	 EQU	  $
	 STA	  OAM2+03,Y	;A
;
	 RTS
;
;
;#####################################################################
;#	 JSR	  FICST2    [ FIRE Chr. set 2 (Expling) ]	     #
;#####################################################################
FIC2DT	 EQU	  $
	 HEX	  CC,CB,CA,FC
;
FICST2	 EQU	  $
	 LDY	  !OAMBK,X
	LDA	FIXSD0,X
	BMI	FIMVLT
	LDA	FIOBJX
	SEC
	SBC	#4
	STA	FIOBJX
	CMP	#0F8H
	BCC	FIMVEN
FIMVRT	EQU	$
	LDA	#01
	STA	OAMSB+8,Y
	STA	OAMSB+0CH,Y
	BRA	FIMVEN
FIMVLT	EQU	$
	LDA	FIOBJX
	CMP	#0F0H
	BCC	FIMVEN
	CMP	#0F8H
	BCC	L1R1
	LDA	#01H
	STA	OAMSB,Y
	STA	OAMSB+4,Y
	BRA	FIMVEN
L1R1	EQU	$
	LDA	#01H
	STA	OAMSB,Y
	STA	OAMSB+4,Y
	BRA	FIMVRT
FIMVEN	EQU	$
;
	 LDA	  <FISTAT,X
	 INC	  <FISTAT,X
;
	 LSR	  A
	 AND	  #7
	 CMP	  #3
	 BCS	  FIC210
;
FICST4	 EQU	  $
	 TAX
	 LDA	  FIC2DT,X
	 INY
	 JSR	  OAMST240
	 DEY
;
	 LDX	  <INDEX
;
	 LDA	  FIOBJY
	 SEC
	 SBC	  #4
	 STA	  OAM+01,Y	;Y
	 STA	  OAM+09,Y	;Y
	 CLC
	 ADC	  #8
	 STA	  OAM+05,Y	;Y
	 STA	  OAM+13,Y	;Y
;
	 LDA	  FIOBJX
	 STA	  OAM+00,Y	;X
	 STA	  OAM+04,Y	;X
	 CLC
	 ADC	  #8
	 STA	  OAM+08,Y	;X
	 STA	  OAM+12,Y	;X
;
	 LDA	  #28H
	 STA	  OAM+03,Y	;A
	 LDA	  #0A8H
	 STA	  OAM+07,Y	;A
	 LDA	  #68H
	 STA	  OAM+11,Y	;A
	 LDA	  #0E8H
	 STA	  OAM+15,Y	;A
	 RTS
;
FIC210	 EQU	  $
;;;	    LDA	     #0
	 STZ	  <FISTAT,X
	 RTS
;
HANADT	EQU	$
	HEX	48,4A,4C,4E
;
HANAAT	EQU	$
	HEX	0C,08,0A,0C,08,0A,0C,08,0A
;
FICST4X	 EQU	  $
	 TAX
	 LDA	  HANADT,X
	 INY
	 JSR	  OAMST242
	 DEY
;
	 LDX	  <INDEX
;
	 LDA	  FIOBJY
	 SEC
	 SBC	  #10H
	 STA	  OAM2+01,Y	;Y
	 STA	  OAM2+09,Y	;Y
	 CLC
	 ADC	  #10H
	 STA	  OAM2+05,Y	;Y
	 STA	  OAM2+13,Y	;Y
;
	 LDA	  FIOBJX
	 SEC
	 SBC	  #08H
	 STA	  OAM2+00,Y	;X
	 STA	  OAM2+04,Y	;X
	 CLC
	 ADC	  #10H
	 STA	  OAM2+08,Y	;X
	 STA	  OAM2+12,Y	;X
	LDA	#02H
	 STA	  OAMSB2+00,Y	;X
	 STA	  OAMSB2+04,Y	;X
	 STA	  OAMSB2+08,Y	;X
	 STA	  OAMSB2+12,Y	;X
;
	PHX
	LDA	<FRWFCT,X
	TAX
	DEX
	LDA	HANAAT,X
	ORA	#20H
	 STA	  OAM2+03,Y	;A
	LDA	HANAAT,X
	ORA	#0A0H
	 STA	  OAM2+07,Y	;A
	LDA	HANAAT,X
	ORA	#60H
	 STA	  OAM2+11,Y	;A
	LDA	HANAAT,X
	ORA	#0E0H
	 STA	  OAM2+15,Y	;A
	PLX
	 RTS
;
;#####################################################################
;#		      Xr -- Index				     #
;#	 JSR	  ELCSET    [ Elevator chara set ]		     #
;#####################################################################
ELCSET	 EQU	  $
;--- Character set -------
	 LDY	  !OAMEN,X
	 LDA	  #087H		  ; Chr No.
	 INY
	 JSR	  OAM2ST2
	 INY
	 LDA	  #00101100B	  ;<M!
	 JSR	  OAM2ST2
	 DEY
	 DEY
;
	 LDA	  ENOBJX	   ; Xpos.
	 STA	  OAM2+00,Y	;X
	 STA	  OAM2+12,Y	;X
	 CLC
	 ADC	  #8
	 STA	  OAM2+04,Y	;X
	 STA	  OAM2+16,Y	;X
	 CLC
	 ADC	  #8
	 STA	  OAM2+08,Y	;X
	 STA	  OAM2+20,Y	;X
;
	 LDA	  ENYPS1,X
	 TAX
	 PHA
	 CPX	  #0H
	 BCS	  BL
	 LDA	  #0F0H
BL	 EQU	  $
	 JSR	  OAMST262
;
	 PLA
	 CLC
	 ADC	  #80H
	 TAX
	 CPX	  #0H
	 BCS	  BL2
	 LDA	  #0F0H
BL2	 EQU	  $
	 STA	  OAM2+13,Y	;Y
	 STA	  OAM2+17,Y	;Y
	 STA	  OAM2+21,Y	;Y
;
	 LDA	  ENFMSD
	 PHA
	 AND	  #00001000B
	 BEQ	  ELCS10	  ; Left out ?
	 LDA	  #01H		 ; Yes ! (OBJ clear)
	 STA	  OAMSB2+00,Y	;Y
	 STA	  OAMSB2+12,Y	;Y
ELCS10	 EQU	  $
	 PLA
	 PHA
	 AND	  #00000100B
	 BEQ	  ELCRET	  ; Right out ?
	 LDA	  #01H		 ; Yes !
	 STA	  OAMSB2+04,Y	;Y
	 STA	  OAMSB2+16,Y	;Y
;
ELCRET	 EQU	  $
	 PLA
	 AND	  #00000010B
	 BEQ	  ELCRE1
	 LDA	  #01H
	 STA	  OAMSB2+08,Y	;Y
	 STA	  OAMSB2+20,Y	;Y
ELCRE1	 EQU	  $
	 LDX	  <INDEX
;
	 RTS
;
;---------------------------------------------------------------------<< Player chara set
;
;#####################################################################
;#	 Player chara No. data table				     #
;#####################################################################
CNOIDX	 EQU	  $		       ; Chara No. index !
PLCI10	 BYTE	  PLBJP-CNDATA			 ; Big mario jump
PLCI20	 BYTE	  PLBSW-CNDATA			 ;	     swim
	 BYTE	  PLCHN-CNDATA+(2*8)		 ;	     stop
	 BYTE	  PLBSL-CNDATA			 ;	     slip
PLCI30	 BYTE	  PLBWK-CNDATA			 ;	     walk
PLCI32	 BYTE	  PLBWR-CNDATA			 ;	     tuch wire
PLCI35	 BYTE	  PLSHD-CNDATA			 ;	     shit down
PLCI38	 BYTE	  PLBFB-CNDATA			 ;	     thru fire ball
;
PLCI40	 BYTE	  PLSJP-CNDATA			 ; Small mario jump
PLCI50	 BYTE	  PLSSW-CNDATA			 ;     "       swim
	 BYTE	  PLCHN-CNDATA			 ;     "       stop
	 BYTE	  PLSSL-CNDATA			 ;     "       slip
PLCI70	 BYTE	  PLSWK-CNDATA			 ;     "       walk
PLCI80	 BYTE	  PLSWR-CNDATA			 ;     "       tuch wire
PLCI85	 BYTE	  PLFAL-CNDATA			 ;     "       fail
;
PLCI90	 BYTE	  PLCHN-CNDATA			 ; Change mario
;
;
CNDATA	 EQU	  $		       ; Chara No. data table !
PLBWK	 HEX	  00,01,02,03,04,05,06,07	 ; Big mario   walk-0
	 HEX	  00,01,02,03,04,05,06,07	 ;		   -1
	 HEX	  00,01,02,03,04,05,06,07	 ;		   -2
PLBSL	 HEX	  00,01,02,03,04,05,06,07	 ; Big mario   slip
PLBJP	 HEX	  00,01,02,03,04,05,06,07	 ;	       jump
PLBSW	 HEX	  00,01,02,03,04,05,06,07	 ;	       swim-0
	 HEX	  00,01,02,03,04,05,06,07	 ;		   -1
	 HEX	  00,01,02,03,04,05,06,07	 ;		   -2
PLBWR	 HEX	  00,01,02,03,04,05,06,07	 ;	       tuch wire-0
	 HEX	  00,01,02,03,04,05,06,07	 ;			-1
PLSHD	 HEX	  00,01,02,03,04,05,06,07	 ;	       shit down
PLBFB	 HEX	  00,01,02,03,04,05,06,07	 ;	       thru fire ball
;
PLSWK	 HEX	  00,01,02,03,04,05,06,07	 ; Small mario walk-0
	 HEX	  00,01,02,03,04,05,06,07	 ;		   -1
	 HEX	  00,01,02,03,04,05,06,07	 ;		   -2
PLSSL	 HEX	  00,01,02,03,04,05,06,07	 ;	       slip
PLSJP	 HEX	  00,01,02,03,04,05,06,07	 ;	       jump
PLSSW	 HEX	  00,01,02,03,04,05,06,07	 ;	       swim-0
	 HEX	  00,01,02,03,04,05,06,07	 ;		   -1
	 HEX	  00,01,02,03,04,05,06,07	 ;		   -2
PLSWR	 HEX	  00,01,02,03,04,05,06,07	 ;	       tuch wire-0
	 HEX	  00,01,02,03,04,05,06,07				-1
PLFAL	 HEX	  00,01,02,03,04,05,06,07	 ;	       fail
;
PLCHN	 HEX	  00,01,02,03,04,05,06,07	 ; Change mario small & stop
	 HEX	  00,01,02,03,04,05,06,07	 ;	 "      midle
	 HEX	  00,01,02,03,04,05,06,07	 ;	 "      big   & stop
;
SWFTCD	 HEX	  9E,9F				 ; Big mario & Small mario siwm foot
;
;#####################################################################
;#	 JSR	  PLCSET    [ Player Chara set ]		     #
;#####################################################################
PLCSET	 EQU	  $	    ; Chara No. table index calc !
	LDA	SMKFLG2
	BNE	PLC09A
	LDA	CHNOID
	CMP	#18H
	BEQ	PLC011
	CMP	#78H
	BNE	PLCAAA
PLC011	EQU	$
	INC	SMKFLG2
	BRA	PLC099
PLC010	EQU	$
	LDA	PLCMKI
	AND	#02H
	BNE	PLCAAA
	INC	SMKFLG2
PLC099	EQU	$
	STZ	SMKFLG
PLC09A	EQU	$
	JSL	>SETSMK
PLCAAA	EQU	$
	LDA	<PLCMOD
	CMP	#03H
	BEQ	PLCT30
	 LDA	  SFTYTM
	 BEQ	  PLCT30	  ; Mario safety time on ?
;
	 LDA	  <FMCNT
	 LSR	  A
	 BCS	  PLSC90	  ; Flashing
;
PLCT30	 EQU	  $
	 LDA	  <PLCMOD
	 CMP	  #PLSF
	 BEQ	  PLFLCS	  ;- IF	 fail small mario ?  ( YES ; PLFLCS )
;
	 LDA	  PLCHFG
	 BNE	  PLCHCS	  ;- IF	 change player ?     ( YES ; PLCHCS )
;
	 LDY	  PLSMFG
	 BEQ	  PLWJCS	  ;- IF	 underwater ?	     ( NO ; PLWJCS )
;
;#####################################################################
;#	 JSR	  PLSWCS    [ Player swim chara set ]		     #
;#####################################################################
PLSWCS	 EQU	  $
	 LDA	  <PLSTAT
	 CMP	  #BWALK
	 BEQ	  PLWJCS	  ;- IF	 swimming ?	  ( NO ; PLWJCS )
;
	 JSR	  PLWJCS	  ; Swim chara set !
;
;	  LDA	   <FMCNT
;	  AND	   #00000100B
;	  BNE	   PLSC90		;- IF  no change swim chara ?  ( YES ; PLSC90 )
;
	 TAX
	 LDY	  !OAMPL
	 LDA	  CMUKI
	 LSR	  A
	 BCS	  PLSC70	       ;- IF  muki = right ?	      ( YES ; PLSC70 )
;
	 INY
	 INY
	 INY
	 INY
;
PLSC70	 EQU	  $
	 LDA	  PLSIZE
	BNE	PLSC90
	LDA	PLSTAT
	CMP	#03H
	BEQ	PLSC90
	LDA	PLCMOD
	CMP	#0BH
	BEQ	PLSC90
;
	PHX
	LDA	PLCMKI
	CMP	#02
	BEQ	PLSW20
	LDA	OAM+10H,Y
	SEC
	SBC	#08H
	STA	OAM+10H,Y
	BCS	PLSW20
	LDA	#3
	BRA	PLSW30
PLSW20	EQU	$
	LDA	#2
PLSW30	EQU	$
	STA	OAMSB+10H,Y
;
	LDA	CHNOID
	SEC
	SBC	#28H
	LSR	A
	LSR	A
	CLC
	ADC	#8
	STA	OAM+02+10H,Y
	LDA	OAM+01+18H,Y
	CMP	#0F0H
	BCC	PLSW40
	LDA	#0F0H
	STA	OAM+01+10H,Y
PLSW40	EQU	$
	LDA	#0F0H
	STA	OAM+01+18H,Y
	PLX
;	  BEQ	   PLSC80		;- IF  big mario ?	       ( YES ; PLSC80 )
;
;	  LDA	   OAM+26,Y	;C
;	  CMP	   PLSSW+8*3-2
;	  BEQ	   PLSC90
;
;	  INX
;
PLSC80	 EQU	  $
;	  LDA	   SWFTCD,X
;	  STA	   OAM+26,Y	;C     ; Chara No. set
;
PLSC90	 EQU	  $
;
	 RTS
;
;#####################################################################
;#	 JSR	  PLWJCS    [ Player walk & jump chara set ]	     #
;#####################################################################
PLWJCS	EQU	$
	JSR	PLWJIC			; Player walk & jump chara index calc
	BRA	PLCSPS
;
;#####################################################################
;#	 JSR	  PLCHCS    [ Player change chara set ]		     #
;#####################################################################
PLCHCS	EQU	$
	JSR	PLCHIC			; Player change chara index calc
	BRA	PLCSPS
;
;#####################################################################
;#	 JSR	  PLFLCS    [ Player small mario fail chara set ]    #
;#####################################################################
PLFLCS	 EQU	  $
	 LDY	  #PLCI85-CNOIDX
	 LDA	  CNOIDX,Y
;
;#####################################################################
;#		      Ar -- Chara No. table index		     #
;#	 JSR	  PLCSPS    [ Player chara set & position set ]	     #
;#####################################################################
PLCSPS	 EQU	  $
	 STA	  CHNOID	  ; OAM set !
;
	LDA	PECECH
	BNE	INCM15
	LDA	INCMPS
	BEQ	INCM10
	LDA	PLSIZE
	BNE	INCM20
	LDA	#0D8H
	STA	CHNOID
	BRA	INCM10
INCM20	EQU	$
	LDA	#0E0H
INCM15	EQU	$
	STA	CHNOID
INCM10	EQU	$
	 LDA	  #4
	 JSR	  PLOMST		    ; player set
	 JSR	  PLFLIP		    ; OBJ one point flipping
;
	LDA	<CMUKI
	CMP	#03H
	BNE	INCM19
	LDA	PLXPS1
	SEC
	SBC	<SCCH1
	LDA	<PLXPS0
	SBC	<SCCH1+1
	BEQ	INCM19
	LDA	#1
	STA	OAMSB+0D0H
	STA	OAMSB+0D8H
	STA	OAMSB+0E0H
	STA	OAMSB+0E8H
INCM19	EQU	$
;
	 LDA	  PLFTFG
	 BEQ	  PLCS30	       ;- IF  fire thru player ?    ( NO ; PLCS30 )
;
	 LDY	  #0		       ; Player thru fire ball set !
	 LDA	  PLCHTM
	 CMP	  PLFTFG
	 STY	  PLFTFG
	 BCS	  PLCS30		    ;- IF  end thru pose ?  ( YES ; PLCS30 )
;
	 STA	  PLFTFG
;
	LDA	<PLSTAT
	CMP	#01H
	BEQ	PLCS10
	 LDY	  #PLCI38-CNOIDX
	 LDA	  CNOIDX,Y
	 STA	  CHNOID
PLCS10	EQU	$
;
	 LDY	  #4
	 LDA	  <XSPED0
	 ORA	  <KEYLR
	 BEQ	  PLCS20		    ;- IF  player stop ?    ( YES ; PLCS20 )
;
	 DEY
;
PLCS20	 EQU	  $
	 TYA
	 JSR	  PLOMST		    ; Fire thru player set
;
PLCS30	 EQU	  $
	 LDA	  PLFMSD	  ; Frame side up & down check !
	 LSR	  A
	 LSR	  A
	 LSR	  A
	 LSR	  A
	 STA	  <WORK			; <WORK <-- Erase side data
;
	 LDX	  #3		  ; Erase !
	 LDA	  !OAMPL
	 CLC
	 ADC	  #4*8-8
	 TAY
;
PLCS70	 EQU	  $
	 LDA	  #0F0H
	 LSR	  <WORK
	 BCC	  PLCS80
;
	 JSR	  OAMST280
;
PLCS80	 EQU	  $
	 TYA
	 SEC
	 SBC	  #8
	 TAY
;
	 DEX
	 BPL	  PLCS70	       ;- IF  all check end ?  ( NO ; PLCS70 )
;
	JSR	DKYUSN		; DOKAN IN YUSEN CHANGE
	 RTS
;
;#####################################################################
;#	 JSR	  MSPLCS    [ Message player chara set ]	     #
;#####################################################################
MSPLCD	 EQU	  $	    ; Message player chara set data !
	 HEX	  40
	 HEX	  01		  ; Muki
	 HEX	  2E		  ; Color
	 HEX	  60		  ; (x)pos
	 HEX	  FF		  ; Dummy
	 HEX	  04		  ; Set OAM count
;
MSPLCS	 EQU	  $
	JSR	OAMC15
	LDA	#0D0H
	STA	CHNOID
	JSL	>PLCHCH
	LDX	#5
;
MPCS30	 EQU	  $
	 LDA	  MSPLCD,X
	 STA	  <WORK+2,X
	 DEX
	 BPL	  MPCS30
;
	 LDX	  #PLCHN-CNDATA
	 LDY	  #0D0H
	 JSR	  PLOMSS	  ; Player OAM set sub
;
	JSR	NEXTID
	JSR	PLOUT
	 RTS
;
;#####################################################################
;#	 JSR	  NEXTID    [ Next world no & bg_dat no set ]	     #
;#			00 : Under Water			     #
;#			01 : Ground				     #
;#			02 : Under Ground			     #
;#			03 : Castle				     #
;#			04 : Asretick				     #
;#####################################################################
NEXTID	EQU	$
	PHX
	PHY
	LDA	#0F0H
OCLR10	EQU	$
	STA	OAM+1,Y
	STA	OAM2+1,Y
	INY
	BNE	OCLR10
;
	JSR	NEXTSB
	LDX	#0
	LDA	#30H
	STA	<TWORK6
NXJP25	EQU	$
	JSR	NXLP10
	CMP	#2
	BNE	NXJP15
	LDA	<ENMYNO,X
	CMP	#16H
	BEQ	NXJP26
	PHY
	PHX
	JSR	ENCS30
	PLX
	LDA	OAMEN,X
	TAY
	LDA	#0
	STA	OAMSB2,Y
	STA	OAMSB2+04H,Y
	STA	OAMSB2+08H,Y
	STA	OAMSB2+0CH,Y
	STA	OAMSB2+10H,Y
	STA	OAMSB2+14H,Y
	LDA	<SCCH1+1
	STA	<ENXPS0,X
	PLY
	BRA	NXJP27
NXJP26	EQU	$
	JSR	KUPAST
	BRA	NXJP45
NXJP27	EQU	$
	LDA	<ENMYNO,X
;
;	CMP	#07H
;	BNE	NXJP28
;	JSR	GESSO
;	BRA	NXJP15
NXJP28	EQU	$
	CMP	#12H
	BNE	NXJP15
	JSR	JYUSET
;	BRA	NXJP20
NXJP15	EQU	$
	INY
	INX
	CPX	#05
	BNE	NXJP25
	LDA	<ENVRFG
	CMP	#03H
	BEQ	NXJP45
	LDX	#0
NXLP40	EQU	$
	LDA	OAM2+2,X
	CMP	OAM2+6,X
	BNE	NXJP30
	LDA	OAM2+3,X
	AND	#00111111B
	STA	OAM2+3,X
	LDA	OAM2+7,X
	ORA	#40H
	STA	OAM2+7,X
	BRA	NXJP40
NXJP30	EQU	$
	LDA	OAM2+7,X
	STA	OAM2+3,X
NXJP40	EQU	$
	INX
	INX
	INX
	INX
	INX
	INX
	INX
	INX
	CPX	#0
	BNE	NXLP40
NXJP45	EQU	$
	LDX	#04H
NXJP60	EQU	$
	STZ	<ENMYNO,X
	DEX
	BPL	NXJP60
	STZ	OPTFLG
	PLY
	PLX
	RTS
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
NXLP10	EQU	$
;
	STZ	OPTFLG
	PHX
	TYX
	LDA	CORSNO
	CMP	#08H
	BCC	BST010
	LDA	>ENOPD2,X
	BRA	BST020
BST010	EQU	$
	LDA	>ENOPDT,X
BST020	EQU	$
	PLX
	CMP	#0FFH
	BNE	OPCHST
	LDA	<TWORK6
	CLC
	ADC	#18H
	STA	<TWORK6
	JMP	OPNTST
OPCHST	EQU	$
	STZ	ENYPS0,X
	STA	<ENMYNO,X
	CMP	#0EH
	BEQ	OPYPLS
	CMP	#0FH
	BEQ	OPYPLS
	CMP	#10H
	BEQ	OPYPLS
	CMP	#14H
	BEQ	OPYPLS
	CMP	#08H
	BEQ	OPYPLS
	LDA	#98H
	BRA	OPYNML
OPYPLS	EQU	$
	LDA	#88H
OPYNML	EQU	$
	STA	ENYPS1,X
	LDA	<TWORK6
	CLC
	ADC	#18H
	STA	<TWORK6
	STA	ENOBJX
	LDA	#20H
	STA	ENOJBG,X
;
	PHX
	TYX
	LDA	CORSNO
	CMP	#08H
	BCC	BST030
	LDA	>ENOPD2,X
	BRA	BST040
BST030	EQU	$
	LDA	>ENOPDT,X
BST040	EQU	$
	PLX
	CMP	#05H
	BNE	OPNHMB
	STA	OPTFLG
	JSR	HMBSET
OPNHMB	EQU	$
	LDA	#02H
	STA	<ENMMKI,X
OPNTST	EQU	$
	RTS
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
NEXTSB	EQU	$
	LDA	CORSNO
	ASL	A
	ASL	A
	CLC
	ADC	CORSNO
	CLC
	ADC	CORSID
	TAX
	LDA	>NXBGDT,X
	STA	NEXTBG
	LDA	>NXCODT,X
	STA	NEXTNO
	PHA
	CMP	#021H
	BCC	URCORS
	SEC
	SBC	#21H
	STA	NEXTNO
URCORS	EQU	$
	ASL	A
	ASL	A
	CLC
	ADC	NEXTNO
	TAY
	PLA
	STA	NEXTNO
;
	LDA	DSXP01
	STA	<SCCHWK
	LDA	DSXP00
	STA	<SCCHWK+1
	INC	<SCCHFG
	STZ	DSXP00
	STZ	SCCH
	STZ	SCCH21
	STZ	SCCH22
	STZ	SCCH31
	STZ	SCCH32
	STZ	210DH
	STZ	210DH
	STZ	210FH
	STZ	210FH
	STZ	2111H
	STZ	2111H
;
	RTS
;;;;;;;;;;;;
GESDAT	EQU	$
	HEX	DC,DC
	HEX	DD,DD
	HEX	DE,DE
GESSO	EQU	$
;
	LDA	GESDAT
	STA	OAM2+62H
	LDA	GESDAT+1
	STA	OAM2+66H
	LDA	GESDAT+2
	STA	OAM2+6AH
	LDA	GESDAT+3
	STA	OAM2+6EH
	LDA	GESDAT+4
	STA	OAM2+72H
	LDA	GESDAT+5
	STA	OAM2+76H
;
	RTS
;;;;;;;;;;;;
JYUDAT	EQU	$
	HEX	B9,B8
	HEX	BB,BA
	HEX	BC,BC
JYUSET	EQU	$
;
	PHY
	LDA	#03
	STA	<WORK3
	LDA	ENYPS1,X
	SEC
	SBC	#28H
	STA	ENYPS1,X
	STZ	<TWORK7
	LDY	#0
JYLP10	EQU	$
	LDA	ENOBJX
	STA	OAM2+90H,Y
	CLC
	ADC	#08
	STA	OAM2+94H,Y
	LDA	ENYPS1,X
	STA	OAM2+91H,Y
	STA	OAM2+95H,Y
	CLC
	ADC	#08H
	STA	ENYPS1,X
	LDA	#2AH
	STA	OAM2+93H,Y
	STA	OAM2+97H,Y
	PHX
	LDX	<TWORK7
	LDA	JYUDAT,X
	STA	OAM2+92H,Y
	LDA	JYUDAT+1,X
	STA	OAM2+96H,Y
	INC	<TWORK7
	INC	<TWORK7
	PLX
	INY
	INY
	INY
	INY
	INY
	INY
	INY
	INY
	DEC	<WORK+3
	BNE	JYLP10
	PLY
;
	RTS
;
KUPAST	EQU	$
;
	PHY
	PHX
;
	LDA	ENYPS1,X
	STA	ENOBJY
	SEC
	SBC	#08H
	STA	ENOBJY
	LDA	ENOBJX
	SEC
	SBC	#10H
	STA	ENOBJX
;
	LDY	#90H
	LDX	#0
KPSB10	EQU	$
	LDA	ENOBJX
	STA	OAM2,Y
	STA	OAM2+08,Y
	CLC
	ADC	#8
	STA	OAM2+16,Y
	CLC
	ADC	#8
	STA	OAM2+04,Y
	STA	OAM2+12,Y
	STA	OAM2+20,Y
	LDA	ENOBJY
	STA	OAM2+01,Y
	STA	OAM2+05,Y
	CLC
	ADC	#10H
	STA	OAM2+09,Y
	STA	OAM2+13,Y
	SEC
	SBC	#18H
	STA	OAM2+17,Y
	STA	OAM2+21,Y
;
	LDA	#0
	STA	OAMSB+16,Y
	STA	OAMSB+20,Y
	LDA	#2
	STA	OAMSB2+00,Y
	STA	OAMSB2+04,Y
	STA	OAMSB2+08,Y
	STA	OAMSB2+12,Y
;
	LDA	#61H
	STA	OAM2+03,Y
	STA	OAM2+07,Y
	STA	OAM2+11,Y
	STA	OAM2+15,Y
	STA	OAM2+19,Y
	STA	OAM2+23,Y
;
	LDA	#0C5H
	STA	OAM2+18,Y
	LDA	#0C4H
	STA	OAM2+22,Y
	LDA	#0EEH
	STA	OAM2+02,Y
	LDA	#0C0H
	STA	OAM2+06,Y
	LDA	#0E2H
	STA	OAM2+10,Y
	LDA	#0E0H
	STA	OAM2+14,Y
;;;;;		FIRE
;
	LDA	#70H
	STA	OAM2+0F0H
	LDA	#78H
	STA	OAM2+0F4H
	LDA	#98H
	STA	OAM2+0F1H
	STA	OAM2+0F5H
	LDA	#86H
	STA	OAM2+0F2H
	LDA	#87H
	STA	OAM2+0F6H
	LDA	#21H
	STA	OAM2+0F3H
	STA	OAM2+0F7H
	LDA	#2
	STA	OAMSB2+0F0H
	STA	OAMSB2+0F4H
;
	PLX
	PLY
;
	RTS
;
HMBSET	EQU	$
	LDA	ENYPS1,X
	SEC
	SBC	#0AH
	STA	OAM+81H
	LDA	ENOBJX
	CLC
	ADC	#3
	STA	OAM+80H
	LDA	#2AH
	STA	OAM+83H
	LDA	#44H
	STA	OAM+82H
	LDA	#02H
	STA	OAMSB+80H
	RTS
;
;
PLOMST	 EQU	  $
	 STA	  <WORK+7
;
	 LDA	  PLOBJX
	 STA	  PLOXPS
	 STA	  <WORK+5		; <WORK+5 <-- OBJ (x)pos
;
	 LDA	  PLOBJY
	 STA	  <WORK+2		; <WORK+2 <-- OBJ (y)pos
;
	 LDA	  PLCMKI
	 STA	  <WORK+3		; <WORK+3 <-- Chara muki
;
	JSL	>PLCHCH
;
	LDA	CHNOID
	AND	#07H
	TAX
;
	 LDA	  PLOJBG
	 STA	  <WORK+4		; <WORK+4 <-- Player color & OBJ.BG priority
	 LDY	  !OAMPL	       ; Yr <-- OAM index
;
;#####################################################################
;#		     (X) -- Chara No. data table index		     #
;#		     (Y) -- Use OAM index			     #
;#		     02H -- (y)pos				     #
;#		     03H -- Muki				     #
;#		     04H -- Color				     #
;#		     05H -- (x)pos				     #
;#		     07H -- Set OAM count			     #
;#	 JSR	  PLOMSS    [ Player OAM set sub ]		     #
;#####################################################################
PLOMSS	 EQU	  $
	 LDA	  CNDATA,X
	 STA	  <WORK
;
	 LDA	  CNDATA+1,X
	 JSR	  OAMSTW
;
	 DEC	  <WORK+7
	 BNE	  PLOMSS	  ;- IF	 all set end ?	( NO ; PLOMSS )
;
	LDA	<WORK5
	CMP	#0F8H
	BCC	PLOMSSR
	LDA	#01H
	STA	OAMSB+0D0H
	STA	OAMSB+0D8H
	STA	OAMSB+0E0H
	STA	OAMSB+0E8H
PLOMSSR EQU	$
	 RTS
;
;#####################################################################
;#	 JSR	  PLWJIC    [ Player walk & jump & slip index calc ] #
;#		      Ar -- Chara No. table index		     #
;#####################################################################
PLWJIC	 EQU	  $
	 LDA	  <CSTAT
	 CMP	  #PWIRE
	 BEQ	  PLWJ70	  ;- IF	 tuch wire ?	    ( YES ; PLWJ70 )
;
	 CMP	  #BDROP
	 BEQ	  PLWJ55	  ;- IF	 now drop ?	    ( YES ; PLWJ55 )
;
	 CMP	  #BJUMP
	 BNE	  PLWJ20	  ;- IF	 now jump ?	    ( NO ; PLWJ20 )
;
	 LDA	  PLSMFG
	 BNE	  PLWJ80	  ;- IF	 now siwming ?	    ( YES ; PLWJ80 )
;
	 LDY	  #PLCI35-CNOIDX
	 LDA	  PLSDFG
	 BNE	  PLWJ50	  ;- IF	 sit down player ?  ( YES ; PLWJ52 )
;
	LDY	#0
	BRA	PLWJ50
;;;	    JMP	     PLWJ50
;
PLWJ20	 EQU	  $
	 LDY	  #PLCI35-CNOIDX
	 LDA	  PLSDFG
	 BNE	  PLWJ50	  ;- IF	 sit down player ?  ( YES ; PLWJ52 )
;
PLWJ30	 EQU	  $
	 LDY	  #2
	 LDA	  <XSPED0
	 ORA	  <KEYLR
	 BEQ	  PLWJ50	  ;- IF	 player stop ?	    ( YES ; PLWJ50 )
;
	 LDA	  XSPLV
	 CMP	  #WKSLW
	 BCC	  PLWJ60	  ;- IF	 walk speed slow ?  ( YES ; PLWJ60 )
;
	 LDA	  <MMUKI
	 AND	  CMUKI
	 BNE	  PLWJ60	  ;- IF	 slip ?		    ( NO ; PLWJ60 )
;
	 INY
;
PLWJ50	EQU	$			; Jump & Slip & Stop player index set !
	JSR	PLWJSB			; Player big or small check
;
	STZ	CNOCNT			; Chara No. counter init
;;;	    LDA	     #0
;;;	    STA	     CNOCNT		  ; Chara No. counter init
;
	 LDA	  CNOIDX,Y
;
	 RTS
;
PLWJ55	 EQU	  $		  ; Drop player index set !
	 LDY	  #PLCI30-CNOIDX
	 JSR	  PLWJSB	       ; Player big or small check
	 BRA	  PLWJ90	       ; Drop chara index set
;
PLWJ60	 EQU	  $		  ; Walk player index set !
	 LDY	  #PLCI30-CNOIDX
	 JSR	  PLWJSB	       ; Player big or small check
	 BRA	  PLCPC0	       ; Walk chara patern calc
;
PLWJ70	 EQU	  $		  ; Tuch wire player index set !
	 LDY	  #PLCI32-CNOIDX
	 LDA	  <PLYCL0
	 BEQ	  PLWJ50	       ;- IF  player up wire ?	 ( NO ; PLWJ50 )
;
	 JSR	  PLWJSB	       ; Player big or small check
	 BRA	  PLCPC1
;
PLWJ80	 EQU	  $		  ; Swim player index set !
	 LDY	  #PLCI20-CNOIDX
	 JSR	  PLWJSB	       ; Player big or small check
;
	 LDA	  PLATM
	 ORA	  CNOCNT
	 BNE	  PLCPC0	       ;- IF  chara harf timing ?     ( YES ; PLCPC0 )
;
	 LDA	  <KEYAB
	 ASL	  A
	 BCS	  PLCPC0	       ;- IF  'A' ON ?		      ( YES ; PLCPC0 )
;
PLWJ90	 EQU	  $
;#####################################################################
;#		      Yr -- Chara No. table class table index	     #
;#	 JSR	  CNDIDC    [ Chara No. data index calc ]	     #
;#####################################################################
CNDIDC	 EQU	  $
	 LDA	  CNOCNT
	 JMP	  PLCH75
;
;#####################################################################
;#		      Yr -- Chara No. table class table index	     #
;#	 JSR	  PLCPC0    [ Player chara patern ( 0-1-2 ) calc ]   #
;#		      Ar -- Chara No. table Index		     #
;#####################################################################
PLCPC0	EQU	$
	LDA	#3
	BRA	PLCP30
;;;	    JMP	     PLCP30
;
;#####################################################################
;#		      Yr -- Chara No. table class table index	     #
;#		  PLCHTV -- Chara change time			     #
;#	 JSR	  PLCPC1    [ Player chara patern ( 0-1 ) calc ]     #
;#		      Ar -- Chara No. table Index		     #
;#####################################################################
PLCPC1	 EQU	  $
	 LDA	  #2
;
PLCP30	 EQU	  $
	 STA	  <WORK
;
	 JSR	  CNDIDC	  ; Chara No. data index calc !
	 PHA
;
	 LDA	  PLCHTM
	 BNE	  PLCP80	  ;- IF	 chara change time ?  ( NO ; PLCP80 )
;
	 LDA	  PLCHTV	  ; Chara No. change counter calc !
	 STA	  PLCHTM	       ; Next change time set
;
	 LDA	  CNOCNT
	 CLC
	 ADC	  #1
	 CMP	  <WORK
	 BCC	  PLCP50
;
	 LDA	  #0
;
PLCP50	 EQU	  $
	 STA	  CNOCNT
;
PLCP80	 EQU	  $
	 PLA
;
	 RTS
;
;#####################################################################
;#	 JSR	  PLWJSB    [ Player big or small check ]	     #
;#####################################################################
PLWJSB	 EQU	  $		  ; Player big or small check !
	 LDA	  PLSIZE
	 BEQ	  PLCS90	       ;- IF  big player ?  ( YES ; PLCS90 )
;
	 TYA
	 CLC
	 ADC	  #PLCI40-CNOIDX
	 TAY
;
PLCS90	 EQU	  $
;
	 RTS
;
;#####################################################################
;#	 JSR	  PLCHIC    [ Change player chara No. index calc ]   #
;#		      Ar -- Chara No. table index		     #
;#		      Yr -- Chara No. table class table index	     #
;#####################################################################
CHMODE	 EQU	  $	    ; Change chara mode data !
	 HEX	  00,01,00,01,00,01,02,00,01,02	      ; Small --! Big
CHMBS	 HEX	  02,00,02,00,02,00,02,00,02,00	      ; Big   --! Small
;
PLCHIC	 EQU	  $
	 LDY	  CNOCNT
	 LDA	  <FMCNT
	 AND	  #00000011B
	 BNE	  PLCH70	  ;- IF	 chara change time ?  ( NO ; PLCH70 )
;
	 INY
	 CPY	  #CHMBS-CHMODE
	 BCC	  PLCH50	  ;- IF	 change end ?	      ( NO ; PLCH50 )
;
	 LDY	  #00H
	 STY	  PLCHFG
;
PLCH50	 EQU	  $
	 STY	  CNOCNT
;
PLCH70	 EQU	  $		  ; Chara No. table index calc !
	 LDA	  PLSIZE
	 BNE	  PLCH80	       ;- IF  next big player ?	 ( YES ; PLCH80 )
;
	 LDA	  CHMODE,Y	       ; Small --! Big change index calc >
	 LDY	  #PLCI90-CNOIDX
PLCH75	 EQU	  $
	 ASL	  A
	 ASL	  A
	 ASL	  A
	 ADC	  CNOIDX,Y
;
	 RTS
;
PLCH80	 EQU	  $		       ; Big --! Samll change index clac >
	 TYA
	 CLC
	 ADC	  #CHMBS-CHMODE
	 TAX
;
	 LDY	  #PLCI50-CNOIDX
	 LDA	  CHMODE,X
	 BNE	  PLCH90
;
	 LDY	  #PLCI20-CNOIDX
;
PLCH90	 EQU	  $
	 LDA	  CNOIDX,Y
;
	 RTS
;
;#####################################################################
;#		  CHNOID -- Chara No. table index		     #
;#	 JSR	  PLFLIP    [ Player obj one point flipping  ]	     #
;#####################################################################
PLFLIP	 EQU	  $
	 LDY	  !OAMPL
	 LDA	  <PLCMOD
	 CMP	  #PLSF
	 BEQ	  PLFP40	  ;- IF	 fail small mario ?	   ( YES ; PLFP40 )
;
	 LDA	  CHNOID
	 CMP	  #PLSHD-CNDATA
	 BEQ	  PLFP50	  ;- IF	 mario shit dowm chara ?   ( YES ; PLFP50 )
;
	 CMP	  #PLCHN-CNDATA
	 BEQ	  PLFP50	  ;- IF	 small mario stop cahar ?  ( YES ; PLFP50 )
;
	 CMP	  #PLCHN+8-CNDATA
	 BEQ	  PLFP50	  ;- IF	 midle mario stop chara ?  ( YES ; PLFP50 )
;
	 CMP	  #PLCHN+16-CNDATA
	 BNE	  PLFP90	  ;- IF	 big mario stop chara ?	   ( NO ; PLFP90 )
;
PLFP40	 EQU	  $		   ;	    +----+----+
;	  LDA	   OAM+19,Y	 ;A ;	     +	  |    |
;	  AND	   #00111111B	    ;	     +----+----+
;	  STA	   OAM+19,Y	 ;A ;	     |	  |    |
;				   ;	    +----+----+
;	  LDA	   OAM+23,Y	 ;A ;	     |	  | FL |
;	  AND	   #00111111B	    ;	     +----+----+
;	  ORA	   #01000000B	    ;	     |	  |    |
;	  STA	   OAM+23,Y	 ;A ;	     +----+----+
;
PLFP50	 EQU	  $		   ;	    +----+----+
;	  LDA	   OAM+27,Y	 ;A ;	     |	  |    |
;	  AND	   #00111111B	    ;	     +----+----+
;	  STA	   OAM+27,Y	 ;A ;	     |	  |    |
;				   ;	    +----+----+
;	  LDA	   OAM+31,Y	;A ;	    |	 |    |
;	  AND	   #00111111B	    ;	     +----+----+
;	  ORA	   #01000000B	    ;	     |	  | FL |
;	  STA	   OAM+31,Y	;A ;	    +----+----+
;
PLFP90	 EQU	  $
;
	 RTS
;
DKYUSN	EQU	$
	LDA	UCHFLG
	BEQ	FLPSKP
	LDX	#0
PLFLLP	EQU	$
	LDA	OAM+0D0H,X
	STA	OAM2+0E0H,X
	INX
	CPX	#20H
	BNE	PLFLLP
	LDA	#0F0H
	STA	OAM+0D1H
	STA	OAM+0D5H
	STA	OAM+0D9H
	STA	OAM+0DDH
	STA	OAM+0E1H
	STA	OAM+0E5H
	STA	OAM+0E9H
	STA	OAM+0EDH
;
	LDA	OAMSB+0D0H
	STA	OAMSB+1E0H
	LDA	OAMSB+0D4H
	STA	OAMSB+1E4H
	LDA	OAMSB+0D8H
	STA	OAMSB+1E8H
	LDA	OAMSB+0DCH
	STA	OAMSB+1ECH
	LDA	OAMSB+0E0H
	STA	OAMSB+1F0H
	LDA	OAMSB+0E4H
	STA	OAMSB+1F4H
	LDA	OAMSB+0E8H
	STA	OAMSB+1F8H
	LDA	OAMSB+0ECH
	STA	OAMSB+1FCH
FLPSKP	EQU	$
	RTS
;---------------------------------------------------------------------<< Chara set common routine
;#####################################################################
;#	 JSR	  PLPSCV    [ Player position convert ]		     #
;#####################################################################
PLPSCV	 EQU	  $
	 LDX	  #PLXPS0-XPOS0
	 LDY	  #PLOBJX-OBJXPS
	 JMP	  CLPC20
;
;#####################################################################
;#	 JSR	  BLPSCV    [ Bubble position convert ]		     #
;#####################################################################
BLPSCV	EQU	$
	LDY	#1
	JSR	ABIDCL
;
	LDY	#BLOBJX-OBJXPS
	BRA	CLPC20
;;;	    JMP	     CLPC20
;
;#####################################################################
;#	 JSR	  FIPSCV    [ Fire position convert ]		     #
;#####################################################################
FIPSCV	 EQU	  $
	 LDY	  #0
	 JSR	  ABIDCL	  ; Calc  Absolute index
;
	 LDY	  #FIOBJX-OBJXPS
;
CLPC20	 EQU	  $
	 JSR	  POSCOV
;
	 LDX	  <INDEX
;
	 RTS
;
;#####################################################################
;#	 JSR	  COPSCV    [ Coin  position convert ]		     #
;#####################################################################
COPSCV	EQU	$
HMPSCV	EQU	$
	LDY	#2
	JSR	ABIDCL			; Calc	Absolute index
;
	LDY	#COOBJX-OBJXPS
	BRA	CLPC20
;;;	    JMP	     CLPC20
;
;#####################################################################
;#	 JSR	  MSPSCV    [ Mushroom position convert ]	     #
;#####################################################################
MSPSCV	 EQU	  $
;#####################################################################
;#		      Xr -- Index				     #
;#	 JSR	  ENPSCV    [ Enmey position convert ]		     #
;#####################################################################
ENPSCV	 EQU	  $
	 LDA	  #ENXPS0-XPOS0
	 LDY	  #ENOBJX-OBJXPS
	 JMP	  POSAAA
;
;#####################################################################
;#		      Xr -- Index    ( 0 ~ 3 )			     #
;#	 JSR	  BKPSCV    [ Block position convert ]		     #
;#####################################################################
BKPSCV	 EQU	  $
	 LDA	  #BKXPS0-XPOS0
	 LDY	  #BKOBJX-OBJXPS
	 JSR	  POSAAA
;
	 INX
	 INX
;
	 LDA	  #BKXPS0-XPOS0
	 INY
;
POSAAA	 EQU	  $
	 STX	  <WORK
	 CLC
	 ADC	  <WORK
	 TAX
;
	 JSR	  POSCOV
;
	 LDX	  <INDEX
;
	 RTS
;
;#####################################################################
;#		      Xr -- Index				     #
;#		      Yr -- Index ( Absolute OBJ pos set area )	     #
;#	 JSR	  POSCOV    [ Position convert ]		     #
;#####################################################################
POSCOV	 EQU	  $
	 LDA	  YPOS1,X
	 STA	  OBJYPS,Y
;
;;TF;;
	LDA	<PLSTFG
	BEQ	POS010
	LDA	PLXPS1
	BNE	POS010
	LDA	#28H
	STA	PLXPS1
	BRA	POS020
POS010	EQU	$
	 LDA	  XPOS1,X
	 SEC
	 SBC	  DSXP01
	 STA	  OBJXPS,Y
	LDA	<XPOS0,X
	SBC	DSXP00
	STA	OBJXP2,Y
;
POS020	EQU	$
	PHY
	TYA
	ASL	A
	TAY
;
	LDA	 XPOS1,X
	STA	<YWORK
	LDA	XPOS0,X
	STA	<YWORK1
	MEM16
	REP	#20H
	LDA	<YWORK
	SEC
	SBC	<SCCH1
	STA	PLOX16,Y
	MEM8
	SEP	#20H
;
	PLY
;
	 RTS
;
;#####################################################################
;#	 JSR	  PLFRCK    [ Player frame check ]		     #
;#		  PLFMSD -- xxxx xxxx				     #
;#			      |	   +--- (x) side		     #
;#			      +-------- (y) side		     #
;#####################################################################
PLFRCK	 EQU	  $
	 LDX	  #PLXPS0-XPOS0
	 LDY	  #PLFMSD-FMSIDE
	 JMP	  FMCDS1
;
;#####################################################################
;#	 JSR	  FIFRCK    [ Player fire frame check ]		     #
;#		  FIFMSD -- xxxx xxxx				     #
;#			      |	   +--- (x) side		     #
;#			      +-------- (y) side		     #
;#####################################################################
FIFRCK	 EQU	  $
	 LDY	  #0
	 JSR	  ABIDCL
;
	 LDY	  #FIFMSD-FMSIDE
	 JMP	  FMCDS1
;
;#####################################################################
;#	 JSR	  BLFRCK    [ Player bubble frame check ]	     #
;#		  FMSIDE -- xxxx xxxx				     #
;#			      |	   +--- (x) side		     #
;#			      +-------- (y) side		     #
;#####################################################################
BLFRCK	 EQU	  $
	 LDY	  #1
	 JSR	  ABIDCL	  ; Calc  Absolute index
;
	 LDY	  #BLFMSD-FMSIDE
	 JMP	  FMCDS1
;
;#####################################################################
;#	 JSR	  COFRCK    [ Coin frame check ]		     #
;#		  FMSIDE -- xxxx xxxx				     #
;#			      |	   +--- (x) side		     #
;#			      +-------- (y) side		     #
;#####################################################################
COFRCK	 EQU	  $
HMFRCK	 EQU	  $
	 LDY	  #2
	 JSR	  ABIDCL	  ; Calc  Absolute index
;
	 LDY	  #COFMSD-FMSIDE
	 JMP	  FMCDS1
;
;#####################################################################
;#		     (X) -- Index				     #
;#		     (Y) -- Kind No.				     #
;#			    0 : Fire ball			     #
;#			    1 : Bubble				     #
;#			    2 : Coin				     #
;#	 JSR	  ABIDCL    [ Absolute index calc ]		     #
;#		     (X) -- Absolute index			     #
;#####################################################################
ABIDCD	 EQU	  $		  ; Absolute index calc data !
	 BYTE	  FIXPS0-XPOS0	       ; Fire ball
	 BYTE	  BLXPS0-XPOS0	       ; Bubble
	 BYTE	  COXPS0-XPOS0	       ; Coin
;
ABIDCL	 EQU	  $
	 TXA
	 CLC
	 ADC	  ABIDCD,Y
	 TAX
;
	 RTS
;
;#####################################################################
;#	 JSR	  MSFRCK    [ Mushroom frame check ]		     #
;#		  FMSIDE -- xxxx xxxx				     #
;#			      |	   +--- (x) side		     #
;#			      +-------- (y) side		     #
;#####################################################################
MSFRCK	 EQU	  $
;#####################################################################
;#	 JSR	  ENFRCK    [ Enemy frame check ]		     #
;#		  ENFMSD -- xxxx xxxx				     #
;#			      |	   +--- (x) side		     #
;#			      +-------- (y) side		     #
;#####################################################################
ENFRCK	EQU	$
	LDA	#ENXPS0-XPOS0
	LDY	#ENFMSD-FMSIDE
	BRA	FMCDS0
;;;	    JMP	     FMCDS0
;
;#####################################################################
;#		      Xr -- Index				     #
;#	 JSR	  BKFRCK    [ Block frame check ]		     #
;#		  FMSIDE -- xxxx xxxx				     #
;#			      |	   +--- (x) side		     #
;#			      +-------- (y) side		     #
;#####################################################################
BKFRCK	 EQU	  $
	 LDA	  #BKXPS0-XPOS0
	 LDY	  #BKFMSD-FMSIDE
;
;#####################################################################
;#		      Ar -- Index ( Pos data area index )	     #
;#		      Yr -- Index ( OBJ pos set area )		     #
;#	 JSR	  FMCDS0    [ Frame side check data set No.0 ]	     #
;#		  FMSIDE -- xxxx xxxx				     #
;#			      |	   +--- (x) side		     #
;#			      +-------- (y) side		     #
;#####################################################################
FMCDS0	 EQU	  $
	 STX	  <WORK
	 CLC
	 ADC	  <WORK
	 TAX
;
;#####################################################################
;#		      Xr -- Index				     #
;#		      Yr -- Index ( Absolute OBJ pos set area )	     #
;#	 JSR	  FMCDS1    [ Frame side check data set No.1 ]	     #
;#		  FMSIDE -- xxxx xxxx				     #
;#			      |	   +--- (x) side		     #
;#			      +-------- (y) side		     #
;#####################################################################
FMCDS1	 EQU	  $
	 TYA
	 PHA
;
	 JSR	  FRMCHK
	 ASL	  A
	 ASL	  A
	 ASL	  A
	 ASL	  A
	 ORA	  <WORK
	 STA	  <WORK
;
	 PLA
	 TAY
;
	 LDA	  <WORK
	 STA	  FMSIDE,Y
	LSR	A
	LSR	A
	PHA
	AND	#00000001B
	STA	FMRIGH,Y
	PLA
	LSR	A
	STA	FMLEFT,Y
;
	 LDX	  <INDEX
;
	 RTS
;
;#####################################################################
;#		      Xr <-- Index ( absolute )	      Obj 4x4 Chrs.  #
;#						   y.		     #
;#	 JSR	  FRMCHK    [ Flame check ]	   1 [][][][]	     #
;#						   2 [][][][]	     #
;#		      Ar     <--  y.		   3 [][][][]	     #
;#		      WORK   <--  x.		   4 [][][][]	     #
;#			     1 2 3 4		   x.1 2 3 4	     #
;#			    [][][][]				 #
;#		   Bit off : display				     #
;#		   Bit on  : No. display			     #
;#####################################################################
FRMCHK	 EQU	  $
	 JSR	  FRMXCK	  ; (x)side check
	 LSR	  A
	 LSR	  A
	 LSR	  A
	 LSR	  A
	 STA	  <WORK
;
	 JMP	  FRMYCK	  ; (y)side check
;
;
;#####################################################################
;#		     (X) -- Index ( Abusolute )			     #
;#	 JSR	  FRMXCK    [ Frame (x)side check ]		     #
;#		     (A) -- Hide data				     #
;#####################################################################
XHDBTD	 EQU	  $	    ; (x)hide check bit data !
	 BIN	  01111111,00111111,00011111,00001111		; Right side
	 BIN		   00000111,00000011,00000001
;
XHBR0	 BIN	  00000000,10000000,11000000,11100000		; Left side
	 BIN		   11110000,11111000,11111100,11111110
XHBR1	 BIN		   11111111
;
XHBSBD	 EQU	  $	    ; Hide bit set sub data !
	 BYTE	  XHBR0-XHDBTD,XHBR1-XHDBTD,XHBR0-XHDBTD
;
FRMXCK	 EQU	  $
	 STX	  <WORK+4	   ; <WORK+4 <-- Index
;
	 LDY	  #1
;
FRXC30	 EQU	  $
	 LDA	  DSXP01,Y
	 SEC
	 SBC	  XPOS1,X
	 STA	  <WORK+7
;
	 LDA	  DSXP00,Y
	 SBC	  <XPOS0,X
	 LDX	  XHBSBD,Y
	 CMP	  #0
	 BMI	  FRXC60	  ;- IF	 all hide ?		( YES ; FRXC60 )
;
	 LDX	  XHBSBD+1,Y
	 CMP	  #1
	 BPL	  FRXC60
;
	 LDA	  #38H
	 STA	  <WORK+6
;
	 LDA	  #(XHBR0-XHDBTD)+1
	 JSR	  XYHDCL	       ; (x)hide calc
;
FRXC60	 EQU	  $
	 LDA	  XHDBTD,X
	 LDX	  <WORK+4
	 CMP	  #0
	 BNE	  FRXC90	  ;- IF	 display potision ?	( NO ; FRXC90 )
;
	 DEY
	 BPL	  FRXC30	  ;- IF	 check end left side ?	( NO ; FRXC30 )
;
FRXC90	 EQU	  $
;
	 RTS
;
;#####################################################################
;#		     (X) -- Index ( Abusolute )			     #
;#	 JSR	  FRMYCK    [ Frame (y)side check ]		     #
;#		     (A) -- Hide data				     #
;#####################################################################
YHDBTD	 EQU	  $
	 BIN	  00000000,00001000,00001100,00001110		; Top side
YHBR	 BIN	  00001111,00000111,00000011,00000001,00000000	; Bottom side
;
YHBSBD	 EQU	  $	    ; Hide bit set sub data !
	 BYTE	  YHBR-YHDBTD,YHDBTD-YHDBTD,YHBR-YHDBTD
;
YHDCLD	 EQU	  $	    ; (y)hide calc data !
	 HEX	  FF,00
;
FRMYCK	 EQU	  $
	 STX	  <WORK+4
;
	 LDY	  #1
;
FRYC20	 EQU	  $
	 LDA	  YHDCLD,Y
	 SEC
	 SBC	  YPOS1,X
	 STA	  <WORK+7
;
	 LDA	  #1
	 SBC	  <YPOS0,X
	 LDX	  YHBSBD,Y
	 CMP	  #0
	 BMI	  FRYC60	  ;- IF	 all hide ?	       ( YES ; FRYC60 )
;
	 LDX	  YHBSBD+1,Y
	 CMP	  #1
	 BPL	  FRYC60
;
	 LDA	  #20H
	 STA	  <WORK+6
;
	 LDA	  #YHBR-YHDBTD
	 JSR	  XYHDCL	       ; (y)hide calc
;
FRYC60	 EQU	  $
	 LDA	  YHDBTD,X
	 LDX	  <WORK+4
	 CMP	  #0
	 BNE	  FRYC90	  ;- IF	 display position ?    ( NO ; FRYC90 )
;
	 DEY
	 BPL	  FRYC20	  ;- IF	 check end top side ?  ( NO ; FRYC20 )
;
FRYC90	 EQU	  $
;
	 RTS
;
;#####################################################################
;#		      Ar -- LF or DW data pointer		     #
;#		  WORK+6 -- Max block value ( 8 x block value )	     #
;#	 JSR	  XYHDCL    [ (x),(y)hide calcl ]		     #
;#		      Xr -- Hide data index			     #
;#####################################################################
XYHDCL	 EQU	  $
	 STA	  <WORK+5
;
	 LDA	  <WORK+7
	 CMP	  <WORK+6
	 BCS	  XYHC60
;
	 LSR	  A
	 LSR	  A
	 LSR	  A
	 AND	  #00000111B
	 CPY	  #1
	 BCS	  XYHC50	  ;- IF	 check top side ?      ( YES ; XYHC50 )
;
	 ADC	  <WORK+5
;
XYHC50	 EQU	  $
	 TAX
;
XYHC60	 EQU	  $
;
	 RTS
;
;#####################################################################
;#	 JSR	  FMXCK	   [ Frame (X)side check ]		     #
;#####################################################################
;
FMXCV	EQU	$
	LDA	<ENXPS0,X
	STA	ENXPWH
	LDA	ENXPS1,X
	STA	ENXPWL
	RTS
;
FMXCV2	EQU	$
	LDA	FMXBKH
	STA	ENXPWH
	LDA	FMXBKL
	STA	ENXPWL
	RTS
;
FMXCK2	EQU	$
	LDA	#6
	STA	<WORK4
	MEM16
	REP	#20H
	LDA	ENXPWL
	SEC
;;;;	SBC	DSXPLL
	SBC	<SCCH1
	STA	DSXPRL
	MEM8
	SEP	#20H
	LDA	DSXPRH
	BNE	SBCLR2
	LDA	#0
	BRA	SBST12
;
SBCLR2	EQU	$
	LDA	#1H
SBST12	EQU	$
	STA	OAMSB+100H,Y	;WORK4 <= 6
	RTS
;
FMXCK	EQU	$
	MEM16
	REP	#20H
	LDA	ENXPWL
	SEC
;;;;	SBC	DSXPLL
	SBC	<SCCH1
	STA	DSXPRL
	MEM8
	SEP	#20H
	LDA	DSXPRH
	BNE	SBCLR
	LDA	#0
	BRA	SBST10
;
SBCLR	EQU	$
	LDA	#1H
SBST10	EQU	$
	STA	OAMSB+110H,Y	;WORK4 <= 0
SBST20	EQU	$
	STA	OAMSB+108H,Y	;WORK4 <= 3
SBST30	EQU	$
	STA	OAMSB+100H,Y	;WORK4 <= 6
FMXRET	EQU	$
	RTS
;
FMXCKX	EQU	$
	MEM16
	REP	#20H
	LDA	ENXPWL
	SEC
;;;	SBC	DSXPLL
	SBC	<SCCH1
	STA	DSXPRL
	MEM8
	SEP	#20H
	LDA	DSXPRH
	BNE	SBCLRX
	LDA	#0
	BRA	SBST10X
;
SBCLRX	EQU	$
	LDA	#01
SBST10X EQU	$
	STA	OAMSB+08H,Y	;WORK4 <= 3
	STA	OAMSB+00H,Y	;WORK4 <= 6
FMXRETX EQU	$
	RTS
;
SBST40	EQU	$
	STA	OAMSB+00H,Y
	STA	OAMSB+08H,Y
	RTS
;
CHSTSU	EQU	$
	MEM16
	REP	#20H
	PLA
	CLC
	ADC	<WORK4
	STA	<WORK4
	PHA
	MEM8
	SEP	#20H
	LDA	#01H
	RTS
;
FMPLS	EQU	$
	MEM16
	REP	#20H
	LDA	ENXPWL
	CLC
	ADC	#0008H
	STA	ENXPWL
	MEM8
	SEP	#20H
	INY
	INY
	INY
	INY
	RTS
;
;#####################################################################
;#		  Yr  -- OAM Index.		      2 Chrs.	     #
;#		  Wk0 -- Character No. Left.	     --------> H     #
;#		  Wk1 --       "       Right.        |               #
;#		  Wk2 -- OBJ Y Position.	Any  |		     #
;#		  Wk3 -- OBJ muki. [ 2 or 1 ]	Chrs.|		     #
;#		  Wk4 -- OBJ Color.		     | V	     #
;#		  Wk5 -- OBJ X Position.	     v		     #
;#								     #
;#	 JSR	  OAMSET	     [ Obj Oam set ]		     #
;#								     #
;#		  Wk2 -- Next OBJ V Position.			     #
;#		  Yr  -- Next OAM Index.			     #
;#####################################################################
OAMSET	 EQU	  $
	 LDA	  <WORK+3
	 LSR	  A
	 LSR	  A
	 LDA	  <WORK
	 BCC	  OAMS10	  ; Muki left. ?
;				  : No.!
	 STA	  OAM+06,Y	;C
	 LDA	  <WORK+1
	 STA	  OAM+02,Y	;C
;
	 LDA	  #01000000B	  ; Flipping.
	 BNE	  OAMS20	  ; JMP	  OAMS20
;
OAMS10	 EQU	  $		  ; Muki Right. !
	 STA	  OAM+02,Y	;C
	 LDA	  <WORK+1
	 STA	  OAM+06,Y	;C
;
	 LDA	  #0		  ; No. Flipping.
OAMS20	 EQU	  $
	 ORA	  <WORK+4	   ; Color set.
	 STA	  OAM+3,Y	;A
	 STA	  OAM+7,Y	;A
;
	 LDA	  <WORK+2	   ; V pos. set.
	 STA	  OAM+01,Y	;Y
	 STA	  OAM+05,Y	;Y
;
	 LDA	  <WORK+5	   ; H pos. set.
	 STA	  OAM+00,Y	;X
	 CLC
	 ADC	  #8
	 STA	  OAM+04,Y	;X
;
	 LDA	  <WORK+2	   ; Next V pos. set.
	 CLC
	 ADC	  #8
	 STA	  <WORK+2
;
	 TYA			  ; Next OAM Index set.
	 CLC
	 ADC	  #8
	 TAY
;
	 INX			  ; pointer incliment.
	 INX
;
	 RTS
;
OAMSET2	 EQU	  $
	 LDA	  <WORK+3
	 LSR	  A
	 LSR	  A
	 LDA	  <WORK
	 BCC	  OAM2S10	   ; Muki left. ?
;				  : No.!
	 STA	  OAM2+06,Y	;C
	 LDA	  <WORK+1
	 STA	  OAM2+02,Y	;C
;
	 LDA	  #01000000B	  ; Flipping.
	 BNE	  OAM2S20	   ; JMP   OAMS20
;
OAM2S10	 EQU	  $
	 STA	  OAM2+02,Y	;C
	 LDA	  <WORK+1
	 STA	  OAM2+06,Y	;C
;
	 LDA	  #0		  ; No. Flipping.
OAM2S20	 EQU	  $
	 ORA	  <WORK+4	   ; Color set.
	 STA	  OAM2+3,Y	;A
	 STA	  OAM2+7,Y	;A
;
	 LDA	  <WORK+2	   ; V pos. set.
	 STA	  OAM2+01,Y	;Y
	 STA	  OAM2+05,Y	;Y
;
	 LDA	  <WORK+5	   ; H pos. set.
	 STA	  OAM2+00,Y	;X
	 CLC
	 ADC	  #8
	 STA	  OAM2+04,Y	;X
;
	 LDA	  <WORK+2	   ; Next V pos. set.
	 CLC
	 ADC	  #8
	 STA	  <WORK+2
;
	 TYA			  ; Next OAM Index set.
	 CLC
	 ADC	  #8
	 TAY
;
	 INX			  ; pointer incliment.
	 INX
;
	 RTS
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	 END
	RTL

