root / proj / proj.c @ 159
History | View | Annotate | Download (3 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 "sprite.h" |
16 |
#include "kbc.h" |
17 |
#include "graphics.h" |
18 |
#include "timer.h" |
19 |
#include "keyboard.h" |
20 |
#include "mouse.h" |
21 |
#include "utils.h" |
22 |
#include "interrupts_func.h" |
23 |
#include "proj_func.h" |
24 |
|
25 |
#ifdef DIOGO
|
26 |
#include "plus.xpm" |
27 |
#endif
|
28 |
|
29 |
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 |
|
44 |
int(proj_main_loop)(int argc, char *argv[]) { |
45 |
|
46 |
if (vbe_get_mode_information(GRAPH_MODE)) {
|
47 |
printf("%s: failed to get information for mode %x.\n", __func__, GRAPH_MODE);
|
48 |
if (cleanup())
|
49 |
printf("%s: failed to cleanup.\n", __func__);
|
50 |
return 1; |
51 |
} |
52 |
|
53 |
map_vram(); // if function fails it aborts program
|
54 |
|
55 |
if (set_graphics_mode(GRAPH_MODE)) {
|
56 |
printf("%s: failed to set graphic mode %x.\n", __func__, GRAPH_MODE);
|
57 |
if (cleanup())
|
58 |
printf("%s: failed to cleanup.\n", __func__);
|
59 |
return 1; |
60 |
}; |
61 |
|
62 |
#ifdef DIOGO
|
63 |
sprite_t *sp = sprite_ctor((xpm_map_t)plus_xpm); |
64 |
sprite_draw(sp); |
65 |
#endif
|
66 |
|
67 |
/// loop stuff
|
68 |
int ipc_status, r;
|
69 |
message msg; |
70 |
|
71 |
/// subscribe interrupts
|
72 |
if (subscribe_all()) {
|
73 |
if (cleanup())
|
74 |
printf("%s: failed to cleanup.\n", __func__);
|
75 |
return 1; |
76 |
} |
77 |
|
78 |
/// 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 |
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 |
} |
94 |
if (scancode[0] == ESC_BREAK_CODE) good = 0; |
95 |
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 |
|
104 |
// Unsubscribe interrupts
|
105 |
if (unsubscribe_all()) {
|
106 |
if (cleanup())
|
107 |
printf("%s: failed to cleanup.\n", __func__);
|
108 |
return 1; |
109 |
} |
110 |
|
111 |
|
112 |
if (cleanup()) {
|
113 |
printf("%s: failed to cleanup.\n", __func__);
|
114 |
return 1; |
115 |
} |
116 |
|
117 |
return 0; |
118 |
} |