-
Notifications
You must be signed in to change notification settings - Fork 0
/
os2iob.c
1744 lines (1364 loc) · 45.8 KB
/
os2iob.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: os2iob.c,v 1.1.1.1 2000/05/10 14:20:51 jholder Exp $
* --------------------------------------------------------------------
* see doc/License.txt for License Information
* --------------------------------------------------------------------
*
* File name: $Id: os2iob.c,v 1.1.1.1 2000/05/10 14:20:51 jholder Exp $
*
* Description:
*
* Modification history:
* $Log: os2iob.c,v $
* Revision 1.1.1.1 2000/05/10 14:20:51 jholder
*
* imported
*
*
* --------------------------------------------------------------------
*/
/*
* os2iob.c
*
* specific thread-1 screen I/O routines for OS/2.
*
*/
/* ZIP2 version Created by John W. Kennedy, May, 1994 */
/* Based on pre-existing mscio.c */
/* Functional improvements over mscio.c: */
/* Keyboard reading is done in a separate thread, with a timed-out wait, */
/* so that the CPU is not uselessly devoured; functions for that thread, */
/* and for that thread alone, are maintained in a separate module */
/* (os2iot.c) so that they can be compiled with stack probes; all the */
/* functions in this module and the OS-neutral modules, running in thread */
/* 1 alone, do not need stack probes */
/* Accomodation is made for screens in color, black-and-white, and */
/* monochrome modes. The modes are by discovery, where possible */
/* Option -b forces black-and-white mode; when determination is impossible, */
/* either in a window or on a display that doesn't feed back color, */
/* and -b is not specified, then the question is asked outright */
/* Screen size is handled by discovery */
/* Complete support for Beyond Zork navigation keys */
/* Cursor appears correctly in Bureaucracy forms */
/* Second ZIP2 release additions, June, 1994: */
/* Bug corrected that made Border Zone loop on input */
/* Functional improvements compared to DOS ZIP 2.00 */
/* Screen information is correctly fed back to Z machine */
/* In V4+, Config byte 0x04 is always set */
/* (per Graham Nelson, it is "Boldface available") */
/* CONFIG_EMPHASIS is set for PALETTE_MONOCHROME only */
/* (per Graham Nelson, it is "Underlining available") */
/* ^D launches a window displaying, in chronological order, all files */
/* in the current directory containing exactly the right number of */
/* bytes to be a save file in the current game */
/* Options -o for color and -m for monochrome added */
/* Options -o, -m, and -b invoke MODE command */
/* Third ZIP2 release additions, June, 1995 (source not released) */
/* Functional improvements compared to DOS ZIP 2.00 */
/* Version-8 support */
/* Fourth ZIP2 release, July, 1997 */
/* __STDC__ tests removed from the two OS/2 modules, which require -Se */
/* (extended-ANSI) compilation, and -Sa (pure-ANSI) used on the rest. */
/* (IBM VisualAge C/C++ sets __STDC__ only in pure-ANSI mode; it */
/* appears that the standard does not define whether this or the more */
/* common ANSI-or-more interpretation is correct.) */
/* Corrected order-of-magnitude error in keyboard timeout. (Ouch! Why */
/* didn't anyone tell me?) */
/* Fifth ZIP2 release, October, 1997 */
/* Functional improvements compared to DOS ZIP 2.00 */
/* Corrected end-of-line erasure (c.f. Jigsaw "style 3. examine frame") */
/* Corrected MORE logic */
/* Added F11, F12 and 0/Ins key */
/* Included Z-machine 1.0 character set (backoff option for Beyond Zork) */
/* JZIP support added (guarded by #if) to OS/2 modules */
/* JZIP history buffer added, adapted from bccio.c */
/* Full Z-machine 1.0 color support, and combination of color and bold supported */
/* Add -y option to set Tandy bit */
/* Move cursor to top at end of run */
/* Options -o, -b and -m are now silently overridden if they conflict with */
/* reality */
/* Remove ^D feature, since it won't work with QUETZAL */
/* Sixth ZIP2 release, February, 1999 */
/* Bring up to JZIP 2.02beta */
/* Move Tandy bit setting to control.c, where it belongs */
/* Minor signed/unsigned and other corrections performed while debugging new mscio.c */
/* Seventh ZIP2 release, February, 2000 */
/* Bring up to JZIP 2.1 */
/* Corrected some errors in command editing */
/* The following special codes are used for keys that do not exist in the Z machine, */
/* but are needed by the history buffer */
/* 20000000 Del */
/* 20000001 Ctrl-Left-arrow */
/* 20000002 Ctrl-Right-arrow */
/* From at least 1994 to the present, IBM module BSESUB.H has had the following
error: structure VIOMODINFO, field ext_data_addr and
structure VIOCOLORREG, field colorregaddr are declared as type PCH when
they are in fact type PCHAR16. Until IBM fixes this, you _must_ correct
your BSESUB.H before compiling, or this module will blow up when running
in full-screen mode */
#include "ztypes.h"
#define INCL_NOCOMMON
#define INCL_DOSPROCESS
#define INCL_DOSSEMAPHORES
#if !defined JZIPVER
#define INCL_DOSSESMGR
#endif
#define INCL_DOSNLS
#define INCL_VIO
#define INCL_KBD
#define INCL_DOSERRORS
#define INCL_NOPMAPI
#include <os2.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
/* Communications with the keyboard thread */
HEV hevKbdReq, hevKbdRsp;
volatile int fKbdOpen = FALSE;
volatile int iKbdChar;
static TID tidKbd = 0;
static int fKbdRequested = FALSE;
#define BLACK 0
#define BLUE 1
#define UNDERSCORE 1
#define GREEN 2
#define CYAN 3
#define RED 4
#define MAGENTA 5
#define BROWN 6
#define WHITE 7
#define BRIGHT 0x08
#define FLASH 0x10
#define PALETTE_NIL -1
#define PALETTE_COLOUR 0
#define PALETTE_BLACK_AND_WHITE 1
#define PALETTE_MONOCHROME 2
int iPalette = PALETTE_NIL;
static int screen_started = FALSE;
static int cursor_saved = OFF;
static int saved_row = 0;
static int saved_col = 0;
static int current_fg = WHITE;
static int current_bg = BLACK;
static int fgBright = 0;
#if !defined JZIPVER
char fTandy = 0;
char fIBMGraphics = 0;
#endif
/* These items are maintained here instead of by the system */
static char achBlankAttribute[2] = { ' ', ( BLACK << 4 ) | WHITE };
static char achClearAttribute[2] = { ' ', ( BLACK << 4 ) | WHITE };
static int current_row, current_col;
void os2_read_key_thread( void *p );
int os2_read_key_byte( void );
int os2_read_key_byte_timed( int timeout );
#if defined JZIPVER
int BUFFER_SIZE;
char *commands;
static int space_avail;
static int ptr1, ptr2 = 0;
static int end_ptr = 0;
static int row, head_col;
static void get_prev_command( void );
static void get_next_command( void );
static void get_first_command( void );
static void delete_command( void );
static void add_command( char *, int size );
static int display_command( char * );
static int init_char_pos, curr_char_pos;
static int loop, tail_col;
#endif
void initialize_screen( void )
{
VIOMODEINFO vmi;
VIOSETULINELOC vsull;
KBDINFO ki;
APIRET rc;
int iPaletteRequested = iPalette;
if ( !fIBMGraphics )
{
/* Set codepage 850; it ought to work, but if it doesn't, there's nothing
* we can do about it, so don't check the return code */
VioSetCp( 0, 850, NULLHANDLE );
} /* endif */
/* There is no VIO interface to reset things like the color palette to
* "normal", so spawn a MODE command to do it */
if ( iPalette != PALETTE_NIL )
{
static char /* const */ *const apszMode[3] =
{ "Mode\0CO80\0",
"Mode\0BW80\0",
"Mode\0Mono\0"
};
RESULTCODES rc;
DosExecPgm( NULL, 0, EXEC_SYNC, apszMode[iPalette], NULL, &rc, "MODE.COM" );
} /* endif */
/* Black-and-white is always correct, so if it is forced, accept it. */
/* For the other options, man proposes, but hardware disposes, so verify it */
if ( iPalette != PALETTE_BLACK_AND_WHITE )
{
iPalette = PALETTE_NIL;
} /* endif */
/* Get the underline location; if < 31, use monochrome palette */
vsull.cb = sizeof vsull;
vsull.type = 5;
rc = VioGetState( &vsull, NULLHANDLE );
if ( !rc && vsull.scanline < 31 )
{
iPalette = PALETTE_MONOCHROME;
}
else
{
/* Otherwise, get color information */
/* If the 16 main colors have R==G==B, use black-and-white palette */
/* If either VioGetState call fails, we still don't know */
PVIOPALSTATE pvps = _alloca( 38 );
pvps->cb = 38;
pvps->type = 0;
pvps->iFirst = 0;
if ( !VioGetState( pvps, NULLHANDLE ) )
{
VIOCOLORREG vcr;
int iLimit;
iLimit = pvps->iFirst + ( pvps->cb - sizeof ( VIOPALSTATE ) ) / sizeof ( USHORT ) + 1;
vcr.cb = sizeof ( VIOCOLORREG );
vcr.type = 3;
vcr.firstcolorreg = 0;
vcr.numcolorregs = 256;
vcr.colorregaddr = _alloca( 3 * 256 );
if ( !VioGetState( &vcr, NULLHANDLE ) )
{
int i;
for ( i = pvps->iFirst; i < iLimit; ++i )
{
typedef struct
{
UCHAR uchRed, uchGreen, uchBlue;
}
COLOURS;
COLOURS *pvcrx = &( ( ( COLOURS * ) vcr.colorregaddr )[i - pvps->iFirst] );
if ( pvcrx->uchRed != pvcrx->uchGreen || pvcrx->uchGreen != pvcrx->uchBlue )
{
break;
} /* endif */
} /* endfor */
if ( i >= iLimit )
{
iPalette = PALETTE_BLACK_AND_WHITE;
} /* endif */
} /* endif */
} /* endif */
} /* endif */
/* If we are still undetermined, it is possible that we are in a */
/* window or that we have a dumb CRT; either way, we could still be */
/* on black and white hardware, so consider what was requested */
if ( iPalette == PALETTE_NIL )
{
if ( iPaletteRequested == PALETTE_MONOCHROME )
{
iPalette = PALETTE_BLACK_AND_WHITE;
}
else
{
iPalette = iPaletteRequested;
} /* endif */
} /* endif */
/* If it isn't determined after all that, just ask */
if ( iPalette == PALETTE_NIL )
{
char ch;
do
{
static /* const */ char sz[] = "Do you want color? ";
KBDKEYINFO kki;
VioScrollUp( 0, 0, 0xFFFF, 0xFFFF, 0xFFFF, achClearAttribute, NULLHANDLE );
VioWrtCharStrAtt( sz, sizeof sz - 1, 0, 0, &achBlankAttribute[1], NULLHANDLE );
VioSetCurPos( 0, sizeof sz - 1, NULLHANDLE );
KbdCharIn( &kki, IO_WAIT, NULLHANDLE );
ch = kki.chChar;
}
while ( ch != 'y' && ch != 'Y' && ch != 'n' && ch != 'N' ); /* enddo */
if ( ch == 'n' || ch == 'N' )
{
iPalette = PALETTE_BLACK_AND_WHITE;
}
else
{
iPalette = PALETTE_COLOUR;
} /* endif */
} /* endif */
/* If we're still in color after all that, set up for color */
if ( iPalette == PALETTE_COLOUR )
{
current_bg = BLUE;
achClearAttribute[1] = achBlankAttribute[1] = ( BLUE << 4 ) | WHITE;
} /* endif */
/* Now get the existing rows and columns */
vmi.cb = sizeof vmi;
VioGetMode( &vmi, NULLHANDLE );
if ( screen_rows == 0 )
{
screen_rows = vmi.row;
} /* endif */
if ( screen_cols == 0 )
{
screen_cols = vmi.col;
} /* endif */
/* Now set up the user's desired rows and columns */
/* If it fails, go to the default */
vmi.cb = sizeof vmi.cb + sizeof vmi.fbType + sizeof vmi.color + sizeof vmi.col + sizeof vmi.row;
vmi.col = screen_cols;
vmi.row = screen_rows;
if ( VioSetMode( &vmi, NULLHANDLE ) )
{
vmi.row = screen_rows = 25;
vmi.col = screen_cols = 80;
VioSetMode( &vmi, NULLHANDLE );
} /* endif */
move_cursor( 1, 1 );
set_attribute( NORMAL );
clear_screen( );
{
#if defined JZIPVER
static const char cb = sizeof JZIPVER - 1;
#else
static /* const */ char sz[] = "ZIP for OS/2 2.0.4";
static const char cb = sizeof sz - 1;
#endif
move_cursor( screen_rows / 2 - 1, ( screen_cols - cb ) / 2 );
#if defined JZIPVER
VioWrtCharStrAtt( JZIPVER, cb, current_row - 1, current_col - 1, &achClearAttribute[1],
NULLHANDLE );
#else
VioWrtCharStrAtt( sz, cb, current_row - 1, current_col - 1, &achClearAttribute[1],
NULLHANDLE );
#endif
current_col += cb;
move_cursor( current_row, current_col );
}
{
static /* const */ char sz[] = "The story is loading...";
static const char cb = sizeof sz - 1;
move_cursor( screen_rows / 2, ( screen_cols - cb ) / 2 );
VioWrtCharStrAtt( sz, cb, current_row - 1, current_col - 1, &achClearAttribute[1],
NULLHANDLE );
current_col += cb;
move_cursor( current_row, current_col );
}
#if defined JZIPVER
/* set up the history buffer to be the right size */
commands = ( char * ) malloc( hist_buf_size * sizeof ( char ) );
if ( commands == NULL )
{
/* try again, with smaller buffer if failure */
if ( hist_buf_size > 1024 )
{
commands = ( char * ) malloc( 1024 * sizeof ( char ) );
if ( commands == NULL )
{
fatal( "Could not allocate history buffer." );
}
else
{
hist_buf_size = 1024;
}
}
else
{
fatal( "Could not allocate history buffer." );
}
}
BUFFER_SIZE = hist_buf_size;
space_avail = hist_buf_size - 1;
/* I have code that analyzes the history buffer - I must first init */
/* the history buffer to a known state to insure it will work. */
#endif
ki.cb = sizeof ki;
KbdGetStatus( &ki, NULLHANDLE );
ki.fsMask = KEYBOARD_ECHO_OFF | KEYBOARD_BINARY_MODE;
KbdSetStatus( &ki, NULLHANDLE );
/* Set up a semaphore for this thread to unblock the other, */
/* and one for the other to respond. Then start the thread */
DosCreateEventSem( NULL, &hevKbdReq, 0, FALSE );
DosCreateEventSem( NULL, &hevKbdRsp, 0, FALSE );
tidKbd = _beginthread( &os2_read_key_thread, NULL, 12288, NULL );
fKbdOpen = TRUE;
screen_started = TRUE;
h_interpreter = INTERP_MSDOS;
#if defined JZIPVER
JTERP = INTERP_MSDOS;
#endif
} /* initialize_screen */
void restart_screen( void )
{
zbyte_t config_byte = get_byte( H_CONFIG );
cursor_saved = OFF;
#if defined JZIPVER
{
zbyte_t high = 1, low = 0;
set_byte( H_STANDARD_HIGH, high );
set_byte( H_STANDARD_LOW, low );
}
#endif
if ( h_type == V3 )
{
config_byte |= CONFIG_MAX_DATA | CONFIG_WINDOWS;
config_byte &= ~0x40 /* not variable pitch */ & ~CONFIG_NOSTATUSLINE;
}
else if ( h_type >= V4 )
{
config_byte |= 0x04 /* Bold */ | 0x80 /* Timer */ ;
if ( iPalette == PALETTE_MONOCHROME )
{
config_byte |= CONFIG_EMPHASIS;
}
else
{
config_byte &= ~CONFIG_EMPHASIS;
} /* endif */
config_byte &= ~0x10 /* no switch to fixed */ ;
if ( h_type >= V5 )
{
config_byte &= ~0x20 /* no sound */ ;
if ( iPalette == PALETTE_COLOUR )
{
config_byte |= CONFIG_COLOUR;
}
else
{
config_byte &= ~CONFIG_COLOUR;
} /* endif */
} /* endif */
} /* endif */
set_byte( H_CONFIG, config_byte );
set_word( H_FLAGS, get_word( H_FLAGS ) & ~GRAPHICS_FLAG & ~0x20 /* Mouse */
& ~NEW_SOUND_FLAG );
} /* restart_screen */
void reset_screen( void )
{
if ( screen_started == TRUE )
{
output_new_line( );
output_string( "[Hit any key to exit.]" );
( void ) input_character( 0 );
current_bg = BLACK;
current_fg = WHITE;
achClearAttribute[1] = achBlankAttribute[1] = ( BLACK << 4 ) | WHITE;
clear_screen( );
move_cursor( 1, 1 );
/* We know that the last input-character was not timed, so set */
/* fKbdOpen to false and unblock the other thread, which should end */
fKbdOpen = FALSE;
DosPostEventSem( hevKbdReq );
if ( tidKbd )
{
DosWaitThread( &tidKbd, DCWW_WAIT );
} /* endif */
} /* endif */
screen_started = FALSE;
} /* reset_screen */
void clear_screen( void )
{
VioScrollUp( 0, 0, 0xFFFF, 0xFFFF, 0xFFFF, achClearAttribute, NULLHANDLE );
lines_written = 0;
if ( h_type >= V4 )
{
set_status_size( 0 );
} /* endif */
} /* clear_screen */
void create_status_window( void )
{
} /* create_status_window */
void delete_status_window( void )
{
} /* delete_status_window */
void select_status_window( void )
{
VIOCURSORINFO vci;
save_cursor_position( );
VioGetCurType( &vci, NULLHANDLE );
vci.attr = -1;
VioSetCurType( &vci, NULLHANDLE );
} /* select_status_window */
void select_text_window( void )
{
VIOCURSORINFO vci;
VioGetCurType( &vci, NULLHANDLE );
vci.attr = 0;
VioSetCurType( &vci, NULLHANDLE );
restore_cursor_position( );
} /* select_text_window */
void clear_line( void )
{
VioScrollRt( current_row - 1, current_col - 1, current_row - 1, screen_cols - 1, 0xFFFF,
achClearAttribute, NULLHANDLE );
} /* clear_line */
void clear_text_window( void )
{
VioScrollUp( status_size, 0, screen_rows - 1, screen_cols - 1, 0xFFFF, achClearAttribute,
NULLHANDLE );
} /* clear_text_window */
void clear_status_window( void )
{
VioScrollUp( 0, 0, status_size - 1, screen_cols - 1, 0xFFFF, achClearAttribute, NULLHANDLE );
} /* clear_status_window */
void move_cursor( int row, int col )
{
current_row = row;
current_col = col;
VioSetCurPos( current_row - 1, current_col - 1, NULLHANDLE );
} /* move_cursor */
void get_cursor_position( int *row, int *col )
{
*row = current_row;
*col = current_col;
} /* get_cursor_position */
void save_cursor_position( void )
{
if ( cursor_saved == OFF )
{
saved_row = current_row;
saved_col = current_col;
cursor_saved = ON;
} /* endif */
} /* save_cursor_position */
void restore_cursor_position( void )
{
if ( cursor_saved == ON )
{
move_cursor( saved_row, saved_col );
cursor_saved = OFF;
} /* endif */
} /* restore_cursor_position */
void set_attribute( int attribute )
{
int fg, bg, new_fg, new_bg;
fg = achBlankAttribute[1] & 0x0F;
bg = achBlankAttribute[1] >> 4;
if ( attribute == NORMAL )
{
new_fg = current_fg;
new_bg = current_bg;
fgBright = 0;
} /* endif */
if ( attribute & REVERSE )
{
if ( iPalette == PALETTE_MONOCHROME )
{
if ( fg == UNDERSCORE )
{
fg == 0;
} /* endif */
} /* endif */
new_fg = bg;
new_bg = fg & WHITE;
fgBright = 0;
} /* endif */
if ( attribute & BOLD )
{
fgBright = BRIGHT;
new_fg = fg | BRIGHT;
new_bg = bg;
}
else
{
fgBright = 0;
} /* endif */
if ( attribute & EMPHASIS )
{
switch ( iPalette )
{
case PALETTE_COLOUR:
new_fg = RED | BRIGHT;
fgBright = BRIGHT;
break;
case PALETTE_BLACK_AND_WHITE:
new_fg = WHITE | BRIGHT;
fgBright = BRIGHT;
break;
case PALETTE_MONOCHROME:
new_fg = UNDERSCORE;
fgBright = 0;
break;
} /* endswitch */
new_bg = bg;
} /* endif */
if ( attribute & FIXED_FONT )
{
new_fg = fg;
new_bg = bg;
fgBright = 0;
} /* endif */
achBlankAttribute[1] = ( new_bg << 4 ) | new_fg | fgBright;;
} /* set_attribute */
void display_char( int c )
{
char ch = c;
switch ( ch )
{
case '\n':
scroll_line( );
break;
case '\a':
DosBeep( 880, 200 );
break;
default:
VioWrtCharStrAtt( &ch, 1, current_row - 1, current_col - 1, &achBlankAttribute[1],
NULLHANDLE );
++current_col;
break;
} /* endswitch */
} /* display_char */
static int convert_key( int c )
{
/* Translate extended keys to Infocom-determined single bytes above 127 */
switch ( c )
{
case 'H': /* Up arrow */
c = '\x81';
break;
case 'P': /* Down arrow */
c = '\x82';
break;
case 'K': /* Left arrow */
c = '\x83';
break;
case 's': /* Ctrl-Left arrow */
c = 0x20000001;
break;
case 'M': /* Right arrow */
c = '\x84';
break;
case 't': /* Ctrl-Right arrow */
c = 0x20000002;
break;
case ';': /* Function keys F1 to F10 */
case '<':
case '=':
case '>':
case '?':
case '@':
case 'A':
case 'B':
case 'C':
case 'D':
c = ( c - ';' ) + '\x85';
break;
case 133: /* Function key F11 */
c = '\x8F';
break;
case 134: /* Function key F12 */
c = '\x90';
break;
case 'R': /* Ins */
c = '\x91';
break;
case 'S': /* Del */
c = 0x20000000;
break;
case 'O': /* End (SW) */
c = '\x92';
break;
case 'Q': /* PgDn (SE) */
c = '\x94';
break;
case 'G': /* Home (NW) */
c = '\x98';
break;
case 'I': /* PgUp (NE) */
c = ( unsigned char ) '\x9A';
break;
case 'L': /* Unnamed (Walk Around) */
c = '\x96';
break;
default:
DosBeep( 880, 200 );
c = 0;
} /* endswitch */
return c;
}
static int read_key( void )
{
int c;
do
{
c = os2_read_key_byte( );
if ( c != '\0' && c != ( unsigned char ) '\xE0' )
{
if ( c == '\x07F' )
{
c = '\b';
}
else
{
if ( c >= ( unsigned char ) '\x80' )
{
DosBeep( 880, 200 );
c = '\0';
} /* endif */
} /* endif */
}
else
{
int c1 = os2_read_key_byte( );
c = convert_key( c1 & 0x3FFFFFFF );
if ( ( c && 0xFF ) >= 0xFC )
{
DosBeep( 880, 200 );
c = '\0';
} /* endif */
c |= c1 & 0x40000000;
} /* endif */
}
while ( c == 0 ); /* enddo */
return c;
} /* read_key */
static int timed_read_key( int timeout )
{
int c;
do
{
c = os2_read_key_byte_timed( timeout );
if ( c != '\0' && c != ( unsigned char ) '\xE0' )
{
if ( c == '\x7F' )
{
c = '\b';
}
else
{
if ( c >= ( unsigned char ) '\x80' )
{
DosBeep( 880, 200 );
c = '\0';
} /* endif */
} /* endif */
}
else
{
int c1 = os2_read_key_byte( );
c = convert_key( c1 & 0x3FFFFFFF );
if ( ( c && 0xFF ) >= 0xFC )
{
DosBeep( 880, 200 );
c = '\0';
} /* endif */
c |= c1 & 0x40000000;
} /* endif */
}
while ( c == 0 ); /* enddo */
return c;
} /* timed_read_key */
#if defined JZIPVER
/*
* Previous command system
*
* Here's how this works:
*
* The previous command buffer is BUFFER_SIZE bytes long. After the player
* presses Enter, the command is added to this buffer, with a trailing '\n'
* added. The '\n' is used to show where one command ends and another begins.
*
* The up arrow key retrieves a previous command. This is done by working
* backwards through the buffer until a '\n' is found. The down arrow
* retieves the next command by counting forward. The ptr1 and ptr2
* values hold the start and end of the currently displayed command.
*
* Unlike the BCC version, this requires Scroll-Lock to be on
*
* Special Key Summary:
*
* left arrow - move one character to the left
* right arrow - move one character to the right
* ctrl + left arrow - move one word to the left
* ctrl + right arrow - move one word to the right
* home - move to beginning of line
* end - move to end of line
* backspace - delete character to the left of the cursor