Added upstream from http://ftp.icm.edu.pl/pub/loglan/
[loglan.git] / doc / iuwgraf.txt
1 \r
2 unit IIUWGRAPH: class;\r
3 \r
4 {    this predefined class enables basic graphic operations }\r
5 \r
6 {    the early versions of library IIUWGRAPH have been elaborated by \r
7        Piotr Carlsson, Miroslawa Milkowska, Janina Jankowska, \r
8        Michal Jankowski  at  Institute of Informatics, \r
9        University of Warsaw 1987,\r
10        and added to Loglan system by Danuta Szczepanska 1987,  \r
11        the recent versions were done at LITA, Pau,\r
12        by\r
13        Pawel Susicki  (1991) for Unix\r
14        Sebastien Bernard (1992) for ATARI \r
15  \r
16 \r
17 fait à Pau, le {TIME \@ "d MMMM, yyyy"|6 August, 1993}  A.S.}\r
18 \r
19 { the predefined class IIUWGRAPH is included in all versions of interpreter of Loglan, with the exception of the present version of interpreter for VAX/VMS.\r
20     Each interpreter is equipped with one version of graphic library which corresponds to one of the following possibilities:\r
21 - EGA  card,  (use egaint if you have a VGA card)\r
22 \r
23 - Hercules mono card,\r
24 \r
25 - IBM CGA card\r
26      several variants are offered\r
27      CGA colour,\r
28      CGA mono 320 x 200\r
29      CGA mono 640 x 200\r
30      all above versions were tested in DOS 3.3 environment\r
31 \r
32 - an emulation of Hercules in a Xwindow for UNIX environment,\r
33 \r
34 - an emulation of IIUWGRAPH in ATARI STE environment.\r
35 \r
36 NEW  (october 1993)\r
37 MM. Becourt et Larrieu did a multiwindow graphic co-process for the int Loglan interpreter in Unix & Xwindows environment. See the separate document on it.\r
38 \r
39 M. Larrieu did an experimental version of  vgaint Loglan executor for the machines 386/486. }\r
40 \r
41 hidden    MaxX, MaxY,  current_X, current_Y, is_graphic_On,      \r
42               current_Colour, current_Background_Colour,  current_Style,\r
43              current_Palette,  current_Pattern ;\r
44 \r
45 \r
46                          {    Hercules            EGA/VGA               CGA   \r
47                         Unix                                            }\r
48 \r
49 const  MaxX =            719  ;           {     639                        319    }\r
50           MaxY =             347  ;           {    349                        199     }\r
51 \r
52 {    the screen's coordinates are\r
53        \r
54        (0,0)   ---------------------->  (MaxX,0)\r
55            ¦\r
56            ¦\r
57            ¦\r
58           V\r
59        (0, MaxY)                            (MaxX,MaxY)\r
60 \r
61 }\r
62 \r
63 \r
64 var  currentDriver : integer,                     { see NOCARD below } \r
65        current_X, current_Y:  integer         { it is the current position }\r
66        is_graphic_On:  Boolean,    { evidently tells whether we are in                                          graphics mode }\r
67        current_Colour : integer,                { }\r
68        current_Background_Colour : integer,\r
69        current_Style : integer,         { }\r
70        current_Palette : integer,\r
71        current_Pattern\r
72 \r
73 unit GRON : procedure (i: integer);\r
74       {  procedure sets the monitor in graphic mode and clears the  buffer      of screen. The parameter is meaningless, the only exception is  made for the IBM CGA card in this case if you have chosen the   mode 320x200 pixels the the value 1 of the parameter means      colours, the value 0 means a mono screen is connected to the card\r
75        }\r
76 \r
77 unit GROFF : procedure;\r
78       {  the procedure sets the monitor in the text mode filling it with        spaces.\r
79          DO NOT FORGET to set the monitor in the text mode before you   terminate  your program\r
80        }\r
81 \r
82 unit NOCARD : function : integer;\r
83       { the value given by this function determines the type of the currently used monitor and it is equal to\r
84             1   for Hercules mono card,\r
85         2       for IBM CGA color\r
86         3       for IBM CGA mono 320 x 200\r
87         4       for IBM CGA mono 640 x 200\r
88         5       for EGA/VGA card\r
89    ??     6          for ATARI STE\r
90    ??     7          for  Unix versions equipped with XWindows\r
91            You can not call the function nocard before GRON sets the graphic mode\r
92        }\r
93 \r
94 unit CLS : procedure;\r
95        { the screen will be cleared and filled with colour 0  }\r
96 \r
97 unit HPAGE : procedure(nr, : integer, clear : boolean);\r
98        { the procedure is applicable to the cards EGA/VGA and   Hercules only!\r
99             it selects a page of video memory with the number = nr,\r
100                 clears its contents if clear is set <>0,\r
101                 and sets the mode\r
102                      mode = 0 the content of the page is shown as text,\r
103                      mode = 1 the content of the page is shown graphically,\r
104                      mode = -1 a worktime buffer is associated with the  page.\r
105         Mode -1 does not change the number not the way it is shown.     Mode 0 links the buffer with the selected page. For card Hercules       only  call HPAGE(0, 1, 1) is equivalent to call GRON(99) and call       HPAGE(0, 0, 1) is equivalent to call GROFF.\r
106 \r
107 Example of an animating loop\r
108 \r
109 var nr: integer;\r
110 begin\r
111    call GRON(0);\r
112    nr := 1;\r
113    (* draw first image *)\r
114    call DRAW(...)\r
115    ...\r
116    while more \r
117    do\r
118         call HPAGE(1-nr, 1,0);      (* displaying *)\r
119         call HPAGE(nr, -1,1);      (* buffering *)\r
120         (* draw modified image *)\r
121         call DRAW( ...)\r
122          ...\r
123         nr := 1-nr\r
124     od\r
125 end example\r
126          \r
127 \r
128 unit VIDEO : procedure( A: array of integer);\r
129        { this procedure can not be applied for the EGA/VGA card }\r
130         { the worktime buffer will be associated with the array A.\r
131             A call of VIDEO does not change the contents of the buffer. \r
132             All subsequent calls of the procedures modifying the screen will \r
133             concern the array A. The screen does not change.\r
134             A ready image can be moved to the screen with the help of               GETMAP/PUTMAP procedures or it can be stored on disk.\r
135             The array should have 16 kBytes for IBM CGA card or \r
136           32 kBytes for Hercules card.}\r
137 \r
138 { PROCEDURES  CONTROLLING THE COLOURS }\r
139 \r
140 unit COLOR : procedure(co : integer);\r
141 {               sets current color to co \r
142         for monochrome displays, 0 means black, non-0 - white\r
143         for color displays, 0 means background\r
144      see PALLET\r
145 }      \r
146 \r
147 \r
148 unit STYLE : procedure(styl : integer);\r
149 {       sets style of lines and fill shades to a combination\r
150         of current color and background color (for mono -\r
151         white and black, respectively) according to 5 predefined\r
152         patterns:\r
153 \r
154                 0       ....\r
155                 1       ****\r
156                 2       ***.\r
157                 3       **..\r
158                 4       *.*.\r
159                 5       *...\r
160 \r
161         where   '*' means current color,  '.' background colour\r
162 When drawing the segments the subsequent pixels will have colour determined by cyclic application of style pattern. The first and the last pixels of a segment will have always current colour.\r
163 When filling contours the given style will be applied to horizontal lines with even coordinate. The style for odd lines is determined automatically.\r
164 The same applies for perpendicular lines.\r
165 There are other possibilities of mixing colours, cf procedure PATERN.\r
166 }\r
167 \r
168 \r
169 unit PATERN : procedure (par, par1, par2, par3 : integer);\r
170                 { sets style of lines and fill shades to an explicitly specified\r
171                    combination of colours. When drawing lines the only parameter of importance will be par. When filling the parameters par and par2 concern the horiwontal (resp. perpendicular) lines with the coordinate x (resp: y) even. lines\r
172         combination of colors : "iv" for even scan lines, "io" for odd.\r
173         Color encoding is decimal, allowing 4 pixels.\r
174         Lines are drawn always according to "iv".\r
175 \r
176         Examples:\r
177 \r
178         call patern(1100,0011)\r
179                 is equivalent to \r
180         call color(1), call style(3)\r
181 \r
182 \r
183         call patern(1212,2121)\r
184                 produces a shade that cannot be otherwise achieved\r
185                 ( a dotted line consisting of pixels in colors 1 and 2 )\r
186 \r
187 \r
188 \r
189 unit BORDER : procedure (background_Colour: integer);\r
190         [ IBM color mode only ]\r
191 \r
192         sets actual background color to i  ( i = 0,1,...,15 )\r
193 \r
194 \r
195 unit PALLET : procedure (nr : integer);\r
196         {\r
197 \r
198 the codes of colors are as follows\r
199                 0       black\r
200                 1       blue dark\r
201                 2       green dark\r
202                 3       turquoise dark\r
203                 4       red dark\r
204                 5       violet\r
205                 6       brown\r
206                 7       grey light\r
207                 8       grey dark        \r
208                 9       blue\r
209                 10      green\r
210                 11      turquoise\r
211                 12      red light\r
212                 13      rose\r
213                 14      yellow\r
214                 15      white\r
215   \r
216        the procedure does not applies for Hercules card}\r
217 \r
218 \r
219 unit INTENS : procedure (i : integer);\r
220 \r
221 {       changes current intensity, 1 means more intensity, 0 less;\r
222         default intensity is 1\r
223         Applies to IBM CGA only\r
224 }\r
225 \r
226 { PROCEDURES CONTROLLING POSITION }\r
227 \r
228 unit MOVE : procedure (x,y :integer);\r
229         { procedure MOVE sets the current position on the screen on the pixel with coordinates\r
230              x  - column,\r
231              y - line   }\r
232          { precondition of  MOVE:\r
233                  0{SYMBOL 163 \f "Symbol"}x{SYMBOL 163 \f "Symbol"}MaxX  & 0{SYMBOL 163 \f "Symbol"}y{SYMBOL 163 \f "Symbol"}MaxY \r
234           }\r
235 \r
236 unit INXPOS : function: integer;\r
237        { function INXPOS returns the x coordinate of the current position }\r
238 \r
239 \r
240 unit INYPOS : function : integer;\r
241         { function INYPOS returns the y coordinate of the current       position }\r
242 \r
243 \r
244 unit PUSHXY : procedure;\r
245 {       pushes current position, color & style onto the stack.\r
246         The stack is kept internally, max depth is 16\r
247 }\r
248 \r
249 \r
250 unit POPXY: procedure;\r
251 \r
252 {       restores position, color & style from internal stack   }\r
253 \r
254 { Example\r
255 unit DIAGONAL : procedure;\r
256     var ix, iy : integer;\r
257 begin\r
258         call PUSHXY;\r
259         ix := INXPOS;\r
260         iy := INYPOS;\r
261         call DRAW(ix+10, iy+10);\r
262         call POPXY\r
263 end DIAGONAL;\r
264 }\r
265 \r
266 \r
267 unit TRACK : procedure (x,y : integer);\r
268 {       displays a small (8*8) arrow-shaped cursor which can be moved around with cursor keys; a single keystroke moves\r
269         it by 5 pixels, in NUM mode step size is 1 pixel;\r
270         "home" key returns the cursor to the initial (x,y);\r
271         "end" removes cursor from screen, and returns - the new current\r
272         position can be read with "INXPOS" and "INYPOS" above.\r
273 \r
274 ATTENTION: if you have a mouse then read on the predefined class Mouse, which permits to control the mouse\r
275 }\r
276 \r
277 { PROCEDURES SERVING POINTS }\r
278 \r
279 unit POINT : procedure(x,y: integer);\r
280 {               moves current position to pixel (x,y) and sets it to current                    color \r
281  }\r
282 \r
283 unit INPIX : function (x,y : integer) : integer;\r
284         {       \r
285                 moves to pixel (x,y) and returns its color setting;\r
286         }\r
287 \r
288 \r
289 unit DRAW : procedure( x,y : integer);\r
290         {   \r
291         draws a line from current screen position to (x,y);\r
292         sets current position to (x,y);\r
293         line is drawn in current color, with both terminal pixels\r
294         always turned white ( non-background) for non-black\r
295         ( non-background ) line color.\r
296         Bresenham's algorithm is used, pixels belonging to the segment  change their state depending on current colour and style.\r
297         }\r
298 \r
299 unit CIRB : procedure (xi, yi, ri : integer, alfa, beta : real,  \r
300                                                  cbord, fill, p, q : integer);\r
301 \r
302         {\r
303         draws a circle (or ellipse, depending on aspect value, see below),\r
304         optionally filling its interior; \r
305         does not preserve position;\r
306         (xi,yi) -  are center coordinates\r
307         ri - radius in pixels (horizontally)\r
308         alfa, beta - starting & ending angles; if alfa=beta a full\r
309                circle is drawn; values should be given in radians;\r
310         cbord - border color,\r
311         fill - if fill <>0, interior is filled in current style&color\r
312         p,q - aspect ratio; if p/q=1, a perfect circle is drawn,\r
313                                      if p/q<1, the horizontal axis is longer, \r
314                                          if p/q>1 - the vertical axis is longer;\r
315         }\r
316 \r
317 unit HFILL : procedure(x: integer);\r
318         \r
319 {       fills current row (horizontally) from current position\r
320         (INXPOS, INYPOS) up to (x,INYPOS) with bit pattern depending\r
321         on current color, style and/or pattern and position on\r
322         the screen in such a way that adjacent "hfill"ed" rows\r
323         will produce a shade simulating color;\r
324 \r
325         ATTENTION hfill does not change current position;\r
326 \r
327 It is advised to use hfill when filling contours since it works faster then DRAW. Procedure hfill is capable to similate additional colours.\r
328 }\r
329 \r
330 unit VFILL : procedure(y: integer);\r
331 \r
332 {       fills current column ( vertically ) from current\r
333         position (INXPOS, INYPOS) up to (INXPOS, y) in a similiar way\r
334         that "hfill" does;\r
335         rectangular area "vfill'ed" is not distinguishable\r
336         on the screen from same shape "hfill'ed", except that\r
337         it will take much longer to fill.\r
338         \r
339         ATTENTION hfill does not change current position;\r
340 \r
341 { Procedures operating on bitmaps }\r
342 \r
343 unit GETMAP : function (x,y : integer) : arrayof integer;\r
344                 {saves rectangular area between current position as\r
345         top left corner and (ix,iy) as bottom right corner,\r
346         including border lines;\r
347         position remains unchanged.\r
348         array of integer should have  \r
349                 4+(rows{SYMBOL 215 \f "Symbol"}{SYMBOL 233 \f "Symbol"}columns/8{SYMBOL 249 \f "Symbol"} {SYMBOL 215 \f "Symbol"}coeff)\r
350         bytes. The coefficient coeff is 1 for Hercules, 2 for CGA, 4 for EGA    card.\r
351          ATTENTION: in DOS environment the size of the array may        necessitate the use of loglan with the option H+, see also memavail \r
352            }\r
353 \r
354 \r
355 unit PUTMAP : procedure ( a: array of integer);\r
356         {sets rectangular area of screen pixels to that saved\r
357         by "getmap" in "iarray";\r
358         same size is restored, with top left corner in current\r
359         position;\r
360         position remains unchanged.\r
361         }\r
362 unit ORMAP : procedure ( a : arrayof integer);\r
363         {same as putmap, but saved bitmap is or'ed into screen\r
364         rather than just set.\r
365         }\r
366 \r
367 unit XORMAP : procedure ( a: arrayof integer);\r
368         {same as putmap, but saved bitmap is xor'ed into screen\r
369         rather than just set.\r
370         }\r
371 \r
372 unit INKEY : function : integer;\r
373 \r
374         {returns next character from keyboard buffer;\r
375         0 is returned if buffer is empty;\r
376         special keys are returned as negative numbers;\r
377         ALT-NUM method may be used for entering character codes\r
378         above 127 (this makes entering special keys 128-132\r
379         impossible);\r
380         if a character is returned, it is also removed\r
381         from the buffer, so MS-DOS will not see it (CTRL-C!);\r
382         typeahead is allowed, echo is suppressed.\r
383         }\r
384 \r
385 unit HASCII : procedure\r
386         {'xor's the character in a 8*8 box with top left corner\r
387         in the current position;\r
388         moves current position by (8,0);\r
389         character code 0 sets complete box to black ( background ),\r
390         with no change in position.\r
391         BIOS ROM font for IBM color card is used. If the font\r
392         table is not at F000:FA6E, the character will probably\r
393         be unrecognizable, and most certainly wrong.\r
394         For codes >127, table pointed to by interrupt vector 31\r
395         is used. }\r
396 \r
397 unit HFONT\r
398         {sets 8*8 horizontal font table address to iseg:ioffs.}\r
399 \r
400 \r
401 unit HFONT8\r
402 {includes a copy of IBM ROM 8*8 font and returns address suitable for passing to "hfont";\r
403 Use of "hfont8" makes program larger but quarantees BIOS ROM independence.}\r
404 \r
405 \r
406 unit INHLINE : procedure (a: arrayof char; output n : integer);\r
407 { reads a line of at most "n" characters from the keyboard, storing them in the "a" array;  characters are echoed at current position with "hascii"  as they are typed in; a blinking cursor prompts for the next character;\r
408 BACKSPACE works as expected, RETURN completes the reading;\r
409 typing "n"-th character also completes the line;\r
410 "l" is blank filled up to "n" bytes;\r
411 on return "n" is the total number of characters read. }\r
412 \r
413         \r
414 unit OUTHLINE : procedure (a : arrayof char; n : integer);\r
415 { calls "hascii"  "n" times with subsequent bytes from "a" array as arguments; before each character is written, "hascii(0)" is called. }\r
416 \r
417 \r
418 end IIUWGRAPH;\r
419 à Pau, le {DATE|06/08/93}               {PAGE|4}\r
420 \r
421 Predefined class        IIUWGRAPH       {PAGE|3}\r
422 \r
423 \r