OpenCores
URL https://opencores.org/ocsvn/ion/ion/trunk

Subversion Repositories ion

[/] [ion/] [trunk/] [src/] [adventure/] [misc.c] - Blame information for rev 237

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 90 ja_rd
#include "main.h"
2
#include "misc.h"
3
#include <stdio.h>
4
 
5
#include "adv_baremetal.h"
6
 
7
#define TRUE  (0==0)
8
#define FALSE (0!=0)
9
 
10
/*  I/O ROUTINES (SPEAK, PSPEAK, RSPEAK, SETPRM, GETIN, YES) */
11
 
12
#undef SPEAK
13
void fSPEAK(N)long N; {
14
long BLANK, CASE, I, K, L, NEG, NPARMS, PARM, PRMTYP, STATE;
15
 
16
/*  PRINT THE MESSAGE WHICH STARTS AT LINES(N).  PRECEDE IT WITH A BLANK LINE
17
 *  UNLESS BLKLIN IS FALSE. */
18
 
19
 
20
        if(N == 0)return;
21
        BLANK=BLKLIN;
22
        K=N;
23
        NPARMS=1;
24
L10:    L=IABS(LINES[K])-1;
25
        K=K+1;
26
        LNLENG=0;
27
        LNPOSN=1;
28
        STATE=0;
29
        /* 20 */ for (I=K; I<=L; I++) {
30
L20:    PUTTXT(LINES[I],STATE,2,I);
31
        } /* end loop */
32
        LNPOSN=0;
33
L30:    LNPOSN=LNPOSN+1;
34
L32:    if(LNPOSN > LNLENG) goto L40;
35
        if(INLINE[LNPOSN] != 63) goto L30;
36
        {long x = LNPOSN+1; PRMTYP=INLINE[x];}
37
/*  63 IS A "%"; THE NEXT CHARACTER DETERMINE THE TYPE OF PARAMETER:  1 (!) =
38
 *  SUPPRESS MESSAGE COMPLETELY, 29 (S) = NULL IF PARM=1, ELSE 'S' (OPTIONAL
39
 *  PLURAL ENDING), 33 (W) = WORD (TWO 30-BIT VALUES) WITH TRAILING SPACES
40
 *  SUPPRESSED, 22 (L) OR 31 (U) = WORD BUT MAP TO LOWER/UPPER CASE, 13 (C) =
41
 *  WORD IN LOWER CASE WITH FIRST LETTER CAPITALISED, 30 (T) = TEXT ENDING
42
 *  WITH A WORD OF -1, 65-73 (1-9) = NUMBER USING THAT MANY CHARACTERS,
43
 *  12 (B) = VARIABLE NUMBER OF BLANKS. */
44
        if(PRMTYP == 1)return;
45
        if(PRMTYP == 29) goto L320;
46
        if(PRMTYP == 30) goto L340;
47
        if(PRMTYP == 12) goto L360;
48
        if(PRMTYP == 33 || PRMTYP == 22 || PRMTYP == 31 || PRMTYP == 13) goto
49
                L380;
50
        PRMTYP=PRMTYP-64;
51
        if(PRMTYP < 1 || PRMTYP > 9) goto L30;
52
        SHFTXT(LNPOSN+2,PRMTYP-2);
53
        LNPOSN=LNPOSN+PRMTYP;
54
        PARM=IABS(PARMS[NPARMS]);
55
        NEG=0;
56
        if(PARMS[NPARMS] < 0)NEG=9;
57
        /* 390 */ for (I=1; I<=PRMTYP; I++) {
58
        LNPOSN=LNPOSN-1;
59
        INLINE[LNPOSN]=MOD(PARM,10)+64;
60
        if(I == 1 || PARM != 0) goto L390;
61
        INLINE[LNPOSN]=NEG;
62
        NEG=0;
63
L390:   PARM=PARM/10;
64
        } /* end loop */
65
        LNPOSN=LNPOSN+PRMTYP;
66
L395:   NPARMS=NPARMS+1;
67
         goto L32;
68
 
69
L320:   SHFTXT(LNPOSN+2,-1);
70
        INLINE[LNPOSN]=55;
71
        if(PARMS[NPARMS] == 1)SHFTXT(LNPOSN+1,-1);
72
         goto L395;
73
 
74
L340:   SHFTXT(LNPOSN+2,-2);
75
        STATE=0;
76
        CASE=2;
77
L345:   if(PARMS[NPARMS] < 0) goto L395;
78
        {long x = NPARMS+1; if(PARMS[x] < 0)CASE=0;}
79
        PUTTXT(PARMS[NPARMS],STATE,CASE,0);
80
        NPARMS=NPARMS+1;
81
         goto L345;
82
 
83
L360:   PRMTYP=PARMS[NPARMS];
84
        SHFTXT(LNPOSN+2,PRMTYP-2);
85
        if(PRMTYP == 0) goto L395;
86
        /* 365 */ for (I=1; I<=PRMTYP; I++) {
87
        INLINE[LNPOSN]=0;
88
L365:   LNPOSN=LNPOSN+1;
89
        } /* end loop */
90
         goto L395;
91
 
92
L380:   SHFTXT(LNPOSN+2,-2);
93
        STATE=0;
94
        CASE= -1;
95
        if(PRMTYP == 31)CASE=1;
96
        if(PRMTYP == 33)CASE=0;
97
        I=LNPOSN;
98
        PUTTXT(PARMS[NPARMS],STATE,CASE,0);
99
        {long x = NPARMS+1; PUTTXT(PARMS[x],STATE,CASE,0);}
100
        if(PRMTYP == 13 && INLINE[I] >= 37 && INLINE[I] <=
101
                62)INLINE[I]=INLINE[I]-26;
102
        NPARMS=NPARMS+2;
103
         goto L32;
104
 
105
L40:    if(BLANK)TYPE0();
106
        BLANK=FALSE;
107
        TYPE();
108
        K=L+1;
109
        if(LINES[K] >= 0) goto L10;
110
        return;
111
}
112
 
113
 
114
 
115
#define SPEAK(N) fSPEAK(N)
116
#undef PSPEAK
117
void fPSPEAK(MSG,SKIP)long MSG, SKIP; {
118
long I, M;
119
 
120
/*  FIND THE SKIP+1ST MESSAGE FROM MSG AND PRINT IT.  MSG SHOULD BE THE INDEX OF
121
 *  THE INVENTORY MESSAGE FOR OBJECT.  (INVEN+N+1 MESSAGE IS PROP=N MESSAGE). */
122
 
123
 
124
        M=PTEXT[MSG];
125
        if(SKIP < 0) goto L9;
126
        /* 3 */ for (I=0; I<=SKIP; I++) {
127
L1:     M=IABS(LINES[M]);
128
        if(LINES[M] >= 0) goto L1;
129
L3:     /*etc*/ ;
130
        } /* end loop */
131
L9:     SPEAK(M);
132
        return;
133
}
134
 
135
 
136
 
137
#define PSPEAK(MSG,SKIP) fPSPEAK(MSG,SKIP)
138
#undef RSPEAK
139
void fRSPEAK(I)long I; {
140
;
141
 
142
/*  PRINT THE I-TH "RANDOM" MESSAGE (SECTION 6 OF DATABASE). */
143
 
144
 
145
        if(I != 0)SPEAK(RTEXT[I]);
146
        return;
147
}
148
 
149
 
150
 
151
#define RSPEAK(I) fRSPEAK(I)
152
#undef SETPRM
153
void fSETPRM(FIRST,P1,P2)long FIRST, P1, P2; {
154
;
155
 
156
/*  STORES PARAMETERS INTO THE PRMCOM PARMS ARRAY FOR USE BY SPEAK.  P1 AND P2
157
 *  ARE STORED INTO PARMS(FIRST) AND PARMS(FIRST+1). */
158
 
159
 
160
        if(FIRST >= 25)BUG(29);
161
        PARMS[FIRST]=P1;
162
        {long x = FIRST+1; PARMS[x]=P2;}
163
        return;
164
}
165
 
166
 
167
 
168
#define SETPRM(FIRST,P1,P2) fSETPRM(FIRST,P1,P2)
169
#undef GETIN
170
#define WORD1 (*wORD1)
171
#define WORD1X (*wORD1X)
172
#define WORD2 (*wORD2)
173
#define WORD2X (*wORD2X)
174
void fGETIN(wORD1,wORD1X,wORD2,wORD2X)long *wORD1, *wORD1X, *wORD2, *wORD2X; {
175
long JUNK;
176
 
177
/*  GET A COMMAND FROM THE ADVENTURER.  SNARF OUT THE FIRST WORD, PAD IT WITH
178
 *  BLANKS, AND RETURN IT IN WORD1.  CHARS 6 THRU 10 ARE RETURNED IN WORD1X, IN
179
 *  CASE WE NEED TO PRINT OUT THE WHOLE WORD IN AN ERROR MESSAGE.  ANY NUMBER OF
180
 *  BLANKS MAY FOLLOW THE WORD.  IF A SECOND WORD APPEARS, IT IS RETURNED IN
181
 *  WORD2 (CHARS 6 THRU 10 IN WORD2X), ELSE WORD2 IS -1. */
182
 
183
 
184
L10:    if(BLKLIN)TYPE0();
185
        MAPLIN(FALSE);
186
        WORD1=GETTXT(TRUE,TRUE,TRUE,0);
187
        if(BLKLIN && WORD1 < 0) goto L10;
188
        WORD1X=GETTXT(FALSE,TRUE,TRUE,0);
189
L12:    JUNK=GETTXT(FALSE,TRUE,TRUE,0);
190
        if(JUNK > 0) goto L12;
191
        WORD2=GETTXT(TRUE,TRUE,TRUE,0);
192
        WORD2X=GETTXT(FALSE,TRUE,TRUE,0);
193
L22:    JUNK=GETTXT(FALSE,TRUE,TRUE,0);
194
        if(JUNK > 0) goto L22;
195
        if(GETTXT(TRUE,TRUE,TRUE,0) <= 0)return;
196
        RSPEAK(53);
197
         goto L10;
198
}
199
 
200
 
201
 
202
#undef WORD1
203
#undef WORD1X
204
#undef WORD2
205
#undef WORD2X
206
#define GETIN(WORD1,WORD1X,WORD2,WORD2X) fGETIN(&WORD1,&WORD1X,&WORD2,&WORD2X)
207
#undef YES
208
long fYES(X,Y,Z)long X, Y, Z; {
209
 
210
long YES, REPLY, JUNK1, JUNK2, JUNK3;
211
 
212
/*  PRINT MESSAGE X, WAIT FOR YES/NO ANSWER.  IF YES, PRINT Y AND RETURN TRUE;
213
 *  IF NO, PRINT Z AND RETURN FALSE. */
214
 
215
L1:     RSPEAK(X);
216
        GETIN(REPLY,JUNK1,JUNK2,JUNK3);
217
        if(REPLY == MAKEWD(250519) || REPLY == MAKEWD(25)) goto L10;
218
        if(REPLY == MAKEWD(1415) || REPLY == MAKEWD(14)) goto L20;
219
        RSPEAK(185);
220
         goto L1;
221
L10:    YES=TRUE;
222
        RSPEAK(Y);
223
        return(YES);
224
L20:    YES=FALSE;
225
        RSPEAK(Z);
226
        return(YES);
227
}
228
 
229
 
230
 
231
 
232
 
233
/*  LINE-PARSING ROUTINES (GETNUM, GETTXT, MAKEWD, PUTTXT, SHFTXT, TYPE0)
234
                */
235
 
236
/*  THE ROUTINES ON THIS PAGE HANDLE ALL THE STUFF THAT WOULD NORMALLY BE
237
 *  TAKEN CARE OF BY FORMAT STATEMENTS.  WE DO IT THIS WAY INSTEAD SO THAT
238
 *  WE CAN HANDLE TEXTUAL DATA IN A MACHINE INDEPENDENT FASHION.  ALL THE
239
 *  MACHINE DEPENDENT I/O STUFF IS ON THE FOLLOWING PAGE.  SEE THAT PAGE
240
 *  FOR A DESCRIPTION OF MAPCOM'S INLINE ARRAY. */
241
 
242
#define YES(X,Y,Z) fYES(X,Y,Z)
243
#undef GETNUM
244
long fGETNUM(K)long K; {
245
long DIGIT, GETNUM, SIGN;
246
 
247
/*  OBTAIN THE NEXT INTEGER FROM AN INPUT LINE.  IF K>0, WE FIRST READ A
248
 *  NEW INPUT LINE FROM A FILE; IF K<0, WE READ A LINE FROM THE KEYBOARD;
249
 *  IF K=0 WE USE A LINE THAT HAS ALREADY BEEN READ (AND PERHAPS PARTIALLY
250
 *  SCANNED).  IF WE'RE AT THE END OF THE LINE OR ENCOUNTER AN ILLEGAL
251
 *  CHARACTER (NOT A DIGIT, HYPHEN, OR BLANK), WE RETURN 0. */
252
 
253
 
254
        if(K != 0)MAPLIN(K > 0);
255
        GETNUM=0;
256
L10:    if(LNPOSN > LNLENG)return(GETNUM);
257
        if(INLINE[LNPOSN] != 0) goto L20;
258
        LNPOSN=LNPOSN+1;
259
         goto L10;
260
 
261
L20:    SIGN=1;
262
        if(INLINE[LNPOSN] != 9) goto L32;
263
        SIGN= -1;
264
L30:    LNPOSN=LNPOSN+1;
265
L32:    if(LNPOSN > LNLENG || INLINE[LNPOSN] == 0) goto L42;
266
        DIGIT=INLINE[LNPOSN]-64;
267
        if(DIGIT < 0 || DIGIT > 9) goto L40;
268
        GETNUM=GETNUM*10+DIGIT;
269
         goto L30;
270
 
271
L40:    GETNUM=0;
272
L42:    GETNUM=GETNUM*SIGN;
273
        LNPOSN=LNPOSN+1;
274
        return(GETNUM);
275
}
276
 
277
 
278
 
279
#define GETNUM(K) fGETNUM(K)
280
#undef GETTXT
281
long fGETTXT(SKIP,ONEWRD,UPPER,HASH)long HASH, ONEWRD, SKIP, UPPER; {
282
long CHAR, GETTXT, I; static long SPLITTING = -1;
283
 
284
/*  TAKE CHARACTERS FROM AN INPUT LINE AND PACK THEM INTO 30-BIT WORDS.
285
 *  SKIP SAYS TO SKIP LEADING BLANKS.  ONEWRD SAYS STOP IF WE COME TO A
286
 *  BLANK.  UPPER SAYS TO MAP ALL LETTERS TO UPPERCASE.  HASH MAY BE USED
287
 *  AS A PARAMETER FOR ENCRYPTING THE TEXT IF DESIRED; HOWEVER, A HASH OF 0
288
 *  SHOULD RESULT IN UNMODIFIED BYTES BEING PACKED.  IF WE REACH THE
289
 *  END OF THE LINE, THE WORD IS FILLED UP WITH BLANKS (WHICH ENCODE AS 0'S).
290
 *  IF WE'RE ALREADY AT END OF LINE WHEN GETTXT IS CALLED, WE RETURN -1. */
291
 
292
        if(LNPOSN != SPLITTING)SPLITTING = -1;
293
        GETTXT= -1;
294
L10:    if(LNPOSN > LNLENG)return(GETTXT);
295
        if((!SKIP) || INLINE[LNPOSN] != 0) goto L11;
296
        LNPOSN=LNPOSN+1;
297
         goto L10;
298
 
299
L11:    GETTXT=0;
300
        /* 15 */ for (I=1; I<=5; I++) {
301
        GETTXT=GETTXT*64;
302
        if(LNPOSN > LNLENG || (ONEWRD && INLINE[LNPOSN] == 0)) goto L15;
303
        CHAR=INLINE[LNPOSN];
304
        if(CHAR >= 63) goto L12;
305
        SPLITTING = -1;
306
        if(UPPER && CHAR >= 37)CHAR=CHAR-26;
307
        GETTXT=GETTXT+CHAR;
308
         goto L14;
309
 
310
L12:    if(SPLITTING == LNPOSN) goto L13;
311
        GETTXT=GETTXT+63;
312
        SPLITTING = LNPOSN;
313
         goto L15;
314
 
315
L13:    GETTXT=GETTXT+CHAR-63;
316
        SPLITTING = -1;
317
L14:    LNPOSN=LNPOSN+1;
318
L15:    /*etc*/ ;
319
        } /* end loop */
320
 
321
        if(HASH)GETTXT=GETTXT+MOD(HASH*13579L+5432L,97531L)*12345L+HASH;
322
        return(GETTXT);
323
}
324
 
325
 
326
 
327
#define GETTXT(SKIP,ONEWRD,UPPER,HASH) fGETTXT(SKIP,ONEWRD,UPPER,HASH)
328
#undef MAKEWD
329
long fMAKEWD(LETTRS)long LETTRS; {
330
long I, L, MAKEWD;
331
 
332
/*  COMBINE FIVE UPPERCASE LETTERS (REPRESENTED BY PAIRS OF DECIMAL DIGITS
333
 *  IN LETTRS) TO FORM A 30-BIT VALUE MATCHING THE ONE THAT GETTXT WOULD
334
 *  RETURN GIVEN THOSE CHARACTERS PLUS TRAILING BLANKS AND HASH=0.  CAUTION:
335
 *  LETTRS WILL OVERFLOW 31 BITS IF 5-LETTER WORD STARTS WITH V-Z.  AS A
336
 *  KLUDGEY WORKAROUND, YOU CAN INCREMENT A LETTER BY 5 BY ADDING 50 TO
337
 *  THE NEXT PAIR OF DIGITS. */
338
 
339
 
340
        MAKEWD=0;
341
        I=1;
342
        L=LETTRS;
343
L10:    MAKEWD=MAKEWD+I*(MOD(L,50)+10);
344
        I=I*64;
345
        if(MOD(L,100) > 50)MAKEWD=MAKEWD+I*5;
346
        L=L/100;
347
        if(L != 0) goto L10;
348
        I=64L*64L*64L*64L*64L/I;
349
        MAKEWD=MAKEWD*I;
350
        return(MAKEWD);
351
}
352
 
353
 
354
 
355
#define MAKEWD(LETTRS) fMAKEWD(LETTRS)
356
#undef PUTTXT
357
#define STATE (*sTATE)
358
void fPUTTXT(WORD,sTATE,CASE,HASH)long CASE, HASH, *sTATE, WORD; {
359
long ALPH1, ALPH2, BYTE, DIV, I, W;
360
 
361
/*  UNPACK THE 30-BIT VALUE IN WORD TO OBTAIN UP TO 5 INTEGER-ENCODED CHARS,
362
 *  AND STORE THEM IN INLINE STARTING AT LNPOSN.  IF LNLENG>=LNPOSN, SHIFT
363
 *  EXISTING CHARACTERS TO THE RIGHT TO MAKE ROOM.  HASH MUST BE THE SAME
364
 *  AS IT WAS WHEN GETTXT CREATED THE 30-BIT WORD.  STATE WILL BE ZERO WHEN
365
 *  PUTTXT IS CALLED WITH THE FIRST OF A SEQUENCE OF WORDS, BUT IS THEREAFTER
366
 *  UNCHANGED BY THE CALLER, SO PUTTXT CAN USE IT TO MAINTAIN STATE ACROSS
367
 *  CALLS.  LNPOSN AND LNLENG ARE INCREMENTED BY THE NUMBER OF CHARS STORED.
368
 *  IF CASE=1, ALL LETTERS ARE MADE UPPERCASE; IF -1, LOWERCASE; IF 0, AS IS.
369
 *  ANY OTHER VALUE FOR CASE IS THE SAME AS 0 BUT ALSO CAUSES TRAILING BLANKS
370
 *  TO BE INCLUDED (IN ANTICIPATION OF SUBSEQUENT ADDITIONAL TEXT). */
371
 
372
 
373
        ALPH1=13*CASE+24;
374
        ALPH2=26*IABS(CASE)+ALPH1;
375
        if(IABS(CASE) > 1)ALPH1=ALPH2;
376
/*  ALPH1&2 DEFINE RANGE OF WRONG-CASE CHARS, 11-36 OR 37-62 OR EMPTY. */
377
        DIV=64L*64L*64L*64L;
378
        W=WORD;
379
        if(HASH)W=W-MOD(HASH*13579L+5432L,97531L)*12345L-HASH;
380
        /* 18 */ for (I=1; I<=5; I++) {
381
        if(W <= 0 && STATE == 0 && IABS(CASE) <= 1)return;
382
        BYTE=W/DIV;
383
        if(STATE != 0 || BYTE != 63) goto L12;
384
        STATE=63;
385
         goto L18;
386
 
387
L12:    SHFTXT(LNPOSN,1);
388
        STATE=STATE+BYTE;
389
        if(STATE < ALPH2 && STATE >= ALPH1)STATE=STATE-26*CASE;
390
        INLINE[LNPOSN]=STATE;
391
        LNPOSN=LNPOSN+1;
392
        STATE=0;
393
L18:    W=(W-BYTE*DIV)*64;
394
        } /* end loop */
395
        return;
396
}
397
 
398
 
399
 
400
#undef STATE
401
#define PUTTXT(WORD,STATE,CASE,HASH) fPUTTXT(WORD,&STATE,CASE,HASH)
402
#undef SHFTXT
403
void fSHFTXT(FROM,DELTA)long DELTA, FROM; {
404
long I, II, JJ;
405
 
406
/*  MOVE INLINE(N) TO INLINE(N+DELTA) FOR N=FROM,LNLENG.  DELTA CAN BE
407
 *  NEGATIVE.  LNLENG IS UPDATED; LNPOSN IS NOT CHANGED. */
408
 
409
 
410
        if(LNLENG < FROM || DELTA == 0) goto L2;
411
        /* 1 */ for (I=FROM; I<=LNLENG; I++) {
412
        II=I;
413
        if(DELTA > 0)II=FROM+LNLENG-I;
414
        JJ=II+DELTA;
415
L1:     INLINE[JJ]=INLINE[II];
416
        } /* end loop */
417
L2:     LNLENG=LNLENG+DELTA;
418
        return;
419
}
420
 
421
 
422
 
423
#define SHFTXT(FROM,DELTA) fSHFTXT(FROM,DELTA)
424
#undef TYPE0
425
void fTYPE0() {
426
long TEMP;
427
 
428
/*  TYPE A BLANK LINE.  THIS PROCEDURE IS PROVIDED AS A CONVENIENCE FOR CALLERS
429
 *  WHO OTHERWISE HAVE NO USE FOR MAPCOM. */
430
 
431
 
432
        TEMP=LNLENG;
433
        LNLENG=0;
434
        TYPE();
435
        LNLENG=TEMP;
436
        return;
437
}
438
 
439
 
440
 
441
#define TYPE0() fTYPE0()
442
 
443
 
444
/*  SUSPEND/RESUME I/O ROUTINES (SAVWDS, SAVARR, SAVWRD) */
445
 
446
#undef SAVWDS
447
void fSAVWDS(W1,W2,W3,W4,W5,W6,W7)long *W1, *W2, *W3, *W4, *W5, *W6, *W7; {
448
;
449
 
450
/*  WRITE OR READ 7 VARIABLES.  SEE SAVWRD. */
451
 
452
 
453
        SAVWRD(0,(*W1));
454
        SAVWRD(0,(*W2));
455
        SAVWRD(0,(*W3));
456
        SAVWRD(0,(*W4));
457
        SAVWRD(0,(*W5));
458
        SAVWRD(0,(*W6));
459
        SAVWRD(0,(*W7));
460
        return;
461
}
462
 
463
 
464
#define SAVWDS(W1,W2,W3,W4,W5,W6,W7) fSAVWDS(&W1,&W2,&W3,&W4,&W5,&W6,&W7)
465
#undef SAVARR
466
void fSAVARR(ARR,N)long ARR[], N; {
467
long I;
468
 
469
/*  WRITE OR READ AN ARRAY OF N WORDS.  SEE SAVWRD. */
470
 
471
 
472
        /* 1 */ for (I=1; I<=N; I++) {
473
L1:     SAVWRD(0,ARR[I]);
474
        } /* end loop */
475
        return;
476
}
477
 
478
 
479
 
480
#define SAVARR(ARR,N) fSAVARR(ARR,N)
481
#undef SAVWRD
482
#define WORD (*wORD)
483
void fSAVWRD(OP,wORD)long OP, *wORD; {
484
static long BUF[250], CKSUM = 0, H1, HASH = 0, N = 0, STATE = 0;
485
 
486
/*  IF OP<0, START WRITING A FILE, USING WORD TO INITIALISE ENCRYPTION; SAVE
487
 *  WORD IN THE FILE.  IF OP>0, START READING A FILE; READ THE FILE TO FIND
488
 *  THE VALUE WITH WHICH TO DECRYPT THE REST.  IN EITHER CASE, IF A FILE IS
489
 *  ALREADY OPEN, FINISH WRITING/READING IT AND DON'T START A NEW ONE.  IF OP=0,
490
 *  READ/WRITE A SINGLE WORD.  WORDS ARE BUFFERED IN CASE THAT MAKES FOR MORE
491
 *  EFFICIENT DISK USE.  WE ALSO COMPUTE A SIMPLE CHECKSUM TO CATCH ELEMENTARY
492
 *  POKING WITHIN THE SAVED FILE.  WHEN WE FINISH READING/WRITING THE FILE,
493
 *  WE STORE ZERO INTO WORD IF THERE'S NO CHECKSUM ERROR, ELSE NONZERO. */
494
 
495
 
496
        if(OP != 0){long ifvar; ifvar=(STATE); switch (ifvar<0? -1 : ifvar>0? 1 :
497
                0) { case -1: goto L30; case 0: goto L10; case 1: goto L30; }}
498
        if(STATE == 0)return;
499
        if(N == 250)SAVEIO(1,STATE > 0,BUF);
500
        N=MOD(N,250)+1;
501
        H1=MOD(HASH*1093L+221573L,1048576L);
502
        HASH=MOD(H1*1093L+221573L,1048576L);
503
        H1=MOD(H1,1234)*765432+MOD(HASH,123);
504
        N--;
505
        if(STATE > 0)WORD=BUF[N]+H1;
506
        BUF[N]=WORD-H1;
507
        N++;
508
        CKSUM=MOD(CKSUM*13+WORD,1000000000L);
509
        return;
510
 
511
L10:    STATE=OP;
512
        SAVEIO(0,STATE > 0,BUF);
513
        N=1;
514
        if(STATE > 0) goto L15;
515
        HASH=MOD(WORD,1048576L);
516
        BUF[0]=1234L*5678L-HASH;
517
L13:    CKSUM=BUF[0];
518
        return;
519
 
520
L15:    SAVEIO(1,TRUE,BUF);
521
        HASH=MOD(1234L*5678L-BUF[0],1048576L);
522
         goto L13;
523
 
524
L30:    if(N == 250)SAVEIO(1,STATE > 0,BUF);
525
        N=MOD(N,250)+1;
526
        if(STATE > 0) goto L32;
527
        N--; BUF[N]=CKSUM; N++;
528
        SAVEIO(1,FALSE,BUF);
529
L32:    N--; WORD=BUF[N]-CKSUM; N++;
530
        SAVEIO(-1,STATE > 0,BUF);
531
        STATE=0;
532
        return;
533
}
534
 
535
 
536
 
537
 
538
 
539
/*  DATA STRUC. ROUTINES (VOCAB, DSTROY, JUGGLE, MOVE, PUT, CARRY, DROP, ATDWRF)
540
                */
541
 
542
#undef WORD
543
#define SAVWRD(OP,WORD) fSAVWRD(OP,&WORD)
544
#undef VOCAB
545
long fVOCAB(ID,INIT)long ID, INIT; {
546
long HASH, I, VOCAB;
547
 
548
/*  LOOK UP ID IN THE VOCABULARY (ATAB) AND RETURN ITS "DEFINITION" (KTAB), OR
549
 *  -1 IF NOT FOUND.  IF INIT IS POSITIVE, THIS IS AN INITIALISATION CALL SETTING
550
 *  UP A KEYWORD VARIABLE, AND NOT FINDING IT CONSTITUTES A BUG.  IT ALSO MEANS
551
 *  THAT ONLY KTAB VALUES WHICH TAKEN OVER 1000 EQUAL INIT MAY BE CONSIDERED.
552
 *  (THUS "STEPS", WHICH IS A MOTION VERB AS WELL AS AN OBJECT, MAY BE LOCATED
553
 *  AS AN OBJECT.)  AND IT ALSO MEANS THE KTAB VALUE IS TAKEN MOD 1000. */
554
 
555
        HASH=10000;
556
        /* 1 */ for (I=1; I<=TABSIZ; I++) {
557
        if(KTAB[I] == -1) goto L2;
558
        HASH=HASH+7;
559
        if(INIT >= 0 && KTAB[I]/1000 != INIT) goto L1;
560
        if(ATAB[I] == ID+HASH*HASH) goto L3;
561
L1:     /*etc*/ ;
562
        } /* end loop */
563
        BUG(21);
564
 
565
L2:     VOCAB= -1;
566
        if(INIT < 0)return(VOCAB);
567
        BUG(5);
568
 
569
L3:     VOCAB=KTAB[I];
570
        if(INIT >= 0)VOCAB=MOD(VOCAB,1000);
571
        return(VOCAB);
572
}
573
 
574
 
575
 
576
#define VOCAB(ID,INIT) fVOCAB(ID,INIT)
577
#undef DSTROY
578
void fDSTROY(OBJECT)long OBJECT; {
579
;
580
 
581
/*  PERMANENTLY ELIMINATE "OBJECT" BY MOVING TO A NON-EXISTENT LOCATION. */
582
 
583
 
584
        MOVE(OBJECT,0);
585
        return;
586
}
587
 
588
 
589
 
590
#define DSTROY(OBJECT) fDSTROY(OBJECT)
591
#undef JUGGLE
592
void fJUGGLE(OBJECT)long OBJECT; {
593
long I, J;
594
 
595
/*  JUGGLE AN OBJECT BY PICKING IT UP AND PUTTING IT DOWN AGAIN, THE PURPOSE
596
 *  BEING TO GET THE OBJECT TO THE FRONT OF THE CHAIN OF THINGS AT ITS LOC. */
597
 
598
 
599
        I=PLACE[OBJECT];
600
        J=FIXED[OBJECT];
601
        MOVE(OBJECT,I);
602
        MOVE(OBJECT+100,J);
603
        return;
604
}
605
 
606
 
607
 
608
#define JUGGLE(OBJECT) fJUGGLE(OBJECT)
609
#undef MOVE
610
void fMOVE(OBJECT,WHERE)long OBJECT, WHERE; {
611
long FROM;
612
 
613
/*  PLACE ANY OBJECT ANYWHERE BY PICKING IT UP AND DROPPING IT.  MAY ALREADY BE
614
 *  TOTING, IN WHICH CASE THE CARRY IS A NO-OP.  MUSTN'T PICK UP OBJECTS WHICH
615
 *  ARE NOT AT ANY LOC, SINCE CARRY WANTS TO REMOVE OBJECTS FROM ATLOC CHAINS. */
616
 
617
 
618
        if(OBJECT > 100) goto L1;
619
        FROM=PLACE[OBJECT];
620
         goto L2;
621
L1:     {long x = OBJECT-100; FROM=FIXED[x];}
622
L2:     if(FROM > 0 && FROM <= 300)CARRY(OBJECT,FROM);
623
        DROP(OBJECT,WHERE);
624
        return;
625
}
626
 
627
 
628
 
629
#define MOVE(OBJECT,WHERE) fMOVE(OBJECT,WHERE)
630
#undef PUT
631
long fPUT(OBJECT,WHERE,PVAL)long OBJECT, PVAL, WHERE; {
632
long PUT;
633
 
634
/*  PUT IS THE SAME AS MOVE, EXCEPT IT RETURNS A VALUE USED TO SET UP THE
635
 *  NEGATED PROP VALUES FOR THE REPOSITORY OBJECTS. */
636
 
637
 
638
        MOVE(OBJECT,WHERE);
639
        PUT=(-1)-PVAL;
640
        return(PUT);
641
}
642
 
643
 
644
 
645
#define PUT(OBJECT,WHERE,PVAL) fPUT(OBJECT,WHERE,PVAL)
646
#undef CARRY
647
void fCARRY(OBJECT,WHERE)long OBJECT, WHERE; {
648
long TEMP;
649
 
650
/*  START TOTING AN OBJECT, REMOVING IT FROM THE LIST OF THINGS AT ITS FORMER
651
 *  LOCATION.  INCR HOLDNG UNLESS IT WAS ALREADY BEING TOTED.  IF OBJECT>100
652
 *  (MOVING "FIXED" SECOND LOC), DON'T CHANGE PLACE OR HOLDNG. */
653
 
654
 
655
        if(OBJECT > 100) goto L5;
656
        if(PLACE[OBJECT] == -1)return;
657
        PLACE[OBJECT]= -1;
658
        HOLDNG=HOLDNG+1;
659
L5:     if(ATLOC[WHERE] != OBJECT) goto L6;
660
        ATLOC[WHERE]=LINK[OBJECT];
661
        return;
662
L6:     TEMP=ATLOC[WHERE];
663
L7:     if(LINK[TEMP] == OBJECT) goto L8;
664
        TEMP=LINK[TEMP];
665
         goto L7;
666
L8:     LINK[TEMP]=LINK[OBJECT];
667
        return;
668
}
669
 
670
 
671
 
672
#define CARRY(OBJECT,WHERE) fCARRY(OBJECT,WHERE)
673
#undef DROP
674
void fDROP(OBJECT,WHERE)long OBJECT, WHERE; {
675
;
676
 
677
/*  PLACE AN OBJECT AT A GIVEN LOC, PREFIXING IT ONTO THE ATLOC LIST.  DECR
678
 *  HOLDNG IF THE OBJECT WAS BEING TOTED. */
679
 
680
 
681
        if(OBJECT > 100) goto L1;
682
        if(PLACE[OBJECT] == -1)HOLDNG=HOLDNG-1;
683
        PLACE[OBJECT]=WHERE;
684
         goto L2;
685
L1:     {long x = OBJECT-100; FIXED[x]=WHERE;}
686
L2:     if(WHERE <= 0)return;
687
        LINK[OBJECT]=ATLOC[WHERE];
688
        ATLOC[WHERE]=OBJECT;
689
        return;
690
}
691
 
692
 
693
 
694
#define DROP(OBJECT,WHERE) fDROP(OBJECT,WHERE)
695
#undef ATDWRF
696
long fATDWRF(WHERE)long WHERE; {
697
long ATDWRF, I;
698
 
699
/*  RETURN THE INDEX OF FIRST DWARF AT THE GIVEN LOCATION, ZERO IF NO DWARF IS
700
 *  THERE (OR IF DWARVES NOT ACTIVE YET), -1 IF ALL DWARVES ARE DEAD.  IGNORE
701
 *  THE PIRATE (6TH DWARF). */
702
 
703
 
704
        ATDWRF=0;
705
        if(DFLAG < 2)return(ATDWRF);
706
        ATDWRF= -1;
707
        /* 1 */ for (I=1; I<=5; I++) {
708
        if(DLOC[I] == WHERE) goto L2;
709
L1:     if(DLOC[I] != 0)ATDWRF=0;
710
        } /* end loop */
711
        return(ATDWRF);
712
 
713
L2:     ATDWRF=I;
714
        return(ATDWRF);
715
}
716
 
717
 
718
 
719
 
720
#define ATDWRF(WHERE) fATDWRF(WHERE)
721
 
722
 
723
 
724
/*  UTILITY ROUTINES (SETBIT, TSTBIT, RAN, RNDVOC, BUG) */
725
 
726
#undef SETBIT
727
long fSETBIT(BIT)long BIT; {
728
long I, SETBIT;
729
 
730
/*  RETURNS 2**BIT FOR USE IN CONSTRUCTING BIT-MASKS. */
731
 
732
 
733
        SETBIT=1;
734
        if(BIT <= 0)return(SETBIT);
735
        /* 1 */ for (I=1; I<=BIT; I++) {
736
L1:     SETBIT=SETBIT+SETBIT;
737
        } /* end loop */
738
        return(SETBIT);
739
}
740
 
741
 
742
 
743
#define SETBIT(BIT) fSETBIT(BIT)
744
#undef TSTBIT
745
long fTSTBIT(MASK,BIT)long BIT, MASK; {
746
long TSTBIT;
747
 
748
/*  RETURNS TRUE IF THE SPECIFIED BIT IS SET IN THE MASK. */
749
 
750
 
751
        TSTBIT=MOD(MASK/SETBIT(BIT),2) != 0;
752
        return(TSTBIT);
753
}
754
 
755
 
756
 
757
#define TSTBIT(MASK,BIT) fTSTBIT(MASK,BIT)
758
#undef RAN
759
long fRAN(RANGE)long RANGE; {
760
static long D, R = 0, RAN, T;
761
 
762
/*  SINCE THE RAN FUNCTION IN LIB40 SEEMS TO BE A REAL LOSE, WE'LL USE ONE OF
763
 *  OUR OWN.  IT'S BEEN RUN THROUGH MANY OF THE TESTS IN KNUTH VOL. 2 AND
764
 *  SEEMS TO BE QUITE RELIABLE.  RAN RETURNS A VALUE UNIFORMLY SELECTED
765
 *  BETWEEN 0 AND RANGE-1. */
766
 
767
 
768
        D=1;
769
        if(R != 0 && RANGE >= 0) goto L1;
770
        DATIME(D,T);
771
        R=MOD(T+5,1048576L);
772
        D=1000+MOD(D,1000);
773
L1:     /* 2 */ for (T=1; T<=D; T++) {
774
L2:     R=MOD(R*1093L+221587L,1048576L);
775
        } /* end loop */
776
        RAN=(RANGE*R)/1048576;
777
        return(RAN);
778
}
779
 
780
 
781
 
782
#define RAN(RANGE) fRAN(RANGE)
783
#undef RNDVOC
784
long fRNDVOC(CHAR,FORCE)long CHAR, FORCE; {
785
long DIV, I, J, RNDVOC;
786
 
787
/*  SEARCHES THE VOCABULARY FOR A WORD WHOSE SECOND CHARACTER IS CHAR, AND
788
 *  CHANGES THAT WORD SUCH THAT EACH OF THE OTHER FOUR CHARACTERS IS A
789
 *  RANDOM LETTER.  IF FORCE IS NON-ZERO, IT IS USED AS THE NEW WORD.
790
 *  RETURNS THE NEW WORD. */
791
 
792
 
793
        RNDVOC=FORCE;
794
        if(RNDVOC != 0) goto L3;
795
        /* 1 */ for (I=1; I<=5; I++) {
796
        J=11+RAN(26);
797
        if(I == 2)J=CHAR;
798
L1:     RNDVOC=RNDVOC*64+J;
799
        } /* end loop */
800
L3:     J=10000;
801
        DIV=64L*64L*64L;
802
        /* 5 */ for (I=1; I<=TABSIZ; I++) {
803
        J=J+7;
804
        if(MOD((ATAB[I]-J*J)/DIV,64L) == CHAR) goto L8;
805
L5:     /*etc*/ ;
806
        } /* end loop */
807
        BUG(5);
808
 
809
L8:     ATAB[I]=RNDVOC+J*J;
810
        return(RNDVOC);
811
}
812
 
813
 
814
 
815
#define RNDVOC(CHAR,FORCE) fRNDVOC(CHAR,FORCE)
816
#undef BUG
817
void fBUG(NUM)long NUM; {
818
 
819
/*  THE FOLLOWING CONDITIONS ARE CURRENTLY CONSIDERED FATAL BUGS.  NUMBERS < 20
820
 *  ARE DETECTED WHILE READING THE DATABASE; THE OTHERS OCCUR AT "RUN TIME".
821
 *      0        MESSAGE LINE > 70 CHARACTERS
822
 *      1       NULL LINE IN MESSAGE
823
 *      2       TOO MANY WORDS OF MESSAGES
824
 *      3       TOO MANY TRAVEL OPTIONS
825
 *      4       TOO MANY VOCABULARY WORDS
826
 *      5       REQUIRED VOCABULARY WORD NOT FOUND
827
 *      6       TOO MANY RTEXT MESSAGES
828
 *      7       TOO MANY HINTS
829
 *      8       LOCATION HAS COND BIT BEING SET TWICE
830
 *      9       INVALID SECTION NUMBER IN DATABASE
831
 *      10      TOO MANY LOCATIONS
832
 *      11      TOO MANY CLASS OR TURN MESSAGES
833
 *      20      SPECIAL TRAVEL (500>L>300) EXCEEDS GOTO LIST
834
 *      21      RAN OFF END OF VOCABULARY TABLE
835
 *      22      VOCABULARY TYPE (N/1000) NOT BETWEEN 0 AND 3
836
 *      23      INTRANSITIVE ACTION VERB EXCEEDS GOTO LIST
837
 *      24      TRANSITIVE ACTION VERB EXCEEDS GOTO LIST
838
 *      25      CONDITIONAL TRAVEL ENTRY WITH NO ALTERNATIVE
839
 *      26      LOCATION HAS NO TRAVEL ENTRIES
840
 *      27      HINT NUMBER EXCEEDS GOTO LIST
841
 *      28      INVALID MONTH RETURNED BY DATE FUNCTION
842
 *      29      TOO MANY PARAMETERS GIVEN TO SETPRM */
843
 
844 177 ja_rd
    printf("Fatal error %d. See source code for interpretation.\n", NUM);
845 90 ja_rd
        exit(FALSE);
846
}
847
 
848
 
849
 
850
 
851
 
852
/*  MACHINE DEPENDENT ROUTINES (MAPLIN, TYPE, MPINIT, SAVEIO) */
853
 
854
#define BUG(NUM) fBUG(NUM)
855
#undef MAPLIN
856
void fMAPLIN(FIL)long FIL; {
857
long I, VAL; static MFILE *OPENED = NULL;
858
 
859
/*  READ A LINE OF INPUT, EITHER FROM A FILE (IF FIL=.TRUE.) OR FROM THE
860
 *  KEYBOARD, TRANSLATE THE CHARS TO INTEGERS IN THE RANGE 0-126 AND STORE
861
 *  THEM IN THE COMMON ARRAY "INLINE".  INTEGER VALUES ARE AS FOLLOWS:
862
 *     0   = SPACE [ASCII CODE 40 OCTAL, 32 DECIMAL]
863
 *    1-2  = !" [ASCII 41-42 OCTAL, 33-34 DECIMAL]
864
 *    3-10 = '()*+,-. [ASCII 47-56 OCTAL, 39-46 DECIMAL]
865
 *   11-36 = UPPER-CASE LETTERS
866
 *   37-62 = LOWER-CASE LETTERS
867
 *    63   = PERCENT (%) [ASCII 45 OCTAL, 37 DECIMAL]
868
 *   64-73 = DIGITS, 0 THROUGH 9
869
 *  REMAINING CHARACTERS CAN BE TRANSLATED ANY WAY THAT IS CONVENIENT;
870
 *  THE "TYPE" ROUTINE BELOW IS USED TO MAP THEM BACK TO CHARACTERS WHEN
871
 *  NECESSARY.  THE ABOVE MAPPINGS ARE REQUIRED SO THAT CERTAIN SPECIAL
872
 *  CHARACTERS ARE KNOWN TO FIT IN 6 BITS AND/OR CAN BE EASILY SPOTTED.
873
 *  ARRAY ELEMENTS BEYOND THE END OF THE LINE SHOULD BE FILLED WITH 0,
874
 *  AND LNLENG SHOULD BE SET TO THE INDEX OF THE LAST CHARACTER.
875
 *
876
 *  IF THE DATA FILE USES A CHARACTER OTHER THAN SPACE (E.G., TAB) TO
877
 *  SEPARATE NUMBERS, THAT CHARACTER SHOULD ALSO TRANSLATE TO 0.
878
 *
879
 *  THIS PROCEDURE MAY USE THE MAP1,MAP2 ARRAYS TO MAINTAIN STATIC DATA FOR
880
 *  THE MAPPING.  MAP2(1) IS SET TO 0 WHEN THE PROGRAM STARTS
881
 *  AND IS NOT CHANGED THEREAFTER UNLESS THE ROUTINES ON THIS PAGE CHOOSE
882
 *  TO DO SO.
883
 *
884
 *  NOTE THAT MAPLIN IS EXPECTED TO OPEN THE FILE THE FIRST TIME IT IS
885
 *  ASKED TO READ A LINE FROM IT.  THAT IS, THERE IS NO OTHER PLACE WHERE
886
 *  THE DATA FILE IS OPENED. */
887
 
888
 
889
        if(MAP2[1] == 0)MPINIT();
890
 
891
        if(FIL) goto L15;
892
        get_command(INLINE+1);
893
        /* EMBEDDED: we don't support 'quitting by closing stdin' */
894
        /* if(feof(stdin)) score(1); */
895
    goto L20;
896
 
897
L15:    if(!OPENED){
898
                OPENED=mopen("adventure.text","r" /* NOT binary */);
899 177 ja_rd
                if(!OPENED){printf("Can't read adventure.text!\n"); exit(FALSE);}
900 90 ja_rd
                }
901
        mgets(INLINE+1,100,OPENED);
902
 
903
L20:    LNLENG=0;
904
        /* 25 */ for (I=1; I<=100 && INLINE[I]!=0; I++) {
905
        VAL=INLINE[I]+1;
906
        INLINE[I]=MAP1[VAL];
907
L25:    if(INLINE[I] != 0)LNLENG=I;
908
        } /* end loop */
909
        LNPOSN=1;
910
        if(FIL && LNLENG == 0) goto L15;
911
/*  ABOVE IS TO GET AROUND AN F40 COMPILER BUG WHEREIN IT READS A BLANK
912
 *  LINE WHENEVER A CRLF IS BROKEN ACROSS A RECORD BOUNDARY. */
913
        return;
914
}
915
 
916
 
917
 
918
#define MAPLIN(FIL) fMAPLIN(FIL)
919
#undef TYPE
920
void fTYPE() {
921
long I, VAL;
922
 
923
/*  TYPE THE FIRST "LNLENG" CHARACTERS STORED IN INLINE, MAPPING THEM
924
 *  FROM INTEGERS TO TEXT PER THE RULES DESCRIBED ABOVE.  INLINE(I),
925
 *  I=1,LNLENG MAY BE CHANGED BY THIS ROUTINE. */
926
 
927
 
928
        if(LNLENG != 0) goto L10;
929 177 ja_rd
        printf("\n");
930 90 ja_rd
        return;
931
 
932
L10:    if(MAP2[1] == 0)MPINIT();
933
        /* 20 */ for (I=1; I<=LNLENG; I++) {
934
        VAL=INLINE[I];
935
L20:    {long x = VAL+1; INLINE[I]=MAP2[x];}
936
        } /* end loop */
937
        {long x = LNLENG+1; INLINE[x]=0;}
938 177 ja_rd
        printf(INLINE+1);
939
        printf("\n");
940 90 ja_rd
        return;
941
}
942
 
943
 
944
 
945
#define TYPE() fTYPE()
946
#undef MPINIT
947
void fMPINIT() {
948
long FIRST, I, J, LAST, VAL;
949
static const long RUNS[7][2] = {32,34, 39,46, 65,90, 97,122, 37,37, 48,57, 0,126};
950
 
951
 
952
        /* 10 */ for (I=1; I<=128; I++) {
953
L10:    MAP1[I]= -1;
954
        } /* end loop */
955
        VAL=0;
956
        /* 20 */ for (I=0; I<7; I++) {
957
        FIRST=RUNS[I][0];
958
        LAST=RUNS[I][1];
959
        /* 22 */ for (J=FIRST; J<=LAST; J++) {
960
        J++; if(MAP1[J] >= 0) goto L22;
961
        MAP1[J]=VAL;
962
        VAL=VAL+1;
963
L22:    J--;
964
        } /* end loop */
965
L20:    /*etc*/ ;
966
        } /* end loop */
967
        MAP1[128]=MAP1[10];
968
/*  FOR THIS VERSION, TAB (9) MAPS TO SPACE (32), SO DEL (127) USES TAB'S VALUE */
969
        MAP1[10]=MAP1[33];
970
        MAP1[11]=MAP1[33];
971
 
972
        /* 30 */ for (I=0; I<=126; I++) {
973
        I++; VAL=MAP1[I]+1; I--;
974
        MAP2[VAL]=I*('B'-'A');
975
L30:    if(I >= 64)MAP2[VAL]=(I-64)*('B'-'A')+'@';
976
        } /* end loop */
977
 
978
        return;
979
}
980
 
981
 
982
 
983
#define MPINIT() fMPINIT()
984
#undef SAVEIO
985
void fSAVEIO(OP,IN,ARR)long ARR[], IN, OP; {
986
static FILE *F; char NAME[50];
987
 
988
/*  IF OP=0, ASK FOR A FILE NAME AND OPEN A FILE.  (IF IN=.TRUE., THE FILE IS FOR
989
 *  INPUT, ELSE OUTPUT.)  IF OP>0, READ/WRITE ARR FROM/INTO THE PREVIOUSLY-OPENED
990
 *  FILE.  (ARR IS A 250-INTEGER ARRAY.)  IF OP<0, FINISH READING/WRITING THE
991
 *  FILE.  (FINISHING WRITING CAN BE A NO-OP IF A "STOP" STATEMENT DOES IT
992
 *  AUTOMATICALLY.  FINISHING READING CAN BE A NO-OP AS LONG AS A SUBSEQUENT
993
 *  SAVEIO(0,.FALSE.,X) WILL STILL WORK.)  IF YOU CAN CATCH ERRORS (E.G., NO SUCH
994
 *  FILE) AND TRY AGAIN, GREAT.  DEC F40 CAN'T. */
995
 
996
/* EMBEDDED version supports no saves */
997
/*
998
        {long ifvar; ifvar=(OP); switch (ifvar<0? -1 : ifvar>0? 1 : 0) { case -1:
999
                goto L10; case 0: goto L20; case 1: goto L30; }}
1000
 
1001
L10:    fclose(F);
1002
        return;
1003
 
1004 177 ja_rd
L20:    printf("\nFile name: ");
1005 90 ja_rd
        gets(NAME);
1006
        F=mopen(NAME,(IN ? READ_MODE : WRITE_MODE));
1007 177 ja_rd
        if(F == NULL) {printf("Can't open file, try again.\n"); goto L20;}
1008 90 ja_rd
        return;
1009
 
1010
L30:    if(IN)fread(ARR,4,250,F);
1011
        if(!IN)fwrite(ARR,4,250,F);
1012
        return;
1013
*/
1014
return;
1015
}
1016
 
1017
 
1018
 
1019
long fIABS(N)long N; {return(N<0? -N : N);}
1020
long fMOD(N,M)long N, M; {return(N%M);}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.