1 // ----------------------------------------------------------------------------
3 // ----------------------------------------------------------------------------
7 static void ReadDemo();
10 // static char *VB_Name = "modGlobals";
12 // --- Option Explicit
13 // --- Option Compare Text
16 // --- const long StretchWidth = 16;
17 // --- const long StretchWidth2 = StretchWidth / 2;
18 // --- const long BaseWidth = 16;
19 // --- const int TwoPixels = 2;
44 boolean DemoRecordFix;
52 char *CurPath, *OrigPath, *TmpPath;
58 int FieldWidth; // = 60
59 int FieldHeight; // = 24
60 int HeaderSize; // = 96
61 int FieldMax, LevelMax;
67 // Public DisplayMin%, DisplayMax%, DisplayWidth%, DisplayHeight%
75 currency DeltaT; // Interval between two frames (in ms)
76 long DeltaTPlay, DeltaTDemo;
77 boolean BlockingSpeed;
79 // --- const int posFrameCorner = 55;
80 // --- const int posFrameVertical = 110;
81 // --- const int posFrameHorizontal = 111;
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)
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
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?)
134 // --- const int fiExplosion = 0x1F;
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;
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;
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 };
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);
228 InitPseudoCompileFlags();
229 UserDragFlag = False;
230 AutoScrollFlag = True;
232 BlockingSpeed = False;
237 FieldMax = (FieldWidth * FieldHeight) + HeaderSize - 1;
238 LevelMax = (FieldWidth * FieldHeight) - 1;
239 Let_ModifiedFlag(False);
242 bSignatureAvailable = False;
243 FirstDemoByte = 0x81;
245 InitErrorReporting();
248 void InitPseudoCompileFlags()
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
287 int GetSI(int X, int Y)
291 GetSI = Y * FieldWidth + X;
300 GetX = si % FieldWidth;
309 GetY = si / FieldWidth;
314 int GetStretchX(int si)
318 GetStretchX = StretchWidth * (si % FieldWidth);
323 int GetStretchY(int si)
327 GetStretchY = StretchWidth * (si / FieldWidth);
335 static char CurPathTEST[1024];
344 // CurPath = "/home/aeglos/projects/rocksndiamonds/levels/TEST_supaplex/supaplex/levels.dat";
347 CurPath = "/home/aeglos/projects/rocksndiamonds/supaplex_demo_JENS0001.sp";
352 // sprintf(CurPathTEST, "/home/aeglos/projects/rocksndiamonds/levels/TEST_supaplex/test_solutions/%03d.sp", level_nr);
354 sprintf(CurPathTEST, "/home/aeglos/projects/Level_Stuff/SUPAPLEX/SUPAPLEX_LEVELS/Set77/77S%03d.SP", level_nr);
356 sprintf(CurPathTEST, "/home/aeglos/projects/Level_Stuff/SUPAPLEX/SUPAPLEX_LEVELS/solve00/JENS%04d.SP", level_nr);
359 CurPath = CurPathTEST;
360 LevelNumber = level_nr;
365 DemoAvailable = False;
367 if (STRING_IS_LIKE(CurPath, "*.mpx") ||
368 STRING_IS_LIKE(CurPath, "*.MPX"))
370 printf("::: reading MPX file ...\n");
376 if (STRING_IS_LIKE(CurPath, "*.sp") ||
377 STRING_IS_LIKE(CurPath, "*.SP"))
379 printf("::: reading SP file ...\n");
387 printf("::: reading demo file ...\n");
393 printf("::: reading level file ...\n");
400 FieldMax = (FieldWidth * FieldHeight) + HeaderSize - 1;
401 LevelMax = (FieldWidth * FieldHeight) - 1;
403 PlayField8 = REDIM_1D(sizeof(byte), 0, FieldMax + 1 - 1);
404 DisPlayField = REDIM_1D(sizeof(byte), 0, FieldMax + 1 - 1);
406 // FNum = FreeFile();
408 // --- On Error GoTo ReadLevelEH
410 printf("::: '%s', %d\n", CurPath, LevelNumber);
412 FNum = fopen(CurPath, "rb");
414 i = (LevelNumber - 1) * ((long)(FieldMax) + 1) + 1;
416 FILE_GET(FNum, i, PlayField8, FieldMax + 1);
418 FILE_GET(FNum, i, &PlayField8, sizeof(PlayField8));
421 i = (LevelNumber) * ((long)(FieldMax) + 1) + 1 - HeaderSize;
422 FILE_GET(FNum, i, &LInfo, sizeof(LInfo)); // store level info in an extra structure
426 // --- On Error GoTo 0
428 if (FieldMax < FileMax)
429 DemoAvailable = True;
433 PlayField16 = REDIM_1D(sizeof(int), -FieldWidth, FieldMax);
435 for (i = 0; i <= FieldMax; i++)
437 PlayField16[i] = PlayField8[i];
438 DisPlayField[i] = PlayField8[i];
446 for (x = 0; x < 60; x++)
450 for (x = 0; x < 60; x++)
454 for (y = 0; y < 24; y++)
456 for (x = 0; x < 60; x++)
458 printf("%02d.", PlayField16[y * 60 + x]);
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);
470 GravityFlag = LInfo.InitialGravity;
471 FreezeZonks = LInfo.InitialFreezeZonks;
485 static void ReadDemo()
492 int RecordNumber = LevelNumber;
495 RecordNumber = 1; // always "1" for "*.sp" style one level/demo files
502 FieldMax = (FieldWidth * FieldHeight) + HeaderSize - 1;
503 LevelMax = (FieldWidth * FieldHeight) - 1;
505 // --- On Error GoTo ReadDemoEH
507 FileMax = FileLen(CurPath) - 1;
509 PlayField8 = REDIM_1D(sizeof(byte), 0, FileMax + 1 - 1);
510 DisPlayField = REDIM_1D(sizeof(byte), 0, FieldMax + 1 - 1);
512 // FNum = FreeFile();
514 FNum = fopen(CurPath, "rb");
516 i = (RecordNumber - 1) * ((long)(FieldMax) + 1) + 1;
518 FILE_GET(FNum, i, PlayField8, FileMax + 1);
520 FILE_GET(FNum, i, &PlayField8, sizeof(PlayField8));
523 i = (RecordNumber) * ((long)(FieldMax) + 1) + 1 - HeaderSize;
524 FILE_GET(FNum, i, &LInfo, sizeof(LInfo)); // store level info in an extra structure
528 // --- On Error GoTo 0
530 if (FieldMax < FileMax)
531 DemoAvailable = True;
535 PlayField16 = REDIM_1D(sizeof(int), -FieldWidth, FieldMax);
537 for (i = 0; i <= FieldMax; i++)
539 PlayField16[i] = PlayField8[i];
540 DisPlayField[i] = PlayField8[i];
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);
548 DemoPointer = FieldMax + 1;
549 DemoOffset = DemoPointer;
550 DemoKeyRepeatCounter = 0;
553 // DemoAvailable = True
555 GravityFlag = LInfo.InitialGravity;
556 FreezeZonks = LInfo.InitialFreezeZonks;
559 printf("::: Globals.c: ReadDemo(): %d / %d\n", GravityFlag, FreezeZonks);
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);
574 printf("::: swapping file bytes for DemoRandomSeed etc.\n");
576 printf("::: keeping file bytes in (maybe wrong) 'native' order.\n");
580 printf("::: LInfo.DemoRandomSeed == %d\n", LInfo.DemoRandomSeed);
584 printf("::: LInfo.SpecialPortCount == %d\n", LInfo.SpecialPortCount);
585 for (i = 0; i < LInfo.SpecialPortCount; i++)
587 int port_x = (LInfo.SpecialPort[i].PortLocation / 2) % FieldWidth;
588 int port_y = (LInfo.SpecialPort[i].PortLocation / 2) / FieldWidth;
590 printf("::: %d: port_location == %d => (%d, %d)\n",
591 i, LInfo.SpecialPort[i].PortLocation, port_x, port_y);
595 RandomSeed = LInfo.DemoRandomSeed;
598 printf("::: SpeedByte == %d\n", LInfo.SpeedByte);
599 printf("::: CheckSumByte == %d\n", LInfo.CheckSumByte);
600 printf("::: RandomSeed == %d\n", RandomSeed);
606 for (i = 0; i < 10; i++)
607 printf("::: TEST random number: %d\n", subGetRandomNumber());
631 copyInternalEngineVars_SP();
638 LevelNumber = level_nr;
641 if (!DemoFlag || !DemoAvailable)