]> git.sur5r.net Git - cc65/commitdiff
Implemented __syschdir on CBM. As getcwd returns a cached directory any direct access...
authorol.sc <ol.sc@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Tue, 16 Oct 2012 21:39:40 +0000 (21:39 +0000)
committerol.sc <ol.sc@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Tue, 16 Oct 2012 21:39:40 +0000 (21:39 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@5857 b7a2c559-68d2-44c3-8de9-860c34a00d81

include/cbm.h
libsrc/cbm/Makefile
libsrc/cbm/filename.s
libsrc/cbm/filevars.s
libsrc/cbm/initcwd.s
libsrc/cbm/syschdir.s [new file with mode: 0644]

index 3ca8715e47f4d1a63542ba01a3b398c524f9faae..5a422806a1c18fc95b231af32c20eccf34ba4393 100644 (file)
 
 
 
-/* The file stream implementation and the POSIX I/O functions will use the
- * following variables to determine the file type and the disk unit to use.
+/* The file stream implementation and the POSIX I/O functions will
+ * use the following variable to determine the file type to use.
  */
-extern unsigned char _curunit;  /* Defaults to current when program started */
 extern char _filetype;          /* Defaults to 's' */
 
 
index 5e3396e13509cf764d7cdcaf3b434b0aa9b32a4a..3230ab3b963b1aa61641ee0a4c9458ee1a583d30 100644 (file)
@@ -19,7 +19,7 @@ CFLAGS        = -Osir -g -T -t $(SYS) --forget-inc-paths -I . -I ../../include
 #--------------------------------------------------------------------------
 # Rules
 
-%.o:           %.c
+%.o:   %.c
        @$(CC) $(CFLAGS) $<
        @$(AS) -o $@ $(AFLAGS) $(*).s
 
@@ -29,74 +29,75 @@ CFLAGS      = -Osir -g -T -t $(SYS) --forget-inc-paths -I . -I ../../include
 #--------------------------------------------------------------------------
 # Object files
 
-C_OBJS =               cbm_dir.o       \
-                cbm_load.o     \
-               cbm_save.o      \
-                opendir.o       \
-                readdir.o       \
-                seekdir.o
+C_OBJS =       cbm_dir.o       \
+               cbm_load.o      \
+               cbm_save.o      \
+               opendir.o       \
+               readdir.o       \
+               seekdir.o
 
 S_OBJS =       c_acptr.o       \
-               c_basin.o       \
+               c_basin.o       \
                c_bsout.o       \
                c_chkin.o       \
-               c_ciout.o       \
-               c_ckout.o       \
+               c_ciout.o       \
+               c_ckout.o       \
                c_clall.o       \
-               c_close.o       \
-               c_clrch.o       \
-                c_getin.o       \
+               c_close.o       \
+               c_clrch.o       \
+               c_getin.o       \
                c_iobase.o      \
                c_listen.o      \
-               c_load.o        \
-               c_open.o        \
-               c_readst.o      \
-               c_save.o        \
+               c_load.o        \
+               c_open.o        \
+               c_readst.o      \
+               c_save.o        \
                c_setlfs.o      \
                c_setnam.o      \
-               c_talk.o        \
+               c_talk.o        \
                c_unlsn.o       \
                c_untlk.o       \
                cbm_close.o     \
-                cbm_filetype.o  \
-               cbm_open.o      \
-               cbm_read.o      \
-               cbm_write.o     \
-               cclear.o        \
-               chline.o        \
-               clock.o         \
-                close.o         \
-                closedir.o      \
-               ctype.o         \
-               cvline.o        \
-                devicedir.o     \
-                dir.o           \
-                diskcmd.o       \
-                exehdr.o        \
-                filedes.o       \
-                filename.o      \
-                filetype.o      \
-                filevars.o      \
-                getdevice.o     \
+               cbm_filetype.o  \
+               cbm_open.o      \
+               cbm_read.o      \
+               cbm_write.o     \
+               cclear.o        \
+               chline.o        \
+               clock.o         \
+               close.o         \
+               closedir.o      \
+               ctype.o         \
+               cvline.o        \
+               devicedir.o     \
+               dir.o           \
+               diskcmd.o       \
+               exehdr.o        \
+               filedes.o       \
+               filename.o      \
+               filetype.o      \
+               filevars.o      \
+               getdevice.o     \
                gotox.o         \
                gotoxy.o        \
                gotoy.o         \
-                initcwd.o       \
-                loadaddr.o      \
-                open.o          \
-                oserrlist.o     \
+               initcwd.o       \
+               loadaddr.o      \
+               open.o          \
+               oserrlist.o     \
                oserror.o       \
-                read.o          \
-                rewinddir.o     \
-                rwcommon.o      \
-                scratch.o       \
-                sysremove.o     \
-                sysrename.o     \
-                telldir.o       \
-                toascii.o       \
-               wherex.o        \
-                wherey.o        \
-                write.o
+               read.o          \
+               rewinddir.o     \
+               rwcommon.o      \
+               scratch.o       \
+               syschdir.o      \
+               sysremove.o     \
+               sysrename.o     \
+               telldir.o       \
+               toascii.o       \
+               wherex.o        \
+               wherey.o        \
+               write.o
 
 #--------------------------------------------------------------------------
 # Targets
@@ -109,4 +110,3 @@ clean:
        @$(RM) *~ *.bck $(C_OBJS:.o=.s) $(C_OBJS) $(S_OBJS)
 
 zap:   clean
-
index 37caef21da8043eb883e44aa8d7fcb08f917f577..e5884bbdf960f6815d050c21722a9c381f21d1a9 100644 (file)
@@ -9,7 +9,7 @@
         .export         fnunit, fnlen, fnisfile, fncmd, fnbuf
 
         .import         SETNAM
-        .import         __curunit, __filetype
+        .import         curunit, __filetype
         .importzp       ptr1, tmp1
 
         .include        "ctype.inc"
@@ -147,7 +147,7 @@ drivedone:
 
 .proc   fndefunit
 
-        lda     __curunit
+        lda     curunit
         sta     fnunit
         rts
 
index baaef66a46de2420743d5aaa6499ad6cff98ab52..316cf276211bfd742c8395e1f3795b002c561401 100644 (file)
@@ -4,14 +4,14 @@
 ; Variables used for CBM file I/O
 ;
 
-        .export         __curunit
+        .export         curunit
         .constructor    initcurunit, 30
         .importzp       devnum
 
 
 .bss
 
-__curunit:
+curunit:
         .res    1
 
 
@@ -23,7 +23,7 @@ __curunit:
         bne     @L0
         lda     #8              ; Default is disk
         sta     devnum
-@L0:    sta     __curunit
+@L0:    sta     curunit
         rts
 
 .endproc
index d5eb7fb90a7ffc84b3b3585e4fab0979510e30ed..1289b71dc5af6a019fb0244257d183ca3a86f6f5 100644 (file)
@@ -5,7 +5,7 @@
 ;
 
        .export         initcwd, devicestr
-       .import         __curunit, __cwd
+       .import         curunit, __cwd
        .import         pusha0, tosudiva0
        .importzp       sreg, ptr1, ptr2
 
@@ -16,7 +16,7 @@ initcwd:
        ldx     #>__cwd
        sta     ptr2
        stx     ptr2+1
-       lda     __curunit
+       lda     curunit
        ; Fall through
 
 ;------------------------------------------------------------------------------
@@ -28,11 +28,11 @@ devicestr:
        jsr     tosudiva0
        ldy     #0
        lda     sreg
-       beq     :+              ; >=10
+       beq     @L0             ; >=10
        add     #'0'
        sta     (ptr2),y
        iny
-:      lda     ptr1            ; rem
+@L0:   lda     ptr1            ; rem
        add     #'0'
        sta     (ptr2),y
        iny
diff --git a/libsrc/cbm/syschdir.s b/libsrc/cbm/syschdir.s
new file mode 100644 (file)
index 0000000..10dbe33
--- /dev/null
@@ -0,0 +1,86 @@
+;
+; Oliver Schmidt, 2012-10-16
+;
+; unsigned char __fastcall__ _syschdir (const char* name);
+;
+
+        .export         __syschdir
+        .import         curunit, initcwd
+        .importzp       ptr1, tmp1, tmp2
+
+;--------------------------------------------------------------------------
+; __syschdir
+
+.proc   __syschdir
+
+; Save name
+
+        sta     ptr1
+        stx     ptr1+1
+
+; Process first character
+
+        ldy     #0
+        lda     (ptr1),y
+        beq     err
+        jsr     getdigit
+        bcs     err
+        tax
+
+; Process second character
+
+        iny
+        lda     (ptr1),y
+        beq     done
+        jsr     getdigit
+        bcs     err
+        stx     tmp1            ; First digit
+        sta     tmp2            ; Second digit
+
+; Multiply first digit by 10
+
+        ldx     #8
+@L0:    asl
+        asl     tmp1
+        bcc     @L1
+        clc
+        adc     #10
+@L1:    dex
+        bne     @L0
+
+; Add second digit to product
+
+        clc
+        adc     tmp2
+        tax
+
+; Process third character
+
+        iny
+        lda     (ptr1),y
+        bne     err
+
+; Success, update cwd
+
+done:   stx     curunit
+        jmp     initcwd         ; Returns with A = 0
+
+err:    lda     #9              ; "Ilegal device"
+        rts
+
+.endproc
+
+;--------------------------------------------------------------------------
+; getdigit
+
+.proc   getdigit
+
+        sec
+        sbc     #'0'
+        bcs     @L0
+        sec
+        rts
+@L0:    cmp     #10
+        rts
+
+.endproc
\ No newline at end of file