root / proj / src / proj.c @ 188
History | View | Annotate | Download (5.78 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 | 188 | up20180642 | 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 | 159 | up20180642 | #ifdef DIOGO
|
69 | 188 | up20180642 | graph_clear_screen(); |
70 | 183 | up20180642 | |
71 | 188 | up20180642 | 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 | 179 | up20180642 | rectangle_set_outline_width(rect, 2);
|
77 | 188 | up20180642 | rectangle_set_outline_color(rect, WHITE); |
78 | 179 | up20180642 | rectangle_draw(rect); |
79 | |||
80 | 188 | up20180642 | text_t *txt = text_ctor(consolas, "Hello world!");
|
81 | text_set_color(txt, 0x888888);
|
||
82 | 182 | up20180642 | |
83 | 188 | up20180642 | 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 | 183 | up20180642 | text_draw(txt); |
88 | text_dtor(txt); |
||
89 | |||
90 | graph_draw(); |
||
91 | 188 | up20180642 | rectangle_dtor(rect); |
92 | 183 | up20180642 | |
93 | tickdelay(micros_to_ticks(1000000));
|
||
94 | |||
95 | 159 | up20180642 | #endif
|
96 | 152 | up20180642 | |
97 | 171 | up20180655 | #ifdef TELMO
|
98 | 174 | up20180642 | sprite_t *crosshair = get_crosshair(); |
99 | 184 | up20180655 | sprite_t *shooter1 = get_shooter(); |
100 | sprite_set_pos(shooter1, 100, 100); |
||
101 | 174 | up20180642 | graph_clear_screen(); |
102 | sprite_draw(crosshair); |
||
103 | 184 | up20180655 | sprite_draw(shooter1); |
104 | 174 | up20180642 | graph_draw(); |
105 | 171 | up20180655 | #endif
|
106 | |||
107 | 149 | up20180655 | /// loop stuff
|
108 | 170 | up20180642 | int ipc_status;
|
109 | 149 | up20180655 | message msg; |
110 | 147 | up20180655 | int good = 1; |
111 | 168 | up20180642 | |
112 | 183 | up20180642 | #ifdef DIOGO
|
113 | good = 0;
|
||
114 | #endif
|
||
115 | |||
116 | 147 | up20180655 | 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 | 153 | up20180655 | for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) { |
126 | if (msg.m_notify.interrupts & n) {
|
||
127 | interrupt_handler(i); |
||
128 | 167 | up20180655 | if ((scancode[0]) == ESC_BREAK_CODE) good = 0; |
129 | 171 | up20180655 | #ifdef TELMO
|
130 | 187 | up20180655 | 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 | 184 | up20180655 | } |
143 | 171 | up20180655 | #endif
|
144 | 153 | up20180655 | } |
145 | 147 | up20180655 | } |
146 | 187 | up20180655 | #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 | 167 | up20180655 | |
154 | 147 | up20180655 | 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 | 174 | up20180642 | #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 | 147 | up20180655 | } |
180 | 149 | up20180655 | |
181 | 188 | up20180642 | font_dtor(consolas); |
182 | |||
183 | 153 | up20180655 | // Unsubscribe interrupts
|
184 | 155 | up20180655 | if (unsubscribe_all()) {
|
185 | if (cleanup())
|
||
186 | printf("%s: failed to cleanup.\n", __func__);
|
||
187 | 152 | up20180642 | return 1; |
188 | } |
||
189 | |||
190 | 155 | up20180655 | |
191 | if (cleanup()) {
|
||
192 | printf("%s: failed to cleanup.\n", __func__);
|
||
193 | 152 | up20180642 | return 1; |
194 | } |
||
195 | |||
196 | 149 | up20180655 | return 0; |
197 | 147 | up20180655 | } |