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