Project

General

Profile

Statistics
| Revision:

root / proj / proj.c @ 155

History | View | Annotate | Download (2.89 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 144 up20180655
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 147 up20180655
39 149 up20180655
int(proj_main_loop)(int argc, char *argv[]) {
40 147 up20180655
41 152 up20180642
    if (vbe_get_mode_information(INDEXED_1024_768)) {
42
        printf("%s: failed to get information for mode %x.\n", __func__, INDEXED_1024_768);
43 155 up20180655
        if (cleanup())
44
            printf("%s: failed to cleanup.\n", __func__);
45 152 up20180642
        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 155 up20180655
        if (cleanup())
53
            printf("%s: failed to cleanup.\n", __func__);
54 152 up20180642
        return 1;
55
    };
56
57
58 149 up20180655
    /// loop stuff
59
    int ipc_status, r;
60
    message msg;
61 147 up20180655
62 153 up20180655
    /// subscribe interrupts
63 155 up20180655
    if (subscribe_all()) {
64
        if (cleanup())
65
            printf("%s: failed to cleanup.\n", __func__);
66
        return 1;
67
    }
68 149 up20180655
69 147 up20180655
    /// 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 153 up20180655
                    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 147 up20180655
                    }
85 153 up20180655
                    if (scancode[0] == ESC_BREAK_CODE) good = 0;
86 147 up20180655
                    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 149 up20180655
95 153 up20180655
    // Unsubscribe interrupts
96 155 up20180655
    if (unsubscribe_all()) {
97
        if (cleanup())
98
            printf("%s: failed to cleanup.\n", __func__);
99 152 up20180642
        return 1;
100
    }
101
102 155 up20180655
103
    if (cleanup()) {
104
        printf("%s: failed to cleanup.\n", __func__);
105 152 up20180642
        return 1;
106
    }
107
108 153 up20180655
109 152 up20180642
    #ifdef DIOGO
110
        hello
111
    #endif
112
113 149 up20180655
    return 0;
114 147 up20180655
}