]> git.sur5r.net Git - cc65/commitdiff
Introduced getdevicedir() - with implementation for the CBMs.
authorol.sc <ol.sc@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sun, 7 Oct 2012 19:18:56 +0000 (19:18 +0000)
committerol.sc <ol.sc@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sun, 7 Oct 2012 19:18:56 +0000 (19:18 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@5840 b7a2c559-68d2-44c3-8de9-860c34a00d81

include/device.h
libsrc/cbm/Makefile
libsrc/cbm/devicedir.s [new file with mode: 0644]
libsrc/cbm/devicestr.s [new file with mode: 0644]
libsrc/cbm/initcwd.s

index 37323e6374180f853d50278bba26ed6468bcca7e..9d525e15a67b8b1a7bdefab8391ec8c7eeb145ec 100644 (file)
@@ -55,6 +55,8 @@ unsigned char getfirstdevice (void);
 
 unsigned char __fastcall__ getnextdevice (unsigned char device);
 
+char* __fastcall__ getdevicedir (unsigned char device, char* buf, size_t size);
+
 
 
 /* End of device.h */
index 1b1a6a4cb0ed1cc7816613809e23b2cd83930b38..fbcaeeeed417b535fafdf469249e7fe3577d9ba3 100644 (file)
@@ -69,6 +69,8 @@ S_OBJS =      c_acptr.o       \
                 closedir.o      \
                ctype.o         \
                cvline.o        \
+                devicedir.o     \
+                devicestr.o     \
                 dir.o           \
                 diskcmd.o       \
                 exehdr.o        \
diff --git a/libsrc/cbm/devicedir.s b/libsrc/cbm/devicedir.s
new file mode 100644 (file)
index 0000000..93e1845
--- /dev/null
@@ -0,0 +1,97 @@
+;
+; Oliver Schmidt, 2012-09-10
+;
+; char* __fastcall__ getdevicedir (unsigned char device, char* buf, size_t size);
+;
+
+        .export         _getdevicedir
+
+        .import         opencmdchannel, closecmdchannel
+        .import         writefndiskcmd, readdiskerror
+        .import         isdisk, fnunit, fncmd, devicestr
+        .import         popa, popax
+        .importzp       ptr2, ptr3
+
+        .include        "errno.inc"
+
+;------------------------------------------------------------------------------
+; _getdevicedir
+
+.proc   _getdevicedir
+
+; Save size
+
+        sta     ptr3
+        stx     ptr3+1
+
+; Save buf
+
+        jsr     popax
+        sta     ptr2
+        stx     ptr2+1
+
+; Save device
+
+        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
+
+; Check for sufficient buf size
+
+        lda     ptr3+1
+        bne     okay            ; Buf >= 256
+        lda     ptr3
+        cmp     #3
+        bcs     okay            ; Buf >= 3
+
+erange: lda     #<ERANGE
+        bne     errno           ; Branch always
+
+oserr:  jsr     __osmaperrno
+
+errno:  jsr     __seterrno      ; Returns 0 in A
+        tax                     ; Return NULL
+        rts
+
+; Copy device string representation into buf
+
+okay:   lda     fnunit
+        jsr     devicestr
+
+; Success, return buf
+
+        lda     ptr2
+        ldx     ptr2+1
+        rts
+
+.endproc
diff --git a/libsrc/cbm/devicestr.s b/libsrc/cbm/devicestr.s
new file mode 100644 (file)
index 0000000..15b4b6c
--- /dev/null
@@ -0,0 +1,35 @@
+;
+; Stefan Haubenthal, 2005-06-08
+;
+; CBM device to string
+;
+
+       .export         devicestr
+       .import         pusha0, tosudiva0
+       .importzp       sreg, ptr1, ptr2
+
+       .macpack        generic
+
+;------------------------------------------------------------------------------
+; Convert unit number in A into string representation pointed to by ptr2.
+
+.proc  devicestr
+
+       jsr     pusha0
+       lda     #10
+       jsr     tosudiva0
+       ldy     #0
+       lda     sreg
+       beq     :+              ; >=10
+       add     #'0'
+       sta     (ptr2),y
+       iny
+:      lda     ptr1            ; rem
+       add     #'0'
+       sta     (ptr2),y
+       iny
+       lda     #0
+       sta     (ptr2),y
+       rts
+
+.endproc
index 2df6dba85fe957c35b663fbdae15a0f672827d46..5f43bc86798860f6cc2fd64dff80ce59cb8fcf5b 100644 (file)
@@ -5,31 +5,18 @@
 ;
 
        .export         initcwd
-       .import         __curunit, __cwd
-       .import         pusha0, tosudiva0
-       .importzp       sreg, ptr1
-
-       .macpack        generic
+       .import         __curunit, __cwd, devicestr
+       .importzp       ptr2
 
        .segment        "INIT"
 
 .proc  initcwd
 
+       lda     #<__cwd
+       ldx     #>__cwd
+       sta     ptr2
+       stx     ptr2+1
        lda     __curunit
-       jsr     pusha0
-       lda     #10
-       jsr     tosudiva0
-       ldx     #0
-       lda     sreg
-       beq     :+              ; >=10
-       add     #'0'
-       sta     __cwd
-       inx
-:      lda     ptr1            ; rem
-       add     #'0'
-       sta     __cwd,x
-       lda     #0
-       sta     __cwd+1,x
-       rts
+       jmp     devicestr
 
 .endproc