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