Project

General

Profile

Statistics
| Revision:

root / proj / src / proj.c @ 185

History | View | Annotate | Download (6.4 KB)

1
#include <lcom/lcf.h>
2
#include <lcom/proj.h>
3
#include <lcom/liblm.h>
4
#include <math.h>
5

    
6
#include "proj_macros.h"
7
#include "proj_func.h"
8

    
9
#include "kbc.h"
10
#include "timer.h"
11
#include "keyboard.h"
12
#include "mouse.h"
13
#include "interrupts_func.h"
14

    
15
#include "graph.h"
16
#include "sprite.h"
17
#include "rectangle.h"
18
#include "font.h"
19

    
20
#ifdef DIOGO
21
    #include "shooter.h"
22
#endif
23

    
24
#ifdef TELMO
25
    #include "crosshair.h"
26
    #include "shooter.h"
27
#endif
28

    
29
int main(int argc, char* argv[]) {
30

    
31
    lcf_set_language("EN-US");
32

    
33
    //lcf_trace_calls("/home/lcom/labs/proj/trace.txt");
34

    
35
    //lcf_log_output("/home/lcom/labs/proj/output.txt");
36

    
37
    if (lcf_start(argc, argv)) return 1;
38

    
39
    lcf_cleanup();
40

    
41
    return 0;
42
}
43

    
44
int(proj_main_loop)(int argc, char *argv[]) {
45

    
46
    int r;
47

    
48
    /// subscribe interrupts
49
    if (subscribe_all()) { return 1; }
50

    
51
    /// initialize graphics
52
    if(graph_init(GRAPH_MODE)){
53
        printf("%s: failed to initalize graphics.\n", __func__);
54
        if (cleanup()) printf("%s: failed to cleanup.\n", __func__);
55
        return 1;
56
    }
57

    
58
    #ifdef DIOGO
59
        //printf("%d\n", 1000000-(int)(1000000*fm_sin(0.5*M_PI)));
60
        //printf("%d\n", (int)(1000000*fm_cos(0.5*M_PI)));
61
        /*
62
        rectangle_t *rect = rectangle_ctor(0,0,graph_get_XRes(), graph_get_YRes());
63
        rectangle_set_fill_color(rect, WHITE);
64

65
        clock_t t = clock();
66
        sprite_t *shooter1 = get_shooter(); sprite_set_pos(shooter1, 100, 100);
67
        for(double angle = 0; angle <= 6.283185; angle += 0.006283185){
68
             sprite_set_angle(shooter1, angle);
69
             graph_clear_screen();
70
             rectangle_draw(rect);
71
             sprite_draw(shooter1);
72
             graph_draw();
73
        }
74
        t = clock() - t;
75
        printf("Time taken: %d/%d \n", t, CLOCKS_PER_SEC);
76
        sprite_dtor(shooter1);
77
        */
78
        /*
79
        rectangle_t *rect = rectangle_ctor(100, 100, 100, 100);
80
        rectangle_set_fill_color   (rect, 0x0000FF);
81
        rectangle_set_outline_color(rect, 0xFF0000);
82
        rectangle_set_outline_width(rect, 0);
83
        rectangle_draw(rect);
84
        rectangle_set_pos(rect, 205, 100);
85
        rectangle_set_outline_width(rect, 1);
86
        rectangle_draw(rect);
87
        rectangle_set_pos(rect, 310, 100);
88
        rectangle_set_outline_width(rect, 2);
89
        rectangle_draw(rect);
90
        rectangle_set_pos(rect, 415, 100);
91
        rectangle_set_outline_width(rect, 3);
92
        rectangle_draw(rect);
93

94
        graph_draw();
95
        */
96

    
97
        font_t      *fnt  = font_ctor("/home/lcom/labs/proj/font/xpm2");
98

    
99

    
100
        rectangle_t *rect = rectangle_ctor(100,100,100, 100);
101
        rectangle_set_fill_color(rect, WHITE);
102
        rectangle_draw(rect);
103
        rectangle_dtor(rect);
104

    
105
        text_t      *txt  = text_ctor(fnt, "Hello world!");
106
        text_set_color(txt, 0x00FF00);
107
        text_set_pos(txt, 100, 100);
108
        text_draw(txt);
109
        text_dtor(txt);
110

    
111
        graph_draw();
112

    
113
        font_dtor(fnt);
114

    
115
        tickdelay(micros_to_ticks(1000000));
116

    
117
    #endif
118

    
119
    #ifdef TELMO
120
        sprite_t *crosshair = get_crosshair();
121
        sprite_t *shooter1 = get_shooter();
122
        sprite_set_pos(shooter1, 100, 100);
123
        graph_clear_screen();
124
        sprite_draw(crosshair);
125
        sprite_draw(shooter1);
126
        graph_draw();
127
    #endif
128

    
129
    /// loop stuff
130
    int ipc_status;
131
    message msg;
132
    int good = 1;
133

    
134
    #ifdef DIOGO
135
        good = 0;
136
    #endif
137

    
138
    while (good) {
139
        /* Get a request message. */
140
        if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) {
141
            printf("driver_receive failed with %d", r);
142
            continue;
143
        }
144
        if (is_ipc_notify(ipc_status)) { /* received notification */
145
            switch (_ENDPOINT_P(msg.m_source)) {
146
                case HARDWARE: /* hardware interrupt notification */
147
                    for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) {
148
                        if (msg.m_notify.interrupts & n) {
149
                            interrupt_handler(i);
150
                            if ((scancode[0]) == ESC_BREAK_CODE) good = 0;
151
                            #ifdef TELMO
152
                            update_movement(shooter1);
153
                            printf("POS: %d %d\n", sprite_get_x(shooter1), sprite_get_y(shooter1));
154
                            if (counter_mouse_ih >= 3) {
155
                                struct packet pp = mouse_parse_packet(packet_mouse_ih);
156
                                update_mouse_position(&pp);
157
                                printf("X: %d | Y: %d | XRES: %d | YRES: %d\n", get_mouse_X(), get_mouse_Y(), graph_get_XRes(), graph_get_YRes());
158
                                counter_mouse_ih = 0;
159
                            }
160

    
161
                            sprite_set_pos(crosshair, get_mouse_X(), get_mouse_Y());
162
                            double angle = get_mouse_angle(shooter1);
163
                            sprite_set_angle(shooter1, angle - M_PI_2);
164
                                graph_clear_screen();
165
                                sprite_draw(crosshair);
166
                                sprite_draw(shooter1);
167
                                graph_draw();
168
                            #endif
169
                        }
170
                    }
171

    
172
                    break;
173
                default:
174
                    break; /* no other notifications expected: do nothing */
175
            }
176
        } else { /* received standart message, not a notification */
177
            /* no standart message expected: do nothing */
178
        }
179
        #ifdef TELMO
180
            switch (get_hor_movement()) {
181
                case LEFT:
182
                    printf("GOING LEFT.\n");
183
                    break;
184
                case RIGHT:
185
                    printf("GOING RIGHT.\n");
186
                    break;
187
            }
188
            switch (get_ver_movement()) {
189
                case UP:
190
                    printf("GOING UP.\n");
191
                    break;
192
                case DOWN:
193
                    printf("GOING DOWN.\n");
194
                    break;
195
            }
196
        #endif
197
    }
198

    
199
    // Unsubscribe interrupts
200
    if (unsubscribe_all()) {
201
        if (cleanup())
202
            printf("%s: failed to cleanup.\n", __func__);
203
        return 1;
204
    }
205

    
206

    
207
    if (cleanup()) {
208
        printf("%s: failed to cleanup.\n", __func__);
209
        return 1;
210
    }
211

    
212
    return 0;
213
}