root / proj / proj.c @ 173
History | View | Annotate | Download (4.74 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 | 168 | 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 | 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_paint_screen(0x777777);
|
74 | graph_clear_screen(); |
||
75 | 162 | up20180642 | sprite_draw(shooter1); |
76 | 168 | up20180642 | graph_draw(); |
77 | 160 | up20180642 | } |
78 | 168 | up20180642 | t = clock() - t; //printf("%d\n", CLOCKS_PER_SEC);
|
79 | //double dt = ((double)t)/(double)CLOCKS_PER_SEC;
|
||
80 | printf("Time taken: %d/%d \n", t, CLOCKS_PER_SEC);
|
||
81 | 162 | up20180642 | sprite_dtor(shooter1); |
82 | 159 | up20180642 | #endif
|
83 | 152 | up20180642 | |
84 | 171 | up20180655 | #ifdef TELMO
|
85 | sprite_t *crosshair = get_crosshair(); |
||
86 | graph_clear_screen(); |
||
87 | sprite_draw(crosshair); |
||
88 | graph_draw(); |
||
89 | #endif
|
||
90 | |||
91 | 149 | up20180655 | /// loop stuff
|
92 | 170 | up20180642 | int ipc_status;
|
93 | 149 | up20180655 | message msg; |
94 | 147 | up20180655 | int good = 1; |
95 | 168 | up20180642 | |
96 | #ifdef DIOGO
|
||
97 | good = 0;
|
||
98 | #endif
|
||
99 | |||
100 | 147 | up20180655 | while (good) {
|
101 | /* Get a request message. */
|
||
102 | if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) { |
||
103 | printf("driver_receive failed with %d", r);
|
||
104 | continue;
|
||
105 | } |
||
106 | if (is_ipc_notify(ipc_status)) { /* received notification */ |
||
107 | switch (_ENDPOINT_P(msg.m_source)) {
|
||
108 | case HARDWARE: /* hardware interrupt notification */ |
||
109 | 153 | up20180655 | for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) { |
110 | if (msg.m_notify.interrupts & n) {
|
||
111 | interrupt_handler(i); |
||
112 | 167 | up20180655 | if ((scancode[0]) == ESC_BREAK_CODE) good = 0; |
113 | 171 | up20180655 | #ifdef TELMO
|
114 | if (counter_mouse_ih >= 3) { |
||
115 | struct packet pp = mouse_parse_packet(packet_mouse_ih);
|
||
116 | update_mouse_position(&pp); |
||
117 | sprite_set_pos(crosshair, get_mouse_X(), get_mouse_Y()); |
||
118 | 173 | up20180655 | printf("X: %d | Y: %d | XRES: %d | YRES: %d\n", get_mouse_X(), get_mouse_Y(), graph_get_XRes(), graph_get_YRes());
|
119 | 171 | up20180655 | graph_clear_screen(); |
120 | sprite_draw(crosshair); |
||
121 | graph_draw(); |
||
122 | 173 | up20180655 | counter_mouse_ih = 0;
|
123 | 171 | up20180655 | } |
124 | #endif
|
||
125 | 153 | up20180655 | } |
126 | 147 | up20180655 | } |
127 | 167 | up20180655 | |
128 | 147 | up20180655 | break;
|
129 | default:
|
||
130 | break; /* no other notifications expected: do nothing */ |
||
131 | } |
||
132 | } else { /* received standart message, not a notification */ |
||
133 | /* no standart message expected: do nothing */
|
||
134 | } |
||
135 | 167 | up20180655 | |
136 | switch (get_hor_movement()) {
|
||
137 | case LEFT:
|
||
138 | printf("GOING LEFT.\n");
|
||
139 | break;
|
||
140 | case RIGHT:
|
||
141 | printf("GOING RIGHT.\n");
|
||
142 | break;
|
||
143 | } |
||
144 | switch (get_ver_movement()) {
|
||
145 | case UP:
|
||
146 | printf("GOING UP.\n");
|
||
147 | break;
|
||
148 | case DOWN:
|
||
149 | printf("GOING DOWN.\n");
|
||
150 | break;
|
||
151 | } |
||
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 | } |