root / proj / proj.c @ 169
History | View | Annotate | Download (3.87 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 | |||
33 | 144 | up20180655 | int main(int argc, char* argv[]) { |
34 | |||
35 | lcf_set_language("EN-US");
|
||
36 | |||
37 | //lcf_trace_calls("/home/lcom/labs/proj/trace.txt");
|
||
38 | |||
39 | //lcf_log_output("/home/lcom/labs/proj/output.txt");
|
||
40 | |||
41 | if (lcf_start(argc, argv)) return 1; |
||
42 | |||
43 | lcf_cleanup(); |
||
44 | |||
45 | return 0; |
||
46 | } |
||
47 | 147 | up20180655 | |
48 | 149 | up20180655 | int(proj_main_loop)(int argc, char *argv[]) { |
49 | 166 | up20180642 | if(graph_init(GRAPH_MODE)){
|
50 | printf("%s: failed to initalize graphics.\n", __func__);
|
||
51 | if (cleanup()) printf("%s: failed to cleanup.\n", __func__); |
||
52 | 152 | up20180642 | return 1; |
53 | } |
||
54 | |||
55 | 159 | up20180642 | #ifdef DIOGO
|
56 | 168 | up20180642 | printf("%d\n", 1000000-(int)(1000000*fm_sin(0.5*M_PI))); |
57 | printf("%d\n", (int)(1000000*fm_cos(0.5*M_PI))); |
||
58 | |||
59 | clock_t t = clock(); |
||
60 | 162 | up20180642 | sprite_t *shooter1 = get_shooter(); sprite_set_pos(shooter1, 100, 100); |
61 | 168 | up20180642 | for(double angle = 0; angle <= 6.283185; angle += 0.006283185){ |
62 | 162 | up20180642 | sprite_set_angle(shooter1, angle); |
63 | 168 | up20180642 | //graph_paint_screen(0x777777);
|
64 | graph_clear_screen(); |
||
65 | 162 | up20180642 | sprite_draw(shooter1); |
66 | 168 | up20180642 | graph_draw(); |
67 | 160 | up20180642 | } |
68 | 168 | up20180642 | t = clock() - t; //printf("%d\n", CLOCKS_PER_SEC);
|
69 | //double dt = ((double)t)/(double)CLOCKS_PER_SEC;
|
||
70 | printf("Time taken: %d/%d \n", t, CLOCKS_PER_SEC);
|
||
71 | 162 | up20180642 | sprite_dtor(shooter1); |
72 | 159 | up20180642 | #endif
|
73 | 152 | up20180642 | |
74 | 149 | up20180655 | /// loop stuff
|
75 | int ipc_status, r;
|
||
76 | message msg; |
||
77 | 147 | up20180655 | |
78 | 153 | up20180655 | /// subscribe interrupts
|
79 | 155 | up20180655 | if (subscribe_all()) {
|
80 | if (cleanup())
|
||
81 | printf("%s: failed to cleanup.\n", __func__);
|
||
82 | return 1; |
||
83 | } |
||
84 | 149 | up20180655 | |
85 | 147 | up20180655 | /// cycle
|
86 | int good = 1; |
||
87 | 168 | up20180642 | |
88 | #ifdef DIOGO
|
||
89 | good = 0;
|
||
90 | #endif
|
||
91 | |||
92 | 147 | up20180655 | while (good) {
|
93 | /* Get a request message. */
|
||
94 | if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) { |
||
95 | printf("driver_receive failed with %d", r);
|
||
96 | continue;
|
||
97 | } |
||
98 | if (is_ipc_notify(ipc_status)) { /* received notification */ |
||
99 | switch (_ENDPOINT_P(msg.m_source)) {
|
||
100 | case HARDWARE: /* hardware interrupt notification */ |
||
101 | 153 | up20180655 | for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) { |
102 | if (msg.m_notify.interrupts & n) {
|
||
103 | interrupt_handler(i); |
||
104 | 167 | up20180655 | if ((scancode[0]) == ESC_BREAK_CODE) good = 0; |
105 | 153 | up20180655 | } |
106 | 147 | up20180655 | } |
107 | 167 | up20180655 | |
108 | 147 | up20180655 | break;
|
109 | default:
|
||
110 | break; /* no other notifications expected: do nothing */ |
||
111 | } |
||
112 | } else { /* received standart message, not a notification */ |
||
113 | /* no standart message expected: do nothing */
|
||
114 | } |
||
115 | 167 | up20180655 | |
116 | switch (get_hor_movement()) {
|
||
117 | case LEFT:
|
||
118 | printf("GOING LEFT.\n");
|
||
119 | break;
|
||
120 | case RIGHT:
|
||
121 | printf("GOING RIGHT.\n");
|
||
122 | break;
|
||
123 | } |
||
124 | switch (get_ver_movement()) {
|
||
125 | case UP:
|
||
126 | printf("GOING UP.\n");
|
||
127 | break;
|
||
128 | case DOWN:
|
||
129 | printf("GOING DOWN.\n");
|
||
130 | break;
|
||
131 | } |
||
132 | 147 | up20180655 | } |
133 | 149 | up20180655 | |
134 | 153 | up20180655 | // Unsubscribe interrupts
|
135 | 155 | up20180655 | if (unsubscribe_all()) {
|
136 | if (cleanup())
|
||
137 | printf("%s: failed to cleanup.\n", __func__);
|
||
138 | 152 | up20180642 | return 1; |
139 | } |
||
140 | |||
141 | 155 | up20180655 | |
142 | if (cleanup()) {
|
||
143 | printf("%s: failed to cleanup.\n", __func__);
|
||
144 | 152 | up20180642 | return 1; |
145 | } |
||
146 | |||
147 | 149 | up20180655 | return 0; |
148 | 147 | up20180655 | } |