coarse 16bpp version works
authorJohn Tsiombikas <nuclear@member.fsf.org>
Wed, 19 Oct 2022 00:35:50 +0000 (03:35 +0300)
committerJohn Tsiombikas <nuclear@member.fsf.org>
Wed, 19 Oct 2022 00:35:50 +0000 (03:35 +0300)
src/gamescr.c
src/gba/gba.c
src/gba/main.c
src/util.h
src/voxscape.c

index 2d283d8..9686456 100644 (file)
@@ -17,7 +17,6 @@
 static int gamescr_start(void);
 static void gamescr_stop(void);
 static void gamescr_frame(void);
-static void gamescr_vblank(void);
 
 static void update(void);
 static void draw(void);
@@ -27,7 +26,7 @@ static struct screen gamescr = {
        gamescr_start,
        gamescr_stop,
        gamescr_frame,
-       gamescr_vblank
+       0
 };
 
 static int nframes, num_vbl, backbuf;
@@ -36,8 +35,8 @@ static uint16_t *vram[] = { gba_vram_lfb0, gba_vram_lfb1 };
 static int32_t pos[2], angle;
 static struct voxscape *vox;
 
-#define COLOR_HORIZON  192
-#define COLOR_ZENITH   255
+#define COLOR_HORIZON  0x7dd9
+#define COLOR_ZENITH   0x662a
 
 
 
@@ -48,8 +47,6 @@ struct screen *init_game_screen(void)
 
 static int gamescr_start(void)
 {
-       int i;
-
        gba_setmode(5, DISPCNT_BG2 | DISPCNT_OBJ | DISPCNT_FB1);
 
        vblperf_setcolor(0);
@@ -88,11 +85,15 @@ static void gamescr_frame(void)
        if(!(nframes & 15)) {
                emuprint("vbl: %d", vblperf_count);
        }
+#ifdef VBLBAR
        vblperf_begin();
+#else
+       vblperf_count = 0;
+#endif
 }
 
 #define WALK_SPEED     0x40000
-#define TURN_SPEED     0x100
+#define TURN_SPEED     0x200
 
 static void update(void)
 {
@@ -133,12 +134,6 @@ static void update(void)
 static void draw(void)
 {
        vox_render(vox);
-       //vox_sky_grad(vox, COLOR_HORIZON, COLOR_ZENITH);
-       vox_sky_solid(vox, COLOR_ZENITH);
-}
-
-ARM_IWRAM
-static void gamescr_vblank(void)
-{
-       num_vbl++;
+       vox_sky_grad(vox, COLOR_HORIZON, COLOR_ZENITH);
+       //vox_sky_solid(vox, COLOR_ZENITH);
 }
index 1cff462..4e7d0c2 100644 (file)
@@ -3,5 +3,16 @@
 void gba_setmode(int mode, unsigned int flags)
 {
        REG_DISPCNT = mode | flags;
-}
 
+       if(DISPCNT_MODE(mode) == 5) {
+               REG_BG2PA = (160 << 8) / 240;
+               REG_BG2PB = 0;
+               REG_BG2PC = 0;
+               REG_BG2PD = (128 << 8) / 160;
+       } else {
+               REG_BG2PA = 0x100;
+               REG_BG2PB = 0;
+               REG_BG2PC = 0;
+               REG_BG2PD = 0x100;
+       }
+}
index 6e5dbc0..49657df 100644 (file)
@@ -16,12 +16,6 @@ int main(void)
 
        REG_WAITCNT = WAITCNT_PREFETCH | WAITCNT_ROM_2_1;
 
-       cptr = (uint16_t*)CRAM_BG_ADDR;
-       for(i=0; i<256; i++) {
-               int c = i >> 3;
-               *cptr++ = c | ((c >> 1) << 10);
-       }
-
 #ifndef NOSOUND
        mmInitDefault(sound_data, 8);
        mmStart(MOD_POPCORN, MM_PLAY_LOOP);
@@ -51,11 +45,9 @@ int main(void)
 ARM_IWRAM
 static void vblank(void)
 {
-#ifdef VBLBAR
        vblperf_count++;
-#endif
 
-       curscr->vblank();
+       /*curscr->vblank();*/
 
 #ifndef NOSOUND
        mmVBlank();
index 2e5f013..3e9e7f5 100644 (file)
@@ -15,7 +15,7 @@
 
 #define present(x) \
        do { \
-               REG_DISPCNT = DISPCNT_BG2 | DISPCNT_OBJ | 4 | ((x) << 4); \
+               REG_DISPCNT = DISPCNT_BG2 | DISPCNT_OBJ | 5 | ((x) << 4); \
        } while(0)
 
 #define ARM_IWRAM      __attribute__((noinline, target("arm"), section(".iwram")))
index 81ba215..3669ede 100644 (file)
@@ -238,6 +238,7 @@ void vox_proj(struct voxscape *vox, int fov, int znear, int zfar)
  * fill the visible (top) part of each column
  */
 
+ARM_IWRAM
 void vox_render(struct voxscape *vox)
 {
        int i;
@@ -248,11 +249,11 @@ void vox_render(struct voxscape *vox)
        }
 }
 
+ARM_IWRAM
 void vox_begin(struct voxscape *vox)
 {
        int i;
 
-       memset(vox->fb, 0, FBWIDTH * FBHEIGHT * 2);
        memset(vox->coltop, 0, FBWIDTH * sizeof *vox->coltop);
 
        if(!(vox->valid & SLICELEN)) {
@@ -267,7 +268,7 @@ void vox_begin(struct voxscape *vox)
 ARM_IWRAM
 void vox_render_slice(struct voxscape *vox, int n)
 {
-       int i, j, hval, last_hval, colstart, colheight, col, z, offs, last_offs = -1;
+       int i, j, hval, last_hval, colstart, colheight, z, offs, last_offs = -1;
        int32_t x, y, len, xstep, ystep;
        uint16_t color, last_col;
        uint16_t *fbptr;
@@ -281,7 +282,7 @@ void vox_render_slice(struct voxscape *vox, int n)
        x = vox->x - SIN(vox->angle) * z - xstep * (FBWIDTH / 2);
        y = vox->y + COS(vox->angle) * z - ystep * (FBWIDTH / 2);
 
-       for(i=1; i<FBWIDTH; i++) {
+       for(i=0; i<FBWIDTH; i++) {
                offs = (((y >> 16) & YMASK) << XSHIFT) + ((x >> 16) & XMASK);
                if(offs == last_offs) {
                        hval = last_hval;
@@ -317,17 +318,18 @@ void vox_sky_solid(struct voxscape *vox, uint16_t color)
        int i, j, colheight;
        uint16_t *fbptr;
 
-       for(i=1; i<FBWIDTH; i++) {
+       for(i=0; i<FBWIDTH; i++) {
                fbptr = vox->fb + i;
                colheight = FBHEIGHT - vox->coltop[i];
 
                for(j=0; j<colheight; j++) {
                        *fbptr = color;
-                       fbptr += FBWIDTH / 2;
+                       fbptr += FBWIDTH;
                }
        }
 }
 
+ARM_IWRAM
 void vox_sky_grad(struct voxscape *vox, uint16_t chor, uint16_t ctop)
 {
        int i, j, colheight, t;
@@ -352,10 +354,10 @@ void vox_sky_grad(struct voxscape *vox, uint16_t chor, uint16_t ctop)
 
        for(i=0; i<vox->fbwidth; i++) {
                fbptr = vox->fb + i;
-               colheight = vox->fbheight - vox->coltop[i];
+               colheight = FBHEIGHT - vox->coltop[i];
                for(j=0; j<colheight; j++) {
                        *fbptr = grad[j];
-                       fbptr += vox->fbwidth;
+                       fbptr += FBWIDTH;
                }
        }
 }