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 static int32_t bgmat[4];
82 static int32_t bgx, bgy;
84 __attribute__((noinline, target("arm"), section(".iwram")))
85 static void draw_tunnel(void)
88 int i, j, tx, ty, angle, depth, zoffs;
89 uint16_t pptop, ppbot;
91 uint32_t tun, *tunptr;
95 if(bnstate & BN_LT) uoffs++;
96 if(bnstate & BN_RT) uoffs--;
98 bgmat[0] = COS(uoffs) << 1;
99 bgmat[1] = -SIN(uoffs) << 1;
100 bgmat[2] = SIN(uoffs) << 1;
101 bgmat[3] = COS(uoffs) << 1;
102 bgx = (120 << 8) - bgmat[0] * 120 + bgmat[1] * -80;
103 bgy = (80 << 8) - bgmat[2] * 120 + bgmat[3] * -80;
106 bot = vram[backbuf] + 159 * 240 / 2;
108 for(i=0; i<80; i++) {
114 for(j=1; j<240/2; j++) {
116 for(j=0; j<240/2; j++) {
121 depth = (tun >> 8) & 0xff;
122 // tx = ((angle >> 1) - uoffs) & 0x1f;
123 tx = (angle >> 1) & 0x1f;
124 ty = ((depth >> 1) + zoffs) & 0x1f;
125 pptop = tex[(ty << 5) + tx];
126 // tx = ~((angle >> 1) + uoffs) & 0x1f;
127 tx = ~(angle >> 1) & 0x1f;
128 ppbot = tex[(ty << 5) + tx];
130 angle = (tun >> 16) & 0xff;
131 depth = (tun >> 24) & 0xff;
132 // tx = ((angle >> 1) - uoffs) & 0x1f;
133 tx = (angle >> 1) & 0x1f;
134 ty = ((depth >> 1) + zoffs) & 0x1f;
135 pptop |= (uint16_t)tex[(ty << 5) + tx] << 8;
136 // tx = ~((angle >> 1) + uoffs) & 0x1f;
137 tx = ~(angle >> 1) & 0x1f;
138 ppbot |= (uint16_t)tex[(ty << 5) + tx] << 8;
147 __attribute__((noinline, target("arm"), section(".iwram")))
148 static void vblank(void)
152 static short gate_speed;
154 REG_BG2PA = bgmat[0];
155 REG_BG2PB = bgmat[1];
156 REG_BG2PC = bgmat[2];
157 REG_BG2PD = bgmat[3];
161 bnstate = ~REG_KEYINPUT;
162 if(bnstate & BN_DPAD) {
167 if(bnstate & BN_LEFT) x -= gate_speed;
168 if(bnstate & BN_RIGHT) x += gate_speed;
169 if(bnstate & BN_UP) y -= gate_speed;
170 if(bnstate & BN_DOWN) y += gate_speed;
180 if(bnstate & BN_A) rot -= 2;
181 if(bnstate & BN_B) rot += 2;
183 spr_oam(oam, 0, 512 + 256, x - 64, y - 64, SPR_256COL | SPR_SZ64 | SPR_DBLSZ |
184 SPR_ROTSCL | SPR_ROTSCL_SEL(0));
186 mat[0] = COS(rot) << 1;
187 mat[1] = -SIN(rot) << 1;
188 mat[2] = SIN(rot) << 1;
189 mat[3] = COS(rot) << 1;
190 spr_transform(oam, 0, mat);
193 dma_copy16(3, (void*)OAM_ADDR, oam, sizeof oam / 2, 0);