2 ; int vcprintf (const char* Format, va_list ap);
4 ; Ullrich von Bassewitz, 2.12.2000
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 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
65 ; Sum up the total count of characters
67 ldy #0 ; ccount in struct outdesc
68 sty tmp1 ; Initialize tmp1 while we have zero available
77 ; Loop outputting characters
94 ; ----------------------------------------------------------------------------
95 ; vcprintf - formatted console i/o
97 ; int vcprintf (const char* format, va_list ap)
101 ; /* Setup descriptor */
104 ; /* Do formatting and output */
105 ; _printf (&d, format, ap);
107 ; /* Return bytes written */
111 ; It is intentional that this function does not have __fastcall__ calling
112 ; conventions - we need the space on the stack anyway, so there's nothing
113 ; gained by using __fastcall__.
119 ; Setup the outdesc structure
123 sta outdesc+1 ; Clear ccount
125 ; Get the format parameter and push it again
134 ; Replace the passed format parameter on the stack by &d - this creates
135 ; exactly the stack frame _printf expects. Parameters will get dropped
138 ldy #2 ; Low byte of d
145 ; Restore ap and call _printf
151 ; Return the number of bytes written.