printalign & alignment enum etc

pull/30/head
E. Almqvist 3 years ago
parent 02faf041ff
commit 46c231a4c5
  1. 17
      drivers/vga.c
  2. 12
      drivers/vga.h
  3. 11
      kernel/kernel.c

@ -1,6 +1,7 @@
// VGA Graphics Library // VGA Graphics Library
#include "vga.h" #include "vga.h"
#include "../kernel/io.h" #include "../kernel/io.h"
#include "../lib/str.h"
// Memory // Memory
#define VGA_ADDRESS (char*)0xb8000 #define VGA_ADDRESS (char*)0xb8000
@ -50,7 +51,7 @@ void set_cursor_pos(unsigned int col, unsigned int row) {
void clear_screen() { void clear_screen() {
for( int c = 0; c < MAX_COLS; c++ ) for( int c = 0; c < MAX_COLS; c++ )
for( int r = 0; r < MAX_ROWS; r++ ) for( int r = 0; r < MAX_ROWS; r++ )
writechar(0x20, c, r, 0x0f); writechar(0x20, c, r, 0xf0);
} }
/* /*
@ -66,4 +67,18 @@ void println(char* str, int attribute_byte) {
cursor_row++; // Increment to next y-pos (newline) cursor_row++; // Increment to next y-pos (newline)
} }
void printalign(char* str, int attribute_byte, enum align alignment) {
unsigned int strlenbuf = strlen(str);
if( !alignment || alignment == LEFT ) {
print(str, attribute_byte);
} else if ( alignment == RIGHT ) {
set_cursor_pos(MAX_COLS - strlenbuf, cursor_row);
} else if ( alignment == MIDDLE ) {
set_cursor_pos((MAX_COLS/2) - (strlenbuf/2), cursor_row);
}
print(str, attribute_byte);
}

@ -1,7 +1,19 @@
#define VGA_ADDRESS (char*)0xb8000
#define VGA_ADDRESS_MAX (char*)0xb8fa0
#define MAX_ROWS 25
#define MAX_COLS 80
static unsigned int cursor_row;
static unsigned int cursor_col;
enum align {LEFT, RIGHT, MIDDLE};
char* get_memory_charpos(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 set_cursor_pos(); void set_cursor_pos();
void print(); void print();
void println(); void println();
void printalign(char* str, int attribute_byte, enum align alignment);
void vga_init(); void vga_init();

@ -6,13 +6,18 @@ void main() {
vga_init(); // Initialize the screen first vga_init(); // Initialize the screen first
// i.e. clear the screen et cetera. // i.e. clear the screen et cetera.
set_cursor_pos(28, 2); char* title = "eOS Version 0.1 2021";
print("eOS Version 0.1 2021", 0x0f); set_cursor_pos(0, 2);
printalign(title, 0xf0, MIDDLE);
char* subtitle = "A x86 operating system, licenced under GPL-2.0";
set_cursor_pos(0, 3);
printalign(subtitle, 0xf8, MIDDLE);
char* strbuf = "Hello"; char* strbuf = "Hello";
char* str2 = "World!"; char* str2 = "World!";
strbuf = strcat(strbuf, str2); strbuf = strcat(strbuf, str2);
set_cursor_pos(0, 0); set_cursor_pos(0, 0);
println(strbuf, 0x0f); println(strbuf, 0xf0);
} }

Loading…
Cancel
Save