    .data
    .bank 0        
    .org $FFF6

    .dw irq_2                    ; irq 2
    .dw irq_1                    ; irq 1
    .dw irq_timer                ; timer
    .dw irq_nmi                  ; nmi
    .dw irq_reset                ; reset

    .code
    .bank 0
    .org $E000

    ; copied from the output of the bpe encoder
BPE_COMPRESSED_STRING_LEN=29
BPE_UNCOMPRESSED_STRING_LEN=49
BPE_PAIR_COUNT=7
BPE_STACK=3 ; beta test
ENCODED_CHAR_MIN=$7b
ENCODED_CHAR_MAX=$ba

_bpe_first: 
        .db $41, $42, $45, $46, $7d, $46, $7b
_bpe_second: 
        .db $42, $45, $44, $7c, $46, $44, $7b
_bpe_encoded:
        .db $7b, $43, $44, $45, $7e, $43, $7f, $7b
        .db $7c, $41, $80, $41, $43, $45, $42, $80
        .db $81, $7f, $43, $46, $7d, $43, $41, $7e
        .db $42, $44, $42, $43, $81

irq_reset:
    sei                         ; disable interrupts
    csh                         ; select the 7.16 MHz clock
    cld                         ; clear the decimal flag
    ldx    #$FF                 ; initialize the stack pointer
    txs
    lda    #$FF                 ; map the I/O bank in the first page
    tam    #0
    lda    #$F8                 ; and the RAM bank in the second page
    tam    #1
    stz    $2000                ; clear all the RAM
    tii    $2000,$2001,$1FFF

    lda    #$01
    sta    $0C01                ; disable timer

    stz    $1402
    stz    $1403

    .bss
_bpe_str    .ds BPE_UNCOMPRESSED_STRING_LEN
dummy       .ds 2
_bpe_stack  .ds BPE_STACK

    .zp
_bpe_idx    .ds 1

    .code
    
    cly
decode:
    lda    _bpe_encoded, Y
    iny
    phy
    
    jsr    bpe_decode

    ply
    cpy    #BPE_COMPRESSED_STRING_LEN
    bcc    decode
    
main:
    nop
    bra    main

    .include "bpe.asm"

irq_2:                    ; irq 2
irq_1:                    ; irq 1
irq_timer:                ; timer
irq_nmi:                  ; nmi
    rti
