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:
parent
cb668eff63
commit
1a80cd1071
4 changed files with 76 additions and 48 deletions
|
@ -72,6 +72,7 @@ S_OBJS = c_acptr.o \
|
|||
devicedir.o \
|
||||
dir.o \
|
||||
diskcmd.o \
|
||||
diskinit.o \
|
||||
exehdr.o \
|
||||
filedes.o \
|
||||
filename.o \
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
53
libsrc/cbm/diskinit.s
Normal file
53
libsrc/cbm/diskinit.s
Normal 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
|
|
@ -5,7 +5,7 @@
|
|||
;
|
||||
|
||||
.export __syschdir
|
||||
.import curunit, initcwd
|
||||
.import diskinit, fnunit, curunit, initcwd
|
||||
.importzp ptr1, tmp1, tmp2
|
||||
|
||||
;--------------------------------------------------------------------------
|
||||
|
@ -31,7 +31,7 @@
|
|||
|
||||
iny
|
||||
lda (ptr1),y
|
||||
beq done
|
||||
beq init
|
||||
jsr getdigit
|
||||
bcs err
|
||||
stx tmp1 ; First digit
|
||||
|
@ -60,13 +60,22 @@
|
|||
lda (ptr1),y
|
||||
bne err
|
||||
|
||||
; Check device readiness
|
||||
|
||||
init: txa
|
||||
jsr diskinit
|
||||
bne done
|
||||
|
||||
; Success, update cwd
|
||||
|
||||
done: stx curunit
|
||||
lda fnunit ; Set by diskinit
|
||||
sta curunit
|
||||
jmp initcwd ; Returns with A = 0
|
||||
|
||||
; Return with error in A
|
||||
|
||||
err: lda #9 ; "Ilegal device"
|
||||
rts
|
||||
done: rts
|
||||
|
||||
.endproc
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue