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
|
/* 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.
*/
namespace Avalanche {
struct joysetup {
word xmid, ymid, xmin, ymin, xmax, ymax;
byte centre; /* Size of centre in tenths */
};
const integer bug_twonames = 255;
const integer bug_pandl = 254;
const integer bug_weirdswitch = 253;
const integer bug_invalidini = 252;
const integer bug_notyesorno = 251;
const integer bug_weirdcard = 250;
byte fv;
char t;
string bugline;
boolean usingp, usingl;
boolean zoomy, numlockhold;
boolean doing_syntax;
joysetup js;
boolean use_joy_a;
boolean filename_specified;
boolean soundfx;
string inihead, initail; /* For reading the .INI file. */
string filetoload;
boolean cl_override, keyboardclick, demo;
string slopeline;
word storage_seg, storage_ofs;
string argon;
longint soundcard, baseaddr, speed, irq, dma;
string strf(longint x) {
string q;
string strf_result;
str(x, q);
strf_result = q;
return strf_result;
}
void linebug(byte which) {
output << "AVALOT : ";
switch (which) {
case bug_twonames :
output << "You may only specify ONE filename." << NL;
break;
case bug_pandl :
output << "/p and /l cannot be used together." << NL;
break;
case bug_weirdswitch :
output << "Unknown switch (\"" << bugline <<
"\"). Type AVALOT /? for a list of switches." << NL;
break;
case bug_invalidini:
output << "Invalid line in AVALOT.INI (\"" << bugline << "\")" << NL;
break;
case bug_notyesorno:
output << "Error in AVALOT.INI: \"" << inihead << "\" must be \"yes\" or \"no.\"" << NL;
break;
case bug_weirdcard:
output << "Unknown card: " << bugline << '.' << NL;
break;
}
exit(which);
}
longint card(string x) {
longint card_result;
if (x == "NONE") card_result = 0;
else if (x == "SB") card_result = 1;
else if (x == "SBPRO") card_result = 2;
else if (x == "SB16") card_result = 3;
else if (x == "PAS") card_result = 4;
else if (x == "PASPLUS") card_result = 5;
else if (x == "PAS16") card_result = 6;
else if (x == "ARIA") card_result = 7;
else if (x == "WINSOUND") card_result = 8;
else if (x == "GRAVIS") card_result = 9;
else if (x == "DACLPT") card_result = 10;
else if (x == "STEREODACS") card_result = 11;
else if (x == "STEREOON1") card_result = 12;
else if (x == "SPEAKER") card_result = 13;
else
linebug(bug_weirdcard);
return card_result;
}
void upstr(string &x) {
byte fv;
for (fv = 1; fv <= length(x); fv ++) x[fv] = upcase(x[fv]);
}
boolean yesno() {
boolean yesno_result;
if (initail == "YES") yesno_result = true;
else if (initail == "NO") yesno_result = false;
else
linebug(bug_notyesorno);
return yesno_result;
}
word value(string x) {
const varying_string<15> hexdigits = "0123456789ABCDEF";
word w;
integer e;
word value_result;
if (x[1] == '$') {
w = 0;
for (e = 2; e <= length(x); e ++) {
w = w << 4;
w += pos(upcase(x[e]), hexdigits) - 1;
}
value_result = w;
} else {
val(x, w, e);
if (e == 0) value_result = w;
else value_result = 0;
}
return value_result;
}
void ini_parse() {
upstr(inihead);
upstr(initail);
if (inihead == "QUIET") soundfx = ! yesno();
else if (inihead == "ZOOMYSTART") zoomy = yesno();
else if (inihead == "NUMLOCKHOLD") numlockhold = yesno();
else if (inihead == "LOADFIRST") filetoload = initail;
else if (inihead == "OVERRIDEEGACHECK") cl_override = yesno();
else if (inihead == "KEYBOARDCLICK") keyboardclick = yesno();
else if (inihead == "JOYTOP") js.ymin = value(initail);
else if (inihead == "JOYBOTTOM") js.ymax = value(initail);
else if (inihead == "JOYLEFT") js.xmin = value(initail);
else if (inihead == "JOYRIGHT") js.xmax = value(initail);
else if (inihead == "JOYMIDX") js.xmid = value(initail);
else if (inihead == "JOYMIDY") js.ymid = value(initail);
else if (inihead == "JOYCENTRINGFACTOR") js.centre = value(initail);
else if (inihead == "WHICHJOY") use_joy_a = value(initail) == 1;
else if (inihead == "SOUNDCARD") soundcard = card(initail);
else if (inihead == "BASEADDRESS") baseaddr = value(initail);
else if (inihead == "IRQ") irq = value(initail);
else if (inihead == "DMA") dma = value(initail);
else if (inihead == "SAMPLERATE") speed = value(initail);
}
void strip_ini() {
byte fv;
if (inihead == "") return;
/* Firstly, delete any comments. */
fv = pos(";", inihead);
if (fv > 0) Delete(inihead, fv, 255);
/* Lose the whitespace... */
while (inihead[length(inihead)] == ' ') inihead[0] -= 1;
while ((inihead != "") && (inihead[1] == ' ')) Delete(inihead, 1, 1);
/* It's possible that now we'll end up with a blank line. */
if ((inihead == "") || (inihead[1] == '[')) return;
fv = pos("=", inihead);
if (fv == 0) {
/* No "="! Weird! */
bugline = inihead;
linebug(bug_invalidini);
}
initail = copy(inihead, fv + 1, 255);
inihead[0] = chr(fv - 1);
}
void load_ini() {
text ini;
assign(ini, "AVALOT.INI");
reset(ini);
while (! eof(ini)) {
ini >> inihead >> NL;
strip_ini();
if (inihead != "") ini_parse();
}
close(ini);
}
void parse(string x);
static string arg;
static string getarg(string otherwis) {
string getarg_result;
if (arg == "") getarg_result = otherwis;
else getarg_result = arg;
return getarg_result;
}
void parse(string x)
{
switch (x[1]) {
case '/':
case '-': {
arg = copy(x, 3, 255);
switch (upcase(x[2])) {
case '?':
doing_syntax = true;
break;
case 'O':
cl_override = true;
break;
case 'L':
if (! usingp) {
usingl = true;
argon = getarg("avvy.log");
} else linebug(bug_pandl);
break;
case 'P':
if (! usingl) {
usingp = true;
argon = getarg("prn");
} else linebug(bug_pandl);
break;
case 'Q':
soundfx = false;
break;
case 'Z':
zoomy = true;
break;
case 'K':
keyboardclick = true;
break;
case 'D':
demo = true;
break;
default: {
bugline = x;
linebug(bug_weirdswitch);
}
}
}
break;
case '*': {
inihead = copy(x, 2, 255);
strip_ini();
if (inihead != "") ini_parse();
}
break;
default: { /* filename */
if (filename_specified)
linebug(bug_twonames);
else
filetoload = x;
filename_specified = true;
}
}
}
void make_slopeline();
static char yn1(boolean b) {
char yn1_result;
if (b) yn1_result = 'y';
else yn1_result = 'n';
return yn1_result;
}
static char pln() {
char pln_result;
if ((! usingp) && (! usingl)) pln_result = 'n';
else if (usingp) pln_result = 'p';
else if (usingl) pln_result = 'l';
return pln_result;
}
void make_slopeline()
{
if (argon == "") argon = "nul";
slopeline = string('1') + yn1(doing_syntax) + yn1(soundfx) + yn1(cl_override) +
yn1(keyboardclick) + pln() + yn1(demo) + yn1(zoomy) + yn1(numlockhold) +
yn1(use_joy_a) +
' ' + strf(js.xmid) +
' ' + strf(js.ymid) +
' ' + strf(js.xmin) +
' ' + strf(js.ymin) +
' ' + strf(js.xmax) +
' ' + strf(js.ymax) +
' ' + strf(js.centre) +
' ' + argon + ' ' + filetoload;
}
void store_slopeline() {
move(slopeline, mem[storage_seg * storage_ofs + 3], sizeof(slopeline));
move(js, mem[storage_seg * storage_ofs + 300], sizeof(js));
move(soundcard, mem[storage_seg * storage_ofs + 5000], 4);
move(baseaddr, mem[storage_seg * storage_ofs + 5004], 4);
move(irq, mem[storage_seg * storage_ofs + 5008], 4);
move(dma, mem[storage_seg * storage_ofs + 5012], 4);
move(speed, mem[storage_seg * storage_ofs + 5016], 4);
}
void get_storage_addr();
static void not_through_bootstrap() {
output << "Not standalone!" << NL;
exit(255);
}
void get_storage_addr() {
integer e;
if (paramstr(1) != "jsb") not_through_bootstrap();
val(paramstr(2), storage_seg, e);
if (e != 0) not_through_bootstrap();
val(paramstr(3), storage_ofs, e);
if (e != 0) not_through_bootstrap();
}
int main(int argc, const char *argv[]) {
pio_initialize(argc, argv);
get_storage_addr();
filetoload = "";
argon = "";
usingl = false;
usingp = false;
cl_override = false;
soundfx = true;
zoomy = false;
numlockhold = false;
filename_specified = false;
keyboardclick = false;
doing_syntax = false;
soundcard = 0;
baseaddr = 0;
irq = 0;
dma = 0;
load_ini();
for (fv = 4; fv <= paramcount; fv ++)
parse(paramstr(fv));
make_slopeline();
store_slopeline();
return EXIT_SUCCESS;
}
} // End of namespace Avalanche.
|