Index: proj/libs/peripherals/include/uart.h
===================================================================
--- proj/libs/peripherals/include/uart.h	(revision 283)
+++ proj/libs/peripherals/include/uart.h	(nonexistent)
@@ -1,64 +0,0 @@
-#ifndef UART_H_INCLUDED
-#define UART_H_INCLUDED
-
-#define COM1_ADDR           0x3F8
-#define COM2_ADDR           0x2F8
-#define COM1_IRQ            4
-#define COM2_IRQ            3
-#define COM1_VECTOR         0x0C
-#define COM2_VECTOR         0x0B
-
-typedef enum {
-    uart_parity_none = 0x0,
-    uart_parity_odd  = 0x1,
-    uart_parity_even = 0x3,
-    uart_parity_par1 = 0x5,
-    uart_parity_par0 = 0x7
-} uart_parity;
-
-typedef struct {
-    int     base_addr               ;
-    uint8_t lcr                     ;
-    uint8_t dll                     ;
-    uint8_t dlm                     ;
-    uint8_t bits_per_char           ;
-    uint8_t stop_bits               ;
-    uart_parity parity              ;
-    uint8_t break_control         :1;
-    uint8_t dlab                  :1;
-    uint16_t divisor_latch          ;
-    uint8_t ier                     ;
-    uint8_t received_data_int     :1;
-    uint8_t transmitter_empty_int :1;
-    uint8_t receiver_line_stat_int:1;
-    uint8_t modem_stat_int        :1;
-} uart_config;
-
-int (subscribe_uart_interrupt)(uint8_t interrupt_bit, int *interrupt_id);
-
-int uart_get_config(int base_addr, uart_config *config);
-void uart_print_config(uart_config config);
-
-int uart_set_bits_per_character(int base_addr, uint8_t     bits_per_char);
-int uart_set_stop_bits         (int base_addr, uint8_t     stop         );
-int uart_set_parity            (int base_addr, uart_parity par          );
-int uart_set_bit_rate          (int base_addr, float       bit_rate     );
-
-int uart_enable_int_rx (int base_addr);
-int uart_disable_int_rx(int base_addr);
-int uart_enable_int_tx (int base_addr);
-int uart_disable_int_tx(int base_addr);
-
-/// NCTP - Non-critical transmission protocol
-int nctp_init(void);
-int nctp_free(void);
-
-int nctp_send(size_t num, uint8_t* ptr[], size_t sz[]);
-
-int nctp_ih_err;
-void nctp_ih(void);
-
-/// HLTP - High-level transmission protocol
-int hltp_send_string(const char *p);
-
-#endif //UART_H_INCLUDED

Property changes on: proj/libs/peripherals/include/uart.h
___________________________________________________________________
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Index: proj/libs/peripherals/include/kbc.h
===================================================================
--- proj/libs/peripherals/include/kbc.h	(revision 283)
+++ proj/libs/peripherals/include/kbc.h	(nonexistent)
@@ -1,107 +0,0 @@
-/**
- * This file concerns everything related to the KBC (KeyBoard Controller, which
- * actually also manages the mouse)
- */
-
-#ifndef KBC_H_INCLUDED
-#define KBC_H_INCLUDED
-
-/* 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   20    /* @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 */
-
-/**
- * @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 0 if operation was successful, 1 otherwise
- */
-int (kbc_restore_keyboard)();
-
-/**
- * @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 //KBC_H_INCLUDED

Property changes on: proj/libs/peripherals/include/kbc.h
___________________________________________________________________
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Index: proj/libs/peripherals/include/timer.h
===================================================================
--- proj/libs/peripherals/include/timer.h	(revision 283)
+++ proj/libs/peripherals/include/timer.h	(nonexistent)
@@ -1,14 +0,0 @@
-/**
- * This file concerns everything related to the timer
- */
-
-#ifndef TIMER_H_INCLUDED
-#define TIMER_H_INCLUDED
-
-#define TIMER0_IRQ     0                                                                /**< @brief Timer 0 IRQ line */
-
-int (subscribe_timer_interrupt)(uint8_t interrupt_bit, int *interrupt_id);
-
-uint32_t no_interrupts;
-
-#endif //TIMER_H_INCLUDED

Property changes on: proj/libs/peripherals/include/timer.h
___________________________________________________________________
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Index: proj/libs/peripherals/include/keyboard.h
===================================================================
--- proj/libs/peripherals/include/keyboard.h	(revision 283)
+++ proj/libs/peripherals/include/keyboard.h	(nonexistent)
@@ -1,28 +0,0 @@
-/**
- * This file concerns everything related to the keyboard
- */
-
-#ifndef KEYBOARD_H_INCLUDED
-#define KEYBOARD_H_INCLUDED
-
-#include "kbc.h"
-
-/**
- * @brief Subscribes Keyboard Interrupts and disables Minix Default IH
- * @param interrupt_bit Bit of Interrupt Vector that will be set when Keyboard Interrupt is pending
- * @param interrupt_id Keyboard Interrupt ID to specify the Keyboard Interrupt in other calls
- * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
- * @see {_ERRORS_H_::errors}
- */
-int (subscribe_kbc_interrupt)(uint8_t interrupt_bit, int *interrupt_id);
-
-uint8_t scancode[2];
-int done;
-int sz;
-int got_error_keyboard;
-
-void (kbc_ih)(void);
-
-int (keyboard_poll)(uint8_t bytes[], uint8_t *size);
-
-#endif //KEYBOARD_H_INCLUDED

Property changes on: proj/libs/peripherals/include/keyboard.h
___________________________________________________________________
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Index: proj/libs/peripherals/include/graph.h
===================================================================
--- proj/libs/peripherals/include/graph.h	(revision 283)
+++ proj/libs/peripherals/include/graph.h	(nonexistent)
@@ -1,53 +0,0 @@
-#ifndef GRAPH_H_INCLUDED
-#define GRAPH_H_INCLUDED
-
-// Graphics modes
-#define INDEXED_1024_768        0x105
-#define DIRECT_640_480_888      0x110
-#define DIRECT_800_600_888      0x115
-#define DIRECT_1024_768_888     0x118
-#define DIRECT_1280_1024_565    0x11A
-#define DIRECT_1280_1024_888    0x11B
-#define LINEAR_FRAME_BUFFER_MD  BIT(14)
-
-// Colors in RBG (8 bit)
-#define GRAPH_BLACK               0x000000
-#define GRAPH_WHITE               0xFFFFFF
-
-// Alpha
-#define ALPHA_THRESHOLD     0x7F
-
-/// MACROS
-#define GET_ALP(n)          (0xFF & ((n) >> 24))
-#define GET_RED(n)          (0xFF & ((n) >> 16))
-#define GET_GRE(n)          (0xFF & ((n) >>  8))
-#define GET_BLU(n)          (0xFF & (n      ))
-#define GET_COLOR(n)        (0xFFFFFF & (n))
-#define SET_ALP(n)          (((n)&0xFF) << 24)
-#define SET_RED(n)          (((n)&0xFF) << 16)
-#define SET_GRE(n)          (((n)&0xFF) <<  8)
-#define SET_BLU(n)          (((n)&0xFF)      )
-#define SET_RGB(r,g,b)      (SET_RED(r) | SET_GRE(g) | SET_BLU(b))
-
-/// PUBLIC GET
-uint16_t   (graph_get_XRes)         (void);
-uint16_t   (graph_get_YRes)         (void);
-uint16_t   (graph_get_bytes_pixel)  (void);
-
-/// INIT
-int (graph_init)(uint16_t mode);
-
-/// CLEANUP
-int (graph_cleanup)(void);
-
-/// PIXEL DRAWING
-int (graph_set_pixel)             (uint16_t x, uint16_t y, uint32_t color);
-void (graph_set_pixel_pos)         (unsigned pos          , uint32_t color);
-
-/// SCREEN
-int (graph_clear_screen)(void);
-
-/// DRAW
-int (graph_draw)(void);
-
-#endif /* end of include guard: GRAPH_H_INCLUDED */

Property changes on: proj/libs/peripherals/include/graph.h
___________________________________________________________________
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Index: proj/libs/peripherals/include/mouse.h
===================================================================
--- proj/libs/peripherals/include/mouse.h	(revision 283)
+++ proj/libs/peripherals/include/mouse.h	(nonexistent)
@@ -1,89 +0,0 @@
-#ifndef MOUSE_H_INCLUDED
-#define MOUSE_H_INCLUDED
-
-/**
- * @brief Subscribes Mouse Interrupts and disables Minix Default IH
- * @param interrupt_bit Bit of Interrupt Vector that will be set when Mouse Interrupt is pending
- * @param interrupt_id Mouse Interrupt ID to specify the Mouse Interrupt in other calls
- * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
- * @see {_ERRORS_H_::errors}
- */
-int (subscribe_mouse_interrupt)(uint8_t interrupt_bit, int *interrupt_id);
-
-//These have to do with mouse_ih
-int got_error_mouse_ih;
-uint8_t packet_mouse_ih[3];
-int counter_mouse_ih;
-
-/**
- * @brief   Parse 3 bytes and returns it as a parsed, struct packet.
- * @param   packet_bytes    array of bytes to parse
- * @param   pp              Pointer to packet to store the information.
- */
-void (mouse_parse_packet)(const uint8_t *packet_bytes, struct packet *pp);
-
-/**
- * @brief Polls mouse for data. Blocks execution until a valid mouse packet is obtained.
- * @param   pp      pointer to packet struct in which the result will be stored
- * @param   period  time (in milliseconds) the poller should wait between pollings of bytes
- * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
- */
-int mouse_poll(struct packet *pp, uint16_t period);
-
-/**
- * @brief Sets data report mode for mouse
- * @param   on  zero to disable data report, any other value to enable data report
- * @return  ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
- */
-int (mouse_set_data_report)(int on);
-
-/**
- * @brief Reads data byte from mouse
- * <summary>
- * Polls the mouse till data is available for reading
- * </summary>
- * @param data Pointer to variable where byte read from mouse will be stored
- * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
- * @see {_ERRORS_H_::errors}
- */
-int (mouse_read_data)(uint8_t *data, uint16_t period);
-
-/**
- * @brief Issues command to mouse
- * <summary>
- * Issues command to mouse, returns error after two consecutive errors reported by the acknowledgment byte
- * </summary>
- * @param cmd Command to be issued
- * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
- * @see {_ERRORS_H_::errors}
- */
-int (mouse_issue_cmd)(uint32_t cmd);
-
-/**
- * @brief Reads byte from mouse
- * <summary>
- * Reads byte from mouse, giving error if exceeds number of tries to read
- * </summary>
- * @param byte Pointer to variable where byte read from mouse will be stored
- * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
- * @see {_ERRORS_H_::errors}
- */
-int (mouse_read_byte)(uint8_t *byte);
-
-/**
- * @brief Polls OUT_BUF for byte coming from mouse.
- * @param   byte    pointer to byte read from OUT_BUF
- * @param   period  time (in milliseconds) the poller should wait between pollings of bytes
- * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
- */
-int (mouse_poll_byte)(uint8_t *byte, uint16_t period);
-
-/**
- * @brief Converts 9-bit number to 16-bit with sign extension
- * @param sign_bit  Sign bit identifiying the signal of the number
- * @param byte      Least significant byte that will be extended
- * @return Extended 9-bit number
- */
-int16_t (sign_extend_byte)(uint8_t sign_bit, uint8_t byte);
-
-#endif //MOUSE_H_INCLUDED

Property changes on: proj/libs/peripherals/include/mouse.h
___________________________________________________________________
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Index: proj/libs/peripherals/include/rtc.h
===================================================================
--- proj/libs/peripherals/include/rtc.h	(revision 283)
+++ proj/libs/peripherals/include/rtc.h	(nonexistent)
@@ -1,46 +0,0 @@
-#ifndef RTC_H_INCLUDED
-#define RTC_H_INCLUDED
-
-#include <stdint.h>
-
-/**
- * @brief Subscribes RTC Interrupts
- * @param interrupt_bit Bit of Interrupt Vector that will be set when RTC Interrupt is pending
- * @param interrupt_id RTC Interrupt ID to specify the RTC Interrupt in other calls
- * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
- * @see {_ERRORS_H_::errors}
- */
-int (subscribe_rtc_interrupt)(uint8_t interrupt_bit, int *interrupt_id);
-
-int (rtc_read_register)(uint32_t reg, uint8_t *data);
-
-int (rtc_write_register)(uint32_t reg, uint8_t data);
-
-/**
- * @brief Checks if there's an update in progress.
- * @return  The value of the flag UIP, or ERROR_CODE if error occurs.
- */
-int (rtc_check_update)(void);
-
-/**
- * @brief Enables/Disables updates of time/date registers.
- * @param   on  zero to disable, any other value to enable
- * @return  ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
- */
-int (rtc_set_updates)(int on);
-
-/**
- * @brief Reads time from RTC.
- * @param   time  Pointer to array of 3 bytes to store the information about time (hours, minutes, seconds)
- * @return  ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
- */
-int (rtc_read_time)(uint8_t *time);
-
-/**
- * @brief Reads date from RTC.
- * @param   date  Pointer to array of 4 bytes to store the information about date (year, month, day, weekday)
- * @return  ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
- */
-int (rtc_read_date)(uint8_t *date);
-
-#endif /* end of include guard: RTC_H_INCLUDED */

Property changes on: proj/libs/peripherals/include/rtc.h
___________________________________________________________________
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Index: proj/libs/peripherals/src/kbc.c
===================================================================
--- proj/libs/peripherals/src/kbc.c	(revision 283)
+++ proj/libs/peripherals/src/kbc.c	(nonexistent)
@@ -1,73 +0,0 @@
-#include <lcom/lcf.h>
-
-#include "kbc.h"
-
-#include "utils.h"
-#include "errors.h"
-
-int (kbc_read_cmd)(uint8_t *cmd){
-    int ret = 0;
-    if((ret = kbc_issue_cmd(READ_KBC_CMD))) return ret;
-    if((ret = kbc_read_byte(cmd))) return ret;
-    return SUCCESS;
-}
-
-int (kbc_change_cmd)(uint8_t cmd){
-    int ret = 0;
-    if((ret = kbc_issue_cmd(WRITE_KBC_CMD))) return ret;
-    if((ret = kbc_issue_arg(cmd))) return ret;
-    return SUCCESS;
-}
-
-int (kbc_restore_kbd)(){
-    int ret = 0;
-    uint8_t cmd = 0;
-    if((ret = kbc_read_cmd(&cmd))) return ret;
-    cmd = (cmd | INT_KBD) & (~DIS_KBD);
-    if((ret = kbc_change_cmd(cmd))) return ret;
-    return SUCCESS;
-}
-
-int (kbc_issue_cmd)(uint8_t cmd){
-    int ret = 0;
-    uint8_t stat;
-    for(int i = 0; i < KBC_NUM_TRIES; ++i){
-        if((ret = util_sys_inb(STATUS_REG, &stat))) return ret;
-        if((stat&IN_BUF_FULL) == 0){
-            if(sys_outb(KBC_CMD, cmd)) return WRITE_ERROR;
-            return SUCCESS;
-        }
-        tickdelay(micros_to_ticks(DELAY));
-    }
-    return TIMEOUT_ERROR;
-}
-
-int (kbc_issue_arg)(uint8_t arg){
-    int ret = 0;
-    uint8_t stat;
-    for(int i = 0; i < KBC_NUM_TRIES; ++i){
-        if((ret = util_sys_inb(STATUS_REG, &stat))) return ret;
-        if((stat&IN_BUF_FULL) == 0){
-            if(sys_outb(KBC_CMD_ARG, arg)) return WRITE_ERROR;
-            return SUCCESS;
-        }
-        tickdelay(micros_to_ticks(DELAY));
-    }
-    return TIMEOUT_ERROR;
-}
-
-int (kbc_read_byte)(uint8_t *byte){
-    int ret = 0;
-    uint8_t stat;
-    for(int i = 0; i < KBC_NUM_TRIES; ++i){
-        if((ret = util_sys_inb(STATUS_REG, &stat))) return ret;
-        if((stat&OUT_BUF_FUL) && (stat&AUX_MOUSE)==0){
-            if(stat & (PARITY_ERROR | TIME_OUT_REC)) return OTHER_ERROR;
-            if((ret = util_sys_inb(OUTPUT_BUF, byte))) return ret;
-            else return SUCCESS;
-        }
-        tickdelay(micros_to_ticks(DELAY));
-    }
-    printf("Timing out\n");
-    return TIMEOUT_ERROR;
-}

Property changes on: proj/libs/peripherals/src/kbc.c
___________________________________________________________________
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Index: proj/libs/peripherals/src/keyboard.c
===================================================================
--- proj/libs/peripherals/src/keyboard.c	(revision 283)
+++ proj/libs/peripherals/src/keyboard.c	(nonexistent)
@@ -1,60 +0,0 @@
-#include <lcom/lcf.h>
-
-#include "keyboard.h"
-
-#include "kbc.h"
-#include "utils.h"
-#include "errors.h"
-#include "proj_func.h"
-
-int (subscribe_kbc_interrupt)(uint8_t interrupt_bit, int *interrupt_id) {
-    if (interrupt_id == NULL) return NULL_PTR;
-    *interrupt_id = interrupt_bit;
-    if(sys_irqsetpolicy(KBC_IRQ, IRQ_REENABLE | IRQ_EXCLUSIVE, interrupt_id)) return SBCR_ERROR;
-    return SUCCESS;
-}
-
-int done = 1;
-int sz = 1;
-int got_error_keyboard = SUCCESS;
-
-void (kbc_ih)(void) {
-    if(done) { sz = 1; }
-    else     sz++;
-    uint8_t status = 0;
-    got_error_keyboard = SUCCESS;
-    if ((got_error_keyboard = util_sys_inb(STATUS_REG, &status))) return;
-    if (status & (TIME_OUT_REC | PARITY_ERROR)) {
-        got_error_keyboard = 1;
-        return;
-    }
-    if ((status & OUT_BUF_FUL) == 0 || (status & AUX_MOUSE) != 0) {
-        got_error_keyboard = READ_ERROR;
-        return;
-    }
-    uint8_t byte = 0;
-    if ((got_error_keyboard = util_sys_inb(OUTPUT_BUF, &byte))) return;
-
-    scancode[sz-1] = byte;
-    done = !(TWO_BYTE_CODE == byte);
-
-    if (done) update_key_presses();
-
-}
-
-int (keyboard_poll)(uint8_t bytes[], uint8_t *size){
-    int ret = 0;
-    if(bytes == NULL || size == NULL) return NULL_PTR;
-    uint8_t c;
-    if((ret = kbc_read_byte(&c))) return ret;
-    if(c == TWO_BYTE_CODE){
-        if((ret = kbc_read_byte(&bytes[1]))) return ret;
-        bytes[0] = c;
-        *size = 2;
-    }else{
-        bytes[1] = 0;
-        bytes[0] = c;
-        *size = 1;
-    }
-    return SUCCESS;
-}

Property changes on: proj/libs/peripherals/src/keyboard.c
___________________________________________________________________
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Index: proj/libs/peripherals/src/timer.c
===================================================================
--- proj/libs/peripherals/src/timer.c	(revision 283)
+++ proj/libs/peripherals/src/timer.c	(nonexistent)
@@ -1,66 +0,0 @@
-#include <lcom/lcf.h>
-
-#include "timer.h"
-#include "graph.h"
-#include "sprite.h"
-
-#define TIMER_FREQ     1193182                                                          /**< @brief clock frequency for timer in PC and AT */
-#define TIMER_MIN_FREQ (TIMER_FREQ/UINT16_MAX) + ((TIMER_FREQ % UINT16_MAX) ? 1 : 0)    /**< @brief mininum frequency for timer */
-
-/* I/O port addresses */
-
-#define TIMER_0    0x40         /**< @brief Timer 0 count register */
-#define TIMER_1    0x41         /**< @brief Timer 1 count register */
-#define TIMER_2    0x42         /**< @brief Timer 2 count register */
-#define TIMER_CTRL 0x43         /**< @brief Control register */
-
-#define SPEAKER_CTRL 0x61       /**< @brief Register for speaker control  */
-
-/* Timer control */
-
-/* Timer selection: bits 7 and 6 */
-
-#define TIMER_SEL0   0x00              /**< @brief Control Word for Timer 0 */
-#define TIMER_SEL1   BIT(6)            /**< @brief Control Word for Timer 1 */
-#define TIMER_SEL2   BIT(7)            /**< @brief Control Word for Timer 2 */
-#define TIMER_RB_CMD (BIT(7) | BIT(6)) /**< @brief Read Back Command */
-
-/* Register selection: bits 5 and 4 */
-
-#define TIMER_LSB     BIT(4)                    /**< @brief Initialize Counter LSB only */
-#define TIMER_MSB     BIT(5)                    /**< @brief Initialize Counter MSB only */
-#define TIMER_LSB_MSB (TIMER_LSB | TIMER_MSB)   /**< @brief Initialize LSB first and MSB afterwards */
-#define TIMER_INMODE_MASK 0x30                  /**< @brief Mask for Timer Counter Mode */
-#define TIMER_INMODE_POS  4                     /**< @brief Bit position of Timer Counter Mode */
-
-/* Operating mode: bits 3, 2 and 1 */
-
-#define TIMER_SQR_WAVE (BIT(2) | BIT(1)) /**< @brief Mode 3: square wave generator */
-#define TIMER_RATE_GEN BIT(2)            /**< @brief Mode 2: rate generator */
-#define TIMER_MODE_MASK 0x0E             /**< @brief Mask for mode */
-#define TIMER_MODE_POS  1                /**< @brief Position of smallest bit from mode */
-#define TIMER_MODE_2ALT 0x6              /**< @brief Alternative notation for mode 2 */
-#define TIMER_MODE_3ALT 0x7              /**< @brief Alternative notation for mode 3 */
-#define TIMER_MODE_RED2 0x03             /**< @brief Reduce 3-bit mode to 2-bit mode */
-
-/* Counting mode: bit 0 */
-
-#define TIMER_BCD 0x01 /**< @brief Count in BCD */
-#define TIMER_BIN 0x00 /**< @brief Count in binary */
-
-/* READ-BACK COMMAND FORMAT */
-
-#define TIMER_RB_COUNT_  BIT(5)         /**< @brief Read counter value on read-back (0 to activate) */
-#define TIMER_RB_STATUS_ BIT(4)         /**< @brief Read status value on read-back (0 to activate) */
-#define TIMER_RB_SEL(n)  BIT((n) + 1)   /**< @brief Select timer to read information from */
-
-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));
-}
-
-uint32_t no_interrupts = 0;
-void (timer_int_handler)() {
-    no_interrupts++;
-}

Property changes on: proj/libs/peripherals/src/timer.c
___________________________________________________________________
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Index: proj/libs/peripherals/src/graph.c
===================================================================
--- proj/libs/peripherals/src/graph.c	(revision 283)
+++ proj/libs/peripherals/src/graph.c	(nonexistent)
@@ -1,432 +0,0 @@
-#include <lcom/lcf.h>
-
-#include "graph.h"
-
-#include "errors.h"
-#include <stdio.h>
-
-#define VC_BIOS_SERV  0x10 /** @brief Interrupt service of video card */
-#define VBE_CALL      0x4F /** @brief VBE call function specifier */
-
-#define MBYTE_BASE  0x0         /** @brief Base address (zero address) */
-#define MBYTE_SIZE  0xFFFFF     /** @brief Size of a mebibyte */
-
-// Graphics Functions
-#define VBE_CTRL_INFO       0x00    /** @brief Get VBE Controller Information */
-#define VBE_MD_INFO         0x01    /** @brief Get VBE Mode Information */
-#define SET_VBE_MD          0x02    /** @brief Set VBE Mode */
-
-// Error codes (AH)
-#define AH_SUCCESS          0x00    /** @brief Success code on BIOS call */
-#define AH_FUNC_CALL_FAIL   0x01    /** @brief Function call failed */
-#define AH_FUNC_NOT_SUPP    0x02    /** @brief Function call is not supported in current HW configuration */
-#define AH_FUNC_INVALID     0x03    /** @brief Invalid function in current video mode */
-
-/// MACROS
-#define FAR2PHYS(n)         ((((n)>>12) & 0xFFFFFFF0) + ((n) & 0x0000FFFF))
-
-/// STRUCT
-typedef struct __attribute__((packed)) {
-
-    char        VbeSignature[4]     ;
-    uint16_t    VbeVersion          ;
-    uint32_t    OemStringPtr        ;
-    uint8_t     Capabilities[4]     ;
-    uint32_t    VideoModePtr        ;
-    uint16_t    TotalMemory         ;
-
-    uint16_t    OemSoftwareRev      ;
-    uint32_t    OemVendorNamePtr    ;
-    uint32_t    OemProductNamePtr   ;
-    uint32_t    OemProductRevPtr    ;
-    char        Reserved[222]       ;
-
-    char        OemData[256]        ;
-} VbeInfoBlock;
-
-static vbe_mode_info_t vbe_mem_info;
-
-/// PRIVATE GET
-static uint16_t   (graph_get_bits_pixel)   (void){ return vbe_mem_info.BitsPerPixel; }
-static phys_bytes (graph_get_phys_addr)    (void){ return vbe_mem_info.PhysBasePtr; }
-static unsigned   (graph_get_vram_size)    (void){ return vbe_mem_info.XResolution * vbe_mem_info.YResolution * graph_get_bytes_pixel(); }
-//static uint16_t   (graph_get_RedMaskSize)  (void){ return vbe_mem_info.RedMaskSize  ; }
-//static uint16_t   (graph_get_GreenMaskSize)(void){ return vbe_mem_info.GreenMaskSize; }
-//static uint16_t   (graph_get_BlueMaskSize) (void){ return vbe_mem_info.BlueMaskSize ; }
-
-/// PUBLIC GET
-uint16_t   (graph_get_XRes)         (void){ return vbe_mem_info.XResolution; }
-uint16_t   (graph_get_YRes)         (void){ return vbe_mem_info.YResolution; }
-uint16_t   (graph_get_bytes_pixel)  (void){ return (graph_get_bits_pixel() + 7) >> 3; }
-
-///
-static int (get_permission)(unsigned int base_addr, unsigned int size) {
-    struct minix_mem_range mmr;
-    mmr.mr_base = base_addr;
-    mmr.mr_limit = base_addr + size;
-    return sys_privctl(SELF, SYS_PRIV_ADD_MEM, &mmr);
-}
-
-//static int (get_permissions_first_mbyte)(void) {
-//    return get_permission(MBYTE_BASE, MBYTE_SIZE);
-//}
-
-/// MEMORY
-static uint8_t *video_mem = NULL; /** @brief Frame-buffer VM address. */
-static uint8_t *video_buf = NULL; /** @brief Primary buffer for drawing before copying to video_mem. */
-static mmap_t mem_map;
-static int (graph_free_memory)(void) {
-    int r = SUCCESS;
-    free(video_buf); video_buf = NULL;
-    r = !lm_free(&mem_map);
-    return r;
-}
-static int (graph_map_vram)(void) {
-    int r;
-    const unsigned vram_base = graph_get_phys_addr();
-    const unsigned vram_size = graph_get_vram_size();
-    if ((r = get_permission(vram_base, vram_size))) {
-        if (graph_free_memory()) {
-            printf("%s: lm_free failed\n", __func__);
-        }
-        panic("%s: sys_privctl (ADD MEM) failed: %d\n", __func__, r);
-    }
-
-    video_mem = vm_map_phys(SELF, (void *)vram_base, vram_size);
-
-    if (video_mem == MAP_FAILED) {
-        if (graph_free_memory()) {
-            printf("%s: lm_free failed\n", __func__);
-        }
-        panic("%s: couldn't map video memory.", __func__);
-    }
-
-    video_buf = malloc(vram_size);
-
-    return SUCCESS;
-}
-
-/// INFO GET
-static int (vbe_get_mode_information)(uint16_t mode) {
-    memset(&vbe_mem_info, 0, sizeof(vbe_mode_info_t)); // reset values
-
-    struct reg86 reg_86;
-    memset(&reg_86, 0, sizeof(struct reg86)); // reset struct
-
-    vbe_mode_info_t *virtual_addr = lm_alloc(sizeof(vbe_mode_info_t), &mem_map);
-
-    reg_86.intno = VC_BIOS_SERV;
-    reg_86.ah = VBE_CALL;
-    reg_86.al = VBE_MD_INFO;
-    reg_86.cx = mode;
-    reg_86.es = PB2BASE(mem_map.phys);
-    reg_86.di = PB2OFF(mem_map.phys);
-    // BIOS CALL
-    if (sys_int86(&reg_86) || reg_86.ah != AH_SUCCESS) {
-        printf("%s: sys_int86 failed\n", __func__);
-        if (graph_free_memory()) {
-            printf("%s: lm_free failed\n", __func__);
-        }
-        return BIOS_CALL_ERROR;
-    }
-
-    memcpy((void*)&vbe_mem_info, (void*)virtual_addr, mem_map.size);
-    return SUCCESS;
-}
-/*
-static int (vbe_get_controller_information)(vg_vbe_contr_info_t *info_p) {
-    memset(info_p, 0, sizeof(vg_vbe_contr_info_t)); // reset values
-
-    mmap_t controller_map;
-
-    struct reg86 reg_86;
-    memset(&reg_86, 0, sizeof(struct reg86)); // reset struct
-
-    VbeInfoBlock *virtual_addr = lm_alloc(sizeof(VbeInfoBlock), &controller_map);
-
-    uint32_t virtual_base = (uint32_t)(virtual_addr) - controller_map.phys;
-
-    virtual_addr->VbeSignature[0] = 'V';
-    virtual_addr->VbeSignature[1] = 'B';
-    virtual_addr->VbeSignature[2] = 'E';
-    virtual_addr->VbeSignature[3] = '2';
-
-
-    reg_86.intno = VC_BIOS_SERV;
-    reg_86.ah = VBE_CALL;
-    reg_86.al = VBE_CTRL_INFO;
-    reg_86.es = PB2BASE(controller_map.phys);
-    reg_86.di = PB2OFF(controller_map.phys);
-    // BIOS CALL
-    if (sys_int86(&reg_86) || reg_86.ah != AH_SUCCESS) {
-        printf("%s: sys_int86 failed\n", __func__);
-        if (!lm_free(&controller_map)) {
-            printf("%s: lm_free failed\n", __func__);
-        }
-        return BIOS_CALL_ERROR;
-    }
-
-    info_p->VBESignature[0] = virtual_addr->VbeSignature[0];
-    info_p->VBESignature[1] = virtual_addr->VbeSignature[1];
-    info_p->VBESignature[2] = virtual_addr->VbeSignature[2];
-    info_p->VBESignature[3] = virtual_addr->VbeSignature[3];
-
-    uint8_t lsb, msb;
-    util_get_LSB(virtual_addr->VbeVersion, &lsb);
-    util_get_MSB(virtual_addr->VbeVersion, &msb);
-    info_p->VBEVersion[0] = lsb;
-    info_p->VBEVersion[1] = msb;
-
-    info_p->TotalMemory = (virtual_addr->TotalMemory << 6);
-
-    // Convert Far Far Pointer to Virtual Address
-
-    uint32_t phys_ptr = FAR2PHYS(virtual_addr->OemStringPtr);
-    uint32_t virtual_ptr = phys_ptr + virtual_base;
-    info_p->OEMString = (char*)(virtual_ptr);
-
-    phys_ptr = FAR2PHYS(virtual_addr->VideoModePtr);
-    virtual_ptr = phys_ptr + virtual_base;
-    info_p->VideoModeList = (uint16_t*)(virtual_ptr);
-
-    phys_ptr = FAR2PHYS(virtual_addr->OemVendorNamePtr);
-    virtual_ptr = phys_ptr + virtual_base;
-    info_p->OEMVendorNamePtr = (char*)(virtual_ptr);
-
-    phys_ptr = FAR2PHYS(virtual_addr->OemProductNamePtr);
-    virtual_ptr = phys_ptr + virtual_base;
-    info_p->OEMProductNamePtr = (char*)(virtual_ptr);
-
-    phys_ptr = FAR2PHYS(virtual_addr->OemProductRevPtr);
-    virtual_ptr = phys_ptr + virtual_base;
-    info_p->OEMProductRevPtr = (char*)(virtual_ptr);
-
-    if (!lm_free(&controller_map)) {
-        printf("%s: lm_free failed\n", __func__);
-        return LCF_ERROR;
-    }
-
-    return SUCCESS;
-}
-*/
-
-/// INIT
-/**
- * @brief
- * @param mode
- * @return
- */
-static int (graph_set_mode)(uint16_t mode) {
-    struct reg86 reg_86;
-
-    memset(&reg_86, 0, sizeof(struct reg86)); // reset struct
-
-    // Set Reg86
-    reg_86.intno = VC_BIOS_SERV;
-    reg_86.ah = VBE_CALL;
-    reg_86.al = SET_VBE_MD;
-    reg_86.bx = mode | LINEAR_FRAME_BUFFER_MD;
-
-    // BIOS CALL
-    if (sys_int86(&reg_86) || reg_86.ah != AH_SUCCESS) {
-        printf("%s: sys_int86 failed\n", __func__);
-        return BIOS_CALL_ERROR;
-    }
-
-    return SUCCESS;
-}
-int (graph_init)(uint16_t mode){
-    if (vbe_get_mode_information(mode)) {
-        printf("%s: failed to get information for mode %x.\n", __func__, mode);
-        return 1;
-    }
-
-    graph_map_vram(); // if function fails it aborts program
-
-    if (graph_set_mode(mode)) {
-        printf("%s: failed to set graphic mode %x.\n", __func__, mode);
-        return 1;
-    };
-    return SUCCESS;
-}
-
-/// CLEANUP
-int (graph_cleanup)(void){
-    int r = SUCCESS;
-    if ((r = vg_exit()))
-        printf("%s: vg_exit failed to exit to text mode.\n", __func__);
-    if ((r = graph_free_memory()))
-        printf("%s: lm_free failed\n", __func__);
-    return r;
-}
-
-/// PIXEL DRAWING
-int (graph_set_pixel)(uint16_t x, uint16_t y, uint32_t color) {
-    //pixels are certain to be inside can reduce lag
-    /*if (x < 0 || vbe_mem_info.XResolution <= x || y < 0 || vbe_mem_info.YResolution <= y) {
-        //printf("%s: invalid pixel.\n", __func__);
-        return OUT_OF_RANGE;
-    }*/
-    unsigned int pos = (x + y * vbe_mem_info.XResolution) * 3/*graph_get_bytes_pixel()*/;
-    memcpy(video_buf + pos, &color, 3/*graph_get_bytes_pixel()*/);
-    return SUCCESS;
-}
-void (graph_set_pixel_pos)(unsigned pos, uint32_t color){
-    memcpy(video_buf + pos, &color, graph_get_bytes_pixel());
-}
-int (graph_clear_screen)(void){ memset(video_buf, 0, graph_get_vram_size()); return SUCCESS; }
-int (graph_draw)(void){ memcpy(video_mem, video_buf, graph_get_vram_size()); return SUCCESS; }
-
-///SPRITE
-#include "sprite.h"
-
-#include "utils.h"
-#include "fast_math.h"
-#include <math.h>
-
-struct basic_sprite{
-    uint8_t *map;
-    uint16_t w, h;
-    int16_t u0, v0;
-};
-basic_sprite_t* (basic_sprite_ctor)(const char **xpm, int16_t u0, int16_t v0){
-    basic_sprite_t *ret = malloc(sizeof(basic_sprite_t));
-    if(ret == NULL) return NULL;
-    enum xpm_image_type type = XPM_8_8_8_8;
-    xpm_image_t img;
-    ret->map = xpm_load((xpm_map_t)xpm, type, &img);
-    if(ret->map == NULL){
-        basic_sprite_dtor(ret);
-        return NULL;
-    }
-    ret->w = img.width;
-    ret->h = img.height;
-    ret->u0 = u0;
-    ret->v0 = v0;
-    return ret;
-}
-void (basic_sprite_dtor)(basic_sprite_t *p){
-    if(p == NULL) return;
-    free(p->map);
-    free(p);
-}
-const uint8_t* (basic_sprite_get_map)(const basic_sprite_t *p){ return p->map; }
-uint16_t       (basic_sprite_get_w)  (const basic_sprite_t *p){ return p->w  ; }
-uint16_t       (basic_sprite_get_h)  (const basic_sprite_t *p){ return p->h  ; }
-int16_t        (basic_sprite_get_u0) (const basic_sprite_t *p){ return p->u0 ; }
-int16_t        (basic_sprite_get_v0) (const basic_sprite_t *p){ return p->v0 ; }
-
-/*
-struct basic_sprite_alpha{
-    uint8_t *map;
-    uint16_t w, h;
-    int16_t u0, v0;
-};
-basic_sprite_alpha_t* (basic_sprite_alpha_ctor)(const char **xpm, int16_t u0, int16_t v0){
-    basic_sprite_alpha_t *ret = malloc(sizeof(basic_sprite_t));
-    if(ret == NULL) return NULL;
-    enum xpm_image_type type = XPM_8_8_8_8;
-    xpm_image_t img;
-    ret->map = NULL;
-    uint8_t *m = xpm_load((xpm_map_t)xpm, type, &img);
-    if(m == NULL){
-        basic_sprite_alpha_dtor(ret);
-        return NULL;
-    }
-    ret->map = m;
-    if(ret->map == NULL){
-        basic_sprite_alpha_dtor(ret);
-        return NULL;
-    }
-    ret->w = img.width;
-    ret->h = img.height;
-    ret->u0 = u0;
-    ret->v0 = v0;
-    return ret;
-}
-void (basic_sprite_alpha_dtor)(basic_sprite_alpha_t *p){
-    if(p == NULL) return;
-    free(p->map);
-    free(p);
-}
-const uint8_t* (basic_sprite_alpha_get_map)(const basic_sprite_alpha_t *p){ return p->map; }
-uint16_t       (basic_sprite_alpha_get_w)  (const basic_sprite_alpha_t *p){ return p->w  ; }
-uint16_t       (basic_sprite_alpha_get_h)  (const basic_sprite_alpha_t *p){ return p->h  ; }
-int16_t        (basic_sprite_alpha_get_u0) (const basic_sprite_alpha_t *p){ return p->u0 ; }
-int16_t        (basic_sprite_alpha_get_v0) (const basic_sprite_alpha_t *p){ return p->v0 ; }
-*/
-
-struct sprite{
-    const basic_sprite_t *bsp;
-    int16_t x, y; //position in screen
-    double theta, s, c;
-    double scale;
-};
-sprite_t* (sprite_ctor)(const basic_sprite_t *bsp){
-    sprite_t *ret = malloc(sizeof(sprite_t));
-    if(ret == NULL) return NULL;
-    ret->bsp = bsp;
-    ret->x = 0;
-    ret->y = 0;
-    sprite_set_angle(ret, 0.0);
-    ret->scale = 1.0;
-    return ret;
-}
-void (sprite_dtor)(sprite_t *p){
-    if(p == NULL) return;
-    free(p);
-}
-void (sprite_set_pos)   (sprite_t *p, int16_t x , int16_t y ){ p->x = x; p->y = y; }
-void (sprite_set_angle) (sprite_t *p, double angle          ){ p->theta = angle; p->c = fm_cos(p->theta); p->s = fm_sin(p->theta); }
-void (sprite_set_scale) (sprite_t *p, double scale          ){ p->scale = scale; }
-int16_t  (sprite_get_x)(const sprite_t *p){ return p->x; }
-int16_t  (sprite_get_y)(const sprite_t *p){ return p->y; }
-double   (sprite_get_angle)(const sprite_t *p){ return p->theta; }
-uint16_t (sprite_get_w)(const sprite_t *p){ return basic_sprite_get_w(p->bsp); }
-uint16_t (sprite_get_h)(const sprite_t *p){ return basic_sprite_get_h(p->bsp); }
-void (sprite_src2pic)(const sprite_t *p, int16_t x, int16_t y, int16_t *u, int16_t *v){
-    double dx = (x - p->x)/p->scale;
-    double dy = (y - p->y)/p->scale;
-    int16_t du = dx*p->c - dy*p->s - 0.5;
-    int16_t dv = dx*p->s + dy*p->c - 0.5;
-    *u = du + basic_sprite_get_u0(p->bsp);
-    *v = dv + basic_sprite_get_v0(p->bsp);
-}
-void (sprite_pic2src)(const sprite_t *p, int16_t u, int16_t v, int16_t *x, int16_t *y){
-    int16_t du = u - basic_sprite_get_u0(p->bsp);
-    int16_t dv = v - basic_sprite_get_v0(p->bsp);
-    double dx =  du*p->c + dv*p->s;
-    double dy = -du*p->s + dv*p->c;
-    *x = dx*p->scale + 0.5 + p->x;
-    *y = dy*p->scale + 0.5 + p->y;
-}
-void (sprite_draw)(const sprite_t *p){
-    const uint16_t w = basic_sprite_get_w(p->bsp);
-    const uint16_t h = basic_sprite_get_h(p->bsp);
-    int16_t xmin, xmax, ymin, ymax; {
-        int16_t x, y;
-        sprite_pic2src(p, 0, 0, &x, &y);
-        xmin = x; xmax = x; ymin = y; ymax = y;
-        sprite_pic2src(p, w, 0, &x, &y);
-        xmin = min(x, xmin); xmax = max(x, xmax); ymin = min(y, ymin); ymax = max(y, ymax);
-        sprite_pic2src(p, 0, h, &x, &y);
-        xmin = min(x, xmin); xmax = max(x, xmax); ymin = min(y, ymin); ymax = max(y, ymax);
-        sprite_pic2src(p, w, h, &x, &y);
-        xmin = min(x, xmin); xmax = max(x, xmax); ymin = min(y, ymin); ymax = max(y, ymax);
-        xmin = max(xmin-(int16_t)p->scale-2, 0); xmax = min(xmax+(int16_t)p->scale+2, graph_get_XRes());
-        ymin = max(ymin-(int16_t)p->scale-2, 0); ymax = min(ymax+(int16_t)p->scale+2, graph_get_YRes());
-    }
-    const uint8_t *map = basic_sprite_get_map(p->bsp);
-    const uint16_t bytes_pixel = 3/*graph_get_bytes_pixel()*/;
-    for(int16_t u, v, y = ymin; y < ymax; ++y){
-        uint8_t *place = video_buf + (xmin + y*graph_get_XRes())*bytes_pixel;
-        for(int16_t x = xmin; x < xmax; ++x, place += bytes_pixel){
-            sprite_src2pic(p, x, y, &u, &v);
-            if(0 <= u && u < w && 0 <= v && v < h){
-                const uint8_t *c_p = map+(v*w+u)*4;
-                if(*(c_p+3) < ALPHA_THRESHOLD) //alpha
-                    memcpy(place, c_p, bytes_pixel);
-            }
-        }
-    }
-}

Property changes on: proj/libs/peripherals/src/graph.c
___________________________________________________________________
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Index: proj/libs/peripherals/src/rtc.c
===================================================================
--- proj/libs/peripherals/src/rtc.c	(revision 283)
+++ proj/libs/peripherals/src/rtc.c	(nonexistent)
@@ -1,159 +0,0 @@
-#include <lcom/lcf.h>
-
-#include "rtc.h"
-
-#include "utils.h"
-#include "errors.h"
-
-// RTC IRQ Line
-
-#define KBC_IRQ   8  /* @brief KBC IRQ Line */
-
-// RTC Ports
-
-#define RTC_ADDR_REG        0x70
-#define RTC_DATA_REG        0x71
-
-// RTC Registers (Byte)
-
-#define RTC_SEC             0
-#define RTC_SEC_ALARM       1
-#define RTC_MIN             2
-#define RTC_MIN_ALARM       3
-#define RTC_HOUR            4
-#define RTC_HOUR_ALARM      5
-#define RTC_WEEK_DAY        6
-#define RTC_MONTH_DAY       7
-#define RTC_MONTH           8
-#define RTC_YEAR            9
-#define RTC_REG_A           10
-#define RTC_REG_B           11
-#define RTC_REG_C           12
-#define RTC_REG_D           13
-
-// Register A
-
-#define RS0     BIT(0)  /** @brief Rate selector */
-#define RS1     BIT(1)  /** @brief Rate selector */
-#define RS2     BIT(2)  /** @brief Rate selector */
-#define RS3     BIT(3)  /** @brief Rate selector */
-#define UIP     BIT(7)  /** @brief Update in progress */
-
-// Register B
-
-#define DSE             BIT(0)  /** @brief Enable Daylight Saving Time */
-#define HOUR_FORM       BIT(1)  /** @brief Set to 1 for 24h format (0-23), 0 to 12h format (1-12) */
-#define DM              BIT(2)  /** @brief Set to 1 if registers are in binary, 0 if in BCD */
-#define SQWE            BIT(3)  /** @brief Enable square wave generation */
-#define UIE             BIT(4)  /** @brief Enable Update interrupts */
-#define AIE             BIT(5)  /** @brief Enable alarm interrupts */
-#define PIE             BIT(6)  /** @brief Enable periodic interrupts */
-#define SET             BIT(7)  /** @brief Set to 1 to inhibit updates of time/date registers */
-
-// Register C
-
-#define UF      BIT(4)  /** @brief Update Interrupt Pending */
-#define AF      BIT(5)  /** @brief Alarm Interrupt Pending */
-#define PF      BIT(6)  /** @brief Periodic Interrupt Pending */
-#define IRQF    BIT(7)  /** @brief IRQ Line Active */
-
-// Register D
-
-#define VRT     BIT(7)  /** @brief Valid RAM/time - If set to 0 RTC reading aren't valid */
-
-int (subscribe_rtc_interrupt)(uint8_t interrupt_bit, int *interrupt_id) {
-    if (interrupt_id == NULL) return NULL_PTR;
-    *interrupt_id = interrupt_bit;
-    if (sys_irqsetpolicy(KBC_IRQ, IRQ_REENABLE | IRQ_EXCLUSIVE, interrupt_id)) return SBCR_ERROR;
-    return SUCCESS;
-}
-
-int (rtc_read_register)(uint32_t reg, uint8_t *data) {
-    if (sys_outb(RTC_ADDR_REG, reg)) return WRITE_ERROR;
-
-    if (util_sys_inb(RTC_DATA_REG, data)) return READ_ERROR;
-
-    return SUCCESS;
-}
-
-int (rtc_write_register)(uint32_t reg, uint8_t data) {
-    if (sys_outb(RTC_ADDR_REG, reg)) return WRITE_ERROR;
-
-    if (sys_outb(RTC_DATA_REG, data)) return WRITE_ERROR;
-
-    return SUCCESS;
-}
-
-int (rtc_check_update)(void) {
-    uint8_t data;
-    int r;
-
-    if ((r = rtc_read_register(RTC_REG_A, &data))) return r;
-
-    return (data & UIP) != 0;
-}
-
-int (rtc_set_updates)(int on) {
-    uint8_t data;
-    int r;
-    if (on) {
-        if ((r = rtc_read_register(RTC_REG_B, &data))) return r;
-
-        data &= ~SET;
-
-        if ((r = rtc_write_register(RTC_REG_B, data))) return r;
-
-    } else {
-        while (rtc_check_update());
-
-        if ((r = rtc_read_register(RTC_REG_B, &data))) return r;
-
-        data |= SET;
-
-        if ((r = rtc_write_register(RTC_REG_B, data))) return r;
-    }
-    return SUCCESS;
-}
-
-int (rtc_read_time)(uint8_t *time) {
-
-    int r;
-    //if ((r = rtc_set_updates(false))) return r;
-    while (rtc_check_update());
-
-    uint8_t hour, min, sec;
-
-    if ((r = rtc_read_register(RTC_SEC, &sec)))    return r;
-    if ((r = rtc_read_register(RTC_MIN, &min)))    return r;
-    if ((r = rtc_read_register(RTC_HOUR, &hour)))  return r;
-
-    //if ((r = rtc_set_updates(true))) return r;
-
-    time[0] = BCD_FIRST(sec)*10   + BCD_SECOND(sec);
-    time[1] = BCD_FIRST(min)*10   + BCD_SECOND(min);
-    time[2] = BCD_FIRST(hour)*10  + BCD_SECOND(hour);
-
-    return SUCCESS;
-}
-
-int (rtc_read_date)(uint8_t *date) {
-    int r;
-    //if ((r = rtc_set_updates(false))) return r;
-    while (rtc_check_update());
-
-    uint8_t year, month, day, weekday;
-
-    if ((r = rtc_read_register(RTC_WEEK_DAY,    &weekday)))     return r;
-    if ((r = rtc_read_register(RTC_MONTH_DAY,   &day)))         return r;
-    if ((r = rtc_read_register(RTC_MONTH,       &month)))       return r;
-    if ((r = rtc_read_register(RTC_YEAR,        &year)))        return r;
-
-    //if ((r = rtc_set_updates(true))) return r;
-
-    date[0] = weekday;
-    date[1] = BCD_FIRST(day)*10     + BCD_SECOND(day);
-    date[2] = BCD_FIRST(month)*10   + BCD_SECOND(month);
-    date[3] = BCD_FIRST(year)*10    + BCD_SECOND(year);
-
-    return SUCCESS;
-}

Property changes on: proj/libs/peripherals/src/rtc.c
___________________________________________________________________
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Index: proj/libs/peripherals/src/mouse.c
===================================================================
--- proj/libs/peripherals/src/mouse.c	(revision 283)
+++ proj/libs/peripherals/src/mouse.c	(nonexistent)
@@ -1,162 +0,0 @@
-#include <lcom/lcf.h>
-
-#include "mouse.h"
-
-#include "errors.h"
-#include "kbc.h"
-
-/* Mouse Data Packet */
-// Byte 0 - Button States
-#define LEFT_BUTTON     BIT(0) /* @brief Left button click event*/
-#define RIGHT_BUTTON    BIT(1) /* @brief Right button click event */
-#define MIDDLE_BUTTON   BIT(2) /* @brief Middle button click event */
-#define FIRST_BYTE_ID   BIT(3) /* @brief Identifier of first byte of packet CAREFUL: Not 100% accurate */
-#define MSB_X_DELTA     BIT(4) /* @brief Most significant bit of X delta */
-#define MSB_Y_DELTA     BIT(5) /* @brief Most significant bit of Y delta */
-#define X_OVERFLOW      BIT(6) /* @brief X delta overflowed */
-#define Y_OVERFLOW      BIT(7) /* @brief Y delta overflowed */
-// Byte 1 - X delta
-// Byte 2 - Y delta
-
-/* Mouse Commands */
-#define RESET           0xFF /* @brief Reset mouse */
-#define RESEND          0xFE /* @brief Resend command */
-#define DEFAULT         0xF6 /* @brief Set default values */
-#define DIS_DATA_REP    0xF5 /* @brief Disable Data Reporting */
-#define ENABLE_DATA_REP 0xF4 /* @brief Enable Data Reporting */
-#define SET_SAMPLE_RT   0xF3 /* @brief Sets state sampling rate */
-#define SET_REMOTE_MD   0xF0 /* @brief Sets Mouse on Remote Mode, data on request */
-#define READ_DATA       0xEB /* @brief Sends data packet request */
-#define SET_STREAM_MD   0xEA /* @brief Sets mouse on Stream Mode, data on events */
-#define STATUS_REQUEST  0xE9 /* @brief Get mouse configuration */
-#define SET_RESOLUTION  0xE8 /* @brief Sets resolution for mouse movement */
-#define SCALING_ACC_MD  0xE7 /* @brief Sets scaling on acceleration mode */
-#define SCALING_LIN_MD  0xE6 /* @brief Sets scaling on linear mode */
-
-/* Mouse Controller Responses */
-#define ACK_OK      0xFA /* @brief Operation sucessful */
-#define ACK_INVALID 0xFE /* @brief Invalid Byte, first occurence */
-#define ACK_ERROR   0xFC /* @brief Invalid Byte on resend */
-
-int (subscribe_mouse_interrupt)(uint8_t interrupt_bit, int *interrupt_id) {
-    if (interrupt_id == NULL) return NULL_PTR;
-    *interrupt_id = interrupt_bit;
-    if (sys_irqsetpolicy(MOUSE_IRQ, IRQ_REENABLE | IRQ_EXCLUSIVE, interrupt_id)) return SBCR_ERROR;
-    return SUCCESS;
-}
-
-int got_error_mouse_ih = 0;
-int counter_mouse_ih = 0;
-
-void (mouse_ih)(void) {
-    uint8_t status = 0;
-    got_error_mouse_ih = 0;
-    if(counter_mouse_ih >= 3) counter_mouse_ih = 0;
-
-    if ((got_error_mouse_ih = util_sys_inb(STATUS_REG, &status))) return;
-
-    if (status & (TIME_OUT_REC | PARITY_ERROR)) {
-        got_error_mouse_ih = OTHER_ERROR;
-        return;
-    }
-    if (((status & AUX_MOUSE) == 0) || ((status & OUT_BUF_FUL) == 0)) {
-        got_error_mouse_ih = READ_ERROR;
-        return;
-    }
-
-    uint8_t byte = 0;
-
-    if ((got_error_mouse_ih = util_sys_inb(OUTPUT_BUF, &byte))) return;
-
-    /// This does not run if: I was expecting the first one but what I get is definitely not the first byte
-    if((byte & FIRST_BYTE_ID)  || counter_mouse_ih){
-        packet_mouse_ih[counter_mouse_ih++] = byte;
-    }
-}
-
-void (mouse_parse_packet)(const uint8_t *packet_bytes, struct packet *pp){
-    pp->bytes[0] = packet_bytes[0];
-    pp->bytes[1] = packet_bytes[1];
-    pp->bytes[2] = packet_bytes[2];
-    pp->rb       = pp->bytes[0] & RIGHT_BUTTON;
-    pp->mb       = pp->bytes[0] & MIDDLE_BUTTON;
-    pp->lb       = pp->bytes[0] & LEFT_BUTTON;
-    pp->delta_x  = sign_extend_byte((packet_bytes[0] & MSB_X_DELTA) != 0, pp->bytes[1]);
-    pp->delta_y  = sign_extend_byte((packet_bytes[0] & MSB_Y_DELTA) != 0, pp->bytes[2]);
-    pp->x_ov     = pp->bytes[0] & X_OVERFLOW;
-    pp->y_ov     = pp->bytes[0] & Y_OVERFLOW;
-}
-
-int mouse_poll(struct packet *pp, uint16_t period){
-    int ret = 0;
-
-    uint8_t packet[3];
-    uint8_t byte;
-    if ((ret = mouse_issue_cmd(READ_DATA))) return ret;
-    for(unsigned i = 0; i < 3; ++i){
-        if((ret = mouse_poll_byte(&byte, period))) return ret;
-        packet[i] = byte;
-    }
-    mouse_parse_packet(packet, pp);
-    return SUCCESS;
-}
-
-int (mouse_set_data_report)(int on){
-    if(on) return mouse_issue_cmd(ENABLE_DATA_REP);
-    else   return mouse_issue_cmd(   DIS_DATA_REP);
-}
-
-int (mouse_read_data)(uint8_t *data, uint16_t period) {
-    int ret;
-    if ((ret = mouse_issue_cmd(READ_DATA))) return ret;
-    if ((ret = mouse_poll_byte(data, period))) return ret;
-    return SUCCESS;
-}
-
-int (mouse_issue_cmd)(uint32_t cmd) {
-    int ret;
-    uint8_t ack = 0;
-    for (unsigned int i = 0; i < KBC_NUM_TRIES; i++) {
-        if ((ret = kbc_issue_cmd(MOUSE_WRITE_B))) return ret;
-        if ((ret = kbc_issue_arg(cmd))) return ret;
-        if ((ret = mouse_read_byte(&ack))) return ret;
-
-        if (ack == ACK_OK) return SUCCESS;
-        if (ack == ACK_ERROR) return INVALID_COMMAND;
-        tickdelay(micros_to_ticks(DELAY));
-    }
-    return TIMEOUT_ERROR;
-}
-
-int (mouse_read_byte)(uint8_t *byte) {
-    int ret = 0;
-    uint8_t stat;
-    for(int i = 0; i < KBC_NUM_TRIES; ++i){
-        if((ret = util_sys_inb(STATUS_REG, &stat))) return ret;
-        if((stat&OUT_BUF_FUL) && (stat&AUX_MOUSE)) {
-            if(stat & (PARITY_ERROR | TIME_OUT_REC)) return OTHER_ERROR;
-            if((ret = util_sys_inb(OUTPUT_BUF, byte))) return ret;
-            else return SUCCESS;
-        }
-        tickdelay(micros_to_ticks(DELAY));
-    }
-    return TIMEOUT_ERROR;
-}
-
-int (mouse_poll_byte)(uint8_t *byte, uint16_t period) {
-    int ret = 0;
-    uint8_t stat;
-    while(true){
-        if((ret = util_sys_inb(STATUS_REG, &stat))) return ret;
-        if((stat&OUT_BUF_FUL) && (stat&AUX_MOUSE)) {
-            if(stat & (PARITY_ERROR | TIME_OUT_REC)) return OTHER_ERROR;
-            if((ret = util_sys_inb(OUTPUT_BUF, byte))) return ret;
-            else return SUCCESS;
-        }
-        tickdelay(micros_to_ticks(DELAY));
-    }
-}
-
-int16_t (sign_extend_byte)(uint8_t sign_bit, uint8_t byte) {
-    return (int16_t)(((0xFF * sign_bit)<<8) | byte);
-}

Property changes on: proj/libs/peripherals/src/mouse.c
___________________________________________________________________
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Index: proj/libs/peripherals/src/uart.c
===================================================================
--- proj/libs/peripherals/src/uart.c	(revision 283)
+++ proj/libs/peripherals/src/uart.c	(nonexistent)
@@ -1,379 +0,0 @@
-#include <lcom/lcf.h>
-
-#include "uart.h"
-
-#include "queue.h"
-#include "errors.h"
-
-#define UART_BITRATE                            115200
-#define UART_WAIT                               20 //microseconds
-
-#define UART_RBR                                0
-#define UART_THR                                0
-#define UART_IER                                1
-#define UART_IIR                                2
-#define UART_FCR                                2
-#define UART_LCR                                3
-#define UART_MCR                                4
-#define UART_LSR                                5
-#define UART_MSR                                6
-#define UART_SR                                 7
-
-#define UART_DLL                                0
-#define UART_DLM                                1
-
-/// LCR
-#define UART_BITS_PER_CHAR_POS                  0
-#define UART_STOP_BITS_POS                      2
-#define UART_PARITY_POS                         3
-#define UART_BREAK_CONTROL_POS                  6
-#define UART_DLAB_POS                           7
-
-#define UART_BITS_PER_CHAR                      (BIT(0) | BIT(1))
-#define UART_STOP_BITS                          (BIT(2))
-#define UART_PARITY                             (BIT(3) | BIT(4) | BIT(5))
-#define UART_BREAK_CONTROL                      (BIT(6))
-#define UART_DLAB                               (BIT(7))
-
-#define UART_GET_BITS_PER_CHAR(n)               (((n)&UART_BITS_PER_CHAR) + 5)
-#define UART_GET_STOP_BITS(n)                   (((n)&UART_STOP_BITS)? 2 : 1)
-#define UART_GET_PARITY(n)                      (((n)&UART_PARITY       )>>UART_PARITY_POS       )
-#define UART_GET_BREAK_CONTROL(n)               (((n)&UART_BREAK_CONTROL)>>UART_BREAK_CONTROL_POS)
-#define UART_GET_DLAB(n)                        (((n)&UART_DLAB         )>>UART_DLAB_POS         )
-#define UART_GET_DIV_LATCH(m,l)                 ((m)<<8 | (l))
-#define UART_GET_DLL(n)                         ((n)&0xFF)
-#define UART_GET_DLM(n)                         (((n)>>8)&0xFF)
-
-/// IER
-#define UART_INT_EN_RX_POS                      0
-#define UART_INT_EN_TX_POS                      1
-#define UART_INT_EN_RECEIVER_LINE_STAT_POS      2
-#define UART_INT_EN_MODEM_STAT_POS              3
-
-#define UART_INT_EN_RX                          (BIT(0))
-#define UART_INT_EN_TX                          (BIT(1))
-#define UART_INT_EN_RECEIVER_LINE_STAT          (BIT(2))
-#define UART_INT_EN_MODEM_STAT                  (BIT(3))
-
-#define UART_GET_INT_EN_RX(n)                   (((n)&UART_INT_EN_RX                )>>UART_INT_EN_RX_POS                )
-#define UART_GET_INT_EN_TX(n)                   (((n)&UART_INT_EN_TX                )>>UART_INT_EN_TX_POS                )
-#define UART_GET_INT_EN_RECEIVER_LINE_STAT(n)   (((n)&UART_INT_EN_RECEIVER_LINE_STAT)>>UART_INT_EN_RECEIVER_LINE_STAT_POS)
-#define UART_GET_INT_EN_MODEM_STAT(n)           (((n)&UART_INT_EN_MODEM_STAT        )>>UART_INT_EN_MODEM_STAT_POS        )
-
-/// LSR
-#define UART_RECEIVER_READY_POS                 0
-#define UART_OVERRUN_ERROR_POS                  1
-#define UART_PARITY_ERROR_POS                   2
-#define UART_FRAMING_ERROR_POS                  3
-#define UART_TRANSMITTER_EMPTY_POS              5
-
-#define UART_RECEIVER_READY                     (BIT(0))
-#define UART_OVERRUN_ERROR                      (BIT(1))
-#define UART_PARITY_ERROR                       (BIT(2))
-#define UART_FRAMING_ERROR                      (BIT(3))
-#define UART_TRANSMITTER_EMPTY                  (BIT(5))
-
-#define UART_GET_RECEIVER_READY(n)              (((n)&UART_RECEIVER_READY           )>>UART_RECEIVER_READY_POS           )
-#define UART_GET_OVERRUN_ERROR                  (((n)&UART_OVERRUN_ERROR            )>>UART_OVERRUN_ERROR_POS            )
-#define UART_GET_PARITY_ERROR                   (((n)&UART_PARITY_ERROR             )>>UART_PARITY_ERROR_POS             )
-#define UART_GET_FRAMING_ERROR                  (((n)&UART_FRAMING_ERROR            )>>UART_FRAMING_ERROR_POS            )
-#define UART_GET_TRANSMITTER_EMPTY(n)           (((n)&UART_TRANSMITTER_EMPTY        )>>UART_TRANSMITTER_EMPTY_POS        )
-
-/// IIR
-#define UART_INT_PEND_POS                       1
-
-#define UART_INT_PEND                           (BIT(3)|BIT(2)|BIT(1))
-
-#define UART_GET_IF_INT_PEND(n)                 (!((n)&1))
-typedef enum {
-    uart_int_receiver_line_stat = (         BIT(1) | BIT(0)),
-    uart_int_rx                 = (         BIT(1)         ),
-    uart_int_char_timeout_fifo  = (BIT(2) | BIT(1)         ),
-    uart_int_tx                 = (                  BIT(0)),
-    uart_int_modem_stat         = (0)
-} uart_int_code;
-#define UART_GET_INT_PEND(n)                    ((uart_int_code)(((n)&UART_INT_PEND)>>UART_INT_PEND_POS))
-
-int (subscribe_uart_interrupt)(uint8_t interrupt_bit, int *interrupt_id) {
-    if (interrupt_id == NULL) return 1;
-    *interrupt_id = interrupt_bit;
-    return (sys_irqsetpolicy(COM1_IRQ, IRQ_REENABLE | IRQ_EXCLUSIVE, interrupt_id));
-}
-
-static void uart_parse_config(uart_config *config){
-    /// LCR
-    config->bits_per_char          = UART_GET_BITS_PER_CHAR     (config->lcr);
-    config->stop_bits              = UART_GET_STOP_BITS         (config->lcr);
-    config->parity                 = UART_GET_PARITY            (config->lcr); if((config->parity & BIT(0)) == 0) config->parity = uart_parity_none;
-    config->break_control          = UART_GET_BREAK_CONTROL     (config->lcr);
-    config->dlab                   = UART_GET_DLAB              (config->lcr);
-    /// IER
-    config->received_data_int      = UART_GET_INT_EN_RX                (config->ier);
-    config->transmitter_empty_int  = UART_GET_INT_EN_TX                (config->ier);
-    config->receiver_line_stat_int = UART_GET_INT_EN_RECEIVER_LINE_STAT(config->ier);
-    config->modem_stat_int         = UART_GET_INT_EN_MODEM_STAT        (config->ier);
-    /// DIV LATCH
-    config->divisor_latch          = UART_GET_DIV_LATCH(config->dlm, config->dll);
-}
-
-static int uart_get_lcr(int base_addr, uint8_t *p){
-    return util_sys_inb(base_addr+UART_LCR, p);
-}
-static int uart_set_lcr(int base_addr, uint8_t config){
-    if(sys_outb(base_addr+UART_LCR, config)) return WRITE_ERROR;
-    return SUCCESS;
-}
-static int uart_get_lsr(int base_addr, uint8_t *p){
-    return util_sys_inb(base_addr+UART_LSR, p);
-}
-static int uart_get_iir(int base_addr, uint8_t *p){
-    return util_sys_inb(base_addr+UART_IIR, p);
-}
-
-static int uart_enable_divisor_latch(int base_addr){
-    int ret = SUCCESS;
-    uint8_t conf; if((ret = uart_get_lcr(base_addr, &conf))) return ret;
-    return uart_set_lcr(base_addr, conf | UART_DLAB);
-}
-static int uart_disable_divisor_latch(int base_addr){
-    int ret = SUCCESS;
-    uint8_t conf; if((ret = uart_get_lcr(base_addr, &conf))) return ret;
-    return uart_set_lcr(base_addr, conf & (~UART_DLAB));
-}
-
-static int uart_get_ier(int base_addr, uint8_t *p){
-    int ret;
-    if((ret = uart_disable_divisor_latch(base_addr))) return ret;
-    return util_sys_inb(base_addr+UART_IER, p);
-}
-static int uart_set_ier(int base_addr, uint8_t n){
-    int ret;
-    if((ret = uart_disable_divisor_latch(base_addr))) return ret;
-    if(sys_outb(base_addr+UART_IER, n)) return WRITE_ERROR;
-    return SUCCESS;
-}
-
-int uart_get_config(int base_addr, uart_config *config){
-    int ret = SUCCESS;
-
-    config->base_addr = base_addr;
-
-    if((ret = uart_get_lcr(base_addr, &config->lcr))) return ret;
-
-    if((ret = uart_get_ier(base_addr, &config->ier))) return ret;
-
-    if((ret = uart_enable_divisor_latch (base_addr))) return ret;
-    if((ret = util_sys_inb(base_addr+UART_DLL, &config->dll   ))) return ret;
-    if((ret = util_sys_inb(base_addr+UART_DLM, &config->dlm   ))) return ret;
-    if((ret = uart_disable_divisor_latch(base_addr))) return ret;
-
-    uart_parse_config(config);
-    return ret;
-}
-void uart_print_config(uart_config config){
-
-    printf("%s configuration:\n", (config.base_addr == COM1_ADDR ? "COM1" : "COM2"));
-    printf("\tLCR = 0x%X: %d bits per char\t %d stop bits\t", config.lcr, config.bits_per_char, config.stop_bits);
-    if((config.parity&BIT(0)) == 0) printf("NO parity\n");
-    else switch(config.parity){
-        case uart_parity_odd : printf("ODD parity\n"     ); break;
-        case uart_parity_even: printf("EVEN parity\n"    ); break;
-        case uart_parity_par1: printf("parity bit is 1\n"); break;
-        case uart_parity_par0: printf("parity bit is 0\n"); break;
-        default              : printf("invalid\n"        ); break;
-    }
-    printf("\tDLM = 0x%02X DLL=0x%02X: bitrate = %d bps\n", config.dlm, config.dll, UART_BITRATE/config.divisor_latch);
-    printf("\tIER = 0x%02X: Rx interrupts: %s\tTx interrupts: %s\n", config.ier,
-        (config.received_data_int     ? "ENABLED":"DISABLED"),
-        (config.transmitter_empty_int ? "ENABLED":"DISABLED"));
-}
-
-int uart_set_bits_per_character(int base_addr, uint8_t bits_per_char){
-    if(bits_per_char < 5 || bits_per_char > 8) return INVALID_ARG;
-    int ret = SUCCESS;
-    bits_per_char = (bits_per_char-5)&0x3;
-    uint8_t conf; if((ret = uart_get_lcr(base_addr, &conf))) return ret;
-    conf = (conf & (~UART_BITS_PER_CHAR)) | bits_per_char;
-    return uart_set_lcr(base_addr, conf);
-}
-int uart_set_stop_bits(int base_addr, uint8_t stop){
-    if(stop != 1 && stop != 2) return INVALID_ARG;
-    int ret = SUCCESS;
-    stop -= 1;
-    stop = (stop&1)<<2;
-    uint8_t conf; if((ret = uart_get_lcr(base_addr, &conf))) return ret;
-    conf = (conf & (~UART_STOP_BITS)) | stop;
-    return uart_set_lcr(base_addr, conf);
-}
-int uart_set_parity(int base_addr, uart_parity par){
-    int ret = SUCCESS;
-    uint8_t parity = par << 3;
-    uint8_t conf; if((ret = uart_get_lcr(base_addr, &conf))) return ret;
-    conf = (conf & (~UART_PARITY)) | parity;
-    return uart_set_lcr(base_addr, conf);
-}
-int uart_set_bit_rate(int base_addr, float bit_rate){
-    int ret = SUCCESS;
-    uint16_t latch = UART_BITRATE/bit_rate;
-    uint8_t dll = UART_GET_DLL(latch);
-    uint8_t dlm = UART_GET_DLM(latch);
-    if((ret = uart_enable_divisor_latch(base_addr))) return ret;
-    if(sys_outb(base_addr+UART_DLL, dll)) return WRITE_ERROR;
-    if(sys_outb(base_addr+UART_DLM, dlm)) return WRITE_ERROR;
-    if((ret = uart_disable_divisor_latch(base_addr))) return ret;
-    return SUCCESS;
-}
-
-static int uart_get_char(int base_addr, uint8_t *p){
-    int ret;
-    if((ret = uart_disable_divisor_latch(base_addr))) return ret;
-    return util_sys_inb(base_addr+UART_RBR, p);
-}
-static int uart_send_char(int base_addr, uint8_t c){
-    int ret;
-    if((ret = uart_disable_divisor_latch(base_addr))) return ret;
-    if(sys_outb(base_addr+UART_THR, c)) return WRITE_ERROR;
-    return SUCCESS;
-}
-static int uart_receiver_ready(int base_addr){
-    uint8_t lsr;
-    if(uart_get_lsr(base_addr, &lsr)) return false;
-    return UART_GET_RECEIVER_READY(lsr);
-}
-static int uart_transmitter_empty(int base_addr){
-    uint8_t lsr;
-    if(uart_get_lsr(base_addr, &lsr)) return false;
-    return UART_GET_TRANSMITTER_EMPTY(lsr);
-}
-
-int uart_enable_int_rx(int base_addr){
-    int ret;
-    uint8_t ier;
-    if((ret = uart_get_ier(base_addr, &ier))) return ret;
-    ier |= UART_INT_EN_RX;
-    return uart_set_ier(base_addr, ier);
-}
-int uart_disable_int_rx(int base_addr){
-    int ret;
-    uint8_t ier;
-    if((ret = uart_get_ier(base_addr, &ier))) return ret;
-    ier &= ~UART_INT_EN_RX;
-    return uart_set_ier(base_addr, ier);
-}
-int uart_enable_int_tx(int base_addr){
-    int ret;
-    uint8_t ier;
-    if((ret = uart_get_ier(base_addr, &ier))) return ret;
-    ier |= UART_INT_EN_TX;
-    return uart_set_ier(base_addr, ier);
-}
-int uart_disable_int_tx(int base_addr){
-    int ret;
-    uint8_t ier;
-    if((ret = uart_get_ier(base_addr, &ier))) return ret;
-    ier &= ~UART_INT_EN_TX;
-    return uart_set_ier(base_addr, ier);
-}
-
-/// NCTP
-
-#define NCTP_START      0x80
-#define NCTP_END        0xFF
-#define NCTP_OK         0xFF
-#define NCTP_NOK        0x00
-
-queue_t *out = NULL;
-queue_t *in  = NULL;
-
-int nctp_init(void){
-    out = queue_ctor(); if(out == NULL) return NULL_PTR;
-    in  = queue_ctor(); if(in  == NULL) return NULL_PTR;
-    return SUCCESS;
-}
-int nctp_free(void){
-    while(!queue_empty(out)){
-        free(queue_top(out));
-        queue_pop(out);
-    }
-    while(!queue_empty(in)){
-        free(queue_top(in));
-        queue_pop(in);
-    }
-    return SUCCESS;
-}
-
-int nctp_send(size_t num, uint8_t* ptr[], size_t sz[]){
-    {
-        size_t cnt = 0;
-        for(size_t i = 0; i < num; ++i){
-            cnt += sz[i];
-            if(cnt > queue_max_size) return TRANS_REFUSED;
-        }
-    }
-    int ret;
-    uint8_t *tmp;
-    tmp = malloc(sizeof(uint8_t)); *tmp = NCTP_START; queue_push(out, tmp);
-    for(size_t i = 0; i < num; ++i){
-        uint8_t *p = ptr[i]; size_t s = sz[i];
-        for(size_t j = 0; j < s; ++j, ++p){
-            tmp = malloc(sizeof(uint8_t)); *tmp = *p; queue_push(out, tmp);
-        }
-    }
-    tmp = malloc(sizeof(uint8_t)); *tmp = NCTP_END; queue_push(out, tmp);
-    if(uart_transmitter_empty(COM1_ADDR)){
-        if((ret = uart_send_char(COM1_ADDR, *(uint8_t*)queue_top(out)))) return ret;
-        queue_pop(out);
-    }
-    return SUCCESS;
-}
-
-static int nctp_transmit(void){
-    if(!queue_empty(out)){
-        int ret = uart_send_char(COM1_ADDR, *(uint8_t*)queue_top(out));
-        queue_pop(out);
-        return ret;
-    }else return SUCCESS;
-}
-
-static void process(){
-    free(queue_top(in)); queue_pop(in);
-    while(*(uint8_t*)queue_top(in) != NCTP_END){
-        printf("%c", *(uint8_t*)queue_top(in));
-        free(queue_top(in)); queue_pop(in);
-    }
-    printf("\n");
-    free(queue_top(in)); queue_pop(in);
-}
-static int nctp_receive(void){
-    int ret;
-    uint8_t c;
-    int num_ends = 0;
-    while(uart_receiver_ready(COM1_ADDR)){
-        if((ret = uart_get_char(COM1_ADDR, &c))) return ret;
-        uint8_t *tmp = malloc(sizeof(uint8_t)); *tmp = c;
-        queue_push(in, tmp);
-        if(c == NCTP_END) ++num_ends;
-    }
-    while(num_ends-- > 0) process();
-    return SUCCESS;
-}
-
-int nctp_ih_err = SUCCESS;
-void nctp_ih(void){
-    uint8_t iir;
-    if((nctp_ih_err = uart_get_iir(COM1_ADDR, &iir))) return;
-    if(UART_GET_IF_INT_PEND(iir)){
-        switch(UART_GET_INT_PEND(iir)){
-            case uart_int_rx: nctp_receive (); break;
-            case uart_int_tx: nctp_transmit(); break;
-            default: break;
-        }
-    }
-}
-
-/// HLTP
-int hltp_send_string(const char *p){
-    uint8_t* ptr[1]; ptr[0] = (uint8_t*)p;
-    size_t    sz[1]; sz[0] = strlen(p)+1;
-    return nctp_send(1, ptr, sz);
-}

Property changes on: proj/libs/peripherals/src/uart.c
___________________________________________________________________
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Index: proj/libs/graph/include/graph.h
===================================================================
--- proj/libs/graph/include/graph.h	(nonexistent)
+++ proj/libs/graph/include/graph.h	(revision 284)
@@ -0,0 +1,53 @@
+#ifndef GRAPH_H_INCLUDED
+#define GRAPH_H_INCLUDED
+
+// Graphics modes
+#define INDEXED_1024_768        0x105
+#define DIRECT_640_480_888      0x110
+#define DIRECT_800_600_888      0x115
+#define DIRECT_1024_768_888     0x118
+#define DIRECT_1280_1024_565    0x11A
+#define DIRECT_1280_1024_888    0x11B
+#define LINEAR_FRAME_BUFFER_MD  BIT(14)
+
+// Colors in RBG (8 bit)
+#define GRAPH_BLACK               0x000000
+#define GRAPH_WHITE               0xFFFFFF
+
+// Alpha
+#define ALPHA_THRESHOLD     0x7F
+
+/// MACROS
+#define GET_ALP(n)          (0xFF & ((n) >> 24))
+#define GET_RED(n)          (0xFF & ((n) >> 16))
+#define GET_GRE(n)          (0xFF & ((n) >>  8))
+#define GET_BLU(n)          (0xFF & (n      ))
+#define GET_COLOR(n)        (0xFFFFFF & (n))
+#define SET_ALP(n)          (((n)&0xFF) << 24)
+#define SET_RED(n)          (((n)&0xFF) << 16)
+#define SET_GRE(n)          (((n)&0xFF) <<  8)
+#define SET_BLU(n)          (((n)&0xFF)      )
+#define SET_RGB(r,g,b)      (SET_RED(r) | SET_GRE(g) | SET_BLU(b))
+
+/// PUBLIC GET
+uint16_t   (graph_get_XRes)         (void);
+uint16_t   (graph_get_YRes)         (void);
+uint16_t   (graph_get_bytes_pixel)  (void);
+
+/// INIT
+int (graph_init)(uint16_t mode);
+
+/// CLEANUP
+int (graph_cleanup)(void);
+
+/// PIXEL DRAWING
+int (graph_set_pixel)             (uint16_t x, uint16_t y, uint32_t color);
+void (graph_set_pixel_pos)         (unsigned pos          , uint32_t color);
+
+/// SCREEN
+int (graph_clear_screen)(void);
+
+/// DRAW
+int (graph_draw)(void);
+
+#endif /* end of include guard: GRAPH_H_INCLUDED */

Property changes on: proj/libs/graph/include/graph.h
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: proj/libs/graph/src/graph.c
===================================================================
--- proj/libs/graph/src/graph.c	(nonexistent)
+++ proj/libs/graph/src/graph.c	(revision 284)
@@ -0,0 +1,432 @@
+#include <lcom/lcf.h>
+
+#include "graph.h"
+
+#include "errors.h"
+#include <stdio.h>
+
+#define VC_BIOS_SERV  0x10 /** @brief Interrupt service of video card */
+#define VBE_CALL      0x4F /** @brief VBE call function specifier */
+
+#define MBYTE_BASE  0x0         /** @brief Base address (zero address) */
+#define MBYTE_SIZE  0xFFFFF     /** @brief Size of a mebibyte */
+
+// Graphics Functions
+#define VBE_CTRL_INFO       0x00    /** @brief Get VBE Controller Information */
+#define VBE_MD_INFO         0x01    /** @brief Get VBE Mode Information */
+#define SET_VBE_MD          0x02    /** @brief Set VBE Mode */
+
+// Error codes (AH)
+#define AH_SUCCESS          0x00    /** @brief Success code on BIOS call */
+#define AH_FUNC_CALL_FAIL   0x01    /** @brief Function call failed */
+#define AH_FUNC_NOT_SUPP    0x02    /** @brief Function call is not supported in current HW configuration */
+#define AH_FUNC_INVALID     0x03    /** @brief Invalid function in current video mode */
+
+/// MACROS
+#define FAR2PHYS(n)         ((((n)>>12) & 0xFFFFFFF0) + ((n) & 0x0000FFFF))
+
+/// STRUCT
+typedef struct __attribute__((packed)) {
+
+    char        VbeSignature[4]     ;
+    uint16_t    VbeVersion          ;
+    uint32_t    OemStringPtr        ;
+    uint8_t     Capabilities[4]     ;
+    uint32_t    VideoModePtr        ;
+    uint16_t    TotalMemory         ;
+
+    uint16_t    OemSoftwareRev      ;
+    uint32_t    OemVendorNamePtr    ;
+    uint32_t    OemProductNamePtr   ;
+    uint32_t    OemProductRevPtr    ;
+    char        Reserved[222]       ;
+
+    char        OemData[256]        ;
+} VbeInfoBlock;
+
+static vbe_mode_info_t vbe_mem_info;
+
+/// PRIVATE GET
+static uint16_t   (graph_get_bits_pixel)   (void){ return vbe_mem_info.BitsPerPixel; }
+static phys_bytes (graph_get_phys_addr)    (void){ return vbe_mem_info.PhysBasePtr; }
+static unsigned   (graph_get_vram_size)    (void){ return vbe_mem_info.XResolution * vbe_mem_info.YResolution * graph_get_bytes_pixel(); }
+//static uint16_t   (graph_get_RedMaskSize)  (void){ return vbe_mem_info.RedMaskSize  ; }
+//static uint16_t   (graph_get_GreenMaskSize)(void){ return vbe_mem_info.GreenMaskSize; }
+//static uint16_t   (graph_get_BlueMaskSize) (void){ return vbe_mem_info.BlueMaskSize ; }
+
+/// PUBLIC GET
+uint16_t   (graph_get_XRes)         (void){ return vbe_mem_info.XResolution; }
+uint16_t   (graph_get_YRes)         (void){ return vbe_mem_info.YResolution; }
+uint16_t   (graph_get_bytes_pixel)  (void){ return (graph_get_bits_pixel() + 7) >> 3; }
+
+///
+static int (get_permission)(unsigned int base_addr, unsigned int size) {
+    struct minix_mem_range mmr;
+    mmr.mr_base = base_addr;
+    mmr.mr_limit = base_addr + size;
+    return sys_privctl(SELF, SYS_PRIV_ADD_MEM, &mmr);
+}
+
+//static int (get_permissions_first_mbyte)(void) {
+//    return get_permission(MBYTE_BASE, MBYTE_SIZE);
+//}
+
+/// MEMORY
+static uint8_t *video_mem = NULL; /** @brief Frame-buffer VM address. */
+static uint8_t *video_buf = NULL; /** @brief Primary buffer for drawing before copying to video_mem. */
+static mmap_t mem_map;
+static int (graph_free_memory)(void) {
+    int r = SUCCESS;
+    free(video_buf); video_buf = NULL;
+    r = !lm_free(&mem_map);
+    return r;
+}
+static int (graph_map_vram)(void) {
+    int r;
+    const unsigned vram_base = graph_get_phys_addr();
+    const unsigned vram_size = graph_get_vram_size();
+    if ((r = get_permission(vram_base, vram_size))) {
+        if (graph_free_memory()) {
+            printf("%s: lm_free failed\n", __func__);
+        }
+        panic("%s: sys_privctl (ADD MEM) failed: %d\n", __func__, r);
+    }
+
+    video_mem = vm_map_phys(SELF, (void *)vram_base, vram_size);
+
+    if (video_mem == MAP_FAILED) {
+        if (graph_free_memory()) {
+            printf("%s: lm_free failed\n", __func__);
+        }
+        panic("%s: couldn't map video memory.", __func__);
+    }
+
+    video_buf = malloc(vram_size);
+
+    return SUCCESS;
+}
+
+/// INFO GET
+static int (vbe_get_mode_information)(uint16_t mode) {
+    memset(&vbe_mem_info, 0, sizeof(vbe_mode_info_t)); // reset values
+
+    struct reg86 reg_86;
+    memset(&reg_86, 0, sizeof(struct reg86)); // reset struct
+
+    vbe_mode_info_t *virtual_addr = lm_alloc(sizeof(vbe_mode_info_t), &mem_map);
+
+    reg_86.intno = VC_BIOS_SERV;
+    reg_86.ah = VBE_CALL;
+    reg_86.al = VBE_MD_INFO;
+    reg_86.cx = mode;
+    reg_86.es = PB2BASE(mem_map.phys);
+    reg_86.di = PB2OFF(mem_map.phys);
+    // BIOS CALL
+    if (sys_int86(&reg_86) || reg_86.ah != AH_SUCCESS) {
+        printf("%s: sys_int86 failed\n", __func__);
+        if (graph_free_memory()) {
+            printf("%s: lm_free failed\n", __func__);
+        }
+        return BIOS_CALL_ERROR;
+    }
+
+    memcpy((void*)&vbe_mem_info, (void*)virtual_addr, mem_map.size);
+    return SUCCESS;
+}
+/*
+static int (vbe_get_controller_information)(vg_vbe_contr_info_t *info_p) {
+    memset(info_p, 0, sizeof(vg_vbe_contr_info_t)); // reset values
+
+    mmap_t controller_map;
+
+    struct reg86 reg_86;
+    memset(&reg_86, 0, sizeof(struct reg86)); // reset struct
+
+    VbeInfoBlock *virtual_addr = lm_alloc(sizeof(VbeInfoBlock), &controller_map);
+
+    uint32_t virtual_base = (uint32_t)(virtual_addr) - controller_map.phys;
+
+    virtual_addr->VbeSignature[0] = 'V';
+    virtual_addr->VbeSignature[1] = 'B';
+    virtual_addr->VbeSignature[2] = 'E';
+    virtual_addr->VbeSignature[3] = '2';
+
+
+    reg_86.intno = VC_BIOS_SERV;
+    reg_86.ah = VBE_CALL;
+    reg_86.al = VBE_CTRL_INFO;
+    reg_86.es = PB2BASE(controller_map.phys);
+    reg_86.di = PB2OFF(controller_map.phys);
+    // BIOS CALL
+    if (sys_int86(&reg_86) || reg_86.ah != AH_SUCCESS) {
+        printf("%s: sys_int86 failed\n", __func__);
+        if (!lm_free(&controller_map)) {
+            printf("%s: lm_free failed\n", __func__);
+        }
+        return BIOS_CALL_ERROR;
+    }
+
+    info_p->VBESignature[0] = virtual_addr->VbeSignature[0];
+    info_p->VBESignature[1] = virtual_addr->VbeSignature[1];
+    info_p->VBESignature[2] = virtual_addr->VbeSignature[2];
+    info_p->VBESignature[3] = virtual_addr->VbeSignature[3];
+
+    uint8_t lsb, msb;
+    util_get_LSB(virtual_addr->VbeVersion, &lsb);
+    util_get_MSB(virtual_addr->VbeVersion, &msb);
+    info_p->VBEVersion[0] = lsb;
+    info_p->VBEVersion[1] = msb;
+
+    info_p->TotalMemory = (virtual_addr->TotalMemory << 6);
+
+    // Convert Far Far Pointer to Virtual Address
+
+    uint32_t phys_ptr = FAR2PHYS(virtual_addr->OemStringPtr);
+    uint32_t virtual_ptr = phys_ptr + virtual_base;
+    info_p->OEMString = (char*)(virtual_ptr);
+
+    phys_ptr = FAR2PHYS(virtual_addr->VideoModePtr);
+    virtual_ptr = phys_ptr + virtual_base;
+    info_p->VideoModeList = (uint16_t*)(virtual_ptr);
+
+    phys_ptr = FAR2PHYS(virtual_addr->OemVendorNamePtr);
+    virtual_ptr = phys_ptr + virtual_base;
+    info_p->OEMVendorNamePtr = (char*)(virtual_ptr);
+
+    phys_ptr = FAR2PHYS(virtual_addr->OemProductNamePtr);
+    virtual_ptr = phys_ptr + virtual_base;
+    info_p->OEMProductNamePtr = (char*)(virtual_ptr);
+
+    phys_ptr = FAR2PHYS(virtual_addr->OemProductRevPtr);
+    virtual_ptr = phys_ptr + virtual_base;
+    info_p->OEMProductRevPtr = (char*)(virtual_ptr);
+
+    if (!lm_free(&controller_map)) {
+        printf("%s: lm_free failed\n", __func__);
+        return LCF_ERROR;
+    }
+
+    return SUCCESS;
+}
+*/
+
+/// INIT
+/**
+ * @brief
+ * @param mode
+ * @return
+ */
+static int (graph_set_mode)(uint16_t mode) {
+    struct reg86 reg_86;
+
+    memset(&reg_86, 0, sizeof(struct reg86)); // reset struct
+
+    // Set Reg86
+    reg_86.intno = VC_BIOS_SERV;
+    reg_86.ah = VBE_CALL;
+    reg_86.al = SET_VBE_MD;
+    reg_86.bx = mode | LINEAR_FRAME_BUFFER_MD;
+
+    // BIOS CALL
+    if (sys_int86(&reg_86) || reg_86.ah != AH_SUCCESS) {
+        printf("%s: sys_int86 failed\n", __func__);
+        return BIOS_CALL_ERROR;
+    }
+
+    return SUCCESS;
+}
+int (graph_init)(uint16_t mode){
+    if (vbe_get_mode_information(mode)) {
+        printf("%s: failed to get information for mode %x.\n", __func__, mode);
+        return 1;
+    }
+
+    graph_map_vram(); // if function fails it aborts program
+
+    if (graph_set_mode(mode)) {
+        printf("%s: failed to set graphic mode %x.\n", __func__, mode);
+        return 1;
+    };
+    return SUCCESS;
+}
+
+/// CLEANUP
+int (graph_cleanup)(void){
+    int r = SUCCESS;
+    if ((r = vg_exit()))
+        printf("%s: vg_exit failed to exit to text mode.\n", __func__);
+    if ((r = graph_free_memory()))
+        printf("%s: lm_free failed\n", __func__);
+    return r;
+}
+
+/// PIXEL DRAWING
+int (graph_set_pixel)(uint16_t x, uint16_t y, uint32_t color) {
+    //pixels are certain to be inside can reduce lag
+    /*if (x < 0 || vbe_mem_info.XResolution <= x || y < 0 || vbe_mem_info.YResolution <= y) {
+        //printf("%s: invalid pixel.\n", __func__);
+        return OUT_OF_RANGE;
+    }*/
+    unsigned int pos = (x + y * vbe_mem_info.XResolution) * 3/*graph_get_bytes_pixel()*/;
+    memcpy(video_buf + pos, &color, 3/*graph_get_bytes_pixel()*/);
+    return SUCCESS;
+}
+void (graph_set_pixel_pos)(unsigned pos, uint32_t color){
+    memcpy(video_buf + pos, &color, graph_get_bytes_pixel());
+}
+int (graph_clear_screen)(void){ memset(video_buf, 0, graph_get_vram_size()); return SUCCESS; }
+int (graph_draw)(void){ memcpy(video_mem, video_buf, graph_get_vram_size()); return SUCCESS; }
+
+///SPRITE
+#include "sprite.h"
+
+#include "utils.h"
+#include "fast_math.h"
+#include <math.h>
+
+struct basic_sprite{
+    uint8_t *map;
+    uint16_t w, h;
+    int16_t u0, v0;
+};
+basic_sprite_t* (basic_sprite_ctor)(const char **xpm, int16_t u0, int16_t v0){
+    basic_sprite_t *ret = malloc(sizeof(basic_sprite_t));
+    if(ret == NULL) return NULL;
+    enum xpm_image_type type = XPM_8_8_8_8;
+    xpm_image_t img;
+    ret->map = xpm_load((xpm_map_t)xpm, type, &img);
+    if(ret->map == NULL){
+        basic_sprite_dtor(ret);
+        return NULL;
+    }
+    ret->w = img.width;
+    ret->h = img.height;
+    ret->u0 = u0;
+    ret->v0 = v0;
+    return ret;
+}
+void (basic_sprite_dtor)(basic_sprite_t *p){
+    if(p == NULL) return;
+    free(p->map);
+    free(p);
+}
+const uint8_t* (basic_sprite_get_map)(const basic_sprite_t *p){ return p->map; }
+uint16_t       (basic_sprite_get_w)  (const basic_sprite_t *p){ return p->w  ; }
+uint16_t       (basic_sprite_get_h)  (const basic_sprite_t *p){ return p->h  ; }
+int16_t        (basic_sprite_get_u0) (const basic_sprite_t *p){ return p->u0 ; }
+int16_t        (basic_sprite_get_v0) (const basic_sprite_t *p){ return p->v0 ; }
+
+/*
+struct basic_sprite_alpha{
+    uint8_t *map;
+    uint16_t w, h;
+    int16_t u0, v0;
+};
+basic_sprite_alpha_t* (basic_sprite_alpha_ctor)(const char **xpm, int16_t u0, int16_t v0){
+    basic_sprite_alpha_t *ret = malloc(sizeof(basic_sprite_t));
+    if(ret == NULL) return NULL;
+    enum xpm_image_type type = XPM_8_8_8_8;
+    xpm_image_t img;
+    ret->map = NULL;
+    uint8_t *m = xpm_load((xpm_map_t)xpm, type, &img);
+    if(m == NULL){
+        basic_sprite_alpha_dtor(ret);
+        return NULL;
+    }
+    ret->map = m;
+    if(ret->map == NULL){
+        basic_sprite_alpha_dtor(ret);
+        return NULL;
+    }
+    ret->w = img.width;
+    ret->h = img.height;
+    ret->u0 = u0;
+    ret->v0 = v0;
+    return ret;
+}
+void (basic_sprite_alpha_dtor)(basic_sprite_alpha_t *p){
+    if(p == NULL) return;
+    free(p->map);
+    free(p);
+}
+const uint8_t* (basic_sprite_alpha_get_map)(const basic_sprite_alpha_t *p){ return p->map; }
+uint16_t       (basic_sprite_alpha_get_w)  (const basic_sprite_alpha_t *p){ return p->w  ; }
+uint16_t       (basic_sprite_alpha_get_h)  (const basic_sprite_alpha_t *p){ return p->h  ; }
+int16_t        (basic_sprite_alpha_get_u0) (const basic_sprite_alpha_t *p){ return p->u0 ; }
+int16_t        (basic_sprite_alpha_get_v0) (const basic_sprite_alpha_t *p){ return p->v0 ; }
+*/
+
+struct sprite{
+    const basic_sprite_t *bsp;
+    int16_t x, y; //position in screen
+    double theta, s, c;
+    double scale;
+};
+sprite_t* (sprite_ctor)(const basic_sprite_t *bsp){
+    sprite_t *ret = malloc(sizeof(sprite_t));
+    if(ret == NULL) return NULL;
+    ret->bsp = bsp;
+    ret->x = 0;
+    ret->y = 0;
+    sprite_set_angle(ret, 0.0);
+    ret->scale = 1.0;
+    return ret;
+}
+void (sprite_dtor)(sprite_t *p){
+    if(p == NULL) return;
+    free(p);
+}
+void (sprite_set_pos)   (sprite_t *p, int16_t x , int16_t y ){ p->x = x; p->y = y; }
+void (sprite_set_angle) (sprite_t *p, double angle          ){ p->theta = angle; p->c = fm_cos(p->theta); p->s = fm_sin(p->theta); }
+void (sprite_set_scale) (sprite_t *p, double scale          ){ p->scale = scale; }
+int16_t  (sprite_get_x)(const sprite_t *p){ return p->x; }
+int16_t  (sprite_get_y)(const sprite_t *p){ return p->y; }
+double   (sprite_get_angle)(const sprite_t *p){ return p->theta; }
+uint16_t (sprite_get_w)(const sprite_t *p){ return basic_sprite_get_w(p->bsp); }
+uint16_t (sprite_get_h)(const sprite_t *p){ return basic_sprite_get_h(p->bsp); }
+void (sprite_src2pic)(const sprite_t *p, int16_t x, int16_t y, int16_t *u, int16_t *v){
+    double dx = (x - p->x)/p->scale;
+    double dy = (y - p->y)/p->scale;
+    int16_t du = dx*p->c - dy*p->s - 0.5;
+    int16_t dv = dx*p->s + dy*p->c - 0.5;
+    *u = du + basic_sprite_get_u0(p->bsp);
+    *v = dv + basic_sprite_get_v0(p->bsp);
+}
+void (sprite_pic2src)(const sprite_t *p, int16_t u, int16_t v, int16_t *x, int16_t *y){
+    int16_t du = u - basic_sprite_get_u0(p->bsp);
+    int16_t dv = v - basic_sprite_get_v0(p->bsp);
+    double dx =  du*p->c + dv*p->s;
+    double dy = -du*p->s + dv*p->c;
+    *x = dx*p->scale + 0.5 + p->x;
+    *y = dy*p->scale + 0.5 + p->y;
+}
+void (sprite_draw)(const sprite_t *p){
+    const uint16_t w = basic_sprite_get_w(p->bsp);
+    const uint16_t h = basic_sprite_get_h(p->bsp);
+    int16_t xmin, xmax, ymin, ymax; {
+        int16_t x, y;
+        sprite_pic2src(p, 0, 0, &x, &y);
+        xmin = x; xmax = x; ymin = y; ymax = y;
+        sprite_pic2src(p, w, 0, &x, &y);
+        xmin = min(x, xmin); xmax = max(x, xmax); ymin = min(y, ymin); ymax = max(y, ymax);
+        sprite_pic2src(p, 0, h, &x, &y);
+        xmin = min(x, xmin); xmax = max(x, xmax); ymin = min(y, ymin); ymax = max(y, ymax);
+        sprite_pic2src(p, w, h, &x, &y);
+        xmin = min(x, xmin); xmax = max(x, xmax); ymin = min(y, ymin); ymax = max(y, ymax);
+        xmin = max(xmin-(int16_t)p->scale-2, 0); xmax = min(xmax+(int16_t)p->scale+2, graph_get_XRes());
+        ymin = max(ymin-(int16_t)p->scale-2, 0); ymax = min(ymax+(int16_t)p->scale+2, graph_get_YRes());
+    }
+    const uint8_t *map = basic_sprite_get_map(p->bsp);
+    const uint16_t bytes_pixel = 3/*graph_get_bytes_pixel()*/;
+    for(int16_t u, v, y = ymin; y < ymax; ++y){
+        uint8_t *place = video_buf + (xmin + y*graph_get_XRes())*bytes_pixel;
+        for(int16_t x = xmin; x < xmax; ++x, place += bytes_pixel){
+            sprite_src2pic(p, x, y, &u, &v);
+            if(0 <= u && u < w && 0 <= v && v < h){
+                const uint8_t *c_p = map+(v*w+u)*4;
+                if(*(c_p+3) < ALPHA_THRESHOLD) //alpha
+                    memcpy(place, c_p, bytes_pixel);
+            }
+        }
+    }
+}

Property changes on: proj/libs/graph/src/graph.c
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: proj/libs/kbc/include/kbc.h
===================================================================
--- proj/libs/kbc/include/kbc.h	(nonexistent)
+++ proj/libs/kbc/include/kbc.h	(revision 284)
@@ -0,0 +1,107 @@
+/**
+ * This file concerns everything related to the KBC (KeyBoard Controller, which
+ * actually also manages the mouse)
+ */
+
+#ifndef KBC_H_INCLUDED
+#define KBC_H_INCLUDED
+
+/* 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   20    /* @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 */
+
+/**
+ * @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 0 if operation was successful, 1 otherwise
+ */
+int (kbc_restore_keyboard)();
+
+/**
+ * @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 //KBC_H_INCLUDED

Property changes on: proj/libs/kbc/include/kbc.h
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: proj/libs/kbc/include/keyboard.h
===================================================================
--- proj/libs/kbc/include/keyboard.h	(nonexistent)
+++ proj/libs/kbc/include/keyboard.h	(revision 284)
@@ -0,0 +1,28 @@
+/**
+ * This file concerns everything related to the keyboard
+ */
+
+#ifndef KEYBOARD_H_INCLUDED
+#define KEYBOARD_H_INCLUDED
+
+#include "kbc.h"
+
+/**
+ * @brief Subscribes Keyboard Interrupts and disables Minix Default IH
+ * @param interrupt_bit Bit of Interrupt Vector that will be set when Keyboard Interrupt is pending
+ * @param interrupt_id Keyboard Interrupt ID to specify the Keyboard Interrupt in other calls
+ * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
+ * @see {_ERRORS_H_::errors}
+ */
+int (subscribe_kbc_interrupt)(uint8_t interrupt_bit, int *interrupt_id);
+
+uint8_t scancode[2];
+int done;
+int sz;
+int got_error_keyboard;
+
+void (kbc_ih)(void);
+
+int (keyboard_poll)(uint8_t bytes[], uint8_t *size);
+
+#endif //KEYBOARD_H_INCLUDED

Property changes on: proj/libs/kbc/include/keyboard.h
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: proj/libs/kbc/include/mouse.h
===================================================================
--- proj/libs/kbc/include/mouse.h	(nonexistent)
+++ proj/libs/kbc/include/mouse.h	(revision 284)
@@ -0,0 +1,89 @@
+#ifndef MOUSE_H_INCLUDED
+#define MOUSE_H_INCLUDED
+
+/**
+ * @brief Subscribes Mouse Interrupts and disables Minix Default IH
+ * @param interrupt_bit Bit of Interrupt Vector that will be set when Mouse Interrupt is pending
+ * @param interrupt_id Mouse Interrupt ID to specify the Mouse Interrupt in other calls
+ * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
+ * @see {_ERRORS_H_::errors}
+ */
+int (subscribe_mouse_interrupt)(uint8_t interrupt_bit, int *interrupt_id);
+
+//These have to do with mouse_ih
+int got_error_mouse_ih;
+uint8_t packet_mouse_ih[3];
+int counter_mouse_ih;
+
+/**
+ * @brief   Parse 3 bytes and returns it as a parsed, struct packet.
+ * @param   packet_bytes    array of bytes to parse
+ * @param   pp              Pointer to packet to store the information.
+ */
+void (mouse_parse_packet)(const uint8_t *packet_bytes, struct packet *pp);
+
+/**
+ * @brief Polls mouse for data. Blocks execution until a valid mouse packet is obtained.
+ * @param   pp      pointer to packet struct in which the result will be stored
+ * @param   period  time (in milliseconds) the poller should wait between pollings of bytes
+ * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
+ */
+int mouse_poll(struct packet *pp, uint16_t period);
+
+/**
+ * @brief Sets data report mode for mouse
+ * @param   on  zero to disable data report, any other value to enable data report
+ * @return  ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
+ */
+int (mouse_set_data_report)(int on);
+
+/**
+ * @brief Reads data byte from mouse
+ * <summary>
+ * Polls the mouse till data is available for reading
+ * </summary>
+ * @param data Pointer to variable where byte read from mouse will be stored
+ * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
+ * @see {_ERRORS_H_::errors}
+ */
+int (mouse_read_data)(uint8_t *data, uint16_t period);
+
+/**
+ * @brief Issues command to mouse
+ * <summary>
+ * Issues command to mouse, returns error after two consecutive errors reported by the acknowledgment byte
+ * </summary>
+ * @param cmd Command to be issued
+ * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
+ * @see {_ERRORS_H_::errors}
+ */
+int (mouse_issue_cmd)(uint32_t cmd);
+
+/**
+ * @brief Reads byte from mouse
+ * <summary>
+ * Reads byte from mouse, giving error if exceeds number of tries to read
+ * </summary>
+ * @param byte Pointer to variable where byte read from mouse will be stored
+ * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
+ * @see {_ERRORS_H_::errors}
+ */
+int (mouse_read_byte)(uint8_t *byte);
+
+/**
+ * @brief Polls OUT_BUF for byte coming from mouse.
+ * @param   byte    pointer to byte read from OUT_BUF
+ * @param   period  time (in milliseconds) the poller should wait between pollings of bytes
+ * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
+ */
+int (mouse_poll_byte)(uint8_t *byte, uint16_t period);
+
+/**
+ * @brief Converts 9-bit number to 16-bit with sign extension
+ * @param sign_bit  Sign bit identifiying the signal of the number
+ * @param byte      Least significant byte that will be extended
+ * @return Extended 9-bit number
+ */
+int16_t (sign_extend_byte)(uint8_t sign_bit, uint8_t byte);
+
+#endif //MOUSE_H_INCLUDED

Property changes on: proj/libs/kbc/include/mouse.h
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: proj/libs/kbc/src/kbc.c
===================================================================
--- proj/libs/kbc/src/kbc.c	(nonexistent)
+++ proj/libs/kbc/src/kbc.c	(revision 284)
@@ -0,0 +1,73 @@
+#include <lcom/lcf.h>
+
+#include "kbc.h"
+
+#include "utils.h"
+#include "errors.h"
+
+int (kbc_read_cmd)(uint8_t *cmd){
+    int ret = 0;
+    if((ret = kbc_issue_cmd(READ_KBC_CMD))) return ret;
+    if((ret = kbc_read_byte(cmd))) return ret;
+    return SUCCESS;
+}
+
+int (kbc_change_cmd)(uint8_t cmd){
+    int ret = 0;
+    if((ret = kbc_issue_cmd(WRITE_KBC_CMD))) return ret;
+    if((ret = kbc_issue_arg(cmd))) return ret;
+    return SUCCESS;
+}
+
+int (kbc_restore_kbd)(){
+    int ret = 0;
+    uint8_t cmd = 0;
+    if((ret = kbc_read_cmd(&cmd))) return ret;
+    cmd = (cmd | INT_KBD) & (~DIS_KBD);
+    if((ret = kbc_change_cmd(cmd))) return ret;
+    return SUCCESS;
+}
+
+int (kbc_issue_cmd)(uint8_t cmd){
+    int ret = 0;
+    uint8_t stat;
+    for(int i = 0; i < KBC_NUM_TRIES; ++i){
+        if((ret = util_sys_inb(STATUS_REG, &stat))) return ret;
+        if((stat&IN_BUF_FULL) == 0){
+            if(sys_outb(KBC_CMD, cmd)) return WRITE_ERROR;
+            return SUCCESS;
+        }
+        tickdelay(micros_to_ticks(DELAY));
+    }
+    return TIMEOUT_ERROR;
+}
+
+int (kbc_issue_arg)(uint8_t arg){
+    int ret = 0;
+    uint8_t stat;
+    for(int i = 0; i < KBC_NUM_TRIES; ++i){
+        if((ret = util_sys_inb(STATUS_REG, &stat))) return ret;
+        if((stat&IN_BUF_FULL) == 0){
+            if(sys_outb(KBC_CMD_ARG, arg)) return WRITE_ERROR;
+            return SUCCESS;
+        }
+        tickdelay(micros_to_ticks(DELAY));
+    }
+    return TIMEOUT_ERROR;
+}
+
+int (kbc_read_byte)(uint8_t *byte){
+    int ret = 0;
+    uint8_t stat;
+    for(int i = 0; i < KBC_NUM_TRIES; ++i){
+        if((ret = util_sys_inb(STATUS_REG, &stat))) return ret;
+        if((stat&OUT_BUF_FUL) && (stat&AUX_MOUSE)==0){
+            if(stat & (PARITY_ERROR | TIME_OUT_REC)) return OTHER_ERROR;
+            if((ret = util_sys_inb(OUTPUT_BUF, byte))) return ret;
+            else return SUCCESS;
+        }
+        tickdelay(micros_to_ticks(DELAY));
+    }
+    printf("Timing out\n");
+    return TIMEOUT_ERROR;
+}

Property changes on: proj/libs/kbc/src/kbc.c
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: proj/libs/kbc/src/keyboard.c
===================================================================
--- proj/libs/kbc/src/keyboard.c	(nonexistent)
+++ proj/libs/kbc/src/keyboard.c	(revision 284)
@@ -0,0 +1,60 @@
+#include <lcom/lcf.h>
+
+#include "keyboard.h"
+
+#include "kbc.h"
+#include "utils.h"
+#include "errors.h"
+#include "proj_func.h"
+
+int (subscribe_kbc_interrupt)(uint8_t interrupt_bit, int *interrupt_id) {
+    if (interrupt_id == NULL) return NULL_PTR;
+    *interrupt_id = interrupt_bit;
+    if(sys_irqsetpolicy(KBC_IRQ, IRQ_REENABLE | IRQ_EXCLUSIVE, interrupt_id)) return SBCR_ERROR;
+    return SUCCESS;
+}
+
+int done = 1;
+int sz = 1;
+int got_error_keyboard = SUCCESS;
+
+void (kbc_ih)(void) {
+    if(done) { sz = 1; }
+    else     sz++;
+    uint8_t status = 0;
+    got_error_keyboard = SUCCESS;
+    if ((got_error_keyboard = util_sys_inb(STATUS_REG, &status))) return;
+    if (status & (TIME_OUT_REC | PARITY_ERROR)) {
+        got_error_keyboard = 1;
+        return;
+    }
+    if ((status & OUT_BUF_FUL) == 0 || (status & AUX_MOUSE) != 0) {
+        got_error_keyboard = READ_ERROR;
+        return;
+    }
+    uint8_t byte = 0;
+    if ((got_error_keyboard = util_sys_inb(OUTPUT_BUF, &byte))) return;
+
+    scancode[sz-1] = byte;
+    done = !(TWO_BYTE_CODE == byte);
+
+    if (done) update_key_presses();
+
+}
+
+int (keyboard_poll)(uint8_t bytes[], uint8_t *size){
+    int ret = 0;
+    if(bytes == NULL || size == NULL) return NULL_PTR;
+    uint8_t c;
+    if((ret = kbc_read_byte(&c))) return ret;
+    if(c == TWO_BYTE_CODE){
+        if((ret = kbc_read_byte(&bytes[1]))) return ret;
+        bytes[0] = c;
+        *size = 2;
+    }else{
+        bytes[1] = 0;
+        bytes[0] = c;
+        *size = 1;
+    }
+    return SUCCESS;
+}

Property changes on: proj/libs/kbc/src/keyboard.c
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: proj/libs/kbc/src/mouse.c
===================================================================
--- proj/libs/kbc/src/mouse.c	(nonexistent)
+++ proj/libs/kbc/src/mouse.c	(revision 284)
@@ -0,0 +1,162 @@
+#include <lcom/lcf.h>
+
+#include "mouse.h"
+
+#include "errors.h"
+#include "kbc.h"
+
+/* Mouse Data Packet */
+// Byte 0 - Button States
+#define LEFT_BUTTON     BIT(0) /* @brief Left button click event*/
+#define RIGHT_BUTTON    BIT(1) /* @brief Right button click event */
+#define MIDDLE_BUTTON   BIT(2) /* @brief Middle button click event */
+#define FIRST_BYTE_ID   BIT(3) /* @brief Identifier of first byte of packet CAREFUL: Not 100% accurate */
+#define MSB_X_DELTA     BIT(4) /* @brief Most significant bit of X delta */
+#define MSB_Y_DELTA     BIT(5) /* @brief Most significant bit of Y delta */
+#define X_OVERFLOW      BIT(6) /* @brief X delta overflowed */
+#define Y_OVERFLOW      BIT(7) /* @brief Y delta overflowed */
+// Byte 1 - X delta
+// Byte 2 - Y delta
+
+/* Mouse Commands */
+#define RESET           0xFF /* @brief Reset mouse */
+#define RESEND          0xFE /* @brief Resend command */
+#define DEFAULT         0xF6 /* @brief Set default values */
+#define DIS_DATA_REP    0xF5 /* @brief Disable Data Reporting */
+#define ENABLE_DATA_REP 0xF4 /* @brief Enable Data Reporting */
+#define SET_SAMPLE_RT   0xF3 /* @brief Sets state sampling rate */
+#define SET_REMOTE_MD   0xF0 /* @brief Sets Mouse on Remote Mode, data on request */
+#define READ_DATA       0xEB /* @brief Sends data packet request */
+#define SET_STREAM_MD   0xEA /* @brief Sets mouse on Stream Mode, data on events */
+#define STATUS_REQUEST  0xE9 /* @brief Get mouse configuration */
+#define SET_RESOLUTION  0xE8 /* @brief Sets resolution for mouse movement */
+#define SCALING_ACC_MD  0xE7 /* @brief Sets scaling on acceleration mode */
+#define SCALING_LIN_MD  0xE6 /* @brief Sets scaling on linear mode */
+
+/* Mouse Controller Responses */
+#define ACK_OK      0xFA /* @brief Operation sucessful */
+#define ACK_INVALID 0xFE /* @brief Invalid Byte, first occurence */
+#define ACK_ERROR   0xFC /* @brief Invalid Byte on resend */
+
+int (subscribe_mouse_interrupt)(uint8_t interrupt_bit, int *interrupt_id) {
+    if (interrupt_id == NULL) return NULL_PTR;
+    *interrupt_id = interrupt_bit;
+    if (sys_irqsetpolicy(MOUSE_IRQ, IRQ_REENABLE | IRQ_EXCLUSIVE, interrupt_id)) return SBCR_ERROR;
+    return SUCCESS;
+}
+
+int got_error_mouse_ih = 0;
+int counter_mouse_ih = 0;
+
+void (mouse_ih)(void) {
+    uint8_t status = 0;
+    got_error_mouse_ih = 0;
+    if(counter_mouse_ih >= 3) counter_mouse_ih = 0;
+
+    if ((got_error_mouse_ih = util_sys_inb(STATUS_REG, &status))) return;
+
+    if (status & (TIME_OUT_REC | PARITY_ERROR)) {
+        got_error_mouse_ih = OTHER_ERROR;
+        return;
+    }
+    if (((status & AUX_MOUSE) == 0) || ((status & OUT_BUF_FUL) == 0)) {
+        got_error_mouse_ih = READ_ERROR;
+        return;
+    }
+
+    uint8_t byte = 0;
+
+    if ((got_error_mouse_ih = util_sys_inb(OUTPUT_BUF, &byte))) return;
+
+    /// This does not run if: I was expecting the first one but what I get is definitely not the first byte
+    if((byte & FIRST_BYTE_ID)  || counter_mouse_ih){
+        packet_mouse_ih[counter_mouse_ih++] = byte;
+    }
+}
+
+void (mouse_parse_packet)(const uint8_t *packet_bytes, struct packet *pp){
+    pp->bytes[0] = packet_bytes[0];
+    pp->bytes[1] = packet_bytes[1];
+    pp->bytes[2] = packet_bytes[2];
+    pp->rb       = pp->bytes[0] & RIGHT_BUTTON;
+    pp->mb       = pp->bytes[0] & MIDDLE_BUTTON;
+    pp->lb       = pp->bytes[0] & LEFT_BUTTON;
+    pp->delta_x  = sign_extend_byte((packet_bytes[0] & MSB_X_DELTA) != 0, pp->bytes[1]);
+    pp->delta_y  = sign_extend_byte((packet_bytes[0] & MSB_Y_DELTA) != 0, pp->bytes[2]);
+    pp->x_ov     = pp->bytes[0] & X_OVERFLOW;
+    pp->y_ov     = pp->bytes[0] & Y_OVERFLOW;
+}
+
+int mouse_poll(struct packet *pp, uint16_t period){
+    int ret = 0;
+
+    uint8_t packet[3];
+    uint8_t byte;
+    if ((ret = mouse_issue_cmd(READ_DATA))) return ret;
+    for(unsigned i = 0; i < 3; ++i){
+        if((ret = mouse_poll_byte(&byte, period))) return ret;
+        packet[i] = byte;
+    }
+    mouse_parse_packet(packet, pp);
+    return SUCCESS;
+}
+
+int (mouse_set_data_report)(int on){
+    if(on) return mouse_issue_cmd(ENABLE_DATA_REP);
+    else   return mouse_issue_cmd(   DIS_DATA_REP);
+}
+
+int (mouse_read_data)(uint8_t *data, uint16_t period) {
+    int ret;
+    if ((ret = mouse_issue_cmd(READ_DATA))) return ret;
+    if ((ret = mouse_poll_byte(data, period))) return ret;
+    return SUCCESS;
+}
+
+int (mouse_issue_cmd)(uint32_t cmd) {
+    int ret;
+    uint8_t ack = 0;
+    for (unsigned int i = 0; i < KBC_NUM_TRIES; i++) {
+        if ((ret = kbc_issue_cmd(MOUSE_WRITE_B))) return ret;
+        if ((ret = kbc_issue_arg(cmd))) return ret;
+        if ((ret = mouse_read_byte(&ack))) return ret;
+
+        if (ack == ACK_OK) return SUCCESS;
+        if (ack == ACK_ERROR) return INVALID_COMMAND;
+        tickdelay(micros_to_ticks(DELAY));
+    }
+    return TIMEOUT_ERROR;
+}
+
+int (mouse_read_byte)(uint8_t *byte) {
+    int ret = 0;
+    uint8_t stat;
+    for(int i = 0; i < KBC_NUM_TRIES; ++i){
+        if((ret = util_sys_inb(STATUS_REG, &stat))) return ret;
+        if((stat&OUT_BUF_FUL) && (stat&AUX_MOUSE)) {
+            if(stat & (PARITY_ERROR | TIME_OUT_REC)) return OTHER_ERROR;
+            if((ret = util_sys_inb(OUTPUT_BUF, byte))) return ret;
+            else return SUCCESS;
+        }
+        tickdelay(micros_to_ticks(DELAY));
+    }
+    return TIMEOUT_ERROR;
+}
+
+int (mouse_poll_byte)(uint8_t *byte, uint16_t period) {
+    int ret = 0;
+    uint8_t stat;
+    while(true){
+        if((ret = util_sys_inb(STATUS_REG, &stat))) return ret;
+        if((stat&OUT_BUF_FUL) && (stat&AUX_MOUSE)) {
+            if(stat & (PARITY_ERROR | TIME_OUT_REC)) return OTHER_ERROR;
+            if((ret = util_sys_inb(OUTPUT_BUF, byte))) return ret;
+            else return SUCCESS;
+        }
+        tickdelay(micros_to_ticks(DELAY));
+    }
+}
+
+int16_t (sign_extend_byte)(uint8_t sign_bit, uint8_t byte) {
+    return (int16_t)(((0xFF * sign_bit)<<8) | byte);
+}

Property changes on: proj/libs/kbc/src/mouse.c
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: proj/libs/rtc/include/rtc.h
===================================================================
--- proj/libs/rtc/include/rtc.h	(nonexistent)
+++ proj/libs/rtc/include/rtc.h	(revision 284)
@@ -0,0 +1,46 @@
+#ifndef RTC_H_INCLUDED
+#define RTC_H_INCLUDED
+
+#include <stdint.h>
+
+/**
+ * @brief Subscribes RTC Interrupts
+ * @param interrupt_bit Bit of Interrupt Vector that will be set when RTC Interrupt is pending
+ * @param interrupt_id RTC Interrupt ID to specify the RTC Interrupt in other calls
+ * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
+ * @see {_ERRORS_H_::errors}
+ */
+int (subscribe_rtc_interrupt)(uint8_t interrupt_bit, int *interrupt_id);
+
+int (rtc_read_register)(uint32_t reg, uint8_t *data);
+
+int (rtc_write_register)(uint32_t reg, uint8_t data);
+
+/**
+ * @brief Checks if there's an update in progress.
+ * @return  The value of the flag UIP, or ERROR_CODE if error occurs.
+ */
+int (rtc_check_update)(void);
+
+/**
+ * @brief Enables/Disables updates of time/date registers.
+ * @param   on  zero to disable, any other value to enable
+ * @return  ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
+ */
+int (rtc_set_updates)(int on);
+
+/**
+ * @brief Reads time from RTC.
+ * @param   time  Pointer to array of 3 bytes to store the information about time (hours, minutes, seconds)
+ * @return  ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
+ */
+int (rtc_read_time)(uint8_t *time);
+
+/**
+ * @brief Reads date from RTC.
+ * @param   date  Pointer to array of 4 bytes to store the information about date (year, month, day, weekday)
+ * @return  ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
+ */
+int (rtc_read_date)(uint8_t *date);
+
+#endif /* end of include guard: RTC_H_INCLUDED */

Property changes on: proj/libs/rtc/include/rtc.h
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: proj/libs/rtc/src/rtc.c
===================================================================
--- proj/libs/rtc/src/rtc.c	(nonexistent)
+++ proj/libs/rtc/src/rtc.c	(revision 284)
@@ -0,0 +1,159 @@
+#include <lcom/lcf.h>
+
+#include "rtc.h"
+
+#include "utils.h"
+#include "errors.h"
+
+// RTC IRQ Line
+
+#define KBC_IRQ   8  /* @brief KBC IRQ Line */
+
+// RTC Ports
+
+#define RTC_ADDR_REG        0x70
+#define RTC_DATA_REG        0x71
+
+// RTC Registers (Byte)
+
+#define RTC_SEC             0
+#define RTC_SEC_ALARM       1
+#define RTC_MIN             2
+#define RTC_MIN_ALARM       3
+#define RTC_HOUR            4
+#define RTC_HOUR_ALARM      5
+#define RTC_WEEK_DAY        6
+#define RTC_MONTH_DAY       7
+#define RTC_MONTH           8
+#define RTC_YEAR            9
+#define RTC_REG_A           10
+#define RTC_REG_B           11
+#define RTC_REG_C           12
+#define RTC_REG_D           13
+
+// Register A
+
+#define RS0     BIT(0)  /** @brief Rate selector */
+#define RS1     BIT(1)  /** @brief Rate selector */
+#define RS2     BIT(2)  /** @brief Rate selector */
+#define RS3     BIT(3)  /** @brief Rate selector */
+#define UIP     BIT(7)  /** @brief Update in progress */
+
+// Register B
+
+#define DSE             BIT(0)  /** @brief Enable Daylight Saving Time */
+#define HOUR_FORM       BIT(1)  /** @brief Set to 1 for 24h format (0-23), 0 to 12h format (1-12) */
+#define DM              BIT(2)  /** @brief Set to 1 if registers are in binary, 0 if in BCD */
+#define SQWE            BIT(3)  /** @brief Enable square wave generation */
+#define UIE             BIT(4)  /** @brief Enable Update interrupts */
+#define AIE             BIT(5)  /** @brief Enable alarm interrupts */
+#define PIE             BIT(6)  /** @brief Enable periodic interrupts */
+#define SET             BIT(7)  /** @brief Set to 1 to inhibit updates of time/date registers */
+
+// Register C
+
+#define UF      BIT(4)  /** @brief Update Interrupt Pending */
+#define AF      BIT(5)  /** @brief Alarm Interrupt Pending */
+#define PF      BIT(6)  /** @brief Periodic Interrupt Pending */
+#define IRQF    BIT(7)  /** @brief IRQ Line Active */
+
+// Register D
+
+#define VRT     BIT(7)  /** @brief Valid RAM/time - If set to 0 RTC reading aren't valid */
+
+int (subscribe_rtc_interrupt)(uint8_t interrupt_bit, int *interrupt_id) {
+    if (interrupt_id == NULL) return NULL_PTR;
+    *interrupt_id = interrupt_bit;
+    if (sys_irqsetpolicy(KBC_IRQ, IRQ_REENABLE | IRQ_EXCLUSIVE, interrupt_id)) return SBCR_ERROR;
+    return SUCCESS;
+}
+
+int (rtc_read_register)(uint32_t reg, uint8_t *data) {
+    if (sys_outb(RTC_ADDR_REG, reg)) return WRITE_ERROR;
+
+    if (util_sys_inb(RTC_DATA_REG, data)) return READ_ERROR;
+
+    return SUCCESS;
+}
+
+int (rtc_write_register)(uint32_t reg, uint8_t data) {
+    if (sys_outb(RTC_ADDR_REG, reg)) return WRITE_ERROR;
+
+    if (sys_outb(RTC_DATA_REG, data)) return WRITE_ERROR;
+
+    return SUCCESS;
+}
+
+int (rtc_check_update)(void) {
+    uint8_t data;
+    int r;
+
+    if ((r = rtc_read_register(RTC_REG_A, &data))) return r;
+
+    return (data & UIP) != 0;
+}
+
+int (rtc_set_updates)(int on) {
+    uint8_t data;
+    int r;
+    if (on) {
+        if ((r = rtc_read_register(RTC_REG_B, &data))) return r;
+
+        data &= ~SET;
+
+        if ((r = rtc_write_register(RTC_REG_B, data))) return r;
+
+    } else {
+        while (rtc_check_update());
+
+        if ((r = rtc_read_register(RTC_REG_B, &data))) return r;
+
+        data |= SET;
+
+        if ((r = rtc_write_register(RTC_REG_B, data))) return r;
+    }
+    return SUCCESS;
+}
+
+int (rtc_read_time)(uint8_t *time) {
+
+    int r;
+    //if ((r = rtc_set_updates(false))) return r;
+    while (rtc_check_update());
+
+    uint8_t hour, min, sec;
+
+    if ((r = rtc_read_register(RTC_SEC, &sec)))    return r;
+    if ((r = rtc_read_register(RTC_MIN, &min)))    return r;
+    if ((r = rtc_read_register(RTC_HOUR, &hour)))  return r;
+
+    //if ((r = rtc_set_updates(true))) return r;
+
+    time[0] = BCD_FIRST(sec)*10   + BCD_SECOND(sec);
+    time[1] = BCD_FIRST(min)*10   + BCD_SECOND(min);
+    time[2] = BCD_FIRST(hour)*10  + BCD_SECOND(hour);
+
+    return SUCCESS;
+}
+
+int (rtc_read_date)(uint8_t *date) {
+    int r;
+    //if ((r = rtc_set_updates(false))) return r;
+    while (rtc_check_update());
+
+    uint8_t year, month, day, weekday;
+
+    if ((r = rtc_read_register(RTC_WEEK_DAY,    &weekday)))     return r;
+    if ((r = rtc_read_register(RTC_MONTH_DAY,   &day)))         return r;
+    if ((r = rtc_read_register(RTC_MONTH,       &month)))       return r;
+    if ((r = rtc_read_register(RTC_YEAR,        &year)))        return r;
+
+    //if ((r = rtc_set_updates(true))) return r;
+
+    date[0] = weekday;
+    date[1] = BCD_FIRST(day)*10     + BCD_SECOND(day);
+    date[2] = BCD_FIRST(month)*10   + BCD_SECOND(month);
+    date[3] = BCD_FIRST(year)*10    + BCD_SECOND(year);
+
+    return SUCCESS;
+}

Property changes on: proj/libs/rtc/src/rtc.c
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: proj/libs/timer/include/timer.h
===================================================================
--- proj/libs/timer/include/timer.h	(nonexistent)
+++ proj/libs/timer/include/timer.h	(revision 284)
@@ -0,0 +1,14 @@
+/**
+ * This file concerns everything related to the timer
+ */
+
+#ifndef TIMER_H_INCLUDED
+#define TIMER_H_INCLUDED
+
+#define TIMER0_IRQ     0                                                                /**< @brief Timer 0 IRQ line */
+
+int (subscribe_timer_interrupt)(uint8_t interrupt_bit, int *interrupt_id);
+
+uint32_t no_interrupts;
+
+#endif //TIMER_H_INCLUDED

Property changes on: proj/libs/timer/include/timer.h
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: proj/libs/timer/src/timer.c
===================================================================
--- proj/libs/timer/src/timer.c	(nonexistent)
+++ proj/libs/timer/src/timer.c	(revision 284)
@@ -0,0 +1,66 @@
+#include <lcom/lcf.h>
+
+#include "timer.h"
+#include "graph.h"
+#include "sprite.h"
+
+#define TIMER_FREQ     1193182                                                          /**< @brief clock frequency for timer in PC and AT */
+#define TIMER_MIN_FREQ (TIMER_FREQ/UINT16_MAX) + ((TIMER_FREQ % UINT16_MAX) ? 1 : 0)    /**< @brief mininum frequency for timer */
+
+/* I/O port addresses */
+
+#define TIMER_0    0x40         /**< @brief Timer 0 count register */
+#define TIMER_1    0x41         /**< @brief Timer 1 count register */
+#define TIMER_2    0x42         /**< @brief Timer 2 count register */
+#define TIMER_CTRL 0x43         /**< @brief Control register */
+
+#define SPEAKER_CTRL 0x61       /**< @brief Register for speaker control  */
+
+/* Timer control */
+
+/* Timer selection: bits 7 and 6 */
+
+#define TIMER_SEL0   0x00              /**< @brief Control Word for Timer 0 */
+#define TIMER_SEL1   BIT(6)            /**< @brief Control Word for Timer 1 */
+#define TIMER_SEL2   BIT(7)            /**< @brief Control Word for Timer 2 */
+#define TIMER_RB_CMD (BIT(7) | BIT(6)) /**< @brief Read Back Command */
+
+/* Register selection: bits 5 and 4 */
+
+#define TIMER_LSB     BIT(4)                    /**< @brief Initialize Counter LSB only */
+#define TIMER_MSB     BIT(5)                    /**< @brief Initialize Counter MSB only */
+#define TIMER_LSB_MSB (TIMER_LSB | TIMER_MSB)   /**< @brief Initialize LSB first and MSB afterwards */
+#define TIMER_INMODE_MASK 0x30                  /**< @brief Mask for Timer Counter Mode */
+#define TIMER_INMODE_POS  4                     /**< @brief Bit position of Timer Counter Mode */
+
+/* Operating mode: bits 3, 2 and 1 */
+
+#define TIMER_SQR_WAVE (BIT(2) | BIT(1)) /**< @brief Mode 3: square wave generator */
+#define TIMER_RATE_GEN BIT(2)            /**< @brief Mode 2: rate generator */
+#define TIMER_MODE_MASK 0x0E             /**< @brief Mask for mode */
+#define TIMER_MODE_POS  1                /**< @brief Position of smallest bit from mode */
+#define TIMER_MODE_2ALT 0x6              /**< @brief Alternative notation for mode 2 */
+#define TIMER_MODE_3ALT 0x7              /**< @brief Alternative notation for mode 3 */
+#define TIMER_MODE_RED2 0x03             /**< @brief Reduce 3-bit mode to 2-bit mode */
+
+/* Counting mode: bit 0 */
+
+#define TIMER_BCD 0x01 /**< @brief Count in BCD */
+#define TIMER_BIN 0x00 /**< @brief Count in binary */
+
+/* READ-BACK COMMAND FORMAT */
+
+#define TIMER_RB_COUNT_  BIT(5)         /**< @brief Read counter value on read-back (0 to activate) */
+#define TIMER_RB_STATUS_ BIT(4)         /**< @brief Read status value on read-back (0 to activate) */
+#define TIMER_RB_SEL(n)  BIT((n) + 1)   /**< @brief Select timer to read information from */
+
+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));
+}
+
+uint32_t no_interrupts = 0;
+void (timer_int_handler)() {
+    no_interrupts++;
+}

Property changes on: proj/libs/timer/src/timer.c
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: proj/libs/uart/include/uart.h
===================================================================
--- proj/libs/uart/include/uart.h	(nonexistent)
+++ proj/libs/uart/include/uart.h	(revision 284)
@@ -0,0 +1,64 @@
+#ifndef UART_H_INCLUDED
+#define UART_H_INCLUDED
+
+#define COM1_ADDR           0x3F8
+#define COM2_ADDR           0x2F8
+#define COM1_IRQ            4
+#define COM2_IRQ            3
+#define COM1_VECTOR         0x0C
+#define COM2_VECTOR         0x0B
+
+typedef enum {
+    uart_parity_none = 0x0,
+    uart_parity_odd  = 0x1,
+    uart_parity_even = 0x3,
+    uart_parity_par1 = 0x5,
+    uart_parity_par0 = 0x7
+} uart_parity;
+
+typedef struct {
+    int     base_addr               ;
+    uint8_t lcr                     ;
+    uint8_t dll                     ;
+    uint8_t dlm                     ;
+    uint8_t bits_per_char           ;
+    uint8_t stop_bits               ;
+    uart_parity parity              ;
+    uint8_t break_control         :1;
+    uint8_t dlab                  :1;
+    uint16_t divisor_latch          ;
+    uint8_t ier                     ;
+    uint8_t received_data_int     :1;
+    uint8_t transmitter_empty_int :1;
+    uint8_t receiver_line_stat_int:1;
+    uint8_t modem_stat_int        :1;
+} uart_config;
+
+int (subscribe_uart_interrupt)(uint8_t interrupt_bit, int *interrupt_id);
+
+int uart_get_config(int base_addr, uart_config *config);
+void uart_print_config(uart_config config);
+
+int uart_set_bits_per_character(int base_addr, uint8_t     bits_per_char);
+int uart_set_stop_bits         (int base_addr, uint8_t     stop         );
+int uart_set_parity            (int base_addr, uart_parity par          );
+int uart_set_bit_rate          (int base_addr, float       bit_rate     );
+
+int uart_enable_int_rx (int base_addr);
+int uart_disable_int_rx(int base_addr);
+int uart_enable_int_tx (int base_addr);
+int uart_disable_int_tx(int base_addr);
+
+/// NCTP - Non-critical transmission protocol
+int nctp_init(void);
+int nctp_free(void);
+
+int nctp_send(size_t num, uint8_t* ptr[], size_t sz[]);
+
+int nctp_ih_err;
+void nctp_ih(void);
+
+/// HLTP - High-level transmission protocol
+int hltp_send_string(const char *p);
+
+#endif //UART_H_INCLUDED

Property changes on: proj/libs/uart/include/uart.h
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: proj/libs/uart/src/uart.c
===================================================================
--- proj/libs/uart/src/uart.c	(nonexistent)
+++ proj/libs/uart/src/uart.c	(revision 284)
@@ -0,0 +1,379 @@
+#include <lcom/lcf.h>
+
+#include "uart.h"
+
+#include "queue.h"
+#include "errors.h"
+
+#define UART_BITRATE                            115200
+#define UART_WAIT                               20 //microseconds
+
+#define UART_RBR                                0
+#define UART_THR                                0
+#define UART_IER                                1
+#define UART_IIR                                2
+#define UART_FCR                                2
+#define UART_LCR                                3
+#define UART_MCR                                4
+#define UART_LSR                                5
+#define UART_MSR                                6
+#define UART_SR                                 7
+
+#define UART_DLL                                0
+#define UART_DLM                                1
+
+/// LCR
+#define UART_BITS_PER_CHAR_POS                  0
+#define UART_STOP_BITS_POS                      2
+#define UART_PARITY_POS                         3
+#define UART_BREAK_CONTROL_POS                  6
+#define UART_DLAB_POS                           7
+
+#define UART_BITS_PER_CHAR                      (BIT(0) | BIT(1))
+#define UART_STOP_BITS                          (BIT(2))
+#define UART_PARITY                             (BIT(3) | BIT(4) | BIT(5))
+#define UART_BREAK_CONTROL                      (BIT(6))
+#define UART_DLAB                               (BIT(7))
+
+#define UART_GET_BITS_PER_CHAR(n)               (((n)&UART_BITS_PER_CHAR) + 5)
+#define UART_GET_STOP_BITS(n)                   (((n)&UART_STOP_BITS)? 2 : 1)
+#define UART_GET_PARITY(n)                      (((n)&UART_PARITY       )>>UART_PARITY_POS       )
+#define UART_GET_BREAK_CONTROL(n)               (((n)&UART_BREAK_CONTROL)>>UART_BREAK_CONTROL_POS)
+#define UART_GET_DLAB(n)                        (((n)&UART_DLAB         )>>UART_DLAB_POS         )
+#define UART_GET_DIV_LATCH(m,l)                 ((m)<<8 | (l))
+#define UART_GET_DLL(n)                         ((n)&0xFF)
+#define UART_GET_DLM(n)                         (((n)>>8)&0xFF)
+
+/// IER
+#define UART_INT_EN_RX_POS                      0
+#define UART_INT_EN_TX_POS                      1
+#define UART_INT_EN_RECEIVER_LINE_STAT_POS      2
+#define UART_INT_EN_MODEM_STAT_POS              3
+
+#define UART_INT_EN_RX                          (BIT(0))
+#define UART_INT_EN_TX                          (BIT(1))
+#define UART_INT_EN_RECEIVER_LINE_STAT          (BIT(2))
+#define UART_INT_EN_MODEM_STAT                  (BIT(3))
+
+#define UART_GET_INT_EN_RX(n)                   (((n)&UART_INT_EN_RX                )>>UART_INT_EN_RX_POS                )
+#define UART_GET_INT_EN_TX(n)                   (((n)&UART_INT_EN_TX                )>>UART_INT_EN_TX_POS                )
+#define UART_GET_INT_EN_RECEIVER_LINE_STAT(n)   (((n)&UART_INT_EN_RECEIVER_LINE_STAT)>>UART_INT_EN_RECEIVER_LINE_STAT_POS)
+#define UART_GET_INT_EN_MODEM_STAT(n)           (((n)&UART_INT_EN_MODEM_STAT        )>>UART_INT_EN_MODEM_STAT_POS        )
+
+/// LSR
+#define UART_RECEIVER_READY_POS                 0
+#define UART_OVERRUN_ERROR_POS                  1
+#define UART_PARITY_ERROR_POS                   2
+#define UART_FRAMING_ERROR_POS                  3
+#define UART_TRANSMITTER_EMPTY_POS              5
+
+#define UART_RECEIVER_READY                     (BIT(0))
+#define UART_OVERRUN_ERROR                      (BIT(1))
+#define UART_PARITY_ERROR                       (BIT(2))
+#define UART_FRAMING_ERROR                      (BIT(3))
+#define UART_TRANSMITTER_EMPTY                  (BIT(5))
+
+#define UART_GET_RECEIVER_READY(n)              (((n)&UART_RECEIVER_READY           )>>UART_RECEIVER_READY_POS           )
+#define UART_GET_OVERRUN_ERROR                  (((n)&UART_OVERRUN_ERROR            )>>UART_OVERRUN_ERROR_POS            )
+#define UART_GET_PARITY_ERROR                   (((n)&UART_PARITY_ERROR             )>>UART_PARITY_ERROR_POS             )
+#define UART_GET_FRAMING_ERROR                  (((n)&UART_FRAMING_ERROR            )>>UART_FRAMING_ERROR_POS            )
+#define UART_GET_TRANSMITTER_EMPTY(n)           (((n)&UART_TRANSMITTER_EMPTY        )>>UART_TRANSMITTER_EMPTY_POS        )
+
+/// IIR
+#define UART_INT_PEND_POS                       1
+
+#define UART_INT_PEND                           (BIT(3)|BIT(2)|BIT(1))
+
+#define UART_GET_IF_INT_PEND(n)                 (!((n)&1))
+typedef enum {
+    uart_int_receiver_line_stat = (         BIT(1) | BIT(0)),
+    uart_int_rx                 = (         BIT(1)         ),
+    uart_int_char_timeout_fifo  = (BIT(2) | BIT(1)         ),
+    uart_int_tx                 = (                  BIT(0)),
+    uart_int_modem_stat         = (0)
+} uart_int_code;
+#define UART_GET_INT_PEND(n)                    ((uart_int_code)(((n)&UART_INT_PEND)>>UART_INT_PEND_POS))
+
+int (subscribe_uart_interrupt)(uint8_t interrupt_bit, int *interrupt_id) {
+    if (interrupt_id == NULL) return 1;
+    *interrupt_id = interrupt_bit;
+    return (sys_irqsetpolicy(COM1_IRQ, IRQ_REENABLE | IRQ_EXCLUSIVE, interrupt_id));
+}
+
+static void uart_parse_config(uart_config *config){
+    /// LCR
+    config->bits_per_char          = UART_GET_BITS_PER_CHAR     (config->lcr);
+    config->stop_bits              = UART_GET_STOP_BITS         (config->lcr);
+    config->parity                 = UART_GET_PARITY            (config->lcr); if((config->parity & BIT(0)) == 0) config->parity = uart_parity_none;
+    config->break_control          = UART_GET_BREAK_CONTROL     (config->lcr);
+    config->dlab                   = UART_GET_DLAB              (config->lcr);
+    /// IER
+    config->received_data_int      = UART_GET_INT_EN_RX                (config->ier);
+    config->transmitter_empty_int  = UART_GET_INT_EN_TX                (config->ier);
+    config->receiver_line_stat_int = UART_GET_INT_EN_RECEIVER_LINE_STAT(config->ier);
+    config->modem_stat_int         = UART_GET_INT_EN_MODEM_STAT        (config->ier);
+    /// DIV LATCH
+    config->divisor_latch          = UART_GET_DIV_LATCH(config->dlm, config->dll);
+}
+
+static int uart_get_lcr(int base_addr, uint8_t *p){
+    return util_sys_inb(base_addr+UART_LCR, p);
+}
+static int uart_set_lcr(int base_addr, uint8_t config){
+    if(sys_outb(base_addr+UART_LCR, config)) return WRITE_ERROR;
+    return SUCCESS;
+}
+static int uart_get_lsr(int base_addr, uint8_t *p){
+    return util_sys_inb(base_addr+UART_LSR, p);
+}
+static int uart_get_iir(int base_addr, uint8_t *p){
+    return util_sys_inb(base_addr+UART_IIR, p);
+}
+
+static int uart_enable_divisor_latch(int base_addr){
+    int ret = SUCCESS;
+    uint8_t conf; if((ret = uart_get_lcr(base_addr, &conf))) return ret;
+    return uart_set_lcr(base_addr, conf | UART_DLAB);
+}
+static int uart_disable_divisor_latch(int base_addr){
+    int ret = SUCCESS;
+    uint8_t conf; if((ret = uart_get_lcr(base_addr, &conf))) return ret;
+    return uart_set_lcr(base_addr, conf & (~UART_DLAB));
+}
+
+static int uart_get_ier(int base_addr, uint8_t *p){
+    int ret;
+    if((ret = uart_disable_divisor_latch(base_addr))) return ret;
+    return util_sys_inb(base_addr+UART_IER, p);
+}
+static int uart_set_ier(int base_addr, uint8_t n){
+    int ret;
+    if((ret = uart_disable_divisor_latch(base_addr))) return ret;
+    if(sys_outb(base_addr+UART_IER, n)) return WRITE_ERROR;
+    return SUCCESS;
+}
+
+int uart_get_config(int base_addr, uart_config *config){
+    int ret = SUCCESS;
+
+    config->base_addr = base_addr;
+
+    if((ret = uart_get_lcr(base_addr, &config->lcr))) return ret;
+
+    if((ret = uart_get_ier(base_addr, &config->ier))) return ret;
+
+    if((ret = uart_enable_divisor_latch (base_addr))) return ret;
+    if((ret = util_sys_inb(base_addr+UART_DLL, &config->dll   ))) return ret;
+    if((ret = util_sys_inb(base_addr+UART_DLM, &config->dlm   ))) return ret;
+    if((ret = uart_disable_divisor_latch(base_addr))) return ret;
+
+    uart_parse_config(config);
+    return ret;
+}
+void uart_print_config(uart_config config){
+
+    printf("%s configuration:\n", (config.base_addr == COM1_ADDR ? "COM1" : "COM2"));
+    printf("\tLCR = 0x%X: %d bits per char\t %d stop bits\t", config.lcr, config.bits_per_char, config.stop_bits);
+    if((config.parity&BIT(0)) == 0) printf("NO parity\n");
+    else switch(config.parity){
+        case uart_parity_odd : printf("ODD parity\n"     ); break;
+        case uart_parity_even: printf("EVEN parity\n"    ); break;
+        case uart_parity_par1: printf("parity bit is 1\n"); break;
+        case uart_parity_par0: printf("parity bit is 0\n"); break;
+        default              : printf("invalid\n"        ); break;
+    }
+    printf("\tDLM = 0x%02X DLL=0x%02X: bitrate = %d bps\n", config.dlm, config.dll, UART_BITRATE/config.divisor_latch);
+    printf("\tIER = 0x%02X: Rx interrupts: %s\tTx interrupts: %s\n", config.ier,
+        (config.received_data_int     ? "ENABLED":"DISABLED"),
+        (config.transmitter_empty_int ? "ENABLED":"DISABLED"));
+}
+
+int uart_set_bits_per_character(int base_addr, uint8_t bits_per_char){
+    if(bits_per_char < 5 || bits_per_char > 8) return INVALID_ARG;
+    int ret = SUCCESS;
+    bits_per_char = (bits_per_char-5)&0x3;
+    uint8_t conf; if((ret = uart_get_lcr(base_addr, &conf))) return ret;
+    conf = (conf & (~UART_BITS_PER_CHAR)) | bits_per_char;
+    return uart_set_lcr(base_addr, conf);
+}
+int uart_set_stop_bits(int base_addr, uint8_t stop){
+    if(stop != 1 && stop != 2) return INVALID_ARG;
+    int ret = SUCCESS;
+    stop -= 1;
+    stop = (stop&1)<<2;
+    uint8_t conf; if((ret = uart_get_lcr(base_addr, &conf))) return ret;
+    conf = (conf & (~UART_STOP_BITS)) | stop;
+    return uart_set_lcr(base_addr, conf);
+}
+int uart_set_parity(int base_addr, uart_parity par){
+    int ret = SUCCESS;
+    uint8_t parity = par << 3;
+    uint8_t conf; if((ret = uart_get_lcr(base_addr, &conf))) return ret;
+    conf = (conf & (~UART_PARITY)) | parity;
+    return uart_set_lcr(base_addr, conf);
+}
+int uart_set_bit_rate(int base_addr, float bit_rate){
+    int ret = SUCCESS;
+    uint16_t latch = UART_BITRATE/bit_rate;
+    uint8_t dll = UART_GET_DLL(latch);
+    uint8_t dlm = UART_GET_DLM(latch);
+    if((ret = uart_enable_divisor_latch(base_addr))) return ret;
+    if(sys_outb(base_addr+UART_DLL, dll)) return WRITE_ERROR;
+    if(sys_outb(base_addr+UART_DLM, dlm)) return WRITE_ERROR;
+    if((ret = uart_disable_divisor_latch(base_addr))) return ret;
+    return SUCCESS;
+}
+
+static int uart_get_char(int base_addr, uint8_t *p){
+    int ret;
+    if((ret = uart_disable_divisor_latch(base_addr))) return ret;
+    return util_sys_inb(base_addr+UART_RBR, p);
+}
+static int uart_send_char(int base_addr, uint8_t c){
+    int ret;
+    if((ret = uart_disable_divisor_latch(base_addr))) return ret;
+    if(sys_outb(base_addr+UART_THR, c)) return WRITE_ERROR;
+    return SUCCESS;
+}
+static int uart_receiver_ready(int base_addr){
+    uint8_t lsr;
+    if(uart_get_lsr(base_addr, &lsr)) return false;
+    return UART_GET_RECEIVER_READY(lsr);
+}
+static int uart_transmitter_empty(int base_addr){
+    uint8_t lsr;
+    if(uart_get_lsr(base_addr, &lsr)) return false;
+    return UART_GET_TRANSMITTER_EMPTY(lsr);
+}
+
+int uart_enable_int_rx(int base_addr){
+    int ret;
+    uint8_t ier;
+    if((ret = uart_get_ier(base_addr, &ier))) return ret;
+    ier |= UART_INT_EN_RX;
+    return uart_set_ier(base_addr, ier);
+}
+int uart_disable_int_rx(int base_addr){
+    int ret;
+    uint8_t ier;
+    if((ret = uart_get_ier(base_addr, &ier))) return ret;
+    ier &= ~UART_INT_EN_RX;
+    return uart_set_ier(base_addr, ier);
+}
+int uart_enable_int_tx(int base_addr){
+    int ret;
+    uint8_t ier;
+    if((ret = uart_get_ier(base_addr, &ier))) return ret;
+    ier |= UART_INT_EN_TX;
+    return uart_set_ier(base_addr, ier);
+}
+int uart_disable_int_tx(int base_addr){
+    int ret;
+    uint8_t ier;
+    if((ret = uart_get_ier(base_addr, &ier))) return ret;
+    ier &= ~UART_INT_EN_TX;
+    return uart_set_ier(base_addr, ier);
+}
+
+/// NCTP
+
+#define NCTP_START      0x80
+#define NCTP_END        0xFF
+#define NCTP_OK         0xFF
+#define NCTP_NOK        0x00
+
+queue_t *out = NULL;
+queue_t *in  = NULL;
+
+int nctp_init(void){
+    out = queue_ctor(); if(out == NULL) return NULL_PTR;
+    in  = queue_ctor(); if(in  == NULL) return NULL_PTR;
+    return SUCCESS;
+}
+int nctp_free(void){
+    while(!queue_empty(out)){
+        free(queue_top(out));
+        queue_pop(out);
+    }
+    while(!queue_empty(in)){
+        free(queue_top(in));
+        queue_pop(in);
+    }
+    return SUCCESS;
+}
+
+int nctp_send(size_t num, uint8_t* ptr[], size_t sz[]){
+    {
+        size_t cnt = 0;
+        for(size_t i = 0; i < num; ++i){
+            cnt += sz[i];
+            if(cnt > queue_max_size) return TRANS_REFUSED;
+        }
+    }
+    int ret;
+    uint8_t *tmp;
+    tmp = malloc(sizeof(uint8_t)); *tmp = NCTP_START; queue_push(out, tmp);
+    for(size_t i = 0; i < num; ++i){
+        uint8_t *p = ptr[i]; size_t s = sz[i];
+        for(size_t j = 0; j < s; ++j, ++p){
+            tmp = malloc(sizeof(uint8_t)); *tmp = *p; queue_push(out, tmp);
+        }
+    }
+    tmp = malloc(sizeof(uint8_t)); *tmp = NCTP_END; queue_push(out, tmp);
+    if(uart_transmitter_empty(COM1_ADDR)){
+        if((ret = uart_send_char(COM1_ADDR, *(uint8_t*)queue_top(out)))) return ret;
+        queue_pop(out);
+    }
+    return SUCCESS;
+}
+
+static int nctp_transmit(void){
+    if(!queue_empty(out)){
+        int ret = uart_send_char(COM1_ADDR, *(uint8_t*)queue_top(out));
+        queue_pop(out);
+        return ret;
+    }else return SUCCESS;
+}
+
+static void process(){
+    free(queue_top(in)); queue_pop(in);
+    while(*(uint8_t*)queue_top(in) != NCTP_END){
+        printf("%c", *(uint8_t*)queue_top(in));
+        free(queue_top(in)); queue_pop(in);
+    }
+    printf("\n");
+    free(queue_top(in)); queue_pop(in);
+}
+static int nctp_receive(void){
+    int ret;
+    uint8_t c;
+    int num_ends = 0;
+    while(uart_receiver_ready(COM1_ADDR)){
+        if((ret = uart_get_char(COM1_ADDR, &c))) return ret;
+        uint8_t *tmp = malloc(sizeof(uint8_t)); *tmp = c;
+        queue_push(in, tmp);
+        if(c == NCTP_END) ++num_ends;
+    }
+    while(num_ends-- > 0) process();
+    return SUCCESS;
+}
+
+int nctp_ih_err = SUCCESS;
+void nctp_ih(void){
+    uint8_t iir;
+    if((nctp_ih_err = uart_get_iir(COM1_ADDR, &iir))) return;
+    if(UART_GET_IF_INT_PEND(iir)){
+        switch(UART_GET_INT_PEND(iir)){
+            case uart_int_rx: nctp_receive (); break;
+            case uart_int_tx: nctp_transmit(); break;
+            default: break;
+        }
+    }
+}
+
+/// HLTP
+int hltp_send_string(const char *p){
+    uint8_t* ptr[1]; ptr[0] = (uint8_t*)p;
+    size_t    sz[1]; sz[0] = strlen(p)+1;
+    return nctp_send(1, ptr, sz);
+}

Property changes on: proj/libs/uart/src/uart.c
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: proj/DR.mk
===================================================================
--- proj/DR.mk	(revision 283)
+++ proj/DR.mk	(revision 284)
@@ -1,14 +1,19 @@
 PROG=proj
 
 .PATH: ${.CURDIR}/src
-.PATH: ${.CURDIR}/libs/peripherals/src
+.PATH: ${.CURDIR}/libs/graph/src
+.PATH: ${.CURDIR}/libs/kbc/src
+.PATH: ${.CURDIR}/libs/rtc/src
+.PATH: ${.CURDIR}/libs/timer/src
+.PATH: ${.CURDIR}/libs/uart/src
 .PATH: ${.CURDIR}/libs/classes/src
 .PATH: ${.CURDIR}/libs/utils/src
 
 SRCS= proj.c list.c queue.c graph.c kbc.c keyboard.c mouse.c utils.c timer.c interrupts_func.c proj_func.c fast_math.c rectangle.c font.c xpm_utils.c ent.c rtc.c uart.c makecode_map.c
-IPATHS=-I./include -I./libs/peripherals/include -I./libs/classes/include -I./libs/utils/include -I./maps -I./media/xpm
+IPATHS=-I./include -I./libs/graph/include -I./libs/kbc/include -I./libs/rtc/include -I./libs/timer/include -I./libs/uart/include -I./libs/classes/include -I./libs/utils/include -I./maps -I./media/xpm
 
-CPPFLAGS += -pedantic ${IPATHS} -D LCOM_MACRO -D DIOGO #-D __LCOM_OPTIMIZED_
+CPPFLAGS += -pedantic ${IPATHS} -D LCOM_MACRO #-D __LCOM_OPTIMIZED_
+CPPFLAGS += -D DIOGO
 
 DPADD += ${LIBLCF}
 LDADD += -llcf
Index: proj/Makefile
===================================================================
--- proj/Makefile	(revision 283)
+++ proj/Makefile	(revision 284)
@@ -1,11 +1,20 @@
 PROG=proj
 
 .PATH: ${.CURDIR}/src
+.PATH: ${.CURDIR}/libs/graph/src
+.PATH: ${.CURDIR}/libs/kbc/src
+.PATH: ${.CURDIR}/libs/rtc/src
+.PATH: ${.CURDIR}/libs/timer/src
+.PATH: ${.CURDIR}/libs/uart/src
+.PATH: ${.CURDIR}/libs/classes/src
+.PATH: ${.CURDIR}/libs/utils/src
 
-SRCS= proj.c list.c queue.c graph.c kbc.c keyboard.c mouse.c utils.c timer.c interrupts_func.c proj_func.c fast_math.c rectangle.c font.c xpm_utils.c ent.c rtc.c uart.c hltp.c makecode_map.c
+SRCS= proj.c list.c queue.c graph.c kbc.c keyboard.c mouse.c utils.c timer.c interrupts_func.c proj_func.c fast_math.c rectangle.c font.c xpm_utils.c ent.c rtc.c uart.c makecode_map.c
+IPATHS=-I./include -I./libs/graph/include -I./libs/kbc/include -I./libs/rtc/include -I./libs/timer/include -I./libs/uart/include -I./libs/classes/include -I./libs/utils/include -I./maps -I./media/xpm
 
-CPPFLAGS += -pedantic -I./include -I./maps -I./media/xpm -D LCOM_MACRO -D __LCOM_OPTIMIZED_
+CPPFLAGS += -pedantic ${IPATHS} -D LCOM_MACRO #-D __LCOM_OPTIMIZED_
 
+
 DPADD += ${LIBLCF}
 LDADD += -llcf
 
Index: proj/TB.mk
===================================================================
--- proj/TB.mk	(revision 283)
+++ proj/TB.mk	(revision 284)
@@ -1,10 +1,19 @@
 PROG=proj
 
 .PATH: ${.CURDIR}/src
+.PATH: ${.CURDIR}/libs/graph/src
+.PATH: ${.CURDIR}/libs/kbc/src
+.PATH: ${.CURDIR}/libs/rtc/src
+.PATH: ${.CURDIR}/libs/timer/src
+.PATH: ${.CURDIR}/libs/uart/src
+.PATH: ${.CURDIR}/libs/classes/src
+.PATH: ${.CURDIR}/libs/utils/src
 
-SRCS= proj.c list.c queue.c graph.c kbc.c keyboard.c mouse.c utils.c timer.c interrupts_func.c proj_func.c fast_math.c rectangle.c font.c xpm_utils.c ent.c rtc.c uart.c hltp.c makecode_map.c
+SRCS= proj.c list.c queue.c graph.c kbc.c keyboard.c mouse.c utils.c timer.c interrupts_func.c proj_func.c fast_math.c rectangle.c font.c xpm_utils.c ent.c rtc.c uart.c makecode_map.c
+IPATHS=-I./include -I./libs/graph/include -I./libs/kbc/include -I./libs/rtc/include -I./libs/timer/include -I./libs/uart/include -I./libs/classes/include -I./libs/utils/include -I./maps -I./media/xpm
 
-CPPFLAGS += -pedantic -I./include -I./maps -I./media/xpm -D LCOM_MACRO -D TELMO #-D __LCOM_OPTIMIZED_
+CPPFLAGS += -pedantic ${IPATHS} -D LCOM_MACRO #-D __LCOM_OPTIMIZED_
+CPPFLAGS += -D TELMO
 
 DPADD += ${LIBLCF}
 LDADD += -llcf
