]> git.sur5r.net Git - cc65/commitdiff
Added a new sysrename module to make the high level function rename work. Code
authoruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sun, 22 Feb 2009 14:06:12 +0000 (14:06 +0000)
committeruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sun, 22 Feb 2009 14:06:12 +0000 (14:06 +0000)
is untested!

git-svn-id: svn://svn.cc65.org/cc65/trunk@3940 b7a2c559-68d2-44c3-8de9-860c34a00d81

libsrc/cbm/Makefile
libsrc/cbm/filename.s
libsrc/cbm/sysrename.s [new file with mode: 0644]

index 39b7f600fdabd1a6200667601db7ae391606976c..8d3adde4b7fc94a090af08232514ea485a876c51 100644 (file)
@@ -77,6 +77,7 @@ S_OBJS =      c_acptr.o       \
                 rwcommon.o      \
                 scratch.o       \
                 sysremove.o     \
+                sysrename.o     \
                 systime.o       \
                wherex.o        \
                 wherey.o        \
index af12496474fd04c5f16c38b1778bbe5722bc6ccb..85d5bc4598ddad0fc38d834662939e0941217b84 100644 (file)
@@ -9,13 +9,63 @@
 
         .import         SETNAM
         .import         __curunit, __filetype
-        .importzp       ptr1
+        .importzp       ptr1, tmp1
 
         .include        "ctype.inc"
+                  
 
+;------------------------------------------------------------------------------
+; fnparsename: Parse a filename (without drive spec) passed in in ptr1 and y.
 
-;--------------------------------------------------------------------------
-; fnparse: Parse a filename passed in in a/x. Will set the following
+.proc   fnparsename
+
+        lda     #0
+        sta     tmp1            ; Remember length of name
+
+nameloop:
+        lda     (ptr1),y        ; Get next char from filename
+        beq     namedone        ; Jump if end of name reached
+
+; Check for valid chars in the file name. We allow letters, digits, plus some
+; additional chars from a table.
+
+        ldx     #fncharcount-1
+namecheck:
+        cmp     fnchars,x
+        beq     nameok
+        dex
+        bpl     namecheck
+        tax
+        lda     __ctype,x
+        and     #CT_ALNUM
+        beq     invalidname
+
+; Check the maximum length, store the character
+
+nameok: ldx     tmp1
+        cpx     #16             ; Maximum length reached?
+        bcs     invalidname
+        lda     (ptr1),y        ; Reload char
+        jsr     fnadd           ; Add character to name
+        iny                     ; Next char from name
+        inc     tmp1            ; Increment length of name
+        bne     nameloop        ; Branch always
+
+; Invalid file name
+
+invalidname:
+        lda     #33             ; Invalid file name
+
+; Done, we've successfully parsed the name.
+
+namedone:
+        rts
+
+.endproc
+
+
+;------------------------------------------------------------------------------
+; fnparse: Parse a full filename passed in in a/x. Will set the following
 ; variables:
 ;
 ;       fnlen   -> length of filename
 
         ldy     #0
         lda     (ptr1),y
-        sta     fnbuf+0
         cmp     #'0'
         beq     digit
         cmp     #'1'
         bne     nodrive
 
-digit:  iny
+digit:  sta     fnbuf+0
+        iny
         lda     (ptr1),y
         cmp     #':'
         bne     nodrive
@@ -63,50 +113,16 @@ nodrive:
         sta     fnbuf+1
         ldy     #$00            ; Reposition to start of name
 
-; Drive spec done. Copy the name into the file name buffer. Check that all
-; file name characters are valid and that the maximum length is not exceeded.
+; Drive spec done. We do now have a drive spec in the buffer.
 
 drivedone:
         lda     #2              ; Length of drive spec
         sta     fnlen
 
-nameloop:
-        lda     (ptr1),y        ; Get next char from filename
-        beq     namedone        ; Jump if end of name reached
-
-; Check for valid chars in the file name. We allow letters, digits, plus some
-; additional chars from a table.
+; Copy the name into the file name buffer. The subroutine returns an error
+; code in A and zero flag set if the were no errors.
 
-        ldx     #fncharcount-1
-namecheck:
-        cmp     fnchars,x
-        beq     nameok
-        dex
-        bpl     namecheck
-        tax
-        lda     __ctype,x
-        and     #CT_ALNUM
-        beq     invalidname
-
-; Check the maximum length, store the character
-
-nameok: ldx     fnlen
-        cpx     #18             ; Maximum length reached?
-        bcs     invalidname
-        lda     (ptr1),y        ; Reload char
-        jsr     fnadd           ; Add character to name
-        iny                     ; Next char from name
-        bne     nameloop        ; Branch always
-
-; Invalid file name
-
-invalidname:
-        lda     #33             ; Invalid file name
-
-; Done, we've successfully parsed the name.
-
-namedone:
-        rts
+        jmp     fnparsename
 
 .endproc
 
@@ -169,8 +185,8 @@ fnlen:  .res    1
 
 .data
 fncmd:  .byte   's'     ; Use as scratch command
-fnbuf:  .res    22      ; 0:0123456789012345,t,m
-
+fnbuf:  .res    35      ; Either 0:0123456789012345,t,m
+                        ; Or     0:0123456789012345=0123456789012345
 .rodata
 ; Characters that are ok in filenames besides digits and letters
 fnchars:.byte   ".,-_+()"
diff --git a/libsrc/cbm/sysrename.s b/libsrc/cbm/sysrename.s
new file mode 100644 (file)
index 0000000..b4211f9
--- /dev/null
@@ -0,0 +1,44 @@
+;
+; Ullrich von Bassewitz, 2009-02-22
+;
+; unsigned char __fastcall__ _sysrename (const char *oldpath, const char *newpath);
+;
+
+        .export         __sysrename
+
+        .import         fnparse, fnadd, fnparsename
+        .import         writefndiskcmd, closecmdchannel
+        .import         popax
+
+        .import         fncmd, fnunit
+
+
+;--------------------------------------------------------------------------
+; __sysrename:
+
+.proc   __sysrename
+
+        jsr     fnparse         ; Parse first filename, pops newpath
+        bne     done
+
+        lda     #'='
+        jsr     fnadd
+
+        jsr     popax
+        jsr     fnparsename     ; Parse second filename
+        bne     done
+
+        lda     #'r'            ; Rename command
+        sta     fncmd
+        jsr     writefndiskcmd
+
+        pha
+        ldx     fnunit
+        jsr     closecmdchannel
+        pla
+
+done:   rts
+
+.endproc
+
+