Merge pull request #27 from E-Almqvist/dev

Update
pull/34/head
Elias Almqvist 3 years ago committed by GitHub
commit fd0ce94dbb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      TODO.md
  2. 22
      drivers/vga.c
  3. 2
      drivers/vga.h
  4. 8
      kernel/io.c
  5. 8
      kernel/io.h

@ -1,6 +1,7 @@
# TO DO
- Refactor the VGA driver
- Finish the book!
- Multiboot support (for grub etc)
- VGA Library (Graphics)
- Rendering (VGA)
- User input (Keyboard)
- File system?

@ -1,5 +1,5 @@
// VGA Graphics Library
#include <sys/io.h>
#include "../kernel/io.h"
// VGA base address: 0xb8000
// Charpos = 0xb8000 + 2(row*80 + col)
@ -19,10 +19,10 @@ char* get_vga_charpos_pointer(unsigned int col, unsigned int row) {
return (char*)(VIDEO_MEM + 2*((row*80) + col));
}
void writechar(char c, unsigned int col, unsigned int row, int colorcode) {
void writechar(char c, unsigned int col, unsigned int row, int attribute_byte) {
char* mem = get_vga_charpos_pointer(col, row);
*mem = c; // Write the character
*(mem+1) = colorcode; // Write the colorcode
*(mem+1) = attribute_byte; // Write the attribute_byte
}
@ -35,9 +35,9 @@ void clear_screen() {
*c = 0x20;
}
void disable_cursor() {
outb(0x3d4, 0x0a);
outb(0x3d5, 0x20);
void disable_vga_cursor() {
port_outb(0x0a, 0x3d4);
port_outb(0x20, 0x3d5);
}
@ -49,19 +49,19 @@ void set_cursor_pos(unsigned int x, unsigned int y) {
cursor_row = y;
}
void print(char* str, int colorcode) {
void print(char* str, int attribute_byte) {
for( char* c = str; *c != '\0'; c++ )
writechar(*c, (unsigned int)(c - str) + cursor_col, cursor_row, colorcode);
writechar(*c, (unsigned int)(c - str) + cursor_col, cursor_row, attribute_byte);
}
void println(char* str, int colorcode) {
print(str, colorcode);
void println(char* str, int attribute_byte) {
print(str, attribute_byte);
cursor_row++; // Increment to next y-pos (newline)
}
// VGA Initialization Function
void vga_init() {
disable_cursor();
disable_vga_cursor();
clear_screen();
}

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

@ -1,5 +1,5 @@
// Function to read a byte from port
unsigned char port_byte_in(unsigned short port) {
unsigned char port_inb(unsigned short port) {
unsigned char res;
__asm__("in %%dx, %%al" : "=a" (res) : "d" (port));
@ -7,13 +7,13 @@ unsigned char port_byte_in(unsigned short port) {
}
// to write a byte to port
void port_byte_out(unsigned short port, unsigned char data) {
void port_outb(unsigned short port, unsigned char data) {
__asm__("out %%al, %%dx" : :"a" (data), "d" (port));
}
// Read word from port
unsigned short port_word_in(unsigned short port) {
unsigned short port_inw(unsigned short port) {
unsigned short res;
__asm__("in %%dx, %%ax" : "=a" (res) : "d" (port));
@ -21,6 +21,6 @@ unsigned short port_word_in(unsigned short port) {
}
// write word to port
void port_word_out(unsigned short port, unsigned short data) {
void port_outw(unsigned short port, unsigned short data) {
__asm__("out %%ax, %%dx" : :"a" (data), "d" (port));
}

@ -1,5 +1,5 @@
unsigned char port_byte_in();
void port_byte_out();
unsigned char port_inb();
void port_outb();
unsigned short port_word_in();
void port_word_out();
unsigned short port_inw();
void port_outw();

Loading…
Cancel
Save