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;
33 REG_DISPCNT = 4 | DISPCNT_BG2 | DISPCNT_OBJ | DISPCNT_FB1;
35 vblperf_setcolor(0xff);
38 spr_setup(16, 16, spr_game_pixels, spr_game_cmap);
42 spr_oam_clear(oam, 0);
43 spr_oam_clear(oam, 1);
44 spr_oam_clear(oam, 2);
45 spr_oam_clear(oam, 3);
47 cdst = (uint16_t*)CRAM_BG_ADDR;
49 for(i=0; i<256; i++) {
50 *cdst++ = CONV_RGB24_RGB15(csrc[0], csrc[1], csrc[2]);
54 fillblock_16byte(vram[0], 0xffffffff, 240 * 160 / 16);
55 fillblock_16byte(vram[1], 0xffffffff, 240 * 160 / 16);
57 tex = iwram_sbrk(32 * 32);
58 memcpy(tex, tuncross_pixels, 32 * 32);
60 /*select_input(BN_DPAD);*/
63 screen_vblank = vblank;
68 backbuf = ++nframes & 1;
70 bnstate = ~REG_KEYINPUT;
81 __attribute__((noinline, target("arm"), section(".iwram")))
82 static void draw_tunnel(void)
85 int i, j, tx, ty, angle, depth, zoffs;
86 uint16_t pptop, ppbot;
88 uint32_t tun, *tunptr;
92 if(bnstate & BN_LT) uoffs++;
93 if(bnstate & BN_RT) uoffs--;
96 bot = vram[backbuf] + 159 * 240 / 2;
104 for(j=1; j<240/2; j++) {
106 for(j=0; j<240/2; j++) {
111 depth = (tun >> 8) & 0xff;
112 tx = ((angle >> 1) + uoffs) & 0x1f;
113 ty = ((depth >> 1) + zoffs) & 0x1f;
114 pptop = tex[(ty << 5) + tx];
115 tx = ~((angle >> 1) - uoffs) & 0x1f;
116 ppbot = tex[(ty << 5) + tx];
118 angle = (tun >> 16) & 0xff;
119 depth = (tun >> 24) & 0xff;
120 tx = ((angle >> 1) + uoffs) & 0x1f;
121 ty = ((depth >> 1) + zoffs) & 0x1f;
122 pptop |= (uint16_t)tex[(ty << 5) + tx] << 8;
123 tx = ~((angle >> 1) - uoffs) & 0x1f;
124 ppbot |= (uint16_t)tex[(ty << 5) + tx] << 8;
133 __attribute__((noinline, target("arm"), section(".iwram")))
134 static void vblank(void)
138 static short gate_speed;
140 bnstate = ~REG_KEYINPUT;
141 if(bnstate & BN_DPAD) {
146 if(bnstate & BN_LEFT) x -= gate_speed;
147 if(bnstate & BN_RIGHT) x += gate_speed;
148 if(bnstate & BN_UP) y -= gate_speed;
149 if(bnstate & BN_DOWN) y += gate_speed;
159 if(bnstate & BN_A) rot -= 2;
160 if(bnstate & BN_B) rot += 2;
162 spr_oam(oam, 0, 512 + 256, x - 64, y - 64, SPR_256COL | SPR_SZ64 | SPR_DBLSZ |
163 SPR_ROTSCL | SPR_ROTSCL_SEL(0));
165 mat[0] = COS(rot) << 1;
166 mat[1] = -SIN(rot) << 1;
167 mat[2] = SIN(rot) << 1;
168 mat[3] = COS(rot) << 1;
169 spr_transform(oam, 0, mat);
172 dma_copy16(3, (void*)OAM_ADDR, oam, sizeof oam / 2, 0);