Subversion Repositories shark

Rev

Rev 1373 | 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
/*
1349 giacomo 2
 * Project: S.Ha.R.K.
1162 tavani 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://hartik.sssup.it
11
 */
12
 
13
#include <kernel/func.h>
14
#include <stdlib.h>
15
#include <semaphore.h>
16
#include "modules/sem.h"
17
#include "modules/hartport.h"
18
 
1373 giacomo 19
#include <drivers/shark_pci26.h>
20
#include <drivers/shark_linuxc26.h>
21
#include <drivers/shark_input26.h>
1349 giacomo 22
#include <drivers/shark_keyb26.h>
23
#include <drivers/shark_fb26.h>
24
 
1162 tavani 25
#include <math.h>
26
 
27
#define ASTRO_MOVE/* If defined then astro else defender */
28
 
1349 giacomo 29
#define FRAME_BUFFER_DEVICE 0
30
 
1162 tavani 31
// DA CALCOLARE
32
#define RGB_BLACK     rgb16(  0,  0,  0)
33
#define RGB_GRAY      rgb16(127,127,127)
34
#define RGB_WHITE     rgb16(255,255,255)
35
#define RGB_RED       rgb16(255,  0,  0)
36
#define RGB_GREEN     rgb16(  0,255,  0)
37
#define RGB_BLUE      rgb16(  0,  0,255)
38
#define RGB_YELLOW    rgb16(255,255,  0)
39
#define RGB_MAGENTA   rgb16(255,  0,255)
40
#define RGB_CYAN      rgb16(  0,255,255)
41
#define RGB_D_RED     rgb16(127,  0,  0)
42
#define RGB_D_GREEN   rgb16(  0,127,  0)
43
#define RGB_D_BLUE    rgb16(  0,  0,127)
44
#define RGB_D_YELLOW  rgb16(127,127,  0)
45
#define RGB_D_MAGENTA rgb16(127,  0,127)
46
#define RGB_D_CYAN    rgb16(  0,127,127)
47
 
48
#define LIVE_0 "      "
49
#define LIVE_1 "     *"
50
#define LIVE_2 "    **"
51
#define LIVE_3 "   ***"
52
#define LIVE_4 "  ****"
53
#define LIVE_5 " *****"
54
#define LIVE_6 "******"
55
#define LIVE_X "------"
56
 
57
/* GameBoard constants */
58
#define GB_YMIN             65               /* position of the top */
59
#define GB_YMAX            460               /* position of the bottom */
60
#define GB_XMIN              5               /* min position X of the asteroid */
61
#define GB_XMAX            505               /* max position X of the asteroid */
62
 
63
/* Asteroid constants */
64
#define ASTEROID_RADIUS      4               /* radius of the asteroid */
65
#define ASTEROID_NMAX       60               /* max number of asteroids */
66
 
67
#define ASTEROID_GROUP       2               /* task group of asteroids */
68
 
69
/* Astro constants */
70
#ifdef ASTRO_MOVE
71
#define ASTRO_Y        (GB_YMAX+GB_YMIN)/2   /* Y position of the astro */
72
#else
73
#define ASTRO_Y        GB_YMAX-22            /* Y position of the astro */
74
#endif
75
#define ASTRO_X        (GB_XMAX+GB_XMIN)/2   /* X position of the astro */
76
#define ASTRO_MAX_VEL  ASTRO_VEL_INC*5       /* Max astro velocity */
77
#ifdef ASTRO_MOVE
78
#define ASTRO_MAX_GRAD     180               /* Max astro angle */
79
#else
80
#define ASTRO_MAX_GRAD      80               /* Max astro angle */
81
#endif
82
#define ASTRO_GRAD_INC      10               /* angular variation */
83
#define ASTRO_VEL_INC        3               /* velocity variation */
84
#define ASTRO_RADIUS        16               /* Dimension of the astro */
85
#define ASTRO_PERIOD     10000
86
#define ASTRO_MOVE_PERIOD 5000
87
#define ASTRO_WCET         300
88
 
89
/* Shot constants */
90
#define SHOT_RADIUS          1               /* radius of the shot */
91
#define SHOT_VEL            35               /* speed of the shot */
92
#define SHOT_NMAX           30               /* max number of shots */
93
 
94
#define SHOT_GROUP           3               /* task group of shots */
95
 
96
#define SHOT_PERIOD      10000
97
#define SHOT_WCET          500
98
 
99
/* Rock constants */
100
#define ROCK_RADIUS_I        8               /* initial radius of the rock */
101
#define ROCK_RADIUS_S        4               /* radius of the rock after one shot */
102
#define ROCK_VEL             6               /* speed of the rock */
103
#define ROCK_NMAX            8               /* max number of rocks */
104
 
105
#define ROCK_GROUP           4               /* task group of rocks */
106
 
107
#define ROCK_PERIOD      20000
108
#define ROCK_WCET          500
109
 
110
/* Statistic constants */
111
#define ENERGY_INIT        200
112
#define ENERGY_SHOT          2
113
#define ENERGY_GOT          10
114
#define SCORE_GOT            2
115
#define LIVES_INIT           3
116
 
117
#define STAT_PERIOD     400000
118
#define STAT_WCET          400
119
 
120
/* Statistic constants */
1376 giacomo 121
#define LOOK_PERIOD      10000
122
#define LOOK_WCET         4000
1162 tavani 123
 
124
typedef struct {
125
        PID pid;
126
        int x, y, r;
127
} rock_pos;
128
 
129
typedef struct {
130
        int i;
131
        int x, y, r;
132
} rock_ini;
133
 
134
double dist_xy(int x1, int y1, int x2, int y2);
135
void draw_rock(int x, int y, int r, int c);
136
void rock_create(rock_ini* ri);
137
void frame_astro();
138
void frame_stat();
139
void init_astro();
140
void init_stat();
141
void init_rock();
142
void reset_astro();
143
void reset_rock();
144
void start_astro();
145
void start_rock();
146
void reset_game();
147
 
148
extern sem_t  mx_mat, mx_grf;       /* mutex semaphores */
149
extern sem_t  mx_pos, mx_vel;       /* mutex semaphores */
150
extern sem_t  mx_xy, mx_rk, mx_rn;  /* mutex semaphores */
151
extern sem_t  mx_st_scr, mx_st_nrg; /* mutex semaphores */
152
extern sem_t  mx_st_kil, mx_st_liv; /* mutex semaphores */
153
extern int nshot;                   /* number of shot active */
154
extern int nrock;                   /* number of rock active */
155
extern int astro_x, astro_y;        /* astro position */
156
extern int astro_grad;              /* astro angolar position */
157
extern int astro_vel;               /* astro velocity */
158
extern int score;                   /* current player score */
159
extern int energy;                  /* current player energy */
160
extern int enemy;                   /* current player strikes */
161
extern int lives;                   /* current player lives*/
162
extern int kill_rock;               /* kill active rocks */
163
extern int kill_shot;               /* kill active shots */
164
extern int freez_astro;             /* turn of control pad */
165
extern int crash;                   /* astro vs. rock */
166
extern rock_pos rocks[ROCK_NMAX];   /* rocks position */
167
extern rock_ini rock_new;