Index: proj/DR.mk
===================================================================
--- proj/DR.mk	(revision 296)
+++ proj/DR.mk	(nonexistent)
@@ -1,21 +0,0 @@
-PROG=proj
-
-.PATH: ${.CURDIR}/src
-.PATH: ${.CURDIR}/libs/graph/src
-.PATH: ${.CURDIR}/libs/kbc/src
-.PATH: ${.CURDIR}/libs/rtc/src
-.PATH: ${.CURDIR}/libs/timer/src
-.PATH: ${.CURDIR}/libs/uart/src
-.PATH: ${.CURDIR}/libs/classes/src
-.PATH: ${.CURDIR}/libs/utils/src
-
-SRCS= proj.c list.c queue.c graph.c kbc.c keyboard.c mouse.c utils.c timer.c interrupts_func.c proj_func.c fast_math.c rectangle.c font.c xpm_utils.c ent.c rtc.c uart.c hltp.c makecode_map.c menu.c
-IPATHS=-I./include -I./libs/graph/include -I./libs/kbc/include -I./libs/rtc/include -I./libs/timer/include -I./libs/uart/include -I./libs/classes/include -I./libs/utils/include -I./maps -I./media/xpm
-
-CPPFLAGS += -pedantic ${IPATHS} -D LCOM_MACRO #-D __LCOM_OPTIMIZED_
-CPPFLAGS += -D DIOGO
-
-DPADD += ${LIBLCF}
-LDADD += -llcf
-
-.include <minix.lcom.mk>

Property changes on: proj/DR.mk
___________________________________________________________________
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Index: proj/TB.mk
===================================================================
--- proj/TB.mk	(revision 296)
+++ proj/TB.mk	(nonexistent)
@@ -1,21 +0,0 @@
-PROG=proj
-
-.PATH: ${.CURDIR}/src
-.PATH: ${.CURDIR}/libs/graph/src
-.PATH: ${.CURDIR}/libs/kbc/src
-.PATH: ${.CURDIR}/libs/rtc/src
-.PATH: ${.CURDIR}/libs/timer/src
-.PATH: ${.CURDIR}/libs/uart/src
-.PATH: ${.CURDIR}/libs/classes/src
-.PATH: ${.CURDIR}/libs/utils/src
-
-SRCS= proj.c list.c queue.c graph.c kbc.c keyboard.c mouse.c utils.c timer.c interrupts_func.c proj_func.c fast_math.c rectangle.c font.c xpm_utils.c ent.c rtc.c uart.c makecode_map.c menu.c
-IPATHS=-I./include -I./libs/graph/include -I./libs/kbc/include -I./libs/rtc/include -I./libs/timer/include -I./libs/uart/include -I./libs/classes/include -I./libs/utils/include -I./maps -I./media/xpm
-
-CPPFLAGS += -pedantic ${IPATHS} -D LCOM_MACRO #-D __LCOM_OPTIMIZED_
-CPPFLAGS += -D TELMO
-
-DPADD += ${LIBLCF}
-LDADD += -llcf
-
-.include <minix.lcom.mk>

Property changes on: proj/TB.mk
___________________________________________________________________
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Index: proj/libs/graph/include/font.h
===================================================================
--- proj/libs/graph/include/font.h	(revision 296)
+++ proj/libs/graph/include/font.h	(revision 297)
@@ -29,6 +29,8 @@
 void (text_set_color) (text_t *p, uint32_t color);
 void (text_set_valign)(text_t *p, enum text_valign valign);
 void (text_set_halign)(text_t *p, enum text_halign halign);
+int16_t (text_get_x)  (const text_t *p);
+int16_t (text_get_y)  (const text_t *p);
 int (text_draw)     (const text_t *p);
 
 #endif //FONT_H_INCLUDED
Index: proj/libs/graph/src/font.c
===================================================================
--- proj/libs/graph/src/font.c	(revision 296)
+++ proj/libs/graph/src/font.c	(revision 297)
@@ -133,6 +133,8 @@
 void (text_set_color) (text_t *p, uint32_t color         ){ p->color = color  ; }
 void (text_set_valign)(text_t *p, enum text_valign valign){ p->valign = valign; }
 void (text_set_halign)(text_t *p, enum text_halign halign){ p->halign = halign; }
+int16_t (text_get_x)  (const text_t *p){ return p->x; }
+int16_t (text_get_y)  (const text_t *p){ return p->y; }
 
 int (text_draw)(const text_t *p){
     if(p == NULL) return NULL_PTR;
Index: proj/libs/graph/src/menu.c
===================================================================
--- proj/libs/graph/src/menu.c	(revision 296)
+++ proj/libs/graph/src/menu.c	(revision 297)
@@ -22,6 +22,21 @@
     rectangle_t *frame;
 };
 
+static int menu_recalculate(menu_t *menu){
+    const int Wtotal = 2*W1+W;
+    const int Htotal = 2*H1+menu->sz*H+(menu->sz-1)*H2;
+    int x = graph_get_XRes()/2-Wtotal/2;
+    int y = graph_get_YRes()/2-Htotal/2;
+    rectangle_set_pos (menu->frame, x, y);
+    rectangle_set_size(menu->frame, Wtotal, Htotal);
+    x += W1; y += H1;
+    for(size_t i = 0; i < menu->sz; ++i, y+=H+H2){
+        rectangle_set_pos(menu->r[i], x, y);
+        text_set_pos     (menu->t[i], x+W/2, y+H/2);
+    }
+    return SUCCESS;
+}
+
 menu_t* (menu_ctor)(const font_t *fnt){
     if(fnt == NULL) return NULL;
     menu_t *ret = (menu_t*)malloc(sizeof(menu_t));
@@ -31,30 +46,17 @@
     ret->r = NULL;
     ret->t = NULL;
 
-    ret->frame = rectangle_ctor(0, 0, 800, 500);
+    ret->frame = rectangle_ctor(0, 0, 0, 0);
     rectangle_set_fill_color(ret->frame, GRAPH_BLACK);
     rectangle_set_outline_width(ret->frame, 6);
     rectangle_set_outline_color(ret->frame, GRAPH_WHITE);
     rectangle_set_fill_trans(ret->frame, GRAPH_TRANSPARENT);
 
+    menu_recalculate(ret);
+
     return ret;
 }
 
-static int menu_recalculate(menu_t *menu){
-    const int Wtotal = 2*W1+W;
-    const int Htotal = 2*H1+menu->sz*H+(menu->sz-1)*H2;
-    int x = graph_get_XRes()/2-Wtotal/2;
-    int y = graph_get_YRes()/2-Htotal/2;
-    rectangle_set_pos (menu->frame, x, y);
-    rectangle_set_size(menu->frame, Wtotal, Htotal);
-    x += W1; y += H1;
-    for(size_t i = 0; i < menu->sz; ++i, y+=H+H2){
-        rectangle_set_pos(menu->r[i], x, y);
-        text_set_pos     (menu->t[i], x+W/2, y+H/2);
-    }
-    return SUCCESS;
-}
-
 int (menu_add_item)(menu_t *menu, const char *s){
     rectangle_t *r = rectangle_ctor(0, 0, W, H);
     text_t      *t = text_ctor(menu->fnt, s);
Index: proj/libs/uart/include/uart.h
===================================================================
--- proj/libs/uart/include/uart.h	(revision 296)
+++ proj/libs/uart/include/uart.h	(revision 297)
@@ -50,7 +50,8 @@
 int uart_disable_int_tx(int base_addr);
 
 /// NCTP - Non-critical transmission protocol
-int nctp_init(void (*proc_func)(const uint8_t*, const size_t));
+int nctp_init(void);
+int nctp_set_processor(void (*proc_func)(const uint8_t*, const size_t));
 int nctp_free(void);
 
 int nctp_send(size_t num, uint8_t* ptr[], size_t sz[]);
Index: proj/libs/uart/src/uart.c
===================================================================
--- proj/libs/uart/src/uart.c	(revision 296)
+++ proj/libs/uart/src/uart.c	(revision 297)
@@ -286,9 +286,12 @@
 queue_t *in  = NULL;
 void (*process)(const uint8_t*, const size_t);
 
-int nctp_init(void (*proc_func)(const uint8_t*, const size_t)){
+int nctp_init(){
     out = queue_ctor(); if(out == NULL) return NULL_PTR;
     in  = queue_ctor(); if(in  == NULL) return NULL_PTR;
+    return SUCCESS;
+}
+int nctp_set_processor(void (*proc_func)(const uint8_t*, const size_t)){
     process = proc_func;
     return SUCCESS;
 }
Index: proj/src/interrupts_func.c
===================================================================
--- proj/src/interrupts_func.c	(revision 296)
+++ proj/src/interrupts_func.c	(revision 297)
@@ -49,7 +49,7 @@
                                          NULL,
                                          NULL,
                                      };
-
+/*
 static void process_received(const uint8_t *p, const size_t sz){
     void *q = NULL;
     hltp_type t = hltp_interpret(p, sz, &q);
@@ -61,7 +61,7 @@
         default: break;
     }
 }
-
+*/
 int (subscribe_all)(void) {
 
     /// Timer interrupt handling
@@ -123,7 +123,7 @@
         return SBCR_ERROR;
     }
     uart_subscribed = 1;
-    nctp_init(process_received);
+    nctp_init();
 
     return SUCCESS;
 }
Index: proj/src/proj.c
===================================================================
--- proj/src/proj.c	(revision 296)
+++ proj/src/proj.c	(revision 297)
@@ -70,24 +70,20 @@
     /// subscribe interrupts
     if (subscribe_all()) { return 1; }
 
-    #ifndef DIOGO
-        /// 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;
-        }
-    #endif
+    /// 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;
+    }
 
     /// Load stuff
     {
-        #ifndef DIOGO
-            graph_clear_screen();
-            text_t *txt = text_ctor(consolas, "Loading...");
-            text_draw(txt);
-            text_dtor(txt);
-            graph_draw();
-        #endif
+        graph_clear_screen();
+        text_t *txt = text_ctor(consolas, "Loading...");
+        text_draw(txt);
+        text_dtor(txt);
+        graph_draw();
 
         bsp_crosshair = get_crosshair(); if(bsp_crosshair == NULL) printf("Failed to get crosshair\n");
         bsp_shooter   = get_shooter  (); if(bsp_shooter   == NULL) printf("Failed to get shooter\n");
@@ -99,32 +95,22 @@
         sp_crosshair = sprite_ctor(bsp_crosshair); if(sp_crosshair == NULL) printf("Failed to get crosshair sprite\n");
     }
 
-    #ifndef DIOGO
-        menu_t *main_menu = menu_ctor(consolas);
-        menu_add_item(main_menu, "Play");
-        menu_add_item(main_menu, "Chat");
-        menu_add_item(main_menu, "Exit");
-    #endif
+    menu_t *main_menu = menu_ctor(consolas);
+    menu_add_item(main_menu, "Play");
+    menu_add_item(main_menu, "Chat");
+    menu_add_item(main_menu, "Exit");
 
-    #ifndef DIOGO
-        //uint32_t refresh_count_value = sys_hz() / REFRESH_RATE;
-        uint8_t last_lb = 0;
-        struct packet pp;
-        keys_t *keys = get_key_presses();
-    #endif
+    //uint32_t refresh_count_value = sys_hz() / REFRESH_RATE;
+    uint8_t last_lb = 0;
+    struct packet pp;
+    keys_t *keys = get_key_presses();
+
     /// loop stuff
     int ipc_status;
     message msg;
 
-    #ifdef DIOGO
-        char buffer[1024]; // buffer
-        int buffer_pos = 0;
-    #endif
+    int click = 0;
 
-    #ifndef DIOGO
-        int click = 0;
-    #endif
-
     int good = true;
 
     while (good) {
@@ -140,7 +126,6 @@
                         if (msg.m_notify.interrupts & n) {
                             interrupt_handler(i);
                             switch (i) {
-                            #ifndef DIOGO
                             case TIMER0_IRQ:
 
                                 graph_clear_screen();
@@ -159,25 +144,8 @@
                                 graph_draw();
 
                                 break;
-                            #endif
                             case KBC_IRQ:
                                 if ((scancode[0]) == ESC_BREAK_CODE) good = false;
-                                #ifdef DIOGO
-                                else if ((scancode[0]) == ENTER_MAKE_CODE) {
-                                    buffer[buffer_pos] = '\0';
-                                    printf("\nSending string -%s-", buffer);
-                                    printf(" (output: %d)\n",
-                                        hltp_send_string(buffer));
-                                    buffer_pos = 0;
-                                }
-                                else {
-                                    char c = map_makecode(scancode[0]);
-                                    if (c == ERROR_CODE) break;
-                                    buffer[buffer_pos++] = c;
-                                    printf("%c", c);
-                                }
-                                #endif
-                            #ifndef DIOGO
                             case MOUSE_IRQ:
                                 if (counter_mouse_ih >= 3) {
                                     mouse_parse_packet(packet_mouse_ih, &pp);
@@ -187,12 +155,6 @@
                                     counter_mouse_ih = 0;
                                 }
                                 break;
-                            #endif
-                            #ifdef DIOGO
-                            case COM1_IRQ:
-                                nctp_ih();
-                                break;
-                            #endif
                             }
                         }
                     }
@@ -221,7 +183,6 @@
         return 1;
     }
 
-
     if (cleanup()) {
         printf("%s: failed to cleanup.\n", __func__);
         return 1;
@@ -362,6 +323,173 @@
     return SUCCESS;
 }
 
+#define CHAT_MAX_SIZE   64
+#define CHAT_MAX_NUM    10
+
+text_t      *t_text[CHAT_MAX_NUM] = {NULL};
+rectangle_t *r_text               =  NULL;
+
+static void chat_process(const uint8_t *p, const size_t sz){
+    char buffer2[CHAT_MAX_NUM+3];
+    void *dest = NULL;
+    hltp_type tp = hltp_interpret(p, sz, &dest);
+    switch(tp){
+        case hltp_type_string:
+            strcpy(buffer2, dest);
+            strncat(buffer2, " <", 2);
+            for(size_t i = CHAT_MAX_NUM-1; i; --i)
+                text_set_text(t_text[i], text_get_string(t_text[i-1]));
+            text_set_text(t_text[0], buffer2);
+            for(size_t i = 0; i < CHAT_MAX_NUM; ++i){
+                if(text_get_string(t_text[i])[0] == '>'){
+                    text_set_pos(t_text[i], rectangle_get_x(r_text)+50, text_get_y(t_text[i]));
+                    text_set_halign(t_text[i], text_halign_left);
+                }else{
+                    text_set_pos(t_text[i], rectangle_get_x(r_text)+rectangle_get_w(r_text)-50, text_get_y(t_text[i]));
+                    text_set_halign(t_text[i], text_halign_right);
+                }
+            }
+            break;
+        default: break;
+    }
+}
+
 int (chat)(void){
+    int r;
+
+    nctp_set_processor(chat_process);
+
+    struct packet pp;
+
+    rectangle_t *r_buffer = NULL; {
+        r_buffer = rectangle_ctor(0,0,750,70);
+        rectangle_set_pos(r_buffer, graph_get_XRes()/2  -rectangle_get_w(r_buffer)/2,
+                                    graph_get_YRes()*0.8-rectangle_get_h(r_buffer)/2);
+        rectangle_set_fill_color   (r_buffer, GRAPH_BLACK);
+        rectangle_set_outline_width(r_buffer, 2);
+        rectangle_set_outline_color(r_buffer, GRAPH_WHITE);
+        rectangle_set_fill_trans(r_buffer, GRAPH_TRANSPARENT);
+    }
+    text_t      *t_buffer = NULL; {
+        t_buffer = text_ctor(consolas, "");
+        text_set_pos(t_buffer, rectangle_get_x(r_buffer)+50,
+                               rectangle_get_y(r_buffer)+rectangle_get_h(r_buffer)/2);
+        text_set_halign(t_buffer, text_halign_left);
+        text_set_valign(t_buffer, text_valign_center);
+        text_set_color (t_buffer, TEXT_COLOR);
+    }
+
+    /** r_text */ {
+        r_text = rectangle_ctor(0,0,750,500);
+        rectangle_set_pos(r_text, graph_get_XRes()/2  -rectangle_get_w(r_buffer)/2,
+                                  graph_get_YRes()*0.1-rectangle_get_h(r_buffer)/2);
+        rectangle_set_fill_color   (r_text, GRAPH_BLACK);
+        rectangle_set_outline_width(r_text, 2);
+        rectangle_set_outline_color(r_text, GRAPH_WHITE);
+        rectangle_set_fill_trans(r_text, GRAPH_TRANSPARENT);
+    }
+    /** t_text */ {
+        for(size_t i = 0; i < CHAT_MAX_NUM; ++i){
+            t_text[i] = text_ctor(consolas, " ");
+            text_set_pos(t_text[i], rectangle_get_x(r_text)+50,
+                                       rectangle_get_y(r_text)+rectangle_get_h(r_text)-30-30*i);
+            text_set_halign(t_text[i], text_halign_left);
+            text_set_valign(t_text[i], text_valign_bottom);
+            text_set_color (t_text[i], TEXT_COLOR);
+        }
+    }
+
+    /// loop stuff
+    int ipc_status;
+    message msg;
+
+    char buffer[CHAT_MAX_SIZE] = "";
+
+    int good = true;
+
+    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);
+                            switch (i) {
+                            case TIMER0_IRQ:
+                                graph_clear_screen();
+                                sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y());
+
+                                rectangle_draw(r_buffer);
+                                text_draw(t_buffer);
+
+                                rectangle_draw(r_text);
+                                for(size_t i = 0; i < CHAT_MAX_NUM; ++i) text_draw(t_text[i]);
+
+                                sprite_draw(sp_crosshair);
+                                graph_draw();
+                                break;
+                            case KBC_IRQ:
+                                if ((scancode[0]) == ESC_BREAK_CODE) good = false;
+                                else if ((scancode[0]) == ENTER_MAKE_CODE) {
+                                    hltp_send_string(buffer);
+                                    char buffer2[CHAT_MAX_SIZE+3] = "> ";
+                                    strncat(buffer2, buffer, strlen(buffer));
+                                    for(size_t i = CHAT_MAX_NUM-1; i; --i)
+                                        text_set_text(t_text[i], text_get_string(t_text[i-1]));
+                                    text_set_text(t_text[0], buffer2);
+                                    for(size_t i = 0; i < CHAT_MAX_NUM; ++i){
+                                        if(text_get_string(t_text[i])[0] == '>'){
+                                            text_set_pos(t_text[i], rectangle_get_x(r_text)+50, text_get_y(t_text[i]));
+                                            text_set_halign(t_text[i], text_halign_left);
+                                        }else{
+                                            text_set_pos(t_text[i], rectangle_get_x(r_text)+rectangle_get_w(r_text)-50, text_get_y(t_text[i]));
+                                            text_set_halign(t_text[i], text_halign_right);
+                                        }
+                                    }
+
+                                    buffer[0] = '\0';
+                                    text_set_text(t_buffer, buffer);
+                                }
+                                else {
+                                    char c = map_makecode(scancode[0]);
+                                    if (c == ERROR_CODE) break;
+                                    if(strlen(buffer) < CHAT_MAX_SIZE) strncat(buffer, &c, 1);
+                                    else                    printf("Char limit exceeded\n");
+                                    text_set_text(t_buffer, buffer);
+                                }
+                            case MOUSE_IRQ:
+                                if (counter_mouse_ih >= 3) {
+                                    mouse_parse_packet(packet_mouse_ih, &pp);
+                                    update_mouse(&pp);
+                                    counter_mouse_ih = 0;
+                                }
+                                break;
+                            case COM1_IRQ:
+                                nctp_ih();
+                                break;
+                            }
+                        }
+                    }
+
+                    break;
+                default:
+                    break; /* no other notifications expected: do nothing */
+            }
+        } else { /* received standart message, not a notification */
+            /* no standart message expected: do nothing */
+        }
+    }
+
+    rectangle_dtor(r_buffer);
+    text_dtor     (t_buffer);
+
+    rectangle_dtor(r_text);
+    for(size_t i = 0; i < CHAT_MAX_NUM; ++i) text_dtor(t_text[i]);
+
     return SUCCESS;
 }
