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