d4c2426fc6f93a1758b6ea1e3d06cffd46c46f05
[gbajam21] / src / debug.c
1 #include <stdio.h>
2 #include <stdarg.h>
3 #include "gbaregs.h"
4 #include "intr.h"
5 #include "debug.h"
6
7 uint16_t vblperf_color[] = {0x3e0, 0xffc0, 0x3ff, 0x1ff, 0x001f, 0xf81f};
8
9 static void vblperf_intr(void)
10 {
11         vblperf_count++;
12 }
13
14 void vblperf_start(int palidx)
15 {
16         vblperf_palptr = (uint16_t*)CRAM_BG_ADDR + palidx;
17         intr_disable();
18         REG_DISPSTAT |= DISPSTAT_IEN_VBLANK;
19         interrupt(INTR_VBLANK, vblperf_intr);
20         unmask(INTR_VBLANK);
21         intr_enable();
22 }
23
24 void vblperf_stop(void)
25 {
26         intr_disable();
27         REG_DISPSTAT &= ~DISPSTAT_IEN_VBLANK;
28         interrupt(INTR_VBLANK, 0);
29         mask(INTR_VBLANK);
30         intr_enable();
31 }
32
33 #ifdef EMUBUILD
34 __attribute__((target("arm")))
35 void emuprint(const char *fmt, ...)
36 {
37         char buf[128];
38         va_list arg_list;
39
40         va_start(arg_list, fmt);
41         vsnprintf(buf, 128, fmt, arg_list);
42         va_end(arg_list);
43
44         __asm__ __volatile__(
45                 "mov r0, %0\n\t"
46                 "swi 0xff0000\n\t" :
47                 : "r" (buf)
48                 : "r0"
49         );
50 }
51 #else
52 void emuprint(const char *fmt, ...)
53 {
54 }
55 #endif