2 pcboot - bootable PC demo/game kernel
3 Copyright (C) 2018 John Tsiombikas <nuclear@member.fsf.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY, without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>.
33 static int video_init(void);
34 static int modecmp(const void *a, const void *b);
36 static struct video_mode vmode;
40 void pcboot_main(void)
51 /* initialize the timer */
58 printf("PCBoot kernel initialized\n");
60 if(video_init() == -1) {
61 panic("Failed to find suitable video mode");
66 memset(fbptr, 0x80, vmode.width * vmode.height * vmode.bpp / 8);
70 static int video_init(void)
73 struct video_mode vinf, *vmodes;
74 int i, xres, yres, nmodes, mode_idx = -1;
77 if(mode_idx == -1 && (vendor = get_video_vendor()) && strstr(vendor, "SeaBIOS")) {
78 mode_idx = find_video_mode_idx(800, 600, 0);
81 if(mode_idx == -1 && vbe_get_edid(&edid) == 0 && edid_preferred_resolution(&edid, &xres, &yres) == 0) {
82 printf("EDID: preferred resolution: %dx%d\n", xres, yres);
83 mode_idx = find_video_mode_idx(xres, yres, 0);
86 nmodes = video_mode_count();
87 if(!(vmodes = malloc(nmodes * sizeof *vmodes))) {
88 printf("failed to allocate video modes array (%d modes)\n", nmodes);
92 for(i=0; i<nmodes; i++) {
93 video_mode_info(i, &vinf);
98 if(!(fbptr = set_video_mode(vmodes[mode_idx].mode))) {
99 printf("failed to set video mode: %x (%dx%d %dbpp)\n", mode_idx,
100 vmodes[mode_idx].width, vmodes[mode_idx].height, vmodes[mode_idx].bpp);
103 vmode = vmodes[mode_idx];
104 printf("video mode: %x (%dx%d %dbpp)\n", vmode.mode, vmode.width,
105 vmode.height, vmode.bpp);
110 qsort(vmodes, nmodes, sizeof *vmodes, modecmp);
112 for(i=0; i<nmodes; i++) {
113 if((fbptr = set_video_mode(vmodes[i].mode))) {
115 printf("video mode: %x (%dx%d %dbpp)\n", vmode.mode, vmode.width,
116 vmode.height, vmode.bpp);
121 printf("failed to find a suitable video mode\n");
132 static int modecmp(const void *a, const void *b)
134 const struct video_mode *ma = a;
135 const struct video_mode *mb = b;
136 unsigned long aval = ma->width | (ma->height << 16);
137 unsigned long bval = mb->width | (mb->height << 16);
142 return mb->bpp - ma->bpp;