major cleanup of preprocessor hell
[rocksndiamonds.git] / src / game_sp / init.c
1
2 #include "main_sp.h"
3 #include "global.h"
4
5
6 char *preceding_playfield_memory[] =
7 {
8   "95 89 95 89 95 89 3b 8a  3b 8a 3b 8a 3b 8a 3b 8a",   // |......;.;.;.;.;.|
9   "3b 8a 3b 8a 3b 8a e8 8a  e8 8a e8 8a e8 8a e8 8a",   // |;.;.;.è.è.è.è.è.|
10   "e8 8a e8 8a e8 8a b1 8b  b1 8b b1 8b b1 8b b1 8b",   // |è.è.è.±.±.±.±.±.|
11   "b1 8b b1 8b b1 8b 85 8c  85 8c 85 8c 85 8c 85 8c",   // |±.±.±...........|
12   "85 8c 85 8c 85 8c 5b 8d  5b 8d 5b 8d 5b 8d 5b 8d",   // |......[.[.[.[.[.|
13   "5b 8d 5b 8d 5b 8d 06 8e  06 8e 06 8e 06 8e 06 8e",   // |[.[.[...........|
14   "06 8e 06 8e 06 8e ac 8e  ac 8e ac 8e ac 8e ac 8e",   // |......¬.¬.¬.¬.¬.|
15   "ac 8e ac 8e ac 8e 59 8f  59 8f 59 8f 59 8f 59 8f",   // |¬.¬.¬.Y.Y.Y.Y.Y.|
16   "59 8f 59 8f 59 8f 00 00  70 13 00 00 00 00 e8 17",   // |Y.Y.Y...p.....è.|
17   "00 00 00 00 00 00 69 38  00 00 00 00 00 00 00 00",   // |......i8........|
18   "00 00 00 00 00 00 00 00  d0 86 00 00 b2 34 00 00",   // |........Ð...²4..|
19   "00 00 00 00 00 00 8f 8b  1d 34 00 00 00 00 00 00",   // |.........4......|
20   "00 00 00 00 23 39 09 09  00 0c 00 08 00 58 00 00",   // |....#9.......X..|
21   "00 00 00 25 77 06 7f 00  00 00 01 00 00 00 00 00",   // |...%w...........|
22   "00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00",   // |................|
23   "00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00",   // |................|
24   "00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00",   // |................|
25   "00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00",   // |................|
26   "00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00",   // |................|
27   "00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00",   // |................|
28   "00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00",   // |................|
29   "00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00",   // |................|
30   "00 00 00 00 00 00 00 00  00 ec 06 26 05 00 00 00",   // |.........ì.&....|
31   "00 00 00 01 00 00 00 00  31 32 33 34 35 36 37 38",   // |........12345678|
32   "39 30 2d 00 08 00 51 57  45 52 54 59 55 49 4f 50",   // |90-...QWERTYUIOP|
33   "00 00 0a 00 41 53 44 46  47 48 4a 4b 4c 00 00 00",   // |....ASDFGHJKL...|
34   "00 00 5a 58 43 56 42 4e  4d 00 00 00 00 00 00 20",   // |..ZXCVBNM...... |
35   "00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00",   // |................|
36   "00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00",   // |................|
37   "00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00",   // |................|
38   "00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00",   // |................|
39   "00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00",   // |................|
40   "00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00",   // |................|
41   "00 00 00 00 00 00 2e 00  1e 00 31 00 14 00 39 00",   // |..........1...9.|
42   "1f 00 14 00 18 00 ff ff  01 00 01 4c 45 56 45 4c",   // |......ÿÿ...LEVEL|
43   "53 2e 44 41 54 00 00 00  00 00 00 00 00 00 00 00",   // |S.DAT...........|
44   "00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00",   // |................|
45   "00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00",   // |................|
46   "00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00",   // |................|
47   "00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00",   // |................|
48   "00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00",   // |................|
49   "00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00",   // |................|
50   "00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00",   // |................|
51
52   NULL
53 };
54
55
56 Bitmap *bitmap_db_field_sp;
57
58 struct EngineSnapshotInfo_SP engine_snapshot_sp;
59
60 void sp_open_all()
61 {
62   Form_Load();
63 }
64
65 void sp_close_all()
66 {
67 }
68
69 void InitPrecedingPlayfieldMemory()
70 {
71   int preceding_buffer_size = 0;
72   int i;
73
74   for (i = 0; preceding_playfield_memory[i] != NULL; i++)
75     preceding_buffer_size += 8;         /* eight 16-bit integer values */
76
77   game_sp.preceding_buffer = preceding_playfield_memory;
78   game_sp.preceding_buffer_size = preceding_buffer_size;
79 }
80
81 void InitGfxBuffers_SP()
82 {
83   ReCreateBitmap(&bitmap_db_field_sp, FXSIZE, FYSIZE, DEFAULT_DEPTH);
84 }
85
86 unsigned int InitEngineRandom_SP(int seed)
87 {
88   if (seed == NEW_RANDOMIZE)
89   {
90     subRandomize();
91
92     seed = (int)RandomSeed;
93   }
94
95   RandomSeed = (short)seed;
96
97   return (unsigned int) seed;
98 }
99
100
101 /* ------------------------------------------------------------------------- */
102 /* Supaplex game engine snapshot handling functions                          */
103 /* ------------------------------------------------------------------------- */
104
105 void SaveEngineSnapshotValues_SP()
106 {
107   int i;
108
109   engine_snapshot_sp.game_sp = game_sp;
110
111   /* these arrays have playfield-size dependent variable size */
112
113   for (i = 0; i < FieldWidth * FieldHeight + HeaderSize; i++)
114     engine_snapshot_sp.PlayField16[i] = PlayField16[i];
115   for (i = 0; i < FieldWidth * FieldHeight + HeaderSize; i++)
116     engine_snapshot_sp.PlayField8[i] = PlayField8[i];
117   for (i = 0; i < FieldWidth * FieldHeight + HeaderSize; i++)
118     engine_snapshot_sp.DisPlayField[i] = DisPlayField[i];
119
120   for (i = 0; i < FieldWidth * (FieldHeight - 2); i++)
121     engine_snapshot_sp.AnimationPosTable[i] = AnimationPosTable[i];
122   for (i = 0; i < FieldWidth * (FieldHeight - 2); i++)
123     engine_snapshot_sp.AnimationSubTable[i] = AnimationSubTable[i];
124   for (i = 0; i < FieldWidth * FieldHeight + HeaderSize; i++)
125     engine_snapshot_sp.TerminalState[i] = TerminalState[i];
126
127   /* store special data into engine snapshot buffers */
128
129   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(FieldWidth));
130   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(FieldHeight));
131   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(FieldMax));
132   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(LevelMax));
133
134   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(TimerVar));
135   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(RandomSeed));
136
137   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(TerminalMaxCycles));
138
139   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(mScrollX));
140   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(mScrollY));
141   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(mScrollX_last));
142   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(mScrollY_last));
143
144   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ScreenScrollXPos));
145   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ScreenScrollYPos));
146   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(DisplayMinX));
147   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(DisplayMinY));
148   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(DisplayMaxX));
149   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(DisplayMaxY));
150
151   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(InfotronsNeeded));
152   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(KillMurphyFlag));
153   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(MurphyMoveCounter));
154   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(MurphyExplodePos));
155   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(SplitMoveFlag));
156   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(RedDiskReleaseMurphyPos));
157   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(MurphyPosIndex));
158   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(MurphyXPos));
159   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(MurphyYPos));
160   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(MurphyScreenXPos));
161   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(MurphyScreenYPos));
162   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(MurphyVarFaceLeft));
163   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(RedDiskCount));
164   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(RedDiskReleaseFlag));
165   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(MovingPictureSequencePhase));
166   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(RedDiskReleasePhase));
167   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ScratchGravity));
168   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(GravityFlag));
169   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(SnikSnaksElectronsFrozen));
170   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(YellowDisksExploded));
171   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(YawnSleepCounter));
172
173   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(LeadOutCounter));
174
175   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(GfxElementLast));
176   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(GfxGraphicLast));
177   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(GfxGraphic));
178   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(GfxFrame));
179
180   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ScrollMinX));
181   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ScrollMinY));
182   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ScrollMaxX));
183   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ScrollMaxY));
184   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ScrollX));
185   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ScrollY));
186
187   SaveEngineSnapshotBuffer(&PlayField16[-game_sp.preceding_buffer_size],
188                            game_sp.preceding_buffer_size * sizeof(int));
189 }
190
191 void LoadEngineSnapshotValues_SP()
192 {
193   int i;
194
195   /* stored engine snapshot buffers already restored at this point */
196
197   game_sp = engine_snapshot_sp.game_sp;
198
199   /* these arrays have playfield-size dependent variable size */
200
201   for (i = 0; i < FieldWidth * FieldHeight + HeaderSize; i++)
202     PlayField16[i] = engine_snapshot_sp.PlayField16[i];
203   for (i = 0; i < FieldWidth * FieldHeight + HeaderSize; i++)
204     PlayField8[i] = engine_snapshot_sp.PlayField8[i];
205   for (i = 0; i < FieldWidth * FieldHeight + HeaderSize; i++)
206     DisPlayField[i] = engine_snapshot_sp.DisPlayField[i];
207
208   for (i = 0; i < FieldWidth * (FieldHeight - 2); i++)
209     AnimationPosTable[i] = engine_snapshot_sp.AnimationPosTable[i];
210   for (i = 0; i < FieldWidth * (FieldHeight - 2); i++)
211     AnimationSubTable[i] = engine_snapshot_sp.AnimationSubTable[i];
212   for (i = 0; i < FieldWidth * FieldHeight + HeaderSize; i++)
213     TerminalState[i] = engine_snapshot_sp.TerminalState[i];
214
215   RedrawPlayfield_SP(TRUE);
216 }