root / proj / src / proj.c @ 187
History | View | Annotate | Download (6.5 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 |
if (i == 0) { |
153 |
uint32_t refresh_count_value = sys_hz() / REFRESH_RATE; |
154 |
if (no_interrupts % refresh_count_value == 0) { |
155 |
update_movement(shooter1); |
156 |
sprite_set_pos(crosshair, get_mouse_X(), get_mouse_Y()); |
157 |
double angle = get_mouse_angle(shooter1);
|
158 |
sprite_set_angle(shooter1, angle - M_PI_2); |
159 |
graph_clear_screen(); |
160 |
sprite_draw(crosshair); |
161 |
sprite_draw(shooter1); |
162 |
graph_draw(); |
163 |
} |
164 |
} |
165 |
#endif
|
166 |
} |
167 |
} |
168 |
#ifdef TELMO
|
169 |
if (counter_mouse_ih >= 3) { |
170 |
struct packet pp = mouse_parse_packet(packet_mouse_ih);
|
171 |
update_mouse_position(&pp); |
172 |
counter_mouse_ih = 0;
|
173 |
} |
174 |
#endif
|
175 |
|
176 |
break;
|
177 |
default:
|
178 |
break; /* no other notifications expected: do nothing */ |
179 |
} |
180 |
} else { /* received standart message, not a notification */ |
181 |
/* no standart message expected: do nothing */
|
182 |
} |
183 |
#ifdef TELMO
|
184 |
switch (get_hor_movement()) {
|
185 |
case LEFT:
|
186 |
printf("GOING LEFT.\n");
|
187 |
break;
|
188 |
case RIGHT:
|
189 |
printf("GOING RIGHT.\n");
|
190 |
break;
|
191 |
} |
192 |
switch (get_ver_movement()) {
|
193 |
case UP:
|
194 |
printf("GOING UP.\n");
|
195 |
break;
|
196 |
case DOWN:
|
197 |
printf("GOING DOWN.\n");
|
198 |
break;
|
199 |
} |
200 |
#endif
|
201 |
} |
202 |
|
203 |
// Unsubscribe interrupts
|
204 |
if (unsubscribe_all()) {
|
205 |
if (cleanup())
|
206 |
printf("%s: failed to cleanup.\n", __func__);
|
207 |
return 1; |
208 |
} |
209 |
|
210 |
|
211 |
if (cleanup()) {
|
212 |
printf("%s: failed to cleanup.\n", __func__);
|
213 |
return 1; |
214 |
} |
215 |
|
216 |
return 0; |
217 |
} |