foo
[gbajam21] / src / gamescr.c
1 #include <stdlib.h>
2 #include <string.h>
3 #include "gbaregs.h"
4 #include "dma.h"
5 #include "data.h"
6 #include "util.h"
7 #include "intr.h"
8 #include "debug.h"
9
10 void gamescr(void)
11 {
12         int i, j, tx, ty, angle, depth, nframes, backbuf, zoffs;
13         static uint16_t *vram[] = { (uint16_t*)VRAM_LFB_FB0_ADDR, (uint16_t*)VRAM_LFB_FB1_ADDR };
14         uint16_t *cdst, *top, *bot;
15         unsigned char *csrc;
16         uint32_t tun, *tunptr;
17         unsigned char *tex;
18
19         REG_DISPCNT = 4 | DISPCNT_BG2 | DISPCNT_FB1;
20
21         vblperf_start(0xff);
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         fillblock_16byte(vram[0], 0xffffffff, 240 * 160 / 16);
31         fillblock_16byte(vram[1], 0xffffffff, 240 * 160 / 16);
32
33         tex = iwram_sbrk(32 * 32);
34         memcpy(tex, tuncross_pixels, 32 * 32);
35
36         nframes = 0;
37         for(;;) {
38                 backbuf = ++nframes & 1;
39
40                 zoffs = nframes << 1;
41
42                 top = vram[backbuf];
43                 bot = vram[backbuf] + 159 * 240 / 2;
44                 tunptr = tunmap;
45                 for(i=0; i<80; i++) {
46                         top++;
47                         bot++;
48                         tunptr++;
49                         for(j=1; j<240/2; j++) {
50                                 uint16_t pptop, ppbot;
51
52                                 tun = *tunptr++;
53
54                                 angle = tun & 0xff;
55                                 depth = (tun >> 8) & 0xff;
56                                 tx = ((angle >> 1) + zoffs) & 0x1f;
57                                 ty = ((depth >> 1) + zoffs) & 0x1f;
58                                 pptop = tex[(ty << 5) + tx];
59                                 tx = ((angle >> 1) - zoffs) & 0x1f;
60                                 ppbot = tex[(ty << 5) + tx];
61
62                                 angle = (tun >> 16) & 0xff;
63                                 depth = (tun >> 24) & 0xff;
64                                 tx = ((angle >> 1) + zoffs) & 0x1f;
65                                 ty = ((depth >> 1) + zoffs) & 0x1f;
66                                 pptop |= (uint16_t)tex[(ty << 5) + tx] << 8;
67                                 tx = ((angle >> 1) - zoffs) & 0x1f;
68                                 ppbot |= (uint16_t)tex[(ty << 5) + tx] << 8;
69
70                                 *top++ = pptop;
71                                 *bot++ = ppbot;
72                         }
73                         bot -= 240;
74                 }
75
76                 vblperf_end();
77                 wait_vblank();
78                 present(backbuf);
79                 vblperf_begin();
80         }
81 }