Index: proj/graphics.c
===================================================================
--- proj/graphics.c	(revision 167)
+++ proj/graphics.c	(nonexistent)
@@ -1,234 +0,0 @@
-#include "graphics.h"
-#include "graphics_macros.h"
-#include "errors.h"
-
-#include <lcom/lcf.h>
-
-#include <stdio.h>
-
-static void *video_mem; /** @brief Frame-buffer VM address */
-static vbe_mode_info_t vbe_mem_info;
-static mmap_t mem_map;
-
-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);
-}
-
-//int (get_permissions_first_mbyte)(void) {
-//    return get_permission(MBYTE_BASE, MBYTE_SIZE);
-//}
-
-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_map()) {
-            printf("%s: lm_free failed\n", __func__);
-        }
-        return BIOS_CALL_ERROR;
-    }
-
-    memcpy((void*)&vbe_mem_info, (void*)virtual_addr, mem_map.size);
-    return SUCCESS;
-}
-
-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;
-}
-
-phys_bytes (graph_get_phys_addr)    (void){ return vbe_mem_info.PhysBasePtr; }
-unsigned   (graph_get_vram_size)    (void){ return vbe_mem_info.XResolution * vbe_mem_info.YResolution * ((vbe_mem_info.BitsPerPixel + 7) >> 3); }
-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_bits_pixel)   (void){ return vbe_mem_info.BitsPerPixel; }
-uint16_t   (graph_get_bytes_pixel)  (void){ return (vbe_mem_info.BitsPerPixel + 7) >> 3; }
-uint16_t   (graph_get_RedMaskSize)  (void){ return vbe_mem_info.RedMaskSize  ; }
-uint16_t   (graph_get_GreenMaskSize)(void){ return vbe_mem_info.GreenMaskSize; }
-uint16_t   (graph_get_BlueMaskSize) (void){ return vbe_mem_info.BlueMaskSize ; }
-
-int (graph_map_vram)(void) {
-    int r;
-    unsigned int vram_base = graph_get_phys_addr();
-    unsigned int vram_size = graph_get_vram_size();
-    if ((r = get_permission(vram_base, vram_size))) {
-        if (graph_free_memory_map()) {
-            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_map()) {
-            printf("%s: lm_free failed\n", __func__);
-        }
-        panic("%s: couldn't map video memory.", __func__);
-    }
-
-    return SUCCESS;
-}
-
-int (graph_free_memory_map)(void) {
-    return !lm_free(&mem_map);
-}
-
-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_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((void*)((unsigned int)video_mem + 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){
-    unsigned int pos = (x + y * vbe_mem_info.XResolution) * graph_get_bytes_pixel();
-    uint32_t color_;
-    memcpy(&color_, (void*)((unsigned int)video_mem + 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_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 (vg_draw_hline)(uint16_t x, uint16_t y, uint16_t len, uint32_t color){
-    return graph_draw_hline(x,y,len,color);
-}
-
-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;
-}
-int (vg_draw_rectangle)(uint16_t x, uint16_t y,uint16_t width, uint16_t height, uint32_t color){
-    return graph_draw_rectangle(x,y,width,height, color);
-}
-
-int (graph_paint_screen)(uint32_t color){
-    return graph_draw_rectangle(0,0,graph_get_XRes(),graph_get_YRes(),color);
-}
-
-int (graph_clear_screen)(void){
-    return graph_paint_screen(BLACK);
-}
-
-int (graph_draw)(void){
-    return 0;
-}

Property changes on: proj/graphics.c
___________________________________________________________________
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Index: proj/graphics.h
===================================================================
--- proj/graphics.h	(revision 167)
+++ proj/graphics.h	(nonexistent)
@@ -1,79 +0,0 @@
-#ifndef GRAPHICS_H_INCLUDED
-#define GRAPHICS_H_INCLUDED
-
-#include <lcom/lcf.h>
-#include <stdint.h>
-
-#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 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))
-#define SET_ARGB(a,r,g,b)   (SET_ALP(a) | SET_RED(r) | SET_GRE(g) | SET_BLU(b))
-#define FAR2PHYS(n)         ((((n)>>12) & 0xFFFFFFF0) + ((n) & 0x0000FFFF))
-
-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;
-
-int (get_permission)(unsigned int base_addr, unsigned int size);
-
-//int (get_permissions_first_mbyte)(void);
-
-int (vbe_get_mode_information)(uint16_t mode);
-
-int (vbe_get_controller_information)(vg_vbe_contr_info_t *info_p);
-
-phys_bytes (graph_get_phys_addr)    (void);
-unsigned   (graph_get_vram_size)    (void);
-uint16_t   (graph_get_XRes)         (void);
-uint16_t   (graph_get_YRes)         (void);
-uint16_t   (graph_get_bits_pixel)   (void);
-uint16_t   (graph_get_bytes_pixel)  (void);
-uint16_t   (graph_get_RedMaskSize)  (void);
-uint16_t   (graph_get_GreenMaskSize)(void);
-uint16_t   (graph_get_BlueMaskSize) (void);
-
-int (graph_map_vram)(void);
-
-int (graph_free_memory_map)(void);
-
-int (graph_set_pixel)      (uint16_t x, uint16_t y, uint32_t color);
-int (graph_set_pixel_alpha)(uint16_t x, uint16_t y, uint32_t color, uint8_t alpha);
-
-/**
- * @brief
- * @param mode
- * @return
- */
-int (graph_set_mode)(uint16_t mode);
-
-int (graph_draw_hline)(uint16_t x, uint16_t y, uint16_t len, uint32_t color);
-
-int (graph_draw_rectangle)(uint16_t x, uint16_t y,uint16_t width, uint16_t height, uint32_t color);
-
-int (graph_paint_screen)(uint32_t color);
-
-int (graph_clear_screen)(void);
-
-int (graph_draw)(void);
-
-#endif /* end of include guard: GRAPHICS_H_INCLUDED */

Property changes on: proj/graphics.h
___________________________________________________________________
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Index: proj/graphics_macros.h
===================================================================
--- proj/graphics_macros.h	(revision 167)
+++ proj/graphics_macros.h	(nonexistent)
@@ -1,32 +0,0 @@
-#ifndef GRAPHICS_MACROS_H_INCLUDED
-#define GRAPHICS_MACROS_H_INCLUDED
-
-#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 */
-
-// Graphics modes
-#define INDEXED_1024_768        0x105
-#define DIRECT_640_480          0x110
-#define DIRECT_800_600          0x115
-#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 BLACK               0x000000
-
-#endif /* end of include guard: GRAPHICS_MACROS_H_INCLUDED */

Property changes on: proj/graphics_macros.h
___________________________________________________________________
Deleted: svn:executable
Index: proj/DR.mk
===================================================================
--- proj/DR.mk	(revision 167)
+++ proj/DR.mk	(revision 168)
@@ -1,8 +1,8 @@
 PROG=proj
 
-SRCS= proj.c graph.c sprite.c kbc.c keyboard.c mouse.c utils.c timer.c interrupts_func.c proj_func.c
+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./bmp -I./xpm -D DIOGO # -D __LCOM_OPTIMIZED_
+CPPFLAGS += -pedantic -I./bmp -I./xpm -D DIOGO -D __LCOM_OPTIMIZED_
 
 DPADD += ${LIBLCF}
 LDADD += -llcf
Index: proj/TB.mk
===================================================================
--- proj/TB.mk	(revision 167)
+++ proj/TB.mk	(revision 168)
@@ -1,6 +1,6 @@
 PROG=proj
 
-SRCS= proj.c graph.c sprite.c kbc.c keyboard.c mouse.c utils.c timer.c interrupts_func.c proj_func.c
+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./bmp -I./xpm -D TELMO #-D __LCOM_OPTIMIZED_
 
Index: proj/fast_math.c
===================================================================
--- proj/fast_math.c	(nonexistent)
+++ proj/fast_math.c	(revision 168)
@@ -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.1666666666666666+x5*0.008333333333333333;//-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.041666666666666666-x6*0.00138888888888888888;//+x8*0.000024801587;
+}

Property changes on: proj/fast_math.c
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: proj/fast_math.h
===================================================================
--- proj/fast_math.h	(nonexistent)
+++ proj/fast_math.h	(revision 168)
@@ -0,0 +1,7 @@
+#ifndef FAST_MATH_H_INCLUDED
+#define FAST_MATH_H_INCLUDED
+
+double fm_sin(double x);
+double fm_cos(double x);
+
+#endif //FAST_MATH_H_INCLUDED

Property changes on: proj/fast_math.h
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: proj/graph.c
===================================================================
--- proj/graph.c	(nonexistent)
+++ proj/graph.c	(revision 168)
@@ -0,0 +1,267 @@
+#include "graph.h"
+#include "graph_macros.h"
+#include "errors.h"
+
+#include <lcom/lcf.h>
+
+#include <stdio.h>
+
+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 vbe_mode_info_t vbe_mem_info;
+static mmap_t mem_map;
+
+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);
+}
+
+//int (get_permissions_first_mbyte)(void) {
+//    return get_permission(MBYTE_BASE, MBYTE_SIZE);
+//}
+
+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;
+}
+
+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;
+}
+
+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;
+}
+
+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;
+}
+
+phys_bytes (graph_get_phys_addr)    (void){ return vbe_mem_info.PhysBasePtr; }
+unsigned   (graph_get_vram_size)    (void){ return vbe_mem_info.XResolution * vbe_mem_info.YResolution * graph_get_bytes_pixel(); }
+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_bits_pixel)   (void){ return vbe_mem_info.BitsPerPixel; }
+uint16_t   (graph_get_bytes_pixel)  (void){ return (vbe_mem_info.BitsPerPixel + 7) >> 3; }
+uint16_t   (graph_get_RedMaskSize)  (void){ return vbe_mem_info.RedMaskSize  ; }
+uint16_t   (graph_get_GreenMaskSize)(void){ return vbe_mem_info.GreenMaskSize; }
+uint16_t   (graph_get_BlueMaskSize) (void){ return vbe_mem_info.BlueMaskSize ; }
+
+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;
+}
+
+int (graph_free_memory)(void) {
+    int r = SUCCESS;
+    free(video_buf); video_buf = NULL;
+    r = !lm_free(&mem_map);
+    return r;
+}
+
+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_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){
+    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_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 (vg_draw_hline)(uint16_t x, uint16_t y, uint16_t len, uint32_t color){
+    return graph_draw_hline(x,y,len,color);
+}
+
+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;
+}
+int (vg_draw_rectangle)(uint16_t x, uint16_t y,uint16_t width, uint16_t height, uint32_t color){
+    return graph_draw_rectangle(x,y,width,height, color);
+}
+
+int (graph_paint_screen)(uint32_t color){
+    return graph_draw_rectangle(0,0,graph_get_XRes(),graph_get_YRes(),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;
+}

Property changes on: proj/graph.c
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: proj/graph.h
===================================================================
--- proj/graph.h	(nonexistent)
+++ proj/graph.h	(revision 168)
@@ -0,0 +1,82 @@
+#ifndef GRAPH_H_INCLUDED
+#define GRAPH_H_INCLUDED
+
+#include <lcom/lcf.h>
+#include <stdint.h>
+
+#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 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))
+#define SET_ARGB(a,r,g,b)   (SET_ALP(a) | SET_RED(r) | SET_GRE(g) | SET_BLU(b))
+#define FAR2PHYS(n)         ((((n)>>12) & 0xFFFFFFF0) + ((n) & 0x0000FFFF))
+
+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;
+
+int (get_permission)(unsigned int base_addr, unsigned int size);
+
+//int (get_permissions_first_mbyte)(void);
+
+int (graph_init)(uint16_t mode);
+int (graph_cleanup)(void);
+
+int (vbe_get_mode_information)(uint16_t mode);
+
+int (vbe_get_controller_information)(vg_vbe_contr_info_t *info_p);
+
+phys_bytes (graph_get_phys_addr)    (void);
+unsigned   (graph_get_vram_size)    (void);
+uint16_t   (graph_get_XRes)         (void);
+uint16_t   (graph_get_YRes)         (void);
+uint16_t   (graph_get_bits_pixel)   (void);
+uint16_t   (graph_get_bytes_pixel)  (void);
+uint16_t   (graph_get_RedMaskSize)  (void);
+uint16_t   (graph_get_GreenMaskSize)(void);
+uint16_t   (graph_get_BlueMaskSize) (void);
+
+int (graph_map_vram)(void);
+
+int (graph_free_memory)(void);
+
+int (graph_set_pixel)      (uint16_t x, uint16_t y, uint32_t color);
+int (graph_set_pixel_alpha)(uint16_t x, uint16_t y, uint32_t color, uint8_t alpha);
+
+/**
+ * @brief
+ * @param mode
+ * @return
+ */
+int (graph_set_mode)(uint16_t mode);
+
+int (graph_draw_hline)(uint16_t x, uint16_t y, uint16_t len, uint32_t color);
+
+int (graph_draw_rectangle)(uint16_t x, uint16_t y,uint16_t width, uint16_t height, uint32_t color);
+
+int (graph_paint_screen)(uint32_t color);
+
+int (graph_clear_screen)(void);
+
+int (graph_draw)(void);
+
+#endif /* end of include guard: GRAPH_H_INCLUDED */

Property changes on: proj/graph.h
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: proj/graph_macros.h
===================================================================
--- proj/graph_macros.h	(nonexistent)
+++ proj/graph_macros.h	(revision 168)
@@ -0,0 +1,32 @@
+#ifndef GRAPHICS_MACROS_H_INCLUDED
+#define GRAPHICS_MACROS_H_INCLUDED
+
+#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 */
+
+// Graphics modes
+#define INDEXED_1024_768        0x105
+#define DIRECT_640_480          0x110
+#define DIRECT_800_600          0x115
+#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 BLACK               0x000000
+
+#endif /* end of include guard: GRAPHICS_MACROS_H_INCLUDED */

Property changes on: proj/graph_macros.h
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: proj/proj.c
===================================================================
--- proj/proj.c	(revision 167)
+++ proj/proj.c	(revision 168)
@@ -22,6 +22,9 @@
 #include "interrupts_func.h"
 #include "proj_func.h"
 
+#include "fast_math.h"
+#include <math.h>
+
 #ifdef DIOGO
     #include "shooter.h"
     #include "pistol.xpm"
@@ -50,16 +53,22 @@
     }
 
     #ifdef DIOGO
-        graph_paint_screen(0x777777);
+        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.29; angle += 0.01){
+        for(double angle = 0; angle <= 6.283185; angle += 0.006283185){
              sprite_set_angle(shooter1, angle);
-             //paint_screen(0x777777);
+             //graph_paint_screen(0x777777);
+             graph_clear_screen();
              sprite_draw(shooter1);
-             tickdelay(micros_to_ticks(10000));
+             graph_draw();
         }
+        t = clock() - t; //printf("%d\n", CLOCKS_PER_SEC);
+        //double dt = ((double)t)/(double)CLOCKS_PER_SEC;
+        printf("Time taken: %d/%d \n", t, CLOCKS_PER_SEC);
         sprite_dtor(shooter1);
-        graph_draw();
     #endif
 
     /// loop stuff
@@ -75,6 +84,11 @@
 
     /// cycle
     int good = 1;
+
+    #ifdef DIOGO
+        good = 0;
+    #endif
+
     while (good) {
         /* Get a request message. */
         if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) {
Index: proj/sprite.c
===================================================================
--- proj/sprite.c	(revision 167)
+++ proj/sprite.c	(revision 168)
@@ -4,6 +4,7 @@
 
 #include "graph.h"
 #include "utils.h"
+#include "fast_math.h"
 #include <math.h>
 
 struct sprite{
@@ -10,7 +11,7 @@
     int16_t x, y;
     uint16_t w, h;
     int16_t u0, v0;
-    double theta;
+    float theta;
     uint8_t *map;
 };
 
@@ -53,8 +54,8 @@
 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 = sin(p->theta);
-    double c = cos(p->theta);
+    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;
 }
