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