Added check for disk in drive on chdir().

git-svn-id: svn://svn.cc65.org/cc65/trunk@5859 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
ol.sc 2012-10-17 20:24:43 +00:00
parent cb668eff63
commit 1a80cd1071
4 changed files with 76 additions and 48 deletions

View file

@ -72,6 +72,7 @@ S_OBJS = c_acptr.o \
devicedir.o \ devicedir.o \
dir.o \ dir.o \
diskcmd.o \ diskcmd.o \
diskinit.o \
exehdr.o \ exehdr.o \
filedes.o \ filedes.o \
filename.o \ filename.o \

View file

@ -5,9 +5,7 @@
; ;
.export _getdevicedir .export _getdevicedir
.import opencmdchannel, closecmdchannel .import diskinit, devicestr, fnunit
.import writefndiskcmd, readdiskerror
.import isdisk, fnunit, fncmd, devicestr
.import popa, popax .import popa, popax
.importzp ptr2, ptr3 .importzp ptr2, ptr3
@ -29,63 +27,30 @@
sta ptr2 sta ptr2
stx ptr2+1 stx ptr2+1
; Save device ; Check device readiness
jsr popa jsr popa
sta fnunit jsr diskinit
beq size
; Check for disk device jsr __mappederrno
bne fail ; Branch always
tax
jsr isdisk
bcs erange
; Open channel
jsr opencmdchannel
bne oserr
; Write command
lda #'i' ; Init command
sta fncmd
jsr writefndiskcmd
bne close
; Read error
ldx fnunit
jsr readdiskerror
; Close channel
close: pha
ldx fnunit
jsr closecmdchannel
pla
bne oserr
; Check for sufficient buf size ; Check for sufficient buf size
lda ptr3+1 size: lda ptr3+1
bne okay ; Buf >= 256 bne okay ; Buf >= 256
lda ptr3 lda ptr3
cmp #3 cmp #3
bcs okay ; Buf >= 3 bcs okay ; Buf >= 3
lda #<ERANGE
erange: lda #<ERANGE
jsr __directerrno jsr __directerrno
bne fail ; Branch always
oserr: jsr __mappederrno
fail: lda #0 ; Return NULL fail: lda #0 ; Return NULL
tax tax
rts rts
; Copy device string representation into buf ; Copy device string representation into buf
okay: lda fnunit okay: lda fnunit ; Set by diskinit
jsr devicestr ; Returns 0 in A jsr devicestr ; Returns 0 in A
sta __oserror ; Clear _oserror sta __oserror ; Clear _oserror

53
libsrc/cbm/diskinit.s Normal file
View file

@ -0,0 +1,53 @@
;
; Oliver Schmidt, 2012-10-17
;
.export diskinit
.import opencmdchannel, closecmdchannel
.import writefndiskcmd, readdiskerror
.import isdisk, fnunit, fncmd
;------------------------------------------------------------------------------
; diskinit
.proc diskinit
; Save device
sta fnunit
; Check for disk device
tax
jsr isdisk
bcc open
lda #9 ; "Ilegal device"
rts
; Open channel
open: jsr opencmdchannel
bne done
; Write command
lda #'i' ; Init command
sta fncmd
jsr writefndiskcmd
bne close
; Read error
ldx fnunit
jsr readdiskerror
; Close channel
close: pha
ldx fnunit
jsr closecmdchannel
pla
done: rts
.endproc

View file

@ -5,7 +5,7 @@
; ;
.export __syschdir .export __syschdir
.import curunit, initcwd .import diskinit, fnunit, curunit, initcwd
.importzp ptr1, tmp1, tmp2 .importzp ptr1, tmp1, tmp2
;-------------------------------------------------------------------------- ;--------------------------------------------------------------------------
@ -31,7 +31,7 @@
iny iny
lda (ptr1),y lda (ptr1),y
beq done beq init
jsr getdigit jsr getdigit
bcs err bcs err
stx tmp1 ; First digit stx tmp1 ; First digit
@ -60,13 +60,22 @@
lda (ptr1),y lda (ptr1),y
bne err bne err
; Check device readiness
init: txa
jsr diskinit
bne done
; Success, update cwd ; Success, update cwd
done: stx curunit lda fnunit ; Set by diskinit
sta curunit
jmp initcwd ; Returns with A = 0 jmp initcwd ; Returns with A = 0
; Return with error in A
err: lda #9 ; "Ilegal device" err: lda #9 ; "Ilegal device"
rts done: rts
.endproc .endproc