initial commit
[gbajam22] / src / gamescr.c
1 #include <stdlib.h>
2 #include <string.h>
3 #include "gbaregs.h"
4 #include "game.h"
5 #include "dma.h"
6 #include "util.h"
7 #include "intr.h"
8 #include "input.h"
9 #include "sprite.h"
10 #include "debug.h"
11
12 static void draw(void);
13 static void vblank(void);
14
15 static int nframes, num_vbl, backbuf;
16 static uint16_t *vram[] = { (uint16_t*)VRAM_LFB_FB0_ADDR, (uint16_t*)VRAM_LFB_FB1_ADDR };
17 static uint16_t bnstate;
18
19
20 void gamescr(void)
21 {
22         int i;
23
24         REG_DISPCNT = 4 | DISPCNT_BG2 | DISPCNT_OBJ | DISPCNT_FB1;
25
26         vblperf_setcolor(0xff);//192);
27
28         fillblock_16byte(vram[0], 0xffffffff, 240 * 160 / 16);
29         fillblock_16byte(vram[1], 0xffffffff, 240 * 160 / 16);
30
31         mask(INTR_VBLANK);
32         screen_vblank = vblank;
33         unmask(INTR_VBLANK);
34
35         nframes = 0;
36         for(;;) {
37                 backbuf = ++nframes & 1;
38
39                 bnstate = ~REG_KEYINPUT;
40
41                 draw();
42
43                 vblperf_end();
44                 wait_vblank();
45                 present(backbuf);
46                 vblperf_begin();
47         }
48 }
49
50 static void draw(void)
51 {
52         int i, j;
53         uint16_t pix;
54         uint16_t *fb = vram[backbuf];
55
56         for(i=0; i<160; i++) {
57                 for(j=0; j<240/2; j++) {
58                         pix = ((i^j) << 1) & 0xff;
59                         pix |= (i^j) << 9;
60                         *fb++ = pix;
61                 }
62         }
63 }
64
65 __attribute__((noinline, target("arm"), section(".iwram")))
66 static void vblank(void)
67 {
68         num_vbl++;
69 }