fucked it up again, need to sleep
[eradicate] / src / dos / main.c
index a41453b..6031b6a 100644 (file)
@@ -1,5 +1,6 @@
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include "game.h"
 #include "keyb.h"
 #include "timer.h"
 static void draw(void);
 
 static struct video_mode *vmode;
-static void *vmem;
+
 
 int main(int argc, char **argv)
 {
+       void *fb_buf;
        struct video_mode *vmodes;
-       int vmidx;
+       int vmidx, status = 0;
 
        init_logger("game.log");
 
@@ -37,7 +39,14 @@ int main(int argc, char **argv)
 
        fb_width = vmode->xsz;
        fb_height = vmode->ysz;
-       fb_size = (vmode->xsz * vmode->bpp / 8) * vmode->ysz;
+       fb_size = vmode->pitch * vmode->ysz;
+
+       if(!(fb_buf = malloc(fb_size + vmode->pitch * 2))) {
+               fprintf(stderr, "failed to allocate framebuffer\n");
+               status = -1;
+               goto break_evloop;
+       }
+       fb_pixels = (char*)fb_buf + vmode->pitch;
 
        reset_timer();
 
@@ -52,26 +61,24 @@ int main(int argc, char **argv)
        }
 
 break_evloop:
+       free(fb_buf);
        set_text_mode();
+       cleanup_video();
        kb_shutdown();
-       return 0;
+       return status;
 }
 
 static void draw(void)
 {
        int i, j;
-       uint16_t *pptr = vmem;
+       uint16_t *pptr = fb_pixels;
 
        for(i=0; i<fb_height; i++) {
                for(j=0; j<fb_width; j++) {
-                       int chess = (i >> 2) == (j >> 2);
+                       int chess = ((i >> 4) & 1) == ((j >> 4) & 1);
                        *pptr++ = chess ? 0xff00 : 0x00ff;
                }
        }
-}
 
-void swap_buffers(void *pixels)
-{
-       wait_vsync();
-       memcpy(vmem, pixels, fb_size);
+       blit_frame(fb_pixels, 1);
 }