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