/* libgba stand-ins for mGBA's keyirq test (gba.h). The console is a plain text buffer at * CONSOLE in EWRAM, NUL-terminated, that the runner reads; puts and iprintf append to it. * keyirq prints only constant strings ("PASS ", "FAIL ", prompts), so iprintf copies its * format and takes no arguments. */ #include #include "gba.h" #define CONSOLE ((volatile char *)0x02000000) #define CONSOLE_SIZE 0x1000 static unsigned length; static void put(const char *text) { for (; *text && length < CONSOLE_SIZE - 1; text++) CONSOLE[length++] = *text; CONSOLE[length] = 0; } int puts(const char *text) { put(text); put("\n"); return 0; } int iprintf(const char *format, ...) { put(format); return 0; } void consoleDemoInit(void) { length = 0; CONSOLE[0] = 0; } extern void irq_handler(void); void irqInit(void) { REG_IME = 0; *(void (*volatile *)(void))0x03007FFC = irq_handler; /* the BIOS's IRQ vector */ REG_IME = 1; } void irqEnable(int mask) { REG_IME = 0; if (mask & IRQ_VBLANK) REG_DISPSTAT |= 0x0008; REG_IE |= mask; REG_IME = 1; }