X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=bootcensus;a=blobdiff_plain;f=src%2Fkmain.c;h=ad76287a321df2aaf885e45473b64db07dfa1b48;hp=8af7cc37fa4a090d90b9a4d74f0db3d98a78eea3;hb=6e968b9e724d9626ed6bdf2119ac7de6a5248f14;hpb=81c11bdd80190ec319a82b0402173cfb65fcbf72
diff --git a/src/kmain.c b/src/kmain.c
index 8af7cc3..ad76287 100644
--- a/src/kmain.c
+++ b/src/kmain.c
@@ -26,12 +26,16 @@ along with this program. If not, see .
#include "timer.h"
#include "contty.h"
#include "video.h"
+#include "vbe.h"
#include "audio.h"
-#include "pci.h"
-#include "vbetest.h"
+#include "panic.h"
+static int video_init(void);
+static int modecmp(const void *a, const void *b);
+
+static struct video_mode vmode;
+static void *fbptr;
-void logohack(void);
void pcboot_main(void)
{
@@ -44,8 +48,6 @@ void pcboot_main(void)
init_mem();
- init_pci();
-
/* initialize the timer */
init_timer();
@@ -55,30 +57,87 @@ void pcboot_main(void)
printf("PCBoot kernel initialized\n");
+ if(video_init() == -1) {
+ panic("Failed to find suitable video mode");
+ }
+
for(;;) {
- int c;
-
- halt_cpu();
- while((c = kb_getkey()) >= 0) {
- switch(c) {
- case KB_F1:
- set_vga_mode(0x13);
- logohack();
- set_vga_mode(3);
- break;
+ wait_vsync();
+ memset(fbptr, 0x80, vmode.width * vmode.height * vmode.bpp / 8);
+ }
+}
+
+static int video_init(void)
+{
+ struct vbe_edid edid;
+ struct video_mode vinf, *vmodes;
+ int i, xres, yres, nmodes, mode_idx = -1;
+ const char *vendor;
+
+ if(mode_idx == -1 && (vendor = get_video_vendor()) && strstr(vendor, "SeaBIOS")) {
+ mode_idx = find_video_mode_idx(800, 600, 0);
+ }
+
+ if(mode_idx == -1 && vbe_get_edid(&edid) == 0 && edid_preferred_resolution(&edid, &xres, &yres) == 0) {
+ printf("EDID: preferred resolution: %dx%d\n", xres, yres);
+ mode_idx = find_video_mode_idx(xres, yres, 0);
+ }
+
+ nmodes = video_mode_count();
+ if(!(vmodes = malloc(nmodes * sizeof *vmodes))) {
+ printf("failed to allocate video modes array (%d modes)\n", nmodes);
+ return -1;
+ }
- case KB_F2:
- vbetest();
+ for(i=0; i= 0) {
+ if(!(fbptr = set_video_mode(vmodes[mode_idx].mode))) {
+ printf("failed to set video mode: %x (%dx%d %dbpp)\n", mode_idx,
+ vmodes[mode_idx].width, vmodes[mode_idx].height, vmodes[mode_idx].bpp);
+ mode_idx = -1;
+ } else {
+ vmode = vmodes[mode_idx];
+ printf("video mode: %x (%dx%d %dbpp)\n", vmode.mode, vmode.width,
+ vmode.height, vmode.bpp);
+ }
+ }
+
+ if(mode_idx == -1) {
+ qsort(vmodes, nmodes, sizeof *vmodes, modecmp);
+
+ for(i=0; i= nmodes) {
+ printf("failed to find a suitable video mode\n");
+ return -1;
}
}
+ free(vmodes);
+
+ return 0;
+}
+
+
+
+static int modecmp(const void *a, const void *b)
+{
+ const struct video_mode *ma = a;
+ const struct video_mode *mb = b;
+ unsigned long aval = ma->width | (ma->height << 16);
+ unsigned long bval = mb->width | (mb->height << 16);
+
+ if(aval != bval) {
+ return bval - aval;
+ }
+ return mb->bpp - ma->bpp;
}