Project

General

Profile

Statistics
| Revision:

root / proj / proj.c @ 160

History | View | Annotate | Download (3.38 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 "shooter.xpm"
27
    #include "pistol.xpm"
28
#endif
29

    
30
int main(int argc, char* argv[]) {
31

    
32
    lcf_set_language("EN-US");
33

    
34
    //lcf_trace_calls("/home/lcom/labs/proj/trace.txt");
35

    
36
    //lcf_log_output("/home/lcom/labs/proj/output.txt");
37

    
38
    if (lcf_start(argc, argv)) return 1;
39

    
40
    lcf_cleanup();
41

    
42
    return 0;
43
}
44

    
45
int(proj_main_loop)(int argc, char *argv[]) {
46

    
47
    if (vbe_get_mode_information(GRAPH_MODE)) {
48
        printf("%s: failed to get information for mode %x.\n", __func__, GRAPH_MODE);
49
        if (cleanup())
50
            printf("%s: failed to cleanup.\n", __func__);
51
        return 1;
52
    }
53

    
54
    map_vram(); // if function fails it aborts program
55

    
56
    if (set_graphics_mode(GRAPH_MODE)) {
57
        printf("%s: failed to set graphic mode %x.\n", __func__, GRAPH_MODE);
58
        if (cleanup())
59
            printf("%s: failed to cleanup.\n", __func__);
60
        return 1;
61
    };
62

    
63
    #ifdef DIOGO
64
        paint_screen(0x777777);
65
        sprite_t *shooter = sprite_ctor((xpm_map_t)shooter_xpm); sprite_set_pos(shooter, 100, 100); sprite_set_center(shooter, 25, 25);
66
        for(double angle = 0; angle < 6.29; angle += 0.01){
67
             sprite_set_angle(shooter, angle);
68
             //paint_screen(0x777777);
69
             sprite_draw(shooter);
70
             tickdelay(micros_to_ticks(10000));
71
        }
72
        sprite_draw(shooter);
73
    #endif
74

    
75
    /// loop stuff
76
    int ipc_status, r;
77
    message msg;
78

    
79
    /// subscribe interrupts
80
    if (subscribe_all()) {
81
        if (cleanup())
82
            printf("%s: failed to cleanup.\n", __func__);
83
        return 1;
84
    }
85

    
86
    /// cycle
87
    int good = 1;
88
    while (good) {
89
        /* Get a request message. */
90
        if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) {
91
            printf("driver_receive failed with %d", r);
92
            continue;
93
        }
94
        if (is_ipc_notify(ipc_status)) { /* received notification */
95
            switch (_ENDPOINT_P(msg.m_source)) {
96
                case HARDWARE: /* hardware interrupt notification */
97
                    for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) {
98
                        if (msg.m_notify.interrupts & n) {
99
                            interrupt_handler(i);
100
                        }
101
                    }
102
                    if (scancode[0] == ESC_BREAK_CODE) good = 0;
103
                    break;
104
                default:
105
                    break; /* no other notifications expected: do nothing */
106
            }
107
        } else { /* received standart message, not a notification */
108
            /* no standart message expected: do nothing */
109
        }
110
    }
111

    
112
    // Unsubscribe interrupts
113
    if (unsubscribe_all()) {
114
        if (cleanup())
115
            printf("%s: failed to cleanup.\n", __func__);
116
        return 1;
117
    }
118

    
119

    
120
    if (cleanup()) {
121
        printf("%s: failed to cleanup.\n", __func__);
122
        return 1;
123
    }
124

    
125
    return 0;
126
}