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 long ScreenBuffer[SP_SCREEN_BUFFER_XSIZE][SP_SCREEN_BUFFER_YSIZE];
69 // Public DisplayMin%, DisplayMax%, DisplayWidth%, DisplayHeight%
77 currency DeltaT; // Interval between two frames (in ms)
78 long DeltaTPlay, DeltaTDemo;
79 boolean BlockingSpeed;
81 // --- const int posFrameCorner = 55;
82 // --- const int posFrameVertical = 110;
83 // --- const int posFrameHorizontal = 111;
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)
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
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?)
136 // --- const int fiExplosion = 0x1F;
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;
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;
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 };
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);
230 InitPseudoCompileFlags();
231 UserDragFlag = False;
232 AutoScrollFlag = True;
234 BlockingSpeed = False;
239 FieldMax = (FieldWidth * FieldHeight) + HeaderSize - 1;
240 LevelMax = (FieldWidth * FieldHeight) - 1;
241 Let_ModifiedFlag(False);
244 bSignatureAvailable = False;
245 FirstDemoByte = 0x81;
247 InitErrorReporting();
250 void InitPseudoCompileFlags()
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
289 int GetSI(int X, int Y)
293 GetSI = Y * FieldWidth + X;
302 GetX = si % FieldWidth;
311 GetY = si / FieldWidth;
316 int GetStretchX(int si)
320 GetStretchX = StretchWidth * (si % FieldWidth);
325 int GetStretchY(int si)
329 GetStretchY = StretchWidth * (si / FieldWidth);
337 static char CurPathTEST[1024];
346 // CurPath = "/home/aeglos/projects/rocksndiamonds/levels/TEST_supaplex/supaplex/levels.dat";
349 CurPath = "/home/aeglos/projects/rocksndiamonds/supaplex_demo_JENS0001.sp";
354 // sprintf(CurPathTEST, "/home/aeglos/projects/rocksndiamonds/levels/TEST_supaplex/test_solutions/%03d.sp", level_nr);
356 sprintf(CurPathTEST, "/home/aeglos/projects/Level_Stuff/SUPAPLEX/SUPAPLEX_LEVELS/Set77/77S%03d.SP", level_nr);
358 sprintf(CurPathTEST, "/home/aeglos/projects/Level_Stuff/SUPAPLEX/SUPAPLEX_LEVELS/solve00/JENS%04d.SP", level_nr);
361 CurPath = CurPathTEST;
362 LevelNumber = level_nr;
367 DemoAvailable = False;
369 if (STRING_IS_LIKE(CurPath, "*.mpx") ||
370 STRING_IS_LIKE(CurPath, "*.MPX"))
372 printf("::: reading MPX file ...\n");
378 if (STRING_IS_LIKE(CurPath, "*.sp") ||
379 STRING_IS_LIKE(CurPath, "*.SP"))
381 printf("::: reading SP file ...\n");
389 printf("::: reading demo file ...\n");
395 printf("::: reading level file ...\n");
402 FieldMax = (FieldWidth * FieldHeight) + HeaderSize - 1;
403 LevelMax = (FieldWidth * FieldHeight) - 1;
405 PlayField8 = REDIM_1D(sizeof(byte), 0, FieldMax + 1 - 1);
406 DisPlayField = REDIM_1D(sizeof(byte), 0, FieldMax + 1 - 1);
408 // FNum = FreeFile();
410 // --- On Error GoTo ReadLevelEH
412 printf("::: '%s', %d\n", CurPath, LevelNumber);
414 FNum = fopen(CurPath, "rb");
416 i = (LevelNumber - 1) * ((long)(FieldMax) + 1) + 1;
418 FILE_GET(FNum, i, PlayField8, FieldMax + 1);
420 FILE_GET(FNum, i, &PlayField8, sizeof(PlayField8));
423 i = (LevelNumber) * ((long)(FieldMax) + 1) + 1 - HeaderSize;
424 FILE_GET(FNum, i, &LInfo, sizeof(LInfo)); // store level info in an extra structure
428 // --- On Error GoTo 0
430 if (FieldMax < FileMax)
431 DemoAvailable = True;
435 PlayField16 = REDIM_1D(sizeof(int), -FieldWidth, FieldMax);
437 for (i = 0; i <= FieldMax; i++)
439 PlayField16[i] = PlayField8[i];
440 DisPlayField[i] = PlayField8[i];
448 for (x = 0; x < 60; x++)
452 for (x = 0; x < 60; x++)
456 for (y = 0; y < 24; y++)
458 for (x = 0; x < 60; x++)
460 printf("%02d.", PlayField16[y * 60 + x]);
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);
472 GravityFlag = LInfo.InitialGravity;
473 FreezeZonks = LInfo.InitialFreezeZonks;
487 static void ReadDemo()
494 int RecordNumber = LevelNumber;
497 RecordNumber = 1; // always "1" for "*.sp" style one level/demo files
504 FieldMax = (FieldWidth * FieldHeight) + HeaderSize - 1;
505 LevelMax = (FieldWidth * FieldHeight) - 1;
507 // --- On Error GoTo ReadDemoEH
509 FileMax = FileLen(CurPath) - 1;
511 PlayField8 = REDIM_1D(sizeof(byte), 0, FileMax + 1 - 1);
512 DisPlayField = REDIM_1D(sizeof(byte), 0, FieldMax + 1 - 1);
514 // FNum = FreeFile();
516 FNum = fopen(CurPath, "rb");
518 i = (RecordNumber - 1) * ((long)(FieldMax) + 1) + 1;
520 FILE_GET(FNum, i, PlayField8, FileMax + 1);
522 FILE_GET(FNum, i, &PlayField8, sizeof(PlayField8));
525 i = (RecordNumber) * ((long)(FieldMax) + 1) + 1 - HeaderSize;
526 FILE_GET(FNum, i, &LInfo, sizeof(LInfo)); // store level info in an extra structure
530 // --- On Error GoTo 0
532 if (FieldMax < FileMax)
533 DemoAvailable = True;
537 PlayField16 = REDIM_1D(sizeof(int), -FieldWidth, FieldMax);
539 for (i = 0; i <= FieldMax; i++)
541 PlayField16[i] = PlayField8[i];
542 DisPlayField[i] = PlayField8[i];
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);
550 DemoPointer = FieldMax + 1;
551 DemoOffset = DemoPointer;
552 DemoKeyRepeatCounter = 0;
555 // DemoAvailable = True
557 GravityFlag = LInfo.InitialGravity;
558 FreezeZonks = LInfo.InitialFreezeZonks;
561 printf("::: Globals.c: ReadDemo(): %d / %d\n", GravityFlag, FreezeZonks);
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);
576 printf("::: swapping file bytes for DemoRandomSeed etc.\n");
578 printf("::: keeping file bytes in (maybe wrong) 'native' order.\n");
582 printf("::: LInfo.DemoRandomSeed == %d\n", LInfo.DemoRandomSeed);
586 printf("::: LInfo.SpecialPortCount == %d\n", LInfo.SpecialPortCount);
587 for (i = 0; i < LInfo.SpecialPortCount; i++)
589 int port_x = (LInfo.SpecialPort[i].PortLocation / 2) % FieldWidth;
590 int port_y = (LInfo.SpecialPort[i].PortLocation / 2) / FieldWidth;
592 printf("::: %d: port_location == %d => (%d, %d)\n",
593 i, LInfo.SpecialPort[i].PortLocation, port_x, port_y);
597 RandomSeed = LInfo.DemoRandomSeed;
600 printf("::: SpeedByte == %d\n", LInfo.SpeedByte);
601 printf("::: CheckSumByte == %d\n", LInfo.CheckSumByte);
602 printf("::: RandomSeed == %d\n", RandomSeed);
608 for (i = 0; i < 10; i++)
609 printf("::: TEST random number: %d\n", subGetRandomNumber());
633 copyInternalEngineVars_SP();
635 LevelNumber = level_nr;
638 if (!DemoFlag || !DemoAvailable)