Project

General

Profile

Statistics
| Revision:

root / proj / proj.c @ 174

History | View | Annotate | Download (4.75 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 "graph_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 "graph.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
#include "fast_math.h"
26
#include <math.h>
27

    
28
#ifdef DIOGO
29
    #include "shooter.h"
30
    #include "pistol.xpm"
31
#endif
32
#ifdef TELMO
33
    #include "crosshair.h"
34
#endif
35

    
36
int main(int argc, char* argv[]) {
37

    
38
    lcf_set_language("EN-US");
39

    
40
    //lcf_trace_calls("/home/lcom/labs/proj/trace.txt");
41

    
42
    //lcf_log_output("/home/lcom/labs/proj/output.txt");
43

    
44
    if (lcf_start(argc, argv)) return 1;
45

    
46
    lcf_cleanup();
47

    
48
    return 0;
49
}
50

    
51
int(proj_main_loop)(int argc, char *argv[]) {
52

    
53
    int r;
54

    
55
    /// subscribe interrupts
56
    if (subscribe_all()) { return 1; }
57

    
58
    /// initialize graphics
59
    if(graph_init(GRAPH_MODE)){
60
        printf("%s: failed to initalize graphics.\n", __func__);
61
        if (cleanup()) printf("%s: failed to cleanup.\n", __func__);
62
        return 1;
63
    }
64

    
65
    #ifdef DIOGO
66
        //printf("%d\n", 1000000-(int)(1000000*fm_sin(0.5*M_PI)));
67
        //printf("%d\n", (int)(1000000*fm_cos(0.5*M_PI)));
68
        /*
69
        clock_t t = clock();
70
        sprite_t *shooter1 = get_shooter(); sprite_set_pos(shooter1, 100, 100);
71
        for(double angle = 0; angle <= 6.283185; angle += 0.006283185){
72
             sprite_set_angle(shooter1, angle);
73
             graph_clear_screen();
74
             sprite_draw(shooter1);
75
             graph_draw();
76
        }
77
        t = clock() - t;
78
        printf("Time taken: %d/%d \n", t, CLOCKS_PER_SEC);
79
        sprite_dtor(shooter1);
80
        */
81
    #endif
82

    
83
    #ifdef TELMO
84
        sprite_t *crosshair = get_crosshair();
85
        graph_clear_screen();
86
        sprite_draw(crosshair);
87
        graph_draw();
88
    #endif
89

    
90
    /// loop stuff
91
    int ipc_status;
92
    message msg;
93
    int good = 1;
94

    
95
    #ifdef DIOGO
96
        good = 0;
97
    #endif
98

    
99
    while (good) {
100
        /* Get a request message. */
101
        if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) {
102
            printf("driver_receive failed with %d", r);
103
            continue;
104
        }
105
        if (is_ipc_notify(ipc_status)) { /* received notification */
106
            switch (_ENDPOINT_P(msg.m_source)) {
107
                case HARDWARE: /* hardware interrupt notification */
108
                    for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) {
109
                        if (msg.m_notify.interrupts & n) {
110
                            interrupt_handler(i);
111
                            if ((scancode[0]) == ESC_BREAK_CODE) good = 0;
112
                            #ifdef TELMO
113
                            if (counter_mouse_ih >= 3) {
114
                                struct packet pp = mouse_parse_packet(packet_mouse_ih);
115
                                update_mouse_position(&pp);
116
                                sprite_set_pos(crosshair, get_mouse_X(), get_mouse_Y());
117
                                printf("X: %d | Y: %d | XRES: %d | YRES: %d\n", get_mouse_X(), get_mouse_Y(), graph_get_XRes(), graph_get_YRes());
118
                                graph_clear_screen();
119
                                sprite_draw(crosshair);
120
                                graph_draw();
121
                                counter_mouse_ih = 0;
122
                            }
123
                            #endif
124
                        }
125
                    }
126

    
127
                    break;
128
                default:
129
                    break; /* no other notifications expected: do nothing */
130
            }
131
        } else { /* received standart message, not a notification */
132
            /* no standart message expected: do nothing */
133
        }
134
        #ifdef TELMO
135
            switch (get_hor_movement()) {
136
                case LEFT:
137
                    printf("GOING LEFT.\n");
138
                    break;
139
                case RIGHT:
140
                    printf("GOING RIGHT.\n");
141
                    break;
142
            }
143
            switch (get_ver_movement()) {
144
                case UP:
145
                    printf("GOING UP.\n");
146
                    break;
147
                case DOWN:
148
                    printf("GOING DOWN.\n");
149
                    break;
150
            }
151
        #endif
152
    }
153

    
154
    // Unsubscribe interrupts
155
    if (unsubscribe_all()) {
156
        if (cleanup())
157
            printf("%s: failed to cleanup.\n", __func__);
158
        return 1;
159
    }
160

    
161

    
162
    if (cleanup()) {
163
        printf("%s: failed to cleanup.\n", __func__);
164
        return 1;
165
    }
166

    
167
    return 0;
168
}