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