-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCode222ea.cpp
More file actions
343 lines (328 loc) · 7.26 KB
/
Code222ea.cpp
File metadata and controls
343 lines (328 loc) · 7.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
#include "stdafx.h"
#include "UI.h"
#include <stdio.h>
//#include "Objects.h"
#include "Dispatch.h"
#include "CSB.h"
#include "Data.h"
void TAG021234()
{
HopefullyNotNeeded(0x21234);
}
// TAG021960
void SortWords(i16 *entries,i16 numEnt)
{
//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
//pnt A3;
ui16 uwD0, uwD1, uwD4, uwD5, uwD6, uwD7;
ui16 uwLOCAL_8;
ui16 uwLOCAL_6;
ui16 logNumEnt;
i32 i;
logNumEnt = 0;
i = numEnt;
while ((i >>= 1) != 0)
{
logNumEnt++;
};
for (i=logNumEnt-1; i>=0; i--)
{
uwLOCAL_6 = uw((1 << i) - 1);
uwLOCAL_8 = uw(uwLOCAL_6 << 1);
for (uwD6=uwLOCAL_6; uwD6<=uwLOCAL_8; uwD6++) // 2nd half of current part??
{
uwD7 = uwD6;
uwD4 = entries[uwD6]; // Middle entry
for (;;)
{
uwD5 = uw((uwD7<<1)+1);
if ((ui16)uwD5 >= numEnt) break;
if ((ui16)uwD5+1 < numEnt)
{
uwD0 = entries[uwD5+1];
if ((ui16)uwD0 >= entries[uwD5]) uwD5++;
};
if ((ui16)uwD4 >= (ui16)entries[uwD5]) break;
uwD0 = entries[uwD5];
entries[uwD7] = uwD0;
uwD7 = uwD5;
//continue;
};
entries[uwD7] = uwD4;
//
};
//
};
for (uwLOCAL_6=uw(numEnt-1); uwLOCAL_6!=0; uwLOCAL_6--)
{
uwD4 = entries[uwLOCAL_6];
uwD7=0;
uwD0 = entries[uwD7];
uwD1 = uwLOCAL_6;
entries[uwD1] = uwD0;
for (;;)
{
uwD5 = uw((uwD7<<1)+1);
if (uwD5 > uwLOCAL_6-1) break;
if (uwD5 < uwLOCAL_6 - 1)
{
uwD0 = entries[uwD5+1];
if (uwD0 >= entries[uwD5]) uwD5++;
};
if (uwD4 >= entries[uwD5]) break;
uwD0 = entries[uwD5];
entries[uwD7] = uwD0;
uwD7 = uwD5;
}; // while (1)
entries[uwD7] = uwD4;
//
};
}
void TAG0220fa(i32 P1)
{
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
while (d.iAvailableGraphicMemory < P1)
{
if (d.pqFirstGraphic == NULL)
{
SystemError(43);
};
DeleteGraphic(d.pqFirstGraphic->graphicNum);
};
}
/*
//*********************************************************
//
//*********************************************************
// TAG022132
void CompactMemory()
{
dReg D5, D6, D7;
pnt A2, A3;
VerifyGraphicFreeList();
//#ifdef _VERIFYPPQ
// verifyppq();
//#endif
//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
if (d.pgUnused == NULL) return;
A2 = A3 = d.pStartMemory;
do
{
D7L = longGear(A2);
if (D7L > 0) // Not being used
{
A2 += D7L; // Look for next buffer in use
}
else
{
D7L = -D7L;
if (A2 != A3)
{
D6W = wordGear(A2+10);
if (D6W >= 0)
{
D5W = d.GraphicIndex0[D6W];
}
else
{
D5W = d.GraphicIndex8000[D6W & 0x7fff];
};
d.ppExpandedGraphics[D5W] = (ITEMQ *)A3;
MemMove(A2, A3, D7W);
if (d.pqFirstGraphic == (ITEMQ *)A2)
{
d.pqFirstGraphic = (ITEMQ *)A3;
};
if (d.pqLastGraphic == (ITEMQ *)A2)
{
d.pqLastGraphic = (ITEMQ *)A3;
};
if (d.pqFirstGraphic2 == (ITEMQ *)A2)
{
d.pqFirstGraphic2 = (ITEMQ *)A3;
};
};
ASSERT(longGear(A3) == longGear(A3+D7L-4));
A2 += D7L;
A3 += D7L;
};
} while (A2 != d.Pointer23318);
//#ifdef _VERIFYPPQ
// verifyppq();
//#endif
d.Pointer23318 = A3;
d.pgUnused = NULL;
}
*/
//*********************************************************
//
//*********************************************************
// _TAG0222ea
void LoadNeededGraphics(i16 *P1, const i32 Count)
{//()
//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
dReg D0, D4, D5, D6, D7;
aReg A0, A2, A3;
i32 iLOCAL_24;
// i16 wLOCAL_14;
pnt pLOCAL_12;
i32 iLOCAL_8;
i32 iLOCAL_4;
i16 count;
//RESTARTMAP
// RESTART(1)
//END_RESTARTMAP
count=sw(Count);
bool fileOpen = false;
SortWords(P1, count);
iLOCAL_4 = 0;
for (D7W=0; D7W<count; D7W++)
{
D5W = P1[D7W];
while ( ((D6W=sw(D7W+1)) < count)
&&(D5W == P1[D6W]) )
{
MemMove((ui8 *)&P1[D6W], (ui8 *)&P1[D7W], 2*((count--)-D6W));
};
D4L = d.GraphicDecompressedSizes[D5W] + 2;
if (D4L & 1) D4L++;
iLOCAL_4 += D4L;
};
if (d.Word23328 != 0)
{
iLOCAL_8 = (ui8 *)d.Pointer23310 - iLOCAL_4 - d.pStartMemory;
}
else
{
iLOCAL_8 = d.pStartAvailMemory - d.pStartMemory;
};
A0 = (aReg)d.LogicalScreenBase;
longGear((ui8 *)A0+32000) = iLOCAL_8;
if (iLOCAL_8 < 19576)
{
SystemError(44); // Error number
};
for (D7W=0; D7W<730; D7W++)
{
if (d.GetDerivedGraphicCacheIndex(D7W) != -1)
{
DeleteGraphic(D7W|0x8000);
};
//
};
D7W = 0;
do
{
D5W = P1[D7W];
for (D6W=0; D6W<D5W; D6W++)
{
A3 = (aReg)d.ppUnExpandedGraphics[D6W];
if (A3 == NULL) continue;
DeleteGraphic(D6W);
d.ppUnExpandedGraphics[D6W] = NULL;
D4L = d.GraphicDecompressedSizes[D6W];
if (D4L & 1) D4L++;
D0L = -D4L;
longGear((ui8 *)A3 + D4L) = D0W;
};
if (d.ppUnExpandedGraphics[D6W++] != NULL)
{
P1[D7W] ^= 0xffff;
};
D7W++;
} while (D7W < count);
for (; D6W<d.NumGraphic; D6W++)
{
A3 = d.ppUnExpandedGraphics[D6W];
if (A3 != NULL)
{
DeleteGraphic(D6W);
d.ppUnExpandedGraphics[D6W] = NULL;
D4L = d.GraphicDecompressedSizes[D6W];
D4L += D4L & 1;
wordGear(A3 + D4L) = sw(-D4L);
};
};
if (d.Word23328 != 0)
{
D4L = d.Pointer23314 - (d.Pointer23310 - iLOCAL_4);
if (D4L > 0)
{
TAG0220fa(D4L);
};
//CompactMemory();
d.iAvailableGraphicMemory -= D4L;
};
A2 = (aReg)d.Pointer23310;
ASSERT(((int)A2 & 3) == 0,"A2");
A3 = A2-2;
while (A3>d.Pointer23314)
{
D5W = wordGear(A3);
if (D5W < 0)
{
A3 += D5W-2;
}
else
{
iLOCAL_24 = A3 - d.ppUnExpandedGraphics[D5W];
D4L = iLOCAL_24+2;
A2 -= D4L;
A3 -= D4L;
if (A2 != A3+2)
{
MemMove((ui8 *)A3+2, (ui8 *)A2, D4W);
ASSERT(((int)A2 & 3) == 0,"A2");
d.ppUnExpandedGraphics[D5W] = A2;
};
};
};
pLOCAL_12 = (pnt)allocateMemory(5004,0);
// while (d.Word23228 != 0) {};
for (D7W=0; D7W<count; D7W++)
{
D5W = P1[D7W];
if (D5W < 0)
{
P1[D7W] ^= 0xffff;
}
else
{
wordGear(A2-2) = D5W;
D4L = (d.GraphicDecompressedSizes[D5W] + 3) & 0xfffffffc;
A2 -= D4L;
if (!fileOpen)
{
InsertDisk(0,0);
openGraphicsFile();
fileOpen = true;
};
D0L = d.GraphicCompressedSizes[D5W];
if (d.GraphicDecompressedSizes[D5W] != D0L)
{
LSEEK(LocateNthGraphic(D5W), // file address
d.GraphicHandle, // handle
SEEK_SET); // relative to start of file
LZWExpand(d.GraphicHandle,
d.GraphicCompressedSizes[D5W],
(ui8 *)A2, // dest
d.pViewportBMP, // scratch area
(ui8 *)pLOCAL_12); // stack area
d.Word11684 = 1;
}
else
{
ReadGraphic(D5W, (ui8 *)A2);
};
ASSERT(((int)A2 & 3) == 0,"A2");
d.ppUnExpandedGraphics[D5W] = A2;
};
//
};
if (fileOpen) closeGraphicsFile();
d.Pointer23314 = A2;
if (d.Word23328 != 0) d.pStartAvailMemory = (ui8 *)d.Pointer23314;
TAG021234();
FreeTempMemory(5004);
return;
}