root / proj / src / proj.c @ 185
History | View | Annotate | Download (6.4 KB)
1 | 144 | up20180655 | #include <lcom/lcf.h> |
---|---|---|---|
2 | #include <lcom/proj.h> |
||
3 | #include <lcom/liblm.h> |
||
4 | 185 | up20180655 | #include <math.h> |
5 | 144 | up20180655 | |
6 | 149 | up20180655 | #include "proj_macros.h" |
7 | 179 | up20180642 | #include "proj_func.h" |
8 | 147 | up20180655 | |
9 | 149 | up20180655 | #include "kbc.h" |
10 | #include "timer.h" |
||
11 | #include "keyboard.h" |
||
12 | 150 | up20180655 | #include "mouse.h" |
13 | 153 | up20180655 | #include "interrupts_func.h" |
14 | 149 | up20180655 | |
15 | 179 | up20180642 | #include "graph.h" |
16 | #include "sprite.h" |
||
17 | #include "rectangle.h" |
||
18 | 182 | up20180642 | #include "font.h" |
19 | 168 | up20180642 | |
20 | 183 | up20180642 | #ifdef DIOGO
|
21 | #include "shooter.h" |
||
22 | #endif
|
||
23 | |||
24 | 171 | up20180655 | #ifdef TELMO
|
25 | #include "crosshair.h" |
||
26 | 184 | up20180655 | #include "shooter.h" |
27 | 171 | up20180655 | #endif
|
28 | 157 | up20180642 | |
29 | 144 | up20180655 | 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 | 147 | up20180655 | |
44 | 149 | up20180655 | int(proj_main_loop)(int argc, char *argv[]) { |
45 | 170 | up20180642 | |
46 | int r;
|
||
47 | |||
48 | /// subscribe interrupts
|
||
49 | if (subscribe_all()) { return 1; } |
||
50 | |||
51 | /// initialize graphics
|
||
52 | 166 | up20180642 | 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 | 152 | up20180642 | return 1; |
56 | } |
||
57 | |||
58 | 159 | up20180642 | #ifdef DIOGO
|
59 | 174 | up20180642 | //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 | 183 | up20180642 | rectangle_t *rect = rectangle_ctor(0,0,graph_get_XRes(), graph_get_YRes());
|
63 | rectangle_set_fill_color(rect, WHITE);
|
||
64 | |||
65 | 168 | up20180642 | clock_t t = clock();
|
66 | 162 | up20180642 | sprite_t *shooter1 = get_shooter(); sprite_set_pos(shooter1, 100, 100);
|
67 | 168 | up20180642 | for(double angle = 0; angle <= 6.283185; angle += 0.006283185){
|
68 | 162 | up20180642 | sprite_set_angle(shooter1, angle);
|
69 | 168 | up20180642 | graph_clear_screen();
|
70 | 183 | up20180642 | rectangle_draw(rect);
|
71 | 162 | up20180642 | sprite_draw(shooter1);
|
72 | 168 | up20180642 | graph_draw();
|
73 | 160 | up20180642 | }
|
74 | 174 | up20180642 | t = clock() - t;
|
75 | 168 | up20180642 | printf("Time taken: %d/%d \n", t, CLOCKS_PER_SEC);
|
76 | 162 | up20180642 | sprite_dtor(shooter1);
|
77 | 174 | up20180642 | */
|
78 | 179 | up20180642 | /*
|
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 | 182 | up20180642 | |
97 | 183 | up20180642 | font_t *fnt = font_ctor("/home/lcom/labs/proj/font/xpm2");
|
98 | 182 | up20180642 | |
99 | |||
100 | 183 | up20180642 | 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 | 159 | up20180642 | #endif
|
118 | 152 | up20180642 | |
119 | 171 | up20180655 | #ifdef TELMO
|
120 | 174 | up20180642 | sprite_t *crosshair = get_crosshair(); |
121 | 184 | up20180655 | sprite_t *shooter1 = get_shooter(); |
122 | sprite_set_pos(shooter1, 100, 100); |
||
123 | 174 | up20180642 | graph_clear_screen(); |
124 | sprite_draw(crosshair); |
||
125 | 184 | up20180655 | sprite_draw(shooter1); |
126 | 174 | up20180642 | graph_draw(); |
127 | 171 | up20180655 | #endif
|
128 | |||
129 | 149 | up20180655 | /// loop stuff
|
130 | 170 | up20180642 | int ipc_status;
|
131 | 149 | up20180655 | message msg; |
132 | 147 | up20180655 | int good = 1; |
133 | 168 | up20180642 | |
134 | 183 | up20180642 | #ifdef DIOGO
|
135 | good = 0;
|
||
136 | #endif
|
||
137 | |||
138 | 147 | up20180655 | 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 | 153 | up20180655 | for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) { |
148 | if (msg.m_notify.interrupts & n) {
|
||
149 | interrupt_handler(i); |
||
150 | 167 | up20180655 | if ((scancode[0]) == ESC_BREAK_CODE) good = 0; |
151 | 171 | up20180655 | #ifdef TELMO
|
152 | 184 | up20180655 | update_movement(shooter1); |
153 | printf("POS: %d %d\n", sprite_get_x(shooter1), sprite_get_y(shooter1));
|
||
154 | 171 | up20180655 | if (counter_mouse_ih >= 3) { |
155 | struct packet pp = mouse_parse_packet(packet_mouse_ih);
|
||
156 | update_mouse_position(&pp); |
||
157 | 173 | up20180655 | printf("X: %d | Y: %d | XRES: %d | YRES: %d\n", get_mouse_X(), get_mouse_Y(), graph_get_XRes(), graph_get_YRes());
|
158 | 184 | up20180655 | counter_mouse_ih = 0;
|
159 | } |
||
160 | |||
161 | sprite_set_pos(crosshair, get_mouse_X(), get_mouse_Y()); |
||
162 | double angle = get_mouse_angle(shooter1);
|
||
163 | 185 | up20180655 | sprite_set_angle(shooter1, angle - M_PI_2); |
164 | 171 | up20180655 | graph_clear_screen(); |
165 | sprite_draw(crosshair); |
||
166 | 184 | up20180655 | sprite_draw(shooter1); |
167 | 171 | up20180655 | graph_draw(); |
168 | #endif
|
||
169 | 153 | up20180655 | } |
170 | 147 | up20180655 | } |
171 | 167 | up20180655 | |
172 | 147 | up20180655 | break;
|
173 | default:
|
||
174 | break; /* no other notifications expected: do nothing */ |
||
175 | } |
||
176 | } else { /* received standart message, not a notification */ |
||
177 | /* no standart message expected: do nothing */
|
||
178 | } |
||
179 | 174 | up20180642 | #ifdef TELMO
|
180 | switch (get_hor_movement()) {
|
||
181 | case LEFT:
|
||
182 | printf("GOING LEFT.\n");
|
||
183 | break;
|
||
184 | case RIGHT:
|
||
185 | printf("GOING RIGHT.\n");
|
||
186 | break;
|
||
187 | } |
||
188 | switch (get_ver_movement()) {
|
||
189 | case UP:
|
||
190 | printf("GOING UP.\n");
|
||
191 | break;
|
||
192 | case DOWN:
|
||
193 | printf("GOING DOWN.\n");
|
||
194 | break;
|
||
195 | } |
||
196 | #endif
|
||
197 | 147 | up20180655 | } |
198 | 149 | up20180655 | |
199 | 153 | up20180655 | // Unsubscribe interrupts
|
200 | 155 | up20180655 | if (unsubscribe_all()) {
|
201 | if (cleanup())
|
||
202 | printf("%s: failed to cleanup.\n", __func__);
|
||
203 | 152 | up20180642 | return 1; |
204 | } |
||
205 | |||
206 | 155 | up20180655 | |
207 | if (cleanup()) {
|
||
208 | printf("%s: failed to cleanup.\n", __func__);
|
||
209 | 152 | up20180642 | return 1; |
210 | } |
||
211 | |||
212 | 149 | up20180655 | return 0; |
213 | 147 | up20180655 | } |