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

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