root / proj / proj.c @ 158
History | View | Annotate | Download (2.86 KB)
1 |
#include <lcom/lcf.h> |
---|---|
2 |
#include <lcom/proj.h> |
3 |
#include <lcom/liblm.h> |
4 |
|
5 |
#include <stdbool.h> |
6 |
#include <stdint.h> |
7 |
|
8 |
#include "i8254.h" |
9 |
#include "kbc_macros.h" |
10 |
#include "graphics_macros.h" |
11 |
#include "mouse_macros.h" |
12 |
#include "proj_macros.h" |
13 |
#include "errors.h" |
14 |
|
15 |
#include "kbc.h" |
16 |
#include "graphics.h" |
17 |
#include "timer.h" |
18 |
#include "keyboard.h" |
19 |
#include "mouse.h" |
20 |
#include "utils.h" |
21 |
#include "interrupts_func.h" |
22 |
#include "proj_func.h" |
23 |
|
24 |
#ifdef DIOGO
|
25 |
#include "plus.xpm" |
26 |
#endif
|
27 |
|
28 |
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 |
|
43 |
int(proj_main_loop)(int argc, char *argv[]) { |
44 |
|
45 |
if (vbe_get_mode_information(GRAPH_MODE)) {
|
46 |
printf("%s: failed to get information for mode %x.\n", __func__, GRAPH_MODE);
|
47 |
if (cleanup())
|
48 |
printf("%s: failed to cleanup.\n", __func__);
|
49 |
return 1; |
50 |
} |
51 |
|
52 |
map_vram(); // if function fails it aborts program
|
53 |
|
54 |
if (set_graphics_mode(GRAPH_MODE)) {
|
55 |
printf("%s: failed to set graphic mode %x.\n", __func__, GRAPH_MODE);
|
56 |
if (cleanup())
|
57 |
printf("%s: failed to cleanup.\n", __func__);
|
58 |
return 1; |
59 |
}; |
60 |
|
61 |
|
62 |
/// loop stuff
|
63 |
int ipc_status, r;
|
64 |
message msg; |
65 |
|
66 |
/// subscribe interrupts
|
67 |
if (subscribe_all()) {
|
68 |
if (cleanup())
|
69 |
printf("%s: failed to cleanup.\n", __func__);
|
70 |
return 1; |
71 |
} |
72 |
|
73 |
/// 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 |
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 |
} |
89 |
if (scancode[0] == ESC_BREAK_CODE) good = 0; |
90 |
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 |
|
99 |
// Unsubscribe interrupts
|
100 |
if (unsubscribe_all()) {
|
101 |
if (cleanup())
|
102 |
printf("%s: failed to cleanup.\n", __func__);
|
103 |
return 1; |
104 |
} |
105 |
|
106 |
|
107 |
if (cleanup()) {
|
108 |
printf("%s: failed to cleanup.\n", __func__);
|
109 |
return 1; |
110 |
} |
111 |
|
112 |
return 0; |
113 |
} |