Basic VGA driver

This commit is contained in:
Arnau Camprubí 2022-06-17 12:28:24 +02:00
pare 30070d84dd
commit 1215e39086
S'han modificat 3 arxius amb 59 adicions i 3 eliminacions

9
src/kernel/drivers/vga.c Normal file
Veure arxiu

@ -0,0 +1,9 @@
#include "vga.h"
void set_char(int x, int y, char c){
VGA_MEMORY[(x+y*VGA_WIDTH)*2] = c;
}
void set_color(int x, int y, uint8_t color){
VGA_MEMORY[(x+y*VGA_WIDTH)*2+1] = color;
}

45
src/kernel/drivers/vga.h Normal file
Veure arxiu

@ -0,0 +1,45 @@
#pragma once
#include <stdint.h>
#define VGA_MEMORY ((char *)0xB8000)
#define VGA_COLOR_FG_BLACK 0x00
#define VGA_COLOR_FG_BLUE 0x01
#define VGA_COLOR_FG_GREEN 0x02
#define VGA_COLOR_FG_CYAN 0x03
#define VGA_COLOR_FG_RED 0x04
#define VGA_COLOR_FG_PINK 0x05
#define VGA_COLOR_FG_ORANGE 0x06
#define VGA_COLOR_FG_WHITE 0x07
#define VGA_COLOR_FG_LIGHT_BLACK 0x08
#define VGA_COLOR_FG_LIGHT_BLUE 0x09
#define VGA_COLOR_FG_LIGHT_GREEN 0x0A
#define VGA_COLOR_FG_LIGHT_CYAN 0x0B
#define VGA_COLOR_FG_LIGHT_RED 0x0C
#define VGA_COLOR_FG_LIGHT_PINK 0x0D
#define VGA_COLOR_FG_LIGHT_ORANGE 0x0E
#define VGA_COLOR_FG_LIGHT_WHITE 0x0F
#define VGA_COLOR_BG_BLACK 0x00
#define VGA_COLOR_BG_BLUE 0x10
#define VGA_COLOR_BG_GREEN 0x20
#define VGA_COLOR_BG_CYAN 0x30
#define VGA_COLOR_BG_RED 0x40
#define VGA_COLOR_BG_PINK 0x50
#define VGA_COLOR_BG_ORANGE 0x60
#define VGA_COLOR_BG_WHITE 0x70
#define VGA_COLOR_BG_LIGHT_BLACK 0x80
#define VGA_COLOR_BG_LIGHT_BLUE 0x90
#define VGA_COLOR_BG_LIGHT_GREEN 0xA0
#define VGA_COLOR_BG_LIGHT_CYAN 0xB0
#define VGA_COLOR_BG_LIGHT_RED 0xC0
#define VGA_COLOR_BG_LIGHT_PINK 0xD0
#define VGA_COLOR_BG_LIGHT_ORANGE 0xE0
#define VGA_COLOR_BG_LIGHT_WHITE 0xF0
#define VGA_WIDTH 80
#define VGA_HEIGHT 25
void set_char(int x, int y, char c);
void set_color(int x, int y, uint8_t color);

Veure arxiu

@ -1,7 +1,9 @@
#include <stdint.h>
#include "arch/i686/io.h"
#include "drivers/vga.h"
void __attribute__((cdecl)) kmain(uint64_t magic, uint64_t addr){
char *mem = (char *)0xB8000; // Screen memory address (when on text mode)
for(int i = 0; 1; i++) mem[i] = 88; // Fill screen with Blue 'X' characters over pink background
// Print a light cyan 'X' over green on the top left corner
set_char(0, 0, 'X');
set_color(0, 0, VGA_COLOR_BG_GREEN | VGA_COLOR_FG_LIGHT_CYAN);
for(;;); // Halt here
}