rnd-20100417-1-src
[rocksndiamonds.git] / src / game_sp / init.c
1
2 #include "main_sp.h"
3 #include "global.h"
4
5
6 Bitmap *bitmap_db_field_sp;
7
8 struct EngineSnapshotInfo_SP engine_snapshot_sp;
9
10 void sp_open_all()
11 {
12   Form_Load();
13
14 #if 0
15   printf("::: open 1: %d, %d [%08x]\n", FXSIZE, FYSIZE, bitmap_db_field_sp);
16
17   /*
18   bitmap_db_field_sp = CreateBitmap(FXSIZE, FYSIZE, DEFAULT_DEPTH);
19   bitmap_db_field_sp = CreateBitmap(MAX_BUF_XSIZE * TILEX, MAX_BUF_YSIZE * TILEY,
20                               DEFAULT_DEPTH);
21   */
22
23   ReCreateBitmap(&bitmap_db_field_sp, FXSIZE, FYSIZE, DEFAULT_DEPTH);
24
25   printf("::: open 2: %d, %d [%08x]\n", FXSIZE, FYSIZE, bitmap_db_field_sp);
26 #endif
27 }
28
29 void sp_close_all()
30 {
31 }
32
33 void InitGfxBuffers_SP()
34 {
35 #if 1
36   printf("::: init 1: %d, %d [%08x]\n", FXSIZE, FYSIZE, bitmap_db_field_sp);
37
38   /*
39   ReCreateBitmap(&bitmap_db_field_sp, MAX_BUF_XSIZE * TILEX, MAX_BUF_YSIZE * TILEY,
40                  DEFAULT_DEPTH);
41   */
42
43   ReCreateBitmap(&bitmap_db_field_sp, FXSIZE, FYSIZE, DEFAULT_DEPTH);
44
45   printf("::: init 2: %d, %d [%08x]\n", FXSIZE, FYSIZE, bitmap_db_field_sp);
46 #endif
47 }
48
49 unsigned int InitEngineRandom_SP(long seed)
50 {
51   if (seed == NEW_RANDOMIZE)
52   {
53     subRandomize();
54
55     seed = (long)RandomSeed;
56   }
57
58   RandomSeed = (short)seed;
59
60   return (unsigned int) seed;
61 }
62
63
64 /* ------------------------------------------------------------------------- */
65 /* Supaplex game engine snapshot handling functions                          */
66 /* ------------------------------------------------------------------------- */
67
68 void SaveEngineSnapshotValues_SP()
69 {
70   int i;
71
72   engine_snapshot_sp.game_sp = game_sp;
73
74   /* these arrays have playfield-size dependent variable size */
75
76   for (i = 0; i < FieldWidth * FieldHeight + HeaderSize; i++)
77     engine_snapshot_sp.PlayField16[i] = PlayField16[i];
78   for (i = 0; i < FieldWidth * FieldHeight + HeaderSize; i++)
79     engine_snapshot_sp.PlayField8[i] = PlayField8[i];
80   for (i = 0; i < FieldWidth * FieldHeight + HeaderSize; i++)
81     engine_snapshot_sp.DisPlayField[i] = DisPlayField[i];
82
83   for (i = 0; i < FieldWidth * (FieldHeight - 2); i++)
84     engine_snapshot_sp.AnimationPosTable[i] = AnimationPosTable[i];
85   for (i = 0; i < FieldWidth * (FieldHeight - 2); i++)
86     engine_snapshot_sp.AnimationSubTable[i] = AnimationSubTable[i];
87   for (i = 0; i < FieldWidth * FieldHeight + HeaderSize; i++)
88     engine_snapshot_sp.TerminalState[i] = TerminalState[i];
89
90   /* store special data into engine snapshot buffers */
91
92   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(FieldWidth));
93   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(FieldHeight));
94   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(FieldMax));
95   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(LevelMax));
96   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(FileMax));
97
98   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(TimerVar));
99   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(RandomSeed));
100
101   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(TerminalMaxCycles));
102
103   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(mScrollX));
104   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(mScrollY));
105   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(mScrollX_last));
106   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(mScrollY_last));
107
108   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ScreenScrollXPos));
109   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ScreenScrollYPos));
110   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(DisplayMinX));
111   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(DisplayMinY));
112   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(DisplayMaxX));
113   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(DisplayMaxY));
114
115   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(InfotronsNeeded));
116   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(KillMurphyFlag));
117   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(MurphyMoveCounter));
118   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(MurphyExplodePos));
119   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(SplitMoveFlag));
120   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(RedDiskReleaseMurphyPos));
121   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(MurphyPosIndex));
122   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(MurphyXPos));
123   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(MurphyYPos));
124   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(MurphyScreenXPos));
125   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(MurphyScreenYPos));
126   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(MurphyVarFaceLeft));
127   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(RedDiskCount));
128   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(RedDiskReleaseFlag));
129   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(MovingPictureSequencePhase));
130   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(RedDiskReleasePhase));
131   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ScratchGravity));
132   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(GravityFlag));
133   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(SnikSnaksElectronsFrozen));
134   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(YellowDisksExploded));
135   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(YawnSleepCounter));
136
137   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(LeadOutCounter));
138
139   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(GfxElementLast));
140   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(GfxGraphicLast));
141   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(GfxGraphic));
142   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(GfxFrame));
143
144   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ScrollMinX));
145   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ScrollMinY));
146   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ScrollMaxX));
147   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ScrollMaxY));
148   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ScrollX));
149   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ScrollY));
150
151   SaveEngineSnapshotBuffer(&PlayField16[-game_sp.preceding_buffer_size],
152                            game_sp.preceding_buffer_size * sizeof(int));
153 }
154
155 void LoadEngineSnapshotValues_SP()
156 {
157   int i;
158
159   /* stored engine snapshot buffers already restored at this point */
160
161   game_sp = engine_snapshot_sp.game_sp;
162
163   /* these arrays have playfield-size dependent variable size */
164
165   for (i = 0; i < FieldWidth * FieldHeight + HeaderSize; i++)
166     PlayField16[i] = engine_snapshot_sp.PlayField16[i];
167   for (i = 0; i < FieldWidth * FieldHeight + HeaderSize; i++)
168     PlayField8[i] = engine_snapshot_sp.PlayField8[i];
169   for (i = 0; i < FieldWidth * FieldHeight + HeaderSize; i++)
170     DisPlayField[i] = engine_snapshot_sp.DisPlayField[i];
171
172   for (i = 0; i < FieldWidth * (FieldHeight - 2); i++)
173     AnimationPosTable[i] = engine_snapshot_sp.AnimationPosTable[i];
174   for (i = 0; i < FieldWidth * (FieldHeight - 2); i++)
175     AnimationSubTable[i] = engine_snapshot_sp.AnimationSubTable[i];
176   for (i = 0; i < FieldWidth * FieldHeight + HeaderSize; i++)
177     TerminalState[i] = engine_snapshot_sp.TerminalState[i];
178
179   RedrawPlayfield_SP(TRUE);
180 }