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