rnd-20090623-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 // --- Option Explicit
12 // --- Option Compare Text
13 // --- Option Base 0
14
15 // --- const long StretchWidth = 16;
16 // --- const long StretchWidth2 = StretchWidth / 2;
17 // --- const long BaseWidth = 16;
18 // --- const int TwoPixels = 2;
19
20 boolean Original;
21 boolean Cracked;
22 boolean Level_Arg;
23 boolean EGA_Arg;
24 boolean Record_Fix;
25 boolean SpeedKeys;
26 boolean Level_Fix;
27 boolean Dead_Code;
28 boolean Redundant;
29 boolean Alignments;
30 boolean Ctrl_Alt_Fix;
31 boolean Protection;
32 boolean EP_ENHANCE;
33 boolean EP_DEMO;
34 boolean EP_DEBUG;
35 boolean EXTRASPEED;
36 boolean TIMINGFIX;
37 boolean SafeRecord;
38 boolean Norm_Time;
39 boolean EP_OLD8;
40 boolean SAVEGAME;
41 boolean HP_DEMO;
42 boolean ScreenFix;
43 boolean DemoRecordFix;
44 boolean DebugSwitch;
45 boolean Ver62;
46 boolean Ver62test;
47 boolean Ver63;
48 boolean Ver64;
49
50 int LevelNumber;
51 char *CurPath, *OrigPath, *TmpPath;
52 boolean LevelLoaded;
53 long SignatureDelay;
54
55 boolean bCapturePane;
56
57 int FieldWidth; // = 60
58 int FieldHeight; // = 24
59 int HeaderSize; // = 96
60 int FieldMax, LevelMax;
61 long FileMax;
62 int *PlayField16;
63 byte *PlayField8;
64 byte *DisPlayField;
65
66 // Public DisplayMin%, DisplayMax%, DisplayWidth%, DisplayHeight%
67
68 int TimerVar, RandomSeed;
69 currency DeltaT; // Interval between two frames (in ms)
70 long DeltaTPlay, DeltaTDemo;
71 boolean BlockingSpeed;
72
73 // --- const int posFrameCorner = 55;
74 // --- const int posFrameVertical = 110;
75 // --- const int posFrameHorizontal = 111;
76
77 int FreezeZonks;
78
79 // constants for  Fixed Fields:
80 // --- const int fiSpace = 0; // &H00  space(28 = wall space ...)
81 // --- const int fiZonk = 1; // &H01  zonk
82 // --- const int fiBase = 2; // &H02  base
83 // --- const int fiMurphy = 3; // &H03  Murphy
84 // --- const int fiInfotron = 4; // &H04  infotron
85 // --- const int fiRAM = 5; // &H05  small RAM chip
86 // --- const int fiHardWare = 6; // &H06  hardware (square, standard pyramid shape)
87 // --- const int fiExit = 7; // &H07  exit
88 // --- const int fiOrangeDisk = 8; // &H08  brown/orange utility disk
89 // --- const int fiPortRight = 9; // &H09  port 1 left to right
90 // --- const int fiPortDown = 10; // &H0A  port 1 up to down
91 // --- const int fiPortLeft = 11; // &H0B  port 1 right to left
92 // --- const int fiPortUp = 12; // &H0C  port 1 down to up
93 // --- const int fiSpPortRight = 13; // &H0D  port 2 left to right (gravity change)
94 // --- const int fiSpPortDown = 14; // &H0E  port 2 up to down     (gravity change)
95 // --- const int fiSpPortLeft = 15; // &H0F  port 2 right to left (gravity change)
96 // --- const int fiSpPortUp = 16; // &H10  port 2 down to up     (gravity change)
97 // --- const int fiSnikSnak = 17; // &H11  snik snak
98 // --- const int fiYellowDisk = 18; // &H12  yellow utility disk
99 // --- const int fiTerminal = 19; // &H13  terminal
100 // --- const int fiRedDisk = 20; // &H14  red utility disk
101 // --- const int fiPortUpAndDown = 21; // &H15  vertical port
102 // --- const int fiPortLeftAndRight = 22; // &H16  horizontal port
103 // --- const int fiPortAllDirections = 23; // &H17  horizontal + vertical port
104 // --- const int fiElectron = 24; // &H18  electron
105 // --- const int fiBug = 25; // &H19  bug
106 // --- const int fiRAMLeft = 26; // &H1A  horizontal RAM chip, left (pin 1)
107 // --- const int fiRAMRight = 27; // &H1B  horizontal RAM chip, right
108 // --- const int fiHWFirst = 28; // &H1C  hardware (radial blue circular cap + coloured shapes)
109
110 // Public Const fiHW1% = 29               '  29 = 1D  hardware (green signal lamp)
111 // Public Const fiHW2% = 30               '  30 = 1E  hardware (blue signal lamp)
112 // Public Const fiHW3% = 31               '  31 = 1F  hardware (red signal lamp)
113 // Public Const fiHW4% = 32               '  32 = 20  hardware (yellow/black diagonal stripes)
114 // Public Const fiHW5% = 33               '  33 = 21  hardware (yellow resistor + blue + red shapes)
115 // Public Const fiHW6% = 34               '  34 = 22  hardware (horizontal red capacitor + smd shape)
116 // Public Const fiHW7% = 35               '  35 = 23  hardware (red + yellow + blue horizontal resistors)
117 // Public Const fiHW8% = 36               '  36 = 24  hardware (3 red vertical resistors)
118 // --- const int fiHWLast = 37;             //  37 = 25  hardware (3 yellow horizontal resistors)
119 // --- const int fiRAMTop = 38;             //  38 = 26  vertical RAM chip, top (pin 1)
120 // --- const int fiRAMBottom = 39;          //  39 = 27  vertical RAM chip, bottom
121
122 // Specials to experiment with ...
123 // --- const int fiWallSpace = 40;          //  40 = 28  invisible wall (can explode, zonks don't roll off)
124 // --- const int fiHWTrash1 = 41;           //  41 = 29  hardware trash
125 // --- const int fiHWTrash2 = 42;           //  42 = 2A  hardware trash
126 // --- const int fiHWMurphy = 43;           //  43 = 2B  hardware inverted Murphy ... (maybe nice for use?)
127
128 // --- const int fiExplosion = 0x1F;
129
130 // --- const int keyNone = 0;
131 // --- const int keyUp = 1;
132 // --- const int keyLeft = 2;
133 // --- const int keyDown = 3;
134 // --- const int keyRight = 4;
135 // --- const int keySpaceUp = 5;
136 // --- const int keySpaceLeft = 6;
137 // --- const int keySpaceDown = 7;
138 // --- const int keySpaceRight = 8;
139 // --- const int keySpace = 9;
140
141 int *aniBug, *aniZonkRollRight, *aniZonkRollLeft;
142 int *aniInfotronRollRight, *aniInfotronRollLeft;
143 int *aniSnikSnak, *aniElectron, *aniExplosion;
144 int *aniTouchBase, *aniTouchInfotron, *aniTouchRedDisk;
145 // --- const int aniExplosionInfo = 111;
146 // --- const int aniSnikSnakUp = 159;
147 // --- const int aniSnikSnakDown = 167;
148 // --- const int aniSnikSnakLeft = 239;
149 // --- const int aniSnikSnakRight = 247;
150 // --- const int aniMurphyYawn = 56;
151 // --- const int aniMurphySleepLeft = 71;
152 // --- const int aniMurphySleepRight = 68;
153 int *aniMurphyExit; // , aniMurphyFaceLeft%, aniMurphyFaceRight%
154 int *aniMurphyEatLeft, *aniMurphyEatRight; // , aniMurphyEatRightRedDisk
155 int *aniMurphyEatUpLeft, *aniMurphyEatUpRight, *aniSplitUpDown;
156 int *aniYellowDisk, *aniOrangeDisk, *aniRedDisk;
157 // --- const int aniMurphyTouchUp = 46;
158 // --- const int aniMurphyTouchLeft = 95;
159 // --- const int aniMurphyTouchDown = 47;
160 // --- const int aniMurphyTouchRight = 94;
161 int *aniEatInfotronLeft, *aniEatInfotronRight;
162 // --- const int aniPushLeft = 45;
163 // --- const int aniPushRight = 44;
164 // --- const int aniPushUpDown = 79;
165
166 void InitGlobals()
167 {
168   aniBug = Array(74, 75, 76, 77, 78, 77, 76, 77, 78, 77, 76, 75, 74, 25);
169   aniZonkRollRight = Array(198, 197, 196, 195, 194, 193, 192, 1, -1);
170   aniZonkRollLeft = Array(192, 193, 194, 195, 196, 197, 198, 1, -1);
171   aniInfotronRollRight = Array(206, 205, 204, 203, 202, 201, 200, 4);
172   aniInfotronRollLeft = Array(200, 201, 202, 203, 204, 205, 206, 4);
173   aniSnikSnak = Array(121, 122, 123, 124, 125, 126, 127, 120, 121);
174   aniElectron = Array(144, 145, 146, 147, 148, 149, 150, 151, 144);
175   aniExplosion = Array(3, 103, 104, 105, 106, 107, 108, 109, 0);
176   aniTouchBase = Array(80, 81, 82, 83, 84, 85, 86, 0, -1);
177   aniTouchInfotron = Array(87, 88, 89, 91, 92, 93, 0, -1); // Only seven frames!!!!
178   aniTouchRedDisk = Array(96, 97, 98, 99, 100, 101, 102, 0, -1);
179   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);
180   aniMurphyEatLeft = Array(176, 177, 178, 179, 180, 181, 182, 183, -1);
181   aniMurphyEatRight = Array(184, 185, 186, 187, 188, 189, 190, 191, -1);
182   aniMurphyEatUpLeft = Array(183, 182, 181, 180, 179, 178, 177, 176, -1);
183   aniMurphyEatUpRight = Array(191, 190, 189, 188, 187, 186, 185, 184, -1);
184   // aniMurphyEatRightRedDisk = Array(184, 184, 185, 186, 187, 188, 189, 190, 191, -1) '9 frames!
185   aniEatInfotronLeft = Array(209, 211, 213, 215, 217, 219, 221, 223, -1);
186   aniEatInfotronRight = Array(224, 226, 228, 230, 232, 234, 236, 238, -1);
187   aniSplitUpDown = Array(3, 3, 3, 3, 3, 3, 3, 3, -1);
188   aniYellowDisk = Array(18, 18, 18, 18, 18, 18, 18, 18, -1);
189   aniOrangeDisk = Array(8, 8, 8, 8, 8, 8, 8, 8, -1);
190   aniRedDisk = Array(20, -1);
191   InitPseudoCompileFlags();
192   UserDragFlag = False;
193   AutoScrollFlag = True;
194   FreezeZonks = 0;
195   BlockingSpeed = False;
196   LevelLoaded = False;
197   FieldWidth = 60;
198   FieldHeight = 24;
199   HeaderSize = 96;
200   FieldMax = (FieldWidth * FieldHeight) + HeaderSize - 1;
201   LevelMax = (FieldWidth * FieldHeight) - 1;
202   Let_ModifiedFlag(False);
203   bPlaying = False;
204   gSignature = "";
205   bSignatureAvailable = False;
206   FirstDemoByte = 0x81;
207   MySignature = "";
208   InitErrorReporting();
209 }
210
211 void InitPseudoCompileFlags()
212 {
213   Cracked = 1;       // If protection Then crack it
214   Level_Arg = 1;     // :number is cmd line option
215   // Level_Arg  = 0     ' Remove Level cmd line option
216   EGA_Arg = 1;       // EGA is command line option
217   Record_Fix = 1;      // Assemble with fixed Demo rec
218   SpeedKeys = 0;     // Remove Speed Keys fix
219   Level_Fix = 1;     // Assemble with Level Fix
220   Dead_Code = 0;     // Remove dead code
221   Redundant = 0;     // Remove redundant code
222   Alignments = 1;      // Assemble with alignments
223   Ctrl_Alt_Fix = 1;      // Assemble with Ctrl/Alt fix
224   Protection = 0;      // Remove protection code,do HP
225   // EP added by EP for version 5.
226   EP_ENHANCE = 1;      // Some more nice things (EP)
227   EP_DEMO = 1;       // Use .SP files for demos (EP)
228   // Including record demo!
229   EP_DEBUG = 0;      // little cmdline debugging
230   EXTRASPEED = 1;      // '@' option, superfast!
231   TIMINGFIX = 1;     // "Fixed" the timing problem..
232   // Inactive If DemoRecordFix Then1
233   SafeRecord = 1;      // skip debug keys in recording
234   Norm_Time = 1;     // force automatic speed test,
235   // save result and then do as
236   // requested from cmd line.
237   EP_OLD8 = 1;       // call old int8 from current.
238   SAVEGAME = 1;      // Allow saving to SUPAPLEX.SAV
239   HP_DEMO = 1;       // Use fixed demo routines 5.5
240   ScreenFix = 1;     // No menu-write to gamy field
241   DemoRecordFix = 1;     // Demo record timing fix on
242   DebugSwitch = 1;     // Allow Ctrl/Alt-ScrollLock
243   Ver62 = 1;       // Version 6.2 stuff
244   Ver62test = 0;     // Version 6.2 test stuff
245   Ver63 = 1;       // Version 6.3 stuff
246   Ver64 = 1;       // Version 6.4 stuff
247
248 }
249
250 int GetSI(int X, int Y)
251 {
252   int GetSI;
253
254   GetSI = Y * FieldWidth + X;
255
256   return GetSI;
257 }
258
259 int GetX(int si)
260 {
261   int GetX;
262
263   GetX = si % FieldWidth;
264
265   return GetX;
266 }
267
268 int GetY(int si)
269 {
270   int GetY;
271
272   GetY = si / FieldWidth;
273
274   return GetY;
275 }
276
277 int GetStretchX(int si)
278 {
279   int GetStretchX;
280
281   GetStretchX = StretchWidth * (si % FieldWidth);
282
283   return GetStretchX;
284 }
285
286 int GetStretchY(int si)
287 {
288   int GetStretchY;
289
290   GetStretchY = StretchWidth * (si / FieldWidth);
291
292   return GetStretchY;
293 }
294
295 void ReadLevel()
296 {
297   // int FNum;
298   FILE *FNum;
299   long i;
300   // byte T;
301
302   DemoAvailable = False;
303   if (STRING_IS_LIKE(CurPath, "*.mpx"))
304   {
305     ReadMPX();
306     return;
307   }
308
309   if (STRING_IS_LIKE(CurPath, "*.sp"))
310   {
311     ReadDemo();
312     return;
313   }
314
315   if (DemoFlag != 0)
316   {
317     ReadDemo();
318     return;
319   }
320
321   FileMax = 0;
322   FieldWidth = 60;
323   FieldHeight = 24;
324   HeaderSize = 96;
325   FieldMax = (FieldWidth * FieldHeight) + HeaderSize - 1;
326   LevelMax = (FieldWidth * FieldHeight) - 1;
327   PlayField8 = REDIM_1D(sizeof(byte), 0, FieldMax + 1 - 1);
328   DisPlayField = REDIM_1D(sizeof(byte), 0, FieldMax + 1 - 1);
329   // FNum = FreeFile();
330
331   // --- On Error GoTo ReadLevelEH
332   FNum = fopen(CurPath, "rb");
333   i = (LevelNumber - 1) * ((long)(FieldMax) + 1) + 1;
334   FILE_GET(FNum, i, &PlayField8, sizeof(PlayField8));
335   i = (LevelNumber) * ((long)(FieldMax) + 1) + 1 - HeaderSize;
336   FILE_GET(FNum, i, &LInfo, sizeof(LInfo)); // store level info in an extra structure
337   fclose(FNum);
338   // --- On Error GoTo 0
339
340   if (FieldMax < FileMax)
341     DemoAvailable = True;
342
343   ReadSignature();
344   PlayField16 = REDIM_1D(sizeof(int), -FieldWidth, FieldMax);
345   for (i = 0; i <= FieldMax; i++)
346   {
347     PlayField16[i] = PlayField8[i];
348     DisPlayField[i] = PlayField8[i];
349     PlayField8[i] = 0;
350   }
351
352   AnimationPosTable = REDIM_1D(sizeof(int), 0, LevelMax - 2 *FieldWidth);
353   AnimationSubTable = REDIM_1D(sizeof(byte), 0, LevelMax - 2 *FieldWidth);
354   TerminalState = REDIM_1D(sizeof(byte), FieldWidth, LevelMax - FieldWidth);
355   GravityFlag = LInfo.InitialGravity;
356   FreezeZonks = LInfo.InitialFreezeZonks;
357   subRandomize();
358   LevelLoaded = True;
359   return;
360
361 #if 0
362 ReadLevelEH:
363   Close();
364 #endif
365 }
366
367 static void ReadDemo()
368 {
369   // int FNum, i;
370   FILE *FNum;
371   int i;
372   // byte T;
373
374   FieldWidth = 60;
375   FieldHeight = 24;
376   HeaderSize = 96;
377   FieldMax = (FieldWidth * FieldHeight) + HeaderSize - 1;
378   LevelMax = (FieldWidth * FieldHeight) - 1;
379
380   // --- On Error GoTo ReadDemoEH
381   FileMax = FileLen(CurPath) - 1;
382   PlayField8 = REDIM_1D(sizeof(byte), 0, FileMax + 1 - 1);
383   DisPlayField = REDIM_1D(sizeof(byte), 0, FieldMax + 1 - 1);
384   // FNum = FreeFile();
385   FNum = fopen(CurPath, "rb");
386   i = (LevelNumber - 1) * ((long)(FieldMax) + 1) + 1;
387   FILE_GET(FNum, i, &PlayField8, sizeof(PlayField8));
388   i = (LevelNumber) * ((long)(FieldMax) + 1) + 1 - HeaderSize;
389   FILE_GET(FNum, i, &LInfo, sizeof(LInfo)); // store level info in an extra structure
390   fclose(FNum);
391   // --- On Error GoTo 0
392
393   if (FieldMax < FileMax)
394     DemoAvailable = True;
395
396   ReadSignature();
397   PlayField16 = REDIM_1D(sizeof(int), -FieldWidth, FieldMax);
398   for (i = 0; i <= FieldMax; i++)
399   {
400     PlayField16[i] = PlayField8[i];
401     DisPlayField[i] = PlayField8[i];
402     PlayField8[i] = 0;
403   }
404
405   AnimationPosTable = REDIM_1D(sizeof(int), 0, LevelMax - 2 *FieldWidth);
406   AnimationSubTable = REDIM_1D(sizeof(byte), 0, LevelMax - 2 *FieldWidth);
407   TerminalState = REDIM_1D(sizeof(byte), 0, FieldMax + 1 - 1);
408   DemoPointer = FieldMax + 1;
409   DemoOffset = DemoPointer;
410   DemoKeyRepeatCounter = 0;
411   // DemoFlag = 1
412   // DemoAvailable = True
413   GravityFlag = LInfo.InitialGravity;
414   FreezeZonks = LInfo.InitialFreezeZonks;
415   RandomSeed = LInfo.DemoRandomSeed;
416   LevelLoaded = True;
417   return;
418
419 #if 0
420 ReadDemoEH:
421   Close();
422 #endif
423 }