;================================================================
; [MENU.INC] -- Main menu and whatever.. This file is very well
;               commented in comparison to other source balls as
;               of this lil' project, so: YAY!! ^.^
;================================================================

; .BANK 0 SLOT 0
; .ORG HEADER_OFF
; .SECTION "menuStuff" SEMIFREE

MENU_MAIN:
    jsr INIT_VIDEO_03
    lda #$80
    sta $2100                   ; screen off, lowest brightness

    lda #%00011111
    sta $212C                   ; sprites enabled

    jsr SPRITEZ_PRIOR30

    lda #NO_SONG
    sta MUSIC
    jsr AUDIO_PLAY_SONG         ; stop the music

    phx                         ; a nice juicy delay interval between
    ldx #$32                    ; splash screen fadeout and the menu.
-   wai
    dex
    cpx #$0000
    bpl -
    plx

    lda #SONG_LUIGI
    sta MUSIC
    jsr AUDIO_PLAY_SONG         ; play music

MENU_MAIN_skipMusChange
    ; load all datas for main menu

    LOAD_PAL MMENU_BG_PAL
    wai
    LOAD_BLOCK2VRAM MMENU_BG1_DAT,$0000,$2000
    wai
    wai
    LOAD_BLOCK2VRAM MMENU_BG1_GFX,$1000,$0800
    wai
    wai
    LOAD_BLOCK2VRAM MMENU_BG2_GFX,$2000,$1800
    wai
    wai
    LOAD_BLOCK2VRAM MMENU_SPR_GFX,$6000,$2000    ; one 32x32 sprite (star)
    wai
    wai

    jsr MM_draw_menu_box

    lda #$cf
    sta SPRBUF2+7               ; show star sprite
    lda #$ff
    sta SPRBUF2
    sta SPRBUF2+1
    sta SPRBUF2+2
    sta SPRBUF2+3
    sta SPRBUF2+4
    sta SPRBUF2+5
    sta SPRBUF2+6
    sta SPRBUF2+8
    sta SPRBUF2+9
    sta SPRBUF2+10
    sta SPRBUF2+11
    sta SPRBUF2+12
    sta SPRBUF2+13
    sta SPRBUF2+14
    sta SPRBUF2+15
    sta SPRBUF2+16
    sta SPRBUF2+17
    sta SPRBUF2+18
    sta SPRBUF2+19
    sta SPRBUF2+20
    sta SPRBUF2+21
    sta SPRBUF2+22
    sta SPRBUF2+23
    sta SPRBUF2+24
    sta SPRBUF2+25
    sta SPRBUF2+26
    sta SPRBUF2+27
    sta SPRBUF2+28
    sta SPRBUF2+29
    sta SPRBUF2+30
    sta SPRBUF2+31

    lda #$30
    sta SPRBUF1+SPRIORITY30
    lda #$00
    sta CURFRAME30

    lda #$04
    sta CURFRAME
    sta CURFRAME1
    sta CURFRAME2
    sta CURFRAME3
    sta CURFRAME4
    sta CURFRAME5
    sta CURFRAME6
    sta CURFRAME7
    sta CURFRAME8
    sta CURFRAME9
    sta CURFRAME10
    sta CURFRAME11
    sta CURFRAME12
    sta CURFRAME13
    sta CURFRAME14
    sta CURFRAME15
    sta CURFRAME16
    sta CURFRAME17
    sta CURFRAME18
    sta CURFRAME19
    sta CURFRAME20
    sta CURFRAME21
    sta CURFRAME22
    sta CURFRAME23
    sta CURFRAME24
    sta CURFRAME25
    sta CURFRAME26
    sta CURFRAME27
    sta CURFRAME28
    sta CURFRAME29
    sta CURFRAME31
    ;--
    stz SPRBUF1+SPRIORITY
    stz SPRBUF1+SPRIORITY1
    stz SPRBUF1+SPRIORITY2
    stz SPRBUF1+SPRIORITY3
    stz SPRBUF1+SPRIORITY4
    stz SPRBUF1+SPRIORITY5
    stz SPRBUF1+SPRIORITY6
    stz SPRBUF1+SPRIORITY7
    stz SPRBUF1+SPRIORITY8
    stz SPRBUF1+SPRIORITY9
    stz SPRBUF1+SPRIORITY10
    stz SPRBUF1+SPRIORITY11
    stz SPRBUF1+SPRIORITY12
    stz SPRBUF1+SPRIORITY13
    stz SPRBUF1+SPRIORITY14
    stz SPRBUF1+SPRIORITY15
    stz SPRBUF1+SPRIORITY16
    stz SPRBUF1+SPRIORITY17
    stz SPRBUF1+SPRIORITY18
    stz SPRBUF1+SPRIORITY19
    stz SPRBUF1+SPRIORITY20
    stz SPRBUF1+SPRIORITY21
    stz SPRBUF1+SPRIORITY22
    stz SPRBUF1+SPRIORITY23
    stz SPRBUF1+SPRIORITY24
    stz SPRBUF1+SPRIORITY25
    stz SPRBUF1+SPRIORITY26
    stz SPRBUF1+SPRIORITY27
    stz SPRBUF1+SPRIORITY28
    stz SPRBUF1+SPRIORITY29
    stz SPRBUF1+SPRIORITY31

    ldx #$54                    ; star sprite cursor x,y
    stx SPRBUF1+SX30
    ldx #$67
    stx SPRBUF1+SY30

    stz MAPX
    stz MAPY                    ; reset bg#1 map x,y location

    stz a_byte                  ; menu pointer (0-2)
    lda #$01
    sta a_byte2                 ; don't allow sfx play unless movement
    ldx #$0000
    stx a_word                  ; menu pointer delay

    lda #$0C                    ; make sure that the pointer colours
    sta $2121                   ; are correct!
    lda #$7C
    sta $2122
    lda #$1F
    sta $2122
    lda #$0D
    sta $2121
    lda #$31
    sta $2122
    lda #$8C
    sta $2122
    lda #$0E
    sta $2121
    lda #$31
    sta $2122
    lda #$8C
    sta $2122

    stz what_fade
    jsr MM_FadeIn_inside

MM_menu_loop
    wai
    wai
    ldx MAPX
    inx
    stx MAPX
    ldx MAPY
    inx
    stx MAPY                    ; background scroll

    jsr MM_menuCurPalFX         ; perform palette "effect"

    ldx a_word                  ; slowdown for gamepad. without this slowdown
    inx                         ; the star pointer would move -way- too fast.
    stx a_word
    cpx #$05
    beq MM_resetAWord
    jmp MM_esc_symlink
MM_resetAWord
    ldx #$0000
    stx a_word

    lda joy1+1
    and #$08                    ; key up?
    beq MM_curNotUp

    lda #a_byte                 ; is a_byte > 0 ?
    cmp #$00
    beq MM_esc_symlink          ; if not then branch
    dec a_byte
    lda a_byte
    cmp #$01                    ; if a_byte == 1 then branch
    beq MM_curTo01
    stz a_byte                  ; makes sure that the value isn't bogus
    jmp MM_curUpDone
MM_curTo01
    lda #$01
    sta a_byte
MM_curUpDone
    jmp MM_curUpdate            ; update star position

MM_curNotUp
    lda joy1+1
    and #$04                    ; key down?
    beq MM_esc_symlink

    lda #a_byte                 ; is a_byte < 2 ?
    cmp #$02
    beq MM_esc_symlink          ; if not then branch
    inc a_byte
    lda a_byte
    cmp #$01                    ; if a_byte == 1 then branch
    beq MM_curTo01_2
    lda #$02                    ; makes sure that the value isn't bogus
    sta a_byte
    jmp MM_curDownDone
MM_curTo01_2
    lda #$01
    sta a_byte
MM_curDownDone
    jmp MM_curUpdate            ; update star position

MM_esc_symlink
    jmp MM_menu_end

MM_curUpdate
    lda a_byte
    cmp #$00
    beq MM_curUpdate0
    cmp #$01
    beq MM_curUpdate1
    jmp MM_curUpdate2
MM_curUpdate0
    lda a_byte2
    cmp #$00
    bne MM_noPing0
;   lda #V1SFX_PING_HIGH
;   sta V1SFX
;   jsr AUDIO_PLAY_V1SFX
MM_noPing0
    lda #$01
    sta a_byte2
    ldx #$67
    jmp MM_curUpdateF
MM_curUpdate1
;   lda #V1SFX_DING_A_LING_LOW
;   sta V1SFX
;   jsr AUDIO_PLAY_V1SFX
    stz a_byte2
    ldx #$6F
    jmp MM_curUpdateF
MM_curUpdate2
    lda a_byte2
    cmp #$00
    bne MM_noPing2
;   lda #V1SFX_PING_LOW
;   sta V1SFX
;   jsr AUDIO_PLAY_V1SFX
MM_noPing2
    lda #$01
    sta a_byte2
    ldx #$77
MM_curUpdateF
    stx SPRBUF1+SY30

MM_menu_end
    ; check button presses (start,x,a,b,y)

    lda joy1+1
    and #$10                    ; check start button
    beq MM_me_chkX
    jmp MM_button_confirmed
MM_me_chkX
    lda joy1
    and #$40                    ; check x button
    beq MM_me_chkA
    jmp MM_button_confirmed
MM_me_chkA
    lda joy1
    and #$80                    ; check a button
    beq MM_me_chkB
    jmp MM_button_confirmed
MM_me_chkB
    lda joy1+1
    and #$80                    ; check b button
    beq MM_me_chkY
    jmp MM_button_confirmed
MM_me_chkY
    lda joy1+1
    and #$40                    ; check y button
    beq MM_menu_endloop
    jmp MM_button_confirmed

MM_menu_endloop
    jmp MM_menu_loop


;===============================


MM_draw_menu_box
    GOTOXY 9,8
    PRINTS "ABCDEEEEEEELMNO"
    GOTOXY 10,8
    PRINTS "GoooooooooooooW"
    GOTOXY 11,8
    PRINTS "Hoot}vwxyz{oooX"    ; pick your poison!
    GOTOXY 12,8
    PRINTS "IoooooooooooooY"
    GOTOXY 13,8
    PRINTS "JooolmnopqrsooZ"    ; new game
    GOTOXY 14,8
    PRINTS "Joooo89:;;<oooZ"    ; stuff.
    GOTOXY 15,8
    PRINTS "eooo1o2345ooooj"    ; < back
    GOTOXY 16,8
    PRINTS "doooooooooooooi"
    GOTOXY 17,8
    PRINTS "coooooooooooooh"
    GOTOXY 18,8
    PRINTS "QRSTUUUUUUU\\]_a"
    rts

MM_undraw_menu_box
    GOTOXY 8,5
    jsr MM_undraw
    GOTOXY 9,5
    jsr MM_undraw
    GOTOXY 10,5
    jsr MM_undraw
    GOTOXY 11,5
    jsr MM_undraw
    GOTOXY 12,5
    jsr MM_undraw
    GOTOXY 13,5
    jsr MM_undraw
    GOTOXY 14,5
    jsr MM_undraw
    GOTOXY 15,5
    jsr MM_undraw
    GOTOXY 16,5
    jsr MM_undraw
    GOTOXY 17,5
    jsr MM_undraw
    GOTOXY 18,5
    jsr MM_undraw
    GOTOXY 19,5
    jsr MM_undraw
    rts
MM_undraw
    PRINTS "                     "
    rts

MM_draw_option_box
    GOTOXY 8,5
    PRINTS "ABCDEEEEEEEEEEEEELMNO"
    GOTOXY 9,5
    PRINTS "GoooooooooooooooooooW"
    GOTOXY 10,5
    PRINTS "HoooooooooooooooooooX"
    GOTOXY 11,5
    PRINTS "IoooooooooooooooooooY"
    GOTOXY 12,5
    PRINTS "JoooooooooooooooooooZ"
    GOTOXY 13,5
    PRINTS "JoooooooooooooooooooZ"
    GOTOXY 14,5
    PRINTS "JoooooooooooooooooooZ"
    GOTOXY 15,5
    PRINTS "JoooooooooooooooooooZ"
    GOTOXY 16,5
    PRINTS "eoooooooooooooooooooj"
    GOTOXY 17,5
    PRINTS "doooooooooooooooooooi"
    GOTOXY 18,5
    PRINTS "coooooooooooooooooooh"
    GOTOXY 19,5
    PRINTS "QRSTUUUUUUUUUUUUU\\]_a"
    rts


;===============================


MM_FadeIn_inside                ; fade in box
    php

    sep #$20                    ; A 8-bits

    stz $2125                   ; disable colour window
    lda #$30
    sta $2130
    stz $2131

    rep #$20                    ; A 16-bits

    lda what_fade
    cmp #$01
    beq MM_ofi_loadCircleData

    ; set pointers to square fade data
    lda.w #square_data_2&$FFFF
    sta.b hdmaPointer
    sep #$20                    ; 8-bits accumulator
    lda #FADE_BANK_2
    sta.b hdmaPointer+$02
    jmp MM_ofi_finishedLoading
MM_ofi_loadCircleData
    ; set pointers to circle fade data
    lda.w #circle_data_2&$FFFF
    sta.b hdmaPointer
    sep #$20                    ; 8-bits accumulator
    lda #FADE_BANK_1
    sta.b hdmaPointer+$02
MM_ofi_finishedLoading

    ; inside window fade in

    php
    sep #$20                    ; A 8-bits

    lda #$00
    sta $2100                   ; screen on, no brightness
    lda #$81
    sta $4200                   ; enable vbi and joypad read
    cli                         ; enable interrupts

    wai

    lda #$33
    sta $2123                   ; enable window
    lda #$03
    sta $2124
    sta $2125

    jmp MM_ofi_rejoin

MM_ofi_done
    plp
    rts                         ; return back on track to the main menu code

MM_ofi_rejoin
    lda #$17
    sta $212E

    ; configure horizontal dma
    lda #$01                    ; 2 address format
    sta $4310
    lda #$26                    ; window positions at $2126
    sta $4311
    ldx.w #windowPositions&$FFFF; hdma list location
    stx $4312
    lda #windowPositions/$10000 ; hdma list bank
    sta $4314

    lda [hdmaPointer]           ; set vb delay between fade out frames
    sta.b delay

    ldy #$0001                  ; configure hdma data for the first time
    jsr configureWindowHdmaData

    lda #$02
    sta $420C                   ; enable hdma channel #2

    lda #$0F
    sta $2100                   ; screen on, full brightness

MM_ofi_loop
    lda #$00

    phx                         ; scroll bg#1
    ldx MAPX
    inx
    stx MAPX
    ldx MAPY
    inx
    stx MAPY
    plx

MM_ofi_delay
    wai
    clc
    adc #$01
    cmp.b delay
    bmi MM_ofi_delay

    ; configure hdma data for the next frame
    jsr configureWindowHdmaData

    cpx.w #$0000                ; finished?
    bne MM_ofi_loop

    lda #$00                    ; disable hdma channel #1
    sta $420C

    stz $2123                   ; disable window
    stz $2124
    stz $2125
    stz $212E

    plp
    jmp MM_ofi_done


;===============================


MM_menuCurPalFX
    pha

    lda a_byte
    cmp #$00
    beq MM_mCPFX_00
    cmp #$01
    beq MM_mCPFX_01

MM_mCPFX_02
    lda #$0C                    ; index #12
    sta $2121
    lda #$31
    sta $2122
    lda #$8C
    sta $2122

    lda #$0D                    ; index #13
    sta $2121
    lda #$31
    sta $2122
    lda #$8C
    sta $2122

    lda #$0E                    ; index #14
    sta $2121
    lda #$7C
    sta $2122
    lda #$1F
    sta $2122

    jmp MM_mCPFX_FF

MM_mCPFX_01
    lda #$0C                    ; index #12
    sta $2121
    lda #$31
    sta $2122
    lda #$8C
    sta $2122

    lda #$0D                    ; index #13
    sta $2121
    lda #$7C
    sta $2122
    lda #$1F
    sta $2122

    lda #$0E                    ; index #14
    sta $2121
    lda #$31
    sta $2122
    lda #$8C
    sta $2122

    jmp MM_mCPFX_FF

MM_mCPFX_00
    lda #$0C                    ; index #12
    sta $2121
    lda #$7C
    sta $2122
    lda #$1F
    sta $2122

    lda #$0D                    ; index #13
    sta $2121
    lda #$31
    sta $2122
    lda #$8C
    sta $2122

    lda #$0E                    ; index #14
    sta $2121
    lda #$31
    sta $2122
    lda #$8C
    sta $2122

MM_mCPFX_FF
    pla
    rts


;================================================================

; this routine also plays the gong and makes your preciouschz
; choice blink rapid like a bunny in heat in addition to the
; triangular fade out.

MM_FadeOut_inside               ; fade out triangle
    stz a_byte2                 ; blink counter

    lda #V0SFX_DEEP_THUMP
    sta V0SFX
    jsr AUDIO_PLAY_V0SFX

    php
    wai

    sep #$20                    ; A 8-bits

    stz $2125                   ; disable colour window
    lda #$30
    sta $2130
    stz $2131

    rep #$20                    ; A 16-bits

    ; set pointers to triangle fade data
    lda.w #triangle_data&$FFFF
    sta.b hdmaPointer
    sep #$20                    ; A 8-bits
    lda #FADE_BANK_1
    sta.b hdmaPointer+$02

    ; perform fade out
    jmp MM_insideFadeOut

MM_ifo_done
    plp
    rts

; inside window fade out
MM_insideFadeOut
    php
    sep #$20                    ; A 8-bits

    wai                         ; wait for vertical blank

    lda #$33                    ; enable window
    sta $2123
    lda #$03
    sta $2124
    lda #$03
    sta $2125
MM_ifo_rejoin
    lda #$17
    sta $212E

; configure horizontal dma
    lda #$01                    ; 2 address format
    sta $4310
    lda #$26                    ; window positions at $2126
    sta $4311
    ldx.w #windowPositions&$FFFF ; hdma list location
    stx $4312
    lda #windowPositions/$10000 ; hdma list bank
    sta $4314

    lda [hdmaPointer]           ; set vb delay between fade out frames
    sta.b delay

    ldy #$0001                  ; configure hdma data for first frame
    jsr configureWindowHdmaData

    lda #$02                    ; enable hdma channel 2
    sta $420C

MM_ifo_loop
    lda #$00                    ; frame delay

    phx                         ; scroll bg#1
    ldx MAPX
    inx
    stx MAPX
    ldx MAPY
    inx
    stx MAPY
    plx

    inc a_byte2
    pha
    lda a_byte2
    cmp #$04
    beq +
    jmp ++
+   stz a_byte2
++  pla

    jsr MM_ifo_bunny_in_heat

MM_ifo_delay
    wai
    clc
    adc #$01
    cmp.b delay
    bmi MM_ifo_delay

; configure hdma data for next frame
    jsr configureWindowHdmaData

    cpx.w #$0000    ; check for finish
    bne MM_ifo_loop

    lda #$00        ; disable hdma channel 1
    sta $420c

    stz $2123       ; disable window
    stz $2124
    stz $2125
    stz $212E
    lda #$80        ; disable screen
    sta $2100

    plp
    jmp MM_ifo_done

MM_ifo_bunny_in_heat
    pha

    lda a_byte
    cmp #$02
    beq MM_ifo_bih2
    cmp #$01
    beq MM_ifo_bih1
    jmp MM_ifo_bih0

MM_ifo_bih2
    lda a_byte2
    cmp #$01
    beq +
    cmp #$02
    beq +

    lda #$0E                    ; index #14
    sta $2121
    lda #$7C
    sta $2122
    lda #$1F
    sta $2122
    ; <- sprite
    lda #%00110010
    sta SPRBUF1+SPRIORITY26
    jmp ++
+   lda #$0E
    jsr MM_ifo_bih_akai
    ; <- sprite
    lda #%00110000
    sta SPRBUF1+SPRIORITY26
++  jmp MM_ifo_bih_end

MM_ifo_bih1
    lda a_byte2
    cmp #$01
    beq +
    cmp #$02
    beq +


    lda #%00110010

    lda #$0D                    ; index #13
    sta $2121
    lda #$7C
    sta $2122
    lda #$1F
    sta $2122
    ; KEYS sprites
    lda #%00110010
    sta SPRBUF1+SPRIORITY22
    sta SPRBUF1+SPRIORITY23
    sta SPRBUF1+SPRIORITY24
    sta SPRBUF1+SPRIORITY25
    jmp ++
+   lda #$0D
    jsr MM_ifo_bih_akai
    ; KEYS sprites
    lda #%00110000
    sta SPRBUF1+SPRIORITY22
    sta SPRBUF1+SPRIORITY23
    sta SPRBUF1+SPRIORITY24
    sta SPRBUF1+SPRIORITY25
++  jmp MM_ifo_bih_end
; BOKMERKE
MM_ifo_bih0
    lda a_byte2
    cmp #$01
    beq +
    cmp #$02
    beq +

    lda #$0C                    ; index #12
    sta $2121
    lda #$7C
    sta $2122
    lda #$1F
    sta $2122
    ; ??? sprites
    lda #%00110010
    sta SPRBUF1+SPRIORITY
    sta SPRBUF1+SPRIORITY1
    sta SPRBUF1+SPRIORITY2
    jmp ++
+   lda #$0C
    jsr MM_ifo_bih_akai
    ; ??? sprites
    lda #%00110000
    sta SPRBUF1+SPRIORITY
    sta SPRBUF1+SPRIORITY1
    sta SPRBUF1+SPRIORITY2
++  jmp MM_ifo_bih_end

MM_ifo_bih_end
    pla
    rts

MM_ifo_bih_akai
    sta $2121
    lda #$31
    sta $2122
    lda #$8C
    sta $2122

    rts


;================================================================


; MM_button_confirmed ~ this routine gets jumped to when one of the
;                       following keys have pressed during the main
;                       menu: start, x, a, b, y.

MM_button_confirmed
    jsr MM_FadeOut_inside
    jsr MM_undraw_menu_box

    lda a_byte
    cmp #$02
    beq MM_backToSplash

    cmp #$01
    beq MM_option_pre

    jsr SEQ_INTRO_KA
    jmp PLAY_GAME


;================================================================


MM_backToSplash
    inc OBJ_HIT                 ; Jikkyou Parodius easter-egg

    jsr INIT_VIDEO_04
    lda #$8f
    sta $2100                   ; screen off, full brightness

    lda #SONG_ICE
    sta MUSIC
    jsr AUDIO_PLAY_SONG         ; play some splashy muzak

    lda #$ff
    sta SPRBUF2

    jmp SPLASH_LOAD


;================================================================

MM_option_pre
    stz hd_py2                  ; if !hd_py2 then the music has been changed.
    stz hd_coll                 ; used to avoid multiple loadings of tune.
    stz OBJ_Y                   ; ??? outcome picker.

MM_option
    stz OBJ_HIT                 ; Jikkyou Parodius easter-egg

    lda #$8f
    sta $2100                   ; screen off, full brightness

    php
    rep #$10                    ; A/mem=8bits, X/Y=16bits
    sep #$20
    lda #$03                    ; Spr sizes = 8x8||16x16,
                                ; VRAM chr data address = $6000
    sta $2101
    lda #$03                    ; Mode #3, 8x8 (BG#1=8bpp, BG#2=4bpp)
    sta $2105
    lda #$08                    ; BG#1 tilemap VRAM offs = $0000 ..
    sta $2107                   ; .. and tilemap size = 64x64 tiles
    lda #$21                    ; BG#1 chr VRAM offs = $1000
    sta $210B                   ; BG#2 chr VRAM offs = $2000
    lda #$58                    ; BG#2 tilemap VRAM offs = $5800 ..
    sta $2108                   ; .. and tilemap size = 32x32 tiles
    lda #$13                    ; Enable BG#1, BG#2 and BG#5
    sta $212C
    lda #$8f
    sta $2100                   ; screen off, full brightness
    lda #$FF                    ; Scroll BG#2 down by one pixel
    sta $2110
    sta $2110
    plp

    jsl bH13_OPTMENU_SPRTEXT
    jsr MM_draw_option_box

    stz a_byte                  ; reset cursor
    lda #$01
    sta a_byte2                 ; don't allow sfx play unless movement
    stz hd_cx2                  ; reset sound effect number (S.E)
    stz hd_px2                  ; reset music/tune number (MUSIC)

    lda #$01
    sta what_fade
    jsr MM_FadeIn_inside

; .ENDS

; <--- lIST OF 8x8 LETTER SPRITE TABLE --->
; 00 A
; 01 ?
; 02 C
; 03 D
; 04 E
; 05 F
; 06 G
; 07 H
; 08 I
; 09 J
; 0a K
; 0b L
; 0c M
; 0d N
; 0e O
; 0f P
; 10 Q
; 11 R
; 12 S
; 13 T
; 14 U
; 15 V
; 16 <blank>
; 17 Y
; 18 <-
; 19 .
; 1a <STAR> POINTER
; 1b #
; 1c 0
; 1d 1
; 1e 2
; 1f 3
; 20 4
; 21 5
; 22 6
; 23 7
; 24 8
; 25 9

MMO_option_loop
    wai
    wai
    ldx MAPX
    inx
    stx MAPX
    ldx MAPY
    inx
    stx MAPY                    ; background scroll

    ldx a_word                  ; slowdown for gamepad. without this slowdown
    inx                         ; the star pointer would move -way- too fast.
    stx a_word
    cpx #$05
    beq MMO_resetAWord
    jmp MMO_esc_symlink
MMO_resetAWord
    ldx #$0000
    stx a_word

    lda joy1+1
    and #$08                    ; key up?
    beq MMO_curNotUp

    lda #a_byte                 ; is a_byte > 0 ?
    cmp #$00
    beq MMO_esc_symlink         ; if not then branch
    dec a_byte
    lda a_byte
    cmp #$01                    ; if a_byte == 1 then branch
    beq MMO_curTo01
    cmp #$02
    beq MMO_curTo02
    cmp #$03
    beq MMO_curTo03
    stz a_byte                  ; makes sure that the value isn't bogus
    jmp MMO_curUpDone
MMO_curTo01
    lda #$01
    sta a_byte
    jmp MMO_curUpDone
MMO_curTo02
    lda #$02
    sta a_byte
    jmp MMO_curUpDone
MMO_curTo03
    lda #$03
    sta a_byte
MMO_curUpDone
    jmp MMO_curUpdate           ; update star position

MMO_curNotUp
    lda joy1+1
    and #$04                    ; key down?
    beq MMO_esc_symlink

    lda #a_byte                 ; is a_byte = 4 ?
    cmp #$04
    beq MMO_esc_symlink         ; if not then branch
    inc a_byte
    lda a_byte
    cmp #$01                    ; if a_byte == 1 then branch
    beq MMO_curTo01_2
    cmp #$02
    beq MMO_UcurTo02
    cmp #$03
    beq MMO_UcurTo03
    lda #$04                    ; makes sure that the value isn't bogus
    sta a_byte
    jmp MMO_curDownDone
MMO_curTo01_2
    lda #$01
    sta a_byte
    jmp MMO_curDownDone
MMO_UcurTo02
    lda #$02
    sta a_byte
    jmp MMO_curDownDone
MMO_UcurTo03
    lda #$03
    sta a_byte
MMO_curDownDone
    jmp MMO_curUpdate           ; update star position

MMO_esc_symlink
    jmp MMO_menu_end

MMO_curUpdate
    jmp MMO_updatePalPriorz
MMO_curUpdatePalDone
    lda a_byte
    cmp #$00
    beq MMO_curUpd00
    cmp #$01
    beq MMO_curUpd01
    cmp #$02
    beq MMO_curUpd02
    cmp #$03
    beq MMO_curUpd03
    jmp MMO_curUpd04
MMO_curUpd00
    lda a_byte2
    cmp #$00
    bne MMO_curUpdEnde
    lda #$57
    sta SPRBUF1+SY30
    lda #$01
    sta a_byte2
;   lda #V1SFX_DING_A_LING_LOW
;   sta V1SFX
;   jsr AUDIO_PLAY_V1SFX
    jmp MMO_curUpdEnde
MMO_curUpd01
    lda #$5f
    sta SPRBUF1+SY30
;   lda #V1SFX_DING_A_LING_LOW
;   sta V1SFX
;   jsr AUDIO_PLAY_V1SFX
    stz a_byte2
    jmp MMO_curUpdEnde
MMO_curUpd02
    lda #$67
    sta SPRBUF1+SY30
;   lda #V1SFX_DING_A_LING_LOW
;   sta V1SFX
;   jsr AUDIO_PLAY_V1SFX
    stz a_byte2
    jmp MMO_curUpdEnde
MMO_curUpd03
    lda #$6f
    sta SPRBUF1+SY30
;   lda #V1SFX_DING_A_LING_LOW
;   sta V1SFX
;   jsr AUDIO_PLAY_V1SFX
    stz a_byte2
    jmp MMO_curUpdEnde
MMO_curUpd04
    lda a_byte2
    cmp #$00
    bne MMO_curUpdEnde
    lda #$7f
    sta SPRBUF1+SY30
    lda #$01
    sta a_byte2
;   lda #V1SFX_DING_A_LING_LOW
;   sta V1SFX
;   jsr AUDIO_PLAY_V1SFX
MMO_curUpdEnde
    
;---------

MMO_menu_end
    inc OBJ_Y
    lda OBJ_Y
    cmp #$10
    bne MMO_objY_not_10h
    stz OBJ_Y

MMO_objY_not_10h

    ; check button presses (start,x,a,b,y)

    lda joy1+1
    and #$10                    ; check start button
    beq MMO_me_chkX
    jmp MMO_button_confirmed
MMO_me_chkX
    lda joy1
    and #$40                    ; check x button
    beq MMO_me_chkA
    jmp MMO_button_confirmed
MMO_me_chkA
    lda joy1
    and #$80                    ; check a button
    beq MMO_me_chkB
    jmp MMO_button_confirmed
MMO_me_chkB
    lda joy1+1
    and #$80                    ; check b button
    beq MMO_me_chkY
    jmp MMO_button_confirmed
MMO_me_chkY
    lda joy1+1
    and #$40                    ; check y button
    beq MMO_menu_endloop
    jmp MMO_button_confirmed

MMO_menu_endloop
    ldx a_word
    cpx #$04
    bne MMO_menu_endloop_noLR
    jsr MMO_checkLeftRight
MMO_menu_endloop_noLR
    jmp MMO_option_loop




MMO_checkLeftRight
    lda a_byte
    cmp #$01                    ; is MUSIC being highlighted?
    beq MMO__adjust_MUS
    cmp #$02                    ; is S.E being highlighted ?
    beq MMO__adjust_SE

MMO__adjust_rts
    rts


MMO__adjust_MUS
    lda joy1+1
    and #$02                    ; check left button
    beq MMO__adjust_MUS_chkR

    lda hd_px2
    cmp #$00
    beq MMO__adjust_MUS_ende

    dec hd_px2
    stz hd_coll
    jsr MMO__update_MUS
    jmp MMO__adjust_MUS_ende

MMO__adjust_MUS_chkR
    lda joy1+1
    and #$01                    ; check right button
    beq MMO__adjust_MUS_ende

    lda hd_px2
    cmp #$16
    beq MMO__adjust_MUS_ende

    inc hd_px2
    stz hd_coll
    jsr MMO__update_MUS
    jmp MMO__adjust_MUS_ende


MMO__adjust_SE
    lda joy1+1
    and #$02                    ; check left button
    beq MMO__adjust_SE_chkR

    lda hd_cx2
    cmp #$00
    beq MMO__adjust_SE_ende

    dec hd_cx2
    jsr MMO__update_SE
    jmp MMO__adjust_SE_ende

MMO__adjust_SE_chkR
    lda joy1+1
    and #$01
    beq MMO__adjust_SE_ende     ; check right button

    lda hd_cx2
    cmp #$0b
    beq MMO__adjust_SE_ende

    inc hd_cx2
    jsr MMO__update_SE

MMO__adjust_SE_ende
    jmp MMO__adjust_rts
MMO__adjust_MUS_ende
    jmp MMO__adjust_rts




MMO__update_SE
    lda hd_cx2
    cmp #$0b
    beq MMO__update_SE_0bx
    cmp #$0a
    beq MMO__update_SE_0ax
    cmp #$09
    beq MMO__update_SE_09x
    cmp #$08
    beq MMO__update_SE_08x
    cmp #$07
    beq MMO__update_SE_07x
    cmp #$06
    beq MMO__update_SE_06x
    cmp #$05
    beq MMO__update_SE_05x
    cmp #$04
    beq MMO__update_SE_04x
    cmp #$03
    beq MMO__update_SE_03x
    cmp #$02
    beq MMO__update_SE_02
    cmp #$01
    beq MMO__update_SE_01
    jmp MMO__update_SE_00

MMO__update_SE_0bx
    jmp MMO__update_SE_0b
MMO__update_SE_0ax
    jmp MMO__update_SE_0a
MMO__update_SE_09x
    jmp MMO__update_SE_09
MMO__update_SE_08x
    jmp MMO__update_SE_08
MMO__update_SE_07x
    jmp MMO__update_SE_07
MMO__update_SE_06x
    jmp MMO__update_SE_06
MMO__update_SE_05x
    jmp MMO__update_SE_05
MMO__update_SE_04x
    jmp MMO__update_SE_04
MMO__update_SE_03x
    jmp MMO__update_SE_03


MMO__update_SE_00
    lda #$A0  ; 160    ; 0
    sta SPRBUF1+SX20
    lda #$68  ; 104
    sta SPRBUF1+SY20
    lda #$1c
    sta CURFRAME20
    ;--
    lda #$A8  ; 168    ; 0
    sta SPRBUF1+SX21
    lda #$68  ; 104
    sta SPRBUF1+SY21
    lda #$1c
    sta CURFRAME21
    rts

MMO__update_SE_01
    lda #$A0  ; 160    ; 0
    sta SPRBUF1+SX20
    lda #$68  ; 104
    sta SPRBUF1+SY20
    lda #$1c
    sta CURFRAME20
    ;--
    lda #$A8  ; 168    ; 1
    sta SPRBUF1+SX21
    lda #$68  ; 104
    sta SPRBUF1+SY21
    lda #$1d
    sta CURFRAME21
    rts

MMO__update_SE_02
    lda #$A0  ; 160    ; 0
    sta SPRBUF1+SX20
    lda #$68  ; 104
    sta SPRBUF1+SY20
    lda #$1c
    sta CURFRAME20
    ;--
    lda #$A8  ; 168    ; 2
    sta SPRBUF1+SX21
    lda #$68  ; 104
    sta SPRBUF1+SY21
    lda #$1e
    sta CURFRAME21
    rts

MMO__update_SE_03
    lda #$A0  ; 160    ; 0
    sta SPRBUF1+SX20
    lda #$68  ; 104
    sta SPRBUF1+SY20
    lda #$1c
    sta CURFRAME20
    ;--
    lda #$A8  ; 168    ; 3
    sta SPRBUF1+SX21
    lda #$68  ; 104
    sta SPRBUF1+SY21
    lda #$1f
    sta CURFRAME21
    rts

MMO__update_SE_04
    lda #$A0  ; 160    ; 0
    sta SPRBUF1+SX20
    lda #$68  ; 104
    sta SPRBUF1+SY20
    lda #$1c
    sta CURFRAME20
    ;--
    lda #$A8  ; 168    ; 4
    sta SPRBUF1+SX21
    lda #$68  ; 104
    sta SPRBUF1+SY21
    lda #$20
    sta CURFRAME21
    rts

MMO__update_SE_05
    lda #$A0  ; 160    ; 0
    sta SPRBUF1+SX20
    lda #$68  ; 104
    sta SPRBUF1+SY20
    lda #$1c
    sta CURFRAME20
    ;--
    lda #$A8  ; 168    ; 5
    sta SPRBUF1+SX21
    lda #$68  ; 104
    sta SPRBUF1+SY21
    lda #$21
    sta CURFRAME21
    rts

MMO__update_SE_06
    lda #$A0  ; 160    ; 0
    sta SPRBUF1+SX20
    lda #$68  ; 104
    sta SPRBUF1+SY20
    lda #$1c
    sta CURFRAME20
    ;--
    lda #$A8  ; 168    ; 6
    sta SPRBUF1+SX21
    lda #$68  ; 104
    sta SPRBUF1+SY21
    lda #$22
    sta CURFRAME21
    rts

MMO__update_SE_07
    lda #$A0  ; 160    ; 0
    sta SPRBUF1+SX20
    lda #$68  ; 104
    sta SPRBUF1+SY20
    lda #$1c
    sta CURFRAME20
    ;--
    lda #$A8  ; 168    ; 7
    sta SPRBUF1+SX21
    lda #$68  ; 104
    sta SPRBUF1+SY21
    lda #$23
    sta CURFRAME21
    rts

MMO__update_SE_08
    lda #$A0  ; 160    ; 0
    sta SPRBUF1+SX20
    lda #$68  ; 104
    sta SPRBUF1+SY20
    lda #$1c
    sta CURFRAME20
    ;--
    lda #$A8  ; 168    ; 8
    sta SPRBUF1+SX21
    lda #$68  ; 104
    sta SPRBUF1+SY21
    lda #$24
    sta CURFRAME21
    rts

MMO__update_SE_09
    lda #$A0  ; 160    ; 0
    sta SPRBUF1+SX20
    lda #$68  ; 104
    sta SPRBUF1+SY20
    lda #$1c
    sta CURFRAME20
    ;--
    lda #$A8  ; 168    ; 9
    sta SPRBUF1+SX21
    lda #$68  ; 104
    sta SPRBUF1+SY21
    lda #$25
    sta CURFRAME21
    rts

MMO__update_SE_0a
    lda #$A0  ; 160    ; 1
    sta SPRBUF1+SX20
    lda #$68  ; 104
    sta SPRBUF1+SY20
    lda #$1d
    sta CURFRAME20
    ;--
    lda #$A8  ; 168    ; 0
    sta SPRBUF1+SX21
    lda #$68  ; 104
    sta SPRBUF1+SY21
    lda #$1c
    sta CURFRAME21
    rts

MMO__update_SE_0b
    lda #$A0  ; 160    ; 1
    sta SPRBUF1+SX20
    lda #$68  ; 104
    sta SPRBUF1+SY20
    lda #$1d
    sta CURFRAME20
    ;--
    lda #$A8  ; 168    ; 1
    sta SPRBUF1+SX21
    lda #$68  ; 104
    sta SPRBUF1+SY21
    lda #$1d
    sta CURFRAME21
    rts


;--------------------------------------


MMO__update_MUS

    lda hd_px2
    cmp #$16
    beq MMO__update_MUS_16x

    cmp #$15
    beq MMO__update_MUS_15x
    cmp #$14
    beq MMO__update_MUS_14x
    cmp #$13
    beq MMO__update_MUS_13x
    cmp #$12
    beq MMO__update_MUS_12x
    cmp #$11
    beq MMO__update_MUS_11x
    cmp #$10
    beq MMO__update_MUS_10x
    cmp #$0f
    beq MMO__update_MUS_0fx
    cmp #$0e
    beq MMO__update_MUS_0ex
    cmp #$0d
    beq MMO__update_MUS_0dx
    cmp #$0c
    beq MMO__update_MUS_0cx
    cmp #$0b
    beq MMO__update_MUS_0bx
    cmp #$0a
    beq MMO__update_MUS_0ax
    cmp #$09
    beq MMO__update_MUS_09x
    cmp #$08
    beq MMO__update_MUS_08x
    cmp #$07
    beq MMO__update_MUS_07x
    cmp #$06
    beq MMO__update_MUS_06x
    cmp #$05
    beq MMO__update_MUS_05x
    cmp #$04
    beq MMO__update_MUS_04x
    cmp #$03
    beq MMO__update_MUS_03x
    cmp #$02
    beq MMO__update_MUS_02x
    cmp #$01
    beq MMO__update_MUS_01x
    jmp MMO__update_MUS_00x



MMO__update_MUS_16x
    jmp MMO__update_MUS_16
MMO__update_MUS_15x
    jmp MMO__update_MUS_15
MMO__update_MUS_14x
    jmp MMO__update_MUS_14
MMO__update_MUS_13x
    jmp MMO__update_MUS_13
MMO__update_MUS_12x
    jmp MMO__update_MUS_12
MMO__update_MUS_11x
    jmp MMO__update_MUS_11
MMO__update_MUS_10x
    jmp MMO__update_MUS_10
MMO__update_MUS_0fx
    jmp MMO__update_MUS_0f
MMO__update_MUS_0ex
    jmp MMO__update_MUS_0e
MMO__update_MUS_0dx
    jmp MMO__update_MUS_0d
MMO__update_MUS_0cx
    jmp MMO__update_MUS_0c
MMO__update_MUS_0bx
    jmp MMO__update_MUS_0b
MMO__update_MUS_0ax
    jmp MMO__update_MUS_0a
MMO__update_MUS_09x
    jmp MMO__update_MUS_09
MMO__update_MUS_08x
    jmp MMO__update_MUS_08
MMO__update_MUS_07x
    jmp MMO__update_MUS_07
MMO__update_MUS_06x
    jmp MMO__update_MUS_06
MMO__update_MUS_05x
    jmp MMO__update_MUS_05
MMO__update_MUS_04x
    jmp MMO__update_MUS_04
MMO__update_MUS_03x
    jmp MMO__update_MUS_03
MMO__update_MUS_02x
    jmp MMO__update_MUS_02
MMO__update_MUS_01x
    jmp MMO__update_MUS_01
MMO__update_MUS_00x
    jmp MMO__update_MUS_00


    ; rin
MMO__update_MUS_16
    lda #$A0  ; 160
    sta SPRBUF1+SX15
    lda #$60  ; 96
    sta SPRBUF1+SY15
    lda #$1e
    sta CURFRAME15     ; 2
    ;--
    lda #$A8  ; 168
    sta SPRBUF1+SX16
    lda #$60  ; 96
    sta SPRBUF1+SY16
    lda #$1e
    sta CURFRAME16     ; 2
    rts

MMO__update_MUS_15
    lda #$A0  ; 160
    sta SPRBUF1+SX15
    lda #$60  ; 96
    sta SPRBUF1+SY15
    lda #$1e
    sta CURFRAME15     ; 2
    ;--
    lda #$A8  ; 168
    sta SPRBUF1+SX16
    lda #$60  ; 96
    sta SPRBUF1+SY16
    lda #$1d
    sta CURFRAME16     ; 1
    rts

MMO__update_MUS_14
    lda #$A0  ; 160
    sta SPRBUF1+SX15
    lda #$60  ; 96
    sta SPRBUF1+SY15
    lda #$1e
    sta CURFRAME15     ; 2
    ;--
    lda #$A8  ; 168
    sta SPRBUF1+SX16
    lda #$60  ; 96
    sta SPRBUF1+SY16
    lda #$1c
    sta CURFRAME16     ; 0
    rts

MMO__update_MUS_13
    lda #$A0  ; 160
    sta SPRBUF1+SX15
    lda #$60  ; 96
    sta SPRBUF1+SY15
    lda #$1d
    sta CURFRAME15     ; 1
    ;--
    lda #$A8  ; 168
    sta SPRBUF1+SX16
    lda #$60  ; 96
    sta SPRBUF1+SY16
    lda #$25
    sta CURFRAME16     ; 9
    rts

MMO__update_MUS_12
    lda #$A0  ; 160
    sta SPRBUF1+SX15
    lda #$60  ; 96
    sta SPRBUF1+SY15
    lda #$1d
    sta CURFRAME15     ; 1
    ;--
    lda #$A8  ; 168
    sta SPRBUF1+SX16
    lda #$60  ; 96
    sta SPRBUF1+SY16
    lda #$24
    sta CURFRAME16     ; 8
    rts

MMO__update_MUS_11
    lda #$A0  ; 160
    sta SPRBUF1+SX15
    lda #$60  ; 96
    sta SPRBUF1+SY15
    lda #$1d
    sta CURFRAME15     ; 1
    ;--
    lda #$A8  ; 168
    sta SPRBUF1+SX16
    lda #$60  ; 96
    sta SPRBUF1+SY16
    lda #$23
    sta CURFRAME16     ; 7
    rts

MMO__update_MUS_10
    lda #$A0  ; 160
    sta SPRBUF1+SX15
    lda #$60  ; 96
    sta SPRBUF1+SY15
    lda #$1d
    sta CURFRAME15     ; 1
    ;--
    lda #$A8  ; 168
    sta SPRBUF1+SX16
    lda #$60  ; 96
    sta SPRBUF1+SY16
    lda #$22
    sta CURFRAME16     ; 6
    rts

MMO__update_MUS_0f
    lda #$A0  ; 160
    sta SPRBUF1+SX15
    lda #$60  ; 96
    sta SPRBUF1+SY15
    lda #$1d
    sta CURFRAME15     ; 1
    ;--
    lda #$A8  ; 168
    sta SPRBUF1+SX16
    lda #$60  ; 96
    sta SPRBUF1+SY16
    lda #$21
    sta CURFRAME16     ; 5
    rts

MMO__update_MUS_0e
    lda #$A0  ; 160
    sta SPRBUF1+SX15
    lda #$60  ; 96
    sta SPRBUF1+SY15
    lda #$1d
    sta CURFRAME15     ; 1
    ;--
    lda #$A8  ; 168
    sta SPRBUF1+SX16
    lda #$60  ; 96
    sta SPRBUF1+SY16
    lda #$20
    sta CURFRAME16     ; 4
    rts

MMO__update_MUS_0d
    lda #$A0  ; 160
    sta SPRBUF1+SX15
    lda #$60  ; 96
    sta SPRBUF1+SY15
    lda #$1d
    sta CURFRAME15     ; 1
    ;--
    lda #$A8  ; 168
    sta SPRBUF1+SX16
    lda #$60  ; 96
    sta SPRBUF1+SY16
    lda #$1f
    sta CURFRAME16     ; 3
    rts

MMO__update_MUS_0c
    lda #$A0  ; 160
    sta SPRBUF1+SX15
    lda #$60  ; 96
    sta SPRBUF1+SY15
    lda #$1d
    sta CURFRAME15     ; 1
    ;--
    lda #$A8  ; 168
    sta SPRBUF1+SX16
    lda #$60  ; 96
    sta SPRBUF1+SY16
    lda #$1e
    sta CURFRAME16     ; 2
    rts

MMO__update_MUS_0b
    lda #$A0  ; 160
    sta SPRBUF1+SX15
    lda #$60  ; 96
    sta SPRBUF1+SY15
    lda #$1d
    sta CURFRAME15     ; 1
    ;--
    lda #$A8  ; 168
    sta SPRBUF1+SX16
    lda #$60  ; 96
    sta SPRBUF1+SY16
    lda #$1d
    sta CURFRAME16     ; 1
    rts

MMO__update_MUS_0a
    lda #$A0  ; 160
    sta SPRBUF1+SX15
    lda #$60  ; 96
    sta SPRBUF1+SY15
    lda #$1d
    sta CURFRAME15     ; 1
    ;--
    lda #$A8  ; 168
    sta SPRBUF1+SX16
    lda #$60  ; 96
    sta SPRBUF1+SY16
    lda #$1c
    sta CURFRAME16     ; 0
    rts

MMO__update_MUS_09
    lda #$A0  ; 160
    sta SPRBUF1+SX15
    lda #$60  ; 96
    sta SPRBUF1+SY15
    lda #$1c
    sta CURFRAME15     ; 0
    ;--
    lda #$A8  ; 168
    sta SPRBUF1+SX16
    lda #$60  ; 96
    sta SPRBUF1+SY16
    lda #$25
    sta CURFRAME16     ; 9
    rts


MMO__update_MUS_08
    lda #$A0  ; 160
    sta SPRBUF1+SX15
    lda #$60  ; 96
    sta SPRBUF1+SY15
    lda #$1c
    sta CURFRAME15     ; 0
    ;--
    lda #$A8  ; 168
    sta SPRBUF1+SX16
    lda #$60  ; 96
    sta SPRBUF1+SY16
    lda #$24
    sta CURFRAME16     ; 8
    rts

MMO__update_MUS_07
    lda #$A0  ; 160
    sta SPRBUF1+SX15
    lda #$60  ; 96
    sta SPRBUF1+SY15
    lda #$1c
    sta CURFRAME15     ; 0
    ;--
    lda #$A8  ; 168
    sta SPRBUF1+SX16
    lda #$60  ; 96
    sta SPRBUF1+SY16
    lda #$23
    sta CURFRAME16     ; 7
    rts

MMO__update_MUS_06
    lda #$A0  ; 160
    sta SPRBUF1+SX15
    lda #$60  ; 96
    sta SPRBUF1+SY15
    lda #$1c
    sta CURFRAME15     ; 0
    ;--
    lda #$A8  ; 168
    sta SPRBUF1+SX16
    lda #$60  ; 96
    sta SPRBUF1+SY16
    lda #$22
    sta CURFRAME16     ; 6
    rts

MMO__update_MUS_05
    lda #$A0  ; 160
    sta SPRBUF1+SX15
    lda #$60  ; 96
    sta SPRBUF1+SY15
    lda #$1c
    sta CURFRAME15     ; 0
    ;--
    lda #$A8  ; 168
    sta SPRBUF1+SX16
    lda #$60  ; 96
    sta SPRBUF1+SY16
    lda #$21
    sta CURFRAME16     ; 5
    rts

MMO__update_MUS_04
    lda #$A0  ; 160
    sta SPRBUF1+SX15
    lda #$60  ; 96
    sta SPRBUF1+SY15
    lda #$1c
    sta CURFRAME15     ; 0
    ;--
    lda #$A8  ; 168
    sta SPRBUF1+SX16
    lda #$60  ; 96
    sta SPRBUF1+SY16
    lda #$20
    sta CURFRAME16     ; 4
    rts

MMO__update_MUS_03
    lda #$A0  ; 160
    sta SPRBUF1+SX15
    lda #$60  ; 96
    sta SPRBUF1+SY15
    lda #$1c
    sta CURFRAME15     ; 0
    ;--
    lda #$A8  ; 168
    sta SPRBUF1+SX16
    lda #$60  ; 96
    sta SPRBUF1+SY16
    lda #$1f
    sta CURFRAME16     ; 3
    rts

MMO__update_MUS_02
    lda #$A0  ; 160
    sta SPRBUF1+SX15
    lda #$60  ; 96
    sta SPRBUF1+SY15
    lda #$1c
    sta CURFRAME15     ; 0
    ;--
    lda #$A8  ; 168
    sta SPRBUF1+SX16
    lda #$60  ; 96
    sta SPRBUF1+SY16
    lda #$1e
    sta CURFRAME16     ; 2
    rts

MMO__update_MUS_01
    lda #$A0  ; 160
    sta SPRBUF1+SX15
    lda #$60  ; 96
    sta SPRBUF1+SY15
    lda #$1c
    sta CURFRAME15     ; 0
    ;--
    lda #$A8  ; 168
    sta SPRBUF1+SX16
    lda #$60  ; 96
    sta SPRBUF1+SY16
    lda #$1d
    sta CURFRAME16     ; 1
    rts

MMO__update_MUS_00
    lda #$A0  ; 160    ; 0
    sta SPRBUF1+SX15
    lda #$60  ; 96
    sta SPRBUF1+SY15
    lda #$1c
    sta CURFRAME15
    ;--
    lda #$A8  ; 168    ; 0
    sta SPRBUF1+SX16
    lda #$60  ; 96
    sta SPRBUF1+SY16
    lda #$1c
    sta CURFRAME16
    rts


;============-
MMO_updatePalPriorz
    lda a_byte
    cmp #$00
    beq MMO_uPPz_00x
    cmp #$01
    beq MMO_uPPz_01x
    cmp #$02
    beq MMO_uPPz_02x
    cmp #$03
    beq MMO_uPPz_03x
    jmp MMO_uPPz_04

MMO_uPPz_00x
    jmp MMO_uPPz_00
MMO_uPPz_01x
    jmp MMO_uPPz_01
MMO_uPPz_02x
    jmp MMO_uPPz_02
MMO_uPPz_03x
    jmp MMO_uPPz_03

MMO_uPPz_04
    lda #%00110010              ; dark colour
    sta SPRBUF1+SPRIORITY
    sta SPRBUF1+SPRIORITY1
    sta SPRBUF1+SPRIORITY2
    sta SPRBUF1+SPRIORITY3
    sta SPRBUF1+SPRIORITY4
    sta SPRBUF1+SPRIORITY5
    sta SPRBUF1+SPRIORITY6
    sta SPRBUF1+SPRIORITY7
    sta SPRBUF1+SPRIORITY8
    sta SPRBUF1+SPRIORITY9
    ;--
    sta SPRBUF1+SPRIORITY10
    sta SPRBUF1+SPRIORITY11
    sta SPRBUF1+SPRIORITY12
    sta SPRBUF1+SPRIORITY13
    sta SPRBUF1+SPRIORITY14
    sta SPRBUF1+SPRIORITY15
    sta SPRBUF1+SPRIORITY16
    sta SPRBUF1+SPRIORITY27
    ;--
    sta SPRBUF1+SPRIORITY17
    sta SPRBUF1+SPRIORITY18
    sta SPRBUF1+SPRIORITY19
    sta SPRBUF1+SPRIORITY20
    sta SPRBUF1+SPRIORITY21
    sta SPRBUF1+SPRIORITY28
    ;--
    sta SPRBUF1+SPRIORITY22
    sta SPRBUF1+SPRIORITY23
    sta SPRBUF1+SPRIORITY24
    sta SPRBUF1+SPRIORITY25
    ;--
    lda #%00110000              ; golden colour
    sta SPRBUF1+SPRIORITY26
    jmp MMO_curUpdatePalDone

MMO_uPPz_03
    lda #%00110010              ; dark colour
    sta SPRBUF1+SPRIORITY
    sta SPRBUF1+SPRIORITY1
    sta SPRBUF1+SPRIORITY2
    sta SPRBUF1+SPRIORITY3
    sta SPRBUF1+SPRIORITY4
    sta SPRBUF1+SPRIORITY5
    sta SPRBUF1+SPRIORITY6
    sta SPRBUF1+SPRIORITY7
    sta SPRBUF1+SPRIORITY8
    sta SPRBUF1+SPRIORITY9
    ;--
    sta SPRBUF1+SPRIORITY10
    sta SPRBUF1+SPRIORITY11
    sta SPRBUF1+SPRIORITY12
    sta SPRBUF1+SPRIORITY13
    sta SPRBUF1+SPRIORITY14
    sta SPRBUF1+SPRIORITY15
    sta SPRBUF1+SPRIORITY16
    sta SPRBUF1+SPRIORITY27
    ;--
    sta SPRBUF1+SPRIORITY17
    sta SPRBUF1+SPRIORITY18
    sta SPRBUF1+SPRIORITY19
    sta SPRBUF1+SPRIORITY20
    sta SPRBUF1+SPRIORITY21
    sta SPRBUF1+SPRIORITY28
    ;--
    lda #%00110000              ; golden colour
    sta SPRBUF1+SPRIORITY22
    sta SPRBUF1+SPRIORITY23
    sta SPRBUF1+SPRIORITY24
    sta SPRBUF1+SPRIORITY25
    ;--
    lda #%00110010              ; dark colour
    sta SPRBUF1+SPRIORITY26
    jmp MMO_curUpdatePalDone

MMO_uPPz_02
    lda #%00110010              ; dark colour
    sta SPRBUF1+SPRIORITY
    sta SPRBUF1+SPRIORITY1
    sta SPRBUF1+SPRIORITY2
    sta SPRBUF1+SPRIORITY3
    sta SPRBUF1+SPRIORITY4
    sta SPRBUF1+SPRIORITY5
    sta SPRBUF1+SPRIORITY6
    sta SPRBUF1+SPRIORITY7
    sta SPRBUF1+SPRIORITY8
    sta SPRBUF1+SPRIORITY9
    ;--
    sta SPRBUF1+SPRIORITY10
    sta SPRBUF1+SPRIORITY11
    sta SPRBUF1+SPRIORITY12
    sta SPRBUF1+SPRIORITY13
    sta SPRBUF1+SPRIORITY14
    sta SPRBUF1+SPRIORITY15
    sta SPRBUF1+SPRIORITY16
    sta SPRBUF1+SPRIORITY27
    ;--
    lda #%00110000              ; golden colour
    sta SPRBUF1+SPRIORITY17
    sta SPRBUF1+SPRIORITY18
    sta SPRBUF1+SPRIORITY19
    sta SPRBUF1+SPRIORITY20
    sta SPRBUF1+SPRIORITY21
    sta SPRBUF1+SPRIORITY28
    ;--
    lda #%00110010              ; dark colour
    sta SPRBUF1+SPRIORITY22
    sta SPRBUF1+SPRIORITY23
    sta SPRBUF1+SPRIORITY24
    sta SPRBUF1+SPRIORITY25
    ;--
    sta SPRBUF1+SPRIORITY26
    jmp MMO_curUpdatePalDone

MMO_uPPz_01
    lda #%00110010              ; dark colour
    sta SPRBUF1+SPRIORITY
    sta SPRBUF1+SPRIORITY1
    sta SPRBUF1+SPRIORITY2
    sta SPRBUF1+SPRIORITY3
    sta SPRBUF1+SPRIORITY4
    sta SPRBUF1+SPRIORITY5
    sta SPRBUF1+SPRIORITY6
    sta SPRBUF1+SPRIORITY7
    sta SPRBUF1+SPRIORITY8
    sta SPRBUF1+SPRIORITY9
    ;--
    lda #%00110000              ; golden colour
    sta SPRBUF1+SPRIORITY10
    sta SPRBUF1+SPRIORITY11
    sta SPRBUF1+SPRIORITY12
    sta SPRBUF1+SPRIORITY13
    sta SPRBUF1+SPRIORITY14
    sta SPRBUF1+SPRIORITY15
    sta SPRBUF1+SPRIORITY16
    sta SPRBUF1+SPRIORITY27
    ;--
    lda #%00110010              ; dark colour
    sta SPRBUF1+SPRIORITY17
    sta SPRBUF1+SPRIORITY18
    sta SPRBUF1+SPRIORITY19
    sta SPRBUF1+SPRIORITY20
    sta SPRBUF1+SPRIORITY21
    sta SPRBUF1+SPRIORITY28
    ;--
    sta SPRBUF1+SPRIORITY22
    sta SPRBUF1+SPRIORITY23
    sta SPRBUF1+SPRIORITY24
    sta SPRBUF1+SPRIORITY25
    ;--
    sta SPRBUF1+SPRIORITY26
    jmp MMO_curUpdatePalDone

MMO_uPPz_00
    lda #%00110000              ; golden colour
    sta SPRBUF1+SPRIORITY
    sta SPRBUF1+SPRIORITY1
    sta SPRBUF1+SPRIORITY2
    sta SPRBUF1+SPRIORITY3
    sta SPRBUF1+SPRIORITY4
    sta SPRBUF1+SPRIORITY5
    sta SPRBUF1+SPRIORITY6
    sta SPRBUF1+SPRIORITY7
    sta SPRBUF1+SPRIORITY8
    sta SPRBUF1+SPRIORITY9
    ;--
    lda #%00110010              ; dark colour
    sta SPRBUF1+SPRIORITY10
    sta SPRBUF1+SPRIORITY11
    sta SPRBUF1+SPRIORITY12
    sta SPRBUF1+SPRIORITY13
    sta SPRBUF1+SPRIORITY14
    sta SPRBUF1+SPRIORITY15
    sta SPRBUF1+SPRIORITY16
    sta SPRBUF1+SPRIORITY27
    ;--
    sta SPRBUF1+SPRIORITY17
    sta SPRBUF1+SPRIORITY18
    sta SPRBUF1+SPRIORITY19
    sta SPRBUF1+SPRIORITY20
    sta SPRBUF1+SPRIORITY21
    sta SPRBUF1+SPRIORITY28
    ;--
    sta SPRBUF1+SPRIORITY22
    sta SPRBUF1+SPRIORITY23
    sta SPRBUF1+SPRIORITY24
    sta SPRBUF1+SPRIORITY25
    ;--
    sta SPRBUF1+SPRIORITY26
    jmp MMO_curUpdatePalDone


;================================================================


iTotallyDislikeMyOwnCode ;-(
    lda hd_coll                ; is it okay to load the music/tune?
    cmp #$01
    beq noChangeNoPlayTune
    jsr MMO_playTheTune_misterDJ
noChangeNoPlayTune
    jmp minusminus


; MMO_button_confirmed ~ this routine gets jumped to when one of the
;                        following keys have pressed during the main
;                        menu: start, x, a, b, y.

MMO_button_confirmed
    lda a_byte
    cmp #$00
    beq sym_bConfKa_firstChoice
    cmp #$01
    beq iTotallyDislikeMyOwnCode
    cmp #$02
    bne MMO_bConfKa_options
    ldx a_word
    cpx #$03
    bne minusminus
    jmp MMO_playThe_SE_misterDJ

;   lda a_byte
;   cmp #$00
;   beq sym_bConfKa_firstChoice
;   cmp #$01
;   beq MMO_playTheTune_misterDJ
;   cmp #$02
    
    

minusminus
    jmp MMO_menu_endloop_noLR
sym_bConfKa_firstChoice
    jmp MMO_bConfKa_firstChoice

MMO_bConfKa_options
    lda a_byte
    cmp #$03
    bne plusspluss
keyskeyskeys
    lda #01                    ; make the word 'KEYS' blink
    sta a_byte
    jsr MMO_SNEZPAD_CONF

    lda #$80
    sta $2100
    LOAD_PAL MMENU_BG_PAL
    wai
    LOAD_BLOCK2VRAM MMENU_BG1_DAT,$0000,$2000
    wai
    wai
    LOAD_BLOCK2VRAM MMENU_BG1_GFX,$1000,$0800
    wai
    wai
    LOAD_BLOCK2VRAM MMENU_BG2_GFX,$2000,$1800
    wai
    wai
    LOAD_BLOCK2VRAM MMENU_SPR_GFX,$6000,$2000    ; one 32x32 sprite (star)
    wai
    wai

    jmp MM_option

plusspluss
    lda #$02                   ; make the <- (arrow) blink
    sta a_byte
    jmp MMO_bConfKa_FIN
;   jsr MM_FadeOut_inside
;   jsr MM_undraw_menu_box
;   jmp MENU_MAIN_skipMusChange

MMO_bConfKa_firstChoice
    stz a_byte                 ; make '???' blink
MMO_bConfKa_FIN
    jsr MM_FadeOut_inside
    jsr MM_undraw_menu_box

    lda a_byte
    cmp #$00
    bne MMO_skipSecretStuff
    lda OBJ_Y

    ; 01 02 04 06 07 0c 0d 0e

    cmp #$00
    beq MMO_RESET
    cmp #$09
    beq MMO_RESET
    cmp #$0f
    beq MMO_message
    cmp #$03
    beq MMO_message
    cmp #$08
    beq MMO_message
    cmp #$0a
    beq MMO_message
    cmp #$05
    beq MMO_goKEYS
    cmp #$0b
    beq MMO_goKEYS

MMO_skipSecretStuff
    lda hd_py2                 ; has the player been playing around with the
    cmp #$00                   ; MUSIC#-thingie in the option/stuff section?
    bne MMO_bConfKa_FIN2
    jmp MENU_MAIN_skipMusChange
MMO_bConfKa_FIN2
    jmp MENU_MAIN


;--------------

MMO_RESET
    lda #$80
    sta $2100
    jsl sym_MUS_NO_SONG
    lda #$ff
    sta SPRBUF2
    jml SJEKK_DEN_KUULE_LOGOEN_ASSE
MMO_message
    jsl bH13_MESSAGE_FROM_CREATOR
    jmp MENU_MAIN
MMO_goKEYS
    lda #$80
    sta $2100
    jmp keyskeyskeys


;----------------------------------------------------------------


MMO_playThe_SE_misterDJ
    lda hd_cx2
    cmp #$00
    beq MMO_pTSEmDJ_S00
    cmp #$01
    beq MMO_pTSEmDJ_S01
    cmp #$02
    beq MMO_pTSEmDJ_S02
    cmp #$03
    beq MMO_pTSEmDJ_S03
    cmp #$04
    beq MMO_pTSEmDJ_S04
    cmp #$05
    beq MMO_pTSEmDJ_S05
    cmp #$06
    beq MMO_pTSEmDJ_S06
    cmp #$07
    beq MMO_pTSEmDJ_S07
    cmp #$08
    beq MMO_pTSEmDJ_S08
    cmp #$09
    beq MMO_pTSEmDJ_S09
    cmp #$0a
    beq MMO_pTSEmDJ_S0a
    cmp #$0b
    beq MMO_pTSEmDJ_S0b

MMO_pTSEmDJ_S00
    jmp MMO_menu_endloop_noLR
MMO_pTSEmDJ_S01
    lda #V0SFX_EXPLOSION
    sta V0SFX
    jsr AUDIO_PLAY_V0SFX
    jmp MMO_menu_endloop_noLR
MMO_pTSEmDJ_S02
    lda #V0SFX_GUN_FIRE
    sta V0SFX
    jsr AUDIO_PLAY_V0SFX
    jmp MMO_menu_endloop_noLR
MMO_pTSEmDJ_S03
    lda #V0SFX_GLASS_SMASH
    sta V0SFX
    jsr AUDIO_PLAY_V0SFX
    jmp MMO_menu_endloop_noLR
MMO_pTSEmDJ_S04
    lda #V0SFX_INTERFERENCE
    sta V0SFX
    jsr AUDIO_PLAY_V0SFX
    jmp MMO_menu_endloop_noLR
MMO_pTSEmDJ_S05
    lda #V0SFX_DEEP_THUMP
    sta V0SFX
    jsr AUDIO_PLAY_V0SFX
    jmp MMO_menu_endloop_noLR
MMO_pTSEmDJ_S06
    lda #V1SFX_PING_HIGH
    sta V1SFX
    jsr AUDIO_PLAY_V1SFX
    jmp MMO_menu_endloop_noLR
MMO_pTSEmDJ_S07
    lda #V1SFX_PING_LOW
    sta V1SFX
    jsr AUDIO_PLAY_V1SFX
    jmp MMO_menu_endloop_noLR
MMO_pTSEmDJ_S08
    lda #V1SFX_DING_A_LING_HIGH
    sta V1SFX
    jsr AUDIO_PLAY_V1SFX
    jmp MMO_menu_endloop_noLR
MMO_pTSEmDJ_S09
    lda #V1SFX_DING_A_LING_LOW
    sta V1SFX
    jsr AUDIO_PLAY_V1SFX
    jmp MMO_menu_endloop_noLR
MMO_pTSEmDJ_S0a
    lda #V1SFX_LASER_FIRE
    sta V1SFX
    jsr AUDIO_PLAY_V1SFX
    jmp MMO_menu_endloop_noLR
MMO_pTSEmDJ_S0b
    lda #V1SFX_SQUISH
    sta V1SFX
    jsr AUDIO_PLAY_V1SFX
    jmp MMO_menu_endloop_noLR


;==================

MMO_playTheTune_misterDJ

    lda #$01
    sta hd_py2                 ; the music has been changed.
    sta hd_coll                ; no multiple loads allowed

    lda hd_px2
    cmp #$16
    beq MMO_pTTmrDJ_16sym
    cmp #$15
    beq MMO_pTTmrDJ_15sym
    cmp #$14
    beq MMO_pTTmrDJ_14sym
    cmp #$13
    beq MMO_pTTmrDJ_13sym
    cmp #$12
    beq MMO_pTTmrDJ_12sym
    cmp #$11
    beq MMO_pTTmrDJ_11sym
    cmp #$10
    beq MMO_pTTmrDJ_10sym
    cmp #$0f
    beq MMO_pTTmrDJ_0fsym
    cmp #$0e
    beq MMO_pTTmrDJ_0esym
    cmp #$0d
    beq MMO_pTTmrDJ_0dsym
    cmp #$0c
    beq MMO_pTTmrDJ_0csym
    cmp #$0b
    beq MMO_pTTmrDJ_0bsym
    cmp #$0a
    beq MMO_pTTmrDJ_0asym
    cmp #$09
    beq MMO_pTTmrDJ_09
    cmp #$08
    beq MMO_pTTmrDJ_08
    cmp #$07
    beq MMO_pTTmrDJ_07
    cmp #$06
    beq MMO_pTTmrDJ_06
    cmp #$05
    beq MMO_pTTmrDJ_05
    cmp #$04
    beq MMO_pTTmrDJ_04
    cmp #$03
    beq MMO_pTTmrDJ_03
    cmp #$02
    beq MMO_pTTmrDJ_02
    cmp #$01
    beq MMO_pTTmrDJ_01
    jmp MMO_pTTmrDJ_00

MMO_pTTmrDJ_16sym
    jmp MMO_pTTmrDJ_16
MMO_pTTmrDJ_15sym
    jmp MMO_pTTmrDJ_15
MMO_pTTmrDJ_14sym
    jmp MMO_pTTmrDJ_14
MMO_pTTmrDJ_13sym
    jmp MMO_pTTmrDJ_13
MMO_pTTmrDJ_12sym
    jmp MMO_pTTmrDJ_12
MMO_pTTmrDJ_11sym
    jmp MMO_pTTmrDJ_11
MMO_pTTmrDJ_10sym
    jmp MMO_pTTmrDJ_10
MMO_pTTmrDJ_0fsym
    jmp MMO_pTTmrDJ_0f
MMO_pTTmrDJ_0esym
    jmp MMO_pTTmrDJ_0e
MMO_pTTmrDJ_0dsym
    jmp MMO_pTTmrDJ_0d
MMO_pTTmrDJ_0csym
    jmp MMO_pTTmrDJ_0c
MMO_pTTmrDJ_0bsym
    jmp MMO_pTTmrDJ_0b
MMO_pTTmrDJ_0asym
    jmp MMO_pTTmrDJ_0a



MMO_pTTmrDJ_09
    jsl sym_MUS_SONG_ICE
    rts
MMO_pTTmrDJ_08
    jsl sym_MUS_SONG_GRADIUS
    rts
MMO_pTTmrDJ_07
    jsl sym_MUS_SONG_C2GO
    rts
MMO_pTTmrDJ_06
    jsl sym_MUS_SONG_C1GO
    rts
MMO_pTTmrDJ_05
    jsl sym_MUS_SONG_BOWSER
    rts
MMO_pTTmrDJ_04
    jsl sym_MUS_SONG_AXELAY
    rts
MMO_pTTmrDJ_03
    jsl sym_MUS_SONG_AWOLF
    rts
MMO_pTTmrDJ_02
    jsl sym_MUS_SONG_ATOMIC
    rts
MMO_pTTmrDJ_01
    jsl sym_MUS_SONG_ASCHE
    rts
MMO_pTTmrDJ_0a
    jsl sym_MUS_SONG_LUIGI
    stz hd_py2
    rts
MMO_pTTmrDJ_0b
    jsl sym_MUS_SONG_SPOOKIE
    rts
MMO_pTTmrDJ_0c
    jsl sym_MUS_SONG_UNSQUAD
    rts
MMO_pTTmrDJ_0d
    jsl sym_MUS_SONG_XENON
    rts
MMO_pTTmrDJ_0e
    jsl sym_MUS_SONG_GOKU
    rts
MMO_pTTmrDJ_0f
    jsl sym_MUS_SONG_MERRY
    rts
MMO_pTTmrDJ_10
    jsl sym_MUS_SONG_METLM
    rts
MMO_pTTmrDJ_11
    jsl sym_MUS_SONG_SEASIA
    rts
MMO_pTTmrDJ_12
    jsl sym_MUS_SONG_RUD21
    rts
MMO_pTTmrDJ_13
    jsl sym_MUS_SONG_FZERO
    rts
MMO_pTTmrDJ_14
    jsl sym_MUS_SONG_GOOP
    rts
MMO_pTTmrDJ_15
    jsl sym_MUS_SONG_SHERB
    rts
MMO_pTTmrDJ_16
    jsl sym_MUS_SONG_PENNY
    rts
MMO_pTTmrDJ_00
    jsl sym_MUS_NO_SONG
    rts

;=========================================================
;=========================================================
;=========================================================
;=========================================================


MMO_SNEZPAD_CONF
    jsr MM_FadeOut_inside
    jsr MM_undraw_menu_box
    jsr INIT_VIDEO_04

    lda #$8F
    sta $2100

    lda #%00000001
    sta $212c                  ; bg#1 enable only

    LOAD_PAL BG1_SNEZPAD_PAL
    wai
    LOAD_BLOCK2VRAM BG1_SNEZPAD_MAP,$0000,$2000
    wai
    wai
    LOAD_BLOCK2VRAM BG1_SNEZPAD_PIC,$2000,$6000
    wai
    wai

    ldx #$0000
    stx MAPX
    ldx #$ffff
    stx MAPY

    jsr MM_undraw_menu_box

    jsl bH13_FADE_IN_MOSAIC_macro

snezploop
    wai

    ; check button presses (start,x,a,b,y)

    lda joy1+1
    and #$10                    ; check start button
    beq padMM_me_chkX
    jmp snezploopend
padMM_me_chkX
    lda joy1
    and #$40                    ; check x button
    beq padMM_me_chkA
    jmp snezploopend
padMM_me_chkA
    lda joy1
    and #$80                    ; check a button
    beq padMM_me_chkB
    jmp snezploopend
padMM_me_chkB
    lda joy1+1
    and #$80                    ; check b button
    beq padMM_me_chkY
    jmp snezploopend
padMM_me_chkY
    lda joy1+1
    and #$40                    ; check y button
    beq snezploopOneMoreTime
    jmp snezploopend
snezploopOneMoreTime
    jmp snezploop
snezploopend
    jsl sym_SFX_LASER_FIRE
    rts
