gba-trycatch

changeset 0:0d2602a1b851

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 12 Jun 2014 05:37:18 +0300
parents
children b7130fe3f073
files Makefile src/logger.c src/logger.h src/main.c
diffstat 4 files changed, 146 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/Makefile	Thu Jun 12 05:37:18 2014 +0300
     1.3 @@ -0,0 +1,59 @@
     1.4 +src = $(wildcard src/*.c)
     1.5 +obj = $(src:.c=.o)
     1.6 +dep = $(obj:.o=.d)
     1.7 +name = trycatch
     1.8 +elf = $(name).elf
     1.9 +bin = $(name).gba
    1.10 +elf_mb = $(name)_mb.elf
    1.11 +bin_mb = $(name)_mb.gba
    1.12 +
    1.13 +ARCH = arm-none-eabi
    1.14 +
    1.15 +CPP = $(ARCH)-cpp
    1.16 +CC = $(ARCH)-gcc
    1.17 +AS = $(ARCH)-as
    1.18 +OBJCOPY = $(ARCH)-objcopy
    1.19 +
    1.20 +opt = -O3 -fomit-frame-pointer -marm -mcpu=arm7tdmi -mtune=arm7tdmi
    1.21 +
    1.22 +CFLAGS = $(opt) -pedantic -Wall -I../gbasys/src -I.
    1.23 +LDFLAGS = ../gbasys/libgbasys.a -lm
    1.24 +
    1.25 +.PHONY: all
    1.26 +all: $(bin) $(bin_mb)
    1.27 +
    1.28 +
    1.29 +$(bin): $(elf)
    1.30 +	$(OBJCOPY) -O binary $(elf) $(bin)
    1.31 +	gbafix $(bin)
    1.32 +
    1.33 +$(bin_mb): $(elf_mb)
    1.34 +	$(OBJCOPY) -O binary $(elf_mb) $(bin_mb)
    1.35 +	gbafix $(bin_mb)
    1.36 +
    1.37 +$(elf): $(obj) ../gbasys/libgbasys.a
    1.38 +	$(CC) -o $(elf) $(obj) -specs=gba.specs $(LDFLAGS)
    1.39 +
    1.40 +$(elf_mb): $(obj) ../gbasys/libgbasys.a
    1.41 +	$(CC) -o $(elf_mb) $(obj) -specs=gba_mb.specs $(LDFLAGS)
    1.42 +
    1.43 +-include $(dep)
    1.44 +
    1.45 +%.d: %.c
    1.46 +	@$(CPP) $(CFLAGS) $< -MM -MT $(@:.d=.o) >$@
    1.47 +
    1.48 +.PHONY: clean
    1.49 +clean:
    1.50 +	rm -f $(obj) $(dep) $(bin) $(bin_mb) $(elf) $(elf_mb)
    1.51 +
    1.52 +.PHONY: install
    1.53 +install: $(bin)
    1.54 +	if2a -n -f -W $<
    1.55 +
    1.56 +.PHONY: run
    1.57 +run: $(bin_mb)
    1.58 +	if2a -m $<
    1.59 +
    1.60 +.PHONY: simrun
    1.61 +simrun: $(bin)
    1.62 +	VisualBoyAdvance -T 100 -2 $(bin)
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/logger.c	Thu Jun 12 05:37:18 2014 +0300
     2.3 @@ -0,0 +1,51 @@
     2.4 +#include <stdio.h>
     2.5 +#include <stdarg.h>
     2.6 +#include <ctype.h>
     2.7 +#include <alloca.h>
     2.8 +#include "logger.h"
     2.9 +
    2.10 +static void putchr(char c);
    2.11 +static void putstr(const char *str);
    2.12 +
    2.13 +static int curx, cury;
    2.14 +static int font_width = 8, font_height = 8;
    2.15 +static int ncols = 20, nrows = 16;
    2.16 +
    2.17 +void logmsg(const char *fmt, ...)
    2.18 +{
    2.19 +	va_list ap;
    2.20 +	int sz;
    2.21 +	char *buf;
    2.22 +
    2.23 +	va_start(ap, fmt);
    2.24 +	sz = vsnprintf(0, 0, fmt, ap);
    2.25 +	va_end(ap);
    2.26 +
    2.27 +	buf = alloca(sz + 1);
    2.28 +	va_start(ap, fmt);
    2.29 +	vsnprintf(buf, sz, fmt, ap);
    2.30 +	va_end(ap);
    2.31 +
    2.32 +	putstr(buf);
    2.33 +}
    2.34 +
    2.35 +static void putchr(char c)
    2.36 +{
    2.37 +	switch(c) {
    2.38 +	case '\n':
    2.39 +	case '\r':
    2.40 +		curx = 0;
    2.41 +		cury += font_height;
    2.42 +		break;
    2.43 +
    2.44 +	default:
    2.45 +		if(isprint(c)) {
    2.46 +			draw_glyph(c, curx, cury, front_buffer);
    2.47 +		}
    2.48 +	}
    2.49 +}
    2.50 +
    2.51 +static void putstr(const char *str)
    2.52 +{
    2.53 +	while(*str) putchr(*str++);
    2.54 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/logger.h	Thu Jun 12 05:37:18 2014 +0300
     3.3 @@ -0,0 +1,6 @@
     3.4 +#ifndef LOGGER_H_
     3.5 +#define LOGGER_H_
     3.6 +
     3.7 +void logmsg(const char *fmt, ...);
     3.8 +
     3.9 +#endif	/* LOGGER_H_ */
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/main.c	Thu Jun 12 05:37:18 2014 +0300
     4.3 @@ -0,0 +1,30 @@
     4.4 +#include "gbasys.h"
     4.5 +
     4.6 +static void draw(void);
     4.7 +static void keyb_handler(void);
     4.8 +
     4.9 +static unsigned int keystate;
    4.10 +
    4.11 +int main(void)
    4.12 +{
    4.13 +	gba_init();
    4.14 +	//interrupt(INTR_KEY, keyb_handler);
    4.15 +
    4.16 +	set_video_mode(VMODE_LFB_160x128_16, 1);
    4.17 +
    4.18 +	clear_buffer(front_buffer, 0);
    4.19 +	draw_string("please wait...", 0, 0, front_buffer);
    4.20 +
    4.21 +	for(;;) {
    4.22 +		draw();
    4.23 +	}
    4.24 +	return 0;
    4.25 +}
    4.26 +
    4.27 +static void draw(void)
    4.28 +{
    4.29 +}
    4.30 +
    4.31 +static void keyb_handler(void)
    4.32 +{
    4.33 +}