gba-x3dtest

view src/logger.c @ 10:23f716fa7f10

changed to mode 5 again, this time with hardware scaling (looks kinda crap)
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 22 Jun 2014 06:31:14 +0300
parents b7130fe3f073
children 62390f9cc93e
line source
1 #include <stdio.h>
2 #include <string.h>
3 #include <stdarg.h>
4 #include <ctype.h>
5 #include <alloca.h>
6 #include "gbasys.h"
7 #include "logger.h"
9 static void putchr(char c);
10 static void putstr(const char *str);
11 static void agbprint(const char *str);
13 static int curx, cury;
14 static int font_width = 8, font_height = 8;
15 static int ncols = 20, nrows = 16;
17 void logmsg(unsigned short where, const char *fmt, ...)
18 {
19 va_list ap;
20 int sz;
21 char *buf;
23 va_start(ap, fmt);
24 sz = vsnprintf(0, 0, fmt, ap);
25 va_end(ap);
27 buf = alloca(sz + 1);
28 va_start(ap, fmt);
29 vsnprintf(buf, sz + 1, fmt, ap);
30 va_end(ap);
32 if(where & LOG_SCREEN) {
33 putstr(buf);
34 }
35 if(where & LOG_DBG) {
36 agbprint(buf);
37 }
38 }
40 static void putchr(char c)
41 {
42 switch(c) {
43 case '\n':
44 curx = 0;
45 if(cury >= nrows - 1) {
46 int row_size = font_height * 160 * 2;
47 memmove(front_buffer->pixels, (char*)front_buffer->pixels + row_size,
48 (nrows - 1) * row_size);
49 memset((char*)front_buffer->pixels + (nrows - 1) * row_size, 0, row_size);
50 } else {
51 ++cury;
52 }
53 break;
55 case '\r':
56 curx = 0;
57 break;
59 default:
60 if(isprint((int)c)) {
61 draw_glyph(c, curx * font_width, cury * font_height, front_buffer);
62 if(++curx >= ncols) {
63 putchr('\n');
64 }
65 }
66 }
67 }
69 static void putstr(const char *str)
70 {
71 while(*str) putchr(*str++);
72 }
74 #ifdef __ARM__
75 static void agbprint(const char *str)
76 {
77 asm volatile (
78 "\n\tmov r0, %0"
79 "\n\tswi 0xff0000"
80 :
81 : "r" (str)
82 : "r0");
83 }
84 #else
85 /* fake version */
86 static void agbprint(const char *str)
87 {
88 fputs(str, stdout);
89 fflush(stdout);
90 }
91 #endif