Project

General

Profile

Revision 321

correcting some problems

View differences:

proj/Makefile
12 12
SRCS= proj.c list.c queue.c graph.c kbc.c keyboard.c mouse.c utils.c timer.c interrupts_func.c proj_func.c fast_math.c rectangle.c font.c xpm_utils.c ent.c rtc.c uart.c hltp.c makecode_map.c menu.c
13 13
IPATHS=-I./include -I./libs/graph/include -I./libs/kbc/include -I./libs/rtc/include -I./libs/timer/include -I./libs/uart/include -I./libs/classes/include -I./libs/utils/include -I./maps -I./media/xpm
14 14

  
15
CPPFLAGS += -pedantic ${IPATHS} -D LCOM_MACRO -D __LCOM_OPTIMIZED_
15
CPPFLAGS += -pedantic -Weverything ${IPATHS} -D LCOM_MACRO -D __LCOM_OPTIMIZED__
16 16

  
17 17

  
18 18
DPADD += ${LIBLCF}
proj/include/ent.h
11 11
double (ent_get_XLength)(void);
12 12
double (ent_get_YLength)(void);
13 13

  
14
typedef enum {
15
    gunner_melee  = BIT(0),
16
    gunner_ranged = BIT(1),
17
    gunner_player = BIT(2),
18
    gunner_follow = BIT(3)
19
} gunner_type;
14
#define GUNNER_MELEE    BIT(0)
15
#define GUNNER_RANGED   BIT(1)
16
#define GUNNER_PLAYER   BIT(2)
17
#define GUNNER_FOLLOW   BIT(3)
20 18

  
21 19
struct gunner;
22 20
typedef struct gunner gunner_t;
23
gunner_t* (gunner_ctor)(basic_sprite_t *dude, basic_sprite_t *weapon, gunner_type type, int team);
21
gunner_t* (gunner_ctor)(basic_sprite_t *dude, basic_sprite_t *weapon, uint16_t type, int team);
24 22
void      (gunner_dtor)(gunner_t *p);
25 23
void (gunner_set_pos)               (gunner_t *p, double x, double y);
26 24
void (gunner_set_spawn)             (gunner_t *p, double x, double y);
......
36 34
double  (gunner_get_curr_health)    (const gunner_t *p);
37 35
int16_t (gunner_get_x_screen)       (const gunner_t *p);
38 36
int16_t (gunner_get_y_screen)       (const gunner_t *p);
39
gunner_type (gunner_get_type)       (const gunner_t *p);
37
uint16_t (gunner_get_type)          (const gunner_t *p);
40 38
int     (gunner_get_team)           (const gunner_t *p);
41 39
void (gunner_draw)(gunner_t *p);
42 40
void (gunner_draw_health)(const gunner_t *p);
......
66 64

  
67 65
struct map;
68 66
typedef struct map map_t;
69
map_t* (map_ctor)(const char **background, const char **collide);
67
map_t* (map_ctor)(const char *const *background, const char *const *collide);
70 68
void   (map_dtor)(map_t *p);
71 69
int    (map_collides_point)(const map_t *p, double x, double y);
72 70
int    (map_collides_gunner)(const map_t *p, const gunner_t *gunner);
73 71
int    (map_collides_bullet)(const map_t *p, const bullet_t *bullet);
74 72
int16_t (map_get_width)   (const map_t *p);
75 73
int16_t (map_get_height)  (const map_t *p);
76
int (map_make_dijkstra)(map_t *p, int16_t x, int16_t y);
77
int (map_where_to_follow)(const map_t *p, float x, float y, float *theta);
74
int (map_make_dijkstra)(map_t *p, double x_, double y_);
75
int (map_where_to_follow)(const map_t *p, double x, double y, double *theta);
78 76
int (gunner_collides_bullet)(const gunner_t *shooter, const bullet_t *bull);
79 77
double (distance_gunners)(const gunner_t *shooter1, const gunner_t *shooter2);
80 78
int (gunner_collides_gunner)(const gunner_t *shooter1, const gunner_t *shooter2);
proj/include/proj_func.h
33 33

  
34 34
void update_scale(void);
35 35

  
36
int32_t* get_mouse_X(void);
36
int16_t* get_mouse_X(void);
37 37

  
38
int32_t* get_mouse_Y(void);
38
int16_t* get_mouse_Y(void);
39 39

  
40 40
void build_host_structure(host_info_t *p, gunner_t *host, gunner_t *remote, list_t *bullet_list);
41 41

  
42 42
void build_remote_structure(remote_info_t *p, keys_t *keys, double angle);
43 43

  
44
/**
45
 * @brief
46
 * @param
47
 * @param
48
 * @param
49
 * @return Angle
50
 */
51 44
double get_mouse_angle(gunner_t *p);
52 45

  
53 46
typedef struct timer {
proj/include/proj_structures.h
15 15
    uint8_t lb_pressed      : 1;
16 16
} keys_t;
17 17

  
18
typedef struct __attribute__((packed)) {
18
typedef struct {
19 19
    // host
20 20
    double  host_x;
21 21
    double  host_y;
......
39 39
    bool   *bullets_shooter; // false for host, true for remote
40 40
} host_info_t;
41 41

  
42
typedef struct __attribute__((packed)) {
42
typedef struct {
43 43
    keys_t  remote_keys_pressed;
44 44
    double  remote_angle;
45 45
} remote_info_t;
46 46

  
47
typedef struct __attribute__((packed)) {
47
typedef struct {
48 48
    bool   new_bullet;
49 49
} bullet_info_t;
50 50

  
proj/libs/graph/include/graph.h
56 56
struct basic_sprite;
57 57
typedef struct basic_sprite basic_sprite_t;
58 58

  
59
basic_sprite_t* (basic_sprite_ctor)(const char **xpm, int16_t u0, int16_t v0);
59
basic_sprite_t* (basic_sprite_ctor)(const char *const *xpm, int16_t u0, int16_t v0);
60 60
void            (basic_sprite_dtor)(basic_sprite_t *p);
61 61
const uint8_t* (basic_sprite_get_map)(const basic_sprite_t *p);
62 62
uint16_t       (basic_sprite_get_w)  (const basic_sprite_t *p);
proj/libs/graph/src/font.c
176 176
void (text_set_halign)(text_t *p, text_halign halign  ){ p->halign = halign; }
177 177
int16_t (text_get_x)  (const text_t *p){ return p->x; }
178 178
int16_t (text_get_y)  (const text_t *p){ return p->y; }
179

  
180 179
int (text_draw)(const text_t *p){
181 180
    if(p == NULL) return NULL_PTR;
182 181
    int ret = SUCCESS;
proj/libs/graph/src/graph.c
287 287
    uint16_t w, h;
288 288
    int16_t u0, v0;
289 289
};
290
basic_sprite_t* (basic_sprite_ctor)(const char **xpm, int16_t u0, int16_t v0){
290
basic_sprite_t* (basic_sprite_ctor)(const char *const *xpm, int16_t u0, int16_t v0){
291 291
    basic_sprite_t *ret = malloc(sizeof(basic_sprite_t));
292 292
    if(ret == NULL) return NULL;
293 293
    enum xpm_image_type type = XPM_8_8_8_8;
......
358 358
    const basic_sprite_t *bsp;
359 359
    int16_t x, y; //position in screen
360 360
    int16_t su0, sv0;
361
    float theta, s, c;
362
    float scale;
361
    double theta, s, c;
362
    double scale;
363 363
    uint8_t *sbuf;
364 364
};
365 365
sprite_t* (sprite_ctor)(const basic_sprite_t *bsp){
......
410 410
        *u = x - p->x + p->su0;
411 411
        *v = y - p->y + p->sv0;
412 412
    }else{
413
        float dx = x - p->x;
414
        float dy = y - p->y;
413
        double dx = x - p->x;
414
        double dy = y - p->y;
415 415
        int16_t du = dx*p->c - dy*p->s - 0.5f;
416 416
        int16_t dv = dx*p->s + dy*p->c - 0.5f;
417 417
        *u = du + p->su0;
proj/libs/kbc/include/kbc.h
90 90

  
91 91
/**
92 92
 * @brief Low-level function to issue an argument of a command
93
 * @param cmd argument to be issued
93
 * @param arg argument to be issued
94 94
 * @return 0 if operation was successful, 1 otherwise
95 95
 */
96 96
int (kbc_issue_arg)(uint8_t arg);
......
99 99
 * @brief Low-level function for reading byte from keyboard
100 100
 * Low-level function for reading byte from keyboard. Waits until output buffer
101 101
 * is full
102
 * @param value Pointer to variable where byte read from keyboard will be stored
102
 * @param byte Pointer to variable where byte read from keyboard will be stored
103 103
 * @return 0 if operation was successful, 1 otherwise
104 104
 */
105 105
int (kbc_read_byte)(uint8_t *byte);
proj/libs/kbc/include/keyboard.h
38 38
 */
39 39
int (subscribe_kbc_interrupt)(uint8_t interrupt_bit, int *interrupt_id);
40 40

  
41
uint8_t scancode[2];
42
int done;
43
int sz;
44
int got_error_keyboard;
45 41

  
42
const uint8_t* keyboard_get_scancode(void);
43
int keyboard_get_done(void);
44
int keyboard_get_size(void);
45
int keyboard_get_error(void);
46

  
46 47
void (kbc_ih)(void);
47 48

  
48 49
int (keyboard_poll)(uint8_t bytes[], uint8_t *size);
proj/libs/kbc/src/keyboard.c
14 14
    return SUCCESS;
15 15
}
16 16

  
17
int done = 1;
18
int sz = 1;
19
int got_error_keyboard = SUCCESS;
17
static uint8_t scancode[2];
18
static int done = 1;
19
static int sz = 1;
20
static int got_error_keyboard = SUCCESS;
21
const uint8_t* keyboard_get_scancode(void){ return scancode; }
22
int keyboard_get_done(void){ return done; }
23
int keyboard_get_size(void){ return sz; }
24
int keyboard_get_error(void){return got_error_keyboard; }
20 25

  
26

  
21 27
void (kbc_ih)(void) {
22 28
    if(done) { sz = 1; }
23 29
    else     sz++;
proj/libs/timer/include/timer.h
9 9

  
10 10
int (subscribe_timer_interrupt)(uint8_t interrupt_bit, int *interrupt_id);
11 11

  
12
uint32_t no_interrupts;
12
uint32_t (timer_get_no_interrupts)(void);
13 13

  
14 14
#endif //TIMER_H_INCLUDED
proj/libs/timer/src/timer.c
58 58
    return (sys_irqsetpolicy(TIMER0_IRQ, IRQ_REENABLE, interrupt_id));
59 59
}
60 60

  
61
uint32_t no_interrupts = 0;
61
static uint32_t no_interrupts = 0;
62 62
void (timer_int_handler)() {
63 63
    no_interrupts++;
64 64
}
65

  
66
uint32_t (timer_get_no_interrupts)(void){ return no_interrupts; }
proj/libs/uart/include/uart.h
42 42
int uart_set_bits_per_character(int base_addr, uint8_t     bits_per_char);
43 43
int uart_set_stop_bits         (int base_addr, uint8_t     stop         );
44 44
int uart_set_parity            (int base_addr, uart_parity par          );
45
int uart_set_bit_rate          (int base_addr, float       bit_rate     );
45
int uart_set_bit_rate          (int base_addr, double      bit_rate     );
46 46

  
47 47
int uart_enable_int_rx (int base_addr);
48 48
int uart_disable_int_rx(int base_addr);
proj/libs/uart/src/uart.c
212 212
    conf = (conf & (~UART_PARITY)) | parity;
213 213
    return uart_set_lcr(base_addr, conf);
214 214
}
215
int uart_set_bit_rate(int base_addr, float bit_rate){
215
int uart_set_bit_rate(int base_addr, double bit_rate){
216 216
    int ret = SUCCESS;
217 217
    uint16_t latch = UART_BITRATE/bit_rate;
218 218
    uint8_t dll = UART_GET_DLL(latch);
proj/maps/map1.h
7 7

  
8 8
#include "xpm_utils.h"
9 9

  
10
map_t* get_map1(void){
10
static map_t* get_map1(void){
11 11
    char **map1         = xpm_load_xpm2("maps/map1.xpm2");
12 12
    char **map1_collide = xpm_load_xpm2("maps/map1_collide.xpm2");
13
    return map_ctor((const char **)map1_xpm, (const char **)map1_collide_xpm);
13
    return map_ctor((const char *const *)map1_xpm, (const char *const *)map1_collide_xpm);
14 14
    free(map1); free(map1_collide);
15 15
}
16 16

  
proj/media/xpm/bullet.h
4 4
#include "bullet.xpm"
5 5
#include "graph.h"
6 6

  
7
basic_sprite_t* get_bullet(void){
8
    return basic_sprite_ctor((const char **)bullet_xpm, 3, 7);
7
static basic_sprite_t* get_bullet(void){
8
    return basic_sprite_ctor((const char *const *)bullet_xpm, 3, 7);
9 9
}
10 10

  
11 11
#endif /* end of include guard: BULLET_H_INCLUDED */
proj/media/xpm/crosshair.h
4 4
#include "crosshair.xpm"
5 5
#include "graph.h"
6 6

  
7
basic_sprite_t* get_crosshair(){
8
    return basic_sprite_ctor(crosshair_xpm, 16, 16);
7
static basic_sprite_t* get_crosshair(){
8
    return basic_sprite_ctor((const char *const *)crosshair_xpm, 16, 16);
9 9
}
10 10

  
11 11
#endif //CROSSHAIR_H_INCLUDED
proj/media/xpm/nothing.h
4 4
#include "nothing.xpm"
5 5
#include "graph.h"
6 6

  
7
basic_sprite_t* get_nothing(void){
8
    return basic_sprite_ctor((const char **)nothing_xpm, 34, 34);
7
static basic_sprite_t* get_nothing(void){
8
    return basic_sprite_ctor((const char *const *)nothing_xpm, 34, 34);
9 9
}
10 10

  
11 11
#endif //NOTHING_H_INCLUDED
proj/media/xpm/pistol.h
4 4
#include "pistol.xpm"
5 5
#include "graph.h"
6 6

  
7
basic_sprite_t* get_pistol(void){
8
    return basic_sprite_ctor((const char **)pistol_xpm, 34, 34);
7
static basic_sprite_t* get_pistol(void){
8
    return basic_sprite_ctor((const char *const *)pistol_xpm, 34, 34);
9 9
}
10 10

  
11 11
#endif //PISTOL_H_INCLUDED
proj/media/xpm/shooter.h
4 4
#include "shooter.xpm"
5 5
#include "graph.h"
6 6

  
7
basic_sprite_t* get_shooter(void){
8
    return basic_sprite_ctor((const char **)shooter_xpm, 34, 34);
7
static basic_sprite_t* get_shooter(void){
8
    return basic_sprite_ctor((const char *const *)shooter_xpm, 34, 34);
9 9
}
10 10

  
11 11
#endif //SHOOTER_H_INCLUDED
proj/media/xpm/zombie.h
4 4
#include "zombie.xpm"
5 5
#include "graph.h"
6 6

  
7
basic_sprite_t* get_zombie(void){
8
    return basic_sprite_ctor((const char **)zombie_xpm, 34, 34);
7
static basic_sprite_t* get_zombie(void){
8
    return basic_sprite_ctor((const char *const *)zombie_xpm, 34, 34);
9 9
}
10 10

  
11 11
#endif //ZOMBIE_H_INCLUDED
proj/src/ent.c
30 30
    double health, current_health;
31 31
    rectangle_t *green_bar, *red_bar;
32 32
    text_t *txt;
33
    gunner_type type;
33
    uint16_t type;
34 34
    int team;
35 35
};
36
gunner_t* (gunner_ctor)(basic_sprite_t *dude, basic_sprite_t *weapon, gunner_type type, int team){
36
gunner_t* (gunner_ctor)(basic_sprite_t *dude, basic_sprite_t *weapon, uint16_t type, int team){
37 37
    gunner_t *ret = malloc(sizeof(gunner_t));
38 38
    if(ret == NULL) return NULL;
39 39
    ret->spawn_x = 0.0;
......
93 93
double  (gunner_get_curr_health)    (const gunner_t *p){ return p->current_health; }
94 94
int16_t (gunner_get_x_screen)       (const gunner_t *p){ return (p->x-x_origin)*scale; }
95 95
int16_t (gunner_get_y_screen)       (const gunner_t *p){ return (p->y-y_origin)*scale; }
96
gunner_type (gunner_get_type)       (const gunner_t *p){ return p->type; }
96
uint16_t (gunner_get_type)          (const gunner_t *p){ return p->type; }
97 97
int     (gunner_get_team)           (const gunner_t *p){ return p->team; }
98 98
void (gunner_draw)(gunner_t *p){
99 99
    const int16_t x_screen = gunner_get_x_screen(p);
......
232 232
    }
233 233
    return 0;
234 234
}
235
map_t* (map_ctor)(const char **background, const char **collide){
235
map_t* (map_ctor)(const char *const *background, const char *const *collide){
236 236
    map_t *ret = malloc(sizeof(map_t));
237 237
    if(ret == NULL) return NULL;
238 238

  
......
299 299
    double radius = max(sprite_get_w(shooter->dude), sprite_get_h(shooter->dude))/2.0;
300 300
    return map_collides_gunner_pos(p, gunner_get_x(shooter), gunner_get_y(shooter), radius);
301 301
}
302
int (map_make_dijkstra)(map_t *p, int16_t x, int16_t y){
302
int (map_make_dijkstra)(map_t *p, double x_, double y_){
303
    int16_t x = x_, y = y_;
303 304

  
304 305
    const uint16_t W = basic_sprite_get_w(p->bsp_background),
305 306
                   H = basic_sprite_get_h(p->bsp_background);
......
334 335

  
335 336
    return SUCCESS;
336 337
}
337
int (map_where_to_follow)(const map_t *p, float x, float y, float *theta){
338
int (map_where_to_follow)(const map_t *p, double x, double y, double *theta){
338 339
    const uint16_t W = basic_sprite_get_w(p->bsp_background);
339 340
    int x_ = x, y_ = y;
340 341
    int pos = y_*W+x_;
proj/src/interrupts_func.c
77 77
    if (subscribe_kbc_interrupt(KBC_IRQ, &kbc_id)) {
78 78
        printf("%s: failed to subscribe keyboard interrupts.\n", __func__);
79 79
        if (unsubscribe_all())
80
            printf("%s: failed to unsubcribe driver, unexpected behaviour is expected.\n");
80
            printf("%s: failed to unsubcribe driver, unexpected behaviour is expected.\n", __func__);
81 81
        return SBCR_ERROR;
82 82
    }
83 83
    keyboard_subscribed = 1;
......
87 87
    if (subscribe_mouse_interrupt(MOUSE_IRQ, &mouse_id)) { // subscribes mouse interrupts in exclusive mode
88 88
        printf("%s: failed to subscribe mouse interrupts.\n", __func__);
89 89
        if (unsubscribe_all())
90
            printf("%s: failed to unsubcribe driver, unexpected behaviour is expected.\n");
90
            printf("%s: failed to unsubcribe driver, unexpected behaviour is expected.\n", __func__);
91 91
        return SBCR_ERROR;
92 92
    }
93 93
    mouse_subscribed = 1;
94 94
    if (sys_irqdisable(&mouse_id)) { // temporarily disables our interrupts notifications
95 95
        printf("%s: failed to disable mouse interrupts.\n", __func__);
96 96
        if (unsubscribe_all())
97
            printf("%s: failed to unsubcribe driver, unexpected behaviour is expected.\n");
97
            printf("%s: failed to unsubcribe driver, unexpected behaviour is expected.\n", __func__);
98 98
        return SBCR_ERROR;
99 99
    }
100 100
    if (mouse_set_data_report(true)) { // enables mouse data reporting
101 101
        printf("%s: failed to enable mouse data reporting.\n", __func__);
102 102
        if (unsubscribe_all())
103
            printf("%s: failed to unsubcribe driver, unexpected behaviour is expected.\n");
103
            printf("%s: failed to unsubcribe driver, unexpected behaviour is expected.\n", __func__);
104 104
        return SBCR_ERROR;
105 105
    }
106 106
    if (sys_irqenable(&mouse_id)) { // re-enables our interrupts notifications
107 107
        printf("%s: failed to enable mouse interrupts.\n", __func__);
108 108
        if (unsubscribe_all())
109
            printf("%s: failed to unsubcribe driver, unexpected behaviour is expected.\n");
109
            printf("%s: failed to unsubcribe driver, unexpected behaviour is expected.\n", __func__);
110 110
        return SBCR_ERROR;
111 111
    }
112 112

  
......
134 134
    // Unsubscribe Timer Interrupts
135 135
    if (timer_subscribed) {
136 136
        if (unsubscribe_interrupt(&timer_id)) {
137
            printf("%s: failed to unsubcribe timer interrupts.\n");
137
            printf("%s: failed to unsubcribe timer interrupts.\n", __func__);
138 138
            r = UNSBCR_ERROR;
139 139
        }
140 140
        timer_subscribed = 0;
......
143 143
    // Unsubscribe Keyboard interrupts
144 144
    if (keyboard_subscribed) {
145 145
        if (unsubscribe_interrupt(&kbc_id)) {
146
            printf("%s: failed to unsubcribe keyboard interrupts.\n");
146
            printf("%s: failed to unsubcribe keyboard interrupts.\n", __func__);
147 147
            r = UNSBCR_ERROR;
148 148
        }
149 149
        keyboard_subscribed = 0;
......
152 152
    // Unsubscribe Mouse Interrupts
153 153
    if (mouse_subscribed) {
154 154
        if (sys_irqdisable(&mouse_id)) { // temporarily disables our interrupts notifications
155
            printf("%s: failed to disable mouse interrupts.\n");
155
            printf("%s: failed to disable mouse interrupts.\n", __func__);
156 156
            r = UNSBCR_ERROR;
157 157
        }
158 158
        if (mouse_set_data_report(false)) { // disables mouse data reporting
159
            printf("%s: failed to disable mouse data reporting.\n");
159
            printf("%s: failed to disable mouse data reporting.\n", __func__);
160 160
            r = UNSBCR_ERROR;
161 161
        }
162 162
        if (sys_irqenable(&mouse_id)) { // re-enables our interrupts notifications
163
            printf("%s: failed to enable mouse interrupts.\n");
163
            printf("%s: failed to enable mouse interrupts.\n", __func__);
164 164
            r = UNSBCR_ERROR;
165 165
        }
166 166
        if (unsubscribe_interrupt(&mouse_id)) { // unsubscribes interrupts
167
            printf("%s: failed to unsubcribe mouse interrupts.\n");
167
            printf("%s: failed to unsubcribe mouse interrupts.\n", __func__);
168 168
            r = UNSBCR_ERROR;
169 169
        }
170 170
        mouse_subscribed = 0;
......
173 173
    // Unsubscribe UART interrupts
174 174
    if (uart_subscribed) {
175 175
        if (unsubscribe_interrupt(&uart_id)) {
176
            printf("%s: failed to unsubcribe UART interrupts.\n");
176
            printf("%s: failed to unsubcribe UART interrupts.\n", __func__);
177 177
            r = UNSBCR_ERROR;
178 178
        }
179 179
        uart_enable_int_rx(COM1_ADDR);
proj/src/proj.c
49 49
    return 0;
50 50
}
51 51

  
52
basic_sprite_t       *bsp_crosshair = NULL;
53
basic_sprite_t       *bsp_shooter   = NULL;
54
basic_sprite_t       *bsp_zombie    = NULL;
55
basic_sprite_t       *bsp_pistol    = NULL;
56
basic_sprite_t       *bsp_nothing   = NULL;
57
basic_sprite_t       *bsp_bullet    = NULL;
58
map_t                *map1          = NULL;
59
sprite_t             *sp_crosshair  = NULL;
52
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 60

  
61 61
static int (singleplayer)(void);
62 62
static int (multiplayer)(void);
......
118 118
    while (good) {
119 119
        /* Get a request message. */
120 120
        if((r = get_interrupts_vector(&int_vector))) return r;
121
        for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) {
121
        uint32_t n = 1;
122
        for (uint8_t i = 0; i < 32; i++, n <<= 1) {
122 123
            if (int_vector & n) {
123 124
                interrupt_handler(i);
124 125
                switch (i) {
......
142 143

  
143 144
                    break;
144 145
                    case KBC_IRQ:
145
                    if ((scancode[0]) == ESC_BREAK_CODE) good = false;
146
                    if (keyboard_get_scancode()[0] == ESC_BREAK_CODE) good = false;
146 147
                    case MOUSE_IRQ:
147 148
                    if (counter_mouse_ih >= 3) {
148 149
                        mouse_parse_packet(packet_mouse_ih, &pp);
......
182 183
    return 0;
183 184
}
184 185

  
185
host_info_t     *host_info   = NULL;
186
remote_info_t   *remote_info = NULL;
187
bullet_info_t   *bullet_info = NULL;
186
static host_info_t     *host_info   = NULL;
187
static remote_info_t   *remote_info = NULL;
188
static bullet_info_t   *bullet_info = NULL;
188 189

  
189 190
static void multiplayer_process(const uint8_t *p, const size_t sz) {
190 191
    void *dest = NULL;
......
202 203
            bullet_info_dtor(bullet_info);
203 204
            bullet_info = (bullet_info_t*)dest;
204 205
            break;
205
        default: break;
206
        case hltp_type_invalid: break;
207
        case hltp_type_string : break;
206 208
    }
207 209
}
208 210
static int (multiplayer_host)(void);
......
227 229
    while (good) {
228 230
        /* Get a request message. */
229 231
        if((r = get_interrupts_vector(&int_vector))) return r;
230
        for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) {
232
        uint32_t n = 1;
233
        for (uint8_t i = 0; i < 32; i++, n <<= 1) {
231 234
            if (int_vector & n) {
232 235
                interrupt_handler(i);
233 236
                switch (i) {
......
250 253

  
251 254
                    break;
252 255
                    case KBC_IRQ:
253
                    if ((scancode[0]) == ESC_BREAK_CODE) good = false;
256
                    if (keyboard_get_scancode()[0] == ESC_BREAK_CODE) good = false;
254 257
                    case MOUSE_IRQ:
255 258
                    if (counter_mouse_ih >= 3) {
256 259
                        mouse_parse_packet(packet_mouse_ih, &pp);
......
279 282

  
280 283
    list_t *shooter_list = list_ctor();
281 284

  
282
    gunner_t *shooter1 = gunner_ctor(bsp_shooter, bsp_pistol, gunner_player, 1); if(shooter1 == NULL) printf("Failed to get shooter1\n");
285
    gunner_t *shooter1 = gunner_ctor(bsp_shooter, bsp_pistol, GUNNER_PLAYER, 1); if(shooter1 == NULL) printf("Failed to get shooter1\n");
283 286
    gunner_set_spawn(shooter1, 75, 75);
284 287

  
285
    gunner_t *shooter2 = gunner_ctor(bsp_shooter, bsp_pistol, gunner_player, 2); if(shooter2 == NULL) printf("Failed to get shooter2\n");
288
    gunner_t *shooter2 = gunner_ctor(bsp_shooter, bsp_pistol, GUNNER_PLAYER, 2); if(shooter2 == NULL) printf("Failed to get shooter2\n");
286 289
    gunner_set_spawn(shooter2, 975, 75);
287 290

  
288 291
    list_insert(shooter_list, list_end(shooter_list), shooter1);
......
314 317
    int state_1, state_2;
315 318
    while (good) {
316 319
        if ((r = get_interrupts_vector(&int_vector))) return r;
317
        for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) {
320
        uint32_t n = 1;
321
        for (uint8_t i = 0; i < 32; i++, n <<= 1) {
318 322
            if (int_vector & n) {
319 323
                interrupt_handler(i);
320 324
                switch (i) {
321 325
                    case TIMER0_IRQ:
322
                    if (no_interrupts % 60 == 0) timer_update(in_game_timer);
326
                    if (timer_get_no_interrupts() % 60 == 0) timer_update(in_game_timer);
323 327

  
324 328
                    update_movement(map1, shooter1, keys, shooter_list);
325 329
                    update_movement(map1, shooter2, &(remote_info->remote_keys_pressed), shooter_list);
......
360 364

  
361 365
                    break;
362 366
                    case KBC_IRQ:
363
                    if ((scancode[0]) == ESC_BREAK_CODE) {
367
                    if (keyboard_get_scancode()[0] == ESC_BREAK_CODE) {
364 368
                        good = false;
365 369
                    }
366 370
                    break;
......
418 422

  
419 423
    list_t *shooter_list = list_ctor();
420 424

  
421
    gunner_t *shooter1 = gunner_ctor(bsp_shooter, bsp_pistol, gunner_player, 2); if(shooter1 == NULL) printf("Failed to get shooter1\n");
425
    gunner_t *shooter1 = gunner_ctor(bsp_shooter, bsp_pistol, GUNNER_PLAYER, 2); if(shooter1 == NULL) printf("Failed to get shooter1\n");
422 426
    gunner_set_spawn(shooter1, 75, 75);
423 427

  
424
    gunner_t *shooter2 = gunner_ctor(bsp_shooter, bsp_pistol, gunner_player, 1); if(shooter2 == NULL) printf("Failed to get shooter2\n");
428
    gunner_t *shooter2 = gunner_ctor(bsp_shooter, bsp_pistol, GUNNER_PLAYER, 1); if(shooter2 == NULL) printf("Failed to get shooter2\n");
425 429
    gunner_set_spawn(shooter2, 975, 75);
426 430

  
427 431
    list_insert(shooter_list, list_end(shooter_list), shooter1);
......
446 450
    int good = true;
447 451
    while (good) {
448 452
        if ((r = get_interrupts_vector(&int_vector))) return r;
449
        for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) {
453
        uint32_t n = 1;
454
        for (uint8_t i = 0; i < 32; i++, n <<= 1) {
450 455
            if (int_vector & n) {
451 456
                interrupt_handler(i);
452 457
                switch (i) {
453 458
                    case TIMER0_IRQ:
454
                    if (no_interrupts % 60 == 0) timer_update(in_game_timer);
459
                    if (timer_get_no_interrupts() % 60 == 0) timer_update(in_game_timer);
455 460

  
456 461
                    double angle = get_mouse_angle(shooter1);
457 462

  
......
472 477
                    ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0,
473 478
                                   gunner_get_y(shooter1)-ent_get_YLength()/2.0);
474 479

  
475
                    for (size_t i = 0; i < host_info->no_bullets; i++) {
476
                        if (host_info->bullets_shooter[i]) { // remote
477
                            bullet_t *bullet = bullet_ctor(shooter1, bsp_bullet, host_info->bullets_x[i], host_info->bullets_y[i], host_info->bullets_vx[i], host_info->bullets_vy[i]);
480
                    for (size_t j = 0; j < host_info->no_bullets; j++) {
481
                        if (host_info->bullets_shooter[j]) { // remote
482
                            bullet_t *bullet = bullet_ctor(shooter1, bsp_bullet, host_info->bullets_x[j], host_info->bullets_y[j], host_info->bullets_vx[j], host_info->bullets_vy[j]);
478 483
                            list_insert(bullet_list, list_end(bullet_list), bullet);
479 484
                        } else { // host
480
                            bullet_t *bullet = bullet_ctor(shooter2, bsp_bullet, host_info->bullets_x[i], host_info->bullets_y[i], host_info->bullets_vx[i], host_info->bullets_vy[i]);
485
                            bullet_t *bullet = bullet_ctor(shooter2, bsp_bullet, host_info->bullets_x[j], host_info->bullets_y[j], host_info->bullets_vx[j], host_info->bullets_vy[j]);
481 486
                            list_insert(bullet_list, list_end(bullet_list), bullet);
482 487
                        }
483 488
                    }
......
500 505

  
501 506
                    break;
502 507
                    case KBC_IRQ:
503
                    if ((scancode[0]) == ESC_BREAK_CODE) {
508
                    if (keyboard_get_scancode()[0] == ESC_BREAK_CODE) {
504 509
                        good = false;
505 510
                    }
506 511
                    break;
......
567 572
    while (good) {
568 573
        /* Get a request message. */
569 574
        if((r = get_interrupts_vector(&int_vector))) return r;
570
        for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) {
575
        uint32_t n = 1;
576
        for (uint8_t i = 0; i < 32; i++, n <<= 1) {
571 577
            if (int_vector & n) {
572 578
                interrupt_handler(i);
573 579
                switch (i) {
......
590 596

  
591 597
                    break;
592 598
                    case KBC_IRQ:
593
                    if ((scancode[0]) == ESC_BREAK_CODE) good = false;
599
                    if (keyboard_get_scancode()[0] == ESC_BREAK_CODE) good = false;
594 600
                    case MOUSE_IRQ:
595 601
                    if (counter_mouse_ih >= 3) {
596 602
                        mouse_parse_packet(packet_mouse_ih, &pp);
......
618 624

  
619 625
    list_t *shooter_list = list_ctor();
620 626

  
621
    gunner_t *shooter1 = gunner_ctor(bsp_shooter, bsp_pistol, gunner_player, 1); if(shooter1 == NULL) printf("Failed to get shooter1\n");
627
    gunner_t *shooter1 = gunner_ctor(bsp_shooter, bsp_pistol, GUNNER_PLAYER, 1); if(shooter1 == NULL) printf("Failed to get shooter1\n");
622 628
    gunner_set_spawn(shooter1, 75, 75);
623 629
    gunner_set_pos(shooter1, 75, 75);
624 630

  
625
    gunner_t *shooter2 = gunner_ctor(bsp_shooter, bsp_nothing, gunner_player, 2);
631
    gunner_t *shooter2 = gunner_ctor(bsp_shooter, bsp_nothing, GUNNER_PLAYER, 2);
626 632
    gunner_set_spawn(shooter2, 975, 75);
627 633
    gunner_set_pos(shooter2, 775, 75);
628 634

  
......
645 651
    while (good) {
646 652
        /* Get a request message. */
647 653
        if((r = get_interrupts_vector(&int_vector))) return r;
648
        for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) {
654
        uint32_t n = 1;
655
        for (uint8_t i = 0; i < 32; i++, n <<= 1) {
649 656
            if(!good) break;
650 657
            if (int_vector & n) {
651 658
                interrupt_handler(i);
652 659
                switch (i) {
653 660
                    case TIMER0_IRQ:
654 661

  
655
                    if (no_interrupts % 60 == 0) timer_update(in_game_timer);
662
                    if (timer_get_no_interrupts() % 60 == 0) timer_update(in_game_timer);
656 663
                    update_movement(map1, shooter1, keys, shooter_list);
657 664

  
658 665
                    update_game_state(map1, shooter_list, bullet_list);
......
677 684

  
678 685
                    break;
679 686
                    case KBC_IRQ:
680
                    if ((scancode[0]) == ESC_BREAK_CODE) {
687
                    if (keyboard_get_scancode()[0] == ESC_BREAK_CODE) {
681 688
                        good = false;
682 689
                    }
683 690
                    break;
......
726 733

  
727 734
    list_t *shooter_list = list_ctor();
728 735

  
729
    gunner_t *shooter1 = gunner_ctor(bsp_shooter, bsp_pistol, gunner_player, 1); if(shooter1 == NULL) printf("Failed to get shooter1\n");
736
    gunner_t *shooter1 = gunner_ctor(bsp_shooter, bsp_pistol, GUNNER_PLAYER, 1); if(shooter1 == NULL) printf("Failed to get shooter1\n");
730 737
    gunner_set_spawn(shooter1, 980, 790);
731 738
    gunner_set_pos(shooter1, 980, 790);
732 739

  
......
749 756

  
750 757
    int health = 50;
751 758

  
752
    /** #DEV */ /* {
753
        gunner_t *zombie = gunner_ctor(bsp_zombie, bsp_nothing, gunner_melee | gunner_follow, 3);
754
        gunner_set_health(zombie, health);
755
        gunner_set_curr_health(zombie, health);
756
        health *= ZOMBIE_HEALTH_FACTOR;
757
        gunner_set_pos(zombie, 1100, 75);
758
        list_push_back(shooter_list, zombie);
759
    }*/ //\#DEV
760

  
761 759
    map_make_dijkstra(map1, gunner_get_x(shooter1), gunner_get_y(shooter1));
762 760

  
763 761
    while (good && !dead) {
764 762
        /* Get a request message. */
765 763
        if((r = get_interrupts_vector(&int_vector))) return r;
766
        for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) {
764
        uint32_t n = 1;
765
        for (uint8_t i = 0; i < 32; i++, n <<= 1) {
767 766
            if(!good || dead) break;
768 767
            if (int_vector & n) {
769 768
                interrupt_handler(i);
770 769
                switch (i) {
771 770
                    case TIMER0_IRQ:
772
                    if (no_interrupts % 60 == 0) timer_update(in_game_timer);
773
                    if (no_interrupts %  6 == 0){
771
                    if (timer_get_no_interrupts() % 60 == 0) timer_update(in_game_timer);
772
                    if (timer_get_no_interrupts() %  6 == 0){
774 773
                        map_make_dijkstra(map1, gunner_get_x(shooter1), gunner_get_y(shooter1));
775 774
                    }
776 775

  
......
791 790
                                   gunner_get_y(shooter1)-ent_get_YLength()/2.0);
792 791

  
793 792
                    while(list_size(shooter_list) < ZOMBIES_NUM+1){
794
                        gunner_t *zombie = gunner_ctor(bsp_zombie, bsp_nothing, gunner_melee | gunner_follow, 3);
793
                        gunner_t *zombie = gunner_ctor(bsp_zombie, bsp_nothing, GUNNER_MELEE | GUNNER_FOLLOW, 3);
795 794
                        gunner_set_health(zombie, health);
796 795
                        gunner_set_curr_health(zombie, health);
797 796
                        health *= ZOMBIE_HEALTH_FACTOR;
......
812 811

  
813 812
                    break;
814 813
                    case KBC_IRQ:
815
                    if ((scancode[0]) == ESC_BREAK_CODE) {
814
                    if (keyboard_get_scancode()[0] == ESC_BREAK_CODE) {
816 815
                        good = false;
817 816
                    }
818 817
                    break;
......
856 855

  
857 856
#define CHAT_MAX_SIZE   75
858 857
#define CHAT_MAX_NUM    19
859
text_t      *t_text[CHAT_MAX_NUM] = {NULL};
860
rectangle_t *r_text               =  NULL;
858
static text_t      *t_text[CHAT_MAX_NUM] = {NULL};
859
static rectangle_t *r_text               =  NULL;
861 860
static void chat_process(const uint8_t *p, const size_t sz){
862 861
    char buffer2[CHAT_MAX_NUM+3];
863 862
    void *dest = NULL;
......
879 878
            }
880 879
        }
881 880
        break;
882
        default: break;
881
        case hltp_type_invalid: break;
882
        case hltp_type_bullet : break;
883
        case hltp_type_host   : break;
884
        case hltp_type_remote : break;
883 885
    }
884 886
}
885 887
static int (chat)(void){
......
894 896
    rectangle_t *r_buffer = NULL; {
895 897
        r_buffer = rectangle_ctor(0,0,900,70);
896 898
        rectangle_set_pos(r_buffer, graph_get_XRes()/2  -rectangle_get_w(r_buffer)/2,
897
        graph_get_YRes()*0.87-rectangle_get_h(r_buffer)/2);
899
        (int16_t)(graph_get_YRes()*0.87-rectangle_get_h(r_buffer)/2));
898 900
        rectangle_set_fill_color   (r_buffer, GRAPH_BLACK);
899 901
        rectangle_set_outline_width(r_buffer, 2);
900 902
        rectangle_set_outline_color(r_buffer, GRAPH_WHITE);
......
924 926
    /** r_text */ {
925 927
    r_text = rectangle_ctor(0,0,900,550);
926 928
    rectangle_set_pos(r_text, graph_get_XRes()/2  -rectangle_get_w(r_buffer)/2,
927
    graph_get_YRes()*0.09);
929
    (int16_t)(graph_get_YRes()*0.09));
928 930
    rectangle_set_fill_color   (r_text, GRAPH_BLACK);
929 931
    rectangle_set_outline_width(r_text, 2);
930 932
    rectangle_set_outline_color(r_text, GRAPH_WHITE);
931 933
    rectangle_set_fill_trans(r_text, GRAPH_TRANSPARENT);
932 934
    }
933 935
    /** t_text */ {
934
    for(size_t i = 0; i < CHAT_MAX_NUM; ++i){
936
    for(uint16_t i = 0; i < CHAT_MAX_NUM; ++i){
935 937
        t_text[i] = text_ctor(font_get_default(), " ");
936 938
        text_set_pos(t_text[i], rectangle_get_x(r_text)+50,
937 939
        rectangle_get_y(r_text)+rectangle_get_h(r_text)-30-25*i);
......
947 949
while (good) {
948 950
    /* Get a request message. */
949 951
    if((r = get_interrupts_vector(&int_vector))) return r;
950
    for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) {
952
    uint32_t n = 1;
953
    for (uint8_t i = 0; i < 32; i++, n <<= 1) {
951 954
        if (int_vector & n) {
952 955
            interrupt_handler(i);
953 956
            switch (i) {
......
960 963
                text_draw(t_size);
961 964

  
962 965
                rectangle_draw(r_text);
963
                for(size_t i = 0; i < CHAT_MAX_NUM; ++i) text_draw(t_text[i]);
966
                for(size_t j = 0; j < CHAT_MAX_NUM; ++j) text_draw(t_text[j]);
964 967

  
965 968
                sprite_draw(sp_crosshair);
966 969
                graph_draw();
967 970
                break;
968 971
                case KBC_IRQ:
969
                if      (scancode[0] == ESC_BREAK_CODE) good = false;
970
                else if (scancode[0] == ENTER_MAKE_CODE) {
972
                if      (keyboard_get_scancode()[0] == ESC_BREAK_CODE) good = false;
973
                else if (keyboard_get_scancode()[0] == ENTER_MAKE_CODE) {
971 974
                    hltp_send_string(buffer);
972 975
                    char buffer2[CHAT_MAX_SIZE+3] = "> ";
973 976
                    strncat(buffer2, buffer, strlen(buffer));
974
                    for(size_t i = CHAT_MAX_NUM-1; i; --i)
975
                    text_set_string(t_text[i], text_get_string(t_text[i-1]));
977
                    for(size_t j = CHAT_MAX_NUM-1; j; --j) text_set_string(t_text[i], text_get_string(t_text[i-1]));
976 978
                    text_set_string(t_text[0], buffer2);
977
                    for(size_t i = 0; i < CHAT_MAX_NUM; ++i){
978
                        if(text_get_string(t_text[i])[0] == '>'){
979
                            text_set_pos(t_text[i], rectangle_get_x(r_text)+50, text_get_y(t_text[i]));
980
                            text_set_halign(t_text[i], text_halign_left);
979
                    for(size_t j = 0; j < CHAT_MAX_NUM; ++j){
980
                        if(text_get_string(t_text[j])[0] == '>'){
981
                            text_set_pos(t_text[j], rectangle_get_x(r_text)+50, text_get_y(t_text[j]));
982
                            text_set_halign(t_text[j], text_halign_left);
981 983
                        }else{
982
                            text_set_pos(t_text[i], rectangle_get_x(r_text)+rectangle_get_w(r_text)-50, text_get_y(t_text[i]));
983
                            text_set_halign(t_text[i], text_halign_right);
984
                            text_set_pos(t_text[j], rectangle_get_x(r_text)+rectangle_get_w(r_text)-50, text_get_y(t_text[j]));
985
                            text_set_halign(t_text[j], text_halign_right);
984 986
                        }
985 987
                    }
986 988
                    buffer[0] = '\0';
987
                } else if(scancode[0] == BACKSPACE_MAKE_CODE){
989
                } else if(keyboard_get_scancode()[0] == BACKSPACE_MAKE_CODE){
988 990
                    buffer[strlen(buffer)-1] = '\0';
989 991
                } else {
990
                    char c = map_makecode(scancode[0]);
992
                    char c = map_makecode(keyboard_get_scancode()[0]);
991 993
                    if (c == ERROR_CODE) break;
992 994
                    if(strlen(buffer) < CHAT_MAX_SIZE) strncat(buffer, &c, 1);
993 995
                    else                               printf("Char limit exceeded\n");
proj/src/proj_func.c
96 96
}
97 97

  
98 98
void update_key_presses(void) {
99
    if (sz == 1) {
100
        switch(scancode[0]) {
99
    if (keyboard_get_size() == 1) {
100
        switch(keyboard_get_scancode()[0]) {
101 101
        case W_MAKE_CODE        : key_presses.w_pressed     = 1;        break;
102 102
        case W_BREAK_CODE       : key_presses.w_pressed     = 0;        break;
103 103
        case A_MAKE_CODE        : key_presses.a_pressed     = 1;        break;
......
154 154
    list_node_t *it = list_begin(shooter_list);
155 155
    while(it != list_end(shooter_list)){
156 156
        gunner_t *g = *(gunner_t**)list_node_val(it);
157
        if(gunner_get_type(g) & gunner_follow){
158
            float theta = 0.0;
157
        if(gunner_get_type(g) & GUNNER_FOLLOW){
158
            double theta = 0.0;
159 159
            map_where_to_follow(map, gunner_get_x(g), gunner_get_y(g), &theta);
160
            float c = fm_cos(theta), s = fm_sin(theta);
161
            float dx = ZOMBIE_SPEED*c, dy = -ZOMBIE_SPEED*s;
160
            double c = fm_cos(theta), s = fm_sin(theta);
161
            double dx = ZOMBIE_SPEED*c, dy = -ZOMBIE_SPEED*s;
162 162
            double x = gunner_get_x(g);
163 163
            double y = gunner_get_y(g);
164 164
            gunner_set_pos(g, x+dx, y+dy);
......
234 234
    list_node_t *it1 = list_begin(shooter_list);
235 235
    while(it1 != list_end(shooter_list)){
236 236
        gunner_t *s1 = *list_node_val(it1);
237
        if(!(gunner_get_type(s1) & gunner_melee)){ it1 = list_node_next(it1); continue; }
237
        if(!(gunner_get_type(s1) & GUNNER_MELEE)){ it1 = list_node_next(it1); continue; }
238 238
        list_node_t *it2 = list_begin(shooter_list);
239 239
        while(it2 != list_end(shooter_list)){
240 240
            gunner_t *s2 = *list_node_val(it2);
......
294 294
    last_minus = key_presses.minus_pressed;
295 295
}
296 296

  
297
static int32_t mouse_x = 0, mouse_y = 0;
297
static int16_t mouse_x = 0, mouse_y = 0;
298 298

  
299 299
void (update_mouse)(struct packet *p) {
300 300
    mouse_x = max(0, mouse_x + p->delta_x);
......
310 310
    return &key_presses;
311 311
}
312 312

  
313
int32_t* get_mouse_X(void) { return &mouse_x; }
313
int16_t* get_mouse_X(void) { return &mouse_x; }
314 314

  
315
int32_t* get_mouse_Y(void) { return &mouse_y; }
315
int16_t* get_mouse_Y(void) { return &mouse_y; }
316 316

  
317 317
double get_mouse_angle(gunner_t *p) {
318 318
    return atan2(gunner_get_y_screen(p) - mouse_y, mouse_x - gunner_get_x_screen(p));

Also available in: Unified diff