Project

General

Profile

Statistics
| Revision:

root / proj / proj.c @ 153

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 "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

    
23
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

    
38
int(proj_main_loop)(int argc, char *argv[]) {
39

    
40
    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
    /// loop stuff
60
    int ipc_status, r;
61
    message msg;
62

    
63
    /// subscribe interrupts
64
    if (subscribe_all()) return 1;
65

    
66
    /// 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
                    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
                    }
82
                    if (scancode[0] == ESC_BREAK_CODE) good = 0;
83
                    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

    
92
    // Unsubscribe interrupts
93
    if (unsubscribe_all()) return 1;
94

    
95

    
96
    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

    
108
    #ifdef DIOGO
109
        hello
110
    #endif
111

    
112

    
113
    return 0;
114

    
115
    return 0;
116
}