Again a stub - will use the std one later...
*/
+#include <stdarg.h>
#include <stdio.h>
-#define NULL 0
+/* PENDING */
+#define NULL 0
-/* A hack because I dont understand how va_arg works...
- sdcc pushes right to left with the real sizes, not cast up
- to an int.
- so printf(int, char, long)
- results in push long, push char, push int
- On the z80 the stack grows down, so the things seem to be in
- the correct order.
- */
-
-typedef char * va_list;
-#define va_start(list, last) list = (char *)&last + sizeof(last)
-#define va_arg(list, type) *(type *)list; list += sizeof(type);
-
-typedef void EMIT(char c, void *pData);
-
-
-static void _printn(unsigned u, unsigned base, char issigned, EMIT *emitter, void *pData)
+static void _printn(unsigned u, unsigned base, char issigned, void (*emitter)(), void *pData)
{
const char *_hex = "0123456789ABCDEF";
if (issigned && ((int)u < 0)) {
(*emitter)(_hex[u%base], pData);
}
-static void _printf(const char *format, EMIT *emitter, void *pData, va_list va)
+static void _printf(const char *format, void (*emitter)(), void *pData, va_list va)
{
while (*format) {
if (*format == '%') {
break;
}
case 'x':
- {
+ {
unsigned u = va_arg(va, unsigned);
_printn(u, 16, 0, emitter, pData);
break;
}
}
+void putchar(char c);
+
static void _char_emitter(char c, void *pData)
{
+ /* PENDING: Make the compiler happy. */
+ pData = 0;
+
putchar(c);
}
-void printf(const char *format, ...)
+int printf(const char *format, ...)
{
va_list va;
va_start(va, format);
_printf(format, _char_emitter, NULL, va);
+ _printf(format, _char_emitter, NULL, va);
+
+ /* PENDING: What to return? */
+ return 0;
}