]> git.sur5r.net Git - cc65/commitdiff
Added check for disk in drive on chdir().
authorol.sc <ol.sc@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Wed, 17 Oct 2012 20:24:43 +0000 (20:24 +0000)
committerol.sc <ol.sc@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Wed, 17 Oct 2012 20:24:43 +0000 (20:24 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@5859 b7a2c559-68d2-44c3-8de9-860c34a00d81

libsrc/cbm/Makefile
libsrc/cbm/devicedir.s
libsrc/cbm/diskinit.s [new file with mode: 0644]
libsrc/cbm/syschdir.s

index 3230ab3b963b1aa61641ee0a4c9458ee1a583d30..99753dd979a795b401b50c430aaae37e6f1d6f6b 100644 (file)
@@ -72,6 +72,7 @@ S_OBJS =      c_acptr.o       \
                devicedir.o     \
                dir.o           \
                diskcmd.o       \
+               diskinit.o      \
                exehdr.o        \
                filedes.o       \
                filename.o      \
index b63a8ebe94b59f1885032df4a188520a9cf4c996..3a4e6d7745c61e2a22fc6baacb3f296e91673ad6 100644 (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
 
         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
 
diff --git a/libsrc/cbm/diskinit.s b/libsrc/cbm/diskinit.s
new file mode 100644 (file)
index 0000000..d84123a
--- /dev/null
@@ -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
index 10dbe33ed7712e511b7fa94fd81f3638cc82a382..78b2df82d9b10c1632dc808519f7397c9b15b173 100644 (file)
@@ -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
         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