Rev 1373 | Rev 1378 | 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 | |||
1373 | giacomo | 19 | volatile int shark_running = 1; |
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 | |||
1373 | giacomo | 68 | shark_running = 0; |
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 | |||
1162 | tavani | 109 | int main(int argc, char **argv) |
110 | { |
||
111 | KEY_EVT k; |
||
112 | TIME seme; |
||
113 | |||
1373 | giacomo | 114 | device_drivers_init(); |
115 | |||
1162 | tavani | 116 | k.flag = CNTR_BIT; |
117 | k.scan = KEY_C; |
||
118 | k.ascii = 'c'; |
||
1349 | giacomo | 119 | k.status = KEY_PRESSED; |
120 | keyb_hook(k,end_func,FALSE); |
||
1162 | tavani | 121 | |
122 | k.flag = CNTL_BIT; |
||
123 | k.scan = KEY_C; |
||
124 | k.ascii = 'c'; |
||
1349 | giacomo | 125 | k.status = KEY_PRESSED; |
126 | keyb_hook(k,end_func,FALSE); |
||
1162 | tavani | 127 | |
128 | sem_init(&mx_mat,0,1); |
||
129 | sem_init(&mx_grf,0,1); |
||
130 | sem_init(&mx_pos,0,1); |
||
131 | sem_init(&mx_vel,0,1); |
||
132 | sem_init(&mx_xy ,0,1); |
||
133 | sem_init(&mx_rk ,0,1); |
||
134 | sem_init(&mx_rn ,0,1); |
||
135 | sem_init(&mx_st_scr,0,1); |
||
136 | sem_init(&mx_st_nrg,0,1); |
||
137 | sem_init(&mx_st_kil,0,1); |
||
138 | sem_init(&mx_st_liv,0,1); |
||
139 | |||
140 | seme = sys_gettime(NULL); |
||
141 | srand(seme); |
||
142 | |||
143 | frame_main(); |
||
144 | |||
145 | init_stat(); |
||
146 | init_astro(); |
||
147 | init_rock(); |
||
148 | |||
1373 | giacomo | 149 | while(shark_running); |
150 | |||
151 | device_drivers_close(); |
||
152 | |||
1376 | giacomo | 153 | sys_shutdown_message("-- S.Ha.R.K. Closed --\n"); |
154 | |||
1373 | giacomo | 155 | sys_end(); |
156 | |||
1162 | tavani | 157 | return 0; |
1373 | giacomo | 158 | |
1162 | tavani | 159 | } |