summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c48
1 files changed, 19 insertions, 29 deletions
diff --git a/src/main.c b/src/main.c
index 68fdb66..4ea0449 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,9 +1,5 @@
-#define NB_COLS 80
-#define NB_ROWS 25
-#define BPC 2
-#define BPR (BPC * NB_COLS)
-
-#define VIDEO_BUFFER 0xB8000
+#include "serial.h"
+#include "vga.h"
/* XXX doest not always handle memory overlaps */
static void my_memmove(void *_dest, const void *_src, int n)
@@ -16,21 +12,12 @@ static void my_memmove(void *_dest, const void *_src, int n)
}
}
-static void my_memset(void *_dest, int c, int n)
-{
- char *dest = _dest;
-
- for (int i = 0; i < n; ++i) {
- dest[i] = c;
- }
-}
-
static void clear_line(void *_addr)
{
char *addr = _addr;
- for (int i = 0; i < NB_COLS; ++i) {
- if (i % BPC == 0) {
+ for (int i = 0; i < VGA_COLS; ++i) {
+ if (i % VGA_BPC == 0) {
*addr++ = ' ';
} else {
*addr++ = 0x7;
@@ -40,33 +27,33 @@ static void clear_line(void *_addr)
int printk(const char *str)
{
- static const long int offset = VIDEO_BUFFER;
- static char *addr = (char *) VIDEO_BUFFER;
+ static const long int offset = VGA_BASE;
+ static char *addr = (char *) VGA_BASE;
int count = 0;
for (int i = 0; str[i]; ++i) {
- /* TODO add the serial port handling */
+ serial_putchar(str[i]);
char chr;
char *new_addr = addr;
- char *addr_line = (char *)(((long)(addr - offset) / BPR) * BPR) + offset;
+ char *addr_line = (char *)(((long)(addr - offset) / VGA_BPR) *
+ VGA_BPR) + offset;
- if ((long)addr >= offset + NB_ROWS * BPR) {
+ if ((long)addr >= offset + VGA_ROWS * VGA_BPR) {
/* shift up */
- addr -= BPR;
- addr_line -= BPR;
- my_memmove((void *)offset, (void *)offset + BPR, BPR * (NB_ROWS - 1));
- clear_line(addr_line);
+ addr -= VGA_BPR;
+ addr_line -= VGA_BPR;
+ my_memmove((void *)offset, (void *)offset + VGA_BPR, VGA_BPR
+ * (VGA_ROWS - 1)); clear_line(addr_line);
}
-
switch (str[i]) {
case '\n':
- new_addr = addr_line + BPR;
+ new_addr = addr_line + VGA_BPR;
chr = '\0';
break;
default:
- new_addr = addr + BPC;
+ new_addr = addr + VGA_BPC;
chr = str[i];
break;
}
@@ -83,4 +70,7 @@ int printk(const char *str)
int main(void)
{
+ serial_init();
+
+ return 0;
}