root / proj / proj.c @ 164
History | View | Annotate | Download (3.35 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 | #include "graphics_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 | #include "graphics.h" |
||
18 | #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 | 147 | up20180655 | |
47 | 157 | up20180642 | if (vbe_get_mode_information(GRAPH_MODE)) {
|
48 | printf("%s: failed to get information for mode %x.\n", __func__, GRAPH_MODE);
|
||
49 | 155 | up20180655 | if (cleanup())
|
50 | printf("%s: failed to cleanup.\n", __func__);
|
||
51 | 152 | up20180642 | return 1; |
52 | } |
||
53 | |||
54 | map_vram(); // if function fails it aborts program
|
||
55 | |||
56 | 157 | up20180642 | if (set_graphics_mode(GRAPH_MODE)) {
|
57 | printf("%s: failed to set graphic mode %x.\n", __func__, GRAPH_MODE);
|
||
58 | 155 | up20180655 | if (cleanup())
|
59 | printf("%s: failed to cleanup.\n", __func__);
|
||
60 | 152 | up20180642 | return 1; |
61 | }; |
||
62 | |||
63 | 159 | up20180642 | #ifdef DIOGO
|
64 | 160 | up20180642 | paint_screen(0x777777);
|
65 | 162 | up20180642 | sprite_t *shooter1 = get_shooter(); sprite_set_pos(shooter1, 100, 100); |
66 | 160 | up20180642 | for(double angle = 0; angle < 6.29; angle += 0.01){ |
67 | 162 | up20180642 | sprite_set_angle(shooter1, angle); |
68 | 160 | up20180642 | //paint_screen(0x777777);
|
69 | 162 | up20180642 | sprite_draw(shooter1); |
70 | 160 | up20180642 | tickdelay(micros_to_ticks(10000));
|
71 | } |
||
72 | 162 | up20180642 | sprite_dtor(shooter1); |
73 | 164 | up20180642 | graph_draw(); |
74 | 159 | up20180642 | #endif
|
75 | 152 | up20180642 | |
76 | 149 | up20180655 | /// loop stuff
|
77 | int ipc_status, r;
|
||
78 | message msg; |
||
79 | 147 | up20180655 | |
80 | 153 | up20180655 | /// subscribe interrupts
|
81 | 155 | up20180655 | if (subscribe_all()) {
|
82 | if (cleanup())
|
||
83 | printf("%s: failed to cleanup.\n", __func__);
|
||
84 | return 1; |
||
85 | } |
||
86 | 149 | up20180655 | |
87 | 147 | up20180655 | /// cycle
|
88 | int good = 1; |
||
89 | while (good) {
|
||
90 | /* Get a request message. */
|
||
91 | if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) { |
||
92 | printf("driver_receive failed with %d", r);
|
||
93 | continue;
|
||
94 | } |
||
95 | if (is_ipc_notify(ipc_status)) { /* received notification */ |
||
96 | switch (_ENDPOINT_P(msg.m_source)) {
|
||
97 | case HARDWARE: /* hardware interrupt notification */ |
||
98 | 153 | up20180655 | for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) { |
99 | if (msg.m_notify.interrupts & n) {
|
||
100 | interrupt_handler(i); |
||
101 | } |
||
102 | 147 | up20180655 | } |
103 | 153 | up20180655 | if (scancode[0] == ESC_BREAK_CODE) good = 0; |
104 | 147 | up20180655 | break;
|
105 | default:
|
||
106 | break; /* no other notifications expected: do nothing */ |
||
107 | } |
||
108 | } else { /* received standart message, not a notification */ |
||
109 | /* no standart message expected: do nothing */
|
||
110 | } |
||
111 | } |
||
112 | 149 | up20180655 | |
113 | 153 | up20180655 | // Unsubscribe interrupts
|
114 | 155 | up20180655 | if (unsubscribe_all()) {
|
115 | if (cleanup())
|
||
116 | printf("%s: failed to cleanup.\n", __func__);
|
||
117 | 152 | up20180642 | return 1; |
118 | } |
||
119 | |||
120 | 155 | up20180655 | |
121 | if (cleanup()) {
|
||
122 | printf("%s: failed to cleanup.\n", __func__);
|
||
123 | 152 | up20180642 | return 1; |
124 | } |
||
125 | |||
126 | 149 | up20180655 | return 0; |
127 | 147 | up20180655 | } |