-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7a00b62
commit 9247306
Showing
7 changed files
with
127 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#include "vga.h" | ||
|
||
#define VGA_WIDTH 80 | ||
#define VGA_HEIGHT 25 | ||
#define VGA_MEMORY ((u16 *)0xB8000) | ||
|
||
static size_t terminal_row; | ||
static size_t terminal_column; | ||
static u8 terminal_color; | ||
static u16* terminal_buffer; | ||
|
||
static u8 vga_entry_color(enum vga_color fg, enum vga_color bg) { | ||
return fg | bg << 4; | ||
} | ||
|
||
static u16 vga_entry(unsigned char uc, u8 color) { | ||
return (u16)uc | (u16)color << 8; | ||
} | ||
|
||
void vga_init(void) { | ||
terminal_row = 0; | ||
terminal_column = 0; | ||
terminal_color = vga_entry_color(VGA_LIGHT_GREY, VGA_BLACK); | ||
terminal_buffer = VGA_MEMORY; | ||
|
||
vga_clear(); | ||
} | ||
|
||
void vga_clear(void) { | ||
for (size_t y = 0; y < VGA_HEIGHT; y++) { | ||
for (size_t x = 0; x < VGA_WIDTH; x++) { | ||
const size_t index = y * VGA_WIDTH + x; | ||
terminal_buffer[index] = vga_entry(' ', terminal_color); | ||
} | ||
} | ||
} | ||
|
||
void vga_setcolor(u8 color) { | ||
terminal_color = color; | ||
} | ||
|
||
void vga_putchar(char c) { | ||
if (c == '\n') { | ||
terminal_column = 0; | ||
terminal_row++; | ||
if (terminal_row == VGA_HEIGHT) { | ||
terminal_row = 0; | ||
} | ||
return; | ||
} | ||
|
||
unsigned char uc = c; | ||
terminal_buffer[terminal_row * VGA_WIDTH + terminal_column] = vga_entry(uc, terminal_color); | ||
|
||
if (++terminal_column == VGA_WIDTH) { | ||
terminal_column = 0; | ||
if (++terminal_row == VGA_HEIGHT) { | ||
terminal_row = 0; | ||
} | ||
} | ||
} | ||
|
||
void vga_write(const char *data, size_t size) { | ||
for (size_t i = 0; i < size; i++) { | ||
vga_putchar(data[i]); | ||
} | ||
} | ||
|
||
void vga_writestring(const char *data) { | ||
for (size_t i = 0; data[i] != '\0'; i++) { | ||
vga_putchar(data[i]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#ifndef VGA_H | ||
#define VGA_H | ||
|
||
#include "../types.h" | ||
|
||
enum vga_color | ||
{ | ||
VGA_BLACK = 0, | ||
VGA_BLUE = 1, | ||
VGA_GREEN = 2, | ||
VGA_CYAN = 3, | ||
VGA_RED = 4, | ||
VGA_MAGENTA = 5, | ||
VGA_BROWN = 6, | ||
VGA_LIGHT_GREY = 7, | ||
VGA_DARK_GREY = 8, | ||
VGA_LIGHT_BLUE = 9, | ||
VGA_LIGHT_GREEN = 10, | ||
VGA_LIGHT_CYAN = 11, | ||
VGA_LIGHT_RED = 12, | ||
VGA_LIGHT_MAGENTA = 13, | ||
VGA_LIGHT_BROWN = 14, | ||
VGA_WHITE = 15 | ||
}; | ||
|
||
void vga_init(void); | ||
void vga_putchar(char c); | ||
void vga_write(const char *data, size_t size); | ||
void vga_writestring(const char *data); | ||
void vga_setcolor(u8 color); | ||
void vga_clear(void); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters