-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEAPP.PAS
325 lines (268 loc) · 6.7 KB
/
EAPP.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
unit EApp;
interface
uses App, Dialogs, Objects, Views;
const
BackgroundText = 'carlafischer.de '#3' ';
CCarlaBackground = #3;
type
TCarlaDrawBuffer = array[0..254] of Word; {l„nger als TDrawBuffer}
PCarlaDrawBuffer = ^TCarlaDrawBuffer;
{ TAboutBoxTemplate }
TAboutBoxTemplate = object(TDialog)
constructor Init;
end;
{ TClockView }
PClockView = ^TClockView;
TClockView = object(TParamText)
constructor Init(var Bounds: TRect);
procedure Update;
end;
{ TCarlaBackground }
PCarlaBackground = ^TCarlaBackground;
TCarlaBackground = object(TBackground)
Wrap: Boolean; {bricht Text um, sonst abgeschnitten}
constructor Init(var R: TRect; AText: string);
destructor Done; virtual;
procedure Draw; virtual;
procedure FillRect(var R: TRect);
function GetPalette: PPalette; virtual;
procedure SetText(AText: string);
private
Text: PString;
DBS: Word;
DrawBuffer: PCarlaDrawBuffer;
procedure FreeDrawBuffer;
function GetDBLength: Word;
procedure InitDrawBuffer;
procedure WriteText(var X, Y: Integer; EP: TPoint; var Buffer: TCarlaDrawBuffer; Length: Word);
end;
{ TCarlaDesktop }
PCarlaDesktop = ^TCarlaDesktop;
TCarlaDesktop = object(TDesktop)
constructor Init(var R: TRect);
procedure InitBackground; virtual;
end;
{ TExtendedApplication }
TExtendedApplication = object(TApplication)
ClockView: PClockView;
procedure ExecProc(DefaultDir, ProgramFile, Parameters: string);
procedure Idle; virtual;
procedure InitDesktop; virtual;
function PutKeyStroke(C: Char; SC: Byte): Boolean;
{False bei Erfolg, True bei Puffer voll}
procedure PutKeyStrokes(S: string);
procedure Terminate;
end;
implementation
uses Drivers, DOS, Memory;
function Min(a, b: Integer): Integer;
begin
if a <= b then Min := a
else Min := b
end;
{ TAboutBoxTemplate }
constructor TAboutBoxTemplate.Init;
var
R: TRect;
begin
if Desktop <> nil then begin
Desktop^.GetExtent(R);
R.Grow(-10, -4);
end
else R.Assign(5, 2, 75, 23);
inherited Init(R, 'Info');
Options := Options or ofCentered
end;
{ TClockView }
type
PTimeRec = ^TTimeRec;
TTimeRec = packed record
Hour, Minute, Second: Longint;
end;
constructor TClockView.Init(var Bounds: TRect);
begin
inherited Init(Bounds, '%2d:%02d:%02d', 3);
end;
procedure TClockView.Update;
var
Hour, Minute, Second, Sec100: Word;
TimeRec: PTimeRec absolute ParamList;
begin
GetTime(Hour, Minute, Second, Sec100);
if Second <> TimeRec^.Second then begin
TimeRec^.Hour := Hour mod 24;
TimeRec^.Minute := Minute;
TimeRec^.Second := Second;
if State and sfVisible <> 0 then Draw
end
end;
{ TCarlaBackground }
constructor TCarlaBackground.Init(var R: TRect; AText: string);
begin
inherited Init(R, #176);
if AText = '' then Text := NewStr(Pattern)
else Text := NewStr(AText);
FreeDrawBuffer;
end;
destructor TCarlaBackground.Done;
begin
if Text <> nil then begin
DisposeStr(Text);
Text := nil
end;
FreeDrawBuffer;
inherited Done
end;
procedure TCarlaBackground.Draw;
var
R: TRect;
DX, X, Y, DXMax: Integer;
begin
if ScreenMode and smMono = smMono then begin
inherited Draw;
Exit
end;
InitDrawBuffer;
GetExtent(R);
FillRect(R);
end;
procedure TCarlaBackground.FillRect(var R: TRect);
var
X, Y, i: Integer;
begin
X := R.A.X; Y := R.A.Y;
while Y < R.B.Y do
WriteText(X, Y, R.B, DrawBuffer^, GetDBLength);
end;
function TCarlaBackground.GetPalette: PPalette;
const
P: TPalette = CCarlaBackground;
begin
if ScreenMode and smMono = smMono then GetPalette := inherited GetPalette
else GetPalette := @P
end;
procedure TCarlaBackground.FreeDrawBuffer;
begin
if DrawBuffer <> nil then
if DBS > 0 then FreeMem(DrawBuffer, DBS);
DrawBuffer := nil;
DBS := 0
end;
function TCarlaBackground.GetDBLength: Word;
begin
GetDBLength := dbs div 2
end;
procedure TCarlaBackground.InitDrawBuffer;
begin
if DrawBuffer = nil then begin
DBS := Length(Text^) * SizeOf(Word);
GetMem(DrawBuffer, DBS);
MoveStr(DrawBuffer^, Text^, GetColor(1))
end;
end;
procedure TCarlaBackground.SetText(AText: string);
begin
if Text <> nil then DisposeStr(Text);
Text := NewStr(AText);
FreeDrawBuffer
end;
procedure TCarlaBackground.WriteText(var X, Y: Integer; EP: TPoint; var Buffer: TCarlaDrawBuffer; Length: Word);
var
DX, DXAvail, DXWrite: Integer;
DB: PCarlaDrawBuffer;
begin
if (X >= EP.X) or (Y >= EP.Y) then Exit;
DX := Length;
DXAvail := EP.X - X;
DXWrite := Min(DX, DXAvail);
WriteBuf(X, Y, DXWrite, 1, Buffer);
Inc(X, DXWrite);
if X >= EP.X then begin
X := 0; Inc(Y);
if Wrap then
if DXWrite < DX then
if Y < EP.Y then begin
DB := @DrawBuffer^[DXWrite];
WriteText(X, Y, EP, DB^, DX - DXWrite)
end
end
end;
{ TCarlaDesktop }
constructor TCarlaDesktop.Init(var R: TRect);
begin
inherited Init(R);
end;
procedure TCarlaDesktop.InitBackground;
var
R: TRect;
begin
GetExtent(R);
Background := New(PCarlaBackground, Init(R, BackgroundText));
PCarlaBackground(Background)^.Wrap := True
end;
{ TExtendedApplication }
procedure TExtendedApplication.ExecProc(DefaultDir, ProgramFile, Parameters: string);
begin
DoneSysError;
DoneEvents;
DoneVideo;
DoneDosMem;
SwapVectors;
if DefaultDir <> '' then ChDir(DefaultDir);
if ProgramFile = '' then ProgramFile := GetEnv('COMSPEC');
Exec(ProgramFile, Parameters);
SwapVectors;
InitDosMem;
InitVideo;
InitEvents;
InitSysError;
Redraw;
end;
procedure TExtendedApplication.Idle;
begin
inherited Idle;
if ClockView <> nil then ClockView^.Update;
end;
procedure TExtendedApplication.InitDesktop;
var
R: TRect;
begin
GetExtent(R);
R.Grow(0, -1);
Desktop := New(PCarlaDesktop, Init(R));
with Desktop^ do begin
GetExtent(R);
R.A.X := R.B.X - 8;
R.A.Y := R.B.Y - 1;
ClockView := New(PClockView, Init(R));
ClockView^.GrowMode := gfGrowAll;
Insert(ClockView)
end
end;
function TExtendedApplication.PutKeyStroke(C: Char; SC: Byte): Boolean;
assembler;
asm
PUSH CX
MOV AH, $05
MOV CH, &SC
MOV CL, &C
INT $16
POP CX
end;
procedure TExtendedApplication.PutKeyStrokes(S: string);
var
i: Byte;
begin
for i := 1 to Length(S) do
if PutKeyStroke(S[i], 0) then Break
end;
procedure TExtendedApplication.Terminate;
var
E: TEvent;
begin
E.What := evCommand;
E.Command := cmQuit;
E.InfoPtr := @Self;
PutEvent(E)
end;
end.