root / proj / src / proj.c @ 182
History | View | Annotate | Download (5.1 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 | 171 | up20180655 | #ifdef TELMO
|
20 | #include "crosshair.h" |
||
21 | #endif
|
||
22 | 157 | up20180642 | |
23 | 144 | up20180655 | 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 | 147 | up20180655 | |
38 | 149 | up20180655 | int(proj_main_loop)(int argc, char *argv[]) { |
39 | 170 | up20180642 | |
40 | int r;
|
||
41 | |||
42 | /// subscribe interrupts
|
||
43 | if (subscribe_all()) { return 1; } |
||
44 | |||
45 | /// initialize graphics
|
||
46 | 166 | up20180642 | 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 | 152 | up20180642 | return 1; |
50 | } |
||
51 | |||
52 | 159 | up20180642 | #ifdef DIOGO
|
53 | 174 | up20180642 | //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 | 168 | up20180642 | clock_t t = clock();
|
57 | 162 | up20180642 | sprite_t *shooter1 = get_shooter(); sprite_set_pos(shooter1, 100, 100);
|
58 | 168 | up20180642 | for(double angle = 0; angle <= 6.283185; angle += 0.006283185){
|
59 | 162 | up20180642 | sprite_set_angle(shooter1, angle);
|
60 | 168 | up20180642 | graph_clear_screen();
|
61 | 162 | up20180642 | sprite_draw(shooter1);
|
62 | 168 | up20180642 | graph_draw();
|
63 | 160 | up20180642 | }
|
64 | 174 | up20180642 | t = clock() - t;
|
65 | 168 | up20180642 | printf("Time taken: %d/%d \n", t, CLOCKS_PER_SEC);
|
66 | 162 | up20180642 | sprite_dtor(shooter1);
|
67 | 174 | up20180642 | */
|
68 | 179 | up20180642 | /*
|
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 | 182 | up20180642 | |
87 | |||
88 | |||
89 | 159 | up20180642 | #endif
|
90 | 152 | up20180642 | |
91 | 171 | up20180655 | #ifdef TELMO
|
92 | 174 | up20180642 | sprite_t *crosshair = get_crosshair(); |
93 | graph_clear_screen(); |
||
94 | sprite_draw(crosshair); |
||
95 | graph_draw(); |
||
96 | 171 | up20180655 | #endif
|
97 | |||
98 | 149 | up20180655 | /// loop stuff
|
99 | 170 | up20180642 | int ipc_status;
|
100 | 149 | up20180655 | message msg; |
101 | 147 | up20180655 | int good = 1; |
102 | 168 | up20180642 | |
103 | 147 | up20180655 | 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 | 153 | up20180655 | for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) { |
113 | if (msg.m_notify.interrupts & n) {
|
||
114 | interrupt_handler(i); |
||
115 | 167 | up20180655 | if ((scancode[0]) == ESC_BREAK_CODE) good = 0; |
116 | 171 | up20180655 | #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 | 173 | up20180655 | printf("X: %d | Y: %d | XRES: %d | YRES: %d\n", get_mouse_X(), get_mouse_Y(), graph_get_XRes(), graph_get_YRes());
|
122 | 171 | up20180655 | graph_clear_screen(); |
123 | sprite_draw(crosshair); |
||
124 | graph_draw(); |
||
125 | 173 | up20180655 | counter_mouse_ih = 0;
|
126 | 171 | up20180655 | } |
127 | #endif
|
||
128 | 153 | up20180655 | } |
129 | 147 | up20180655 | } |
130 | 167 | up20180655 | |
131 | 147 | up20180655 | 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 | 174 | up20180642 | #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 | 147 | up20180655 | } |
157 | 149 | up20180655 | |
158 | 153 | up20180655 | // Unsubscribe interrupts
|
159 | 155 | up20180655 | if (unsubscribe_all()) {
|
160 | if (cleanup())
|
||
161 | printf("%s: failed to cleanup.\n", __func__);
|
||
162 | 152 | up20180642 | return 1; |
163 | } |
||
164 | |||
165 | 155 | up20180655 | |
166 | if (cleanup()) {
|
||
167 | printf("%s: failed to cleanup.\n", __func__);
|
||
168 | 152 | up20180642 | return 1; |
169 | } |
||
170 | |||
171 | 149 | up20180655 | return 0; |
172 | 147 | up20180655 | } |