root / proj / proj.c @ 166
History | View | Annotate | Download (3.01 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 | 157 | up20180642 | #ifdef DIOGO
|
26 | 162 | up20180642 | #include "shooter.h" |
27 | 160 | up20180642 | #include "pistol.xpm" |
28 | 157 | up20180642 | #endif
|
29 | |||
30 | 144 | up20180655 | int main(int argc, char* argv[]) { |
31 | |||
32 | lcf_set_language("EN-US");
|
||
33 | |||
34 | //lcf_trace_calls("/home/lcom/labs/proj/trace.txt");
|
||
35 | |||
36 | //lcf_log_output("/home/lcom/labs/proj/output.txt");
|
||
37 | |||
38 | if (lcf_start(argc, argv)) return 1; |
||
39 | |||
40 | lcf_cleanup(); |
||
41 | |||
42 | return 0; |
||
43 | } |
||
44 | 147 | up20180655 | |
45 | 149 | up20180655 | int(proj_main_loop)(int argc, char *argv[]) { |
46 | 166 | up20180642 | if(graph_init(GRAPH_MODE)){
|
47 | printf("%s: failed to initalize graphics.\n", __func__);
|
||
48 | if (cleanup()) printf("%s: failed to cleanup.\n", __func__); |
||
49 | 152 | up20180642 | return 1; |
50 | } |
||
51 | |||
52 | 159 | up20180642 | #ifdef DIOGO
|
53 | 165 | up20180642 | graph_paint_screen(0x777777);
|
54 | 162 | up20180642 | sprite_t *shooter1 = get_shooter(); sprite_set_pos(shooter1, 100, 100); |
55 | 160 | up20180642 | for(double angle = 0; angle < 6.29; angle += 0.01){ |
56 | 162 | up20180642 | sprite_set_angle(shooter1, angle); |
57 | 160 | up20180642 | //paint_screen(0x777777);
|
58 | 162 | up20180642 | sprite_draw(shooter1); |
59 | 160 | up20180642 | tickdelay(micros_to_ticks(10000));
|
60 | } |
||
61 | 162 | up20180642 | sprite_dtor(shooter1); |
62 | 164 | up20180642 | graph_draw(); |
63 | 159 | up20180642 | #endif
|
64 | 152 | up20180642 | |
65 | 149 | up20180655 | /// loop stuff
|
66 | int ipc_status, r;
|
||
67 | message msg; |
||
68 | 147 | up20180655 | |
69 | 153 | up20180655 | /// subscribe interrupts
|
70 | 155 | up20180655 | if (subscribe_all()) {
|
71 | if (cleanup())
|
||
72 | printf("%s: failed to cleanup.\n", __func__);
|
||
73 | return 1; |
||
74 | } |
||
75 | 149 | up20180655 | |
76 | 147 | up20180655 | /// cycle
|
77 | int good = 1; |
||
78 | while (good) {
|
||
79 | /* Get a request message. */
|
||
80 | if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) { |
||
81 | printf("driver_receive failed with %d", r);
|
||
82 | continue;
|
||
83 | } |
||
84 | if (is_ipc_notify(ipc_status)) { /* received notification */ |
||
85 | switch (_ENDPOINT_P(msg.m_source)) {
|
||
86 | case HARDWARE: /* hardware interrupt notification */ |
||
87 | 153 | up20180655 | for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) { |
88 | if (msg.m_notify.interrupts & n) {
|
||
89 | interrupt_handler(i); |
||
90 | } |
||
91 | 147 | up20180655 | } |
92 | 153 | up20180655 | if (scancode[0] == ESC_BREAK_CODE) good = 0; |
93 | 147 | up20180655 | break;
|
94 | default:
|
||
95 | break; /* no other notifications expected: do nothing */ |
||
96 | } |
||
97 | } else { /* received standart message, not a notification */ |
||
98 | /* no standart message expected: do nothing */
|
||
99 | } |
||
100 | } |
||
101 | 149 | up20180655 | |
102 | 153 | up20180655 | // Unsubscribe interrupts
|
103 | 155 | up20180655 | if (unsubscribe_all()) {
|
104 | if (cleanup())
|
||
105 | printf("%s: failed to cleanup.\n", __func__);
|
||
106 | 152 | up20180642 | return 1; |
107 | } |
||
108 | |||
109 | 155 | up20180655 | |
110 | if (cleanup()) {
|
||
111 | printf("%s: failed to cleanup.\n", __func__);
|
||
112 | 152 | up20180642 | return 1; |
113 | } |
||
114 | |||
115 | 149 | up20180655 | return 0; |
116 | 147 | up20180655 | } |