root / proj / src / proj.c @ 180
History | View | Annotate | Download (5.12 KB)
1 |
#include <lcom/lcf.h> |
---|---|
2 |
#include <lcom/proj.h> |
3 |
#include <lcom/liblm.h> |
4 |
|
5 |
#include "proj_macros.h" |
6 |
#include "proj_func.h" |
7 |
|
8 |
#include "kbc.h" |
9 |
#include "timer.h" |
10 |
#include "keyboard.h" |
11 |
#include "mouse.h" |
12 |
#include "interrupts_func.h" |
13 |
|
14 |
#include "graph.h" |
15 |
#include "sprite.h" |
16 |
#include "rectangle.h" |
17 |
|
18 |
#ifdef DIOGO
|
19 |
#include "shooter.h" |
20 |
#endif
|
21 |
#ifdef TELMO
|
22 |
#include "crosshair.h" |
23 |
#endif
|
24 |
|
25 |
int main(int argc, char* argv[]) { |
26 |
|
27 |
lcf_set_language("EN-US");
|
28 |
|
29 |
//lcf_trace_calls("/home/lcom/labs/proj/trace.txt");
|
30 |
|
31 |
//lcf_log_output("/home/lcom/labs/proj/output.txt");
|
32 |
|
33 |
if (lcf_start(argc, argv)) return 1; |
34 |
|
35 |
lcf_cleanup(); |
36 |
|
37 |
return 0; |
38 |
} |
39 |
|
40 |
int(proj_main_loop)(int argc, char *argv[]) { |
41 |
|
42 |
int r;
|
43 |
|
44 |
/// subscribe interrupts
|
45 |
if (subscribe_all()) { return 1; } |
46 |
|
47 |
/// initialize graphics
|
48 |
if(graph_init(GRAPH_MODE)){
|
49 |
printf("%s: failed to initalize graphics.\n", __func__);
|
50 |
if (cleanup()) printf("%s: failed to cleanup.\n", __func__); |
51 |
return 1; |
52 |
} |
53 |
|
54 |
#ifdef DIOGO
|
55 |
//printf("%d\n", 1000000-(int)(1000000*fm_sin(0.5*M_PI)));
|
56 |
//printf("%d\n", (int)(1000000*fm_cos(0.5*M_PI)));
|
57 |
/*
|
58 |
clock_t t = clock();
|
59 |
sprite_t *shooter1 = get_shooter(); sprite_set_pos(shooter1, 100, 100);
|
60 |
for(double angle = 0; angle <= 6.283185; angle += 0.006283185){
|
61 |
sprite_set_angle(shooter1, angle);
|
62 |
graph_clear_screen();
|
63 |
sprite_draw(shooter1);
|
64 |
graph_draw();
|
65 |
}
|
66 |
t = clock() - t;
|
67 |
printf("Time taken: %d/%d \n", t, CLOCKS_PER_SEC);
|
68 |
sprite_dtor(shooter1);
|
69 |
*/
|
70 |
/*
|
71 |
rectangle_t *rect = rectangle_ctor(100, 100, 100, 100);
|
72 |
rectangle_set_fill_color (rect, 0x0000FF);
|
73 |
rectangle_set_outline_color(rect, 0xFF0000);
|
74 |
rectangle_set_outline_width(rect, 0);
|
75 |
rectangle_draw(rect);
|
76 |
rectangle_set_pos(rect, 205, 100);
|
77 |
rectangle_set_outline_width(rect, 1);
|
78 |
rectangle_draw(rect);
|
79 |
rectangle_set_pos(rect, 310, 100);
|
80 |
rectangle_set_outline_width(rect, 2);
|
81 |
rectangle_draw(rect);
|
82 |
rectangle_set_pos(rect, 415, 100);
|
83 |
rectangle_set_outline_width(rect, 3);
|
84 |
rectangle_draw(rect);
|
85 |
|
86 |
graph_draw();
|
87 |
*/
|
88 |
#endif
|
89 |
|
90 |
#ifdef TELMO
|
91 |
sprite_t *crosshair = get_crosshair(); |
92 |
graph_clear_screen(); |
93 |
sprite_draw(crosshair); |
94 |
graph_draw(); |
95 |
#endif
|
96 |
|
97 |
/// loop stuff
|
98 |
int ipc_status;
|
99 |
message msg; |
100 |
int good = 1; |
101 |
|
102 |
while (good) {
|
103 |
/* Get a request message. */
|
104 |
if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) { |
105 |
printf("driver_receive failed with %d", r);
|
106 |
continue;
|
107 |
} |
108 |
if (is_ipc_notify(ipc_status)) { /* received notification */ |
109 |
switch (_ENDPOINT_P(msg.m_source)) {
|
110 |
case HARDWARE: /* hardware interrupt notification */ |
111 |
for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) { |
112 |
if (msg.m_notify.interrupts & n) {
|
113 |
interrupt_handler(i); |
114 |
if ((scancode[0]) == ESC_BREAK_CODE) good = 0; |
115 |
#ifdef TELMO
|
116 |
if (counter_mouse_ih >= 3) { |
117 |
struct packet pp = mouse_parse_packet(packet_mouse_ih);
|
118 |
update_mouse_position(&pp); |
119 |
sprite_set_pos(crosshair, get_mouse_X(), get_mouse_Y()); |
120 |
printf("X: %d | Y: %d | XRES: %d | YRES: %d\n", get_mouse_X(), get_mouse_Y(), graph_get_XRes(), graph_get_YRes());
|
121 |
graph_clear_screen(); |
122 |
sprite_draw(crosshair); |
123 |
graph_draw(); |
124 |
counter_mouse_ih = 0;
|
125 |
} |
126 |
#endif
|
127 |
} |
128 |
} |
129 |
|
130 |
break;
|
131 |
default:
|
132 |
break; /* no other notifications expected: do nothing */ |
133 |
} |
134 |
} else { /* received standart message, not a notification */ |
135 |
/* no standart message expected: do nothing */
|
136 |
} |
137 |
#ifdef TELMO
|
138 |
switch (get_hor_movement()) {
|
139 |
case LEFT:
|
140 |
printf("GOING LEFT.\n");
|
141 |
break;
|
142 |
case RIGHT:
|
143 |
printf("GOING RIGHT.\n");
|
144 |
break;
|
145 |
} |
146 |
switch (get_ver_movement()) {
|
147 |
case UP:
|
148 |
printf("GOING UP.\n");
|
149 |
break;
|
150 |
case DOWN:
|
151 |
printf("GOING DOWN.\n");
|
152 |
break;
|
153 |
} |
154 |
#endif
|
155 |
} |
156 |
|
157 |
// Unsubscribe interrupts
|
158 |
if (unsubscribe_all()) {
|
159 |
if (cleanup())
|
160 |
printf("%s: failed to cleanup.\n", __func__);
|
161 |
return 1; |
162 |
} |
163 |
|
164 |
|
165 |
if (cleanup()) {
|
166 |
printf("%s: failed to cleanup.\n", __func__);
|
167 |
return 1; |
168 |
} |
169 |
|
170 |
return 0; |
171 |
} |