Project

General

Profile

Statistics
| Revision:

root / proj / src / proj.c @ 184

History | View | Annotate | Download (6.38 KB)

1 144 up20180655
#include <lcom/lcf.h>
2
#include <lcom/proj.h>
3
#include <lcom/liblm.h>
4
5 149 up20180655
#include "proj_macros.h"
6 179 up20180642
#include "proj_func.h"
7 147 up20180655
8 149 up20180655
#include "kbc.h"
9
#include "timer.h"
10
#include "keyboard.h"
11 150 up20180655
#include "mouse.h"
12 153 up20180655
#include "interrupts_func.h"
13 149 up20180655
14 179 up20180642
#include "graph.h"
15
#include "sprite.h"
16
#include "rectangle.h"
17 182 up20180642
#include "font.h"
18 168 up20180642
19 183 up20180642
#ifdef DIOGO
20
    #include "shooter.h"
21
#endif
22
23 171 up20180655
#ifdef TELMO
24
    #include "crosshair.h"
25 184 up20180655
    #include "shooter.h"
26 171 up20180655
#endif
27 157 up20180642
28 144 up20180655
int main(int argc, char* argv[]) {
29
30
    lcf_set_language("EN-US");
31
32
    //lcf_trace_calls("/home/lcom/labs/proj/trace.txt");
33
34
    //lcf_log_output("/home/lcom/labs/proj/output.txt");
35
36
    if (lcf_start(argc, argv)) return 1;
37
38
    lcf_cleanup();
39
40
    return 0;
41
}
42 147 up20180655
43 149 up20180655
int(proj_main_loop)(int argc, char *argv[]) {
44 170 up20180642
45
    int r;
46
47
    /// subscribe interrupts
48
    if (subscribe_all()) { return 1; }
49
50
    /// initialize graphics
51 166 up20180642
    if(graph_init(GRAPH_MODE)){
52
        printf("%s: failed to initalize graphics.\n", __func__);
53
        if (cleanup()) printf("%s: failed to cleanup.\n", __func__);
54 152 up20180642
        return 1;
55
    }
56
57 159 up20180642
    #ifdef DIOGO
58 174 up20180642
        //printf("%d\n", 1000000-(int)(1000000*fm_sin(0.5*M_PI)));
59
        //printf("%d\n", (int)(1000000*fm_cos(0.5*M_PI)));
60
        /*
61 183 up20180642
        rectangle_t *rect = rectangle_ctor(0,0,graph_get_XRes(), graph_get_YRes());
62
        rectangle_set_fill_color(rect, WHITE);
63

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

93
        graph_draw();
94
        */
95 182 up20180642
96 183 up20180642
        font_t      *fnt  = font_ctor("/home/lcom/labs/proj/font/xpm2");
97 182 up20180642
98
99 183 up20180642
        rectangle_t *rect = rectangle_ctor(100,100,100, 100);
100
        rectangle_set_fill_color(rect, WHITE);
101
        rectangle_draw(rect);
102
        rectangle_dtor(rect);
103
104
        text_t      *txt  = text_ctor(fnt, "Hello world!");
105
        text_set_color(txt, 0x00FF00);
106
        text_set_pos(txt, 100, 100);
107
        text_draw(txt);
108
        text_dtor(txt);
109
110
        graph_draw();
111
112
        font_dtor(fnt);
113
114
        tickdelay(micros_to_ticks(1000000));
115
116 159 up20180642
    #endif
117 152 up20180642
118 171 up20180655
    #ifdef TELMO
119 174 up20180642
        sprite_t *crosshair = get_crosshair();
120 184 up20180655
        sprite_t *shooter1 = get_shooter();
121
        sprite_set_pos(shooter1, 100, 100);
122 174 up20180642
        graph_clear_screen();
123
        sprite_draw(crosshair);
124 184 up20180655
        sprite_draw(shooter1);
125 174 up20180642
        graph_draw();
126 171 up20180655
    #endif
127
128 149 up20180655
    /// loop stuff
129 170 up20180642
    int ipc_status;
130 149 up20180655
    message msg;
131 147 up20180655
    int good = 1;
132 168 up20180642
133 183 up20180642
    #ifdef DIOGO
134
        good = 0;
135
    #endif
136
137 147 up20180655
    while (good) {
138
        /* Get a request message. */
139
        if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) {
140
            printf("driver_receive failed with %d", r);
141
            continue;
142
        }
143
        if (is_ipc_notify(ipc_status)) { /* received notification */
144
            switch (_ENDPOINT_P(msg.m_source)) {
145
                case HARDWARE: /* hardware interrupt notification */
146 153 up20180655
                    for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) {
147
                        if (msg.m_notify.interrupts & n) {
148
                            interrupt_handler(i);
149 167 up20180655
                            if ((scancode[0]) == ESC_BREAK_CODE) good = 0;
150 171 up20180655
                            #ifdef TELMO
151 184 up20180655
                            update_movement(shooter1);
152
                            printf("POS: %d %d\n", sprite_get_x(shooter1), sprite_get_y(shooter1));
153 171 up20180655
                            if (counter_mouse_ih >= 3) {
154
                                struct packet pp = mouse_parse_packet(packet_mouse_ih);
155
                                update_mouse_position(&pp);
156 173 up20180655
                                printf("X: %d | Y: %d | XRES: %d | YRES: %d\n", get_mouse_X(), get_mouse_Y(), graph_get_XRes(), graph_get_YRes());
157 184 up20180655
                                counter_mouse_ih = 0;
158
                            }
159
160
                            sprite_set_pos(crosshair, get_mouse_X(), get_mouse_Y());
161
                            double angle = get_mouse_angle(shooter1);
162
                            sprite_set_angle(shooter1, angle);
163 171 up20180655
                                graph_clear_screen();
164
                                sprite_draw(crosshair);
165 184 up20180655
                                sprite_draw(shooter1);
166 171 up20180655
                                graph_draw();
167
                            #endif
168 153 up20180655
                        }
169 147 up20180655
                    }
170 167 up20180655
171 147 up20180655
                    break;
172
                default:
173
                    break; /* no other notifications expected: do nothing */
174
            }
175
        } else { /* received standart message, not a notification */
176
            /* no standart message expected: do nothing */
177
        }
178 174 up20180642
        #ifdef TELMO
179
            switch (get_hor_movement()) {
180
                case LEFT:
181
                    printf("GOING LEFT.\n");
182
                    break;
183
                case RIGHT:
184
                    printf("GOING RIGHT.\n");
185
                    break;
186
            }
187
            switch (get_ver_movement()) {
188
                case UP:
189
                    printf("GOING UP.\n");
190
                    break;
191
                case DOWN:
192
                    printf("GOING DOWN.\n");
193
                    break;
194
            }
195
        #endif
196 147 up20180655
    }
197 149 up20180655
198 153 up20180655
    // Unsubscribe interrupts
199 155 up20180655
    if (unsubscribe_all()) {
200
        if (cleanup())
201
            printf("%s: failed to cleanup.\n", __func__);
202 152 up20180642
        return 1;
203
    }
204
205 155 up20180655
206
    if (cleanup()) {
207
        printf("%s: failed to cleanup.\n", __func__);
208 152 up20180642
        return 1;
209
    }
210
211 149 up20180655
    return 0;
212 147 up20180655
}