]> git.sur5r.net Git - cc65/blob - libsrc/common/vsprintf.s
c6084bdda7591072c46c310b70f91216a7a297ed
[cc65] / libsrc / common / vsprintf.s
1 ;
2 ; int vsprintf (char* Buf, const char* Format, va_list ap);
3 ;
4 ; Ullrich von Bassewitz, 2009-09-26
5 ;
6
7         .export         _vsprintf
8         .import         ldax0sp, pushax, staxysp
9         .import         _vsnprintf
10
11
12 ; ----------------------------------------------------------------------------
13 ; vsprintf - formatted output into a buffer
14 ;
15 ; int vsprintf (char* buf, const char* format, va_list ap);
16 ;
17
18
19 _vsprintf:
20         pha                     ; Save low byte of ap
21         txa
22         pha                     ; Save high byte of op
23
24 ; Build a stackframe for vsnprintf. To do that, we move format one word down,
25 ; and store 0x7FF (INT_MAX) as size.
26
27         jsr     ldax0sp         ; Get format
28         jsr     pushax          ; And push it
29         lda     #$7F
30         ldx     #$FF            ; INT_MAX
31         ldy     #2
32         jsr     staxysp
33
34 ; Retrieve ap and contine by jumping to _vsnprintf, which will cleanup the stack
35
36         pla
37         tax
38         pla
39         jmp     _vsnprintf
40