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 Modifications for PIC14 by
8 Copyright (C) 2019 Gonzalo Pérez de Olaguer Córdoba <salo@gpoc.es>
10 This library is free software; you can redistribute it and/or modify it
11 under the terms of the GNU General Public License as published by the
12 Free Software Foundation; either version 2, or (at your option) any
15 This library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this library; see the file COPYING. If not, write to the
22 Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
25 As a special exception, if you link this library with other files,
26 some of which are compiled with SDCC, to produce an executable,
27 this library does not by itself cause the resulting executable to
28 be covered by the GNU General Public License. This exception does
29 not however invalidate any other reasons why the executable file
30 might be covered by the GNU General Public License.
31 -------------------------------------------------------------------------*/
33 /* following formats are supported :-
34 format output type argument-type
45 %s character generic pointer
52 #if !(defined(__SDCC_pic14) && !defined(__SDCC_PIC14_HAS_VARARGS))
54 #if defined(__SDCC_pic14)
57 #define __idata __data
61 static __data
char radix
;
62 static __bit long_flag
= 0;
63 static __bit string_flag
=0;
64 static __bit char_flag
= 0;
65 static char * __data str
;
66 static __data
long val
;
68 /* This great loop fails with the ds390 port (2003-01-13).
70 At the beginning resp. end of the loop the compiler inserts a "push ar2"
71 resp. "pop ar2", which badly interferes with the push/pop in the source.
73 Library functions should be rock solid and portable. There's an _ltoa in
74 the library, so let's use it and don't reinvent the wheel.
79 #if NICE_LIFO_IMPLEMENTATION_BUT_NOT_PORTABLE
83 static __data
volatile char ch
;
86 static void pval(void)
92 if (val
< 0 && radix
!= 16)
97 else { sign
= 0; lval
= val
;}
110 if(radix
!= 16) ch
= (lval
% radix
) + '0';
111 else ch
= "0123456789ABCDEF"[(unsigned char)lval
& 0x0f];
112 __asm push _ch __endasm
;
115 // This only looks more efficient, but isn't. see the .map
116 ch
= (lval
% radix
) + '0';
118 __asm push _ch __endasm
;
126 __asm push _ch __endasm
;
130 __asm pop _ch __endasm
;
136 #if defined(__SDCC_pic14)
137 void printf_small (const char *fmt
, ...)
139 void printf_small (char * fmt
, ... ) __reentrant
146 for (; *fmt
; fmt
++ ) {
148 long_flag
= string_flag
= char_flag
= 0;
179 str
= va_arg(ap
, char *);
180 while (*str
) putchar(*str
++);
185 val
= va_arg(ap
,long);
188 val
= va_arg(ap
,char);
190 val
= va_arg(ap
,int);
192 #if NICE_LIFO_IMPLEMENTATION_BUT_NOT_PORTABLE
197 static char __idata buffer
[12]; /* 37777777777(oct) */
200 _ltoa (val
, buffer
, radix
);
216 #endif /* __SDCC_pic14 */