;
		INCLUDE mn_hp_mr3ram.asm
;
	 EXT	  RAMADR,RABGDA0
;
;====== <MR3MAIN> ====================================================
         EXT      JSRSUB
;--- VRFLG -- 
         EXT    BGVC
; 
;====== <MR3ENMY> ====================================================
;<Sub>
         EXT      PLAYAT
; 
;<Auto Scroll Data Index> 
         EXT      MVDTIN
         EXT      SC00,SC01,SC02,SC03,SC04,SC05,SC06,SC07,SC08,SC09,SC0A
         EXT      SC0B,SC0C,SC0D,SC0E,SC0F,SC0G,SC0H,SC0I,SC0J,SC0K 
; 
;<Enemy BG> 
         EXT      TOGEM,KURAM 
; 
; 
;====== <MR3SCRL> ====================================================
         GLB      SCRLMV
; 
         GLB      SC00MV,SC10MV,SC20MV,SC30MV,SC45MV
;;k;;         GLB      MVDI00,MVDI01,MVDI02,MVDI03,MVDI04,MVDI05,MVDI06,MVDI07 
;;k;;         GLB      MVDI08,MVDI09,MVDI0A,MVDI0B,MVDI0C,MVDI0D,MVDI0E,MVDI0F 
;;k;;         GLB      MVDI0G,MVDI0H,MVDI0I,MVDI0J,MVDI0K,MVDIEN 
; 
;<Auto Scroll Data Index> 
         GLB      SC45
         GLB      SC20
         GLB      SC50
; 
; 
;====== <MR3DATA0> ===================================================
; --------------------------------------------------------------all scroll
	EXT	SCENFG,MOVDT,MVDT0,MVDT1,MVDT2,MVDT3,MVDT4,MVDT5
	EXT	MVDT6,MVDT7,MVDT8,MVDT9,MVDTA,MVDTB,MVDTC,MVDTD
	EXT	MVDTE,MVDTH,MVDTI,MVDTJ,MVDTK,MVDTF,MVDTG,MVDEN
	EXT	TIMDT,TMDT0,TMDT1,TMDT2,TMDT3,TMDT4,TMDT5,TMDT6
	EXT	TMDT7,TMDT8,TMDT9,TMDTA,TMDTB,TMDTC,TMDTD,TMDTE
	EXT	TMDTH,TMDTI,TMDTJ,TMDTK,TMDTF,TMDTG,MOVAD,MV00
;
	EXT	HKMSPD
;
	EXT	SC0ADS,MV01,MVFF,PTMVIN,PTMV00,PTMV01,PTMV02,PTMV03
	EXT	PTMV04,PTMV05,PTMV06,PTMV07,PTMVD,PTMV0,PTMV1
	EXT	PTMV2,PTMV3,PTMV4,PTMV5,PTMV6,PTMV7,PTMVE,PTTMD
	EXT	PTTM0,PTTM1,PTTM2,PTTM3,PTTM4,PTTM5,PTTM6,PTTM7
;
	EXT	NOMV,XP00,XM00,YP00,YM00,PP00,PM00,MP00,MM00
	EXT	PT00,PT01,PT02,PT03,PT04,PT05,PT06,PT07
	EXT	MVDI00,MVDI01,MVDI02,MVDI03,MVDI04,MVDI05,MVDI06
	EXT	MVDI07,MVDI08,MVDI09,MVDI0A,MVDI0B,MVDI0C,MVDI0D
	EXT	MVDI0E,MVDI0H,MVDI0I,MVDI0J,MVDI0K,MVDI0F,MVDI0G
	EXT	MVDIEN
; -------------------------------------------------------------COBLNK
	EXT	COBLDT
; -------------------------------------------------------------V scroll only
	EXT	WTTRCY
; -------------------------------------------------------------JSR    SC10MV
	EXT	SC10AD,SC10MX,SC10ST,SC10S,SC11S,SC10,SC11
; -------------------------------------------------------------JSR    SC30MV
	EXT	SC30MX,SC30ST,SC30S,SC31S,SC32S,SC33S,SC3ES
	EXT	SC3FS,SC3GS,SC30,SC31,SC32,SC33,SC3E,SC3F,SC3G
; -------------------------------------------------------------JSR    SC45MV
	EXT	SC45XP
; 
;====== <MR3BG2ST> ===================================================
	EXT	SNDFLAS
;=====================================================================
         ORG      0278500H
		EXTEND
		IDX8
		MEM8
; 
; 
;*********************************************************************
;*       JSR      SCRLMV          :auto scroll                       *
;*                                                                   *
;*                                                                   *
;*********************************************************************
; 
SCRLMV   EQU      $ 
         LDA      !BAKUTM 
         ORA      !CHGTIM 
         ORA      <ENSTOP
         BEQ      SCRM10      ;enemy stop ? ( yes:SCRM10 )
; 
         LDA      !SCPTNO 
         CMP      #SC0F 
         BCC      SCRM00      ;tank ? ( no:SCRM00 ) 
; 
         LDA      #80H        ;bank change stop !!
         STA      !TIMEFG 
SCRM00   EQU      $ 
         RTL
; 
SCRM10   EQU      $ 
         STA      !TIMEFG     ;bank change set !! 
; 
         LDA      !SCTIME     ;timer set !! 
         BEQ      SCRM20
         DEC      !SCTIME 
SCRM20   EQU      $ 
	 JSR	  SCRM28
	 RTL
;---------------------------------
SCRM28   EQU      $ 
; 
         LDA      !SCMODE 
         JSL      >JSRSUB
SC00M    WORD     SC00MV      ;data read all scroll 
         WORD     SC00MV      ;          "
SC45M    WORD     SC45MV      ;test / 45
SC10M    WORD     SC10MV      ;up boude up & down 
SC20M    WORD     SC20MV      ;    "    down only 
SC30M    WORD     SC30MV      ;water
SC50M    EQU      $           ;not scroll !!
; 
SC000    EQU      (SC00M-SC00M)/2*10H 
SC450    EQU      (SC45M-SC00M)/2*10H 
SC100    EQU      (SC10M-SC00M)/2*10H 
SC200    EQU      (SC20M-SC00M)/2*10H 
SC300    EQU      (SC30M-SC00M)/2*10H 
SC50     EQU      (SC50M-SC00M)/2*10H 
; 
;----------------------------------------------------------------------------- 
; 
; 
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;%       COBLNK   Coin Color blinking                                %
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;K;COBLDT   EQU      $ 
;K;         HEX    27,27,27,17,07,17 
; 
COBLNK   EQU      $ 
         DEC    !COCGTM 
         BPL    COBL20
; 
         LDA    #05H
         STA    !COCGTM 
; 
         INC    !COCGCT 
         LDA    !COCGCT 
         CMP    #06H
         BCC    COBL10
; 
         LDA    #00H
         STA    !COCGCT 
COBL10   EQU    $ 
         TAY
         LDA    COBLDT,Y
         STA    !SLTCG0+0AH 
COBL20   EQU    $ 
         RTS
;
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
;%                                                          % 
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
SC00MV   EQU      $ 
         LDX      #00         ;X move 
         JSR      SCRCLC
         LDA      !SCPTNO 
         CMP      #SC0J 
         BNE      SC00E0
; 
         PHA
         JSR      COBLNK
         PLA
SC00E0   EQU      $ 
         CMP      #SC0E 
         BNE      SC00FF      ;water enter prize ? ( no:SC00FF )
; 
         JSR      PLWTCK      ;player water check & NMI,IRQ set 
SC00FF   EQU      $ 
         JSR      PLSTCK      ;player stop check & etc
; 
;------- scroll move set -------- 
SCRMOV   EQU      $ 
         LDA      !SCTIME 
         LSR      A 
         BCS      SC0RTS      ;move ? ( no:SC0RTS ) 
; 
         PHA
         JSR      SCYCLC      ;Y move 
         PLA
         BNE      SC0RTS      ;long timer dec ? ( no:SC0RTS ) 
; 
         LDA      !SCTIMH 
         BEQ      SC0000      ;long timer = 0 ? ( yes:SC0000 )
         JMP      SC0020
; 
SC0000   EQU      $ 
         LDA      !SCPTCT 
         BNE      SC0014      ;pattern move ? ( yes:SC0014 )
; 
SC0001   EQU      $
	 STX	  <ENMWK2
         LDX      !SCPTNO 
         LDA      !SCWK00     ;move data index
         CMP      >MVDTIN+1,X 
	 PHP
	 TXY
	 LDX	  <ENMWK2
	 PLP
         BNE      SC0010      ;move end ? ( no:SC0010 ) 
; 
         CPY      #SC0F 
         BCC      SC00015     ;tank ? ( no:SC00015 )
;                             ;[ LDA #80H    ]
         ROR      !TIMEFG     ;[ STA >TIMEFG ]
SC00015  EQU      $
         LDA      #00         ;X move end !!
         STA      !SCXSPD 
;------- auto scroll end check -------- 
         LDA      !SCENFG,Y 
         BNE      SC0002      ;scroll end ? ( no:SC0002 ) 
; 
         STA      !SCYSPD 
         STA      !SCXSDR 
SC0RTS   EQU      $ 
         RTS
; 
;------- wave move -------- 
SC0002   EQU      $ 
         STA      !SCWK01     ;pattern move no. set 
         LDA      #0FFH       ;[-] loop move set
         STA      !SCPTCT 
         BNE      SC0012      ;[ JMP SC0012 ] 
; 
;------- auto scroll -------- 
SC0010   EQU      $ 
         INC      !SCWK00     ;move data index
         LDY      !SCWK00     ;long timer set 
         LDA      !MOVDT,Y
         LSR      A 
         LSR      A 
         LSR      A 
         LSR      A 
         BEQ      SC0018      ;pattern move ? ( no:SC0018 ) 
; 
         STA      !SCWK01     ;pattern move no. set 
         LDY      !SCWK00 
         LDA      !TIMDT,Y    ;pattern move count set 
         STA      !SCPTCT 
; 
SC0012   EQU      $ 
         LDY      !SCWK01     ;pattern move data index set
         LDA      !PTMVIN,Y 
         STA      !SCPTPT 
; 
SC0014   EQU      $ 
         LDY      !SCWK01 
         LDA      !SCPTPT 
         CMP      !PTMVIN+1,Y 
         BNE      SC0016      ;pattern move data end ? ( no:SC0016 )
; 
         LDA      !PTMVIN,Y 
         STA      !SCPTPT 
         LDA      !SCPTCT 
         BMI      SC0016      ;loop move ? ( yes:SC0016 ) 
; 
         DEC      !SCPTCT     ;pattern move count dec !!
         BEQ      SC0001      ;pattern move end ? ( yes:SC0001 )
; 
SC0016   EQU      $ 
         INC      !SCPTPT 
         LDY      !SCPTPT 
         LDA      !PTTMD,Y
         BNE      SC0019      ;[ JMP SC0019 ] 
; 
SC0018   EQU      $ 
         LDA      !TIMDT,Y
SC0019   EQU      $ 
         STA      !SCTIMH     ;move long timer set
SC0020   EQU      $ 
         DEC      !SCTIMH 
         LDA      !SCPTCT 
         BEQ      SC0022      ;pattern move ? ( no:SC0022 ) 
; 
         LDY      !SCPTPT     ;move set 
         LDA      !PTMVD,Y
         BPL      SC0024      ;[ JMP SC0024 ] 
; 
SC0022   EQU      $ 
         LDY      !SCWK00     ;move set 
         LDA      !MOVDT,Y
SC0024   EQU      $ 
         PHA
         LSR      A 
         LSR      A 
         AND      #03H
         TAY
         LDA      !MOVAD,Y
         CLC
         ADC      !SCXSPD 
         STA      !SCXSPD 
         PLA
         AND      #03H
         TAY
         LDA      !MOVAD,Y
         CLC
         ADC      !SCYSPD 
         STA      !SCYSPD 
; 
SC0025   EQU      $ 
         LDA      #04         ;long timer dec timer 
         STA      !SCTIME 
SC0030   EQU      $
	 LDA	  BG3SCRF
	 CMP	  #003H
	 BNE	  SC0100	;BG3 KUMO hikousen?
;
	 LDX	  !MAPCOS 	;data index set
	 BRA	  SC0110
SC0100   EQU      $
	 LDX	  #008H		;takara bune index
	 CMP	  #004H
	 BEQ	  SC0110
;	  
	 RTS
SC0110   EQU      $
	 LDA	  !B3SCXSP
	 INC	  A
	 INC	  A
	 CMP	  HKMSPD,X
	 BCC	  SC0120
;
		AND	HKMSPD,X
SC0120		EQU	$
		STA	!B3SCXSP	;BG3 hikousen kumo speed set
		LDA	!BG2COS
		CMP	#023H
		BEQ	SC0125
		JSL	>SNDFLAS	; BG2 frashing sub
SC0125		EQU	$
		MEM16
		REP	#00100000B
		LDA	!SCCH2
		STA	!ACSCPT0+6
		LSR	A
		STA	!ACSCPT0+4
		LSR	A
		STA	!ACSCPT0+2
		LSR	A
		STA	!ACSCPT0+0
		MEM8
		SEP	#00100000B
		LDA	#007H
		STA	!NMIRCF
		RTS
;
;-------------------------------------------------
;-       player side stop check & etc            -
;-------------------------------------------------
PLSTCK   EQU      $ 
         LDA      #01         ;all scroll flag set !! 
         STA      !SCRSTP 
; 
         LDY      <JMPFLG
         BNE      SC0036      ;player jump ? ( yes:SC0036 ) 
; 
         LDA      !SCPTNO 
         CMP      #SC0F 
         BCC      SC0032      ;tank ? ( no:SC0032  )
; 
;------- auto scroll set --------
	 LDA	  #004H
	 STA      !NMIRCF     ;ground auto scroll set (new!!)
;
         LDA      <PLZPSH
         CMP      #01 
         BNE      SC0032      ;player stand up pos ok ? ( no:SC0032 ) 
         LDA      <PLZPSL
         CMP      #70H
         BCS      SC0034      ;                "        ( yes;SC0034 )
SC0032   EQU      $ 
         INY
SC0034   EQU      $ 
         STY      !SCRVSF 
; 
SC0036   EQU      $
;
;
;------- 93/02/23 change program ----------------------------------------
;;;;         LDA      <PLXDSP
;;;;         CMP      #10H
;;;;         BCC      SC0040      ;player side over ? ( yes:SC0040 )
;;;;         CMP      #0E0H 
;;;;         BCC      SC0045      ;         "         ( no:SC0045 ) 
;;;;SC0040   EQU      $
;;;;         LDA      !SCXSPD 
;;;;         CLC                  ;[!]
;;;;         SBC      <XSPEED
;;;;         EOR      <PLXDSP
;;;;         BMI      SC0050      ;player hosei ? ( no:SC0050 ) 
;;;;; 
;;;;         LDA      !SCXSPD     ;player hosei !!
;;;;         STA      <XSPEED
;;;;;
;
	 LDA	  #010H-1
	 SEC
	 SBC	  <PLXDSP
	 BCS	  SC0040	;left side over ? ( yes:SC0040 )
	 LDA	  <PLXDSP
	 SEC
	 SBC	  #0E0H
	 BCC	  SC0045	;right side over ? ( no:SC0045 )
SC0040   EQU      $
;
         LDA      !SCXSPD 
	 EOR	  <XSPEED
	 BMI	  SC0041
         STZ      !PLXSDR 
;
SC0041	 EQU	  $
         LDA      !SCXSPD 
         CLC
         SBC      <XSPEED
         EOR      <PLXDSP
         BMI      SC0050      ;player hosei ? ( no:SC0050 ) 
;
         LDA      !SCXSPD     ;player hosei !!
         STA      <XSPEED
	 BRA	 SC0050	
; 
;------------------------------------------------------------------------
;
;
SC0045   EQU      $ 
         LDA      !SCRVSF 
         BNE      SC0050      ;player X pos hosei ? ( no:SC0050 ) 
; 
         LDA      <PLXPSL
         CLC
         ADC      !SCMOVD 
         STA      <PLXPSL
         BCC      SC0050      ;(H) + ? ( no:SC0050 )
         INC      <PLXPSH
; 
SC0050   EQU      $ 
;------- scroll point set --------
SCRLST   EQU      $ 
         LDA      !SCXSPD     ;scroll muki set
         ASL      A 
         ROL      A 
         AND      #01H
         STA      !SCMUKI 
; 
;------- player X pos hosei --------- 
PLXPST   EQU      $ 
         LDA      <XSPEED
         BEQ      SC0070      ;player X move ? ( no:SC0070 )
         EOR      !SCXSPD 
         BMI      SC0070      ;player X speed ok ? ( no:SC0070 )
         LDY      #00 
         LDA      !SCMOVD 
         BEQ      SC0070      ;X scroll ? ( no:SC0070 ) 
         BPL      SC0060
         DEY
SC0060   EQU      $ 
         CLC
         ADC      <PLXPSL
         STA      <PLXPSL
         TYA
         ADC      <PLXPSH
         STA      <PLXPSH
         LDA      #00 
         STA      !PLXSDR 
SC0070   EQU      $ 
         RTS
; 
;K;;===========================================================
;K;;=       V scroll only                                     =
;K;;=                                                         =
;K;;===========================================================
;K;WTTRCY   EQU      $           ;water in check Y pos data
;K;; player size --> sml big 
;K;         HEX      08C,090 
;K;; 
;-------------------------------------------------
;-       JSR      SC20MV      ;down only boude   -
;-                                               -
;-------------------------------------------------
SC20     EQU      SC200 
; 
SC20MV   EQU      $ 
         LDA      !SCWK01 
         BNE      SC2020      ;move ? ( yes:SC2020 )
; 
         LDA      !SCCV1
         CMP      #0EFH 
         BNE      SC0070      ;move start ? ( no:SC0070 ) 
; 
         LDA      !SCCV1        ;intial Y pos set 
         STA      !SCYPOSL
         INC      !SCWK01     ;move "ON" !! 
         LDA      #020H       ;buru timer set !!
         BNE      SC2025      ;[ JMP SC2025 ] 
; 
SC2020   EQU      $ 
         LDA      !SCTIME 
         BEQ      SC2022      ;buru ? ( no:SC2022 ) 
; 
         JMP      SC1020
; 
SC2022   EQU      $ 
         LDA      !SCYPOSL
         CMP      #0DH
         BEQ      SC2040      ;scroll stop ? ( yes:SC2040 ) 
         CMP      #0FH
         BNE      SC2030      ;buru set ? ( no:SC2030 ) 
; 
;<SOUND : SFX>         LDA      4F2H        ;[S]
;<SOUND : SFX>         ORA      #08H
;<SOUND : SFX>         STA      4F2H
;;S;;
        LDA     #9H
        STA     !SOUND3
;; 
         LDA      #20H        ;buru timer set !!
SC2025   EQU      $ 
         STA      !SCTIME 
; 
SC2030   EQU      $ 
         JSR      SCYCLC      ;Y move 
         LDA      <FRCNT 
         AND      #07H
         BNE      SC2040
         LDA      !SCYSPD 
         CMP      #0F8H 
         BEQ      SC2040      ;max speed ? ( yes:SC2020 ) 
         DEC      !SCYSPD 
SC2040   EQU      $ 
         JMP      PLBGCK      ;auto scroll set
; 
;-------------------------------------------------
;-       JSR      SC10MV      ;up doude down !!  -
;-                                               -
;-------------------------------------------------
;K;SC10AD   EQU      $ 
;K;         HEX      FF,01 
;K;SC10MX   EQU      $ 
;K;         HEX      F8,08 
;K;SC10ST   EQU      $ 
;K;SC10S    HEX      7C,EF 
;K;SC11S    HEX      CF,EF 
; 
;;k;;SC10     EQU      (SC10S-SC10ST)/2+SC100
;;k;;SC11     EQU      (SC11S-SC10ST)/2+SC100
; 
;
SC10MV   EQU      $ 
         LDA      !SCTIME 
         BNE      SC1020      ;buru ? ( yes:SC1020 )
; 
         JSR      SCYCLC      ;Y move 
         LDA      <FRCNT 
         AND      #07H
         BNE      SC1010      ;X speed up ? ( no:SC1010 ) 
         LDY      !SCWK00 
         LDA      !SCYSPD 
         CMP      !SC10MX,Y 
         BEQ      SC1010      ;max speed ? ( yes:SC1010 ) 
         CLC
         ADC      !SC10AD,Y 
         STA      !SCYSPD 
SC1010   EQU      $ 
         LDA      !SCPTNO     ;(Y) <-- scroll data index
         ASL      A 
         ORA      !SCWK00 
         TAY
         LDA      !SCYPOSL
         CMP      !SC10ST,Y 
         BNE      SC1045      ;scroll stop ? ( no:SC1045 )
; 
         LDA      #00         ;Y move stop !! 
         STA      !SCYSPD 
         LDA      !SCWK00     ;muki EOR !!
         EOR      #01 
         STA      !SCWK00 
         BEQ      SC1015      ;sound set ? ( no:SC1015 )
; 
;<SOUND : SFX>         LDA      4F2H        ;[S]
;<SOUND : SFX>         ORA      #08H
;<SOUND : SFX>         STA      4F2H
;;S;;
        LDA     #9H
        STA     !SOUND3
; 
SC1015   EQU      $ 
         LDA      #20H        ;bulu timer 
         STA      !SCTIME 
SC1020   EQU      $ 
         AND      #01 
         EOR      !SCYPOSL
         STA      !SCYPOSL
SC1045   EQU      $ 
; 
;---------------------------------------------------
;-       JSR      PLBGCK      :player BG check     -
;---------------------------------------------------
PLBGCK   EQU      $ 
         LDA      #01H        ;BG check Y pos add data
         STA      !OBFLFG 
;                                             +--- foot point[80H]
         LDA      #81H        ;OBJ > BG bank set
;------- auto scroll set -------- 
ATSCST   EQU      $ 
         STA      !NMIRCF 
; 
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;%       Player hari check !!            %
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
HARICK   EQU    $ 
         LDA    #06H
         LDY    <JTIFLG
         BNE    HRCK10
         LDA    #12H
HRCK10   EQU    $ 
         ADC    <PLZPSL
         AND    #0F0H 
         STA    <WORK8 
; 
         LDA    <PLZPSH
         ADC    #00H
         AND    #01H
         STA    <WORK2 
; 
         LDA    <PLXPSL
         CLC
         ADC    #08H
         STA    <WORK9 
; 
         LDA    <PLXPSH
         ADC    #00H
; 
         ASL    A 
         TAY
         LDA    !RAMADR,Y 
         STA    <WORK0 
         LDA    !RAMADR+1,Y 
         CLC
         ADC    <WORK2 
         STA    <WORK1 
; 
         LDA    <WORK9 
         LSR    A 
         LSR    A 
         LSR    A 
         LSR    A 
         ORA    <WORK8 
         TAY
	 LDA	#BANK RABGDA0
	 STA	<WORK2
         LDA    [<WORK0],Y 
         STA    <WORK0 
; 
         LDY    !SEENFG 
         LDA    !KURAM,Y    :Kurage ? 
         CMP    <WORK0 
         BEQ    HRCK15
         LDA    !TOGEM,Y
         CMP    #0FFH 
         BEQ    HRCK90
         SEC
         SBC    <WORK0 
         CMP    #02H
         BCS    HRCK90       ;Toge ?
; 
HRCK15   EQU    $ 
         JSL    >PLAYAT     ; Yes !! Player Fail ! 
; 
HRCK90   EQU    $ 
         LDA      #81H        ;V only auto scroll "ON"
         STA      !SCRSTP 
         RTS
; 
;-------------------------------------------------
;-       JSR      SC30MV      ;water             -
;-                                               -
;-------------------------------------------------
;K;SC30MX   EQU      $ 
;K;         HEX      FC,04 
;K;SC30ST   EQU      $ 
;K;SC30S    HEX      C4,EA     ;;;;;9F,EA       ;water 
;K;SC31S    HEX      94,EA     ;;;;;32,9A
;K;SC32S    HEX      C4,EA     ;;;;;CF,EA
;K;SC33S    HEX      D4,EA     ;;;;;DF,EA
;K;SC3ES    HEX      90,EA       ;floer water
;K;SC3FS    HEX      B4,EA       ;muko 
;K;SC3GS    HEX      CF,EA       ; 
; 
;;k;;SC30     EQU      (SC30S-SC30ST)/2+SC300
;;k;;SC31     EQU      (SC31S-SC30ST)/2+SC300
;;k;;SC32     EQU      (SC32S-SC30ST)/2+SC300
;;k;;SC33     EQU      (SC33S-SC30ST)/2+SC300
;;k;;; 
;;k;;SC3E     EQU      (SC3ES-SC30ST)/2+SC300
;;k;;SC3F     EQU      (SC3FS-SC30ST)/2+SC300
;;k;;SC3G     EQU      (SC3GS-SC30ST)/2+SC300
;
;
SC30MV   EQU      $ 
         JSR      SCYCLC      ;Y move 
         LDA      <FRCNT 
         AND      #07H
         BNE      SC3010      ;X speed up ? ( no:SC3010 ) 
         LDY      !SCWK00 
         LDA      !SCYSPD 
         CMP      !SC30MX,Y 
         BEQ      SC3010      ;max speed ? ( yes:SC3010 ) 
         CLC
         ADC      !SC10AD,Y 
         STA      !SCYSPD 
SC3010   EQU      $ 
         LDA      !SCPTNO     ;(Y) <-- scroll data index
         ASL      A 
         ORA      !SCWK00 
         TAY
         LDA      !SCYPOSL
         CMP      !SC30ST,Y 
         BNE      SC3020      ;scroll stop ? ( no:SC3020 )
; 
         LDA      !SCWK00     ;muki EOR 
         EOR      #01 
         STA      !SCWK00 
SC3020   EQU      $ 
; 
;---------------------------------------------------
;-       player water in check                     -
;---------------------------------------------------
         LDA      !SCPTNO 
         CMP      #SC3E-SC300 
         BCC      SC3030      ;water check ? ( no:SC3030 )
         JMP      PLBGCK      ;player BG check
; 
PLWTCK   EQU      $ 
SC3030   EQU      $ 
;;;;;         LDA      #01H        ;BG > OBJ 
         LDY      #00H        ;BG > OBJ (3w-3,4w-2 nami auto scroll [new!!]) 
;;;NOM;;;		LDA	!MAPCOS		; water ? [NO:SC3040]
;;;NOM;;;		CMP	#007H
;;;NOM;;;		BNE	SC3040
;;;NOM;;;		LDA	>MAPXPH
;;;NOM;;;		BNE	SC3040
;;;NOM;;;;
;;;NOM;;;         LDY      #05H        ;BG > OBJ (8w nami auto scroll [new!!]) 
;;;NOM;;;SC3040   EQU      $ 
;;;NOM;;;	 TYA
	 LDA	  #000H
         JSR      ATSCST      ;auto scroll set
         LDA      !PYDSPH 
         BNE      PBC080      ;player display ? ( no:PBC080 ) 
; 
         TAY                  ;(Y) <-- 00 
         LDA      !SHAGFG 
         BNE      PBC070      ;player sit down ? ( yes:PBC070 ) 
         LDA      <JTIFLG
         BEQ      PBC070      ;player small ? ( no:PBC070 ) 
         INY
PBC070   EQU      $ 
         LDA      <PLYDSP
         CMP      !WTTRCY,Y 
         TAY
         ROR      A 
         CPY      #0A0H-20H 
         ROR      A 
         STA      !PTSWTR     ;flag "ON" !! ( **000001B ) 
PBC080   EQU      $ ;                          ^^
         RTS
; 
;-------------------------------------------------
;-       JSR      SC45MV      :test /45 scroll   -
;-                                               -
;-------------------------------------------------
SC45     EQU      SC450 
; 
;K;SC45XP   EQU      $-2 
;K;         HEX      70,D0 
;K;         HEX      60,C0 
;K;         HEX      90,30 
;K;         HEX      F0,00 
; 
SC45MV   EQU      $ 
         INC      !SCCNT2     ;move timming set !!
; 
         LDA      #00         ;move clear !!
         STA      !SCXSPD 
         STA      !SCMOVD 
         LDA      !SCWK01 
         CMP      #05 
         BCS      SC4555      ;move stop ? ( yes:SC4555 ) 
;
;******** SC45 BG3 SCROLL SET ********
	 MEM16
	 REP	  #00100000B	;memory 16bit mode
;
	 LDA	  !FRCNT2
	 AND	  #0003H
	 BNE 	  AAA
;
	 INC	  !SPSCH3
AAA	 EQU	  $
 	 LDA	  !FRCNT2
	 AND	  #0003H
	 BNE	  BBB
;
	 DEC	  !SPSCV3
BBB	 EQU	  $
	 MEM8
	 SEP	  #00100000B	;memory 8bit mode
;*************************************
; 
;
         LDA      #08H        ;move speed set ( /45 ) 
         STA      !SCXSPD 
         LDA      #0F8H 
         STA      !SCYSPD 
         LDA      !SCCNT2     ;move check dot set 
         LSR      A 
         BCC      SC4510      ;move ? ( no:SC4510 ) 
         INC      !SCMOVD 
SC4510   EQU      $ 
         LDA      !SC45WK 
         BNE      SC4530      ;normal scroll ? ( no:SC4530 )
; 
         BCC      SC4570      ;move ? ( no:SC4570 ) 
         INC      !SCXPOSL
         BNE      SC4520      ;(H) + ? ( no:SC4520 )
         INC      !SCXPOSH
SC4520   EQU      $ 
         LDA      !SCYPOSL
         BNE      SC4525      ;hosei move start ? ( no:SC4525 ) 
         INC      !SCWK01 
         BNE      SC4550      ;[ JMP SC4550 ] 
; 
SC4525   EQU      $ 
         DEC      !SCYPOSL
         BCS      SC4570      ;[ JMP SC4570 ] 
; 
SC4530   EQU      $ 
         LSR      A 
         LSR      A           ;(C) serve ( SC45FG: 1=0 , 2,3=1 )
         LDA      !SCWK01 
         ROL      A           ;(C) resive 
         TAY                  ;(Y) <-- move stop check data index 
         LDA      !SCXPOSL
         CLC
         ADC      #04H
         STA      !SCXPOSL
         BCC      SC4540      ;(H) + ? ( no:SC4540 )
         INC      !SCXPOSH
SC4540   EQU      $ 
         AND      #0F0H 
         CMP      !SC45XP,Y 
         BNE      SC4570      ;next point ? ( no:SC4570 ) 
         STA      !SCXPOSL
         LDA      #0EFH       ;down !!
         STA      !SCYPOSL
SC4550   EQU      $ 
         LDY      !SC45WK 
         INY
         CPY      #04 
         BCC      SC4560      ;normal move again ? ( no:SC4560 )
; 
SC4555   EQU      $ 
         LDY      #00 
SC4560   EQU      $ 
         STY      !SC45WK 
; 
SC4570   EQU      $ 
         JMP      PLSTCK      ;player stop check & etc
; 
;---------------------------------------------------------------------
;-       JSR      SCYCLC          :Y move                            -
;---------------------------------------------------------------------
SCYCLC   EQU      $ 
         LDX      #01         ;Y calc 
; 
SCRCLC   EQU    $ 
         LDA      !SCXSPD,X 
         ASL      A 
         ASL      A 
         ASL      A 
         ASL      A 
         CLC
         ADC      !SCXSDR,X   < Calc  New (x) position >
         STA      !SCXSDR,X 
         PHP
         PHP
; 
         LDY      #00H
         LDA      !SCXSPD,X 
         LSR      A 
         LSR      A 
         LSR      A 
         LSR      A 
         CMP      #08H
         BCC      CALX60
; 
         ORA      #11110000B
         DEY
CALX60   EQU      $ 
         PLP
         PHA
         ADC      !SCXPOSL,X
         STA      !SCXPOSL,X
; 
         TYA
         ADC      !SCXPOSH,X
         STA      !SCXPOSH,X
; 
         PLA
         PLP
         ADC      #00H
         STA      !SCMOVD 
         RTS
; 
		END
