Project

General

Profile

Revision 298

implemented chat. changed place of some macros

View differences:

proj/include/proj_macros.h
1 1
#ifndef PROJ_MACROS_H_INCLUDED
2 2
#define PROJ_MACROS_H_INCLUDED
3 3

  
4
// WASD Movement Keys
5
#define W_MAKE_CODE         0x11    /** @brief W Make Code */
6
#define W_BREAK_CODE        0x91    /** @brief W Break Code */
7
#define A_MAKE_CODE         0x1E    /** @brief A Make Code */
8
#define A_BREAK_CODE        0x9E    /** @brief A Break Code */
9
#define S_MAKE_CODE         0x1F    /** @brief S Make Code */
10
#define S_BREAK_CODE        0x9F    /** @brief S Break Code */
11
#define D_MAKE_CODE         0x20    /** @brief D Make Code */
12
#define D_BREAK_CODE        0xA0    /** @brief D Break Code */
13
#define CTRL_MAKE_CODE      0x1D    /** @brief CTRL Make Code */
14
#define CTRL_BREAK_CODE     0x9D    /** @brief CTRL Break Code */
15
#define PLUS_MAKE_CODE      0x1A    /** @brief Plus (+) Make Code */
16
#define PLUS_BREAK_CODE     0x9A    /** @brief Plus (+) Break Code */
17
#define MINUS_MAKE_CODE     0x35    /** @brief Minus (-) Make Code */
18
#define MINUS_BREAK_CODE    0xB5    /** @brief Minus (-) Break Code */
19
#define ENTER_MAKE_CODE     0x1C
20
#define ENTER_BREAK_CODE    0x9C
21

  
22 4
// Movement Directions
23 5
#define UP      -1  /** @brief Moving to the top side of screen */
24 6
#define DOWN    1   /** @brief Moving to the bottom side of screen */
......
30 12
#define SHOOTER_SPEED   5   /** @brief Shooter speed */
31 13
#define BULLET_SPEED    8   /** @brief Bullet speet */
32 14

  
33
// Game States
34
#define MENU            0
35
#define GAME            1
36
#define TEST            2
37
#define EXIT            3
38

  
39
// Extra Keys
40
#define ESC_MAKE_CODE   0x01    /** @brief ESC Make Code */
41
#define ESC_BREAK_CODE  0x81    /** @brief ESC Break Code */
42

  
43 15
// Refresh Rate
44 16
#define REFRESH_RATE    60      /** @brief Screen refresh rate */
45 17

  
proj/libs/graph/src/font.c
170 170
        if(alp_new_buf == NULL) return ALLOC_ERROR;
171 171

  
172 172
        for(size_t newy = 0; newy < newH; ++newy){
173
            size_t y = newy/factor+0.5;
173
            size_t y = newy/factor;
174 174
            for(size_t newx = 0; newx < newW; ++newx){
175
                size_t x = newx/factor+0.5;
175
                size_t x = newx/factor;
176 176
                *(alp_new_buf+newx+newy*newW) = *(alp_buf+x+y*W);
177 177
            }
178 178
        }
proj/libs/kbc/include/keyboard.h
7 7

  
8 8
#include "kbc.h"
9 9

  
10
#define W_MAKE_CODE             0x11    /** @brief W Make Code */
11
#define W_BREAK_CODE            0x91    /** @brief W Break Code */
12
#define A_MAKE_CODE             0x1E    /** @brief A Make Code */
13
#define A_BREAK_CODE            0x9E    /** @brief A Break Code */
14
#define S_MAKE_CODE             0x1F    /** @brief S Make Code */
15
#define S_BREAK_CODE            0x9F    /** @brief S Break Code */
16
#define D_MAKE_CODE             0x20    /** @brief D Make Code */
17
#define D_BREAK_CODE            0xA0    /** @brief D Break Code */
18
#define CTRL_MAKE_CODE          0x1D    /** @brief CTRL Make Code */
19
#define CTRL_BREAK_CODE         0x9D    /** @brief CTRL Break Code */
20
#define PLUS_MAKE_CODE          0x1A    /** @brief Plus (+) Make Code */
21
#define PLUS_BREAK_CODE         0x9A    /** @brief Plus (+) Break Code */
22
#define MINUS_MAKE_CODE         0x35    /** @brief Minus (-) Make Code */
23
#define MINUS_BREAK_CODE        0xB5    /** @brief Minus (-) Break Code */
24
#define ENTER_MAKE_CODE         0x1C
25
#define ENTER_BREAK_CODE        0x9C
26
#define BACKSPACE_MAKE_CODE     0x0E
27
#define BACKSPACE_BREAK_CODE    0x8E
28

  
29
#define ESC_MAKE_CODE           0x01    /** @brief ESC Make Code */
30
#define ESC_BREAK_CODE          0x81    /** @brief ESC Break Code */
31

  
10 32
/**
11 33
 * @brief Subscribes Keyboard Interrupts and disables Minix Default IH
12 34
 * @param interrupt_bit Bit of Interrupt Vector that will be set when Keyboard Interrupt is pending
proj/libs/uart/include/uart.h
51 51

  
52 52
/// NCTP - Non-critical transmission protocol
53 53
int nctp_init(void);
54
int nctp_dump(void);
54 55
int nctp_set_processor(void (*proc_func)(const uint8_t*, const size_t));
55 56
int nctp_free(void);
56 57

  
proj/libs/uart/src/uart.c
284 284

  
285 285
queue_t *out = NULL;
286 286
queue_t *in  = NULL;
287
void (*process)(const uint8_t*, const size_t);
287
void (*process)(const uint8_t*, const size_t) = NULL;
288 288

  
289
int nctp_init(){
289
int nctp_init(void){
290 290
    out = queue_ctor(); if(out == NULL) return NULL_PTR;
291 291
    in  = queue_ctor(); if(in  == NULL) return NULL_PTR;
292 292
    return SUCCESS;
293 293
}
294
int nctp_dump(void){
295
    int ret;
296
    if((ret = nctp_free())) return ret;
297
    return nctp_init();
298
}
294 299
int nctp_set_processor(void (*proc_func)(const uint8_t*, const size_t)){
295 300
    process = proc_func;
296 301
    return SUCCESS;
......
350 355
        if(i >= sz) p = realloc(p, sz=2*sz);
351 356
    }
352 357
    free(queue_top(in)); queue_pop(in);
353
    process(p, i);
358
    if(process != NULL) process(p, i);
354 359
    free(p);
355 360
}
356 361
static int nctp_receive(void){
proj/src/proj.c
155 155
                                    counter_mouse_ih = 0;
156 156
                                }
157 157
                                break;
158
                            case COM1_IRQ: nctp_ih(); break;
158 159
                            }
159 160
                        }
160 161
                    }
......
294 295

  
295 296
                               }
296 297
                               break;
298
                           case COM1_IRQ: nctp_ih(); break;
297 299
                           }
298 300
                       }
299 301
                   }
......
323 325
    return SUCCESS;
324 326
}
325 327

  
326
#define CHAT_MAX_SIZE   64
327
#define CHAT_MAX_NUM    10
328
#define CHAT_MAX_SIZE   75
329
#define CHAT_MAX_NUM    19
328 330

  
329 331
text_t      *t_text[CHAT_MAX_NUM] = {NULL};
330 332
rectangle_t *r_text               =  NULL;
......
357 359
int (chat)(void){
358 360
    int r;
359 361

  
362
    nctp_dump();
360 363
    nctp_set_processor(chat_process);
361 364

  
362 365
    struct packet pp;
363 366

  
367
    char buffer[CHAT_MAX_SIZE] = "";
364 368
    rectangle_t *r_buffer = NULL; {
365
        r_buffer = rectangle_ctor(0,0,750,70);
369
        r_buffer = rectangle_ctor(0,0,900,70);
366 370
        rectangle_set_pos(r_buffer, graph_get_XRes()/2  -rectangle_get_w(r_buffer)/2,
367
                                    graph_get_YRes()*0.8-rectangle_get_h(r_buffer)/2);
371
                                    graph_get_YRes()*0.87-rectangle_get_h(r_buffer)/2);
368 372
        rectangle_set_fill_color   (r_buffer, GRAPH_BLACK);
369 373
        rectangle_set_outline_width(r_buffer, 2);
370 374
        rectangle_set_outline_color(r_buffer, GRAPH_WHITE);
......
378 382
        text_set_valign(t_buffer, text_valign_center);
379 383
        text_set_color (t_buffer, TEXT_COLOR);
380 384
    }
385
    text_t      *t_size   = NULL; {
386
        t_size = text_ctor(consolas, "");
387
        text_set_pos(t_size, rectangle_get_x(r_buffer)+rectangle_get_w(r_buffer)-5,
388
                             rectangle_get_y(r_buffer)+rectangle_get_h(r_buffer)-5);
389
        text_set_halign(t_size, text_halign_right);
390
        text_set_valign(t_size, text_valign_bottom);
391
        text_set_color (t_size, TEXT_COLOR);
392
        text_set_size  (t_size, 18);
393
        char buffer2[20];
394
        sprintf(buffer2, "%d/%d", strlen(buffer), CHAT_MAX_SIZE);
395
        text_set_text(t_size, buffer2);
396
    }
381 397

  
382 398
    /** r_text */ {
383
        r_text = rectangle_ctor(0,0,750,500);
399
        r_text = rectangle_ctor(0,0,900,550);
384 400
        rectangle_set_pos(r_text, graph_get_XRes()/2  -rectangle_get_w(r_buffer)/2,
385
                                  graph_get_YRes()*0.1-rectangle_get_h(r_buffer)/2);
401
                                  graph_get_YRes()*0.09);
386 402
        rectangle_set_fill_color   (r_text, GRAPH_BLACK);
387 403
        rectangle_set_outline_width(r_text, 2);
388 404
        rectangle_set_outline_color(r_text, GRAPH_WHITE);
......
392 408
        for(size_t i = 0; i < CHAT_MAX_NUM; ++i){
393 409
            t_text[i] = text_ctor(consolas, " ");
394 410
            text_set_pos(t_text[i], rectangle_get_x(r_text)+50,
395
                                       rectangle_get_y(r_text)+rectangle_get_h(r_text)-30-30*i);
411
                                       rectangle_get_y(r_text)+rectangle_get_h(r_text)-30-25*i);
396 412
            text_set_halign(t_text[i], text_halign_left);
397 413
            text_set_valign(t_text[i], text_valign_bottom);
398 414
            text_set_color (t_text[i], TEXT_COLOR);
......
402 418
    /// loop stuff
403 419
    int ipc_status;
404 420
    message msg;
405

  
406
    char buffer[CHAT_MAX_SIZE] = "";
407

  
408 421
    int good = true;
409

  
410 422
    while (good) {
411 423
        /* Get a request message. */
412 424
        if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) {
......
426 438

  
427 439
                                rectangle_draw(r_buffer);
428 440
                                text_draw(t_buffer);
441
                                text_draw(t_size);
429 442

  
430 443
                                rectangle_draw(r_text);
431 444
                                for(size_t i = 0; i < CHAT_MAX_NUM; ++i) text_draw(t_text[i]);
......
434 447
                                graph_draw();
435 448
                                break;
436 449
                            case KBC_IRQ:
437
                                if ((scancode[0]) == ESC_BREAK_CODE) good = false;
438
                                else if ((scancode[0]) == ENTER_MAKE_CODE) {
450
                                if      (scancode[0] == ESC_BREAK_CODE) good = false;
451
                                else if (scancode[0] == ENTER_MAKE_CODE) {
439 452
                                    hltp_send_string(buffer);
440 453
                                    char buffer2[CHAT_MAX_SIZE+3] = "> ";
441 454
                                    strncat(buffer2, buffer, strlen(buffer));
......
451 464
                                            text_set_halign(t_text[i], text_halign_right);
452 465
                                        }
453 466
                                    }
454

  
455 467
                                    buffer[0] = '\0';
456
                                    text_set_text(t_buffer, buffer);
457
                                }
458
                                else {
468
                                } else if(scancode[0] == BACKSPACE_MAKE_CODE){
469
                                    buffer[strlen(buffer)-1] = '\0';
470
                                } else {
459 471
                                    char c = map_makecode(scancode[0]);
460 472
                                    if (c == ERROR_CODE) break;
461 473
                                    if(strlen(buffer) < CHAT_MAX_SIZE) strncat(buffer, &c, 1);
462
                                    else                    printf("Char limit exceeded\n");
463
                                    text_set_text(t_buffer, buffer);
474
                                    else                               printf("Char limit exceeded\n");
464 475
                                }
476
                                text_set_text(t_buffer, buffer);
477
                                char buffer2[20];
478
                                sprintf(buffer2, "%d/%d", strlen(buffer), CHAT_MAX_SIZE);
479
                                text_set_text(t_size, buffer2);
465 480
                            case MOUSE_IRQ:
466 481
                                if (counter_mouse_ih >= 3) {
467 482
                                    mouse_parse_packet(packet_mouse_ih, &pp);
......
469 484
                                    counter_mouse_ih = 0;
470 485
                                }
471 486
                                break;
472
                            case COM1_IRQ:
473
                                nctp_ih();
474
                                break;
487
                            case COM1_IRQ: nctp_ih(); break;
475 488
                            }
476 489
                        }
477 490
                    }
478

  
479 491
                    break;
480 492
                default:
481 493
                    break; /* no other notifications expected: do nothing */
......
491 503
    rectangle_dtor(r_text);
492 504
    for(size_t i = 0; i < CHAT_MAX_NUM; ++i) text_dtor(t_text[i]);
493 505

  
506
    nctp_set_processor(NULL);
507

  
494 508
    return SUCCESS;
495 509
}

Also available in: Unified diff