+
+/* XXX all the sptr calculations assume mounttex.width == 512 */
+static void draw_mountains(void)
+{
+ int i, j, y;
+ int32_t x, xstart, xend, dx;
+ uint16_t *dptr, *sptr;
+
+ /* 24.8 fixed point, 512 width, 90deg arc */
+ xstart = cround64(cam_theta * (256.0 * 512.0 / 90.0));
+ xend = cround64((cam_theta + HFOV) * (256.0 * 512.0 / 90.0));
+ dx = (xend - xstart) / FB_WIDTH;
+ x = xstart;
+
+ y = cround64(-cam_phi * (FB_HEIGHT / 45.0)) + (FB_HEIGHT / 2 - 64);
+
+ dptr = fb_pixels + y * FB_WIDTH;
+
+ for(i=0; i<FB_WIDTH; i++) {
+ sptr = mounttex.pixels + ((x >> 8) & 0x1ff);
+
+ for(j=0; j<64; j++) {
+ if(j + y >= FB_HEIGHT) break;
+ if(j + y >= 0) {
+ int32_t col = sptr[j << 9];
+ if(col != 0x7e0) {
+ dptr[j * FB_WIDTH] = col;
+ }
+ }
+ }
+ dptr++;
+
+ x += dx;
+ }
+
+ y += 64;
+ if(y < 0) {
+ memset(fb_pixels, 0, FB_WIDTH * FB_HEIGHT * 2);
+ } else {
+ if(y < FB_HEIGHT) {
+ dptr = fb_pixels + y * FB_WIDTH;
+ memset(dptr, 0, (FB_HEIGHT - y) * FB_WIDTH * 2);
+ }
+ }
+}