Index: lab3/timer_func.c
===================================================================
--- lab3/timer_func.c	(revision 59)
+++ lab3/timer_func.c	(nonexistent)
@@ -1,15 +0,0 @@
-#include "timer_func.h"
-
-#include <lcom/lcf.h>
-#include "i8254.h"
-
-int (subscribe_timer_interrupt)(uint8_t interrupt_bit, int *interrupt_id) {
-    if (interrupt_id == NULL) return 1;
-    *interrupt_id = interrupt_bit;
-    return (sys_irqsetpolicy(TIMER0_IRQ, IRQ_REENABLE, interrupt_id));
-}
-
-int no_interrupts = 0;
-void (timer_int_handler)() {
-    no_interrupts++;
-}

Property changes on: lab3/timer_func.c
___________________________________________________________________
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Index: lab3/timer_func.h
===================================================================
--- lab3/timer_func.h	(revision 59)
+++ lab3/timer_func.h	(nonexistent)
@@ -1,8 +0,0 @@
-#ifndef TIMER_FUNC_H_INCLUDED
-#define TIMER_FUNC_H_INCLUDED
-
-#include <stdint.h>
-
-int (subscribe_timer_interrupt)(uint8_t interrupt_bit, int *interrupt_id);
-
-#endif //TIMER_FUNC_H_INCLUDED

Property changes on: lab3/timer_func.h
___________________________________________________________________
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Index: lab3/kbc_func.c
===================================================================
--- lab3/kbc_func.c	(revision 59)
+++ lab3/kbc_func.c	(nonexistent)
@@ -1,130 +0,0 @@
-#include "kbc_func.h"
-#include "kbc.h"
-
-#include <lcom/lcf.h>
-
-int (subscribe_kbc_interrupt)(uint8_t interrupt_bit, int *interrupt_id) {
-    if (interrupt_id == NULL) return 1;
-    *interrupt_id = interrupt_bit;
-    return (sys_irqsetpolicy(KBC_IRQ, IRQ_REENABLE | IRQ_EXCLUSIVE, interrupt_id));
-}
-
-int (unsubscribe_interrupt)(int *interrupt_id) {
-    if (interrupt_id == NULL) return 1;
-    return sys_irqrmpolicy(interrupt_id);
-}
-
-uint8_t scancode[2];
-int got_error = 0;
-int done = 1;
-int sz = 1;
-
-void (kbc_ih)(void) {
-
-    if(done) sz = 1;
-    else     sz++;
-
-    uint8_t status = 0;
-    got_error = 0;
-
-    if (util_sys_inb(STATUS_REG, &status)) {
-        got_error = 1;
-        return;
-    }
-
-    if (status & (TIME_OUT_REC | PARITY_ERROR)) {
-        got_error = 1;
-        return;
-    }
-
-    if ((status & OUT_BUF_FUL) == 0 || (status & AUX_MOUSE) != 0) {
-        got_error = 1;
-        return;
-    }
-
-    uint8_t byte = 0;
-
-    if (util_sys_inb(OUTPUT_BUF, &byte)) {
-        got_error = 1;
-        return;
-    }
-
-    scancode[sz-1] = byte;
-    done = !(TWO_BYTE_CODE == byte);
-
-}
-
-int (kbd_poll)(uint8_t bytes[], uint8_t *size){
-    if(bytes == NULL || size == NULL) return 1;
-    uint8_t c;
-    if(kbc_read_byte(&c)) return 1;
-    if(c == TWO_BYTE_CODE){
-        if(kbc_read_byte(&bytes[1])) return 1;
-        bytes[0] = c;
-        *size = 2;
-    }else{
-        bytes[1] = 0;
-        bytes[0] = c;
-        *size = 1;
-    }
-    return 0;
-}
-
-int (kbc_read_cmd)(uint8_t *cmd){
-    if(kbc_issue_cmd(READ_KBC_CMD)) return 1;
-    if(kbc_read_byte(cmd)) return 1;
-    return 0;
-}
-
-int (kbc_change_cmd)(uint8_t cmd){
-    if(kbc_issue_cmd(WRITE_KBC_CMD)) return 1;
-    if(kbc_issue_arg(cmd)) return 1;
-    return 0;
-}
-
-int (kbc_restore_kbd)(){
-    uint8_t cmd = 0;
-    if(kbc_read_cmd(&cmd)) return 1;
-    cmd = (cmd | INT_KBD) & (~DIS_KBD);
-    if(kbc_change_cmd(cmd)) return 1;
-    return 0;
-}
-
-int (kbc_issue_cmd)(uint8_t cmd){
-    uint8_t stat;
-    for(int i = 0; i < KBC_NUM_TRIES; ++i){
-        if(util_sys_inb(STATUS_REG, &stat)) return 1;
-        if((stat&IN_BUF_FULL) == 0){
-            if(sys_outb(KBC_CMD, cmd)) return 1;
-            return 0;
-        }
-        tickdelay(micros_to_ticks(DELAY));
-    }
-    return 1;
-}
-
-int (kbc_issue_arg)(uint8_t arg){
-    uint8_t stat;
-    for(int i = 0; i < KBC_NUM_TRIES; ++i){
-        if(util_sys_inb(STATUS_REG, &stat)) return 1;
-        if((stat&IN_BUF_FULL) == 0){
-            if(sys_outb(KBC_CMD_ARG, arg)) return 1;
-            return 0;
-        }
-        tickdelay(micros_to_ticks(DELAY));
-    }
-    return 1;
-}
-
-int (kbc_read_byte)(uint8_t *byte){
-    uint8_t stat;
-    while(true){
-        if(util_sys_inb(STATUS_REG, &stat)) return 1;
-        if((stat&OUT_BUF_FUL) && (stat&AUX_MOUSE)==0){
-            if(stat & (PARITY_ERROR | TIME_OUT_REC)) return 1;
-            if(util_sys_inb(OUTPUT_BUF, byte)) return 1;
-            else return 0;
-        }
-        tickdelay(micros_to_ticks(DELAY));
-    }
-}

Property changes on: lab3/kbc_func.c
___________________________________________________________________
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Index: lab3/compile.sh
===================================================================
--- lab3/compile.sh	(revision 59)
+++ lab3/compile.sh	(nonexistent)
@@ -1,3 +0,0 @@
-reset
-make depend
-make

Property changes on: lab3/compile.sh
___________________________________________________________________
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Index: lab3/kbc_func.h
===================================================================
--- lab3/kbc_func.h	(revision 59)
+++ lab3/kbc_func.h	(nonexistent)
@@ -1,87 +0,0 @@
-#ifndef _KBC_FUNC_H_
-#define _KBC_FUNC_H_
-
-#include <stdint.h>
-
-#define GET         0 /* @brief Argument to get counter without incrementing */
-#define INCREMENT   1 /* @brief Argument for incrementing counter */
-
-/**
- * @brief Subscribes KBC Interrupts and disables Minix Default Keyboard IH
- * @param interrupt_bit Bit of Interrupt Vector that will be set when KBC Interrupt is pending
- * @param interrupt_id KBC Interrupt ID to specify the KBC Interrupt in other calls
- * @return Whether operation was sucessful or not
- */
-int (subscribe_kbc_interrupt)(uint8_t interrupt_bit, int *interrupt_id);
-
-/**
- * @brief Unsubcribes Interrupts
- * @param interrupt_id Interrupt ID, value via arguments on subscription of the interrupt_id
- * @see subscribe_kbc_interrupt, subscribe_timer_interrupt
- * @return Whether operation was sucessful or not
- */
-int (unsubscribe_interrupt)(int *interrupt_id);
-
-/**
- * @brief KBC Interrupt Handler
- */
-void (kbc_ih)(void);
-
-/**
- * @brief High-level function that polls keyboard for scancode
- * High-level function that polls keyboard for scancode of up to 2 bytes. If
- * scancode has only 1 byte, the second byte is set to 0x00.
- * @param bytes Array of at least 2 bytes to store scancode
- * @param size Size of scancode in bytes
- * @return 0 if operation was successful, 1 otherwise
- */
-int (kbd_poll)(uint8_t bytes[], uint8_t *size);
-
-/**
- * @brief High-level function that reads the command byte of the KBC
- * @param cmd Pointer to variable where command byte read from KBC will be stored
- * @return 0 if operation was successful, 1 otherwise
- */
-int (kbc_read_cmd)(uint8_t *cmd);
-
-/**
- * @brief High-level function that changes the command byte of the KBC
- * @param cmd New value for command byte of KBC
- * @return 0 if operation was successful, 1 otherwise
- */
-int (kbc_change_cmd)(uint8_t cmd);
-
-/**
- * @brief High-level function that restores KBC to normal state
- * High-level function that restores KBC to normal state, because lcf_start
- * changes the command byte of KBC. If this function is not used, there is a
- * chance that the keyboard and keyboard interrupts remain disabled.
- * @return 1 if operation was successful, 1 otherwise
- */
-int (kbc_restore_kbd)();
-
-/**
- * @brief Low-level function to issue a command to keyboard
- * @param cmd command to be issued
- * @return 0 if operation was successful, 1 otherwise
- */
-int (kbc_issue_cmd)(uint8_t cmd);
-
-/**
- * @brief Low-level function to issue an argument of a command
- * @param cmd argument to be issued
- * @return 0 if operation was successful, 1 otherwise
- */
-int (kbc_issue_arg)(uint8_t arg);
-
-/**
- * @brief Low-level function for reading byte from keyboard
- * Low-level function for reading byte from keyboard. Waits until output buffer
- * is full
- * @param value Pointer to variable where byte read from keyboard will be stored
- * @return 0 if operation was successful, 1 otherwise
- */
-int (kbc_read_byte)(uint8_t *byte);
-
-
-#endif

Property changes on: lab3/kbc_func.h
___________________________________________________________________
Deleted: svn:executable
Index: lab3/Makefile
===================================================================
--- lab3/Makefile	(revision 59)
+++ lab3/Makefile	(revision 60)
@@ -2,7 +2,7 @@
 PROG=lab3
 
 # source code files to be compiled
-SRCS = lab3.c kbc_func.c timer_func.c utils.c
+SRCS = lab3.c kbc.c keyboard.c timer.c utils.c
 
 # additional compilation flags
 # "-Wall -Wextra -Werror -I . -std=c11 -Wno-unused-parameter" are already set
Index: lab3/kbc.c
===================================================================
--- lab3/kbc.c	(nonexistent)
+++ lab3/kbc.c	(revision 60)
@@ -0,0 +1,57 @@
+#include <lcom/lcf.h>
+
+#include "kbc.h"
+
+#include "kbc_macros.h"
+#include "utils.h"
+
+int (unsubscribe_interrupt)(int *interrupt_id) {
+    if (interrupt_id == NULL) return 1;
+    return sys_irqrmpolicy(interrupt_id);
+}
+
+int (kbc_read_cmd)(uint8_t *cmd){
+    if(kbc_issue_cmd(READ_KBC_CMD)) return 1;
+    if(kbc_read_byte(cmd)) return 1;
+    return 0;
+}
+
+int (kbc_change_cmd)(uint8_t cmd){
+    if(kbc_issue_cmd(WRITE_KBC_CMD)) return 1;
+    if(sys_outb(KBC_CMD_ARG, cmd)) return 1;
+    return 0;
+}
+
+int (kbc_restore_keyboard)(){
+    uint8_t cmd = 0;
+    if(kbc_read_cmd(&cmd)) return 1;
+    cmd = (cmd | INT_KBD) & (~DIS_KBD) ;
+    if(kbc_change_cmd(cmd)) return 1;
+    return 0;
+}
+
+int (kbc_issue_cmd)(uint8_t cmd){
+    uint8_t stat;
+    for(int i = 0; i < KBC_NUM_TRIES; ++i){
+        if(util_sys_inb(STATUS_REG, &stat)) return 1;
+        if((stat&IN_BUF_FULL) == 0){
+            if(sys_outb(KBC_CMD, cmd)) return 1;
+            return 0;
+        }
+        tickdelay(micros_to_ticks(DELAY));
+    }
+    return 1;
+}
+
+int (kbc_read_byte)(uint8_t *byte){
+    uint8_t stat;
+    while(true){
+        if(util_sys_inb(STATUS_REG, &stat)) return 1;
+        if((stat&OUT_BUF_FUL) && (stat&AUX_MOUSE)==0){
+            if(stat & (PARITY_ERROR | TIME_OUT_REC)) return 1;
+            if(util_sys_inb(OUTPUT_BUF, byte)) return 1;
+            else return 0;
+        }
+        tickdelay(micros_to_ticks(DELAY));
+    }
+}

Property changes on: lab3/kbc.c
___________________________________________________________________
Added: svn:executable
Index: lab3/kbc.h
===================================================================
--- lab3/kbc.h	(revision 59)
+++ lab3/kbc.h	(revision 60)
@@ -1,51 +1,57 @@
-#ifndef _KBC_H_
-#define _KBC_H_
+/**
+ * This file concerns everything related to the KBC (KeyBoard Controller, which
+ * actually also manages the mouse)
+ */
 
-/* KBC IRQ Line */
+#ifndef _KBC_FUNC_H_
+#define _KBC_FUNC_H_
 
-#define KBC_IRQ     1 /* @brief KBC Controller IRQ Line */
+/**
+ * @brief Unsubcribes Interrupts
+ * @param interrupt_id Interrupt ID, value via arguments on subscription of the interrupt_id
+ * @see subscribe_kbc_interrupt, subscribe_timer_interrupt
+ * @return Whether operation was sucessful or not
+ */
+int (unsubscribe_interrupt)(int *interrupt_id);
 
-/* Delay for KBC */
-#define DELAY           20000 /* @brief KBC Response Delay */
-#define KBC_NUM_TRIES   10    /* @brief Number of tries to issue command before timeout */
+/**
+ * @brief High-level function that reads the command byte of the KBC
+ * @param cmd Pointer to variable where command byte read from KBC will be stored
+ * @return 0 if operation was successful, 1 otherwise
+ */
+int (kbc_read_cmd)(uint8_t *cmd);
 
-/* I/O Ports Addresses */
+/**
+ * @brief High-level function that changes the command byte of the KBC
+ * @param cmd New value for command byte of KBC
+ * @return 0 if operation was successful, 1 otherwise
+ */
+int (kbc_change_cmd)(uint8_t cmd);
 
-#define KBC_CMD     0x64 /* @brief Address to send commands to KBC */
-#define KBC_CMD_ARG 0x60 /* @brief Address to write KBC Command Arguments */
-#define STATUS_REG  0x64 /* @brief KBC Status Register address */
+/**
+ * @brief High-level function that restores KBC to normal state
+ * High-level function that restores KBC to normal state, because lcf_start
+ * changes the command byte of KBC. If this function is not used, there is a
+ * chance that the keyboard and keyboard interrupts remain disabled.
+ * @return 1 if operation was successful, 1 otherwise
+ */
+int (kbc_restore_keyboard)();
 
-#define OUTPUT_BUF  0x60 /* @brief Address of Output Buffer of KBC */
+/**
+ * @brief Low-level function to issue a command to keyboard
+ * @param cmd command to be issued
+ * @return 0 if operation was successful, 1 otherwise
+ */
+int (kbc_issue_cmd)(uint8_t cmd);
 
-/* KBC Commands */
-#define READ_KBC_CMD    0x20 /* @brief Read KBC Command Byte */
-#define WRITE_KBC_CMD   0x60 /* @brief Write KBC Command Byte */
-#define KBC_SELF_TEST   0xAA /* @brief KBC Diagnostic Tests */
-#define KBC_INT_TEST    0xAB /* @brief Tests Keyboard Clock and Data lines */
-#define KBC_INT_DISABLE 0xAD /* @brief Disable KBC Interface */
-#define KBC_INT_ENABLE  0xAE /* @brief Enable KBC Interface */
+/**
+ * @brief Low-level function for reading byte from keyboard
+ * Low-level function for reading byte from keyboard. Waits until output buffer
+ * is full
+ * @param value Pointer to variable where byte read from keyboard will be stored
+ * @return 0 if operation was successful, 1 otherwise
+ */
+int (kbc_read_byte)(uint8_t *byte);
 
-/* Status Byte Masking */
 
-#define OUT_BUF_FUL     BIT(0) /* @brief Output Buffer State */
-#define IN_BUF_FULL     BIT(1) /* @brief Input Buffer State */
-#define SYS_FLAG        BIT(2) /* @brief System Flag */
-#define DATA_CMD_WRITE  BIT(3) /* @brief Identifier of type of byte in input buffer */
-#define INH_FLAG        BIT(4) /* @brief Keyboard inihibited */
-#define AUX_MOUSE       BIT(5) /* @brief Mouse Data */
-#define TIME_OUT_REC    BIT(6) /* @brief Time Out Error - Invalid Data */
-#define PARITY_ERROR    BIT(7) /* @brief Parity Error - Invalid Data */
-
-/* Scancode Constants */
-
-#define ESC_BREAK_CODE  0x81    /* @brief ESC Break Code */
-#define TWO_BYTE_CODE   0xE0    /* @brief First byte of a two byte Scancode */
-#define BREAK_CODE_BIT  BIT(7)  /* @brief Bit to distinguish between Make code and Break code */
-
-/* Command byte masks */
-#define INT_KBD         BIT(0)
-#define INT_MOU         BIT(1)
-#define DIS_KBD         BIT(4)
-#define DIS_MOU         BIT(5)
-
 #endif
Index: lab3/kbc_macros.h
===================================================================
--- lab3/kbc_macros.h	(nonexistent)
+++ lab3/kbc_macros.h	(revision 60)
@@ -0,0 +1,56 @@
+#ifndef _KBC_H_
+#define _KBC_H_
+
+/* KBC IRQ Line */
+
+#define KBC_IRQ     1   /* @brief KBC Controller IRQ Line */
+#define MOUSE_IRQ   12  /* @brief Mouse IRQ Line */
+
+/* Delay for KBC */
+#define DELAY           20000 /* @brief KBC Response Delay */
+#define KBC_NUM_TRIES   10    /* @brief Number of tries to issue command before timeout */
+
+/* I/O Ports Addresses */
+
+#define KBC_CMD     0x64 /* @brief Address to send commands to KBC */
+#define KBC_CMD_ARG 0x60 /* @brief Address to write KBC Command Arguments */
+#define STATUS_REG  0x64 /* @brief KBC Status Register address */
+
+#define OUTPUT_BUF  0x60 /* @brief Address of Output Buffer of KBC */
+
+/* KBC Commands */
+#define READ_KBC_CMD    0x20 /* @brief Read KBC Command Byte */
+#define WRITE_KBC_CMD   0x60 /* @brief Write KBC Command Byte */
+#define KBC_SELF_TEST   0xAA /* @brief KBC Diagnostic Tests */
+#define KBC_INT_TEST    0xAB /* @brief Tests Keyboard Clock and Data lines */
+#define KBC_INT_DISABLE 0xAD /* @brief Disable KBC Interface */
+#define KBC_INT_ENABLE  0xAE /* @brief Enable KBC Interface */
+#define MOUSE_DISABLE   0xA7 /* @brief Disable Mouse */
+#define MOUSE_ENABLE    0xA8 /* @brief Enable Mouse */
+#define MOUSE_INT_TEST  0xA9 /* @brief Tests Mouse data line */
+#define MOUSE_WRITE_B   0xD4 /* @brief Write a byte directly to the mouse */
+
+/* Status Byte Masking */
+
+#define OUT_BUF_FUL     BIT(0) /* @brief Output Buffer State */
+#define IN_BUF_FULL     BIT(1) /* @brief Input Buffer State */
+#define SYS_FLAG        BIT(2) /* @brief System Flag */
+#define DATA_CMD_WRITE  BIT(3) /* @brief Identifier of type of byte in input buffer */
+#define INH_FLAG        BIT(4) /* @brief Keyboard inihibited */
+#define AUX_MOUSE       BIT(5) /* @brief Mouse Data */
+#define TIME_OUT_REC    BIT(6) /* @brief Time Out Error - Invalid Data */
+#define PARITY_ERROR    BIT(7) /* @brief Parity Error - Invalid Data */
+
+/* Scancode Constants */
+
+#define ESC_BREAK_CODE  0x81    /* @brief ESC Break Code */
+#define TWO_BYTE_CODE   0xE0    /* @brief First byte of a two byte Scancode */
+#define BREAK_CODE_BIT  BIT(7)  /* @brief Bit to distinguish between Make code and Break code */
+
+/* Command byte masks */
+#define INT_KBD         BIT(0)  /* @brief Enable Keyboard Interrupts */
+#define INT_MOU         BIT(1)  /* @brief Enable Mouse Interrupts */
+#define DIS_KBD         BIT(4)  /* @brief Disable Keyboard */
+#define DIS_MOU         BIT(5)  /* @brief Disable Mouse */
+
+#endif

Property changes on: lab3/kbc_macros.h
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: lab3/keyboard.c
===================================================================
--- lab3/keyboard.c	(nonexistent)
+++ lab3/keyboard.c	(revision 60)
@@ -0,0 +1,63 @@
+#include <lcom/lcf.h>
+
+#include "keyboard.h"
+
+#include "kbc.h"
+#include "kbc_macros.h"
+#include "utils.h"
+
+int (subscribe_keyboard_interrupt)(uint8_t interrupt_bit, int *interrupt_id) {
+    if (interrupt_id == NULL) return 1;
+    *interrupt_id = interrupt_bit;
+    return (sys_irqsetpolicy(KBC_IRQ, IRQ_REENABLE | IRQ_EXCLUSIVE, interrupt_id));
+}
+
+int got_error_keyboard = 0;
+int two_byte_scancode = 0;
+
+void (kbc_ih)(void) {
+    uint8_t status = 0;
+    got_error_keyboard = 0;
+
+    if (util_sys_inb(STATUS_REG, &status)) {
+        got_error_keyboard = 1;
+        return;
+    }
+
+    if (status & (TIME_OUT_REC | PARITY_ERROR)) {
+        got_error_keyboard = 1;
+        return;
+    }
+
+    uint8_t byte = 0;
+
+    if (util_sys_inb(OUTPUT_BUF, &byte)) {
+        got_error_keyboard = 1;
+        return;
+    }
+
+    if (two_byte_scancode) {
+        scancode[1] = byte;
+        two_byte_scancode = 0;
+    } else {
+        scancode[0] = byte;
+        two_byte_scancode = (byte == TWO_BYTE_CODE);
+    }
+
+}
+
+int (keyboard_poll)(uint8_t bytes[], uint8_t *size){
+    if(bytes == NULL || size == NULL) return 1;
+    uint8_t c;
+    if(kbc_read_byte(&c)) return 1;
+    if(c == TWO_BYTE_CODE){
+        if(kbc_read_byte(&bytes[1])) return 1;
+        bytes[0] = c;
+        *size = 2;
+    }else{
+        bytes[1] = 0;
+        bytes[0] = c;
+        *size = 1;
+    }
+    return 0;
+}

Property changes on: lab3/keyboard.c
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: lab3/keyboard.h
===================================================================
--- lab3/keyboard.h	(nonexistent)
+++ lab3/keyboard.h	(revision 60)
@@ -0,0 +1,35 @@
+/**
+ * This file concerns everything related to the keyboard
+ */
+
+#ifndef KEYBOARD_H_INCLUDED
+#define KEYBOARD_H_INCLUDED
+
+/**
+ * @brief Subscribes KBC Interrupts and disables Minix Default Keyboard IH
+ * @param interrupt_bit Bit of Interrupt Vector that will be set when KBC Interrupt is pending
+ * @param interrupt_id KBC Interrupt ID to specify the KBC Interrupt in other calls
+ * @return Whether operation was sucessful or not
+ */
+int (subscribe_keyboard_interrupt)(uint8_t interrupt_bit, int *interrupt_id);
+
+uint8_t scancode[2];
+int two_byte_scancode;
+int got_error_keyboard;
+
+/**
+ * @brief KBC Interrupt Handler
+ */
+void (kbc_ih)(void);
+
+/**
+ * @brief High-level function that polls keyboard for scancode
+ * High-level function that polls keyboard for scancode of up to 2 bytes. If
+ * scancode has only 1 byte, the second byte is set to 0x00.
+ * @param bytes Array of at least 2 bytes to store scancode
+ * @param size Size of scancode in bytes
+ * @return 0 if operation was successful, 1 otherwise
+ */
+int (keyboard_poll)(uint8_t bytes[], uint8_t *size);
+
+#endif //KEYBOARD_H_INCLUDED

Property changes on: lab3/keyboard.h
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: lab3/lab3.c
===================================================================
--- lab3/lab3.c	(revision 59)
+++ lab3/lab3.c	(revision 60)
@@ -5,8 +5,10 @@
 #include <stdint.h>
 
 #include "kbc.h"
-#include "kbc_func.h"
-#include "timer_func.h"
+#include "kbc_macros.h"
+#include "keyboard.h"
+#include "timer.h"
+#include "utils.h"
 
 int main(int argc, char *argv[]) {
   // sets the language of LCF messages (can be either EN-US or PT-PT)
@@ -32,12 +34,6 @@
   return 0;
 }
 
-extern uint8_t scancode[2];
-extern int sz;
-extern int done;
-extern int got_error;
-extern uint32_t sys_inb_counter;
-
 int(kbd_test_scan)() {
     /// loop stuff
     int ipc_status, r;
@@ -46,7 +42,7 @@
     uint8_t kbc_irq_bit = 1;
     int kbc_id = 0;
     int kbc_irq = BIT(kbc_irq_bit);
-    if (subscribe_kbc_interrupt(kbc_irq_bit, &kbc_id)) return 1;
+    if (subscribe_keyboard_interrupt(kbc_irq_bit, &kbc_id)) return 1;
     /// cycle
     int good = 1;
     while (good) {
@@ -60,9 +56,12 @@
                 case HARDWARE: /* hardware interrupt notification */
                     if (msg.m_notify.interrupts & kbc_irq) { /* subscribed interrupt */
                         kbc_ih();
+                        if (!(two_byte_scancode || got_error_keyboard)) { /* finished processing a scancode */
+                            if (scancode[0] == TWO_BYTE_CODE) kbd_print_scancode(!(scancode[1] & BREAK_CODE_BIT), 2, scancode);
+                            else                              kbd_print_scancode(!(scancode[0] & BREAK_CODE_BIT), 1, scancode);
+                        } else { break; }
                         if(done)
                             kbd_print_scancode(!(scancode[sz-1] & BREAK_CODE_BIT), sz, scancode);
-
                         if (scancode[0] == ESC_BREAK_CODE) good = 0;
                     }
                     break;
@@ -84,11 +83,11 @@
 int(kbd_test_poll)() {
     uint8_t c[2]; uint8_t size;
     do{
-        if(kbd_poll(c, &size)) return 1;
+        if(keyboard_poll(c, &size)) return 1;
         if(kbd_print_scancode((~c[size-1])&BREAK_CODE_BIT, size, c)) return 1;
     }while(!(size == 1 && c[0] == ESC_BREAK_CODE));
 
-    if(kbc_restore_kbd()) return 1;
+    if(kbc_restore_keyboard()) return 1;
 
     if(kbd_print_no_sysinb(sys_inb_counter)) return 1;
 
@@ -95,8 +94,6 @@
     return 0;
 }
 
-extern int no_interrupts;
-
 int(kbd_test_timed_scan)(uint8_t idle) {
     /// loop stuff
     int ipc_status, r;
@@ -114,7 +111,7 @@
     uint8_t kbc_irq_bit = 1;
     int kbc_id = 0;
     int kbc_irq = BIT(kbc_irq_bit);
-    if(subscribe_kbc_interrupt(kbc_irq_bit, &kbc_id)) return 1;
+    if(subscribe_keyboard_interrupt(kbc_irq_bit, &kbc_id)) return 1;
     /// cycle
     int good = 1;
     while (good) {
@@ -134,6 +131,10 @@
                     }
                     if (msg.m_notify.interrupts & kbc_irq) { /// subscribed interrupt
                         kbc_ih();
+
+                        if (!(two_byte_scancode || got_error_keyboard)) { /// finished processing a scancode
+                            if (scancode[0] == TWO_BYTE_CODE) kbd_print_scancode(!(scancode[1] & BREAK_CODE_BIT), 2, scancode);
+                            else                              kbd_print_scancode(!(scancode[0] & BREAK_CODE_BIT), 1, scancode);
                         if(done) {
                             kbd_print_scancode(!(scancode[sz-1] & BREAK_CODE_BIT), sz, scancode);
                             time = 0;
Index: lab3/timer.c
===================================================================
--- lab3/timer.c	(nonexistent)
+++ lab3/timer.c	(revision 60)
@@ -0,0 +1,16 @@
+#include <lcom/lcf.h>
+
+#include "timer.h"
+
+#include "i8254.h"
+
+int (subscribe_timer_interrupt)(uint8_t interrupt_bit, int *interrupt_id) {
+    if (interrupt_id == NULL) return 1;
+    *interrupt_id = interrupt_bit;
+    return (sys_irqsetpolicy(TIMER0_IRQ, IRQ_REENABLE, interrupt_id));
+}
+
+int no_interrupts = 0;
+void (timer_int_handler)() {
+    no_interrupts++;
+}

Property changes on: lab3/timer.c
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: lab3/timer.h
===================================================================
--- lab3/timer.h	(nonexistent)
+++ lab3/timer.h	(revision 60)
@@ -0,0 +1,14 @@
+/**
+ * This file concerns everything related to the timer
+ */
+
+#ifndef TIMER_H_INCLUDED
+#define TIMER_H_INCLUDED
+
+#include <stdint.h>
+
+int (subscribe_timer_interrupt)(uint8_t interrupt_bit, int *interrupt_id);
+
+int no_interrupts;
+
+#endif //TIMER_H_INCLUDED

Property changes on: lab3/timer.h
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: lab3/utils.h
===================================================================
--- lab3/utils.h	(nonexistent)
+++ lab3/utils.h	(revision 60)
@@ -0,0 +1,10 @@
+#ifndef UTILS_H_INCLUDED
+#define UTILS_H_INCLUDED
+
+#ifdef LAB3
+    uint32_t sys_inb_counter;
+#endif
+
+int (util_sys_inb)(int port, uint8_t *value);
+
+#endif //UTILS_H_INCLUDED

Property changes on: lab3/utils.h
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
