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