forked from rochus-keller/OberonSystem3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDisplays.Display.Mod
678 lines (616 loc) · 22 KB
/
Displays.Display.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
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
(* ETH Oberon, Copyright 1990-2003 Computer Systems Institute, ETH Zurich, CH-8092 Zurich.
Refer to the license.txt file provided with this distribution. *)
MODULE Display; (* pjm *)
(* Native Oberon display module based on Displays. *)
(**
Module Display provides the display drawing primitives and the base type of the visual objects, called Frames.
*)
IMPORT Displays, Kernel, Modules, Objects, DisplayLinear, P := ObxPal;
CONST
BG* = 0; FG* = 15; (** Background, foreground colors. *)
w_h_bitofs = 16; // width of the w and h fields of a pattern in bits
(** Drawing operation modes. *)
replace* = 0; (** replace destination. *)
paint* = 1; (** paint over destination. *)
invert* = 2; (** invert destination. *)
(** Message ids. *)
remove* = 0; suspend* = 1; restore* = 2; newprinter* = 3; (** ControlMsg id. *)
reduce* = 0; extend* = 1; move* = 2; (** ModifyMsg id. *)
display* = 0; state* = 1; (** ModifyMsg mode. *)
screen* = 0; printer* = 1; (** DisplayMsg device *)
full* = 0; area* = 1; contents* = 2; (** DisplayMsg id. *)
get* = 0; set* = 1; reset* = 2; (** SelectMsg id. *)
drop* = 0; integrate* = 1; (** ConsumeMsg id. *)
(** TransferFormat types. *)
unknown* = 0; index8* = 8; color555* = 16; color565* = 17; color664* = 18; color888* = 24; color8888* = 32;
TYPE
Color* = LONGINT;
Pattern* = Displays.Pattern; // was originally LONGINT;
List = POINTER TO ListDesc;
ListDesc = RECORD
next: List;
pat: Pattern
END;
Frame* = POINTER TO FrameDesc; (** Base type of all displayable objects. *)
FrameDesc* = RECORD (Objects.ObjDesc)
next*, dsc*: Frame; (** Sibling, child pointers. *)
X*, Y*, W*, H*: INTEGER (** Coordinates. *)
END;
FrameMsg* = RECORD (Objects.ObjMsg) (** Base type of messages sent to frames. *)
F*: Frame; (*target*) (** Message target, NIL for broadcast. *)
x*, y*: INTEGER; (** Message origin. *)
res*: INTEGER (** Result code: <0 = error or no response, >=0 response. *)
END;
ControlMsg* = RECORD (FrameMsg)
id*: INTEGER (** remove, suspend, restore. *)
END;
ModifyMsg* = RECORD (FrameMsg) (** Change coordinates in container frame. *)
id*: INTEGER; (** reduce, extend, move. *)
mode*: INTEGER; (** Modes display, state. *)
dX*, dY*, dW*, dH*: INTEGER; (** Change from old coordinates (delta). *)
X*, Y*, W*, H*: INTEGER (** New coordinates. *)
END;
DisplayMsg* = RECORD (FrameMsg) (** Display a frame, a part of it or its contents. *)
device*: INTEGER; (** screen, printer *)
id*: INTEGER; (** full, area, contents. *)
u*, v*, w*, h*: INTEGER (** Area to be restored. *)
END;
LocateMsg* = RECORD (FrameMsg) (** Locate frame in display space. *)
loc*: Frame; (** Result. *)
X*, Y*: INTEGER; (** Absolute location. *)
u*, v*: INTEGER (** Relative coordinates in loc. *)
END;
SelectMsg* = RECORD (FrameMsg) (** Selection control. *)
id*: INTEGER; (** get, set, reset. *)
time*: LONGINT; (** Time of selection. *)
sel*: Frame; (** Parent of selection. *)
obj*: Objects.Object (** List of objects involved, linked with slink. *)
END;
ConsumeMsg* = RECORD (FrameMsg) (** Drop, integrate frames. *)
id*: INTEGER; (** drop, integrate. *)
u*, v*: INTEGER; (** Relative coordinates in destination when drop. *)
obj*: Objects.Object (** List of objects to be consumed, linked with slink. *)
END;
MsgProc* = PROCEDURE (VAR M: FrameMsg);
VAR
Unit*: LONGINT; (** RasterUnit = Unit/36000 mm *)
Left*, (** Left margin of black-and-white screen. *)
ColLeft*, (** Left margin of secondary display, often same as Left. *)
Bottom*, (** Bottom of primary map. *)
UBottom*, (** Bottom of offscreen area (negative), 0 if not supported. *)
Width*, (** Display width. *)
Height*: INTEGER; (** Display height. *)
arrow*, (** Oberon cursor. *)
star*, (** Star marker to mark documents and viewers. *)
cross*, (** Insertion marker. *)
downArrow*, (** Marker to indicate disk operation. *)
hook*, (** Text caret pattern. *)
grey0*, grey1*, grey2*, ticks*, solid*: Pattern; (** Simulated grey levels. *)
Broadcast*: MsgProc; (** Message broadcast to all frames in the display space. *)
palette: ARRAY 256 OF LONGINT;
clipX1, clipY1, clipX2, clipY2: LONGINT; (* bottom left corner & top right corner, in Oberon coordinates *)
pattern: List;
buf: POINTER TO ARRAY OF CHAR; (* for DisplayBlock *)
disp: Displays.Display;
height: LONGINT;
PROCEDURE ProcessEvents*():BOOLEAN;
BEGIN
RETURN P.process_events(0) # 0 // already suspends and waits for events, sleep not necessary
END ProcessEvents;
(** Change color palette entry. 0 <= col, red, green, blue < 256. *)
PROCEDURE SetColor*(col: Color; red, green, blue: LONGINT);
BEGIN
palette[col MOD 256] := ASH(ASH(red, 8) + green, 8) + blue
END SetColor;
(** Retrieve color palette entry or color components. 0 <= red, green, blue < 256. *)
PROCEDURE GetColor*(col: Color; VAR red, green, blue: INTEGER);
BEGIN
IF col >= 0 THEN col := palette[col MOD 256] END;
red := SHORT(ASH(col, -16) MOD 256);
green := SHORT(ASH(col, -8) MOD 256);
blue := SHORT(col MOD 256)
END GetColor;
(** Return color with specified components. 0 <= red, green, blue < 256. *)
PROCEDURE RGB*(red, green, blue: LONGINT): Color;
BEGIN
RETURN MIN(LONGINT) + ASH(red, 16) + ASH(green, 8) + blue
END RGB;
(** Returns the number of bits per pixel for the given x coordinate. Typical values are 1, 4, 8 (maximum 8). *)
PROCEDURE Depth*(x: LONGINT): INTEGER;
BEGIN
RETURN 8
END Depth;
(** Returns if truecolor values are supported in the interface. *)
PROCEDURE TrueColor*(x: LONGINT): BOOLEAN;
BEGIN
RETURN TRUE
END TrueColor;
(** Get the current clip rectangle. *)
PROCEDURE GetClip*(VAR x, y, w, h: INTEGER);
BEGIN
x := SHORT(clipX1); y := SHORT(clipY1);
w := SHORT(clipX2-clipX1+1); h := SHORT(clipY2-clipY1+1)
END GetClip;
(** Set the new clipping rectangle. *)
PROCEDURE SetClip*(x, y, w, h: LONGINT);
BEGIN
clipX1 := x; clipY1 := y; clipX2 := clipX1+w-1; clipY2 := clipY1+h-1
END SetClip;
(** Intersect with current clip rectangle resulting in a new clip rectangle. *)
PROCEDURE AdjustClip*(x, y, w, h: LONGINT);
VAR x2, y2: LONGINT;
BEGIN
x2 := x + w - 1; y2 := y + h - 1;
IF x > clipX1 THEN clipX1 := x END;
IF y > clipY1 THEN clipY1 := y END;
IF x2 < clipX2 THEN clipX2 := x2 END;
IF y2 < clipY2 THEN clipY2 := y2 END
END AdjustClip;
(** Reset the current clipping rectangle to the whole display, including offscreen area. *)
PROCEDURE ResetClip*;
BEGIN
clipX1 := 0; clipY1 := UBottom; clipX2 := disp.width-1; clipY2 := height-1
END ResetClip;
(** Copy source block SX, SY, W, H to destination DX, DY using operation mode. A block is given by its
lower left corner X, Y and its dimension W, H. *)
PROCEDURE CopyBlock*(sx, sy, w, h, dx, dy, mode: LONGINT);
BEGIN
disp.Copy(sx, height-sy-h, w, h, dx, height-dy-h)
END CopyBlock;
(* Place a dot of color col in operation mode at x, y. Effect equivalent to ReplConst with a block of
size 1, 1. *)
PROCEDURE CopyPattern*(col: Color; pat: Pattern; x, y, mode: LONGINT);
VAR pw, ph, stride: LONGINT;
BEGIN
pw := ORD(pat[0]); ph := ORD(pat[1]);
IF (x >= clipX1) & (y >= clipY1) & (x+pw-1 <= clipX2) & (y+ph-1 <= clipY2) THEN (* completely visible *)
IF col >= 0 THEN col := palette[col MOD 256] END;
stride := (pw+7) DIV 8;
CASE mode OF
replace:
disp.Mask(pat, w_h_bitofs + (ph-1)*stride*8, -stride, col MOD 1000000H,
palette[BG], x, height-y-ph, pw, ph)
|invert:
disp.Mask(pat, w_h_bitofs + (ph-1)*stride*8, -stride, col MOD 1000000H + Displays.invert,
Displays.trans, x, height-y-ph, pw, ph)
ELSE (* paint *)
disp.Mask(pat, w_h_bitofs + (ph-1)*stride*8, -stride, col MOD 1000000H,
Displays.trans, x, height-y-ph, pw, ph)
END
ELSIF (x+pw-1 >= clipX1) & (y+ph-1 >= clipY1) & (x <= clipX2) & (y <= clipY2) THEN (* partially visible *)
FillPattern(col, pat, x, y, x, y, pw, ph, mode)
ELSE (* not visible *)
(* skip *)
END
END CopyPattern;
(** Replicate pattern pat in color col into block x, y, w, h using operation mode, proceeding from
left to right and from bottom to top, starting at lower left corner. The pattern origin is placed
at px, py. *)
PROCEDURE FillPattern*(col: Color; pat: Pattern; px, py, x, y, w, h, mode: LONGINT);
VAR pw, ph, rdx, lpx, ldw, lsx, rdw, tdy, bpy, cdy, csy, cdh, cdx, csx, stride, fg, bg: LONGINT;
p: Pattern;
(* See Displays.Display.Text for documentation *)
BEGIN
rdx := x+w-1; tdy := y+h-1; (* (x,y) bottom left & (rdx,tdy) top right *)
IF (x <= clipX2) & (y <= clipY2) & (rdx >= clipX1) & (tdy >= clipY1) THEN
IF x < clipX1 THEN DEC(w, clipX1-x); x := clipX1 END;
IF y < clipY1 THEN DEC(h, clipY1-y); y := clipY1 END;
IF rdx > clipX2 THEN DEC(w, rdx-clipX2) END;
IF tdy > clipY2 THEN DEC(h, tdy-clipY2) END;
IF (w > 0) & (h > 0) THEN
IF col >= 0 THEN col := palette[col MOD 256] END;
CASE mode OF
|replace: fg := col MOD 1000000H;
bg := palette[BG]
|invert: fg := col MOD 1000000H + Displays.invert;
bg := Displays.trans;
ELSE fg := col MOD 1000000H; bg := Displays.trans
END;
p := pat; pw := ORD(p[0]); ph := ORD(p[1]);
IF (pw > 0) & (ph > 0) THEN (* rest of code copied from eos' TileBuffer *)
stride := (pw+7) DIV 8;
INC(px, (x - px) DIV pw * pw); INC(py, (y - py) DIV ph * ph);
rdx := x + w; lpx := px + pw;
ldw := lpx - x; lsx := pw - ldw;
IF ldw > w THEN ldw := w END;
rdw := (rdx - px) MOD pw;
tdy := y + h; bpy := py + ph;
cdy := y; csy := y - py;
IF (py < y) & (bpy < tdy) THEN
cdh := bpy - cdy;
cdx := x; csx := lsx;
IF px < x THEN
disp.Mask(p, w_h_bitofs + (csy+cdh-1)*stride*8+lsx, -stride, fg, bg, cdx, height-cdh-cdy, ldw, cdh);
csx := 0; cdx := lpx
END;
WHILE cdx + pw <= rdx DO
disp.Mask(p, w_h_bitofs + (csy+cdh-1)*stride*8, -stride, fg, bg, cdx, height-cdh-cdy, pw, cdh);
INC(cdx, pw)
END;
IF cdx < rdx THEN
disp.Mask(p, w_h_bitofs + (csy+cdh-1)*stride*8+csx, -stride, fg, bg, cdx, height-cdh-cdy, rdw, cdh);
END;
csy := 0; cdy := bpy
END;
WHILE cdy + ph <= tdy DO
cdx := x; csx := lsx;
IF px < x THEN (* draw left border *)
disp.Mask(p, w_h_bitofs + (ph-1)*stride*8+lsx, -stride, fg, bg, cdx, height-ph-cdy, ldw, ph);
csx := 0; cdx := lpx
END;
WHILE cdx + pw <= rdx DO
disp.Mask(p, w_h_bitofs + (ph-1)*stride*8, -stride, fg, bg, cdx, height-ph-cdy, pw, ph);
INC(cdx, pw)
END;
IF cdx < rdx THEN (* draw right border *)
disp.Mask(p, w_h_bitofs + (ph-1)*stride*8+csx, -stride, fg, bg, cdx, height-ph-cdy, rdw, ph);
END;
INC(cdy, ph)
END;
IF cdy < tdy THEN (* draw top border *)
cdh := tdy - cdy;
cdx := x; csx := lsx;
IF px < x THEN (* draw top left corner *)
disp.Mask(p, w_h_bitofs + (csy+cdh-1)*stride*8+lsx, -stride, fg, bg, cdx, height-cdh-cdy, ldw, cdh);
csx := 0; cdx := lpx
END;
WHILE cdx + pw <= rdx DO
disp.Mask(p, w_h_bitofs + (csy+cdh-1)*stride*8, -stride, fg, bg, cdx, height-cdh-cdy, pw, cdh);
INC(cdx, pw)
END;
IF cdx < rdx THEN (* draw top right corner *)
disp.Mask(p, w_h_bitofs + (csy+cdh-1)*stride*8+csx, -stride, fg, bg, cdx, height-cdh-cdy, rdw, cdh);
END
END
END
END
END
END FillPattern;
(** Like FillPattern, but the pattern origin is placed at 0, 0. *)
PROCEDURE ReplPattern*(col: Color; pat: Pattern; x, y, w, h, mode: LONGINT);
BEGIN
FillPattern(col, pat, 0, 0, x, y, w, h, mode)
END ReplPattern;
(** Block fill in color col and operation mode. **)
PROCEDURE ReplConst*(col: Color; x, y, w, h, mode: LONGINT);
VAR rx, ty: LONGINT;
BEGIN
rx := x+w-1; ty := y+h-1; (* (x,y) bottom left & (rx,ty) top right *)
IF (x <= clipX2) & (y <= clipY2) & (rx >= clipX1) & (ty >= clipY1) THEN
IF x < clipX1 THEN DEC(w, clipX1-x); x := clipX1 END;
IF y < clipY1 THEN DEC(h, clipY1-y); y := clipY1 END;
IF rx > clipX2 THEN DEC(w, rx-clipX2) END;
IF ty > clipY2 THEN DEC(h, ty-clipY2) END;
IF (w > 0) & (h > 0) THEN
IF col >= 0 THEN col := palette[col MOD 256] END;
IF mode = invert THEN
disp.Fill(col MOD 1000000H + Displays.invert, x, height-y-h, w, h)
ELSE
disp.Fill(col MOD 1000000H, x, height-y-h, w, h)
END
END
END
END ReplConst;
(** Place a dot of color col in operation mode at x, y. Effect equivalent to ReplConst with a block of
size 1, 1. *)
PROCEDURE Dot*(col: Color; x, y, mode: LONGINT);
BEGIN
IF (x <= clipX2) & (y <= clipY2) & (x >= clipX1) & (y >= clipY1) THEN
IF col >= 0 THEN col := palette[col MOD 256] END;
IF mode = invert THEN
disp.Dot(col MOD 1000000H + Displays.invert, x, height-y-1)
ELSE
disp.Dot(col MOD 1000000H, x, height-y-1)
END
END
END Dot;
(** Returns the dimensions of a pattern. *)
PROCEDURE GetDim*(pat: Pattern; VAR w, h: INTEGER);
VAR ch: CHAR;
BEGIN
w := ORD(pat[0]);
h := ORD(pat[1])
END GetDim;
(** Define a new pattern. *)
PROCEDURE NewPattern*(w, h: LONGINT; VAR image: ARRAY OF SET): Pattern;
VAR len, src, dest, i: LONGINT; p: Pattern; pl: List; tmp: ARRAY 4 OF CHAR;
BEGIN
len := (w+7) DIV 8;
NEW(p, 2+len*h); p[0] := CHR(w); p[1] := CHR(h);
src := 0; // index to image
dest := 2; // index to p
i := 0;
WHILE i < h DO
BYTES(tmp,image[src]); Displays.Move(tmp,0,p,dest,len);
INC(src); INC(dest, len); INC(i)
END;
NEW(pl); pl.pat := p; pl.next := pattern; pattern := pl; (* put in list to avoid GC *)
RETURN p
END NewPattern;
(* Define standard patterns. *)
PROCEDURE CreatePatterns;
VAR image: ARRAY 16 OF SET;
BEGIN
image[0] := {13};
image[1] := {12..14};
image[2] := {11..13};
image[3] := {10..12};
image[4] := {9..11};
image[5] := {8..10};
image[6] := {7..9};
image[7] := {0, 6..8};
image[8] := {0, 1, 5..7};
image[9] := {0..2, 4..6};
image[10] := {0..5};
image[11] := {0..4};
image[12] := {0..5};
image[13] := {0..6};
image[14] := {0..7};
arrow := NewPattern(15, 15, image);
image[0] := {0, 10};
image[1] := {1, 9};
image[2] := {2, 8};
image[3] := {3, 7};
image[4] := {4, 6};
image[5] := {};
image[6] := {4, 6};
image[7] := {3, 7};
image[8] := {2, 8};
image[9] := {1, 9};
image[10] := {0, 10};
cross := NewPattern(11, 11, image);
image[0] := {6};
image[1] := {5..7};
image[2] := {4..8};
image[3] := {3..9};
image[4] := {2..10};
image[5] := {5..7};
image[6] := {5..7};
image[7] := {5..7};
image[8] := {5..7};
image[9] := {5..7};
image[10] := {5..7};
image[11] := {5..7};
image[12] := {5..7};
image[13] := {5..7};
image[14] := {};
downArrow := NewPattern(11, 15, image);
image[0] := {0, 4, 8, 12};
image[1] := {};
image[2] := {2, 6, 10, 14};
image[3] := {};
image[4] := {0, 4, 8, 12};
image[5] := {};
image[6] := {2, 6, 10, 14};
image[7] := {};
image[8] := {0, 4, 8, 12};
image[9] := {};
image[10] := {2, 6, 10, 14};
image[11] := {};
image[12] := {0, 4, 8, 12};
image[13] := {};
image[14] := {2, 6, 10, 14};
image[15] := {};
grey0 := NewPattern(16, 16, image);
image[0] := {0, 2, 4, 6, 8, 10, 12, 14};
image[1] := {1, 3, 5, 7, 9, 11, 13, 15};
image[2] := {0, 2, 4, 6, 8, 10, 12, 14};
image[3] := {1, 3, 5, 7, 9, 11, 13, 15};
image[4] := {0, 2, 4, 6, 8, 10, 12, 14};
image[5] := {1, 3, 5, 7, 9, 11, 13, 15};
image[6] := {0, 2, 4, 6, 8, 10, 12, 14};
image[7] := {1, 3, 5, 7, 9, 11, 13, 15};
image[8] := {0, 2, 4, 6, 8, 10, 12, 14};
image[9] := {1, 3, 5, 7, 9, 11, 13, 15};
image[10] := {0, 2, 4, 6, 8, 10, 12, 14};
image[11] := {1, 3, 5, 7, 9, 11, 13, 15};
image[12] := {0, 2, 4, 6, 8, 10, 12, 14};
image[13] := {1, 3, 5, 7, 9, 11, 13, 15};
image[14] := {0, 2, 4, 6, 8, 10, 12, 14};
image[15] := {1, 3, 5, 7, 9, 11, 13, 15};
grey1 := NewPattern(16, 16, image);
image[0] := {0, 1, 4, 5, 8, 9, 12, 13};
image[1] := {0, 1, 4, 5, 8, 9, 12, 13};
image[2] := {2, 3, 6, 7, 10, 11, 14, 15};
image[3] := {2, 3, 6, 7, 10, 11, 14, 15};
image[4] := {0, 1, 4, 5, 8, 9, 12, 13};
image[5] := {0, 1, 4, 5, 8, 9, 12, 13};
image[6] := {2, 3, 6, 7, 10, 11, 14, 15};
image[7] := {2, 3, 6, 7, 10, 11, 14, 15};
image[8] := {0, 1, 4, 5, 8, 9, 12, 13};
image[9] := {0, 1, 4, 5, 8, 9, 12, 13};
image[10] := {2, 3, 6, 7, 10, 11, 14, 15};
image[11] := {2, 3, 6, 7, 10, 11, 14, 15};
image[12] := {0, 1, 4, 5, 8, 9, 12, 13};
image[13] := {0, 1, 4, 5, 8, 9, 12, 13};
image[14] := {2, 3, 6, 7, 10, 11, 14, 15};
image[15] := {2, 3, 6, 7, 10, 11, 14, 15};
grey2 := NewPattern(16, 16, image);
image[0] := {0..2, 8..11};
image[1] := {0..2, 7..10};
image[2] := {0..2, 6..9};
image[3] := {0..2, 5..8};
image[4] := {0..2, 4..7};
image[5] := {0..6};
image[6] := {0..5};
image[7] := {0..4};
image[8] := {0..3};
image[9] := {0..2};
image[10] := {0, 1};
image[11] := {0};
hook := NewPattern(12, 12, image);
image[0] := {7};
image[1] := {7};
image[2] := {2, 7, 12};
image[3] := {3, 7, 11};
image[4] := {4, 7, 10};
image[5] := {5, 7, 9};
image[6] := {6..8};
image[7] := {0..6, 8..14};
image[8] := {6..8};
image[9] := {5, 7, 9};
image[10] := {4, 7, 10};
image[11] := {3, 7, 11};
image[12] := {2, 7, 12};
image[13] := {7};
image[14] := {7};
star := NewPattern(15, 15, image);
image[0] := {};
image[1] := {};
image[2] := {0};
image[3] := {};
image[4] := {};
image[5] := {};
image[6] := {};
image[7] := {};
image[8] := {};
image[9] := {};
image[10] := {};
image[11] := {};
image[12] := {};
image[13] := {};
image[14] := {};
image[15] := {};
ticks := NewPattern(16, 16, image);
image[0] := -{};
image[1] := -{};
image[2] := -{};
image[3] := -{};
image[4] := -{};
image[5] := -{};
image[6] := -{};
image[7] := -{};
solid := NewPattern(16, 8, image)
END CreatePatterns;
(** Return the format of a display region, for TransferBlock. *)
PROCEDURE TransferFormat*(x: LONGINT): LONGINT;
BEGIN
CASE disp.format OF
Displays.index8: RETURN index8
|Displays.color565: RETURN color565
|Displays.color888: RETURN color888
|Displays.color8888: RETURN color8888
ELSE RETURN unknown
END
END TransferFormat;
(** Transfer a block of pixels in display format to (mode = set) or from (mode = get) the display. Pixels in the rectangular area are transferred from bottom to top and left to right. The pixels are transferred to or from buf, starting at ofs, and with line increment stride, which may be < 0. *)
PROCEDURE TransferBlock*(VAR buf: ARRAY OF CHAR; ofs, stride, x, y, w, h, mode: LONGINT);
VAR rdx, tdy: LONGINT;
BEGIN
rdx := x+w-1; tdy := y+h-1; (* (x,y) bottom left & (rdx,tdy) top right *)
IF (x <= clipX2) & (y <= clipY2) & (rdx >= clipX1) & (tdy >= clipY1) THEN
IF x < clipX1 THEN DEC(w, clipX1-x); INC(ofs, (clipX1-x)*disp.format); x := clipX1 END;
IF y < clipY1 THEN DEC(h, clipY1-y); INC(ofs, (clipY1-y)*stride); y := clipY1 END;
IF rdx > clipX2 THEN DEC(w, rdx-clipX2) END;
IF tdy > clipY2 THEN DEC(h, tdy-clipY2) END;
IF (w > 0) & (h > 0) THEN
disp.Transfer(buf, ofs + (h-1)*stride, -stride, x, height-h-y, w, h, mode)
END
END
END TransferBlock;
(** Change screen mode. *)
PROCEDURE SetMode*(x: LONGINT; s: SET);
BEGIN
disp := Displays.main; height := disp.height;
Left := 0; ColLeft := 0; Bottom := 0;
Unit := disp.unit;
UBottom := SHORT(-disp.offscreen);
Width := SHORT(disp.width); Height := SHORT(height);
ResetClip
END SetMode;
(** Display a picture. Used internally by Pictures module only. *)
// TODO: To Review, in concert with Bitmaps
PROCEDURE DisplayBlock*(data: POINTER TO ARRAY OF CHAR; depth: INTEGER; wth,
dx, dy, w, h, sx, sy, mode: LONGINT);
VAR pw, pd, src, dst, rdx, tdy, col: LONGINT; ch, prev, prevmap: CHAR; tmp: ARRAY 4 OF CHAR;
BEGIN
rdx := sx+w-1; tdy := sy+h-1; (* (sx,sy) bottom left & (rdx,tdy) top right *)
IF (sx <= clipX2) & (sy <= clipY2) & (rdx >= clipX1) & (tdy >= clipY1) THEN
IF sx < clipX1 THEN DEC(w, clipX1-sx); INC(dx, clipX1-sx); sx := clipX1 END;
IF sy < clipY1 THEN DEC(h, clipY1-sy); INC(dy, clipY1-sy); sy := clipY1 END;
IF rdx > clipX2 THEN DEC(w, rdx-clipX2) END;
IF tdy > clipY2 THEN DEC(h, tdy-clipY2) END;
IF (w > 0) & (h > 0) THEN
pd := depth;
IF pd = 8 THEN
pw := wth; src := 0; // index into data
INC(src, (dy+h-1)*pw + dx); (* top left corner *)
IF w*h*disp.format+1 > LEN(buf^) THEN NEW(buf, w*h*disp.format+1) END; (* +1 for *** below *)
dst := 0; // index into buf
CASE disp.format OF
Displays.index8:
prev := CHR(BG); prevmap := CHR(disp.ColorToIndex(palette[ORD(prev)]));
FOR tdy := 0 TO h-1 DO
FOR rdx := 0 TO w-1 DO
ch := data[src]; INC(src);
IF ch # prev THEN
prev := ch; prevmap := CHR(disp.ColorToIndex(palette[ORD(prev)]))
END;
buf[dst] := prevmap; INC(dst)
END;
INC(src, -w-pw)
END
|Displays.color565:
FOR tdy := 0 TO h-1 DO
FOR rdx := 0 TO w-1 DO
ch := data[src]; INC(src); col := palette[ORD(ch)];
BYTES(tmp,
BITS(ASH(col, 15-23)) * {11..15} +
BITS(ASH(col, 10-15)) * {5..10} +
BITS(ASH(col, 4-7)) * {0..4});
Displays.Move(tmp,0,buf,dst,2);
INC(dst, 2)
END;
INC(src, -w-pw)
END
|Displays.color888, Displays.color8888:
col := disp.format; (* size *)
FOR tdy := 0 TO h-1 DO
FOR rdx := 0 TO w-1 DO
ch := data[src]; INC(src);
BYTES(tmp,palette[ORD(ch)]);
Displays.Move(tmp,0,buf,dst,col);
INC(dst, col)
END;
INC(src, -w-pw)
END
END;
disp.Transfer(buf^, 0, w*disp.format, sx, height-h-sy, w, h, set)
ELSE (* depth not supported *)
(* skip *)
END
END
END
END DisplayBlock;
(** Return address of display located at x, or 0 if not supported. *)
PROCEDURE Map*(x: LONGINT): LONGINT;
BEGIN
RETURN 0
END Map;
PROCEDURE LoadDriver;
VAR m: Modules.Module; c: Modules.Command; name: ARRAY 32 OF CHAR;
BEGIN
Kernel.GetConfig("DDriver", name);
IF name = "" THEN name := "DisplayLinear" END;
m := Modules.ThisMod(name);
IF m # NIL THEN
c := Modules.ThisCommand(m, "Install");
IF c # NIL THEN c() END
ELSE
c := NIL
END;
IF c = NIL THEN
Kernel.WriteString("Display: "); Kernel.WriteString(Modules.resMsg); Kernel.WriteLn
END
END LoadDriver;
BEGIN
ASSERT((get = Displays.get) & (set = Displays.set));
DisplayLinear.Install; // instead of LoadDriver
NEW(buf, 8192);
pattern := NIL;
CreatePatterns;
SetMode(0, {});
P.open_screen(disp.width,disp.height,disp.format,"Oberon System 3", disp.fb^);
END Display.
Compiler.Compile Displays.Display.Mod\X ~
TestDisplay.Text TestTransferBlock.Mod TestSVGA.Mod