]> git.sur5r.net Git - cc65/commitdiff
implement _sysrename for Atari
authorChristian Groessler <chris@groessler.org>
Tue, 23 Jul 2013 22:40:09 +0000 (00:40 +0200)
committerChristian Groessler <chris@groessler.org>
Tue, 23 Jul 2013 22:41:49 +0000 (00:41 +0200)
libsrc/atari/open.s
libsrc/atari/syschdir.s
libsrc/atari/sysmkdir.s
libsrc/atari/sysremove.s
libsrc/atari/sysrename.s [new file with mode: 0644]
libsrc/atari/sysrmdir.s
libsrc/atari/ucase_fn.s

index 306cf52c21feb66adf18f7a2b7bbba0f641305a0..2188257cb17d8f404d1131516cbaadf220d5cce0 100644 (file)
@@ -91,7 +91,10 @@ cont:   ldy     #3
         jsr     ldaxysp
 
 .ifdef  UCASE_FILENAME
-
+.ifdef  DEFAULT_DEVICE
+        ldy     #$80
+        sty     tmp2            ; set flag for ucase_fn
+.endif
         jsr     ucase_fn
         bcc     ucok1
 invret: lda     #<EINVAL        ; file name is too long
index 16cb3a1febcc9b94046f212521cadd35a4a729ff..d577083849136996613fcba3d892765ba46c6996 100644 (file)
@@ -15,6 +15,9 @@
         .importzp tmp3
         .import addysp
         .import ucase_fn
+.ifdef  DEFAULT_DEVICE
+        .importzp tmp2
+.endif
 .endif
         .export __syschdir
 
@@ -40,6 +43,10 @@ iocbok: stx     tmp4            ; remember IOCB index
 
 .ifdef  UCASE_FILENAME
 
+.ifdef  DEFAULT_DEVICE
+        ldy     #$80
+        sty     tmp2            ; set flag for ucase_fn
+.endif
         jsr     ucase_fn
         bcc     ucok1
 
index 56a0687576d1420c712155b86c4179a61dfb766a..cc1b3e2bfb4ebd205e07724bff533001a7691138 100644 (file)
@@ -15,6 +15,9 @@
 .ifdef  UCASE_FILENAME
         .importzp tmp3
         .import ucase_fn
+.ifdef  DEFAULT_DEVICE
+        .importzp tmp2
+.endif
 .endif
         .export __sysmkdir
 
@@ -46,6 +49,10 @@ iocbok: stx     tmp4            ; remember IOCB index
 
 .ifdef  UCASE_FILENAME
 
+.ifdef  DEFAULT_DEVICE
+        ldy     #$80
+        sty     tmp2            ; set flag for ucase_fn
+.endif
         jsr     ucase_fn
         bcc     ucok1
 
index 1e7b4760f6e7b885842f70919327d39c18c10e0c..15bc19e1cb25a3073132ae894b079d72b4448812 100644 (file)
@@ -12,6 +12,9 @@
         .importzp tmp3
         .import addysp
         .import ucase_fn
+.ifdef  DEFAULT_DEVICE
+        .importzp tmp2
+.endif
 .endif
         .export __sysremove
 
@@ -37,6 +40,10 @@ iocbok: stx     tmp4            ; remember IOCB index
 
 .ifdef  UCASE_FILENAME
 
+.ifdef  DEFAULT_DEVICE
+        ldy     #$80
+        sty     tmp2            ; set flag for ucase_fn
+.endif
         jsr     ucase_fn
         bcc     ucok1
 
diff --git a/libsrc/atari/sysrename.s b/libsrc/atari/sysrename.s
new file mode 100644 (file)
index 0000000..d3e430a
--- /dev/null
@@ -0,0 +1,184 @@
+;
+; Christian Groessler, 2013-07-24
+;
+; unsigned char __fastcall__ _sysrename (const char* oldname, const char* newname);
+;
+
+        .include "atari.inc"
+        .import findfreeiocb
+        .importzp tmp4, sp, ptr2, ptr3
+        .import incsp2, subysp, addysp, popax
+.ifdef  UCASE_FILENAME
+        .importzp tmp3
+        .import ucase_fn
+.ifdef  DEFAULT_DEVICE
+        .importzp tmp2
+.endif
+.endif
+        .export __sysrename
+
+.proc   __sysrename
+
+        pha                     ; save input parameter
+        txa
+        pha
+
+        jsr     findfreeiocb
+        beq     iocbok          ; we found one
+
+        pla
+        pla                     ; fix up stack
+        jsr     incsp2
+
+        lda     #TMOF           ; too many open files
+        rts
+
+iocbok: stx     tmp4            ; remember IOCB index
+
+        pla
+        sta     ptr2+1          ; remember newname
+        pla
+        sta     ptr2            ; ditto.
+
+        jsr     popax           ; get oldname
+
+        ldy     #0
+        sty     sspc+1          ; initialize stack space
+
+.ifndef  UCASE_FILENAME
+
+        sta     ptr3
+        stx     ptr3+1
+        sty     sspc
+
+.else
+
+; uppercase first (old) name and prepend device if needed
+
+.ifdef  DEFAULT_DEVICE
+        ldy     #$80
+        sty     tmp2            ; set flag for ucase_fn
+.endif
+        jsr     ucase_fn
+        bcc     ucok1
+
+        lda     #183            ; see oserror.s
+        rts
+
+ucok1:  sta     ptr3
+        stx     ptr3+1          ; remember pointer to uppercased old name
+        lda     tmp3            ; # of bytes reserved on the stack
+        sta     sspc            ; remember...
+
+; uppercase second (new) name and don't prepend device
+
+.ifdef  DEFAULT_DEVICE
+        ldy     #0
+        sty     tmp2            ; set flag for ucase_fn
+.endif
+        lda     ptr2
+        ldx     ptr2+1
+
+        jsr     ucase_fn
+        bcc     ucok2
+
+        ldy     tmp3            ; get size
+        jsr     addysp          ; free used space on the stack
+        lda     #183            ; see oserror.s
+        rts
+
+ucok2:  sta     ptr2            ; remember pointer to uppercased new name
+        stx     ptr2+1
+
+; update sspc -- # of bytes used on the stack
+
+        lda     sspc
+        clc
+        adc     tmp3
+        sta     sspc
+        bcc     ukok4
+        inc     sspc+1
+ukok4:
+
+.endif
+
+; create a string on the stack with the old filename and the new filename separated by an invalid character (space in our case)
+; ptr2 - pointer to new name
+; ptr3 - pointer to old name
+
+        lda     #128
+        tay
+        clc
+        adc     sspc
+        sta     sspc
+        bcc     L1
+        inc     sspc+1
+L1:     jsr     subysp          ; make room on the stack
+
+; copy old name
+        ldy     #0
+con:    lda     (ptr3),y
+        sta     (sp),y
+        beq     copyend
+        iny
+        bne     con
+
+copyend:lda     #$20            ; space
+        sta     (sp),y
+        iny
+        tya                     ; get current offset (beyond old name)
+        clc
+        adc     sp
+        sta     ptr3
+        lda     sp+1
+        adc     #0
+        sta     ptr3+1          ; ptr3 now contains pointer to space for new filename
+
+; copy new name
+        ldy     #0
+cnn:    lda     (ptr2),y
+        sta     (ptr3),y
+        beq     copend2
+        iny
+        bne     cnn
+
+copend2:ldx     tmp4
+        lda     sp
+        sta     ICBAL,x
+        lda     sp+1
+        sta     ICBAH,x
+        lda     #RENAME
+        sta     ICCOM,x
+        lda     #0
+        sta     ICAX1,x
+        sta     ICAX2,x
+        sta     ICBLL,x
+        sta     ICBLH,x
+        jsr     CIOV
+        tya
+        pha
+
+; clean up stack
+
+        lda     sp
+        clc
+        adc     sspc
+        sta     sp
+        bcc     L2
+        inc     sp+1
+L2:     pla
+        tay
+
+; handle status
+
+        bmi     cioerr
+        lda     #0
+        rts
+cioerr: tya
+        rts
+
+.endproc        ; __sysrename
+
+        .bss
+
+sspc:   .res    2               ; stack space used
index 2a2b160c122a19522a855f6ae3f09cee9ab98a9d..126c11cca2cc1200f66049a7bfd603d982a38d23 100644 (file)
         .export         __sysrmdir
         .import         __sysremove
         .import         __dos_type
-        .import         ucase_fn
         .import         findfreeiocb
+        .importzp       tmp4
+.ifdef  UCASE_FILENAME
+        .import         ucase_fn
         .import         addysp
         .importzp       sreg
         .importzp       tmp3
-        .importzp       tmp4
+.ifdef  DEFAULT_DEVICE
+        .importzp tmp2
+.endif
+.endif
 
 .proc   __sysrmdir
 
@@ -53,6 +58,10 @@ do_sparta:
 
 .ifdef  UCASE_FILENAME
 
+.ifdef  DEFAULT_DEVICE
+        ldy     #$80
+        sty     tmp2            ; set flag for ucase_fn
+.endif
         jsr     ucase_fn
         bcc     ucok1
 
index a32ddce23dbd0dc824b80b0f2afe5b0c1ff9cb1b..eb3ebfb371f5b2ba0e40c9fc45c63d47a71c5d7e 100644 (file)
@@ -7,6 +7,8 @@
 ;
 ; Calling parameters:
 ;       AX   - points to filename
+;       tmp2 - 0/$80 for don't/do prepend default device if no device
+;              is present in the passed string (only .ifdef DEFAULT_DEVICE)
 ; Return parameters:
 ;       C    - 0/1 for OK/Error (filename too long)
 ;       AX   - points to uppercased version of the filename on the stack
@@ -19,7 +21,7 @@
         .include        "atari.inc"
 
 .ifdef  DEFAULT_DEVICE
-        .importzp tmp2
+        .importzp tmp2, tmp1
         .import __defdev
 .endif
         .importzp tmp3,ptr4,sp
         stx     ptr4+1
 
 .ifdef  DEFAULT_DEVICE
+        ; bit #0 of tmp2 is used as a flag whether device name is present in passed string (1 = present, 0 = not present)
         ldy     #1
-        sty     tmp2            ; initialize flag: device present in passed string
+        inc     tmp2            ; initialize flag: device present
         lda     #':'
         cmp     (ptr4),y
         beq     hasdev
         iny
         cmp     (ptr4),y
         beq     hasdev
-        sta     tmp2            ; set flag: no device in passed string
+        dec     tmp2            ; set flag: no device in passed string
 hasdev:
 .endif
 
@@ -54,7 +57,7 @@ hasdev:
         sty     tmp3            ; save size
         jsr     subysp          ; make room on the stack
 
-        ; copy filename to the temp. place on the stack, also uppercasing it
+        ; copy filename to the temp. place on the stack, while uppercasing it
         ldy     #0
 
 loop2:  lda     (ptr4),y
@@ -77,9 +80,10 @@ L1:
 copy_end:
 
 .ifdef  DEFAULT_DEVICE
-        lda     tmp2
-        cmp     #1              ; was device present in passed string?
-        beq     hasdev2         ; yes, don't prepend something
+        lda     #1
+        bit     tmp2
+        bne     hasdev2         ; yes, don't prepend something
+        bpl     hasdev2
 
         ldy     #128+3          ; no, prepend "D:" (or other device)
         sty     tmp3            ; adjust stack size used