* printf_tiny.c: NEW,
authorvrokas <vrokas@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 22 Jan 2005 19:24:50 +0000 (19:24 +0000)
committervrokas <vrokas@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 22 Jan 2005 19:24:50 +0000 (19:24 +0000)
* device/lib/pic16/libc/*/Makefile: added --stack-auto to correctly compile
printf_*.c, ltoa.c, etc...

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3649 4a8a32a2-be11-0410-ad9d-d568d2c75423

device/include/pic16/stdio.h
device/lib/pic16/libc/Makefile.rules
device/lib/pic16/libc/stdio/Makefile
device/lib/pic16/libc/stdio/printf_small.c
device/lib/pic16/libc/stdio/printf_tiny.c [new file with mode: 0644]
device/lib/pic16/libc/stdlib/Makefile
device/lib/pic16/libc/stdlib/ltoa.c

index daf5d204b1617c559243cbe38161ba394d7b359c..22cecd5699913723b75ef5481f248f38252ef56e 100644 (file)
 
 /*-----------------------------------------------------------------------*/
 
+/* printf_small() supports float print */
 extern void printf_small(char *, ...);
 
+/* printf_tiny() does not support float print */
+extern void printf_tiny(char *, ...);
+
 extern int printf (char *,...);
 extern int vprintf (char *, va_list);
 
index 582d5bd958ca57a532447222427c7c41f72031c2..839757814ba906ac65f2b029442138d28c4459ad 100644 (file)
@@ -20,7 +20,8 @@ LIBC_INC_DIR  = $(PRJDIR)/device/include/pic16
 
 #OPT_FLAGS     += --pstack-model=large
 
-COMPILE_FLAGS  += $(MODELFLAGS) $(OPT_FLAGS)
+COMPILE_FLAGS  += $(MODELFLAGS)
+COMPILE_FLAGS  += $(OPT_FLAGS)
 
 
 CFLAGS = -I$(LIBC_INC_DIR)
index 3797e4e06efd5358fbebd26fa96038beeff0c5a3..40080668d0d4706854ee38be02cf16bb21d0096d 100644 (file)
@@ -21,7 +21,7 @@ CFILES        = $(patsubst %,%.c,$(SRCS))
 OFILES = $(patsubst %.c,%.o,$(CFILES))
 
 
-DEBUG=
+DEBUG= --stack-auto
 #COMPILE_FLAGS   += --pomit-config-words --pomit-ivt --no-peep
 COMPILE_FLAGS  += $(DEBUG)
 
index 31ef420261bbd10ab9fc4f11d4f5fca2cb7a03b6..2fc589af18bfc903b3f3d1cc2ce1386a0abb6c6b 100644 (file)
@@ -67,8 +67,10 @@ void printf_small(char *fmt, ...)
   float flt;
   char *str;
   data char *str1;
+//#define str1 str
   long val;
-  static char buffer[16];
+//  static
+  char buffer[35];
   va_list ap ;
 
     ch = fmt;
@@ -76,7 +78,8 @@ void printf_small(char *fmt, ...)
 
     while( *ch ) {                     //for (; *fmt ; fmt++ )
         if (*ch == '%') {
-            flong = fstr = fchar = ffloat = 0;
+            flong = 0; fstr = 0; fchar = 0;
+            ffloat = 0;
             radix = 0;
             ch++;
 
diff --git a/device/lib/pic16/libc/stdio/printf_tiny.c b/device/lib/pic16/libc/stdio/printf_tiny.c
new file mode 100644 (file)
index 0000000..d700b3f
--- /dev/null
@@ -0,0 +1,122 @@
+/*-----------------------------------------------------------------
+    printf_tiny.c - source file for reduced version of printf
+
+    Modified for pic16 port, by Vangelis Rokas, 2004 (vrokas@otenet.gr)
+    
+    Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
+
+    This library is free software; you can redistribute it and/or modify it
+    under the terms of the GNU Library General Public License as published by the
+    Free Software Foundation; either version 2, or (at your option) any
+    later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU Library General Public License for more details.
+
+    You should have received a copy of the GNU Library General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+    In other words, you are welcome to use, share and improve this program.
+    You are forbidden to forbid anyone else to use, share and improve
+    what you give them.   Help stamp out software-hoarding!
+-------------------------------------------------------------------------*/
+
+/*
+** $Id$
+*/
+
+/* This function uses function putchar() to dump a character
+ * to standard output. putchar() is defined in libc18f.lib
+ * as dummy function, which will be linked if no putchar()
+ * function is provided by the user.
+ * The user can write his own putchar() function and link it
+ * with the source *BEFORE* the libc18f.lib library. This way
+ * the linker will link the first function (i.e. the user's function) */
+
+/* following formats are supported :-
+   format     output type       argument-type
+     %d        decimal             int
+     %ld       decimal             long
+     %hd       decimal             char
+     %x        hexadecimal         int
+     %lx       hexadecimal         long
+     %hx       hexadecimal         char
+     %o        octal               int
+     %lo       octal               long
+     %ho       octal               char
+     %c        character           char
+     %s        character           generic pointer
+*/
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+void printf_tiny(char *fmt, ...) 
+{
+  char *ch;
+  char radix;
+  char flong;
+  char fstr;
+  char fchar;
+  char *str;
+  data char *str1;
+  long val;
+//  static
+  char buffer[35];
+  va_list ap ;
+
+    ch = fmt;
+    va_start(ap,fmt);
+
+    while( *ch ) {                     //for (; *fmt ; fmt++ )
+        if (*ch == '%') {
+            flong = fstr = fchar = 0;
+            radix = 0;
+            ch++;
+
+            if(*ch == 'l') {
+              flong = 1;
+              ch++;
+            } else
+            if(*ch == 'h') {
+              fchar = 1;
+              ch++;
+            }
+            
+            if(*ch == 's')fstr = 1;
+            else if(*ch == 'd')radix = 10;
+            else if(*ch == 'x')radix = 16;
+            else if(*ch == 'c')radix = 0;
+            else if(*ch == 'o')radix = 8;
+            
+            if(fstr) {
+                str = va_arg(ap, char *);
+                while (*str) putchar(*str++);
+            } else {
+              if(flong)val = va_arg(ap, long);
+              else
+              if(fchar)val = va_arg(ap, char);
+              else {
+                  val = va_arg(ap, int);
+              }
+            
+              if(radix) {
+                ltoa (val, buffer, radix);
+
+                str1 = buffer;
+                while ( *str1 ) {
+                  putchar ( *str1++ );
+                }
+              }        else
+                putchar((char)val);
+            }
+          } else
+            putchar(*ch);
+
+        ch++;
+    }
+}
index b166c4695fb52e2e1af18665674eff1185d6ab9b..00cf59f469a11d6beaa952e5f10606c1be1300a0 100644 (file)
@@ -29,7 +29,7 @@ CFILES        = $(patsubst %,%.c,$(SRCS))
 OFILES = $(patsubst %.c,%.o,$(CFILES))
 
 
-DEBUG=
+DEBUG= --stack-auto
 #COMPILE_FLAGS   += --pomit-config-words --pomit-ivt --denable-peeps --optimize-goto --obanksel=2
 COMPILE_FLAGS  += $(DEBUG)
 
index 84203e8bb6d6ed4954573c05a78e4ca27a353874..875972bfa538dd02f20c26bfd3522eedd7b71638 100644 (file)
@@ -15,7 +15,7 @@
 
 #define NUMBER_OF_DIGITS 32
 
-void ultoa(unsigned long value, data charstring, unsigned char radix)
+void ultoa(unsigned long value, data char *string, unsigned char radix)
 {
 unsigned char index;
 char buffer[NUMBER_OF_DIGITS];  /* space for NUMBER_OF_DIGITS + '\0' */
@@ -35,7 +35,7 @@ char buffer[NUMBER_OF_DIGITS];  /* space for NUMBER_OF_DIGITS + '\0' */
   *string = 0;  /* string terminator */
 }
 
-void ltoa(long value, data charstring, unsigned char radix)
+void ltoa(long value, data char *string, unsigned char radix)
 {
   if (value < 0 && radix == 10) {
     *string++ = '-';