Project

General

Profile

Statistics
| Revision:

root / proj / src / proj.c @ 343

History | View | Annotate | Download (37.6 KB)

1 144 up20180655
#include <lcom/lcf.h>
2
#include <lcom/proj.h>
3
#include <lcom/liblm.h>
4 185 up20180655
#include <math.h>
5 144 up20180655
6 149 up20180655
#include "proj_macros.h"
7 179 up20180642
#include "proj_func.h"
8 147 up20180655
9 149 up20180655
#include "kbc.h"
10
#include "timer.h"
11
#include "keyboard.h"
12 150 up20180655
#include "mouse.h"
13 189 up20180655
#include "graph.h"
14 291 up20180642
#include "menu.h"
15 234 up20180655
#include "rtc.h"
16 287 up20180642
#include "hltp.h"
17 153 up20180655
#include "interrupts_func.h"
18 270 up20180655
#include "makecode_map.h"
19 149 up20180655
20 179 up20180642
#include "graph.h"
21 332 up20180642
#include "sprite.h"
22 179 up20180642
#include "rectangle.h"
23 182 up20180642
#include "font.h"
24 192 up20180642
#include "ent.h"
25 168 up20180642
26 192 up20180642
#include "crosshair.h"
27
#include "shooter.h"
28 303 up20180642
#include "zombie.h"
29 192 up20180642
#include "pistol.h"
30
#include "nothing.h"
31 237 up20180642
#include "bullet.h"
32 216 up20180642
#include "map1.h"
33 183 up20180642
34 294 up20180642
#include "errors.h"
35
36 226 up20180642
#include "list.h"
37
38 144 up20180655
int main(int argc, char* argv[]) {
39
40
    lcf_set_language("EN-US");
41
42 323 up20180642
    lcf_trace_calls("/home/lcom/labs/proj/trace.txt");
43 144 up20180655
44 323 up20180642
    lcf_log_output("/home/lcom/labs/proj/output.txt");
45 144 up20180655
46
    if (lcf_start(argc, argv)) return 1;
47
48
    lcf_cleanup();
49
50
    return 0;
51
}
52 147 up20180655
53 321 up20180642
static basic_sprite_t       *bsp_crosshair = NULL;
54
static basic_sprite_t       *bsp_shooter   = NULL;
55
static basic_sprite_t       *bsp_zombie    = NULL;
56
static basic_sprite_t       *bsp_pistol    = NULL;
57
static basic_sprite_t       *bsp_nothing   = NULL;
58
static basic_sprite_t       *bsp_bullet    = NULL;
59
static map_t                *map1          = NULL;
60
static sprite_t             *sp_crosshair  = NULL;
61 294 up20180642
62 300 up20180642
static int (singleplayer)(void);
63 311 up20180655
static int (multiplayer)(void);
64 300 up20180642
static int (chat)(void);
65 149 up20180655
int(proj_main_loop)(int argc, char *argv[]) {
66 328 up20180642
    (void)argc; (void)argv;
67 170 up20180642
68
    int r;
69
70 313 up20180642
    if(font_init()){ printf("Failed to initialize fonts\n"); return 1; }
71 192 up20180642
72 261 up20180642
    /// subscribe interrupts
73
    if (subscribe_all()) { return 1; }
74 170 up20180642
75 297 up20180642
    /// initialize graphics
76
    if(graph_init(GRAPH_MODE)){
77
        printf("%s: failed to initalize graphics.\n", __func__);
78
        if (cleanup()) printf("%s: failed to cleanup.\n", __func__);
79
        return 1;
80
    }
81 152 up20180642
82 261 up20180642
    /// Load stuff
83
    {
84 297 up20180642
        graph_clear_screen();
85 314 up20180642
        text_t *txt = text_ctor(font_get_default(), "Loading...");
86 309 up20180642
        text_set_pos(txt, graph_get_XRes()/2, graph_get_YRes()/2);
87
        text_set_valign(txt, text_valign_center);
88
        text_set_halign(txt, text_halign_center);
89
        text_set_color(txt, TEXT_COLOR);
90 297 up20180642
        text_draw(txt);
91
        text_dtor(txt);
92
        graph_draw();
93 183 up20180642
94 261 up20180642
        bsp_crosshair = get_crosshair(); if(bsp_crosshair == NULL) printf("Failed to get crosshair\n");
95
        bsp_shooter   = get_shooter  (); if(bsp_shooter   == NULL) printf("Failed to get shooter\n");
96 303 up20180642
        bsp_zombie    = get_zombie   (); if(bsp_zombie    == NULL) printf("Failed to get zombie\n");
97 261 up20180642
        bsp_pistol    = get_pistol   (); if(bsp_pistol    == NULL) printf("Failed to get pistol\n");
98
        bsp_nothing   = get_nothing  (); if(bsp_nothing   == NULL) printf("Failed to get nothing\n");
99
        bsp_bullet    = get_bullet   (); if(bsp_bullet    == NULL) printf("Failed to get bullet\n");
100
        map1          = get_map1     (); if(map1          == NULL) printf("Failed to get map1\n");
101 226 up20180642
102 261 up20180642
        sp_crosshair = sprite_ctor(bsp_crosshair); if(sp_crosshair == NULL) printf("Failed to get crosshair sprite\n");
103
    }
104 226 up20180642
105 314 up20180642
    menu_t *main_menu = menu_ctor(font_get_default());
106 299 up20180642
    menu_add_item(main_menu, "Single player");
107
    menu_add_item(main_menu, "Multiplayer");
108 297 up20180642
    menu_add_item(main_menu, "Chat");
109
    menu_add_item(main_menu, "Exit");
110 234 up20180655
111 297 up20180642
    //uint32_t refresh_count_value = sys_hz() / REFRESH_RATE;
112
    uint8_t last_lb = 0;
113
    struct packet pp;
114
    keys_t *keys = get_key_presses();
115
116 261 up20180642
    /// loop stuff
117 297 up20180642
    int click = 0;
118 323 up20180642
    uint64_t int_vector = 0;
119 295 up20180642
    int good = true;
120
    while (good) {
121 261 up20180642
        /* Get a request message. */
122 307 up20180642
        if((r = get_interrupts_vector(&int_vector))) return r;
123 321 up20180642
        uint32_t n = 1;
124
        for (uint8_t i = 0; i < 32; i++, n <<= 1) {
125 307 up20180642
            if (int_vector & n) {
126
                interrupt_handler(i);
127
                switch (i) {
128
                    case TIMER0_IRQ:
129 192 up20180642
130 307 up20180642
                    graph_clear_screen();
131
                    switch(menu_update_state(main_menu, click)){
132
                        case -1: break;
133
                        case  0: singleplayer(); break; //campaign(); break;
134 311 up20180655
                        case  1: multiplayer() ; break;
135 307 up20180642
                        case  2: chat(); break;
136
                        case  3: good = false; break;
137
                    }
138
                    menu_draw(main_menu);
139 192 up20180642
140 307 up20180642
                    click = 0;
141 202 up20180655
142 307 up20180642
                    sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y());
143
                    sprite_draw(sp_crosshair);
144
                    graph_draw();
145 231 up20180655
146 307 up20180642
                    break;
147
                    case KBC_IRQ:
148 321 up20180642
                    if (keyboard_get_scancode()[0] == ESC_BREAK_CODE) good = false;
149 307 up20180642
                    case MOUSE_IRQ:
150 323 up20180642
                    if (mouse_get_counter_mouse_ih() >= 3) {
151
                        mouse_parse_packet(mouse_get_packet_mouse_ih(), &pp);
152 307 up20180642
                        update_mouse(&pp);
153
                        if (!click) click = last_lb ^ keys->lb_pressed && keys->lb_pressed;
154
                        last_lb = keys->lb_pressed;
155 323 up20180642
                        mouse_set_counter_mouse_ih(0);
156 261 up20180642
                    }
157 307 up20180642
                    break;
158
                    case COM1_IRQ: nctp_ih(); break;
159 305 up20180642
                }
160 147 up20180655
            }
161
        }
162 261 up20180642
    }
163 149 up20180655
164 261 up20180642
    basic_sprite_dtor      (bsp_crosshair); bsp_crosshair = NULL;
165
    basic_sprite_dtor      (bsp_shooter  ); bsp_shooter   = NULL;
166 307 up20180642
    basic_sprite_dtor      (bsp_zombie   ); bsp_zombie    = NULL;
167 261 up20180642
    sprite_dtor            (sp_crosshair ); sp_crosshair  = NULL;
168
    basic_sprite_dtor      (bsp_pistol   ); bsp_pistol    = NULL;
169
    basic_sprite_dtor      (bsp_nothing  ); bsp_nothing   = NULL;
170
    map_dtor               (map1         ); map1          = NULL;
171 319 up20180642
    font_free();
172 243 up20180642
173 261 up20180642
    // Unsubscribe interrupts
174
    if (unsubscribe_all()) {
175
        if (cleanup())
176 305 up20180642
        printf("%s: failed to cleanup.\n", __func__);
177 261 up20180642
        return 1;
178
    }
179 188 up20180642
180 261 up20180642
    if (cleanup()) {
181
        printf("%s: failed to cleanup.\n", __func__);
182
        return 1;
183
    }
184 155 up20180655
185 149 up20180655
    return 0;
186 147 up20180655
}
187 294 up20180642
188 321 up20180642
static host_info_t     *host_info   = NULL;
189
static remote_info_t   *remote_info = NULL;
190
static bullet_info_t   *bullet_info = NULL;
191 308 up20180655
192 311 up20180655
static void multiplayer_process(const uint8_t *p, const size_t sz) {
193
    void *dest = NULL;
194
    hltp_type tp = hltp_interpret(p, sz, &dest);
195 342 up20180655
    if (dest == NULL) return;
196 311 up20180655
    switch(tp){
197
        case hltp_type_host:
198 320 up20180655
            host_info = (host_info_t*)dest;
199 311 up20180655
            break;
200
        case hltp_type_remote:
201 320 up20180655
            remote_info = (remote_info_t*)dest;
202 311 up20180655
            break;
203 320 up20180655
        case hltp_type_bullet:
204
            bullet_info = (bullet_info_t*)dest;
205
            break;
206 321 up20180642
        case hltp_type_invalid: break;
207
        case hltp_type_string : break;
208 311 up20180655
    }
209
}
210
static int (multiplayer_host)(void);
211
static int (multiplayer_remote)(void);
212
static int (multiplayer)(void) {
213
    int r;
214 308 up20180655
215 314 up20180642
    menu_t *main_menu = menu_ctor(font_get_default());
216 311 up20180655
    menu_add_item(main_menu, "Create");
217
    menu_add_item(main_menu, "Connect");
218
    menu_add_item(main_menu, "Back");
219 308 up20180655
220 311 up20180655
    //uint32_t refresh_count_value = sys_hz() / REFRESH_RATE;
221
    uint8_t last_lb = 0;
222
    struct packet pp;
223
    keys_t *keys = get_key_presses();
224 308 up20180655
225 311 up20180655
    /// loop stuff
226
    int click = 0;
227 323 up20180642
    uint64_t int_vector = 0;
228 311 up20180655
    int good = true;
229
    while (good) {
230
        /* Get a request message. */
231
        if((r = get_interrupts_vector(&int_vector))) return r;
232 321 up20180642
        uint32_t n = 1;
233
        for (uint8_t i = 0; i < 32; i++, n <<= 1) {
234 311 up20180655
            if (int_vector & n) {
235
                interrupt_handler(i);
236
                switch (i) {
237
                    case TIMER0_IRQ:
238 308 up20180655
239 311 up20180655
                    graph_clear_screen();
240
                    switch(menu_update_state(main_menu, click)){
241
                        case -1: break;
242
                        case  0: multiplayer_host(); break;
243
                        case  1: multiplayer_remote(); break;
244
                        case  2: good = false; break;
245
                    }
246
                    menu_draw(main_menu);
247
248
                    click = 0;
249
250
                    sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y());
251
                    sprite_draw(sp_crosshair);
252
                    graph_draw();
253
254
                    break;
255
                    case KBC_IRQ:
256 321 up20180642
                    if (keyboard_get_scancode()[0] == ESC_BREAK_CODE) good = false;
257 311 up20180655
                    case MOUSE_IRQ:
258 323 up20180642
                    if (mouse_get_counter_mouse_ih() >= 3) {
259
                        mouse_parse_packet(mouse_get_packet_mouse_ih(), &pp);
260 311 up20180655
                        update_mouse(&pp);
261
                        if (!click) click = last_lb ^ keys->lb_pressed && keys->lb_pressed;
262
                        last_lb = keys->lb_pressed;
263 323 up20180642
                        mouse_set_counter_mouse_ih(0);
264 311 up20180655
                    }
265
                    break;
266
                    case COM1_IRQ: nctp_ih(); break;
267
                }
268
            }
269
        }
270
    }
271
    return 0;
272 308 up20180655
}
273
274 311 up20180655
static int (multiplayer_host)(void) {
275 320 up20180655
    int r;
276 308 up20180655
277 311 up20180655
    nctp_dump();
278 320 up20180655
    nctp_set_processor(multiplayer_process);
279 311 up20180655
280 308 up20180655
    ent_set_scale(DEFAULT_SCALE);
281 314 up20180642
    text_timer_t *in_game_timer = timer_ctor(font_get_default());
282 308 up20180655
283
    list_t *shooter_list = list_ctor();
284
285 321 up20180642
    gunner_t *shooter1 = gunner_ctor(bsp_shooter, bsp_pistol, GUNNER_PLAYER, 1); if(shooter1 == NULL) printf("Failed to get shooter1\n");
286 308 up20180655
    gunner_set_spawn(shooter1, 75, 75);
287
288 321 up20180642
    gunner_t *shooter2 = gunner_ctor(bsp_shooter, bsp_pistol, GUNNER_PLAYER, 2); if(shooter2 == NULL) printf("Failed to get shooter2\n");
289 308 up20180655
    gunner_set_spawn(shooter2, 975, 75);
290
291
    list_insert(shooter_list, list_end(shooter_list), shooter1);
292
    list_insert(shooter_list, list_end(shooter_list), shooter2);
293
294
    do {
295
        get_random_spawn(map1, shooter1, shooter_list);
296
        get_random_spawn(map1, shooter2, shooter_list);
297 339 up20180642
    } while (gunner_distance(shooter1, shooter2) < 500);
298 308 up20180655
299 320 up20180655
    host_info = host_info_ctor(shooter1, shooter2);
300
    remote_info = remote_info_ctor();
301
    bullet_info = bullet_info_ctor();
302
303 308 up20180655
    list_t *bullet_list  = list_ctor();
304
305
    ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0,
306
    gunner_get_y(shooter1)-ent_get_YLength()/2.0);
307
308
    //uint32_t refresh_count_value = sys_hz() / REFRESH_RATE;
309
    uint8_t last_lb = 0;
310
    struct packet pp;
311
    keys_t *keys = get_key_presses();
312
    /// loop stuff
313 323 up20180642
    uint64_t int_vector = 0;
314 308 up20180655
    int good = true;
315 311 up20180655
    int state = 0; // -1 for remote win, 0 for draw, 1 for host win
316 320 up20180655
    list_node_t *p1, *p2; // player states
317
    int state_1, state_2;
318 311 up20180655
    while (good) {
319
        if ((r = get_interrupts_vector(&int_vector))) return r;
320 321 up20180642
        uint32_t n = 1;
321
        for (uint8_t i = 0; i < 32; i++, n <<= 1) {
322 320 up20180655
            if (int_vector & n) {
323
                interrupt_handler(i);
324
                switch (i) {
325
                    case TIMER0_IRQ:
326 321 up20180642
                    if (timer_get_no_interrupts() % 60 == 0) timer_update(in_game_timer);
327 320 up20180655
                    update_movement(map1, shooter1, keys, shooter_list);
328
                    update_movement(map1, shooter2, &(remote_info->remote_keys_pressed), shooter_list);
329 308 up20180655
330 320 up20180655
                    update_game_state(map1, shooter_list, bullet_list);
331 311 up20180655
332 320 up20180655
                    p1 = list_find(shooter_list, shooter1);
333
                    p2 = list_find(shooter_list, shooter2);
334 311 up20180655
335 320 up20180655
                    if ((state_1 = (p1 == list_end(shooter_list))) || (state_2 = (p2 == list_end(shooter_list)))) {
336
                        state = state_1 - state_2;
337
                        good = false;
338
                        break;
339
                    }
340 311 up20180655
341 320 up20180655
                    double angle = get_mouse_angle(shooter1);
342
                    gunner_set_angle(shooter1, angle - M_PI_2);
343 311 up20180655
344 320 up20180655
                    ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0,
345
                                   gunner_get_y(shooter1)-ent_get_YLength()/2.0);
346 311 up20180655
347 320 up20180655
                    gunner_set_angle(shooter2, remote_info->remote_angle);
348 342 up20180655
                    if (timer_get_no_interrupts() % 6 == 0) {
349
                        build_host_structure(host_info, shooter1, shooter2);
350 320 up20180655
351 342 up20180655
                        hltp_send_host_info(host_info);
352
                    }
353 320 up20180655
354
                    graph_clear_screen();
355
                    map_draw   (map1);
356
                    bullet_draw_list(bullet_list);
357
                    gunner_draw_list(shooter_list);
358
359
                    text_draw(in_game_timer->text);
360
361
                    sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y());
362
                    sprite_draw(sp_crosshair);
363
                    graph_draw();
364
365
                    break;
366
                    case KBC_IRQ:
367 321 up20180642
                    if (keyboard_get_scancode()[0] == ESC_BREAK_CODE) {
368 320 up20180655
                        good = false;
369
                    }
370
                    break;
371
                    case MOUSE_IRQ:
372 323 up20180642
                    if (mouse_get_counter_mouse_ih() >= 3) {
373
                        mouse_parse_packet(mouse_get_packet_mouse_ih(), &pp);
374 320 up20180655
                        update_mouse(&pp);
375
                        if (last_lb ^ keys->lb_pressed && keys->lb_pressed)
376
                        shoot_bullet(shooter1, bullet_list, bsp_bullet);
377
                        last_lb = keys->lb_pressed;
378 323 up20180642
                        mouse_set_counter_mouse_ih(0);
379 320 up20180655
                    }
380
                    break;
381
382
                    case COM1_IRQ:
383
                        nctp_ih();
384
                        if (bullet_info->new_bullet) {
385
                            shoot_bullet(shooter2, bullet_list, bsp_bullet);
386
                            bullet_info->new_bullet = false;
387
                        }
388
                        break;
389
                }
390 311 up20180655
            }
391
        }
392 320 up20180655
    }
393 311 up20180655
394 320 up20180655
    while(list_size(shooter_list) > 0){
395
        gunner_t *p = list_erase(shooter_list, list_begin(shooter_list));
396
        gunner_dtor(p);
397
    }
398
    if(list_dtor(shooter_list)) printf("COULD NOT DESTRUCT SHOOTER LIST\n");
399
400
    while(list_size(bullet_list) > 0){
401
        bullet_t *p = (bullet_t*)list_erase(bullet_list, list_begin(bullet_list));
402
        bullet_dtor(p);
403
    }
404
    if(list_dtor(bullet_list)) printf("COULD NOT DESTRUCT BULLET LIST\n");
405
406
    host_info_dtor(host_info);
407
    remote_info_dtor(remote_info);
408
    bullet_info_dtor(bullet_info);
409
410 330 up20180655
    nctp_set_processor(NULL);
411
412 320 up20180655
    timer_dtor(in_game_timer); in_game_timer = NULL;
413
414 308 up20180655
    return 0;
415 311 up20180655
}
416 320 up20180655
static int (multiplayer_remote)(void) {
417 311 up20180655
    int r;
418 308 up20180655
419 311 up20180655
    nctp_dump();
420
    nctp_set_processor(multiplayer_process);
421
422
    ent_set_scale(DEFAULT_SCALE);
423 314 up20180642
    text_timer_t *in_game_timer = timer_ctor(font_get_default());
424 311 up20180655
425
    list_t *shooter_list = list_ctor();
426
427 321 up20180642
    gunner_t *shooter1 = gunner_ctor(bsp_shooter, bsp_pistol, GUNNER_PLAYER, 2); if(shooter1 == NULL) printf("Failed to get shooter1\n");
428 311 up20180655
    gunner_set_spawn(shooter1, 75, 75);
429
430 321 up20180642
    gunner_t *shooter2 = gunner_ctor(bsp_shooter, bsp_pistol, GUNNER_PLAYER, 1); if(shooter2 == NULL) printf("Failed to get shooter2\n");
431 311 up20180655
    gunner_set_spawn(shooter2, 975, 75);
432
433
    list_insert(shooter_list, list_end(shooter_list), shooter1);
434
    list_insert(shooter_list, list_end(shooter_list), shooter2);
435
436 320 up20180655
    host_info = host_info_ctor(shooter2, shooter1);
437
    remote_info = remote_info_ctor();
438
    bullet_info = bullet_info_ctor();
439 311 up20180655
440
    list_t *bullet_list  = list_ctor();
441
442
    ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0,
443
    gunner_get_y(shooter1)-ent_get_YLength()/2.0);
444
445
    //uint32_t refresh_count_value = sys_hz() / REFRESH_RATE;
446
    uint8_t last_lb = 0;
447
    struct packet pp;
448
    keys_t *keys = get_key_presses();
449
450
    /// loop stuff
451 323 up20180642
    uint64_t int_vector = 0;
452 311 up20180655
    int good = true;
453
    while (good) {
454
        if ((r = get_interrupts_vector(&int_vector))) return r;
455 321 up20180642
        uint32_t n = 1;
456
        for (uint8_t i = 0; i < 32; i++, n <<= 1) {
457 320 up20180655
            if (int_vector & n) {
458
                interrupt_handler(i);
459
                switch (i) {
460
                    case TIMER0_IRQ:
461 321 up20180642
                    if (timer_get_no_interrupts() % 60 == 0) timer_update(in_game_timer);
462 311 up20180655
463 326 up20180655
                    double angle = get_mouse_angle(shooter1) - M_PI_2;
464 311 up20180655
465 320 up20180655
                    build_remote_structure(remote_info, keys, angle);
466 311 up20180655
467 342 up20180655
468 327 up20180655
                    //hltp_send_remote_info(remote_info);
469 330 up20180655
                    gunner_set_pos(shooter1, (double)host_info->remote_x, (double)host_info->remote_y);
470
                    gunner_set_angle(shooter1, (double)host_info->remote_angle);
471
                    gunner_set_health(shooter1, (double)host_info->remote_health);
472
                    gunner_set_curr_health(shooter1, (double)host_info->remote_current_health);
473 311 up20180655
474 330 up20180655
                    gunner_set_pos(shooter2, (double)host_info->host_x, (double)host_info->host_y);
475
                    gunner_set_angle(shooter2, (double)host_info->host_angle);
476
                    gunner_set_health(shooter2, (double)host_info->host_health);
477
                    gunner_set_curr_health(shooter2, (double)host_info->host_current_health);
478 311 up20180655
479 320 up20180655
                    ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0,
480
                                   gunner_get_y(shooter1)-ent_get_YLength()/2.0);
481 311 up20180655
482 342 up20180655
                    /*
483 321 up20180642
                    for (size_t j = 0; j < host_info->no_bullets; j++) {
484
                        if (host_info->bullets_shooter[j]) { // remote
485 330 up20180655
                            bullet_t *bullet = bullet_ctor(shooter1, bsp_bullet, (double)host_info->bullets_x[j], (double)host_info->bullets_y[j], (double)host_info->bullets_vx[j], (double)host_info->bullets_vy[j]);
486 320 up20180655
                            list_insert(bullet_list, list_end(bullet_list), bullet);
487
                        } else { // host
488 330 up20180655
                            bullet_t *bullet = bullet_ctor(shooter2, bsp_bullet, (double)host_info->bullets_x[j], (double)host_info->bullets_y[j], (double)host_info->bullets_vx[j], (double)host_info->bullets_vy[j]);
489 320 up20180655
                            list_insert(bullet_list, list_end(bullet_list), bullet);
490
                        }
491 342 up20180655
                    }*/
492 320 up20180655
493
                    graph_clear_screen();
494
                    map_draw   (map1);
495
                    bullet_draw_list(bullet_list);
496
                    gunner_draw_list(shooter_list);
497
498
                    text_draw(in_game_timer->text);
499
500
                    sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y());
501
                    sprite_draw(sp_crosshair);
502
                    graph_draw();
503 342 up20180655
                    /*
504 320 up20180655
                    while(list_size(bullet_list) > 0){
505
                        bullet_t *p = (bullet_t*)list_erase(bullet_list, list_begin(bullet_list));
506
                        bullet_dtor(p);
507
                    }
508 342 up20180655
                    */
509 320 up20180655
510
                    break;
511
                    case KBC_IRQ:
512 321 up20180642
                    if (keyboard_get_scancode()[0] == ESC_BREAK_CODE) {
513 320 up20180655
                        good = false;
514
                    }
515
                    break;
516
                    case MOUSE_IRQ:
517 323 up20180642
                    if (mouse_get_counter_mouse_ih() >= 3) {
518
                        mouse_parse_packet(mouse_get_packet_mouse_ih(), &pp);
519 320 up20180655
                        update_mouse(&pp);
520
                        if (last_lb ^ keys->lb_pressed && keys->lb_pressed) {
521
                            bullet_info->new_bullet = true;
522 327 up20180655
                            //hltp_send_bullet_info(bullet_info);
523 320 up20180655
                        }
524
                        last_lb = keys->lb_pressed;
525 323 up20180642
                        mouse_set_counter_mouse_ih(0);
526 320 up20180655
                    }
527
                    break;
528
529 342 up20180655
                    case COM1_IRQ:
530
                        nctp_ih();
531
                        break;
532 320 up20180655
                }
533 311 up20180655
            }
534
        }
535 320 up20180655
    }
536 311 up20180655
537 320 up20180655
    while(list_size(shooter_list) > 0){
538
        gunner_t *p = list_erase(shooter_list, list_begin(shooter_list));
539
        gunner_dtor(p);
540
    }
541
    if(list_dtor(shooter_list)) printf("COULD NOT DESTRUCT SHOOTER LIST\n");
542
543
    while(list_size(bullet_list) > 0){
544
        bullet_t *p = (bullet_t*)list_erase(bullet_list, list_begin(bullet_list));
545
        bullet_dtor(p);
546
    }
547
    if(list_dtor(bullet_list)) printf("COULD NOT DESTRUCT BULLET LIST\n");
548
549
    host_info_dtor(host_info);
550
    remote_info_dtor(remote_info);
551
    bullet_info_dtor(bullet_info);
552
553 330 up20180655
    nctp_set_processor(NULL);
554
555 320 up20180655
    timer_dtor(in_game_timer); in_game_timer = NULL;
556
557 311 up20180655
    return 0;
558
}
559
560 300 up20180642
static int (campaign)(void);
561 301 up20180642
static int (zombies)(void);
562 300 up20180642
static int (singleplayer)(void) {
563
564 295 up20180642
    int r;
565
566 314 up20180642
    menu_t *main_menu = menu_ctor(font_get_default());
567 300 up20180642
    menu_add_item(main_menu, "Campaign");
568
    menu_add_item(main_menu, "Zombies");
569
    menu_add_item(main_menu, "Back");
570
571
    //uint32_t refresh_count_value = sys_hz() / REFRESH_RATE;
572
    uint8_t last_lb = 0;
573
    struct packet pp;
574
    keys_t *keys = get_key_presses();
575
576
    /// loop stuff
577
    int click = 0;
578 323 up20180642
    uint64_t int_vector = 0;
579 300 up20180642
    int good = true;
580
    while (good) {
581
        /* Get a request message. */
582 304 up20180642
        if((r = get_interrupts_vector(&int_vector))) return r;
583 321 up20180642
        uint32_t n = 1;
584
        for (uint8_t i = 0; i < 32; i++, n <<= 1) {
585 304 up20180642
            if (int_vector & n) {
586
                interrupt_handler(i);
587
                switch (i) {
588 305 up20180642
                    case TIMER0_IRQ:
589 300 up20180642
590 304 up20180642
                    graph_clear_screen();
591
                    switch(menu_update_state(main_menu, click)){
592
                        case -1: break;
593
                        case  0: campaign(); break;
594
                        case  1: zombies(); break;
595
                        case  2: good = false; break;
596
                    }
597
                    menu_draw(main_menu);
598 300 up20180642
599 304 up20180642
                    click = 0;
600 300 up20180642
601 304 up20180642
                    sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y());
602
                    sprite_draw(sp_crosshair);
603
                    graph_draw();
604 300 up20180642
605 304 up20180642
                    break;
606 305 up20180642
                    case KBC_IRQ:
607 321 up20180642
                    if (keyboard_get_scancode()[0] == ESC_BREAK_CODE) good = false;
608 305 up20180642
                    case MOUSE_IRQ:
609 323 up20180642
                    if (mouse_get_counter_mouse_ih() >= 3) {
610
                        mouse_parse_packet(mouse_get_packet_mouse_ih(), &pp);
611 304 up20180642
                        update_mouse(&pp);
612
                        if (!click) click = last_lb ^ keys->lb_pressed && keys->lb_pressed;
613
                        last_lb = keys->lb_pressed;
614 323 up20180642
                        mouse_set_counter_mouse_ih(0);
615 300 up20180642
                    }
616
                    break;
617 305 up20180642
                    case COM1_IRQ: nctp_ih(); break;
618 304 up20180642
                }
619 300 up20180642
            }
620
        }
621
    }
622
623
    return 0;
624
}
625
626
static int (campaign)(void){
627
628
    int r;
629
630 295 up20180642
    ent_set_scale(DEFAULT_SCALE);
631 314 up20180642
    text_timer_t *in_game_timer = timer_ctor(font_get_default());
632 295 up20180642
633
    list_t *shooter_list = list_ctor();
634
635 321 up20180642
    gunner_t *shooter1 = gunner_ctor(bsp_shooter, bsp_pistol, GUNNER_PLAYER, 1); if(shooter1 == NULL) printf("Failed to get shooter1\n");
636 295 up20180642
    gunner_set_spawn(shooter1, 75, 75);
637
    gunner_set_pos(shooter1, 75, 75);
638
639 321 up20180642
    gunner_t *shooter2 = gunner_ctor(bsp_shooter, bsp_nothing, GUNNER_PLAYER, 2);
640 295 up20180642
    gunner_set_spawn(shooter2, 975, 75);
641
    gunner_set_pos(shooter2, 775, 75);
642
643
    list_insert(shooter_list, list_end(shooter_list), shooter1);
644
    list_insert(shooter_list, list_end(shooter_list), shooter2);
645
646
    list_t *bullet_list  = list_ctor();
647
648
    ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0,
649 305 up20180642
    gunner_get_y(shooter1)-ent_get_YLength()/2.0);
650 295 up20180642
651 305 up20180642
    //uint32_t refresh_count_value = sys_hz() / REFRESH_RATE;
652
    uint8_t last_lb = 0;
653
    struct packet pp;
654
    keys_t *keys = get_key_presses();
655 295 up20180642
656
    /// loop stuff
657 323 up20180642
    uint64_t int_vector = 0;
658 296 up20180642
    int good = true;
659
    while (good) {
660 304 up20180642
        /* Get a request message. */
661
        if((r = get_interrupts_vector(&int_vector))) return r;
662 321 up20180642
        uint32_t n = 1;
663
        for (uint8_t i = 0; i < 32; i++, n <<= 1) {
664 309 up20180642
            if(!good) break;
665 305 up20180642
            if (int_vector & n) {
666
                interrupt_handler(i);
667
                switch (i) {
668
                    case TIMER0_IRQ:
669 295 up20180642
670 321 up20180642
                    if (timer_get_no_interrupts() % 60 == 0) timer_update(in_game_timer);
671 305 up20180642
                    update_movement(map1, shooter1, keys, shooter_list);
672 295 up20180642
673 305 up20180642
                    update_game_state(map1, shooter_list, bullet_list);
674 295 up20180642
675 305 up20180642
                    //update_scale();
676
                    double angle = get_mouse_angle(shooter1);
677
                    gunner_set_angle(shooter1, angle - M_PI_2);
678 295 up20180642
679 305 up20180642
                    ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0,
680
                    gunner_get_y(shooter1)-ent_get_YLength()/2.0);
681 295 up20180642
682 305 up20180642
                    graph_clear_screen();
683
                    map_draw   (map1);
684
                    bullet_draw_list(bullet_list);
685
                    gunner_draw_list(shooter_list);
686 295 up20180642
687 305 up20180642
                    text_draw(in_game_timer->text);
688 295 up20180642
689 305 up20180642
                    sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y());
690
                    sprite_draw(sp_crosshair);
691
                    graph_draw();
692 295 up20180642
693 305 up20180642
                    break;
694
                    case KBC_IRQ:
695 321 up20180642
                    if (keyboard_get_scancode()[0] == ESC_BREAK_CODE) {
696 305 up20180642
                        good = false;
697
                    }
698
                    break;
699
                    case MOUSE_IRQ:
700 323 up20180642
                    if (mouse_get_counter_mouse_ih() >= 3) {
701
                        mouse_parse_packet(mouse_get_packet_mouse_ih(), &pp);
702 305 up20180642
                        update_mouse(&pp);
703
                        if (last_lb ^ keys->lb_pressed && keys->lb_pressed)
704
                        shoot_bullet(shooter1, bullet_list, bsp_bullet);
705
                        last_lb = keys->lb_pressed;
706 323 up20180642
                        mouse_set_counter_mouse_ih(0);
707 304 up20180642
708 305 up20180642
                    }
709
                    break;
710
                    case COM1_IRQ: nctp_ih(); break;
711
                }
712
            }
713 304 up20180642
        }
714 295 up20180642
    }
715
716
    while(list_size(shooter_list) > 0){
717
        gunner_t *p = list_erase(shooter_list, list_begin(shooter_list));
718
        gunner_dtor(p);
719
    }
720 296 up20180642
    if(list_dtor(shooter_list)) printf("COULD NOT DESTRUCT SHOOTER LIST\n");
721 295 up20180642
722 301 up20180642
    while(list_size(bullet_list) > 0){
723
        bullet_t *p = (bullet_t*)list_erase(bullet_list, list_begin(bullet_list));
724
        bullet_dtor(p);
725
    }
726
    if(list_dtor(bullet_list)) printf("COULD NOT DESTRUCT BULLET LIST\n");
727
728
    timer_dtor(in_game_timer); in_game_timer = NULL;
729
730
    return SUCCESS;
731
}
732
733
#define ZOMBIES_NUM             5
734
#define ZOMBIE_HEALTH_FACTOR    1.1
735
static int (zombies)(void){
736
737
    int r;
738
739
    ent_set_scale(DEFAULT_SCALE);
740 314 up20180642
    text_timer_t *in_game_timer = timer_ctor(font_get_default());
741 301 up20180642
742
    list_t *shooter_list = list_ctor();
743
744 321 up20180642
    gunner_t *shooter1 = gunner_ctor(bsp_shooter, bsp_pistol, GUNNER_PLAYER, 1); if(shooter1 == NULL) printf("Failed to get shooter1\n");
745 305 up20180642
    gunner_set_spawn(shooter1, 980, 790);
746
    gunner_set_pos(shooter1, 980, 790);
747 301 up20180642
748
    list_insert(shooter_list, list_end(shooter_list), shooter1);
749
750
    list_t *bullet_list  = list_ctor();
751
752
    ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0,
753 305 up20180642
    gunner_get_y(shooter1)-ent_get_YLength()/2.0);
754 301 up20180642
755 305 up20180642
    //uint32_t refresh_count_value = sys_hz() / REFRESH_RATE;
756
    uint8_t last_lb = 0;
757
    struct packet pp;
758
    keys_t *keys = get_key_presses();
759 301 up20180642
760
    /// loop stuff
761 323 up20180642
    uint64_t int_vector = 0;
762 301 up20180642
    int good = true;
763 302 up20180642
    int dead = false;
764 301 up20180642
765
    int health = 50;
766
767 309 up20180642
    map_make_dijkstra(map1, gunner_get_x(shooter1), gunner_get_y(shooter1));
768
769 302 up20180642
    while (good && !dead) {
770 304 up20180642
        /* Get a request message. */
771
        if((r = get_interrupts_vector(&int_vector))) return r;
772 321 up20180642
        uint32_t n = 1;
773
        for (uint8_t i = 0; i < 32; i++, n <<= 1) {
774 309 up20180642
            if(!good || dead) break;
775 304 up20180642
            if (int_vector & n) {
776 305 up20180642
                interrupt_handler(i);
777
                switch (i) {
778
                    case TIMER0_IRQ:
779 321 up20180642
                    if (timer_get_no_interrupts() % 60 == 0) timer_update(in_game_timer);
780
                    if (timer_get_no_interrupts() %  6 == 0){
781 309 up20180642
                        map_make_dijkstra(map1, gunner_get_x(shooter1), gunner_get_y(shooter1));
782
                    }
783 301 up20180642
784 305 up20180642
                    update_movement(map1, shooter1, keys, shooter_list);
785 301 up20180642
786 305 up20180642
                    update_game_state(map1, shooter_list, bullet_list);
787 302 up20180642
788 305 up20180642
                    if(list_find(shooter_list, shooter1) == list_end(shooter_list)){
789
                        good = false;
790
                        dead = true;
791
                        break;
792
                    }
793 301 up20180642
794 305 up20180642
                    double angle = get_mouse_angle(shooter1);
795
                    gunner_set_angle(shooter1, angle - M_PI_2);
796 301 up20180642
797 305 up20180642
                    ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0,
798
                                   gunner_get_y(shooter1)-ent_get_YLength()/2.0);
799 301 up20180642
800 309 up20180642
                    while(list_size(shooter_list) < ZOMBIES_NUM+1){
801 321 up20180642
                        gunner_t *zombie = gunner_ctor(bsp_zombie, bsp_nothing, GUNNER_MELEE | GUNNER_FOLLOW, 3);
802 305 up20180642
                        gunner_set_health(zombie, health);
803
                        gunner_set_curr_health(zombie, health);
804
                        health *= ZOMBIE_HEALTH_FACTOR;
805 307 up20180642
                        get_random_spawn(map1, zombie, shooter_list);
806 305 up20180642
                        list_push_back(shooter_list, zombie);
807
                    }
808 301 up20180642
809 305 up20180642
                    graph_clear_screen();
810
                    map_draw   (map1);
811
                    bullet_draw_list(bullet_list);
812
                    gunner_draw_list(shooter_list);
813 301 up20180642
814 305 up20180642
                    text_draw(in_game_timer->text);
815 301 up20180642
816 305 up20180642
                    sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y());
817
                    sprite_draw(sp_crosshair);
818
                    graph_draw();
819 304 up20180642
820 305 up20180642
                    break;
821
                    case KBC_IRQ:
822 321 up20180642
                    if (keyboard_get_scancode()[0] == ESC_BREAK_CODE) {
823 305 up20180642
                        good = false;
824
                    }
825
                    break;
826
                    case MOUSE_IRQ:
827 323 up20180642
                    if (mouse_get_counter_mouse_ih() >= 3) {
828
                        mouse_parse_packet(mouse_get_packet_mouse_ih(), &pp);
829 305 up20180642
                        update_mouse(&pp);
830
                        if (last_lb ^ keys->lb_pressed && keys->lb_pressed)
831
                        shoot_bullet(shooter1, bullet_list, bsp_bullet);
832
                        last_lb = keys->lb_pressed;
833 323 up20180642
                        mouse_set_counter_mouse_ih(0);
834 305 up20180642
835
                    }
836
                    break;
837
                    case COM1_IRQ: nctp_ih(); break;
838
                }
839
            }
840
        }
841 301 up20180642
    }
842
843
    while(list_size(shooter_list) > 0){
844
        gunner_t *p = list_erase(shooter_list, list_begin(shooter_list));
845
        gunner_dtor(p);
846
    }
847
    if(list_dtor(shooter_list)) printf("COULD NOT DESTRUCT SHOOTER LIST\n");
848
849 295 up20180642
    while(list_size(bullet_list) > 0){
850
        bullet_t *p = (bullet_t*)list_erase(bullet_list, list_begin(bullet_list));
851
        bullet_dtor(p);
852
    }
853
    if(list_dtor(bullet_list)) printf("COULD NOT DESTRUCT BULLET LIST\n");
854
855 302 up20180642
    if(dead){
856
        printf("YOU DIED\n");
857
    }
858
859 295 up20180642
    timer_dtor(in_game_timer); in_game_timer = NULL;
860
861 294 up20180642
    return SUCCESS;
862
}
863 296 up20180642
864 298 up20180642
#define CHAT_MAX_SIZE   75
865
#define CHAT_MAX_NUM    19
866 321 up20180642
static text_t      *t_text[CHAT_MAX_NUM] = {NULL};
867
static rectangle_t *r_text               =  NULL;
868 297 up20180642
static void chat_process(const uint8_t *p, const size_t sz){
869
    char buffer2[CHAT_MAX_NUM+3];
870
    void *dest = NULL;
871
    hltp_type tp = hltp_interpret(p, sz, &dest);
872
    switch(tp){
873
        case hltp_type_string:
874 305 up20180642
        strcpy(buffer2, dest);
875
        strncat(buffer2, " <", 2);
876
        for(size_t i = CHAT_MAX_NUM-1; i; --i)
877 314 up20180642
        text_set_string(t_text[i], text_get_string(t_text[i-1]));
878
        text_set_string(t_text[0], buffer2);
879 305 up20180642
        for(size_t i = 0; i < CHAT_MAX_NUM; ++i){
880
            if(text_get_string(t_text[i])[0] == '>'){
881
                text_set_pos(t_text[i], rectangle_get_x(r_text)+50, text_get_y(t_text[i]));
882
                text_set_halign(t_text[i], text_halign_left);
883
            }else{
884
                text_set_pos(t_text[i], rectangle_get_x(r_text)+rectangle_get_w(r_text)-50, text_get_y(t_text[i]));
885
                text_set_halign(t_text[i], text_halign_right);
886 297 up20180642
            }
887 305 up20180642
        }
888
        break;
889 321 up20180642
        case hltp_type_invalid: break;
890
        case hltp_type_bullet : break;
891
        case hltp_type_host   : break;
892
        case hltp_type_remote : break;
893 297 up20180642
    }
894
}
895 300 up20180642
static int (chat)(void){
896 297 up20180642
    int r;
897
898 298 up20180642
    nctp_dump();
899 297 up20180642
    nctp_set_processor(chat_process);
900
901
    struct packet pp;
902
903 298 up20180642
    char buffer[CHAT_MAX_SIZE] = "";
904 297 up20180642
    rectangle_t *r_buffer = NULL; {
905 298 up20180642
        r_buffer = rectangle_ctor(0,0,900,70);
906 297 up20180642
        rectangle_set_pos(r_buffer, graph_get_XRes()/2  -rectangle_get_w(r_buffer)/2,
907 321 up20180642
        (int16_t)(graph_get_YRes()*0.87-rectangle_get_h(r_buffer)/2));
908 297 up20180642
        rectangle_set_fill_color   (r_buffer, GRAPH_BLACK);
909
        rectangle_set_outline_width(r_buffer, 2);
910
        rectangle_set_outline_color(r_buffer, GRAPH_WHITE);
911
        rectangle_set_fill_trans(r_buffer, GRAPH_TRANSPARENT);
912
    }
913
    text_t      *t_buffer = NULL; {
914 314 up20180642
        t_buffer = text_ctor(font_get_default(), "");
915 297 up20180642
        text_set_pos(t_buffer, rectangle_get_x(r_buffer)+50,
916 305 up20180642
        rectangle_get_y(r_buffer)+rectangle_get_h(r_buffer)/2);
917 297 up20180642
        text_set_halign(t_buffer, text_halign_left);
918
        text_set_valign(t_buffer, text_valign_center);
919
        text_set_color (t_buffer, TEXT_COLOR);
920
    }
921 298 up20180642
    text_t      *t_size   = NULL; {
922 314 up20180642
        t_size = text_ctor(font_get_default(), "");
923 298 up20180642
        text_set_pos(t_size, rectangle_get_x(r_buffer)+rectangle_get_w(r_buffer)-5,
924 305 up20180642
        rectangle_get_y(r_buffer)+rectangle_get_h(r_buffer)-5);
925 298 up20180642
        text_set_halign(t_size, text_halign_right);
926
        text_set_valign(t_size, text_valign_bottom);
927
        text_set_color (t_size, TEXT_COLOR);
928
        text_set_size  (t_size, 18);
929
        char buffer2[20];
930
        sprintf(buffer2, "%d/%d", strlen(buffer), CHAT_MAX_SIZE);
931 314 up20180642
        text_set_string(t_size, buffer2);
932 298 up20180642
    }
933 297 up20180642
934
    /** r_text */ {
935 305 up20180642
    r_text = rectangle_ctor(0,0,900,550);
936
    rectangle_set_pos(r_text, graph_get_XRes()/2  -rectangle_get_w(r_buffer)/2,
937 321 up20180642
    (int16_t)(graph_get_YRes()*0.09));
938 305 up20180642
    rectangle_set_fill_color   (r_text, GRAPH_BLACK);
939
    rectangle_set_outline_width(r_text, 2);
940
    rectangle_set_outline_color(r_text, GRAPH_WHITE);
941
    rectangle_set_fill_trans(r_text, GRAPH_TRANSPARENT);
942 311 up20180655
    }
943
    /** t_text */ {
944 321 up20180642
    for(uint16_t i = 0; i < CHAT_MAX_NUM; ++i){
945 314 up20180642
        t_text[i] = text_ctor(font_get_default(), " ");
946 311 up20180655
        text_set_pos(t_text[i], rectangle_get_x(r_text)+50,
947
        rectangle_get_y(r_text)+rectangle_get_h(r_text)-30-25*i);
948
        text_set_halign(t_text[i], text_halign_left);
949
        text_set_valign(t_text[i], text_valign_bottom);
950
        text_set_color (t_text[i], TEXT_COLOR);
951
    }
952 305 up20180642
}
953 297 up20180642
954 305 up20180642
/// loop stuff
955 323 up20180642
uint64_t int_vector = 0;
956 305 up20180642
int good = true;
957
while (good) {
958
    /* Get a request message. */
959
    if((r = get_interrupts_vector(&int_vector))) return r;
960 321 up20180642
    uint32_t n = 1;
961
    for (uint8_t i = 0; i < 32; i++, n <<= 1) {
962 305 up20180642
        if (int_vector & n) {
963
            interrupt_handler(i);
964
            switch (i) {
965 304 up20180642
                case TIMER0_IRQ:
966 305 up20180642
                graph_clear_screen();
967
                sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y());
968 297 up20180642
969 305 up20180642
                rectangle_draw(r_buffer);
970
                text_draw(t_buffer);
971
                text_draw(t_size);
972 297 up20180642
973 305 up20180642
                rectangle_draw(r_text);
974 321 up20180642
                for(size_t j = 0; j < CHAT_MAX_NUM; ++j) text_draw(t_text[j]);
975 297 up20180642
976 305 up20180642
                sprite_draw(sp_crosshair);
977
                graph_draw();
978
                break;
979 304 up20180642
                case KBC_IRQ:
980 321 up20180642
                if      (keyboard_get_scancode()[0] == ESC_BREAK_CODE) good = false;
981
                else if (keyboard_get_scancode()[0] == ENTER_MAKE_CODE) {
982 305 up20180642
                    hltp_send_string(buffer);
983
                    char buffer2[CHAT_MAX_SIZE+3] = "> ";
984
                    strncat(buffer2, buffer, strlen(buffer));
985 321 up20180642
                    for(size_t j = CHAT_MAX_NUM-1; j; --j) text_set_string(t_text[i], text_get_string(t_text[i-1]));
986 314 up20180642
                    text_set_string(t_text[0], buffer2);
987 321 up20180642
                    for(size_t j = 0; j < CHAT_MAX_NUM; ++j){
988
                        if(text_get_string(t_text[j])[0] == '>'){
989
                            text_set_pos(t_text[j], rectangle_get_x(r_text)+50, text_get_y(t_text[j]));
990
                            text_set_halign(t_text[j], text_halign_left);
991 305 up20180642
                        }else{
992 321 up20180642
                            text_set_pos(t_text[j], rectangle_get_x(r_text)+rectangle_get_w(r_text)-50, text_get_y(t_text[j]));
993
                            text_set_halign(t_text[j], text_halign_right);
994 297 up20180642
                        }
995
                    }
996 305 up20180642
                    buffer[0] = '\0';
997 321 up20180642
                } else if(keyboard_get_scancode()[0] == BACKSPACE_MAKE_CODE){
998 305 up20180642
                    buffer[strlen(buffer)-1] = '\0';
999
                } else {
1000 321 up20180642
                    char c = map_makecode(keyboard_get_scancode()[0]);
1001 305 up20180642
                    if (c == ERROR_CODE) break;
1002
                    if(strlen(buffer) < CHAT_MAX_SIZE) strncat(buffer, &c, 1);
1003
                    else                               printf("Char limit exceeded\n");
1004
                }
1005 314 up20180642
                text_set_string(t_buffer, buffer);
1006 305 up20180642
                char buffer2[20];
1007
                sprintf(buffer2, "%d/%d", strlen(buffer), CHAT_MAX_SIZE);
1008 314 up20180642
                text_set_string(t_size, buffer2);
1009 304 up20180642
                case MOUSE_IRQ:
1010 323 up20180642
                if (mouse_get_counter_mouse_ih() >= 3) {
1011
                    mouse_parse_packet(mouse_get_packet_mouse_ih(), &pp);
1012 305 up20180642
                    update_mouse(&pp);
1013 323 up20180642
                    mouse_set_counter_mouse_ih(0);
1014 305 up20180642
                }
1015
                break;
1016 304 up20180642
                case COM1_IRQ: nctp_ih(); break;
1017 297 up20180642
            }
1018
        }
1019
    }
1020 305 up20180642
}
1021 297 up20180642
1022 305 up20180642
rectangle_dtor(r_buffer);
1023
text_dtor     (t_buffer);
1024 297 up20180642
1025 305 up20180642
rectangle_dtor(r_text);
1026
for(size_t i = 0; i < CHAT_MAX_NUM; ++i) text_dtor(t_text[i]);
1027 297 up20180642
1028 305 up20180642
nctp_set_processor(NULL);
1029 298 up20180642
1030 305 up20180642
return SUCCESS;
1031 296 up20180642
}