; Source for coldstart and BASIC I/O ROM. Generated by disassembling
; code.

        NMI = $0130     ; NMI interrupt address
        IRQ = $01C0     ; IRQ interrupt address

        L0000 = $0000
        L0218 = $0218
        L021A = $021A
        L021C = $021C
        L021E = $021E
        L0220 = $0220
        LA636 = $A636
        LBD11 = $BD11
        LBF2D = $BF2D
        LFC00 = $FC00   ; Floppy disc bootstrap
        LFCA6 = $FCA6
        LFCB1 = $FCB1
        LFD00 = $FD00   ; Keyboard input
        LFE00 = $FE00   ; Monitor

        * = $FF00

RESET:  cld             ; clear decimal mode
        ldx     #$28    ; initialize stack pointer to $0128
        txs
        ldy     #$0A
LFF06:  lda     $FEEF,y
        sta     $0217,y
        dey
        bne     LFF06
        jsr     LFCA6
        sty     $0212
        sty     $0203
        sty     $0205
        sty     $0206
        lda     LFFE0
        sta     $0200
        lda     #' '
LFF26:  sta     $D300,y ; Clear screen
        sta     $D200,y
        sta     $D100,y
        sta     $D000,y
        iny
        bne     LFF26
LFF35:  lda     LFF5F,y
        beq     LFF40
        jsr     LBF2D
        iny
        bne     LFF35
LFF40:  jsr     LFFBA
        cmp     #'M'    ; User selected M for Monitor?
        bne     LFF4A
        jmp     LFE00   ; Jump to monitor
LFF4A:  cmp     #'W'    ; User selected W for BASIC Warm start?
        bne     LFF51
        jmp     L0000   ; Jump to BASIC warm start
LFF51:  cmp     #'C'    ; User selected C for BASIC Carm start?
        bne     LFF58
        jmp     LBD11   ; Jump to BASIC cold start
LFF58:  cmp     #'D'    ; User selected D for boot from disk?
        bne     RESET   ; Restart if invalid input
        jmp     LFC00   ; Jump to disk boot
LFF5F:  .asciiz   "D/C/W/M ?"
        jsr     LBF2D
        pha
        lda     $0205
        beq     LFF94
        pla
        jsr     LFCB1
        cmp     #$0D
        bne     LFF95
        pha
        txa
        pha
        ldx     #$0A
        lda     #$00
LFF81:  jsr     LFCB1
        dex
        bne     LFF81
        pla
        tax
        pla
        rts

        pha
        dec     $0203
        lda     #$00
LFF91:  sta     $0205
LFF94:  pla
LFF95:  rts

        pha
        lda     #$01
        bne     LFF91
        lda     $0212
        bne     LFFB9
        lda     #$FE
        sta     $DF00
        bit     $DF00
        bvs     LFFB9
        lda     #$FB
        sta     $DF00
        bit     $DF00
        bvs     LFFB9
        lda     #$03
        jmp     LA636
LFFB9:  rts

LFFBA:  bit     $0203
        bpl     LFFD8
LFFBF:  lda     #$FD
        sta     $DF00
        lda     #$10
        bit     $DF00
        beq     LFFD5
        lda     $F000
        lsr     a
        bcc     LFFBF
        lda     $F001
        rts

LFFD5:  inc     $0203
LFFD8:  jmp     LFD00
        .byte   $FF, $FF, $FF, $FF,  $FF
LFFE0:  .byte   $65, $17, $00, $00, $03, $FF, $9F, $00, $03, $FF, $9F
        jmp     (L0218)
        jmp     (L021A)
        jmp     (L021C)
        jmp     (L021E)
        jmp     (L0220)
        .word   NMI
        .word   RESET
        .word   IRQ
