gba-x3dtest
annotate src/logger.c @ 20:2e903e27e35a
fixed x3d_disable_texture
added runtime teture checks in the rasterizer
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Tue, 01 Jul 2014 23:23:37 +0300 |
parents | 850be43b3135 |
children |
rev | line source |
---|---|
nuclear@0 | 1 #include <stdio.h> |
nuclear@1 | 2 #include <string.h> |
nuclear@0 | 3 #include <stdarg.h> |
nuclear@0 | 4 #include <ctype.h> |
nuclear@0 | 5 #include <alloca.h> |
nuclear@1 | 6 #include "gbasys.h" |
nuclear@0 | 7 #include "logger.h" |
nuclear@0 | 8 |
nuclear@0 | 9 static void putchr(char c); |
nuclear@0 | 10 static void putstr(const char *str); |
nuclear@1 | 11 static void agbprint(const char *str); |
nuclear@0 | 12 |
nuclear@0 | 13 static int curx, cury; |
nuclear@0 | 14 static int font_width = 8, font_height = 8; |
nuclear@0 | 15 static int ncols = 20, nrows = 16; |
nuclear@0 | 16 |
nuclear@1 | 17 void logmsg(unsigned short where, const char *fmt, ...) |
nuclear@0 | 18 { |
nuclear@0 | 19 va_list ap; |
nuclear@0 | 20 int sz; |
nuclear@0 | 21 char *buf; |
nuclear@0 | 22 |
nuclear@0 | 23 va_start(ap, fmt); |
nuclear@0 | 24 sz = vsnprintf(0, 0, fmt, ap); |
nuclear@0 | 25 va_end(ap); |
nuclear@0 | 26 |
nuclear@0 | 27 buf = alloca(sz + 1); |
nuclear@0 | 28 va_start(ap, fmt); |
nuclear@1 | 29 vsnprintf(buf, sz + 1, fmt, ap); |
nuclear@0 | 30 va_end(ap); |
nuclear@0 | 31 |
nuclear@1 | 32 if(where & LOG_SCREEN) { |
nuclear@1 | 33 putstr(buf); |
nuclear@1 | 34 } |
nuclear@1 | 35 if(where & LOG_DBG) { |
nuclear@1 | 36 agbprint(buf); |
nuclear@1 | 37 } |
nuclear@0 | 38 } |
nuclear@0 | 39 |
nuclear@0 | 40 static void putchr(char c) |
nuclear@0 | 41 { |
nuclear@0 | 42 switch(c) { |
nuclear@0 | 43 case '\n': |
nuclear@1 | 44 curx = 0; |
nuclear@1 | 45 if(cury >= nrows - 1) { |
nuclear@1 | 46 int row_size = font_height * 160 * 2; |
nuclear@1 | 47 memmove(front_buffer->pixels, (char*)front_buffer->pixels + row_size, |
nuclear@1 | 48 (nrows - 1) * row_size); |
nuclear@1 | 49 memset((char*)front_buffer->pixels + (nrows - 1) * row_size, 0, row_size); |
nuclear@1 | 50 } else { |
nuclear@1 | 51 ++cury; |
nuclear@1 | 52 } |
nuclear@1 | 53 break; |
nuclear@1 | 54 |
nuclear@0 | 55 case '\r': |
nuclear@0 | 56 curx = 0; |
nuclear@0 | 57 break; |
nuclear@0 | 58 |
nuclear@0 | 59 default: |
nuclear@1 | 60 if(isprint((int)c)) { |
nuclear@1 | 61 draw_glyph(c, curx * font_width, cury * font_height, front_buffer); |
nuclear@1 | 62 if(++curx >= ncols) { |
nuclear@1 | 63 putchr('\n'); |
nuclear@1 | 64 } |
nuclear@0 | 65 } |
nuclear@0 | 66 } |
nuclear@0 | 67 } |
nuclear@0 | 68 |
nuclear@0 | 69 static void putstr(const char *str) |
nuclear@0 | 70 { |
nuclear@0 | 71 while(*str) putchr(*str++); |
nuclear@0 | 72 } |
nuclear@1 | 73 |
nuclear@19 | 74 #ifdef __arm__ |
nuclear@1 | 75 static void agbprint(const char *str) |
nuclear@1 | 76 { |
nuclear@1 | 77 asm volatile ( |
nuclear@1 | 78 "\n\tmov r0, %0" |
nuclear@1 | 79 "\n\tswi 0xff0000" |
nuclear@1 | 80 : |
nuclear@1 | 81 : "r" (str) |
nuclear@1 | 82 : "r0"); |
nuclear@1 | 83 } |
nuclear@5 | 84 #else |
nuclear@5 | 85 /* fake version */ |
nuclear@5 | 86 static void agbprint(const char *str) |
nuclear@5 | 87 { |
nuclear@5 | 88 fputs(str, stdout); |
nuclear@5 | 89 fflush(stdout); |
nuclear@5 | 90 } |
nuclear@5 | 91 #endif |