3 ; int fastcall vfprintf(FILE* f, const char* Format, va_list ap);
5 ; 2005-02-08, Ullrich von Bassewitz
6 ; 2005-02-11, Greg King
9 .import push1, pushwysp, incsp6
10 .import _fwrite, __printf
18 ; ----------------------------------------------------------------------------
19 ; Static data for the _vfprintf routine
21 outdesc: ; Static outdesc structure
23 .word out ; Output function pointer
24 ptr: .res 2 ; Points to output file
25 .res 2 ; (Not used by this function)
29 ; ----------------------------------------------------------------------------
30 ; Callback routine used for the actual output.
32 ; Since we know, that this routine is always called with "our" outdesc, we
33 ; can ignore the passed pointer d, and access the data directly. While this
34 ; is not very clean, it gives better and shorter code.
36 ; static void out (struct outdesc* d, const char* buf, unsigned count)
37 ; /* Routine used for writing */
39 ; register size_t cnt;
41 ; /* Write to the file */
42 ; if ((cnt = fwrite(buf, 1, count, ptr)) == 0) {
51 ; fwrite (buf, 1, count, ptr);
54 jsr pushwysp ; Push buf
57 jsr pushwysp ; Push count
61 sta ptr1 ; Save function result
64 ; Check the return value.
69 ; We had an error. Store -1 into ccount
77 bne @Done ; Branch always
79 ; Result was ok, count bytes written
87 jmp incsp6 ; Drop stackframe
90 ; ----------------------------------------------------------------------------
91 ; vfprintf - formatted output
93 ; int fastcall vfprintf(FILE* f, const char* format, va_list ap)
95 ; static struct outdesc d = {
100 ; /* Setup descriptor */
104 ; /* Do formatting and output */
105 ; _printf (&d, format, ap);
107 ; /* Return bytes written */
112 pha ; Save low byte of ap
114 ; Setup the outdesc structure
118 sta ccount+1 ; Clear character-count
120 ; Reorder the stack. Replace f on the stack by &d, so the stack frame is
121 ; exactly as _printf expects it. Parameters will get dropped by _printf.
124 lda (sp),y ; Low byte of f
129 lda (sp),y ; High byte of f
134 ; Restore low byte of ap and call _printf
139 ; Return the number of bytes written