gba-x3dtest
changeset 1:b7130fe3f073
foo
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Fri, 13 Jun 2014 19:10:11 +0300 |
parents | 0d2602a1b851 |
children | 5143908d0220 |
files | .clang_complete Makefile src/logger.c src/logger.h src/main.c |
diffstat | 5 files changed, 101 insertions(+), 15 deletions(-) [+] |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/.clang_complete Fri Jun 13 19:10:11 2014 +0300 1.3 @@ -0,0 +1,2 @@ 1.4 +-Isrc 1.5 +-I../gbasys/src
2.1 --- a/Makefile Thu Jun 12 05:37:18 2014 +0300 2.2 +++ b/Makefile Fri Jun 13 19:10:11 2014 +0300 2.3 @@ -13,11 +13,14 @@ 2.4 CC = $(ARCH)-gcc 2.5 AS = $(ARCH)-as 2.6 OBJCOPY = $(ARCH)-objcopy 2.7 +EMU = vbam 2.8 2.9 -opt = -O3 -fomit-frame-pointer -marm -mcpu=arm7tdmi -mtune=arm7tdmi 2.10 +#opt = -O3 -fomit-frame-pointer -mcpu=arm7tdmi -mtune=arm7tdmi 2.11 +dbg = -g 2.12 2.13 -CFLAGS = $(opt) -pedantic -Wall -I../gbasys/src -I. 2.14 +CFLAGS = $(opt) $(dbg) -pedantic -Wall -I../gbasys/src -I. 2.15 LDFLAGS = ../gbasys/libgbasys.a -lm 2.16 +EMUFLAGS = -T 100 -f 1 2.17 2.18 .PHONY: all 2.19 all: $(bin) $(bin_mb) 2.20 @@ -56,4 +59,4 @@ 2.21 2.22 .PHONY: simrun 2.23 simrun: $(bin) 2.24 - VisualBoyAdvance -T 100 -2 $(bin) 2.25 + $(EMU) $(EMUFLAGS) $(bin)
3.1 --- a/src/logger.c Thu Jun 12 05:37:18 2014 +0300 3.2 +++ b/src/logger.c Fri Jun 13 19:10:11 2014 +0300 3.3 @@ -1,17 +1,20 @@ 3.4 #include <stdio.h> 3.5 +#include <string.h> 3.6 #include <stdarg.h> 3.7 #include <ctype.h> 3.8 #include <alloca.h> 3.9 +#include "gbasys.h" 3.10 #include "logger.h" 3.11 3.12 static void putchr(char c); 3.13 static void putstr(const char *str); 3.14 +static void agbprint(const char *str); 3.15 3.16 static int curx, cury; 3.17 static int font_width = 8, font_height = 8; 3.18 static int ncols = 20, nrows = 16; 3.19 3.20 -void logmsg(const char *fmt, ...) 3.21 +void logmsg(unsigned short where, const char *fmt, ...) 3.22 { 3.23 va_list ap; 3.24 int sz; 3.25 @@ -23,24 +26,42 @@ 3.26 3.27 buf = alloca(sz + 1); 3.28 va_start(ap, fmt); 3.29 - vsnprintf(buf, sz, fmt, ap); 3.30 + vsnprintf(buf, sz + 1, fmt, ap); 3.31 va_end(ap); 3.32 3.33 - putstr(buf); 3.34 + if(where & LOG_SCREEN) { 3.35 + putstr(buf); 3.36 + } 3.37 + if(where & LOG_DBG) { 3.38 + agbprint(buf); 3.39 + } 3.40 } 3.41 3.42 static void putchr(char c) 3.43 { 3.44 switch(c) { 3.45 case '\n': 3.46 + curx = 0; 3.47 + if(cury >= nrows - 1) { 3.48 + int row_size = font_height * 160 * 2; 3.49 + memmove(front_buffer->pixels, (char*)front_buffer->pixels + row_size, 3.50 + (nrows - 1) * row_size); 3.51 + memset((char*)front_buffer->pixels + (nrows - 1) * row_size, 0, row_size); 3.52 + } else { 3.53 + ++cury; 3.54 + } 3.55 + break; 3.56 + 3.57 case '\r': 3.58 curx = 0; 3.59 - cury += font_height; 3.60 break; 3.61 3.62 default: 3.63 - if(isprint(c)) { 3.64 - draw_glyph(c, curx, cury, front_buffer); 3.65 + if(isprint((int)c)) { 3.66 + draw_glyph(c, curx * font_width, cury * font_height, front_buffer); 3.67 + if(++curx >= ncols) { 3.68 + putchr('\n'); 3.69 + } 3.70 } 3.71 } 3.72 } 3.73 @@ -49,3 +70,13 @@ 3.74 { 3.75 while(*str) putchr(*str++); 3.76 } 3.77 + 3.78 +static void agbprint(const char *str) 3.79 +{ 3.80 + asm volatile ( 3.81 + "\n\tmov r0, %0" 3.82 + "\n\tswi 0xff0000" 3.83 + : 3.84 + : "r" (str) 3.85 + : "r0"); 3.86 +}
4.1 --- a/src/logger.h Thu Jun 12 05:37:18 2014 +0300 4.2 +++ b/src/logger.h Fri Jun 13 19:10:11 2014 +0300 4.3 @@ -1,6 +1,12 @@ 4.4 #ifndef LOGGER_H_ 4.5 #define LOGGER_H_ 4.6 4.7 -void logmsg(const char *fmt, ...); 4.8 +enum { 4.9 + LOG_SCREEN = 1, 4.10 + LOG_DBG = 2 4.11 +}; 4.12 +#define LOG_ALL 0xffff 4.13 + 4.14 +void logmsg(unsigned short where, const char *fmt, ...); 4.15 4.16 #endif /* LOGGER_H_ */
5.1 --- a/src/main.c Thu Jun 12 05:37:18 2014 +0300 5.2 +++ b/src/main.c Fri Jun 13 19:10:11 2014 +0300 5.3 @@ -1,21 +1,34 @@ 5.4 #include "gbasys.h" 5.5 +#include "logger.h" 5.6 5.7 static void draw(void); 5.8 -static void keyb_handler(void); 5.9 +static void keyb(int key, int pressed); 5.10 +static void keyb_intr(void); 5.11 5.12 -static unsigned int keystate; 5.13 +static unsigned short keystate; 5.14 + 5.15 +#define EVQ_SIZE 8 5.16 +volatile static unsigned short evhead, evtail; 5.17 +static unsigned short events[EVQ_SIZE]; 5.18 5.19 int main(void) 5.20 { 5.21 gba_init(); 5.22 - //interrupt(INTR_KEY, keyb_handler); 5.23 + interrupt(INTR_KEY, keyb_intr); 5.24 5.25 set_video_mode(VMODE_LFB_160x128_16, 1); 5.26 5.27 clear_buffer(front_buffer, 0); 5.28 - draw_string("please wait...", 0, 0, front_buffer); 5.29 + set_text_writebg(1); 5.30 + logmsg(LOG_ALL, "please wait...\n"); 5.31 5.32 for(;;) { 5.33 + /* process events */ 5.34 + while(evhead != evtail) { 5.35 + unsigned short ev = events[evhead]; 5.36 + evhead = (evhead + 1) % EVQ_SIZE; 5.37 + keyb(ev, 1); 5.38 + } 5.39 draw(); 5.40 } 5.41 return 0; 5.42 @@ -25,6 +38,37 @@ 5.43 { 5.44 } 5.45 5.46 -static void keyb_handler(void) 5.47 +static void keyb(int key, int pressed) 5.48 { 5.49 + static const char *keyname[] = { 5.50 + "A", "B", "select", "start", "right", "left", "up", "down", "RT", "LT" 5.51 + }; 5.52 + int i; 5.53 + for(i=0; i<32; i++) { 5.54 + if(key & 1) { 5.55 + break; 5.56 + } 5.57 + key >>= 1; 5.58 + } 5.59 + if(i < sizeof keyname / sizeof *keyname) { 5.60 + logmsg(LOG_ALL, "key %s %s\n", keyname[i], pressed ? "pressed" : "released"); 5.61 + } 5.62 } 5.63 + 5.64 +static void keyb_intr(void) 5.65 +{ 5.66 + int i; 5.67 + unsigned short prev_keystate = keystate; 5.68 + unsigned short diff; 5.69 + keystate = get_key_state(KEY_ALL); 5.70 + diff = keystate ^ prev_keystate; 5.71 + 5.72 + for(i=0; i<32; i++) { 5.73 + int key = 1 << i; 5.74 + 5.75 + if(diff & key) { 5.76 + events[evtail] = key; 5.77 + evtail = (evtail + 1) % EVQ_SIZE; 5.78 + } 5.79 + } 5.80 +}