Modified Linux source.
[crow/jumpnbump.git] / menu.c
1 #include "globals.h"
2
3 #define NUM_MESSAGES 25
4
5 char *menu_background;
6
7 char menu_pal[768];
8 char menu_cur_pal[768];
9
10 char message[NUM_MESSAGES][70] = {
11         "Jump 'n Bump",
12         "by Brainchild Design in 1998.",
13         "Code by Mattias Brynervall.",
14         "Graphics by Martin Magnusson",
15         "and Andreas Brynervall.",
16         "Music by Anders Nilsson.",
17         "Linux port by Chuck Mason.",
18         "Visit our homepage at:",
19         "http://www.algonet.se/~mattiasb",
20         "Jump 'n Bump is e-mailware.",
21         "That means you're supposed to send us an e-mail!",
22         "Write for example where you're from",
23         "and what you thought about this game.",
24         "If you do that, you will greatly encourage us",
25         "to make more games for you!",
26         "Send your e-mail to: matbr656@student.liu.se",
27         "Oh, and by the way, there's a lot of secrets!",
28         "If you can't find them, you'd better ask us...",
29         "If you'd like to contact a specific member of BCD,",
30         "these are their e-mail addresses:",
31         "Andreas Brynervall: andreasb@acc.umu.se",
32         "Mattias Brynervall: matbr656@student.liu.se",
33         "Martin Magnusson: marma102@student.liu.se",
34         "Anders Nilsson: equel@swipnet.se",
35         " "
36 };
37
38
39 char menu(void)
40 {
41         int c1;
42         char esc_pressed;
43         char end_loop_flag, new_game_flag, fade_flag;
44         char mod_vol = 0, mod_fade_direction = 0;
45         int cur_message;
46         int fade_dir, fade_count, fade_tick;
47         char fade_pal[48];
48
49         if (menu_init() != 0)
50                 return 1;
51
52         mod_vol = 0;
53         mod_fade_direction = 1;
54         dj_ready_mod(MOD_MENU);
55         dj_set_mod_volume(mod_vol);
56         dj_set_sfx_volume(64);
57         dj_start_mod();
58         dj_set_nosound(0);
59
60         memset(fade_pal, 0, 48);
61         setpalette(240, 16, fade_pal);
62
63         fade_dir = 0;
64         fade_count = 0;
65         fade_tick = 0;
66         cur_message = NUM_MESSAGES - 1;
67
68         main_info.page_info[0].num_pobs = 0;
69         main_info.page_info[1].num_pobs = 0;
70         main_info.view_page = 0;
71         main_info.draw_page = 1;
72
73         esc_pressed = key_pressed(1);
74         end_loop_flag = new_game_flag = 0;
75
76         while (1) {
77
78                 dj_mix();
79                 intr_sysupdate();
80
81                 if (key_pressed(1) == 1 && esc_pressed == 0) {
82                         end_loop_flag = 1;
83                         new_game_flag = 0;
84                         memset(menu_pal, 0, 768);
85                         mod_fade_direction = 0;
86                 } else if (key_pressed(1) == 0)
87                         esc_pressed = 0;
88
89                 if (main_info.mouse_enabled == 1)
90                         read_mouse();
91                 if (main_info.joy_enabled == 1)
92                         read_joy();
93                 for (c1 = 0; c1 < 4; c1++) {
94                         if (end_loop_flag == 1 && new_game_flag == 1) {
95                                 if ((player[c1].x >> 16) > (165 + c1 * 2)) {
96                                         if (player[c1].x_add < 0)
97                                                 player[c1].x_add += 16384;
98                                         else
99                                                 player[c1].x_add += 12288;
100                                         if (player[c1].x_add > 98304L)
101                                                 player[c1].x_add = 98304L;
102                                         player[c1].direction = 0;
103                                         if (player[c1].anim == 0) {
104                                                 player[c1].anim = 1;
105                                                 player[c1].frame = 0;
106                                                 player[c1].frame_tick = 0;
107                                                 player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
108                                         }
109                                         player[c1].enabled = 1;
110                                 }
111                                 if ((c1 == 0 && key_pressed(KEY_PL1_JUMP) == 0) || (c1 == 1 && key_pressed(KEY_PL2_JUMP) == 0) || (c1 == 2 && key_pressed(KEY_PL3_JUMP) == 0) || (c1 == 3 && key_pressed(KEY_PL4_JUMP) == 0)) {
112                                         if (player[c1].y_add < 0) {
113                                                 player[c1].y_add += 32768;
114                                                 if (player[c1].y_add > 0)
115                                                         player[c1].y_add = 0;
116                                         }
117                                 }
118                                 player[c1].y_add += 12288;
119                                 if (player[c1].y_add > 36864 && player[c1].anim != 3) {
120                                         player[c1].anim = 3;
121                                         player[c1].frame = 0;
122                                         player[c1].frame_tick = 0;
123                                         player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
124                                 }
125                                 player[c1].y += player[c1].y_add;
126                                 if ((player[c1].x >> 16) <= (165 + c1 * 2) || (player[c1].x >> 16) >= (208 + c1 * 2)) {
127                                         if ((player[c1].y >> 16) > (160 + c1 * 2)) {
128                                                 player[c1].y = (160L + c1 * 2) << 16;
129                                                 player[c1].y_add = 0;
130                                                 if (player[c1].anim != 0 && player[c1].anim != 1) {
131                                                         player[c1].anim = 0;
132                                                         player[c1].frame = 0;
133                                                         player[c1].frame_tick = 0;
134                                                         player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
135                                                 }
136                                         }
137                                 } else {
138                                         if ((player[c1].y >> 16) > (138 + c1 * 2)) {
139                                                 player[c1].y = (138L + c1 * 2) << 16;
140                                                 player[c1].y_add = 0;
141                                                 if (player[c1].anim != 0 && player[c1].anim != 1) {
142                                                         player[c1].anim = 0;
143                                                         player[c1].frame = 0;
144                                                         player[c1].frame_tick = 0;
145                                                         player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
146                                                 }
147                                                 if ((c1 == 0 && key_pressed(KEY_PL1_JUMP) == 0) || (c1 == 1 && key_pressed(KEY_PL2_JUMP) == 0) || (c1 == 2 && key_pressed(KEY_PL3_JUMP) == 0) || (c1 == 3 && key_pressed(KEY_PL4_JUMP) == 0))
148                                                         player[c1].jump_ready = 1;
149                                         }
150                                 }
151                                 player[c1].x += player[c1].x_add;
152                                 if ((player[c1].y >> 16) > (138 + c1 * 2)) {
153                                         if ((player[c1].x >> 16) > (165 + c1 * 2) && (player[c1].x >> 16) < (190 + c1 * 2)) {
154                                                 player[c1].x = (165L + c1 * 2) << 16;
155                                                 player[c1].x_add = 0;
156                                         }
157                                         if ((player[c1].x >> 16) > (190 + c1 * 2) && (player[c1].x >> 16) < (208 + c1 * 2)) {
158                                                 player[c1].x = (208L + c1 * 2) << 16;
159                                                 player[c1].x_add = 0;
160                                         }
161                                 }
162                         } else {
163                                 if ((c1 == 0 && key_pressed(KEY_PL1_LEFT) == 1 && key_pressed(KEY_PL1_RIGHT) == 1) || (c1 == 1 && key_pressed(KEY_PL2_LEFT) == 1 && key_pressed(KEY_PL2_RIGHT) == 1) || (c1 == 2 && key_pressed(KEY_PL3_LEFT) == 1 && key_pressed(KEY_PL3_RIGHT) == 1) || (c1 == 3 && key_pressed(KEY_PL4_LEFT) == 1 && key_pressed(KEY_PL4_RIGHT) == 1)) {
164                                         if (player[c1].direction == 1) {
165                                                 if ((player[c1].x >> 16) <= (165 + c1 * 2) || (player[c1].x >> 16) >= (208 + c1 * 2)) {
166                                                         if (player[c1].x_add > 0) {
167                                                                 player[c1].x_add -= 16384;
168                                                                 if ((player[c1].y >> 16) >= (160 + c1 * 2))
169                                                                         add_object(OBJ_SMOKE, (player[c1].x >> 16) + 2 + rnd(9), (player[c1].y >> 16) + 13 + rnd(5), 0, -16384 - rnd(8192), OBJ_ANIM_SMOKE, 0);
170                                                         } else
171                                                                 player[c1].x_add -= 12288;
172                                                 }
173                                                 if ((player[c1].x >> 16) > (165 + c1 * 2) && (player[c1].x >> 16) < (208 + c1 * 2)) {
174                                                         if (player[c1].x_add > 0) {
175                                                                 player[c1].x_add -= 16384;
176                                                                 if ((player[c1].y >> 16) >= (138 + c1 * 2))
177                                                                         add_object(OBJ_SMOKE, (player[c1].x >> 16) + 2 + rnd(9), (player[c1].y >> 16) + 13 + rnd(5), 0, -16384 - rnd(8192), OBJ_ANIM_SMOKE, 0);
178                                                         } else
179                                                                 player[c1].x_add -= 12288;
180                                                 }
181                                                 if (player[c1].x_add < -98304L)
182                                                         player[c1].x_add = -98304L;
183                                                 player[c1].direction = 1;
184                                                 if (player[c1].anim == 0) {
185                                                         player[c1].anim = 1;
186                                                         player[c1].frame = 0;
187                                                         player[c1].frame_tick = 0;
188                                                         player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
189                                                 }
190                                         } else {
191                                                 if ((player[c1].x >> 16) <= (165 + c1 * 2) || (player[c1].x >> 16) >= (208 + c1 * 2)) {
192                                                         if (player[c1].x_add < 0) {
193                                                                 player[c1].x_add += 16384;
194                                                                 if ((player[c1].y >> 16) >= (160 + c1 * 2))
195                                                                         add_object(OBJ_SMOKE, (player[c1].x >> 16) + 2 + rnd(9), (player[c1].y >> 16) + 13 + rnd(5), 0, -16384 - rnd(8192), OBJ_ANIM_SMOKE, 0);
196                                                         } else
197                                                                 player[c1].x_add += 12288;
198                                                 }
199                                                 if ((player[c1].x >> 16) > (165 + c1 * 2) && (player[c1].x >> 16) < (208 + c1 * 2)) {
200                                                         if (player[c1].x_add < 0) {
201                                                                 player[c1].x_add += 16384;
202                                                                 if ((player[c1].y >> 16) >= (138 + c1 * 2))
203                                                                         add_object(OBJ_SMOKE, (player[c1].x >> 16) + 2 + rnd(9), (player[c1].y >> 16) + 13 + rnd(5), 0, -16384 - rnd(8192), OBJ_ANIM_SMOKE, 0);
204                                                         } else
205                                                                 player[c1].x_add += 12288;
206                                                 }
207                                                 if (player[c1].x_add > 98304L)
208                                                         player[c1].x_add = 98304L;
209                                                 player[c1].direction = 0;
210                                                 if (player[c1].anim == 0) {
211                                                         player[c1].anim = 1;
212                                                         player[c1].frame = 0;
213                                                         player[c1].frame_tick = 0;
214                                                         player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
215                                                 }
216                                         }
217                                 } else if ((c1 == 0 && key_pressed(KEY_PL1_LEFT) == 1) || (c1 == 1 && key_pressed(KEY_PL2_LEFT) == 1) || (c1 == 2 && key_pressed(KEY_PL3_LEFT) == 1) || (c1 == 3 && key_pressed(KEY_PL4_LEFT) == 1)) {
218                                         if ((player[c1].x >> 16) <= (165 + c1 * 2) || (player[c1].x >> 16) >= (208 + c1 * 2)) {
219                                                 if (player[c1].x_add > 0) {
220                                                         player[c1].x_add -= 16384;
221                                                         if ((player[c1].y >> 16) >= (160 + c1 * 2))
222                                                                 add_object(OBJ_SMOKE, (player[c1].x >> 16) + 2 + rnd(9), (player[c1].y >> 16) + 13 + rnd(5), 0, -16384 - rnd(8192), OBJ_ANIM_SMOKE, 0);
223                                                 } else
224                                                         player[c1].x_add -= 12288;
225                                         }
226                                         if ((player[c1].x >> 16) > (165 + c1 * 2) && (player[c1].x >> 16) < (208 + c1 * 2)) {
227                                                 if (player[c1].x_add > 0) {
228                                                         player[c1].x_add -= 16384;
229                                                         if ((player[c1].y >> 16) >= (138 + c1 * 2))
230                                                                 add_object(OBJ_SMOKE, (player[c1].x >> 16) + 2 + rnd(9), (player[c1].y >> 16) + 13 + rnd(5), 0, -16384 - rnd(8192), OBJ_ANIM_SMOKE, 0);
231                                                 } else
232                                                         player[c1].x_add -= 12288;
233                                         }
234                                         if (player[c1].x_add < -98304L)
235                                                 player[c1].x_add = -98304L;
236                                         player[c1].direction = 1;
237                                         if (player[c1].anim == 0) {
238                                                 player[c1].anim = 1;
239                                                 player[c1].frame = 0;
240                                                 player[c1].frame_tick = 0;
241                                                 player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
242                                         }
243                                 } else if ((c1 == 0 && key_pressed(KEY_PL1_RIGHT) == 1) || (c1 == 1 && key_pressed(KEY_PL2_RIGHT) == 1) || (c1 == 2 && key_pressed(KEY_PL3_RIGHT) == 1) || (c1 == 3 && key_pressed(KEY_PL4_RIGHT) == 1)) {
244                                         if ((player[c1].x >> 16) <= (165 + c1 * 2) || (player[c1].x >> 16) >= (208 + c1 * 2)) {
245                                                 if (player[c1].x_add < 0) {
246                                                         player[c1].x_add += 16384;
247                                                         if ((player[c1].y >> 16) >= (160 + c1 * 2))
248                                                                 add_object(OBJ_SMOKE, (player[c1].x >> 16) + 2 + rnd(9), (player[c1].y >> 16) + 13 + rnd(5), 0, -16384 - rnd(8192), OBJ_ANIM_SMOKE, 0);
249                                                 } else
250                                                         player[c1].x_add += 12288;
251                                         }
252                                         if ((player[c1].x >> 16) > (165 + c1 * 2) && (player[c1].x >> 16) < (208 + c1 * 2)) {
253                                                 if (player[c1].x_add < 0) {
254                                                         player[c1].x_add += 16384;
255                                                         if ((player[c1].y >> 16) >= (138 + c1 * 2))
256                                                                 add_object(OBJ_SMOKE, (player[c1].x >> 16) + 2 + rnd(9), (player[c1].y >> 16) + 13 + rnd(5), 0, -16384 - rnd(8192), OBJ_ANIM_SMOKE, 0);
257                                                 } else
258                                                         player[c1].x_add += 12288;
259                                         }
260                                         if (player[c1].x_add > 98304L)
261                                                 player[c1].x_add = 98304L;
262                                         player[c1].direction = 0;
263                                         if (player[c1].anim == 0) {
264                                                 player[c1].anim = 1;
265                                                 player[c1].frame = 0;
266                                                 player[c1].frame_tick = 0;
267                                                 player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
268                                         }
269                                 } else {
270                                         if (((player[c1].x >> 16) <= (165 + c1 * 2) || (player[c1].x >> 16) >= (208 + c1 * 2)) && (player[c1].y >> 16) >= (160 + c1 * 2)) {
271                                                 if (player[c1].x_add < 0) {
272                                                         player[c1].x_add += 16384;
273                                                         if (player[c1].x_add > 0)
274                                                                 player[c1].x_add = 0;
275                                                         add_object(OBJ_SMOKE, (player[c1].x >> 16) + 2 + rnd(9), (player[c1].y >> 16) + 13 + rnd(5), 0, -16384 - rnd(8192), OBJ_ANIM_SMOKE, 0);
276                                                 } else if (player[c1].x_add > 0) {
277                                                         player[c1].x_add -= 16384;
278                                                         if (player[c1].x_add < 0)
279                                                                 player[c1].x_add = 0;
280                                                         add_object(OBJ_SMOKE, (player[c1].x >> 16) + 2 + rnd(9), (player[c1].y >> 16) + 13 + rnd(5), 0, -16384 - rnd(8192), OBJ_ANIM_SMOKE, 0);
281                                                 }
282                                         }
283                                         if ((((player[c1].x >> 16) > (165 + c1 * 2) && (player[c1].x >> 16) < (208 + c1 * 2)) && (player[c1].y >> 16) >= (138 + c1 * 2))) {
284                                                 if (player[c1].x_add < 0) {
285                                                         player[c1].x_add += 16384;
286                                                         if (player[c1].x_add > 0)
287                                                                 player[c1].x_add = 0;
288                                                         add_object(OBJ_SMOKE, (player[c1].x >> 16) + 2 + rnd(9), (player[c1].y >> 16) + 13 + rnd(5), 0, -16384 - rnd(8192), OBJ_ANIM_SMOKE, 0);
289                                                 } else if (player[c1].x_add > 0) {
290                                                         player[c1].x_add -= 16384;
291                                                         if (player[c1].x_add < 0)
292                                                                 player[c1].x_add = 0;
293                                                         add_object(OBJ_SMOKE, (player[c1].x >> 16) + 2 + rnd(9), (player[c1].y >> 16) + 13 + rnd(5), 0, -16384 - rnd(8192), OBJ_ANIM_SMOKE, 0);
294                                                 }
295                                         }
296                                         if (player[c1].anim == 1) {
297                                                 player[c1].anim = 0;
298                                                 player[c1].frame = 0;
299                                                 player[c1].frame_tick = 0;
300                                                 player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
301                                         }
302                                 }
303                                 if (player[c1].jump_ready == 1 && ((c1 == 0 && key_pressed(KEY_PL1_JUMP) == 1) || (c1 == 1 && key_pressed(KEY_PL2_JUMP) == 1) || (c1 == 2 && key_pressed(KEY_PL3_JUMP) == 1) || (c1 == 3 && key_pressed(KEY_PL4_JUMP) == 1))) {
304                                         if ((player[c1].x >> 16) <= (165 + c1 * 2) || (player[c1].x >> 16) >= (208 + c1 * 2)) {
305                                                 if ((player[c1].y >> 16) >= (160 + c1 * 2)) {
306                                                         player[c1].y_add = -280000L;
307                                                         player[c1].anim = 2;
308                                                         player[c1].frame = 0;
309                                                         player[c1].frame_tick = 0;
310                                                         player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
311                                                         player[c1].jump_ready = 0;
312                                                         dj_play_sfx(SFX_JUMP, SFX_JUMP_FREQ + rnd(2000) - 1000, 64, 0, 0, -1);
313                                                 }
314                                         } else {
315                                                 if ((player[c1].y >> 16) >= (138 + c1 * 2)) {
316                                                         player[c1].y_add = -280000L;
317                                                         player[c1].anim = 2;
318                                                         player[c1].frame = 0;
319                                                         player[c1].frame_tick = 0;
320                                                         player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
321                                                         player[c1].jump_ready = 0;
322                                                         dj_play_sfx(SFX_JUMP, SFX_JUMP_FREQ + rnd(2000) - 1000, 64, 0, 0, -1);
323                                                 }
324                                         }
325                                 }
326                                 if ((c1 == 0 && key_pressed(KEY_PL1_JUMP) == 0) || (c1 == 1 && key_pressed(KEY_PL2_JUMP) == 0) || (c1 == 2 && key_pressed(KEY_PL3_JUMP) == 0) || (c1 == 3 && key_pressed(KEY_PL4_JUMP) == 0)) {
327                                         if (player[c1].y_add < 0) {
328                                                 player[c1].y_add += 32768;
329                                                 if (player[c1].y_add > 0)
330                                                         player[c1].y_add = 0;
331                                         }
332                                 }
333                                 if ((c1 == 0 && key_pressed(KEY_PL1_JUMP) == 0) || (c1 == 1 && key_pressed(KEY_PL2_JUMP) == 0) || (c1 == 2 && key_pressed(KEY_PL3_JUMP) == 0) || (c1 == 3 && key_pressed(KEY_PL4_JUMP) == 0))
334                                         player[c1].jump_ready = 1;
335                                 player[c1].y_add += 12288;
336                                 if (player[c1].y_add > 36864 && player[c1].anim != 3) {
337                                         player[c1].anim = 3;
338                                         player[c1].frame = 0;
339                                         player[c1].frame_tick = 0;
340                                         player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
341                                 }
342                                 player[c1].y += player[c1].y_add;
343                                 if ((player[c1].x >> 16) <= (165 + c1 * 2) || (player[c1].x >> 16) >= (208 + c1 * 2)) {
344                                         if ((player[c1].y >> 16) > (160 + c1 * 2)) {
345                                                 player[c1].y = (160L + c1 * 2) << 16;
346                                                 player[c1].y_add = 0;
347                                                 if (player[c1].anim != 0 && player[c1].anim != 1) {
348                                                         player[c1].anim = 0;
349                                                         player[c1].frame = 0;
350                                                         player[c1].frame_tick = 0;
351                                                         player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
352                                                 }
353                                         }
354                                 } else {
355                                         if ((player[c1].y >> 16) > (138 + c1 * 2)) {
356                                                 player[c1].y = (138L + c1 * 2) << 16;
357                                                 player[c1].y_add = 0;
358                                                 if (player[c1].anim != 0 && player[c1].anim != 1) {
359                                                         player[c1].anim = 0;
360                                                         player[c1].frame = 0;
361                                                         player[c1].frame_tick = 0;
362                                                         player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
363                                                 }
364                                         }
365                                 }
366                                 player[c1].x += player[c1].x_add;
367                                 if ((player[c1].x >> 16) < 0) {
368                                         player[c1].x = 0;
369                                         player[c1].x_add = 0;
370                                 }
371                                 if ((player[c1].x >> 16) > 400) {
372                                         end_loop_flag = 1;
373                                         new_game_flag = 1;
374                                         memset(menu_pal, 0, 768);
375                                         mod_fade_direction = 0;
376                                 }
377                                 if ((player[c1].y >> 16) > (138 + c1 * 2)) {
378                                         if ((player[c1].x >> 16) > (165 + c1 * 2) && (player[c1].x >> 16) < (190 + c1 * 2)) {
379                                                 player[c1].x = (165L + c1 * 2) << 16;
380                                                 player[c1].x_add = 0;
381                                         }
382                                         if ((player[c1].x >> 16) > (190 + c1 * 2) && (player[c1].x >> 16) < (208 + c1 * 2)) {
383                                                 player[c1].x = (208L + c1 * 2) << 16;
384                                                 player[c1].x_add = 0;
385                                         }
386                                 }
387                         }
388                         player[c1].frame_tick++;
389                         if (player[c1].frame_tick >= player_anims[player[c1].anim].frame[player[c1].frame].ticks) {
390                                 player[c1].frame++;
391                                 if (player[c1].frame >= player_anims[player[c1].anim].num_frames)
392                                         player[c1].frame = player_anims[player[c1].anim].restart_frame;
393                                 player[c1].frame_tick = 0;
394                         }
395                         player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
396                 }
397
398                 dj_mix();
399
400                 main_info.page_info[main_info.draw_page].num_pobs = 0;
401
402                 for (c1 = 3; c1 >= 0; c1--)
403                         add_pob(main_info.draw_page, player[c1].x >> 16, player[c1].y >> 16, player[c1].image + c1 * 18, rabbit_gobs);
404
405                 update_objects();
406
407                 draw_pobs(main_info.draw_page);
408
409                 dj_mix();
410
411                 if (mod_fade_direction == 1) {
412                         if (mod_vol < 35) {
413                                 mod_vol++;
414                                 dj_set_mod_volume(mod_vol);
415                         }
416                 } else {
417                         if (mod_vol > 0) {
418                                 mod_vol--;
419                                 dj_set_mod_volume(mod_vol);
420                         }
421                 }
422
423                 fade_flag = 0;
424                 for (c1 = 0; c1 < 720; c1++) {
425                         if (menu_cur_pal[c1] < menu_pal[c1]) {
426                                 menu_cur_pal[c1]++;
427                                 fade_flag = 1;
428                         } else if (menu_cur_pal[c1] > menu_pal[c1]) {
429                                 menu_cur_pal[c1]--;
430                                 fade_flag = 2;
431                         }
432                 }
433                 if (fade_flag == 0 && end_loop_flag == 1) {
434                         menu_deinit();
435                         if (new_game_flag == 1)
436                                 return 0;
437                         else
438                                 return 1;
439                 }
440                 switch (fade_dir) {
441                 case 0:
442                         if (fade_count < 30) {
443                                 for (c1 = 0; c1 < 48; c1++) {
444                                         if (fade_pal[c1] > 0)
445                                                 fade_pal[c1]--;
446                                 }
447                                 fade_count++;
448                         } else {
449 /*
450                                 outportw(0x3c4, 0x0f02);
451                                 memset((char *) (0xa0000 + 220 * 100 + __djgpp_conventional_base), 0, 2000);
452                                 memset((char *) (0xa0000 + 32768 + 220 * 100 + __djgpp_conventional_base), 0, 2000);
453                                 /* clear 5 lines at x=0,y=220 in front and backbuffer */
454                                 */memset((void *) get_vgaptr(0, 0, 220), 0, 8000);
455
456                                 cur_message++;
457                                 if (cur_message >= NUM_MESSAGES)
458                                         cur_message -= NUM_MESSAGES;
459                                 put_text(0, 200, 220, message[cur_message], 2);
460                                 put_text(1, 200, 220, message[cur_message], 2);
461                                 fade_dir = 1;
462                                 fade_count = 0;
463                                 fade_tick = 0;
464                         }
465                         break;
466                 case 1:
467                         if (fade_count < 100) {
468                                 for (c1 = 0; c1 < 48; c1++) {
469                                         if (fade_pal[c1] < menu_pal[c1 + 720])
470                                                 fade_pal[c1]++;
471                                 }
472                                 fade_count++;
473                         } else {
474                                 fade_dir = 0;
475                                 fade_count = 0;
476                                 fade_tick = 0;
477                         }
478                         break;
479                 }
480
481                 for (c1 = 0; c1 < 48; c1++) {
482                         if (fade_pal[c1] > menu_pal[c1 + 720])
483                                 fade_pal[c1]--;
484                 }
485
486                 main_info.draw_page ^= 1;
487                 main_info.view_page ^= 1;
488
489 #ifndef LINUX
490                 outportw(0x3d4, (main_info.view_page << 23) + 0x0d);
491                 outportw(0x3d4, ((main_info.view_page << 15) & 0xff00) + 0x0c);
492 #else
493                 flippage(main_info.view_page);
494 #endif
495
496 /*
497                 while ((inportb(0x3da) & 8) == 0)
498                         dj_mix();
499                 while ((inportb(0x3da) & 8) == 8)
500                         dj_mix();
501 */
502
503                 if (fade_flag != 0) {
504                         setpalette(0, 240, menu_cur_pal);
505                 }
506
507                 setpalette(240, 16, fade_pal);
508
509                 dj_mix();
510
511                 redraw_pob_backgrounds(main_info.draw_page);
512
513         }
514
515         menu_deinit();
516         return 0;
517
518 }
519
520
521 char menu_init(void)
522 {
523         FILE *handle;
524         int c1;
525
526         fillpalette(0, 0, 0);
527
528         if ((handle = dat_open("menu.pcx", datfile_name, "rb")) == 0) {
529                 strcpy(main_info.error_str, "Error loading 'menu.pcx', aborting...\n");
530                 return 1;
531         }
532         if (read_pcx(handle, background_pic, 102400, menu_pal) != 0) {
533                 strcpy(main_info.error_str, "Error loading 'menu.pcx', aborting...\n");
534                 return 1;
535         }
536         fclose(handle);
537         if ((handle = dat_open("menumask.pcx", datfile_name, "rb")) == 0) {
538                 strcpy(main_info.error_str, "Error loading 'menumask.pcx', aborting...\n");
539                 return 1;
540         }
541         if (read_pcx(handle, mask_pic, 102400, 0) != 0) {
542                 strcpy(main_info.error_str, "Error loading 'menumask.pcx', aborting...\n");
543                 return 1;
544         }
545         fclose(handle);
546         memset(menu_cur_pal, 0, 768);
547
548         put_block(0, 0, 0, 400, 256, background_pic);
549         put_block(1, 0, 0, 400, 256, background_pic);
550
551         for (c1 = 0; c1 < 4; c1++) {
552                 player[c1].enabled = 0;
553                 player[c1].x = (long) rnd(150) << 16;
554                 player[c1].y = (160L + c1 * 2) << 16;
555                 player[c1].x_add = 0;
556                 player[c1].y_add = 0;
557                 player[c1].direction = rnd(2);
558                 player[c1].jump_ready = 1;
559                 player[c1].anim = 0;
560                 player[c1].frame = 0;
561                 player[c1].frame_tick = 0;
562                 player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image;
563         }
564
565         for (c1 = 0; c1 < 300; c1++)
566                 objects[c1].used = 0;
567
568         main_info.page_info[0].num_pobs = 0;
569         main_info.page_info[1].num_pobs = 0;
570
571         return 0;
572
573 }
574
575
576 void menu_deinit(void)
577 {
578         dj_set_nosound(1);
579 }