Project

General

Profile

Statistics
| Revision:

root / proj / src / proj.c @ 179

History | View | Annotate | Download (5.12 KB)

1 144 up20180655
#include <lcom/lcf.h>
2
#include <lcom/proj.h>
3
#include <lcom/liblm.h>
4
5 149 up20180655
#include "proj_macros.h"
6 179 up20180642
#include "proj_func.h"
7 147 up20180655
8 149 up20180655
#include "kbc.h"
9
#include "timer.h"
10
#include "keyboard.h"
11 150 up20180655
#include "mouse.h"
12 153 up20180655
#include "interrupts_func.h"
13 149 up20180655
14 179 up20180642
#include "graph.h"
15
#include "sprite.h"
16
#include "rectangle.h"
17 168 up20180642
18 157 up20180642
#ifdef DIOGO
19 162 up20180642
    #include "shooter.h"
20 157 up20180642
#endif
21 171 up20180655
#ifdef TELMO
22
    #include "crosshair.h"
23
#endif
24 157 up20180642
25 144 up20180655
int main(int argc, char* argv[]) {
26
27
    lcf_set_language("EN-US");
28
29
    //lcf_trace_calls("/home/lcom/labs/proj/trace.txt");
30
31
    //lcf_log_output("/home/lcom/labs/proj/output.txt");
32
33
    if (lcf_start(argc, argv)) return 1;
34
35
    lcf_cleanup();
36
37
    return 0;
38
}
39 147 up20180655
40 149 up20180655
int(proj_main_loop)(int argc, char *argv[]) {
41 170 up20180642
42
    int r;
43
44
    /// subscribe interrupts
45
    if (subscribe_all()) { return 1; }
46
47
    /// initialize graphics
48 166 up20180642
    if(graph_init(GRAPH_MODE)){
49
        printf("%s: failed to initalize graphics.\n", __func__);
50
        if (cleanup()) printf("%s: failed to cleanup.\n", __func__);
51 152 up20180642
        return 1;
52
    }
53
54 159 up20180642
    #ifdef DIOGO
55 174 up20180642
        //printf("%d\n", 1000000-(int)(1000000*fm_sin(0.5*M_PI)));
56
        //printf("%d\n", (int)(1000000*fm_cos(0.5*M_PI)));
57
        /*
58 168 up20180642
        clock_t t = clock();
59 162 up20180642
        sprite_t *shooter1 = get_shooter(); sprite_set_pos(shooter1, 100, 100);
60 168 up20180642
        for(double angle = 0; angle <= 6.283185; angle += 0.006283185){
61 162 up20180642
             sprite_set_angle(shooter1, angle);
62 168 up20180642
             graph_clear_screen();
63 162 up20180642
             sprite_draw(shooter1);
64 168 up20180642
             graph_draw();
65 160 up20180642
        }
66 174 up20180642
        t = clock() - t;
67 168 up20180642
        printf("Time taken: %d/%d \n", t, CLOCKS_PER_SEC);
68 162 up20180642
        sprite_dtor(shooter1);
69 174 up20180642
        */
70 179 up20180642
        /*
71
        rectangle_t *rect = rectangle_ctor(100, 100, 100, 100);
72
        rectangle_set_fill_color   (rect, 0x0000FF);
73
        rectangle_set_outline_color(rect, 0xFF0000);
74
        rectangle_set_outline_width(rect, 0);
75
        rectangle_draw(rect);
76
        rectangle_set_pos(rect, 205, 100);
77
        rectangle_set_outline_width(rect, 1);
78
        rectangle_draw(rect);
79
        rectangle_set_pos(rect, 310, 100);
80
        rectangle_set_outline_width(rect, 2);
81
        rectangle_draw(rect);
82
        rectangle_set_pos(rect, 415, 100);
83
        rectangle_set_outline_width(rect, 3);
84
        rectangle_draw(rect);
85

86
        graph_draw();
87
        */
88 159 up20180642
    #endif
89 152 up20180642
90 171 up20180655
    #ifdef TELMO
91 174 up20180642
        sprite_t *crosshair = get_crosshair();
92
        graph_clear_screen();
93
        sprite_draw(crosshair);
94
        graph_draw();
95 171 up20180655
    #endif
96
97 149 up20180655
    /// loop stuff
98 170 up20180642
    int ipc_status;
99 149 up20180655
    message msg;
100 147 up20180655
    int good = 1;
101 168 up20180642
102 147 up20180655
    while (good) {
103
        /* Get a request message. */
104
        if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) {
105
            printf("driver_receive failed with %d", r);
106
            continue;
107
        }
108
        if (is_ipc_notify(ipc_status)) { /* received notification */
109
            switch (_ENDPOINT_P(msg.m_source)) {
110
                case HARDWARE: /* hardware interrupt notification */
111 153 up20180655
                    for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) {
112
                        if (msg.m_notify.interrupts & n) {
113
                            interrupt_handler(i);
114 167 up20180655
                            if ((scancode[0]) == ESC_BREAK_CODE) good = 0;
115 171 up20180655
                            #ifdef TELMO
116
                            if (counter_mouse_ih >= 3) {
117
                                struct packet pp = mouse_parse_packet(packet_mouse_ih);
118
                                update_mouse_position(&pp);
119
                                sprite_set_pos(crosshair, get_mouse_X(), get_mouse_Y());
120 173 up20180655
                                printf("X: %d | Y: %d | XRES: %d | YRES: %d\n", get_mouse_X(), get_mouse_Y(), graph_get_XRes(), graph_get_YRes());
121 171 up20180655
                                graph_clear_screen();
122
                                sprite_draw(crosshair);
123
                                graph_draw();
124 173 up20180655
                                counter_mouse_ih = 0;
125 171 up20180655
                            }
126
                            #endif
127 153 up20180655
                        }
128 147 up20180655
                    }
129 167 up20180655
130 147 up20180655
                    break;
131
                default:
132
                    break; /* no other notifications expected: do nothing */
133
            }
134
        } else { /* received standart message, not a notification */
135
            /* no standart message expected: do nothing */
136
        }
137 174 up20180642
        #ifdef TELMO
138
            switch (get_hor_movement()) {
139
                case LEFT:
140
                    printf("GOING LEFT.\n");
141
                    break;
142
                case RIGHT:
143
                    printf("GOING RIGHT.\n");
144
                    break;
145
            }
146
            switch (get_ver_movement()) {
147
                case UP:
148
                    printf("GOING UP.\n");
149
                    break;
150
                case DOWN:
151
                    printf("GOING DOWN.\n");
152
                    break;
153
            }
154
        #endif
155 147 up20180655
    }
156 149 up20180655
157 153 up20180655
    // Unsubscribe interrupts
158 155 up20180655
    if (unsubscribe_all()) {
159
        if (cleanup())
160
            printf("%s: failed to cleanup.\n", __func__);
161 152 up20180642
        return 1;
162
    }
163
164 155 up20180655
165
    if (cleanup()) {
166
        printf("%s: failed to cleanup.\n", __func__);
167 152 up20180642
        return 1;
168
    }
169
170 149 up20180655
    return 0;
171 147 up20180655
}