[vid] Fix up the graphics driver, support more stuff, boot logo.

This commit is contained in:
Kevin Lange 2011-03-25 23:24:22 -05:00
parent 4d3118bad7
commit 216a91524b
4 changed files with 56 additions and 16 deletions

BIN
initrd/bs.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

View File

@ -212,6 +212,24 @@ start_shell() {
kprintf("Unknown graphics driver: %s\n", argv[1]);
}
}
} else if (!strcmp(cmd, "logo")) {
fs_node_t * file = kopen("/bs.bmp",0);
char *bufferb = malloc(file->length);
size_t bytes_read = read_fs(file, 0, file->length, (uint8_t *)bufferb);
size_t i;
uint16_t x = 0;
uint16_t y = 0;
for (i = 54; i < bytes_read; i += 3) {
uint32_t color = bufferb[i] +
bufferb[i+1] * 0x100 +
bufferb[i+2] * 0x10000;
bochs_set_coord(406 + x, 350 + (68 - y), color);
++x;
if (x == 212) {
x = 0;
++y;
}
}
} else {
kprintf("Unrecognized command: %s\n", cmd);
}

View File

@ -7,14 +7,21 @@
#include <system.h>
uint16_t bochs_resolution_x = 1024;
uint16_t bochs_resolution_y = 768;
uint16_t bochs_resolution_b = 32;
uint16_t bochs_current_bank = 0;
#define BOCHS_BANK_SIZE 16384
#define BOCHS_VID_MEMORY ((uint32_t *)0xA0000)
void
graphics_install_bochs() {
outports(0x1CE, 0x00);
outports(0x1CF, 0xB0C4);
short i = inports(0x1CF);
kprintf("Bochs VBE Mode [%x]\n", (unsigned int)i);
kprintf("Switching to GRAPHICS MODE!\n");
timer_wait(90);
kprintf("[bochs] Graphics ID is %x\n", (unsigned int)i);
kprintf("[bochs] Enabling 1024x768x32 graphics mode!\n");
/* Disable VBE */
outports(0x1CE, 0x04);
outports(0x1CF, 0x00);
@ -29,17 +36,30 @@ graphics_install_bochs() {
outports(0x1CF, 0x20);
/* Re-enable VBE */
outports(0x1CE, 0x04);
outports(0x1CF, 0x41);
/* Let's draw some stuff */
uint32_t * vid_mem = (uint32_t *)0xA0000;
uint32_t x = 0;
while (x < 1024 * 768) {
if ((x / 1024) % 2) {
*vid_mem = 0x00FF0000;
} else {
*vid_mem = krand();
}
++vid_mem;
++x;
}
outports(0x1CF, 0x01);
}
void
bochs_set_bank(
uint16_t bank
) {
if (bank == bochs_current_bank) {
/* We are already in this bank, stop wasting cycles */
return;
}
outports(0x1CE, 0x05); /* Bank */
outports(0x1CF, bank);
bochs_current_bank = bank;
}
void
bochs_set_coord(
uint16_t x,
uint16_t y,
uint32_t color
) {
uint32_t location = y * bochs_resolution_x + x;
bochs_set_bank(location / BOCHS_BANK_SIZE);
uint32_t offset = location % BOCHS_BANK_SIZE;
BOCHS_VID_MEMORY[offset] = color;
}

View File

@ -183,5 +183,7 @@ extern void get_time(uint16_t * hours, uint16_t * minutes, uint16_t * seconds);
/* Video Drivers */
/* BOCHS / QEMU VBE Driver */
extern void graphics_install_bochs();
extern void bochs_set_bank(uint16_t bank);
extern void bochs_set_coord(uint16_t x, uint16_t y, uint32_t color);
#endif