2000-12-02 09:15:43 +00:00
|
|
|
;
|
2015-07-22 16:56:34 +00:00
|
|
|
; int __fastcall__ vcprintf (const char* Format, va_list ap);
|
2000-12-02 09:15:43 +00:00
|
|
|
;
|
|
|
|
; Ullrich von Bassewitz, 2.12.2000
|
|
|
|
;
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.export _vcprintf
|
2018-05-20 13:30:18 +00:00
|
|
|
.import pushax, popax, popptr1
|
2013-05-09 11:56:54 +00:00
|
|
|
.import __printf, _cputc
|
|
|
|
.importzp sp, ptr1, ptr2, ptr3, tmp1
|
2000-12-02 09:15:43 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.macpack generic
|
2000-12-02 09:15:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
.data
|
|
|
|
|
|
|
|
; ----------------------------------------------------------------------------
|
|
|
|
;
|
|
|
|
; Static data for the _vsprintf routine
|
|
|
|
;
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
outdesc: ; Static outdesc structure
|
|
|
|
.word 0 ; ccount
|
|
|
|
.word out ; Output function pointer
|
|
|
|
.word 0 ; ptr
|
|
|
|
.word 0 ; uns
|
2000-12-02 09:15:43 +00:00
|
|
|
|
|
|
|
.code
|
|
|
|
|
|
|
|
; ----------------------------------------------------------------------------
|
|
|
|
; Callback routine used for the actual output.
|
|
|
|
;
|
2015-07-22 16:56:34 +00:00
|
|
|
; static void __cdecl__ out (struct outdesc* d, const char* buf, unsigned count)
|
2000-12-02 09:15:43 +00:00
|
|
|
; /* Routine used for writing */
|
|
|
|
; {
|
|
|
|
; /* Fast screen output */
|
|
|
|
; d->ccount += count;
|
|
|
|
; while (count) {
|
2013-05-09 11:56:54 +00:00
|
|
|
; cputc (*buf);
|
|
|
|
; ++buf;
|
|
|
|
; --count;
|
2000-12-02 09:15:43 +00:00
|
|
|
; }
|
|
|
|
; }
|
|
|
|
;
|
|
|
|
; We're using ptr1 and tmp1, since we know that the cputc routine will not use
|
|
|
|
; them (they're also used in cputs, so they must be safe).
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
out: jsr popax ; count
|
|
|
|
sta ptr2
|
2020-11-01 21:59:07 +00:00
|
|
|
stx ptr2+1
|
|
|
|
inx
|
|
|
|
stx outdesc+7
|
|
|
|
tax
|
|
|
|
inx
|
|
|
|
stx outdesc+6
|
2000-12-02 09:15:43 +00:00
|
|
|
|
2018-05-20 13:30:18 +00:00
|
|
|
jsr popptr1 ; buf
|
2000-12-02 09:15:43 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
jsr popax ; d
|
|
|
|
sta ptr3
|
|
|
|
stx ptr3+1
|
2000-12-02 09:15:43 +00:00
|
|
|
|
|
|
|
; Sum up the total count of characters
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
ldy #0 ; ccount in struct outdesc
|
|
|
|
sty tmp1 ; Initialize tmp1 while we have zero available
|
|
|
|
lda (ptr3),y
|
|
|
|
add ptr2
|
|
|
|
sta (ptr3),y
|
|
|
|
iny
|
|
|
|
lda (ptr3),y
|
|
|
|
adc ptr2+1
|
|
|
|
sta (ptr3),y
|
2000-12-02 09:15:43 +00:00
|
|
|
|
|
|
|
; Loop outputting characters
|
|
|
|
|
2020-11-01 21:59:07 +00:00
|
|
|
@L1: dec outdesc+6
|
2013-05-09 11:56:54 +00:00
|
|
|
beq @L4
|
|
|
|
@L2: ldy tmp1
|
|
|
|
lda (ptr1),y
|
|
|
|
iny
|
|
|
|
bne @L3
|
|
|
|
inc ptr1+1
|
|
|
|
@L3: sty tmp1
|
|
|
|
jsr _cputc
|
|
|
|
jmp @L1
|
|
|
|
|
2020-11-01 21:59:07 +00:00
|
|
|
@L4: dec outdesc+7
|
2013-05-09 11:56:54 +00:00
|
|
|
bne @L2
|
|
|
|
rts
|
2000-12-02 09:15:43 +00:00
|
|
|
|
|
|
|
; ----------------------------------------------------------------------------
|
|
|
|
; vcprintf - formatted console i/o
|
|
|
|
;
|
2015-07-22 16:56:34 +00:00
|
|
|
; int __fastcall__ vcprintf (const char* format, va_list ap)
|
2000-12-02 09:15:43 +00:00
|
|
|
; {
|
|
|
|
; struct outdesc d;
|
|
|
|
;
|
|
|
|
; /* Setup descriptor */
|
|
|
|
; d.fout = out;
|
|
|
|
;
|
|
|
|
; /* Do formatting and output */
|
|
|
|
; _printf (&d, format, ap);
|
|
|
|
;
|
|
|
|
; /* Return bytes written */
|
|
|
|
; return d.ccount;
|
|
|
|
; }
|
|
|
|
|
|
|
|
_vcprintf:
|
2013-05-09 11:56:54 +00:00
|
|
|
sta ptr1 ; Save ap
|
|
|
|
stx ptr1+1
|
2000-12-02 09:15:43 +00:00
|
|
|
|
|
|
|
; Setup the outdesc structure
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
lda #0
|
|
|
|
sta outdesc
|
|
|
|
sta outdesc+1 ; Clear ccount
|
2000-12-02 09:15:43 +00:00
|
|
|
|
|
|
|
; Get the format parameter and push it again
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
ldy #1
|
|
|
|
lda (sp),y
|
|
|
|
tax
|
|
|
|
dey
|
|
|
|
lda (sp),y
|
|
|
|
jsr pushax
|
2000-12-02 09:15:43 +00:00
|
|
|
|
|
|
|
; Replace the passed format parameter on the stack by &d - this creates
|
|
|
|
; exactly the stack frame _printf expects. Parameters will get dropped
|
|
|
|
; by _printf.
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
ldy #2 ; Low byte of d
|
|
|
|
lda #<outdesc
|
|
|
|
sta (sp),y
|
|
|
|
iny
|
|
|
|
lda #>outdesc
|
|
|
|
sta (sp),y
|
2000-12-02 09:15:43 +00:00
|
|
|
|
|
|
|
; Restore ap and call _printf
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
lda ptr1
|
|
|
|
ldx ptr1+1
|
|
|
|
jsr __printf
|
2000-12-02 09:15:43 +00:00
|
|
|
|
|
|
|
; Return the number of bytes written.
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
lda outdesc ; ccount
|
|
|
|
ldx outdesc+1
|
|
|
|
rts
|