#include "voxscape.h"
#include "data.h"
+#define FOV 30
+#define NEAR 2
+#define FAR 85
+
static int gamescr_start(void);
static void gamescr_stop(void);
static void gamescr_frame(void);
static int nframes, backbuf;
static uint16_t *vram[] = { gba_vram_lfb0, gba_vram_lfb1 };
-static int32_t pos[2], angle;
+static int32_t pos[2], angle, horizon = 80;
static struct voxscape *vox;
#define COLOR_HORIZON 192
if(!(vox = vox_create(VOX_SZ, VOX_SZ, height_pixels, color_pixels))) {
panic(get_pc(), "vox_create");
}
- vox_proj(vox, 30, 2, 85);
+ vox_proj(vox, FOV, NEAR, FAR);
+ vox_view(vox, pos[0], pos[1], -40, angle);
/* setup color image palette */
for(i=0; i<256; i++) {
backbuf = ++nframes & 1;
framebuf = vram[backbuf];
- vox_framebuf(vox, 240, 160, framebuf, -1);
+ vox_framebuf(vox, 240, 160, framebuf, horizon);
update();
draw();
#define WALK_SPEED 0x40000
#define TURN_SPEED 0x200
-
-static volatile uint16_t input;
+#define ELEV_SPEED 8
static void update(void)
{
int32_t fwd[2], right[2];
- if((input = read_input())) {
+ update_keyb();
+
+ if(KEYPRESS(BN_SELECT)) {
+ vox_quality ^= 1;
+ }
- if(input & BN_LEFT) {
+ if(keystate) {
+ if(keystate & BN_LEFT) {
angle += TURN_SPEED;
}
- if(input & BN_RIGHT) {
+ if(keystate & BN_RIGHT) {
angle -= TURN_SPEED;
}
right[0] = fwd[1];
right[1] = -fwd[0];
- if(input & BN_UP) {
+ if(keystate & BN_A) {
pos[0] += fwd[0];
pos[1] += fwd[1];
}
- if(input & BN_DOWN) {
+ /*
+ if(keystate & BN_DOWN) {
pos[0] -= fwd[0];
pos[1] -= fwd[1];
}
- if(input & BN_RT) {
+ */
+ if(keystate & BN_UP) {
+ if(horizon > 40) horizon -= ELEV_SPEED;
+ }
+ if(keystate & BN_DOWN) {
+ if(horizon < 200 - ELEV_SPEED) horizon += ELEV_SPEED;
+ }
+ if(keystate & BN_RT) {
pos[0] += right[0];
pos[1] += right[1];
}
- if(input & BN_LT) {
+ if(keystate & BN_LT) {
pos[0] -= right[0];
pos[1] -= right[1];
}
REG_BG2PC = -sa;
REG_BG2PD = ca;
- if((input & (BN_LEFT | BN_RIGHT)) == 0) {
+ keystate = ~REG_KEYINPUT;
+
+ if((keystate & (BN_LEFT | BN_RIGHT)) == 0) {
if(bank) {
bank -= bankdir << 4;
}
- } else if(input & BN_LEFT) {
+ } else if(keystate & BN_LEFT) {
bankdir = -1;
if(bank > -MAXBANK) bank -= 16;
- } else if(input & BN_RIGHT) {
+ } else if(keystate & BN_RIGHT) {
bankdir = 1;
if(bank < MAXBANK) bank += 16;
}
#include "input.h"
#include "gbaregs.h"
-#include "intr.h"
+#include "util.h"
-static void keyintr(void);
+/*
+#define NUM_KEYS 10
-static uint16_t bnstate;
+static int rep_start, rep_rep;
+static unsigned long first_press[16], last_press[16];
+static uint16_t repmask;
-void select_input(uint16_t bmask)
+void key_repeat(int start, int rep, uint16_t mask)
{
- bnstate = 0;
-
- mask(INTR_KEY);
- if(bmask) {
- REG_KEYCNT = bmask | KEYCNT_IE;
- interrupt(INTR_KEY, keyintr);
- unmask(INTR_KEY);
- } else {
- REG_KEYCNT = 0;
- interrupt(INTR_KEY, 0);
- }
+ rep_start = start;
+ rep_rep = rep;
+ repmask = mask;
}
+*/
-uint16_t get_input(void)
+void update_keyb(void)
{
- uint16_t s;
-
- mask(INTR_KEY);
- s = bnstate;
- bnstate = 0;
- unmask(INTR_KEY);
-
- return s;
+ static uint16_t prevstate;
+ /*
+ int i;
+ unsigned long msec = timer_msec;
+ */
+
+ //keystate = (~REG_KEYINPUT & 0x3ff);
+ keydelta = keystate ^ prevstate;
+ prevstate = keystate;
+
+ /*
+ for(i=0; i<NUM_KEYS; i++) {
+ uint16_t bit = 1 << i;
+ if(!(bit & repmask)) {
+ continue;
+ }
+
+ if(keystate & bit) {
+ if(keydelta & bit) {
+ first_press[i] = msec;
+ } else {
+ if(msec - first_press[i] >= rep_start && msec - last_press[i] >= rep_rep) {
+ keydelta |= bit;
+ last_press[i] = msec;
+ }
+ }
+ }
+ }
+ */
}
-static void keyintr(void)
-{
- bnstate |= ~REG_KEYINPUT;
-}
BN_LT = 0x0200
};
-#define BN_DPAD (BN_RIGHT | BN_LEFT | BN_UP | BN_DOWN)
+#define KEYPRESS(key) ((keystate & (key)) && (keydelta & (key)))
+#define KEYRELEASE(key) ((keystate & (key)) == 0 && (keydelta & (key)))
-void select_input(uint16_t bmask);
-uint16_t get_input(void);
+volatile uint16_t keystate, keydelta;
+
+/*void key_repeat(int start, int rep, uint16_t mask);*/
+
+void update_keyb(void);
-#ifdef BUILD_GBA
-#define read_input() (~REG_KEYINPUT)
-#else
-#define read_input() get_input()
-#endif
#endif /* INPUT_H_ */
unsigned int valid;
};
+int vox_quality = 1;
+
struct voxscape *vox_create(int xsz, int ysz, uint8_t *himg, uint8_t *cimg)
{
struct voxscape *vox;
vox->zfar = zfar;
vox->nslices = vox->zfar - vox->znear;
- free(vox->slicelen);
- if(!(vox->slicelen = iwram_sbrk(vox->nslices * sizeof *vox->slicelen))) {
- panic(get_pc(), "vox_proj: failed to allocate slice length table (%d)\n", vox->nslices);
- return;
+ if(!vox->slicelen) {
+ if(!(vox->slicelen = iwram_sbrk(vox->nslices * sizeof *vox->slicelen))) {
+ panic(get_pc(), "vox_proj: failed to allocate slice length table (%d)\n", vox->nslices);
+ return;
+ }
}
vox->valid &= ~SLICELEN;
int i;
vox_begin(vox);
- for(i=0; i<vox->nslices; i++) {
- /*if(i >= 10 && (i & 1) == 0) {
- continue;
- }*/
- vox_render_slice(vox, i);
+
+ if(vox_quality) {
+ for(i=0; i<vox->nslices; i++) {
+ vox_render_slice(vox, i);
+ }
+ } else {
+ for(i=0; i<vox->nslices; i++) {
+ if(i >= 10 && (i & 1) == 0) {
+ continue;
+ }
+ vox_render_slice(vox, i);
+ }
}
}
struct voxscape;
+extern int vox_quality;
+
struct voxscape *vox_create(int xsz, int ysz, uint8_t *himg, uint8_t *cimg);
void vox_free(struct voxscape *vox);