From b85a42da521dac79a7cf478168c2777ea7897070 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Wed, 4 Nov 2015 12:03:25 +0100 Subject: tty: support '\n', fix API to putc and puts --- kernel/tty.c | 22 ++++++++++++++-------- kernel/tty.h | 4 ++-- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/kernel/tty.c b/kernel/tty.c index 4cb2cf1..628a21e 100644 --- a/kernel/tty.c +++ b/kernel/tty.c @@ -40,7 +40,7 @@ static inline uint16_t make_vgaentry(char c, uint8_t color) return ((uint16_t) c) | (((uint16_t) color) << VGA_COLOR_SHIFT); } -static inline void tty_putentryat(char c, uint8_t color, size_t x, size_t y) +static inline void tty_putc_at(char c, uint8_t color, size_t x, size_t y) { const size_t i = y * VGA_WIDTH + x; tty_buffer[i] = make_vgaentry(c, color); @@ -51,21 +51,27 @@ void tty_setcolor(uint8_t color) tty_color = color; } -void tty_putchar(char c) +void tty_putc(char c) { - tty_putentryat(c, tty_color, tty_col, tty_row); - if (++tty_col == VGA_WIDTH) { + if (c == '\n') + { tty_col = 0; - if (++tty_row == VGA_HEIGHT) { - tty_row = 0; + tty_row++; + } else { + tty_putc_at(c, tty_color, tty_col, tty_row); + if (++tty_col == VGA_WIDTH) { + tty_col = 0; + if (++tty_row == VGA_HEIGHT) { + tty_row = 0; + } } } } -void tty_writestring(const char* data) +void tty_puts(const char* data) { for (const char* p = data; *p != 0; p++) - tty_putchar(*p); + tty_putc(*p); } void tty_init() diff --git a/kernel/tty.h b/kernel/tty.h index 3c4b09e..27dfe23 100644 --- a/kernel/tty.h +++ b/kernel/tty.h @@ -7,8 +7,8 @@ void tty_init(); void tty_setcolor(uint8_t color); -void tty_putchar(char c); +void tty_putc(char c); -void tty_writestring(const char* data); +void tty_puts(const char* data); #endif -- cgit v1.1-2-g2b99