summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2015-09-28 02:39:47 -0700
committeriximeow <me@iximeow.net>2015-09-28 03:36:28 -0700
commit00d5836c010e82463fff1db14e588be881cdac4e (patch)
tree40bca3ce8cd2c74a2b4d604020512f0b85d6c8d1
parentafeac47a0192e0124006e13d6a098668903589fb (diff)
refactor to multi-file build
-rw-r--r--src/kernel/main.c59
-rw-r--r--src/output/vga_character.c49
-rw-r--r--src/output/vga_character.h16
3 files changed, 67 insertions, 57 deletions
diff --git a/src/kernel/main.c b/src/kernel/main.c
index c1c6ab6..4e9a580 100644
--- a/src/kernel/main.c
+++ b/src/kernel/main.c
@@ -1,23 +1,11 @@
__asm__(".code16gcc\n");
-void vga_graphics_write_at_offset(char, short);
-void vga_graphics_write(char);
-void vga_graphics_write_with_attr(char, char);
-void vga_graphics_write_str(char*);
+#include "../output/vga_character.h"
-void vga_graphics_byte_hex(char);
-//void vga_graphics_short_hex(short);
-//void vga_graphics_int_hex(int);
-//void vga_graphics_long_hex(long);
-
-void clear();
-
-static short CURSOR_LOC = 0;
-static char* HEX_CHARS = "0123456789abcdef";
char foo[] = "hello how are you";
void _start() {
- clear();
+ vga_graphics_clear();
vga_graphics_write_with_attr('a', 1);
vga_graphics_write_with_attr('/', 2);
vga_graphics_write_with_attr('b', 3);
@@ -27,46 +15,3 @@ void _start() {
vga_graphics_byte_hex(0x40);
while(1) { }
}
-
-void clear() {
- int TERM_WIDTH = 80;
- int TERM_HEIGHT = 25;
-
- int i = 0;
- while(i < TERM_WIDTH * TERM_HEIGHT) {
- vga_graphics_write_with_attr(' ', 7);
- i++;
- }
- CURSOR_LOC = 0;
-}
-
-void vga_graphics_write_str(char* str) {
- while(*str) {
- vga_graphics_write_with_attr(*str++, 7);
- }
-}
-
-void vga_graphics_write_with_attr(char value, char attr) {
- vga_graphics_write_at_offset(value, CURSOR_LOC++);
- vga_graphics_write_at_offset(attr, CURSOR_LOC++);
-}
-
-void vga_graphics_write(char value) {
- vga_graphics_write_at_offset(value, CURSOR_LOC);
- CURSOR_LOC += 2;
-}
-
-void vga_graphics_byte_hex(char value) {
- char low = value & 0x0f;
- char high = (value & 0xf0) >> 4;
- vga_graphics_write(HEX_CHARS[high]);
- vga_graphics_write(HEX_CHARS[low]);
-}
-
-void vga_graphics_write_at_offset(char value, short offset) {
- __asm__(
- "mov %0, %%al \n"
- "mov %1, %%di \n"
- "mov %%al, %%gs:(%%di) \n"
- : :"r"(value), "r"(offset) : "%ax", "%di");
-}
diff --git a/src/output/vga_character.c b/src/output/vga_character.c
new file mode 100644
index 0000000..bd59a97
--- /dev/null
+++ b/src/output/vga_character.c
@@ -0,0 +1,49 @@
+#include "vga_character.h"
+
+__asm__(".code16gcc\n");
+
+static short CURSOR_LOC = 0;
+static char* HEX_CHARS = "0123456789abcdef";
+
+void vga_graphics_write_str(char* str) {
+ while(*str) {
+ vga_graphics_write_with_attr(*str++, 7);
+ }
+}
+
+void vga_graphics_write_with_attr(char value, char attr) {
+ vga_graphics_write_at_offset(value, CURSOR_LOC++);
+ vga_graphics_write_at_offset(attr, CURSOR_LOC++);
+}
+
+void vga_graphics_write(char value) {
+ vga_graphics_write_at_offset(value, CURSOR_LOC);
+ CURSOR_LOC += 2;
+}
+
+void vga_graphics_byte_hex(char value) {
+ char low = value & 0x0f;
+ char high = (value & 0xf0) >> 4;
+ vga_graphics_write(HEX_CHARS[high]);
+ vga_graphics_write(HEX_CHARS[low]);
+}
+
+void vga_graphics_write_at_offset(char value, short offset) {
+ __asm__(
+ "mov %0, %%al \n"
+ "mov %1, %%di \n"
+ "mov %%al, %%gs:(%%di) \n"
+ : :"r"(value), "r"(offset) : "%ax", "%di");
+}
+
+void vga_graphics_clear() {
+ int TERM_WIDTH = 80;
+ int TERM_HEIGHT = 25;
+
+ int i = 0;
+ while(i < TERM_WIDTH * TERM_HEIGHT) {
+ vga_graphics_write_with_attr(' ', 7);
+ i++;
+ }
+ CURSOR_LOC = 0;
+}
diff --git a/src/output/vga_character.h b/src/output/vga_character.h
new file mode 100644
index 0000000..0d067f3
--- /dev/null
+++ b/src/output/vga_character.h
@@ -0,0 +1,16 @@
+#ifndef vga_character
+#define vga_character
+
+void vga_graphics_write_at_offset(char, short);
+void vga_graphics_write(char);
+void vga_graphics_write_with_attr(char, char);
+void vga_graphics_write_str(char*);
+
+void vga_graphics_byte_hex(char);
+//void vga_graphics_short_hex(short);
+//void vga_graphics_int_hex(int);
+//void vga_graphics_long_hex(long);
+
+void vga_graphics_clear(void);
+
+#endif