+#include "config.h"
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dos.h>
#include "video.h"
#include "3dgfx.h"
+#include "vmath.h"
#include "util.h"
void update(void);
static int quit;
static unsigned char *fb;
+static long nframes;
-static volatile unsigned long nticks;
+volatile unsigned long nticks;
static void interrupt (*prev_timer_intr)();
int main(void)
{
- long rate, nframes = 0;
- long tstart, tdur;
+ int32_t proj[16];
+ long rate;
- if(!(fb = malloc(64000))) {
+ if(!(fb = calloc(1, 64000))) {
fprintf(stderr, "failed to allocate framebuffer\n");
return 1;
}
g3d_init();
g3d_framebuffer(320, 200, fb);
+ mat_perspective(proj, 50, (4 << 16) / 3, 0x8000, 0x100000);
+ g3d_projection(proj);
+
prev_timer_intr = _dos_getvect(0x1c);
_dos_setvect(0x1c, timer_intr);
- _disable();
- tstart = nticks;
- _enable();
for(;;) {
while(kbhit()) {
}
end:
- _disable();
- tdur = nticks - tstart;
- _enable();
_dos_setvect(0x1c, prev_timer_intr);
close_video();
free(fb);
- rate = nframes * 100 * 18 / tdur;
- printf("%ld frames in %ld sec, rate: %ld.%ld\n", nframes, tdur / 18,
+ rate = nframes * 100 * 18 / nticks;
+ printf("%ld frames in %ld sec, rate: %ld.%ld\n", nframes, nticks / 18,
rate / 100, rate % 100);
return 0;
}
+#define VERT(x, y, z) { x << 16, y << 16, z << 16, 0x10000 }
struct g3d_vertex varr[] = {
- {0, 0x8000, 0, 0x10000},
- {-0x8f00, -0x8000, 0, 0x10000},
- {0x8c00, -0x6000, 0, 0x10000}
+ VERT(-1, -1, 1), VERT(1, -1, 1), VERT(1, 1, 1), VERT(-1, 1, 1),
+ VERT(1, -1, 1), VERT(1, -1, -1), VERT(1, 1, -1), VERT(1, 1, 1),
+ VERT(1, -1, -1), VERT(-1, -1, -1), VERT(-1, 1, -1), VERT(1, 1, -1),
+ VERT(-1, -1, -1), VERT(-1, -1, 1), VERT(-1, 1, 1), VERT(-1, 1, -1),
+ VERT(-1, 1, 1), VERT(1, 1, 1), VERT(1, 1, -1), VERT(-1, 1, -1),
+ VERT(-1, -1, -1), VERT(1, -1, -1), VERT(1, -1, 1), VERT(-1, -1, 1)
};
-void mat_rotz(int32_t *m, int theta)
-{
- m[0] = XCOS(theta);
- m[1] = XSIN(theta);
- m[4] = -XSIN(theta);
- m[5] = XCOS(theta);
- m[10] = 0x10000;
- m[15] = 0x10000;
- m[2] = m[3] = m[6] = m[7] = m[8] = m[9] = m[11] = m[12] = m[13] = m[14] = 0;
-}
-
void update(void)
{
int32_t xform[16];
+#ifdef USE_DIRTY_CLEAR
+ g3d_clear_dirty();
+#else
vid_clearfb(fb);
+#endif
- mat_rotz(xform, nticks);
+ mat_trans(xform, 0, 0, -0x40000);
+ mat_mul_rotx(xform, nframes);
+ mat_mul_roty(xform, nframes);
g3d_modelview(xform);
- g3d_color(15);
- g3d_draw(G3D_TRIANGLES, varr, sizeof varr / sizeof *varr);
-
- /*wait_vsync();*/
+ g3d_color(9);
+ g3d_draw(G3D_QUADS, varr, 4);
+ g3d_color(10);
+ g3d_draw(G3D_QUADS, varr + 4, 4);
+ g3d_color(11);
+ g3d_draw(G3D_QUADS, varr + 8, 4);
+ g3d_color(12);
+ g3d_draw(G3D_QUADS, varr + 12, 4);
+ g3d_color(13);
+ g3d_draw(G3D_QUADS, varr + 16, 4);
+ g3d_color(14);
+ g3d_draw(G3D_QUADS, varr + 20, 4);
+
+#ifdef USE_VSYNC
+ wait_vsync();
+#endif
+#ifdef USE_DIRTY_COPY
+ g3d_copy_dirty();
+#else
vid_copyfb(fb);
+#endif
}
void handle_key(int key)