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