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> |
||
1109 | pj | 9 | #include <semaphore.h> |
1085 | pj | 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 my_close(void *arg) |
||
80 | { |
||
81 | grx_close(); |
||
82 | kern_printf("Shutting down SIMCITY\n"); |
||
83 | } |
||
84 | |||
85 | int main(int argc, char **argv) |
||
86 | { |
||
87 | int i; |
||
88 | char tl_name[4]; |
||
89 | |||
90 | version(); |
||
91 | |||
92 | sys_atrunlevel(my_close, NULL, RUNLEVEL_BEFORE_EXIT); |
||
93 | |||
94 | //resetting kill flags |
||
95 | for(i=0;i<MAX_CAR;i++) { |
||
96 | p_table[i]=0; |
||
97 | kill_flag[i]=0; |
||
98 | } |
||
99 | |||
100 | // graphic mode initialization |
||
101 | #ifdef GRAPH |
||
102 | if (grx_init() < 1) { |
||
103 | kern_printf("Error initializing graphics\n"); |
||
104 | sys_abort(1); |
||
105 | } |
||
106 | if (grx_open(c,r,bpp) < 0) { |
||
107 | kern_printf("GRX Open Err\n"); |
||
108 | sys_abort(1); |
||
109 | } |
||
110 | get_images(); |
||
111 | #endif |
||
112 | srand(sys_gettime(NULL)); |
||
113 | |||
114 | //init the graphic mutex |
||
115 | sem_init(&mutex,1,1); |
||
116 | //init kill flag mutexes |
||
117 | for(i=0;i<MAX_CAR;i++) sem_init(&(kill_mutex[i]),1,1); |
||
118 | //fill sine & cosine lookup tables |
||
119 | fill_table(); |
||
120 | /*init keys*/ |
||
121 | keyb_h(); |
||
122 | set_start_point(); |
||
123 | tl_init(); |
||
124 | init_struct(); |
||
125 | |||
126 | /* useful colors ... */ |
||
127 | white = rgb(255,255,255); |
||
128 | black = rgb(0,0,0); |
||
129 | red = rgb(255,0,0); |
||
130 | gray = rgb(210,210,210); |
||
131 | blue = rgb(0,0,220); |
||
132 | green = rgb(0,255,0); |
||
133 | border= rgb(128,128,128); |
||
134 | tl_bg= rgb(0,128,0); |
||
135 | #ifdef GRAPH |
||
136 | /* paint scenario*/ |
||
137 | draw_scenario(); |
||
138 | #endif |
||
139 | #ifndef GRAPH |
||
140 | cprintf("Main: max_tl:%d\n",MAX_TL); |
||
141 | #endif |
||
142 | |||
143 | //creating refresher,killer and traffic light processes... |
||
144 | ref_create(); |
||
145 | killer_create(); |
||
146 | for(i=0;i<MAX_TL;i++) { |
||
147 | sprintf(tl_name,"tl%d",i+1); |
||
148 | #ifndef GRAPH |
||
149 | cprintf("main:tname=%s",tl_name); |
||
150 | #endif |
||
151 | stl_create(tl_name,i); |
||
152 | } |
||
153 | return 0; |
||
154 | } |