-
Notifications
You must be signed in to change notification settings - Fork 0
/
Oberon.Mod
414 lines (352 loc) · 12.2 KB
/
Oberon.Mod
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
MODULE Oberon; (*JG 6.9.90 / 23.9.93 / 13.8.94 / NW 14.4.2013 / 22.12.2015*)
IMPORT SYSTEM, Kernel, Files, Modules, Input, Display, Viewers, Fonts, Texts;
CONST (*message ids*)
consume* = 0; track* = 1; defocus* = 0; neutralize* = 1; mark* = 2;
off = 0; idle = 1; active = 2; (*task states*)
BasicCycle = 20;
ESC = 1BX; SETSTAR = 1AX;
TYPE Painter* = PROCEDURE (x, y: INTEGER);
Marker* = RECORD Fade*, Draw*: Painter END;
Cursor* = RECORD
marker*: Marker; on*: BOOLEAN; X*, Y*: INTEGER
END;
InputMsg* = RECORD (Display.FrameMsg)
id*: INTEGER;
keys*: SET;
X*, Y*: INTEGER;
codepoint*: INTEGER;
fnt*: Fonts.Font;
col*, voff*: INTEGER
END;
SelectionMsg* = RECORD (Display.FrameMsg)
time*: LONGINT;
text*: Texts.Text;
beg*, end*: LONGINT
END;
ControlMsg* = RECORD (Display.FrameMsg)
id*, X*, Y*: INTEGER
END;
CopyMsg* = RECORD (Display.FrameMsg)
F*: Display.Frame
END;
Task* = POINTER TO TaskDesc;
Handler* = PROCEDURE;
TaskDesc* = RECORD
state, nextTime, period*: INTEGER;
next: Task;
handle: Handler
END;
VAR User*: ARRAY 8 OF CHAR; Password*: LONGINT;
Arrow*, Star*: Marker;
Mouse, Pointer: Cursor;
FocusViewer*: Viewers.Viewer;
Log*: Texts.Text;
Par*: RECORD
vwr*: Viewers.Viewer;
frame*: Display.Frame;
text*: Texts.Text;
pos*: LONGINT
END;
CurFnt*: Fonts.Font;
CurCol*, CurOff*: INTEGER;
NofTasks*: INTEGER;
CurTask: Task;
DW, DH, CL: INTEGER;
ActCnt: INTEGER; (*action count for GC*)
Mod: Modules.Module;
(*user identification*)
PROCEDURE Code(VAR s: ARRAY OF CHAR): LONGINT;
VAR i: INTEGER; a, b, c: LONGINT;
BEGIN
a := 0; b := 0; i := 0;
WHILE s[i] # 0X DO
c := b; b := a; a := (c MOD 509 + 1) * 127 + ORD(s[i]);
INC(i)
END;
IF b >= 32768 THEN b := b - 65536 END;
RETURN b * 65536 + a
END Code;
PROCEDURE SetUser* (VAR user, password: ARRAY OF CHAR);
BEGIN User := user; Password := Code(password)
END SetUser;
PROCEDURE Clock*(): LONGINT;
BEGIN RETURN Kernel.Clock()
END Clock;
PROCEDURE SetClock* (d: LONGINT);
BEGIN Kernel.SetClock(d)
END SetClock;
PROCEDURE Time*(): LONGINT;
BEGIN RETURN Kernel.Time()
END Time;
(*cursor handling*)
PROCEDURE FlipArrow (X, Y: INTEGER);
BEGIN
IF X < CL THEN
IF X > DW - 15 THEN X := DW - 15 END
ELSE
IF X > CL + DW - 15 THEN X := CL + DW - 15 END
END;
IF Y < 14 THEN Y := 14 ELSIF Y > DH THEN Y := DH END;
Display.CopyPattern(Display.white, Display.arrow, X, Y - 14, Display.invert)
END FlipArrow;
PROCEDURE FlipStar (X, Y: INTEGER);
BEGIN
IF X < CL THEN
IF X < 7 THEN X := 7 ELSIF X > DW - 8 THEN X := DW - 8 END
ELSE
IF X < CL + 7 THEN X := CL + 7 ELSIF X > CL + DW - 8 THEN X := CL + DW - 8 END
END ;
IF Y < 7 THEN Y := 7 ELSIF Y > DH - 8 THEN Y := DH - 8 END;
Display.CopyPattern(Display.white, Display.star, X - 7, Y - 7, Display.invert)
END FlipStar;
PROCEDURE OpenCursor(VAR c: Cursor);
BEGIN c.on := FALSE; c.X := 0; c.Y := 0
END OpenCursor;
PROCEDURE FadeCursor(VAR c: Cursor);
BEGIN IF c.on THEN c.marker.Fade(c.X, c.Y); c.on := FALSE END
END FadeCursor;
PROCEDURE DrawCursor(VAR c: Cursor; m: Marker; x, y: INTEGER);
BEGIN
IF c.on & ((x # c.X) OR (y # c.Y) OR (m.Draw # c.marker.Draw)) THEN
c.marker.Fade(c.X, c.Y); c.on := FALSE
END;
IF ~c.on THEN
m.Draw(x, y); c.marker := m; c.X := x; c.Y := y; c.on := TRUE
END
END DrawCursor;
PROCEDURE DrawMouse*(m: Marker; x, y: INTEGER);
BEGIN DrawCursor(Mouse, m, x, y)
END DrawMouse;
PROCEDURE DrawMouseArrow*(x, y: INTEGER);
BEGIN DrawCursor(Mouse, Arrow, x, y)
END DrawMouseArrow;
PROCEDURE FadeMouse*;
BEGIN FadeCursor(Mouse)
END FadeMouse;
PROCEDURE DrawPointer*(x, y: INTEGER);
BEGIN DrawCursor(Pointer, Star, x, y)
END DrawPointer;
(*display management*)
PROCEDURE RemoveMarks* (X, Y, W, H: INTEGER);
BEGIN
IF (Mouse.X > X - 16) & (Mouse.X < X + W + 16) & (Mouse.Y > Y - 16) & (Mouse.Y < Y + H + 16) THEN
FadeCursor(Mouse)
END;
IF (Pointer.X > X - 8) & (Pointer.X < X + W + 8) & (Pointer.Y > Y - 8) & (Pointer.Y < Y + H + 8) THEN
FadeCursor(Pointer)
END
END RemoveMarks;
PROCEDURE HandleFiller (V: Display.Frame; VAR M: Display.FrameMsg);
BEGIN
CASE M OF
InputMsg: IF M.id = track THEN DrawCursor(Mouse, Arrow, M.X, M.Y) END |
ControlMsg: IF M.id = mark THEN DrawCursor(Pointer, Star, M.X, M.Y) END |
Viewers.ViewerMsg:
IF (M.id = Viewers.restore) & (V.W > 0) & (V.H > 0) THEN
RemoveMarks(V.X, V.Y, V.W, V.H);
Display.ReplConst(Display.black, V.X, V.Y, V.W, V.H, Display.replace)
ELSIF (M.id = Viewers.modify) & (M.Y < V.Y) THEN
RemoveMarks(V.X, M.Y, V.W, V.Y - M.Y);
Display.ReplConst(Display.black, V.X, M.Y, V.W, V.Y - M.Y, Display.replace)
END
END
END HandleFiller;
PROCEDURE OpenDisplay* (UW, SW, H: INTEGER);
VAR Filler: Viewers.Viewer;
BEGIN
Input.SetMouseLimits(Viewers.curW + UW + SW, H);
Display.ReplConst(Display.black, Viewers.curW, 0, UW + SW, H, Display.replace);
NEW(Filler); Filler.handle := HandleFiller;
Viewers.InitTrack(UW, H, Filler); (*init user track*)
NEW(Filler); Filler.handle := HandleFiller;
Viewers.InitTrack(SW, H, Filler) (*init system track*)
END OpenDisplay;
PROCEDURE DisplayWidth* (X: INTEGER): INTEGER;
BEGIN RETURN DW
END DisplayWidth;
PROCEDURE DisplayHeight* (X: INTEGER): INTEGER;
BEGIN RETURN DH
END DisplayHeight;
PROCEDURE OpenTrack* (X, W: INTEGER);
VAR Filler: Viewers.Viewer;
BEGIN
NEW(Filler); Filler.handle := HandleFiller;
Viewers.OpenTrack(X, W, Filler)
END OpenTrack;
PROCEDURE UserTrack* (X: INTEGER): INTEGER;
BEGIN RETURN X DIV DW * DW
END UserTrack;
PROCEDURE SystemTrack* (X: INTEGER): INTEGER;
BEGIN RETURN X DIV DW * DW + DW DIV 8 * 5
END SystemTrack;
PROCEDURE UY (X: INTEGER): INTEGER;
VAR h: INTEGER;
fil, bot, alt, max: Display.Frame;
BEGIN
Viewers.Locate(X, 0, fil, bot, alt, max);
IF fil.H >= DH DIV 8 THEN h := DH ELSE h := max.Y + max.H DIV 2 END ;
RETURN h
END UY;
PROCEDURE AllocateUserViewer* (DX: INTEGER; VAR X, Y: INTEGER);
BEGIN
IF Pointer.on THEN X := Pointer.X; Y := Pointer.Y
ELSE X := DX DIV DW * DW; Y := UY(X)
END
END AllocateUserViewer;
PROCEDURE SY (X: INTEGER): INTEGER;
VAR H0, H1, H2, H3, y: INTEGER;
fil, bot, alt, max: Display.Frame;
BEGIN H3 := DH - DH DIV 3;
H2 := H3 - H3 DIV 2; H1 := DH DIV 5; H0 := DH DIV 10;
Viewers.Locate(X, DH, fil, bot, alt, max);
IF fil.H >= DH DIV 8 THEN y := DH
ELSIF max.H >= DH - H0 THEN y := max.Y + H3
ELSIF max.H >= H3 - H0 THEN y := max.Y + H2
ELSIF max.H >= H2 - H0 THEN y := max.Y + H1
ELSIF max # bot THEN y := max.Y + max.H DIV 2
ELSIF bot.H >= H1 THEN y := bot.H DIV 2
ELSE y := alt.Y + alt.H DIV 2
END ;
RETURN y
END SY;
PROCEDURE AllocateSystemViewer* (DX: INTEGER; VAR X, Y: INTEGER);
BEGIN
IF Pointer.on THEN X := Pointer.X; Y := Pointer.Y
ELSE X := DX DIV DW * DW + DW DIV 8 * 5; Y := SY(X)
END
END AllocateSystemViewer;
PROCEDURE MarkedViewer* (): Viewers.Viewer;
BEGIN RETURN Viewers.This(Pointer.X, Pointer.Y)
END MarkedViewer;
PROCEDURE PassFocus* (V: Viewers.Viewer);
VAR M: ControlMsg;
BEGIN M.id := defocus; FocusViewer.handle(FocusViewer, M); FocusViewer := V
END PassFocus;
PROCEDURE OpenLog*(T: Texts.Text);
BEGIN Log := T
END OpenLog;
(*command interpretation*)
PROCEDURE SetPar*(F: Display.Frame; T: Texts.Text; pos: LONGINT);
BEGIN Par.vwr := Viewers.This(F.X, F.Y); Par.frame := F; Par.text := T; Par.pos := pos
END SetPar;
PROCEDURE Call* (name: ARRAY OF CHAR; VAR res: INTEGER);
VAR mod: Modules.Module; P: Modules.Command;
i, j: INTEGER; ch: CHAR;
Mname, Cname: ARRAY 32 OF CHAR;
BEGIN i := 0; ch := name[0];
WHILE (ch # ".") & (ch # 0X) DO Mname[i] := ch; INC(i); ch := name[i] END ;
IF ch = "." THEN
Mname[i] := 0X; INC(i);
Modules.Load(Mname, mod); res := Modules.res;
IF Modules.res = 0 THEN
j := 0; ch := name[i]; INC(i);
WHILE ch # 0X DO Cname[j] := ch; INC(j); ch := name[i]; INC(i) END ;
Cname[j] := 0X;
P := Modules.ThisCommand(mod, Cname); res := Modules.res;
IF Modules.res = 0 THEN P END
END
ELSE res := 5
END
END Call;
PROCEDURE GetSelection* (VAR text: Texts.Text; VAR beg, end, time: LONGINT);
VAR M: SelectionMsg;
BEGIN
M.time := -1; Viewers.Broadcast(M); time := M.time;
IF time >= 0 THEN text := M.text; beg := M.beg; end := M.end END
END GetSelection;
PROCEDURE GC;
VAR mod: Modules.Module;
BEGIN
IF (ActCnt <= 0) OR (Kernel.allocated >= Kernel.heapLim - Kernel.heapOrg - 10000H) THEN
mod := Modules.root; LED(21H);
WHILE mod # NIL DO
IF mod.name[0] # 0X THEN Kernel.Mark(mod.ptr) END ;
mod := mod.next
END ;
LED(23H);
Files.RestoreList; LED(27H);
Kernel.Scan; LED(20H);
ActCnt := BasicCycle
END
END GC;
PROCEDURE NewTask*(h: Handler; period: INTEGER): Task;
VAR t: Task;
BEGIN NEW(t); t.state := off; t.next := t; t.handle := h; t.period := period; RETURN t
END NewTask;
PROCEDURE Install* (T: Task);
BEGIN
IF T.state = off THEN
T.next := CurTask.next; CurTask.next := T; T.state := idle; T.nextTime := 0; INC(NofTasks)
END
END Install;
PROCEDURE Remove* (T: Task);
VAR t: Task;
BEGIN
IF T.state # off THEN t := T;
WHILE t.next # T DO t := t.next END ;
t.next := T.next; T.state := off; T.next := NIL; CurTask := t; DEC(NofTasks)
END
END Remove;
PROCEDURE Collect* (count: INTEGER);
BEGIN ActCnt := count
END Collect;
PROCEDURE SetFont* (fnt: Fonts.Font);
BEGIN CurFnt := fnt
END SetFont;
PROCEDURE SetColor* (col: INTEGER);
BEGIN CurCol := col
END SetColor;
PROCEDURE SetOffset* (voff: INTEGER);
BEGIN CurOff := voff
END SetOffset;
PROCEDURE Loop*;
VAR V: Viewers.Viewer; M: InputMsg; N: ControlMsg;
prevX, prevY, X, Y, t: INTEGER; keys: SET; codepoint: INTEGER;
BEGIN
REPEAT
Input.Mouse(keys, X, Y);
IF Input.Available() > 0 THEN Input.ReadUnicode(codepoint);
IF codepoint = ORD(ESC) THEN
N.id := neutralize; Viewers.Broadcast(N); FadeCursor(Pointer); LED(0)
ELSIF codepoint = ORD(SETSTAR) THEN
N.id := mark; N.X := X; N.Y := Y; V := Viewers.This(X, Y); V.handle(V, N)
ELSE M.id := consume; M.codepoint := codepoint; M.fnt := CurFnt; M.col := CurCol; M.voff := CurOff;
FocusViewer.handle(FocusViewer, M); DEC(ActCnt)
END
ELSIF keys # {} THEN
M.id := track; M.X := X; M.Y := Y; M.keys := keys;
REPEAT V := Viewers.This(M.X, M.Y); V.handle(V, M); Input.Mouse(M.keys, M.X, M.Y)
UNTIL M.keys = {};
DEC(ActCnt)
ELSE
IF (X # prevX) OR (Y # prevY) OR ~Mouse.on THEN
M.id := track; M.X := X;
IF Y >= Display.Height THEN Y := Display.Height END ;
M.Y := Y; M.keys := keys; V := Viewers.This(X, Y); V.handle(V, M); prevX := X; prevY := Y
END;
CurTask := CurTask.next; t := Kernel.Time();
IF t >= CurTask.nextTime THEN
CurTask.nextTime := t + CurTask.period; CurTask.state := active; CurTask.handle; CurTask.state := idle
END
END
UNTIL FALSE
END Loop;
PROCEDURE Reset*;
BEGIN
IF CurTask.state = active THEN Remove(CurTask) END ;
SYSTEM.LDREG(14, Kernel.stackOrg); (*reset stack pointer*) Loop
END Reset;
BEGIN OUCH(79); OUCH(66); OUCH(69); OUCH(82); OUCH(79); OUCH(78); OUCH(10);
LED(128);
User[0] := 0X;
Arrow.Fade := FlipArrow; Arrow.Draw := FlipArrow;
Star.Fade := FlipStar; Star.Draw := FlipStar;
OpenCursor(Mouse); OpenCursor(Pointer);
DW := Display.Width; DH := Display.Height; CL := DW;
OpenDisplay(DW DIV 8 * 5, DW DIV 8 * 3, DH);
FocusViewer := Viewers.This(0, 0);
CurFnt := Fonts.Default; CurCol := Display.white; CurOff := 0;
ActCnt := 0; CurTask := NewTask(GC, 1000); Install(CurTask);
LED(0);
Modules.Load("System", Mod); Mod := NIL; Loop
END Oberon.