forked from MarkHofmann11/WWIVEdit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWWIVOUTP.PAS
361 lines (323 loc) · 8.04 KB
/
WWIVOUTP.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
UNIT WWIVOutp;
{$I WEGLOBAL.PAS}
INTERFACE
{ -- Output unit for WWIVEdit 2.3. This should be generic enough to use with
-- any WWIV on liner. It provides an interface to the output portion of the
-- Fossil and NewCrt units.
}
USES NewCrt;
CONST
C0 = ^C'0';
C1 = ^C'1';
C2 = ^C'2';
C3 = ^C'3';
C4 = ^C'4';
C5 = ^C'5';
C6 = ^C'6';
C7 = ^C'7';
ESC = #27;
working: boolean=FALSE;
IDColorMap: string[9]='IDCLRMAP*';
ColorMap : Array[0..255] OF Byte = (
007,007,007,007,007,007,007,007,007,007, { 0.. 9}
007,007,007,007,007,007,007,007,007,007, { 10.. 19}
007,007,007,007,007,007,007,007,007,007, { 20.. 29}
007,007,007,007,007,007,007,007,007,007, { 30.. 39}
007,007,007,007,007,007,007,007,007,011, { 40.. 49}
014,005,031,002,140,009,007,007,007,007, { 50.. 59}
007,007,007,007,007,007,007,007,007,007, { 60.. 69}
007,007,007,007,007,007,007,007,007,007, { 70.. 79}
007,007,007,007,007,007,007,007,007,007, { 80.. 89}
007,007,007,007,007,007,007,007,007,007, { 90.. 99}
007,007,007,007,007,007,007,007,007,007, {100..109}
007,007,007,007,007,007,007,007,007,007, {110..119}
007,007,007,007,007,007,007,007,007,007, {120..129}
007,007,007,007,007,007,007,007,007,007, {130..139}
007,007,007,007,007,007,007,007,007,007, {140..149}
007,007,007,007,007,007,007,007,007,007, {150..159}
007,007,007,007,007,007,007,007,007,007, {160..169}
007,007,007,007,007,007,007,007,007,007, {170..179}
007,007,007,007,007,007,007,007,007,007, {180..189}
007,007,007,007,007,007,007,007,007,007, {190..199}
007,007,007,007,007,007,007,007,007,007, {200..209}
007,007,007,007,007,007,007,007,007,007, {210..219}
007,007,007,007,007,007,007,007,007,007, {220..229}
007,007,007,007,007,007,007,007,007,007, {230..239}
007,007,007,007,007,007,007,007,007,007, {240..249}
007,007,007,007,007,007 {250..255}
);
PROCEDURE GotoXY(x,y:integer);
PROCEDURE ClrScr;
PROCEDURE ClrEol;
FUNCTION WhereX : byte;
FUNCTION WhereY : byte;
PROCEDURE InitOutp(MaxX,MaxY:integer; SetDirectVideo,SetComm,SetFossil,color,IS_WWIV:Boolean; port:byte);
PROCEDURE MoveLeft(n:integer);
PROCEDURE ReverseVideoOn;
PROCEDURE ReverseVideoOff;
PROCEDURE BiosScrollWindowUp(x1,y1,x2,y2:byte);
PROCEDURE BiosScrollWindowDown(x1,y1,x2,y2:byte);
IMPLEMENTATION
USES WECom,WEFossil, DOS;
TYPE
Translation = (None, Bios, DirectVideo, ANSI);
DisplayRec = RECORD
{ Txt : POINTER; { pointer to the text part of the display }
{ Clr : POINTER; { pointer to the color part of the display }
x,y : byte; { Current X and Y coords }
mx,my: byte; { Max X and Y coords }
END;
CONST
Translate : Translation = DirectVideo;
VAR
OldOutput : text;
CenterString : string;
D : DisplayRec; { The primary dispay }
FG, BG : Byte; { The foreground and background colors }
CurrentColor : Char;
IS_WWIV : boolean;
PROCEDURE BiosScrollWindowUp(x1,y1,x2,y2:byte);
BEGIN
NewCRT.BiosScrollWindowUp(x1,y1,x2,y2);
END;
PROCEDURE BiosScrollWindowDown(x1,y1,x2,y2:byte);
BEGIN
NewCRT.BiosScrollWindowDown(x1,y1,x2,y2);
END;
FUNCTION Pos:word;
BEGIN
WITH d do
Pos:=(y-1)+MX+x-1;
END;
FUNCTION WhereX : byte;
BEGIN
flush(output);
WhereX:=d.x;
END;
FUNCTION WhereY : byte;
BEGIN
flush(output);
WhereY:=d.Y;
END;
PROCEDURE GotoXY(x,y:integer);
BEGIN
flush(output);
d.x:=x; d.y:=y;
IF Translate=DirectVideo THEN
NewCrt.gotoxy(x,y)
ELSE write(oldoutput,ESC,'[',y,';',x,'H');
END;
PROCEDURE ClrScr;
BEGIN
flush(output);
gotoxy(1,1);
IF Translate=DirectVideo THEN
NewCrt.ClrScr
ELSE write(oldoutput,ESC,'[2J');
END;
PROCEDURE ClrEol;
BEGIN
flush(output);
IF Translate=DirectVideo THEN
NewCrt.ClrEol
ELSE write(oldoutput,ESC,'[K');
END;
PROCEDURE Color(F,B:integer);
BEGIN
fg:=f; bg:=b;
newcrt.textcolor(f);
newcrt.textbackground(b);
END;
PROCEDURE DoColor(ch:char);
CONST
AnsiTr : ARRAY[0..7] OF Byte = (0, 4, 2, 6, 1, 5, 3, 7);
VAR
s:string;
tmp:string[5];
BEGIN
CurrentColor:=ch;
IF Translate=DirectVideo THEN
BEGIN
Flush(output);
TextAttr:=ColorMap[ord(ch)];
Fg:=TextAttr AND $F;
BG:=(TextAttr AND $70) div 16;
END ELSE IF (IS_WWIV) THEN write(oldoutput,^C+ch)
ELSE
BEGIN
TextAttr:=ColorMap[ord(ch)];
Fg:=TextAttr AND $F;
BG:=(TextAttr AND $70) div 16;
s:=#27+'[0m';
write(OldOutput,s);
s:=#27+'[';
IF FG>7 THEN s:=s+'1;';
str(30+ansitr[fg mod 8],tmp);
s:=s+tmp+';';
str(40+ansitr[bg],tmp);
s:=s+tmp;
IF TextAttr AND $80 >0 THEN
s:=s+';5';
s:=s+'m';
write(oldoutput,s);
END;
END;
PROCEDURE ReverseVideoOn;
BEGIN
flush(output);
IF Translate=DirectVideo THEN
Color(bg,fg)
ELSE
write(oldoutput,ESC+'[7m');
END;
PROCEDURE ReverseVideoOff;
BEGIN
flush(output);
IF Translate=DirectVideo THEN
Color(bg,fg)
ELSE BEGIN
write(oldoutput,ESC+'[0m');
DoColor(CurrentColor);
END;
END;
PROCEDURE Center(VAR s:string);
VAR
i,l : integer;
BEGIN
l:=0;
FOR i:=1 TO length(s) DO
BEGIN
inc(l);
IF s[i]=^C THEN dec(l,2);
END;
FOR i:=1 TO 40-(l div 2) DO
write(OldOutput,' ');
WHILE s<>'' DO
IF s[1]<>^C THEN
BEGIN
write(OldOutput,s[1]);
delete(s,1,1);
END
ELSE BEGIN
DoColor(s[2]);
delete(s,1,2);
END;
END;
{$F+}
FUNCTION DoNothing(VAR f:TextRec):integer;
BEGIN
DoNothing :=0;
END;
VAR
inverseon:boolean;
PROCEDURE MoveLeft(n:integer);
BEGIN
flush(output);
IF d.x>n THEN d.x:=d.x-n ELSE d.x:=1;
IF Translate=DirectVideo THEN gotoxy(d.x,d.y)
ELSE write(oldoutput,ESC,'[',n,'D');
END;
FUNCTION TranslateOutput(VAR f:TextRec):integer;
VAR
i:integer;
ch : char;
p : integer;
x, y, e : integer;
s:string;
BEGIN
IF NOT working AND (f.Bufpos>0) THEN
WITH f DO
BEGIN
working:=true;
s:='';
FOR i:=0 TO BufPos-1 DO
BEGIN
ch :=BufPtr^[i];
CASE UserData[1] OF
0 : BEGIN
IF ch=^M THEN
d.x:=0
ELSE IF ch=^J THEN
BEGIN
dec(d.x);
inc(d.y);
END
ELSE IF (ch=^H) AND (d.x>1) THEN dec(d.x,2);
IF ch=^C THEN
UserData[1]:=1
ELSE
IF ch=^L THEN BEGIN
s:='';
clrscr
END
ELSE IF (ch=^B) AND (d.x=1) THEN
UserData[1]:=2
ELSE
BEGIN
inc(d.x);
IF d.x>d.mx THEN
BEGIN
d.x:=1;
inc(d.y);
END;
s:=s+ch;
{write(OldOutput,ch);}
END
END;
1 : BEGIN
write(OldOutput,s);
s:='';
DoColor(ch);
UserData[1]:=0;
END;
2 : IF ch<>^M THEN
CenterString := CenterString + ch
ELSE BEGIN
Center(CenterString);
UserData[1]:=0;
write(OldOutput,^M);
CenterString := '';
END;
END;
END;
write(oldoutput,s);
s:='';
f.BufPos:=0;
working:=false;
END;
TranslateOutput:=0;
END;
PROCEDURE InitOutp(MaxX,MaxY:integer;
SetDirectVideo,SetComm,SetFossil,color,IS_WWIV:Boolean; port:byte);
BEGIN
(* THE NEXT TWO LINES ARE NEEDED IF YOU WANT TO MODIFY THE COLORMAP EXTERNALLY*)
CenterString:=IdColorMap;
CenterString:=chr(colormap[0]);
CenterString:='';
WWIVOUTP.IS_WWIV:=IS_WWIV;
IF SetDirectVideo THEN InitNewCrt(color,MaxY)
ELSE IF SetFossil THEN FossilInit(port)
ELSE IF SetComm THEN AsyncInit(port);
IF SetDirectVideo THEN
Translate:=DirectVideo
ELSE
Translate:=None;
TextRec(OldOutput) := TextRec(OutPut);
WITH TextRec(Output) DO
BEGIN
Mode:=fmOutput;
InOutFunc := @TranslateOutput;
FlushFunc := @TranslateOutput;
GetMem(BufPtr,128);
UserData[1]:=0;
END;
WITH D DO
BEGIN
{ GetMem(Txt,MaxX*MaxY);
GetMem(Clr,MaxX*MaxY);}
x:=1; y:=1;
mx:=maxx; my:=maxy;
END;
END;
{$F-}
END.