Merge pull request #28 from E-Almqvist/dev

Refactor & cleanup
pull/34/head
Elias Almqvist 3 years ago committed by GitHub
commit a25af9a937
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 60
      drivers/vga.c
  2. 3
      drivers/vga.h
  3. 6
      kernel/kernel.c

@ -1,54 +1,61 @@
// VGA Graphics Library // VGA Graphics Library
#include "vga.h"
#include "../kernel/io.h" #include "../kernel/io.h"
// VGA base address: 0xb8000
// Charpos = 0xb8000 + 2(row*80 + col)
// Memory // Memory
#define VIDEO_MEM (char*)0xb8000 #define VGA_ADDRESS (char*)0xb8000
#define VIDEO_MEM_MAX (char*)0xb8fa0 #define VGA_ADDRESS_MAX (char*)0xb8fa0
#define MAX_ROWS 25
#define MAX_COLS 80
// Global
static unsigned int cursor_row = 0; static unsigned int cursor_row = 0;
static unsigned int cursor_col = 0; static unsigned int cursor_col = 0;
void vga_init() {
// Disable cursor
port_outb(0x3d4, 0x0a);
port_outb(0x3d5, 0x20);
// Clear screen
clear_screen();
}
/* /*
VGA & Memory Functions VGA & Memory Functions
*/ */
char* get_vga_charpos_pointer(unsigned int col, unsigned int row) { char* get_memory_charpos(unsigned int col, unsigned int row) {
return (char*)(VIDEO_MEM + 2*((row*80) + col)); return (char*)(VGA_ADDRESS + 2*((row*80) + col));
} }
void writechar(char c, unsigned int col, unsigned int row, int attribute_byte) { void writechar(char c, unsigned int col, unsigned int row, int attribute_byte) {
char* mem = get_vga_charpos_pointer(col, row); if( !attribute_byte )
*mem = c; // Write the character attribute_byte = 0x0f;
char* mem = get_memory_charpos(col, row);
*mem = c; // Write the character
*(mem+1) = attribute_byte; // Write the attribute_byte *(mem+1) = attribute_byte; // Write the attribute_byte
} }
void set_cursor_pos(unsigned int col, unsigned int row) {
cursor_col = col;
cursor_row = row;
}
/* /*
Graphics Functions Graphics Functions
*/ */
void clear_screen() { void clear_screen() {
// Make all the characters spaces for( int c = 0; c < MAX_COLS; c++ )
for( char* c = VIDEO_MEM; c <= VIDEO_MEM_MAX; c += 2 ) for( int r = 0; r < MAX_ROWS; r++ )
*c = 0x20; writechar(0x20, c, r, 0xf0);
}
void disable_vga_cursor() {
port_outb(0x0a, 0x3d4);
port_outb(0x20, 0x3d5);
} }
/* /*
General Printing Functions General Printing Functions
*/ */
void set_cursor_pos(unsigned int x, unsigned int y) {
cursor_col = x;
cursor_row = y;
}
void print(char* str, int attribute_byte) { void print(char* str, int attribute_byte) {
for( char* c = str; *c != '\0'; c++ ) for( char* c = str; *c != '\0'; c++ )
writechar(*c, (unsigned int)(c - str) + cursor_col, cursor_row, attribute_byte); writechar(*c, (unsigned int)(c - str) + cursor_col, cursor_row, attribute_byte);
@ -60,8 +67,3 @@ void println(char* str, int attribute_byte) {
} }
// VGA Initialization Function
void vga_init() {
disable_vga_cursor();
clear_screen();
}

@ -1,7 +1,6 @@
char* get_vga_charpos_pointer(unsigned int col, unsigned int row); char* get_memory_charpos(unsigned int col, unsigned int row);
void writechar(char c, unsigned int col, unsigned int row, int colorcode); void writechar(char c, unsigned int col, unsigned int row, int colorcode);
void clear_screen(); void clear_screen();
void disable_vga_cursor();
void set_cursor_pos(); void set_cursor_pos();
void print(); void print();
void println(); void println();

@ -6,4 +6,10 @@ void main() {
set_cursor_pos(28, 2); set_cursor_pos(28, 2);
print("eOS Version 0.1 2021", 0xf0); print("eOS Version 0.1 2021", 0xf0);
/*
set_cursor_pos(0, 0);
for( int i = 0; i < 255; i++ )
println("X", i);
*/
} }

Loading…
Cancel
Save