Project

General

Profile

Statistics
| Revision:

root / proj / src / proj.c @ 183

History | View | Annotate | Download (5.89 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
#endif
26

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

    
29
    lcf_set_language("EN-US");
30

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

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

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

    
37
    lcf_cleanup();
38

    
39
    return 0;
40
}
41

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

    
44
    int r;
45

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

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

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

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

92
        graph_draw();
93
        */
94

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

    
97

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

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

    
109
        graph_draw();
110

    
111
        font_dtor(fnt);
112

    
113
        tickdelay(micros_to_ticks(1000000));
114

    
115
    #endif
116

    
117
    #ifdef TELMO
118
        sprite_t *crosshair = get_crosshair();
119
        graph_clear_screen();
120
        sprite_draw(crosshair);
121
        graph_draw();
122
    #endif
123

    
124
    /// loop stuff
125
    int ipc_status;
126
    message msg;
127
    int good = 1;
128

    
129
    #ifdef DIOGO
130
        good = 0;
131
    #endif
132

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

    
161
                    break;
162
                default:
163
                    break; /* no other notifications expected: do nothing */
164
            }
165
        } else { /* received standart message, not a notification */
166
            /* no standart message expected: do nothing */
167
        }
168
        #ifdef TELMO
169
            switch (get_hor_movement()) {
170
                case LEFT:
171
                    printf("GOING LEFT.\n");
172
                    break;
173
                case RIGHT:
174
                    printf("GOING RIGHT.\n");
175
                    break;
176
            }
177
            switch (get_ver_movement()) {
178
                case UP:
179
                    printf("GOING UP.\n");
180
                    break;
181
                case DOWN:
182
                    printf("GOING DOWN.\n");
183
                    break;
184
            }
185
        #endif
186
    }
187

    
188
    // Unsubscribe interrupts
189
    if (unsubscribe_all()) {
190
        if (cleanup())
191
            printf("%s: failed to cleanup.\n", __func__);
192
        return 1;
193
    }
194

    
195

    
196
    if (cleanup()) {
197
        printf("%s: failed to cleanup.\n", __func__);
198
        return 1;
199
    }
200

    
201
    return 0;
202
}