]> git.sur5r.net Git - cc65/commitdiff
Replaced fscanf by an assembler version
authorcuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sun, 28 Nov 2004 18:11:17 +0000 (18:11 +0000)
committercuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sun, 28 Nov 2004 18:11:17 +0000 (18:11 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@3313 b7a2c559-68d2-44c3-8de9-860c34a00d81

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

index b15eaacc83097a22d7af9217c01b5cf1fed1e824..5e71fc4a5267913c03d98401b1a03ad245ac6394 100644 (file)
@@ -14,7 +14,6 @@ fgets.s
 fputc.s
 fputs.s
 freopen.s
-fscanf.s
 fseek.s
 fsetpos.s
 ftell.s
index 2aad615caa6963a1fdf4f86acbe2a846e9422517..86cdd7af5c2a6d6d0219bb58d87fe3093a75132f 100644 (file)
@@ -44,7 +44,6 @@ C_OBJS =      _afailed.o      \
                fputc.o         \
                fputs.o         \
                freopen.o       \
-                fscanf.o        \
                fseek.o         \
                fsetpos.o       \
                ftell.o         \
@@ -100,6 +99,7 @@ S_OBJS =     _cwd.o          \
                fprintf.o       \
                fread.o         \
                free.o          \
+                fscanf.o        \
                fwrite.o        \
                getcpu.o        \
                 getcwd.o        \
diff --git a/libsrc/common/fscanf.c b/libsrc/common/fscanf.c
deleted file mode 100644 (file)
index dae7109..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * fscanf.c
- *
- * Ullrich von Bassewitz (uz@cc65.org), 2004-11-26
- *
- */
-
-
-
-#include <stdio.h>
-
-
-
-/*****************************************************************************/
-/*                                          Code                                    */
-/*****************************************************************************/
-
-
-
-int fscanf (FILE* f, const char* format, ...)
-/* Standard C function */
-{
-    va_list ap;
-
-    /* Setup for variable arguments */
-    va_start (ap, format);
-
-    /* Call vfscanf(). Since we know that va_end won't do anything, we will
-     * save the call and return the value directly.
-     */
-    return vfscanf (f, format, ap);
-}
-
-
-
-
diff --git a/libsrc/common/fscanf.s b/libsrc/common/fscanf.s
new file mode 100644 (file)
index 0000000..2411f74
--- /dev/null
@@ -0,0 +1,81 @@
+;
+; int fscanf (FILE* f, const char* format, ...);
+;
+; Ullrich von Bassewitz, 2004-11-28
+;
+
+       .export         _fscanf
+               .import         addysp, decsp4, _vfscanf
+       .importzp       sp, ptr1
+
+       .macpack        generic
+
+; ----------------------------------------------------------------------------
+; Data
+
+.bss
+
+ParamSize:     .res    1               ; Number of parameter bytes
+
+; ----------------------------------------------------------------------------
+; int fscanf (FILE* f, const char* format, ...)
+; /* Standard C function */
+; {
+;     va_list ap;
+;
+;     /* Setup for variable arguments */
+;     va_start (ap, format);
+;
+;     /* Call vfscanf(). Since we know that va_end won't do anything, we will
+;      * save the call and return the value directly.
+;      */
+;     return vfscanf (f, format, ap);
+; }
+;
+
+.code
+
+_fscanf:
+       sty     ParamSize               ; Number of param bytes passed in Y
+
+; We have to push f and format, both in the order they already have on stack.
+; To make this somewhat more efficient, we will create space on the stack and
+; then do a copy of the complete block instead of pushing each parameter
+; separately. Since the size of the arguments passed is the same as the size
+; of the fixed arguments, this will allow us to calculate the pointer to the
+; fixed size arguments easier (they're just ParamSize bytes away).
+
+       jsr     decsp4
+
+; Calculate a pointer to the Format argument
+
+       lda     ParamSize
+       add     sp
+       sta     ptr1
+       ldx     sp+1
+       bcc     @L1
+       inx
+@L1:   stx     ptr1+1
+
+; Now copy both, f and format
+
+       ldy     #4-1
+@L2:   lda     (ptr1),y
+       sta     (sp),y
+       dey
+       bpl     @L2
+
+; Load va_list (last and __fastcall__ parameter to vfscanf)
+
+       lda     ptr1
+       ldx     ptr1+1
+
+; Call vfscanf
+
+       jsr     _vfscanf
+
+; Cleanup the stack. We will return what we got from vfscanf
+
+       ldy     ParamSize
+       jmp     addysp
+