-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtext.c
1213 lines (1029 loc) · 29.5 KB
/
text.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
/* $Id: text.c,v 1.5 2000/10/10 14:46:22 jholder Exp $
* --------------------------------------------------------------------
* see doc/License.txt for License Information
* --------------------------------------------------------------------
*
* File name: $Id: text.c,v 1.5 2000/10/10 14:46:22 jholder Exp $
*
* Description:
*
* Modification history:
* $Log: text.c,v $
* Revision 1.5 2000/10/10 14:46:22 jholder
* Fixed text wrap bug when printing array w/ \r chars in it
*
* Revision 1.4 2000/10/04 23:07:57 jholder
* fixed redirect problem with isolatin1 range chars
*
* Revision 1.3 2000/07/05 15:20:34 jholder
* Updated code to remove warnings.
*
* Revision 1.2 2000/05/25 22:28:56 jholder
* changes routine names to reflect zmachine opcode names per spec 1.0
*
* Revision 1.1.1.1 2000/05/10 14:21:34 jholder
*
* imported
*
*
* --------------------------------------------------------------------
*/
/*
* text.c
*
* Text manipulation routines
*
*/
#include "ztypes.h"
static int saved_formatting = ON;
static int story_buffer = 0;
static int story_pos = 0;
static int story_count = 0;
static int line_pos = 0;
/*
* decode_text
*
* Convert ZSCII encoded text to ASCII. Text is encoded by squeezing each character
* into 5 bits. 3 x 5 bit encoded characters can fit in one word with a spare
* bit left over. The spare bit is used to signal to end of a string. The 5 bit
* encoded characters can either be actual character codes or prefix codes that
* modifier the following code.
*
*/
void decode_text( unsigned long *address )
{
int i, synonym_flag, synonym = 0, zscii_flag, zscii = 0;
int data, code, shift_state, shift_lock;
unsigned long addr;
/* Set state variables */
shift_state = 0;
shift_lock = 0;
zscii_flag = 0;
synonym_flag = 0;
do
{
/*
* Read one 16 bit word. Each word contains three 5 bit codes. If the
* high bit is set then this is the last word in the string.
*/
data = read_data_word( address );
for ( i = 10; i >= 0; i -= 5 )
{
/* Get code, high bits first */
code = ( data >> i ) & 0x1f;
/* Synonym codes */
if ( synonym_flag )
{
synonym_flag = 0;
synonym = ( synonym - 1 ) * 64;
addr = ( unsigned long ) get_word( h_synonyms_offset + synonym + ( code * 2 ) ) * 2;
decode_text( &addr );
shift_state = shift_lock;
}
/* ZSCII codes */
else if ( zscii_flag )
{
/*
* If this is the first part ZSCII ten-bit code then remember it.
* Because the codes are only 5 bits you need two codes to make
* one eight bit ASCII character. The first code contains the
* top 5 bits (although only 3 bits are used at the moment).
* The second code contains the bottom 5 bits.
*/
if ( zscii_flag++ == 1 )
{
zscii = code << 5;
}
/*
* If this is the second part of a ten-bit ZSCII code then assemble the
* character from the two codes and output it.
*/
else
{
zscii_flag = 0;
write_zchar( ( unsigned char ) ( zscii | code ) );
}
}
/* Character codes */
else if ( code > 5 )
{
code -= 6;
/*
* If this is character 0 in the punctuation set then the next two
* codes make a ten-bit ZSCII character. (Std. Sec. 3.4)
*/
if ( shift_state == 2 && code == 0 )
{
zscii_flag = 1;
}
/*
* If this is character 1 in the punctuation set then this
* is a new line.
*/
else if ( shift_state == 2 && code == 1 && h_type > V1 )
{
z_new_line( );
}
/*
* This is a normal character so select it from the character
* table appropriate for the current shift state.
*/
else
{
write_zchar( lookup_table[shift_state][code] );
}
shift_state = shift_lock;
}
/* Special codes 0 to 5 */
else
{
/* Space: 0 Output a space character. */
if ( code == 0 )
{
write_zchar( ' ' );
}
else
{
/* The use of the synonym and shift codes is the only
* difference between the different versions.
*/
if ( h_type < V3 )
{
/* Newline or synonym: 1
* Output a newline character or set synonym flag.
*/
if ( code == 1 )
{
if ( h_type == V1 )
{
z_new_line( );
}
else
{
synonym_flag = 1;
synonym = code;
}
}
else
{
/*
* Shift keys: 2, 3, 4 or 5
*
* Shift keys 2 & 3 only shift the next character and can be used regardless of
* the state of the shift lock. Shift keys 4 & 5 lock the shift until reset.
*
* The following code implements the the shift code state transitions:
* +-------------+-------------+-------------+-------------+
* | Shift State | Lock State |
* +-------------+-------------+-------------+-------------+-------------+
* | Code | 2 | 3 | 4 | 5 |
* +-------------+-------------+-------------+-------------+-------------+
* | lowercase | uppercase | punctuation | uppercase | punctuation |
* | uppercase | punctuation | lowercase | punctuation | lowercase |
* | punctuation | lowercase | uppercase | lowercase | uppercase |
* +-------------+-------------+-------------+-------------+-------------+
*/
if ( code < 4 )
{
shift_state = ( shift_lock + code + 2 ) % 3;
}
else
{
shift_lock = shift_state = ( shift_lock + code ) % 3;
}
}
}
else /* not V3 */
{
/*
* Synonym table: 1, 2 or 3
*
* Selects which of three synonym tables the synonym
* code following in the next code is to use.
*/
if ( code < 4 )
{
synonym_flag = 1;
synonym = code;
}
/*
* Shift key: 4 or 5
*
* Selects the shift state for the next character,
* either uppercase (4) or punctuation (5). The shift
* state automatically gets reset back to lowercase for
* V3+ games after the next character is output.
*
*/
else
{
shift_state = code - 3;
shift_lock = 0;
}
}
}
}
}
}
while ( ( data & 0x8000 ) == 0 );
} /* decode_text */
/*
* encode_text
*
* Pack a string into up to 9 codes or 3 words.
*
*/
void encode_text( int len, const char *s, ZINT16 * buffer )
{
int i, j, prev_table, table, next_table, shift_state, code, codes_count;
char codes[9];
/* Initialise codes count and prev_table number */
codes_count = 0;
prev_table = 0;
/* Scan do the string one character at a time */
while ( len-- )
{
/*
* Set the table and code to be the ASCII character inducer, then
* look for the character in the three lookup tables. If the
* character isn't found then it will be an ASCII character.
*/
table = 2;
code = 0;
for ( i = 0; i < 3; i++ )
{
for ( j = 0; j < 26; j++ )
{
if ( lookup_table[i][j] == *s )
{
table = i;
code = j;
}
}
}
/*
* Type 1 and 2 games differ on how the shift keys are used. Switch
* now depending on the game version.
*/
if ( h_type < V3 )
{
/*
* If the current table is the same as the previous table then
* just store the character code, otherwise switch tables.
*/
if ( table != prev_table )
{
/* Find the table for the next character */
next_table = 0;
if ( len )
{
next_table = 2;
for ( i = 0; i < 3; i++ )
{
for ( j = 0; j < 26; j++ )
{
if ( lookup_table[i][j] == s[1] )
next_table = i;
}
}
}
/*
* Calculate the shift key. This magic. See the description in
* decode_text for more information on version 1 and 2 shift
* key changes.
*/
shift_state = ( table + ( prev_table * 2 ) ) % 3;
/* Only store the shift key if there is a change in table */
if ( shift_state )
{
/*
* If the next character as the uses the same table as
* this character then change the shift from a single
* shift to a shift lock. Also remember the current
* table for the next iteration.
*/
if ( next_table == table )
{
shift_state += 2;
prev_table = table;
}
else
prev_table = 0;
/* Store the code in the codes buffer */
if ( codes_count < 9 )
codes[codes_count++] = ( char ) ( shift_state + 1 );
}
}
}
else
{
/*
* For V3 games each uppercase or punctuation table is preceded
* by a separate shift key. If this is such a shift key then
* put it in the codes buffer.
*/
if ( table && codes_count < 9 )
codes[codes_count++] = ( char ) ( table + 3 );
}
/* Put the character code in the code buffer */
if ( codes_count < 9 )
codes[codes_count++] = ( char ) ( code + 6 );
/*
* Cannot find character in table so treat it as a literal ASCII
* code. The ASCII code inducer (code 0 in table 2) is followed by
* the high 3 bits of the ASCII character followed by the low 5
* bits to make 8 bits in total.
*/
if ( table == 2 && code == 0 )
{
if ( codes_count < 9 )
codes[codes_count++] = ( char ) ( ( *s >> 5 ) & 0x07 );
if ( codes_count < 9 )
codes[codes_count++] = ( char ) ( *s & 0x1f );
}
/* Advance to next character */
s++;
}
/* Pad out codes with shift 5's */
while ( codes_count < 9 )
codes[codes_count++] = 5;
/* Pack codes into buffer */
buffer[0] = ( ( ZINT16 ) codes[0] << 10 ) | ( ( ZINT16 ) codes[1] << 5 ) | ( ZINT16 ) codes[2];
buffer[1] = ( ( ZINT16 ) codes[3] << 10 ) | ( ( ZINT16 ) codes[4] << 5 ) | ( ZINT16 ) codes[5];
buffer[2] = ( ( ZINT16 ) codes[6] << 10 ) | ( ( ZINT16 ) codes[7] << 5 ) | ( ZINT16 ) codes[8];
/* Terminate buffer at 6 or 9 codes depending on the version */
if ( h_type < V4 )
buffer[1] |= 0x8000;
else
buffer[2] |= 0x8000;
} /* encode_text */
/*
* translate_from_zscii
*
*
*/
int translate_from_zscii(int c)
{
c = ( unsigned int ) ( c & 0xff );
if ( c > 154 )
{
unsigned short s = '?';
if ( c < 224 )
s = zscii2unicode[(int)fIBMGraphics][c - 155];
if ( h_unicode_table )
{
int len = get_byte( h_unicode_table );
if ( c < 155 + len )
{
s = get_word( h_unicode_table + 2 * ( c - 155 ) + 1);
}
}
return s;
}
return c;
}
/*
* write_zchar
*
* High level Z-code character output routine. Translates Z-code characters to
* machine specific character(s) before output. If it cannot translate it then
* use the default translation. If the character is still unknown then display
* a '?'.
*
*/
void write_zchar( int c )
{
int i;
c = ( unsigned int ) ( c & 0xff );
/* If character is not special character then just write it */
if ( c >= ' ' && c <= '~' )
{
write_char( c );
}
else if ( c == 13 )
{
write_char( '\r' );
}
else if ( c > 154 )
{
if ( unicode )
write_char( translate_from_zscii( c ) );
else
{
char *s = "?";
if ( !h_unicode_table && c < 224 )
s = zscii2txt[(int)fIBMGraphics][c - 155];
while ( *s )
write_char( *s++ );
}
}
else if ( c > 23 && c < 28 && !unicode )
{
/* Arrow keys approximation */
static char xlat[4] = { '^', 'v', '>', '<' } ;
write_char( xlat[c - 24] );
}
else if ( c > 23 && c < 28 )
{
/* Arrow keys in unicode */
static unsigned short xlat[4] = { 0x2191, 0x2193, 0x2192, 0x2190 } ;
write_char( xlat[c - 24] );
}
else
{
char xlat_buffer[5];
/* Put default character in translation buffer */
xlat_buffer[0] = '?';
xlat_buffer[1] = '\0';
if ( c == 0 )
{
/* Null - print nothing */
xlat_buffer[0] = '\0';
}
else if ( c < 32 )
{
/* Some other control character: print an octal escape. */
xlat_buffer[0] = '\\';
xlat_buffer[1] = ( char ) ( '0' + ( ( c >> 6 ) & 7 ) );
xlat_buffer[2] = ( char ) ( '0' + ( ( c >> 3 ) & 7 ) );
xlat_buffer[3] = ( char ) ( '0' + ( c & 7 ) );
xlat_buffer[4] = '\0';
}
/* Substitute translated characters */
for ( i = 0; xlat_buffer[i] != '\0'; i++ )
{
write_char( xlat_buffer[i] );
}
}
} /* write_zchar */
/*
* translate_to_zscii
*
*
*/
int translate_to_zscii(int c)
{
int i;
if( c>= 0xa0 )
{
int len = 0;
if ( h_unicode_table )
{
int len = get_byte( h_unicode_table );
for (i = 0; i < len; i++)
{
if ( c == ( get_word( h_unicode_table + 2 * i + 1 ) ) )
{
return (0x9b + i);
}
}
}
for (i = 0x9b + len; i <= 0xdf; i++)
{
if (c == zscii2unicode[(int)fIBMGraphics][i - 0x9b])
{
return i;
}
}
return '?';
}
return c;
}
static unsigned short *strrushort( unsigned short *s, unsigned short c )
{
unsigned short *r = NULL;
while ( *s )
{
if ( *s == c )
r = s;
s++;
}
return r;
}
/*
* write_char
*
* High level character output routine. The write_char routine is slightly
* complicated by the fact that the output can be limited by a fixed character
* count, as well as, filling up the buffer.
*
*/
void write_char( int c )
{
unsigned short *cp;
int right_len;
/* Only do if text formatting is turned on */
if ( redirect_depth )
{
/* If redirect is on then write the character to the status line
* for V1 to V3 games or into the writeable data area for V4+ games */
if ( h_type < V4 )
{
status_line[status_pos++] = c;
}
else
{
set_byte( story_pos++, translate_to_zscii(c) );
story_count++;
}
}
else if ( formatting == ON && screen_window == TEXT_WINDOW )
{
int row, col;
if ( c == 13 )
{
z_new_line( );
return;
}
get_cursor_position( &row, &col );
if ( fit_line( line, line_pos + col - 1, screen_cols - right_margin ) == 0)
{
/* Null terminate the line */
line[line_pos] = '\0';
/* If the next character is a space then no wrap is neccessary */
if ( c == ' ' )
{
z_new_line( );
return;
}
else
{
/* Wrap the line. First find the last space */
cp = strrushort( line, ' ' );
/* If no spaces in the lines then cannot do wrap */
if ( cp == NULL )
{
/* Output the buffer and a new line */
z_new_line( );
}
else
{
/* Terminate the line at the last space */
*cp++ = '\0';
/* Calculate the text length after the last space */
right_len = &line[line_pos] - cp;
/* Output the buffer and a new line */
z_new_line( );
/* If any text to wrap then move it to the start of the line */
if ( right_len > 0 )
{
memmove( line, cp, right_len * sizeof( unsigned short ) );
memmove( style, &style[cp - line], right_len + 1 );
line_pos = right_len;
}
}
}
}
/* Put the character into the buffer and count it.
* Decrement line width if the character is visible */
if ( c )
{
line[line_pos++] = c;
line[line_pos] = 0;
style[line_pos] = 0;
}
}
else
{
/* No formatting or output redirection, so just output the character */
script_char( c );
output_char( c );
}
} /* write_char */
/*
* z_set_text_style
*
* Set a video attribute. Write the video mode, from 0 to 8, incremented.
* This is so the output routines don't confuse video attribute 0 as the
* end of the string.
*
*/
void z_set_text_style( zword_t mode )
{
if ( mode >= MIN_ATTRIBUTE && mode <= MAX_ATTRIBUTE )
{
if ( !redirect_depth && formatting == ON && screen_window == TEXT_WINDOW )
{
if ( mode == NORMAL)
style[line_pos] = 0x80;
else
style[line_pos] |= mode;
return;
}
set_attribute( mode );
}
else
{
fatal( "@set_text_style called with invalid mode." );
}
} /* z_set_text_style */
/*
* write_string
*
* Output a string
*
*/
void write_string( const char *s )
{
while ( *s )
write_char( *s++ );
} /* write_string */
/*
* flush_buffer
*
* Send output buffer to the screen.
*
*/
void flush_buffer( void )
{
int i;
/* Terminate the line */
line[line_pos] = '\0';
/* Send the line buffer to the printer */
for ( i = 0; line[i]; i++ )
script_char( line[i] );
flush_script( );
/* Send the line buffer to the screen */
for ( i = 0; i <= line_pos; i++ )
{
if ( style[i] & 0x80 )
set_attribute( NORMAL );
if ( style[i] & 0x7f )
set_attribute( style[i] & 0x7f );
if ( !line[i] )
break;
output_char( line[i] );
}
/* Reset the buffer pointer */
style[0] = 0;
line_pos = 0;
} /* flush_buffer */
/*
* z_buffer_mode
*
* Set the format mode flag. Formatting disables writing into the output buffer.
* If set to 1, text output in the lower window on stream one is buffered so that
* it can be word-wrapped properly. If set to 0, it isn't.
*
*/
void z_buffer_mode( zword_t flag )
{
/* Flush any current output */
flush_buffer( );
/* Set formatting depending on the flag */
if ( flag )
formatting = ON;
else
formatting = OFF;
} /* z_buffer_mode */
/*
* z_output_stream
*
* Set various printing modes. These can be: disabling output, scripting and
* redirecting output. Redirection is peculiar. I use it to format the status
* line for V1 to V3 games, otherwise it wasn't used. V4 games format the
* status line themselves in an internal buffer in the writeable data area.
* To use the normal text decoding routines they have to redirect output to
* the writeable data area. This is done by passing in a buffer pointer.
* The first word of the buffer will receive the number of characters
* written since the output was redirected. The remainder of the buffer
* will contain the redirected text.
*
*/
typedef struct redirect_stash_struct
{
zword_t count;
zword_t buffer;
zword_t pos;
}
redirect_stash_t;
void z_output_stream( zword_t type, zword_t option )
{
static int redirect_size = 0;
static redirect_stash_t *stash = NULL;
if ( ( ZINT16 ) type == 1 )
{
/* Turn on text output */
outputting = ON;
}
else if ( ( ZINT16 ) type == 2 )
{
/* Turn on scripting */
open_script( );
}
else if ( ( ZINT16 ) type == 3 )
{
/* Turn on output redirection */
if ( redirect_depth == 0 )
{
/* Disable text formatting during redirection */
saved_formatting = formatting;
formatting = OFF;
/* Enable text redirection */
redirect_depth = 1;
}
else
{
if ( redirect_size == 0 )
{
redirect_size = 4;
stash = ( redirect_stash_t * ) malloc( redirect_size * sizeof ( redirect_stash_t ) );
}
if ( redirect_depth > redirect_size )
{
redirect_size *= 2;
stash = ( redirect_stash_t * ) realloc( stash, redirect_size * sizeof ( redirect_stash_t ) );
}
if ( h_type < V4 )
{
stash[redirect_depth - 1].pos = status_pos;
}
else
{
stash[redirect_depth - 1].pos = story_pos;
stash[redirect_depth - 1].buffer = story_buffer;
stash[redirect_depth - 1].count = story_count;
}
redirect_depth++;
}
/* Set up the redirection pointers */
if ( h_type < V4 )
{
status_pos = 0;
}
else
{
story_count = 0;
story_buffer = option;
story_pos = option + 2;
}
}
else if ( ( ZINT16 ) type == 4 )
{
/* Turn on input recording */
open_record( );
}
else if ( ( ZINT16 ) type == -1 )
{
/* Turn off text output */
outputting = OFF;
}
else if ( ( ZINT16 ) type == -2 )
{
/* Turn off scripting */
close_script( );
}
else if ( ( ZINT16 ) type == -3 )
{
/* Turn off output redirection */
if ( redirect_depth )
{
if ( redirect_depth == 1 )
{
/* Restore the format mode and turn off redirection */
formatting = saved_formatting;
redirect_depth = 0;
/* Terminate the redirection buffer and store the count of
* character in the buffer into the first word of the buffer */
if ( h_type > V3 )
{
set_word( story_buffer, story_count );
}
}
else
{
if ( h_type > V3 )
{
set_word( story_buffer, story_count );
}
redirect_depth--;
if ( h_type < V4 )
{
status_pos = stash[redirect_depth - 1].pos;
}
else
{
story_pos = stash[redirect_depth - 1].pos;
story_buffer = stash[redirect_depth - 1].buffer;
story_count = stash[redirect_depth - 1].count;
}
}
}
}
else if ( ( ZINT16 ) type == -4 )
{
/* Turn off input recording */
close_record( );
}
} /* z_output_stream */
/*
* z_print_char
*
* Write a character.
*
*/
void z_print_char( zword_t c )
{
write_zchar( ( char ) c );
} /* z_print_char */
/*
* z_print_num
*
* Write a signed number.
*
*/
void z_print_num( zword_t num )
{
int i, count;
char buffer[10];
i = ( ZINT16 ) num;
sprintf( buffer, "%d", i );
count = strlen( buffer );
for ( i = 0; i < count; i++ )
write_char( buffer[i] );
} /* z_print_num */
/*
* z_print_paddr
*
* Print using a packed address. Packed addresses are used to save space and
* reference addresses outside of the data region.
*
*/
void z_print_paddr( zword_t packed_address )
{
unsigned long address;
/* Convert packed address to real address */
address = ( unsigned long ) packed_address * story_scaler;
/* Decode and output text at address */
decode_text( &address );
} /* z_print_paddr */