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