blue!
This commit is contained in:
@@ -1,49 +0,0 @@
|
||||
#include <drivers/console/console.h>
|
||||
|
||||
#include <lib/font.h>
|
||||
#include <drivers/vga/vga.h>
|
||||
|
||||
static psf_font_t* font;
|
||||
|
||||
static uint32_t console_row;
|
||||
static uint32_t console_col;
|
||||
static uint32_t console_text_color;
|
||||
static uint32_t console_backgrnd_color;
|
||||
|
||||
static void write_vga_char(int row, int col, char c) {
|
||||
uint32_t vga_pitch = vga_get_pitch();
|
||||
uint8_t* glyph = (uint8_t*)font->glyphs + (c * font->hdr->charsz);
|
||||
|
||||
for (uint32_t y = 0; y < font->hdr->charsz; y++) {
|
||||
uint8_t bits = glyph[y];
|
||||
uint32_t* row = (uint32_t*)((uintptr_t)VGA_FRAMEBUFFER + ((console_row + y) * vga_pitch));
|
||||
for (int x = 0; x < 8; x++) {
|
||||
if (bits & (0b10000000 >> x)) {
|
||||
row[console_col + x] = console_text_color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void set_console_font(const char* path) {
|
||||
font = load_font(path);
|
||||
}
|
||||
|
||||
void set_console_fg(uint32_t color) {
|
||||
console_text_color = color;
|
||||
}
|
||||
|
||||
void set_console_bg(uint32_t color) {
|
||||
console_backgrnd_color = color;
|
||||
}
|
||||
|
||||
void console_init() {
|
||||
console_row = 0;
|
||||
console_col = 0;
|
||||
set_console_fg(0xFFFFFFFF);
|
||||
set_console_bg(0x00000000);
|
||||
}
|
||||
|
||||
void console_putchar(char c) {
|
||||
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
#ifndef D_CONSOLE_H
|
||||
#define D_CONSOLE_H
|
||||
|
||||
#include <lib/font.h>
|
||||
|
||||
void console_putchar(char c);
|
||||
|
||||
void set_console_font(const char* path);
|
||||
void set_console_fg(uint32_t color);
|
||||
void set_console_bg(uint32_t color);
|
||||
void console_init();
|
||||
|
||||
#endif
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <lib/stream.h>
|
||||
|
||||
#include <drivers/vga/vga.h>
|
||||
#include <drivers/serial/serial.h>
|
||||
|
||||
#include <common.h>
|
||||
#include <memory/mm.h>
|
||||
@@ -15,13 +16,55 @@ static uint32_t framebuffer_total_pixels;
|
||||
static uint32_t framebuffer_pitch;
|
||||
static uint32_t framebuffer_bpp;
|
||||
|
||||
static uint8_t red_mask_sz;
|
||||
static uint8_t red_field_pos;
|
||||
static uint8_t green_mask_sz;
|
||||
static uint8_t green_field_pos;
|
||||
static uint8_t blue_mask_sz;
|
||||
static uint8_t blue_field_pos;
|
||||
|
||||
static uint32_t create_pixel(uint8_t r, uint8_t g, uint8_t b) {
|
||||
return (r >> (8 - red_mask_sz)) << red_field_pos
|
||||
| (g >> (8 - green_mask_sz)) << green_field_pos
|
||||
| (b >> (8 - blue_mask_sz)) << blue_field_pos;
|
||||
}
|
||||
|
||||
vga_color_t VGA_COLOR_BLACK = {0, 0, 0, 255};
|
||||
vga_color_t VGA_COLOR_RED = {0, 0, 255, 255};
|
||||
vga_color_t VGA_COLOR_GREEN = {0, 255, 0, 255};
|
||||
vga_color_t VGA_COLOR_BLUE = {255, 0, 0, 255};
|
||||
|
||||
void vga_init(
|
||||
uint32_t fb_paddr,
|
||||
uint32_t fb_width,
|
||||
uint32_t fb_height,
|
||||
uint32_t fb_pitch,
|
||||
uint8_t fb_bpp
|
||||
uint8_t fb_bpp,
|
||||
uint8_t _red_mask_sz,
|
||||
uint8_t _red_field_pos,
|
||||
uint8_t _green_mask_sz,
|
||||
uint8_t _green_field_pos,
|
||||
uint8_t _blue_mask_sz,
|
||||
uint8_t _blue_field_pos
|
||||
) {
|
||||
framebuffer_address = VGA_FRAMEBUFFER;
|
||||
|
||||
red_mask_sz = _red_mask_sz;
|
||||
red_field_pos = _red_field_pos;
|
||||
green_mask_sz = _green_mask_sz;
|
||||
green_field_pos = _green_field_pos;
|
||||
blue_mask_sz = _blue_mask_sz;
|
||||
blue_field_pos = _blue_field_pos;
|
||||
|
||||
print_serial("initializing vga.\r\n");
|
||||
print_serial_hex(fb_paddr);
|
||||
print_serial("\r\n");
|
||||
print_serial_hex(framebuffer_address);
|
||||
print_serial("\r\n");
|
||||
print_serial("BPP: ");
|
||||
print_serial_hex(fb_bpp);
|
||||
print_serial("\r\n");
|
||||
|
||||
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++) {
|
||||
@@ -30,36 +73,58 @@ void vga_init(
|
||||
map_page(virt_addr, phys_addr, PAGE_PRESENT | PAGE_WRITABLE);
|
||||
}
|
||||
|
||||
framebuffer_address = VGA_FRAMEBUFFER;
|
||||
framebuffer_width = fb_width;
|
||||
framebuffer_height = fb_height;
|
||||
framebuffer_pitch = fb_pitch;
|
||||
framebuffer_bpp = fb_bpp;
|
||||
framebuffer_total_pixels = framebuffer_width * framebuffer_height;
|
||||
|
||||
vga_clear_scrn(0x000000FF);
|
||||
framebuffer_pitch = fb_pitch;
|
||||
framebuffer_bpp = fb_bpp;
|
||||
|
||||
vga_clear_scrn(0x00000000);
|
||||
}
|
||||
|
||||
uint32_t vga_get_framebuffer() {
|
||||
return framebuffer_address;
|
||||
}
|
||||
|
||||
uint32_t vga_get_width() {
|
||||
return framebuffer_width;
|
||||
}
|
||||
|
||||
uint32_t vga_get_height() {
|
||||
return framebuffer_height;
|
||||
}
|
||||
|
||||
uint32_t vga_get_pitch() {
|
||||
return framebuffer_pitch;
|
||||
}
|
||||
|
||||
uint8_t vga_get_bpp() {
|
||||
return framebuffer_bpp;
|
||||
}
|
||||
|
||||
void vga_clear_scrn(uint32_t color) {
|
||||
if (framebuffer_address == 0) return;
|
||||
|
||||
for (uint32_t y = 0; y < framebuffer_height; y++) {
|
||||
uint32_t* row = (uint32_t*)((uintptr_t)framebuffer_address + (y * framebuffer_pitch));
|
||||
uint8_t* fb_bytes = (uint8_t*)framebuffer_address;
|
||||
uint8_t bytes_per_pixel = framebuffer_bpp / 8;
|
||||
|
||||
for (uint32_t y = 0; y < framebuffer_height; y++) {
|
||||
uint8_t* row = fb_bytes + (y * framebuffer_pitch);
|
||||
|
||||
for (uint32_t x = 0; x < framebuffer_width; x++) {
|
||||
row[x] = color;
|
||||
uint8_t* pixel = row + (x * bytes_per_pixel);
|
||||
|
||||
switch(framebuffer_bpp) {
|
||||
case 32: {
|
||||
*(uint32_t*)pixel = color;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void vga_drawchar(char c, int x, int y, psf_font_t* font) {
|
||||
|
||||
}
|
||||
|
||||
uint32_t vga_write(vfs_node_t* node, uint32_t offset, uint32_t size, uint8_t* buf) {
|
||||
// probably just memcpy here
|
||||
return size;
|
||||
}
|
||||
@@ -4,39 +4,41 @@
|
||||
#include <vfs.h>
|
||||
#include <lib/font.h>
|
||||
|
||||
#define VGA_FRAMEBUFFER 0xFF700000
|
||||
#define VGA_FRAMEBUFFER 0xF0000000
|
||||
|
||||
enum vga_color {
|
||||
VGA_COLOR_BLACK = 0,
|
||||
VGA_COLOR_BLUE = 1,
|
||||
VGA_COLOR_GREEN = 2,
|
||||
VGA_COLOR_CYAN = 3,
|
||||
VGA_COLOR_RED = 4,
|
||||
VGA_COLOR_MAGENTA = 5,
|
||||
VGA_COLOR_BROWN = 6,
|
||||
VGA_COLOR_LIGHT_GREY = 7,
|
||||
VGA_COLOR_DARK_GREY = 8,
|
||||
VGA_COLOR_LIGHT_BLUE = 9,
|
||||
VGA_COLOR_LIGHT_GREEN = 10,
|
||||
VGA_COLOR_LIGHT_CYAN = 11,
|
||||
VGA_COLOR_LIGHT_RED = 12,
|
||||
VGA_COLOR_LIGHT_MAGENTA = 13,
|
||||
VGA_COLOR_LIGHT_BROWN = 14,
|
||||
VGA_COLOR_WHITE = 15,
|
||||
};
|
||||
typedef struct {
|
||||
uint8_t b;
|
||||
uint8_t g;
|
||||
uint8_t r;
|
||||
uint8_t a;
|
||||
} vga_color_t;
|
||||
|
||||
extern vga_color_t VGA_COLOR_BLACK;
|
||||
extern vga_color_t VGA_COLOR_RED;
|
||||
extern vga_color_t VGA_COLOR_GREEN;
|
||||
extern vga_color_t VGA_COLOR_BLUE;
|
||||
|
||||
void vga_init(
|
||||
uint32_t fb_paddr,
|
||||
uint32_t fb_width,
|
||||
uint32_t fb_height,
|
||||
uint32_t fb_pitch,
|
||||
uint8_t fb_bpp
|
||||
uint8_t fb_bpp,
|
||||
uint8_t red_mask_sz,
|
||||
uint8_t red_field_pos,
|
||||
uint8_t green_mask_sz,
|
||||
uint8_t green_field_pos,
|
||||
uint8_t blue_mask_sz,
|
||||
uint8_t blue_field_pos
|
||||
);
|
||||
|
||||
uint32_t vga_get_framebuffer();
|
||||
uint32_t vga_get_width();
|
||||
uint32_t vga_get_height();
|
||||
uint32_t vga_get_pitch();
|
||||
uint8_t vga_get_bpp();
|
||||
|
||||
void vga_clear_scrn(uint32_t color);
|
||||
void vga_drawchar(char c, int x, int y, psf_font_t* font);
|
||||
|
||||
uint32_t vga_write(vfs_node_t* node, uint32_t offset, uint32_t size, uint8_t* buf);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user