From e4d9fd3bd17dfc57ad8d17852d4c1cd75abd15a3 Mon Sep 17 00:00:00 2001 From: uz Date: Mon, 28 Sep 2009 18:39:55 +0000 Subject: [PATCH] Fixed more bugs, shortened the code where possible. git-svn-id: svn://svn.cc65.org/cc65/trunk@4257 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- libsrc/common/vsnprintf.s | 171 ++++++++++++++++++++------------------ libsrc/common/vsprintf.s | 14 ++-- 2 files changed, 98 insertions(+), 87 deletions(-) diff --git a/libsrc/common/vsnprintf.s b/libsrc/common/vsnprintf.s index 10dc7fa1d..21c358780 100644 --- a/libsrc/common/vsnprintf.s +++ b/libsrc/common/vsnprintf.s @@ -4,7 +4,7 @@ ; Ullrich von Bassewitz, 2009-09-26 ; - .export _vsnprintf + .export _vsnprintf, vsnprintf .import ldaxysp, popax, incsp2, incsp6 .import _memcpy, __printf .importzp sp, ptr1 @@ -26,75 +26,6 @@ bufsize:.word 0 ; Buffer size .code -; ---------------------------------------------------------------------------- -; Callback routine used for the actual output. -; -; static void out (struct outdesc* d, const char* buf, unsigned count) -; /* Routine used for writing */ -; -; Since we know, we're called with a pointer to our static outdesc structure, -; we don't need the pointer passed on the stack. - -out: - -; Calculate the space left in the buffer. If no space is left, don't copy -; any characters - - lda bufsize ; Low byte of buffer size - sec - sbc ccount+0 ; Low byte of bytes already written - sta ptr1 - lda bufsize+1 - sbc ccount+1 - sta ptr1+1 - bcs @L0 ; Space left - lda #0 - sta ptr1 - sta ptr1+1 - -; Replace the pointer to d by a pointer to the write position in the buffer -; for the call to memcpy that follows. - -@L0: lda bufptr+0 - clc - adc ccount+0 - ldy #4 - sta (sp),y - - lda bufptr+1 - adc ccount+1 - iny - sta (sp),y - -; Get Count from stack - - jsr popax - -; outdesc.ccount += Count; - - pha - clc - adc ccount+0 - sta ccount+0 - txa - adc ccount+1 - sta ccount+1 - pla - -; if (Count > Left) Count = Left; - - cpx ptr1+1 - bne @L1 - cmp ptr1 -@L1: bcc @L2 - lda ptr1 - ldx ptr1+1 - -; Jump to memcpy, which will cleanup the stack and return to the caller - -@L2: jmp _memcpy - - ; ---------------------------------------------------------------------------- ; vsprintf - formatted output into a buffer ; @@ -102,10 +33,14 @@ out: ; _vsnprintf: - pha ; Save low byte of ap + pha ; Save ap + txa + pha -; Setup the outdesc structure +; Setup the outdesc structure. This is also an additional entry point for +; vsprintf with ap on stack +vsnprintf: lda #0 sta ccount+0 sta ccount+1 ; Clear ccount @@ -117,11 +52,14 @@ _vsnprintf: ldy #2 lda (sp),y sta ptr1 + lda # Left) Count = Left; + + cpx ptr1+1 + bne @L1 + cmp ptr1 +@L1: bcc @L2 + lda ptr1 + ldx ptr1+1 + +; Jump to memcpy, which will cleanup the stack and return to the caller + +@L2: jmp _memcpy + + + diff --git a/libsrc/common/vsprintf.s b/libsrc/common/vsprintf.s index 4c265ec22..f1a2fe5d8 100644 --- a/libsrc/common/vsprintf.s +++ b/libsrc/common/vsprintf.s @@ -4,9 +4,9 @@ ; Ullrich von Bassewitz, 2009-09-26 ; - .export _vsprintf - .import pushw0sp, staxysp - .import _vsnprintf + .export _vsprintf + .import pushw0sp, staxysp + .import vsnprintf ; ---------------------------------------------------------------------------- @@ -30,10 +30,8 @@ _vsprintf: ldy #2 jsr staxysp -; Retrieve ap and contine by jumping to _vsnprintf, which will cleanup the stack +; Contine by jumping to vsnprintf, which expects ap on the CPU stack and will +; cleanup the C stack - pla - tax - pla - jmp _vsnprintf + jmp vsnprintf -- 2.39.5