Index: lab3/lab3
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/x-executable
Index: lab3/lab3.c
===================================================================
--- lab3/lab3.c	(revision 4)
+++ lab3/lab3.c	(revision 5)
@@ -29,7 +29,7 @@
   // handles control over to LCF
   // [LCF handles command line arguments and invokes the right function]
   if (lcf_start(argc, argv))
-    return 1;
+     return 1;
 
   // LCF clean up tasks
   // [must be the last statement before return]
@@ -38,56 +38,89 @@
   return 0;
 }
 
-void (kbc_ih)()
-{
-  sys_inb(I_O_BUFFER, &scancode);
-}
+void(kbc_ih)() {}
 
 int(kbd_test_scan)() {
   /* To be completed by the students */
   int ipc_status;
-  uint8_t r, bit_no=0;
+  uint8_t r, bit_no = 0;
   message msg;
-  int hook_id=bit_no;
-  uint8_t scan_arr[2] = {0,0};
-  scan_arr[0]=scancode & 0xFF;
-  scan_arr[1]=scancode & 0xFF00;
-  sys_irqsetpolicy(IRQ_KB,IRQ_REENABLE|IRQ_EXCLUSIVE,&hook_id);
+  int hook_id = bit_no;
+  uint8_t scan_arr[2] = {0, 0};
+  scan_arr[0] = scancode & 0xFF;
+  scan_arr[1] = scancode & 0xFF00;
+  int flag=0;
 
-  //kbc_ih();
-  printf("%x\n",scancode);
-   while( 1)//(scancode & 0xFF) != EXIT_CODE )
- { /* You may want to use a different condition */
-     /* Get a request message. */
-     // printf("1\n");
-     //printf("cont:%d, time:%d\n\n",cont/60,time);
-     if ( (r = driver_receive(ANY, &msg, &ipc_status)) != 0 ) 
-     { 
-        printf("driver_receive failed with: %d", r);
-       continue;
+  printf("%d\n",
+         sys_irqsetpolicy(IRQ_KB, IRQ_REENABLE | IRQ_EXCLUSIVE, &hook_id));
+  /* sys_outb(0x64, 0x20);
+  sys_inb(0x64, &scancode);
+  printf("%x\n", scancode);
+  if (scancode & 0x10) {
+    scancode = (scancode & 0xEF);
+  }
+
+  printf("%x\n", scancode);
+  sys_outb(0x64, 0x60);
+  sys_outb(0x64, scancode); */
+
+  printf("%x\n", scancode);
+  kbc_ih();
+  printf("\n");
+  while ((scancode & 0xFF) !=
+         EXIT_CODE) { /* You may want to use a different condition */
+    /* Get a request message. */
+    // printf("1\n");
+    // printf("cont:%d, time:%d\n\n",cont/60,time);
+    if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) {
+      printf("driver_receive failed with: %d", r);
+      continue;
     }
     if (is_ipc_notify(ipc_status)) { /* received notification */
-        switch (_ENDPOINT_P(msg.m_source)) {
-            case HARDWARE: /* hardware interrupt notification */				
-                if (msg.m_notify.interrupts  & BIT(0)) { /* subscribed interrupt */
-                   
-                   kbd_print_scancode((scancode & 0xFF & 0x80),2,scan_arr );
-               }
-                //printf("msg:%x\n",msg.m_notify.interrupts);
-                break;
-            default:
-                //printf("2\n");
-                break; /* no other notifications expected: do nothing */	
+      switch (_ENDPOINT_P(msg.m_source)) {
+      case HARDWARE: /* hardware interrupt notification */
+        if (msg.m_notify.interrupts & BIT(0)) { /* subscribed interrupt */
+
+          sys_inb(0x64, &scancode);
+          if (scancode & 0x01) {
+            sys_inb(0x60, &scancode);
+          }
+          
+          if(scancode !=0xe0 && flag==0)
+          {
+            //tickdelay(micros_to_ticks(DELAY_US));
+            scan_arr[0] = scancode;
+            kbd_print_scancode(!(scancode & 0x80), 1, scan_arr);
+          }
+
+          else if(scancode==0xe0)
+          {
+            scan_arr[0]=scancode;
+            flag=1;
+          }
+
+          else if(flag==1)
+          {
+            scan_arr[1] = scancode;
+            kbd_print_scancode(!(scancode & 0x80), 2, scan_arr);
+            flag=0;
+          }
+
         }
+        // printf("msg:%x\n",msg.m_notify.interrupts);
+        break;
+      default:
+        // printf("2\n");
+        break; /* no other notifications expected: do nothing */
+      }
     } else {
-     // printf("3\n"); /* received a standard message, not a notification */
-        /* no standard messages expected: do nothing */
+      // printf("3\n"); /* received a standard message, not a notification */
+      /* no standard messages expected: do nothing */
     }
- }
- if(timer_unsubscribe_int()!=0) return 1;
-sys_irqrmpolicy(&hook_id);
+  }
+  if (sys_irqrmpolicy(&hook_id) != 0)
+    return 1;
 
-
   return 0;
 }
 
