root / proj / proj.c @ 173
History | View | Annotate | Download (4.74 KB)
1 |
#include <lcom/lcf.h> |
---|---|
2 |
#include <lcom/proj.h> |
3 |
#include <lcom/liblm.h> |
4 |
|
5 |
#include <stdbool.h> |
6 |
#include <stdint.h> |
7 |
|
8 |
#include "i8254.h" |
9 |
#include "kbc_macros.h" |
10 |
#include "graph_macros.h" |
11 |
#include "mouse_macros.h" |
12 |
#include "proj_macros.h" |
13 |
#include "errors.h" |
14 |
|
15 |
#include "sprite.h" |
16 |
#include "kbc.h" |
17 |
#include "graph.h" |
18 |
#include "timer.h" |
19 |
#include "keyboard.h" |
20 |
#include "mouse.h" |
21 |
#include "utils.h" |
22 |
#include "interrupts_func.h" |
23 |
#include "proj_func.h" |
24 |
|
25 |
#include "fast_math.h" |
26 |
#include <math.h> |
27 |
|
28 |
#ifdef DIOGO
|
29 |
#include "shooter.h" |
30 |
#include "pistol.xpm" |
31 |
#endif
|
32 |
#ifdef TELMO
|
33 |
#include "crosshair.h" |
34 |
#endif
|
35 |
|
36 |
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 |
|
51 |
int(proj_main_loop)(int argc, char *argv[]) { |
52 |
|
53 |
int r;
|
54 |
|
55 |
/// subscribe interrupts
|
56 |
if (subscribe_all()) { return 1; } |
57 |
|
58 |
/// initialize graphics
|
59 |
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 |
return 1; |
63 |
} |
64 |
|
65 |
#ifdef DIOGO
|
66 |
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 |
sprite_t *shooter1 = get_shooter(); sprite_set_pos(shooter1, 100, 100); |
71 |
for(double angle = 0; angle <= 6.283185; angle += 0.006283185){ |
72 |
sprite_set_angle(shooter1, angle); |
73 |
//graph_paint_screen(0x777777);
|
74 |
graph_clear_screen(); |
75 |
sprite_draw(shooter1); |
76 |
graph_draw(); |
77 |
} |
78 |
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 |
sprite_dtor(shooter1); |
82 |
#endif
|
83 |
|
84 |
#ifdef TELMO
|
85 |
sprite_t *crosshair = get_crosshair(); |
86 |
graph_clear_screen(); |
87 |
sprite_draw(crosshair); |
88 |
graph_draw(); |
89 |
#endif
|
90 |
|
91 |
/// loop stuff
|
92 |
int ipc_status;
|
93 |
message msg; |
94 |
int good = 1; |
95 |
|
96 |
#ifdef DIOGO
|
97 |
good = 0;
|
98 |
#endif
|
99 |
|
100 |
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 |
for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) { |
110 |
if (msg.m_notify.interrupts & n) {
|
111 |
interrupt_handler(i); |
112 |
if ((scancode[0]) == ESC_BREAK_CODE) good = 0; |
113 |
#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 |
printf("X: %d | Y: %d | XRES: %d | YRES: %d\n", get_mouse_X(), get_mouse_Y(), graph_get_XRes(), graph_get_YRes());
|
119 |
graph_clear_screen(); |
120 |
sprite_draw(crosshair); |
121 |
graph_draw(); |
122 |
counter_mouse_ih = 0;
|
123 |
} |
124 |
#endif
|
125 |
} |
126 |
} |
127 |
|
128 |
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 |
|
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 |
} |
153 |
|
154 |
// Unsubscribe interrupts
|
155 |
if (unsubscribe_all()) {
|
156 |
if (cleanup())
|
157 |
printf("%s: failed to cleanup.\n", __func__);
|
158 |
return 1; |
159 |
} |
160 |
|
161 |
|
162 |
if (cleanup()) {
|
163 |
printf("%s: failed to cleanup.\n", __func__);
|
164 |
return 1; |
165 |
} |
166 |
|
167 |
return 0; |
168 |
} |