]> git.sur5r.net Git - cc65/commitdiff
Rewrote cbm_open and cbm_read in assembler saving about 80 bytes total.
authorcuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sat, 22 Jun 2002 10:58:24 +0000 (10:58 +0000)
committercuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sat, 22 Jun 2002 10:58:24 +0000 (10:58 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@1318 b7a2c559-68d2-44c3-8de9-860c34a00d81

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

index 1de83fbdbe56297f630b540ca2ad0f8dbd1c26c2..47de2da60b8df336303d19fcc7a4bd5eb316a4ea 100644 (file)
@@ -1,5 +1,3 @@
 cbm_load.s
-cbm_open.s
-cbm_read.s
 cbm_save.s
 cbm_write.s
index a4222f2d660fc87438eb34cb7e5ed6aff791bec7..316f06da541587031c6afdb17053a3ebeff703e5 100644 (file)
 %.o:   %.s
        @$(AS) -g -o $@ $(AFLAGS) $<
 
-C_OBJS = cbm_load.o cbm_save.o cbm_open.o cbm_read.o cbm_write.o
-
-S_OBJS = ctype.o getenv.o gotoxy.o gotox.o gotoy.o where.o\
-        clock.o chline.o cvline.o cclear.o revers.o\
-        c_readst.o c_close.o c_open.o c_ckout.o c_clrch.o c_bsout.o\
-        c_basin.o c_clall.o c_iobase.o c_setnam.o c_setlfs.o c_acptr.o\
-        c_ciout.o c_untlk.o c_unlsn.o c_listen.o c_talk.o c_load.o\
-        c_save.o oserror.o cbm_close.o c_chkin.o
+C_OBJS =       cbm_load.o      \
+               cbm_save.o      \
+               cbm_write.o
+
+S_OBJS =       c_acptr.o       \
+               c_basin.o       \
+               c_bsout.o       \
+               c_chkin.o       \
+               c_ciout.o       \
+               c_ckout.o       \
+               c_clall.o       \
+               c_close.o       \
+               c_clrch.o       \
+               c_iobase.o      \
+               c_listen.o      \
+               c_load.o        \
+               c_open.o        \
+               c_readst.o      \
+               c_save.o        \
+               c_setlfs.o      \
+               c_setnam.o      \
+               c_talk.o        \
+               c_unlsn.o       \
+               c_untlk.o       \
+               cbm_close.o     \
+               cbm_open.o      \
+               cbm_read.o      \
+               cclear.o        \
+               chline.o        \
+               clock.o         \
+               ctype.o         \
+               cvline.o        \
+               getenv.o        \
+               gotox.o         \
+               gotoxy.o        \
+               gotoy.o         \
+               oserror.o       \
+               revers.o        \
+               where.o
 
 all:   $(C_OBJS) $(S_OBJS)
 
index c6c9d9270932f1e3039b7d2048a84718604f0933..23577f9d483dcc4fec7661b4cf2a42355aada469 100644 (file)
@@ -12,4 +12,5 @@ _cbm_k_open:
        jsr     OPEN
        bcs     @NotOk
         lda     #0
-@NotOk:        rts
+@NotOk:        ldx     #0              ; Clear high byte
+        rts
diff --git a/libsrc/cbm/cbm_open.c b/libsrc/cbm/cbm_open.c
deleted file mode 100644 (file)
index 242628e..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * Marc 'BlackJack' Rintsch, 18.03.2001
- *
- * unsigned char cbm_open(unsigned char lfn, unsigned char device,
- *                        unsigned char sec_addr, const char* name);
- */
-#include <cbm.h>
-#include <errno.h>
-
-/* It's like BASIC's: OPEN lfn, device, sec_addr, "name"
- */
-unsigned char cbm_open(unsigned char lfn, unsigned char device,
-                       unsigned char sec_addr, const char* name)
-{
-    cbm_k_setlfs(lfn, device, sec_addr);
-    cbm_k_setnam(name);
-    return _oserror = cbm_k_open();
-}
diff --git a/libsrc/cbm/cbm_open.s b/libsrc/cbm/cbm_open.s
new file mode 100644 (file)
index 0000000..055df9b
--- /dev/null
@@ -0,0 +1,44 @@
+;
+; Ullrich von Bassewitz, 22.06.2002
+;
+; Original C code by Marc 'BlackJack' Rintsch, 18.03.2001
+;
+; unsigned char __fastcall__ cbm_open (unsigned char lfn,
+;                                      unsigned char device,
+;                                      unsigned char sec_addr,
+;                                      const char* name);
+; /* Opens a file. Works just like the BASIC command.
+;  * Returns 0 if opening was successful, otherwise an errorcode (see table
+;  * below).
+;  */
+; {
+;     cbm_k_setlfs(lfn, device, sec_addr);
+;     cbm_k_setnam(name);
+;     return _oserror = cbm_k_open();
+; }
+;
+
+               .export         _cbm_open
+       .import         popa
+        .import         _cbm_k_setlfs, _cbm_k_setnam, _cbm_k_open
+        .import         __oserror
+
+_cbm_open:
+        pha
+        txa
+        pha                     ; Save name
+
+        jsr     popa            ; Get sec_addr
+        jsr     _cbm_k_setlfs   ; Call SETLFS, pop all args
+
+        pla
+        tax
+        pla                     ; Get name
+        jsr     _cbm_k_setnam
+
+        jsr     _cbm_k_open
+        sta     __oserror
+
+        rts
+
+
diff --git a/libsrc/cbm/cbm_read.c b/libsrc/cbm/cbm_read.c
deleted file mode 100644 (file)
index f001128..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Marc 'BlackJack' Rintsch, 19.03.2001
- *
- * int cbm_read(unsigned char lfn, void* buffer, unsigned int size);
- */
-
-#include <cbm.h>
-#include <errno.h>
-
-int cbm_read(unsigned char lfn, void* buffer, unsigned int size)
-{
-    static unsigned int bytesread;
-    static unsigned char tmp;
-
-    /* if we can't change to the inputchannel #lfn then return an error */
-    if (_oserror = cbm_k_chkin(lfn)) return -1;
-    
-    bytesread = 0;
-
-    while (bytesread<size && !cbm_k_readst()) {
-        tmp = cbm_k_basin();
-        
-        /* the kernal routine BASIN sets ST to EOF if the end of file
-         * is reached the first time, then we have store tmp.
-         * every subsequent call returns EOF and READ ERROR in ST, then
-         * we have to exit the loop here immidiatly. */
-        if (cbm_k_readst() & 0xBF) break;
-        
-        ((unsigned char*)buffer)[bytesread++] = tmp;
-    }
-    
-    cbm_k_clrch();
-    return bytesread;
-}
diff --git a/libsrc/cbm/cbm_read.s b/libsrc/cbm/cbm_read.s
new file mode 100644 (file)
index 0000000..20d3db1
--- /dev/null
@@ -0,0 +1,111 @@
+;
+; Ullrich von Bassewitz, 22.06.2002
+;
+; Original C code by Marc 'BlackJack' Rintsch, 19.03.2001
+;
+; int __fastcall__ cbm_read (unsigned char lfn, void* buffer, unsigned int size)
+; /* Reads up to "size" bytes from a file to "buffer".
+;  * Returns the number of actually read bytes, 0 if there are no bytes left
+;  * (EOF) or -1 in case of an error. _oserror contains an errorcode then (see
+;  * table below).
+;  */
+; {
+;     static unsigned int bytesread;
+;     static unsigned char tmp;
+;
+;     /* if we can't change to the inputchannel #lfn then return an error */
+;     if (_oserror = cbm_k_chkin(lfn)) return -1;
+;
+;     bytesread = 0;
+;
+;     while (bytesread<size && !cbm_k_readst()) {
+;         tmp = cbm_k_basin();
+;
+;         /* the kernal routine BASIN sets ST to EOF if the end of file
+;          * is reached the first time, then we have store tmp.
+;          * every subsequent call returns EOF and READ ERROR in ST, then
+;          * we have to exit the loop here immidiatly. */
+;         if (cbm_k_readst() & 0xBF) break;
+;
+;         ((unsigned char*)buffer)[bytesread++] = tmp;
+;     }
+;
+;     cbm_k_clrch();
+;     return bytesread;
+; }
+;
+
+        .include        "cbm.inc"
+
+               .export         _cbm_read
+        .importzp       ptr1, ptr2, ptr3, tmp1
+       .import         popax, popa
+        .import         __oserror
+
+_cbm_read:
+        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     CHKIN
+        bcs     @E1             ; Branch on error
+
+; bytesread = 0;
+
+        lda     #$00
+        sta     ptr3
+        sta     ptr3+1
+        beq     @L3             ; Branch always
+
+; Loop
+
+@L1:    jsr     READST
+        cmp     #0              ; Status ok?
+        bne     @L4
+
+        jsr     BASIN           ; Read next char from file
+        sta     tmp1            ; Save it for later
+
+        jsr     READST
+        and     #$BF
+        bne     @L4
+
+        lda     tmp1
+        ldy     #0
+        sta     (ptr2),y        ; Save read byte
+
+        inc     ptr2
+        bne     @L2
+        inc     ptr2+1          ; ++buffer;
+
+@L2:    inc     ptr3
+        bne     @L3
+        inc     ptr3+1          ; ++bytesread;
+
+@L3:    inc     ptr1
+        bne     @L1
+        inc     ptr1+1
+        bne     @L1
+
+@L4:    jsr     CLRCH
+
+        lda     ptr3
+        ldx     ptr3+1          ; return bytesread;
+
+        rts
+
+; CHKIN failed
+
+@E1:    sta     __oserror
+        lda     #$FF
+        tax
+        rts                     ; return -1
+