;=================== the source code for SNES/SFC Myth Cart menu v0.09 ===================
;===================             Copy right by: Neo TeAm               ===================
;===================        www.NEOFLASH.com / Feb.22th 2010           ===================

; WLA-DX version

 .INCLUDE "myth_header.asm"
 .INCLUDE "snes_io.inc"
 .INCLUDE "myth_io.inc"
 .INCLUDE "myth_macros.inc"
 
 
 .EQU XY_8BIT $10
 .EQU A_8BIT  $20
 .EQU ALL_8BIT $30
 
 
 .EQU ITEM          $00
 .EQU MY            $01
 .EQU MX            $02
 .EQU TP            $03         ;3,4
 .EQU TPP           $04         ;3,4
 .EQU A1L           $05
 .EQU A1H           $06
 .EQU JOY1          $07
 .EQU JOYA          $08
 .EQU T_PAGE        $09
 .EQU PAGE          $0A
 .EQU G_STA1        $0B
 .EQU POINT         $0C
 .EQU COLOR         $0D
 .EQU COUNT         $0E
 .EQU GO            $0F

 .EQU MYTH         $10
 .EQU LEX          $11
 .EQU M1L          $12
 .EQU M1H          $13
 .EQU M2L          $14
 .EQU M2H          $15
 
 .EQU M3L          $16
 .EQU M3H          $17

 .EQU RUX          $20 ;0
 .EQU RBH          $21 ;2
 .EQU RBL          $22 ;1
 .EQU RZX          $23 ;3
 .EQU SBX          $24 ;4
 .EQU SZX          $25 ;5
 .EQU MODE         $26 ;6
 .EQU RSZ          $27 ;1
 .EQU EDSP         $28 ;1
 .EQU ESRAM        $29 ;1
 .EQU SRAM_M       $2A ;1    ;NEW
 .EQU CARD_M       $2B ;1    ;NEW
 .EQU PMENU        $2C ;1    ;NEW
 .EQU MOV          $2F ;6

 .EQU AA           $30 ;6
 .EQU AP0          $31 ;6
 .EQU AP1          $32 ;6
 .EQU RAP0         $33 ;6
 .EQU WAP0         $34 ;6
 .EQU RAP1         $35 ;6
 .EQU WAP1         $36 ;6
 .EQU WAZ0         $37 ;6
 .EQU WAZ1         $38 ;6
 .EQU WAZ2         $39 ;6
 .EQU CPID         $3F ;6

 .EQU TERR      $40 ;6
 
 .EQU GAMEFIRSTSHOWN 	$41
 .EQU GAMEHIGHLIGHTED 	$43
 .EQU GAMEPRINT		$45
 
 .EQU BANK      $8000

 
 .MACRO CPU_REGS16
 	REP	#ALL_8BIT
 .ENDM
 
 
 .MACRO CPU_REGS8
 	SEP	#ALL_8BIT
 .ENDM
 
 
 .MACRO CPU_ACC16
 	REP 	#A_8BIT
 .ENDM
 
 
 .MACRO CPU_ACC8
 	SEP	#A_8BIT
 .ENDM
 
 
 .MACRO CPU_XY16
 	REP	#XY_8BIT
 .ENDM
 
 
 .MACRO CPU_XY8
 	SEP	#XY_8BIT
 .ENDM
 
 
 .MACRO WAIT_VSYNC
 	-:
         LDA.L   REG_RDNMI
         STA     AA
         BIT     AA
         BMI     -
 	-:
         LDA.L   REG_RDNMI
         STA     AA
         BIT     AA
         BPL     -
 .ENDM



 .BANK 1 SLOT 0

 .ORG $0000 
Start:
         JMP.L   START

        .ORG    $0010      ;MYTH
;...............................................................................
MS2
        .DB     $FF,14,01,02
        .DB   	" LOADING......(  )"
        .DB     0

        .ORG    $0035      ;MYTH
;===============================================================================
; Copy 1 Mbit of data from the GBA Card to PSRAM
;
; DBR is set to the source bank ($4x) so that word addressing can be used
; when reading data from the GBA Card, thus saving 1 cycle per read.
;
; Then 512 kb (64 kB) are copied at 16 bytes per iteration. The destination bank
; is then incremented by overwriting parts of the code, and then another 512 kb
; are copied.
MOV_1M:
    	CPU_ACC8
    	CPU_XY16
    	PHB        	   ; Save DBR
    	LDA   	RAP0
	LDY	#2	   ; Copy 2 * 512 kbit	
MOV_512K:	
    	PHA
    	PLB        	   ; Set DBR

    	CPU_REGS16         ; A,16 & X,Y 16 BIT
    	LDX     #$1FFE
-:
    	LDA.W   $0000,X    ; READ GBA CARD
    	STA.L   $500000,X  ; WRITE PSRAM ;+17
    	LDA.W   $2000,X    ; READ GBA CARD
    	STA.L   $502000,X  ; WRITE PSRAM 
    	LDA.W   $4000,X    ; ...
    	STA.L   $504000,X 
    	LDA.W   $6000,X   
    	STA.L   $506000,X 
    	LDA.W   $8000,X   
    	STA.L   $508000,X 
    	LDA.W   $A000,X    
    	STA.L   $50A000,X 
    	LDA.W   $C000,X   
    	STA.L   $50C000,X  
    	LDA.W   $E000,X   
    	STA.L   $50E000,X  
    	DEX
    	DEX
    	BPL     -

	DEY
	BEQ	+
	CPU_ACC8
	LDA	WAP1
	STA.L	$7E8035+$17	; Increase the MSB of all the addresses above of the form $5xxxxx
	STA.L	$7E8035+$1E	; ...
	STA.L	$7E8035+$25
	STA.L	$7E8035+$2C
	STA.L	$7E8035+$33
	STA.L	$7E8035+$3A
	STA.L	$7E8035+$41
	STA.L	$7E8035+$48
	
	; Increase DBR
	PHB
	PLA
	INA
	BRA	MOV_512K
+:	
    	PLB        	   ; Restore DBR
    	CPU_REGS8
    	RTS

;...............................................................................
        .ORG    $00F0        ;MYTH
MS4
        .DB     $FF,19,01,02
        .DB   	" GAME (001)"
        .DB     0
;===============================================================================


;===============================================================================
; print card name
        .ORG    $0100        ;MYTH
MS3:
        .DB     $FF,12,01,02
        .DB     "                        "
        .DB     0
        
;===============================================================================
        .ORG    $0180        ;MYTH

TEST_CARD:

         LDA     #30
         JSR     PRINT

         LDA     #$20      ; OFF A21
         STA.L   MYTH_GBAC_ZIO
 
         JSR     SET_NEOCMC  ; ON_NEO CARD A24 & A25 + SA16 & SA17

         LDA     #$20      ; OFF A21
         STA.L   MYTH_GBAC_ZIO

         LDA     #$00
         STA.L   MYTH_GBAC_ZIO   ; SET A16~A23
         STA.L   MYTH_GBAC_HIO   ; SET A24,A25

         LDA     #$01
         STA.L   MYTH_EXTM_ON   ; A25,A24 ON

         LDA     #$04
         STA.L   MYTH_SRAM_TYPE  ; SET SRAM SAVE TYPE
         LDA     #$0F
         STA.L   MYTH_SRAM_MAP  ; SET $700000

         LDA     #$01
         STA.L   MYTH_SRAM_WE  ; SRAM ON !

         LDA     #$00
         STA.L   $700000
         LDA     #$01
         STA.L   $720000
         LDA     #$02
         STA.L   $740000
         LDA     #$03
         STA.L   $760000
         
         LDA.L   $700000
         CMP     #$00
         BNE     PSRAM_SETUP
         LDA.L   $720000
         CMP     #$01
         BNE     PSRAM_SETUP
         LDA.L   $740000
         CMP     #$02
         BNE     PSRAM_SETUP
         LDA.L   $760000
         CMP     #$03
         BNE     PSRAM_SETUP
         LDA     #$00
         LDA     #28
         JSR     PRINT
         
PSRAM_SETUP:
         STA.L  MYTH_SRAM_TYPE  ; SET SRAM SAVE TYPE
         STA.L  MYTH_SRAM_MAP  ; SET $000000
         STA.L  MYTH_SRAM_WE  ; SRAM ON !
;------------------------------------------------------------------------------
         LDA    #$04       ; COPY MODE !
         STA.L  MYTH_OPTION_IO

         LDA    #$01       ; PSRAM WE ON !
         STA.L  MYTH_WE_IO

         LDA    #$F8
         STA.L  MYTH_PRAM_ZIO     ;PSRAM    8M SIZE
;-------------------------------------------------------------------------------
         LDA    #$00       ;PSRAM   BANK
         STA.L  MYTH_PRAM_BIO
         STA.L  $500000
         STA.L  $500001

         LDA    #$01       ;PSRAM   BANK
         STA.L  MYTH_PRAM_BIO
         STA.L  $500000
         STA.L  $500001

         LDA    #$02       ;PSRAM   BANK
         STA.L  MYTH_PRAM_BIO
         STA.L  $500000
         STA.L  $500001

         LDA    #$03       ;PSRAM   BANK
         STA.L  MYTH_PRAM_BIO
         STA.L  $500000
         STA.L  $500001

         LDA    #$04       ;PSRAM   BANK
         STA.L  MYTH_PRAM_BIO
         STA.L  $500000
         STA.L  $500001

         LDA    #$05       ;PSRAM   BANK
         STA.L  MYTH_PRAM_BIO
         STA.L  $500000
         STA.L  $500001

         LDA    #$06       ;PSRAM   BANK
         STA.L  MYTH_PRAM_BIO
         STA.L  $500000
         STA.L  $500001

         LDA    #$07       ;PSRAM   BANK
         STA.L  MYTH_PRAM_BIO
         STA.L  $500000
         STA.L  $500001
;-------------------------------------------------------------------------------

         LDA    #$00       ;PSRAM   BANK
         STA.L  MYTH_PRAM_BIO
         LDA.L  $500000
         CMP    #$00
         BNE    TS_ERR

         LDA    #$01       ;PSRAM   BANK
         STA.L  MYTH_PRAM_BIO
         LDA.L  $500000
         CMP    #$01
         BNE    TS_ERR

         LDA    #$02       ;PSRAM   BANK
         STA.L  MYTH_PRAM_BIO
         LDA.L  $500000
         CMP    #$02
         BNE    TS_ERR
         JMP    PSRAM_VERIFY
TS_ERR:
         LDA    #32
         JSR    PRINT
         JMP    +
TS_OK:
         LDA    #31
         JSR    PRINT
+:
         LDA    #$00       ;
         STA.L  MYTH_OPTION_IO
         JMP    MENU1
;-------------------------------------------------------------------------------
PSRAM_VERIFY:

 	VERIFY_PSRAM 0
 	VERIFY_PSRAM 1
 	VERIFY_PSRAM 2
 	VERIFY_PSRAM 3
 	VERIFY_PSRAM 4
 	VERIFY_PSRAM 5
 	VERIFY_PSRAM 6
 	VERIFY_PSRAM 7
     
        JMP     TS_OK
;------------------------------------------------------------------------------
TEST_PARMA0:

        LDA     #$00
        STA     TERR
        
        REP     #$30        ; A,16 & X,Y 16 BIT

	MOV_BOOT_TO_SRAM 0
	MOV_BOOT_TO_SRAM 1
	MOV_BOOT_TO_SRAM 2
	MOV_BOOT_TO_SRAM 3
	MOV_BOOT_TO_SRAM 4
	MOV_BOOT_TO_SRAM 5
	MOV_BOOT_TO_SRAM 6
	MOV_BOOT_TO_SRAM 7
	MOV_BOOT_TO_SRAM 8
	MOV_BOOT_TO_SRAM 9
	MOV_BOOT_TO_SRAM 10
	MOV_BOOT_TO_SRAM 11
	MOV_BOOT_TO_SRAM 12
	MOV_BOOT_TO_SRAM 13
	MOV_BOOT_TO_SRAM 14
	MOV_BOOT_TO_SRAM 15
	
;-------------------------------------------------------------------------------
        SEP     #$30
        RTS
MOV_BOOT_TO_SRAM_BREAK_LAST:
        SEP     #$30
        LDA     #$01
        STA     TERR
        RTS
        
;===============================================================================
SET_NEOCM5:
         LDA    #$E0      	; SET BANK   ;1 1 1 0
         STA.L  MYTH_GBAC_LIO
         LDA.L  $FFA400  	; FFD2XX     ;01

         LDA    #$00      	; SET BANK   ; 0 0 0
         STA.L  MYTH_GBAC_LIO
         LDA.L  $C02A00  	; 0015XX     ;02
         LDA.L  $C3A400  	; 01D2XX     ;03
         LDA.L  $C42A00  	; 0215XX     ;04

         LDA    #$E0      	; SET BANK   ;1 1 1 0
         STA.L  MYTH_GBAC_LIO
         LDA.L  $FC2A00  	; FE15XX     ;05
         RTS
;===============================================================================
SET_NEOCMA:
         JSR    SET_NEOCM5
         LDA    #$20      	; SET BANK   ;0 0 1 0
         STA.L  MYTH_GBAC_LIO
         LDA.L  $EE2406  	; 372203     ;06   ;
         RTS
;===============================================================================
SET_NEOCMB:
         JSR    SET_NEOCM5

         LDA    CARD_M
         CMP    #$00
         BEQ    A_CARD
         CMP    #$01
         BEQ    B_CARD
         JMP    C_CARD
;-------------------------------------------------------------------------------
A_CARD:
         LDA    #$C0      	; SET    ;1 1 0 0
         STA.L  MYTH_GBAC_LIO
         LDA.L  $F55C88  	; DAAE44     ;06
         RTS
;-------------------------------------------------------------------------------
B_CARD:
         LDA    #$C0      	; SET    ;1 1 0 0
         STA.L  MYTH_GBAC_LIO
         LDA.L  $F51C88  	; DA8E44     ;06
         RTS
;-------------------------------------------------------------------------------
C_CARD:
         LDA    #$C0      	; SET    ;1 1 0 0
         STA.L  MYTH_GBAC_LIO
         LDA.L  $F41C88  	; DA0E44     ;06
         RTS
;===============================================================================
SET_NEOCMC:
         JSR    SET_NEOCM5

         LDA    #$E0      	; SET        ;1 1 1 0
         STA.L  MYTH_GBAC_LIO
         LDA.L  $DC0C60  	; EE0630     ;06
         RTS
;===============================================================================
SET_NEOCMD:

         JSR    SET_NEOCM5
         LDA    #$20      	; SET BANK   ;0 0 1 0
         STA.L  MYTH_GBAC_LIO
         LDA.L  $EE2006  	; 372003     ;06   ;  TO BIOS MENU

         JSR    SET_NEOCM5
         LDA    #$C0      	; SET        ;1 1 0 0
         STA.L  MYTH_GBAC_LIO
         LDA.L  $F50088  	; DA0044     ;06
         RTS
;===============================================================================
;
;===============================================================================

BOOT_RUN:

         LDA    #$20      	; OFF A21
         STA.L  MYTH_GBAC_ZIO
         JSR    SET_NEOCMA  	;
         JSR    SET_NEOCMB  	;
         JSR    SET_NEOCMC  	; ON_NEO CARD A24 & A25 + SA16 & SA17

         LDA     RBH
         STA.L   MYTH_GBAC_HIO	; SET AH25,AH25
         
         LDA     #$01
         STA.L   MYTH_EXTM_ON   ; A25,A24 ON


; MOVE   PSRAM
MOV_4M:

	;                    4M    4M    4M  4M~8M
	MOV_PSRAM_SETUP $04, $3C, $3035, $04, $00
	;                    8M    8M    8M  4M~8M
	MOV_PSRAM_SETUP $08, $38, $3039, $08, $00
	;                    16M   16M   8M   16M
	MOV_PSRAM_SETUP $09, $30, $3137, $08, $01
	;                    32M   24M   8M   24M
	MOV_PSRAM_SETUP $0A, $20, $3235, $08, $02
	;                    32M   32M   8M   32M
	MOV_PSRAM_SETUP $0B, $20, $3333, $08, $03
	;                    64M   40M   8M   40M
	MOV_PSRAM_SETUP $0C, $00, $3431, $08, $04
	;                    64M   48M   8M   48M
	MOV_PSRAM_SETUP $0D, $00, $3439, $08, $05
	;                    64M   64M   8M   64M
	MOV_PSRAM_SETUP $0E, $00, $3635, $08, $07

         
;===============================================================================
MOV_PSRAM:

         LDA    #$00
         STA    WAZ2
             
         LDA    #$04       	; COPY MODE !
         STA.L  MYTH_OPTION_IO

         LDA    #$01       	; PSRAM WE ON !
         STA.L  MYTH_WE_IO
                         
         LDA    #$F8
         STA.L  MYTH_GBAC_ZIO  	; GBA CARD 8M SIZE
         STA.L  MYTH_PRAM_ZIO  	; PSRAM    8M SIZE

         LDA    RBL
         STA.L  MYTH_GBAC_LIO
         
         LDA    #$00
         STA.L  MYTH_PRAM_BIO

MOV_PSRAM_LOOP:
         LDA    #$3E
         STA    RAP0
         LDA    #$4E
         STA    WAP0
         
         LDA    #$3F
         STA    RAP1
         
         LDA    #$4F
         STA    WAP1
         
-:
         INC    RAP0
         ;INC    RAP1
         INC    WAP0
         INC    WAP1
         
         INC    RAP0
         ;INC    RAP1
         INC    WAP0
         INC    WAP1

         LDA    WAP0
	 STA.L	$7E8035+$17
	 STA.L	$7E8035+$1E
	 STA.L	$7E8035+$25
	 STA.L	$7E8035+$2C
	 STA.L	$7E8035+$33
	 STA.L	$7E8035+$3A
	 STA.L	$7E8035+$41
	 STA.L	$7E8035+$48
	
         DEC    AP0
         LDA    AP0        ; L-BYTE
         STA.L  $7E8024
         LDA    AP1        ; H-BYTE
         STA.L  $7E8023   ;
         
         LDA    #$02
         JSR    PRINT
         
         JSR    MOV_1M
         LDA    AP0
         CMP    #$30
         BNE    +
         LDA    #$3A
         STA    AP0
         DEC    AP1  ;
+:
         DEC    WAZ0
         LDA    WAZ0
         CMP    #$00
         BNE    -
         
         LDX    WAZ1
         CPX    WAZ2
         BNE    MOV_PSRAM_1
         JMP    MOV_PSRAM_DONE
MOV_PSRAM_1:
;===============================================================================
         INC    WAZ2
         LDA    WAZ2
         CMP    #$01
         BNE    +
         
         LDA    #$01        ;16M
         STA.L  MYTH_PRAM_BIO

         CLC
         LDA    #$08
         ADC    RBL
         STA    RBL
         STA.L  MYTH_GBAC_LIO
         
         LDA    #$8
         STA    WAZ0      ;
         JMP    MOV_PSRAM_LOOP
;-------------------------------------------------------------------------------
+:       CMP    #$02        ;24M
         BNE    +
         LDA    #$02
         STA.L  MYTH_PRAM_BIO

         CLC
         LDA    #$08
         ADC    RBL
         STA    RBL
         STA.L  MYTH_GBAC_LIO
         
         LDA    #$8
         STA    WAZ0
         JMP    MOV_PSRAM_LOOP
;-------------------------------------------------------------------------------
+:       CMP    #$03        ;32M
         BNE    +
         LDA    #$03
         STA.L  MYTH_PRAM_BIO
         
         CLC
         LDA    #$08
         ADC    RBL
         STA    RBL
         STA.L  MYTH_GBAC_LIO
         
         LDA    #$8
         STA    WAZ0      ;
         JMP    MOV_PSRAM_LOOP
;-------------------------------------------------------------------------------
+:       CMP    #$04        ;40M
         BNE    +
         LDA    #$04
         STA.L  MYTH_PRAM_BIO

         CLC
         LDA    #$08
         ADC    RBL
         STA    RBL
         STA.L  MYTH_GBAC_LIO
         
         
         LDA    #$8
         STA    WAZ0      ;
         JMP    MOV_PSRAM_LOOP
;-------------------------------------------------------------------------------
+:       CMP    #$05        ;48M
         BNE    +
         LDA    #$05
         STA.L  MYTH_PRAM_BIO
         
         CLC
         LDA    #$08
         ADC    RBL
         STA    RBL
         STA.L  MYTH_GBAC_LIO
         
         LDA    #$8
         STA    WAZ0      ;
         JMP    MOV_PSRAM_LOOP
;-------------------------------------------------------------------------------
+:       CMP    #$06        ;56M
         BNE    +
         LDA    #$06
         STA.L  MYTH_PRAM_BIO
         
         CLC
         LDA    #$08
         ADC    RBL
         STA    RBL
         STA.L  MYTH_GBAC_LIO
         
         LDA    #$8
         STA    WAZ0      ;
         JMP    MOV_PSRAM_LOOP
;-------------------------------------------------------------------------------
+:       CMP    #$07        ;64M
         BNE    MOV_PSRAM_DONE
         LDA    #$07
         STA.L  MYTH_PRAM_BIO
         
         CLC
         LDA    #$08
         ADC    RBL
         STA    RBL
         STA.L  MYTH_GBAC_LIO
         
         LDA    #$8
         STA    WAZ0      ;
         JMP    MOV_PSRAM_LOOP
MOV_PSRAM_DONE:
;===============================================================================
         LDA     #$00       ;
         STA.L   MYTH_WE_IO     ; PSRAM WRITE OFF
;-------------------------------------------------------------------------------
;neo gba card menu ,swap back to power on mode

         LDA     #$00       	; SET GBA CARD RUN
         STA.L   MYTH_OPTION_IO

         LDA     #$20       	; OFF A21
         STA.L   MYTH_GBAC_ZIO
         JSR     SET_NEOCMD	; SET MENU

         LDA     #$00
         STA.L   MYTH_GBAC_LIO
         STA.L   MYTH_GBAC_HIO
         STA.L   MYTH_GBAC_ZIO
;-------------------------------------------------------------------------------
;SET  SNES PSARM RUN
         LDA     #$01       	; SET PSRAM RUN
         STA.L   MYTH_OPTION_IO

         LDA     #$00
         STA.L   MYTH_PRAM_BIO
        
         LDA     RSZ
         STA.L   MYTH_PRAM_ZIO

         LDA     SBX
         LDA     #$00
         STA.L   MYTH_GBAS_BIO
;===============================================================================
;SET  GAME SAVE  SIZE & BANK
         LDA     SZX
         CMP     #$00
         BNE     MAP_SRAM
         CMP     #$00
         STA.L   MYTH_SRAM_TYPE ;  OFF SRAM TYPE
         JMP     SET_EXT_DSP
;-------------------------------------------------------------------------------
MAP_SRAM:
         LDA     SRAM_M

 	MAP_SRAM_CHECK $01, $02
 	MAP_SRAM_CHECK $08, $03
 	MAP_SRAM_CHECK $07, $07
 	MAP_SRAM_CHECK $06, $07
 	MAP_SRAM_CHECK $05, $0F
 	MAP_SRAM_CHECK $04, $0F
 	
MAP_SRAM_DONE:
         LDA     #$01
         STA.L   MYTH_SRAM_WE    ; GBA SRAM WE ON !
;-------------------------------------------------------------------------------
;SET SAVE SRAM BANK

         LDA     SZX
         CMP     #$01
         BNE     +
         LDA     #$FF    ;2K  SIZE
         STA.L   MYTH_GBAS_ZIO
         
         LDA     SBX
         ASL     A
         ASL     A
         AND     #$FC
         STA.L   MYTH_GBAS_BIO
         JMP     SET_EXT_DSP

+:
         CMP     #$02
         BNE     +
         LDA     #$FC    ;8K   SIZE
         STA.L   MYTH_GBAS_ZIO
         
         LDA     SBX
         ASL     A
         ASL     A
         AND     #$FC
         STA.L   MYTH_GBAS_BIO
         STA.L   MYTH_GBAS_BIO
         JMP     SET_EXT_DSP
         
+:
         CMP     #$03
         BNE     +
         LDA     #$F0    ;32K  SIZE
         STA.L   MYTH_GBAS_ZIO

         LDA     SBX
         ASL     A
         ASL     A
         ASL     A
         ASL     A
         AND     #$F0
         STA.L   MYTH_GBAS_BIO
         JMP     SET_EXT_DSP
;-------------------------------------------------------------------------------
+:
         CMP     #$04
         BNE     +
         LDA     #$E0    ;64K SIZE
         STA.L   MYTH_GBAS_ZIO

         LDA     SBX
         ASL     A
         ASL     A
         ASL     A
         ASL     A
         ASL     A
         AND     #$F0
         STA.L   MYTH_GBAS_BIO
         JMP     SET_EXT_DSP
;-------------------------------------------------------------------------------
+:
         CMP     #$05
         BNE     +
         LDA     #$C0    ;128K SIZE
         STA.L   MYTH_GBAS_ZIO

         LDA     SBX
         ASL     A
         ASL     A
         ASL     A
         ASL     A
         ASL     A
         ASL     A
         AND     #$C0
         STA.L   MYTH_GBAS_BIO
         JMP     SET_EXT_DSP
+:
         JMP    MENU
;-------------------------------------------------------------------------------
;SET EXIT DSP
SET_EXT_DSP:

         LDA     EDSP
         CMP     #$00
         BNE     +
         STA.L   MYTH_DSP_TYPE
         LDA     #$00
         STA.L   MYTH_DSP_MAP
         JMP     MAP_DSP_DONE
;-------------------------------------------------------------------------------
+:
         LDA     EDSP
         CMP     #$01
         BNE     +
         STA.L   MYTH_DSP_TYPE
         LDA     #$00
         STA.L   MYTH_DSP_MAP
         JMP     MAP_DSP_DONE
;-------------------------------------------------------------------------------
+:
         CMP     #$03
         BNE     +
         STA.L   MYTH_DSP_TYPE   ;EXT DSP
         LDA     RZX
         CMP     #$04     ;4M ROM
         BNE     +
         LDA     #$03     ;$300000
         STA.L   MYTH_DSP_MAP
         JMP     MAP_DSP_DONE
;-------------------------------------------------------------------------------
+:
         LDA     #$03
         STA.L   MYTH_DSP_TYPE  ;EXT DSP
         LDA     #$06    ;$600000
         STA.L   MYTH_DSP_MAP
         JMP     MAP_DSP_DONE
         
;-------------------------------------------------------------------------------
;-------------------------------------------------------------------------------
MAP_DSP_DONE:
         LDA     ESRAM
         CMP     #$07    ;
         BNE     +      ;
         LDA     #$06    ;
         STA.L   MYTH_OPTION_IO  ;
         LDA     #$C0    ;
         STA.L   $C01F  ;
+:

         LDA     RUX
         STA.L   MYTH_RUN_IO
RUN_M01:
         JMP     RUN_3800     ; FOR EXIT RAM
 ;       JMP     RUN_RAM      ; FOR SNES RAM

;===============================================================================
RUN_RAM:
        LDA     #$01                 ;
        STA.L   MYTH_RST_SEL         ;
        LDA     #$FF                 ;
        STA.L   MYTH_RST_IO          ; LOCK BIT

        LDA     #$0   ;#$00 0000     ;MYTH
        PHA                          ;
        PLB

        LDX     #$00                 ;0  MOVE BOOT CODE TO SRAM
-:      LDA.L   RAM_R01+$7E0000,X   ;
        STA.L   $7F2000,X           ;
        INX
        BNE     -                   ;
        JMP.L   $7F2000

RAM_R01:
        CPU_REGS16       ; A,8 & X,Y 16 BIT
        LDX     #$0000
-:
        LDA     #$0000      ;
        STA.L   $7E0000,X  ; clean RAM
        INX
        INX
        BNE     -
        CPU_REGS8

                   
        LDA     #$00                
        STA.L   REG_DISPCNT
        STA.L   REG_MDMAEN
        STA.L   REG_HDMAEN
        STA.L   REG_NMI_TIMEN
        
        SEI
        SEC
        XCE              ;SET 65C02 MODE
        
        LDA     #$5C
        STA.L   $7F2800
        
        LDA.L   $00FFFC
        STA.L   $7F2801
        
        LDA.L   $00FFFD
        STA.L   $7F2802
        
        LDA     #$00
        STA.L   $7F2803
        
        JMP.L   $7F2800
        
;===============================================================================
;  RUN CPLD RAM
;===============================================================================

OFF_3800_RAM_IO:
        LDA     #$57
        STA.L   MYTH_CPLD_RIO
        LDA     #$63
        STA.L   MYTH_CPLD_RIO
        LDA     #$FF
        STA.L   MYTH_CPLD_RIO
        RTS

RUN_3800:

        LDA     #$01                 ;
        STA.L   $C00E                ; HARD REST IO

        LDA     #$01                 ;
        STA.L   $C012                ; CPLD RAM ON
        STA.L   $C015                ; CPLD RAM ON
              
        LDA     #$FF                 ; RUN
        STA.L   MYTH_RST_IO          ; RUN
        
;       JSR     OFF_3800_RAM_IO
                                             
        LDA     #$0   ;#$00 0000     ;MYTH
        PHA                          ;
        PLB
         
        LDX     #$00                 ;0  MOVE BOOT CODE TO SRAM
-:      LDA.L   CPLD_RAM+$7E0000,X  ;0
        STA.L   $3800,X             ;0  CPLD SRAM
        INX
        BNE     -                   ;0

        LDX     #$00                 ;0  MOVE CHEAT CODE TO SRAM
-:      LDA.L   CHEAT+$7E0000,X     ;0
        STA.L   $3E00,X             ;0  CPLD SRAM
        INX
        BNE     -                   ;0

        
        JMP.L   $003800
;===============================================================================
; EXIT RAM  $003800~003FFF
;===============================================================================
CPLD_RAM:
        CPU_REGS16        ; A,8 & X,Y 16 BIT
        LDX     #$0000
-:
        LDA     #$0000      ; READ GBA CARD
        STA.L   $7E0000,X  ; CLERA SRAM
        INX
        INX
        BNE     -
        CPU_REGS8

        LDA     #$00                 ;
        STA.L   REG_DISPCNT
        STA.L   REG_MDMAEN
        STA.L   REG_HDMAEN
        STA.L   REG_NMI_TIMEN
        SEI
        SEC
        XCE              ;SET 65C02 MODE
        JMP     ($FFFC)

CHEAT:
        LDA   #$63
        STA.L $7EFA91
        
        LDA   #$01
-:
        BIT   $4012
        BNE   -
        RTL
;===============================================================================
RUN_CARD:

        JSR     CLRSCR
        LDA     #$01
        STA.L   $C017
        
        LDA     #$05            ;
        STA.L   MYTH_OPTION_IO

        LDX     #$00         	;0  MOVE BOOT CODE TO SRAM
-:      LDA.L   $00FFC0,X    	;0
        STA.L   $7E8104,X    	;0  CPLD SRAM
        INX
        CPX     #$14
        BNE     -               ;0
        
        LDA     #3
        JSR     PRINT           ; PRINT CARD NAME !

-:
        JSR     KEY
        LDA     JOYA
        CMP     #$80
        BEQ     B_PRESSED     	;B

        CMP     #$40
        BEQ     Y_PRESSED     	;Y
        
        JMP      -

Y_PRESSED:
        LDA     #$00
        STA.L   $C017
        
        LDA     #$05                 ;
        STA.L   MYTH_OPTION_IO
        JMP     RUN_M01


B_PRESSED:
        LDA     #$00
        STA.L   $C017
        
        LDA     #$00           	;
        STA.L   MYTH_OPTION_IO
        JMP     MENU
        
START:
        SEI
        CLC
        XCE      		;SET 65C816 MODE
        LDA      #$00
        STA      MYTH
        STA      LEX
        STA      GO
        STA      COLOR

	STA	GAMEFIRSTSHOWN
	STA	GAMEHIGHLIGHTED
	STA	GAMEPRINT
	STA	GAMEPRINT+1
	
        LDA     #$7E        	;#$7E 00 00   ;
        PHA
        PLB
;-------------------------------------------------------------------------------
        LDA     #$00
        STA.L   $00C040  	;W0X00 FOR CPLD ROM
        LDA.L   $00FFE1
        CMP     #$63
        BNE     +
        LDA.L   $00FFE2
        CMP     #$57
        BNE     +
        LDA.L   $00FFE0
        STA     CPID    	; CPLD VER
+:
        LDA     #$01
        STA.L   $00C040  	;W0X01 FOR GBA CARD MENU
        
        LDA.L   $00FFF0
        STA     CARD_M  	; read neo card mode "00=A,01=B,02,C"
;===============================================================================
;MOVE MENU TO SNES RAM
        CPU_XY16        	; A,8 & X,Y 16 BIT
        LDX     #$8000      	;0  MOVE BOOT CODE TO SRAM
-:      LDA.L  $000000,X  	;
        STA.L  $7E0000,X  	;
        INX
        BNE     -          	;
        CPU_XY8      		; A,8  BIT

        JMP.L     SXXXX+$7E0000

SXXXX:
        JSR     V_SET
        LDA     #$1
        STA.L   REG_NMI_TIMEN
        SEI
        LDX     #$FF
        TXS

testBOOT_RUN:

MENU:
        LDA     #$00    ;$C800
        STA     M1L
        STA     M2L
        STA     M3L
        LDA     #$C8    ;$C800
        STA     M1H
        STA     M2H
        STA     M3H

        JSR     CLRSCR
        LDA     #$00
        JSR     PRINT
        
        LDA     CARD_M     ; TEST CARD B
        CMP     #$01
        BNE     +
        LDA     #5
        JSR     PRINT
+:
        LDA     CARD_M     ; TEST CARD C
        CMP     #$02
        BNE     +
        LDA     #6
        JSR     PRINT
+:
        LDA     CPID       ; HARD ID
        CMP     #$01
        BNE     +
        LDA     #9
        JSR     PRINT
+:

        LDA     #$04
        JSR     PRINT
        LDA	GAMEFIRSTSHOWN
        STA	GAMEPRINT
;PRINTGAMES:
        JSR     PRINTX
;	INC	GAMEPRINT
;	LDA	GAMEPRINT
;	CMP	#8
;	BNE	PRINTGAMES
	
	LDA	#0
	STA	GAMEPRINT
	
MENU1:
        JSR     KEY

        LDA     JOYA
        CMP     #$08
        BEQ     MENU_UP          ;UU
        CMP     #$04
        BEQ     MENU_DOWN        ;DD
        CMP     #$02
        BEQ     MENU_LEFTRIGHT   ;LL
        CMP     #$01
        BEQ     MENU_LEFTRIGHT   ;RR
        CMP     #$80
        BEQ     MENU_B          ;B
        CMP     #$40
        BEQ     MENU_Y         ;Y
        CMP     #$10
        BEQ     MENU_START  ;Start
        JMP     MENU1

MENU_START:
        JMP     TEST_CARD
        
MENU_Y

        JMP     RUN_CARD

MENU_UP:
	JMP     UP_A
MENU_DOWN:
	JMP     DOWN_A

MENU_B: JMP     RUN_A

MENU_LEFTRIGHT:	; D-pad left or right (not shoulder buttons)
        JMP     MENU1
;===============================================================================
UP_A:

        LDA     M1H
        CMP     #$C8
        BNE     +
        LDA     M1L
        CMP     #$00
        BNE     +
        JMP     MENU1
+:
        JSR     SUB_M
        JMP     MENU1
;===============================================================================
DOWN_A:
        JSR     INX_M
        JMP     MENU1
;===============================================================================
RUN_A:        
         JMP     BOOT_RUN
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

STR:    .DW     MS0,MS1,MS2,MS3,MS4,MS5,MS6,MS7,MS8,MS9,MS10,MS11,MS12,MS13,MS14,MS15
        .DW     MS16,MS17,MS18,MS19,MS20,MS21,MS22,MS23,MS24,MS25,MS26,MS27,MS28,MS29
        .DW     MS30,MS31,MS32
MS1:
        .DB     $FF,1,$FE,15,10,
        .DB     $68,$69,$6A,$20,$71,$72,$73,$20,$7A,$7B,$7C,$83,$84,$85
        .DB     $FE,16,10
        .DB     $6B,$6C,$6D,$20,$74,$75,$76,$20,$7D,$7E,$7F,$86,$87,$88
        .DB     $FE,17,10
        .DB     $6E,$6F,$70,$20,$77,$78,$79,$20,$80,$81,$82,$89,$8A,$8B
        .DB     $FE,23,6,$FF,4
        .DB   	"                             "
        .DB     0
MS0:
        .DB     $FF,01,01,01
        .DB   	"       MENU V 0.09 "
        .DB     $FF,03,01,03
        .DB   	" NEO POWER SNES MYTH CARD (A)"
        .DB     $FF,26,02,05
        .DB     $22
        .DB   	" 2010 WWW.NEOFLASH.COM       "
        .DB     0
   
MS5:    .DB     $FF,03,27,03
        .DB   	"(B)"
        .DB     0
MS6:
        .DB     $FF,03,27,03
        .DB   	"(C)"
        .DB     0
MS7:
MS8:
MS9:
        .DB     $FF,01,21,03
        .DB   	"(HARD 0.1)"
        .DB     0
;-------------------------------------------------------------------------------
MS10
        .DB     $FF,20,01,05
        .DB   	"           "
        .DB     0

MS11
        .DB     $FF,20,01,05
        .DB   	" SAVE  2KB"
        .DB     0

MS12
        .DB     $FF,20,01,05
        .DB   	" SAVE  8KB"
        .DB     0

MS13
        .DB     $FF,20,01,05
        .DB   	" SAVE 32KB"
        .DB     0

MS14
        .DB     $FF,20,01,05
        .DB   	" SAVE 64KB"
        .DB     0

MS15
        .DB     $FF,20,01,05
        .DB   	" SAVE 128KB"
        .DB     0

MS16
        .DB     $FF,20,01,05
        .DB   	" DSP       "
        .DB     0

MS17
MS18
MS19

;-------------------------------------------------------------------------------
MS20
        .DB     $FF,17,01,05
        .DB   	"  8M    "
        .DB     0

MS21
        .DB     $FF,17,01,05
        .DB   	" 16M    "
        .DB     0

MS22
        .DB     $FF,17,01,05
        .DB   	" 24M    "
        .DB     0

MS23
        .DB     $FF,17,01,05
        .DB   	" 32M    "
        .DB     0

MS24
        .DB     $FF,17,01,05
        .DB   	" 40M    "
        .DB     0

MS25
        .DB     $FF,17,01,05
        .DB   	" 48M    "
        .DB     0
MS26
        .DB     $FF,17,01,05
        .DB   	" 56M    "
        .DB     0

MS27
        .DB     $FF,17,01,05
        .DB   	" 64M    "
        .DB     0

MS28
        .DB     $FF,19,01,05
        .DB   	" TEST A24 & A25 OK !   "
        .DB     0
MS29

MS30
        .DB     $FF,18,01,02
        .DB   	" TEST ...........  "
        .DB     0

MS31
        .DB     $FF,18,01,03
        .DB   	" TEST PSRAM OK     "
        .DB     0

MS32
        .DB     $FF,18,01,01
        .DB   	" TEST PSRAM ERR!   "
        .DB     0

        
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;[VIDEO IO ROUTINES]
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

SDATA1:  .DB     3,0,0,0,1,0,$23,0,0,0,0,0
SDATA2:  .DB     $1,0,0,0,2,$20,0,0,0

V_SET:
        JSR     VOFF
        LDA     #0
        STA.L   REG_BG0HOFS
        STA.L   REG_BG0HOFS
        LDA     #$B
        STA.L   REG_BG0VOFS
        LDA     #0
        STA.L   REG_BG0VOFS

        LDX     #$0     ; MODE SET
-:      LDA.W   SDATA1,X
        STA.L   REG_OBSEL,X
        LDA.W   SDATA2,X
        STA.L   REG_BGCNT,X
        INX
        CPX     #12
        BCC     -

        LDA     #<TYPE   ; CHAR LOAD
        STA     TP
        LDA     #>TYPE
        STA     TP+1
        LDA     #$80    ; ?
        STA.L   REG_VRAM_INC

        LDA     #$0
        STA.L   REG_VRAM_ADDR_L
        LDA     #$2     ;0- #$0
        STA.L   REG_VRAM_ADDR_H
        JSR     CHR
        INC     TP+1  ; 256
        JSR     CHR
        INC     TP+1  ; 256
        JSR     CHR
        INC     TP+1  ; 256
        JSR     CHR
        INC     TP+1  ; 256
        JSR     CHR
        INC     TP+1  ; 256
        JSR     CHR
        INC     TP+1  ; 256
        JSR     CHR
        INC     TP+1  ; 256

        LDX     #$0
-:
        LDA.W   COLOR_T,X       ; COLOR
        STA.L   REG_CGRAM_ADDR
        INX
        LDA.W   COLOR_T,X
        STA.L   REG_CGRAM_DATAW
        INX
        LDA.W   COLOR_T,X
        STA.L   REG_CGRAM_DATAW
        INX
        CPX     #27
        BCC     -


        LDA     #$23   ;DXL   ;BG COLOR
        STA.L   REG_COLDATA
        LDA     #$40
        STA.L   REG_COLDATA
        LDA     #$83
        STA.L   REG_COLDATA
        RTS

COLOR_T .DB     1,$FF,$7F,$11,$7F,$3C,$21,$FC,$31,$31,$F1,$47,$41,$C6,$1F
        .DB     $51,$18,$7F,$61,$63,$7C,$71,$8F,$71
        .DB     0,$0

CHR:
         LDY    #0
CHR_LOOP:
	 LDX    #8
-:       LDA    (TP),Y
         STA.L  REG_VRAM_DATAW1
         LDA    #0
         STA.L  REG_VRAM_DATAW2
         INY
         DEX
         BNE    -
         LDX    #8
         LDA    #0
-:       STA.L  REG_VRAM_DATAW1
         STA.L  REG_VRAM_DATAW2
         DEX
         BNE    -
         CPY    #0
         BNE    CHR_LOOP
         RTS
         
VON:
-:	 
         LDA.L   REG_RDNMI
         STA     AA
         BIT     AA
         BPL     -
         LDA     #(ENABLE_SCREEN | BRIGHTNESS_15)
         STA.L   REG_DISPCNT
         RTS

VOFF:
        LDA     #BLANK_SCREEN
        STA.L   REG_DISPCNT
        RTS

CLRSCR:
        JSR     VOFF
        LDA     #VRAM_WORD_ACCESS
        STA.L   REG_VRAM_INC
        CPU_REGS16		; All registers 16-bit
        LDA     #$2000
        STA.L   REG_VRAM_ADDR_L

        LDX     #$3FF
-:
        LDA     #$20
        STA.L   REG_VRAM_DATAW1
        DEX
        BPL     -
        CPU_REGS8		; All registers 8-bit
        LDA     #$00
        STA.L   REG_BG0VOFS
        STA.L   REG_BG0VOFS
        JMP     VON


;===============================================================================
INX_MM:
        LDA     (M1L)     ;1
        CMP     #$FF
        BNE     INX_MM_SKIP

        LDA.L   $7E80FD
        CMP     #$39
        BNE     +
        LDA.L   $7E80FC
        INC     A
        STA.L   $7E80FC
        LDA     #$30
        STA.L   $7E80FD
        JMP     INX_MM_DONE
+:
        INC     A
        STA.L   $7E80FD
INX_MM_DONE:
	INC	GAMEFIRSTSHOWN
        LDA     #$4
        JSR     PRINT	; Print "Game (nnn)"
INX_MM_SKIP:
        RTS
;===============================================================================
SUB_MM:
        LDA.L   $7E80FD
        CMP     #$30
        BNE     +
        LDA.L   $7E80FC
        DEC     A
        STA.L   $7E80FC
        LDA     #$39
        STA.L   $7E80FD
        JMP     SUB_MM_DONE
+:
        DEC     A
        STA.L   $7E80FD
SUB_MM_DONE:
	DEC	GAMEFIRSTSHOWN
        LDA     #$4
        JSR     PRINT
        RTS
;===============================================================================
INX_M:
        CLC
        LDA     #$40
        ADC     M1L
        STA     M1L
        BCC     +       
        INC     M1H
+:
        JSR     INX_MM
        JMP     PRINTX	; Print Save type

SUB_M:

        JSR    SUB_MM
        CLC
        LDA    M1L
        ADC    #$C0
        STA    M1L
        BCC    +
        JMP   PRINTX	; Print Save type
+:      DEC    M1H
        JMP   PRINTX	; Print Save type

;===============================================================================
-:
        LDA   M2L
        STA   M1L
        LDA   M2H
        STA   M1H
        RTS

PRINTX:
	CPU_ACC16
	LDA	GAMEPRINT
	ASL	A
	ASL	A
	ASL	A
	ASL	A
	ASL	A
	ASL	A
	CLC
	ADC	M1L
	STA	A1L
	CPU_ACC8
	
;        LDA    M1L
;        STA    A1L
;        LDA    M1H
;        STA    A1H

        LDY    #$00
        LDA   (A1L),Y   ;0    1
        CMP    #$FF               ; NO GAME
        BNE   -
        
        INY
        LDA   (A1L),Y   ;1    2
        STA   MODE
        
;-------------------------------------------------------------------------------
        INY
        LDA   (A1L),Y   ;2    3
        LSR   A
        LSR   A
        LSR   A
        LSR   A
        AND   #$0F
        STA   RZX
        
        LDA   (A1L),Y   ;2    3
        AND   #$0F
        STA   RBH
;-------------------------------------------------------------------------------
        INY
        LDA   (A1L),Y   ;3    5
        STA   RBL
;-------------------------------------------------------------------------------
        INY
        LDA   (A1L),Y   ;4    5
        LSR   A
        LSR   A
        LSR   A
        LSR   A
        AND   #$0F
        STA   SBX
        LDA   (A1L),Y   ;4    5
        AND   #$0F
        STA   SZX
;-------------------------------------------------------------------------------
        INY
        LDA   (A1L),Y   ;5    6
        LSR   A
        LSR   A
        LSR   A
        LSR   A
        AND   #$0F
        STA   EDSP
        LDA   (A1L),Y   ;5    6
        AND   #$0F
        STA   ESRAM
;-------------------------------------------------------------------------------
; NEW
        INY
        LDA   (A1L),Y   ;5    6
        LSR   A
        LSR   A
        LSR   A
        LSR   A
        AND   #$0F
        STA   RUX
        
        LDA   (A1L),Y   ;5    5
        AND   #$0F
        STA   SRAM_M

;-------------------------------------------------------------------------------
        INY
        LDA   (A1L),Y   ;7    8
;-------------------------------------------------------------------------------

                    ; wait vsync
	WAIT_VSYNC

        LDA     #$80
        STA.L   REG_VRAM_INC
        JSR     PRI2
        LDA     M1L
        STA     M2L
        LDA     M1H
        STA     M2H

	LDA	SZX
	BMI	+
	CMP	#6
	BCS	+
	CLC
	ADC	#10
	JSR	PRINT
+:
        RTS
;===============================================================================
PRINT:
        ASL     A          ; set address
        TAY
        LDA     STR,Y
        STA     A1L
        LDA     STR+1,Y
        STA     A1H

	WAIT_VSYNC

        LDA     #VRAM_WORD_ACCESS
        STA.L   REG_VRAM_INC
        LDY     #$FF
;**************************
PRI2:
        INY
        LDA     (A1L),Y
        BEQ     PRI3       ;<= 0 ,exit
        
        CMP     #$FF       ;<= FF, jump to SET X,Y,C
        BEQ     PRI5

        STA.L   REG_VRAM_DATAW1
        LDA     COLOR
        STA.L   REG_VRAM_DATAW2
        JMP     PRI2
PRI3:
        RTS
;===============================================================================
PRI5:
        LDA     #$20
        STA.L   REG_WRMPYA
        INY
        LDA     (A1L),Y
  CLC
  ADC GAMEPRINT
  
        TAX                     ;V
        INY
        LDA     (A1L),Y         ;H
        JSR     SET_XY1
        INY
        LDA     (A1L),Y
        ASL     A
        ASL     A
        STA     COLOR
        JMP     PRI2
;===============================================================================

SET_XY:
	WAIT_VSYNC
;===============================================================================
SET_XY1:
         PHA
         TXA                   ;X TO A
         STA.L   REG_WRMPYA    ;Y -> V
         LDA     #$20
         STA.L   REG_WRMPYB
         PLA                             
         
         PHA
         LDA.L   REG_RDMPYL
         STA     AA
         PLA
         ORA     AA
         
         ; Set VRAM address to $2000 + X*$20
         STA.L   REG_VRAM_ADDR_L	
         LDA.L   REG_RDMPYH
         ORA     #$20
         STA.L   REG_VRAM_ADDR_H
         RTS

                  
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
KEY:
-:
        LDA    #$00
JOY_DELAY:
        DEC     A
        BNE     JOY_DELAY

        LDA     #$01 ;01
        STA.L   REG_NMI_TIMEN
        
        JSR      KEY1
        LDA      JOY1
        STA      JOYA
        BEQ      -
        
-:
        LDA     #$01 ;01
        STA.L   REG_NMI_TIMEN
        JSR      KEY1
        BNE      -
        RTS

KEY1:
-:
        LDA.L   REG_HVB_JOY
        AND     #$01
        BEQ     -
-:
        LDA.L   REG_HVB_JOY
        AND     #$01
        BNE     -
        NOP
        NOP
        LDA.L   REG_JOY1H
        STA     JOY1
        RTS

; Needed to satisfy interrupt definition in "Header.inc".
 VBlank:
   	rti
   	
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
        .ORG    $3000
TYPE:           ;20,21
        .DB     $00,$00,$00,$00,$00,$00,$00,$00,$30,$30,$30,$30,$30,$00,$30,$00
        .DB     $3C,$42,$B9,$A1,$B9,$42,$3C,$00,$6C,$6C,$FE,$6C,$FE,$6C,$6C,$00
        .DB     $10,$7C,$D2,$7C,$86,$7C,$10,$00,$F0,$96,$FC,$18,$3E,$72,$DE,$00
        .DB     $30,$48,$30,$78,$CE,$CC,$78,$00,$0C,$0C,$18,$00,$00,$00,$00,$00
                ;28,29
        .DB     $10,$60,$C0,$C0,$C0,$60,$10,$00  ;8
        .DB     $10,$0C,$06,$06,$06,$0C,$10,$00  ;9
        .DB     $00,$54,$38,$FE,$38,$54,$00,$00  ;A
        .DB     $00,$18,$18,$7E,$18,$18,$00,$00  ;B
        .DB     $10,$38,$38,$7C,$7C,$38,$38,$10  ;C
        .DB     $00,$00,$00,$FF,$FF,$00,$00,$00  ;D   -
        .DB     $00,$00,$00,$00,$00,$00,$18,$00
        .DB     $02,$06,$0C,$18,$30,$60,$C0,$00

                ;30,31
        .DB     $7C,$CE,$DE,$F6,$E6,$E6,$7C,$00,$18,$38,$78,$18,$18,$18,$3C,$00
        .DB     $7C,$C6,$06,$0C,$30,$60,$FE,$00,$7C,$C6,$06,$3C,$06,$C6,$7C,$00
        .DB     $0E,$1E,$36,$66,$FE,$06,$06,$00,$FE,$C0,$C0,$FC,$06,$06,$FC,$00
        .DB     $7C,$C6,$C0,$FC,$C6,$C6,$7C,$00,$FE,$06,$0C,$18,$30,$60,$60,$00
        .DB     $7C,$C6,$C6,$7C,$C6,$C6,$7C,$00,$7C,$C6,$C6,$7E,$06,$C6,$7C,$00
        .DB     $00,$30,$00,$00,$00,$30,$00,$00,$00,$30,$00,$00,$00,$30,$20,$00
        .DB     $00,$1C,$30,$60,$30,$1C,$00,$00,$00,$00,$7E,$00,$7E,$00,$00,$00
        .DB     $00,$70,$18,$0C,$18,$70,$00,$00,$7C,$C6,$0C,$18,$30,$00,$30,$00
        .DB     $7C,$82,$9A,$AA,$AA,$9E,$7C,$00,$7C,$C6,$C6,$FE,$C6,$C6,$C6,$00
        .DB     $FC,$66,$66,$7C,$66,$66,$FC,$00,$7C,$C6,$C0,$C0,$C0,$C6,$7C,$00
        .DB     $FC,$66,$66,$66,$66,$66,$FC,$00,$FE,$62,$68,$78,$68,$62,$FE,$00
        .DB     $FE,$62,$68,$78,$68,$60,$F0,$00,$7C,$C6,$C6,$C0,$DE,$C6,$7C,$00
        .DB     $C6,$C6,$C6,$FE,$C6,$C6,$C6,$00,$3C,$18,$18,$18,$18,$18,$3C,$00
        .DB     $1E,$0C,$0C,$0C,$0C,$CC,$78,$00,$C6,$CC,$D8,$F0,$D8,$CC,$C6,$00
        .DB     $F0,$60,$60,$60,$60,$62,$FE,$00,$C6,$EE,$FE,$D6,$C6,$C6,$C6,$00
        .DB     $C6,$E6,$F6,$DE,$CE,$C6,$C6,$00,$7C,$C6,$C6,$C6,$C6,$C6,$7C,$00
        .DB     $FC,$66,$66,$7C,$60,$60,$F0,$00,$7C,$C6,$C6,$C6,$C6,$C6,$7C,$0C
        .DB     $FC,$66,$66,$7C,$66,$66,$E6,$00,$7C,$C6,$C0,$7C,$06,$C6,$7C,$00
        .DB     $7E,$5A,$18,$18,$18,$18,$3C,$00,$C6,$C6,$C6,$C6,$C6,$C6,$7C,$00
        .DB     $C6,$C6,$C6,$C6,$C6,$6C,$38,$00,$C6,$C6,$C6,$C6,$D6,$EE,$C6,$00
        .DB     $C6,$6C,$38,$38,$38,$6C,$C6,$00,$66,$66,$66,$3C,$18,$18,$3C,$00
        .DB     $FE,$C6,$0C,$18,$30,$66,$FE,$00,$1C,$18,$18,$18,$18,$18,$1C,$00

        .DB     $C0,$60,$30,$18,$0C,$06,$02,$00,$70,$30,$30,$30,$30,$30,$70,$00

        .DB     $00,$00,$10,$38,$6C,$C6,$00,$00,$00,$00,$00,$FF,$FF,$00,$00,$00

        .DB     $07,$0C,$38,$38,$78,$78,$78,$78,$E4,$1C,$0C,$0C,$04,$04,$00,$00

        .DB     $78,$78,$78,$78,$38,$38,$0C,$07,$00,$00,$02,$02,$04,$0C,$18,$F0

        .DB     $3F,$1C,$1C,$1C,$1C,$1C,$1C,$1C,$1C,$1C,$1C,$1C,$1C,$1C,$1C,$3F

        .DB     $00,$00,$00,$00,$08,$08,$18,$F8,$00,$00,$00,$00,$00,$38,$38,$38

                    ;68   69
        .DB     $00,$00,$00,$00,$09,$0F,$19,$18,$00,$3F,$FC,$10,$FF,$10,$93,$90
        .DB     $00,$00,$00,$30,$F8,$3C,$30,$00,$11,$01,$00,$07,$04,$04,$07,$0C
        .DB     $93,$91,$03,$EF,$44,$46,$83,$1F,$80,$00,$20,$E0,$C0,$80,$FC,$C0
        .DB     $0F,$1C,$14,$27,$44,$00,$00,$00,$C3,$4F,$9B,$C3,$03,$03,$03,$01
        .DB     $00,$F8,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$09,$0F,$19,$18
        .DB     $00,$3F,$FC,$10,$FF,$17,$D3,$D3,$00,$00,$00,$F0,$F8,$3C,$60,$00
        .DB     $19,$00,$07,$06,$06,$06,$06,$0F,$D3,$87,$FF,$31,$73,$C5,$FF,$E7
        .DB     $00,$C0,$C0,$C0,$80,$E0,$F0,$C0,$0C,$0D,$1A,$18,$30,$60,$CF,$00
        .DB     $FD,$F9,$4D,$CF,$C8,$4F,$FF,$00,$78,$3E,$00,$80,$00,$F8,$F8,$00
        .DB     $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$60,$70,$70,$30,$20,$20
        .DB     $00,$00,$00,$00,$00,$00,$00,$00,$00,$08,$18,$18,$30,$30,$70,$60
        .DB     $20,$21,$20,$20,$20,$20,$20,$30,$00,$80,$E0,$E0,$70,$30,$30,$00
        .DB     $60,$00,$03,$01,$00,$00,$00,$00,$30,$30,$F0,$F0,$E0,$60,$00,$00
        .DB     $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$07,$03,$00,$00
        .DB     $00,$00,$01,$3F,$F3,$07,$06,$3C,$00,$00,$80,$C0,$C0,$80,$00,$00
        .DB     $00,$00,$00,$7F,$38,$00,$00,$00,$18,$18,$FF,$C8,$0C,$0C,$0C,$0C
        .DB     $00,$3C,$FE,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
        .DB     $0C,$0C,$1C,$D8,$78,$38,$10,$00,$00,$00,$00,$00,$00,$00,$00,$00
;
        .DB     $00,$00,$00,$00,$04,$04,$0C,$0C,$40,$70,$60,$60,$63,$61,$60,$60
        .DB     $00,$00,$00,$00,$00,$80,$C0,$C0,$18,$08,$00,$00,$00,$3F,$18,$00
        .DB     $E0,$60,$00,$63,$7F,$E0,$60,$60,$00,$00,$00,$00,$C0,$00,$00,$00
        .DB     $00,$00,$01,$03,$0E,$78,$00,$00,$D0,$88,$8C,$07,$03,$03,$01,$00
        .DB     $00,$00,$00,$00,$80,$F0,$FC,$00,$00,$00,$00,$04,$07,$07,$03,$03
        .DB     $06,$0F,$3E,$70,$80,$00,$03,$3F,$00,$00,$00,$00,$00,$00,$80,$80
        .DB     $03,$03,$03,$03,$03,$03,$FF,$F8,$FC,$0C,$0C,$08,$0F,$FF,$80,$00
        .DB     $00,$00,$00,$00,$F8,$FC,$00,$00,$01,$03,$07,$0F,$1C,$30,$00,$00
        .DB     $86,$C3,$81,$00,$00,$00,$00,$00,$00,$80,$C0,$E0,$E0,$60,$00,$00
                ;9E     ;9F
        .DB     $01,$FF,$3F,$21,$3F,$21,$3F,$01,$00,$FE,$F8,$08,$F8,$08,$F8,$04
        .DB     $7F,$00,$FF,$10,$08,$00,$00,$00,$FC,$10,$FE,$10,$10,$30,$00,$00
        .DB     $09,$08,$1F,$10,$3F,$50,$9F,$10,$00,$80,$F8,$80,$F8,$80,$F8,$80
        .DB     $1F,$00,$1F,$10,$10,$1F,$00,$00,$FC,$00,$F8,$08,$08,$F8,$00,$00
        .DB     $04,$07,$08,$14,$22,$01,$06,$18,$00,$F0,$10,$20,$40,$80,$60,$1E
        .DB     $E0,$0F,$08,$08,$0F,$08,$00,$00,$04,$F0,$10,$10,$F0,$10,$00,$00
        .DB     $08,$1D,$F0,$13,$FC,$11,$31,$39,$08,$F0,$20,$FE,$20,$FC,$24,$FC
        .DB     $55,$91,$10,$11,$10,$13,$00,$00,$24,$FC,$20,$FC,$20,$FE,$00,$00
        .DB     $FF,$01,$7F,$51,$89,$11,$01,$3F,$FE,$00,$FE,$12,$24,$10,$00,$F8
        .DB     $21,$3F,$21,$3F,$01,$00,$00,$00,$08,$F8,$08,$F8,$00,$FC,$00,$00
        .DB     $20,$11,$FD,$05,$09,$11,$31,$59,$00,$FC,$04,$FC,$04,$FC,$04,$FC
        .DB     $94,$10,$10,$10,$11,$12,$00,$00,$50,$50,$50,$92,$12,$0E,$00,$00
        .DB     $82,$42,$0F,$F4,$17,$24,$44,$84,$10,$20,$BC,$00,$BC,$88,$90,$BC
        .DB     $48,$20,$22,$21,$40,$BF,$00,$00,$88,$88,$A8,$10,$00,$FE,$00,$00
        .DB     $22,$4F,$F4,$27,$54,$F7,$01,$7F,$08,$D2,$5C,$C8,$52,$DE,$00,$FC
        .DB     $01,$09,$11,$21,$C1,$01,$00,$00,$00,$20,$10,$0C,$04,$00,$00,$00
        .DB     $3E,$22,$22,$3E,$01,$01,$FF,$02,$F8,$88,$88,$F8,$20,$10,$FE,$80
        .DB     $0C,$30,$FE,$22,$22,$3E,$00,$00,$60,$18,$FE,$88,$88,$F8,$00,$00
        .DB     $03,$0C,$18,$30,$30,$30,$30,$30,$C4,$34,$1C,$0C,$04,$00,$00,$00
        .DB     $30,$30,$30,$18,$0C,$03,$00,$00,$00,$04,$0C,$18,$30,$C0,$00,$00
        .DB     $3F,$18,$18,$18,$18,$18,$18,$18,$C0,$70,$1C,$0C,$0C,$0C,$0C,$0C
        .DB     $18,$18,$18,$18,$18,$3F,$00,$00,$0C,$0C,$0C,$18,$70,$C0,$00,$00
        .DB     $02,$02,$03,$02,$02,$FF,$02,$02,$00,$20,$F0,$00,$04,$FE,$00,$00
        .DB     $02,$02,$02,$02,$02,$02,$00,$00,$80,$60,$30,$10,$00,$00,$00,$00
        .DB     $24,$24,$FF,$24,$47,$00,$7F,$41,$48,$48,$FE,$48,$CE,$00,$FE,$02
        .DB     $9F,$11,$11,$11,$11,$01,$00,$00,$F4,$10,$10,$50,$20,$00,$00,$00
        .DB     $01,$01,$01,$7F,$41,$41,$41,$7F,$00,$00,$04,$FE,$04,$04,$04,$FC
        .DB     $41,$01,$01,$01,$01,$01,$00,$00,$04,$00,$00,$00,$00,$00,$00,$00
        .DB     $01,$01,$01,$FF,$01,$01,$01,$1F,$00,$00,$04,$FE,$00,$00,$10,$F8
        .DB     $10,$10,$10,$10,$1F,$10,$00,$00,$10,$10,$10,$10,$F0,$10,$00,$00
        .DB     $01,$01,$FF,$08,$10,$28,$44,$02,$00,$04,$FE,$10,$0C,$24,$40,$80
        .DB     $01,$02,$04,$08,$30,$C0,$00,$00,$00,$80,$40,$30,$0E,$04,$00,$00
        .DB     $20,$21,$22,$F8,$23,$2A,$32,$63,$80,$F8,$10,$20,$FC,$44,$A4,$14
        .DB     $A2,$2F,$20,$21,$A2,$4C,$00,$00,$44,$FE,$A0,$10,$08,$06,$00,$00
        .DB     $02,$01,$F8,$27,$41,$42,$74,$D7,$08,$98,$A0,$FE,$08,$52,$A4,$BC
        .DB     $51,$52,$54,$74,$57,$00,$00,$00,$08,$10,$A4,$A2,$FE,$42,$00,$00
        .DB     $10,$10,$10,$10,$1F,$10,$10,$1F,$10,$10,$10,$10,$F0,$00,$00,$F0
        .DB     $10,$10,$10,$10,$20,$40,$00,$00,$10,$10,$10,$10,$10,$10,$00,$00
        .DB     $11,$10,$7C,$10,$10,$FE,$10,$50,$FC,$44,$44,$44,$54,$88,$00,$FC
        .DB     $5E,$50,$50,$70,$48,$87,$00,$00,$84,$84,$84,$FC,$00,$FE,$00,$00
        .DB     $08,$08,$0B,$10,$30,$50,$9F,$10,$00,$10,$F8,$40,$40,$44,$FE,$40
        .DB     $10,$10,$10,$17,$10,$10,$00,$00,$40,$40,$48,$FC,$00,$00,$00,$00
        ;.DB
        ;.DB
        ;.DB
        ;.DB
        ;.DB
        ;.DB
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;[MENU DRIVER]
                    
;==============================================================================
;  XY
; $00 IF FF HAVE GAME
; $01 ,MODE 04 >SNES GAME
; $02 ,RBH  XY >X= ROM SIZE & Y = A25 ~A24
; $03 ,RBL     >A23~A16
; $04 ,SRAM XY >X SRAM BANK & Y = SRAM SIZE
; $05 ,EXT  P  >X = EXT DSP & Y = EXT SAVE
; $06 ,RUX      X = SAVE MODE Y = RUN MODE
;
        .ORG    $4800
;                 0   1   2   3   4   5   6   7
        .DB     $FF,$04,$40,$00,$01,$11,$01,$00
        .DB     $FF,10,01,0
        .DB   	" DSP1  HROM 4M SAVE 2K       "
        .DB     0

        .ORG    $4840
        .DB     $FF,$04,$40,$00,$00,$30,$10,$00
        .DB     $FF,10,01,1
        .DB  	" DSP1  LROM 4M               "
        .DB     0

        .ORG    $4880
        .DB     $FF,$04,$80,$00,$03,$74,$10,$00
        .DB     $FF,10,01,2
        .DB   	" DSP FX 8M                   "
        .DB     0

        .ORG    $48C0
        .DB     $FF,$00,$00,$F0,$02,$00,$00,$00
        .DB     $FF,10,01,3
        .DB   	" ROM 24M                     "
        .DB     0

        .ORG    $4900
        .DB     $FF,$01,$B0,$00,$01,$01,$01,$32
        .DB     $FF,10,01,4
        .DB   	"     HROM  32M SAVE 2K       "
        .DB     0

        .ORG    $4940
        .DB     $FF,$04,$D0,$00,$01,$01,$21,$00
        .DB     $FF,10,01,5
        .DB   	"     HROM 48M S8K (256M-B0)  "
        .DB     0

        .ORG    $4980
        .DB     $FF,$04,$D1,$00,$02,$01,$21,$00
        .DB     $FF,10,01,6
        .DB   	"     HROM 48M S8K (256M-B1)  "
        .DB     0

        .ORG    $49C0
        .DB     $FF,$04,$D2,$00,$02,$01,$21,$00
        .DB     $FF,10,01,7
        .DB   	"     HROM 48M S8K (256M-B2)  "
        .DB     0

        .ORG    $4A00
        .DB     $FF,$04,$D3,$00,$02,$01,$21,$00
        .DB     $FF,10,01,8
        .DB   	"     HROM 48M S8K (256M-B3)  "
        .DB     0

        .ORG    $4A40
        .DB     $FF,$04,$D0,$40,$02,$01,$21,$00
        .DB     $FF,10,01,9
        .DB   	"    HROM 48M S8K (64M-B1)    "
        .DB     0

        .ORG    $4A80
        .DB     $FF,$04,$D0,$40,$02,$01,$21,$00
        .DB     $FF,10,01,10
        .DB   	"    HROM 48M S8K (64M-B1)    "
        .DB     0


; Padding
 .BANK 2
 .DB 0
 .BANK 3
 .ORG $7FFF
 .DB 0


 
