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