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