Replace vfscanf by an assembler version
git-svn-id: svn://svn.cc65.org/cc65/trunk@3305 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
dbb003c9ac
commit
35b7d549f4
5 changed files with 72 additions and 42 deletions
|
@ -37,7 +37,6 @@ strtok.s
|
||||||
strxfrm.s
|
strxfrm.s
|
||||||
system.s
|
system.s
|
||||||
timezone.s
|
timezone.s
|
||||||
vfscanf.s
|
|
||||||
vscanf.s
|
vscanf.s
|
||||||
vsscanf.s
|
vsscanf.s
|
||||||
|
|
||||||
|
|
|
@ -67,7 +67,6 @@ C_OBJS = _afailed.o \
|
||||||
strtok.o \
|
strtok.o \
|
||||||
system.o \
|
system.o \
|
||||||
timezone.o \
|
timezone.o \
|
||||||
vfscanf.o \
|
|
||||||
vscanf.o \
|
vscanf.o \
|
||||||
vsscanf.o
|
vsscanf.o
|
||||||
|
|
||||||
|
@ -169,6 +168,7 @@ S_OBJS = _cwd.o \
|
||||||
unlink.o \
|
unlink.o \
|
||||||
utscopy.o \
|
utscopy.o \
|
||||||
vfprintf.o \
|
vfprintf.o \
|
||||||
|
vfscanf.o \
|
||||||
vprintf.o \
|
vprintf.o \
|
||||||
vsprintf.o \
|
vsprintf.o \
|
||||||
zerobss.o
|
zerobss.o
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
;----------------------------------------------------------------------------
|
;----------------------------------------------------------------------------
|
||||||
; Global data
|
; Global data
|
||||||
|
|
||||||
.global _scanf
|
.global __scanf
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,39 +0,0 @@
|
||||||
/*
|
|
||||||
* vfscanf.c
|
|
||||||
*
|
|
||||||
* Ullrich von Bassewitz (uz@cc65.org), 2004-11-26
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include "_scanf.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
/* Code */
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int __fastcall__ vfscanf (FILE* f, const char* format, va_list ap)
|
|
||||||
/* Standard C function */
|
|
||||||
{
|
|
||||||
struct scanfdata d;
|
|
||||||
|
|
||||||
/* Initialize the data struct. We do only need the given file as user data,
|
|
||||||
* since the get and ungetc are crafted so they match the standard fgetc
|
|
||||||
* and ungetc functions.
|
|
||||||
*/
|
|
||||||
d.get = (getfunc) fgetc,
|
|
||||||
d.unget = (ungetfunc) ungetc,
|
|
||||||
d.data = f;
|
|
||||||
|
|
||||||
/* Call the internal function and return the result */
|
|
||||||
return _scanf (&d, format, ap);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
70
libsrc/common/vfscanf.s
Normal file
70
libsrc/common/vfscanf.s
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
;
|
||||||
|
; int __fastcall__ vfscanf (FILE* f, const char* format, va_list ap);
|
||||||
|
;
|
||||||
|
; Ullrich von Bassewitz, 2004-11-27
|
||||||
|
;
|
||||||
|
|
||||||
|
.export _vfscanf
|
||||||
|
.import _fgetc, _ungetc
|
||||||
|
|
||||||
|
.include "zeropage.inc"
|
||||||
|
.include "_scanf.inc"
|
||||||
|
|
||||||
|
|
||||||
|
; ----------------------------------------------------------------------------
|
||||||
|
; Static scanfdata structure for the _vfscanf routine
|
||||||
|
;
|
||||||
|
|
||||||
|
.data
|
||||||
|
d: .addr _fgetc ; GET
|
||||||
|
.addr _ungetc ; UNGET
|
||||||
|
.addr 0 ; data
|
||||||
|
|
||||||
|
|
||||||
|
; ----------------------------------------------------------------------------
|
||||||
|
; int __fastcall__ vfscanf (FILE* f, const char* format, va_list ap)
|
||||||
|
; /* Standard C function */
|
||||||
|
; {
|
||||||
|
; struct scanfdata d;
|
||||||
|
;
|
||||||
|
; /* Initialize the data struct. We do only need the given file as user data,
|
||||||
|
; * since the get and ungetc are crafted so they match the standard fgetc
|
||||||
|
; * and ungetc functions.
|
||||||
|
; */
|
||||||
|
; d.get = (getfunc) fgetc,
|
||||||
|
; d.unget = (ungetfunc) ungetc,
|
||||||
|
; d.data = f;
|
||||||
|
;
|
||||||
|
; /* Call the internal function and return the result */
|
||||||
|
; return _scanf (&d, format, ap);
|
||||||
|
; }
|
||||||
|
;
|
||||||
|
; Since _scanf has the same parameter stack as vfscanf, with f replaced by &d,
|
||||||
|
; we will do exactly that. _scanf will then clean up the stack, so we can jump
|
||||||
|
; directly there, no need to return.
|
||||||
|
; Beware: Since ap is a fastcall parameter, we must not destroy a/x.
|
||||||
|
;
|
||||||
|
|
||||||
|
.code
|
||||||
|
_vfscanf:
|
||||||
|
pha ; Save low byte of ap
|
||||||
|
|
||||||
|
; Swap f against &d on the stack, placing f into d.data
|
||||||
|
|
||||||
|
ldy #2 ; Offset of f on the stack
|
||||||
|
lda (sp),y
|
||||||
|
sta d + SCANFDATA::DATA
|
||||||
|
lda #<d
|
||||||
|
sta (sp),y
|
||||||
|
|
||||||
|
iny ; High byte
|
||||||
|
lda (sp),y
|
||||||
|
sta d + SCANFDATA::DATA + 1
|
||||||
|
lda #>d
|
||||||
|
sta (sp),y
|
||||||
|
|
||||||
|
; Restore the low byte of ap and jump to the _scanf function
|
||||||
|
|
||||||
|
pla
|
||||||
|
jmp __scanf
|
||||||
|
|
Loading…
Add table
Reference in a new issue