tunnel
[gbajam21] / src / gamescr.c
1 #include <string.h>
2 #include "gbaregs.h"
3 #include "dma.h"
4 #include "data.h"
5 #include "debug.h"
6
7 #define present(x) \
8         do { \
9                 REG_DISPCNT = DISPCNT_BG2 | 4 | ((x) << 4); \
10         } while(0)
11
12
13 void gamescr(void)
14 {
15         int i, j, tx, ty, angle, depth, nframes, backbuf, zoffs;
16         static uint16_t *vram[] = { (uint16_t*)VRAM_LFB_FB0_ADDR, (uint16_t*)VRAM_LFB_FB1_ADDR };
17         uint16_t *cdst;
18         unsigned char *csrc;
19         uint32_t tun, *tunptr;
20
21         REG_DISPCNT = 4 | DISPCNT_BG2 | DISPCNT_FB1;
22
23         cdst = (uint16_t*)CRAM_BG_ADDR;
24         csrc = tuncross_cmap;
25         for(i=0; i<256; i++) {
26                 *cdst++ = CONV_RGB24_RGB15(csrc[0], csrc[1], csrc[2]);
27                 csrc += 3;
28         }
29
30         nframes = 0;
31         for(;;) {
32                 backbuf = ++nframes & 1;
33
34                 zoffs = nframes << 1;
35
36                 cdst = vram[backbuf];
37                 tunptr = tunmap;
38                 for(i=0; i<160; i++) {
39                         for(j=0; j<240/2; j++) {
40                                 uint16_t pp;
41
42                                 tun = *tunptr++;
43                                 angle = tun & 0xffff;
44                                 depth = tun >> 16;
45                                 tx = (angle >> 6) & 0x7f;
46                                 ty = ((depth >> 7) - zoffs) & 0x7f;
47                                 pp = tuncross_pixels[(ty << 7) + tx];
48
49                                 tun = *tunptr++;
50                                 angle = tun & 0xffff;
51                                 depth = tun >> 16;
52                                 tx = (angle >> 6) & 0x7f;
53                                 ty = ((depth >> 7) - zoffs) & 0x7f;
54                                 pp |= (uint16_t)tuncross_pixels[(ty << 7) + tx] << 8;
55
56                                 *cdst++ = pp;
57                         }
58                 }
59
60                 //while(!(REG_DISPSTAT & DISPSTAT_VBLANK));
61                 while(REG_VCOUNT < 160);
62                 //REG_DISPCNT ^= DISPCNT_FB1;
63                 present(backbuf);
64         }
65 }