2 ; int __fastcall__ vcprintf (const char* Format, va_list ap);
4 ; Ullrich von Bassewitz, 2.12.2000
8 .import pushax, popax, popptr1
9 .import __printf, _cputc
10 .importzp sp, ptr1, ptr2, ptr3, tmp1
17 ; ----------------------------------------------------------------------------
19 ; Static data for the _vsprintf routine
22 outdesc: ; Static outdesc structure
24 .word out ; Output function pointer
30 ; ----------------------------------------------------------------------------
31 ; Callback routine used for the actual output.
33 ; static void __cdecl__ out (struct outdesc* d, const char* buf, unsigned count)
34 ; /* Routine used for writing */
36 ; /* Fast screen output */
45 ; We're using ptr1 and tmp1, since we know that the cputc routine will not use
46 ; them (they're also used in cputs, so they must be safe).
48 out: jsr popax ; count
63 ; Sum up the total count of characters
65 ldy #0 ; ccount in struct outdesc
66 sty tmp1 ; Initialize tmp1 while we have zero available
75 ; Loop outputting characters
92 ; ----------------------------------------------------------------------------
93 ; vcprintf - formatted console i/o
95 ; int __fastcall__ vcprintf (const char* format, va_list ap)
99 ; /* Setup descriptor */
102 ; /* Do formatting and output */
103 ; _printf (&d, format, ap);
105 ; /* Return bytes written */
113 ; Setup the outdesc structure
117 sta outdesc+1 ; Clear ccount
119 ; Get the format parameter and push it again
128 ; Replace the passed format parameter on the stack by &d - this creates
129 ; exactly the stack frame _printf expects. Parameters will get dropped
132 ldy #2 ; Low byte of d
139 ; Restore ap and call _printf
145 ; Return the number of bytes written.