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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
|
/* 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 the original source code of Lord Avalot d'Argent version 1.3.
* Copyright (c) 1994-1995 Mike, Mark and Thomas Thurman.
*/
#include "graph.h"
/*#include "Crt.h"*/
/*$R+*/
namespace Avalanche {
const array<1, 5, shortint> adjustment = {{7, 0, 7, 7, 7}};
const array<0, 3, byte> plane_to_use = {{2, 2, 2, 3}};
const array<1, 5, byte> waveorder = {{5, 1, 2, 3, 4}};
const array<1, 26, byte> glerkfade =
{{1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 3, 3, 3, 2, 2, 1}};
const array<1, 18, byte> greldetfade = {{1, 2, 3, 4, 5, 6, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1}};
enum flavourtype {ch_ega, ch_bgi, ch_natural, ch_two, ch_one, last_flavourtype};
struct chunkblocktype {
flavourtype flavour;
integer x, y;
integer xl, yl;
longint size;
};
typedef array<1, 6, 0, 3, 0, 34, 1, 9, byte> glerktype;
untyped_file f;
chunkblocktype cb;
array<1, 5, 2, 3, 0, 65, 0, 25, byte> ghost;
byte fv;
pointer memlevel;
byte y, yy, bit, xofs;
array<0, 1, pointer> eyes;
pointer exclamation;
array<1, 6, pointer> aargh;
array<1, 3, pointer> bat;
glerktype *glerk;
array<1, 5, pointer> green_eyes;
matrix<1, 6, false, true, pointer> greldet;
array<1, 6, pointtype> aargh_where;
integer gd, gm;
boolean gb;
byte glerkstage;
integer bat_x, bat_y;
word bat_count;
shortint aargh_count;
integer greldet_x, greldet_y;
byte greldet_count;
boolean red_greldet;
void plain_grab()
/* Just grabs the next one and puts it where it's told to. */
{
integer xx, yy, xofs;
blockread(f, cb, sizeof(cb));
switch (cb.flavour) {
case ch_one: {
xofs = cb.x / 8;
bit = 3;
for (yy = 0; yy <= cb.yl; yy ++) {
port[0x3c4] = 2;
port[0x3ce] = 4;
port[0x3c5] = 1 << bit;
port[0x3cf] = bit;
blockread(f, mem[0xa000 * (yy + cb.y) * 80 + xofs], cb.xl / 8);
}
}
break;
case ch_ega: {
xofs = cb.x / 8;
bit = 3;
for (bit = 0; bit <= 3; bit ++)
for (yy = 0; yy <= cb.yl; yy ++) {
port[0x3c4] = 2;
port[0x3ce] = 4;
port[0x3c5] = 1 << bit;
port[0x3cf] = bit;
blockread(f, mem[0xa000 * (yy + cb.y) * 80 + xofs], cb.xl / 8);
}
}
break;
}
}
void get_me(pointer &p) {
blockread(f, cb, sizeof(cb));
/* Take it for granted that cb.flavour = ch_BGI! */
{
getmem(p, cb.size);
blockread(f, p, cb.size);
}
}
void get_me_aargh(byte which) {
blockread(f, cb, sizeof(cb));
/* Take it for granted that cb.flavour = ch_BGI! */
{
getmem(aargh[which], cb.size);
blockread(f, aargh[which], cb.size);
}
{
pointtype &with = aargh_where[which];
with.x = cb.x;
with.y = cb.y;
}
}
void wait(word how_long) {
word i;
char r;
for (i = 1; i <= how_long; i ++)
if (keypressed()) {
sound(6177);
while (keypressed()) r = readkey();
delay(1);
nosound;
} else
delay(1);
}
void do_bat();
static byte batimage;
static pointtype batsize;
static void super_blank() {
pointtype oldsize;
move(bat[batimage - 1], oldsize, 4);
bar(bat_x + batsize.x, bat_y, bat_x + oldsize.x, bat_y + oldsize.y);
}
void do_bat() {
shortint dx, iy;
bat_count += 1;
if (odd(bat_count)) {
switch (bat_count) {
case 1 ... 90: {
dx = 2;
iy = 1;
batimage = 1;
}
break;
case 91 ... 240: {
dx = 1;
iy = 1;
batimage = 2;
}
break;
case 241 ... 260: {
dx = 1;
iy = 4;
batimage = 3;
}
break;
}
move(bat[batimage], batsize, 4);
if ((bat_count == 91) || (bat_count == 241))
super_blank(); /* When the bat changes, blank out the old one. */
bar(bat_x, bat_y, bat_x + batsize.x, bat_y + iy);
bar(bat_x + batsize.x, bat_y, bat_x + batsize.x - dx, bat_y + batsize.y);
bat_x -= dx;
bat_y += 1;
putimage(bat_x, bat_y, bat[batimage], 0);
}
}
void big_green_eyes(byte how) {
putimage(330, 103, green_eyes[how], 0);
putimage(376, 103, green_eyes[how], 0);
}
int main(int argc, const char *argv[]) {
pio_initialize(argc, argv);
if (paramstr(1) != "jsb") exit(255);
gd = 3;
gm = 0;
initgraph(gd, gm, "");
fillchar(ghost, sizeof(ghost), '\0');
assign(f, "spooky.avd");
reset(f, 1);
seek(f, 44);
mark(memlevel);
for (fv = 1; fv <= 5; fv ++) {
blockread(f, cb, sizeof(cb));
for (bit = 2; bit <= 3; bit ++)
for (y = 0; y <= cb.yl; y ++)
blockread(f, ghost[fv][bit][y], cb.xl / 8);
}
get_me(eyes[0]); /* Get BGI-based ones */
get_me(eyes[1]);
get_me(exclamation);
plain_grab(); /* Grabs to screen (cobweb) */
plain_grab(); /* Grabs to screen (Mark's signature) */
plain_grab(); /* Grabs to screen (open door) */
for (fv = 1; fv <= 3; fv ++)
get_me(bat[fv]);
/* new(glerk);
for fv:=1 to 5 do { Grab the Glerk. }
begin;
blockread(f,cb,sizeof(cb));
for bit:=0 to 3 do
for y:=0 to 34 do
blockread(f,glerk^[fv,bit,y],cb.xl div 8);
inc(gd,gm);
end;
*/
glerk = new glerktype;
for (fv = 1; fv <= 6; fv ++) {
blockread(f, cb, sizeof(cb));
bit = 3;
for (bit = 0; bit <= 3; bit ++)
for (yy = 0; yy <= cb.yl; yy ++)
/* begin;
port[$3c4]:=2; port[$3ce]:=4;
port[$3C5]:=1 shl bit; port[$3CF]:=bit;*/
blockread(f, (*glerk)[fv][bit][yy], cb.xl / 8);
/* move(glerk^[fv,bit,yy],mem[$A000:yy*80+177],xl div 8);*/
/* blockread(f,mem[$A000:yy*80+177],xl div 8);*/
/* end;*/
}
for (fv = 1; fv <= 6; fv ++) get_me_aargh(fv);
for (fv = 1; fv <= 5; fv ++) get_me(green_eyes[fv]);
for (gb = false; gb <= true; gb ++)
for (fv = 1; fv <= 6; fv ++) get_me(greldet[fv][gb]);
close(f);
/* Avvy walks over... */
setfillstyle(1, 0);
glerkstage = 0;
bat_x = 277;
bat_y = 40;
bat_count = 0;
for (gd = 500; gd >= 217; gd --) {
if (set::of(range(22, 27), eos).has((gd % 30))) {
if ((gd % 30) == 27) bar(gd, 135, gd + 16, 136);
putimage(gd, 136, eyes[0], 0);
putpixel(gd + 16, 137, 0);
} else {
if (gd % 30 == 21) bar(gd, 137, gd + 17, 138);
putimage(gd, 135, eyes[0], 0);
putpixel(gd + 16, 136, 0); /* eyes would leave a trail 1 pixel high behind them */
}
/* Plot the Glerk: */
if (gd % 10 == 0) {
glerkstage += 1;
if (glerkstage > 26) flush();
for (gm = 0; gm <= 34; gm ++)
for (bit = 0; bit <= 3; bit ++) {
port[0x3c4] = 2;
port[0x3ce] = 4;
port[0x3c5] = 1 << bit;
port[0x3cf] = bit;
move((*glerk)[glerkfade[glerkstage]][bit][gm],
mem[0xa000 * 1177 + gm * 80], 9);
}
bit = getpixel(0, 0);
}
do_bat();
wait(15);
}
setfillstyle(1, 0);
bar(456, 14, 530, 50);
/* It descends... */
for (gm = -64; gm <= 103; gm ++) {
bit = getpixel(0, 0);
if (gm > 0)
fillchar(mem[0xa000 * (gm - 1) * 80], 26, '\0');
for (y = 0; y <= 65; y ++)
if ((y + gm) >= 0)
for (bit = 0; bit <= 3; bit ++) {
port[0x3c4] = 2;
port[0x3ce] = 4;
port[0x3c5] = 1 << bit;
port[0x3cf] = bit;
move(ghost[2 + (abs(gm / 7) % 2) * 3][plane_to_use[bit]][y],
mem[0xa000 * (y + gm) * 80], 26);
}
wait(27);
}
/* And waves... */
aargh_count = -14;
for (gd = 1; gd <= 4; gd ++)
for (fv = 1; fv <= 5; fv ++) {
y = getpixel(0, 0);
for (y = 0; y <= 7; y ++)
fillchar(mem[0xa000 * 7760 + y * 80], 26, '\0');
for (y = 0; y <= 65; y ++)
for (bit = 0; bit <= 3; bit ++) {
port[0x3c4] = 2;
port[0x3ce] = 4;
port[0x3c5] = 1 << bit;
port[0x3cf] = bit;
move(ghost[waveorder[fv]][plane_to_use[bit]][y],
mem[0xa000 * 7760 + (y + adjustment[fv]) * 80], 26);
}
aargh_count += 1;
if (aargh_count > 0) {
pointtype &with = aargh_where[aargh_count];
putimage(with.x, with.y, aargh[aargh_count], 0);
}
wait(177);
}
/* ! appears */
gd = getpixel(0, 0);
putimage(246, 127, exclamation, 0);
wait(777);
bar(172, 78, 347, 111); /* erase "aargh" */
for (gm = 5; gm >= 1; gm --) {
wait(377);
big_green_eyes(gm);
}
bar(246, 127, 251, 133); /* erase the "!" */
/* He hurries back. */
glerkstage = 1;
greldet_count = 18;
red_greldet = false;
for (gd = 217; gd <= 479; gd ++) {
if (set::of(range(22, 27), eos).has((gd % 30))) {
if ((gd % 30) == 22)
bar(gd + 22, 134, gd + 38, 137);
putimage(gd + 23, 136, eyes[1], 0);
putpixel(gd + 22, 137, 0);
} else {
if (gd % 30 == 28)
bar(gd + 22, 135, gd + 38, 138);
putimage(gd + 23, 135, eyes[1], 0);
putpixel(gd + 22, 136, 0); /* eyes would leave a trail 1 pixel high behind them */
}
/* Plot the Green Eyes: */
if (gd % 53 == 5) {
big_green_eyes(glerkstage);
glerkstage += 1;
}
/* Plot the Greldet: */
if (greldet_count == 18) {
/* A new greldet. */
greldet_x = Random(600);
greldet_y = Random(80);
greldet_count = 0;
red_greldet = ! red_greldet;
}
greldet_count += 1;
putimage
(greldet_x, greldet_y, greldet[greldetfade[greldet_count]][red_greldet], 0);
wait(10);
}
release(memlevel);
closegraph();
return EXIT_SUCCESS;
}
} // End of namespace Avalanche.
|