Subversion Repositories shark

Rev

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

Rev Author Line No. Line
1085 pj 1
/************************** Simcity ************************/
2
// Main,initialization functions and global variables allocation
3
#include <kernel/func.h>
4
#include <string.h>
5
#include <stdlib.h>
6
#include <drivers/keyb.h>
7
#include <drivers/glib.h>
8
#include <kernel/kern.h>
9
#include <semaphor.h>
10
#include <math.h>
11
#include "include/constant.h"
12
#include "include/misc.h"
13
#include "include/draw.h"
14
#include "include/proc.h"
15
#define rgb rgb16
16
 
17
/* graphic mutex... */
18
sem_t mutex;
19
//kill flag mutexes
20
sem_t kill_mutex[MAX_CAR];
21
 
22
// various sprites to use with grx_putimage()....
23
BYTE vbuf[MAX_CAR][ROW*COL*2];
24
BYTE clrscr[800*600*2];
25
BYTE clrcam[(ROW+2)*(COL+2)*2];
26
BYTE gauge_img[ROW*COL*2];
27
BYTE brk_gauge[ROW*COL*2];
28
BYTE arrow[3][ROW*COL*2];
29
BYTE street[H*W*2];
30
 
31
//task chain pointers
32
car_data *free_n,*free_o,*busy_n,*busy_o;
33
 
34
// various sprites to plot
35
extern DWORD macchine[ROW][COL][NCAR];
36
extern DWORD sprites[ROW][COL][NO_SPRITE];
37
extern DWORD strada[H][W];
38
 
39
//resolution to use
40
WORD r=600;
41
WORD c=800;
42
BYTE bpp=16;
43
 
44
// useful colors...
45
DWORD white;
46
DWORD black;
47
DWORD red;
48
DWORD gray;
49
DWORD blue;
50
DWORD green;
51
DWORD border;
52
DWORD tl_bg;
53
 
54
//PID vectors
55
 
56
PID p_table[MAX_CAR];
57
PID c_table[MAX_CAR];
58
PID g_table[MAX_CAR];
59
PID a_table[MAX_CAR];
60
 
61
char kill_flag[MAX_CAR];
62
float cosine[360],sine[360];
63
 
64
// data structures
65
car_data car_data_array[MAX_CAR];
66
tl_data tl_data_array[MAX_TL];
67
starting_set starting_set_array[S_POINT];
68
 
69
void keyb_h(void);
70
 
71
static void version( void )
72
{
73
  cprintf("\n\nDemo presented by\n");
74
  cprintf("Aguzzi Marco\n");
75
  cprintf("   &\n");
76
  cprintf("Ferrari Fabio\n");
77
}
78
 
79
void demo_exc_handler(int signo, siginfo_t *info, void *extra)
80
{
81
  struct timespec t;
82
 
83
  grx_close();
84
  /* Default action for an kern exception is  */
85
  kern_cli();
86
  ll_gettime(TIME_EXACT, &t),
87
  kern_printf("\nS.Ha.R.K. Exception raised!!!"
88
              "\nTime (s:ns)     :%d:%d"
89
              "\nException number:%d"
90
              "\nPID             :%d\n",
91
              t.tv_sec, t.tv_nsec, info->si_value.sival_int,
92
              info->si_task);
93
  sys_end();
94
}
95
 
96
void my_close(void *arg)
97
{
98
  grx_close();
99
  kern_printf("Shutting down SIMCITY\n");
100
}
101
 
102
int main(int argc, char **argv)
103
{
104
  int i;
105
  char tl_name[4];
106
  struct sigaction action;
107
 
108
  version();
109
 
110
/* Init the standard Hartik exception handler */
111
/* Set the signal action */
112
  action.sa_flags = SA_SIGINFO;
113
  action.sa_sigaction = demo_exc_handler;
114
  action.sa_handler = 0;
115
  sigfillset(&action.sa_mask); /* we block all the other signals... */
116
  if (sigaction(SIGHEXC, &action, NULL) == -1) {
117
    perror("Error initializing signals...");
118
    sys_end();
119
  }
120
  sys_atrunlevel(my_close, NULL, RUNLEVEL_BEFORE_EXIT);
121
 
122
//resetting kill flags
123
  for(i=0;i<MAX_CAR;i++) {
124
    p_table[i]=0;
125
    kill_flag[i]=0;
126
  }
127
 
128
// graphic mode initialization
129
#ifdef GRAPH
130
  if (grx_init() < 1) {
131
    kern_printf("Error initializing graphics\n");
132
    sys_abort(1);
133
  }
134
  if (grx_open(c,r,bpp) < 0) {
135
    kern_printf("GRX Open Err\n");
136
    sys_abort(1);
137
  }
138
  get_images();
139
#endif
140
  srand(sys_gettime(NULL));
141
 
142
//init the graphic mutex
143
  sem_init(&mutex,1,1);
144
//init kill flag mutexes
145
  for(i=0;i<MAX_CAR;i++) sem_init(&(kill_mutex[i]),1,1);
146
//fill sine & cosine lookup tables
147
  fill_table();
148
/*init keys*/
149
  keyb_h();
150
  set_start_point();
151
  tl_init();
152
  init_struct();
153
 
154
/* useful colors ... */
155
  white = rgb(255,255,255);
156
  black = rgb(0,0,0);
157
  red   = rgb(255,0,0);
158
  gray  = rgb(210,210,210);
159
  blue  = rgb(0,0,220);
160
  green = rgb(0,255,0);
161
  border= rgb(128,128,128);
162
  tl_bg= rgb(0,128,0);
163
#ifdef GRAPH
164
/* paint scenario*/
165
  draw_scenario();
166
#endif
167
#ifndef GRAPH
168
  cprintf("Main: max_tl:%d\n",MAX_TL);
169
#endif
170
 
171
//creating refresher,killer and traffic light processes...
172
  ref_create();
173
  killer_create();
174
  for(i=0;i<MAX_TL;i++) {
175
    sprintf(tl_name,"tl%d",i+1);
176
#ifndef GRAPH
177
    cprintf("main:tname=%s",tl_name);
178
#endif
179
    stl_create(tl_name,i);
180
  }
181
  return 0;
182
}