17 static int gamescr_start(void);
18 static void gamescr_stop(void);
19 static void gamescr_frame(void);
20 static void gamescr_vblank(void);
22 static void update(void);
23 static void draw(void);
25 static struct screen gamescr = {
33 static int nframes, num_vbl, backbuf;
34 static uint16_t *vram[] = { gba_vram_lfb0, gba_vram_lfb1 };
36 static int32_t pos[2], angle;
37 static struct voxscape *vox;
39 #define COLOR_HORIZON 192
40 #define COLOR_ZENITH 255
44 struct screen *init_game_screen(void)
49 static int gamescr_start(void)
53 gba_setmode(4, DISPCNT_BG2 | DISPCNT_OBJ | DISPCNT_FB1);
57 pos[0] = pos[1] = 256 << 16;
59 if(!(vox = vox_create(512, 512, height_pixels, color_pixels))) {
60 panic(get_pc(), "vox_create");
62 vox_proj(vox, 45, 10, 100);
64 /* setup color image palette */
65 for(i=0; i<192; i++) {
66 int r = color_cmap[i * 3];
67 int g = color_cmap[i * 3 + 1];
68 int b = color_cmap[i * 3 + 2];
69 gba_bgpal[i] = (((uint16_t)b << 7) & 0x7c00) | (((uint16_t)g << 2) & 0x3e0) | (((uint16_t)r >> 3) & 0x1f);
72 /* setup sky gradient palette */
74 int t = (i << 8) / 64;
75 int r = (0xcc00 + (0x55 - 0xcc) * t) >> 8;
76 int g = (0x7700 + (0x88 - 0x77) * t) >> 8;
77 int b = (0xff00 + (0xcc - 0xff) * t) >> 8;
78 int cidx = COLOR_HORIZON + i;
79 gba_bgpal[cidx] = ((b << 7) & 0x7c00) | ((g << 2) & 0x3e0) | (r >> 3);
86 static void gamescr_stop(void)
90 static void gamescr_frame(void)
94 backbuf = ++nframes & 1;
95 fb = (unsigned char*)vram[backbuf];
97 vox_framebuf(vox, 240, 160, fb, -1);
108 #define WALK_SPEED 0x40000
109 #define TURN_SPEED 0x100
111 static void update(void)
113 int32_t fwd[2], right[2];
116 if((input = read_input())) {
118 if(input & BN_LT) angle += TURN_SPEED;
119 if(input & BN_RT) angle -= TURN_SPEED;
121 fwd[0] = -SIN(angle);
130 if(input & BN_DOWN) {
134 if(input & BN_RIGHT) {
138 if(input & BN_LEFT) {
143 vox_view(vox, pos[0], pos[1], -30, angle);
147 static void draw(void)
150 //vox_sky_grad(vox, COLOR_HORIZON, COLOR_ZENITH);
151 vox_sky_solid(vox, COLOR_ZENITH);
155 __attribute__((noinline, target("arm"), section(".iwram")))
157 static void gamescr_vblank(void)