Merge pull request #30 from E-Almqvist/dev

UI Stuff
pull/34/head
Elias Almqvist 3 years ago committed by GitHub
commit 8bb0dd10aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 24
      drivers/vga.c
  2. 12
      drivers/vga.h
  3. 15
      kernel/kernel.c
  4. BIN
      preview.png

@ -1,13 +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
#define VGA_ADDRESS (char*)0xb8000
#define VGA_ADDRESS_MAX (char*)0xb8fa0
#define MAX_ROWS 25
#define MAX_COLS 80
static unsigned int cursor_row = 0; static unsigned int cursor_row = 0;
static unsigned int cursor_col = 0; static unsigned int cursor_col = 0;
@ -50,7 +44,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 +60,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* str2 = "World!"; char* strbuf = "String concat: ";
char* str2 = "WORKS! :D";
strbuf = strcat(strbuf, str2); strbuf = strcat(strbuf, str2);
set_cursor_pos(0, 0); set_cursor_pos(0, 0);
println(strbuf, 0x0f); println(strbuf, 0xf0);
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB

Loading…
Cancel
Save