;=================================================================
; [GAMEOVER.INC] -- Game over, baby!
;=================================================================


GAME_OVER
    lda #$00
    sta $2106

    jsr INIT_VIDEO_04

    lda #$8F
    sta $2100

    jsl bH13_DEINIT_doThe50p

    LOAD_PAL BG_GOVERPAL
    wai
    wai
    LOAD_BLOCK2VRAM BG_GOVERDAT,$0000,$2000
    wai
    wai
    wai
    LOAD_BLOCK2VRAM BG_GOVERGFX,$2000,$6000
    wai
    wai
    wai
    LOAD_BLOCK2VRAM SPR_SPLASH,$6000,$2000
    wai
    wai
    wai

    lda #%00000001             ; disable bg#2-4 + oam
    sta $212C

    ldx #$00
    stx MAPX
    stx MAPY

    lda #SONG_C2G0             ; this song does not auto-repeat, so
    jsr AUDIO_PLAY_SONG        ; there is no need to time it. :)
    wai

    lda #$00
    sta $2100
    FADE_IN

    ldx #$0000
    stx a_word
    stz a_byte

-   wai

    inc a_byte
    lda a_byte
    cmp #$02
    bne +
    ldx a_word
    inx
    stx a_word
    stz a_byte

+   ldx a_word
    cpx #$C8
    beq +

    jmp -

+   ldx #$0000
    stx a_word
    stz a_byte

-   wai

    inc a_byte
    lda a_byte
    cmp #$01
    bne +
    ldx a_word
    inx
    stx a_word
    stz a_byte

+   ldx MAPY
    ldy a_word
    cpy #$08
    bmi gover_dex
    cpy #$12
    bmi gover_dexx
    jmp gover_dexxx
gover_dex_done
    stx MAPY

    ldx a_word
    cpx #$50
    bpl gover_fadeout

    jmp -

gover_dexxx
    dex
gover_dexx
    dex
gover_dex
    phx
    ldx MAPX
    dex
    stx MAPX
    plx
    dex
    jmp gover_dex_done

gover_fadeout
    jsl sym_SFX_GUN_FIRE
    jsl bH13_FADE_OUT_macro
    stz a_byte
-   wai                        ; 20 times wai = a decent delay
    inc a_byte
    lda a_byte
    cmp #$14
    beq +
    jmp -

+   lda #%00011111
    sta $212C

    jsr INIT_SPRITES

    stz SPRBUF1+SPRIORITY12    ; reset vh-flips and/or priorities in general.
    stz SPRBUF1+SPRIORITY13
    stz SPRBUF1+SPRIORITY14
    stz SPRBUF1+SPRIORITY15
    stz SPRBUF1+SPRIORITY16
    stz SPRBUF1+SPRIORITY17
    stz SPRBUF1+SPRIORITY18

    GOTOXY 0,0                 ; clean up bg#2
    jsr gover_uuuu
    GOTOXY 1,0
    jsr gover_uuuu
    GOTOXY 2,0
    jsr gover_uuuu
    GOTOXY 3,0
    jsr gover_uuuu
    GOTOXY 1,0
    jsr gover_uuuu
    GOTOXY 2,0
    jsr gover_uuuu
    jmp +

gover_uuuu
    PRINTS "uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu"
    rts

+   jsl bH13_MSG_ENDSCORE
    lda #NO_SONG
    sta MUSIC
    jsr AUDIO_PLAY_SONG

    stz OBJ_HIT                 ; Jikkyou Parodius easter-egg

    jmp SJEKK_DEN_KUULE_LOGOEN_ASSE
