[comp.sys.cbm] Device Error Handling in Assembler

piskacrj@mentor.cc.purdue.edu (Robert J Piskac) (04/16/91)

I am trying to learn how to handle disk drive errors.  Like
device not present, file not found and others.  Where can i read 
up on how to handle these errors?

The questions I have are why would I get an error after a jsr open
was performed?  Why would I get an error after a jsr chkin was 
performed?  Where would a file not found error be discovered?

How do I read the error channel after an error occurs, do I have to
do any clean up before I read the error channel?  

I included a simple Assembler example that someone can rip apart
and show me the correct way.  If anyone can help me, I would be greatful!

;================================
slow     = $77c7
fast     = $77b3
setbnk   = $ff68
setlfs   = $ffba
open     = $ffc0
close    = $ffc3
chkin    = $ffc6
ckout    = $ffc9
clrchn   = $ffcc
chrin    = $ffcf
readss   = $ffb7
setnam   = $ffbd
istop    = $ffe1
chrout   = $ffd2
;============================
start   jsr fast
        jsr openfile
        rts
;============================
openfile lda #16
        ldx #<fname
        ldy #>fname
        jsr setnam
        ldx #0
        jsr setbnk
        lda #3
        ldx #9
        ldy #0
        jsr setlfs
        jsr open
        bcs eofload  ; Error in open
        ldx #3
        jsr chkin
        bcs eofload ; Error in open channel for input
        jsr chrin
        pha
        jsr readss  ; end of file or error 
        bne 02$
        jsr clrchn
        ldx #2
        jsr ckout
        pla
        sta tmpchr
        jsr chrout
        jsr istop
        beq eofload ; stop key pressed
02$     pla
eofload jsr clrchn
        lda #3
        jsr close
        rts