Project

General

Profile

Revision 335

more docs

View differences:

proj/libs/graph/src/font.c
188 188
        uint16_t W = 0, H = 0; {
189 189
            for(size_t i = 0; i < len; ++i){
190 190
                const glyph_t *g = p->fnt->glyphs[(size_t)p->txt[i]];
191
                if(g != NULL){ W += g->w; H = umax16(H, g->h); }
191
                if(g != NULL){ W += g->w; H = max_u16(H, g->h); }
192 192
            }
193 193
        }
194 194
        uint8_t *alp_buf = malloc(W*H);
proj/libs/graph/src/graph.c
333 333
void (sprite_set_pos)   (sprite_t *p, int16_t x , int16_t y ){ p->x = x; p->y = y; }
334 334
void (sprite_set_angle) (sprite_t *p, double angle          ){ p->theta = angle; p->c = fm_cos(p->theta); p->s = fm_sin(p->theta); }
335 335
void (sprite_set_scale) (sprite_t *p, double scale          ){
336
    if(deq(p->scale, scale)) return;
336
    if(eq_d(p->scale, scale)) return;
337 337
    p->scale = scale;
338 338

  
339 339
    p->su0 = (int16_t)(p->bsp->u0*p->scale);
......
385 385
        sprite_sbuf2src(p, 0          , 0          , &x, &y);
386 386
        xmin = x; xmax = x; ymin = y; ymax = y;
387 387
        sprite_sbuf2src(p, (int16_t)sw, 0          , &x, &y);
388
        xmin = min16(x, xmin); xmax = max16(x, xmax); ymin = min16(y, ymin); ymax = max16(y, ymax);
388
        xmin = min_16(x, xmin); xmax = max_16(x, xmax); ymin = min_16(y, ymin); ymax = max_16(y, ymax);
389 389
        sprite_sbuf2src(p, 0          , (int16_t)sh, &x, &y);
390
        xmin = min16(x, xmin); xmax = max16(x, xmax); ymin = min16(y, ymin); ymax = max16(y, ymax);
390
        xmin = min_16(x, xmin); xmax = max_16(x, xmax); ymin = min_16(y, ymin); ymax = max_16(y, ymax);
391 391
        sprite_sbuf2src(p, (int16_t)sw, (int16_t)sh, &x, &y);
392
        xmin = min16(x, xmin); xmax = max16(x, xmax); ymin = min16(y, ymin); ymax = max16(y, ymax);
393
        xmin = max16(xmin-2, 0); xmax = min16(xmax+2, (int16_t)graph_get_XRes());
394
        ymin = max16(ymin-2, 0); ymax = min16(ymax+2, (int16_t)graph_get_YRes());
392
        xmin = min_16(x, xmin); xmax = max_16(x, xmax); ymin = min_16(y, ymin); ymax = max_16(y, ymax);
393
        xmin = max_16(xmin-2, 0); xmax = min_16(xmax+2, (int16_t)graph_get_XRes());
394
        ymin = max_16(ymin-2, 0); ymax = min_16(ymax+2, (int16_t)graph_get_YRes());
395 395
    }
396 396
    const uint16_t bytes_pixel = 3/*graph_get_bytes_pixel()*/;
397 397
    for(int16_t u, v, y = ymin; y < ymax; ++y){
proj/libs/graph/src/rectangle.c
51 51

  
52 52
static void (rectangle_draw_hline)(int16_t x, int16_t y, int16_t l, uint32_t color){
53 53
    if(l < 0){ rectangle_draw_hline(x+l, y, -l, color); return; }
54
    for(int16_t x_ = max16(0,x); x_ < min16(x+l,(int16_t)graph_get_XRes()); ++x_){
54
    for(int16_t x_ = max_16(0,x); x_ < min_16(x+l,(int16_t)graph_get_XRes()); ++x_){
55 55
        graph_set_pixel((uint16_t)x_, (uint16_t)y, color);
56 56
    }
57 57
}
58 58
static void (rectangle_draw_vline)(int16_t x, int16_t y, int16_t l, uint32_t color){
59 59
    if(l < 0){ rectangle_draw_vline(x, y+l, -l, color); return; }
60
    for(int16_t y_ = max16(0,y); y_ < min16(y+l,(int16_t)graph_get_YRes()); ++y_){
60
    for(int16_t y_ = max_16(0,y); y_ < min_16(y+l,(int16_t)graph_get_YRes()); ++y_){
61 61
        graph_set_pixel((uint16_t)x, (uint16_t)y_, color);
62 62
    }
63 63
}
......
65 65
void (rectangle_draw)(const rectangle_t *p){
66 66
    /// fill
67 67
    if(p->fill_alpha > ALPHA_THRESHOLD)
68
        for(int16_t y = max16(p->y,0); y < min16(p->y+p->h, (int16_t)graph_get_YRes()); ++y)
68
        for(int16_t y = max_16(p->y,0); y < min_16(p->y+p->h, (int16_t)graph_get_YRes()); ++y)
69 69
            rectangle_draw_hline(p->x, y, (int16_t)p->w, p->fill_color);
70 70
    /// border
71 71
    int16_t step = (p->outline_width > 0 ? 1 : -1);
proj/libs/uart/include/uart.h
8 8
 * @{
9 9
 */
10 10

  
11
/// @brief COM1 base address
11 12
#define COM1_ADDR           0x3F8
13
/// @brief COM2 base address
12 14
#define COM2_ADDR           0x2F8
15
/// @brief COM1 IRQ line
13 16
#define COM1_IRQ            4
17
/// @brief COM2 IRQ line
14 18
#define COM2_IRQ            3
19
/// @brief COM1 Vector (???)
15 20
#define COM1_VECTOR         0x0C
21
/// @brief COM2 Vector (???)
16 22
#define COM2_VECTOR         0x0B
17 23

  
24
/**
25
 * @brief Possible parity schemes for UART.
26
 */
18 27
typedef enum {
19 28
    uart_parity_none = 0x0,
20 29
    uart_parity_odd  = 0x1,
......
23 32
    uart_parity_par0 = 0x7
24 33
} uart_parity;
25 34

  
35
/**
36
 * @brief UART configuration
37
 */
26 38
typedef struct {
39
    /// @brief  Base address of the serial port this configuration was read from
27 40
    int     base_addr               ;
41
    /// @brief  LCR (Line Control Register)
28 42
    uint8_t lcr                     ;
43
    /// @brief DLL (Divisor Latch Least significant byte)
29 44
    uint8_t dll                     ;
45
    /// @brief DLL (Divisor Latch Most significant byte)
30 46
    uint8_t dlm                     ;
47
    /// @brief Number of bits per char
31 48
    uint8_t bits_per_char           ;
49
    /// @brief Number of stop bits
32 50
    uint8_t stop_bits               ;
51
    /// @brief Parity scheme
33 52
    uart_parity parity              ;
53
    /// @brief Break control (???)
34 54
    uint8_t break_control         :1;
55
    /// @brief Divisor Latch Access Bit (1 if DLL, DLM can be accessed)
35 56
    uint8_t dlab                  :1;
57
    ///  @brief Divisor latch
36 58
    uint16_t divisor_latch          ;
59
    /// @brief IER (Interrupt Enable Register)
37 60
    uint8_t ier                     ;
61
    /// @brief  Receiver data interrupt enabled if 1
38 62
    uint8_t received_data_int     :1;
63
    /// @brief  Transmitter empty interrupt enabled if 1
39 64
    uint8_t transmitter_empty_int :1;
65
    /// @brief  Receiver line status register (LSR) change interrupt enabled if 1
40 66
    uint8_t receiver_line_stat_int:1;
67
    /// @brief  Modem status interrupt enabled if 1
41 68
    uint8_t modem_stat_int        :1;
42 69
} uart_config;
43 70

  
proj/libs/utils/include/utils.h
51 51
 * @param b     Second value
52 52
 * @return  The minimum of the two values
53 53
 */
54
int16_t min16(int16_t a, int16_t b);
55
uint16_t umin16(uint16_t a, uint16_t b);
56
int32_t min32(int32_t a, int32_t b);
57
double  dmin (double  a, double  b);
54
int16_t min_16(int16_t a, int16_t b);
55
/// @overload
56
uint16_t min_u16(uint16_t a, uint16_t b);
57
/// @overload
58
int32_t min_32(int32_t a, int32_t b);
59
/// @overload
60
double  min_d(double  a, double  b);
58 61

  
59 62
/**
60 63
 * @brief Gets the maximum value out of two values.
......
62 65
 * @param b     Second value
63 66
 * @return  The maximum of the two values
64 67
 */
65
int16_t max16(int16_t a, int16_t b);
66
uint16_t umax16(uint16_t a, uint16_t b);
67
int32_t max32(int32_t a, int32_t b);
68
double  dmax (double  a, double  b);
68
int16_t max_16(int16_t a, int16_t b);
69
/// @overload
70
uint16_t max_u16(uint16_t a, uint16_t b);
71
/// @overload
72
int32_t max_32(int32_t a, int32_t b);
73
/// @overload
74
double  max_d(double  a, double  b);
69 75

  
70 76
/**
71 77
 * @brief Get the absolute value of a double.
72 78
 * @param   a   Argument
73 79
 * @return      Absolute value of a
74 80
 */
75
double dabs(double a);
81
double abs_d(double a);
76 82

  
77 83
/**
78 84
 * @brief Compare if two doubles are approximately equal (within 1e-10).
......
80 86
 * @param   b   Second value
81 87
 * @return      true if the two numbers are approximately equal, false otherwise
82 88
 */
83
int deq(double a, double b);
89
int eq_d(double a, double b);
84 90

  
85 91
/**
86 92
 * @}
proj/libs/utils/src/utils.c
31 31
    return SUCCESS;
32 32
}
33 33

  
34
int16_t min16(int16_t a, int16_t b){ return (b < a ? b : a); }
35
uint16_t umin16(uint16_t a, uint16_t b){ return (b < a ? b : a); }
34
int16_t min_16(int16_t a, int16_t b){ return (b < a ? b : a); }
35
uint16_t umin_16(uint16_t a, uint16_t b){ return (b < a ? b : a); }
36 36
int32_t min32(int32_t a, int32_t b){ return (b < a ? b : a); }
37 37
double  dmin (double  a, double  b){ return (b < a ? b : a); }
38 38

  
39
int16_t max16(int16_t a, int16_t b){ return (a < b ? b : a); }
40
uint16_t umax16(uint16_t a, uint16_t b){ return (a < b ? b : a); }
39
int16_t max_16(int16_t a, int16_t b){ return (a < b ? b : a); }
40
uint16_t max_u16(uint16_t a, uint16_t b){ return (a < b ? b : a); }
41 41
int32_t max32(int32_t a, int32_t b){ return (a < b ? b : a); }
42
double  dmax (double  a, double  b){ return (a < b ? b : a); }
42
double  max_d (double  a, double  b){ return (a < b ? b : a); }
43 43

  
44
double dabs(double a)          { return (a < 0 ? -a: a); }
44
double abs_d(double a)          { return (a < 0 ? -a: a); }
45 45

  
46
int deq(double a, double b){ return (dabs(a-b) < 1e-10 ? true : false); }
46
int eq_d(double a, double b){ return (abs_d(a-b) < 1e-10 ? true : false); }
proj/src/ent.c
298 298
    else return false;
299 299
}
300 300
int (map_collides_gunner)(const map_t *p, const gunner_t *shooter) {
301
    double radius = dmax(sprite_get_w(shooter->dude), sprite_get_h(shooter->dude))/2.0;
301
    double radius = max_d(sprite_get_w(shooter->dude), sprite_get_h(shooter->dude))/2.0;
302 302
    return map_collides_gunner_pos(p, gunner_get_x(shooter), gunner_get_y(shooter), radius);
303 303
}
304 304
int (map_make_dijkstra)(map_t *p, double x_, double y_){
......
347 347
}
348 348

  
349 349
int (map_collides_bullet)(const map_t *p, const bullet_t *bull){
350
    double radius = dmax(sprite_get_w(bull->b), sprite_get_h(bull->b))/2.0;
350
    double radius = max_d(sprite_get_w(bull->b), sprite_get_h(bull->b))/2.0;
351 351
    double bullet_x = bullet_get_x(bull);
352 352
    double bullet_y = bullet_get_y(bull);
353 353
    for (double x = -radius; x < radius; x += 1){
......
361 361
int (gunner_collides_bullet)(const gunner_t *shooter, const bullet_t *bull){
362 362
    if(bull->shooter == shooter) return false;
363 363

  
364
    double shooter_radius = dmax(sprite_get_w(shooter->dude), sprite_get_h(shooter->dude))/2.0;
364
    double shooter_radius = max_d(sprite_get_w(shooter->dude), sprite_get_h(shooter->dude))/2.0;
365 365
    double shooter_x = gunner_get_x(shooter);
366 366
    double shooter_y = gunner_get_y(shooter);
367 367

  
368
    double bullet_radius = dmax(sprite_get_w(bull->b), sprite_get_h(bull->b))/2.0;
368
    double bullet_radius = max_d(sprite_get_w(bull->b), sprite_get_h(bull->b))/2.0;
369 369
    double bullet_x = bullet_get_x(bull);
370 370
    double bullet_y = bullet_get_y(bull);
371 371

  
......
389 389

  
390 390
int (gunner_collides_gunner)(const gunner_t *shooter1, const gunner_t *shooter2) {
391 391
    if (shooter1 == shooter2) return false;
392
    double shooter1_radius = dmax(sprite_get_w(shooter1->dude), sprite_get_h(shooter1->dude))/2.0;
393
    double shooter2_radius = dmax(sprite_get_w(shooter2->dude), sprite_get_h(shooter2->dude))/2.0;
392
    double shooter1_radius = max_d(sprite_get_w(shooter1->dude), sprite_get_h(shooter1->dude))/2.0;
393
    double shooter2_radius = max_d(sprite_get_w(shooter2->dude), sprite_get_h(shooter2->dude))/2.0;
394 394
    double distance = distance_gunners(shooter1, shooter2);
395 395
    return distance <= shooter1_radius+shooter2_radius;
396 396
}
proj/src/proj_func.c
297 297
static int16_t mouse_x = 0, mouse_y = 0;
298 298

  
299 299
void (update_mouse)(struct packet *p) {
300
    mouse_x = max16(0, mouse_x + p->delta_x);
301
    mouse_x = min16(mouse_x, (int16_t)graph_get_XRes() - 1);
300
    mouse_x = max_16(0, mouse_x + p->delta_x);
301
    mouse_x = min_16(mouse_x, (int16_t)graph_get_XRes() - 1);
302 302

  
303
    mouse_y = max16(0, mouse_y - p->delta_y);
304
    mouse_y = min16(mouse_y, (int16_t)graph_get_YRes() - 1);
303
    mouse_y = max_16(0, mouse_y - p->delta_y);
304
    mouse_y = min_16(mouse_y, (int16_t)graph_get_YRes() - 1);
305 305

  
306 306
    key_presses.lb_pressed = p->lb;
307 307
}

Also available in: Unified diff