Project

General

Profile

Statistics
| Revision:

root / proj / src / proj.c @ 184

History | View | Annotate | Download (6.38 KB)

1
#include <lcom/lcf.h>
2
#include <lcom/proj.h>
3
#include <lcom/liblm.h>
4

    
5
#include "proj_macros.h"
6
#include "proj_func.h"
7

    
8
#include "kbc.h"
9
#include "timer.h"
10
#include "keyboard.h"
11
#include "mouse.h"
12
#include "interrupts_func.h"
13

    
14
#include "graph.h"
15
#include "sprite.h"
16
#include "rectangle.h"
17
#include "font.h"
18

    
19
#ifdef DIOGO
20
    #include "shooter.h"
21
#endif
22

    
23
#ifdef TELMO
24
    #include "crosshair.h"
25
    #include "shooter.h"
26
#endif
27

    
28
int main(int argc, char* argv[]) {
29

    
30
    lcf_set_language("EN-US");
31

    
32
    //lcf_trace_calls("/home/lcom/labs/proj/trace.txt");
33

    
34
    //lcf_log_output("/home/lcom/labs/proj/output.txt");
35

    
36
    if (lcf_start(argc, argv)) return 1;
37

    
38
    lcf_cleanup();
39

    
40
    return 0;
41
}
42

    
43
int(proj_main_loop)(int argc, char *argv[]) {
44

    
45
    int r;
46

    
47
    /// subscribe interrupts
48
    if (subscribe_all()) { return 1; }
49

    
50
    /// initialize graphics
51
    if(graph_init(GRAPH_MODE)){
52
        printf("%s: failed to initalize graphics.\n", __func__);
53
        if (cleanup()) printf("%s: failed to cleanup.\n", __func__);
54
        return 1;
55
    }
56

    
57
    #ifdef DIOGO
58
        //printf("%d\n", 1000000-(int)(1000000*fm_sin(0.5*M_PI)));
59
        //printf("%d\n", (int)(1000000*fm_cos(0.5*M_PI)));
60
        /*
61
        rectangle_t *rect = rectangle_ctor(0,0,graph_get_XRes(), graph_get_YRes());
62
        rectangle_set_fill_color(rect, WHITE);
63

64
        clock_t t = clock();
65
        sprite_t *shooter1 = get_shooter(); sprite_set_pos(shooter1, 100, 100);
66
        for(double angle = 0; angle <= 6.283185; angle += 0.006283185){
67
             sprite_set_angle(shooter1, angle);
68
             graph_clear_screen();
69
             rectangle_draw(rect);
70
             sprite_draw(shooter1);
71
             graph_draw();
72
        }
73
        t = clock() - t;
74
        printf("Time taken: %d/%d \n", t, CLOCKS_PER_SEC);
75
        sprite_dtor(shooter1);
76
        */
77
        /*
78
        rectangle_t *rect = rectangle_ctor(100, 100, 100, 100);
79
        rectangle_set_fill_color   (rect, 0x0000FF);
80
        rectangle_set_outline_color(rect, 0xFF0000);
81
        rectangle_set_outline_width(rect, 0);
82
        rectangle_draw(rect);
83
        rectangle_set_pos(rect, 205, 100);
84
        rectangle_set_outline_width(rect, 1);
85
        rectangle_draw(rect);
86
        rectangle_set_pos(rect, 310, 100);
87
        rectangle_set_outline_width(rect, 2);
88
        rectangle_draw(rect);
89
        rectangle_set_pos(rect, 415, 100);
90
        rectangle_set_outline_width(rect, 3);
91
        rectangle_draw(rect);
92

93
        graph_draw();
94
        */
95

    
96
        font_t      *fnt  = font_ctor("/home/lcom/labs/proj/font/xpm2");
97

    
98

    
99
        rectangle_t *rect = rectangle_ctor(100,100,100, 100);
100
        rectangle_set_fill_color(rect, WHITE);
101
        rectangle_draw(rect);
102
        rectangle_dtor(rect);
103

    
104
        text_t      *txt  = text_ctor(fnt, "Hello world!");
105
        text_set_color(txt, 0x00FF00);
106
        text_set_pos(txt, 100, 100);
107
        text_draw(txt);
108
        text_dtor(txt);
109

    
110
        graph_draw();
111

    
112
        font_dtor(fnt);
113

    
114
        tickdelay(micros_to_ticks(1000000));
115

    
116
    #endif
117

    
118
    #ifdef TELMO
119
        sprite_t *crosshair = get_crosshair();
120
        sprite_t *shooter1 = get_shooter();
121
        sprite_set_pos(shooter1, 100, 100);
122
        graph_clear_screen();
123
        sprite_draw(crosshair);
124
        sprite_draw(shooter1);
125
        graph_draw();
126
    #endif
127

    
128
    /// loop stuff
129
    int ipc_status;
130
    message msg;
131
    int good = 1;
132

    
133
    #ifdef DIOGO
134
        good = 0;
135
    #endif
136

    
137
    while (good) {
138
        /* Get a request message. */
139
        if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) {
140
            printf("driver_receive failed with %d", r);
141
            continue;
142
        }
143
        if (is_ipc_notify(ipc_status)) { /* received notification */
144
            switch (_ENDPOINT_P(msg.m_source)) {
145
                case HARDWARE: /* hardware interrupt notification */
146
                    for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) {
147
                        if (msg.m_notify.interrupts & n) {
148
                            interrupt_handler(i);
149
                            if ((scancode[0]) == ESC_BREAK_CODE) good = 0;
150
                            #ifdef TELMO
151
                            update_movement(shooter1);
152
                            printf("POS: %d %d\n", sprite_get_x(shooter1), sprite_get_y(shooter1));
153
                            if (counter_mouse_ih >= 3) {
154
                                struct packet pp = mouse_parse_packet(packet_mouse_ih);
155
                                update_mouse_position(&pp);
156
                                printf("X: %d | Y: %d | XRES: %d | YRES: %d\n", get_mouse_X(), get_mouse_Y(), graph_get_XRes(), graph_get_YRes());
157
                                counter_mouse_ih = 0;
158
                            }
159

    
160
                            sprite_set_pos(crosshair, get_mouse_X(), get_mouse_Y());
161
                            double angle = get_mouse_angle(shooter1);
162
                            sprite_set_angle(shooter1, angle);
163
                                graph_clear_screen();
164
                                sprite_draw(crosshair);
165
                                sprite_draw(shooter1);
166
                                graph_draw();
167
                            #endif
168
                        }
169
                    }
170

    
171
                    break;
172
                default:
173
                    break; /* no other notifications expected: do nothing */
174
            }
175
        } else { /* received standart message, not a notification */
176
            /* no standart message expected: do nothing */
177
        }
178
        #ifdef TELMO
179
            switch (get_hor_movement()) {
180
                case LEFT:
181
                    printf("GOING LEFT.\n");
182
                    break;
183
                case RIGHT:
184
                    printf("GOING RIGHT.\n");
185
                    break;
186
            }
187
            switch (get_ver_movement()) {
188
                case UP:
189
                    printf("GOING UP.\n");
190
                    break;
191
                case DOWN:
192
                    printf("GOING DOWN.\n");
193
                    break;
194
            }
195
        #endif
196
    }
197

    
198
    // Unsubscribe interrupts
199
    if (unsubscribe_all()) {
200
        if (cleanup())
201
            printf("%s: failed to cleanup.\n", __func__);
202
        return 1;
203
    }
204

    
205

    
206
    if (cleanup()) {
207
        printf("%s: failed to cleanup.\n", __func__);
208
        return 1;
209
    }
210

    
211
    return 0;
212
}