static void draw_tunnel(void);
static void vblank(void);
-static int nframes, backbuf;
+static int nframes, num_vbl, backbuf;
static uint16_t *vram[] = { (uint16_t*)VRAM_LFB_FB0_ADDR, (uint16_t*)VRAM_LFB_FB1_ADDR };
static unsigned char *tex;
static uint16_t bnstate;
}
}
+#define TUN_U(x) ((x) & 0x3f)
+#define TUN_V(x) (((x) >> 7) & 0x1ff)
+
__attribute__((noinline, target("arm"), section(".iwram")))
static void draw_tunnel(void)
{
- int i, j, tx, ty, angle, depth, zoffs, uoffs, flip, tunturn;
+ int i, j, tx, ty, u, v, angle, depth, zoffs, uoffs, flip, tunturn;
static int tunsweep;
uint16_t pptop, ppbot;
uint16_t *top, *bot;
flip = tunsweep < 0;
tunturn = abs(tunsweep) & 0x1f;
- zoffs = nframes;
-
- uoffs = flip ? -nframes : nframes;
+ zoffs = num_vbl;
+ uoffs = 0;//(flip ? -num_vbl : num_vbl) >> 2;
top = vram[backbuf];
bot = vram[backbuf] + 159 * 240 / 2;
for(i=0; i<80; i++) {
for(j=0; j<240/2; j++) {
tun = *--tunptr;
- tun = (tun >> 16) | (tun << 16);
- angle = tun & 0xff;
- depth = (tun >> 8) & 0xff;
- tx = ~((angle >> 1) - uoffs) & 0x1f;
- ty = ((depth >> 1) + zoffs) & 0x1f;
+ angle = TUN_U(tun >> 16);
+ depth = TUN_V(tun >> 16);
+ tx = ~(angle - uoffs) & 0x1f;
+ ty = (depth + zoffs) & 0x1f;
pptop = tex[(ty << 5) + tx];
- tx = ((angle >> 1) + uoffs) & 0x1f;
+ tx = (angle + uoffs) & 0x1f;
ppbot = tex[(ty << 5) + tx];
- angle = (tun >> 16) & 0xff;
- depth = (tun >> 24) & 0xff;
- tx = ~((angle >> 1) - uoffs) & 0x1f;
- ty = ((depth >> 1) + zoffs) & 0x1f;
+ angle = TUN_U(tun);
+ depth = TUN_V(tun);
+ tx = ~(angle - uoffs) & 0x1f;
+ ty = (depth + zoffs) & 0x1f;
pptop |= (uint16_t)tex[(ty << 5) + tx] << 8;
- tx = ((angle >> 1) + uoffs) & 0x1f;
+ tx = (angle + uoffs) & 0x1f;
ppbot |= (uint16_t)tex[(ty << 5) + tx] << 8;
*top++ = pptop;
for(j=0; j<240/2; j++) {
tun = *tunptr++;
- angle = tun & 0xff;
- depth = (tun >> 8) & 0xff;
- tx = ((angle >> 1) - uoffs) & 0x1f;
- ty = ((depth >> 1) + zoffs) & 0x1f;
+ angle = TUN_U(tun);
+ depth = TUN_V(tun);
+ tx = (angle - uoffs) & 0x1f;
+ ty = (depth + zoffs) & 0x1f;
pptop = tex[(ty << 5) + tx];
- tx = ~((angle >> 1) + uoffs) & 0x1f;
+ tx = ~(angle + uoffs) & 0x1f;
ppbot = tex[(ty << 5) + tx];
- angle = (tun >> 16) & 0xff;
- depth = (tun >> 24) & 0xff;
- tx = ((angle >> 1) - uoffs) & 0x1f;
- ty = ((depth >> 1) + zoffs) & 0x1f;
+ angle = TUN_U(tun >> 16);
+ depth = TUN_V(tun >> 16);
+ tx = (angle - uoffs) & 0x1f;
+ ty = (depth + zoffs) & 0x1f;
pptop |= (uint16_t)tex[(ty << 5) + tx] << 8;
- tx = ~((angle >> 1) + uoffs) & 0x1f;
+ tx = ~(angle + uoffs) & 0x1f;
ppbot |= (uint16_t)tex[(ty << 5) + tx] << 8;
*top++ = pptop;
int16_t mat[4];
static short gate_speed;
+ num_vbl++;
+
bnstate = ~REG_KEYINPUT;
if(bnstate & BN_DPAD) {
if(gate_speed < 5) {
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <stdint.h>
#include <math.h>
struct vec2 {
- float x, y;
+ int x, y;
};
int main(int argc, char **argv)
for(frm=0; frm<num_frames; frm++) {
int coffs = num_frames > 1 ? frm * center / (num_frames - 1) : center;
+ memset(buf, 0xff, xsz * ysz * sizeof *buf);
+
#define UDIV 2048
#define VDIV 32768
prev_r = 0.0f;
float z = v * coffs;
/* don't bother drawing rings < 1 pixel apart */
- if(fabs(r - prev_r) < 0.05) continue;
+ if(r < 0 || fabs(r - prev_r) < 0.05) continue;
for(j=0; j<UDIV; j++) {
- float u = (float)j / (float)UDIV;
+ float u = (float)j / (float)(UDIV - 1);
float theta = 2.0f * u * M_PI;
int x = (int)(cos(theta) * r - z) + xsz / 2;
if(x >= 0 && x < xsz && y >= 0 && y < ysz) {
ptr = buf + y * xsz + x;
- ptr->x = u;
- ptr->y = v * 8;
+ ptr->x = (j << 8) / UDIV;
+ ptr->y = ((VDIV - i) << 11) / VDIV;
}
}
prev_r = r;
ptr = buf;
for(i=0; i<out_nlines; i++) {
for(j=0; j<xsz; j++) {
- float u = ptr->x;
- float v = ptr->y;
- int r = (int)(u * 8.0 * 255.0f) & 0xff;
- int g = (int)(v * 8.0 * 255.0f) & 0xff;
- int b = (~(int)(v * 0.5 * 255.0f) & 0xff) + 105;
- if(b > 255) b = 255;
- if(b < 0) b = 0;
+ int u = ptr->x;
+ int v = ptr->y;
+ int r = (u << 3) & 0xff;
+ int g = (v >> 3) & 0xff;
/*if(v > 2.0) r = g = b = 0;*/
ptr++;
- uint16_t out = ((uint16_t)(u * 255.0f) & 0xff) |
- (((uint16_t)(v * 255.0f) & 0xff) << 8);
+ uint16_t out = ((uint16_t)u & 0x3f) | (((uint16_t)v & 0x3ff) << 6);
fwrite(&out, sizeof out, 1, stdout);
if(fp) {
fputc(r, fp);
fputc(g, fp);
- fputc(b, fp);
+ fputc(0, fp);
}
}
}