void clr_screen(void) { xputs(CL); curx = cury = 1; }
void start_screen(void) { xputs(TI); xputs(VS); }
void end_screen(void) { xputs(VE); xputs(TE); }
void __xprintf(void *outbuf, const char *fmt, va_list ap, void (*xputc)(void *outbuf, unsigned n, void *cookie), void *cookie) { char scratch[16]; curbufidx = 0; /*serial_puts_msg("\n 1outbuf="); dump_uint(outbuf); serial_puts_msg(" "); serial_puts_msg(" 1curbufidx="); dump_uint(curbufidx); serial_puts_msg(" ");*/ for(;;) { switch(*fmt) { case 0: va_end(ap); return; case '%': switch(fmt[1]) { case 'c': { unsigned n = va_arg(ap, unsigned); xputc(outbuf, n, cookie); fmt += 2; continue; } case 'h': { unsigned n = va_arg(ap, unsigned); xputc(outbuf, hex2asc(n >> 12), cookie); xputc(outbuf, hex2asc(n >> 8), cookie); xputc(outbuf, hex2asc(n >> 4), cookie); xputc(outbuf, hex2asc(n >> 0), cookie); fmt += 2; continue; } case 'b': { unsigned n = va_arg(ap, unsigned); xputc(outbuf, hex2asc(n >> 4), cookie); xputc(outbuf, hex2asc(n >> 0), cookie); fmt += 2; continue; } case 'p': case 'X': case 'x': { unsigned n = va_arg(ap, unsigned); char *p = scratch + 15; *p = 0; do { *--p = hex2asc(n); n = n >> 4; } while(n != 0); while(p > (scratch + 7)) *--p = '0'; xputs(outbuf, p, xputc, cookie); fmt += 2; continue; } case 'd': { int n = va_arg(ap, int); char *p = scratch + 15; *p = 0; if(n < 0) { xputc(outbuf, '-', cookie); n = -n; } do { *--p = (n % 10) + '0'; n /= 10; } while(n != 0); xputs(outbuf, p, xputc, cookie); fmt += 2; continue; } case 's': { char *s = va_arg(ap, char*); if(s == 0) s = "(null)"; xputs(outbuf, s, xputc, cookie); fmt += 2; continue; } } xputc(outbuf, *fmt++, cookie); break; #if 0 case '\n': /*serial_puts_msg(" [ is return : "); dump_uint(fmt[1]); serial_puts_msg(" ] ");*/ xputc(outbuf, '\r', cookie); #endif default: xputc(outbuf, *fmt++, cookie); } } }