-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add writing to screen and print function
- Loading branch information
1 parent
8bf1818
commit 4eb6ad9
Showing
6 changed files
with
94 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
build/ | ||
bin/ |
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,3 @@ | ||
#/bin/bash | ||
./build.sh | ||
qemu-system-x86_64 -hda bin/os.bin |
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,71 @@ | ||
#include "kernel.h" | ||
#include <stdint.h> | ||
#include <stddef.h> | ||
|
||
uint16_t *video_mem = 0; | ||
uint16_t terminal_row = 0; | ||
uint16_t terminal_col = 0; | ||
|
||
uint16_t terminal_make_char(char c, char color) | ||
{ | ||
return (color << 8) | c; | ||
} | ||
|
||
void terminal_putchar(int x, int y, char c, char color) | ||
{ | ||
video_mem[(y * VGA_WIDTH + x)] = terminal_make_char(c, color); | ||
} | ||
|
||
void terminal_writechar(char c, char color) | ||
{ | ||
if (c == '\n') | ||
{ | ||
terminal_row += 1; | ||
terminal_col = 0; | ||
return; | ||
} | ||
terminal_putchar(terminal_col, terminal_row, c, color); | ||
terminal_col += 1; | ||
if (terminal_col >= VGA_WIDTH) | ||
{ | ||
terminal_col = 0; | ||
terminal_row += 1; | ||
} | ||
} | ||
|
||
void terminal_initialize() | ||
{ | ||
video_mem = (uint16_t *)(0xB8000); | ||
for (int y = 0; y < VGA_HEIGHT; y++) | ||
{ | ||
for (int x = 0; x < VGA_WIDTH; x++) | ||
{ | ||
terminal_putchar(x, y, ' ', 0); | ||
} | ||
} | ||
} | ||
|
||
size_t strlen(const char *str) | ||
{ | ||
size_t len = 0; | ||
while (str[len]) | ||
{ | ||
len++; | ||
} | ||
|
||
return len; | ||
} | ||
|
||
void print(const char *str) | ||
{ | ||
size_t len = strlen(str); | ||
for (int i = 0; i < len; i++) | ||
{ | ||
terminal_writechar(str[i], 15); | ||
} | ||
} | ||
void kernel_main() | ||
{ | ||
terminal_initialize(); | ||
print("Hello World!\nThis is fun"); | ||
} |
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,9 @@ | ||
#ifndef KERNEL_H | ||
#define KERNEL_H | ||
|
||
#define VGA_WIDTH 80 | ||
#define VGA_HEIGHT 80 | ||
|
||
void kernel_main(); | ||
|
||
#endif |