]> git.sur5r.net Git - cc65/commitdiff
Rewrite cbm_write() in assembler
authorcuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Fri, 15 Nov 2002 18:21:32 +0000 (18:21 +0000)
committercuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Fri, 15 Nov 2002 18:21:32 +0000 (18:21 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@1524 b7a2c559-68d2-44c3-8de9-860c34a00d81

libsrc/cbm/.cvsignore
libsrc/cbm/Makefile
libsrc/cbm/cbm_write.c [deleted file]
libsrc/cbm/cbm_write.s [new file with mode: 0644]

index 47de2da60b8df336303d19fcc7a4bd5eb316a4ea..4b273aef66324bbabbb6887a792718250f7420f9 100644 (file)
@@ -1,3 +1,2 @@
 cbm_load.s
 cbm_save.s
-cbm_write.s
index b224d139b3a2a51bde0cd75b28ce4541b880c284..a95d33219fb7bd406248def0dabce9e4a9084e70 100644 (file)
@@ -12,8 +12,7 @@
        @$(AS) -g -o $@ $(AFLAGS) $<
 
 C_OBJS =       cbm_load.o      \
-               cbm_save.o      \
-               cbm_write.o
+               cbm_save.o
 
 S_OBJS =       c_acptr.o       \
                c_basin.o       \
@@ -38,6 +37,7 @@ S_OBJS =      c_acptr.o       \
                cbm_close.o     \
                cbm_open.o      \
                cbm_read.o      \
+               cbm_write.o     \
                cclear.o        \
                chline.o        \
                clock.o         \
diff --git a/libsrc/cbm/cbm_write.c b/libsrc/cbm/cbm_write.c
deleted file mode 100644 (file)
index 8443362..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Marc 'BlackJack' Rintsch, 25.03.2001
- *
- * int cbm_write(unsigned char lfn, void* buffer, unsigned int size);
- */
-
-#include <cbm.h>
-#include <errno.h>
-
-int cbm_write(unsigned char lfn, void* buffer, unsigned int size) {
-
-    static unsigned int byteswritten;
-    
-    /* if we can't change to the outputchannel #lfn then return an error */
-    if (_oserror = cbm_k_ckout(lfn)) return -1;
-    
-    byteswritten = 0;
-    
-    while (byteswritten<size && !cbm_k_readst()) {
-        cbm_k_bsout(((unsigned char*)buffer)[byteswritten++]);
-    }
-
-    if (cbm_k_readst()) {
-        _oserror = 5;       /* device not present */
-        byteswritten = -1;
-    }
-        
-    cbm_k_clrch();
-    
-    return byteswritten;
-}
diff --git a/libsrc/cbm/cbm_write.s b/libsrc/cbm/cbm_write.s
new file mode 100644 (file)
index 0000000..71ce6c9
--- /dev/null
@@ -0,0 +1,92 @@
+;
+; Ullrich von Bassewitz, 15.11.2002
+;
+; Original C code by Marc 'BlackJack' Rintsch, 25.03.2001
+;
+; int cbm_write(unsigned char lfn, void* buffer, unsigned int size) {
+;
+;     static unsigned int byteswritten;
+;
+;     /* if we can't change to the outputchannel #lfn then return an error */
+;     if (_oserror = cbm_k_ckout(lfn)) return -1;
+;
+;     byteswritten = 0;
+;
+;     while (byteswritten<size && !cbm_k_readst()) {
+;         cbm_k_bsout(((unsigned char*)buffer)[byteswritten++]);
+;     }
+;
+;     if (cbm_k_readst()) {
+;         _oserror = 5;       /* device not present */
+;         byteswritten = -1;
+;     }
+;
+;     cbm_k_clrch();
+;
+;     return byteswritten;
+; }
+;
+
+        .include        "cbm.inc"
+
+               .export         _cbm_write
+        .importzp       ptr1, ptr2, ptr3
+       .import         popax, popa
+        .import         __oserror
+
+_cbm_write:
+        sta     ptr3
+        stx     ptr3+1          ; Save size
+        eor     #$FF
+        sta     ptr1
+        txa
+        eor     #$FF
+        sta     ptr1+1          ; Save -size-1
+
+        jsr     popax
+        sta     ptr2
+        stx     ptr2+1          ; Save buffer
+
+        jsr     popa
+        tax
+        jsr     CKOUT
+        bcs     @E2             ; Branch on error
+        bcc     @L3             ; Branch always
+
+; Loop
+
+@L1:    jsr     READST
+        cmp     #0              ; Status ok?
+        bne     @E1
+
+        ldy     #0
+        lda     (ptr2),y        ;
+        inc     ptr2
+        bne     @L2
+        inc     ptr2+1          ; A = *buffer++;
+
+@L2:    jsr     BSOUT           ; cbm_k_bsout (A);
+
+@L3:    inc     ptr1            ; --size;
+        bne     @L1
+        inc     ptr1+1
+        bne     @L1
+
+        jsr     CLRCH
+
+        lda     ptr3
+        ldx     ptr3+1          ; return size;
+
+        rts
+
+; Error entry, called when READST fails
+
+@E1:    lda     #5
+
+; Error entry, error code is in A
+
+@E2:    sta     __oserror
+        lda     #$FF
+        tax
+        rts                     ; return -1
+