From 2ab3eaf2158516a223732f362e479e7160c9e600 Mon Sep 17 00:00:00 2001
From: y2-shaffan <yousuf2.shaffan@live.uwe.ac.uk>
Date: Mon, 4 Mar 2024 12:49:09 +0000
Subject: [PATCH] Update file kernel.c

---
 kernel.c | 45 +++++++++++++--------------------------------
 1 file changed, 13 insertions(+), 32 deletions(-)

diff --git a/kernel.c b/kernel.c
index 1333412..0bcaf45 100644
--- a/kernel.c
+++ b/kernel.c
@@ -79,42 +79,23 @@ void terminal_setcolor(uint8_t color) {
   terminal_color = color;
 }
  
-void terminal_putentryat(char c, uint8_t color, size_t x, size_t y) {
-  const size_t index = y * VGA_WIDTH + x;
-  terminal_buffer[index] = make_vgaentry(c, color);
-}
-
 void terminal_putchar(char c) {
-  if (c == '\n') {
-    terminal_column = 0;
-    if (++terminal_row == VGA_HEIGHT) {
-      for (size_t y = 1; y < VGA_HEIGHT; y++) {
-        for (size_t x = 0; x < VGA_WIDTH; x++) {
-          terminal_buffer[(y - 1) * VGA_WIDTH + x] = terminal_buffer[y * VGA_WIDTH + x];
+    if (c == '\n') {
+        terminal_column = 0;
+        if (++terminal_row == VGA_HEIGHT) {
+            terminal_row = 0;
         }
-      }
-      for (size_t x = 0; x < VGA_WIDTH; x++) {
-        terminal_buffer[(VGA_HEIGHT - 1) * VGA_WIDTH + x] = make_vgaentry(' ', terminal_color);
-      }
-      terminal_row = VGA_HEIGHT - 1;
-    }
-  } else {
-    terminal_putentryat(c, terminal_color, terminal_column, terminal_row);
-    if (++terminal_column == VGA_WIDTH) {
-      terminal_column = 0;
-      if (++terminal_row == VGA_HEIGHT) {
-        for (size_t y = 1; y < VGA_HEIGHT; y++) {
-          for (size_t x = 0; x < VGA_WIDTH; x++) {
-            terminal_buffer[(y - 1) * VGA_WIDTH + x] = terminal_buffer[y * VGA_WIDTH + x];
-          }
+    } else if (c == '\r') {
+        terminal_column = 0;
+    } else {
+        terminal_putentryat(c, terminal_color, terminal_column, terminal_row);
+        if (++terminal_column == VGA_WIDTH) {
+            terminal_column = 0;
+            if (++terminal_row == VGA_HEIGHT) {
+                terminal_row = 0;
+            }
         }
-        for (size_t x = 0; x < VGA_WIDTH; x++) {
-          terminal_buffer[(VGA_HEIGHT - 1) * VGA_WIDTH + x] = make_vgaentry(' ', terminal_color);
-        }
-        terminal_row = VGA_HEIGHT - 1;
-      }
     }
-  }
 }
 
 void terminal_writestring(const char* data) {
-- 
GitLab