2 <B>program</B> monitors;
4 (* this an example showing 5 processes: two of them are in fact monitors, one controls the screen=ekran *)
6 <B>unit</B> ANSI: <B>class</B>;
7 (* CHECK whether config.sys contains a line device=ansi.sy the class ANSI enables operations on cursor, and bold, blink, underscore etc. *)
9 <B>unit</B> Bold : <B>procedure</B>;
11 write( chr(27), "[1m")
14 <B>unit</B> Blink : <B>procedure</B>;
16 write( chr(27), "[5m")
19 <B>unit</B> Reverse : <B>procedure</B>;
21 write( chr(27), "[7m")
24 <B>unit</B> Normal : <B>procedure</B>;
26 write( chr(27), "[0m")
29 <B>unit</B> Underscore : <B>procedure</B>;
31 write( chr(27), "[4m")
32 <B>end</B> Underscore;
34 <B>unit</B> inchar : IIUWgraph <B>function</B> : integer;
35 (*podaj nr znaku przeslanego z klawiatury *)
36 <B>var</B> i : integer;
40 <B>if</B> i <> 0 <B>then</B> <B>exit</B> <B>fi</B>;
45 <B>unit</B> NewPage : <B>procedure</B>;
47 write( chr(27), "[2J")
50 <B>unit</B> SetCursor : <B>procedure</B>(row, column : integer);
51 <B>var</B> c,d,e,f : char,
54 i := row <B>div</B> 10;
55 j := row <B>mod</B> 10;
58 i := column <B>div</B> 10;
59 j := column <B>mod</B> 10;
62 write( chr(27), "[", c, d, ";", e, f, "H")
67 <B>unit</B> monitor: process(node:integer, size:integer,e: ekran);
69 <B>var</B> buf: <B>arrayof</B> integer,
70 nr,i,j,k1,k2,n1,n2: integer;
73 <B>unit</B> lire: <B>procedure</B>(<B>output</B> k: integer);
75 <B>call</B> e.druk(13,2+nr*30+k1,0,k2);
76 <B>call</B> e.druk(13,2+nr*30+(i-1)*6,1,buf(i));
80 i:= (i <B>mod</B> size)+1;
83 <B>call</B> e.printtext("i equal j")
87 <B>unit</B> ecrire: <B>procedure</B>(n:integer);
89 <B>call</B> e.druk(13,2+nr*30+n1,0,n2);
90 <B>call</B> e.druk(13,2+nr*30+(j-1)*6,2,n);
94 j := (j <B>mod</B> size)+1;
97 <B>call</B> e.printtext("j equal i")
101 <B>array</B> buf <B>dim</B>(1:size);
103 <B>for</B> i := 1 to size
106 <B>call</B> e.druk(13,2+nr*30+(i-1)*6,0,buf(i));
114 (* <B>end</B> initialize buffer *)
118 <B>accept</B> lire, ecrire
122 <B>unit</B> prcs: process(node,nr:integer, mleft,mright:
124 <B>var</B> l,o: integer;
127 <B>call</B> e.SetCursor(8+(nr-1)*10,29);
130 <B>call</B> e.printtext("<-- p1 <--");
132 <B>call</B> e.printtext("--> p2 -->");
136 <B>call</B> mleft.lire(l) ;
137 <B>call</B> e.druk(11+(nr-1)*4,31-(nr-1)*8,1,l);
139 <B>call</B> mright.ecrire(l) ;
140 <B>call</B> e.druk(10+(nr-1)*6,23+(nr-1)*8,2,l);
141 <B>if</B> l <B>mod</B> 15 = 0
144 <B>if</B> o = -79 <B>then</B> <B>call</B> <B>endrun</B> <B>fi</B>;
149 <B>unit</B> ekran : ANSI process(nrprocesora: integer);
150 <B>unit</B> printtext: <B>procedure</B>(s:string);
154 <B>end</B> printtext;
156 <B>unit</B> druk: <B>procedure</B>(gdzieW,gdzieK,jak,co:integer);
158 <B>call</B> SetCursor(gdzieW,gdzieK);
160 <B>if</B> jak=0 <B>then</B> <B>call</B> Normal <B>else</B>
161 <B>if</B> jak=1 <B>then</B> <B>call</B> Reverse <B>else</B>
162 <B>if</B> jak=2 <B>then</B> <B>call</B> Bold
170 <B>unit</B> print: <B>procedure</B> (i:integer);
177 <B>do</B> <B>accept</B> inchar,
178 Normal,NewPage, SetCursor, Bold, Underscore,
179 Reverse, Blink, print, printtext, druk
183 <B>var</B> m1,m2:monitor,
187 <B>begin</B> (* ----- HERE IS THE MAIN PROGRAM ----- *)
188 (* create a configuration *)
189 e:= <B>new</B> ekran(0);
191 <B>call</B> e.Normal;
192 <B>call</B> e.NewPage;
193 m1 := <B>new</B> monitor(0,4,e);
194 m2 := <B>new</B> monitor(0,5,e);
196 p1 := <B>new</B> prcs(0,1,m2,m1,e);
197 p2 := <B>new</B> prcs(0,2,m1,m2,e);