VGA set_cursor() and get_cursor()

This commit is contained in:
Arnau Camprubí 2022-06-17 12:47:57 +02:00
pare 541d7924b0
commit 1816cefb47
S'han modificat 3 arxius amb 22 adicions i 0 eliminacions

Veure arxiu

@ -1,4 +1,5 @@
#include "vga.h"
#include "../arch/i686/io.h"
void set_char(int x, int y, char c){
VGA_MEMORY[(x+y*VGA_WIDTH)*2] = c;
@ -7,3 +8,18 @@ void set_char(int x, int y, char c){
void set_color(int x, int y, uint8_t color){
VGA_MEMORY[(x+y*VGA_WIDTH)*2+1] = color;
}
void set_cursor(int offset){
i686_outb(VGA_PORT_CTRL, 14);
i686_outb(VGA_PORT_DATA, (uint8_t)(offset >> 8));
i686_outb(VGA_PORT_CTRL, 15);
i686_outb(VGA_PORT_DATA, (uint8_t)(offset & 0xff));
}
int get_cursor(){
i686_outb(VGA_PORT_CTRL, 14);
int offset = i686_inb(VGA_PORT_DATA) << 8; // High byte
i686_outb(VGA_PORT_CTRL, 15);
offset += i686_inb(VGA_PORT_DATA); // Low byte
return offset;
}

Veure arxiu

@ -41,5 +41,10 @@
#define VGA_WIDTH 80
#define VGA_HEIGHT 25
#define VGA_PORT_CTRL 0x3D4
#define VGA_PORT_DATA 0x3D5
void set_char(int x, int y, char c);
void set_color(int x, int y, uint8_t color);
void set_cursor(int offset);
int get_cursor();

Veure arxiu

@ -5,5 +5,6 @@ void __attribute__((cdecl)) kmain(uint64_t magic, uint64_t addr){
// 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);
set_cursor(1);
for(;;); // Halt here
}