; gameover.asm

GameOver:

    	;xor a
    	;ld hl, wOAMBuffer
    	;ld bc, 8*5*4
    	;call FillMemory

    call DelayFrame
    call HideSprites
    			;call CutToBlack
    call $2233    ;StopAllMusic
    call LoadGameOverGfx

    			;call ResetPalettes

    ld a, $80
    coord hl, 0, 0
    ld bc, 20 * 18
    call FillMemory
    
    coord hl, 7, 3
    ld e, $A4
    ld bc, DebbieGfxInstructions
.drawDebbieLoop
    ld a, [bc]
    ld d, a
    call DrawIncTiles

    inc bc
    ld a, [bc]
    cp $FF
    jr z, .exitDrawDebbieLoop

    push bc
    ld b, 0
    ld c, a
    add hl, bc
    pop bc
    inc bc
    jr .drawDebbieLoop

.exitDrawDebbieLoop
    
    coord hl, $00, $0B
    lb bc, 5, 18
    
    push hl
    ld a, $9C
    ld [hli], a
    inc a ; ─
    call NPlaceChar
    inc a ; ┐
    ld [hl], a
    pop hl

    ld de, SCREEN_WIDTH
    add hl, de

.next
    push hl
    ld a, $9F
    ld [hli], a
    ld a, $81
    call NPlaceChar
    ld [hl], $A0
    pop hl

    ld de, SCREEN_WIDTH
    add hl, de
    dec b
    jr nz, .next
    
    ld a, $A1
    ld [hli], a
    inc a
    call NPlaceChar
    inc a
    ld [hl], a

    
    coord hl, $01, $0E
    lb de, $05, $92
    call DrawIncTiles

    			;coord hl, $06, $0E
    lb de, $08, $82
    call DrawIncTiles

    lb de, $05, $92
    call DrawIncTiles

    coord hl, $01, $0F
    lb de, $05, $97
    call DrawIncTiles

    			;coord hl, $06, $0E
    lb de, $08, $8A
    call DrawIncTiles

    lb de, $05, $97
    call DrawIncTiles
    

    				;coord hl, $06, $0F
    					;lb de, $08, $8A
    				;ld d, $08
    				;call DrawIncTiles

    ld a, $98
    ldh [$FFBD], a
    ldh [$FFBA], a

    call Delay3

    xor a
    ldh [$FFBA], a
    ldh [$FFAE], a
    ldh [$FFAF], a

    ld c, $44
    call DelayFrames

    ld a, 160
    ldh [$FFB0], a

    call GBFadeInFromBlack

    call PlaySong_M2

.forever
    jr .forever
    
    

DebbieGfxInstructions:
    db 5, SCREEN_WIDTH - 5
    db 7, SCREEN_WIDTH - 7
    db 3, 1, 3, SCREEN_WIDTH - 7
    db 7, SCREEN_WIDTH - 7
    db 2, 1, 4, SCREEN_WIDTH - 7
    db 2, 1, 4, SCREEN_WIDTH - 7
    db 2, 1, 3, $FF

DrawIncTiles:
    ld a, e
.loop
    ld [hli], a
    inc a
    dec d
    jr nz, .loop
    ld e, a
    ret