Index: proj/keyboard.c
===================================================================
--- proj/keyboard.c	(revision 176)
+++ proj/keyboard.c	(nonexistent)
@@ -1,61 +0,0 @@
-#include <lcom/lcf.h>
-
-#include "keyboard.h"
-
-#include "kbc.h"
-#include "kbc_macros.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_movement();
-
-}
-
-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/keyboard.c
___________________________________________________________________
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Index: proj/fast_math.c
===================================================================
--- proj/fast_math.c	(revision 176)
+++ proj/fast_math.c	(nonexistent)
@@ -1,27 +0,0 @@
-#include "fast_math.h"
-
-#include <math.h>
-
-double fm_sin(double x){
-    if(x < 0.0)         return -fm_sin(-x);
-    if(x > 2.0*M_PI) return fm_sin(x-2.0*M_PI);
-    if(x > M_PI)      return -fm_sin(x-M_PI);
-    if(x > 0.5*M_PI) x = M_PI - x;
-    double x2 = x*x;
-    double x3 = x*x2;
-    double x5 = x3*x2;
-    //double x7 = x5*x2;
-    return x-x3*0.1666666666666666666666+x5*0.008333333333333333333333;//-x7*0.0001984126984127;
-}
-
-double fm_cos(double x){
-    if(x < 0.0)         x = -x;
-    if(x > 2.0*M_PI) return fm_cos(x-2.0*M_PI);
-    if(x > M_PI)      x = 2.0*M_PI-x;
-    if(x > 0.5*M_PI) return -fm_cos(M_PI-x);
-    double x2 = x*x;
-    double x4 = x2*x2;
-    double x6 = x4*x2;
-    //double x8 = x4*x4;
-    return 1.0-x2*0.5+x4*0.041666666666666666666666-x6*0.0013888888888888888888888;//+x8*0.000024801587;
-}

Property changes on: proj/fast_math.c
___________________________________________________________________
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Index: proj/utils.c
===================================================================
--- proj/utils.c	(revision 176)
+++ proj/utils.c	(nonexistent)
@@ -1,35 +0,0 @@
-#include <lcom/lcf.h>
-
-#include "utils.h"
-
-#include <stdint.h>
-#include "errors.h"
-
-int(util_get_LSB)(uint16_t val, uint8_t *lsb) {
-    if (lsb == NULL) return NULL_PTR;
-    *lsb = val;
-    return SUCCESS;
-}
-
-int(util_get_MSB)(uint16_t val, uint8_t *msb) {
-    if (msb == NULL) return NULL_PTR;
-    *msb = (val >> 8);
-    return SUCCESS;
-}
-
-int (util_sys_inb)(int port, uint8_t *value) {
-    if(value == NULL) return NULL_PTR;
-    uint32_t n = 0;
-    if(sys_inb(port, &n)) return READ_ERROR;
-    *value = n;
-    return SUCCESS;
-}
-
-int (unsubscribe_interrupt)(int *interrupt_id) {
-    if (interrupt_id == NULL) return NULL_PTR;
-    if(sys_irqrmpolicy(interrupt_id)) return UNSBCR_ERROR;
-    return SUCCESS;
-}
-
-int32_t min(int32_t a, int32_t b){ return (b < a ? b : a); }
-int32_t max(int32_t a, int32_t b){ return (a < b ? b : a); }

Property changes on: proj/utils.c
___________________________________________________________________
Deleted: svn:executable
Index: proj/timer.c
===================================================================
--- proj/timer.c	(revision 176)
+++ proj/timer.c	(nonexistent)
@@ -1,16 +0,0 @@
-#include <lcom/lcf.h>
-
-#include "timer.h"
-
-#include "i8254.h"
-
-int (subscribe_timer_interrupt)(uint8_t interrupt_bit, int *interrupt_id) {
-    if (interrupt_id == NULL) return 1;
-    *interrupt_id = interrupt_bit;
-    return (sys_irqsetpolicy(TIMER0_IRQ, IRQ_REENABLE, interrupt_id));
-}
-
-uint32_t no_interrupts = 0;
-void (timer_int_handler)() {
-    no_interrupts++;
-}

Property changes on: proj/timer.c
___________________________________________________________________
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Index: proj/graph.c
===================================================================
--- proj/graph.c	(revision 176)
+++ proj/graph.c	(nonexistent)
@@ -1,296 +0,0 @@
-#include "graph.h"
-#include "graph_macros.h"
-#include "errors.h"
-
-#include <lcom/lcf.h>
-
-#include <stdio.h>
-
-/// 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;
-
-/// PUBLIC GET
-uint16_t   (graph_get_XRes)         (void){ return vbe_mem_info.XResolution; }
-uint16_t   (graph_get_YRes)         (void){ return vbe_mem_info.YResolution; }
-
-/// PRIVATE GET
-static uint16_t   (graph_get_bits_pixel)   (void){ return vbe_mem_info.BitsPerPixel; }
-static uint16_t   (graph_get_bytes_pixel)  (void){ return (graph_get_bits_pixel() + 7) >> 3; }
-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 ; }
-
-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 void    *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) {
-    if (x >= vbe_mem_info.XResolution || y >= vbe_mem_info.YResolution) {
-        //printf("%s: invalid pixel.\n", __func__);
-        return OUT_OF_RANGE;
-    }
-    unsigned int pos = (x + y * vbe_mem_info.XResolution) * graph_get_bytes_pixel();
-    memcpy(video_buf + pos, &color, graph_get_bytes_pixel());
-    return SUCCESS;
-}
-int (graph_set_pixel_alpha)(uint16_t x, uint16_t y, uint32_t color, uint8_t alpha){
-    if (x >= vbe_mem_info.XResolution || y >= vbe_mem_info.YResolution) {
-        //printf("%s: invalid pixel.\n", __func__);
-        return OUT_OF_RANGE;
-    }
-    unsigned int pos = (x + y * vbe_mem_info.XResolution) * graph_get_bytes_pixel();
-    uint32_t color_;
-    memcpy(&color_, video_buf + pos, graph_get_bytes_pixel());
-    float a = 1.0-(alpha&0xFF)/(float)0xFF;
-    uint8_t r = GET_RED(color)*a + GET_RED(color_)*(1.0-a);
-    uint8_t g = GET_GRE(color)*a + GET_GRE(color_)*(1.0-a);
-    uint8_t b = GET_BLU(color)*a + GET_BLU(color_)*(1.0-a);
-    return graph_set_pixel(x,y,SET_RGB(r,g,b));
-    //return set_pixel(x,y,color);
-}
-
-int (graph_clear_screen)(void){
-    //return graph_paint_screen(BLACK);
-    memset(video_buf, 0, graph_get_vram_size());
-    return SUCCESS;
-}
-
-int (graph_draw)(void){
-    memcpy((uint8_t*)video_mem, video_buf, graph_get_vram_size());
-    return 0;
-}
-
-/// RECTANGLE
-int (graph_draw_hline)(uint16_t x, uint16_t y, uint16_t len, uint32_t color){
-    int r;
-    for (uint16_t i = 0; i < len; i++)
-        if ((r = graph_set_pixel(x + i, y, color))) return r;
-    return SUCCESS;
-}
-
-int (graph_draw_rectangle)(uint16_t x, uint16_t y,uint16_t width, uint16_t height, uint32_t color)	{
-    int r;
-    for (uint16_t i = 0; i < height; i++)
-        if ((r = graph_draw_hline(x, y + i, width, color))) return r;
-    return SUCCESS;
-}

Property changes on: proj/graph.c
___________________________________________________________________
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Index: proj/proj_func.c
===================================================================
--- proj/proj_func.c	(revision 176)
+++ proj/proj_func.c	(nonexistent)
@@ -1,66 +0,0 @@
-#include <lcom/lcf.h>
-
-#include "proj_func.h"
-
-#include "interrupts_func.h"
-#include "graph.h"
-#include "keyboard.h"
-#include "errors.h"
-#include "proj_macros.h"
-#include "utils.h"
-
-#include "kbc_macros.h"
-
-#include <math.h>
-
-int cleanup(void) {
-    int r = SUCCESS;
-    if ((r = unsubscribe_all()))
-        printf("%s: failed to unsubscribe drivers.\n", __func__);
-    if ((r = graph_cleanup()))
-        printf("%s: graph cleanup failed\n", __func__);
-
-    return r;
-}
-
-static int hor_mov = REST, ver_mov = REST;
-
-void update_movement(void) {
-    static int w_pressed = 0, a_pressed = 0, s_pressed = 0, d_pressed = 0;
-    if (sz == 1) {
-        switch(scancode[0]) {
-        case W_MAKE_CODE  : w_pressed = 1;      break;
-        case W_BREAK_CODE : w_pressed = 0;      break;
-        case A_MAKE_CODE  : a_pressed = 1;      break;
-        case A_BREAK_CODE : a_pressed = 0;      break;
-        case S_MAKE_CODE  : s_pressed = 1;      break;
-        case S_BREAK_CODE : s_pressed = 0;      break;
-        case D_MAKE_CODE  : d_pressed = 1;      break;
-        case D_BREAK_CODE : d_pressed = 0;      break;
-        }
-    }
-    ver_mov = s_pressed - w_pressed;
-    hor_mov = d_pressed - a_pressed;
-}
-
-static int32_t mouse_x = 0, mouse_y = 0;
-
-void update_mouse_position(struct packet *p) {
-    mouse_x = max(0, mouse_x + p->delta_x);
-    mouse_x = min(mouse_x, graph_get_XRes() - 1);
-
-    mouse_y = max(0, mouse_y - p->delta_y);
-    mouse_y = min(mouse_y, graph_get_YRes() - 1);
-}
-
-int32_t get_mouse_X(void) { return mouse_x; }
-
-int32_t get_mouse_Y(void) { return mouse_y; }
-
-double get_mouse_angle(sprite_t *p) {
-    return atan2(sprite_get_y(p) - mouse_y, mouse_x - sprite_get_x(p));
-}
-
-int get_hor_movement(void) { return hor_mov; }
-
-int get_ver_movement(void) { return ver_mov; }

Property changes on: proj/proj_func.c
___________________________________________________________________
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Index: proj/sprite.c
===================================================================
--- proj/sprite.c	(revision 176)
+++ proj/sprite.c	(nonexistent)
@@ -1,76 +0,0 @@
-#include <lcom/lcf.h>
-
-#include "sprite.h"
-
-#include "graph.h"
-#include "utils.h"
-#include "fast_math.h"
-#include <math.h>
-
-struct sprite{
-    int16_t x, y;
-    uint16_t w, h;
-    int16_t u0, v0;
-    float theta;
-    uint8_t *map;
-};
-
-sprite_t* (sprite_ctor)(const char **xpm, int u0, int v0){
-    sprite_t *ret = (sprite_t*)malloc(sizeof(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){
-        free(ret);
-        return NULL;
-    }
-    ret->x = 0;
-    ret->y = 0;
-    ret->w = img.width;
-    ret->h = img.height;
-    ret->u0 = u0;
-    ret->v0 = u0;
-    ret->theta = 0;
-    return ret;
-}
-void (sprite_dtor)(sprite_t *p){
-    if(p == NULL) return;
-    if(p->map) free(p->map);
-    free(p);
-}
-
-void (sprite_set_x)     (sprite_t *p, int16_t x){ p->x = x; }
-void (sprite_set_y)     (sprite_t *p, int16_t y){ p->y = y; }
-void (sprite_set_pos)   (sprite_t *p, int16_t x, int16_t y){ sprite_set_x(p, x); sprite_set_y(p, y); }
-void (sprite_set_angle) (sprite_t *p, double angle){ p->theta = angle; }
-void (sprite_set_center)(sprite_t *p, int16_t u0, int16_t v0){ p->u0 = u0; p->v0 = v0; }
-
-int sprite_get_x(const sprite_t *p){ return p->x; }
-int sprite_get_y(const sprite_t *p){ return p->y; }
-int sprite_get_w(const sprite_t *p){ return p->w; }
-int sprite_get_h(const sprite_t *p){ return p->h; }
-
-void (sprite_src2pic)(const sprite_t *p, int16_t x, int16_t y, int16_t *u, int16_t *v){
-    int16_t dx = x - p->x;
-    int16_t dy = y - p->y;
-    double s = fm_sin(p->theta);
-    double c = fm_cos(p->theta);
-    *u = dx*c - dy*s + p->u0;
-    *v = dx*s + dy*c + p->v0;
-}
-
-void (sprite_draw)(const sprite_t *p){
-    const int16_t diag = sqrt(p->w*p->w + p->h*p->h)+2;
-    int16_t u, v;
-    for(int16_t y = max(0,p->y-diag); y < min(p->y+diag,graph_get_YRes()); ++y){
-        for(int16_t x = max(0,p->x-diag); x < min(p->x+diag,graph_get_XRes()); ++x){
-            sprite_src2pic(p, x, y, &u, &v);
-            if(0 <= u && u < p->w && 0 <= v && v < p->h){
-                uint8_t *m = p->map + (v*p->w + u)*4;
-                uint32_t color = SET_RGB(*(m+2), *(m+1), *(m));
-                graph_set_pixel_alpha(p->x + x, p->y + y, color, *(m+3));
-            }
-        }
-    }
-}

Property changes on: proj/sprite.c
___________________________________________________________________
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Index: proj/proj.c
===================================================================
--- proj/proj.c	(revision 176)
+++ proj/proj.c	(nonexistent)
@@ -1,168 +0,0 @@
-#include <lcom/lcf.h>
-#include <lcom/proj.h>
-#include <lcom/liblm.h>
-
-#include <stdbool.h>
-#include <stdint.h>
-
-#include "i8254.h"
-#include "kbc_macros.h"
-#include "graph_macros.h"
-#include "mouse_macros.h"
-#include "proj_macros.h"
-#include "errors.h"
-
-#include "sprite.h"
-#include "kbc.h"
-#include "graph.h"
-#include "timer.h"
-#include "keyboard.h"
-#include "mouse.h"
-#include "utils.h"
-#include "interrupts_func.h"
-#include "proj_func.h"
-
-#include "fast_math.h"
-#include <math.h>
-
-#ifdef DIOGO
-    #include "shooter.h"
-    #include "pistol.xpm"
-#endif
-#ifdef TELMO
-    #include "crosshair.h"
-#endif
-
-int main(int argc, char* argv[]) {
-
-    lcf_set_language("EN-US");
-
-    //lcf_trace_calls("/home/lcom/labs/proj/trace.txt");
-
-    //lcf_log_output("/home/lcom/labs/proj/output.txt");
-
-    if (lcf_start(argc, argv)) return 1;
-
-    lcf_cleanup();
-
-    return 0;
-}
-
-int(proj_main_loop)(int argc, char *argv[]) {
-
-    int r;
-
-    /// subscribe interrupts
-    if (subscribe_all()) { return 1; }
-
-    /// initialize graphics
-    if(graph_init(GRAPH_MODE)){
-        printf("%s: failed to initalize graphics.\n", __func__);
-        if (cleanup()) printf("%s: failed to cleanup.\n", __func__);
-        return 1;
-    }
-
-    #ifdef DIOGO
-        //printf("%d\n", 1000000-(int)(1000000*fm_sin(0.5*M_PI)));
-        //printf("%d\n", (int)(1000000*fm_cos(0.5*M_PI)));
-        /*
-        clock_t t = clock();
-        sprite_t *shooter1 = get_shooter(); sprite_set_pos(shooter1, 100, 100);
-        for(double angle = 0; angle <= 6.283185; angle += 0.006283185){
-             sprite_set_angle(shooter1, angle);
-             graph_clear_screen();
-             sprite_draw(shooter1);
-             graph_draw();
-        }
-        t = clock() - t;
-        printf("Time taken: %d/%d \n", t, CLOCKS_PER_SEC);
-        sprite_dtor(shooter1);
-        */
-    #endif
-
-    #ifdef TELMO
-        sprite_t *crosshair = get_crosshair();
-        graph_clear_screen();
-        sprite_draw(crosshair);
-        graph_draw();
-    #endif
-
-    /// loop stuff
-    int ipc_status;
-    message msg;
-    int good = 1;
-
-    #ifdef DIOGO
-        good = 0;
-    #endif
-
-    while (good) {
-        /* Get a request message. */
-        if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) {
-            printf("driver_receive failed with %d", r);
-            continue;
-        }
-        if (is_ipc_notify(ipc_status)) { /* received notification */
-            switch (_ENDPOINT_P(msg.m_source)) {
-                case HARDWARE: /* hardware interrupt notification */
-                    for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) {
-                        if (msg.m_notify.interrupts & n) {
-                            interrupt_handler(i);
-                            if ((scancode[0]) == ESC_BREAK_CODE) good = 0;
-                            #ifdef TELMO
-                            if (counter_mouse_ih >= 3) {
-                                struct packet pp = mouse_parse_packet(packet_mouse_ih);
-                                update_mouse_position(&pp);
-                                sprite_set_pos(crosshair, get_mouse_X(), get_mouse_Y());
-                                printf("X: %d | Y: %d | XRES: %d | YRES: %d\n", get_mouse_X(), get_mouse_Y(), graph_get_XRes(), graph_get_YRes());
-                                graph_clear_screen();
-                                sprite_draw(crosshair);
-                                graph_draw();
-                                counter_mouse_ih = 0;
-                            }
-                            #endif
-                        }
-                    }
-
-                    break;
-                default:
-                    break; /* no other notifications expected: do nothing */
-            }
-        } else { /* received standart message, not a notification */
-            /* no standart message expected: do nothing */
-        }
-        #ifdef TELMO
-            switch (get_hor_movement()) {
-                case LEFT:
-                    printf("GOING LEFT.\n");
-                    break;
-                case RIGHT:
-                    printf("GOING RIGHT.\n");
-                    break;
-            }
-            switch (get_ver_movement()) {
-                case UP:
-                    printf("GOING UP.\n");
-                    break;
-                case DOWN:
-                    printf("GOING DOWN.\n");
-                    break;
-            }
-        #endif
-    }
-
-    // Unsubscribe interrupts
-    if (unsubscribe_all()) {
-        if (cleanup())
-            printf("%s: failed to cleanup.\n", __func__);
-        return 1;
-    }
-
-
-    if (cleanup()) {
-        printf("%s: failed to cleanup.\n", __func__);
-        return 1;
-    }
-
-    return 0;
-}

Property changes on: proj/proj.c
___________________________________________________________________
Deleted: svn:executable
Index: proj/interrupts_func.c
===================================================================
--- proj/interrupts_func.c	(revision 176)
+++ proj/interrupts_func.c	(nonexistent)
@@ -1,152 +0,0 @@
-#include "interrupts_func.h"
-#include "timer.h"
-#include "i8254.h"
-#include "kbc_macros.h"
-#include "keyboard.h"
-#include "mouse.h"
-#include "utils.h"
-#include "errors.h"
-
-#include <lcom/lcf.h>
-
-static int timer_subscribed = 0, timer_id;
-
-static int keyboard_subscribed = 0, kbc_id;
-
-static int mouse_subscribed = 0, mouse_id;
-
-static void (*const ih[])(void) =   {    timer_int_handler,
-                                         kbc_ih,
-                                         NULL,
-                                         NULL,
-                                         NULL,
-                                         NULL,
-                                         NULL,
-                                         NULL,
-                                         NULL,
-                                         NULL,
-                                         NULL,
-                                         NULL,
-                                         mouse_ih,
-                                         NULL,
-                                         NULL,
-                                         NULL,
-                                         NULL,
-                                         NULL,
-                                         NULL,
-                                         NULL,
-                                         NULL,
-                                         NULL,
-                                         NULL,
-                                         NULL,
-                                         NULL,
-                                         NULL,
-                                         NULL,
-                                         NULL,
-                                         NULL,
-                                         NULL,
-                                         NULL,
-                                         NULL,
-                                     };
-
-int (subscribe_all)(void) {
-
-    /// Timer interrupt handling
-    timer_id = 0;
-    if(subscribe_timer_interrupt(TIMER0_IRQ, &timer_id)) {
-        printf("%s: failed to subscribe timer interrupts.\n", __func__);
-        return SBCR_ERROR;
-    }
-    timer_subscribed = 1;
-
-    /// Keyboard interrupt handling
-    kbc_id = 0;
-    if (subscribe_kbc_interrupt(KBC_IRQ, &kbc_id)) {
-        printf("%s: failed to subscribe keyboard interrupts.\n", __func__);
-        if (unsubscribe_all())
-            printf("%s: failed to unsubcribe driver, unexpected behaviour is expected.\n");
-        return SBCR_ERROR;
-    }
-    keyboard_subscribed = 1;
-
-    /// Mouse interrupt handling
-    mouse_id = 0;
-    if (subscribe_mouse_interrupt(MOUSE_IRQ, &mouse_id)) { // subscribes mouse interrupts in exclusive mode
-        printf("%s: failed to subscribe mouse interrupts.\n", __func__);
-        if (unsubscribe_all())
-            printf("%s: failed to unsubcribe driver, unexpected behaviour is expected.\n");
-        return SBCR_ERROR;
-    }
-    mouse_subscribed = 1;
-    if (sys_irqdisable(&mouse_id)) { // temporarily disables our interrupts notifications
-        printf("%s: failed to disable mouse interrupts.\n", __func__);
-        if (unsubscribe_all())
-            printf("%s: failed to unsubcribe driver, unexpected behaviour is expected.\n");
-        return SBCR_ERROR;
-    }
-    if (mouse_set_data_report(true)) { // enables mouse data reporting
-        printf("%s: failed to enable mouse data reporting.\n", __func__);
-        if (unsubscribe_all())
-            printf("%s: failed to unsubcribe driver, unexpected behaviour is expected.\n");
-        return SBCR_ERROR;
-    }
-    if (sys_irqenable(&mouse_id)) { // re-enables our interrupts notifications
-        printf("%s: failed to enable mouse interrupts.\n", __func__);
-        if (unsubscribe_all())
-            printf("%s: failed to unsubcribe driver, unexpected behaviour is expected.\n");
-        return SBCR_ERROR;
-    }
-
-    return SUCCESS;
-}
-
-int (unsubscribe_all)(void) {
-    int r = SUCCESS;
-
-    // Unsubscribe Timer Interrupts
-    if (timer_subscribed) {
-        if (unsubscribe_interrupt(&timer_id)) {
-            printf("%s: failed to unsubcribe timer interrupts.\n");
-            r = UNSBCR_ERROR;
-        }
-        timer_subscribed = 0;
-    }
-
-    // Unsubscribe Keyboard interrupts
-    if (keyboard_subscribed) {
-        if (unsubscribe_interrupt(&kbc_id)) {
-            printf("%s: failed to unsubcribe keyboard interrupts.\n");
-            r = UNSBCR_ERROR;
-        }
-        keyboard_subscribed = 0;
-    }
-
-    // Unsubscribe Mouse Interrupts
-    if (mouse_subscribed) {
-        if (sys_irqdisable(&mouse_id)) { // temporarily disables our interrupts notifications
-            printf("%s: failed to disable mouse interrupts.\n");
-            r = UNSBCR_ERROR;
-        }
-        if (mouse_set_data_report(false)) { // disables mouse data reporting
-            printf("%s: failed to disable mouse data reporting.\n");
-            r = UNSBCR_ERROR;
-        }
-        if (sys_irqenable(&mouse_id)) { // re-enables our interrupts notifications
-            printf("%s: failed to enable mouse interrupts.\n");
-            r = UNSBCR_ERROR;
-        }
-        if (unsubscribe_interrupt(&mouse_id)) { // unsubscribes interrupts
-            printf("%s: failed to unsubcribe mouse interrupts.\n");
-            r = UNSBCR_ERROR;
-        }
-        mouse_subscribed = 0;
-    }
-
-    return r;
-}
-
-void interrupt_handler(uint8_t handler) {
-    if (handler >= 32)              return;
-    if ((*ih[handler]) == NULL)     return;
-    (*ih[handler])();
-}

Property changes on: proj/interrupts_func.c
___________________________________________________________________
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Index: proj/mouse.c
===================================================================
--- proj/mouse.c	(revision 176)
+++ proj/mouse.c	(nonexistent)
@@ -1,133 +0,0 @@
-#include <lcom/lcf.h>
-
-#include "mouse.h"
-
-#include "errors.h"
-#include "kbc_macros.h"
-#include "mouse_macros.h"
-#include "kbc.h"
-
-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;
-    }
-}
-
-struct packet (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;
-    return pp;
-}
-
-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;
-    }
-    *pp = mouse_parse_packet(packet);
-    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/mouse.c
___________________________________________________________________
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Index: proj/kbc.c
===================================================================
--- proj/kbc.c	(revision 176)
+++ proj/kbc.c	(nonexistent)
@@ -1,74 +0,0 @@
-#include <lcom/lcf.h>
-
-#include "kbc.h"
-
-#include "kbc_macros.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/kbc.c
___________________________________________________________________
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Index: proj/src/fast_math.c
===================================================================
--- proj/src/fast_math.c	(nonexistent)
+++ proj/src/fast_math.c	(revision 177)
@@ -0,0 +1,27 @@
+#include "fast_math.h"
+
+#include <math.h>
+
+double fm_sin(double x){
+    if(x < 0.0)         return -fm_sin(-x);
+    if(x > 2.0*M_PI) return fm_sin(x-2.0*M_PI);
+    if(x > M_PI)      return -fm_sin(x-M_PI);
+    if(x > 0.5*M_PI) x = M_PI - x;
+    double x2 = x*x;
+    double x3 = x*x2;
+    double x5 = x3*x2;
+    //double x7 = x5*x2;
+    return x-x3*0.1666666666666666666666+x5*0.008333333333333333333333;//-x7*0.0001984126984127;
+}
+
+double fm_cos(double x){
+    if(x < 0.0)         x = -x;
+    if(x > 2.0*M_PI) return fm_cos(x-2.0*M_PI);
+    if(x > M_PI)      x = 2.0*M_PI-x;
+    if(x > 0.5*M_PI) return -fm_cos(M_PI-x);
+    double x2 = x*x;
+    double x4 = x2*x2;
+    double x6 = x4*x2;
+    //double x8 = x4*x4;
+    return 1.0-x2*0.5+x4*0.041666666666666666666666-x6*0.0013888888888888888888888;//+x8*0.000024801587;
+}

Property changes on: proj/src/fast_math.c
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: proj/src/graph.c
===================================================================
--- proj/src/graph.c	(nonexistent)
+++ proj/src/graph.c	(revision 177)
@@ -0,0 +1,296 @@
+#include "graph.h"
+#include "graph_macros.h"
+#include "errors.h"
+
+#include <lcom/lcf.h>
+
+#include <stdio.h>
+
+/// 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;
+
+/// PUBLIC GET
+uint16_t   (graph_get_XRes)         (void){ return vbe_mem_info.XResolution; }
+uint16_t   (graph_get_YRes)         (void){ return vbe_mem_info.YResolution; }
+
+/// PRIVATE GET
+static uint16_t   (graph_get_bits_pixel)   (void){ return vbe_mem_info.BitsPerPixel; }
+static uint16_t   (graph_get_bytes_pixel)  (void){ return (graph_get_bits_pixel() + 7) >> 3; }
+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 ; }
+
+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 void    *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) {
+    if (x >= vbe_mem_info.XResolution || y >= vbe_mem_info.YResolution) {
+        //printf("%s: invalid pixel.\n", __func__);
+        return OUT_OF_RANGE;
+    }
+    unsigned int pos = (x + y * vbe_mem_info.XResolution) * graph_get_bytes_pixel();
+    memcpy(video_buf + pos, &color, graph_get_bytes_pixel());
+    return SUCCESS;
+}
+int (graph_set_pixel_alpha)(uint16_t x, uint16_t y, uint32_t color, uint8_t alpha){
+    if (x >= vbe_mem_info.XResolution || y >= vbe_mem_info.YResolution) {
+        //printf("%s: invalid pixel.\n", __func__);
+        return OUT_OF_RANGE;
+    }
+    unsigned int pos = (x + y * vbe_mem_info.XResolution) * graph_get_bytes_pixel();
+    uint32_t color_;
+    memcpy(&color_, video_buf + pos, graph_get_bytes_pixel());
+    float a = 1.0-(alpha&0xFF)/(float)0xFF;
+    uint8_t r = GET_RED(color)*a + GET_RED(color_)*(1.0-a);
+    uint8_t g = GET_GRE(color)*a + GET_GRE(color_)*(1.0-a);
+    uint8_t b = GET_BLU(color)*a + GET_BLU(color_)*(1.0-a);
+    return graph_set_pixel(x,y,SET_RGB(r,g,b));
+    //return set_pixel(x,y,color);
+}
+
+int (graph_clear_screen)(void){
+    //return graph_paint_screen(BLACK);
+    memset(video_buf, 0, graph_get_vram_size());
+    return SUCCESS;
+}
+
+int (graph_draw)(void){
+    memcpy((uint8_t*)video_mem, video_buf, graph_get_vram_size());
+    return 0;
+}
+
+/// RECTANGLE
+int (graph_draw_hline)(uint16_t x, uint16_t y, uint16_t len, uint32_t color){
+    int r;
+    for (uint16_t i = 0; i < len; i++)
+        if ((r = graph_set_pixel(x + i, y, color))) return r;
+    return SUCCESS;
+}
+
+int (graph_draw_rectangle)(uint16_t x, uint16_t y,uint16_t width, uint16_t height, uint32_t color)	{
+    int r;
+    for (uint16_t i = 0; i < height; i++)
+        if ((r = graph_draw_hline(x, y + i, width, color))) return r;
+    return SUCCESS;
+}

Property changes on: proj/src/graph.c
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: proj/src/interrupts_func.c
===================================================================
--- proj/src/interrupts_func.c	(nonexistent)
+++ proj/src/interrupts_func.c	(revision 177)
@@ -0,0 +1,152 @@
+#include "interrupts_func.h"
+#include "timer.h"
+#include "i8254.h"
+#include "kbc_macros.h"
+#include "keyboard.h"
+#include "mouse.h"
+#include "utils.h"
+#include "errors.h"
+
+#include <lcom/lcf.h>
+
+static int timer_subscribed = 0, timer_id;
+
+static int keyboard_subscribed = 0, kbc_id;
+
+static int mouse_subscribed = 0, mouse_id;
+
+static void (*const ih[])(void) =   {    timer_int_handler,
+                                         kbc_ih,
+                                         NULL,
+                                         NULL,
+                                         NULL,
+                                         NULL,
+                                         NULL,
+                                         NULL,
+                                         NULL,
+                                         NULL,
+                                         NULL,
+                                         NULL,
+                                         mouse_ih,
+                                         NULL,
+                                         NULL,
+                                         NULL,
+                                         NULL,
+                                         NULL,
+                                         NULL,
+                                         NULL,
+                                         NULL,
+                                         NULL,
+                                         NULL,
+                                         NULL,
+                                         NULL,
+                                         NULL,
+                                         NULL,
+                                         NULL,
+                                         NULL,
+                                         NULL,
+                                         NULL,
+                                         NULL,
+                                     };
+
+int (subscribe_all)(void) {
+
+    /// Timer interrupt handling
+    timer_id = 0;
+    if(subscribe_timer_interrupt(TIMER0_IRQ, &timer_id)) {
+        printf("%s: failed to subscribe timer interrupts.\n", __func__);
+        return SBCR_ERROR;
+    }
+    timer_subscribed = 1;
+
+    /// Keyboard interrupt handling
+    kbc_id = 0;
+    if (subscribe_kbc_interrupt(KBC_IRQ, &kbc_id)) {
+        printf("%s: failed to subscribe keyboard interrupts.\n", __func__);
+        if (unsubscribe_all())
+            printf("%s: failed to unsubcribe driver, unexpected behaviour is expected.\n");
+        return SBCR_ERROR;
+    }
+    keyboard_subscribed = 1;
+
+    /// Mouse interrupt handling
+    mouse_id = 0;
+    if (subscribe_mouse_interrupt(MOUSE_IRQ, &mouse_id)) { // subscribes mouse interrupts in exclusive mode
+        printf("%s: failed to subscribe mouse interrupts.\n", __func__);
+        if (unsubscribe_all())
+            printf("%s: failed to unsubcribe driver, unexpected behaviour is expected.\n");
+        return SBCR_ERROR;
+    }
+    mouse_subscribed = 1;
+    if (sys_irqdisable(&mouse_id)) { // temporarily disables our interrupts notifications
+        printf("%s: failed to disable mouse interrupts.\n", __func__);
+        if (unsubscribe_all())
+            printf("%s: failed to unsubcribe driver, unexpected behaviour is expected.\n");
+        return SBCR_ERROR;
+    }
+    if (mouse_set_data_report(true)) { // enables mouse data reporting
+        printf("%s: failed to enable mouse data reporting.\n", __func__);
+        if (unsubscribe_all())
+            printf("%s: failed to unsubcribe driver, unexpected behaviour is expected.\n");
+        return SBCR_ERROR;
+    }
+    if (sys_irqenable(&mouse_id)) { // re-enables our interrupts notifications
+        printf("%s: failed to enable mouse interrupts.\n", __func__);
+        if (unsubscribe_all())
+            printf("%s: failed to unsubcribe driver, unexpected behaviour is expected.\n");
+        return SBCR_ERROR;
+    }
+
+    return SUCCESS;
+}
+
+int (unsubscribe_all)(void) {
+    int r = SUCCESS;
+
+    // Unsubscribe Timer Interrupts
+    if (timer_subscribed) {
+        if (unsubscribe_interrupt(&timer_id)) {
+            printf("%s: failed to unsubcribe timer interrupts.\n");
+            r = UNSBCR_ERROR;
+        }
+        timer_subscribed = 0;
+    }
+
+    // Unsubscribe Keyboard interrupts
+    if (keyboard_subscribed) {
+        if (unsubscribe_interrupt(&kbc_id)) {
+            printf("%s: failed to unsubcribe keyboard interrupts.\n");
+            r = UNSBCR_ERROR;
+        }
+        keyboard_subscribed = 0;
+    }
+
+    // Unsubscribe Mouse Interrupts
+    if (mouse_subscribed) {
+        if (sys_irqdisable(&mouse_id)) { // temporarily disables our interrupts notifications
+            printf("%s: failed to disable mouse interrupts.\n");
+            r = UNSBCR_ERROR;
+        }
+        if (mouse_set_data_report(false)) { // disables mouse data reporting
+            printf("%s: failed to disable mouse data reporting.\n");
+            r = UNSBCR_ERROR;
+        }
+        if (sys_irqenable(&mouse_id)) { // re-enables our interrupts notifications
+            printf("%s: failed to enable mouse interrupts.\n");
+            r = UNSBCR_ERROR;
+        }
+        if (unsubscribe_interrupt(&mouse_id)) { // unsubscribes interrupts
+            printf("%s: failed to unsubcribe mouse interrupts.\n");
+            r = UNSBCR_ERROR;
+        }
+        mouse_subscribed = 0;
+    }
+
+    return r;
+}
+
+void interrupt_handler(uint8_t handler) {
+    if (handler >= 32)              return;
+    if ((*ih[handler]) == NULL)     return;
+    (*ih[handler])();
+}

Property changes on: proj/src/interrupts_func.c
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: proj/src/kbc.c
===================================================================
--- proj/src/kbc.c	(nonexistent)
+++ proj/src/kbc.c	(revision 177)
@@ -0,0 +1,74 @@
+#include <lcom/lcf.h>
+
+#include "kbc.h"
+
+#include "kbc_macros.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/src/kbc.c
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: proj/src/keyboard.c
===================================================================
--- proj/src/keyboard.c	(nonexistent)
+++ proj/src/keyboard.c	(revision 177)
@@ -0,0 +1,61 @@
+#include <lcom/lcf.h>
+
+#include "keyboard.h"
+
+#include "kbc.h"
+#include "kbc_macros.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_movement();
+
+}
+
+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/src/keyboard.c
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: proj/src/mouse.c
===================================================================
--- proj/src/mouse.c	(nonexistent)
+++ proj/src/mouse.c	(revision 177)
@@ -0,0 +1,133 @@
+#include <lcom/lcf.h>
+
+#include "mouse.h"
+
+#include "errors.h"
+#include "kbc_macros.h"
+#include "mouse_macros.h"
+#include "kbc.h"
+
+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;
+    }
+}
+
+struct packet (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;
+    return pp;
+}
+
+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;
+    }
+    *pp = mouse_parse_packet(packet);
+    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/src/mouse.c
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: proj/src/proj.c
===================================================================
--- proj/src/proj.c	(nonexistent)
+++ proj/src/proj.c	(revision 177)
@@ -0,0 +1,168 @@
+#include <lcom/lcf.h>
+#include <lcom/proj.h>
+#include <lcom/liblm.h>
+
+#include <stdbool.h>
+#include <stdint.h>
+
+#include "i8254.h"
+#include "kbc_macros.h"
+#include "graph_macros.h"
+#include "mouse_macros.h"
+#include "proj_macros.h"
+#include "errors.h"
+
+#include "sprite.h"
+#include "kbc.h"
+#include "graph.h"
+#include "timer.h"
+#include "keyboard.h"
+#include "mouse.h"
+#include "utils.h"
+#include "interrupts_func.h"
+#include "proj_func.h"
+
+#include "fast_math.h"
+#include <math.h>
+
+#ifdef DIOGO
+    #include "shooter.h"
+    #include "pistol.xpm"
+#endif
+#ifdef TELMO
+    #include "crosshair.h"
+#endif
+
+int main(int argc, char* argv[]) {
+
+    lcf_set_language("EN-US");
+
+    //lcf_trace_calls("/home/lcom/labs/proj/trace.txt");
+
+    //lcf_log_output("/home/lcom/labs/proj/output.txt");
+
+    if (lcf_start(argc, argv)) return 1;
+
+    lcf_cleanup();
+
+    return 0;
+}
+
+int(proj_main_loop)(int argc, char *argv[]) {
+
+    int r;
+
+    /// subscribe interrupts
+    if (subscribe_all()) { return 1; }
+
+    /// initialize graphics
+    if(graph_init(GRAPH_MODE)){
+        printf("%s: failed to initalize graphics.\n", __func__);
+        if (cleanup()) printf("%s: failed to cleanup.\n", __func__);
+        return 1;
+    }
+
+    #ifdef DIOGO
+        //printf("%d\n", 1000000-(int)(1000000*fm_sin(0.5*M_PI)));
+        //printf("%d\n", (int)(1000000*fm_cos(0.5*M_PI)));
+        /*
+        clock_t t = clock();
+        sprite_t *shooter1 = get_shooter(); sprite_set_pos(shooter1, 100, 100);
+        for(double angle = 0; angle <= 6.283185; angle += 0.006283185){
+             sprite_set_angle(shooter1, angle);
+             graph_clear_screen();
+             sprite_draw(shooter1);
+             graph_draw();
+        }
+        t = clock() - t;
+        printf("Time taken: %d/%d \n", t, CLOCKS_PER_SEC);
+        sprite_dtor(shooter1);
+        */
+    #endif
+
+    #ifdef TELMO
+        sprite_t *crosshair = get_crosshair();
+        graph_clear_screen();
+        sprite_draw(crosshair);
+        graph_draw();
+    #endif
+
+    /// loop stuff
+    int ipc_status;
+    message msg;
+    int good = 1;
+
+    #ifdef DIOGO
+        good = 0;
+    #endif
+
+    while (good) {
+        /* Get a request message. */
+        if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) {
+            printf("driver_receive failed with %d", r);
+            continue;
+        }
+        if (is_ipc_notify(ipc_status)) { /* received notification */
+            switch (_ENDPOINT_P(msg.m_source)) {
+                case HARDWARE: /* hardware interrupt notification */
+                    for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) {
+                        if (msg.m_notify.interrupts & n) {
+                            interrupt_handler(i);
+                            if ((scancode[0]) == ESC_BREAK_CODE) good = 0;
+                            #ifdef TELMO
+                            if (counter_mouse_ih >= 3) {
+                                struct packet pp = mouse_parse_packet(packet_mouse_ih);
+                                update_mouse_position(&pp);
+                                sprite_set_pos(crosshair, get_mouse_X(), get_mouse_Y());
+                                printf("X: %d | Y: %d | XRES: %d | YRES: %d\n", get_mouse_X(), get_mouse_Y(), graph_get_XRes(), graph_get_YRes());
+                                graph_clear_screen();
+                                sprite_draw(crosshair);
+                                graph_draw();
+                                counter_mouse_ih = 0;
+                            }
+                            #endif
+                        }
+                    }
+
+                    break;
+                default:
+                    break; /* no other notifications expected: do nothing */
+            }
+        } else { /* received standart message, not a notification */
+            /* no standart message expected: do nothing */
+        }
+        #ifdef TELMO
+            switch (get_hor_movement()) {
+                case LEFT:
+                    printf("GOING LEFT.\n");
+                    break;
+                case RIGHT:
+                    printf("GOING RIGHT.\n");
+                    break;
+            }
+            switch (get_ver_movement()) {
+                case UP:
+                    printf("GOING UP.\n");
+                    break;
+                case DOWN:
+                    printf("GOING DOWN.\n");
+                    break;
+            }
+        #endif
+    }
+
+    // Unsubscribe interrupts
+    if (unsubscribe_all()) {
+        if (cleanup())
+            printf("%s: failed to cleanup.\n", __func__);
+        return 1;
+    }
+
+
+    if (cleanup()) {
+        printf("%s: failed to cleanup.\n", __func__);
+        return 1;
+    }
+
+    return 0;
+}

Property changes on: proj/src/proj.c
___________________________________________________________________
Added: svn:executable
Index: proj/src/proj_func.c
===================================================================
--- proj/src/proj_func.c	(nonexistent)
+++ proj/src/proj_func.c	(revision 177)
@@ -0,0 +1,66 @@
+#include <lcom/lcf.h>
+
+#include "proj_func.h"
+
+#include "interrupts_func.h"
+#include "graph.h"
+#include "keyboard.h"
+#include "errors.h"
+#include "proj_macros.h"
+#include "utils.h"
+
+#include "kbc_macros.h"
+
+#include <math.h>
+
+int cleanup(void) {
+    int r = SUCCESS;
+    if ((r = unsubscribe_all()))
+        printf("%s: failed to unsubscribe drivers.\n", __func__);
+    if ((r = graph_cleanup()))
+        printf("%s: graph cleanup failed\n", __func__);
+
+    return r;
+}
+
+static int hor_mov = REST, ver_mov = REST;
+
+void update_movement(void) {
+    static int w_pressed = 0, a_pressed = 0, s_pressed = 0, d_pressed = 0;
+    if (sz == 1) {
+        switch(scancode[0]) {
+        case W_MAKE_CODE  : w_pressed = 1;      break;
+        case W_BREAK_CODE : w_pressed = 0;      break;
+        case A_MAKE_CODE  : a_pressed = 1;      break;
+        case A_BREAK_CODE : a_pressed = 0;      break;
+        case S_MAKE_CODE  : s_pressed = 1;      break;
+        case S_BREAK_CODE : s_pressed = 0;      break;
+        case D_MAKE_CODE  : d_pressed = 1;      break;
+        case D_BREAK_CODE : d_pressed = 0;      break;
+        }
+    }
+    ver_mov = s_pressed - w_pressed;
+    hor_mov = d_pressed - a_pressed;
+}
+
+static int32_t mouse_x = 0, mouse_y = 0;
+
+void update_mouse_position(struct packet *p) {
+    mouse_x = max(0, mouse_x + p->delta_x);
+    mouse_x = min(mouse_x, graph_get_XRes() - 1);
+
+    mouse_y = max(0, mouse_y - p->delta_y);
+    mouse_y = min(mouse_y, graph_get_YRes() - 1);
+}
+
+int32_t get_mouse_X(void) { return mouse_x; }
+
+int32_t get_mouse_Y(void) { return mouse_y; }
+
+double get_mouse_angle(sprite_t *p) {
+    return atan2(sprite_get_y(p) - mouse_y, mouse_x - sprite_get_x(p));
+}
+
+int get_hor_movement(void) { return hor_mov; }
+
+int get_ver_movement(void) { return ver_mov; }

Property changes on: proj/src/proj_func.c
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: proj/src/sprite.c
===================================================================
--- proj/src/sprite.c	(nonexistent)
+++ proj/src/sprite.c	(revision 177)
@@ -0,0 +1,76 @@
+#include <lcom/lcf.h>
+
+#include "sprite.h"
+
+#include "graph.h"
+#include "utils.h"
+#include "fast_math.h"
+#include <math.h>
+
+struct sprite{
+    int16_t x, y;
+    uint16_t w, h;
+    int16_t u0, v0;
+    float theta;
+    uint8_t *map;
+};
+
+sprite_t* (sprite_ctor)(const char **xpm, int u0, int v0){
+    sprite_t *ret = (sprite_t*)malloc(sizeof(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){
+        free(ret);
+        return NULL;
+    }
+    ret->x = 0;
+    ret->y = 0;
+    ret->w = img.width;
+    ret->h = img.height;
+    ret->u0 = u0;
+    ret->v0 = u0;
+    ret->theta = 0;
+    return ret;
+}
+void (sprite_dtor)(sprite_t *p){
+    if(p == NULL) return;
+    if(p->map) free(p->map);
+    free(p);
+}
+
+void (sprite_set_x)     (sprite_t *p, int16_t x){ p->x = x; }
+void (sprite_set_y)     (sprite_t *p, int16_t y){ p->y = y; }
+void (sprite_set_pos)   (sprite_t *p, int16_t x, int16_t y){ sprite_set_x(p, x); sprite_set_y(p, y); }
+void (sprite_set_angle) (sprite_t *p, double angle){ p->theta = angle; }
+void (sprite_set_center)(sprite_t *p, int16_t u0, int16_t v0){ p->u0 = u0; p->v0 = v0; }
+
+int sprite_get_x(const sprite_t *p){ return p->x; }
+int sprite_get_y(const sprite_t *p){ return p->y; }
+int sprite_get_w(const sprite_t *p){ return p->w; }
+int sprite_get_h(const sprite_t *p){ return p->h; }
+
+void (sprite_src2pic)(const sprite_t *p, int16_t x, int16_t y, int16_t *u, int16_t *v){
+    int16_t dx = x - p->x;
+    int16_t dy = y - p->y;
+    double s = fm_sin(p->theta);
+    double c = fm_cos(p->theta);
+    *u = dx*c - dy*s + p->u0;
+    *v = dx*s + dy*c + p->v0;
+}
+
+void (sprite_draw)(const sprite_t *p){
+    const int16_t diag = sqrt(p->w*p->w + p->h*p->h)+2;
+    int16_t u, v;
+    for(int16_t y = max(0,p->y-diag); y < min(p->y+diag,graph_get_YRes()); ++y){
+        for(int16_t x = max(0,p->x-diag); x < min(p->x+diag,graph_get_XRes()); ++x){
+            sprite_src2pic(p, x, y, &u, &v);
+            if(0 <= u && u < p->w && 0 <= v && v < p->h){
+                uint8_t *m = p->map + (v*p->w + u)*4;
+                uint32_t color = SET_RGB(*(m+2), *(m+1), *(m));
+                graph_set_pixel_alpha(p->x + x, p->y + y, color, *(m+3));
+            }
+        }
+    }
+}

Property changes on: proj/src/sprite.c
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: proj/src/timer.c
===================================================================
--- proj/src/timer.c	(nonexistent)
+++ proj/src/timer.c	(revision 177)
@@ -0,0 +1,16 @@
+#include <lcom/lcf.h>
+
+#include "timer.h"
+
+#include "i8254.h"
+
+int (subscribe_timer_interrupt)(uint8_t interrupt_bit, int *interrupt_id) {
+    if (interrupt_id == NULL) return 1;
+    *interrupt_id = interrupt_bit;
+    return (sys_irqsetpolicy(TIMER0_IRQ, IRQ_REENABLE, interrupt_id));
+}
+
+uint32_t no_interrupts = 0;
+void (timer_int_handler)() {
+    no_interrupts++;
+}

Property changes on: proj/src/timer.c
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: proj/src/utils.c
===================================================================
--- proj/src/utils.c	(nonexistent)
+++ proj/src/utils.c	(revision 177)
@@ -0,0 +1,35 @@
+#include <lcom/lcf.h>
+
+#include "utils.h"
+
+#include <stdint.h>
+#include "errors.h"
+
+int(util_get_LSB)(uint16_t val, uint8_t *lsb) {
+    if (lsb == NULL) return NULL_PTR;
+    *lsb = val;
+    return SUCCESS;
+}
+
+int(util_get_MSB)(uint16_t val, uint8_t *msb) {
+    if (msb == NULL) return NULL_PTR;
+    *msb = (val >> 8);
+    return SUCCESS;
+}
+
+int (util_sys_inb)(int port, uint8_t *value) {
+    if(value == NULL) return NULL_PTR;
+    uint32_t n = 0;
+    if(sys_inb(port, &n)) return READ_ERROR;
+    *value = n;
+    return SUCCESS;
+}
+
+int (unsubscribe_interrupt)(int *interrupt_id) {
+    if (interrupt_id == NULL) return NULL_PTR;
+    if(sys_irqrmpolicy(interrupt_id)) return UNSBCR_ERROR;
+    return SUCCESS;
+}
+
+int32_t min(int32_t a, int32_t b){ return (b < a ? b : a); }
+int32_t max(int32_t a, int32_t b){ return (a < b ? b : a); }

Property changes on: proj/src/utils.c
___________________________________________________________________
Added: svn:executable
Index: proj/DR.mk
===================================================================
--- proj/DR.mk	(revision 176)
+++ proj/DR.mk	(revision 177)
@@ -1,5 +1,7 @@
 PROG=proj
 
+.PATH: ${.CURDIR}/src
+
 SRCS= proj.c graph.c sprite.c kbc.c keyboard.c mouse.c utils.c timer.c interrupts_func.c proj_func.c fast_math.c
 
 CPPFLAGS += -pedantic -I./include -I./bmp -I./xpm -D DIOGO -D __LCOM_OPTIMIZED_
Index: proj/Makefile
===================================================================
--- proj/Makefile	(revision 176)
+++ proj/Makefile	(revision 177)
@@ -1,5 +1,7 @@
 PROG=proj
 
+.PATH: ${.CURDIR}/src
+
 SRCS= proj.c graph.c sprite.c kbc.c keyboard.c mouse.c utils.c timer.c interrupts_func.c proj_func.c fast_math.c
 
 CPPFLAGS += -pedantic -I./include -I./bmp -I./xpm -D __LCOM_OPTIMIZED_
Index: proj/TB.mk
===================================================================
--- proj/TB.mk	(revision 176)
+++ proj/TB.mk	(revision 177)
@@ -1,5 +1,7 @@
 PROG=proj
 
+.PATH: ${.CURDIR}/src
+
 SRCS= proj.c graph.c sprite.c kbc.c keyboard.c mouse.c utils.c timer.c interrupts_func.c proj_func.c fast_math.c
 
 CPPFLAGS += -pedantic -I./include -I./bmp -I./xpm -D TELMO #-D __LCOM_OPTIMIZED_
