* configure,
[fw/sdcc] / device / lib / z80 / printf.c
index d584bdb8c201db7d8eb643f75ab261d1120b237c..65c25b9732de3f67423291f52d37a502d49ea267 100644 (file)
@@ -1,5 +1,5 @@
 /** Simple printf implementation
-    Again a stub - will use the std one later...
+    This stub has been replaced by the std printf_large / sprintf / vprintf
 */
 
 #include <stdarg.h>
@@ -7,10 +7,7 @@
 
 #define STATIC
 
-/* PENDING */
-#define NULL   0
-
-STATIC void _printn(unsigned u, unsigned base, char issigned, void (*emitter)(char, void *), void *pData)
+static void _printn(unsigned u, unsigned base, char issigned, volatile void (*emitter)(char, void *), void *pData)
 {
     const char *_hex = "0123456789ABCDEF";
     if (issigned && ((int)u < 0)) {
@@ -22,7 +19,7 @@ STATIC void _printn(unsigned u, unsigned base, char issigned, void (*emitter)(ch
     (*emitter)(_hex[u%base], pData);
 }
 
-STATIC void _printf(const char *format, void (*emitter)(char, void *), void *pData, va_list va)
+STATIC void _printf(const char *format, volatile void (*emitter)(char, void *), void *pData, va_list va)
 {
     while (*format) {
        if (*format == '%') {
@@ -50,7 +47,7 @@ STATIC void _printf(const char *format, void (*emitter)(char, void *), void *pDa
                    _printn(u, 16, 0, emitter, pData);
                    break;
                }
-           case 's': 
+           case 's':
                {
                    char *s = va_arg(va, char *);
                    while (*s) {
@@ -87,3 +84,20 @@ int printf(const char *format, ...)
     /* PENDING: What to return? */
     return 0;
 }
+
+STATIC void _buf_emitter(char c, void *pData)
+{
+  *((*((char **)pData)))++ = c;
+}
+
+int sprintf(char *pInto, const char *format, ...)
+{
+    va_list va;
+    va_start(va, format);
+
+    _printf(format, _buf_emitter, &pInto, va);
+    *pInto++ = '\0';
+
+    /* PENDING: What to return? */
+    return 0;
+}