gba-trycatch

view 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 source
1 #include <stdio.h>
2 #include <stdarg.h>
3 #include <ctype.h>
4 #include <alloca.h>
5 #include "logger.h"
7 static void putchr(char c);
8 static void putstr(const char *str);
10 static int curx, cury;
11 static int font_width = 8, font_height = 8;
12 static int ncols = 20, nrows = 16;
14 void logmsg(const char *fmt, ...)
15 {
16 va_list ap;
17 int sz;
18 char *buf;
20 va_start(ap, fmt);
21 sz = vsnprintf(0, 0, fmt, ap);
22 va_end(ap);
24 buf = alloca(sz + 1);
25 va_start(ap, fmt);
26 vsnprintf(buf, sz, fmt, ap);
27 va_end(ap);
29 putstr(buf);
30 }
32 static void putchr(char c)
33 {
34 switch(c) {
35 case '\n':
36 case '\r':
37 curx = 0;
38 cury += font_height;
39 break;
41 default:
42 if(isprint(c)) {
43 draw_glyph(c, curx, cury, front_buffer);
44 }
45 }
46 }
48 static void putstr(const char *str)
49 {
50 while(*str) putchr(*str++);
51 }