-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathc_con.pas
1152 lines (1040 loc) · 30.2 KB
/
c_con.pas
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
//------------------------------------------------------------------------------
//
// FPCDoom - Port of Doom to Free Pascal Compiler
// Copyright (C) 1993-1996 by id Software, Inc.
// Copyright (C) 2004-2007 by Jim Valavanis
// Copyright (C) 2017-2022 by Jim Valavanis
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// 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. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
//------------------------------------------------------------------------------
// E-Mail: [email protected]
// Site : https://sourceforge.net/projects/fpcdoom/
//------------------------------------------------------------------------------
{$I FPCDoom.inc}
unit c_con;
//
// Console
//
interface
uses
d_event;
//==============================================================================
//
// C_Init
//
//==============================================================================
procedure C_Init;
//==============================================================================
//
// C_ShutDown
//
//==============================================================================
procedure C_ShutDown;
//==============================================================================
//
// C_AdjustScreenSize
//
//==============================================================================
procedure C_AdjustScreenSize;
//==============================================================================
//
// C_AddLine
//
//==============================================================================
procedure C_AddLine(const line: string; len: integer = -1);
//==============================================================================
//
// C_AddText
//
//==============================================================================
procedure C_AddText(const txt: string);
//==============================================================================
//
// C_Drawer
//
//==============================================================================
procedure C_Drawer;
//==============================================================================
//
// C_Ticker
//
//==============================================================================
procedure C_Ticker;
//==============================================================================
//
// C_Responder
//
//==============================================================================
function C_Responder(ev: Pevent_t): boolean;
//==============================================================================
//
// C_IsConsoleActive
//
//==============================================================================
function C_IsConsoleActive: boolean;
//==============================================================================
//
// C_ConsoleHeight
//
//==============================================================================
function C_ConsoleHeight: integer;
//==============================================================================
//
// C_AddDivideLine
//
//==============================================================================
procedure C_AddDivideLine;
var
ConsoleColormap: integer;
var
mirror_stdout: boolean;
autoexecfile: string;
const
DEFAUTOEXEC = 'FPCDoom.con';
implementation
uses
d_fpc,
doomdef,
c_cmds,
d_main,
g_game,
hu_stuff,
m_argv,
m_fixed,
i_io,
i_system,
p_tick,
r_defs,
r_main,
v_video,
w_wad,
z_memory;
const
CONSOLE_PROMPTCHAR: string = ']';
MAX_CONSOLE_LINES = 256; //must be power of 2
CONSOLETEXT_MASK = MAX_CONSOLE_LINES - 1;
CMD_HISTORY_SIZE = 64;
type
conline_t = record
line: string;
end;
consolestate_t = (
CST_UP,
CST_RAISE,
CST_LOWER,
CST_DOWN
);
var
consoleraiseticks: integer = 0;
consolelowerticks: integer = 0;
var
ConsoleText: array[0..MAX_CONSOLE_LINES - 1] of conline_t;
ConsoleHead: integer;
ConsoleWidth: integer; //chars
ConsoleHeight: integer = 0; //lines
ConsolePgUpDown: integer = -1; // Page Up / Page Down
ConsolePos: integer = 0; //bottom of console, in pixels
MaxConsolePos: integer;
ConsoleYFrac: integer = 0;
ConsoleLineBuffer: string = '';
ConsoleState: consolestate_t;
ConsoleInputBuff: string;
CommandsHistory: array[0..CMD_HISTORY_SIZE - 1] of string;
PrevCommandHead: integer;
NextCommand: integer;
con_needsupdate: boolean;
divideline: string;
var
ConsoleInitialized: boolean = false;
const
C_FONTWIDTH = 8;
C_FONTHEIGHT = 8;
//==============================================================================
//
// isDivideLine
//
//==============================================================================
function isDivideLine(const s: string): boolean;
var
i: integer;
begin
result := Length(s) > 3;
if result then
for i := 1 to Length(s) do
if not (s[i] in ['-', '=']) then
begin
result := false;
exit;
end;
end;
//==============================================================================
//
// C_ResetInputBuff
//
//==============================================================================
procedure C_ResetInputBuff;
begin
ConsoleInputBuff := CONSOLE_PROMPTCHAR;
con_needsupdate := true;
end;
//==============================================================================
//
// C_IsInputBuffEmpty
//
//==============================================================================
function C_IsInputBuffEmpty: boolean;
begin
result := ConsoleInputBuff = CONSOLE_PROMPTCHAR;
end;
//==============================================================================
// C_CmdCloseConsole
//
// Commands
//
//==============================================================================
procedure C_CmdCloseConsole(const parm: string);
var
ticks: integer;
begin
ticks := atoi(parm);
if ticks <= 0 then
ConsoleState := CST_RAISE
else
consoleraiseticks := ticks;
end;
//==============================================================================
//
// C_CmdOpenConsole
//
//==============================================================================
procedure C_CmdOpenConsole(const parm: string);
var
ticks: integer;
begin
ticks := atoi(parm);
if ticks <= 0 then
ConsoleState := CST_LOWER
else
consolelowerticks := ticks
end;
//==============================================================================
//
// C_CmdConsoleColormap
//
//==============================================================================
procedure C_CmdConsoleColormap(const parm1: string);
var
c: integer;
begin
c := atoi(parm1);
if (parm1 = '') or (c < 0) or (c >= NUMCOLORMAPS) then
begin
printf('Please specify a parameter in range [0..%d]'#13#10, [NUMCOLORMAPS - 1]);
printf('Current console colormap: %d'#13#10, [ConsoleColormap]);
end
else
ConsoleColormap := c;
end;
//==============================================================================
//
// C_CmdCls
//
//==============================================================================
procedure C_CmdCls;
var
i: integer;
begin
for i := 0 to MAX_CONSOLE_LINES - 1 do
ConsoleText[i].line := '';
C_ResetInputBuff;
end;
var
execs: TDStringList = nil;
//==============================================================================
//
// C_ExecCommandFile
//
//==============================================================================
procedure C_ExecCommandFile(const filename: string);
var
fname: string;
cmd: string;
t: text;
begin
if filename = '' then
begin
printf('Usage:'#13#10' exec [command file(*.con)]'#13#10);
exit;
end;
fname := fexpand(filename);
if not fexists(fname) then
begin
fname := fname + '.CON';
if not fexists(fname) then
begin
printf(' Command file not found: %s'#13#10, [filename]);
exit;
end;
end;
fname := strupper(fname);
if execs = nil then
execs := TDStringList.Create
else if execs.IndexOf(fname) >= 0 then
begin
I_Warning(' Recursive calls of con files is not allowed(%s)'#13#10, [filename]);
exit;
end;
execs.Add(fname);
printf(' Running command file: %s'#13#10, [fname]);
{$I-}
assign(t, fname);
FileMode := 0;
reset(t);
while not EOF(t) and (IOResult = 0) do
begin
readln(t, cmd);
cmd := strtrim(cmd);
if cmd <> '' then
if Pos('//', cmd) <> 1 then
C_ExecuteCmd(cmd);
end;
close(t);
{$I+}
execs.Delete(execs.IndexOf(fname));
end;
//==============================================================================
//
// C_CmdPrintf
//
//==============================================================================
procedure C_CmdPrintf(const parm1, parm2: string);
begin
if parm2 = '' then
printf(parm1 + #13#10)
else
printf(parm1 + ' ' + parm2 + #13#10);
end;
var
console_paused: boolean = false;
//==============================================================================
//
// C_CmdPauseConsole
//
//==============================================================================
procedure C_CmdPauseConsole;
begin
console_paused := true;
end;
//==============================================================================
//
// Cmd_Use
//
//==============================================================================
procedure Cmd_Use(const parm1, parm2: string);
begin
if parm1 = '' then
begin
C_ExecuteCmd('cmdlist', 'use*');
exit;
end;
if not C_ExecuteCmd('use' + parm1, parm2) then
printf('%s mnemonic not found!'#13#10);
end;
//==============================================================================
//
// Cmd_Freeze
//
//==============================================================================
procedure Cmd_Freeze(const parm1, parm2: string);
begin
if demoplayback or demorecording then
begin
printf('Can not freeze game while demo playback/recording'#13#10);
exit;
end;
isgamefreezed := not isgamefreezed;
if isgamefreezed then
printf('Game is freezed'#13#10)
else
printf('Game is not freezed'#13#10);
end;
//
// C_Init
//
var
consolebuffer: TDStringList;
const
MAX_CONSOLE_BUFFER = 8192;
//==============================================================================
//
// C_Init
//
//==============================================================================
procedure C_Init;
var
i: integer;
begin
consolebuffer := TDStringList.Create;
ConsoleHead := 0;
ConsoleState := CST_UP;
for i := 0 to MAX_CONSOLE_LINES - 1 do
ConsoleText[i].line := '';
C_ResetInputBuff;
C_AdjustScreenSize;
divideline := '';
for i := 1 to ConsoleWidth do
divideline := divideline + '-';
divideline := divideline + #13#10;
for i := 0 to CMD_HISTORY_SIZE - 1 do
CommandsHistory[i] := '';
PrevCommandHead := 0;
NextCommand := 0;
ConsoleInitialized := true;
C_AddText(stdoutbuffer.Text);
outproc := C_AddText;
C_AddCmd('closeconsole', @C_CmdCloseConsole);
C_AddCmd('openconsole', @C_CmdOpenConsole); // For autoexec
C_AddCmd('consolecolormap', @C_CmdConsoleColormap);
C_AddCmd('cls, clearscreen', @C_CmdCls);
C_AddCmd('cmdlist, list, listcmds', @C_CmdList);
C_AddCmd('screenshot', @G_ScreenShot);
C_AddCmd('playdemo', @G_CmdPlayDemo);
C_AddCmd('start, playgame', @G_CmdNewGame);
C_AddCmd('load, loadgame', @G_LoadGame);
C_AddCmd('save, savegame', @G_CmdSaveGame);
C_AddCmd('exec, execcommandfile', @C_ExecCommandFile);
C_AddCmd('printf, write, writeln', @C_CmdPrintf); // Mostly for autoexec
C_AddCmd('pause_console, pauseconsole', @C_CmdPauseConsole);
C_AddCmd('commandlineparams', @M_CmdShowCommandLineParams);
C_AddCmd('cmdline', @M_CmdShowCmdline);
C_AddCmd('use', @Cmd_Use);
C_AddCmd('freeze', @Cmd_Freeze);
end;
//==============================================================================
//
// C_AdjustScreenSize
//
//==============================================================================
procedure C_AdjustScreenSize;
begin
ConsoleYFrac := V_GetScreenHeight(SCN_CON) div 20;
MaxConsolePos := ConsoleYFrac * 11;
ConsoleWidth := V_GetScreenWidth(SCN_CON) div C_FONTWIDTH - 2;
ConsolePos := 0;
end;
//==============================================================================
//
// C_ShutDown
//
//==============================================================================
procedure C_ShutDown;
begin
if execs <> nil then
execs.Free;
consolebuffer.Free;
ConsoleInitialized := false;
end;
var
commandbuffer: string;
//==============================================================================
//
// C_RestoreFromBuffer
//
//==============================================================================
procedure C_RestoreFromBuffer;
var
i: integer;
begin
for i := consolebuffer.Count - MAX_CONSOLE_LINES to consolebuffer.Count - 1 do
begin
ConsoleHead := (ConsoleHead + CONSOLETEXT_MASK) and CONSOLETEXT_MASK;
if i >= 0 then
ConsoleText[ConsoleHead].line := consolebuffer.Strings[i]
else
ConsoleText[ConsoleHead].line := '';
end;
i := (ConsoleHead + CONSOLETEXT_MASK) and CONSOLETEXT_MASK;
ConsoleText[i].line := '';
end;
//==============================================================================
//
// C_AddLine
//
//==============================================================================
procedure C_AddLine(const line: string; len: integer = -1);
var
cline: string;
i, j: integer;
begin
if not ConsoleInitialized then
exit; //not initialised yet
if line = '' then
cline := ' '
else
begin
cline := '';
if len = -1 then
len := Length(line);
for i := 1 to len do
begin
if line[i] = #8 then
begin
if cline <> '' then
SetLength(cline, Length(cline) - 1);
end
else
cline := cline + line[i];
end;
end;
if console_paused then
begin
commandbuffer := commandbuffer + cline + #13#10;
end
else
begin
if ConsolePgUpDown <> -1 then
begin
C_RestoreFromBuffer;
ConsolePgUpDown := -1;
end;
ConsoleHead := (ConsoleHead + CONSOLETEXT_MASK) and CONSOLETEXT_MASK;
ConsoleText[ConsoleHead].line := cline;
consolebuffer.Add(cline);
if consolebuffer.Count > MAX_CONSOLE_BUFFER then
for j := 0 to MAX_CONSOLE_BUFFER div 4 do
consolebuffer.Delete(0);
i := (ConsoleHead + CONSOLETEXT_MASK) and CONSOLETEXT_MASK;
ConsoleText[i].line := '';
con_needsupdate := true;
end;
end;
//==============================================================================
//
// C_DoPageUp
//
//==============================================================================
procedure C_DoPageUp;
var
bufstart, bufend: integer;
i: integer;
begin
if consolebuffer.Count < ConsoleHeight then
Exit; // Too short output to page up
if ConsolePgUpDown = 0 then
Exit; // At the top
if ConsolePgUpDown = -1 then
ConsolePgUpDown := consolebuffer.Count - 2 * ConsoleHeight
else
ConsolePgUpDown := ConsolePgUpDown - ConsoleHeight;
if ConsolePgUpDown < 0 then
ConsolePgUpDown := 0;
bufstart := ConsolePgUpDown;
bufend := ConsolePgUpDown + ConsoleHeight - 1;
for i := bufstart to bufend do
begin
ConsoleHead := (ConsoleHead + CONSOLETEXT_MASK) and CONSOLETEXT_MASK;
if i < consolebuffer.Count then
ConsoleText[ConsoleHead].line := consolebuffer.Strings[i]
else
ConsoleText[ConsoleHead].line := '';
end;
i := (ConsoleHead + CONSOLETEXT_MASK) and CONSOLETEXT_MASK;
ConsoleText[i].line := '';
con_needsupdate := true;
end;
//==============================================================================
//
// C_DoPageDown
//
//==============================================================================
procedure C_DoPageDown;
var
bufstart, bufend: integer;
i: integer;
begin
if consolebuffer.Count < ConsoleHeight then
Exit; // Too short output to page up
if ConsolePgUpDown = -1 then
Exit; // At the end
if ConsolePgUpDown >= consolebuffer.Count - ConsoleHeight then
ConsolePgUpDown := ConsolePgUpDown - 2 * ConsoleHeight
else
ConsolePgUpDown := ConsolePgUpDown + ConsoleHeight;
if ConsolePgUpDown >= consolebuffer.Count - ConsoleHeight then
begin
C_RestoreFromBuffer;
ConsolePgUpDown := -1;
con_needsupdate := true;
Exit;
end;
bufstart := ConsolePgUpDown;
bufend := ConsolePgUpDown + ConsoleHeight - 1;
for i := bufstart to bufend do
begin
ConsoleHead := (ConsoleHead + CONSOLETEXT_MASK) and CONSOLETEXT_MASK;
if i >= 0 then
ConsoleText[ConsoleHead].line := consolebuffer.Strings[i]
else
ConsoleText[ConsoleHead].line := '';
end;
i := (ConsoleHead + CONSOLETEXT_MASK) and CONSOLETEXT_MASK;
ConsoleText[i].line := '';
con_needsupdate := true;
end;
//==============================================================================
//
// C_AddText
//
//==============================================================================
procedure C_AddText(const txt: string);
var
i: integer;
c: char;
begin
if not ConsoleInitialized then
exit; //not initialised yet
for i := 1 to Length(txt) do
begin
c := txt[i];
if c = #13 then
C_AddLine(ConsoleLineBuffer)
else if c = #10 then
ConsoleLineBuffer := ''
else
ConsoleLineBuffer := ConsoleLineBuffer + c;
end;
if mirror_stdout then
fprintf(stdout, txt);
end;
//==============================================================================
//
// C_RunAutoExec
//
//==============================================================================
procedure C_RunAutoExec;
var
str: TDstringList;
deffile: string;
begin
printf('C_RunAutoExec()'#13#10);
if not fexists(M_SaveFileName(DEFAUTOEXEC)) then
begin
str := TDStringList.Create;
try
str.Add('// Add autoexec console commands in this file.');
deffile := M_SaveFileName(DEFAUTOEXEC);
str.SaveToFile(deffile);
finally
str.Free;
end;
end;
C_ExecCommandFile(autoexecfile);
end;
var
shiftdown: boolean = false;
firsttime: boolean = true;
//==============================================================================
//
// C_Responder
//
//==============================================================================
function C_Responder(ev: Pevent_t): boolean;
var
c: integer;
begin
if not ConsoleInitialized then
begin
result := false;
exit; //not initialised yet
end;
if firsttime then
begin
C_RunAutoExec;
firsttime := false;
end;
if (ev._type <> ev_keyup) and (ev._type <> ev_keydown) then
begin
result := false;
exit;
end;
c := ev.data1;
if c = KEY_RSHIFT then
shiftdown := ev._type = ev_keydown;
case ConsoleState of
CST_DOWN,
CST_LOWER:
begin
if ev._type = ev_keydown then
begin
if console_paused then
begin
console_paused := false;
C_AddText(commandbuffer);
commandbuffer := '';
end
else
case c of
KEY_CON:
begin
ConsoleState := CST_RAISE;
end;
KEY_ESCAPE:
begin
if not C_IsInputBuffEmpty then
C_ResetInputBuff
else
ConsoleState := CST_RAISE
end;
KEY_ENTER:
begin
if not C_IsInputBuffEmpty then
begin
C_AddText(ConsoleInputBuff + #13#10);
CommandsHistory[PrevCommandHead] := ConsoleInputBuff;
inc(PrevCommandHead);
NextCommand := PrevCommandHead;
if PrevCommandHead >= CMD_HISTORY_SIZE then
PrevCommandHead := 0;
CommandsHistory[PrevCommandHead] := '';
if not C_ExecuteCmd(Copy(ConsoleInputBuff, Length(CONSOLE_PROMPTCHAR) + 1, Length(ConsoleInputBuff) - Length(CONSOLE_PROMPTCHAR))) then
C_UnknowCommandMsg;
C_ResetInputBuff;
end;
end;
KEY_UPARROW,
KEY_DOWNARROW:
begin
if c = KEY_UPARROW then
begin
c := NextCommand - 1;
if c < 0 then
c := CMD_HISTORY_SIZE - 1
end
else
begin
c := NextCommand + 1;
if c >= CMD_HISTORY_SIZE then
c := 0;
end;
if CommandsHistory[c] <> '' then
begin
ConsoleInputBuff := CommandsHistory[c];
NextCommand := c;
con_needsupdate := true;
end;
end;
KEY_BACKSPACE:
begin
if not C_IsInputBuffEmpty then
begin
SetLength(ConsoleInputBuff, Length(ConsoleInputBuff) - 1);
con_needsupdate := true;
end;
end;
KEY_PAGEUP:
C_DoPageUp;
KEY_PAGEDOWN:
C_DoPageDown;
else
begin
c := Ord(toupper(Chr(c)));
if ((c >= Ord(HU_FONTSTART)) and (c <= Ord(HU_FONTEND))) or
(Chr(c) in [' ', '.', '!', '-', '+', '=', '*', '/', '\']) then
begin
if shiftdown then
c := Ord(shiftxform[c]);
ConsoleInputBuff := ConsoleInputBuff + Chr(c);
con_needsupdate := true;
end;
end;
end;
result := true;
exit;
end;
end;
CST_UP,
CST_RAISE:
begin
if c = Ord('~') then
begin
if ev._type = ev_keydown then
begin
ConsoleState := CST_LOWER;
result := true;
exit;
end;
end;
end;
end;
if (ev._type = ev_keydown) and ((devparm and (c = KEY_F1)) or (c = KEY_PRNT)) then
begin
G_ScreenShot;
result := true;
exit;
end;
result := false;
end;
const
C_BLINKRATE = TICRATE * 3 div 4;
var
cursonon: boolean = false;
cursorticker: integer = C_BLINKRATE;
cursor_x: integer = 0;
cursor_y: integer = 0;
cursor_needs_update: boolean = true;
//==============================================================================
//
// C_Ticker
//
//==============================================================================
procedure C_Ticker;
begin
if not ConsoleInitialized then
exit; //not initialised yet
if consoleraiseticks > 0 then
begin
dec(consoleraiseticks);
if consoleraiseticks = 0 then
ConsoleState := CST_RAISE;
end;
if consolelowerticks > 0 then
begin
dec(consolelowerticks);
if consolelowerticks = 0 then
ConsoleState := CST_LOWER;
end;
case ConsoleState of
CST_LOWER:
begin
inc(ConsolePos, ConsoleYFrac);
if ConsolePos >= MaxConsolePos then
begin
ConsoleState := CST_DOWN;
MaxConsolePos := (1 + ConsoleHeight) * C_FONTHEIGHT;
ConsolePos := MaxConsolePos; // Crop MaxConsolePos
end
else
ConsoleHeight := ConsolePos div C_FONTHEIGHT;
con_needsupdate := true;
end;
CST_RAISE:
begin
if ConsolePos < MaxConsolePos div 5 then
dec(ConsolePos, ConsoleYFrac)
else
dec(ConsolePos, 2 * ConsoleYFrac); // Raise console faster...
if ConsolePos <= 0 then
begin
ConsoleState := CST_UP;
ConsolePos := 0;
ConsoleHeight := 0;
end
else
ConsoleHeight := ConsolePos div C_FONTHEIGHT;
con_needsupdate := true;
end;
end;
// Decide of cursor visibility
dec(cursorticker);
if cursorticker = 0 then
begin
cursonon := not cursonon;
cursorticker := C_BLINKRATE;
if cursonon then
cursor_needs_update := true
else
con_needsupdate := true;
end;
end;
//==============================================================================
//
// C_DrawConsoleBackground
//
//==============================================================================
procedure C_DrawConsoleBackground;
begin
V_DrawPatch(0, 0, SCN_TMP, 'TITLEPIC', false);
// A little bit darker background...
R_ApplyColormap(0, 320 * 200, SCN_TMP, ConsoleColormap);
V_CopyRect(0, 0, SCN_TMP, 320, 200, 0, 0, SCN_CON, true);
end;
const
FIXED_PITCH_CHARS = ['1'..'9', '0', '.', '=', '-'];
//==============================================================================
//
// C_Drawer
//
//==============================================================================
procedure C_Drawer;
var
line: integer;
y: integer;
i: integer;
c: char;
x: integer;
len: integer;
lnum: integer;
xmax: integer;
patch: Ppatch_t;
begin
if not ConsoleInitialized then
exit; //not initialised yet
if ConsoleHeight <= 0 then
exit;
xmax := ConsoleWidth * C_FONTWIDTH;
if con_needsupdate then
begin