2 ; int __fastcall__ vsscanf (const char* str, const char* format, va_list ap);
3 ; /* Standard C function */
5 ; 2004-11-28, Ullrich von Bassewitz
6 ; 2004-12-21, Greg King
11 .import popax, __scanf
12 .importzp sp, ptr1, ptr2
17 ; ----------------------------------------------------------------------------
18 ; Structure used to pass data to the callback functions
26 ; ----------------------------------------------------------------------------
27 ; static int __fastcall__ get (struct sscanfdata* d)
28 ; /* Read a character from the input string and return it */
30 ; char C = d->str[d->index];
34 ; /* Increment index only if end not reached */
46 ; Get d->str adding the high byte of index to the pointer, so we can access
47 ; the byte in the string with just the low byte as index
54 ldy #SSCANFDATA::INDEX+1
58 ; Load the low byte of the index and fetch the byte from the string
60 dey ; = SSCANFDATA::INDEX
65 ; Return EOF if we are at the end of the string
72 ; Bump the index (beware: A contains the char we must return)
74 L1: tax ; Save return value
75 tya ; Low byte of index
76 ldy #SSCANFDATA::INDEX
84 ; Return the char just read
92 ; ----------------------------------------------------------------------------
93 ; static int __fastcall__ unget (int c, struct sscanfdata* d)
94 ; /* Push back a character onto the input stream */
96 ; /* We do assume here that the _scanf routine will not push back anything
97 ; * not read, so we can ignore c safely and won't check the index.
110 ; Decrement the index
112 ldy #SSCANFDATA::INDEX
127 ; ----------------------------------------------------------------------------
128 ; int __fastcall__ vsscanf (const char* str, const char* format, va_list ap)
129 ; /* Standard C function */
131 ; /* Initialize the data structs. The sscanfdata struct will be passed back
132 ; * to the get and unget functions by _scanf().
134 ; static struct sscanfdata sd;
135 ; static const struct scanfdata d = {
144 ; /* Call the internal function and return the result */
145 ; return _scanf (&d, format, ap);
160 ; Save the low byte of ap (which is passed in a/x)
164 ; Initialize sd and at the same time replace str on the stack by a pointer
167 ldy #2 ; Stack offset of str
169 sta sd + SSCANFDATA::STR
174 sta sd + SSCANFDATA::STR+1
179 sta sd + SSCANFDATA::INDEX
180 sta sd + SSCANFDATA::INDEX+1
182 ; Restore the low byte of ap, and jump to _scanf() which will clean up the stack