-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathddplus.pas
301 lines (264 loc) · 8.15 KB
/
ddplus.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
unit DDPlus;
{$mode objfpc}{$H-}
interface
const
ProgName: string[60] = 'DDPlus via RMDoor';
var
AnsiOn: Boolean; {Process ANSI locally }
Default_Fore: Byte; {default foreground color }
Graphics: Byte; {from DROP FILE: graphics code }
Local: Boolean; {from DROP FILE: local mode }
LocalCol: Boolean; {From .CTL file: Local color enabled }
MaxTime: Word; {from .CTL file: maximum time in door }
Node_Num: Integer; {Node number }
NoTime: String; {Out of time filename }
Stacked: String; {used internally - stacked commands }
StatLine: Boolean; {status line background }
User_First_Name: String[30]; {from DROP FILE: user's first name }
User_Last_Name: String[30]; {from DROP FILE: user's last name }
procedure Display_Status(AForce: Boolean); {jakob added force!}
procedure DisplayFile1(const AFileName: string); {jakobs special! remove original!}
procedure Elapsed(AHour1, AMin1, ASec1, AHour2, AMin2, ASec2: LongInt; var AOutHour, AOutMin, AOutSec: LongInt);
procedure InitDoorDriver(AConfigFileName: String);
function LoCase(ACh: Char): Char;
procedure PromptJ(var AText: String; ALength: Integer; APromptColour: Boolean; AGetStack: Boolean);
procedure PromptSec(var AText: String; ALength: Integer; APromptColour: Boolean; AMask: Char); {jakobs own edited version}
procedure PromptWR(var AText: String; ALength: Integer; APromptColour: Boolean); {jakobs own edited version}
procedure ReleaseTimeSlice;
procedure Set_Background(AColour: Byte);
procedure Set_Color(AFore, ABack: Byte);
procedure Set_Foreground(AColour: Byte);
procedure SClrScr;
procedure SGoto_XY(AX, AY: Integer);
function SKeyPressed: Boolean;
procedure SRead_Char(var ACh: Char);
procedure SWrite(AText: String);
procedure SWriteC(ACh: Char);
procedure SWriteLn(AText: String);
function Time_Left: Integer;
function va(AInt: Integer): String;
implementation
uses
Ansi, Door, FileUtils,
SysUtils;
procedure Display_Status(AForce: Boolean); {jakob added force!}
begin
if Assigned(DoorOnStatusBar) AND NOT(DoorLocal) AND NOT(DoorSTDIO) then DoorOnStatusBar;
end;
procedure DisplayFile1(const AFileName: string); {jakobs special! remove original!}
var
Ch: Char;
F: Text;
LineIndex: Integer;
NonStop: Boolean;
Quit: Boolean;
S: String;
begin
// TODOX Not exactly matching logic
// If filename contains period, use it.
// Otherwise try extension based on graphcs mode with fallback to lower graphics modes until a match is found
// (ie ANSI tries ANSI then ASCII, RIP tries RIP then ANSI then ASCII)
if NOT(OpenFileForRead(F, AFileName, 100)) then
begin
if NOT(OpenFileForRead(F, AFileName + '.ANS', 100)) then
begin
if NOT(OpenFileForRead(F, AFileName + '.ASC', 100)) then
begin
// Unable to read file:
// d(error_col, error_mes + 'Unable to READ : ' + s);
// d(error_col, '(' + error_message(error) + ')');
DoorTextColour(12);
DoorWriteLn('File-Alert! Unable to READ : ' + AFileName);
Exit;
end;
end;
end;
LineIndex := 0;
NonStop := false;
Quit := false;
repeat
ReadLn(F, S);
DoorWriteLn(S);
// If a key was hit, read it. If it was CTRL-C, CTRL-K, or S, stop output
if (DoorKeyPressed) then
begin
Ch := DoorReadKey;
if (Ch in [^C, ^K, 's', 'S']) then
begin
Quit := true;
end;
end;
// If we've shown a screen full of text, then show the continue prompt
if NOT(Quit) then
begin
Inc(LineIndex);
if (LineIndex mod 23 = 0) AND NOT(NonStop) then // TODOX 23
begin
DoorWrite('(C)ontinue, (N)on-stop, (S)top ? ');
Ch := DoorReadKey;
DoorWrite(AnsiGotoX(1) + AnsiClrEol);
if Ch in ['S', 's'] then
begin
Quit := true;
end;
if Ch in ['N', 'n'] then
begin
NonStop := true;
end;
end;
end;
until EOF(F) OR Quit;
Close(F);
DoorTextColour(Default_Fore);
end;
procedure Elapsed(AHour1, AMin1, ASec1, AHour2, AMin2, ASec2: LongInt; var AOutHour, AOutMin, AOutSec: LongInt);
var
a, b, c: Integer;
begin
if AHour1 < AHour2 then
AHour1 := AHour1 + 24;
a := (AHour1 * 3600) + (AMin1 * 60) + ASec1;
b := (AHour2 * 3600) + (AMin2 * 60) + ASec2;
c := a - b;
AOutHour := c div 3600;
c := c mod 3600;
AOutMin := c div 60;
c := c mod 60;
AOutSec := c;
end;
procedure InitDoorDriver(AConfigFileName: String);
var
I: Integer;
SawSpace: Boolean;
begin
// TODOX Big function, haven't confirmed matching implementation yet
DoorStartUp;
if (DoorDropInfo.Emulation = etASCII) then
begin
Graphics := 2;
end else
begin
Graphics := 3;
end;
Local := DoorLocal;
MaxTime := DoorDropInfo.MaxSeconds div 60;
Node_Num := DoorDropInfo.Node;
User_First_Name := '';
User_Last_Name := '';
SawSpace := false;
for I := 1 to Length(DoorDropInfo.RealName) do
begin
if (DoorDropInfo.RealName[I] = ' ') then
begin
SawSpace := true;
end else
if (SawSpace) then
begin
User_Last_Name := User_Last_Name + DoorDropInfo.RealName[I];
end else
begin
User_First_Name := User_First_Name + DoorDropInfo.RealName[I];
end;
end;
end;
function LoCase(ACh: Char): Char;
begin
Result := LowerCase(ACh);
end;
procedure PromptJ(var AText: String; ALength: Integer; APromptColour: Boolean; AGetStack: Boolean);
begin
// TODOX Big function, haven't confirmed matching implementation yet
AText := DoorInput(AText, DOOR_INPUT_CHARS_ALL, #0, ALength, ALength, 23);
end;
procedure PromptSec(var AText: String; ALength: Integer; APromptColour: Boolean; AMask: Char); {jakobs own edited version}
begin
// TODOX Big function, haven't confirmed matching implementation yet
AText := DoorInput(AText, DOOR_INPUT_CHARS_ALL, AMask, ALength, ALength, 23);
end;
procedure PromptWR(var AText: String; ALength: Integer; APromptColour: Boolean); {jakobs own edited version}
begin
// TODOX Big function, haven't confirmed matching implementation yet
AText := DoorInput(AText, DOOR_INPUT_CHARS_ALL, #0, ALength, ALength, 23);
end;
procedure ReleaseTimeSlice;
begin
// TODOX Confirm this is CPU friendly on all platforms
Sleep(1);
end;
procedure SClrScr;
begin
DoorClrScr;
end;
procedure Set_Background(AColour: Byte);
begin
// TODOX Big function, haven't confirmed matching implementation yet
DoorTextBackground(AColour);
end;
procedure Set_Color(AFore, ABack: Byte);
begin
// TODOX Big function, haven't confirmed matching implementation yet
DoorTextBackground(ABack);
DoorTextColour(AFore);
end;
procedure Set_Foreground(AColour: Byte);
begin
// TODOX Big function, haven't confirmed matching implementation yet
DoorTextColour(AColour);
end;
procedure SGoto_XY(AX, AY: Integer);
begin
DoorGotoXY(AX, AY);
end;
function SKeyPressed: Boolean;
begin
// TODOX References macro variable, grep says it may not be used
Result := DoorKeyPressed;
end;
procedure SRead_Char(var ACh: Char);
begin
// TODOX Has some weird stuff for macros, but grep shows it likely isn't used
ACh := DoorReadKey;
end;
procedure SWrite(AText: String);
begin
DoorWrite(AText);
end;
procedure SWriteC(ACh: Char);
begin
DoorWrite(ACh);
end;
procedure SWriteLn(AText: String);
begin
DoorWriteLn(AText);
(*TODOX
Inc(curlinenum);
if (curlinenum = (numlines - 1)) then
begin;
curlinenum := 1;
if moreok then
morecheck;
end;*)
end;
function Time_Left: Integer;
begin
Result := DoorSecondsLeft div 60;
end;
function va(AInt: Integer): String;
begin
Result := IntToStr(AInt);
end;
begin
// TODOX Most of these should be updated in InitDoorDriver
AnsiOn := true;
Default_Fore := 7;
Graphics := 3; // ANSI
Local := false;
LocalCol := true;
MaxTime := 60;
Node_Num := 0;
NoTime := 'Out of time!';
Stacked := '';
StatLine := true;
User_First_Name := 'Usurper';
User_Last_Name := 'Fan';
end.