3 * Copyright 2007 Free Software Foundation, Inc.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * Based on code from the SDCC z80 library ;)
25 #include <hal_io.h> /* FIXME refactor into stdio */
27 #define PUTCHAR(x) hal_putc(x)
31 _printn(unsigned u, unsigned base, char issigned)
33 const char *_hex = "0123456789ABCDEF";
34 if (issigned && ((int)u < 0)) {
36 u = (unsigned)-((int)u);
39 _printn(u/base, base, 0);
40 PUTCHAR(_hex[u%base]);
44 _printf(const char *format, va_list va)
51 case 0: /* hit end of format string */
55 char c = (char)va_arg(va, int);
61 unsigned u = va_arg(va, unsigned);
67 unsigned u = va_arg(va, unsigned);
74 unsigned u = va_arg(va, unsigned);
80 char *s = va_arg(va, char *);
95 _char_emitter(char c, void *pData __attribute__((unused)))
102 printf(const char *format, ...)
105 va_start(va, format);
109 // wrong return value...
116 // Totally dangerous. Don't use
118 _buf_emitter(char c, void *pData)
120 *((*((char **)pData)))++ = c;
123 int sprintf(char *pInto, const char *format, ...)
126 va_start(va, format);
128 _printf(format, _buf_emitter, &pInto, va);
131 // FIXME wrong return value