Project

General

Profile

Statistics
| Revision:

root / proj / src / proj.c @ 189

History | View | Annotate | Download (5.91 KB)

1 144 up20180655
#include <lcom/lcf.h>
2
#include <lcom/proj.h>
3
#include <lcom/liblm.h>
4 185 up20180655
#include <math.h>
5 144 up20180655
6 149 up20180655
#include "proj_macros.h"
7 179 up20180642
#include "proj_func.h"
8 147 up20180655
9 149 up20180655
#include "kbc.h"
10
#include "timer.h"
11
#include "keyboard.h"
12 150 up20180655
#include "mouse.h"
13 189 up20180655
#include "graph.h"
14 153 up20180655
#include "interrupts_func.h"
15 149 up20180655
16 179 up20180642
#include "graph.h"
17
#include "sprite.h"
18
#include "rectangle.h"
19 182 up20180642
#include "font.h"
20 168 up20180642
21 183 up20180642
#ifdef DIOGO
22
    #include "shooter.h"
23
#endif
24
25 171 up20180655
#ifdef TELMO
26
    #include "crosshair.h"
27 184 up20180655
    #include "shooter.h"
28 171 up20180655
#endif
29 157 up20180642
30 144 up20180655
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 189 up20180655
    lcf_log_output("/home/lcom/labs/proj/output.txt");
37 144 up20180655
38
    if (lcf_start(argc, argv)) return 1;
39
40
    lcf_cleanup();
41
42
    return 0;
43
}
44 147 up20180655
45 149 up20180655
int(proj_main_loop)(int argc, char *argv[]) {
46 170 up20180642
47
    int r;
48
49
    /// subscribe interrupts
50
    if (subscribe_all()) { return 1; }
51
52
    /// initialize graphics
53 166 up20180642
    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 152 up20180642
        return 1;
57
    }
58
59 188 up20180642
    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 159 up20180642
    #ifdef DIOGO
70 188 up20180642
        graph_clear_screen();
71 183 up20180642
72 188 up20180642
        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 179 up20180642
        rectangle_set_outline_width(rect, 2);
78 188 up20180642
        rectangle_set_outline_color(rect, WHITE);
79 179 up20180642
        rectangle_draw(rect);
80
81 188 up20180642
        text_t *txt  = text_ctor(consolas, "Hello world!");
82
        text_set_color(txt, 0x888888);
83 182 up20180642
84 188 up20180642
        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 183 up20180642
        text_draw(txt);
89
        text_dtor(txt);
90
91
        graph_draw();
92 188 up20180642
        rectangle_dtor(rect);
93 183 up20180642
94
        tickdelay(micros_to_ticks(1000000));
95
96 159 up20180642
    #endif
97 152 up20180642
98 171 up20180655
    #ifdef TELMO
99 174 up20180642
        sprite_t *crosshair = get_crosshair();
100 184 up20180655
        sprite_t *shooter1 = get_shooter();
101 189 up20180655
        sprite_set_pos(shooter1, graph_get_XRes()/2, graph_get_YRes()/2);
102 174 up20180642
        graph_clear_screen();
103
        sprite_draw(crosshair);
104 184 up20180655
        sprite_draw(shooter1);
105 174 up20180642
        graph_draw();
106 171 up20180655
    #endif
107
108 149 up20180655
    /// loop stuff
109 170 up20180642
    int ipc_status;
110 149 up20180655
    message msg;
111 147 up20180655
    int good = 1;
112 168 up20180642
113 183 up20180642
    #ifdef DIOGO
114
        good = 0;
115
    #endif
116
117 147 up20180655
    while (good) {
118
        /* Get a request message. */
119
        if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) {
120
            printf("driver_receive failed with %d", r);
121
            continue;
122
        }
123
        if (is_ipc_notify(ipc_status)) { /* received notification */
124
            switch (_ENDPOINT_P(msg.m_source)) {
125
                case HARDWARE: /* hardware interrupt notification */
126 153 up20180655
                    for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) {
127
                        if (msg.m_notify.interrupts & n) {
128
                            interrupt_handler(i);
129 167 up20180655
                            if ((scancode[0]) == ESC_BREAK_CODE) good = 0;
130 171 up20180655
                            #ifdef TELMO
131 187 up20180655
                            if (i == 0) {
132
                                uint32_t refresh_count_value = sys_hz() / REFRESH_RATE;
133
                                if (no_interrupts % refresh_count_value == 0) {
134
                                    update_movement(shooter1);
135
                                    sprite_set_pos(crosshair, get_mouse_X(), get_mouse_Y());
136
                                    double angle = get_mouse_angle(shooter1);
137
                                    sprite_set_angle(shooter1, angle - M_PI_2);
138
                                    graph_clear_screen();
139
                                    sprite_draw(crosshair);
140
                                    sprite_draw(shooter1);
141
                                    graph_draw();
142
                                }
143 184 up20180655
                            }
144 171 up20180655
                            #endif
145 153 up20180655
                        }
146 147 up20180655
                    }
147 187 up20180655
                    #ifdef TELMO
148
                    if (counter_mouse_ih >= 3) {
149
                        struct packet pp = mouse_parse_packet(packet_mouse_ih);
150
                        update_mouse_position(&pp);
151 189 up20180655
                        //printf("X: %d Y: %d\n", get_mouse_X(), get_mouse_Y());
152 187 up20180655
                        counter_mouse_ih = 0;
153
                    }
154
                    #endif
155 167 up20180655
156 147 up20180655
                    break;
157
                default:
158
                    break; /* no other notifications expected: do nothing */
159
            }
160
        } else { /* received standart message, not a notification */
161
            /* no standart message expected: do nothing */
162
        }
163 174 up20180642
        #ifdef TELMO
164
            switch (get_hor_movement()) {
165
                case LEFT:
166
                    printf("GOING LEFT.\n");
167
                    break;
168
                case RIGHT:
169
                    printf("GOING RIGHT.\n");
170
                    break;
171
            }
172
            switch (get_ver_movement()) {
173
                case UP:
174
                    printf("GOING UP.\n");
175
                    break;
176
                case DOWN:
177
                    printf("GOING DOWN.\n");
178
                    break;
179
            }
180
        #endif
181 147 up20180655
    }
182 149 up20180655
183 188 up20180642
    font_dtor(consolas);
184
185 153 up20180655
    // Unsubscribe interrupts
186 155 up20180655
    if (unsubscribe_all()) {
187
        if (cleanup())
188
            printf("%s: failed to cleanup.\n", __func__);
189 152 up20180642
        return 1;
190
    }
191
192 155 up20180655
193
    if (cleanup()) {
194
        printf("%s: failed to cleanup.\n", __func__);
195 152 up20180642
        return 1;
196
    }
197
198 149 up20180655
    return 0;
199 147 up20180655
}