Project

General

Profile

Statistics
| Revision:

root / proj / proj.c @ 171

History | View | Annotate | Download (4.55 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_paint_screen(0x777777);
74
             graph_clear_screen();
75
             sprite_draw(shooter1);
76
             graph_draw();
77
        }
78
        t = clock() - t; //printf("%d\n", CLOCKS_PER_SEC);
79
        //double dt = ((double)t)/(double)CLOCKS_PER_SEC;
80
        printf("Time taken: %d/%d \n", t, CLOCKS_PER_SEC);
81
        sprite_dtor(shooter1);
82
    #endif
83

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

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

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

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

    
126
                    break;
127
                default:
128
                    break; /* no other notifications expected: do nothing */
129
            }
130
        } else { /* received standart message, not a notification */
131
            /* no standart message expected: do nothing */
132
        }
133

    
134
        switch (get_hor_movement()) {
135
            case LEFT:
136
                printf("GOING LEFT.\n");
137
                break;
138
            case RIGHT:
139
                printf("GOING RIGHT.\n");
140
                break;
141
        }
142
        switch (get_ver_movement()) {
143
            case UP:
144
                printf("GOING UP.\n");
145
                break;
146
            case DOWN:
147
                printf("GOING DOWN.\n");
148
                break;
149
        }
150
    }
151

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

    
159

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

    
165
    return 0;
166
}