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