Project

General

Profile

Statistics
| Revision:

root / proj / src / proj.c @ 191

History | View | Annotate | Download (5.94 KB)

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

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

    
9
#include "kbc.h"
10
#include "timer.h"
11
#include "keyboard.h"
12
#include "mouse.h"
13
#include "graph.h"
14
#include "interrupts_func.h"
15

    
16
#include "graph.h"
17
#include "sprite.h"
18
#include "rectangle.h"
19
#include "font.h"
20

    
21
#ifdef DIOGO
22
    #include "shooter.h"
23
#endif
24

    
25
#ifdef TELMO
26
    #include "crosshair.h"
27
    #include "shooter.h"
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
    int r;
48

    
49
    /// subscribe interrupts
50
    if (subscribe_all()) { return 1; }
51

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

    
59
    font_t *consolas = font_ctor("/home/lcom/labs/proj/font/xpm2");
60

    
61
    /// Load stuff
62
    {
63
        graph_clear_screen();
64
        text_t *txt = text_ctor(consolas, "Loading...");
65
        text_draw(txt);
66
        text_dtor(txt);
67
        graph_draw();
68
    }
69
    #ifdef DIOGO
70
        graph_clear_screen();
71

    
72
        rectangle_t *rect = rectangle_ctor(0,0,400,100);
73
        rectangle_set_pos(rect,
74
                          graph_get_XRes()/2    - rectangle_get_w(rect)/2,
75
                          graph_get_YRes()*0.25 - rectangle_get_h(rect)/2);
76
        rectangle_set_fill_color(rect, BLACK);
77
        rectangle_set_outline_width(rect, 2);
78
        rectangle_set_outline_color(rect, WHITE);
79
        rectangle_draw(rect);
80

    
81
        text_t *txt  = text_ctor(consolas, "Hello world!");
82
        text_set_color(txt, 0x888888);
83

    
84
        text_set_pos(txt, rectangle_get_x(rect)+rectangle_get_w(rect)/2,
85
                          rectangle_get_y(rect)+rectangle_get_h(rect)/2);
86
        text_set_valign(txt, text_valign_center);
87
        text_set_halign(txt, text_halign_center);
88
        text_draw(txt);
89
        text_dtor(txt);
90

    
91
        graph_draw();
92
        rectangle_dtor(rect);
93

    
94
        tickdelay(micros_to_ticks(1000000));
95

    
96
    #endif
97

    
98
    #ifdef TELMO
99
        sprite_t *crosshair = get_crosshair();
100
        sprite_t *shooter1 = get_shooter();
101
        sprite_set_pos(shooter1, graph_get_XRes()/2, graph_get_YRes()/2);
102
        sprite_set_scale(shooter1, 4);
103
        graph_clear_screen();
104
        sprite_draw(crosshair);
105
        sprite_draw(shooter1);
106
        graph_draw();
107
    #endif
108

    
109
    /// loop stuff
110
    int ipc_status;
111
    message msg;
112
    int good = 1;
113

    
114
    #ifdef DIOGO
115
        good = 0;
116
    #endif
117

    
118
    while (good) {
119
        /* Get a request message. */
120
        if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) {
121
            printf("driver_receive failed with %d", r);
122
            continue;
123
        }
124
        if (is_ipc_notify(ipc_status)) { /* received notification */
125
            switch (_ENDPOINT_P(msg.m_source)) {
126
                case HARDWARE: /* hardware interrupt notification */
127
                    for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) {
128
                        if (msg.m_notify.interrupts & n) {
129
                            interrupt_handler(i);
130
                            if ((scancode[0]) == ESC_BREAK_CODE) good = 0;
131
                            #ifdef TELMO
132
                            if (i == 0) {
133
                                uint32_t refresh_count_value = sys_hz() / REFRESH_RATE;
134
                                if (no_interrupts % refresh_count_value == 0) {
135
                                    update_movement(shooter1);
136
                                    sprite_set_pos(crosshair, get_mouse_X(), get_mouse_Y());
137
                                    double angle = get_mouse_angle(shooter1);
138
                                    sprite_set_angle(shooter1, angle - M_PI_2);
139
                                    graph_clear_screen();
140
                                    sprite_draw(crosshair);
141
                                    sprite_draw(shooter1);
142
                                    graph_draw();
143
                                }
144
                            }
145
                            #endif
146
                        }
147
                    }
148
                    #ifdef TELMO
149
                    if (counter_mouse_ih >= 3) {
150
                        struct packet pp = mouse_parse_packet(packet_mouse_ih);
151
                        update_mouse_position(&pp);
152
                        //printf("X: %d Y: %d\n", get_mouse_X(), get_mouse_Y());
153
                        counter_mouse_ih = 0;
154
                    }
155
                    #endif
156

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

    
184
    font_dtor(consolas);
185

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

    
193

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

    
199
    return 0;
200
}