From 302ed3b816e8b155c43aace2a17496250bff2e98 Mon Sep 17 00:00:00 2001 From: ngiddings Date: Tue, 13 Apr 2021 00:21:08 -0500 Subject: [PATCH] Fixed issues with tabs and newlines in putchar() --- src/x86/putc.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/x86/putc.c b/src/x86/putc.c index cac04ab..854751f 100644 --- a/src/x86/putc.c +++ b/src/x86/putc.c @@ -29,6 +29,7 @@ struct cell_t }; struct cell_t *screen = (struct cell_t*)0xFF8B8000; +size_t cursor = 0; const size_t tab_width = 4; const size_t line_width = 80; @@ -38,19 +39,20 @@ int putchar(int c) switch(c) { case '\n': - screen += line_width; - screen -= (size_t) screen % line_width; + cursor += line_width; + cursor -= cursor % line_width; break; case '\t': - screen += (tab_width) & ~(tab_width); + cursor += tab_width; + cursor -= cursor % tab_width; break; case '\r': - screen -= line_width - 1; - screen += line_width - ((size_t) screen % line_width); + cursor -= line_width - 1; + cursor += line_width - (cursor % line_width); break; default: - screen->c = (char) c; - screen++; + screen[cursor].c = (char) c; + cursor++; } return c; } @@ -60,6 +62,7 @@ int puts(const char *str) while(*str) { putchar(*str); + str++; } return 0; } \ No newline at end of file