ebf59fd6b444a1f76631840bfcc7d15319506a9c
[rocksndiamonds.git] / src / game_sp / Globals.c
1 // ----------------------------------------------------------------------------
2 // Globals.c
3 // ----------------------------------------------------------------------------
4
5 #include "Globals.h"
6
7 static void ReadDemo();
8 void ReadLevel();
9
10 // static char *VB_Name = "modGlobals";
11
12 // --- Option Explicit
13 // --- Option Compare Text
14 // --- Option Base 0
15
16 // --- const long StretchWidth = 16;
17 // --- const long StretchWidth2 = StretchWidth / 2;
18 // --- const long BaseWidth = 16;
19 // --- const int TwoPixels = 2;
20
21 boolean Original;
22 boolean Cracked;
23 boolean Level_Arg;
24 boolean EGA_Arg;
25 boolean Record_Fix;
26 boolean SpeedKeys;
27 boolean Level_Fix;
28 boolean Dead_Code;
29 boolean Redundant;
30 boolean Alignments;
31 boolean Ctrl_Alt_Fix;
32 boolean Protection;
33 boolean EP_ENHANCE;
34 boolean EP_DEMO;
35 boolean EP_DEBUG;
36 boolean EXTRASPEED;
37 boolean TIMINGFIX;
38 boolean SafeRecord;
39 boolean Norm_Time;
40 boolean EP_OLD8;
41 boolean SAVEGAME;
42 boolean HP_DEMO;
43 boolean ScreenFix;
44 boolean DemoRecordFix;
45 boolean DebugSwitch;
46 boolean Ver62;
47 boolean Ver62test;
48 boolean Ver63;
49 boolean Ver64;
50
51 int LevelNumber;
52 char *CurPath, *OrigPath, *TmpPath;
53 boolean LevelLoaded;
54 long SignatureDelay;
55
56 boolean bCapturePane;
57
58 int FieldWidth; // = 60
59 int FieldHeight; // = 24
60 int HeaderSize; // = 96
61 int FieldMax, LevelMax;
62 long FileMax;
63 int *PlayField16;
64 byte *PlayField8;
65 byte *DisPlayField;
66
67 // Public DisplayMin%, DisplayMax%, DisplayWidth%, DisplayHeight%
68
69 int TimerVar;
70 #if 1
71 short RandomSeed;
72 #else
73 int RandomSeed;
74 #endif
75 currency DeltaT; // Interval between two frames (in ms)
76 long DeltaTPlay, DeltaTDemo;
77 boolean BlockingSpeed;
78
79 // --- const int posFrameCorner = 55;
80 // --- const int posFrameVertical = 110;
81 // --- const int posFrameHorizontal = 111;
82
83 int FreezeZonks;
84
85 // constants for  Fixed Fields:
86 // --- const int fiSpace = 0; // &H00  space(28 = wall space ...)
87 // --- const int fiZonk = 1; // &H01  zonk
88 // --- const int fiBase = 2; // &H02  base
89 // --- const int fiMurphy = 3; // &H03  Murphy
90 // --- const int fiInfotron = 4; // &H04  infotron
91 // --- const int fiRAM = 5; // &H05  small RAM chip
92 // --- const int fiHardWare = 6; // &H06  hardware (square, standard pyramid shape)
93 // --- const int fiExit = 7; // &H07  exit
94 // --- const int fiOrangeDisk = 8; // &H08  brown/orange utility disk
95 // --- const int fiPortRight = 9; // &H09  port 1 left to right
96 // --- const int fiPortDown = 10; // &H0A  port 1 up to down
97 // --- const int fiPortLeft = 11; // &H0B  port 1 right to left
98 // --- const int fiPortUp = 12; // &H0C  port 1 down to up
99 // --- const int fiSpPortRight = 13; // &H0D  port 2 left to right (gravity change)
100 // --- const int fiSpPortDown = 14; // &H0E  port 2 up to down     (gravity change)
101 // --- const int fiSpPortLeft = 15; // &H0F  port 2 right to left (gravity change)
102 // --- const int fiSpPortUp = 16; // &H10  port 2 down to up     (gravity change)
103 // --- const int fiSnikSnak = 17; // &H11  snik snak
104 // --- const int fiYellowDisk = 18; // &H12  yellow utility disk
105 // --- const int fiTerminal = 19; // &H13  terminal
106 // --- const int fiRedDisk = 20; // &H14  red utility disk
107 // --- const int fiPortUpAndDown = 21; // &H15  vertical port
108 // --- const int fiPortLeftAndRight = 22; // &H16  horizontal port
109 // --- const int fiPortAllDirections = 23; // &H17  horizontal + vertical port
110 // --- const int fiElectron = 24; // &H18  electron
111 // --- const int fiBug = 25; // &H19  bug
112 // --- const int fiRAMLeft = 26; // &H1A  horizontal RAM chip, left (pin 1)
113 // --- const int fiRAMRight = 27; // &H1B  horizontal RAM chip, right
114 // --- const int fiHWFirst = 28; // &H1C  hardware (radial blue circular cap + coloured shapes)
115
116 // Public Const fiHW1% = 29               '  29 = 1D  hardware (green signal lamp)
117 // Public Const fiHW2% = 30               '  30 = 1E  hardware (blue signal lamp)
118 // Public Const fiHW3% = 31               '  31 = 1F  hardware (red signal lamp)
119 // Public Const fiHW4% = 32               '  32 = 20  hardware (yellow/black diagonal stripes)
120 // Public Const fiHW5% = 33               '  33 = 21  hardware (yellow resistor + blue + red shapes)
121 // Public Const fiHW6% = 34               '  34 = 22  hardware (horizontal red capacitor + smd shape)
122 // Public Const fiHW7% = 35               '  35 = 23  hardware (red + yellow + blue horizontal resistors)
123 // Public Const fiHW8% = 36               '  36 = 24  hardware (3 red vertical resistors)
124 // --- const int fiHWLast = 37;             //  37 = 25  hardware (3 yellow horizontal resistors)
125 // --- const int fiRAMTop = 38;             //  38 = 26  vertical RAM chip, top (pin 1)
126 // --- const int fiRAMBottom = 39;          //  39 = 27  vertical RAM chip, bottom
127
128 // Specials to experiment with ...
129 // --- const int fiWallSpace = 40;          //  40 = 28  invisible wall (can explode, zonks don't roll off)
130 // --- const int fiHWTrash1 = 41;           //  41 = 29  hardware trash
131 // --- const int fiHWTrash2 = 42;           //  42 = 2A  hardware trash
132 // --- const int fiHWMurphy = 43;           //  43 = 2B  hardware inverted Murphy ... (maybe nice for use?)
133
134 // --- const int fiExplosion = 0x1F;
135
136 // --- const int keyNone = 0;
137 // --- const int keyUp = 1;
138 // --- const int keyLeft = 2;
139 // --- const int keyDown = 3;
140 // --- const int keyRight = 4;
141 // --- const int keySpaceUp = 5;
142 // --- const int keySpaceLeft = 6;
143 // --- const int keySpaceDown = 7;
144 // --- const int keySpaceRight = 8;
145 // --- const int keySpace = 9;
146
147 #if 0
148 int *aniBug, *aniZonkRollRight, *aniZonkRollLeft;
149 int *aniInfotronRollRight, *aniInfotronRollLeft;
150 int *aniSnikSnak, *aniElectron, *aniExplosion;
151 int *aniTouchBase, *aniTouchInfotron, *aniTouchRedDisk;
152 // --- const int aniExplosionInfo = 111;
153 // --- const int aniSnikSnakUp = 159;
154 // --- const int aniSnikSnakDown = 167;
155 // --- const int aniSnikSnakLeft = 239;
156 // --- const int aniSnikSnakRight = 247;
157 // --- const int aniMurphyYawn = 56;
158 // --- const int aniMurphySleepLeft = 71;
159 // --- const int aniMurphySleepRight = 68;
160 int *aniMurphyExit; // , aniMurphyFaceLeft%, aniMurphyFaceRight%
161 int *aniMurphyEatLeft, *aniMurphyEatRight; // , aniMurphyEatRightRedDisk
162 int *aniMurphyEatUpLeft, *aniMurphyEatUpRight, *aniSplitUpDown;
163 int *aniYellowDisk, *aniOrangeDisk, *aniRedDisk;
164 // --- const int aniMurphyTouchUp = 46;
165 // --- const int aniMurphyTouchLeft = 95;
166 // --- const int aniMurphyTouchDown = 47;
167 // --- const int aniMurphyTouchRight = 94;
168 int *aniEatInfotronLeft, *aniEatInfotronRight;
169 // --- const int aniPushLeft = 45;
170 // --- const int aniPushRight = 44;
171 // --- const int aniPushUpDown = 79;
172 #endif
173
174 #if 1
175 int aniBug[] = { 74, 75, 76, 77, 78, 77, 76, 77, 78, 77, 76, 75, 74, 25 };
176 int aniZonkRollRight[] = { 198, 197, 196, 195, 194, 193, 192, 1, -1 };
177 int aniZonkRollLeft[] = { 192, 193, 194, 195, 196, 197, 198, 1, -1 };
178 int aniInfotronRollRight[] = { 206, 205, 204, 203, 202, 201, 200, 4 };
179 int aniInfotronRollLeft[] = { 200, 201, 202, 203, 204, 205, 206, 4 };
180 int aniSnikSnak[] = { 121, 122, 123, 124, 125, 126, 127, 120, 121 };
181 int aniElectron[] = { 144, 145, 146, 147, 148, 149, 150, 151, 144 };
182 int aniExplosion[] = { 3, 103, 104, 105, 106, 107, 108, 109, 0 };
183 int aniTouchBase[] = { 80, 81, 82, 83, 84, 85, 86, 0, -1 };
184 int aniTouchInfotron[] = { 87, 88, 89, 91, 92, 93, 0, -1 }; // Only seven frames!!!!
185 int aniTouchRedDisk[] = { 96, 97, 98, 99, 100, 101, 102, 0, -1 };
186 int aniMurphyExit[] = { 46, 46, 46, 46, 47, 47, 47, 47, 48, 48, 48, 48, 49, 49, 49, 49, 50, 50, 50, 50, 51, 51, 51, 51, 52, 52, 52, 52, 53, 53, 53, 53, 54, 54, 54, 54, 0, 0, 0, 0, -1 };
187 int aniMurphyEatLeft[] = { 176, 177, 178, 179, 180, 181, 182, 183, -1 };
188 int aniMurphyEatRight[] = { 184, 185, 186, 187, 188, 189, 190, 191, -1 };
189 int aniMurphyEatUpLeft[] = { 183, 182, 181, 180, 179, 178, 177, 176, -1 };
190 int aniMurphyEatUpRight[] = { 191, 190, 189, 188, 187, 186, 185, 184, -1 };
191   // aniMurphyEatRightRedDisk = { 184, 184, 185, 186, 187, 188, 189, 190, 191, -1) '9 frames!
192 int aniEatInfotronLeft[] = { 209, 211, 213, 215, 217, 219, 221, 223, -1 };
193 int aniEatInfotronRight[] = { 224, 226, 228, 230, 232, 234, 236, 238, -1 };
194 int aniSplitUpDown[] = { 3, 3, 3, 3, 3, 3, 3, 3, -1 };
195 int aniYellowDisk[] = { 18, 18, 18, 18, 18, 18, 18, 18, -1 };
196 int aniOrangeDisk[] = { 8, 8, 8, 8, 8, 8, 8, 8, -1 };
197 int aniRedDisk[] = { 20, -1 };
198 #endif
199
200 void InitGlobals()
201 {
202 #if 0
203   aniBug = Array(74, 75, 76, 77, 78, 77, 76, 77, 78, 77, 76, 75, 74, 25);
204   aniZonkRollRight = Array(198, 197, 196, 195, 194, 193, 192, 1, -1);
205   aniZonkRollLeft = Array(192, 193, 194, 195, 196, 197, 198, 1, -1);
206   aniInfotronRollRight = Array(206, 205, 204, 203, 202, 201, 200, 4);
207   aniInfotronRollLeft = Array(200, 201, 202, 203, 204, 205, 206, 4);
208   aniSnikSnak = Array(121, 122, 123, 124, 125, 126, 127, 120, 121);
209   aniElectron = Array(144, 145, 146, 147, 148, 149, 150, 151, 144);
210   aniExplosion = Array(3, 103, 104, 105, 106, 107, 108, 109, 0);
211   aniTouchBase = Array(80, 81, 82, 83, 84, 85, 86, 0, -1);
212   aniTouchInfotron = Array(87, 88, 89, 91, 92, 93, 0, -1); // Only seven frames!!!!
213   aniTouchRedDisk = Array(96, 97, 98, 99, 100, 101, 102, 0, -1);
214   aniMurphyExit = Array(46, 46, 46, 46, 47, 47, 47, 47, 48, 48, 48, 48, 49, 49, 49, 49, 50, 50, 50, 50, 51, 51, 51, 51, 52, 52, 52, 52, 53, 53, 53, 53, 54, 54, 54, 54, 0, 0, 0, 0, -1);
215   aniMurphyEatLeft = Array(176, 177, 178, 179, 180, 181, 182, 183, -1);
216   aniMurphyEatRight = Array(184, 185, 186, 187, 188, 189, 190, 191, -1);
217   aniMurphyEatUpLeft = Array(183, 182, 181, 180, 179, 178, 177, 176, -1);
218   aniMurphyEatUpRight = Array(191, 190, 189, 188, 187, 186, 185, 184, -1);
219   // aniMurphyEatRightRedDisk = Array(184, 184, 185, 186, 187, 188, 189, 190, 191, -1) '9 frames!
220   aniEatInfotronLeft = Array(209, 211, 213, 215, 217, 219, 221, 223, -1);
221   aniEatInfotronRight = Array(224, 226, 228, 230, 232, 234, 236, 238, -1);
222   aniSplitUpDown = Array(3, 3, 3, 3, 3, 3, 3, 3, -1);
223   aniYellowDisk = Array(18, 18, 18, 18, 18, 18, 18, 18, -1);
224   aniOrangeDisk = Array(8, 8, 8, 8, 8, 8, 8, 8, -1);
225   aniRedDisk = Array(20, -1);
226 #endif
227
228   InitPseudoCompileFlags();
229   UserDragFlag = False;
230   AutoScrollFlag = True;
231   FreezeZonks = 0;
232   BlockingSpeed = False;
233   LevelLoaded = False;
234   FieldWidth = 60;
235   FieldHeight = 24;
236   HeaderSize = 96;
237   FieldMax = (FieldWidth * FieldHeight) + HeaderSize - 1;
238   LevelMax = (FieldWidth * FieldHeight) - 1;
239   Let_ModifiedFlag(False);
240   bPlaying = False;
241   gSignature = "";
242   bSignatureAvailable = False;
243   FirstDemoByte = 0x81;
244   MySignature = "";
245   InitErrorReporting();
246 }
247
248 void InitPseudoCompileFlags()
249 {
250   Cracked = 1;       // If protection Then crack it
251   Level_Arg = 1;     // :number is cmd line option
252   // Level_Arg  = 0     ' Remove Level cmd line option
253   EGA_Arg = 1;       // EGA is command line option
254   Record_Fix = 1;      // Assemble with fixed Demo rec
255   SpeedKeys = 0;     // Remove Speed Keys fix
256   Level_Fix = 1;     // Assemble with Level Fix
257   Dead_Code = 0;     // Remove dead code
258   Redundant = 0;     // Remove redundant code
259   Alignments = 1;      // Assemble with alignments
260   Ctrl_Alt_Fix = 1;      // Assemble with Ctrl/Alt fix
261   Protection = 0;      // Remove protection code,do HP
262   // EP added by EP for version 5.
263   EP_ENHANCE = 1;      // Some more nice things (EP)
264   EP_DEMO = 1;       // Use .SP files for demos (EP)
265   // Including record demo!
266   EP_DEBUG = 0;      // little cmdline debugging
267   EXTRASPEED = 1;      // '@' option, superfast!
268   TIMINGFIX = 1;     // "Fixed" the timing problem..
269   // Inactive If DemoRecordFix Then1
270   SafeRecord = 1;      // skip debug keys in recording
271   Norm_Time = 1;     // force automatic speed test,
272   // save result and then do as
273   // requested from cmd line.
274   EP_OLD8 = 1;       // call old int8 from current.
275   SAVEGAME = 1;      // Allow saving to SUPAPLEX.SAV
276   HP_DEMO = 1;       // Use fixed demo routines 5.5
277   ScreenFix = 1;     // No menu-write to gamy field
278   DemoRecordFix = 1;     // Demo record timing fix on
279   DebugSwitch = 1;     // Allow Ctrl/Alt-ScrollLock
280   Ver62 = 1;       // Version 6.2 stuff
281   Ver62test = 0;     // Version 6.2 test stuff
282   Ver63 = 1;       // Version 6.3 stuff
283   Ver64 = 1;       // Version 6.4 stuff
284
285 }
286
287 int GetSI(int X, int Y)
288 {
289   int GetSI;
290
291   GetSI = Y * FieldWidth + X;
292
293   return GetSI;
294 }
295
296 int GetX(int si)
297 {
298   int GetX;
299
300   GetX = si % FieldWidth;
301
302   return GetX;
303 }
304
305 int GetY(int si)
306 {
307   int GetY;
308
309   GetY = si / FieldWidth;
310
311   return GetY;
312 }
313
314 int GetStretchX(int si)
315 {
316   int GetStretchX;
317
318   GetStretchX = StretchWidth * (si % FieldWidth);
319
320   return GetStretchX;
321 }
322
323 int GetStretchY(int si)
324 {
325   int GetStretchY;
326
327   GetStretchY = StretchWidth * (si / FieldWidth);
328
329   return GetStretchY;
330 }
331
332 void OLD_ReadLevel()
333 {
334 #if 1
335   static char CurPathTEST[1024];
336 #endif
337
338   // int FNum;
339   FILE *FNum;
340   long i;
341   // byte T;
342
343 #if 1
344   // CurPath = "/home/aeglos/projects/rocksndiamonds/levels/TEST_supaplex/supaplex/levels.dat";
345
346 #if 0
347   CurPath = "/home/aeglos/projects/rocksndiamonds/supaplex_demo_JENS0001.sp";
348   LevelNumber = 1;
349 #else
350
351 #if 0
352   // sprintf(CurPathTEST, "/home/aeglos/projects/rocksndiamonds/levels/TEST_supaplex/test_solutions/%03d.sp", level_nr);
353
354   sprintf(CurPathTEST, "/home/aeglos/projects/Level_Stuff/SUPAPLEX/SUPAPLEX_LEVELS/Set77/77S%03d.SP", level_nr);
355 #else
356   sprintf(CurPathTEST, "/home/aeglos/projects/Level_Stuff/SUPAPLEX/SUPAPLEX_LEVELS/solve00/JENS%04d.SP", level_nr);
357 #endif
358
359   CurPath = CurPathTEST;
360   LevelNumber = level_nr;
361 #endif
362
363 #endif
364
365   DemoAvailable = False;
366
367   if (STRING_IS_LIKE(CurPath, "*.mpx") ||
368       STRING_IS_LIKE(CurPath, "*.MPX"))
369   {
370     printf("::: reading MPX file ...\n");
371
372     ReadMPX();
373     return;
374   }
375
376   if (STRING_IS_LIKE(CurPath, "*.sp") ||
377       STRING_IS_LIKE(CurPath, "*.SP"))
378   {
379     printf("::: reading SP file ...\n");
380
381     ReadDemo();
382     return;
383   }
384
385   if (DemoFlag != 0)
386   {
387     printf("::: reading demo file ...\n");
388
389     ReadDemo();
390     return;
391   }
392
393   printf("::: reading level file ...\n");
394
395   FileMax = 0;
396   FieldWidth = 60;
397   FieldHeight = 24;
398   HeaderSize = 96;
399
400   FieldMax = (FieldWidth * FieldHeight) + HeaderSize - 1;
401   LevelMax = (FieldWidth * FieldHeight) - 1;
402
403   PlayField8 = REDIM_1D(sizeof(byte), 0, FieldMax + 1 - 1);
404   DisPlayField = REDIM_1D(sizeof(byte), 0, FieldMax + 1 - 1);
405
406   // FNum = FreeFile();
407
408   // --- On Error GoTo ReadLevelEH
409
410   printf("::: '%s', %d\n", CurPath, LevelNumber);
411
412   FNum = fopen(CurPath, "rb");
413
414   i = (LevelNumber - 1) * ((long)(FieldMax) + 1) + 1;
415 #if 1
416   FILE_GET(FNum, i, PlayField8, FieldMax + 1);
417 #else
418   FILE_GET(FNum, i, &PlayField8, sizeof(PlayField8));
419 #endif
420
421   i = (LevelNumber) * ((long)(FieldMax) + 1) + 1 - HeaderSize;
422   FILE_GET(FNum, i, &LInfo, sizeof(LInfo)); // store level info in an extra structure
423
424   fclose(FNum);
425
426   // --- On Error GoTo 0
427
428   if (FieldMax < FileMax)
429     DemoAvailable = True;
430
431   ReadSignature();
432
433   PlayField16 = REDIM_1D(sizeof(int), -FieldWidth, FieldMax);
434
435   for (i = 0; i <= FieldMax; i++)
436   {
437     PlayField16[i]  = PlayField8[i];
438     DisPlayField[i] = PlayField8[i];
439     PlayField8[i] = 0;
440   }
441
442 #if 0
443  {
444    int x, y;
445
446    for (x = 0; x < 60; x++)
447      printf("%02d.", x);
448    printf("\n");
449
450    for (x = 0; x < 60; x++)
451      printf("...");
452    printf("\n");
453
454    for (y = 0; y < 24; y++)
455    {
456      for (x = 0; x < 60; x++)
457      {
458        printf("%02d.", PlayField16[y * 60 + x]);
459      }
460
461      printf("\n");
462    }
463  }
464 #endif
465
466   AnimationPosTable = REDIM_1D(sizeof(int), 0, LevelMax - 2 * FieldWidth);
467   AnimationSubTable = REDIM_1D(sizeof(byte), 0, LevelMax - 2 * FieldWidth);
468   TerminalState = REDIM_1D(sizeof(byte), FieldWidth, LevelMax - FieldWidth);
469
470   GravityFlag = LInfo.InitialGravity;
471   FreezeZonks = LInfo.InitialFreezeZonks;
472
473   subRandomize();
474
475   LevelLoaded = True;
476
477   return;
478
479 #if 0
480 ReadLevelEH:
481   Close();
482 #endif
483 }
484
485 static void ReadDemo()
486 {
487   // int FNum, i;
488   FILE *FNum;
489   int i;
490   // byte T;
491
492   int RecordNumber = LevelNumber;
493
494 #if 1
495   RecordNumber = 1;     // always "1" for "*.sp" style one level/demo files
496 #endif
497
498   FieldWidth = 60;
499   FieldHeight = 24;
500   HeaderSize = 96;
501
502   FieldMax = (FieldWidth * FieldHeight) + HeaderSize - 1;
503   LevelMax = (FieldWidth * FieldHeight) - 1;
504
505   // --- On Error GoTo ReadDemoEH
506
507   FileMax = FileLen(CurPath) - 1;
508
509   PlayField8 = REDIM_1D(sizeof(byte), 0, FileMax + 1 - 1);
510   DisPlayField = REDIM_1D(sizeof(byte), 0, FieldMax + 1 - 1);
511
512   // FNum = FreeFile();
513
514   FNum = fopen(CurPath, "rb");
515
516   i = (RecordNumber - 1) * ((long)(FieldMax) + 1) + 1;
517 #if 1
518   FILE_GET(FNum, i, PlayField8, FileMax + 1);
519 #else
520   FILE_GET(FNum, i, &PlayField8, sizeof(PlayField8));
521 #endif
522
523   i = (RecordNumber) * ((long)(FieldMax) + 1) + 1 - HeaderSize;
524   FILE_GET(FNum, i, &LInfo, sizeof(LInfo)); // store level info in an extra structure
525
526   fclose(FNum);
527
528   // --- On Error GoTo 0
529
530   if (FieldMax < FileMax)
531     DemoAvailable = True;
532
533   ReadSignature();
534
535   PlayField16 = REDIM_1D(sizeof(int), -FieldWidth, FieldMax);
536
537   for (i = 0; i <= FieldMax; i++)
538   {
539     PlayField16[i] = PlayField8[i];
540     DisPlayField[i] = PlayField8[i];
541     PlayField8[i] = 0;
542   }
543
544   AnimationPosTable = REDIM_1D(sizeof(int), 0, LevelMax - 2 * FieldWidth);
545   AnimationSubTable = REDIM_1D(sizeof(byte), 0, LevelMax - 2 * FieldWidth);
546   TerminalState = REDIM_1D(sizeof(byte), 0, FieldMax + 1 - 1);
547
548   DemoPointer = FieldMax + 1;
549   DemoOffset = DemoPointer;
550   DemoKeyRepeatCounter = 0;
551
552   // DemoFlag = 1
553   // DemoAvailable = True
554
555   GravityFlag = LInfo.InitialGravity;
556   FreezeZonks = LInfo.InitialFreezeZonks;
557
558 #if 0
559   printf("::: Globals.c: ReadDemo(): %d / %d\n", GravityFlag, FreezeZonks);
560 #endif
561
562
563
564 #if 0
565   /* !!! TESTING BIG / LITTLE ENDIAN STUFF !!! */
566   LInfo.DemoRandomSeed =
567     LowByte(LInfo.DemoRandomSeed) << 8 |
568     HighByte(LInfo.DemoRandomSeed);
569   for (i = 0; i < 10; i++)
570     LInfo.SpecialPort[i].PortLocation =
571       LowByte(LInfo.SpecialPort[i].PortLocation) << 8 |
572       HighByte(LInfo.SpecialPort[i].PortLocation);
573
574   printf("::: swapping file bytes for DemoRandomSeed etc.\n");
575 #else
576   printf("::: keeping file bytes in (maybe wrong) 'native' order.\n");
577 #endif
578
579 #if 1
580   printf("::: LInfo.DemoRandomSeed == %d\n", LInfo.DemoRandomSeed);
581 #endif
582
583 #if 0
584   printf("::: LInfo.SpecialPortCount == %d\n", LInfo.SpecialPortCount);
585   for (i = 0; i < LInfo.SpecialPortCount; i++)
586   {
587     int port_x = (LInfo.SpecialPort[i].PortLocation / 2) % FieldWidth;
588     int port_y = (LInfo.SpecialPort[i].PortLocation / 2) / FieldWidth;
589
590     printf("::: %d: port_location == %d => (%d, %d)\n",
591            i, LInfo.SpecialPort[i].PortLocation, port_x, port_y);
592   }
593 #endif
594
595   RandomSeed = LInfo.DemoRandomSeed;
596
597 #if 0
598   printf("::: SpeedByte == %d\n", LInfo.SpeedByte);
599   printf("::: CheckSumByte == %d\n", LInfo.CheckSumByte);
600   printf("::: RandomSeed == %d\n", RandomSeed);
601
602 #if 0
603   {
604     int i;
605
606     for (i = 0; i < 10; i++)
607       printf("::: TEST random number: %d\n", subGetRandomNumber());
608   }
609 #endif
610
611 #endif
612
613   LevelLoaded = True;
614
615   return;
616
617 #if 0
618 ReadDemoEH:
619   Close();
620 #endif
621 }
622
623 void ReadLevel()
624 {
625 #if 0
626   OLD_ReadLevel();
627
628   // return;
629 #endif
630
631   copyInternalEngineVars_SP();
632
633 #if 1
634   SetDisplayRegion();
635   SetScrollEdges();
636 #endif
637
638   LevelNumber = level_nr;
639
640 #if 0
641   if (!DemoFlag || !DemoAvailable)
642     subRandomize();
643 #endif
644
645   LevelLoaded = True;
646 }