2 ; int vsnprintf (char* Buf, size_t size, const char* Format, va_list ap);
4 ; Ullrich von Bassewitz, 2009-09-26
8 .import ldaxysp, popax, incsp2, incsp6
9 .import _memcpy, __printf
16 ; ----------------------------------------------------------------------------
18 ; Static data for the _vsnprintf routine
21 outdesc: ; Static outdesc structure
22 ccount: .word 0 ; ccount
23 func: .word out ; Output function pointer
25 bufsize:.word 0 ; Buffer size
29 ; ----------------------------------------------------------------------------
30 ; Callback routine used for the actual output.
32 ; static void out (struct outdesc* d, const char* buf, unsigned count)
33 ; /* Routine used for writing */
35 ; Since we know, we're called with a pointer to our static outdesc structure,
36 ; we don't need the pointer passed on the stack.
40 ; Calculate the space left in the buffer. If no space is left, don't copy
43 lda bufsize ; Low byte of buffer size
45 sbc ccount+0 ; Low byte of bytes already written
55 ; Replace the pointer to d by a pointer to the write position in the buffer
56 ; for the call to memcpy that follows.
69 ; Get Count from stack
73 ; outdesc.ccount += Count;
84 ; if (Count > Left) Count = Left;
93 ; Jump to memcpy, which will cleanup the stack and return to the caller
98 ; ----------------------------------------------------------------------------
99 ; vsprintf - formatted output into a buffer
101 ; int __fastcall__ vsnprintf (char* buf, size_t size, const char* format, va_list ap);
105 pha ; Save low byte of ap
107 ; Setup the outdesc structure
111 sta ccount+1 ; Clear ccount
113 ; Get the size parameter and replace it by a pointer to outdesc. This is to
114 ; build a stack frame for the call to _printf.
115 ; If size is zero, there's nothing to do.
131 ; Write size-1 to outdesc.uns
141 ; Copy buf to the outdesc.ptr
148 ; Restore low byte of ap and call _printf
153 ; Terminate the string
174 ; Return the number of bytes written and drop buf
180 ; Bail out if size is zero
184 jmp incsp6 ; Drop parameters