Project

General

Profile

Statistics
| Revision:

root / proj / proj.c @ 171

History | View | Annotate | Download (4.55 KB)

1 144 up20180655
#include <lcom/lcf.h>
2
#include <lcom/proj.h>
3
#include <lcom/liblm.h>
4
5 147 up20180655
#include <stdbool.h>
6 144 up20180655
#include <stdint.h>
7
8 149 up20180655
#include "i8254.h"
9
#include "kbc_macros.h"
10 166 up20180642
#include "graph_macros.h"
11 150 up20180655
#include "mouse_macros.h"
12 149 up20180655
#include "proj_macros.h"
13
#include "errors.h"
14 147 up20180655
15 159 up20180642
#include "sprite.h"
16 149 up20180655
#include "kbc.h"
17 166 up20180642
#include "graph.h"
18 149 up20180655
#include "timer.h"
19
#include "keyboard.h"
20 150 up20180655
#include "mouse.h"
21 149 up20180655
#include "utils.h"
22 153 up20180655
#include "interrupts_func.h"
23 155 up20180655
#include "proj_func.h"
24 149 up20180655
25 168 up20180642
#include "fast_math.h"
26
#include <math.h>
27
28 157 up20180642
#ifdef DIOGO
29 162 up20180642
    #include "shooter.h"
30 160 up20180642
    #include "pistol.xpm"
31 157 up20180642
#endif
32 171 up20180655
#ifdef TELMO
33
    #include "crosshair.h"
34
#endif
35 157 up20180642
36 144 up20180655
int main(int argc, char* argv[]) {
37
38
    lcf_set_language("EN-US");
39
40
    //lcf_trace_calls("/home/lcom/labs/proj/trace.txt");
41
42
    //lcf_log_output("/home/lcom/labs/proj/output.txt");
43
44
    if (lcf_start(argc, argv)) return 1;
45
46
    lcf_cleanup();
47
48
    return 0;
49
}
50 147 up20180655
51 149 up20180655
int(proj_main_loop)(int argc, char *argv[]) {
52 170 up20180642
53
    int r;
54
55
    /// subscribe interrupts
56
    if (subscribe_all()) { return 1; }
57
58
    /// initialize graphics
59 166 up20180642
    if(graph_init(GRAPH_MODE)){
60
        printf("%s: failed to initalize graphics.\n", __func__);
61
        if (cleanup()) printf("%s: failed to cleanup.\n", __func__);
62 152 up20180642
        return 1;
63
    }
64
65 159 up20180642
    #ifdef DIOGO
66 168 up20180642
        printf("%d\n", 1000000-(int)(1000000*fm_sin(0.5*M_PI)));
67
        printf("%d\n", (int)(1000000*fm_cos(0.5*M_PI)));
68
69
        clock_t t = clock();
70 162 up20180642
        sprite_t *shooter1 = get_shooter(); sprite_set_pos(shooter1, 100, 100);
71 168 up20180642
        for(double angle = 0; angle <= 6.283185; angle += 0.006283185){
72 162 up20180642
             sprite_set_angle(shooter1, angle);
73 168 up20180642
             //graph_paint_screen(0x777777);
74
             graph_clear_screen();
75 162 up20180642
             sprite_draw(shooter1);
76 168 up20180642
             graph_draw();
77 160 up20180642
        }
78 168 up20180642
        t = clock() - t; //printf("%d\n", CLOCKS_PER_SEC);
79
        //double dt = ((double)t)/(double)CLOCKS_PER_SEC;
80
        printf("Time taken: %d/%d \n", t, CLOCKS_PER_SEC);
81 162 up20180642
        sprite_dtor(shooter1);
82 159 up20180642
    #endif
83 152 up20180642
84 171 up20180655
    #ifdef TELMO
85
    sprite_t *crosshair = get_crosshair();
86
    graph_clear_screen();
87
    sprite_draw(crosshair);
88
    graph_draw();
89
    #endif
90
91 149 up20180655
    /// loop stuff
92 170 up20180642
    int ipc_status;
93 149 up20180655
    message msg;
94 147 up20180655
    int good = 1;
95 168 up20180642
96
    #ifdef DIOGO
97
        good = 0;
98
    #endif
99
100 147 up20180655
    while (good) {
101
        /* Get a request message. */
102
        if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) {
103
            printf("driver_receive failed with %d", r);
104
            continue;
105
        }
106
        if (is_ipc_notify(ipc_status)) { /* received notification */
107
            switch (_ENDPOINT_P(msg.m_source)) {
108
                case HARDWARE: /* hardware interrupt notification */
109 153 up20180655
                    for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) {
110
                        if (msg.m_notify.interrupts & n) {
111
                            interrupt_handler(i);
112 167 up20180655
                            if ((scancode[0]) == ESC_BREAK_CODE) good = 0;
113 171 up20180655
                            #ifdef TELMO
114
                            if (counter_mouse_ih >= 3) {
115
                                struct packet pp = mouse_parse_packet(packet_mouse_ih);
116
                                update_mouse_position(&pp);
117
                                sprite_set_pos(crosshair, get_mouse_X(), get_mouse_Y());
118
                                graph_clear_screen();
119
                                sprite_draw(crosshair);
120
                                graph_draw();
121
                            }
122
                            #endif
123 153 up20180655
                        }
124 147 up20180655
                    }
125 167 up20180655
126 147 up20180655
                    break;
127
                default:
128
                    break; /* no other notifications expected: do nothing */
129
            }
130
        } else { /* received standart message, not a notification */
131
            /* no standart message expected: do nothing */
132
        }
133 167 up20180655
134
        switch (get_hor_movement()) {
135
            case LEFT:
136
                printf("GOING LEFT.\n");
137
                break;
138
            case RIGHT:
139
                printf("GOING RIGHT.\n");
140
                break;
141
        }
142
        switch (get_ver_movement()) {
143
            case UP:
144
                printf("GOING UP.\n");
145
                break;
146
            case DOWN:
147
                printf("GOING DOWN.\n");
148
                break;
149
        }
150 147 up20180655
    }
151 149 up20180655
152 153 up20180655
    // Unsubscribe interrupts
153 155 up20180655
    if (unsubscribe_all()) {
154
        if (cleanup())
155
            printf("%s: failed to cleanup.\n", __func__);
156 152 up20180642
        return 1;
157
    }
158
159 155 up20180655
160
    if (cleanup()) {
161
        printf("%s: failed to cleanup.\n", __func__);
162 152 up20180642
        return 1;
163
    }
164
165 149 up20180655
    return 0;
166 147 up20180655
}