foo
[bootcensus] / src / kmain.c
index ad76287..bcd8a91 100644 (file)
@@ -18,6 +18,7 @@ along with this program.  If not, see <https://www.gnu.org/licenses/>.
 #include <stdio.h>
 #include <string.h>
 #include <ctype.h>
+#include <unistd.h>
 #include "segm.h"
 #include "intr.h"
 #include "mem.h"
@@ -29,12 +30,14 @@ along with this program.  If not, see <https://www.gnu.org/licenses/>.
 #include "vbe.h"
 #include "audio.h"
 #include "panic.h"
+#include "census/census.h"
 
 static int video_init(void);
 static int modecmp(const void *a, const void *b);
 
 static struct video_mode vmode;
-static void *fbptr;
+static void *fbptr, *backbuf;
+static int fbsize;
 
 
 void pcboot_main(void)
@@ -60,10 +63,17 @@ void pcboot_main(void)
        if(video_init() == -1) {
                panic("Failed to find suitable video mode");
        }
+       fbsize = vmode.width * vmode.height * vmode.bpp / 8;
+       if(!(backbuf = malloc(fbsize))) {
+               panic("Failed to allocate back buffer");
+       }
+       init_census(backbuf, vmode.width, vmode.height);
 
        for(;;) {
+               draw_census();
+
                wait_vsync();
-               memset(fbptr, 0x80, vmode.width * vmode.height * vmode.bpp / 8);
+               memcpy(fbptr, backbuf, fbsize);
        }
 }
 
@@ -75,7 +85,7 @@ static int video_init(void)
        const char *vendor;
 
        if(mode_idx == -1 && (vendor = get_video_vendor()) && strstr(vendor, "SeaBIOS")) {
-               mode_idx = find_video_mode_idx(800, 600, 0);
+               mode_idx = find_video_mode_idx(800, 600, 32);
        }
 
        if(mode_idx == -1 && vbe_get_edid(&edid) == 0 && edid_preferred_resolution(&edid, &xres, &yres) == 0) {
@@ -110,10 +120,11 @@ static int video_init(void)
                qsort(vmodes, nmodes, sizeof *vmodes, modecmp);
 
                for(i=0; i<nmodes; i++) {
+                       printf("trying video mode: %x (%dx%d %dbpp)\n", vmodes[i].mode, vmodes[i].width,
+                                       vmodes[i].height, vmodes[i].bpp);
+                       usleep(5000000);
                        if((fbptr = set_video_mode(vmodes[i].mode))) {
                                vmode = vmodes[i];
-                               printf("video mode: %x (%dx%d %dbpp)\n", vmode.mode, vmode.width,
-                                               vmode.height, vmode.bpp);
                                break;
                        }
                }