gba-x3dtest
diff src/logger.c @ 1:b7130fe3f073
foo
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Fri, 13 Jun 2014 19:10:11 +0300 |
parents | 0d2602a1b851 |
children | 850be43b3135 |
line diff
1.1 --- a/src/logger.c Thu Jun 12 05:37:18 2014 +0300 1.2 +++ b/src/logger.c Fri Jun 13 19:10:11 2014 +0300 1.3 @@ -1,17 +1,20 @@ 1.4 #include <stdio.h> 1.5 +#include <string.h> 1.6 #include <stdarg.h> 1.7 #include <ctype.h> 1.8 #include <alloca.h> 1.9 +#include "gbasys.h" 1.10 #include "logger.h" 1.11 1.12 static void putchr(char c); 1.13 static void putstr(const char *str); 1.14 +static void agbprint(const char *str); 1.15 1.16 static int curx, cury; 1.17 static int font_width = 8, font_height = 8; 1.18 static int ncols = 20, nrows = 16; 1.19 1.20 -void logmsg(const char *fmt, ...) 1.21 +void logmsg(unsigned short where, const char *fmt, ...) 1.22 { 1.23 va_list ap; 1.24 int sz; 1.25 @@ -23,24 +26,42 @@ 1.26 1.27 buf = alloca(sz + 1); 1.28 va_start(ap, fmt); 1.29 - vsnprintf(buf, sz, fmt, ap); 1.30 + vsnprintf(buf, sz + 1, fmt, ap); 1.31 va_end(ap); 1.32 1.33 - putstr(buf); 1.34 + if(where & LOG_SCREEN) { 1.35 + putstr(buf); 1.36 + } 1.37 + if(where & LOG_DBG) { 1.38 + agbprint(buf); 1.39 + } 1.40 } 1.41 1.42 static void putchr(char c) 1.43 { 1.44 switch(c) { 1.45 case '\n': 1.46 + curx = 0; 1.47 + if(cury >= nrows - 1) { 1.48 + int row_size = font_height * 160 * 2; 1.49 + memmove(front_buffer->pixels, (char*)front_buffer->pixels + row_size, 1.50 + (nrows - 1) * row_size); 1.51 + memset((char*)front_buffer->pixels + (nrows - 1) * row_size, 0, row_size); 1.52 + } else { 1.53 + ++cury; 1.54 + } 1.55 + break; 1.56 + 1.57 case '\r': 1.58 curx = 0; 1.59 - cury += font_height; 1.60 break; 1.61 1.62 default: 1.63 - if(isprint(c)) { 1.64 - draw_glyph(c, curx, cury, front_buffer); 1.65 + if(isprint((int)c)) { 1.66 + draw_glyph(c, curx * font_width, cury * font_height, front_buffer); 1.67 + if(++curx >= ncols) { 1.68 + putchr('\n'); 1.69 + } 1.70 } 1.71 } 1.72 } 1.73 @@ -49,3 +70,13 @@ 1.74 { 1.75 while(*str) putchr(*str++); 1.76 } 1.77 + 1.78 +static void agbprint(const char *str) 1.79 +{ 1.80 + asm volatile ( 1.81 + "\n\tmov r0, %0" 1.82 + "\n\tswi 0xff0000" 1.83 + : 1.84 + : "r" (str) 1.85 + : "r0"); 1.86 +}