13 static void draw_tunnel(void);
14 static void vblank(void);
16 static int nframes, backbuf;
17 static uint16_t *vram[] = { (uint16_t*)VRAM_LFB_FB0_ADDR, (uint16_t*)VRAM_LFB_FB1_ADDR };
18 static unsigned char *tex;
19 static uint16_t bnstate;
22 static uint16_t oam[4 * MAX_SPR];
24 static short x = 120, y = 80;
25 static unsigned char rot;
27 static int32_t bgmat[4];
28 static int32_t bgx, bgy;
29 static int32_t tunrot;
37 REG_DISPCNT = 4 | DISPCNT_BG2 | DISPCNT_OBJ | DISPCNT_FB1;
39 vblperf_setcolor(0xff);
42 spr_setup(16, 16, spr_game_pixels, spr_game_cmap);
46 spr_oam_clear(oam, 0);
47 spr_oam_clear(oam, 1);
48 spr_oam_clear(oam, 2);
49 spr_oam_clear(oam, 3);
51 cdst = (uint16_t*)CRAM_BG_ADDR;
53 for(i=0; i<256; i++) {
54 *cdst++ = CONV_RGB24_RGB15(csrc[0], csrc[1], csrc[2]);
58 fillblock_16byte(vram[0], 0xffffffff, 240 * 160 / 16);
59 fillblock_16byte(vram[1], 0xffffffff, 240 * 160 / 16);
61 tex = iwram_sbrk(32 * 32);
62 memcpy(tex, tuncross_pixels, 32 * 32);
64 /*select_input(BN_DPAD);*/
67 screen_vblank = vblank;
72 backbuf = ++nframes & 1;
74 bnstate = ~REG_KEYINPUT;
85 __attribute__((noinline, target("arm"), section(".iwram")))
86 static void draw_tunnel(void)
88 int i, j, tx, ty, angle, depth, zoffs, uoffs, flip, tunturn;
90 uint16_t pptop, ppbot;
92 uint32_t tun, *tunptr;
94 //tunsweep = SIN(nframes) >> 4;
96 if((bnstate & BN_RT) && tunsweep > -31) tunsweep--;
97 if((bnstate & BN_LT) && tunsweep < 31) tunsweep++;
100 tunturn = abs(tunsweep) & 0x1f;
104 uoffs = flip ? -nframes : nframes;
107 bot = vram[backbuf] + 159 * 240 / 2;
108 tunptr = tunmap + tunturn * 9600;
112 for(i=0; i<80; i++) {
113 for(j=0; j<240/2; j++) {
115 tun = (tun >> 16) | (tun << 16);
118 depth = (tun >> 8) & 0xff;
119 tx = ~((angle >> 1) - uoffs) & 0x1f;
120 ty = ((depth >> 1) + zoffs) & 0x1f;
121 pptop = tex[(ty << 5) + tx];
122 tx = ((angle >> 1) + uoffs) & 0x1f;
123 ppbot = tex[(ty << 5) + tx];
125 angle = (tun >> 16) & 0xff;
126 depth = (tun >> 24) & 0xff;
127 tx = ~((angle >> 1) - uoffs) & 0x1f;
128 ty = ((depth >> 1) + zoffs) & 0x1f;
129 pptop |= (uint16_t)tex[(ty << 5) + tx] << 8;
130 tx = ((angle >> 1) + uoffs) & 0x1f;
131 ppbot |= (uint16_t)tex[(ty << 5) + tx] << 8;
140 for(i=0; i<80; i++) {
141 for(j=0; j<240/2; j++) {
145 depth = (tun >> 8) & 0xff;
146 tx = ((angle >> 1) - uoffs) & 0x1f;
147 ty = ((depth >> 1) + zoffs) & 0x1f;
148 pptop = tex[(ty << 5) + tx];
149 tx = ~((angle >> 1) + uoffs) & 0x1f;
150 ppbot = tex[(ty << 5) + tx];
152 angle = (tun >> 16) & 0xff;
153 depth = (tun >> 24) & 0xff;
154 tx = ((angle >> 1) - uoffs) & 0x1f;
155 ty = ((depth >> 1) + zoffs) & 0x1f;
156 pptop |= (uint16_t)tex[(ty << 5) + tx] << 8;
157 tx = ~((angle >> 1) + uoffs) & 0x1f;
158 ppbot |= (uint16_t)tex[(ty << 5) + tx] << 8;
168 __attribute__((noinline, target("arm"), section(".iwram")))
169 static void vblank(void)
173 static short gate_speed;
175 bnstate = ~REG_KEYINPUT;
176 if(bnstate & BN_DPAD) {
181 if(bnstate & BN_LEFT) x -= gate_speed;
182 if(bnstate & BN_RIGHT) x += gate_speed;
183 if(bnstate & BN_UP) y -= gate_speed;
184 if(bnstate & BN_DOWN) y += gate_speed;
194 if(bnstate & BN_A) rot -= 2;
195 if(bnstate & BN_B) rot += 2;
198 spr_oam(oam, 0, 512 + 256, x - 64, y - 64, SPR_256COL | SPR_SZ64 | SPR_DBLSZ |
199 SPR_ROTSCL | SPR_ROTSCL_SEL(0));
205 spr_transform(oam, 0, mat);
208 dma_copy16(3, (void*)OAM_ADDR, oam, sizeof oam / 2, 0);