14 void handle_key(int key);
15 void interrupt timer_intr();
16 int parse_args(int argc, char **argv);
19 static int opt_vsync = 1;
21 static unsigned long nframes;
23 volatile unsigned long nticks;
25 static void interrupt (*prev_timer_intr)();
27 int main(int argc, char **argv)
30 unsigned long rate, total_ticks, sec;
32 if(parse_args(argc, argv) == -1) {
39 g3d_framebuffer(320, 200, 0);
41 mat_perspective(proj, 50, (4 << 16) / 3, 0x8000, 0x100000);
44 prev_timer_intr = _dos_getvect(0x1c);
45 _dos_setvect(0x1c, timer_intr);
61 _dos_setvect(0x1c, prev_timer_intr);
66 /* 1.193182MHz / 65536 = 18.20651245117 ticks/sec */
67 rate = nframes * 1820 / nticks;
68 sec = nticks * 100 / 182;
69 printf("%lu frames in %lu.%lu sec - %lu.%lu fps\n", nframes,
70 sec / 10, sec % 10, rate / 100, rate % 100);
75 #define VERT(x, y, z) { x << 16, y << 16, z << 16, 0x10000 }
76 struct g3d_vertex varr[] = {
77 VERT(-1, -1, 1), VERT(1, -1, 1), VERT(1, 1, 1), VERT(-1, 1, 1),
78 VERT(1, -1, 1), VERT(1, -1, -1), VERT(1, 1, -1), VERT(1, 1, 1),
79 VERT(1, -1, -1), VERT(-1, -1, -1), VERT(-1, 1, -1), VERT(1, 1, -1),
80 VERT(-1, -1, -1), VERT(-1, -1, 1), VERT(-1, 1, 1), VERT(-1, 1, -1),
81 VERT(-1, 1, 1), VERT(1, 1, 1), VERT(1, 1, -1), VERT(-1, 1, -1),
82 VERT(-1, -1, -1), VERT(1, -1, -1), VERT(1, -1, 1), VERT(-1, -1, 1)
89 mat_trans(xform, 0, 0, -0x40000);
90 mat_mul_rotx(xform, nframes);
91 mat_mul_roty(xform, nframes);
94 g3d_fbpixels = vid_backbuf;
99 #ifdef USE_DIRTY_CLEAR
106 g3d_draw(G3D_QUADS, varr, 4);
108 g3d_draw(G3D_QUADS, varr + 4, 4);
110 g3d_draw(G3D_QUADS, varr + 8, 4);
112 g3d_draw(G3D_QUADS, varr + 12, 4);
114 g3d_draw(G3D_QUADS, varr + 16, 4);
116 g3d_draw(G3D_QUADS, varr + 20, 4);
121 void handle_key(int key)
134 void interrupt timer_intr()
137 _chain_intr(prev_timer_intr);
140 static const char *helpfmt = "Usage: %s [options]\n"
142 " -vsync: enable vsync (default)\n"
143 " -novsync: disable vsync\n"
144 " -help,-h: print usage and exit\n";
146 int parse_args(int argc, char **argv)
150 for(i=1; i<argc; i++) {
151 if(argv[i][0] == '-') {
152 if(strcmp(argv[i], "-vsync") == 0) {
154 } else if(strcmp(argv[i], "-novsync") == 0) {
156 } else if(strcmp(argv[i], "-help") == 0 || strcmp(argv[i], "-h") == 0) {
157 printf(helpfmt, argv[0]);
160 fprintf(stderr, "invalid option: %s\n", argv[i]);
164 fprintf(stderr, "unexpected argument: %s\n", argv[i]);
172 #define GC_ADDR 0x3ce
173 #define GC_DATA 0x3cf
178 unsigned char *img, *src, *dest;
179 unsigned char cmap[256][3];
185 for(i=0; i<256; i++) {
186 cmap[i][0] = inp(0x3c9) << 2;
187 cmap[i][1] = inp(0x3c9) << 2;
188 cmap[i][2] = inp(0x3c9) << 2;
192 if(!(img = malloc(320 * 400 * 3))) {
195 if(!(fp = fopen("vmem.ppm", "wb"))) {
200 src = (unsigned char*)0xa0000;
202 outp(0x3ce, 4); /* graphics controller: read map select register */
205 for(j=0; j<16000; j++) {
207 dest[0] = cmap[idx][0];
208 dest[1] = cmap[idx][1];
209 dest[2] = cmap[idx][2];
214 src = (unsigned char*)0xa4000;
216 outp(0x3ce, 4); /* graphics controller: read map select register */
219 for(j=0; j<16000; j++) {
221 dest[0] = cmap[idx][0];
222 dest[1] = cmap[idx][1];
223 dest[2] = cmap[idx][2];
228 fprintf(fp, "P6\n%d %d\n255\n", 320, 400);
229 fwrite(img, 1, 320 * 400 * 3, fp);