Project

General

Profile

Statistics
| Revision:

root / proj / proj.c @ 170

History | View | Annotate | Download (3.8 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

    
50
    int r;
51

    
52
    /// subscribe interrupts
53
    if (subscribe_all()) { return 1; }
54

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

    
62
    #ifdef DIOGO
63
        printf("%d\n", 1000000-(int)(1000000*fm_sin(0.5*M_PI)));
64
        printf("%d\n", (int)(1000000*fm_cos(0.5*M_PI)));
65

    
66
        clock_t t = clock();
67
        sprite_t *shooter1 = get_shooter(); sprite_set_pos(shooter1, 100, 100);
68
        for(double angle = 0; angle <= 6.283185; angle += 0.006283185){
69
             sprite_set_angle(shooter1, angle);
70
             //graph_paint_screen(0x777777);
71
             graph_clear_screen();
72
             sprite_draw(shooter1);
73
             graph_draw();
74
        }
75
        t = clock() - t; //printf("%d\n", CLOCKS_PER_SEC);
76
        //double dt = ((double)t)/(double)CLOCKS_PER_SEC;
77
        printf("Time taken: %d/%d \n", t, CLOCKS_PER_SEC);
78
        sprite_dtor(shooter1);
79
    #endif
80

    
81
    /// loop stuff
82
    int ipc_status;
83
    message msg;
84
    int good = 1;
85

    
86
    #ifdef DIOGO
87
        good = 0;
88
    #endif
89

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

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

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

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

    
139

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

    
145
    return 0;
146
}