Project

General

Profile

Statistics
| Revision:

root / proj / proj.c @ 168

History | View | Annotate | Download (3.87 KB)

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

    
5
#include <stdbool.h>
6
#include <stdint.h>
7

    
8
#include "i8254.h"
9
#include "kbc_macros.h"
10
#include "graph_macros.h"
11
#include "mouse_macros.h"
12
#include "proj_macros.h"
13
#include "errors.h"
14

    
15
#include "sprite.h"
16
#include "kbc.h"
17
#include "graph.h"
18
#include "timer.h"
19
#include "keyboard.h"
20
#include "mouse.h"
21
#include "utils.h"
22
#include "interrupts_func.h"
23
#include "proj_func.h"
24

    
25
#include "fast_math.h"
26
#include <math.h>
27

    
28
#ifdef DIOGO
29
    #include "shooter.h"
30
    #include "pistol.xpm"
31
#endif
32

    
33
int main(int argc, char* argv[]) {
34

    
35
    lcf_set_language("EN-US");
36

    
37
    //lcf_trace_calls("/home/lcom/labs/proj/trace.txt");
38

    
39
    //lcf_log_output("/home/lcom/labs/proj/output.txt");
40

    
41
    if (lcf_start(argc, argv)) return 1;
42

    
43
    lcf_cleanup();
44

    
45
    return 0;
46
}
47

    
48
int(proj_main_loop)(int argc, char *argv[]) {
49
    if(graph_init(GRAPH_MODE)){
50
        printf("%s: failed to initalize graphics.\n", __func__);
51
        if (cleanup()) printf("%s: failed to cleanup.\n", __func__);
52
        return 1;
53
    }
54

    
55
    #ifdef DIOGO
56
        printf("%d\n", 1000000-(int)(1000000*fm_sin(0.5*M_PI)));
57
        printf("%d\n", (int)(1000000*fm_cos(0.5*M_PI)));
58

    
59
        clock_t t = clock();
60
        sprite_t *shooter1 = get_shooter(); sprite_set_pos(shooter1, 100, 100);
61
        for(double angle = 0; angle <= 6.283185; angle += 0.006283185){
62
             sprite_set_angle(shooter1, angle);
63
             //graph_paint_screen(0x777777);
64
             graph_clear_screen();
65
             sprite_draw(shooter1);
66
             graph_draw();
67
        }
68
        t = clock() - t; //printf("%d\n", CLOCKS_PER_SEC);
69
        //double dt = ((double)t)/(double)CLOCKS_PER_SEC;
70
        printf("Time taken: %d/%d \n", t, CLOCKS_PER_SEC);
71
        sprite_dtor(shooter1);
72
    #endif
73

    
74
    /// loop stuff
75
    int ipc_status, r;
76
    message msg;
77

    
78
    /// subscribe interrupts
79
    if (subscribe_all()) {
80
        if (cleanup())
81
            printf("%s: failed to cleanup.\n", __func__);
82
        return 1;
83
    }
84

    
85
    /// cycle
86
    int good = 1;
87

    
88
    #ifdef DIOGO
89
        good = 0;
90
    #endif
91

    
92
    while (good) {
93
        /* Get a request message. */
94
        if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) {
95
            printf("driver_receive failed with %d", r);
96
            continue;
97
        }
98
        if (is_ipc_notify(ipc_status)) { /* received notification */
99
            switch (_ENDPOINT_P(msg.m_source)) {
100
                case HARDWARE: /* hardware interrupt notification */
101
                    for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) {
102
                        if (msg.m_notify.interrupts & n) {
103
                            interrupt_handler(i);
104
                            if ((scancode[0]) == ESC_BREAK_CODE) good = 0;
105
                        }
106
                    }
107

    
108
                    break;
109
                default:
110
                    break; /* no other notifications expected: do nothing */
111
            }
112
        } else { /* received standart message, not a notification */
113
            /* no standart message expected: do nothing */
114
        }
115

    
116
        switch (get_hor_movement()) {
117
            case LEFT:
118
                printf("GOING LEFT.\n");
119
                break;
120
            case RIGHT:
121
                printf("GOING RIGHT.\n");
122
                break;
123
        }
124
        switch (get_ver_movement()) {
125
            case UP:
126
                printf("GOING UP.\n");
127
                break;
128
            case DOWN:
129
                printf("GOING DOWN.\n");
130
                break;
131
        }
132
    }
133

    
134
    // Unsubscribe interrupts
135
    if (unsubscribe_all()) {
136
        if (cleanup())
137
            printf("%s: failed to cleanup.\n", __func__);
138
        return 1;
139
    }
140

    
141

    
142
    if (cleanup()) {
143
        printf("%s: failed to cleanup.\n", __func__);
144
        return 1;
145
    }
146

    
147
    return 0;
148
}