Project

General

Profile

Revision 167

some changes

View differences:

proj/TB.mk
2 2

  
3 3
SRCS= proj.c graph.c sprite.c kbc.c keyboard.c mouse.c utils.c timer.c interrupts_func.c proj_func.c
4 4

  
5
CPPFLAGS += -pedantic -I./bmp -I./xpm -D __LCOM_OPTIMIZED_ -D TELMO
5
CPPFLAGS += -pedantic -I./bmp -I./xpm -D TELMO #-D __LCOM_OPTIMIZED_
6 6

  
7 7
DPADD += ${LIBLCF}
8 8
LDADD += -llcf
proj/keyboard.c
6 6
#include "kbc_macros.h"
7 7
#include "utils.h"
8 8
#include "errors.h"
9
#include "proj_func.h"
9 10

  
10 11
int (subscribe_kbc_interrupt)(uint8_t interrupt_bit, int *interrupt_id) {
11 12
    if (interrupt_id == NULL) return NULL_PTR;
......
19 20
int got_error_keyboard = SUCCESS;
20 21

  
21 22
void (kbc_ih)(void) {
22
    if(done) sz = 1;
23
    if(done) { update_movement(); sz = 1; }
23 24
    else     sz++;
24 25
    uint8_t status = 0;
25 26
    got_error_keyboard = SUCCESS;
......
37 38

  
38 39
    scancode[sz-1] = byte;
39 40
    done = !(TWO_BYTE_CODE == byte);
41

  
42

  
40 43
}
41 44

  
42 45
int (keyboard_poll)(uint8_t bytes[], uint8_t *size){
proj/proj.c
87 87
                    for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) {
88 88
                        if (msg.m_notify.interrupts & n) {
89 89
                            interrupt_handler(i);
90
                            if ((scancode[0]) == ESC_BREAK_CODE) good = 0;
90 91
                        }
91 92
                    }
92
                    if (scancode[0] == ESC_BREAK_CODE) good = 0;
93

  
93 94
                    break;
94 95
                default:
95 96
                    break; /* no other notifications expected: do nothing */
......
97 98
        } else { /* received standart message, not a notification */
98 99
            /* no standart message expected: do nothing */
99 100
        }
101

  
102
        switch (get_hor_movement()) {
103
            case LEFT:
104
                printf("GOING LEFT.\n");
105
                break;
106
            case RIGHT:
107
                printf("GOING RIGHT.\n");
108
                break;
109
        }
110
        switch (get_ver_movement()) {
111
            case UP:
112
                printf("GOING UP.\n");
113
                break;
114
            case DOWN:
115
                printf("GOING DOWN.\n");
116
                break;
117
        }
100 118
    }
101 119

  
102 120
    // Unsubscribe interrupts
proj/proj_func.c
1
#include <lcom/lcf.h>
2

  
1 3
#include "proj_func.h"
4

  
2 5
#include "interrupts_func.h"
3 6
#include "graph.h"
7
#include "keyboard.h"
4 8
#include "errors.h"
9
#include "proj_macros.h"
10
#include "utils.h"
5 11

  
6
#include <lcom/lcf.h>
12
#include "kbc_macros.h"
7 13

  
14
#include <math.h>
15

  
8 16
int cleanup(void) {
9 17
    int r = SUCCESS;
10 18
    if ((r = unsubscribe_all()))
......
14 22

  
15 23
    return r;
16 24
}
25

  
26
static int hor_mov = REST, ver_mov = REST;
27

  
28
void update_movement(void) {
29
    static int w_pressed = 0, a_pressed = 0, s_pressed = 0, d_pressed = 0;
30
    if (sz == 1) {
31
        kbd_print_scancode(!(scancode[0] & BREAK_CODE_BIT), 1, scancode);
32
        switch(scancode[0]) {
33
        case W_MAKE_CODE  : w_pressed = 1;      break;
34
        case W_BREAK_CODE : w_pressed = 0;      break;
35
        case A_MAKE_CODE  : a_pressed = 1;      break;
36
        case A_BREAK_CODE : a_pressed = 0;      break;
37
        case S_MAKE_CODE  : s_pressed = 1;      break;
38
        case S_BREAK_CODE : s_pressed = 0;      break;
39
        case D_MAKE_CODE  : d_pressed = 1;      break;
40
        case D_BREAK_CODE : d_pressed = 0;      break;
41
        }
42
    }
43
    ver_mov = s_pressed - w_pressed;
44
    hor_mov = d_pressed - a_pressed;
45
}
46

  
47
double get_mouse_angle(sprite_t *p, int32_t mouse_x, int32_t mouse_y) {
48
    return atan2(sprite_get_y(p) - mouse_y, mouse_x - sprite_get_x(p));
49
}
50

  
51
int get_hor_movement(void) { return hor_mov; }
52

  
53
int get_ver_movement(void) { return ver_mov; }
proj/proj_func.h
1 1
#ifndef PROJ_FUNC_H_INCLUDED
2 2
#define PROJ_FUNC_H_INCLUDED
3 3

  
4
#include "sprite.h"
5

  
4 6
/**
5 7
 * @brief Cleans up all memory, unsubscribes interrupts.
6 8
 * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
......
8 10
 */
9 11
int cleanup(void);
10 12

  
13
/**
14
 * @brief Updates movement variables.
15
 */
16
void update_movement(void);
17

  
18
/**
19
 * @brief
20
 * @param
21
 * @param
22
 * @param
23
 * @return Angle
24
 */
25
double get_mouse_angle(sprite_t *p, int32_t mouse_x, int32_t mouse_y);
26

  
27
/**
28
 * @brief Get horizontal movement direction.
29
 * @return Horizontal movement direction (-1 -> heading LEFT; 0 -> not moving horizontally; 1 -> heading RIGHT)
30
 */
31
int get_hor_movement(void);
32

  
33
/**
34
 * @brief Get vertical movement direction.
35
 * @return Vertical movement direction (-1 -> heading UP; 0 -> not moving vertically; 1 -> heading DOWN)
36
 */
37
int get_ver_movement(void);
38

  
11 39
#endif /* end of include guard: PROJ_FUNC_H_INCLUDED */
proj/proj_macros.h
3 3

  
4 4
// WASD Movement Keys
5 5
#define W_MAKE_CODE     0x11    /** @brief W Make Code */
6
#define W_BREAK_CODE    0x91    /** @brief W Make Code */
6
#define W_BREAK_CODE    0x91    /** @brief W Break Code */
7 7
#define A_MAKE_CODE     0x1E    /** @brief A Make Code */
8
#define A_BREAK_CODE    0x9E    /** @brief A Make Code */
8
#define A_BREAK_CODE    0x9E    /** @brief A Break Code */
9 9
#define S_MAKE_CODE     0x1F    /** @brief S Make Code */
10
#define S_BREAK_CODE    0x9F    /** @brief S Make Code */
10
#define S_BREAK_CODE    0x9F    /** @brief S Break Code */
11 11
#define D_MAKE_CODE     0x20    /** @brief D Make Code */
12
#define D_BREAK_CODE    0xA0    /** @brief D Make Code */
12
#define D_BREAK_CODE    0xA0    /** @brief D Break Code */
13 13

  
14
// Movement Directions
15
#define UP      -1  /** @brief Moving to the top side of screen */
16
#define DOWN    1   /** @brief Moving to the bottom side of screen */
17
#define LEFT    -1  /** @brief Moving to the left side of screen */
18
#define RIGHT   1   /** @brief Moving to the right side of screen */
19
#define REST    0   /** @brief Not moving */
20

  
14 21
// Extra Keys
15 22
#define ESC_MAKE_CODE   0x01    /** @brief ESC Make Code */
16 23
#define ESC_BREAK_CODE  0x81    /** @brief ESC Break Code */
proj/sprite.c
45 45
void (sprite_set_angle) (sprite_t *p, double angle){ p->theta = angle; }
46 46
void (sprite_set_center)(sprite_t *p, int16_t u0, int16_t v0){ p->u0 = u0; p->v0 = v0; }
47 47

  
48
uint16_t (sprite_get_w)(const sprite_t *p){ return p->w; }
49
uint16_t (sprite_get_h)(const sprite_t *p){ return p->h; }
48
int sprite_get_x(const sprite_t *p){ return p->x; }
49
int sprite_get_y(const sprite_t *p){ return p->y; }
50
int sprite_get_w(const sprite_t *p){ return p->w; }
51
int sprite_get_h(const sprite_t *p){ return p->h; }
50 52

  
51 53
void (sprite_src2pic)(const sprite_t *p, int16_t x, int16_t y, int16_t *u, int16_t *v){
52 54
    int16_t dx = x - p->x;
proj/sprite.h
13 13
void (sprite_set_angle) (sprite_t *p, double angle);
14 14
void (sprite_set_center)(sprite_t *p, int16_t u0, int16_t v0);
15 15

  
16
uint16_t (sprite_get_w)(const sprite_t *p);
17
uint16_t (sprite_get_h)(const sprite_t *p);
16
int sprite_get_x(const sprite_t *p);
17
int sprite_get_y(const sprite_t *p);
18
int sprite_get_w(const sprite_t *p);
19
int sprite_get_h(const sprite_t *p);
18 20

  
19 21
void (sprite_draw)(const sprite_t *p);
20 22

  
proj/utils.c
31 31
    return SUCCESS;
32 32
}
33 33

  
34
int16_t min(int16_t a, int16_t b){ return (b < a ? b : a); }
35
int16_t max(int16_t a, int16_t b){ return (a < b ? b : a); }
34
int32_t min(int32_t a, int32_t b){ return (b < a ? b : a); }
35
int32_t max(int32_t a, int32_t b){ return (a < b ? b : a); }
proj/utils.h
39 39
 * @param b     Second value
40 40
 * @return  The minimum of the two values
41 41
 */
42
int16_t min(int16_t a, int16_t b);
42
int32_t min(int32_t a, int32_t b);
43 43

  
44 44
/**
45 45
 * @brief Gets the maximum value out of two values.
......
47 47
 * @param b     Second value
48 48
 * @return  The maximum of the two values
49 49
 */
50
int16_t max(int16_t a, int16_t b);
50
int32_t max(int32_t a, int32_t b);
51 51

  
52 52

  
53 53
#endif //UTILS_H_INCLUDED

Also available in: Unified diff