coarse 16bpp version works
[gbajam22] / src / voxscape.c
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;
                }
        }
 }