This repository has been archived by the owner on Nov 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSCREEN.PAS
257 lines (240 loc) · 5.29 KB
/
SCREEN.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
{$A-,B-,D-,E-,F-,I-,L-,N-,O-,R-,S-,V-}
{$M 16384,0,655360}
unit Screen;
interface
uses Crt,Strings;
type
str=^string;
Wind=record
y1,x1,y2,x2,ysize:byte;
first,pos:byte;{pos - current line}
scr:array[1..24] of str;
end;
Keyboard=(Space,Enter,Homekey,PgUp,
Endkey,PgDn,Up,Down,Left,Right,
F1,F2,F3,F4,F5,F6,F7,F8,F9,F10,
Esc,Yes,No,Another);
var
MainWnd,ExerWnd,Current:Wind;
color,highcolor:byte;
CurrentMode:Workmode;
procedure NormalMode;
{procedure HighMode;}
{procedure Inverse;}
procedure ClrBuf(var w:Wind);
procedure ClrScreen;
procedure NewWnd(x1,y1,x2,y2:byte;var w:Wind);
procedure WriteWnd;
procedure ActivateWnd(var w:Wind);
procedure WriteBuf(var s:string);
procedure WriteLine(var s:string);
procedure Change(y,x:byte;var s:string);
function GetKey:Keyboard;
procedure WriteMenu(s:string);
procedure WriteMenuBar;
implementation
procedure NormalMode;
begin
lowvideo;
textcolor(color);
textbackground(black);
end;
procedure HighMode;
begin
highvideo;
textcolor(highcolor);
textbackground(black);
end;
procedure Inverse;
begin
lowvideo;
textcolor(black);
textbackground(color);
end;
procedure ClrBuf(var w:Wind);
var i:byte;
begin
with w do begin
for i:=1 to ysize do
scr[i]^:='';
pos:=1;first:=1;
end;
end;
procedure ClrScreen;
begin
ClrBuf(Current);
clrscr;
WriteMenuBar;
Current.pos:=1;
gotoxy(1,1)
end;
procedure NewWnd(x1,y1,x2,y2:byte;var w:Wind);
var i:byte;
begin
w.x1:=x1;w.y1:=y1;
w.x2:=x2;w.y2:=y2;
w.pos:=1;w.first:=1;
w.ysize:=y2-y1+1;
for i:=1 to w.ysize do begin
new(w.scr[i]);
w.scr[i]^:='';
end;
end;
procedure WriteLine(var s:string);
var l,x, i,len:byte;
ch:char;
begin
with Current do begin
len:=length(s);x:=1;i:=1;
WHILE (i<=len) and (x<x2-x1+1) do BEGIN
Case s[i] of
'\':begin
Inc(i);
case s[i] of
'\':begin
write('\');
Inc(x);
end;
' ':TextAttr:=7;
'h':HighMode;
'i':Inverse; {inversed text}
'b':Inc(TextAttr,$80);{blinking}
end;
Inc(i);
end;
Else
begin
write(s[i]);
Inc(x);Inc(i);
end;
End;{of Case}
END;{of WHILE ... BEGIN}
NormalMode;
clreol;
writeln;
end;{of with}
end;
procedure WriteWnd;
var l,y:byte;
begin
NormalMode;
with Current do begin
window(x1,y1,x2,y2);
l:=(first-1)mod ysize+1;
gotoxy(1,1);
for y:=1 to ysize-1 do begin
writeline(scr[l]^);
l:=l mod ysize+1;
end;
gotoxy(1,pos);
end;
end;
procedure ActivateWnd(var w:Wind);
var i:byte;
begin
with w do
window(x1,y1,x2,y2);
Current:=w;
WriteWnd;
end;
procedure WriteBuf(var s:string);
begin
with Current do begin
scr[(pos+first-2)mod ysize+1]^:=s;
if pos=y2 then first:=first mod ysize+1
else inc(pos);
end;
end;
procedure Change(y,x:byte;var s:string);
var l:byte;st:string;
begin
with Current do begin
y:=pos-y;
l:=(y+first-2) mod ysize+1;
st:=scr[l]^;
if x>=length(st) then x:=length(st)-1;
if x=0 then x:=1;
delete(st,x,length(s));insert(s,st,x);
gotoxy(1,y);writeline(st);
scr[l]^:=st;
end;
end;
function Getkey:Keyboard;
var
ch:char;c:byte;
wminold,wmaxold:word;
xold,yold:byte;
begin
wminold:=windmin;wmaxold:=windmax;
xold:=wherex;yold:=wherey;
window(1,25,2,25);
gotoxy(1,1);
ch:=readkey;
if ch=#0 then begin
c:=ord(readkey);
case c of
59..68:Getkey:=Keyboard(ord(F1)+c-59);
71:Getkey:=Homekey;
73:Getkey:=PgUp;
79:Getkey:=Endkey;
81:Getkey:=PgDn;
72:Getkey:=Up;
80:Getkey:=Down;
75:Getkey:=Left;
77:Getkey:=Right;
else Getkey:=Another;
end;
end
else
case ch of
'y','d','¤':Getkey:=Yes;
'n','':Getkey:=No;
#32:Getkey:=Space;
#13:Getkey:=Enter;
#27:Getkey:=Esc;
else Getkey:=Another;
end;
window(lo(wminold)+1,hi(wminold)+1,lo(wmaxold)+1,hi(wmaxold)+1);
gotoxy(xold,yold);
end;
procedure WriteMenu(s:string);
var
i,len,color:byte;
begin
window(1,25,80,25);
HighMode;
color:=white;textcolor(color);
len:=length(s);i:=1;
while i<=len do begin
if s[i]='\' then begin
if color=magenta then begin
color:=white;highvideo;
end
else begin
color:=magenta;lowvideo;
end;
Inc(i);
end;
write(s[i]);
Inc(i);
end;
NormalMode;
clreol;
with Current do begin
window(x1,y1,x2,y2);
gotoxy(1,pos);
end;
end;
procedure WriteMenuBar;
begin
WriteMenu(menu[CurrentMode]);
end;
var k:Keyboard;
begin
color:=lightgray;
highcolor:=white;
NewWnd(1,1,80,24,MainWnd);
NewWnd(1,1,80,24,ExerWnd);
clrscr;
Current:=MainWnd;
end.