From 9b5760aa26108d5dd8ef6a4defadeeba0efc9630 Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Sun, 11 Oct 2015 13:22:20 +0200 Subject: kfs: fixed the printing on the frame buffer when clearing a line, we used to set the second byte to 0, which means black foreground on black background. Thus, it looked like nothing was written anymore afterwards. Fixed by setting the foreground to white. Signed-off-by: Olivier Gayot --- src/main.c | 45 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/main.c b/src/main.c index 7c1172c..68fdb66 100644 --- a/src/main.c +++ b/src/main.c @@ -1,6 +1,7 @@ #define NB_COLS 80 #define NB_ROWS 25 #define BPC 2 +#define BPR (BPC * NB_COLS) #define VIDEO_BUFFER 0xB8000 @@ -24,6 +25,19 @@ static void my_memset(void *_dest, int c, int n) } } +static void clear_line(void *_addr) +{ + char *addr = _addr; + + for (int i = 0; i < NB_COLS; ++i) { + if (i % BPC == 0) { + *addr++ = ' '; + } else { + *addr++ = 0x7; + } + } +} + int printk(const char *str) { static const long int offset = VIDEO_BUFFER; @@ -33,15 +47,34 @@ int printk(const char *str) for (int i = 0; str[i]; ++i) { /* TODO add the serial port handling */ - if ((long)addr >= offset + NB_COLS * NB_ROWS * BPC) { + char chr; + char *new_addr = addr; + char *addr_line = (char *)(((long)(addr - offset) / BPR) * BPR) + offset; + + if ((long)addr >= offset + NB_ROWS * BPR) { /* shift up */ - addr -= NB_COLS * BPC; - my_memmove((void *)offset, (void *)offset + NB_COLS * BPC, NB_COLS * (NB_ROWS - 1) * BPC); - my_memset((void *)offset + NB_COLS * (NB_ROWS - 1) * BPC, ' ', NB_COLS * BPC); + addr -= BPR; + addr_line -= BPR; + my_memmove((void *)offset, (void *)offset + BPR, BPR * (NB_ROWS - 1)); + clear_line(addr_line); } - *addr = str[i]; - addr += BPC; + + switch (str[i]) { + case '\n': + new_addr = addr_line + BPR; + chr = '\0'; + break; + default: + new_addr = addr + BPC; + chr = str[i]; + break; + } + + if (chr) + *addr = chr; + + addr = new_addr; ++count; } -- cgit v1.2.3