fixed bug in single button handling causing broken tapes (EM engine)
[rocksndiamonds.git] / src / game_sp / Infotrons.c
1 // ----------------------------------------------------------------------------
2 // Infotrons.c
3 // ----------------------------------------------------------------------------
4
5 #include "Infotrons.h"
6
7
8 // ==========================================================================
9 //                              SUBROUTINE
10 // Animate Infotrons (falling)
11 // ==========================================================================
12
13 void subAnimateInfotrons(int si)
14 {
15   int tFld;
16
17   int ax, bx, dx, X, Y;
18   int al, bl;
19
20   tFld = PlayField16[si];
21   if ((tFld & 0xFF) != fiInfotron)
22     return;
23
24   if (tFld == fiInfotron)
25   {
26     ax = PlayField16[si + FieldWidth]; // select case playfield16(si+60)
27     if (ax == 0)
28       goto loc_g_11D5;
29
30     if (ax == fiZonk)
31       goto loc_g_11A6;
32
33     if (ax == fiInfotron)
34       goto loc_g_11A6;
35
36     if (ax == fiRAM)
37       goto loc_g_11A6;
38
39     return;
40
41 loc_g_11A6: //        Case fiZonk, fiInfotron, fiRAM
42     ax = PlayField16[si + FieldWidth - 1];
43     if (ax == 0 || ax == 0x8888 || ax == 0xAAAA)
44       goto loc_g_11DC;
45
46 loc_g_11BD:
47     ax = PlayField16[si + FieldWidth + 1];
48     if (ax == 0 || ax == 0x8888 || ax == 0xAAAA)
49       goto loc_g_11F2;
50
51     return;
52
53 loc_g_11D5: //       Case fiSpace
54     MovHighByte(&PlayField16[si], 0x40);
55     goto loc_g_1207;
56
57 loc_g_11DC: // roll left?
58     if (PlayField16[si - 1] == 0)
59       goto loc_g_11E5;
60
61     goto loc_g_11BD;
62
63 loc_g_11E5:
64     MovHighByte(&PlayField16[si], 0x50);
65     PlayField16[si - 1] = 0x8888;
66     goto loc_g_1207;
67
68 loc_g_11F2: // roll right?
69     if (PlayField16[si + 1] == 0)
70       goto loc_g_11FA;
71
72     return;
73
74 loc_g_11FA:
75     MovHighByte(&PlayField16[si], 0x60);
76     PlayField16[si + 1] = 0x8888;
77   } // tFld = fiInfotron
78
79 loc_g_1207:
80   // from now on the infotron is definitely moving,
81   // maybe the sequence is in an advanced frame
82   // or just beeing initialized due to the code above
83   bl = HighByte(PlayField16[si]);
84   bx = 0;
85   MovLowByte(&bx, bl);
86
87   al = bl & 0xF0;
88   if (al == 0x10) // infotron comes falling from above
89     goto loc_g_1242;
90
91   if (al == 0x20) // infotron comes rolling from right to left
92     goto loc_g_138D;
93
94   if (al == 0x30) // infotron comes rolling from left to right
95     goto loc_g_13E9;
96
97   if (al == 0x40) // infotron falls straight down
98     goto loc_g_1444;
99
100   if (al == 0x50) // infotron rolls left
101     goto loc_g_1472;
102
103   if (al == 0x60) // infotron rolls right
104     goto loc_g_14E0;
105
106   if (al == 0x70) // intermediate state
107     goto loc_g_154E;
108
109   return;
110
111 loc_g_1242: // infotron comes falling from above
112   //      To Do: draw infotron falling from above
113   //      according to position in (bl And &H07)
114   // +++++++++++++++++++++++++++++++++++++++++++++++++++++
115   X = GetStretchX(si);
116   Y = GetStretchY(si - FieldWidth);
117   dx = bl & 0x7;
118   DDSpriteBuffer_BltImg(X, Y, aniSpace, 0);
119   DDSpriteBuffer_BltImg(X, Y + TwoPixels * (dx + 1), aniInfotron, dx);
120   // +++++++++++++++++++++++++++++++++++++++++++++++++++++
121
122   bl = HighByte(PlayField16[si]) + 1;
123   if (bl == 0x16)
124   {
125     MovHighByte(&PlayField16[si], bl);
126     subCleanUpForInfotronsAbove(si - FieldWidth);
127
128     return;
129   } // loc_g_1285:
130
131   if (bl < 0x18)
132   {
133     MovHighByte(&PlayField16[si], bl);
134
135     return;
136   } // loc_g_128F:
137
138   MovHighByte(&PlayField16[si], 0); // infotron arrived at the field
139
140   // now check if the zonk may go on falling somehow
141   ax = PlayField16[si + FieldWidth];
142   if (ax == 0) // below is empty!-> go on falling
143     goto loc_g_132D;
144
145   if (ax == 0x9999) // below is only temporarily used
146     goto loc_g_132D;
147
148   if ((ax & 0xFF) == fiMurphy) // Murphy dies
149     goto loc_g_1364;
150
151   if (ax == fiRedDisk) // red disk hit
152     goto loc_g_1386;
153
154   if ((ax & 0xFF) == fiSnikSnak) // SnikSnak dies
155     goto loc_g_1386;
156
157
158   if ((ax & 0xFF) == fiElectron) // Electron cracked!
159     goto loc_g_1386;
160
161   if (ax == fiYellowDisk) // yellow disk hit
162     goto loc_g_1386;
163
164   if (ax == fiOrangeDisk) // orange disk hit
165     goto loc_g_1386;
166
167   // play the infotron sound, 'cause infotron hits something "hard"
168   subSoundFX(si, fiInfotron, actImpact);
169
170   if (! (ax == fiZonk || ax == fiInfotron || ax == fiRAM))
171     return;
172
173   // infotron rolls somewhere
174   ax = PlayField16[si + FieldWidth - 1];
175   if (ax == 0 || ax == 0x8888 || ax == 0xAAAA) // may roll left
176     goto loc_g_133A;
177
178   ax = PlayField16[si + FieldWidth + 1];
179   if (ax == 0 || ax == 0x8888 || ax == 0xAAAA) // may roll right
180     goto loc_g_1350;
181
182   return;
183
184 loc_g_132D:     // go on falling down?
185   PlayField16[si] = 0x7004; // go into intermediate waitstate
186   PlayField16[si + FieldWidth] = 0x9999; // mark as "zonk waiting to access"
187
188   return;
189
190 loc_g_133A:     // test if infotron may roll left
191   // This if(if true) jumps up far above
192   // to the according rountine for fixed infotrons!
193   if (PlayField16[si - 1] != 0) // Remarkable!!! ' loc_g_0EF4:
194     goto loc_g_11BD;
195
196   MovHighByte(&PlayField16[si], 0x50); // infotron rolls left
197   PlayField16[si - 1] = 0x8888;
198
199   return;
200
201 loc_g_1350:     // test if infotron may roll right
202   if (PlayField16[si + 1] != 0)
203     return;
204
205   MovHighByte(&PlayField16[si], 0x60); // infotron rolls right
206   PlayField16[si + 1] = 0x8888;
207
208   return;
209
210 loc_g_1364:     // Murphy dies, but not in any case
211   bl = HighByte(PlayField16[si + FieldWidth]);
212   if (bl == 0xE || bl == 0xF || bl == 0x28)
213     return;
214
215   if (bl == 0x29 || bl == 0x25 || bl == 0x26)
216     return;
217
218 loc_g_1386:     // someone dies/explodes immediately
219   si = si + FieldWidth;                 // 1 field down
220   ExplodeFieldSP(si);               // Explode
221
222   return;
223
224 loc_g_138D: // infotron comes rolling from right to left
225   //  To Do: draw infotron rolling from right
226   //  according to position in (bl And &H07)
227   // +++++++++++++++++++++++++++++++++++++++++++++++++++++
228   X = GetStretchX(si + 1);
229   Y = GetStretchY(si);
230   dx = (bl & 0x7) + 1;
231   DDSpriteBuffer_BltImg(X, Y, aniSpace, 0);
232   DDSpriteBuffer_BltImg(X - (TwoPixels * dx), Y, aniInfotronRollLeft, dx - 1);
233   // +++++++++++++++++++++++++++++++++++++++++++++++++++++
234
235   bl = HighByte(PlayField16[si]) + 1; // get and increment sequence#
236   if (bl == 0x24)
237     PlayField16[si + 1] = 0xAAAA;
238
239   if (bl == 0x26)
240   {
241     MovHighByte(&PlayField16[si], bl);
242     subCleanUpForInfotronsAbove(si + 1);
243   }
244   else if (bl < 0x28)
245   {
246     MovHighByte(&PlayField16[si], bl);
247   }
248   else
249   {
250     PlayField16[si] = 0x7004; // go into intermediate state
251   }
252
253   return;
254
255 loc_g_13E9: // infotron comes rolling from left to right
256   //  To Do: draw infotron rolling from left
257   //  according to position in (bl And &H07)
258   // +++++++++++++++++++++++++++++++++++++++++++++++++++++
259   X = GetStretchX(si - 1);
260   Y = GetStretchY(si);
261   dx = (bl & 0x7) + 1;
262   DDSpriteBuffer_BltImg(X, Y, aniSpace, 0);
263   DDSpriteBuffer_BltImg(X + (TwoPixels * dx), Y, aniInfotronRollRight, dx - 1);
264   // +++++++++++++++++++++++++++++++++++++++++++++++++++++
265
266   bl = HighByte(PlayField16[si]) + 1;
267   if (bl == 0x34)
268     PlayField16[si - 1] = 0xAAAA;
269
270   if (bl == 0x36)
271   {
272     MovHighByte(&PlayField16[si], bl);
273     subCleanUpForInfotronsAbove(si - 1);
274   }
275   else if (bl < 0x38)
276   {
277     MovHighByte(&PlayField16[si], bl);
278   }
279   else
280   {
281     PlayField16[si] = 0x7004; // go into intermediate state
282   }
283
284   return;
285
286 loc_g_1444: // infotron falls straight down
287   bl = bl + 1;
288   if (bl < 0x42)
289   {
290     MovHighByte(&PlayField16[si], bl);
291   }
292   else if (PlayField16[si + FieldWidth] != 0)
293   {
294     bl = bl - 1; // stay waiting
295     MovHighByte(&PlayField16[si], bl);
296   }
297   else
298   {
299     PlayField16[si] = 0xFFFF;
300     si = si + FieldWidth;                 // 1 field down
301     PlayField16[si] = 0x1004; // go falling
302   }
303
304   return;
305
306 loc_g_1472: // infotron rolls left
307   //  To Do: draw infotron rolling to left
308   //  according to position in (bl And &H0F)
309   // +++++++++++++++++++++++++++++++++++++++++++++++++++++
310   X = GetStretchX(si);
311   Y = GetStretchY(si);
312   dx = (bl & 0xF) + 1;
313   DDSpriteBuffer_BltImg(X, Y, aniSpace, 0);
314   DDSpriteBuffer_BltImg(X - (TwoPixels * dx), Y, aniInfotronRollLeft, dx - 1);
315   // +++++++++++++++++++++++++++++++++++++++++++++++++++++
316
317   bl = HighByte(PlayField16[si]) + 1; // retrieve and increment sequence#
318   if (bl < 0x52)
319   {
320     MovHighByte(&PlayField16[si], bl);
321
322     return;
323   }
324
325   if (PlayField16[si + FieldWidth - 1] != 0)
326     goto loc_g_14D9;
327
328   if (PlayField16[si - 1] != 0)
329   {
330     if (PlayField16[si - 1] != 0x8888)
331       goto loc_g_14D9;
332   }
333
334   PlayField16[si] = 0xFFFF;
335   si = si - 1;                   // 1 field left
336   PlayField16[si] = 0x2204;
337   PlayField16[si + FieldWidth] = 0x9999;
338
339   return;
340
341 loc_g_14D9: // stay waiting
342   bl = bl - 1;
343   MovHighByte(&PlayField16[si], bl);
344
345   return;
346
347 loc_g_14E0: // infotron rolls right
348   //  To Do: draw infotron rolling to right
349   //  according to position in (bl And &H07)
350   // +++++++++++++++++++++++++++++++++++++++++++++++++++++
351   X = GetStretchX(si);
352   Y = GetStretchY(si);
353   dx = (bl & 0x7) + 1;
354   DDSpriteBuffer_BltImg(X, Y, aniSpace, 0);
355   DDSpriteBuffer_BltImg(X + (TwoPixels * dx), Y, aniInfotronRollRight, dx - 1);
356   // +++++++++++++++++++++++++++++++++++++++++++++++++++++
357
358   bl = HighByte(PlayField16[si]) + 1;
359   if (bl < 0x62)
360   {
361     MovHighByte(&PlayField16[si], bl);
362
363     return;
364   }
365
366   if (PlayField16[si + FieldWidth + 1] != 0)
367     goto loc_g_1547;
368
369   if (PlayField16[si + 1] != 0)
370   {
371     if (PlayField16[si + 1] != 0x8888)
372       goto loc_g_1547;
373   }
374
375   PlayField16[si] = 0xFFFF;
376   si = si + 1;
377   PlayField16[si] = 0x3204;
378   PlayField16[si + FieldWidth] = 0x9999;
379
380   return;
381
382 loc_g_1547: // stay waiting
383   bl = bl - 1;
384   MovHighByte(&PlayField16[si], bl);
385
386   return;
387
388 loc_g_154E: // intermediate state
389   ax = PlayField16[si + FieldWidth];
390   if (ax == 0 || ax == 0x9999)
391   {
392     PlayField16[si] = 0xFFFF;
393     si = si + FieldWidth;                 // 1 field down
394     PlayField16[si] = 0x1004; // start falling down
395     goto loc_g_1242;
396   }
397 }
398
399 void subCleanUpForInfotronsAbove(int si)
400 {
401   int ax;
402
403   if (LowByte(PlayField16[si]) != fiExplosion)
404     PlayField16[si] = 0;
405
406   if (PlayField16[si - FieldWidth] != 0)
407   {
408     if (PlayField16[si - FieldWidth] != 0x9999)
409       return;
410
411     if (LowByte(PlayField16[si - 2 * FieldWidth]) != fiZonk)
412       return;
413   }
414
415   if (PlayField16[si - FieldWidth - 1] == fiInfotron)
416     goto loc_g_16FE;
417
418 loc_g_16F6:
419   if (PlayField16[si - FieldWidth + 1] == fiInfotron)
420     goto loc_g_1722;
421
422   return;
423
424 loc_g_16FE:
425   ax = PlayField16[si - 1];
426   if (ax == fiZonk || ax == fiInfotron || ax == fiRAM)
427   {
428     PlayField16[si - FieldWidth - 1] = 0x6004;
429     PlayField16[si - FieldWidth] = 0x8888;
430
431     return;
432   }
433
434   goto loc_g_16F6;
435
436 loc_g_1722:
437   ax = PlayField16[si + 1];
438   if (ax == fiZonk || ax == fiInfotron || ax == fiRAM)
439   {
440     PlayField16[si - FieldWidth + 1] = 0x5004;
441     PlayField16[si - FieldWidth] = 0x8888;
442   }
443 }