-
Notifications
You must be signed in to change notification settings - Fork 0
/
Quixe-channels-extended.i7x
1685 lines (1428 loc) · 53.3 KB
/
Quixe-channels-extended.i7x
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
Quixe Channels Extended (for Glulx only) by Vikar begins here.
"Quixe Channels extension to be used for making story files runnable through IF-ionic."
"Based on original Quixe Channels Core by David Cornelson"
Include Locksmith by Emily Short.
Chapter 1 - FyreVM-specific constants and definitions
[FyreVM defines a new opcode to handle the things that would otherwise be handled by @glk. These definitions allow us to use that opcode.]
Include (-
! FY_READLINE: Takes a buffer address and size and reads a line of input
! from the player. The line length is written into the word at the start
! of the buffer, and the characters are written after (starting at offset 4).
! Writes a length of 0 if the read failed.
Constant FY_READLINE = 1;
! FY_TOLOWER/FY_TOUPPER: Converts a character to lower or upper case, based
! on whichever encoding is used for the dictionary and input buffer.
Constant FY_TOLOWER = 2;
Constant FY_TOUPPER = 3;
! FY_CHANNEL: Selects an output channel.
Constant FY_CHANNEL = 4;
! FY_READKEY: Reads a single character of input, e.g. for pausing the game.
! Returns the Unicode character, or 0 if the read failed.
Constant FY_READKEY = 5;
! FY_SETVENEER: Registers a routine address or constant value with the
! interpreter's veneer acceleration system.
Constant FY_SETVENEER = 6;
! FY_TRANSITION_REQUESTED: Occurs when the game is jumping forward. Helps the UI identify how to do this.
Constant FY_REQUEST_TRANSITION = 7;
! **** Channel IO Layout ****
!
! Each channel constant is a 4 byte integer packed with 4 upper case letters.
!
! Required Channels for FY_CHANNEL.
!
Constant FYC_MAIN = ('M' * $1000000) + ('A' * $10000) + ('I' * $100) + 'N'; ! MAIN
Constant FYC_PROMPT = ('P' * $1000000) + ('R' * $10000) + ('P' * $100) + 'T'; ! PRPT
Constant FYC_LOCATION = ('L' * $1000000) + ('O' * $10000) + ('C' * $100) + 'N'; ! LOCN
Constant FYC_SCORE = ('S' * $1000000) + ('C' * $10000) + ('O' * $100) + 'R'; ! SCOR
Constant FYC_TIME = ('T' * $1000000) + ('I' * $10000) + ('M' * $100) + 'E'; ! TIME
Constant FYC_DEATH = ('D' * $1000000) + ('E' * $10000) + ('A' * $100) + 'D'; ! DEAD
Constant FYC_ENDGAME = ('E' * $1000000) + ('N' * $10000) + ('D' * $100) + 'G'; ! ENDG
Constant FYC_TURN = ('T' * $1000000) + ('U' * $10000) + ('R' * $100) + 'N'; ! TURN
Constant FYC_STORYINFO = ('I' * $1000000) + ('N' * $10000) + ('F' * $100) + 'O'; ! INFO
Constant FYC_SCORENOTIFY = ('S' * $1000000) + ('N' * $10000) + ('O' * $100) + 'T'; ! SNOT
Constant FYC_BANNER = ('B' * $1000000) + ('A' * $10000) + ('N' * $100) + 'N'; ! BANN
Constant FYC_GAMENOTIFY = ('N' * $1000000) + ('O' * $10000) + ('T' * $100) + 'F'; ! NOTF
Constant FYC_IOBJ = ('I' * $1000000) + ('O' * $10000) + ('B' * $100) + 'J'; ! IOBJ
Constant FYC_SUBJ = ('S' * $1000000) + ('U' * $10000) + ('B' * $100) + 'J'; !SUBJ
Constant FYC_PROLOGUE = ('P' * $1000000) + ('L' * $10000) + ('O' * $100) + 'G'; !PLOG
Constant FYC_COMMANDS = ('C' * $1000000) + ('O' * $10000) + ('M' * $100) + 'M'; !COMM
Constant FYC_DIALOGUE = ('D' * $1000000) + ('L' * $10000) + ('O' * $100) + 'G'; !DLOG
Constant FYC_DIRECTIONS = ('D' * $1000000) + ('I' * $10000) + ('R' * $100) + 'T'; !DIRT
! Slots for FY_SETVENEER.
Constant FYV_Z__Region = 1;
Constant FYV_CP__Tab = 2;
Constant FYV_OC__Cl = 3;
Constant FYV_RA__Pr = 4;
Constant FYV_RT__ChLDW = 5;
Constant FYV_Unsigned__Compare = 6;
Constant FYV_RL__Pr = 7;
Constant FYV_RV__Pr = 8;
Constant FYV_OP__Pr = 9;
Constant FYV_RT__ChSTW = 10;
Constant FYV_RT__ChLDB = 11;
Constant FYV_Meta__class = 12;
Constant FYV_String = 1001;
Constant FYV_Routine = 1002;
Constant FYV_Class = 1003;
Constant FYV_Object = 1004;
Constant FYV_RT__Err = 1005;
Constant FYV_NUM_ATTR_BYTES = 1006;
Constant FYV_classes_table = 1007;
Constant FYV_INDIV_PROP_START = 1008;
Constant FYV_cpv__start = 1009;
Constant FYV_ofclass_err = 1010;
Constant FYV_readprop_err = 1011;
[ FyreCall a b c res; @"S4:4096" a b c res; return res; ];
-).
[These activate FyreVM's veneer optimizations.]
Include (-
[ REGISTER_VENEER_R;
@gestalt 4 20 is_fyrevm; ! Test if this interpreter has FyreVM channels
if (~~is_fyrevm) rfalse;
FyreCall(FY_SETVENEER, FYV_Z__Region, Z__Region);
FyreCall(FY_SETVENEER, FYV_CP__Tab, CP__Tab);
FyreCall(FY_SETVENEER, FYV_OC__Cl, OC__Cl);
FyreCall(FY_SETVENEER, FYV_RA__Pr, RA__Pr);
FyreCall(FY_SETVENEER, FYV_Unsigned__Compare, Unsigned__Compare);
FyreCall(FY_SETVENEER, FYV_RL__Pr, RL__Pr);
FyreCall(FY_SETVENEER, FYV_RV__Pr, RV__Pr);
FyreCall(FY_SETVENEER, FYV_OP__Pr, OP__Pr);
FyreCall(FY_SETVENEER, FYV_Meta__class, Meta__class);
#ifdef STRICT_MODE;
FyreCall(FY_SETVENEER, FYV_RT__ChLDW, RT__ChLDW);
FyreCall(FY_SETVENEER, FYV_RT__ChSTW, RT__ChSTW);
FyreCall(FY_SETVENEER, FYV_RT__ChLDB, RT__ChLDB);
#endif;
FyreCall(FY_SETVENEER, FYV_String, String);
FyreCall(FY_SETVENEER, FYV_Routine, Routine);
FyreCall(FY_SETVENEER, FYV_Class, Class);
FyreCall(FY_SETVENEER, FYV_Object, Object);
FyreCall(FY_SETVENEER, FYV_RT__Err, RT__Err);
FyreCall(FY_SETVENEER, FYV_NUM_ATTR_BYTES, NUM_ATTR_BYTES);
FyreCall(FY_SETVENEER, FYV_classes_table, #classes_table);
FyreCall(FY_SETVENEER, FYV_INDIV_PROP_START, INDIV_PROP_START);
FyreCall(FY_SETVENEER, FYV_cpv__start, #cpv__start);
FyreCall(FY_SETVENEER, FYV_ofclass_err, "apply 'ofclass' for");
FyreCall(FY_SETVENEER, FYV_readprop_Err, "read");
];
-).
The register veneer routines rule translates into I6 as "REGISTER_VENEER_R".
To decide whether FyreVM is present: (- (is_fyrevm) -). [This global variable is defined below, before VM_Initialise.]
To decide whether FyreVM is not present: (- (~~is_fyrevm) -).
After starting the virtual machine: follow the register veneer routines rule.
[And these set up an alternative way to print text into an array, since Inform's default way of doing that requires Glk. FyreVM includes a Glk wrapper which could theoretically support that, but it's only active when the Glk output system is selected.]
Include (-
Global output_buffer_address;
Global output_buffer_size;
Global output_buffer_pos;
Global output_buffer_uni;
Constant MAX_OUTPUT_NESTING = 32;
Array output_buffer_stack --> (MAX_OUTPUT_NESTING * 4);
Global output_buffer_sp = 0;
[ OpenOutputBufferUnicode buffer size;
output_buffer_stack-->(output_buffer_sp++) = output_buffer_address;
output_buffer_stack-->(output_buffer_sp++) = output_buffer_size;
output_buffer_stack-->(output_buffer_sp++) = output_buffer_pos;
output_buffer_stack-->(output_buffer_sp++) = output_buffer_uni;
output_buffer_address = buffer;
output_buffer_size = size;
output_buffer_pos = 0;
output_buffer_uni = 1;
@setiosys 1 _OutputBufferProcUni;
];
[ OpenOutputBuffer buffer size;
output_buffer_stack-->(output_buffer_sp++) = output_buffer_address;
output_buffer_stack-->(output_buffer_sp++) = output_buffer_size;
output_buffer_stack-->(output_buffer_sp++) = output_buffer_pos;
output_buffer_stack-->(output_buffer_sp++) = output_buffer_uni;
output_buffer_address = buffer;
output_buffer_size = size;
output_buffer_pos = 0;
output_buffer_uni = 0;
@setiosys 1 _OutputBufferProc;
];
[ CloseOutputBuffer results rv;
if (results) {
results-->0 = 0;
results-->1 = output_buffer_pos;
}
rv = output_buffer_pos;
ResumeOutputBuffer();
return rv;
];
[ SuspendOutputBuffer;
output_buffer_stack-->(output_buffer_sp++) = output_buffer_address;
output_buffer_stack-->(output_buffer_sp++) = output_buffer_size;
output_buffer_stack-->(output_buffer_sp++) = output_buffer_pos;
output_buffer_stack-->(output_buffer_sp++) = output_buffer_uni;
@setiosys 20 0;
];
[ ResumeOutputBuffer;
output_buffer_uni = output_buffer_stack-->(--output_buffer_sp);
output_buffer_pos = output_buffer_stack-->(--output_buffer_sp);
output_buffer_size = output_buffer_stack-->(--output_buffer_sp);
output_buffer_address = output_buffer_stack-->(--output_buffer_sp);
if (output_buffer_sp > 0) {
if (output_buffer_uni)
@setiosys 1 _OutputBufferProcUni;
else
@setiosys 1 _OutputBufferProc;
} else
@setiosys 20 0;
];
[ _OutputBufferProcUni ch;
if (output_buffer_pos < output_buffer_size)
output_buffer_address-->output_buffer_pos = ch;
output_buffer_pos++;
];
[ _OutputBufferProc ch;
if (output_buffer_pos < output_buffer_size)
output_buffer_address->output_buffer_pos = ch;
output_buffer_pos++;
];
-).
Chapter 2 - Template replacements
Section 1 - Glulx segment
Include (-
Global is_fyrevm = 0;
[ VM_PreInitialise res;
@gestalt 4 20 is_fyrevm; ! Test if this interpreter has FyreVM channels
if (is_fyrevm) {
! If so, we can skip all the Glk business
unicode_gestalt_ok = true;
@setiosys 20 0;
return;
}
];
[ VM_Initialise res;
@gestalt 4 20 is_fyrevm; ! Test if this interpreter has FyreVM channels
if (is_fyrevm) {
! If so, we can skip all the Glk business
unicode_gestalt_ok = true;
@setiosys 20 0;
return;
}
@gestalt 4 2 res; ! Test if this interpreter has Glk...
if (res == 0) quit; ! ...without which there would be nothing we could do
unicode_gestalt_ok = false;
if (glk_gestalt(gestalt_Unicode, 0))
unicode_gestalt_ok = true;
! Set the VM's I/O system to be Glk.
@setiosys 2 0;
! First, we must go through all the Glk objects that exist, and see
! if we created any of them. One might think this strange, since the
! program has just started running, but remember that the player might
! have just typed "restart".
GGRecoverObjects();
res = InitGlkWindow(0);
if (res ~= 0) return;
! Now, gg_mainwin and gg_storywin might already be set. If not, set them.
if (gg_mainwin == 0) {
! Open the story window.
res = InitGlkWindow(GG_MAINWIN_ROCK);
if (res == 0) {
glk_stylehint_set(3, 3, 2, 0); ! left-justify style_Header
gg_mainwin = glk_window_open(0, 0, 0, 3, GG_MAINWIN_ROCK);
}
if (gg_mainwin == 0) quit; ! If we can't even open one window, give in
}
else {
! There was already a story window. We should erase it.
glk_window_clear(gg_mainwin);
}
if (gg_statuswin == 0) {
res = InitGlkWindow(GG_STATUSWIN_ROCK);
if (res == 0) {
statuswin_cursize = statuswin_size;
for (res=0: res<=10: res++)
glk_stylehint_set(4, res, 9, 1); ! enable ReverseColor
gg_statuswin = glk_window_open(gg_mainwin, $12, statuswin_cursize,
4, GG_STATUSWIN_ROCK);
}
}
! It's possible that the status window couldn't be opened, in which case
! gg_statuswin is now zero. We must allow for that later on.
glk_set_window(gg_mainwin);
InitGlkWindow(1);
if (glk_gestalt(gestalt_Sound, 0)) {
if (gg_foregroundchan == 0)
gg_foregroundchan = glk_schannel_create(GG_FOREGROUNDCHAN_ROCK);
if (gg_backgroundchan == 0)
gg_backgroundchan = glk_schannel_create(GG_BACKGROUNDCHAN_ROCK);
}
glk_stylehint_set(wintype_TextBuffer, style_Emphasized, stylehint_Weight, 0);
glk_stylehint_set(wintype_TextBuffer, style_Emphasized, stylehint_Oblique, 1);
#ifdef FIX_RNG;
@random 10000 i;
i = -i-2000;
print "[Random number generator seed is ", i, "]^";
@setrandom i;
#endif; ! FIX_RNG
];
[ GGRecoverObjects id;
! If GGRecoverObjects() has been called, all these stored IDs are
! invalid, so we start by clearing them all out.
! (In fact, after a restoreundo, some of them may still be good.
! For simplicity, though, we assume the general case.)
gg_mainwin = 0;
gg_statuswin = 0;
gg_quotewin = 0;
gg_scriptfref = 0;
gg_scriptstr = 0;
gg_savestr = 0;
statuswin_cursize = 0;
#Ifdef DEBUG;
gg_commandstr = 0;
gg_command_reading = false;
#Endif; ! DEBUG
! Also tell the game to clear its object references.
IdentifyGlkObject(0);
! Check for FyreVM
@gestalt 4 20 is_fyrevm;
if (is_fyrevm) return;
id = glk_stream_iterate(0, gg_arguments);
while (id) {
switch (gg_arguments-->0) {
GG_SAVESTR_ROCK: gg_savestr = id;
GG_SCRIPTSTR_ROCK: gg_scriptstr = id;
#Ifdef DEBUG;
GG_COMMANDWSTR_ROCK: gg_commandstr = id;
gg_command_reading = false;
GG_COMMANDRSTR_ROCK: gg_commandstr = id;
gg_command_reading = true;
#Endif; ! DEBUG
default: IdentifyGlkObject(1, 1, id, gg_arguments-->0);
}
id = glk_stream_iterate(id, gg_arguments);
}
id = glk_window_iterate(0, gg_arguments);
while (id) {
switch (gg_arguments-->0) {
GG_MAINWIN_ROCK: gg_mainwin = id;
GG_STATUSWIN_ROCK: gg_statuswin = id;
GG_QUOTEWIN_ROCK: gg_quotewin = id;
default: IdentifyGlkObject(1, 0, id, gg_arguments-->0);
}
id = glk_window_iterate(id, gg_arguments);
}
id = glk_fileref_iterate(0, gg_arguments);
while (id) {
switch (gg_arguments-->0) {
GG_SCRIPTFREF_ROCK: gg_scriptfref = id;
default: IdentifyGlkObject(1, 2, id, gg_arguments-->0);
}
id = glk_fileref_iterate(id, gg_arguments);
}
! Tell the game to tie up any loose ends.
IdentifyGlkObject(2);
];
-) instead of "Starting Up" in "Glulx.i6t".
Include (-
[ VM_KeyChar win nostat done res ix jx ch;
if (is_fyrevm) return FyreCall(FY_READKEY);
jx = ch; ! squash compiler warnings
if (win == 0) win = gg_mainwin;
if (gg_commandstr ~= 0 && gg_command_reading ~= false) {
done = glk_get_line_stream(gg_commandstr, gg_arguments, 31);
if (done == 0) {
glk_stream_close(gg_commandstr);
gg_commandstr = 0;
gg_command_reading = false;
! fall through to normal user input.
} else {
! Trim the trailing newline
if (gg_arguments->(done-1) == 10) done = done-1;
res = gg_arguments->0;
if (res == '\') {
res = 0;
for (ix=1 : ix<done : ix++) {
ch = gg_arguments->ix;
if (ch >= '0' && ch <= '9') {
@shiftl res 4 res;
res = res + (ch-'0');
} else if (ch >= 'a' && ch <= 'f') {
@shiftl res 4 res;
res = res + (ch+10-'a');
} else if (ch >= 'A' && ch <= 'F') {
@shiftl res 4 res;
res = res + (ch+10-'A');
}
}
}
jump KCPContinue;
}
}
done = false;
glk_request_char_event(win);
while (~~done) {
glk_select(gg_event);
switch (gg_event-->0) {
5: ! evtype_Arrange
if (nostat) {
glk_cancel_char_event(win);
res = $80000000;
done = true;
break;
}
DrawStatusLine();
2: ! evtype_CharInput
if (gg_event-->1 == win) {
res = gg_event-->2;
done = true;
}
}
ix = HandleGlkEvent(gg_event, 1, gg_arguments);
if (ix == 2) {
res = gg_arguments-->0;
done = true;
} else if (ix == -1) done = false;
}
if (gg_commandstr ~= 0 && gg_command_reading == false) {
if (res < 32 || res >= 256 || (res == '\' or ' ')) {
glk_put_char_stream(gg_commandstr, '\');
done = 0;
jx = res;
for (ix=0 : ix<8 : ix++) {
@ushiftr jx 28 ch;
@shiftl jx 4 jx;
ch = ch & $0F;
if (ch ~= 0 || ix == 7) done = 1;
if (done) {
if (ch >= 0 && ch <= 9) ch = ch + '0';
else ch = (ch - 10) + 'A';
glk_put_char_stream(gg_commandstr, ch);
}
}
} else {
glk_put_char_stream(gg_commandstr, res);
}
glk_put_char_stream(gg_commandstr, 10); ! newline
}
.KCPContinue;
return res;
];
[ VM_KeyDelay tenths key done ix;
if (is_fyrevm) rfalse; ! FyreVM doesn't support timed input
glk_request_char_event(gg_mainwin);
glk_request_timer_events(tenths*100);
while (~~done) {
glk_select(gg_event);
ix = HandleGlkEvent(gg_event, 1, gg_arguments);
if (ix == 2) {
key = gg_arguments-->0;
done = true;
}
else if (ix >= 0 && gg_event-->0 == 1 or 2) {
key = gg_event-->2;
done = true;
}
}
glk_cancel_char_event(gg_mainwin);
glk_request_timer_events(0);
return key;
];
[ VM_ReadKeyboard a_buffer a_table done ix;
if (is_fyrevm) {
FyreCall(FY_READLINE, a_buffer, INPUT_BUFFER_LEN);
jump KPContinue;
}
if (gg_commandstr ~= 0 && gg_command_reading ~= false) {
done = glk_get_line_stream(gg_commandstr, a_buffer+WORDSIZE,
(INPUT_BUFFER_LEN-WORDSIZE)-1);
if (done == 0) {
glk_stream_close(gg_commandstr);
gg_commandstr = 0;
gg_command_reading = false;
! L__M(##CommandsRead, 5); would come after prompt
! fall through to normal user input.
}
else {
! Trim the trailing newline
if ((a_buffer+WORDSIZE)->(done-1) == 10) done = done-1;
a_buffer-->0 = done;
VM_Style(INPUT_VMSTY);
glk_put_buffer(a_buffer+WORDSIZE, done);
VM_Style(NORMAL_VMSTY);
print "^";
jump KPContinue;
}
}
done = false;
glk_request_line_event(gg_mainwin, a_buffer+WORDSIZE, INPUT_BUFFER_LEN-WORDSIZE, 0);
while (~~done) {
glk_select(gg_event);
switch (gg_event-->0) {
5: ! evtype_Arrange
DrawStatusLine();
3: ! evtype_LineInput
if (gg_event-->1 == gg_mainwin) {
a_buffer-->0 = gg_event-->2;
done = true;
}
}
ix = HandleGlkEvent(gg_event, 0, a_buffer);
if (ix == 2) done = true;
else if (ix == -1) done = false;
}
if (gg_commandstr ~= 0 && gg_command_reading == false) {
glk_put_buffer_stream(gg_commandstr, a_buffer+WORDSIZE, a_buffer-->0);
glk_put_char_stream(gg_commandstr, 10); ! newline
}
.KPContinue;
VM_Tokenise(a_buffer,a_table);
! It's time to close any quote window we've got going.
if (gg_quotewin) {
glk_window_close(gg_quotewin, 0);
gg_quotewin = 0;
}
#ifdef ECHO_COMMANDS;
print "** ";
for (ix=WORDSIZE: ix<(a_buffer-->0)+WORDSIZE: ix++) print (char) a_buffer->ix;
print "^";
#endif; ! ECHO_COMMANDS
];
-) instead of "Keyboard Input" in "Glulx.i6t".
Include (-
[ VM_Picture resource_ID;
if ((~~is_fyrevm) && glk_gestalt(gestalt_Graphics, 0)) {
glk_image_draw(gg_mainwin, resource_ID, imagealign_InlineCenter, 0);
} else {
print "[Picture number ", resource_ID, " here.]^";
}
];
[ VM_SoundEffect resource_ID;
if ((~~is_fyrevm) && glk_gestalt(gestalt_Sound, 0)) {
glk_schannel_play(gg_foregroundchan, resource_ID);
} else {
print "[Sound effect number ", resource_ID, " here.]^";
}
];
-) instead of "Audiovisual Resources" in "Glulx.i6t".
[ FyreVM does not do anything about styles. This has to be managed in the game file with markup. ]
Include (-
[ VM_Style sty;
if (~~is_fyrevm) {
switch (sty) {
NORMAL_VMSTY: glk_set_style(style_Normal);
HEADER_VMSTY: glk_set_style(style_Header);
SUBHEADER_VMSTY: glk_set_style(style_Subheader);
NOTE_VMSTY: glk_set_style(style_Note);
ALERT_VMSTY: glk_set_style(style_Alert);
BLOCKQUOTE_VMSTY: glk_set_style(style_BlockQuote);
INPUT_VMSTY: glk_set_style(style_Input);
}
}
];
-) instead of "Typography" in "Glulx.i6t".
Include (-
[ VM_UpperToLowerCase c;
if (is_fyrevm) return FyreCall(FY_TOLOWER, c);
return glk_char_to_lower(c);
];
[ VM_LowerToUpperCase c;
if (is_fyrevm) return FyreCall(FY_TOUPPER, c);
return glk_char_to_upper(c);
];
-) instead of "Character Casing" in "Glulx.i6t".
Include (-
! Glulx_PrintAnything() <nothing printed>
! Glulx_PrintAnything(0) <nothing printed>
! Glulx_PrintAnything("string"); print (string) "string";
! Glulx_PrintAnything('word') print (address) 'word';
! Glulx_PrintAnything(obj) print (name) obj;
! Glulx_PrintAnything(obj, prop) obj.prop();
! Glulx_PrintAnything(obj, prop, args...) obj.prop(args...);
! Glulx_PrintAnything(func) func();
! Glulx_PrintAnything(func, args...) func(args...);
[ Glulx_PrintAnything _vararg_count obj mclass;
if (_vararg_count == 0) return;
@copy sp obj;
_vararg_count--;
if (obj == 0) return;
if (obj->0 == $60) {
! Dictionary word. Metaclass() can't catch this case, so we do it manually
print (address) obj;
return;
}
mclass = metaclass(obj);
switch (mclass) {
nothing:
return;
String:
print (string) obj;
return;
Routine:
! Call the function with all the arguments which are already
! on the stack.
@call obj _vararg_count 0;
return;
Object:
if (_vararg_count == 0) {
print (name) obj;
}
else {
! Push the object back onto the stack, and call the
! veneer routine that handles obj.prop() calls.
@copy obj sp;
_vararg_count++;
@call CA__Pr _vararg_count 0;
}
return;
}
];
[ Glulx_PrintAnyToArray _vararg_count arr arrlen str oldstr len;
@copy sp arr;
@copy sp arrlen;
_vararg_count = _vararg_count - 2;
if (is_fyrevm) {
OpenOutputBuffer(arr, arrlen);
} else {
oldstr = glk_stream_get_current();
str = glk_stream_open_memory(arr, arrlen, 1, 0);
if (str == 0) return 0;
glk_stream_set_current(str);
}
@call Glulx_PrintAnything _vararg_count 0;
if (is_fyrevm) {
len = CloseOutputBuffer(0);
} else {
glk_stream_set_current(oldstr);
@copy $ffffffff sp;
@copy str sp;
@glk $0044 2 0; ! stream_close
@copy sp len;
@copy sp 0;
}
return len;
];
Constant GG_ANYTOSTRING_LEN 66;
Array AnyToStrArr -> GG_ANYTOSTRING_LEN+1;
[ Glulx_ChangeAnyToCString _vararg_count ix len;
ix = GG_ANYTOSTRING_LEN-2;
@copy ix sp;
ix = AnyToStrArr+1;
@copy ix sp;
ix = _vararg_count+2;
@call Glulx_PrintAnyToArray ix len;
AnyToStrArr->0 = $E0;
if (len >= GG_ANYTOSTRING_LEN)
len = GG_ANYTOSTRING_LEN-1;
AnyToStrArr->(len+1) = 0;
return AnyToStrArr;
];
-) instead of "Glulx-Only Printing Routines" in "Glulx.i6t".
Include (-
[ VM_ClearScreen window;
if (is_fyrevm) return; ! not supported
if (window == WIN_ALL or WIN_MAIN) {
glk_window_clear(gg_mainwin);
if (gg_quotewin) {
glk_window_close(gg_quotewin, 0);
gg_quotewin = 0;
}
}
if (gg_statuswin && window == WIN_ALL or WIN_STATUS) glk_window_clear(gg_statuswin);
];
[ VM_ScreenWidth id;
if (is_fyrevm) return 80; ! not supported
id=gg_mainwin;
if (gg_statuswin && statuswin_current) id = gg_statuswin;
glk_window_get_size(id, gg_arguments, 0);
return gg_arguments-->0;
];
[ VM_ScreenHeight;
if (is_fyrevm) return 25; ! not supported
glk_window_get_size(gg_mainwin, 0, gg_arguments);
return gg_arguments-->0;
];
-) instead of "The Screen" in "Glulx.i6t".
Include (-
[ VM_SetWindowColours f b window doclear i fwd bwd swin;
if (is_fyrevm) return; ! not supported
if (clr_on && f && b) {
if (window) swin = 5-window; ! 4 for TextGrid, 3 for TextBuffer
fwd = MakeColourWord(f);
bwd = MakeColourWord(b);
for (i=0 : i<=10: i++) {
if (f == CLR_DEFAULT || b == CLR_DEFAULT) { ! remove style hints
glk_stylehint_clear(swin, i, 7);
glk_stylehint_clear(swin, i, 8);
} else {
glk_stylehint_set(swin, i, 7, fwd);
glk_stylehint_set(swin, i, 8, bwd);
}
}
! Now re-open the windows to apply the hints
if (gg_statuswin) glk_window_close(gg_statuswin, 0);
if (doclear || ( window ~= 1 && (clr_fg ~= f || clr_bg ~= b) ) ) {
glk_window_close(gg_mainwin, 0);
gg_mainwin = glk_window_open(0, 0, 0, 3, GG_MAINWIN_ROCK);
if (gg_scriptstr ~= 0)
glk_window_set_echo_stream(gg_mainwin, gg_scriptstr);
}
gg_statuswin =
glk_window_open(gg_mainwin, $12, statuswin_cursize, 4, GG_STATUSWIN_ROCK);
if (statuswin_current && gg_statuswin) VM_MoveCursorInStatusLine(); else VM_MainWindow();
if (window ~= 2) {
clr_fgstatus = f;
clr_bgstatus = b;
}
if (window ~= 1) {
clr_fg = f;
clr_bg = b;
}
}
];
[ VM_RestoreWindowColours; ! used after UNDO: compare I6 patch L61007
if (is_fyrevm) return; ! not supported
if (clr_on) { ! check colour has been used
VM_SetWindowColours(clr_fg, clr_bg, 2); ! make sure both sets of variables are restored
VM_SetWindowColours(clr_fgstatus, clr_bgstatus, 1, true);
VM_ClearScreen();
}
];
[ MakeColourWord c;
if (c > 9) return c;
c = c-2;
return $ff0000*(c&1) + $ff00*(c&2 ~= 0) + $ff*(c&4 ~= 0);
];
-) instead of "Window Colours" in "Glulx.i6t".
Include (-
[ VM_MainWindow;
if (is_fyrevm) return; ! not supported
glk_set_window(gg_mainwin); ! set_window
statuswin_current=0;
];
-) instead of "Main Window" in "Glulx.i6t".
Include (-
[ VM_StatusLineHeight hgt;
if (is_fyrevm) return; ! not supported
if (gg_statuswin == 0) return;
if (hgt == statuswin_cursize) return;
glk_window_set_arrangement(glk_window_get_parent(gg_statuswin), $12, hgt, 0);
statuswin_cursize = hgt;
];
[ VM_MoveCursorInStatusLine line column;
if (is_fyrevm) return; ! not supported
if (gg_statuswin) glk_set_window(gg_statuswin);
if (line == 0) { line = 1; column = 1; }
glk_window_move_cursor(gg_statuswin, column-1, line-1);
statuswin_current=1;
];
-) instead of "Status Line" in "Glulx.i6t".
Include (-
[ Box__Routine maxwid arr ix lines lastnl parwin;
if (is_fyrevm) return; ! not supported
maxwid = 0; ! squash compiler warning
lines = arr-->0;
if (gg_quotewin == 0) {
gg_arguments-->0 = lines;
ix = InitGlkWindow(GG_QUOTEWIN_ROCK);
if (ix == 0)
gg_quotewin =
glk_window_open(gg_mainwin, $12, lines, 3, GG_QUOTEWIN_ROCK);
} else {
parwin = glk_window_get_parent(gg_quotewin);
glk_window_set_arrangement(parwin, $12, lines, 0);
}
lastnl = true;
if (gg_quotewin) {
glk_window_clear(gg_quotewin);
glk_set_window(gg_quotewin);
lastnl = false;
}
VM_Style(BLOCKQUOTE_VMSTY);
for (ix=0 : ix<lines : ix++) {
print (string) arr-->(ix+1);
if (ix < lines-1 || lastnl) new_line;
}
VM_Style(NORMAL_VMSTY);
if (gg_quotewin) glk_set_window(gg_mainwin);
];
-) instead of "Quotation Boxes" in "Glulx.i6t".
Include (-
#Ifdef DEBUG;
[ GlkListSub id val;
if (is_fyrevm) {
print "Glk is not used with this interpreter.^";
return;
}
id = glk_window_iterate(0, gg_arguments);
while (id) {
print "Window ", id, " (", gg_arguments-->0, "): ";
val = glk_window_get_type(id);
switch (val) {
1: print "pair";
2: print "blank";
3: print "textbuffer";
4: print "textgrid";
5: print "graphics";
default: print "unknown";
}
val = glk_window_get_parent(id);
if (val) print ", parent is window ", val;
else print ", no parent (root)";
val = glk_window_get_stream(id);
print ", stream ", val;
val = glk_window_get_echo_stream(id);
if (val) print ", echo stream ", val;
print "^";
id = glk_window_iterate(id, gg_arguments);
}
id = glk_stream_iterate(0, gg_arguments);
while (id) {
print "Stream ", id, " (", gg_arguments-->0, ")^";
id = glk_stream_iterate(id, gg_arguments);
}
id = glk_fileref_iterate(0, gg_arguments);
while (id) {
print "Fileref ", id, " (", gg_arguments-->0, ")^";
id = glk_fileref_iterate(id, gg_arguments);
}
if (glk_gestalt(gestalt_Sound, 0)) {
id = glk_schannel_iterate(0, gg_arguments);
while (id) {
print "Soundchannel ", id, " (", gg_arguments-->0, ")^";
id = glk_schannel_iterate(id, gg_arguments);
}
}
];
Verb meta 'glklist'
* -> Glklist;
#Endif;
-) instead of "GlkList Command" in "Glulx.i6t".
Include (-
[ QUIT_THE_GAME_R;
if (actor ~= player) rfalse;
if (is_fyrevm) FyreCall(FY_CHANNEL, FYC_PROMPT);
if ((actor == player) && (untouchable_silence == false))
QUIT_THE_GAME_RM('A');
if (is_fyrevm) FyreCall(FY_CHANNEL, FYC_MAIN);
if (YesOrNo()~=0) quit;
];
-) instead of "Quit The Game Rule" in "Glulx.i6t".
Include (-
[ RESTART_THE_GAME_R;
if (actor ~= player) rfalse;
if (is_fyrevm) FyreCall(FY_CHANNEL, FYC_PROMPT);
RESTART_THE_GAME_RM('A');
if (is_fyrevm) FyreCall(FY_CHANNEL, FYC_MAIN);
if (YesOrNo()~=0) {
@restart;
RESTART_THE_GAME_RM('B'); new_line;
}
];
-) instead of "Restart The Game Rule" in "Glulx.i6t".
Include (-
[ RESTORE_THE_GAME_R res fref;
if (actor ~= player) rfalse;
if (is_fyrevm) {
@restore 0 res;
} else {
fref = glk_fileref_create_by_prompt($01, $02, 0);
if (fref == 0) jump RFailed;
gg_savestr = glk_stream_open_file(fref, $02, GG_SAVESTR_ROCK);
glk_fileref_destroy(fref);
if (gg_savestr == 0) jump RFailed;
@restore gg_savestr res;
glk_stream_close(gg_savestr, 0);
gg_savestr = 0;
}
.RFailed;
RESTORE_THE_GAME_RM('A'); new_line;
];
-) instead of "Restore The Game Rule" in "Glulx.i6t".
Include (-
[ SAVE_THE_GAME_R res fref;
if (actor ~= player) rfalse;
if (is_fyrevm) {
@save 0 res;
if (res == -1) {
! The player actually just typed "restore". We're going to print
! GL__M(##Restore,2); the Z-Code Inform library does this correctly
! now. But first, we have to recover all the Glk objects; the values
! in our global variables are all wrong.
GGRecoverObjects();
RESTORE_THE_GAME_RM('B'); new_line;
rtrue;
}
} else {
fref = glk_fileref_create_by_prompt($01, $01, 0);
if (fref == 0) jump SFailed;
gg_savestr = glk_stream_open_file(fref, $01, GG_SAVESTR_ROCK);
glk_fileref_destroy(fref);
if (gg_savestr == 0) jump SFailed;
@save gg_savestr res;
if (res == -1) {
! The player actually just typed "restore". We first have to recover
! all the Glk objects; the values in our global variables are all wrong.
GGRecoverObjects();
glk_stream_close(gg_savestr, 0); ! stream_close
gg_savestr = 0;
RESTORE_THE_GAME_RM('B'); new_line;
rtrue;
}
glk_stream_close(gg_savestr, 0); ! stream_close
gg_savestr = 0;
}
if (res == 0) { SAVE_THE_GAME_RM('B'); new_line; rtrue; }
.SFailed;
SAVE_THE_GAME_RM('A'); new_line;
];
-) instead of "Save The Game Rule" in "Glulx.i6t".
Include (-
[ SWITCH_TRANSCRIPT_ON_R;
if (actor ~= player) rfalse;
if (is_fyrevm) {
print "Transcripting is not available with this interpreter.^";
return;
}
if (gg_scriptstr ~= 0) { SWITCH_TRANSCRIPT_ON_RM('A'); new_line; rtrue; }
if (gg_scriptfref == 0) {
gg_scriptfref = glk_fileref_create_by_prompt($102, $05, GG_SCRIPTFREF_ROCK);
if (gg_scriptfref == 0) jump S1Failed;
}
! stream_open_file
gg_scriptstr = glk_stream_open_file(gg_scriptfref, $05, GG_SCRIPTSTR_ROCK);
if (gg_scriptstr == 0) jump S1Failed;
glk_window_set_echo_stream(gg_mainwin, gg_scriptstr);
SWITCH_TRANSCRIPT_ON_RM('B'); new_line;
VersionSub();
return;
.S1Failed;
SWITCH_TRANSCRIPT_ON_RM('C'); new_line;
];
-) instead of "Switch Transcript On Rule" in "Glulx.i6t".
Include (-
[ SWITCH_TRANSCRIPT_OFF_R;
if (actor ~= player) rfalse;