From c74253d081329289dabb4e8269883f9482ad9e4d Mon Sep 17 00:00:00 2001 From: cuz Date: Sun, 28 Nov 2004 18:11:17 +0000 Subject: [PATCH] Replaced fscanf by an assembler version git-svn-id: svn://svn.cc65.org/cc65/trunk@3313 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- libsrc/common/.cvsignore | 1 - libsrc/common/Makefile | 2 +- libsrc/common/fscanf.c | 36 ------------------ libsrc/common/fscanf.s | 81 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 82 insertions(+), 38 deletions(-) delete mode 100644 libsrc/common/fscanf.c create mode 100644 libsrc/common/fscanf.s diff --git a/libsrc/common/.cvsignore b/libsrc/common/.cvsignore index b15eaacc8..5e71fc4a5 100644 --- a/libsrc/common/.cvsignore +++ b/libsrc/common/.cvsignore @@ -14,7 +14,6 @@ fgets.s fputc.s fputs.s freopen.s -fscanf.s fseek.s fsetpos.s ftell.s diff --git a/libsrc/common/Makefile b/libsrc/common/Makefile index 2aad615ca..86cdd7af5 100644 --- a/libsrc/common/Makefile +++ b/libsrc/common/Makefile @@ -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 index dae7109a5..000000000 --- a/libsrc/common/fscanf.c +++ /dev/null @@ -1,36 +0,0 @@ -/* - * fscanf.c - * - * Ullrich von Bassewitz (uz@cc65.org), 2004-11-26 - * - */ - - - -#include - - - -/*****************************************************************************/ -/* 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 index 000000000..2411f742c --- /dev/null +++ b/libsrc/common/fscanf.s @@ -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 + -- 2.39.5