root / proj / src / proj.c @ 189
History | View | Annotate | Download (5.91 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 "graph.h" |
14 |
#include "interrupts_func.h" |
15 |
|
16 |
#include "graph.h" |
17 |
#include "sprite.h" |
18 |
#include "rectangle.h" |
19 |
#include "font.h" |
20 |
|
21 |
#ifdef DIOGO
|
22 |
#include "shooter.h" |
23 |
#endif
|
24 |
|
25 |
#ifdef TELMO
|
26 |
#include "crosshair.h" |
27 |
#include "shooter.h" |
28 |
#endif
|
29 |
|
30 |
int main(int argc, char* argv[]) { |
31 |
|
32 |
lcf_set_language("EN-US");
|
33 |
|
34 |
//lcf_trace_calls("/home/lcom/labs/proj/trace.txt");
|
35 |
|
36 |
lcf_log_output("/home/lcom/labs/proj/output.txt");
|
37 |
|
38 |
if (lcf_start(argc, argv)) return 1; |
39 |
|
40 |
lcf_cleanup(); |
41 |
|
42 |
return 0; |
43 |
} |
44 |
|
45 |
int(proj_main_loop)(int argc, char *argv[]) { |
46 |
|
47 |
int r;
|
48 |
|
49 |
/// subscribe interrupts
|
50 |
if (subscribe_all()) { return 1; } |
51 |
|
52 |
/// initialize graphics
|
53 |
if(graph_init(GRAPH_MODE)){
|
54 |
printf("%s: failed to initalize graphics.\n", __func__);
|
55 |
if (cleanup()) printf("%s: failed to cleanup.\n", __func__); |
56 |
return 1; |
57 |
} |
58 |
|
59 |
font_t *consolas = font_ctor("/home/lcom/labs/proj/font/xpm2");
|
60 |
|
61 |
/// Load stuff
|
62 |
{ |
63 |
graph_clear_screen(); |
64 |
text_t *txt = text_ctor(consolas, "Loading...");
|
65 |
text_draw(txt); |
66 |
text_dtor(txt); |
67 |
graph_draw(); |
68 |
} |
69 |
#ifdef DIOGO
|
70 |
graph_clear_screen(); |
71 |
|
72 |
rectangle_t *rect = rectangle_ctor(0,0,400,100); |
73 |
rectangle_set_pos(rect, |
74 |
graph_get_XRes()/2 - rectangle_get_w(rect)/2, |
75 |
graph_get_YRes()*0.25 - rectangle_get_h(rect)/2); |
76 |
rectangle_set_fill_color(rect, BLACK); |
77 |
rectangle_set_outline_width(rect, 2);
|
78 |
rectangle_set_outline_color(rect, WHITE); |
79 |
rectangle_draw(rect); |
80 |
|
81 |
text_t *txt = text_ctor(consolas, "Hello world!");
|
82 |
text_set_color(txt, 0x888888);
|
83 |
|
84 |
text_set_pos(txt, rectangle_get_x(rect)+rectangle_get_w(rect)/2,
|
85 |
rectangle_get_y(rect)+rectangle_get_h(rect)/2);
|
86 |
text_set_valign(txt, text_valign_center); |
87 |
text_set_halign(txt, text_halign_center); |
88 |
text_draw(txt); |
89 |
text_dtor(txt); |
90 |
|
91 |
graph_draw(); |
92 |
rectangle_dtor(rect); |
93 |
|
94 |
tickdelay(micros_to_ticks(1000000));
|
95 |
|
96 |
#endif
|
97 |
|
98 |
#ifdef TELMO
|
99 |
sprite_t *crosshair = get_crosshair(); |
100 |
sprite_t *shooter1 = get_shooter(); |
101 |
sprite_set_pos(shooter1, graph_get_XRes()/2, graph_get_YRes()/2); |
102 |
graph_clear_screen(); |
103 |
sprite_draw(crosshair); |
104 |
sprite_draw(shooter1); |
105 |
graph_draw(); |
106 |
#endif
|
107 |
|
108 |
/// loop stuff
|
109 |
int ipc_status;
|
110 |
message msg; |
111 |
int good = 1; |
112 |
|
113 |
#ifdef DIOGO
|
114 |
good = 0;
|
115 |
#endif
|
116 |
|
117 |
while (good) {
|
118 |
/* Get a request message. */
|
119 |
if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) { |
120 |
printf("driver_receive failed with %d", r);
|
121 |
continue;
|
122 |
} |
123 |
if (is_ipc_notify(ipc_status)) { /* received notification */ |
124 |
switch (_ENDPOINT_P(msg.m_source)) {
|
125 |
case HARDWARE: /* hardware interrupt notification */ |
126 |
for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) { |
127 |
if (msg.m_notify.interrupts & n) {
|
128 |
interrupt_handler(i); |
129 |
if ((scancode[0]) == ESC_BREAK_CODE) good = 0; |
130 |
#ifdef TELMO
|
131 |
if (i == 0) { |
132 |
uint32_t refresh_count_value = sys_hz() / REFRESH_RATE; |
133 |
if (no_interrupts % refresh_count_value == 0) { |
134 |
update_movement(shooter1); |
135 |
sprite_set_pos(crosshair, get_mouse_X(), get_mouse_Y()); |
136 |
double angle = get_mouse_angle(shooter1);
|
137 |
sprite_set_angle(shooter1, angle - M_PI_2); |
138 |
graph_clear_screen(); |
139 |
sprite_draw(crosshair); |
140 |
sprite_draw(shooter1); |
141 |
graph_draw(); |
142 |
} |
143 |
} |
144 |
#endif
|
145 |
} |
146 |
} |
147 |
#ifdef TELMO
|
148 |
if (counter_mouse_ih >= 3) { |
149 |
struct packet pp = mouse_parse_packet(packet_mouse_ih);
|
150 |
update_mouse_position(&pp); |
151 |
//printf("X: %d Y: %d\n", get_mouse_X(), get_mouse_Y());
|
152 |
counter_mouse_ih = 0;
|
153 |
} |
154 |
#endif
|
155 |
|
156 |
break;
|
157 |
default:
|
158 |
break; /* no other notifications expected: do nothing */ |
159 |
} |
160 |
} else { /* received standart message, not a notification */ |
161 |
/* no standart message expected: do nothing */
|
162 |
} |
163 |
#ifdef TELMO
|
164 |
switch (get_hor_movement()) {
|
165 |
case LEFT:
|
166 |
printf("GOING LEFT.\n");
|
167 |
break;
|
168 |
case RIGHT:
|
169 |
printf("GOING RIGHT.\n");
|
170 |
break;
|
171 |
} |
172 |
switch (get_ver_movement()) {
|
173 |
case UP:
|
174 |
printf("GOING UP.\n");
|
175 |
break;
|
176 |
case DOWN:
|
177 |
printf("GOING DOWN.\n");
|
178 |
break;
|
179 |
} |
180 |
#endif
|
181 |
} |
182 |
|
183 |
font_dtor(consolas); |
184 |
|
185 |
// Unsubscribe interrupts
|
186 |
if (unsubscribe_all()) {
|
187 |
if (cleanup())
|
188 |
printf("%s: failed to cleanup.\n", __func__);
|
189 |
return 1; |
190 |
} |
191 |
|
192 |
|
193 |
if (cleanup()) {
|
194 |
printf("%s: failed to cleanup.\n", __func__);
|
195 |
return 1; |
196 |
} |
197 |
|
198 |
return 0; |
199 |
} |