-
Notifications
You must be signed in to change notification settings - Fork 0
/
showverb.c
1701 lines (1476 loc) · 52.4 KB
/
showverb.c
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
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* showverb - part of infodump
*
* Verb and grammar display routines.
*/
#include "tx.h"
#ifdef __STDC__
static void show_verb_parse_table
(unsigned long, unsigned int, unsigned int, unsigned int, unsigned long, unsigned long);
static void show_action_tables
(unsigned long, unsigned int, unsigned int, unsigned int, unsigned int,
unsigned int, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long);
static void show_preposition_table
(unsigned int, unsigned long, unsigned int);
static void show_preposition
(unsigned int, int, unsigned long);
static void show_words
(unsigned int, unsigned long, unsigned int, unsigned int);
static unsigned long lookup_word
(unsigned long, unsigned int, unsigned int, unsigned int);
#else
static void show_verb_parse_table ();
static void show_action_tables ();
static void show_preposition_table ();
static void show_preposition ();
static void show_words ();
static unsigned long lookup_word ();
#endif
static const int verb_sizes[4] = { 2, 4, 7, 0 };
/*
* configure_parse_tables
*
* Determine the start of the parse table, the start of the parse data, the
* start of the action routine table, the start of the pre-action routine
* table, the start of the preposition list and other sundry things.
*
* Format of the verb parse tables:
*
* base:
* Table of pointers (2 bytes) to each verb entry. Each verb in the
* dictionary has an index (1 byte) into this table. The index in the
* dictionary is inverted so an index of 255 = table entry 0, etc.
* In GV2 the index is 2 bytes and it is not inverted -- except that
* Inform 6.10 uses the old method. Thus type GV2A is used internally
* to indicate the 2-byte form which will presumably be used in
* later Inform versions.
*
* Next comes the parse data for each verb pointed to by the table of
* pointers. The format of the parse data varies between games. Basically,
* each entry has a count (1 byte) of parse structures corresponding to
* different sentence structures. For example, the verb 'take' in the
* dictionary may have two forms; 'take object' or 'take object with object'.
* Each form has an index (1 byte) into the pre-action and action routine
* tables.
*
* Next come the action routine tables. There is an entry (2 bytes) for
* each verb form index. The entries are packed addresses of the Z-code
* routines that perform the main verb processing.
*
* Next come the pre-action routine tables. There is an entry (2 bytes) for
* each verb form index. The entries are packed addresses of the Z-code
* routines that are called before the main verb action routine.
*
* Finally, there is a list of prepositions that can be used by any verb
* in the verb parse table. This list has a count (2 bytes) followed by
* the address of the preposition in the dictionary and an index.
*
* Verb parse entry format:
*
* The format of the data varies between games. The information in the
* entry is the same though:
*
* An object count (0, 1 or 2)
* A preposition index for the verb
* Data for object(s) 1
* A preposition index for the objects
* Data for object(s) 2
* A pre-action/action routine table index
*
* This means a sentence can have the following form:
*
* verb [+ prep] 'look [at]'
* verb [+ prep] + object 'look [at] book'
* verb [+ prep] + object [+ prep] + object 'look [at] book [with] glasses'
*
* The verb and prepositions can only be a single word each. The object
* could be a multiple words 'green book' or a list depending on the object
* data.
*
* Notes:
*
* Story files produced by Graham Nelson's Inform compiler do not have a
* concept of pre-actions. Instead, the pre-actions table is filled with
* pointers to general parsing routines which are related to certain verb
* parse entries. The format of the parse entries has changed, too. Parse
* entries have now become a string of tokens. Objects have token values
* between 0x00 and 0xaf, prepositions correspond to token values from 0xb0
* to 0xff. Therefore more complicated verb structures with more than two
* prepositions are possible. See the "Inform Technical Manual" for further
* information.
*
* Inform 6 reduces the size of the pre-action table (which no longer holds
* any pre-action routines, see above) to the number of parsing routines.
*
* Inform 6.10 adds a new grammar form, called GV2, which does away with
* the pre-action table and preposition table entirely, and completely
* changes the parse entry format. Again, see the "Inform Technical Manual"
* for further information. Also note that Inform (in both GV1 and GV2)
* uses the flags bytes in the dictionary entry in a slightly different
* manner than Infocom games.
*
* Graphic (V6) Infocom games use a different grammar format. The basic
* elements are mostly still there, but in a different set of tables.
* The table of pointers to the verb entries is gone. Instead, the
* first word of 'extra' dictionary information contains a pointer to the
* verb entry. Pointers to the action and preaction tables are in
* the next-to-last and last global variables respectively, but in practice
* the tables are in their usual location right after the verb grammar table,
* which is in its usual location at the base of dynamic memory. The
* verb grammar table has the following format
*
* Bytes 0-1: Action/pre-action index of the 0-object entry. That is, action
* if this verb is used alone. $FFFF if this verb cannot be used
* as a sentence in itself
*
* Bytes 2-3: Doesn't seem to be used. Might be intended for actions with
* no objects but with a preposition.
*
* Bytes 4-5: Pointer to grammar entries for 1-object entries -- i.e. those
* of the form "verb [+ prep] + object"
*
* Bytes 6-7: Pointer to grammar entries for 2-object entries -- i.e. those
* of the form "verb [+ prep] + object [+ prep] + object"
*
* The grammar entries area is new. Each item contains data of the following
* format:
*
* Bytes 0-1: Number of entries in this item. Entries immediately follow
* For each entry in the item:
* Bytes 0-1: Action/pre-action index for this item.
* Bytes 2-3: Byte address of the dictionary word for the preposition
* $0000 if no preposition.
*
* Byte 4: Attribute # associated with this entry. This does not appear
* to be used by the parser itself, but instead by the helper
* which suggests possible commands, in order to suggest
* sensible ones. Actually verifying that the object has the
* attribute seems to be left to the action routine.
*
* Byte 5: I'm not sure about this one. $80 appears to mean anything can
* be used, particularly including quoted strings. $0F seems to
* mean an object in scope. $14 may mean an object being held. I
* suspect it's a flags byte.
*
* Bytes 6-7: (Two object entries only) Same as bytes 2-3, for second preposition
* Bytes 8-9: (Two object entries only) Same as bytes 4-5, for second object
*
*
* Note also that the dictionary flags have moved from the first to the last byte
* of each dictionary entry, and that while Zork Zero has only three bytes of
* extra dictionary data (as with V1-5), Shogun and Arthur have four.
* Also, I believe there is more grammar data than I've listed here, though how
* much is for the parser proper and how much for the helper I don't know -- MTR
*
* Journey has no grammar.
*
*/
#ifdef __STDC__
void configure_parse_tables (unsigned int *verb_count,
unsigned int *action_count,
unsigned int *parse_count,
unsigned int *parser_type,
unsigned int *prep_type,
unsigned long *verb_table_base,
unsigned long *verb_data_base,
unsigned long *action_table_base,
unsigned long *preact_table_base,
unsigned long *prep_table_base,
unsigned long *prep_table_end)
#else
void configure_parse_tables (verb_count,
action_count,
parse_count,
parser_type,
prep_type,
verb_table_base,
verb_data_base,
action_table_base,
preact_table_base,
prep_table_base,
prep_table_end)
unsigned int *verb_count;
unsigned int *action_count;
unsigned int *parse_count;
unsigned int *parser_type;
unsigned int *prep_type;
unsigned long *verb_table_base;
unsigned long *verb_data_base;
unsigned long *action_table_base;
unsigned long *preact_table_base;
unsigned long *prep_table_base;
unsigned long *prep_table_end;
#endif
{
unsigned long address, first_entry, second_entry, verb_entry;
unsigned int entry_count, object_count, prep_count, action_index;
unsigned int parse_index, val;
int i, j;
*verb_table_base = 0;
*verb_data_base = 0;
*action_table_base = 0;
*preact_table_base = 0;
*prep_table_base = 0;
*prep_table_end = 0;
*verb_count = 0;
*action_count = 0;
*parser_type = 0;
*prep_type = 0;
if (header.serial[0] >= '0' && header.serial[0] <= '9' &&
header.serial[1] >= '0' && header.serial[1] <= '9' &&
header.serial[2] >= '0' && header.serial[2] <= '1' &&
header.serial[3] >= '0' && header.serial[3] <= '9' &&
header.serial[4] >= '0' && header.serial[4] <= '3' &&
header.serial[5] >= '0' && header.serial[5] <= '9' &&
header.serial[0] != '8') {
*parser_type = inform5_grammar;
if (header.name[4] >= '6')
*parser_type = inform_gv1;
}
if ((*parser_type < inform5_grammar) && (unsigned int) header.version == V6) {
unsigned long word_address, first_word, last_word;
unsigned short word_size, word_count;
unsigned long vbase, vend;
unsigned long area2base, area2end;
unsigned long parse_address;
*parser_type = infocom6_grammar;
address = header.objects - 4;
*action_table_base = (unsigned short)read_data_word(&address);
*preact_table_base = (unsigned short)read_data_word(&address);
/* Calculate dictionary bounds and entry size */
address = (unsigned long) header.dictionary;
address += (unsigned long) read_data_byte (&address);
word_size = read_data_byte (&address);
word_count = read_data_word (&address);
first_word = address;
last_word = address + ((word_count - 1) * word_size);
vbase = area2base = 0xFFFF;
vend = area2end = 0;
for (word_address = first_word; word_address <= last_word; word_address += word_size) {
address = word_address + 6;
parse_index = (unsigned short)read_data_word(&address);
address = word_address + word_size - 1;
val = read_data_byte(&address); /* flags */
if ((val&1) && !(val & 0x80) && (parse_index != 0) && (parse_index < *action_table_base)) { /* dictionary verb */
if (vbase > parse_index)
vbase = parse_index;
if (vend <= parse_index)
vend = parse_index + 8;
address = parse_index + 4;
/* retrieve direct-object only parse entries */
parse_address = (unsigned short)read_data_word(&address);
if (parse_address && (area2base > parse_address))
area2base = parse_address;
if (parse_address && (area2end <= parse_address)) {
val = (unsigned short)read_data_word(&parse_address);
area2end = (parse_address + 6 * val);
}
/* retrieve indrect-object parse entries */
parse_address = (unsigned short)read_data_word(&address);
if (parse_address && (area2base > parse_address))
area2base = parse_address;
if (parse_address && (area2end <= parse_address)) {
val = (unsigned short)read_data_word(&parse_address);
area2end = (parse_address + 10 * val);
}
}
}
if (vend == 0) /* no verbs */
return;
*verb_count = (vend - vbase)/8;
*verb_table_base = vbase;
*verb_data_base = area2base;
/* there is no preposition table, but *prep_table_base bounds the verb data area */
*prep_table_base = area2end;
*prep_table_end = area2end;
*action_count = (*preact_table_base - *action_table_base) / 2;
return;
}
/* Start of table comes from the header */
*verb_table_base = (unsigned long) header.dynamic_size;
/*
* Calculate the number of verb entries in the table. This can be done
* because the verb entries immediately follow the verb table.
*/
address = *verb_table_base;
first_entry = read_data_word (&address);
if (first_entry == 0) /* No verb entries at all */
return;
*verb_count = (unsigned int) ((first_entry - *verb_table_base) / sizeof (zword_t));
/*
* Calculate the form of the verb parse table entries. Basically,
* Infocom used two types of table. The first types have 8 bytes per
* entry, and the second type has a variable sized amount of data per
* entry. In addition, Inform uses two new types of table. We look at
* the serial number to distinguish Inform story files from Infocom
* games, and we look at the last header entry to identify Inform 6
* story files because Inform 6 writes its version number into the
* last four bytes of this entry.
*/
/*
* Inform 6.10 addes an additional table format, called GV2. GV1 is the
* Inform 6.0-6.05 format, and is essentially similar to the Inform 5
* format except that the parsing routine table is not padded out
* to the length of the action table.
* Infocom: parser_type = 0,1
* Inform 1?-5: parser_type = 2
* Inform 6 GV1: parser_type = 3
* Inform 6 GV2: parser_type = 4
*/
address = *verb_table_base;
first_entry = read_data_word (&address);
second_entry = read_data_word (&address);
*verb_data_base = first_entry;
entry_count = (unsigned int) read_data_byte (&first_entry);
if (*parser_type < inform5_grammar) {
*parser_type = infocom_fixed;
if (((second_entry - first_entry) / entry_count) <= 7)
*parser_type = infocom_variable;
}
/* Distinguishing between GV1 and GV2 isn't trivial.
Here I check the length of the first entry. It will be 1 mod 3
for GV2 and 1 mod 8 for GV1. If it's 1 mod 24, first I check to see if
its length matches the GV1 length. Then I check for illegal GV1 values.
If they aren't found, I assume GV1. I believe it is actually possible for
a legal (if somewhat nonsensical) GV1 table to be the same as a legal GV2
table, but I haven't actually constructed such a weird table. In practice,
the ENDIT (15) byte of the GV2 table will probably cause an illegal token
if the table is interpreted as GV1 -- MTR.
*/
if (*parser_type == inform_gv1) {
first_entry = *verb_data_base;
if (((second_entry - first_entry) % 3) == 1) {
entry_count = read_data_byte (&first_entry);
if ((entry_count * 8 + 1) == (second_entry - first_entry)) {
/* this is the most ambiguous case */
for (i = 0; i < entry_count && (*parser_type == inform_gv1); i++) {
if (read_data_byte (&first_entry) > 6) {
*parser_type = inform_gv2;
break;
}
for (j = 1; j < 7; j++) {
val = read_data_byte (&first_entry);
if ((val >= 9) || (val <= 15) || (val >= 112) || (val <= 127)) {
*parser_type = inform_gv2;
break;
}
}
read_data_byte (&first_entry); /* action number. This can be anything */
}
}
else {
*parser_type = inform_gv2;
}
}
else if (((second_entry - first_entry) % 8) != 1) {
fprintf(stderr, "Grammar table illegal size!");
}
}
/*
* Make a pass through the verb parse table looking at the pre-action and
* action routine indices. We need to know what the highest index is to
* find the size of the pre-action and action tables. Before Inform 6
* both tables had the same size. For Inform 6 story files we also need
* to know the number of parsing routines that occupy the pre-action
* table (instead of pre-actions).
*/
*action_count = 0;
*parse_count = 0;
address = *verb_table_base;
for (i = 0; (unsigned int) i < *verb_count; i++) {
verb_entry = (unsigned long) read_data_word (&address);
entry_count = (unsigned int) read_data_byte (&verb_entry);
while (entry_count--) {
if (*parser_type == infocom_fixed) {
verb_entry += 7;
action_index = (unsigned int) read_data_byte (&verb_entry);
} else if (*parser_type == infocom_variable) {
object_count = (unsigned int) read_data_byte (&verb_entry);
action_index = (unsigned int) read_data_byte (&verb_entry);
verb_entry += verb_sizes[(object_count >> 6) & 0x03] - 2;
} else if ((*parser_type == inform_gv1) || (*parser_type == inform5_grammar)) {
/* GV1 */
object_count = (unsigned int) read_data_byte (&verb_entry);
for (j = 0; j < 6; j++) {
val = read_data_byte (&verb_entry);
if (val < 16 || val >= 112)
continue;
parse_index = (val - 16) % 32;
if (parse_index > *parse_count)
*parse_count = parse_index;
}
action_index = (unsigned int) read_data_byte (&verb_entry);
}
else {
/* GV2 */
action_index = (unsigned int) (read_data_word (&verb_entry) & 0x3FF);
val = read_data_byte (&verb_entry);
while (val != 15) {
read_data_byte (&verb_entry);
read_data_byte (&verb_entry);
val = read_data_byte (&verb_entry);
}
}
if (action_index > *action_count)
*action_count = action_index;
}
}
(*action_count)++;
if ((*parser_type == inform_gv1) || (*parser_type == inform5_grammar))
(*parse_count)++;
while ((unsigned int) read_data_byte (&verb_entry) == 0) /* Skip padding, if any */
;
/*
* Set the start addresses of the pre-action and action routines tables
* and the preposition table.
*/
*action_table_base = verb_entry - 1;
*preact_table_base = *action_table_base + (*action_count * sizeof (zword_t));
if (*parser_type >= inform_gv2) {
/* GV2 has neither preaction/parse table nor preposition table */
*prep_table_base = *preact_table_base;
*prep_table_end = *preact_table_base;
}
else {
if (*parser_type < inform_gv1)
*prep_table_base = *preact_table_base + (*action_count * sizeof (zword_t));
else
*prep_table_base = *preact_table_base + (*parse_count * sizeof (zword_t));
/*
* Set the preposition table type by looking to see if the byte index
* is stored in a word (an hence the upper 8 bits are zero).
*/
address = *prep_table_base;
prep_count = (unsigned int) read_data_word (&address);
address += 2; /* Skip first address */
if ((unsigned int) read_data_byte (&address) == 0) {
*prep_type = 0;
*prep_table_end = *prep_table_base + 2 + (4 * prep_count) - 1;
} else {
*prep_type = 1;
*prep_table_end = *prep_table_base + 2 + (3 * prep_count) - 1;
}
}
}/* configure_parse_tables */
/*
* show_verbs
*
* Display the verb parse tables, sentence structure, action routines and
* prepositions.
*/
#ifdef __STDC__
void show_verbs (int symbolic)
#else
void show_verbs (symbolic)
int symbolic;
#endif
{
unsigned long verb_table_base, verb_data_base;
unsigned long action_table_base, preact_table_base;
unsigned long prep_table_base, prep_table_end;
unsigned int verb_count, action_count, parse_count, parser_type, prep_type;
unsigned int obj_count;
unsigned long obj_table_base, obj_table_end, obj_data_base, obj_data_end;
unsigned int inform_version;
unsigned long class_numbers_base, class_numbers_end;
unsigned long property_names_base, property_names_end;
unsigned long attr_names_base, attr_names_end;
unsigned long action_names_base;
/* Get parse table configuration */
configure_parse_tables (&verb_count, &action_count, &parse_count, &parser_type, &prep_type,
&verb_table_base, &verb_data_base,
&action_table_base, &preact_table_base,
&prep_table_base, &prep_table_end);
/* I wonder weather you can guess which author required the following test? */
if (verb_count == 0) {
tx_printf ("\n **** There are no parse tables ****\n\n");
tx_printf (" Verb entries = 0\n\n");
return;
}
if (symbolic) {
configure_object_tables (&obj_count, &obj_table_base, &obj_table_end,
&obj_data_base, &obj_data_end);
configure_inform_tables(obj_data_end, &inform_version, &class_numbers_base, &class_numbers_end,
&property_names_base, &property_names_end, &attr_names_base, &attr_names_end);
}
else {
attr_names_base = property_names_base = class_numbers_base = 0;
}
action_names_base = attr_names_base?attr_names_end + 1:0;
/* Display parse data */
show_verb_parse_table (verb_table_base, verb_count, parser_type,
prep_type, prep_table_base, attr_names_base);
/* Display action routines */
show_action_tables (verb_table_base,
verb_count, action_count, parse_count, parser_type, prep_type,
action_table_base, preact_table_base,
prep_table_base, attr_names_base, action_names_base);
/* Display prepositions */
if ((parser_type <= inform_gv2) && (parser_type != infocom6_grammar)) /* no preposition table in GV2 */
show_preposition_table (prep_type, prep_table_base, parser_type);
}/* show_verbs */
/*
* show_verb_parse_table
*
* Display the parse information associated with each verb. The entry into the
* table is found from the dictionary. Each verb has a parse table entry index.
* These indices range from 255 to 0*. Each parse table entry can have one or
* more sentence formats associated with the verb. Once the verb and sentence
* structure match, an index taken from the parse data is used to index into the
* pre-action and action routine tables. This format allows multiple similar
* verb and sentence structures to parse to the same action routine.
* * 0 to 65535 in GV2
*
* Synonyms for each verb are also show. The first verb in the dictionary is
* used in the sentence structure text. This can lead to bizarre looking
* sentences, but they all work!
*
* The index used to find the action routine is the same number printed when
* debugging is turned on in games that support this. The number is printed as
* performing: nn
*/
#ifdef __STDC__
static void show_verb_parse_table (unsigned long verb_table_base,
unsigned int verb_count,
unsigned int parser_type,
unsigned int prep_type,
unsigned long prep_table_base,
unsigned long attr_names_base)
#else
static void show_verb_parse_table (verb_table_base,
verb_count,
parser_type,
prep_type,
prep_table_base,
attr_names_base)
unsigned long verb_table_base;
unsigned int verb_count;
unsigned int parser_type;
unsigned int prep_type;
unsigned long prep_table_base;
unsigned long attr_names_base;
#endif
{
unsigned long address, verb_entry, parse_entry;
unsigned int entry_count, object_count, parse_data;
int i, j, verb_size;
tx_printf ("\n **** Parse tables ****\n\n");
tx_printf (" Verb entries = %d\n", (int) verb_count);
/* Go through each verb and print its parse information and grammar */
address = verb_table_base;
for (i = 0; (unsigned int) i < verb_count; i++) {
/* Get start of verb entry and number of entries */
if (parser_type == infocom6_grammar) {
unsigned long do_address, doio_address;
unsigned int verb_address;
verb_address = (unsigned int)address; /* cast is guaranteed to work provided unsigned int >= 16 bits */
tx_printf ("\n%3d. @ $%04x, verb = ", i, address);
show_words ((unsigned int)address, 0L, VERB_V6, parser_type);
tx_printf ("\n Main data");
tx_printf ("\n [");
parse_data = (unsigned int) read_data_word (&address);
tx_printf ("%04x ", (unsigned int) parse_data);
read_data_word (&address); /* I don't know what this word does */
tx_printf ("%04x ", (unsigned int) parse_data);
do_address = (unsigned int) read_data_word (&address);
tx_printf ("%04x ", (unsigned int) do_address);
doio_address = (unsigned int) read_data_word (&address);
tx_printf ("%04x", (unsigned int) doio_address);
tx_printf ("] ");
if (verb_entry != 0xFFFF)
show_verb_grammar (parse_entry, verb_address, (int) parser_type, 0, 0, 0L, 0L);
if (do_address) {
tx_printf ("\n One object entries:\n");
verb_entry = do_address;
entry_count = (unsigned int) read_data_word (&verb_entry);
verb_size = 3; /* words */
while (entry_count --) {
parse_entry = verb_entry;
tx_printf (" [");
for (j = 0; j < verb_size; j++) {
parse_data = (unsigned int) read_data_word (&verb_entry);
tx_printf ("%04x", (unsigned int) parse_data);
if (j < (verb_size - 1))
tx_printf (" ");
}
tx_printf ("] ");
show_verb_grammar (parse_entry, verb_address, (int) parser_type, 1,
0, 0L, 0L);
tx_printf ("\n");
}
}
if (doio_address) {
tx_printf ("\n Two object entries:\n");
verb_entry = doio_address;
entry_count = (unsigned int) read_data_word (&verb_entry);
verb_size = 5; /* words */
while (entry_count --) {
parse_entry = verb_entry;
tx_printf (" [");
for (j = 0; j < verb_size; j++) {
parse_data = (unsigned int) read_data_word (&verb_entry);
tx_printf ("%04x", (unsigned int) parse_data);
if (j < (verb_size - 1))
tx_printf (" ");
}
tx_printf ("] ");
show_verb_grammar (parse_entry, verb_address, (int) parser_type, 2,
0, 0L, 0L);
tx_printf ("\n");
}
}
}
else { /* everything but Zork Zero, Shogun, and Arthur */
verb_entry = (unsigned long) read_data_word (&address);
entry_count = (unsigned int) read_data_byte (&verb_entry);
/* Show the verb index, entry count, verb and synonyms */
tx_printf ("\n%3d. %d entr%s, verb = ", (int) VERB_NUM(i, parser_type),
(int) entry_count, (entry_count == 1) ? "y" : "ies");
show_words (VERB_NUM(i, parser_type), 0L, VERB, parser_type);
tx_printf ("\n");
/* Show parse data and grammar for each verb entry */
while (entry_count--) {
parse_entry = verb_entry;
/* Calculate the amount of verb data */
if (parser_type != infocom_variable) {
verb_size = 8;
} else {
object_count = (unsigned int) read_data_byte (&parse_entry);
verb_size = verb_sizes[(object_count >> 6) & 0x03];
parse_entry = verb_entry;
}
/* Show parse data for each verb */
tx_printf (" [");
if (parser_type < inform_gv2) {
for (j = 0; j < verb_size; j++) {
parse_data = (unsigned int) read_data_byte (&verb_entry);
tx_printf ("%02x", (unsigned int) parse_data);
if (j < (verb_size - 1))
tx_printf (" ");
}
}
else {
/* GV2 variable entry format
<flags and action high> <action low> n*(<token type> <token data 1> <token data 2>) <ENDIT>*/
for (j = 0; (j == 0) || (j%3 != 0) || (parse_data != ENDIT); j++) {
if (j != 0)
tx_printf (" ");
parse_data = (unsigned int) read_data_byte (&verb_entry);
tx_printf ("%02x", (unsigned int) parse_data);
}
verb_size = j;
}
tx_printf ("] ");
for (; j < 8; j++)
tx_printf (" ");
/* Show the verb grammar for this entry */
show_verb_grammar (parse_entry, VERB_NUM(i, parser_type), (int) parser_type, 0,
(int) prep_type, prep_table_base, attr_names_base);
tx_printf ("\n");
}
}
}
}/* show_verb_parse_table */
/* show_syntax_of_action
*
* Display the syntax entries for a given action number. Used by
* txd as well as by show_action_tables. A pre-action number works as well
* (because they are the same as action numbers), but not a parsing routine
* number (see show_syntax_of_parsing_routine)
*
*/
#ifdef __STDC__
void show_syntax_of_action( int action,
unsigned long verb_table_base,
unsigned int verb_count,
unsigned int parser_type,
unsigned int prep_type,
unsigned long prep_table_base,
unsigned long attr_names_base)
#else
void show_syntax_of_action( action,
verb_table_base,
verb_count,
parser_type,
prep_type,
prep_table_base,
attr_names_base)
int action;
unsigned long verb_table_base;
unsigned int verb_count;
unsigned int parser_type;
unsigned int prep_type;
unsigned long prep_table_base;
unsigned long attr_names_base;
#endif
{
unsigned long address;
unsigned long verb_entry, parse_entry;
unsigned int entry_count, object_count, val, action_index;
int i;
int matched = 0;
address = verb_table_base;
for (i = 0; (unsigned int) i < verb_count; i++) {
if (parser_type == infocom6_grammar) {
unsigned long do_address, doio_address;
unsigned int verb_address;
verb_address = (unsigned int)address;
parse_entry = address;
action_index = read_data_word(&address);
if (action_index == (unsigned int) action) {
show_verb_grammar (parse_entry, verb_address, (int) parser_type, 0,
(int) 0, 0L, 0L);
tx_printf ("\n");
matched = 1;
}
read_data_word(&address);
do_address = read_data_word(&address);
doio_address = read_data_word(&address);
if (do_address) {
verb_entry = do_address;
entry_count = (unsigned int) read_data_word (&verb_entry);
while (entry_count --) {
parse_entry = verb_entry;
action_index = read_data_word(&verb_entry);
if (action_index == (unsigned int) action) {
show_verb_grammar (parse_entry, verb_address, (int) parser_type, 1,
0, 0L, 0L);
tx_printf ("\n");
matched = 1;
}
verb_entry += 4; /* skip preposition and object */
}
}
if (doio_address) {
verb_entry = doio_address;
entry_count = (unsigned int) read_data_word (&verb_entry);
while (entry_count --) {
parse_entry = verb_entry;
action_index = read_data_word(&verb_entry);
if (action_index == (unsigned int) action) {
show_verb_grammar (parse_entry, verb_address, (int) parser_type, 2,
0, 0L, 0L);
tx_printf ("\n");
matched = 1;
}
verb_entry += 8; /* skip preposition and direct object and preposition and indirect object*/
}
}
}
else {
/* Get the parse data address for this entry */
verb_entry = (unsigned long) read_data_word (&address);
entry_count = (unsigned int) read_data_byte (&verb_entry);
/* Look through the sentence structures looking for a match */
while (entry_count--) {
parse_entry = verb_entry;
if (parser_type >= inform_gv2) { /* GV2, variable length with terminator */
action_index = read_data_word(&verb_entry) & 0x3FF;
val = read_data_byte(&verb_entry);
while (val != ENDIT) {
read_data_word(&verb_entry);
val = read_data_byte(&verb_entry);
}
}
else if (parser_type != infocom_variable) { /* Index is in last (8th) byte */
verb_entry += 7;
action_index = (unsigned int) read_data_byte (&verb_entry);
} else { /* Index is in second byte */
object_count = (unsigned int) read_data_byte (&verb_entry);
action_index = (unsigned int) read_data_byte (&verb_entry);
verb_entry += verb_sizes[(object_count >> 6) & 0x03] - 2;
}
/* Check if this verb/sentence structure uses the action routine */
if (action_index == (unsigned int) action) {
show_verb_grammar (parse_entry, VERB_NUM(i, parser_type), (int) parser_type, 0,
(int) prep_type, prep_table_base, attr_names_base);
tx_printf ("\n");
matched = 1;
}
}
}
}
if (!matched) {
tx_printf ("\n");
}
}
#ifdef __STDC__
int is_gv2_parsing_routine(unsigned long parsing_routine,
unsigned long verb_table_base,
unsigned int verb_count)
#else
int is_gv2_parsing_routine(parsing_routine,
verb_table_base,
verb_count)
unsigned long parsing_routine;
unsigned long verb_table_base;
unsigned int verb_count;
#endif
{
unsigned long address;
unsigned long verb_entry;
unsigned short token_data;
unsigned int entry_count, val;
int i, found;
unsigned long parsing_routine_packed = (parsing_routine - (unsigned long) story_scaler * header.routines_offset)/ code_scaler;
address = verb_table_base;
found = 0;
for (i = 0; !found && (unsigned int) i < verb_count; i++) {
/* Get the parse data address for this entry */
verb_entry = (unsigned long) read_data_word (&address);
entry_count = (unsigned int) read_data_byte (&verb_entry);
while (!found && entry_count--) {
read_data_word(&verb_entry); /* skip action # and flags */
val = (unsigned int) read_data_byte (&verb_entry);
while (val != ENDIT) {
token_data = read_data_word(&verb_entry);
if (((val & 0xC0) == 0x80) && (token_data == parsing_routine_packed))
found = 1;
val = (unsigned int) read_data_byte (&verb_entry);
}
}
}
return found;
}
/* show_syntax_of_parsing_routine
*
* Display the syntax entries for a given parsing routine number or address. Used by
* txd as well as by show_action_tables. For Inform 5 and GV1, the input should be
* the parsing routine number. For GV2, it should be the parsing routine address.
*
*/
#ifdef __STDC__
void show_syntax_of_parsing_routine(unsigned long parsing_routine,
unsigned long verb_table_base,
unsigned int verb_count,
unsigned int parser_type,
unsigned int prep_type,
unsigned long prep_table_base,
unsigned long attr_names_base)
#else
void show_syntax_of_parsing_routine(parsing_routine,
verb_table_base,
verb_count,
parser_type,
prep_type,
prep_table_base,
attr_names_base)
unsigned long parsing_routine;
unsigned long verb_table_base;
unsigned int verb_count;
unsigned int parser_type;
unsigned int prep_type;
unsigned long prep_table_base;
unsigned long attr_names_base;
#endif
{
unsigned long address;
unsigned long verb_entry, parse_entry;
unsigned short token_data;
unsigned int entry_count, object_count, val;
unsigned long parsing_routine_packed = (parsing_routine - (unsigned long) story_scaler * header.routines_offset)/ code_scaler;
int i, found;
address = verb_table_base;
for (i = 0; (unsigned int) i < verb_count; i++) {
/* Get the parse data address for this entry */
verb_entry = (unsigned long) read_data_word (&address);
entry_count = (unsigned int) read_data_byte (&verb_entry);
while (entry_count--) {
parse_entry = verb_entry;
found = 0;
if (parser_type < inform_gv2) {
object_count = (unsigned int) read_data_byte (&verb_entry);
while (object_count) {
val = (unsigned int) read_data_byte (&verb_entry);
if (val < 0xb0) {
object_count--;
if (val >= 0x10 && val < 0x70 && ((val - 0x10) & 0x1f) == (unsigned int) parsing_routine)
found = 1;
}
}
verb_entry = parse_entry + 8;
}
else {
read_data_word(&verb_entry); /* skip action # and flags */
val = (unsigned int) read_data_byte (&verb_entry);
while (val != ENDIT) {
token_data = read_data_word(&verb_entry);
if (((val & 0xC0) == 0x80) && (token_data == parsing_routine_packed)) /* V7/V6 issue here */
found = 1;
val = (unsigned int) read_data_byte (&verb_entry);
}
}
if (found) {