gba-trycatch

diff src/logger.c @ 0:0d2602a1b851

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 12 Jun 2014 05:37:18 +0300
parents
children b7130fe3f073
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/logger.c	Thu Jun 12 05:37:18 2014 +0300
     1.3 @@ -0,0 +1,51 @@
     1.4 +#include <stdio.h>
     1.5 +#include <stdarg.h>
     1.6 +#include <ctype.h>
     1.7 +#include <alloca.h>
     1.8 +#include "logger.h"
     1.9 +
    1.10 +static void putchr(char c);
    1.11 +static void putstr(const char *str);
    1.12 +
    1.13 +static int curx, cury;
    1.14 +static int font_width = 8, font_height = 8;
    1.15 +static int ncols = 20, nrows = 16;
    1.16 +
    1.17 +void logmsg(const char *fmt, ...)
    1.18 +{
    1.19 +	va_list ap;
    1.20 +	int sz;
    1.21 +	char *buf;
    1.22 +
    1.23 +	va_start(ap, fmt);
    1.24 +	sz = vsnprintf(0, 0, fmt, ap);
    1.25 +	va_end(ap);
    1.26 +
    1.27 +	buf = alloca(sz + 1);
    1.28 +	va_start(ap, fmt);
    1.29 +	vsnprintf(buf, sz, fmt, ap);
    1.30 +	va_end(ap);
    1.31 +
    1.32 +	putstr(buf);
    1.33 +}
    1.34 +
    1.35 +static void putchr(char c)
    1.36 +{
    1.37 +	switch(c) {
    1.38 +	case '\n':
    1.39 +	case '\r':
    1.40 +		curx = 0;
    1.41 +		cury += font_height;
    1.42 +		break;
    1.43 +
    1.44 +	default:
    1.45 +		if(isprint(c)) {
    1.46 +			draw_glyph(c, curx, cury, front_buffer);
    1.47 +		}
    1.48 +	}
    1.49 +}
    1.50 +
    1.51 +static void putstr(const char *str)
    1.52 +{
    1.53 +	while(*str) putchr(*str++);
    1.54 +}