Initial revision
[crow/jumpnbump.git] / main.c
1 #include "globals.h"
2
3
4 __dpmi_regs regs;
5
6 char *object_gobs;
7 char *number_gobs;
8
9 char pal[768];
10 char cur_pal[768];
11
12 char ban_map[17][22] = {
13 1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
14 1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,1,0,0,0,
15 1,0,0,0,1,1,1,1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,
16 1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,1,1,
17 1,1,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,1,
18 1,1,1,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,
19 1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,1,
20 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,
21 1,1,1,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,
22 1,0,0,0,0,0,0,0,0,0,0,0,3,1,0,0,0,0,0,0,0,1,
23 1,0,0,0,0,0,0,0,0,0,0,3,1,1,1,0,0,0,0,0,0,1,
24 1,0,1,1,1,1,0,0,0,0,3,1,1,1,1,1,1,1,1,0,0,1,
25 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
26 1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,
27 2,2,2,2,2,2,2,2,1,1,0,0,0,0,0,1,3,3,3,1,1,1,
28 2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
29
30 struct {
31         int num_frames;
32   int restart_frame;
33   struct {
34         int image;
35     int ticks;
36   } frame[10];
37 } object_anims[8] = {6, 0, 0, 3, 1, 3, 2, 3, 3, 3, 4, 3, 5, 3, 0, 0, 0, 0, 0, 0, 0, 0,
38                                                                                  9, 0, 6, 2, 7, 2, 8, 2, 9, 2,10, 2,11, 2,12, 2,13, 2,14, 2, 0, 0,
39                                                                                  5, 0,15, 3,16, 3,16, 3,17, 3,18, 3,19, 3, 0, 0, 0, 0, 0, 0, 0, 0,
40                                                                                 10, 0,20, 2,21, 2,22, 2,23, 2,24, 2,25, 2,24, 2,23, 2,22, 2,21, 2,
41                                                                                 10, 0,26, 2,27, 2,28, 2,29, 2,30, 2,31, 2,30, 2,29, 2,28, 2,27, 2,
42                                                                                 10, 0,32, 2,33, 2,34, 2,35, 2,36, 2,37, 2,36, 2,35, 2,34, 2,33, 2,
43                                                                                 10, 0,38, 2,39, 2,40, 2,41, 2,42, 2,43, 2,42, 2,41, 2,40, 2,39, 2,
44                                                                                  4, 0,76, 4,77, 4,78, 4,79, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
45
46 /*} object_anims[4] = {5, 0, 0, 2, 1, 2, 2, 2, 3, 2, 4, 2, 0, 0,
47                                                                                  6, 0, 5, 5, 6, 5, 7, 5, 8, 5, 9, 5,10, 5,
48                                                                                  6, 0,11, 3,12, 3,13, 3,14, 3,15, 3,16, 0x7fff,
49                                                                                  5, 0,17, 2,18, 2,19, 2,20, 2,21, 2, 0, 0};*/
50
51 struct {
52         int x, y;
53         int old_x, old_y;
54         char back[2], back_defined[2];
55 } flies[NUM_FLIES];
56
57 struct {
58         struct {
59                 short num_pobs;
60                 struct {
61                         int x, y;
62                         int image;
63                         char *pob_data;
64                 } pobs[NUM_LEFTOVERS];
65         } page[2];
66 } leftovers;
67
68 char pogostick, bunnies_in_space, jetpack, lord_of_the_flies, blood_is_thicker_than_water;
69
70
71 char main(int argc, char *argv[]) {
72         FILE *handle;
73         int c1, c2, c3, c4;
74   int l1, l2;
75   int s1, s2, s3, s4;
76         int closest_player, dist, cur_dist;
77         char end_loop_flag, fade_flag;
78         char mod_vol, sfx_vol, mod_fade_direction;
79         sfx_data fly;
80         char *ptr1;
81         char str1[100];
82
83   if (init_program(argc, argv) != 0)
84         deinit_program();
85
86         if (main_info.fireworks == 1) {
87                 fireworks();
88                 deinit_program();
89         }
90
91   while (1) {
92
93         if (menu() != 0)
94         deinit_program();
95
96                 if (key_pressed(1) == 1)
97         break;
98
99     if (init_level(0) != 0) {
100         deinit_level();
101         deinit_program();
102     }
103
104           outportb(0x3c8, 0);
105         for (c1 = 0; c1 < 768; c1++)
106                 outportb(0x3c9, cur_pal[c1]);
107
108                 for (c1 = 0; c1 < 4; c1++) {
109                         outportw(0x3c4, ( (1 << c1) << 8) + 0x02);
110                         l1 = c1;
111             for (l2 = 0; l2 < 25600; l2++) {
112                 *(char *)(0xa0000 + l2 + __djgpp_conventional_base) = *(char *)(background_pic + l1);
113                 *(char *)(0xa0000 + 32768 + l2 + __djgpp_conventional_base) = *(char *)(background_pic + l1);
114                                 l1 += 4;
115                         }
116                 }
117
118                 s1 = rnd(250) + 50;
119                 s2 = rnd(150) + 50;
120                 for (c1 = 0; c1 < NUM_FLIES; c1++) {
121                         while (1) {
122                                 flies[c1].x = s1 + rnd(101) - 50;
123                                 flies[c1].y = s2 + rnd(101) - 50;
124                                 if (ban_map[flies[c1].y >> 4][flies[c1].x >> 4] == 0)
125                                         break;
126                         }
127                         flies[c1].back_defined[0] = 0;
128                         flies[c1].back_defined[1] = 0;
129                 }
130
131                 mod_vol = sfx_vol = 10;
132                 mod_fade_direction = 1;
133     dj_ready_mod(MOD_GAME);
134                 dj_set_mod_volume(mod_vol);
135                 dj_set_sfx_volume(mod_vol);
136           dj_start_mod();
137                 dj_play_sfx(SFX_FLY, SFX_FLY_FREQ, 0, 0, 0, 4);
138                 dj_set_nosound(0);
139
140                 lord_of_the_flies = bunnies_in_space = jetpack = pogostick = blood_is_thicker_than_water = 0;
141                 end_loop_flag = 0;
142         main_info.page_info[0].num_pobs = 0;
143           main_info.page_info[1].num_pobs = 0;
144     main_info.view_page = 0;
145     main_info.draw_page = 1;
146
147     while (1) {
148
149                         if (key_pressed(1) == 1) {
150                                 end_loop_flag = 1;
151                                 memset(pal, 0, 768);
152                                 mod_fade_direction = 0;
153                         }
154
155                         if (strncmp(last_keys, "kcitsogop", strlen("kcitsogop") ) == 0) {
156                                 pogostick ^= 1;
157                                 last_keys[0] = 0;
158                         }
159                         if (strncmp(last_keys, "ecapsniseinnub", strlen("ecapsniseinnub") ) == 0) {
160                                 bunnies_in_space ^= 1;
161                                 last_keys[0] = 0;
162                         }
163                         if (strncmp(last_keys, "kcaptej", strlen("kcaptej") ) == 0) {
164                                 jetpack ^= 1;
165                                 last_keys[0] = 0;
166                         }
167                         if (strncmp(last_keys, "seilfehtfodrol", strlen("seilfehtfodrol") ) == 0) {
168                                 lord_of_the_flies ^= 1;
169                                 last_keys[0] = 0;
170                         }
171                         if (strncmp(last_keys, "retawnahtrekcihtsidoolb", strlen("retawnahtrekcihtsidoolb") ) == 0) {
172                                 blood_is_thicker_than_water ^= 1;
173                                 if (blood_is_thicker_than_water == 1) {
174                                         pal[432] = 63;
175                                         pal[433] = 32;
176                                         pal[434] = 32;
177                                         pal[435] = 53;
178                                         pal[436] = 17;
179                                         pal[437] = 17;
180                                         pal[438] = 42;
181                                         pal[439] = 7;
182                                         pal[440] = 7;
183                                         pal[441] = 28;
184                                         pal[442] = 0;
185                                         pal[443] = 0;
186                                         pal[444] = 24;
187                                         pal[445] = 0;
188                                         pal[446] = 0;
189                                         pal[447] = 19;
190                                         pal[448] = 0;
191                                         pal[449] = 0;
192                                         pal[450] = 12;
193                                         pal[451] = 0;
194                                         pal[452] = 0;
195                                         pal[453] = 7;
196                                         pal[454] = 0;
197                                         pal[455] = 0;
198                                 }
199                                 else {
200                                         pal[432] = 63;
201                                         pal[433] = 63;
202                                         pal[434] = 63;
203                                         pal[435] = 40;
204                                         pal[436] = 53;
205                                         pal[437] = 62;
206                                         pal[438] = 19;
207                                         pal[439] = 42;
208                                         pal[440] = 60;
209                                         pal[441] = 0;
210                                         pal[442] = 33;
211                                         pal[443] = 60;
212                                         pal[444] = 3;
213                                         pal[445] = 32;
214                                         pal[446] = 46;
215                                         pal[447] = 3;
216                                         pal[448] = 26;
217                                         pal[449] = 33;
218                                         pal[450] = 3;
219                                         pal[451] = 19;
220                                         pal[452] = 21;
221                                         pal[453] = 1;
222                                         pal[454] = 8;
223                                         pal[455] = 8;
224                                 }
225                                 last_keys[0] = 0;
226                         }
227
228         steer_players();
229
230       dj_mix();
231
232       for (c3 = 0; c3 < 6; c3++) {
233         if (c3 == 0) {
234                 c1 = 0;
235           c2 = 1;
236         }
237         else if (c3 == 1) {
238                 c1 = 0;
239           c2 = 2;
240         }
241         else if (c3 == 2) {
242                 c1 = 0;
243           c2 = 3;
244         }
245         else if (c3 == 3) {
246                 c1 = 1;
247           c2 = 2;
248         }
249         else if (c3 == 4) {
250                 c1 = 1;
251           c2 = 3;
252         }
253         else if (c3 == 5) {
254                 c1 = 2;
255           c2 = 3;
256         }
257         if (player[c1].enabled == 1 && player[c2].enabled == 1) {
258                 if (labs(player[c1].x - player[c2].x) < (12L << 16) && labs(player[c1].y - player[c2].y) < (12L << 16) ) {
259                         if ( (labs(player[c1].y - player[c2].y) >> 16) > 5) {
260                         if (player[c1].y < player[c2].y) {
261                       if (player[c1].y_add >= 0) {
262 //                  player[c1].y = player[c2].y - (16L << 16);
263                             player[c1].y_add = -player[c1].y_add;
264                   if (player[c1].y_add > -262144L)
265                         player[c1].y_add = -262144L;
266                   player[c1].jump_abort = 1;
267                   player[c2].dead_flag = 1;
268                   if (player[c2].anim != 6) {
269                                                                           player[c2].anim = 6;
270                                                         player[c2].frame = 0;
271                                                       player[c2].frame_tick = 0;
272                                                                         player[c2].image = player_anims[player[c2].anim].frame[player[c2].frame].image + player[c2].direction * 9;
273                                                                                 if (main_info.no_gore == 0) {
274                                                                                         for (c4 = 0; c4 < 6; c4++)
275                                                                                                 add_object(OBJ_FUR, (player[c2].x >> 16) + 6 + rnd(5), (player[c2].y >> 16) + 6 + rnd(5), (rnd(65535) - 32768) * 3, (rnd(65535) - 32768) * 3, 0, 44 + c2 * 8);
276                                                                                         for (c4 = 0; c4 < 6; c4++)
277                                                                                                 add_object(OBJ_FLESH, (player[c2].x >> 16) + 6 + rnd(5), (player[c2].y >> 16) + 6 + rnd(5), (rnd(65535) - 32768) * 3, (rnd(65535) - 32768) * 3, 0, 76);
278                                                                                         for (c4 = 0; c4 < 6; c4++)
279                                                                                                 add_object(OBJ_FLESH, (player[c2].x >> 16) + 6 + rnd(5), (player[c2].y >> 16) + 6 + rnd(5), (rnd(65535) - 32768) * 3, (rnd(65535) - 32768) * 3, 0, 77);
280                                                                                         for (c4 = 0; c4 < 8; c4++)
281                                                                                                 add_object(OBJ_FLESH, (player[c2].x >> 16) + 6 + rnd(5), (player[c2].y >> 16) + 6 + rnd(5), (rnd(65535) - 32768) * 3, (rnd(65535) - 32768) * 3, 0, 78);
282                                                                                         for (c4 = 0; c4 < 10; c4++)
283                                                                                                 add_object(OBJ_FLESH, (player[c2].x >> 16) + 6 + rnd(5), (player[c2].y >> 16) + 6 + rnd(5), (rnd(65535) - 32768) * 3, (rnd(65535) - 32768) * 3, 0, 79);
284                                                                                 }
285                                                                                 dj_play_sfx(SFX_DEATH, SFX_DEATH_FREQ + rnd(2000) - 1000, 64, 0, 0, -1);
286                                                                                 player[c1].bumps++;
287                                                                                 player[c1].bumped[c2]++;
288                                                                                 s1 = player[c1].bumps % 100;
289                                                                                 add_leftovers(0, 360, 34 + c1 * 64, s1 / 10, number_gobs);
290                                                                                 add_leftovers(1, 360, 34 + c1 * 64, s1 / 10, number_gobs);
291                                                                                 add_leftovers(0, 376, 34 + c1 * 64, s1 - (s1 / 10) * 10, number_gobs);
292                                                                                 add_leftovers(1, 376, 34 + c1 * 64, s1 - (s1 / 10) * 10, number_gobs);
293                   }
294                 }
295                 else {
296 //                  player[c1].y = player[c2].y - (16L << 16);
297                   if (player[c2].y_add < 0)
298                         player[c2].y_add = 0;
299                 }
300                         }
301                     else {
302                       if (player[c2].y_add >= 0) {
303 //                  player[c2].y = player[c1].y - (16L << 16);
304                             player[c2].y_add = -player[c2].y_add;
305                   if (player[c2].y_add > -262144L)
306                         player[c2].y_add = -262144L;
307                   player[c2].jump_abort = 1;
308                   player[c1].dead_flag = 1;
309                   if (player[c1].anim != 6) {
310                                                                           player[c1].anim = 6;
311                                                         player[c1].frame = 0;
312                                                       player[c1].frame_tick = 0;
313                                                                         player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
314                                                                                 if (main_info.no_gore == 0) {
315                                                                                         for (c4 = 0; c4 < 6; c4++)
316                                                                                                 add_object(OBJ_FUR, (player[c1].x >> 16) + 6 + rnd(5), (player[c1].y >> 16) + 6 + rnd(5), (rnd(65535) - 32768) * 3, (rnd(65535) - 32768) * 3, 0, 44 + c1 * 8);
317                                                                                         for (c4 = 0; c4 < 6; c4++)
318                                                                                                 add_object(OBJ_FLESH, (player[c1].x >> 16) + 6 + rnd(5), (player[c1].y >> 16) + 6 + rnd(5), (rnd(65535) - 32768) * 3, (rnd(65535) - 32768) * 3, 0, 76);
319                                                                                         for (c4 = 0; c4 < 7; c4++)
320                                                                                                 add_object(OBJ_FLESH, (player[c1].x >> 16) + 6 + rnd(5), (player[c1].y >> 16) + 6 + rnd(5), (rnd(65535) - 32768) * 3, (rnd(65535) - 32768) * 3, 0, 77);
321                                                                                         for (c4 = 0; c4 < 8; c4++)
322                                                                                                 add_object(OBJ_FLESH, (player[c1].x >> 16) + 6 + rnd(5), (player[c1].y >> 16) + 6 + rnd(5), (rnd(65535) - 32768) * 3, (rnd(65535) - 32768) * 3, 0, 78);
323                                                                                         for (c4 = 0; c4 < 10; c4++)
324                                                                                                 add_object(OBJ_FLESH, (player[c1].x >> 16) + 6 + rnd(5), (player[c1].y >> 16) + 6 + rnd(5), (rnd(65535) - 32768) * 3, (rnd(65535) - 32768) * 3, 0, 79);
325                                                                                 }
326                                                                                 dj_play_sfx(SFX_DEATH, SFX_DEATH_FREQ + rnd(2000) - 1000, 64, 0, 0, -1);
327                                                                                 player[c2].bumps++;
328                                                                                 player[c2].bumped[c1]++;
329                                                                                 s1 = player[c2].bumps % 100;
330                                                                                 add_leftovers(0, 360, 34 + c2 * 64, s1 / 10, number_gobs);
331                                                                                 add_leftovers(1, 360, 34 + c2 * 64, s1 / 10, number_gobs);
332                                                                                 add_leftovers(0, 376, 34 + c2 * 64, s1 - (s1 / 10) * 10, number_gobs);
333                                                                                 add_leftovers(1, 376, 34 + c2 * 64, s1 - (s1 / 10) * 10, number_gobs);
334                   }
335                 }
336                 else {
337 //                  player[c2].y = player[c1].y - (16L << 16);
338                   if (player[c1].y_add < 0)
339                         player[c1].y_add = 0;
340                 }
341                     }
342                   }
343                       else {
344                         if (player[c1].x < player[c2].x) {
345                 if (player[c1].x_add > 0)
346                                 player[c1].x = player[c2].x - (12L << 16);
347                 else if (player[c2].x_add < 0)
348                                 player[c2].x = player[c1].x + (12L << 16);
349                 else {
350                                 player[c1].x -= player[c1].x_add;
351                                 player[c2].x -= player[c2].x_add;
352                 }
353                                         l1 = player[c2].x_add;
354                                 player[c2].x_add = player[c1].x_add;
355                           player[c1].x_add = l1;
356                           if (player[c1].x_add > 0)
357                                 player[c1].x_add = -player[c1].x_add;
358                       if (player[c2].x_add < 0)
359                                 player[c2].x_add = -player[c2].x_add;
360                     }
361                         else {
362                 if (player[c1].x_add > 0)
363                                 player[c2].x = player[c1].x - (12L << 16);
364                 else if (player[c2].x_add < 0)
365                                 player[c1].x = player[c2].x + (12L << 16);
366                 else {
367                                 player[c1].x -= player[c1].x_add;
368                                 player[c2].x -= player[c2].x_add;
369                 }
370                                         l1 = player[c2].x_add;
371                                 player[c2].x_add = player[c1].x_add;
372                           player[c1].x_add = l1;
373                           if (player[c1].x_add < 0)
374                         player[c1].x_add = -player[c1].x_add;
375                           if (player[c2].x_add > 0)
376                                 player[c2].x_add = -player[c2].x_add;
377                     }
378                       }
379                 }
380         }
381             }
382
383       dj_mix();
384
385       main_info.page_info[main_info.draw_page].num_pobs = 0;
386                         for (c1 = 0; c1 < 4; c1++) {
387                                 if (player[c1].enabled == 1)
388                       main_info.page_info[main_info.draw_page].num_pobs++;
389                         }
390
391       update_objects();
392
393       dj_mix();
394
395                         s1 = s2 = 0;
396                         for (c1 = 0; c1 < NUM_FLIES; c1++) {
397                                 s1 += flies[c1].x;
398                                 s2 += flies[c1].y;
399                         }
400                         s1 /= NUM_FLIES;
401                         s2 /= NUM_FLIES;
402
403                         dist = 0x7fff;
404                         for (c1 = 0; c1 < 4; c1++) {
405                                 if (player[c1].enabled == 1) {
406                                         cur_dist = sqrt( (s1 - ( (player[c1].x >> 16) + 8) ) * (s1 - ( (player[c1].x >> 16) + 8) ) + (s2 - ( (player[c1].y >> 16) + 8) ) * (s2 - ( (player[c1].y >> 16) + 8) ) );
407                                         if (cur_dist < dist) {
408                                                 closest_player = c1;
409                                                 dist = cur_dist;
410                                         }
411                                 }
412                         }
413                         s3 = 32 - dist / 3;
414                         if (s3 < 0)
415                                 s3 = 0;
416                         dj_set_sfx_channel_volume(4, s3);
417
418                         for (c1 = 0; c1 < NUM_FLIES; c1++) {
419                                 dist = 0x7fff;
420                                 for (c2 = 0; c2 < 4; c2++) {
421                                         if (player[c2].enabled == 1) {
422                                                 cur_dist = sqrt( (flies[c1].x - ( (player[c2].x >> 16) + 8) ) * (flies[c1].x - ( (player[c2].x >> 16) + 8) ) + (flies[c1].y - ( (player[c2].y >> 16) + 8) ) * (flies[c1].y - ( (player[c2].y >> 16) + 8) ) );
423                                                 if (cur_dist < dist) {
424                                                         closest_player = c2;
425                                                         dist = cur_dist;
426                                                 }
427                                         }
428                                 }
429                                 flies[c1].old_x = flies[c1].x;
430                                 flies[c1].old_y = flies[c1].y;
431                                 s3 = 0;
432                                 if ( (s1 - flies[c1].x) > 30)
433                                         s3 += 1;
434                                 else if ( (s1 - flies[c1].x) < -30)
435                                         s3 -= 1;
436                                 if (dist < 30) {
437                                         if ( ( (player[closest_player].x >> 16) + 8) > flies[c1].x) {
438                                                 if (lord_of_the_flies == 0)
439                                                         s3 -= 1;
440                                                 else
441                                                         s3 += 1;
442                                         }
443                                         else {
444                                                 if (lord_of_the_flies == 0)
445                                                         s3 += 1;
446                                                 else
447                                                         s3 -= 1;
448                                         }
449                                 }
450                                 s4 = rnd(3) - 1 + s3;
451                                 if ( (flies[c1].x + s4) < 16)
452                                         s4 = 0;
453                                 if ( (flies[c1].x + s4) > 351)
454                                         s4 = 0;
455                                 if (ban_map[flies[c1].y >> 4][(flies[c1].x + s4) >> 4] != 0)
456                                         s4 = 0;
457                                 flies[c1].x += s4;
458                                 s3 = 0;
459                                 if ( (s2 - flies[c1].y) > 30)
460                                         s3 += 1;
461                                 else if ( (s2 - flies[c1].y) < -30)
462                                         s3 -= 1;
463                                 if (dist < 30) {
464                                         if ( ( (player[closest_player].y >> 16) + 8) > flies[c1].y) {
465                                                 if (lord_of_the_flies == 0)
466                                                         s3 -= 1;
467                                                 else
468                                                         s3 += 1;
469                                         }
470                                         else {
471                                                 if (lord_of_the_flies == 0)
472                                                         s3 += 1;
473                                                 else
474                                                         s3 -= 1;
475                                         }
476                                 }
477                                 s4 = rnd(3) - 1 + s3;
478                                 if ( (flies[c1].y + s4) < 0)
479                                         s4 = 0;
480                                 if ( (flies[c1].y + s4) > 239)
481                                         s4 = 0;
482                                 if (ban_map[(flies[c1].y + s4) >> 4][flies[c1].x >> 4] != 0)
483                                         s4 = 0;
484                                 flies[c1].y += s4;
485                         }
486
487       dj_mix();
488
489                         s1 = 0;
490             for (c1 = 0; c1 < 4; c1++) {
491         if (player[c1].enabled == 1) {
492                                         main_info.page_info[main_info.draw_page].pobs[s1].x = player[c1].x >> 16;
493                                         main_info.page_info[main_info.draw_page].pobs[s1].y = player[c1].y >> 16;
494                                         main_info.page_info[main_info.draw_page].pobs[s1].image = player[c1].image + c1 * 18;
495                                         main_info.page_info[main_info.draw_page].pobs[s1].pob_data = rabbit_gobs;
496                                         s1++;
497                                 }
498       }
499
500       draw_pobs(main_info.draw_page);
501
502       dj_mix();
503
504                         ptr1 = (char *)(0xa0000 + ( (long)main_info.draw_page << 15) - __djgpp_base_address);
505                         for (c1 = 0; c1 < 4; c1++) {
506                                 outportw(0x3ce, (c1 << 8) + 0x04);
507                                 outportw(0x3c4, ( (1 << c1) << 8) + 0x02);
508                                 for (c2 = 0; c2 < NUM_FLIES; c2++) {
509                                         if ( (flies[c2].x & 3) == c1) {
510                                                 flies[c2].back[main_info.draw_page] = *(char *)(ptr1 + flies[c2].y * 100 + (flies[c2].x >> 2) );
511                                                 flies[c2].back_defined[main_info.draw_page] = 1;
512                                                 if (mask_pic[flies[c2].y * 400 + flies[c2].x] == 0)
513                                                         *(char *)(ptr1 + flies[c2].y * 100 + (flies[c2].x >> 2) ) = 0;
514                                         }
515                                 }
516                         }
517
518                         if (mod_fade_direction == 1) {
519                                 if (mod_vol < 30) {
520                                         mod_vol++;
521                                         dj_set_mod_volume(mod_vol);
522                                 }
523                         }
524                         else {
525                                 if (mod_vol > 0) {
526                                         mod_vol--;
527                                         dj_set_mod_volume(mod_vol);
528                                 }
529                         }
530
531                         if (mod_fade_direction == 1) {
532                                 if (sfx_vol < 64) {
533                                         sfx_vol++;
534                                         dj_set_sfx_volume(sfx_vol);
535                                 }
536                         }
537                         else {
538                                 if (sfx_vol > 0) {
539                                         sfx_vol--;
540                                         dj_set_sfx_volume(sfx_vol);
541                                 }
542                         }
543
544                         fade_flag = 0;
545                         for (c1 = 0; c1 < 768; c1++) {
546                                 if (cur_pal[c1] < pal[c1]) {
547                                         cur_pal[c1]++;
548                                         fade_flag = 1;
549                                 }
550                                 else if (cur_pal[c1] > pal[c1]) {
551                                         cur_pal[c1]--;
552                                         fade_flag = 1;
553                                 }
554                         }
555                         if (fade_flag == 0 && end_loop_flag == 1)
556                                 break;
557
558       main_info.draw_page ^= 1;
559       main_info.view_page ^= 1;
560
561                         outportw(0x3d4, (main_info.view_page << 23) + 0x0d);
562                         outportw(0x3d4, ( (main_info.view_page << 15) & 0xff00) + 0x0c);
563
564                         while( (inportb(0x3da) & 8) == 0)
565                                 dj_mix();
566                   while( (inportb(0x3da) & 8) == 8)
567                                 dj_mix();
568
569                         if (fade_flag == 1) {
570                         outportb(0x3c8, 0);
571                                 for (c1 = 0; c1 < 768; c1++)
572                                         outportb(0x3c9, cur_pal[c1]);
573                         }
574
575                         ptr1 = (char *)(0xa0000 + ( (long)main_info.draw_page << 15) - __djgpp_base_address);
576                         for (c1 = 0; c1 < 4; c1++) {
577                                 outportw(0x3c4, ( (1 << c1) << 8) + 0x02);
578                                 for (c2 = NUM_FLIES - 1; c2 >= 0; c2--) {
579                                         if ( (flies[c2].old_x & 3) == c1 && flies[c2].back_defined[main_info.draw_page] == 1)
580                                                 *(char *)(ptr1 + flies[c2].old_y * 100 + (flies[c2].old_x >> 2) ) = flies[c2].back[main_info.draw_page];
581                                 }
582                         }
583
584                         redraw_pob_backgrounds(main_info.draw_page);
585
586       draw_leftovers(main_info.draw_page);
587
588     }
589
590                 dj_stop_sfx_channel(4);
591
592     deinit_level();
593
594                 memset(mask_pic, 0, 102400L);
595
596                 outportw(0x3c4, 0x0f02);
597           memset( (char *)(0xa0000 + (long)(main_info.view_page << 15) + __djgpp_conventional_base), 0, 32768);
598                 put_text(main_info.view_page, 100, 50, "DOTT", 2);
599                 put_text(main_info.view_page, 160, 50, "JIFFY", 2);
600                 put_text(main_info.view_page, 220, 50, "FIZZ", 2);
601                 put_text(main_info.view_page, 280, 50, "MIJJI", 2);
602                 put_text(main_info.view_page, 40, 80, "DOTT", 2);
603                 put_text(main_info.view_page, 40, 110, "JIFFY", 2);
604                 put_text(main_info.view_page, 40, 140, "FIZZ", 2);
605                 put_text(main_info.view_page, 40, 170, "MIJJI", 2);
606                 for (c1 = 0; c1 < 4; c1++) {
607                         for (c2 = 0; c2 < 4; c2++) {
608                                 if (c2 != c1) {
609                                         itoa(player[c1].bumped[c2], str1, 10);
610                                         put_text(main_info.view_page, 100 + c2 * 60, 80 + c1 * 30, str1, 2);
611                                 }
612                                 else
613                                         put_text(main_info.view_page, 100 + c2 * 60, 80 + c1 * 30, "-", 2);
614                         }
615                         itoa(player[c1].bumps, str1, 10);
616                         put_text(main_info.view_page, 350, 80 + c1 * 30, str1, 2);
617                 }
618                 put_text(main_info.view_page, 200, 230, "Press ESC to continue", 2);
619
620           if ( (handle = dat_open("menu.pcx", datfile_name, "rb") ) == 0) {
621                         strcpy(main_info.error_str, "Error loading 'menu.pcx', aborting...\n");
622                         return 1;
623                 }
624         if (read_pcx(handle, background_pic, 102400L, pal) != 0) {
625                         strcpy(main_info.error_str, "Error loading 'menu.pcx', aborting...\n");
626                         return 1;
627                 }
628                 fclose(handle);
629
630                 memset(cur_pal, 0, 768);
631
632           outportb(0x3c8, 0);
633                 for (c1 = 0; c1 < 768; c1++)
634                         outportb(0x3c9, cur_pal[c1]);
635
636                 mod_vol = 0;
637     dj_ready_mod(MOD_SCORES);
638                 dj_set_mod_volume(mod_vol);
639           dj_start_mod();
640                 dj_set_nosound(0);
641
642                 while (key_pressed(1) == 0) {
643                         if (mod_vol < 35)
644                                 mod_vol++;
645                         dj_set_mod_volume(mod_vol);
646                         for (c1 = 0; c1 < 768; c1++) {
647                                 if (cur_pal[c1] < pal[c1])
648                                         cur_pal[c1]++;
649                         }
650                         dj_mix();
651                         wait_vrt();
652                         outportb(0x3c8, 0);
653                         for (c1 = 0; c1 < 768; c1++)
654                                 outportb(0x3c9, cur_pal[c1]);
655                 }
656                 while (key_pressed(1) == 1)
657                         dj_mix();
658
659                 memset(pal, 0, 768);
660
661                 while (mod_vol > 0) {
662                         mod_vol--;
663                         dj_set_mod_volume(mod_vol);
664                         for (c1 = 0; c1 < 768; c1++) {
665                                 if (cur_pal[c1] > pal[c1])
666                                         cur_pal[c1]--;
667                         }
668                         dj_mix();
669                         wait_vrt();
670                         outportb(0x3c8, 0);
671                         for (c1 = 0; c1 < 768; c1++)
672                                 outportb(0x3c9, cur_pal[c1]);
673                 }
674
675           outportb(0x3c8, 0);
676                 for (c1 = 0; c1 < 768; c1++)
677                         outportb(0x3c9, 0);
678
679                 dj_set_nosound(1);
680           dj_stop_mod();
681
682   }
683
684   deinit_program();
685
686 }
687
688
689 void steer_players(void) {
690         int c1, c2;
691   int s1, s2;
692
693         if (main_info.mouse_enabled == 1)
694                 read_mouse();
695         if (main_info.joy_enabled == 1)
696                 read_joy();
697
698   for (c1 = 0; c1 < 4; c1++) {
699
700         if (player[c1].enabled == 1) {
701
702         if (player[c1].dead_flag == 0) {
703
704         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 && ( (joy.x < -512 && joy.x > 512) ) ) || (c1 == 3 && ( (mouse.but1 == 1 && mouse.but2 == 1) ) ) ) {
705                                 if (player[c1].direction == 0) {
706                                         if ( (c1 == 0 && key_pressed(KEY_PL1_RIGHT) == 1) || (c1 == 1 && key_pressed(KEY_PL2_RIGHT) == 1) || (c1 == 2 && joy.x > 512) || (c1 == 3 && mouse.but2 == 1) ) {
707                                 s1 = (player[c1].x >> 16);
708                                 s2 = (player[c1].y >> 16);
709                         if (ban_map[(s2 + 16) >> 4][(s1 + 8) >> 4] == 3) {
710                                         if (player[c1].x_add < 0)
711                                                 player[c1].x_add += 1024;
712                                 else
713                                                 player[c1].x_add += 768;
714                     }
715                         else if ( (ban_map[(s2 + 16) >> 4][s1 >> 4] != 1 && ban_map[(s2 + 16) >> 4][(s1 + 15) >> 4] == 3) || (ban_map[(s2 + 16) >> 4][s1 >> 4] == 3 && ban_map[(s2 + 16) >> 4][(s1 + 15) >> 4] != 1) ) {
716                                         if (player[c1].x_add > 0)
717                                                 player[c1].x_add += 1024;
718                                 else
719                                                 player[c1].x_add += 768;
720                         }
721                     else {
722                                         if (player[c1].x_add < 0) {
723                                                 player[c1].x_add += 16384;
724                                                     if (player[c1].x_add < 98304L && player[c1].in_water == 0 && ban_map[(s2 + 16) >> 4][(s1 + 8) >> 4] == 1)
725                                         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);
726                           }
727                                 else
728                                                 player[c1].x_add += 12288;
729                         }
730                         if (player[c1].x_add > 98304L)
731                                 player[c1].x_add = 98304L;
732                               player[c1].direction = 0;
733                         if (player[c1].anim == 0) {
734                         player[c1].anim = 1;
735                           player[c1].frame = 0;
736                           player[c1].frame_tick = 0;
737                                                 player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
738                         }
739                                         }
740                                 }
741                                 else {
742                                         if ( (c1 == 0 && key_pressed(KEY_PL1_LEFT) == 1) || (c1 == 1 && key_pressed(KEY_PL2_LEFT) == 1) || (c1 == 2 && joy.x < -512) || (c1 == 3 && mouse.but1 == 1) ) {
743                                 s1 = (player[c1].x >> 16);
744                                 s2 = (player[c1].y >> 16);
745                         if (ban_map[(s2 + 16) >> 4][(s1 + 8) >> 4] == 3) {
746                                         if (player[c1].x_add > 0)
747                                                 player[c1].x_add -= 1024;
748                                 else
749                                                 player[c1].x_add -= 768;
750                         }
751                     else if ( (ban_map[(s2 + 16) >> 4][s1 >> 4] != 1 && ban_map[(s2 + 16) >> 4][(s1 + 15) >> 4] == 3) || (ban_map[(s2 + 16) >> 4][s1 >> 4] == 3 && ban_map[(s2 + 16) >> 4][(s1 + 15) >> 4] != 1) ) {
752                                         if (player[c1].x_add > 0)
753                                                 player[c1].x_add -= 1024;
754                                 else
755                                                 player[c1].x_add -= 768;
756                         }
757                     else {
758                                         if (player[c1].x_add > 0) {
759                                                 player[c1].x_add -= 16384;
760                                                     if (player[c1].x_add > -98304L && player[c1].in_water == 0 && ban_map[(s2 + 16) >> 4][(s1 + 8) >> 4] == 1)
761                                         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);
762                           }
763                                 else
764                                                 player[c1].x_add -= 12288;
765                         }
766                                 if (player[c1].x_add < -98304L)
767                                         player[c1].x_add = -98304L;
768                               player[c1].direction = 1;
769                         if (player[c1].anim == 0) {
770                         player[c1].anim = 1;
771                           player[c1].frame = 0;
772                           player[c1].frame_tick = 0;
773                                                 player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
774                         }
775                                         }
776                                 }
777                         }
778                 else if ( (c1 == 0 && key_pressed(KEY_PL1_LEFT) == 1) || (c1 == 1 && key_pressed(KEY_PL2_LEFT) == 1) || (c1 == 2 && joy.x < -512) || (c1 == 3 && mouse.but1 == 1) ) {
779                 s1 = (player[c1].x >> 16);
780                 s2 = (player[c1].y >> 16);
781         if (ban_map[(s2 + 16) >> 4][(s1 + 8) >> 4] == 3) {
782                         if (player[c1].x_add > 0)
783                                 player[c1].x_add -= 1024;
784                 else
785                                 player[c1].x_add -= 768;
786         }
787         else if ( (ban_map[(s2 + 16) >> 4][s1 >> 4] != 1 && ban_map[(s2 + 16) >> 4][(s1 + 15) >> 4] == 3) || (ban_map[(s2 + 16) >> 4][s1 >> 4] == 3 && ban_map[(s2 + 16) >> 4][(s1 + 15) >> 4] != 1) ) {
788                         if (player[c1].x_add > 0)
789                                 player[c1].x_add -= 1024;
790                 else
791                                 player[c1].x_add -= 768;
792         }
793         else {
794                         if (player[c1].x_add > 0) {
795                                 player[c1].x_add -= 16384;
796                                     if (player[c1].x_add > -98304L && player[c1].in_water == 0 && ban_map[(s2 + 16) >> 4][(s1 + 8) >> 4] == 1)
797                         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);
798           }
799                 else
800                                 player[c1].x_add -= 12288;
801         }
802                     if (player[c1].x_add < -98304L)
803                         player[c1].x_add = -98304L;
804               player[c1].direction = 1;
805         if (player[c1].anim == 0) {
806                 player[c1].anim = 1;
807           player[c1].frame = 0;
808           player[c1].frame_tick = 0;
809                                 player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
810         }
811           }
812                 else if ( (c1 == 0 && key_pressed(KEY_PL1_RIGHT) == 1) || (c1 == 1 && key_pressed(KEY_PL2_RIGHT) == 1) || (c1 == 2 && joy.x > 512) || (c1 == 3 && mouse.but2 == 1) ) {
813                 s1 = (player[c1].x >> 16);
814                 s2 = (player[c1].y >> 16);
815         if (ban_map[(s2 + 16) >> 4][(s1 + 8) >> 4] == 3) {
816                         if (player[c1].x_add < 0)
817                                 player[c1].x_add += 1024;
818                 else
819                                 player[c1].x_add += 768;
820         }
821         else if ( (ban_map[(s2 + 16) >> 4][s1 >> 4] != 1 && ban_map[(s2 + 16) >> 4][(s1 + 15) >> 4] == 3) || (ban_map[(s2 + 16) >> 4][s1 >> 4] == 3 && ban_map[(s2 + 16) >> 4][(s1 + 15) >> 4] != 1) ) {
822                         if (player[c1].x_add > 0)
823                                 player[c1].x_add += 1024;
824                 else
825                                 player[c1].x_add += 768;
826         }
827         else {
828                         if (player[c1].x_add < 0) {
829                                 player[c1].x_add += 16384;
830                                     if (player[c1].x_add < 98304L && player[c1].in_water == 0 && ban_map[(s2 + 16) >> 4][(s1 + 8) >> 4] == 1)
831                         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);
832           }
833                 else
834                                 player[c1].x_add += 12288;
835         }
836         if (player[c1].x_add > 98304L)
837                 player[c1].x_add = 98304L;
838               player[c1].direction = 0;
839         if (player[c1].anim == 0) {
840                 player[c1].anim = 1;
841           player[c1].frame = 0;
842           player[c1].frame_tick = 0;
843                                 player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
844         }
845           }
846 //      if ( (c1 == 0 && ( (key_pressed(KEY_PL1_LEFT) == 0 && key_pressed(KEY_PL1_RIGHT) == 0) || (key_pressed(KEY_PL1_LEFT) == 1 && key_pressed(KEY_PL1_RIGHT) == 1) ) ) || (c1 == 1 && ( (key_pressed(KEY_PL2_LEFT) == 0 && key_pressed(KEY_PL2_RIGHT) == 0) || (key_pressed(KEY_PL2_LEFT) == 1 && key_pressed(KEY_PL2_RIGHT) == 1) ) ) || (c1 == 2 && ( (joy.x >= -512 && joy.x <= 512) || (joy.x < -512 && joy.x > 512) ) ) || (c1 == 3 && ( (mouse.but1 == 0 && mouse.but2 == 0) || (mouse.but1 == 1 && mouse.but2 == 1) ) ) ) {
847         else if ( (c1 == 0 && ( (key_pressed(KEY_PL1_LEFT) == 0 && key_pressed(KEY_PL1_RIGHT) == 0) ) ) || (c1 == 1 && ( (key_pressed(KEY_PL2_LEFT) == 0 && key_pressed(KEY_PL2_RIGHT) == 0) ) ) || (c1 == 2 && ( (joy.x >= -512 && joy.x <= 512) ) ) || (c1 == 3 && ( (mouse.but1 == 0 && mouse.but2 == 0) ) ) ) {
848                 s1 = (player[c1].x >> 16);
849                 s2 = (player[c1].y >> 16);
850           if (ban_map[(s2 + 16) >> 4][(s1 + 8) >> 4] == 1 || ban_map[(s2 + 16) >> 4][(s1 + 8) >> 4] == 4 || ( ( (ban_map[(s2 + 16) >> 4][s1 >> 4] == 1 || ban_map[(s2 + 16) >> 4][s1 >> 4] == 4) && ban_map[(s2 + 16) >> 4][(s1 + 15) >> 4] != 3) || (ban_map[(s2 + 16) >> 4][s1 >> 4] != 3 && (ban_map[(s2 + 16) >> 4][(s1 + 15) >> 4] == 1 || ban_map[(s2 + 16) >> 4][(s1 + 15) >> 4] == 4) ) ) ) {
851                         if (player[c1].x_add < 0) {
852                                 player[c1].x_add += 16384;
853                             if (player[c1].x_add > 0)
854                                         player[c1].x_add = 0;
855                       }
856                         else {
857                                 player[c1].x_add -= 16384;
858                           if (player[c1].x_add < 0)
859                                         player[c1].x_add = 0;
860                       }
861                             if (player[c1].x_add != 0 && ban_map[(s2 + 16) >> 4][(s1 + 8) >> 4] == 1)
862                         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);
863         }
864         if (player[c1].anim == 1) {
865                 player[c1].anim = 0;
866           player[c1].frame = 0;
867           player[c1].frame_tick = 0;
868                                 player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
869         }
870 //                              if (c1 == 3 && main_info.num_mouse_buttons == 2)
871 //                                      player[c1].jump_abort = 1;
872           }
873 /*
874 //                      if ( (player[c1].y >> 16) >= 208 && (player[c1].x >> 16) >= 136 && (player[c1].x >> 16) < 160) {
875         if (ban_map[( (player[c1].y >> 16) + 15) >> 4][( (player[c1].x >> 16) + 8) >> 4] == 4) {
876                                 player[c1].y = ( (player[c1].y >> 16) & 0xfff0) << 16;
877                 player[c1].y_add = -400000L;
878         player[c1].anim = 2;
879               player[c1].frame = 0;
880             player[c1].frame_tick = 0;
881                                 player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
882                         player[c1].jump_ready = 0;
883         player[c1].jump_abort = 0;
884 //        objects[0].frame = 0;
885 //            objects[0].ticks = object_anims[objects[0].anim].frame[objects[0].frame].ticks;
886 //                objects[0].image = object_anims[objects[0].anim].frame[objects[0].frame].image;
887                                 dj_play_sfx(SFX_SPRING, SFX_SPRING_FREQ + rnd(2000) - 1000, 64, 0, 0, -1);
888       }*/
889
890                         if (jetpack == 0) {
891
892 //              if (pogostick == 1 || (player[c1].jump_ready == 1 && ( (c1 == 0 && key_pressed(KEY_PL1_JUMP) == 1) || (c1 == 1 && key_pressed(KEY_PL2_JUMP) == 1) || (c1 == 2 && joy.but1 == 1)  || (c1 == 3 && mouse.but3 == 1) ) ) ) {
893                 if (pogostick == 1 || (player[c1].jump_ready == 1 && ( (c1 == 0 && key_pressed(KEY_PL1_JUMP) == 1) || (c1 == 1 && key_pressed(KEY_PL2_JUMP) == 1) || (c1 == 2 && joy.but1 == 1)  || (c1 == 3 && ( (main_info.num_mouse_buttons == 2 && mouse.but1 == 1 && mouse.but2 == 1) || (main_info.num_mouse_buttons == 3 && mouse.but3 == 1) ) ) ) ) ) {
894                 s1 = (player[c1].x >> 16);
895                 s2 = (player[c1].y >> 16);
896               if (s2 < -16)
897                 s2 = -16;
898                 if (ban_map[(s2 + 16) >> 4][s1 >> 4] == 1 || ban_map[(s2 + 16) >> 4][s1 >> 4] == 3 || ban_map[(s2 + 16) >> 4][(s1 + 15) >> 4] == 1 || ban_map[(s2 + 16) >> 4][(s1 + 15) >> 4] == 3) {
899                 player[c1].y_add = -280000L;
900                 player[c1].anim = 2;
901               player[c1].frame = 0;
902             player[c1].frame_tick = 0;
903                                         player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
904                         player[c1].jump_ready = 0;
905 //                                      if (c1 == 3 && main_info.num_mouse_buttons == 2)
906 //                      player[c1].jump_abort = 0;
907 //                                      else
908                         player[c1].jump_abort = 1;
909                                         if (pogostick == 0)
910                                                 dj_play_sfx(SFX_JUMP, SFX_JUMP_FREQ + rnd(2000) - 1000, 64, 0, 0, -1);
911                                         else
912                                                 dj_play_sfx(SFX_SPRING, SFX_SPRING_FREQ + rnd(2000) - 1000, 64, 0, 0, -1);
913               }
914                 if ( (ban_map[(s2 + 7) >> 4][s1 >> 4] == 0 || ban_map[(s2 + 7) >> 4][(s1 + 15) >> 4] == 0) && (ban_map[(s2 + 8) >> 4][s1 >> 4] == 2 || ban_map[(s2 + 8) >> 4][(s1 + 15) >> 4] == 2) ) {
915                 player[c1].y_add = -196608L;
916           player[c1].in_water = 0;
917                 player[c1].anim = 2;
918               player[c1].frame = 0;
919             player[c1].frame_tick = 0;
920                                         player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
921                         player[c1].jump_ready = 0;
922 //                                      if (c1 == 3 && main_info.num_mouse_buttons == 2)
923 //                      player[c1].jump_abort = 0;
924 //                                      else
925                         player[c1].jump_abort = 1;
926                                         if (pogostick == 0)
927                                                 dj_play_sfx(SFX_JUMP, SFX_JUMP_FREQ + rnd(2000) - 1000, 64, 0, 0, -1);
928                                         else
929                                                 dj_play_sfx(SFX_SPRING, SFX_SPRING_FREQ + rnd(2000) - 1000, 64, 0, 0, -1);
930         }
931         }
932 //              if (pogostick == 0 && ( (c1 == 0 && key_pressed(KEY_PL1_JUMP) == 0) || (c1 == 1 && key_pressed(KEY_PL2_JUMP) == 0) || (c1 == 2 && joy.but1 == 0) || (c1 == 3 && mouse.but3 == 0) ) ) {
933                 if (pogostick == 0 && ( (c1 == 0 && key_pressed(KEY_PL1_JUMP) == 0) || (c1 == 1 && key_pressed(KEY_PL2_JUMP) == 0) || (c1 == 2 && joy.but1 == 0) || (c1 == 3 && ( (main_info.num_mouse_buttons == 2 && (mouse.but1 == 0 && mouse.but2 == 0) ) || (main_info.num_mouse_buttons == 3 && mouse.but3 == 0) ) ) ) ) {
934                 player[c1].jump_ready = 1;
935                   if (player[c1].in_water == 0 && player[c1].y_add < 0 && player[c1].jump_abort == 1) {
936                                         if (bunnies_in_space == 0)
937                                         player[c1].y_add += 32768;
938                                         else
939                                         player[c1].y_add += 16384;
940                         if (player[c1].y_add > 0)
941                                         player[c1].y_add = 0;
942                         }
943       }
944                         if (c1 == 3 && main_info.num_mouse_buttons == 2 && (mouse.but1 == 0 || mouse.but2 == 0) )
945                 player[c1].jump_ready = 1;
946
947                         }
948                         else {
949
950                         if ( ( (c1 == 0 && key_pressed(KEY_PL1_JUMP) == 1) || (c1 == 1 && key_pressed(KEY_PL2_JUMP) == 1) || (c1 == 2 && joy.but1 == 1)  || (c1 == 3 && mouse.but3 == 1) ) ) {
951                 player[c1].y_add -= 16384;
952                         if (player[c1].y_add < -400000L)
953                         player[c1].y_add = -400000L;
954                         if ( (ban_map[(s2 + 7) >> 4][s1 >> 4] == 0 || ban_map[(s2 + 7) >> 4][(s1 + 15) >> 4] == 0) && (ban_map[(s2 + 8) >> 4][s1 >> 4] == 2 || ban_map[(s2 + 8) >> 4][(s1 + 15) >> 4] == 2) )
955                                                 player[c1].in_water = 0;
956                                         if (rnd(100) <  50)
957                         add_object(OBJ_SMOKE, (player[c1].x >> 16) + 6 + rnd(5), (player[c1].y >> 16) + 10 + rnd(5), 0, 16384 + rnd(8192), OBJ_ANIM_SMOKE, 0);
958                                 }
959
960                         }
961
962         player[c1].x += player[c1].x_add;
963             if ( (player[c1].x >> 16) < 0) {
964                 player[c1].x = 0;
965                         player[c1].x_add = 0;
966       }
967             if ( (player[c1].x >> 16) + 15 > 351) {
968                 player[c1].x = 336L << 16;
969                         player[c1].x_add = 0;
970       }
971       if (player[c1].y > 0) {
972 //          if (player[c1].x_add < 0) {
973                 s1 = (player[c1].x >> 16);
974                 s2 = (player[c1].y >> 16);
975         if (ban_map[s2 >> 4][s1 >> 4] == 1 || ban_map[s2 >> 4][s1 >> 4] == 3 || ban_map[s2 >> 4][s1 >> 4] == 4 || ban_map[(s2 + 15) >> 4][s1 >> 4] == 1 || ban_map[(s2 + 15) >> 4][s1 >> 4] == 3 || ban_map[(s2 + 15) >> 4][s1 >> 4] == 4) {
976                 player[c1].x = ( ( (s1 + 16) & 0xfff0) ) << 16;
977                 player[c1].x_add = 0;
978             }
979 //      }
980 //          else {
981                 s1 = (player[c1].x >> 16);
982                 s2 = (player[c1].y >> 16);
983               if (ban_map[s2 >> 4][(s1 + 15) >> 4] == 1 || ban_map[s2 >> 4][(s1 + 15) >> 4] == 3 || ban_map[s2 >> 4][(s1 + 15) >> 4] == 4 || ban_map[(s2 + 15) >> 4][(s1 + 15) >> 4] == 1 || ban_map[(s2 + 15) >> 4][(s1 + 15) >> 4] == 3 || ban_map[(s2 + 15) >> 4][(s1 + 15) >> 4] == 4) {
984                 player[c1].x = ( ( (s1 + 16) & 0xfff0) - 16) << 16;
985                 player[c1].x_add = 0;
986         }
987 //          }
988                         }
989                         else {
990                 s1 = (player[c1].x >> 16);
991                 s2 = 0;
992         if (ban_map[s2 >> 4][s1 >> 4] == 1 || ban_map[s2 >> 4][s1 >> 4] == 3 || ban_map[s2 >> 4][s1 >> 4] == 4 || ban_map[(s2 + 15) >> 4][s1 >> 4] == 1 || ban_map[(s2 + 15) >> 4][s1 >> 4] == 3 || ban_map[(s2 + 15) >> 4][s1 >> 4] == 4) {
993                 player[c1].x = ( ( (s1 + 16) & 0xfff0) ) << 16;
994                 player[c1].x_add = 0;
995             }
996                 s1 = (player[c1].x >> 16);
997                 s2 = 0;
998               if (ban_map[s2 >> 4][(s1 + 15) >> 4] == 1 || ban_map[s2 >> 4][(s1 + 15) >> 4] == 3 || ban_map[s2 >> 4][(s1 + 15) >> 4] == 4 || ban_map[(s2 + 15) >> 4][(s1 + 15) >> 4] == 1 || ban_map[(s2 + 15) >> 4][(s1 + 15) >> 4] == 3 || ban_map[(s2 + 15) >> 4][(s1 + 15) >> 4] == 4) {
999                 player[c1].x = ( ( (s1 + 16) & 0xfff0) - 16) << 16;
1000                 player[c1].x_add = 0;
1001         }
1002       }
1003
1004             player[c1].y += player[c1].y_add;
1005
1006                 s1 = (player[c1].x >> 16);
1007                 s2 = (player[c1].y >> 16);
1008         if (ban_map[(s2 + 15) >> 4][(s1 + 8) >> 4] == 4 || ( (ban_map[(s2 + 15) >> 4][s1 >> 4] == 4 && ban_map[(s2 + 15) >> 4][(s1 + 15) >> 4] != 1) || (ban_map[(s2 + 15) >> 4][s1 >> 4] != 1 && ban_map[(s2 + 15) >> 4][(s1 + 15) >> 4] == 4) ) ) {
1009                                 player[c1].y = ( (player[c1].y >> 16) & 0xfff0) << 16;
1010                 player[c1].y_add = -400000L;
1011         player[c1].anim = 2;
1012               player[c1].frame = 0;
1013             player[c1].frame_tick = 0;
1014                                 player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
1015                         player[c1].jump_ready = 0;
1016         player[c1].jump_abort = 0;
1017                                 for (c2 = 0; c2 < 300; c2++) {
1018                                         if (objects[c2].used == 1 && objects[c2].type == OBJ_SPRING) {
1019                                                 if (ban_map[(s2 + 15) >> 4][(s1 + 8) >> 4] == 4) {
1020                                                         if ( (objects[c2].x >> 20) == ( (s1 + 8) >> 4) && (objects[c2].y >> 20) == ( (s2 + 15) >> 4) ) {
1021                                       objects[c2].frame = 0;
1022                                             objects[c2].ticks = object_anims[objects[c2].anim].frame[objects[c2].frame].ticks;
1023                                                 objects[c2].image = object_anims[objects[c2].anim].frame[objects[c2].frame].image;
1024                                                                 break;
1025                                                         }
1026                                                 }
1027                                                 else {
1028                                                         if (ban_map[(s2 + 15) >> 4][s1 >> 4] == 4) {
1029                                                                 if ( (objects[c2].x >> 20) == (s1 >> 4) && (objects[c2].y >> 20) == ( (s2 + 15) >> 4) ) {
1030                                               objects[c2].frame = 0;
1031                                                     objects[c2].ticks = object_anims[objects[c2].anim].frame[objects[c2].frame].ticks;
1032                                                         objects[c2].image = object_anims[objects[c2].anim].frame[objects[c2].frame].image;
1033                                                                         break;
1034                                                                 }
1035                                                         }
1036                                                         else if (ban_map[(s2 + 15) >> 4][(s1 + 15) >> 4] == 4) {
1037                                                                 if ( (objects[c2].x >> 20) == ( (s1 + 15) >> 4) && (objects[c2].y >> 20) == ( (s2 + 15) >> 4) ) {
1038                                               objects[c2].frame = 0;
1039                                                     objects[c2].ticks = object_anims[objects[c2].anim].frame[objects[c2].frame].ticks;
1040                                                         objects[c2].image = object_anims[objects[c2].anim].frame[objects[c2].frame].image;
1041                                                                         break;
1042                                                                 }
1043                                                         }
1044                                                 }
1045                                         }
1046                                 }
1047                                 dj_play_sfx(SFX_SPRING, SFX_SPRING_FREQ + rnd(2000) - 1000, 64, 0, 0, -1);
1048       }
1049
1050 /*          if ( (player[c1].y >> 16) < 0) {
1051                 player[c1].y = 0;
1052                         player[c1].y_add = 0;
1053       }*/
1054 //          if ( (player[c1].y >> 16) + 15 > 255) {
1055 //              player[c1].y = 240L << 16;
1056 //                      player[c1].y_add = 0;
1057 /*              player[c1].anim = 2;
1058         player[c1].frame = 0;
1059         player[c1].frame_tick = 0;*/
1060 //      }
1061 //          if (player[c1].y_add < 0) {
1062                 s1 = (player[c1].x >> 16);
1063                 s2 = (player[c1].y >> 16);
1064               if (s2 < 0)
1065                 s2 = 0;
1066               if (ban_map[s2 >> 4][s1 >> 4] == 1 || ban_map[s2 >> 4][s1 >> 4] == 3 || ban_map[s2 >> 4][s1 >> 4] == 4 || ban_map[s2 >> 4][(s1 + 15) >> 4] == 1 || ban_map[s2 >> 4][(s1 + 15) >> 4] == 3 || ban_map[s2 >> 4][(s1 + 15) >> 4] == 4) {
1067                 player[c1].y = ( ( (s2 + 16) & 0xfff0) ) << 16;
1068                 player[c1].y_add = 0;
1069                 player[c1].anim = 0;
1070           player[c1].frame = 0;
1071           player[c1].frame_tick = 0;
1072                                 player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
1073         }
1074 //      }
1075 //      if (player[c1].y_add > 0) {
1076                 s1 = (player[c1].x >> 16);
1077                 s2 = (player[c1].y >> 16);
1078               if (s2 < 0)
1079                 s2 = 0;
1080 //        if (ban_map[(s2 + 8) >> 4][s1 >> 4] == 2 || ban_map[(s2 + 8) >> 4][(s1 + 15) >> 4] == 2) {
1081         if (ban_map[(s2 + 8) >> 4][(s1 + 8) >> 4] == 2) {
1082                 if (player[c1].in_water == 0) {
1083                                         player[c1].in_water = 1;
1084                                           player[c1].anim = 4;
1085                         player[c1].frame = 0;
1086                       player[c1].frame_tick = 0;
1087                                         player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
1088                                                 if (player[c1].y_add >= 32768) {
1089                                 add_object(OBJ_SPLASH, (player[c1].x >> 16) + 8, ( (player[c1].y >> 16) & 0xfff0) + 15, 0, 0, OBJ_ANIM_SPLASH, 0);
1090                                                         if (blood_is_thicker_than_water == 0)
1091                                                                 dj_play_sfx(SFX_SPLASH, SFX_SPLASH_FREQ + rnd(2000) - 1000, 64, 0, 0, -1);
1092                                                         else
1093                                                                 dj_play_sfx(SFX_SPLASH, SFX_SPLASH_FREQ + rnd(2000) - 5000, 64, 0, 0, -1);
1094                                                 }
1095           }
1096                 player[c1].y_add -= 1536;
1097           if (player[c1].y_add < 0 && player[c1].anim != 5) {
1098                                           player[c1].anim = 5;
1099                         player[c1].frame = 0;
1100                       player[c1].frame_tick = 0;
1101                                         player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
1102           }
1103                 if (player[c1].y_add < -65536L)
1104             player[c1].y_add = -65536L;
1105                 if (player[c1].y_add > 65535L)
1106             player[c1].y_add = 65535L;
1107 /*                                player[c1].anim = 2;
1108                 player[c1].frame = 0;
1109               player[c1].frame_tick = 0;
1110                                 player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;*/
1111                   if (ban_map[(s2 + 15) >> 4][s1 >> 4] == 1 || ban_map[(s2 + 15) >> 4][s1 >> 4] == 3 || ban_map[(s2 + 15) >> 4][(s1 + 15) >> 4] == 1 || ban_map[(s2 + 15) >> 4][(s1 + 15) >> 4] == 3) {
1112                         player[c1].y = ( ( (s2 + 16) & 0xfff0) - 16) << 16;
1113                         player[c1].y_add = 0;
1114                     }
1115         }
1116           else if (ban_map[(s2 + 15) >> 4][s1 >> 4] == 1 || ban_map[(s2 + 15) >> 4][s1 >> 4] == 3 || ban_map[(s2 + 15) >> 4][s1 >> 4] == 4 || ban_map[(s2 + 15) >> 4][(s1 + 15) >> 4] == 1 || ban_map[(s2 + 15) >> 4][(s1 + 15) >> 4] == 3 || ban_map[(s2 + 15) >> 4][(s1 + 15) >> 4] == 4) {
1117                                         player[c1].in_water = 0;
1118                 player[c1].y = ( ( (s2 + 16) & 0xfff0) - 16) << 16;
1119                 player[c1].y_add = 0;
1120           if (player[c1].anim != 0 && player[c1].anim != 1) {
1121                   player[c1].anim = 0;
1122                       player[c1].frame = 0;
1123                       player[c1].frame_tick = 0;
1124                                         player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
1125 //                                              dj_play_sfx(SFX_LAND, SFX_LAND_FREQ, 64, 0, 0, -1);
1126           }
1127             }
1128         else {
1129                 if (player[c1].in_water == 0) {
1130                                                 if (bunnies_in_space == 0)
1131                                           player[c1].y_add += 12288;
1132                                                 else
1133                                           player[c1].y_add += 6144;
1134                                 if (player[c1].y_add > 327680L)
1135                                 player[c1].y_add = 327680L;
1136           }
1137           else {
1138                 player[c1].y = (player[c1].y & 0xffff0000) + 0x10000;
1139                                   player[c1].y_add = 0;
1140           }
1141                                         player[c1].in_water = 0;
1142         }
1143                         if (player[c1].y_add > 36864 && player[c1].anim != 3 && player[c1].in_water == 0) {
1144                                   player[c1].anim = 3;
1145                 player[c1].frame = 0;
1146               player[c1].frame_tick = 0;
1147                                 player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
1148         }
1149 //          }
1150
1151                                 }
1152
1153                         player[c1].frame_tick++;
1154             if (player[c1].frame_tick >= player_anims[player[c1].anim].frame[player[c1].frame].ticks) {
1155                 player[c1].frame++;
1156                                 if (player[c1].frame >= player_anims[player[c1].anim].num_frames) {
1157                 if (player[c1].anim != 6)
1158                                                 player[c1].frame = player_anims[player[c1].anim].restart_frame;
1159             else
1160                 position_player(c1);
1161           }
1162                       player[c1].frame_tick = 0;
1163               }
1164                                 player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
1165
1166     }
1167
1168   }
1169
1170 }
1171
1172
1173 void position_player(short player_num) {
1174         int c1;
1175   int s1, s2;
1176
1177   while (1) {
1178     while (1) {
1179                 s1 = rnd(22);
1180                         s2 = rnd(16);
1181       if (ban_map[s2][s1] == 0 && (ban_map[s2 + 1][s1] == 1 || ban_map[s2 + 1][s1] == 3) )
1182         break;
1183     }
1184           for (c1 = 0; c1 < 4; c1++) {
1185                 if (c1 != player_num && player[c1].enabled == 1) {
1186         if (abs( (s1 << 4) - (player[c1].x >> 16) ) < 32 && abs( (s2 << 4) - (player[c1].y >> 16) ) < 32)
1187                 break;
1188       }
1189           }
1190     if (c1 == 4) {
1191       player[player_num].dead_flag = 0;
1192                   player[player_num].x = (long)s1 << 20;
1193                         player[player_num].y = (long)s2 << 20;
1194                   player[player_num].x_add = player[player_num].y_add = 0;
1195                 player[player_num].direction = 0;
1196                 player[player_num].jump_ready = 1;
1197                 player[player_num].in_water = 0;
1198       player[player_num].anim = 0;
1199       player[player_num].frame = 0;
1200       player[player_num].frame_tick = 0;
1201       player[player_num].image = player_anims[player[player_num].anim].frame[player[player_num].frame].image;
1202         break;
1203     }
1204   }
1205
1206 }
1207
1208
1209 void fireworks(void) {
1210         FILE *handle;
1211         int c1, c2;
1212         int s1, s2, s3;
1213         struct {
1214                 char used, direction, colour;
1215                 int x, y;
1216                 int x_add, y_add;
1217                 int timer;
1218           int anim, frame, frame_tick, image;
1219         } rabbits[20];
1220         struct {
1221                 int x, y;
1222                 int old_x, old_y;
1223                 char col, back[2];
1224         } stars[300];
1225
1226         outportw(0x3c4, 0x0f02);
1227   memset( (char *)(0xa0000 - __djgpp_base_address), 0, 65535);
1228
1229   if ( (handle = dat_open("level.pcx", datfile_name, "rb") ) == 0) {
1230                 strcpy(main_info.error_str, "Error loading 'level.pcx', aborting...\n");
1231                 return;
1232         }
1233   read_pcx(handle, mask_pic, 102400, pal);
1234         fclose(handle);
1235
1236         memset(mask_pic, 0, 102400);
1237
1238         memset(ban_map, 0, sizeof(ban_map) );
1239
1240   outportb(0x3c8, 0);
1241         for (c1 = 0; c1 < 768; c1++)
1242                 outportb(0x3c9, 0);
1243
1244         for (c1 = 0; c1 < 4; c1++) {
1245                 outportw(0x3c4, ( (1 << c1) << 8) + 0x02);
1246                 for (c2 =       193; c2 < 256; c2++) {
1247                         memset( (void *)(0xa0000 + c2 * 100 - __djgpp_base_address), (c2 - 192) >> 2, 100);
1248                         memset( (void *)(0xa0000 + 32768 + c2 * 100 - __djgpp_base_address), (c2 - 192) >> 2, 100);
1249                 }
1250         }
1251
1252   outportb(0x3c8, 0);
1253         for (c1 = 0; c1 < 768; c1++)
1254                 outportb(0x3c9, pal[c1]);
1255
1256         for (c1 = 0; c1 < 20; c1++)
1257                 rabbits[c1].used = 0;
1258
1259         rabbits[0].used = 1;
1260         rabbits[0].colour = rnd(4);
1261         rabbits[0].x = (int)(150 + rnd(100) ) << 16;
1262         rabbits[0].y = 256 << 16;
1263         rabbits[0].x_add = ( (int)rnd(65535) << 1) - 65536;
1264         if (rabbits[0].x_add > 0)
1265                 rabbits[0].direction = 0;
1266         else
1267                 rabbits[0].direction = 1;
1268         rabbits[0].y_add = -262144 + (rnd(16384) * 5);
1269         rabbits[0].timer = 30 + rnd(150);
1270         rabbits[0].anim = 2;
1271   rabbits[0].frame = 0;
1272   rabbits[0].frame_tick = 0;
1273         rabbits[0].image = player_anims[rabbits[0].anim].frame[rabbits[0].frame].image + rabbits[0].colour * 18 + rabbits[0].direction * 9;
1274
1275         for (c1 = 0; c1 < 300; c1++) {
1276                 s1 = rnd(400);
1277                 s2 = rnd(256);
1278                 s3 = 30 - rnd(7);
1279                 stars[c1].x = stars[c1].old_x = (s1 << 16);
1280                 stars[c1].y = stars[c1].old_y = (s2 << 16);
1281                 stars[c1].col = s3;
1282                 outportw(0x3ce, ( (s1 & 3) << 8) + 0x04);
1283                 stars[c1].back[0] =     stars[c1].back[1] = *(char *)(0xa0000 + s2 * 100 + (s1 >> 2) - __djgpp_base_address);
1284         }
1285
1286         dj_set_nosound(0);
1287
1288   main_info.page_info[0].num_pobs = 0;
1289         main_info.page_info[1].num_pobs = 0;
1290   main_info.view_page = 0;
1291   main_info.draw_page = 1;
1292
1293         while (key_pressed(1) == 0) {
1294
1295                 dj_mix();
1296
1297                 for (c1 = 0; c1 < 300; c1++) {
1298                         stars[c1].old_x = stars[c1].x;
1299                         stars[c1].old_y = stars[c1].y;
1300                         stars[c1].y -= (int)(31 - stars[c1].col) * 16384;
1301                         if ( (stars[c1].y >> 16) < 0)
1302                                 stars[c1].y += 256 << 16;;
1303                         if ( (stars[c1].y >> 16) >= 256)
1304                                 stars[c1].y -= 256 << 16;;
1305                 }
1306
1307                 for (c1 = 0, c2 = 0; c1 < 20; c1++) {
1308                         if (rabbits[c1].used == 1)
1309                                 c2++;
1310                 }
1311                 if ( (c2 == 0 && rnd(10000) < 200) || (c2 == 1 && rnd(10000) < 150) || (c2 == 2 && rnd(10000) < 100) || (c2 == 3 && rnd(10000) < 50)) {
1312                         for (c1 = 0; c1 < 20; c1++) {
1313                                 if (rabbits[c1].used == 0) {
1314                                         rabbits[c1].used = 1;
1315                                         rabbits[c1].colour = rnd(4);
1316                                         rabbits[c1].x = (int)(150 + rnd(100) ) << 16;
1317                                         rabbits[c1].y = 256 << 16;
1318                                         rabbits[c1].x_add = ( (int)rnd(65535) << 1) - 65536;
1319                                         if (rabbits[c1].x_add > 0)
1320                                                 rabbits[c1].direction = 0;
1321                                         else
1322                                                 rabbits[c1].direction = 1;
1323                                         rabbits[c1].y_add = -262144 + (rnd(16384) * 5);
1324                                         rabbits[c1].timer = 30 + rnd(150);
1325                                         rabbits[c1].anim = 2;
1326                                 rabbits[c1].frame = 0;
1327                                   rabbits[c1].frame_tick = 0;
1328                                         rabbits[c1].image = player_anims[rabbits[c1].anim].frame[rabbits[c1].frame].image + rabbits[c1].colour * 18 + rabbits[c1].direction * 9;
1329                                         break;
1330                                 }
1331                         }
1332                 }
1333
1334                 dj_mix();
1335
1336           main_info.page_info[main_info.draw_page].num_pobs = 0;
1337
1338                 for (c1 = 0; c1 < 20; c1++) {
1339                         if (rabbits[c1].used == 1) {
1340                                 rabbits[c1].y_add += 2048;
1341                         if (rabbits[c1].y_add > 36864 && rabbits[c1].anim != 3) {
1342                                   rabbits[c1].anim = 3;
1343                 rabbits[c1].frame = 0;
1344               rabbits[c1].frame_tick = 0;
1345                                         rabbits[c1].image = player_anims[rabbits[c1].anim].frame[rabbits[c1].frame].image + rabbits[c1].colour * 18 + rabbits[c1].direction * 9;
1346         }
1347                                 rabbits[c1].x += rabbits[c1].x_add;
1348                                 rabbits[c1].y += rabbits[c1].y_add;
1349                                 if ( (rabbits[c1].x >> 16) < 16 || (rabbits[c1].x >> 16) > 400 || (rabbits[c1].y >> 16) > 256) {
1350                                         rabbits[c1].used = 0;
1351                                         continue;
1352                                 }
1353                                 rabbits[c1].timer--;
1354                                 if (rabbits[c1].timer <= 0) {
1355                                         rabbits[c1].used = 0;
1356                                         for (c2 = 0; c2 < 6; c2++)
1357                                                 add_object(OBJ_FUR, (rabbits[c1].x >> 16) + 6 + rnd(5), (rabbits[c1].y >> 16) + 6 + rnd(5), rabbits[c1].x_add + (rnd(65535) - 32768) * 3, rabbits[c1].y_add + (rnd(65535) - 32768) * 3, 0, 44 + rabbits[c1].colour * 8);
1358                                         for (c2 = 0; c2 < 6; c2++)
1359                                                 add_object(OBJ_FLESH, (rabbits[c1].x >> 16) + 6 + rnd(5), (rabbits[c1].y >> 16) + 6 + rnd(5), rabbits[c1].x_add + (rnd(65535) - 32768) * 3, rabbits[c1].y_add + (rnd(65535) - 32768) * 3, 0, 76);
1360                                         for (c2 = 0; c2 < 6; c2++)
1361                                                 add_object(OBJ_FLESH, (rabbits[c1].x >> 16) + 6 + rnd(5), (rabbits[c1].y >> 16) + 6 + rnd(5), rabbits[c1].x_add + (rnd(65535) - 32768) * 3, rabbits[c1].y_add + (rnd(65535) - 32768) * 3, 0, 77);
1362                                         for (c2 = 0; c2 < 8; c2++)
1363                                                 add_object(OBJ_FLESH, (rabbits[c1].x >> 16) + 6 + rnd(5), (rabbits[c1].y >> 16) + 6 + rnd(5), rabbits[c1].x_add + (rnd(65535) - 32768) * 3, rabbits[c1].y_add + (rnd(65535) - 32768) * 3, 0, 78);
1364                                         for (c2 = 0; c2 < 10; c2++)
1365                                                 add_object(OBJ_FLESH, (rabbits[c1].x >> 16) + 6 + rnd(5), (rabbits[c1].y >> 16) + 6 + rnd(5), rabbits[c1].x_add + (rnd(65535) - 32768) * 3, rabbits[c1].y_add + (rnd(65535) - 32768) * 3, 0, 79);
1366                                         dj_play_sfx(SFX_DEATH, SFX_DEATH_FREQ, 64, 0, 0, -1);
1367                                         continue;
1368                                 }
1369                         rabbits[c1].frame_tick++;
1370             if (rabbits[c1].frame_tick >= player_anims[rabbits[c1].anim].frame[rabbits[c1].frame].ticks) {
1371                 rabbits[c1].frame++;
1372                                 if (rabbits[c1].frame >= player_anims[rabbits[c1].anim].num_frames)
1373                                         rabbits[c1].frame = player_anims[rabbits[c1].anim].restart_frame;
1374                       rabbits[c1].frame_tick = 0;
1375               }
1376                                 rabbits[c1].image = player_anims[rabbits[c1].anim].frame[rabbits[c1].frame].image + rabbits[c1].colour * 18 + rabbits[c1].direction * 9;
1377                                 if (rabbits[c1].used == 1)
1378                                         add_pob(main_info.draw_page, rabbits[c1].x >> 16, rabbits[c1].y >> 16, rabbits[c1].image, rabbit_gobs);
1379                         }
1380                 }
1381
1382                 dj_mix();
1383
1384                 update_objects();
1385
1386                 for (c1 = 0; c1 < 300; c1++) {
1387                         outportw(0x3ce, ( ( (stars[c1].x >> 16) & 3) << 8) + 0x04);
1388                         outportw(0x3c4, ( (1 << ( (stars[c1].x >> 16) & 3) ) << 8) + 0x02);
1389                         stars[c1].back[main_info.draw_page] = *(char *)(0xa0000 + ( (int)main_info.draw_page << 15) + (stars[c1].y >> 16) * 100 + (stars[c1].x >> 18) - __djgpp_base_address);
1390                         *(char *)(0xa0000 + ( (int)main_info.draw_page << 15) + (stars[c1].y >> 16) * 100 + (stars[c1].x >> 18) - __djgpp_base_address) = stars[c1].col;
1391                 }
1392
1393                 dj_mix();
1394
1395                 draw_pobs(main_info.draw_page);
1396
1397 /*              outportb(0x3c8, 0);
1398                 outportb(0x3c9, 0);
1399                 outportb(0x3c9, 0);
1400                 outportb(0x3c9, 0);*/
1401
1402     main_info.draw_page ^= 1;
1403     main_info.view_page ^= 1;
1404                 outportw(0x3d4, (main_info.view_page << 23) + 0x0d);
1405                 outportw(0x3d4, ( (main_info.view_page << 15) & 0xff00) + 0x0c);
1406
1407                 while( (inportb(0x3da) & 8) == 0)
1408                         dj_mix();
1409           while( (inportb(0x3da) & 8) == 8)
1410                         dj_mix();
1411
1412 /*              outportb(0x3c8, 0);
1413                 outportb(0x3c9, 0);
1414                 outportb(0x3c9, 63);
1415                 outportb(0x3c9, 0);*/
1416
1417                 redraw_pob_backgrounds(main_info.draw_page);
1418
1419                 dj_mix();
1420
1421                 for (c1 = 299; c1 >= 0; c1--) {
1422                         outportw(0x3c4, ( (1 << ( (stars[c1].old_x >> 16) & 3) ) << 8) + 0x02);
1423                         *(char *)(0xa0000 + ( (int)main_info.draw_page << 15) + (stars[c1].old_y >> 16) * 100 + (stars[c1].old_x >> 18) - __djgpp_base_address) = stars[c1].back[main_info.draw_page];
1424                 }
1425
1426 /*              for (c1 = 0; c1 < 20; c1++) {
1427                         if (rabbits[c1].used == 1)
1428                                 break;
1429                 }
1430                 if (c1 == 20) {
1431                   for (c1 = 0; c1 < NUM_OBJECTS; c1++) {
1432                         if (objects[c1].used == 1)
1433                                         break;
1434                         }
1435                         if (c1 == NUM_OBJECTS) {
1436                                 for (c1 = 0; c1 < 4; c1++) {
1437                                         outportw(0x3c4, ( (1 << c1) << 8) + 0x02);
1438                                         memset( (void *)(0xa0000 + ( (int)main_info.draw_page << 15) - __djgpp_base_address), 0, 25600);
1439                                 }
1440                         }
1441                 }*/
1442
1443         }
1444
1445         dj_set_nosound(1);
1446
1447 }
1448
1449
1450 void add_object(char type, short x, short y, long x_add, long y_add, short anim, short frame) {
1451         int c1;
1452
1453   for (c1 = 0; c1 < NUM_OBJECTS; c1++) {
1454         if (objects[c1].used == 0) {
1455         objects[c1].used = 1;
1456       objects[c1].type = type;
1457       objects[c1].x = (long)x << 16;
1458       objects[c1].y = (long)y << 16;
1459       objects[c1].x_add = x_add;
1460       objects[c1].y_add = y_add;
1461       objects[c1].x_acc = 0;
1462       objects[c1].y_acc = 0;
1463       objects[c1].anim = anim;
1464       objects[c1].frame = frame;
1465       objects[c1].ticks = object_anims[anim].frame[frame].ticks;
1466       objects[c1].image = object_anims[anim].frame[frame].image;
1467       break;
1468     }
1469   }
1470
1471 }
1472
1473
1474 void update_objects(void) {
1475         int c1;
1476         int s1;
1477
1478         for (c1 = 0; c1 < NUM_OBJECTS; c1++) {
1479         if (objects[c1].used == 1) {
1480         switch (objects[c1].type) {
1481         case OBJ_SPRING:
1482                     objects[c1].ticks--;
1483                   if (objects[c1].ticks <= 0) {
1484                   objects[c1].frame++;
1485                 if (objects[c1].frame >= object_anims[objects[c1].anim].num_frames) {
1486                         objects[c1].frame--;
1487               objects[c1].ticks = object_anims[objects[c1].anim].frame[objects[c1].frame].ticks;
1488             }
1489                         else {
1490                         objects[c1].ticks = object_anims[objects[c1].anim].frame[objects[c1].frame].ticks;
1491                   objects[c1].image = object_anims[objects[c1].anim].frame[objects[c1].frame].image;
1492                   }
1493                 }
1494                     if (objects[c1].used == 1)
1495                         add_pob(main_info.draw_page, objects[c1].x >> 16, objects[c1].y >> 16, objects[c1].image, object_gobs);
1496           break;
1497                                 case OBJ_SPLASH:
1498                     objects[c1].ticks--;
1499                   if (objects[c1].ticks <= 0) {
1500                           objects[c1].frame++;
1501                         if (objects[c1].frame >= object_anims[objects[c1].anim].num_frames)
1502                         objects[c1].used = 0;
1503                     else {
1504                         objects[c1].ticks = object_anims[objects[c1].anim].frame[objects[c1].frame].ticks;
1505                           objects[c1].image = object_anims[objects[c1].anim].frame[objects[c1].frame].image;
1506                           }
1507                                         }
1508                     if (objects[c1].used == 1)
1509                         add_pob(main_info.draw_page, objects[c1].x >> 16, objects[c1].y >> 16, objects[c1].image, object_gobs);
1510                                         break;
1511         case OBJ_SMOKE:
1512                         objects[c1].x += objects[c1].x_add;
1513                         objects[c1].y += objects[c1].y_add;
1514                     objects[c1].ticks--;
1515                   if (objects[c1].ticks <= 0) {
1516                   objects[c1].frame++;
1517                 if (objects[c1].frame >= object_anims[objects[c1].anim].num_frames)
1518                         objects[c1].used = 0;
1519                         else {
1520                         objects[c1].ticks = object_anims[objects[c1].anim].frame[objects[c1].frame].ticks;
1521                   objects[c1].image = object_anims[objects[c1].anim].frame[objects[c1].frame].image;
1522                   }
1523                 }
1524                     if (objects[c1].used == 1)
1525                         add_pob(main_info.draw_page, objects[c1].x >> 16, objects[c1].y >> 16, objects[c1].image, object_gobs);
1526           break;
1527                                 case OBJ_YEL_BUTFLY:
1528                                 case OBJ_PINK_BUTFLY:
1529                                         objects[c1].x_acc += rnd(128) - 64;
1530                                         if (objects[c1].x_acc < -1024)
1531                                                 objects[c1].x_acc = -1024;
1532                                         if (objects[c1].x_acc > 1024)
1533                                                 objects[c1].x_acc = 1024;
1534                                         objects[c1].x_add += objects[c1].x_acc;
1535                                         if (objects[c1].x_add < -32768)
1536                                                 objects[c1].x_add = -32768;
1537                                         if (objects[c1].x_add > 32768)
1538                                                 objects[c1].x_add = 32768;
1539                         objects[c1].x += objects[c1].x_add;
1540                                         if ( (objects[c1].x >> 16) < 16) {
1541                                                 objects[c1].x = 16 << 16;
1542                                                 objects[c1].x_add =     -objects[c1].x_add >> 2;
1543                                                 objects[c1].x_acc = 0;
1544                                         }
1545                                         else if ( (objects[c1].x >> 16) > 350) {
1546                                                 objects[c1].x = 350 << 16;
1547                                                 objects[c1].x_add =     -objects[c1].x_add >> 2;
1548                                                 objects[c1].x_acc = 0;
1549                                         }
1550                                         if (ban_map[objects[c1].y >> 20][objects[c1].x >> 20] != 0) {
1551                                                 if (objects[c1].x_add < 0) {
1552                                                         objects[c1].x = ( ( (objects[c1].x >> 16) + 16) & 0xfff0) << 16;
1553                                                 }
1554                                                 else {
1555                                                         objects[c1].x = ( ( ( (objects[c1].x >> 16) - 16) & 0xfff0) + 15) << 16;
1556                                                 }
1557                                                 objects[c1].x_add = -objects[c1].x_add >> 2;
1558                                                 objects[c1].x_acc = 0;
1559                                         }
1560                                         objects[c1].y_acc += rnd(64) - 32;
1561                                         if (objects[c1].y_acc < -1024)
1562                                                 objects[c1].y_acc = -1024;
1563                                         if (objects[c1].y_acc > 1024)
1564                                                 objects[c1].y_acc = 1024;
1565                                         objects[c1].y_add += objects[c1].y_acc;
1566                                         if (objects[c1].y_add < -32768)
1567                                                 objects[c1].y_add = -32768;
1568                                         if (objects[c1].y_add > 32768)
1569                                                 objects[c1].y_add = 32768;
1570                         objects[c1].y += objects[c1].y_add;
1571                                         if ( (objects[c1].y >> 16) < 0) {
1572                                                 objects[c1].y = 0;
1573                                                 objects[c1].y_add =     -objects[c1].y_add >> 2;
1574                                                 objects[c1].y_acc = 0;
1575                                         }
1576                                         else if ( (objects[c1].y >> 16) > 255) {
1577                                                 objects[c1].y = 255 << 16;
1578                                                 objects[c1].y_add =     -objects[c1].y_add >> 2;
1579                                                 objects[c1].y_acc = 0;
1580                                         }
1581                                         if (ban_map[objects[c1].y >> 20][objects[c1].x >> 20] != 0) {
1582                                                 if (objects[c1].y_add < 0) {
1583                                                         objects[c1].y = ( ( (objects[c1].y >> 16) + 16) & 0xfff0) << 16;
1584                                                 }
1585                                                 else {
1586                                                         objects[c1].y = ( ( ( (objects[c1].y >> 16) - 16) & 0xfff0) + 15) << 16;
1587                                                 }
1588                                                 objects[c1].y_add =     -objects[c1].y_add >> 2;
1589                                                 objects[c1].y_acc = 0;
1590                                         }
1591                                         if (objects[c1].type == OBJ_YEL_BUTFLY) {
1592                                                 if (objects[c1].x_add < 0 && objects[c1].anim != OBJ_ANIM_YEL_BUTFLY_LEFT) {
1593                                     objects[c1].anim = OBJ_ANIM_YEL_BUTFLY_LEFT;
1594                                 objects[c1].frame = 0;
1595                                       objects[c1].ticks = object_anims[objects[c1].anim].frame[objects[c1].frame].ticks;
1596                                 objects[c1].image = object_anims[objects[c1].anim].frame[objects[c1].frame].image;
1597                                                 }
1598                                                 else if (objects[c1].x_add > 0 && objects[c1].anim != OBJ_ANIM_YEL_BUTFLY_RIGHT) {
1599                                     objects[c1].anim = OBJ_ANIM_YEL_BUTFLY_RIGHT;
1600                                 objects[c1].frame = 0;
1601                                       objects[c1].ticks = object_anims[objects[c1].anim].frame[objects[c1].frame].ticks;
1602                                 objects[c1].image = object_anims[objects[c1].anim].frame[objects[c1].frame].image;
1603                                                 }
1604                                         }
1605                                         else {
1606                                                 if (objects[c1].x_add < 0 && objects[c1].anim != OBJ_ANIM_PINK_BUTFLY_LEFT) {
1607                                     objects[c1].anim = OBJ_ANIM_PINK_BUTFLY_LEFT;
1608                                 objects[c1].frame = 0;
1609                                       objects[c1].ticks = object_anims[objects[c1].anim].frame[objects[c1].frame].ticks;
1610                                 objects[c1].image = object_anims[objects[c1].anim].frame[objects[c1].frame].image;
1611                                                 }
1612                                                 else if (objects[c1].x_add > 0 && objects[c1].anim != OBJ_ANIM_PINK_BUTFLY_RIGHT) {
1613                                     objects[c1].anim = OBJ_ANIM_PINK_BUTFLY_RIGHT;
1614                                 objects[c1].frame = 0;
1615                                       objects[c1].ticks = object_anims[objects[c1].anim].frame[objects[c1].frame].ticks;
1616                                 objects[c1].image = object_anims[objects[c1].anim].frame[objects[c1].frame].image;
1617                                                 }
1618                                         }
1619                     objects[c1].ticks--;
1620                   if (objects[c1].ticks <= 0) {
1621                   objects[c1].frame++;
1622                 if (objects[c1].frame >= object_anims[objects[c1].anim].num_frames)
1623                         objects[c1].frame =     object_anims[objects[c1].anim].restart_frame;
1624                         else {
1625                         objects[c1].ticks = object_anims[objects[c1].anim].frame[objects[c1].frame].ticks;
1626                   objects[c1].image = object_anims[objects[c1].anim].frame[objects[c1].frame].image;
1627                   }
1628                 }
1629                     if (objects[c1].used == 1)
1630                         add_pob(main_info.draw_page, objects[c1].x >> 16, objects[c1].y >> 16, objects[c1].image, object_gobs);
1631                                         break;
1632                                 case OBJ_FUR:
1633                                         if (rnd(100) < 30)
1634                                                 add_object(OBJ_FLESH_TRACE, objects[c1].x >> 16, objects[c1].y >> 16, 0, 0, OBJ_ANIM_FLESH_TRACE, 0);
1635                                         if (ban_map[objects[c1].y >> 20][objects[c1].x >> 20] == 0) {
1636                                                 objects[c1].y_add += 3072;
1637                                 if (objects[c1].y_add > 196608L)
1638                                 objects[c1].y_add = 196608L;
1639                                         }
1640                                         else if (ban_map[objects[c1].y >> 20][objects[c1].x >> 20] == 2) {
1641                                                 if (objects[c1].x_add < 0) {
1642                                                         if (objects[c1].x_add < -65536L)
1643                                                                 objects[c1].x_add = -65536L;
1644                                                         objects[c1].x_add += 1024;
1645                                                         if (objects[c1].x_add > 0)
1646                                                                 objects[c1].x_add = 0;
1647                                                 }
1648                                                 else {
1649                                                         if (objects[c1].x_add > 65536L)
1650                                                                 objects[c1].x_add = 65536L;
1651                                                         objects[c1].x_add -= 1024;
1652                                                         if (objects[c1].x_add < 0)
1653                                                                 objects[c1].x_add = 0;
1654                                                 }
1655                                                 objects[c1].y_add += 1024;
1656                                 if (objects[c1].y_add < -65536L)
1657                                 objects[c1].y_add = -65536L;
1658                                 if (objects[c1].y_add > 65536L)
1659                                 objects[c1].y_add = 65536L;
1660                                         }
1661                         objects[c1].x += objects[c1].x_add;
1662                                         if ( (objects[c1].y >> 16) > 0 && (ban_map[objects[c1].y >> 20][objects[c1].x >> 20] == 1 || ban_map[objects[c1].y >> 20][objects[c1].x >> 20] == 3) ) {
1663                                                 if (objects[c1].x_add < 0) {
1664                                                         objects[c1].x = ( ( (objects[c1].x >> 16) + 16) & 0xfff0) << 16;
1665                                                         objects[c1].x_add =     -objects[c1].x_add >> 2;
1666                                                 }
1667                                                 else {
1668                                                         objects[c1].x = ( ( ( (objects[c1].x >> 16) - 16) & 0xfff0) + 15) << 16;
1669                                                         objects[c1].x_add =     -objects[c1].x_add >> 2;
1670                                                 }
1671                                         }
1672                         objects[c1].y += objects[c1].y_add;
1673                                         if ( (objects[c1].x >> 16) < -5 ||      (objects[c1].x >> 16) > 405 || (objects[c1].y >> 16) > 260)
1674                                                 objects[c1].used = 0;
1675                                         if ( (objects[c1].y >> 16) > 0 && (ban_map[objects[c1].y >> 20][objects[c1].x >> 20] != 0) ) {
1676                                                 if (objects[c1].y_add < 0) {
1677                                                         if (ban_map[objects[c1].y >> 20][objects[c1].x >> 20] != 2) {
1678                                                                 objects[c1].y = ( ( (objects[c1].y >> 16) + 16) & 0xfff0) << 16;
1679                                                                 objects[c1].x_add >>= 2;
1680                                                                 objects[c1].y_add =     -objects[c1].y_add >> 2;
1681                                                         }
1682                                                 }
1683                                                 else {
1684                                                         if (ban_map[objects[c1].y >> 20][objects[c1].x >> 20] == 1) {
1685                                                                 if (objects[c1].y_add > 131072L) {
1686                                                                         objects[c1].y = ( ( ( (objects[c1].y >> 16) - 16) & 0xfff0) + 15) << 16;
1687                                                                         objects[c1].x_add >>= 2;
1688                                                                         objects[c1].y_add =     -objects[c1].y_add >> 2;
1689                                                                 }
1690                                                                 else
1691                                                                         objects[c1].used = 0;
1692                                                         }
1693                                                         else if (ban_map[objects[c1].y >> 20][objects[c1].x >> 20] == 3) {
1694                                                                 objects[c1].y = ( ( ( (objects[c1].y >> 16) - 16) & 0xfff0) + 15) << 16;
1695                                                                 if (objects[c1].y_add > 131072L)
1696                                                                         objects[c1].y_add =     -objects[c1].y_add >> 2;
1697                                                                 else
1698                                                                         objects[c1].y_add = 0;
1699                                                         }
1700                                                 }
1701                                         }
1702                                         if (objects[c1].x_add < 0 && objects[c1].x_add > -16384)
1703                                                 objects[c1].x_add = -16384;
1704                                         if (objects[c1].x_add > 0 && objects[c1].x_add < 16384)
1705                                                 objects[c1].x_add = 16384;
1706                     if (objects[c1].used == 1) {
1707                                                 s1 = atan2(objects[c1].y_add, objects[c1].x_add) * 4 / M_PI;
1708                                                 if (s1 < 0)
1709                                                         s1 += 8;
1710                                                 if (s1 < 0)
1711                                                         s1 = 0;
1712                                                 if (s1 > 7)
1713                                                         s1 = 7;
1714                                                 add_pob(main_info.draw_page, objects[c1].x >> 16, objects[c1].y >> 16, objects[c1].frame + s1, object_gobs);
1715 //                                              add_pob(main_info.draw_page, objects[c1].x >> 16, objects[c1].y >> 16, objects[c1].frame, object_gobs);
1716                                         }
1717                                         break;
1718                                 case OBJ_FLESH:
1719                                         if (rnd(100) < 30) {
1720                                                 if (objects[c1].frame == 76)
1721                                                         add_object(OBJ_FLESH_TRACE, objects[c1].x >> 16, objects[c1].y >> 16, 0, 0, OBJ_ANIM_FLESH_TRACE, 1);
1722                                                 else if (objects[c1].frame == 77)
1723                                                         add_object(OBJ_FLESH_TRACE, objects[c1].x >> 16, objects[c1].y >> 16, 0, 0, OBJ_ANIM_FLESH_TRACE, 2);
1724                                                 else if (objects[c1].frame == 78)
1725                                                         add_object(OBJ_FLESH_TRACE, objects[c1].x >> 16, objects[c1].y >> 16, 0, 0, OBJ_ANIM_FLESH_TRACE, 3);
1726                                         }
1727                                         if (ban_map[objects[c1].y >> 20][objects[c1].x >> 20] == 0) {
1728                                                 objects[c1].y_add += 3072;
1729                                 if (objects[c1].y_add > 196608L)
1730                                 objects[c1].y_add = 196608L;
1731                                         }
1732                                         else if (ban_map[objects[c1].y >> 20][objects[c1].x >> 20] == 2) {
1733                                                 if (objects[c1].x_add < 0) {
1734                                                         if (objects[c1].x_add < -65536L)
1735                                                                 objects[c1].x_add = -65536L;
1736                                                         objects[c1].x_add += 1024;
1737                                                         if (objects[c1].x_add > 0)
1738                                                                 objects[c1].x_add = 0;
1739                                                 }
1740                                                 else {
1741                                                         if (objects[c1].x_add > 65536L)
1742                                                                 objects[c1].x_add = 65536L;
1743                                                         objects[c1].x_add -= 1024;
1744                                                         if (objects[c1].x_add < 0)
1745                                                                 objects[c1].x_add = 0;
1746                                                 }
1747                                                 objects[c1].y_add += 1024;
1748                                 if (objects[c1].y_add < -65536L)
1749                                 objects[c1].y_add = -65536L;
1750                                 if (objects[c1].y_add > 65536L)
1751                                 objects[c1].y_add = 65536L;
1752                                         }
1753                         objects[c1].x += objects[c1].x_add;
1754                                         if ( (objects[c1].y >> 16) > 0 && (ban_map[objects[c1].y >> 20][objects[c1].x >> 20] == 1 || ban_map[objects[c1].y >> 20][objects[c1].x >> 20] == 3) ) {
1755                                                 if (objects[c1].x_add < 0) {
1756                                                         objects[c1].x = ( ( (objects[c1].x >> 16) + 16) & 0xfff0) << 16;
1757                                                         objects[c1].x_add =     -objects[c1].x_add >> 2;
1758                                                 }
1759                                                 else {
1760                                                         objects[c1].x = ( ( ( (objects[c1].x >> 16) - 16) & 0xfff0) + 15) << 16;
1761                                                         objects[c1].x_add =     -objects[c1].x_add >> 2;
1762                                                 }
1763                                         }
1764                         objects[c1].y += objects[c1].y_add;
1765                                         if ( (objects[c1].x >> 16) < -5 ||      (objects[c1].x >> 16) > 405 || (objects[c1].y >> 16) > 260)
1766                                                 objects[c1].used = 0;
1767                                         if ( (objects[c1].y >> 16) > 0 && (ban_map[objects[c1].y >> 20][objects[c1].x >> 20] != 0) ) {
1768                                                 if (objects[c1].y_add < 0) {
1769                                                         if (ban_map[objects[c1].y >> 20][objects[c1].x >> 20] != 2) {
1770                                                                 objects[c1].y = ( ( (objects[c1].y >> 16) + 16) & 0xfff0) << 16;
1771                                                                 objects[c1].x_add >>= 2;
1772                                                                 objects[c1].y_add =     -objects[c1].y_add >> 2;
1773                                                         }
1774                                                 }
1775                                                 else {
1776                                                         if (ban_map[objects[c1].y >> 20][objects[c1].x >> 20] == 1) {
1777                                                                 if (objects[c1].y_add > 131072L) {
1778                                                                         objects[c1].y = ( ( ( (objects[c1].y >> 16) - 16) & 0xfff0) + 15) << 16;
1779                                                                         objects[c1].x_add >>= 2;
1780                                                                         objects[c1].y_add =     -objects[c1].y_add >> 2;
1781                                                                 }
1782                                                                 else {
1783                                                                         if (rnd(100) < 10) {
1784                                                                                 s1 = rnd(4) - 2;
1785                                                                                 add_leftovers(0, objects[c1].x >> 16, (objects[c1].y >> 16) + s1, objects[c1].frame, object_gobs);
1786                                                                                 add_leftovers(1, objects[c1].x >> 16, (objects[c1].y >> 16) + s1, objects[c1].frame, object_gobs);
1787                                                                         }
1788                                                                         objects[c1].used = 0;
1789                                                                 }
1790                                                         }
1791                                                         else if (ban_map[objects[c1].y >> 20][objects[c1].x >> 20] == 3) {
1792                                                                 objects[c1].y = ( ( ( (objects[c1].y >> 16) - 16) & 0xfff0) + 15) << 16;
1793                                                                 if (objects[c1].y_add > 131072L)
1794                                                                         objects[c1].y_add =     -objects[c1].y_add >> 2;
1795                                                                 else
1796                                                                         objects[c1].y_add = 0;
1797                                                         }
1798                                                 }
1799                                         }
1800                                         if (objects[c1].x_add < 0 && objects[c1].x_add > -16384)
1801                                                 objects[c1].x_add = -16384;
1802                                         if (objects[c1].x_add > 0 && objects[c1].x_add < 16384)
1803                                                 objects[c1].x_add = 16384;
1804                     if (objects[c1].used == 1)
1805                                                 add_pob(main_info.draw_page, objects[c1].x >> 16, objects[c1].y >> 16, objects[c1].frame, object_gobs);
1806                                         break;
1807                                 case OBJ_FLESH_TRACE:
1808                     objects[c1].ticks--;
1809                   if (objects[c1].ticks <= 0) {
1810                   objects[c1].frame++;
1811                 if (objects[c1].frame >= object_anims[objects[c1].anim].num_frames)
1812                         objects[c1].used = 0;
1813                         else {
1814                         objects[c1].ticks = object_anims[objects[c1].anim].frame[objects[c1].frame].ticks;
1815                   objects[c1].image = object_anims[objects[c1].anim].frame[objects[c1].frame].image;
1816                   }
1817                 }
1818                     if (objects[c1].used == 1)
1819                         add_pob(main_info.draw_page, objects[c1].x >> 16, objects[c1].y >> 16, objects[c1].image, object_gobs);
1820                                         break;
1821       }
1822     }
1823   }
1824
1825 }
1826
1827
1828 char add_pob(char page, short x, short y, short image, char *pob_data) {
1829
1830         if (main_info.page_info[page].num_pobs >= NUM_POBS)
1831                 return 1;
1832
1833         main_info.page_info[page].pobs[main_info.page_info[page].num_pobs].x = x;
1834         main_info.page_info[page].pobs[main_info.page_info[page].num_pobs].y = y;
1835         main_info.page_info[page].pobs[main_info.page_info[page].num_pobs].image = image;
1836         main_info.page_info[page].pobs[main_info.page_info[page].num_pobs].pob_data = pob_data;
1837         main_info.page_info[page].num_pobs++;
1838
1839         return 0;
1840
1841 }
1842
1843
1844 void draw_pobs(char page) {
1845         int c1;
1846         int back_buf_ofs;
1847
1848         back_buf_ofs = 0;
1849
1850         for (c1 = main_info.page_info[page].num_pobs - 1; c1 >= 0; c1--) {
1851                 main_info.page_info[page].pobs[c1].back_buf_ofs = back_buf_ofs;
1852                 get_block(page, main_info.page_info[page].pobs[c1].x - pob_hs_x(main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data), main_info.page_info[page].pobs[c1].y - pob_hs_y(main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data), pob_width(main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data), pob_height(main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data), (char *)(main_info.pob_backbuf[page] + back_buf_ofs) );
1853                 back_buf_ofs += pob_width(main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data) * pob_height(main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data);
1854                 put_pob(page, main_info.page_info[page].pobs[c1].x, main_info.page_info[page].pobs[c1].y, main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data, 1, mask_pic);
1855         }
1856
1857 }
1858
1859
1860 void redraw_pob_backgrounds(char page) {
1861         int c1;
1862
1863         for (c1 = 0; c1 < main_info.page_info[page].num_pobs; c1++)
1864                 put_block(page, main_info.page_info[page].pobs[c1].x - pob_hs_x(main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data), main_info.page_info[page].pobs[c1].y - pob_hs_y(main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data), pob_width(main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data), pob_height(main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data), (char *)(main_info.pob_backbuf[page] + main_info.page_info[page].pobs[c1].back_buf_ofs) );
1865
1866 }
1867
1868
1869 char add_leftovers(char page, short x, short y, short image, char *pob_data) {
1870
1871         if (leftovers.page[page].num_pobs >= NUM_LEFTOVERS)
1872                 return 1;
1873
1874         leftovers.page[page].pobs[leftovers.page[page].num_pobs].x = x;
1875         leftovers.page[page].pobs[leftovers.page[page].num_pobs].y = y;
1876         leftovers.page[page].pobs[leftovers.page[page].num_pobs].image = image;
1877         leftovers.page[page].pobs[leftovers.page[page].num_pobs].pob_data = pob_data;
1878         leftovers.page[page].num_pobs++;
1879
1880         return 0;
1881
1882 }
1883
1884
1885 void draw_leftovers(char page) {
1886         int c1;
1887         int back_buf_ofs;
1888
1889         for (c1 = leftovers.page[page].num_pobs - 1; c1 >= 0; c1--)
1890                 put_pob(page, leftovers.page[page].pobs[c1].x, leftovers.page[page].pobs[c1].y, leftovers.page[page].pobs[c1].image, leftovers.page[page].pobs[c1].pob_data, 1, mask_pic);
1891
1892         leftovers.page[page].num_pobs = 0;
1893
1894 }
1895
1896
1897 char init_level(short level) {
1898         FILE *handle;
1899   int c1, c2;
1900   int l1;
1901   int s1, s2;
1902
1903   if ( (handle = dat_open("level.pcx", datfile_name, "rb") ) == 0) {
1904                 strcpy(main_info.error_str, "Error loading 'level.pcx', aborting...\n");
1905                 return 1;
1906         }
1907   if (read_pcx(handle, background_pic, 102400L, pal) != 0) {
1908                 strcpy(main_info.error_str, "Error loading 'level.pcx', aborting...\n");
1909                 return 1;
1910         }
1911         fclose(handle);
1912   if ( (handle = dat_open("mask.pcx", datfile_name, "rb") ) == 0) {
1913                 strcpy(main_info.error_str, "Error loading 'mask.pcx', aborting...\n");
1914                 return 1;
1915         }
1916   if (read_pcx(handle, mask_pic, 102400L, 0) != 0) {
1917                 strcpy(main_info.error_str, "Error loading 'mask.pcx', aborting...\n");
1918                 return 1;
1919         }
1920         fclose(handle);
1921         memset(cur_pal, 0, 768);
1922
1923   for (c1 = 0; c1 < 4; c1++) {
1924         if (player[c1].enabled == 1) {
1925                         player[c1].bumps = 0;
1926                         player[c1].bumped[0] = 0;
1927                         player[c1].bumped[1] = 0;
1928                         player[c1].bumped[2] = 0;
1929                         player[c1].bumped[3] = 0;
1930             position_player(c1);
1931                 }
1932   }
1933
1934         for (c1 = 0; c1 <       300; c1++)
1935                 objects[c1].used = 0;
1936
1937 //      add_object(OBJ_SPRING, 144, 224, 0, 0, OBJ_ANIM_SPRING, 5);
1938
1939         for (c1 = 0; c1 < 16; c1++) {
1940                 for (c2 = 0; c2 < 22; c2++) {
1941                         if (ban_map[c1][c2] == 4)
1942                                 add_object(OBJ_SPRING, c2 << 4, c1 << 4, 0, 0, OBJ_ANIM_SPRING, 5);
1943                 }
1944         }
1945
1946         while (1) {
1947                 s1 = rnd(22);
1948                 s2 = rnd(16);
1949                 if (ban_map[s2][s1] == 0) {
1950                         add_object(OBJ_YEL_BUTFLY, (s1 << 4) + 8, (s2 << 4) + 8, (rnd(65535) - 32768) * 2, (rnd(65535) - 32768) * 2, 0, 0);
1951                         break;
1952                 }
1953         }
1954         while (1) {
1955                 s1 = rnd(22);
1956                 s2 = rnd(16);
1957                 if (ban_map[s2][s1] == 0) {
1958                         add_object(OBJ_YEL_BUTFLY, (s1 << 4) + 8, (s2 << 4) + 8, (rnd(65535) - 32768) * 2, (rnd(65535) - 32768) * 2, 0, 0);
1959                         break;
1960                 }
1961         }
1962         while (1) {
1963                 s1 = rnd(22);
1964                 s2 = rnd(16);
1965                 if (ban_map[s2][s1] == 0) {
1966                         add_object(OBJ_PINK_BUTFLY, (s1 << 4) + 8, (s2 << 4) + 8, (rnd(65535) - 32768) * 2, (rnd(65535) - 32768) * 2, 0, 0);
1967                         break;
1968                 }
1969         }
1970         while (1) {
1971                 s1 = rnd(22);
1972                 s2 = rnd(16);
1973                 if (ban_map[s2][s1] == 0) {
1974                         add_object(OBJ_PINK_BUTFLY, (s1 << 4) + 8, (s2 << 4) + 8, (rnd(65535) - 32768) * 2, (rnd(65535) - 32768) * 2, 0, 0);
1975                         break;
1976                 }
1977         }
1978
1979   return 0;
1980
1981 }
1982
1983
1984 void deinit_level(void) {
1985         int c1, c2;
1986
1987         dj_set_nosound(1);
1988   dj_stop_mod();
1989
1990 }
1991
1992
1993 char init_program(int argc, char *argv[]) {
1994         FILE *handle;
1995         int c1, c2;
1996         char load_flag;
1997         char force2, force3;
1998         sfx_data fly;
1999         int player_anim_data[] = {1, 0, 0, 0x7fff, 0, 0, 0, 0, 0, 0,
2000                                                                                                                 4, 0, 0, 4, 1, 4, 2, 4, 3, 4,
2001                                                 1, 0, 4, 0x7fff, 0, 0, 0, 0, 0, 0,
2002                                                 4, 2, 5, 8, 6, 10, 7, 3, 6, 3,
2003                                                         1, 0, 6, 0x7fff, 0, 0, 0, 0, 0, 0,
2004                                                 2, 1, 5, 8, 4, 0x7fff, 0, 0, 0, 0,
2005                                                 1, 0, 8, 5, 0, 0, 0, 0, 0, 0};
2006
2007         if (__djgpp_nearptr_enable() == 0)
2008         return 1;
2009
2010   srandom(time(0) );
2011
2012   if (hook_keyb_handler() != 0)
2013         return 1;
2014
2015         memset(&main_info, 0, sizeof(main_info) );
2016         main_info.joy_enabled = 1;
2017
2018         strcpy(datfile_name, "jumpbump.dat");
2019
2020         force2 = force3 = 0;
2021
2022         if (argc > 1) {
2023                 for (c1 = 1; c1 < argc; c1++) {
2024                         if (stricmp(argv[c1], "-nosound") == 0)
2025                                 main_info.no_sound = 1;
2026                         else if (stricmp(argv[c1], "-nogore") == 0)
2027                                 main_info.no_gore = 1;
2028                         else if (stricmp(argv[c1], "-nojoy") == 0)
2029                                 main_info.joy_enabled = 0;
2030                         else if (stricmp(argv[c1], "-fireworks") == 0)
2031                                 main_info.fireworks = 1;
2032                         else if (stricmp(argv[c1], "-dat") == 0) {
2033                                 if (c1 < (argc - 1) ) {
2034                                         if ( (handle = fopen(argv[c1 + 1], "rb") ) != NULL) {
2035                                                 fclose(handle);
2036                                                 strcpy(datfile_name, argv[c1 + 1]);
2037                                         }
2038                                 }
2039                         }
2040                         else if (stricmp(argv[c1], "-mouse") == 0) {
2041                                 if (c1 < (argc - 1) ) {
2042                                         if (stricmp(argv[c1 + 1], "2") == 0)
2043                                                 force2 = 1;
2044                                         if (stricmp(argv[c1 + 1], "3") == 0)
2045                                                 force3 = 1;
2046                                 }
2047                         }
2048                 }
2049         }
2050
2051         for (c1 = 0; c1 < 7; c1++) {
2052                 player_anims[c1].num_frames = player_anim_data[c1 * 10];
2053                 player_anims[c1].restart_frame = player_anim_data[c1 * 10 + 1];
2054                 for (c2 = 0; c2 < 4; c2++) {
2055                         player_anims[c1].frame[c2].image = player_anim_data[c1 * 10 + c2 * 2 + 2];
2056                         player_anims[c1].frame[c2].ticks = player_anim_data[c1 * 10 + c2 * 2 + 3];
2057                 }
2058         }
2059
2060   if ( (background_pic = malloc(102400L) ) == 0)
2061     return 1;
2062   if ( (mask_pic = malloc(102400L) ) == 0)
2063     return 1;
2064         memset(mask_pic, 0, 102400);
2065
2066         main_info.pob_backbuf[0] = malloc(65535);
2067         main_info.pob_backbuf[1] = malloc(65535);
2068         if (main_info.pob_backbuf[0] == 0 || main_info.pob_backbuf[1] == 0)
2069                 return 1;
2070
2071   if ( (handle = dat_open("rabbit.gob", datfile_name, "rb") ) == 0) {
2072                 strcpy(main_info.error_str, "Error loading 'rabbit.gob', aborting...\n");
2073     return 1;
2074         }
2075   if ( (rabbit_gobs = malloc(dat_filelen("rabbit.gob", datfile_name) ) ) == 0) {
2076                 strcpy(main_info.error_str, "Not enough memory, aborting...\n");
2077     fclose(handle);
2078     return 1;
2079   }
2080         fread(rabbit_gobs, 1,   dat_filelen("rabbit.gob", datfile_name), handle);
2081   fclose(handle);
2082
2083   if ( (handle = dat_open("objects.gob", datfile_name, "rb") ) == 0) {
2084                 strcpy(main_info.error_str, "Error loading 'objects.gob', aborting...\n");
2085     return 1;
2086         }
2087   if ( (object_gobs = malloc(dat_filelen("objects.gob", datfile_name) ) ) == 0) {
2088                 strcpy(main_info.error_str, "Not enough memory, aborting...\n");
2089     fclose(handle);
2090     return 1;
2091   }
2092         fread(object_gobs, 1,   dat_filelen("objects.gob", datfile_name), handle);
2093   fclose(handle);
2094
2095   if ( (handle = dat_open("font.gob", datfile_name, "rb") ) == 0) {
2096                 strcpy(main_info.error_str, "Error loading 'font.gob', aborting...\n");
2097     return 1;
2098         }
2099   if ( (font_gobs = malloc(dat_filelen("font.gob", datfile_name) ) ) == 0) {
2100                 strcpy(main_info.error_str, "Not enough memory, aborting...\n");
2101     fclose(handle);
2102     return 1;
2103   }
2104         fread(font_gobs, 1,     dat_filelen("font.gob", datfile_name), handle);
2105   fclose(handle);
2106
2107   if ( (handle = dat_open("numbers.gob", datfile_name, "rb") ) == 0) {
2108                 strcpy(main_info.error_str, "Error loading 'numbers.gob', aborting...\n");
2109     return 1;
2110         }
2111   if ( (number_gobs = malloc(dat_filelen("numbers.gob", datfile_name) ) ) == 0) {
2112                 strcpy(main_info.error_str, "Not enough memory, aborting...\n");
2113     fclose(handle);
2114     return 1;
2115   }
2116         fread(number_gobs, 1,   dat_filelen("numbers.gob", datfile_name), handle);
2117   fclose(handle);
2118
2119         if (read_level() != 0) {
2120                 strcpy(main_info.error_str, "Error loading 'levelmap.txt', aborting...\n");
2121     fclose(handle);
2122     return 1;
2123         }
2124
2125         dj_init();
2126         if (main_info.no_sound == 0) {
2127           dj_autodetect_sd();
2128                 dj_set_mixing_freq(20000);
2129                 dj_set_stereo(0);
2130         dj_set_auto_mix(0);
2131           dj_set_dma_time(8);
2132                 dj_set_num_sfx_channels(5);
2133                 dj_set_sfx_volume(64);
2134                 dj_set_nosound(1);
2135         dj_start();
2136
2137           if ( (handle = dat_open("jump.mod", datfile_name, "rb") ) == 0) {
2138                         strcpy(main_info.error_str, "Error loading 'jump.mod', aborting...\n");
2139           return 1;
2140                 }
2141           if (dj_load_mod(handle, 0, MOD_MENU) != 0) {
2142                         strcpy(main_info.error_str, "Error loading 'jump.mod', aborting...\n");
2143           return 1;
2144           }
2145                 fclose(handle);
2146
2147           if ( (handle = dat_open("bump.mod", datfile_name, "rb") ) == 0) {
2148                         strcpy(main_info.error_str, "Error loading 'bump.mod', aborting...\n");
2149           return 1;
2150                 }
2151           if (dj_load_mod(handle, 0, MOD_GAME) != 0) {
2152                         strcpy(main_info.error_str, "Error loading 'bump.mod', aborting...\n");
2153           return 1;
2154           }
2155                 fclose(handle);
2156
2157           if ( (handle = dat_open("scores.mod", datfile_name, "rb") ) == 0) {
2158                         strcpy(main_info.error_str, "Error loading 'scores.mod', aborting...\n");
2159           return 1;
2160                 }
2161           if (dj_load_mod(handle, 0, MOD_SCORES) != 0) {
2162                         strcpy(main_info.error_str, "Error loading 'scores.mod', aborting...\n");
2163           return 1;
2164           }
2165                 fclose(handle);
2166
2167           if ( (handle = dat_open("jump.smp", datfile_name, "rb") ) == 0) {
2168                         strcpy(main_info.error_str, "Error loading 'jump.smp', aborting...\n");
2169           return 1;
2170                 }
2171                 if (dj_load_sfx(handle, 0, dat_filelen("jump.smp", datfile_name), DJ_SFX_TYPE_SMP, SFX_JUMP) != 0) {
2172                         strcpy(main_info.error_str, "Error loading 'jump.smp', aborting...\n");
2173           return 1;
2174           }
2175                 fclose(handle);
2176
2177 /*        if ( (handle = dat_open("land.smp", datfile_name, "rb") ) == 0) {
2178                         strcpy(main_info.error_str, "Error loading 'land.smp', aborting...\n");
2179           return 1;
2180                 }
2181                 if (dj_load_sfx(handle, 0, dat_filelen("land.smp", datfile_name), DJ_SFX_TYPE_SMP, SFX_LAND) != 0) {
2182                         strcpy(main_info.error_str, "Error loading 'land.smp', aborting...\n");
2183           return 1;
2184           }
2185                 fclose(handle);*/
2186
2187           if ( (handle = dat_open("death.smp", datfile_name, "rb") ) == 0) {
2188                         strcpy(main_info.error_str, "Error loading 'death.smp', aborting...\n");
2189           return 1;
2190                 }
2191                 if (dj_load_sfx(handle, 0, dat_filelen("death.smp", datfile_name), DJ_SFX_TYPE_SMP, SFX_DEATH) != 0) {
2192                         strcpy(main_info.error_str, "Error loading 'death.smp', aborting...\n");
2193           return 1;
2194           }
2195                 fclose(handle);
2196
2197           if ( (handle = dat_open("spring.smp", datfile_name, "rb") ) == 0) {
2198                         strcpy(main_info.error_str, "Error loading 'spring.smp', aborting...\n");
2199           return 1;
2200                 }
2201                 if (dj_load_sfx(handle, 0, dat_filelen("spring.smp", datfile_name), DJ_SFX_TYPE_SMP, SFX_SPRING) != 0) {
2202                         strcpy(main_info.error_str, "Error loading 'spring.smp', aborting...\n");
2203         return 1;
2204         }
2205                 fclose(handle);
2206
2207           if ( (handle = dat_open("splash.smp", datfile_name, "rb") ) == 0) {
2208                         strcpy(main_info.error_str, "Error loading 'splash.smp', aborting...\n");
2209           return 1;
2210                 }
2211                 if (dj_load_sfx(handle, 0, dat_filelen("splash.smp", datfile_name), DJ_SFX_TYPE_SMP, SFX_SPLASH) != 0) {
2212                         strcpy(main_info.error_str, "Error loading 'splash.smp', aborting...\n");
2213           return 1;
2214           }
2215                 fclose(handle);
2216
2217           if ( (handle = dat_open("fly.smp", datfile_name, "rb") ) == 0) {
2218                         strcpy(main_info.error_str, "Error loading 'fly.smp', aborting...\n");
2219           return 1;
2220                 }
2221                 if (dj_load_sfx(handle, 0, dat_filelen("fly.smp", datfile_name), DJ_SFX_TYPE_SMP, SFX_FLY) != 0) {
2222                         strcpy(main_info.error_str, "Error loading 'fly.smp', aborting...\n");
2223           return 1;
2224           }
2225                 fclose(handle);
2226
2227                 dj_get_sfx_settings(SFX_FLY, &fly);
2228                 fly.priority = 10;
2229                 fly.default_freq = SFX_FLY_FREQ;
2230                 fly.loop = 1;
2231                 fly.loop_start = 0;
2232                 fly.loop_length = fly.length;
2233                 dj_set_sfx_settings(SFX_FLY, &fly);
2234         }
2235
2236         open_screen();
2237
2238   if ( (handle = dat_open("menu.pcx", datfile_name, "rb") ) == 0) {
2239                 strcpy(main_info.error_str, "Error loading 'menu.pcx', aborting...\n");
2240                 return 1;
2241         }
2242   if (read_pcx(handle, background_pic, 102400L, pal) != 0) {
2243                 strcpy(main_info.error_str, "Error loading 'menu.pcx', aborting...\n");
2244                 return 1;
2245         }
2246         fclose(handle);
2247
2248   outportb(0x3c8, 0);
2249         for (c1 = 0; c1 < 768; c1++)
2250                 outportb(0x3c9, pal[c1]);
2251
2252         if (main_info.joy_enabled == 1 && main_info.fireworks == 0) {
2253         c1 = 0;
2254         outportb(0x201, 0);
2255         while (c1 < 0x7fff) {
2256                 if ( (inportb(0x201) & 1) == 0)
2257                         break;
2258                 c1++;
2259         }
2260         if (c1 != 0x7fff) {
2261                 main_info.joy_enabled = 1;
2262                 load_flag = 0;
2263                 put_text(0, 200, 40, "JOYSTICK CALIBRATION", 2);
2264                 put_text(0, 200, 100, "Move the joystick to the", 2);
2265                 put_text(0, 200, 115, "UPPER LEFT", 2);
2266                 put_text(0, 200, 130, "and press button A", 2);
2267                 put_text(0, 200, 200, "Or press ESC to use", 2);
2268                 put_text(0, 200, 215, "previous settings", 2);
2269                 if (calib_joy(0) != 0)
2270                         load_flag = 1;
2271                 else {
2272                         outportw(0x3c4, 0x0f02);
2273                   memset( (char *)(0xa0000 + 32768 + __djgpp_conventional_base), 0, 32768);
2274                         main_info.view_page = 1;
2275                         outportw(0x3d4, (1 << 23) + 0x0d);
2276                         outportw(0x3d4, ( (1 << 15) & 0xff00) + 0x0c);
2277                         wait_vrt();
2278
2279                         put_text(1, 200, 40, "JOYSTICK CALIBRATION", 2);
2280                         put_text(1, 200, 100, "Move the joystick to the", 2);
2281                         put_text(1, 200, 115, "LOWER RIGHT", 2);
2282                         put_text(1, 200, 130, "and press button A", 2);
2283                         put_text(1, 200, 200, "Or press ESC to use", 2);
2284                         put_text(1, 200, 215, "previous settings", 2);
2285                         if (calib_joy(1) != 0)
2286                                 load_flag = 1;
2287                         else {
2288                                 outportw(0x3c4, 0x0f02);
2289                           memset( (char *)(0xa0000 + __djgpp_conventional_base), 0, 32768);
2290                                 outportw(0x3d4, (0 << 23) + 0x0d);
2291                                 outportw(0x3d4, ( (0 << 15) & 0xff00) + 0x0c);
2292                                 wait_vrt();
2293
2294                                 put_text(0, 200, 40, "JOYSTICK CALIBRATION", 2);
2295                                 put_text(0, 200, 100, "Move the joystick to the", 2);
2296                                 put_text(0, 200, 115, "CENTER", 2);
2297                                 put_text(0, 200, 130, "and press button A", 2);
2298                                 put_text(0, 200, 200, "Or press ESC to use", 2);
2299                                 put_text(0, 200, 215, "previous settings", 2);
2300                                 if (calib_joy(2) != 0)
2301                                         load_flag = 1;
2302                                 else {
2303                                         if (joy.calib_data.x1 == joy.calib_data.x2)
2304                                                 joy.calib_data.x1 -= 10;
2305                                         if (joy.calib_data.x3 == joy.calib_data.x2)
2306                                                 joy.calib_data.x3 += 10;
2307                                         if (joy.calib_data.y1 == joy.calib_data.y2)
2308                                                 joy.calib_data.y1 -= 10;
2309                                         if (joy.calib_data.y3 == joy.calib_data.y2)
2310                                                 joy.calib_data.y3 += 10;
2311                                         write_calib_data();
2312                                 }
2313                         }
2314                 }
2315                 if (load_flag == 1) {
2316                   if ( (handle = dat_open("calib.dat", datfile_name, "rb") ) == 0) {
2317                                 strcpy(main_info.error_str, "Error loading 'calib.dat', aborting...\n");
2318                   return 1;
2319                         }
2320                         joy.calib_data.x1 = fgetc(handle) + (fgetc(handle) << 8) + (fgetc(handle) << 16) + (fgetc(handle) << 24);
2321                         joy.calib_data.x2 = fgetc(handle) + (fgetc(handle) << 8) + (fgetc(handle) << 16) + (fgetc(handle) << 24);
2322                         joy.calib_data.x3 = fgetc(handle) + (fgetc(handle) << 8) + (fgetc(handle) << 16) + (fgetc(handle) << 24);
2323                         joy.calib_data.y1 = fgetc(handle) + (fgetc(handle) << 8) + (fgetc(handle) << 16) + (fgetc(handle) << 24);
2324                         joy.calib_data.y2 = fgetc(handle) + (fgetc(handle) << 8) + (fgetc(handle) << 16) + (fgetc(handle) << 24);
2325                         joy.calib_data.y3 = fgetc(handle) + (fgetc(handle) << 8) + (fgetc(handle) << 16) + (fgetc(handle) << 24);
2326                         fclose(handle);
2327                 }
2328   }
2329   else
2330                 main_info.joy_enabled = 0;
2331
2332         }
2333
2334   regs.x.ax = 0;
2335   __dpmi_int(0x33, &regs);
2336   if (regs.x.ax == 0xffff) {
2337                 main_info.mouse_enabled = 1;
2338                 main_info.num_mouse_buttons = regs.x.bx;
2339                 if (force2 == 1)
2340                         main_info.num_mouse_buttons = 2;
2341                 if (force3 == 1)
2342                         main_info.num_mouse_buttons = 3;
2343         }
2344         else
2345                 main_info.mouse_enabled = 0;
2346
2347   return 0;
2348
2349 }
2350
2351
2352 void deinit_program(void) {
2353         __dpmi_regs regs;
2354
2355         dj_stop();
2356   dj_free_mod(MOD_MENU);
2357   dj_free_mod(MOD_GAME);
2358   dj_free_sfx(SFX_DEATH);
2359   dj_free_sfx(SFX_SPRING);
2360   dj_free_sfx(SFX_SPLASH);
2361   dj_deinit();
2362
2363   if (rabbit_gobs != 0)
2364     free(rabbit_gobs);
2365         if (object_gobs != 0)
2366                 free(object_gobs);
2367         if (number_gobs != 0)
2368                 free(number_gobs);
2369
2370   if (main_info.pob_backbuf[0] != 0)
2371     free(main_info.pob_backbuf[0]);
2372   if (main_info.pob_backbuf[1] != 0)
2373     free(main_info.pob_backbuf[1]);
2374
2375   if (background_pic != 0)
2376     free(background_pic);
2377   if (mask_pic != 0)
2378     free(mask_pic);
2379
2380         remove_keyb_handler();
2381
2382         regs.x.ax = 0x3;
2383   __dpmi_int(0x10, &regs);
2384
2385         if (main_info.error_str[0] != 0) {
2386                 printf(main_info.error_str);
2387                 exit(1);
2388         }
2389         else
2390                 exit(0);
2391
2392 }
2393
2394
2395 void read_joy(void) {
2396         int c1;
2397         int x, y;
2398         int s1;
2399         char flag;
2400
2401         c1 = x = y = flag = 0;
2402         outportb(0x201, 0);
2403
2404         while (1) {
2405
2406                 s1 = inportb(0x201);
2407
2408                 if (x == 0) {
2409                         if ( (s1 & 1) == 0)
2410                                 x = c1;
2411                 }
2412                 if (y == 0) {
2413                         if ( (s1 & 2) == 0)
2414                                 y = c1;
2415                 }
2416                 if (x != 0 && y != 0)
2417                         break;
2418
2419                 c1++;
2420                 if (c1 == 0x7fff) {
2421                         flag = 1;
2422                         break;
2423                 }
2424
2425         }
2426
2427         if (flag == 0) {
2428                 joy.raw_x = x;
2429                 joy.raw_y = y;
2430
2431                 if (joy.raw_x < joy.calib_data.x2)
2432                         joy.x = ( (long)(joy.raw_x - joy.calib_data.x2) << 10) / (joy.calib_data.x2 - joy.calib_data.x1);
2433                 else
2434                         joy.x = ( (long)(joy.raw_x - joy.calib_data.x2) << 10) / (joy.calib_data.x3 - joy.calib_data.x2);
2435                 if (joy.raw_y < joy.calib_data.y2)
2436                         joy.y = ( (long)(joy.raw_y - joy.calib_data.y2) << 10) / (joy.calib_data.y2 - joy.calib_data.y1);
2437                 else
2438                         joy.y = ( (long)(joy.raw_y - joy.calib_data.y2) << 10) / (joy.calib_data.y3 - joy.calib_data.y2);
2439
2440                 if (joy.x < -1024)
2441                         joy.x = -1024;
2442                 if (joy.x > 1024)
2443                         joy.x = 1024;
2444                 if (joy.y < -1024)
2445                         joy.y = -1024;
2446                 if (joy.y > 1024)
2447                         joy.y = 1024;
2448
2449                 s1 = inportb(0x201);
2450                 joy.but1 = ( ( (s1 >> 4) & 1) ^ 1);
2451                 joy.but2 = ( ( (s1 >> 5) & 1) ^ 1);
2452         }
2453         else {
2454                 joy.raw_x = joy.calib_data.x2;
2455                 joy.raw_y = joy.calib_data.y2;
2456
2457                 joy.x = joy.y = 0;
2458
2459                 joy.but1 = joy.but2 = 0;
2460         }
2461
2462 }
2463
2464
2465 char calib_joy(char type) {
2466         int c1;
2467         int x, y;
2468         int s1;
2469         int num_times;
2470         char flag;
2471
2472         while (joy.but1 == 1) {
2473                 s1 = inportb(0x201);
2474                 joy.but1 = ( ( (s1 >> 4) & 1) ^ 1);
2475                 if (key_pressed(1) == 1) {
2476                         while (key_pressed(1) == 1);
2477                         return 1;
2478                 }
2479         }
2480
2481         num_times = 0;
2482
2483         while (joy.but1 == 0) {
2484
2485                 c1 = x = y = flag = 0;
2486                 outportb(0x201, 0);
2487
2488                 while (1) {
2489
2490                         s1 = inportb(0x201);
2491
2492                         if (x == 0) {
2493                                 if ( (s1 & 1) == 0)
2494                                         x = c1;
2495                         }
2496                         if (y == 0) {
2497                                 if ( (s1 & 2) == 0)
2498                                         y = c1;
2499                         }
2500                         if (x != 0 && y != 0)
2501                                 break;
2502
2503                         c1++;
2504                         if (c1 == 0x7fff) {
2505                                 flag = 1;
2506                                 break;
2507                         }
2508
2509                 }
2510
2511                 joy.raw_x = x;
2512                 joy.raw_y = y;
2513
2514                 s1 = inportb(0x201);
2515                 joy.but1 = ( ( (s1 >> 4) & 1) ^ 1);
2516
2517                 if (num_times < 0x7fffffff)
2518                         num_times++;
2519
2520                 if (flag == 1)
2521                         break;
2522
2523                 if (key_pressed(1) == 1) {
2524                         while (key_pressed(1) == 1);
2525                         return 1;
2526                 }
2527
2528         }
2529
2530         if (num_times < 16)
2531                 return 1;
2532
2533         if (flag == 0) {
2534
2535                 switch (type) {
2536                         case 0:
2537                                 joy.calib_data.x1 = joy.raw_x;
2538                                 joy.calib_data.y1 = joy.raw_y;
2539                                 break;
2540                         case 1:
2541                                 joy.calib_data.x3 = joy.raw_x;
2542                                 joy.calib_data.y3 = joy.raw_y;
2543                                 break;
2544                         case 2:
2545                                 joy.calib_data.x2 = joy.raw_x;
2546                                 joy.calib_data.y2 = joy.raw_y;
2547                                 break;
2548                 }
2549
2550                 while (joy.but1 == 1) {
2551                         s1 = inportb(0x201);
2552                         joy.but1 = ( ( (s1 >> 4) & 1) ^ 1);
2553                 }
2554
2555         }
2556
2557         return 0;
2558
2559 }
2560
2561
2562 void read_mouse(void) {
2563
2564   regs.x.ax = 3;
2565   __dpmi_int(0x33, &regs);
2566   mouse.but1 = regs.x.bx & 1;
2567   mouse.but2 = (regs.x.bx & 2) >> 1;
2568   mouse.but3 = (regs.x.bx & 4) >> 2;
2569
2570 }
2571
2572
2573 unsigned short rnd(unsigned short max) {
2574   int l1;
2575
2576   l1 = ( (random() >> 16) * max) / 0x7fff;
2577   if (l1 > max - 1)
2578     l1 = max - 1;
2579   return l1;
2580 }
2581
2582
2583 char read_level(void) {
2584         FILE *handle;
2585         int c1, c2;
2586         int chr;
2587
2588   if ( (handle = dat_open("levelmap.txt", datfile_name, "rb") ) == 0) {
2589                 strcpy(main_info.error_str, "Error loading 'levelmap.txt', aborting...\n");
2590     return 1;
2591         }
2592
2593         for (c1 = 0; c1 <       16; c1++) {
2594                 for (c2 = 0; c2 <       22; c2++) {
2595                         while (1) {
2596                                 chr = fgetc(handle);
2597                                 if (chr == EOF) {
2598                                         fclose(handle);
2599                                         return 1;
2600                                 }
2601                                 if (chr >= '0' && chr <= '4')
2602                                         break;
2603                         }
2604                         ban_map[c1][c2] = chr - '0';
2605                 }
2606         }
2607
2608         for (c2 = 0; c2 <       22; c2++)
2609                 ban_map[16][c2] = 1;
2610
2611   fclose(handle);
2612         return 0;
2613
2614 }
2615
2616
2617 FILE *dat_open(char *file_name, char *dat_name, char *mode) {
2618         FILE *handle;
2619         int num;
2620         int c1;
2621         char name[21];
2622         int ofs;
2623
2624         if ( (handle = fopen(dat_name, mode) ) == NULL)
2625                 return 0;
2626
2627         num = fgetc(handle) +   (fgetc(handle) << 8) +  (fgetc(handle) << 16) + (fgetc(handle) << 24);
2628         for (c1 = 0; c1 < num; c1++) {
2629                 fread(name, 1, 12, handle);
2630                 if (strnicmp(name, file_name, strlen(file_name) ) == 0) {
2631                         ofs = fgetc(handle) +   (fgetc(handle) << 8) +  (fgetc(handle) << 16) + (fgetc(handle) << 24);
2632                         fseek(handle, ofs, SEEK_SET);
2633                         return handle;
2634                 }
2635                 fseek(handle, 8, SEEK_CUR);
2636         }
2637
2638         return 0;
2639 }
2640
2641
2642 int dat_filelen(char *file_name, char *dat_name) {
2643         FILE *handle;
2644         int num;
2645         int c1;
2646         char name[21];
2647         int len;
2648
2649         if ( (handle = fopen(dat_name, "rb") ) == NULL)
2650                 return 0;
2651
2652         num = fgetc(handle) +   (fgetc(handle) << 8) +  (fgetc(handle) << 16) + (fgetc(handle) << 24);
2653         for (c1 = 0; c1 < num; c1++) {
2654                 fread(name, 1, 12, handle);
2655                 if (strnicmp(name, file_name, strlen(file_name) ) == 0) {
2656                         fseek(handle, 4, SEEK_CUR);
2657                         len = fgetc(handle) +   (fgetc(handle) << 8) +  (fgetc(handle) << 16) + (fgetc(handle) << 24);
2658                         return len;
2659                 }
2660                 fseek(handle, 8, SEEK_CUR);
2661         }
2662
2663         return 0;
2664 }
2665
2666 void write_calib_data(void) {
2667         FILE *handle;
2668         int c1;
2669         int len, num;
2670         char *mem;
2671         int ofs;
2672
2673         if ( (handle = fopen(datfile_name, "rb") ) == NULL)
2674                 return;
2675         len = filelength(fileno(handle) );
2676         if ( (mem = malloc(len) ) == NULL)
2677                 return;
2678         fread(mem, 1, len, handle);
2679         fclose(handle);
2680
2681         ofs = 4;
2682         num = *(int *)(&mem[0]);
2683         for (c1 = 0; c1 < num; c1++) {
2684                 if (strnicmp(&mem[ofs], "calib.dat", strlen("calib.dat") ) == 0) {
2685                         ofs = *(int *)(&mem[ofs + 12]);
2686                         break;
2687                 }
2688                 ofs += 20;
2689         }
2690
2691         mem[ofs] = joy.calib_data.x1 & 0xff;
2692         mem[ofs + 1] = (joy.calib_data.x1 >> 8) & 0xff;
2693         mem[ofs + 2] = (joy.calib_data.x1 >> 16) & 0xff;
2694         mem[ofs + 3] = (joy.calib_data.x1 >> 24) & 0xff;
2695         mem[ofs + 4] = joy.calib_data.x2 & 0xff;
2696         mem[ofs + 5] = (joy.calib_data.x2 >> 8) & 0xff;
2697         mem[ofs + 6] = (joy.calib_data.x2 >> 16) & 0xff;
2698         mem[ofs + 7] = (joy.calib_data.x2 >> 24) & 0xff;
2699         mem[ofs + 8] = joy.calib_data.x3 & 0xff;
2700         mem[ofs + 9] = (joy.calib_data.x3 >> 8) & 0xff;
2701         mem[ofs + 10] = (joy.calib_data.x3 >> 16) & 0xff;
2702         mem[ofs + 11] = (joy.calib_data.x3 >> 24) & 0xff;
2703         mem[ofs + 12] = joy.calib_data.y1 & 0xff;
2704         mem[ofs + 13] = (joy.calib_data.y1 >> 8) & 0xff;
2705         mem[ofs + 14] = (joy.calib_data.y1 >> 16) & 0xff;
2706         mem[ofs + 15] = (joy.calib_data.y1 >> 24) & 0xff;
2707         mem[ofs + 16] = joy.calib_data.y2 & 0xff;
2708         mem[ofs + 17] = (joy.calib_data.y2 >> 8) & 0xff;
2709         mem[ofs + 18] = (joy.calib_data.y2 >> 16) & 0xff;
2710         mem[ofs + 19] = (joy.calib_data.y2 >> 24) & 0xff;
2711         mem[ofs + 20] = joy.calib_data.y3 & 0xff;
2712         mem[ofs + 21] = (joy.calib_data.y3 >> 8) & 0xff;
2713         mem[ofs + 22] = (joy.calib_data.y3 >> 16) & 0xff;
2714         mem[ofs + 23] = (joy.calib_data.y3 >> 24) & 0xff;
2715
2716         if ( (handle = fopen(datfile_name, "wb") ) == NULL)
2717                 return;
2718         fwrite(mem, 1, len, handle);
2719         fclose(handle);
2720
2721 }
2722