Index: proj/include/interrupts_func.h
===================================================================
--- proj/include/interrupts_func.h	(revision 303)
+++ proj/include/interrupts_func.h	(revision 304)
@@ -21,4 +21,6 @@
  */
 void interrupt_handler(uint8_t handler);
 
+int get_interrupts_vector(uint32_t *p);
+
 #endif /* end of include guard: INTERRUPTS_FUNC_H_INCLUDED */
Index: proj/src/interrupts_func.c
===================================================================
--- proj/src/interrupts_func.c	(revision 303)
+++ proj/src/interrupts_func.c	(revision 304)
@@ -198,3 +198,25 @@
 void (mouse_manager)() {
 
 }
+
+int get_interrupts_vector(uint32_t *p){
+    int r;
+
+    *p = 0;
+
+    int ipc_status;
+    message msg;
+    if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) {
+        printf("driver_receive failed with %d", r);
+        return OTHER_ERROR;
+    }
+    if (is_ipc_notify(ipc_status)) { /* received notification */
+        switch (_ENDPOINT_P(msg.m_source)) {
+            case HARDWARE: /* hardware interrupt notification */
+                *p = msg.m_notify.interrupts;
+                return SUCCESS;
+            default: break; /* no other notifications expected: do nothing */
+        }
+    }
+    return SUCCESS;
+}
Index: proj/src/proj.c
===================================================================
--- proj/src/proj.c	(revision 303)
+++ proj/src/proj.c	(revision 304)
@@ -214,66 +214,48 @@
     keys_t *keys = get_key_presses();
 
     /// loop stuff
-    int ipc_status;
-    message msg;
-
     int click = 0;
-
+    uint32_t int_vector = 0;
     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:
+        if((r = get_interrupts_vector(&int_vector))) return r;
+        for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) {
+            if (int_vector & n) {
+                interrupt_handler(i);
+                switch (i) {
+                case TIMER0_IRQ:
 
-                                graph_clear_screen();
-                                switch(menu_update_state(main_menu, click)){
-                                    case -1: break;
-                                    case  0: campaign(); break;
-                                    case  1: zombies(); break;
-                                    case  2: good = false; break;
-                                }
-                                menu_draw(main_menu);
+                    graph_clear_screen();
+                    switch(menu_update_state(main_menu, click)){
+                        case -1: break;
+                        case  0: campaign(); break;
+                        case  1: zombies(); break;
+                        case  2: good = false; break;
+                    }
+                    menu_draw(main_menu);
 
-                                click = 0;
+                    click = 0;
 
-                                sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y());
-                                sprite_draw(sp_crosshair);
-                                graph_draw();
+                    sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y());
+                    sprite_draw(sp_crosshair);
+                    graph_draw();
 
-                                break;
-                            case KBC_IRQ:
-                                if ((scancode[0]) == ESC_BREAK_CODE) good = false;
-                            case MOUSE_IRQ:
-                                if (counter_mouse_ih >= 3) {
-                                    mouse_parse_packet(packet_mouse_ih, &pp);
-                                    update_mouse(&pp);
-                                    if (!click) click = last_lb ^ keys->lb_pressed && keys->lb_pressed;
-                                    last_lb = keys->lb_pressed;
-                                    counter_mouse_ih = 0;
-                                }
-                                break;
-                            case COM1_IRQ: nctp_ih(); break;
-                            }
-                        }
+                    break;
+                case KBC_IRQ:
+                    if ((scancode[0]) == ESC_BREAK_CODE) good = false;
+                case MOUSE_IRQ:
+                    if (counter_mouse_ih >= 3) {
+                        mouse_parse_packet(packet_mouse_ih, &pp);
+                        update_mouse(&pp);
+                        if (!click) click = last_lb ^ keys->lb_pressed && keys->lb_pressed;
+                        last_lb = keys->lb_pressed;
+                        counter_mouse_ih = 0;
                     }
-
                     break;
-                default:
-                    break; /* no other notifications expected: do nothing */
+                case COM1_IRQ: nctp_ih(); break;
+                }
             }
-        } else { /* received standart message, not a notification */
-            /* no standart message expected: do nothing */
         }
     }
 
@@ -311,89 +293,74 @@
    keys_t *keys = get_key_presses();
 
     /// loop stuff
-    int ipc_status;
-    message msg;
+    uint32_t int_vector = 0;
     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:
+        /* Get a request message. */
+        if((r = get_interrupts_vector(&int_vector))) return r;
+        for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) {
+           if (int_vector & n) {
+               interrupt_handler(i);
+               switch (i) {
+               case TIMER0_IRQ:
 
-                               if (no_interrupts % 60 == 0) timer_update(in_game_timer);
-                               update_movement(map1, shooter1, keys, shooter_list);
+                   if (no_interrupts % 60 == 0) timer_update(in_game_timer);
+                   update_movement(map1, shooter1, keys, shooter_list);
 
-                               update_game_state(map1, shooter_list, bullet_list);
+                   update_game_state(map1, shooter_list, bullet_list);
 
-                               //update_scale();
-                               double angle = get_mouse_angle(shooter1);
-                               gunner_set_angle(shooter1, angle - M_PI_2);
+                   //update_scale();
+                   double angle = get_mouse_angle(shooter1);
+                   gunner_set_angle(shooter1, angle - M_PI_2);
 
-                               ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0,
-                                              gunner_get_y(shooter1)-ent_get_YLength()/2.0);
+                   ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0,
+                                  gunner_get_y(shooter1)-ent_get_YLength()/2.0);
 
-                               graph_clear_screen();
-                               map_draw   (map1);
-                               bullet_draw_list(bullet_list);
-                               gunner_draw_list(shooter_list);
+                   graph_clear_screen();
+                   map_draw   (map1);
+                   bullet_draw_list(bullet_list);
+                   gunner_draw_list(shooter_list);
 
-                               text_draw(in_game_timer->text);
+                   text_draw(in_game_timer->text);
 
-                               sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y());
-                               sprite_draw(sp_crosshair);
-                               graph_draw();
+                   sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y());
+                   sprite_draw(sp_crosshair);
+                   graph_draw();
 
-                               break;
-                           case KBC_IRQ:
-                               if ((scancode[0]) == ESC_BREAK_CODE) {
-                                   good = false;
-                                   // reset game
-                                   while(list_size(bullet_list) > 0){
-                                       bullet_t *p = (bullet_t*)list_erase(bullet_list, list_begin(bullet_list));
-                                       bullet_dtor(p);
-                                   }
-                                   list_node_t *it = list_begin(shooter_list);
-                                   while (it != list_end(shooter_list)) {
-                                       gunner_t *p = *(gunner_t**)list_node_val(it);
-                                       get_random_spawn(map1, p);
-                                       gunner_set_curr_health(p, gunner_get_health(p));
-                                       it = list_node_next(it);
-                                   }
-                                   timer_reset(in_game_timer);
-                               }
-                               break;
-                           case MOUSE_IRQ:
-                               if (counter_mouse_ih >= 3) {
-                                   mouse_parse_packet(packet_mouse_ih, &pp);
-                                   update_mouse(&pp);
-                                   if (last_lb ^ keys->lb_pressed && keys->lb_pressed)
-                                       shoot_bullet(shooter1, bullet_list, bsp_bullet);
-                                   last_lb = keys->lb_pressed;
-                                   counter_mouse_ih = 0;
-
-                               }
-                               break;
-                           case COM1_IRQ: nctp_ih(); break;
-                           }
+                   break;
+               case KBC_IRQ:
+                   if ((scancode[0]) == ESC_BREAK_CODE) {
+                       good = false;
+                       // reset game
+                       while(list_size(bullet_list) > 0){
+                           bullet_t *p = (bullet_t*)list_erase(bullet_list, list_begin(bullet_list));
+                           bullet_dtor(p);
                        }
+                       list_node_t *it = list_begin(shooter_list);
+                       while (it != list_end(shooter_list)) {
+                           gunner_t *p = *(gunner_t**)list_node_val(it);
+                           get_random_spawn(map1, p);
+                           gunner_set_curr_health(p, gunner_get_health(p));
+                           it = list_node_next(it);
+                       }
+                       timer_reset(in_game_timer);
                    }
                    break;
-               default:
-                   break; /* no other notifications expected: do nothing */
+               case MOUSE_IRQ:
+                   if (counter_mouse_ih >= 3) {
+                       mouse_parse_packet(packet_mouse_ih, &pp);
+                       update_mouse(&pp);
+                       if (last_lb ^ keys->lb_pressed && keys->lb_pressed)
+                           shoot_bullet(shooter1, bullet_list, bsp_bullet);
+                       last_lb = keys->lb_pressed;
+                       counter_mouse_ih = 0;
+
+                   }
+                   break;
+               case COM1_IRQ: nctp_ih(); break;
+               }
            }
-       } else { /* received standart message, not a notification */
-           /* no standart message expected: do nothing */
-       }
+        }
     }
 
     while(list_size(shooter_list) > 0){
@@ -442,8 +409,7 @@
    keys_t *keys = get_key_presses();
 
     /// loop stuff
-    int ipc_status;
-    message msg;
+    uint32_t int_vector = 0;
     int good = true;
     int dead = false;
 
@@ -450,98 +416,85 @@
     int health = 50;
 
     while (good && !dead) {
-       /* 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: //printf("L463\n");
+        /* Get a request message. */
+        if((r = get_interrupts_vector(&int_vector))) return r;
+        for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) {
+            if (int_vector & n) {
+               interrupt_handler(i);
+               switch (i) {
+               case TIMER0_IRQ: //printf("L463\n");
 
-                               if (no_interrupts % 60 == 0) timer_update(in_game_timer);//printf("L465\n");
-                               update_movement(map1, shooter1, keys, shooter_list);//printf("L466\n");
+                   if (no_interrupts % 60 == 0) timer_update(in_game_timer);//printf("L465\n");
+                   update_movement(map1, shooter1, keys, shooter_list);//printf("L466\n");
 
-                               update_game_state(map1, shooter_list, bullet_list);//printf("L468\n");
+                   update_game_state(map1, shooter_list, bullet_list);//printf("L468\n");
 
-                               if(list_find(shooter_list, shooter1) == list_end(shooter_list)){ printf("YOU DIED\n");
-                                   good = false;
-                                   dead = true;
-                                   break;
-                               } //printf("L489\n");
+                   if(list_find(shooter_list, shooter1) == list_end(shooter_list)){
+                       good = false;
+                       dead = true;
+                       break;
+                   } //printf("L489\n");
 
-                               //update_scale();
-                               double angle = get_mouse_angle(shooter1);//printf("L471\n");
-                               gunner_set_angle(shooter1, angle - M_PI_2); //printf("L472\n");
+                   //update_scale();
+                   double angle = get_mouse_angle(shooter1);//printf("L471\n");
+                   gunner_set_angle(shooter1, angle - M_PI_2); //printf("L472\n");
 
-                               ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0,
-                                              gunner_get_y(shooter1)-ent_get_YLength()/2.0);
+                   ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0,
+                                  gunner_get_y(shooter1)-ent_get_YLength()/2.0);
 
-                               while(list_size(shooter_list) < ZOMBIES_NUM){
-                                   gunner_t *zombie = gunner_ctor(bsp_zombie, bsp_nothing, gunner_meelee, 3);
-                                   gunner_set_health(zombie, health);
-                                   gunner_set_curr_health(zombie, health);
-                                   health *= ZOMBIE_HEALTH_FACTOR;
-                                   get_random_spawn(map1, zombie);
-                                   list_push_back(shooter_list, zombie);
-                               } //printf("L484\n");
+                   while(list_size(shooter_list) < ZOMBIES_NUM){
+                       gunner_t *zombie = gunner_ctor(bsp_zombie, bsp_nothing, gunner_meelee, 3);
+                       gunner_set_health(zombie, health);
+                       gunner_set_curr_health(zombie, health);
+                       health *= ZOMBIE_HEALTH_FACTOR;
+                       get_random_spawn(map1, zombie);
+                       list_push_back(shooter_list, zombie);
+                   } //printf("L484\n");
 
-                               graph_clear_screen();
-                               map_draw   (map1);
-                               bullet_draw_list(bullet_list);
-                               gunner_draw_list(shooter_list);
+                   graph_clear_screen();
+                   map_draw   (map1);
+                   bullet_draw_list(bullet_list);
+                   gunner_draw_list(shooter_list);
 
-                               text_draw(in_game_timer->text);
+                   text_draw(in_game_timer->text);
 
-                               sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y());
-                               sprite_draw(sp_crosshair);
-                               graph_draw(); //printf("L508\n");
+                   sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y());
+                   sprite_draw(sp_crosshair);
+                   graph_draw(); //printf("L508\n");
 
-                               break;
-                           case KBC_IRQ:
-                               if ((scancode[0]) == ESC_BREAK_CODE) {
-                                   good = false;
-                                   // reset game
-                                   while(list_size(bullet_list) > 0){
-                                       bullet_t *p = (bullet_t*)list_erase(bullet_list, list_begin(bullet_list));
-                                       bullet_dtor(p);
-                                   }
-                                   list_node_t *it = list_begin(shooter_list);
-                                   while (it != list_end(shooter_list)) {
-                                       gunner_t *p = *(gunner_t**)list_node_val(it);
-                                       get_random_spawn(map1, p);
-                                       gunner_set_curr_health(p, gunner_get_health(p));
-                                       it = list_node_next(it);
-                                   }
-                                   timer_reset(in_game_timer);
-                               }
-                               break;
-                           case MOUSE_IRQ:
-                               if (counter_mouse_ih >= 3) {
-                                   mouse_parse_packet(packet_mouse_ih, &pp);
-                                   update_mouse(&pp);
-                                   if (last_lb ^ keys->lb_pressed && keys->lb_pressed)
-                                       shoot_bullet(shooter1, bullet_list, bsp_bullet);
-                                   last_lb = keys->lb_pressed;
-                                   counter_mouse_ih = 0;
-
-                               }
-                               break;
-                           case COM1_IRQ: nctp_ih(); break;
-                           }
+                   break;
+               case KBC_IRQ:
+                   if ((scancode[0]) == ESC_BREAK_CODE) {
+                       good = false;
+                       // reset game
+                       while(list_size(bullet_list) > 0){
+                           bullet_t *p = (bullet_t*)list_erase(bullet_list, list_begin(bullet_list));
+                           bullet_dtor(p);
                        }
+                       list_node_t *it = list_begin(shooter_list);
+                       while (it != list_end(shooter_list)) {
+                           gunner_t *p = *(gunner_t**)list_node_val(it);
+                           get_random_spawn(map1, p);
+                           gunner_set_curr_health(p, gunner_get_health(p));
+                           it = list_node_next(it);
+                       }
+                       timer_reset(in_game_timer);
                    }
                    break;
-               default:
-                   break; /* no other notifications expected: do nothing */
+               case MOUSE_IRQ:
+                   if (counter_mouse_ih >= 3) {
+                       mouse_parse_packet(packet_mouse_ih, &pp);
+                       update_mouse(&pp);
+                       if (last_lb ^ keys->lb_pressed && keys->lb_pressed)
+                           shoot_bullet(shooter1, bullet_list, bsp_bullet);
+                       last_lb = keys->lb_pressed;
+                       counter_mouse_ih = 0;
+
+                   }
+                   break;
+               case COM1_IRQ: nctp_ih(); break;
+               }
            }
-       } else { /* received standart message, not a notification */
-           /* no standart message expected: do nothing */
        }
     }
 
@@ -654,84 +607,70 @@
     }
 
     /// loop stuff
-    int ipc_status;
-    message msg;
+    uint32_t int_vector = 0;
     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());
+        if((r = get_interrupts_vector(&int_vector))) return r;
+        for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) {
+            if (int_vector & 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);
-                                text_draw(t_size);
+                    rectangle_draw(r_buffer);
+                    text_draw(t_buffer);
+                    text_draw(t_size);
 
-                                rectangle_draw(r_text);
-                                for(size_t i = 0; i < CHAT_MAX_NUM; ++i) text_draw(t_text[i]);
+                    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';
-                                } else if(scancode[0] == BACKSPACE_MAKE_CODE){
-                                    buffer[strlen(buffer)-1] = '\0';
-                                } 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);
-                                char buffer2[20];
-                                sprintf(buffer2, "%d/%d", strlen(buffer), CHAT_MAX_SIZE);
-                                text_set_text(t_size, buffer2);
-                            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;
+                    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';
+                    } else if(scancode[0] == BACKSPACE_MAKE_CODE){
+                        buffer[strlen(buffer)-1] = '\0';
+                    } 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);
+                    char buffer2[20];
+                    sprintf(buffer2, "%d/%d", strlen(buffer), CHAT_MAX_SIZE);
+                    text_set_text(t_size, buffer2);
+                case MOUSE_IRQ:
+                    if (counter_mouse_ih >= 3) {
+                        mouse_parse_packet(packet_mouse_ih, &pp);
+                        update_mouse(&pp);
+                        counter_mouse_ih = 0;
+                    }
                     break;
-                default:
-                    break; /* no other notifications expected: do nothing */
+                case COM1_IRQ: nctp_ih(); break;
+                }
             }
-        } else { /* received standart message, not a notification */
-            /* no standart message expected: do nothing */
         }
     }
 
