From 9007f21b11ce65e219f8b2a26dd294bcd3666da9 Mon Sep 17 00:00:00 2001
From: unknown <abinade2@illinois.edu>
Date: Sat, 28 Apr 2018 23:46:56 -0500
Subject: [PATCH] control L partially working

---
 student-distrib/keyboard.c | 12 +++++++-----
 student-distrib/keyboard.h |  8 ++++----
 student-distrib/lib.c      | 24 +++++++++++++++++++++++-
 student-distrib/lib.h      |  1 +
 4 files changed, 35 insertions(+), 10 deletions(-)

diff --git a/student-distrib/keyboard.c b/student-distrib/keyboard.c
index 3047f6e..17abc76 100644
--- a/student-distrib/keyboard.c
+++ b/student-distrib/keyboard.c
@@ -146,10 +146,10 @@ void KB_init(void) {
     // initialize modifier flags
 
      enter_flag[0] = enter_flag[1] = enter_flag[2] = 0;
+      ctrl_flag[0] =  ctrl_flag[1] =  ctrl_flag[2] = 0;
 
      caps_flag = 0;
      alt_flag = 0;
-     ctrl_flag = 0;
      shift_flag = 0;
 
     enable_irq(KB_IRQ);
@@ -298,13 +298,13 @@ void KB_handler(void) {
 
         case 0x1D : //ctrl pressed
 
-            ctrl_flag = 1;
+            ctrl_flag[visible_terminal] = 1;
             send_eoi(KB_IRQ);
             return;
 
         case 0x9D : //ctrl released
 
-            ctrl_flag = 0;
+            ctrl_flag[visible_terminal] = 0;
             send_eoi(KB_IRQ);
             return;
 
@@ -352,9 +352,10 @@ void KB_handler(void) {
 
     // 0x15 = scancode for L
     // check if ctrl-L is pressed
-    if(ctrl_flag && !shift_flag && pressed_key == 0x15)
+    if(ctrl_flag[visible_terminal] /*&& !shift_flag*/ && pressed_key == 0x15)
     {
-        clear();
+        //clear();
+        clear_memory();
         reset_cursor();
         send_eoi(KB_IRQ);
         return;
@@ -384,6 +385,7 @@ void KB_handler(void) {
     }
 
     page_table[0xB8] = ((uint32_t)0xB8000) | USER | READ_WRITE | PRESENT;
+    flush_tlb();
 
     //memcpy( (void*)TERM_VID, (const void*) terminal[visible_terminal].vid_mem, _4_KB );
 
diff --git a/student-distrib/keyboard.h b/student-distrib/keyboard.h
index 2679cec..3b658b3 100644
--- a/student-distrib/keyboard.h
+++ b/student-distrib/keyboard.h
@@ -16,10 +16,10 @@
 #define ASCII_SIZE      51
 
 // keyboard modifier flags
-uint8_t caps_flag;
-uint8_t ctrl_flag;
-uint8_t shift_flag;
-uint8_t alt_flag;
+		 uint8_t caps_flag;
+		 uint8_t shift_flag;
+		 uint8_t alt_flag;
+         uint8_t ctrl_flag[3];
 volatile uint8_t enter_flag[3];
 
 /************************ KB driver functions ************************/
diff --git a/student-distrib/lib.c b/student-distrib/lib.c
index a30956f..325f335 100644
--- a/student-distrib/lib.c
+++ b/student-distrib/lib.c
@@ -17,9 +17,31 @@ static char* video_mem = (char *)VIDEO;
  * Function: Clears video memory */
 void clear(void) {
     int32_t i;
+
     for (i = 0; i < NUM_ROWS * NUM_COLS; i++) {
         *(uint8_t *)(video_mem + (i << 1)) = ' ';
-        *(uint8_t *)(video_mem + (i << 1) + 1) = ATTRIB;
+        *(uint8_t *)(video_mem + (i << 1) + 1) = ATTRIB;    
+    }
+}
+
+void clear_memory(void)
+{
+    int32_t i;
+    uint8_t * video_memory;
+
+    if(running_terminal == running_terminal)
+        video_memory = (uint8_t *) video_mem;
+    else
+        video_memory = (uint8_t *) terminal[visible_terminal].vid_mem;
+
+    for (i = 0; i < NUM_ROWS * NUM_COLS; i++) {
+        *(uint8_t *)(video_memory + (i << 1)) = ' ';
+        *(uint8_t *)(video_memory + (i << 1) + 1) = ATTRIB;    
+    }
+
+    for (i = 0; i < NUM_ROWS * NUM_COLS; i++) {
+        *(uint8_t *)(terminal[visible_terminal].vid_mem + (i << 1)) = ' ';
+        *(uint8_t *)(terminal[visible_terminal].vid_mem + (i << 1) + 1) = ATTRIB;
     }
 }
 
diff --git a/student-distrib/lib.h b/student-distrib/lib.h
index 98e587c..d22f01a 100644
--- a/student-distrib/lib.h
+++ b/student-distrib/lib.h
@@ -15,6 +15,7 @@ int8_t *itoa(uint32_t value, int8_t* buf, int32_t radix);
 int8_t *strrev(int8_t* s);
 uint32_t strlen(const int8_t* s);
 void clear(void);
+void clear_memory(void);
 void reset_cursor(void);
 void update_cursor(int32_t term_id);
 int32_t get_screen_x(void);
-- 
GitLab