1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-15 17:30:06 +00:00
cc65/libsrc/cbm/diskerror.s
cuz 751aaee63d Finally: Commodore file I/O
git-svn-id: svn://svn.cc65.org/cc65/trunk@1531 b7a2c559-68d2-44c3-8de9-860c34a00d81
2002-11-16 23:45:15 +00:00

88 lines
2.2 KiB
ArmAsm

;
; Ullrich von Bassewitz, 16.11.2002
;
; Read the disk error channel
;
.export readdiskerror, getdiskerror
.import fnunit
.importzp tmp1
.include "cbm.inc"
;--------------------------------------------------------------------------
; readdiskerror: Read a disk error from an already open command channel.
; Returns an error code in A, which may either be the code read from the
; command channel, or another error when accessing the command channel failed.
.proc readdiskerror
; Read the command channel. We won't check the status after the channel is
; open, because this seems to be unnecessary in most cases.
ldx #15
jsr CHKIN ; Read from LFN 15
bcs done ; Bail out with error code in A
jsr BASIN
and #$0F ; Make digit value from PETSCII
sta tmp1
asl a ; * 2
asl a ; * 4, carry clear
adc tmp1 ; * 5
asl a ; * 10
sta tmp1
jsr BASIN
and #$0F ; Make digit value from PETSCII
clc
adc tmp1
; Errors below 20 are not real errors. Fix that
cmp #20+1
bcs done
lda #0
done: rts
.endproc
;--------------------------------------------------------------------------
; getdiskerror: Open the command channel to a disk unit with id in X. Read
; the error and close it again. Returns an error code in A, which may either
; be the code read from the command channel, or another error when accessing
; the command channel failed.
.proc getdiskerror
cpx #8 ; Disk unit?
bcc nodisk
lda #15 ; Command channel
tay ; Secondary address
jsr SETLFS
lda #$00
jsr SETNAM ; No name supplied to OPEN
jsr OPEN
bcs err
jsr readdiskerror
pha ; Save error code
lda #15
jsr CLOSE
pla
err: rts
nodisk: lda #$00
rts
.endproc