Subversion Repositories shark

Rev

Rev 1376 | Rev 1392 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1162 tavani 1
/*
2
 * Project: S.Ha.R.K.
3
 *
4
 * Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
5
 *
6
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
7
 *
8
 * http://www.sssup.it
9
 * http://retis.sssup.it
10
 * http://shark.sssup.it
11
 */
12
 
13
#include "asteroid.h"
14
#include <kernel/kern.h>
15
 
16
sem_t  mx_mat, mx_grf, mx_pos, mx_vel, mx_xy, mx_rk, mx_rn; /* mutex semaphores */
17
sem_t  mx_st_nrg, mx_st_scr, mx_st_kil, mx_st_liv;          /* mutex semaphores */
18
 
1378 giacomo 19
PID shutdown_task_PID = -1;
1373 giacomo 20
 
1162 tavani 21
double dist_xy(int x1, int y1, int x2, int y2)
22
{
23
        double dst;
24
        int dx, dy;
25
 
26
        dx = x2 - x1;
27
        dy = y2 - y1;
28
        sem_wait(&mx_mat);
29
        dst = sqrt(dx*dx + dy*dy);
30
        sem_post(&mx_mat);
31
 
32
        return dst;
33
 
34
}
35
 
36
void frame_main()
37
{
1350 giacomo 38
 
39
        grx_clear(RGB_BLACK);
40
 
1162 tavani 41
#ifdef ASTRO_MOVE
42
        grx_text("S.Ha.R.K. - Asteroid 2002 RC1", 0, 0, RGB_GREEN, RGB_BLACK );
43
#else
44
        grx_text("S.Ha.R.K. - Defender 2002 RC1", 0, 0, RGB_GREEN, RGB_BLACK );
45
#endif
46
        grx_text("by Marinoni Mauro"            ,24,16, RGB_GREEN, RGB_BLACK );
47
        grx_text("   Scaricabarozzi Mattia"     ,24,24, RGB_GREEN, RGB_BLACK );
48
 
49
        grx_text("Ctrl-C, Ctrr-C: exit"  ,300, 0, RGB_GRAY, RGB_BLACK );
50
        grx_text("O-P : turn left/right" ,300,16, RGB_GRAY, RGB_BLACK );
51
#ifdef ASTRO_MOVE
52
        grx_text("A-Z : speed up/down"   ,300,24, RGB_GRAY, RGB_BLACK );
53
        grx_text("S   : stop engine"     ,300,32, RGB_GRAY, RGB_BLACK );
54
        grx_text("F   : flip astro"      ,300,40, RGB_GRAY, RGB_BLACK );
55
#else
56
        grx_text("Z-X : move left/right" ,300,24, RGB_GRAY, RGB_BLACK );
57
#endif
58
        grx_text("Space : fire"          ,485,16, RGB_GRAY, RGB_BLACK );
59
        grx_text("N     : new game"      ,485,24, RGB_GRAY, RGB_BLACK );
60
        grx_text("B     : begin game"    ,485,32, RGB_GRAY, RGB_BLACK );
61
 
62
        frame_stat();
63
        frame_astro();
64
}
65
 
1349 giacomo 66
void end_func(KEY_EVT *k) {
67
 
1378 giacomo 68
        task_activate(shutdown_task_PID);
1373 giacomo 69
 
70
}
71
 
72
int device_drivers_close() {
73
 
1349 giacomo 74
        FB26_close(FRAME_BUFFER_DEVICE);
75
 
1373 giacomo 76
        KEYB26_close();
77
        INPUT26_close();
78
 
79
        return 0;
80
 
1349 giacomo 81
}
82
 
1373 giacomo 83
int device_drivers_init() {
84
 
85
        KEYB_PARMS kparms = BASE_KEYB;
86
 
87
        LINUXC26_register_module();
88
 
89
        PCI26_init();
90
 
91
        INPUT26_init();
92
 
93
        keyb_def_ctrlC(kparms, NULL);
94
 
95
        KEYB26_init(&kparms);
96
 
97
        FB26_init();
98
 
99
        FB26_open(FRAME_BUFFER_DEVICE);
100
 
101
        FB26_use_grx(FRAME_BUFFER_DEVICE);
102
 
103
        FB26_setmode(FRAME_BUFFER_DEVICE,"640x480-16");
104
 
105
        return 0;
106
 
107
}
108
 
1378 giacomo 109
TASK shutdown_task_body(void *arg) {
110
 
111
        device_drivers_close();
112
 
113
        sys_shutdown_message("-- S.Ha.R.K. Closed --\n");
114
 
115
        sys_end();
116
 
117
        return NULL;
118
 
119
}
120
 
121
void set_shutdown_task() {
122
 
123
        NRT_TASK_MODEL nrt;
124
 
125
        nrt_task_default_model(nrt);
126
 
127
        shutdown_task_PID = task_create("Shutdown Task",shutdown_task_body,&nrt,NULL);
128
        if (shutdown_task_PID == NIL) {
129
                sys_shutdown_message("Error: Cannot create shutdown task\n");
130
                sys_end();
131
        }
132
 
133
}
134
 
1162 tavani 135
int main(int argc, char **argv)
136
{
137
        KEY_EVT k;
138
        TIME seme;
139
 
1378 giacomo 140
        set_shutdown_task();
141
 
1373 giacomo 142
        device_drivers_init();
143
 
1162 tavani 144
        k.flag = CNTR_BIT;
145
        k.scan = KEY_C;
146
        k.ascii = 'c';
1349 giacomo 147
        k.status = KEY_PRESSED;
148
        keyb_hook(k,end_func,FALSE);
1162 tavani 149
 
150
        k.flag = CNTL_BIT;
151
        k.scan = KEY_C;
152
        k.ascii = 'c';
1349 giacomo 153
        k.status = KEY_PRESSED;
154
        keyb_hook(k,end_func,FALSE);
1162 tavani 155
 
156
        sem_init(&mx_mat,0,1);
157
        sem_init(&mx_grf,0,1);
158
        sem_init(&mx_pos,0,1);
159
        sem_init(&mx_vel,0,1);
160
        sem_init(&mx_xy ,0,1);
161
        sem_init(&mx_rk ,0,1);
162
        sem_init(&mx_rn ,0,1);
163
        sem_init(&mx_st_scr,0,1);
164
        sem_init(&mx_st_nrg,0,1);
165
        sem_init(&mx_st_kil,0,1);
166
        sem_init(&mx_st_liv,0,1);
167
 
168
        seme = sys_gettime(NULL);
169
        srand(seme);
170
 
171
        frame_main();
172
 
173
        init_stat();
174
        init_astro();
175
        init_rock();
176
 
177
        return 0;
1373 giacomo 178
 
1162 tavani 179
}