trying to get VGA fb mode to work..
This commit is contained in:
@@ -7,9 +7,12 @@
|
||||
|
||||
#include <common.h>
|
||||
|
||||
#define VGA_WIDTH 80
|
||||
#define VGA_HEIGHT 25
|
||||
#define VGA_MEMORY (0xB8000 + 0xC0000000)
|
||||
static uint32_t framebuffer_address;
|
||||
static uint32_t framebuffer_width;
|
||||
static uint32_t framebuffer_height;
|
||||
static uint32_t framebuffer_total_pixels;
|
||||
static uint32_t framebuffer_pitch;
|
||||
static uint32_t framebuffer_bpp;
|
||||
|
||||
enum vga_color {
|
||||
VGA_COLOR_BLACK = 0,
|
||||
@@ -30,52 +33,39 @@ enum vga_color {
|
||||
VGA_COLOR_WHITE = 15,
|
||||
};
|
||||
|
||||
static size_t terminal_row;
|
||||
static size_t terminal_column;
|
||||
static uint8_t terminal_color;
|
||||
static uint16_t* terminal_buffer = (uint16_t*)VGA_MEMORY;
|
||||
void vga_init(
|
||||
uint32_t fb_vaddr,
|
||||
uint32_t fb_width,
|
||||
uint32_t fb_height,
|
||||
uint32_t fb_pitch,
|
||||
uint8_t fb_bpp
|
||||
) {
|
||||
framebuffer_address = fb_vaddr;
|
||||
framebuffer_width = fb_width;
|
||||
framebuffer_height = fb_height;
|
||||
framebuffer_pitch = fb_pitch;
|
||||
framebuffer_bpp = fb_bpp;
|
||||
|
||||
static inline uint8_t vga_entry_color(enum vga_color fg, enum vga_color bg)
|
||||
{
|
||||
return fg | bg << 4;
|
||||
framebuffer_total_pixels = framebuffer_width * framebuffer_height;
|
||||
|
||||
vga_clear_scrn(0xFFFFFFFF);
|
||||
}
|
||||
|
||||
static inline uint16_t vga_entry(unsigned char uc, uint8_t color)
|
||||
{
|
||||
return (uint16_t) uc | (uint16_t) color << 8;
|
||||
}
|
||||
void vga_clear_scrn(uint32_t color) {
|
||||
if (framebuffer_address == 0) return;
|
||||
|
||||
static void update_cursor()
|
||||
{
|
||||
uint16_t pos = terminal_row * VGA_WIDTH + terminal_column;
|
||||
outb(0x3D4, 0x0F);
|
||||
outb(0x3D5, (uint8_t) (pos & 0xFF));
|
||||
outb(0x3D4, 0x0E);
|
||||
outb(0x3D5, (uint8_t) ((pos >> 8) & 0xFF));
|
||||
}
|
||||
|
||||
void vga_init() {
|
||||
outb(0x3D4, 0x0A);
|
||||
outb(0x3D5, (inb(0x3D5) & 0xC0) | 14);
|
||||
outb(0x3D4, 0x0B);
|
||||
outb(0x3D5, (inb(0x3D5) & 0xE0) | 15);
|
||||
|
||||
terminal_row = 0;
|
||||
terminal_column = 0;
|
||||
terminal_color = vga_entry_color(VGA_COLOR_LIGHT_GREY, VGA_COLOR_BLACK);
|
||||
|
||||
for (size_t y = 0; y < VGA_HEIGHT; y++) {
|
||||
for (size_t x = 0; x < VGA_WIDTH; x++) {
|
||||
const size_t index = y * VGA_WIDTH + x;
|
||||
terminal_buffer[index] = vga_entry(' ', terminal_color);
|
||||
}
|
||||
}
|
||||
// Completely ignore the framebuffer address for a split second.
|
||||
// Let's force raw ASCII text into the legacy VGA text console area.
|
||||
uint16_t* text_mode_buffer = (uint16_t*)0xB8000;
|
||||
|
||||
// Fill the screen with 'A' characters on a red background
|
||||
for (int i = 0; i < 80 * 25; i++) {
|
||||
text_mode_buffer[i] = (0x4F << 8) | 'A';
|
||||
}
|
||||
}
|
||||
|
||||
void vga_putchar(char c) {
|
||||
if (c == '\n') {
|
||||
terminal_row++;
|
||||
terminal_column = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -85,19 +75,9 @@ void vga_putchar(char c) {
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const size_t index = terminal_row * VGA_WIDTH + terminal_column;
|
||||
terminal_buffer[index] = vga_entry(c, terminal_color);
|
||||
if (++terminal_column == VGA_WIDTH) {
|
||||
terminal_column = 0;
|
||||
if (++terminal_row == VGA_HEIGHT)
|
||||
terminal_row = 0;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t vga_seek(vfs_node_t* node, uint32_t offset, int whence) {
|
||||
terminal_row = offset / VGA_WIDTH;
|
||||
terminal_column = offset % VGA_WIDTH;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -105,6 +85,5 @@ uint32_t vga_write(vfs_node_t* node, uint32_t offset, uint32_t size, uint8_t* bu
|
||||
for (uint32_t i = 0; i < size; i++) {
|
||||
vga_putchar((char)buf[i]);
|
||||
}
|
||||
update_cursor();
|
||||
return size;
|
||||
}
|
||||
@@ -3,7 +3,15 @@
|
||||
|
||||
#include <vfs.h>
|
||||
|
||||
void vga_init();
|
||||
void vga_init(
|
||||
uint32_t fb_vaddr,
|
||||
uint32_t fb_width,
|
||||
uint32_t fb_height,
|
||||
uint32_t fb_pitch,
|
||||
uint8_t fb_bpp
|
||||
);
|
||||
|
||||
void vga_clear_scrn(uint32_t color);
|
||||
void vga_putchar(char c);
|
||||
|
||||
uint32_t vga_write(vfs_node_t* node, uint32_t offset, uint32_t size, uint8_t* buf);
|
||||
|
||||
Reference in New Issue
Block a user