-
Notifications
You must be signed in to change notification settings - Fork 1
/
crt.pp
1652 lines (1470 loc) · 34.9 KB
/
crt.pp
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
{
This file is part of the Free Pascal run time library.
Copyright (c) 1999-2000 by Michael Van Canneyt and Peter Vreman,
members of the Free Pascal development team.
See the file COPYING.FPC, included in this distribution,
for details about the copyright.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
**********************************************************************}
unit Crt;
Interface
{$i crth.inc}
Const
{ Controlling consts }
Flushing = false; {if true then don't buffer output}
ConsoleMaxX = 1024;
ConsoleMaxY = 1024;
ScreenHeight : longint = 25;
ScreenWidth : longint = 80;
Type
TCharAttr=packed record
ch : char;
attr : byte;
end;
TConsoleBuf=Array[0..ConsoleMaxX*ConsoleMaxY-1] of TCharAttr;
PConsoleBuf=^TConsoleBuf;
var
ConsoleBuf : PConsoleBuf;
Implementation
uses BaseUnix ,unix, termio;
Const
OldTextAttr : byte = $07;
Var
CurrX,CurrY : Byte;
OutputRedir, InputRedir : boolean; { is the output/input being redirected (not a TTY) }
{$ifdef debugcrt}
DebugFile : Text;
{$endif}
{*****************************************************************************
Some Handy Functions Not in the System.PP
*****************************************************************************}
{$ifdef debugcrt}
Procedure Debug(Msg : string);
begin
Writeln(DebugFile,Msg);
end;
{$endif}
Function Str(l:longint):string;
{
Return a String of the longint
}
var
hstr : string[32];
begin
System.Str(l,hstr);
Str:=hstr;
end;
Function Max(l1,l2:longint):longint;
{
Return the maximum of l1 and l2
}
begin
if l1>l2 then
Max:=l1
else
Max:=l2;
end;
Function Min(l1,l2:longint):longint;
{
Return the minimum of l1 and l2
}
begin
if l1<l2 then
Min:=l1
else
Min:=l2;
end;
{*****************************************************************************
Optimal AnsiString Conversion Routines
*****************************************************************************}
Function XY2Ansi(x,y,ox,oy:longint):String;
{
Returns a string with the escape sequences to go to X,Y on the screen
}
Begin
{ in case of potential ox overflow, send full position information
(mantis #20880) }
if (y=oy) and
(ox<>$ff) then
begin
if x=ox then
begin
// this workaround should improve behaviour on some terminals.
// debian bug 216057 but I also observed this with video on FreeBSD
if x=screenwidth then
XY2Ansi:=#27'['+Str(y)+';'+Str(x)+'H'
else
// end workaround
XY2Ansi:='';
exit;
end;
{$ifdef Linux} // linux CRT shortcut
if x=1 then
begin
XY2Ansi:=#13;
exit;
end;
{$endif}
if x>ox then
begin
XY2Ansi:=#27'['+Str(x-ox)+'C';
exit;
end
else
begin
XY2Ansi:=#27'['+Str(ox-x)+'D';
exit;
end;
end;
if x=ox then
begin
if y>oy then
begin
XY2Ansi:=#27'['+Str(y-oy)+'B';
exit;
end
else
begin
XY2Ansi:=#27'['+Str(oy-y)+'A';
exit;
end;
end;
{$ifdef Linux} // this shortcut isn't for everybody
if (x=1) and (oy+1=y) then
XY2Ansi:=#13#10
else
{$endif}
XY2Ansi:=#27'['+Str(y)+';'+Str(x)+'H';
End;
const
AnsiTbl : string[8]='04261537';
Function Attr2Ansi(Attr,OAttr:longint):string;
{
Convert Attr to an Ansi String, the Optimal code is calculate
with use of the old OAttr
}
var
hstr : string[16];
OFg,OBg,Fg,Bg : longint;
procedure AddSep(ch:char);
begin
if length(hstr)>0 then
hstr:=hstr+';';
hstr:=hstr+ch;
end;
begin
if Attr=OAttr then
begin
Attr2Ansi:='';
exit;
end;
Hstr:='';
Fg:=Attr and $f;
Bg:=Attr shr 4;
OFg:=OAttr and $f;
OBg:=OAttr shr 4;
if (OFg<>7) or (Fg=7) or ((OFg>7) and (Fg<8)) or ((OBg>7) and (Bg<8)) then
begin
hstr:='0';
OFg:=7;
OBg:=0;
end;
if (Fg>7) and (OFg<8) then
begin
AddSep('1');
OFg:=OFg or 8;
end;
if (Bg and 8)<>(OBg and 8) then
begin
AddSep('5');
OBg:=OBg or 8;
end;
if (Fg<>OFg) then
begin
AddSep('3');
hstr:=hstr+AnsiTbl[(Fg and 7)+1];
end;
if (Bg<>OBg) then
begin
AddSep('4');
hstr:=hstr+AnsiTbl[(Bg and 7)+1];
end;
if hstr='0' then
hstr:='';
Attr2Ansi:=#27'['+hstr+'m';
end;
Function Ansi2Attr(Const HStr:String;oattr:longint):longint;
{
Convert an Escape sequence to an attribute value, uses Oattr as the last
color written
}
var
i,j : longint;
begin
i:=2;
if (Length(HStr)<3) or (Hstr[1]<>#27) or (Hstr[2]<>'[') then
i:=255;
while (i<length(Hstr)) do
begin
inc(i);
case Hstr[i] of
'0' : OAttr:=7;
'1' : OAttr:=OAttr or $8;
'5' : OAttr:=OAttr or $80;
'3' : begin
inc(i);
j:=pos(Hstr[i],AnsiTbl);
if j>0 then
OAttr:=(OAttr and $f8) or (j-1);
end;
'4' : begin
inc(i);
j:=pos(Hstr[i],AnsiTbl);
if j>0 then
OAttr:=(OAttr and $8f) or ((j-1) shl 4);
end;
'm' : i:=length(HStr);
end;
end;
Ansi2Attr:=OAttr;
end;
{*****************************************************************************
Buffered StdIn/StdOut IO
*****************************************************************************}
const
ttyIn=0; {Handles for stdin/stdout}
ttyOut=1;
ttyFlush:boolean=true;
{Buffered Input/Output}
InSize=256;
OutSize=1024;
var
InBuf : array[0..InSize-1] of char;
InCnt,
InHead,
InTail : longint;
OutBuf : array[0..OutSize-1] of char;
OutCnt : longint;
{Flush Output Buffer}
procedure ttyFlushOutput;
begin
if OutCnt>0 then
begin
fpWrite(ttyOut,OutBuf,OutCnt);
OutCnt:=0;
end;
end;
Function ttySetFlush(b:boolean):boolean;
begin
ttySetFlush:=ttyFlush;
ttyFlush:=b;
if ttyFlush then
ttyFlushOutput;
end;
{Send Char to Remote}
Procedure ttySendChar(c:char);
Begin
if OutCnt<OutSize then
begin
OutBuf[OutCnt]:=c;
inc(OutCnt);
end;
{Full ?}
if (OutCnt>=OutSize) then
ttyFlushOutput;
End;
{Send String to Remote}
procedure ttySendStr(const hstr:string);
var
i : longint;
begin
for i:=1to length(hstr) do
ttySendChar(hstr[i]);
if ttyFlush then
ttyFlushOutput;
end;
{Get Char from Remote}
function ttyRecvChar:char;
var
Readed,i : longint;
begin
{Buffer Empty? Yes, Input from StdIn}
if (InHead=InTail) then
begin
{Calc Amount of Chars to Read}
i:=InSize-InHead;
if InTail>InHead then
i:=InTail-InHead;
{Read}
Readed:=fpread(TTYIn,InBuf[InHead],i);
{Increase Counters}
inc(InCnt,Readed);
inc(InHead,Readed);
{Wrap if End has Reached}
if InHead>=InSize then
InHead:=0;
end;
{Check Buffer}
if (InCnt=0) then
ttyRecvChar:=#0
else
begin
ttyRecvChar:=InBuf[InTail];
dec(InCnt);
inc(InTail);
if InTail>=InSize then
InTail:=0;
end;
end;
{*****************************************************************************
Screen Routines not Window Depended
*****************************************************************************}
procedure ttyGotoXY(x,y:longint);
{
Goto XY on the Screen, if a value is 0 the goto the current
postion of that value and always recalc the ansicode for it
}
begin
if x=0 then
begin
x:=CurrX;
CurrX:=$ff;
end;
if y=0 then
begin
y:=CurrY;
CurrY:=$ff;
end;
if OutputRedir then
begin
if longint(y)-longint(CurrY)=1 then
ttySendStr(#10);
end
else
ttySendStr(XY2Ansi(x,y,CurrX,CurrY));
CurrX:=x;
CurrY:=y;
end;
procedure ttyColor(a:longint);
{
Set Attribute to A, only output if not the last attribute is set
}
begin
if a<>OldTextAttr then
begin
if not OutputRedir then
ttySendStr(Attr2Ansi(a,OldTextAttr));
TextAttr:=a;
OldTextAttr:=a;
end;
end;
procedure ttyWrite(const s:string);
{
Write a string to the output, memory copy and Current X&Y are also updated
}
var
idx,i : longint;
begin
ttySendStr(s);
{Update MemCopy}
idx:=(CurrY-1)*ScreenWidth-1;
for i:=1 to length(s) do
if s[i]=#8 then
begin
if CurrX>1 then
dec(CurrX);
end
else
begin
ConsoleBuf^[idx+CurrX].ch:=s[i];
ConsoleBuf^[idx+CurrX].attr:=TextAttr;
inc(CurrX);
If CurrX>ScreenWidth then
CurrX:=$FF; // Mark as invalid.
end;
end;
Function FullWin:boolean;
{
Full Screen 80x25? Window(1,1,80,25) is used, allows faster routines
}
begin
FullWin:=(WindMinX=1) and (WindMinY=1) and
(WindMaxX=ScreenWidth) and (WindMaxY=ScreenHeight);
end;
procedure LineWrite(const temp:String);
{
Write a Line to the screen, doesn't write on 80,25 under Dos
the Current CurrX is set to WindMax. NO MEMORY UPDATE!
}
begin
CurrX:=WindMaxX+1;
ttySendStr(Temp);
end;
Procedure DoEmptyLine(y,xl,xh:Longint);
{
Write an empty line at row Y from column Xl to Xh. Memory is also updated.
}
Var
len : Longint;
blank_with_attribute : TCharAttr;
Begin
ttyGotoXY(xl,y);
len:=xh-xl+1;
LineWrite(Space(len));
blank_with_attribute.ch:=' ';
blank_with_attribute.attr:=TextAttr;
FillWord(ConsoleBuf^[(y-1)*ScreenWidth+xl-1],len,word(blank_with_attribute));
End;
procedure DoScrollLine(y1,y2,xl,xh:longint);
{
Move Line y1 to y2, use only columns Xl-Xh, Memory is updated also
}
var
Temp : string;
idx,
OldAttr,
x,attr : longint;
begin
ttyGotoXY(xl,y2);
{ precalc ConsoleBuf[] y-offset }
idx:=(y1-1)*ScreenWidth-1;
{ update screen }
OldAttr:=$ff;
Temp:='';
For x:=xl To xh Do
Begin
attr:=ConsoleBuf^[idx+x].attr;
if (attr<>OldAttr) and (not OutputRedir) then
begin
temp:=temp+Attr2Ansi(Attr,OldAttr);
OldAttr:=Attr;
end;
Temp:=Temp+ConsoleBuf^[idx+x].ch;
if (x=xh) or (length(Temp)>240) then
begin
LineWrite(Temp);
Temp:='';
end;
End;
{Update memory copy}
Move(ConsoleBuf^[(y1-1)*ScreenWidth+xl-1],ConsoleBuf^[(y2-1)*ScreenWidth+xl-1],(xh-xl+1)*2);
end;
Procedure TextColor(Color: Byte);
{
Switch foregroundcolor
}
var AddBlink : byte;
Begin
If (Color>15) Then
AddBlink:=Blink
else
AddBlink:=0;
ttyColor((Color and $f) or (TextAttr and $70) or AddBlink);
End;
Procedure TextBackground(Color: Byte);
{
Switch backgroundcolor
}
Begin
TextAttr:=((Color shl 4) and ($f0 and not Blink)) or (TextAttr and ($0f OR Blink));
ttyColor(TextAttr);
End;
Procedure HighVideo;
{
Set highlighted output.
}
Begin
TextColor(TextAttr Or $08);
End;
Procedure LowVideo;
{
Set normal output
}
Begin
TextColor(TextAttr And $77);
End;
Procedure NormVideo;
{
Set normal back and foregroundcolors.
}
Begin
TextColor(7);
TextBackGround(0);
End;
Procedure GotoXy(X: tcrtcoord; Y: tcrtcoord);
{
Go to coordinates X,Y in the current window.
}
Begin
If (X>0) and (X<=WindMaxX- WindMinX+1) and
(Y>0) and (Y<=WindMaxY-WindMinY+1) Then
Begin
Inc(X,WindMinX-1);
Inc(Y,WindMinY-1);
ttyGotoXY(x,y);
End;
End;
Procedure Window(X1, Y1, X2, Y2: Byte);
{
Set screen window to the specified coordinates.
}
Begin
if (X1>X2) or (X2>ScreenWidth) or
(Y1>Y2) or (Y2>ScreenHeight) then
exit;
WindMinX:=X1;
WindMaxX:=X2;
WindMinY:=Y1;
WindMaxY:=Y2;
WindMin:=((Y1-1) Shl 8)+(X1-1);
WindMax:=((Y2-1) Shl 8)+(X2-1);
GoToXY(1,1);
End;
Procedure ClrScr;
{
Clear the current window, and set the cursor on 1,1
}
Var
CY,i : Longint;
oldflush : boolean;
blank_with_attribute : TCharAttr;
Begin
{ See if color has changed }
if OldTextAttr<>TextAttr then
begin
i:=TextAttr;
TextAttr:=OldTextAttr;
ttyColor(i);
end;
oldflush:=ttySetFlush(Flushing);
if FullWin then
begin
if not OutputRedir then
ttySendStr(#27'[H'#27'[2J');
CurrX:=1;
CurrY:=1;
blank_with_attribute.ch := ' ';
blank_with_attribute.attr := TextAttr;
FillWord(ConsoleBuf^,ScreenWidth*ScreenHeight,word(blank_with_attribute));
end
else
begin
For Cy:=WindMinY To WindMaxY Do
DoEmptyLine(Cy,WindMinX,WindMaxX);
GoToXY(1,1);
end;
ttySetFlush(oldflush);
End;
Procedure ClrEol;
{
Clear from current position to end of line.
}
var
len,i : longint;
IsLastLine : boolean;
Begin
{ See if color has changed }
if OldTextAttr<>TextAttr then
begin
i:=TextAttr;
TextAttr:=OldTextAttr;
ttyColor(i);
end;
if FullWin or (WindMaxX = ScreenWidth) then
begin
if not OutputRedir then
ttySendStr(#27'[K');
end
else
begin
{ Tweak WindMaxx and WindMaxy so no scrolling happends }
len:=WindMaxX-CurrX+1;
IsLastLine:=false;
if CurrY=WindMaxY then
begin
inc(WindMaxX,3);
inc(WindMaxY,2);
IsLastLine:=true;
end;
ttySendStr(Space(len));
if IsLastLine then
begin
dec(WindMaxX,3);
dec(WindMaxY,2);
end;
ttyGotoXY(0,0);
end;
End;
Function WhereX: tcrtcoord;
{
Return current X-position of cursor.
}
Begin
WhereX:=CurrX-WindMinX+1;
End;
Function WhereY: tcrtcoord;
{
Return current Y-position of cursor.
}
Begin
WhereY:=CurrY-WindMinY+1;
End;
Procedure ScrollScrnRegionUp(xl,yl,xh,yh, count: longint);
{
Scroll the indicated region count lines up. The empty lines are filled
with blanks in the current color. The screen position is restored
afterwards.
}
Var
y,oldx,oldy : byte;
oldflush : boolean;
Begin
oldflush:=ttySetFlush(Flushing);
oldx:=CurrX;
oldy:=CurrY;
{Scroll}
For y:=yl to yh-count do
DoScrollLine(y+count,y,xl,xh);
{Restore TextAttr}
ttySendStr(Attr2Ansi(TextAttr,$ff));
{Fill the rest with empty lines}
for y:=yh-count+1 to yh do
DoEmptyLine(y,xl,xh);
{Restore current position}
ttyGotoXY(OldX,OldY);
ttySetFlush(oldflush);
End;
Procedure ScrollScrnRegionDown(xl,yl,xh,yh, count: longint);
{
Scroll the indicated region count lines down. The empty lines are filled
with blanks in the current color. The screen position is restored
afterwards.
}
Var
y,oldx,oldy : byte;
oldflush : boolean;
Begin
oldflush:=ttySetFlush(Flushing);
oldx:=CurrX;
oldy:=CurrY;
{Scroll}
for y:=yh downto yl+count do
DoScrollLine(y-count,y,xl,xh);
{Restore TextAttr}
ttySendStr(Attr2Ansi(TextAttr,$ff));
{Fill the rest with empty lines}
for y:=yl to yl+count-1 do
DoEmptyLine(y,xl,xh);
{Restore current position}
ttyGotoXY(OldX,OldY);
ttySetFlush(oldflush);
End;
{*************************************************************************
KeyBoard
*************************************************************************}
Const
KeyBufferSize = 20;
var
KeyBuffer : Array[0..KeyBufferSize-1] of Char;
KeyPut,
KeySend : longint;
Procedure PushKey(Ch:char);
Var
Tmp : Longint;
Begin
Tmp:=KeyPut;
Inc(KeyPut);
If KeyPut>=KeyBufferSize Then
KeyPut:=0;
If KeyPut<>KeySend Then
KeyBuffer[Tmp]:=Ch
Else
KeyPut:=Tmp;
End;
Function PopKey:char;
Begin
If KeyPut<>KeySend Then
Begin
PopKey:=KeyBuffer[KeySend];
Inc(KeySend);
If KeySend>=KeyBufferSize Then
KeySend:=0;
End
Else
PopKey:=#0;
End;
Procedure PushExt(b:byte);
begin
PushKey(#0);
PushKey(chr(b));
end;
const
AltKeyStr : string[38]='qwertyuiopasdfghjklzxcvbnm1234567890-=';
AltCodeStr : string[38]=#016#017#018#019#020#021#022#023#024#025#030#031#032#033#034#035#036#037#038+
#044#045#046#047#048#049#050#120#121#122#123#124#125#126#127#128#129#130#131;
Function FAltKey(ch:char):byte;
var
Idx : longint;
Begin
Idx:=Pos(ch,AltKeyStr);
if Idx>0 then
FAltKey:=byte(AltCodeStr[Idx])
else
FAltKey:=0;
End;
{ This one doesn't care about keypresses already processed by readkey }
{ and waiting in the KeyBuffer, only about waiting keypresses at the }
{ TTYLevel (including ones that are waiting in the TTYRecvChar buffer) }
function sysKeyPressed: boolean;
var
fdsin : tfdSet;
begin
if (InCnt>0) then
sysKeyPressed:=true
else
begin
fpFD_ZERO(fdsin);
fpFD_SET(TTYin,fdsin);
sysKeypressed:=(fpSelect(TTYIn+1,@fdsin,nil,nil,0)>0);
end;
end;
Function KeyPressed:Boolean;
Begin
Keypressed := (KeySend<>KeyPut) or sysKeyPressed;
End;
Function ReadKey:char;
Var
ch : char;
OldState,
State : longint;
FDS : TFDSet;
Begin
{Check Buffer first}
if KeySend<>KeyPut then
begin
ReadKey:=PopKey;
exit;
end;
{Wait for Key}
{ Only if none are waiting! (JM) }
if not sysKeyPressed then
begin
FpFD_ZERO (FDS);
fpFD_SET (0,FDS);
fpSelect (1,@FDS,nil,nil,nil);
end;
ch:=ttyRecvChar;
{Esc Found ?}
CASE ch OF
#27: begin
State:=1;
Delay(10);
{ This has to be sysKeyPressed and not "keyPressed", since after }
{ one iteration keyPressed will always be true because of the }
{ pushKey commands (JM) }
while (State<>0) and (sysKeyPressed) do
begin
ch:=ttyRecvChar;
OldState:=State;
State:=0;
case OldState of
1 : begin {Esc}
case ch of
'a'..'z',
'0'..'9',
'-','=' : PushExt(FAltKey(ch));
#10 : PushKey(#10);
'[' : State:=2;
{$IFDEF Unix}
'O': State:=7;
{$ENDIF}
else
begin
PushKey(ch);
PushKey(#27);
end;
end;
end;
2 : begin {Esc[}
case ch of
'[' : State:=3;
'A' : PushExt(72);
'B' : PushExt(80);
'C' : PushExt(77);
'D' : PushExt(75);
{$IFDEF FREEBSD}
{'E' - Center key, not handled in DOS TP7}
'F' : PushExt(79); {End}
'G': PushExt(81); {PageDown}
{$ELSE}
'G' : PushKey('5'); {Center key, Linux}
{$ENDIF}
'H' : PushExt(71);
{$IFDEF FREEBSD}
'I' : PushExt(73); {PageUp}
{$ENDIF}
'K' : PushExt(79);
{$IFDEF FREEBSD}
'L' : PushExt(82); {Insert - Deekoo}
'M' : PushExt(59); {F1-F10 - Deekoo}
'N' : PushExt(60); {F2}
'O' : PushExt(61); {F3}
'P' : PushExt(62); {F4}
'Q' : PushExt(63); {F5}
'R' : PushExt(64); {F6}
'S' : PushExt(65); {F7}
'T' : PushExt(66); {F8}
'U' : PushExt(67); {F9}
'V' : PushExt(68); {F10}
{Not sure if TP/BP handles F11 and F12 like this normally;
In pcemu, a TP7 executable handles 'em this way, though.}
'W' : PushExt(133); {F11}
'X' : PushExt(134); {F12}
'Y' : PushExt(84); {Shift-F1}
'Z' : PushExt(85); {Shift-F2}
'a' : PushExt(86); {Shift-F3}
'b' : PushExt(87); {Shift-F4}
'c' : PushExt(88); {Shift-F5}
'd' : PushExt(89); {Shift-F6}
'e' : PushExt(90); {Shift-F7}
'f' : PushExt(91); {Shift-F8}
'g' : PushExt(92); {Shift-F9}
'h' : PushExt(93); {Shift-F10}
'i' : PushExt(135); {Shift-F11}
'j' : PushExt(136); {Shift-F12}
'k' : PushExt(94); {Ctrl-F1}
'l' : PushExt(95);
'm' : PushExt(96);
'n' : PushExt(97);
'o' : PushExt(98);
'p' : PushExt(99);
'q' : PushExt(100);
'r' : PushExt(101);
's' : PushExt(102);
't' : PushExt(103); {Ctrl-F10}
'u' : PushExt(137); {Ctrl-F11}
'v' : PushExt(138); {Ctrl-F12}
{$ENDIF}
'1' : State:=4;
'2' : State:=5;
'3' : State:=6;
'4' : PushExt(79);
'5' : PushExt(73);
'6' : PushExt(81);
else
begin
PushKey(ch);
PushKey('[');
PushKey(#27);
end;
end;
if ch in ['4'..'6'] then
State:=255;
end;
3 : begin {Esc[[}
case ch of
'A' : PushExt(59);
'B' : PushExt(60);
'C' : PushExt(61);
'D' : PushExt(62);
'E' : PushExt(63);
end;
end;
4 : begin {Esc[1}