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