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
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
/*
* This code is based on original Soltys source code
* Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon
*/
#include "cge/cge.h"
#include "cge/general.h"
#include "cge/snddrv.h"
#include "cge/wav.h"
namespace CGE {
Dac _stdPal[] = {// R G B
{ 0, 60, 0}, // 198
{ 0, 104, 0}, // 199
{ 20, 172, 0}, // 200
{ 82, 82, 0}, // 201
{ 0, 132, 82}, // 202
{ 132, 173, 82}, // 203
{ 82, 0, 0}, // 204
{ 206, 0, 24}, // 205
{ 255, 33, 33}, // 206
{ 123, 41, 0}, // 207
{ 0, 41, 0}, // 208
{ 0, 0, 82}, // 209
{ 132, 0, 0}, // 210
{ 255, 0, 0}, // 211
{ 255, 66, 66}, // 212
{ 148, 66, 16}, // 213
{ 0, 82, 0}, // 214
{ 0, 0, 132}, // 215
{ 173, 0, 0}, // 216
{ 255, 49, 0}, // 217
{ 255, 99, 99}, // 218
{ 181, 107, 49}, // 219
{ 0, 132, 0}, // 220
{ 0, 0, 255}, // 221
{ 173, 41, 0}, // 222
{ 255, 82, 0}, // 223
{ 255, 132, 132}, // 224
{ 214, 148, 74}, // 225
{ 41, 214, 0}, // 226
{ 0, 82, 173}, // 227
{ 255, 214, 0}, // 228
{ 247, 132, 49}, // 229
{ 255, 165, 165}, // 230
{ 239, 198, 123}, // 231
{ 173, 214, 0}, // 232
{ 0, 132, 214}, // 233
{ 57, 57, 57}, // 234
{ 247, 189, 74}, // 235
{ 255, 198, 198}, // 236
{ 255, 239, 173}, // 237
{ 214, 255, 173}, // 238
{ 82, 173, 255}, // 239
{ 107, 107, 107}, // 240
{ 247, 222, 99}, // 241
{ 255, 0, 255}, // 242
{ 255, 132, 255}, // 243
{ 132, 132, 173}, // 244
{ 148, 247, 255}, // 245
{ 148, 148, 148}, // 246
{ 82, 0, 82}, // 247
{ 112, 68, 112}, // 248
{ 176, 88, 144}, // 249
{ 214, 132, 173}, // 250
{ 206, 247, 255}, // 251
{ 198, 198, 198}, // 252
{ 0, 214, 255}, // 253
{ 96, 224, 96 }, // 254
{ 255, 255, 255}, // 255
};
void _fqsort(void *base, uint16 nelem, uint16 width, int (*fcmp)(const void *, const void *)) {
warning("STUB: _fqsort");
}
const char *progName(const char *ext) {
static char buf[kMaxFile];
strcpy(buf, "CGE");
if (ext) {
strcat(buf, ".");
if (*ext == '.')
ext++;
strcat(buf, ext);
}
return buf;
}
char *mergeExt(char *buf, const char *name, const char *ext) {
strcpy(buf, name);
char *dot = strrchr(buf, '.');
if (!dot)
strcat(buf, ext);
return buf;
}
char *forceExt(char *buf, const char *name, const char *ext) {
strcpy(buf, name);
char *dot = strrchr(buf, '.');
if (dot)
*dot = '\0';
strcat(buf, ext);
return buf;
}
static unsigned Seed = 0xA5;
unsigned fastRand() {
return Seed = 257 * Seed + 817;
}
unsigned fastRand(unsigned s) {
return Seed = 257 * s + 817;
}
uint16 RCrypt(void *buf, uint16 siz, uint16 seed) {
if (buf && siz) {
byte *b = static_cast<byte *>(buf);
byte *q = b + (siz - 1);
seed = fastRand(seed);
*b++ ^= seed;
while (buf < q)
*b++ ^= fastRand();
if (buf == q)
*b ^= (seed = fastRand());
}
return seed;
}
uint16 XCrypt(void *buf, uint16 siz, uint16 seed) {
byte *b = static_cast<byte *>(buf);
for (uint16 i = 0; i < siz; i++)
*b++ ^= seed;
return seed;
}
uint16 atow(const char *a) {
uint16 w = 0;
if (a)
while (IsDigit(*a))
w = (10 * w) + (*(a++) & 0xF);
return w;
}
uint16 xtow(const char *x) {
uint16 w = 0;
if (x) {
while (IsHxDig(*x)) {
register uint16 d = *(x++);
if (d > '9')
d -= 'A' - ('9' + 1);
w = (w << 4) | (d & 0xF);
}
}
return w;
}
char *wtom(uint16 val, char *str, int radix, int len) {
while (--len >= 0) {
uint16 w = val % radix;
if (w > 9)
w += ('A' - ('9' + 1));
str[len] = '0' + w;
val /= radix;
}
return str;
}
char *dwtom(uint32 val, char *str, int radix, int len) {
while (--len >= 0) {
uint16 w = (uint16) (val % radix);
if (w > 9)
w += ('A' - ('9' + 1));
str[len] = '0' + w;
val /= radix;
}
return str;
}
IoHand::IoHand(IOMode mode, Crypt *crypt)
: XFile(mode), _crypt(crypt), _seed(kCryptSeed) {
_file = new Common::File();
}
IoHand::IoHand(const char *name, IOMode mode, Crypt *crypt)
: XFile(mode), _crypt(crypt), _seed(kCryptSeed) {
// TODO: Check if WRI and/or UPD modes are needed, and map to a save file
assert(mode == kModeRead);
_file = new Common::File();
_file->open(name);
}
IoHand::~IoHand() {
_file->close();
delete _file;
}
uint16 IoHand::read(void *buf, uint16 len) {
if (_mode == kModeWrite || !_file->isOpen())
return 0;
uint16 bytesRead = _file->read(buf, len);
if (!bytesRead)
error("Read %s - %d bytes", _file->getName(), len);
if (_crypt)
_seed = _crypt(buf, len, Seed);
return bytesRead;
}
uint16 IoHand::write(void *buf, uint16 len) {
warning("IOHAND::Write not supported");
return 0;
/*
if (len) {
if (Mode == kModeRead || Handle < 0)
return 0;
if (Crypt)
Seed = Crypt(buf, len, Seed);
Error = _dos_write(Handle, buf, len, &len);
if (Crypt)
Seed = Crypt(buf, len, Seed); //------$$$$$$$
}
return len;
*/
}
long IoHand::mark() {
return _file->pos();
}
long IoHand::seek(long pos) {
_file->seek(pos, SEEK_SET);
return _file->pos();
}
long IoHand::size() {
return _file->size();
}
bool IoHand::exist(const char *name) {
Common::File f;
return f.exists(name);
}
void sndInit() {
warning("STUB: SNDInit");
}
void sndDone() {
// FIXME: STUB: SNDDone
}
void sndSetVolume() {
warning("STUB: SNDSetVolume");
}
void sndDigiStart(SmpInfo *PSmpInfo) {
warning("STUB: SNDDigitStart");
}
void sndDigiStop(SmpInfo *PSmpInfo) {
warning("STUB: SNDDigiStop");
}
void sndMidiStart(uint8 *MIDFile) {
warning("STUB: SNDMIDIStart");
}
void sndMidiStop() {
// FIXME: STUB: sndMIDIStop
}
DataCk *loadWave(XFile *file) {
warning("STUB: LoadWave");
return NULL;
}
int takeEnum(const char **tab, const char *text) {
const char **e;
if (text) {
for (e = tab; *e; e++) {
if (scumm_stricmp(text, *e) == 0) {
return e - tab;
}
}
}
return -1;
}
long timer() {
/*
asm mov ax,0x40
asm mov es,ax
asm mov cx,es:[0x6C]
asm mov dx,es:[0x6E]
return ((long) _DX << 16) | _CX;
*/
warning("STUB: timer");
return 0;
}
int newRandom(int range) {
return ((CGEEngine *)g_engine)->_randomSource.getRandomNumber(range - 1);
}
DataCk::~DataCk() {
if (_buf)
free(_buf);
}
} // End of namespace CGE
|