Project

General

Profile

Statistics
| Revision:

root / proj / src / proj.c @ 331

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