2 ; int __fastcall__ vfscanf (FILE* f, const char* format, va_list ap);
4 ; 2004-11-27, Ullrich von Bassewitz
5 ; 2004-12-21, Greg King
9 .import _fgetc, _ungetc, _ferror
11 .include "zeropage.inc"
16 count := ptr3 ; Result of scan
19 ; ----------------------------------------------------------------------------
20 ; Static scanfdata structure for the _vfscanf routine
29 ; ----------------------------------------------------------------------------
30 ; int __fastcall__ vfscanf (FILE* f, const char* format, va_list ap)
31 ; /* Standard C function */
33 ; /* Initialize the data struct. We do only need the given file as user data,
34 ; * because the (getfunc) and (ungetfunc) functions are crafted so that they
35 ; * match the standard-I/O fgetc() and ungetc().
37 ; static struct scanfdata d = {
45 ; /* Call the internal function */
46 ; count = _scanf (&d, format, ap);
48 ; /* And, return the result */
49 ; return ferror (f) ? EOF : count;
52 ; Because _scanf() has the same parameter stack as vfscanf(), with f replaced
53 ; by &d, we will do exactly that. _scanf() then will clean up the stack.
54 ; Beware: Since ap is a fastcall parameter, we must not destroy a/x.
59 pha ; Save low byte of ap
61 ; Swap f against &d on the stack, placing f into d.data
63 ldy #2 ; Offset of f on the stack
65 sta d + SCANFDATA::DATA
71 sta d + SCANFDATA::DATA + 1
75 ; Restore the low byte of ap, and call the _scanf function
82 ; Return -1 if there was a read error during the scan
84 lda d + SCANFDATA::DATA ; Get f
85 ldx d + SCANFDATA::DATA+1
93 ; Or, return the result of the scan