2026-06-10 18:28:33 -05:00
|
|
|
#include <stddef.h>
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
|
|
#include <lib/stream.h>
|
|
|
|
|
|
2026-07-12 11:42:49 -05:00
|
|
|
#include <drivers/vga/vga.h>
|
|
|
|
|
|
|
|
|
|
#include <common.h>
|
2026-07-14 17:40:30 -05:00
|
|
|
#include <memory/mm.h>
|
2026-07-10 07:46:46 -05:00
|
|
|
|
2026-07-14 00:07:50 -05:00
|
|
|
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;
|
2026-06-10 18:28:33 -05:00
|
|
|
|
2026-07-14 00:07:50 -05:00
|
|
|
void vga_init(
|
2026-07-14 17:40:30 -05:00
|
|
|
uint32_t fb_paddr,
|
2026-07-14 00:07:50 -05:00
|
|
|
uint32_t fb_width,
|
|
|
|
|
uint32_t fb_height,
|
|
|
|
|
uint32_t fb_pitch,
|
|
|
|
|
uint8_t fb_bpp
|
|
|
|
|
) {
|
2026-07-14 17:40:30 -05:00
|
|
|
uint32_t fb_size_bytes = fb_height * fb_pitch;
|
|
|
|
|
uint32_t num_pages = (fb_size_bytes + 4095) / 4096;
|
|
|
|
|
for (uint32_t i = 0; i < num_pages; i++) {
|
|
|
|
|
uint32_t phys_addr = fb_paddr + (i * 4096);
|
|
|
|
|
uint32_t virt_addr = VGA_FRAMEBUFFER + (i * 4096);
|
|
|
|
|
map_page(virt_addr, phys_addr, PAGE_PRESENT | PAGE_WRITABLE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
framebuffer_address = VGA_FRAMEBUFFER;
|
2026-07-14 00:07:50 -05:00
|
|
|
framebuffer_width = fb_width;
|
|
|
|
|
framebuffer_height = fb_height;
|
|
|
|
|
framebuffer_pitch = fb_pitch;
|
|
|
|
|
framebuffer_bpp = fb_bpp;
|
|
|
|
|
framebuffer_total_pixels = framebuffer_width * framebuffer_height;
|
|
|
|
|
|
2026-07-14 17:40:30 -05:00
|
|
|
vga_clear_scrn(0x000000FF);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint32_t vga_get_pitch() {
|
|
|
|
|
return framebuffer_pitch;
|
2026-07-12 11:42:49 -05:00
|
|
|
}
|
|
|
|
|
|
2026-07-14 00:07:50 -05:00
|
|
|
void vga_clear_scrn(uint32_t color) {
|
|
|
|
|
if (framebuffer_address == 0) return;
|
|
|
|
|
|
2026-07-14 17:40:30 -05:00
|
|
|
for (uint32_t y = 0; y < framebuffer_height; y++) {
|
|
|
|
|
uint32_t* row = (uint32_t*)((uintptr_t)framebuffer_address + (y * framebuffer_pitch));
|
|
|
|
|
for (uint32_t x = 0; x < framebuffer_width; x++) {
|
|
|
|
|
row[x] = color;
|
|
|
|
|
}
|
2026-07-14 00:07:50 -05:00
|
|
|
}
|
2026-06-10 18:28:33 -05:00
|
|
|
}
|
|
|
|
|
|
2026-07-14 17:40:30 -05:00
|
|
|
void vga_drawchar(char c, int x, int y, psf_font_t* font) {
|
2026-06-12 23:03:00 -04:00
|
|
|
|
2026-07-12 04:37:46 -05:00
|
|
|
}
|
2026-07-12 03:56:25 -05:00
|
|
|
|
2026-07-12 04:37:46 -05:00
|
|
|
uint32_t vga_write(vfs_node_t* node, uint32_t offset, uint32_t size, uint8_t* buf) {
|
2026-07-14 17:40:30 -05:00
|
|
|
// probably just memcpy here
|
2026-07-12 03:56:25 -05:00
|
|
|
return size;
|
2026-06-26 20:05:01 -05:00
|
|
|
}
|