1 /*-----------------------------------------------------------------
2 printfl.c - source file for reduced version of printf
4 Copyright (C) 1999, Sandeep Dutta . sandeep.dutta@usa.net
5 2001060401: Improved by was@icb.snz.chel.su
7 This library is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 2, or (at your option) any
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this library; see the file COPYING. If not, write to the
19 Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
22 As a special exception, if you link this library with other files,
23 some of which are compiled with SDCC, to produce an executable,
24 this library does not by itself cause the resulting executable to
25 be covered by the GNU General Public License. This exception does
26 not however invalidate any other reasons why the executable file
27 might be covered by the GNU General Public License.
28 -------------------------------------------------------------------------*/
30 /* following formats are supported :-
31 format output type argument-type
42 %s character generic pointer
49 static __data
char radix
;
50 static __bit long_flag
= 0;
51 static __bit string_flag
=0;
52 static __bit char_flag
= 0;
53 static char * __data str
;
54 static __data
long val
;
56 /* This great loop fails with the ds390 port (2003-01-13).
58 At the beginning resp. end of the loop the compiler inserts a "push ar2"
59 resp. "pop ar2", which badly interferes with the push/pop in the source.
61 Library functions should be rock solid and portable. There's an __ltoa in
62 the library, so let's use it and don't reinvent the wheel.
67 #if NICE_LIFO_IMPLEMENTATION_BUT_NOT_PORTABLE
71 static __data
volatile char ch
;
74 static void pval(void)
80 if (val
< 0 && radix
!= 16)
85 else { sign
= 0; lval
= val
;}
98 if(radix
!= 16) ch
= (lval
% radix
) + '0';
99 else ch
= "0123456789ABCDEF"[(unsigned char)lval
& 0x0f];
100 __asm push _ch __endasm
;
103 // This only looks more efficient, but isn't. see the .map
104 ch
= (lval
% radix
) + '0';
106 __asm push _ch __endasm
;
114 __asm push _ch __endasm
;
118 __asm pop _ch __endasm
;
124 void printf_small (char * fmt
, ... ) __reentrant
130 for (; *fmt
; fmt
++ ) {
132 long_flag
= string_flag
= char_flag
= 0;
163 str
= va_arg(ap
, char *);
164 while (*str
) putchar(*str
++);
169 val
= va_arg(ap
,long);
172 val
= va_arg(ap
,char);
174 val
= va_arg(ap
,int);
176 #if NICE_LIFO_IMPLEMENTATION_BUT_NOT_PORTABLE
181 static char __idata buffer
[12]; /* 37777777777(oct) */
184 __ltoa (val
, buffer
, radix
);