13 static void draw_tunnel(void);
14 static void vblank(void);
16 static int nframes, num_vbl, 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 tunrot;
28 static int32_t tunmat[4], tunx, tuny;
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);
69 REG_BG2X = (120 << 8) - scale * 120;
70 REG_BG2Y = (80 << 8) - scale * 80;
72 /*select_input(BN_DPAD);*/
75 screen_vblank = vblank;
80 backbuf = ++nframes & 1;
82 bnstate = ~REG_KEYINPUT;
93 #define TUN_U(x) ((x) & 0x3f)
94 #define TUN_V(x) (((x) >> 6) & 0x3ff)
95 #define TEXEL(x, y, lvl) \
96 tuncross_shade[((int)tex[((y) << 5) + (x)] << 3) + (lvl)]
98 __attribute__((noinline, target("arm"), section(".iwram")))
99 static void draw_tunnel(void)
101 int i, j, tx, ty, u, v, angle, depth, zoffs, uoffs, flip, tunturn, shade;
103 uint16_t pptop, ppbot;
105 uint32_t tun, *tunptr;
107 //tunsweep = SIN(nframes) >> 4;
109 if((bnstate & BN_RT) && tunsweep > -31) tunsweep--;
110 if((bnstate & BN_LT) && tunsweep < 31) tunsweep++;
113 tunturn = abs(tunsweep) & 0x1f;
116 uoffs = (flip ? -num_vbl : num_vbl) >> 1;
119 bot = vram[backbuf] + 159 * 240 / 2;
120 tunptr = tunmap + tunturn * 9600;
124 for(i=0; i<80; i++) {
125 for(j=0; j<240/2; j++) {
128 angle = TUN_U(tun >> 16);
129 depth = TUN_V(tun >> 16);
131 tx = ~(angle - uoffs) & 0x1f;
132 ty = ((depth >> 1) + zoffs) & 0x1f;
133 pptop = TEXEL(tx, ty, shade);
134 tx = (angle + uoffs) & 0x1f;
135 ppbot = TEXEL(tx, ty, shade);
140 tx = ~(angle - uoffs) & 0x1f;
141 ty = ((depth >> 1) + zoffs) & 0x1f;
142 pptop |= (uint16_t)TEXEL(tx, ty, shade) << 8;
143 tx = (angle + uoffs) & 0x1f;
144 ppbot |= (uint16_t)TEXEL(tx, ty, shade) << 8;
153 for(i=0; i<80; i++) {
154 for(j=0; j<240/2; j++) {
160 tx = (angle - uoffs) & 0x1f;
161 ty = ((depth >> 1) + zoffs) & 0x1f;
162 pptop = TEXEL(tx, ty, shade);
163 tx = ~(angle + uoffs) & 0x1f;
164 ppbot = TEXEL(tx, ty, shade);
166 angle = TUN_U(tun >> 16);
167 depth = TUN_V(tun >> 16);
169 tx = (angle - uoffs) & 0x1f;
170 ty = ((depth >> 1) + zoffs) & 0x1f;
171 pptop |= (uint16_t)TEXEL(tx, ty, shade) << 8;
172 tx = ~(angle + uoffs) & 0x1f;
173 ppbot |= (uint16_t)TEXEL(tx, ty, shade) << 8;
183 __attribute__((noinline, target("arm"), section(".iwram")))
184 static void vblank(void)
188 static short gate_speed;
192 bnstate = ~REG_KEYINPUT;
193 if(bnstate & BN_DPAD) {
198 if(bnstate & BN_LEFT) x -= gate_speed;
199 if(bnstate & BN_RIGHT) x += gate_speed;
200 if(bnstate & BN_UP) y -= gate_speed;
201 if(bnstate & BN_DOWN) y += gate_speed;
211 if(bnstate & BN_A) rot -= 2;
212 if(bnstate & BN_B) rot += 2;
215 spr_oam(oam, 0, 512 + 256, x - 64, y - 64, SPR_256COL | SPR_SZ64 | SPR_DBLSZ |
216 SPR_ROTSCL | SPR_ROTSCL_SEL(0));
222 spr_transform(oam, 0, mat);
225 dma_copy16(3, (void*)OAM_ADDR, oam, sizeof oam / 2, 0);