]> 4ch.mooo.com Git - 16.git/blob - 16/PCGPE10/TUT6.TXT
modified: 16/DOS_GFX.EXE
[16.git] / 16 / PCGPE10 / TUT6.TXT
1 \r
2                    ÕÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͸\r
3                    ³         W E L C O M E         ³\r
4                    ³  To the VGA Trainer Program   ³ ³\r
5                    ³              By               ³ ³\r
6                    ³      DENTHOR of ASPHYXIA      ³ ³ ³\r
7                    ÔÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ; ³ ³\r
8                      ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ³\r
9                        ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ\r
10 \r
11                            --==[ PART 6 ]==--\r
12 \r
13 \r
14 \r
15 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
16 þ Introduction\r
17 \r
18 Hi there! I'm back, with the latest part in the series : Pregenerated\r
19 arrays. This is a fairly simple concept that can treble the speed of\r
20 your code, so have a look.\r
21 \r
22 I still suggest that if you haven't got a copy of TEXTER that you get it.\r
23 This is shareware, written by me, that allows you to grab fonts and use\r
24 them in your own programs.\r
25 \r
26 I downloaded the Friendly City BBS Demo, an intro for a PE BBS, written\r
27 by a new group called DamnRite, with coder Brett Step. The music was\r
28 excellent, written by Kon Wilms (If I'm not mistaken, he is an Amiga\r
29 weenie ;-)). A very nice first production, and I can't wait to see more\r
30 of their work. I will try con a local BBS to allow me to send Brett some\r
31 fido-mail.\r
32 \r
33 If you would like to contact me, or the team, there are many ways you\r
34 can do it : 1) Write a message to Grant Smith in private mail here on\r
35                   the Mailbox BBS.\r
36             2) Write a message here in the Programming conference here\r
37                   on the Mailbox (Preferred if you have a general\r
38                   programming query or problem others would benefit from)\r
39             3) Write to ASPHYXIA on the ASPHYXIA BBS.\r
40             4) Write to Denthor, Eze or Livewire on Connectix.\r
41             5) Write to :  Grant Smith\r
42                            P.O.Box 270 Kloof\r
43                            3640\r
44                            Natal\r
45             6) Call me (Grant Smith) at (031) 73 2129 (leave a message if you\r
46                   call during varsity)\r
47 \r
48 NB : If you are a representative of a company or BBS, and want ASPHYXIA\r
49        to do you a demo, leave mail to me; we can discuss it.\r
50 NNB : If you have done/attempted a demo, SEND IT TO ME! We are feeling\r
51         quite lonely and want to meet/help out/exchange code with other demo\r
52         groups. What do you have to lose? Leave a message here and we can work\r
53         out how to transfer it. We really want to hear from you!\r
54 \r
55 \r
56 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
57 þ  Why do I need a lookup table? What is it?\r
58 \r
59 A lookup table is an imaginary table in memory where you look up the\r
60 answers to certain mathematical equations instead of recalculating them\r
61 each time. This may speed things up considerably. Please note that a\r
62 lookup table is sometimes referred to as a pregenerated array.\r
63 \r
64 One way of looking at a lookup table is as follows : Let us say that for\r
65 some obscure reason you need to calculate a lot of multiplications (eg.\r
66 5*5 , 7*4 , 9*2 etc.). Instead of actually doing a slow multiply each\r
67 time, you can generate a kind of bonds table, as seen below :\r
68 \r
69 \r
70 ÉÍÑÍËÍÍÍÍÍÍÍÑÍÍÍÍÍÍÑÍÍÍÍÍÍÑÍÍÍÍÍÍÑÍÍÍÍÍÍÑÍÍÍÍÍÍÑÍÍÍÍÍÍÑÍÍÍÍÍÍÑÍÍÍÍÍÍ»\r
71 ÇÄÅĶ   1   ³  2   ³  3   ³  4   ³  5   ³  6   ³  7   ³  8   ³  9   º\r
72 ÇÄÁÄ×ÍÍÍÍÍÍÍØÍÍÍÍÍÍØÍÍÍÍÍÍØÍÍÍÍÍÍØÍÍÍÍÍÍØÍÍÍÍÍÍØÍÍÍÍÍÍØÍÍÍÍÍÍØÍÍÍÍÍ͵\r
73 º 1 º   1   ³  2   ³  3   ³  4   ³  5   ³  6   ³  7   ³  8   ³  9   ³\r
74 ÇÄÄÄ×ÄÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄ´\r
75 º 2 º   2   ³  4   ³  6   ³  8   ³  10  ³  12  ³  14  ³  16  ³  18  ³\r
76 ÇÄÄÄ×ÄÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄ´\r
77 º 3 º   3   ³  6   ³  9   ³  12  ³  15  ³  18  ³  21  ³  24  ³  27  ³\r
78 ÇÄÄÄ×ÄÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄ´\r
79 º 4 º   4   ³  8   ³  12  ³  16  ³  20  ³  24  ³  28  ³  32  ³  36  ³\r
80 ÇÄÄÄ×ÄÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄ´\r
81 º 5 º   5   ³  10  ³  15  ³  20  ³  25  ³  30  ³  35  ³  40  ³  45  ³\r
82 ÇÄÄÄ×ÄÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄ´\r
83 º 6 º   6   ³  12  ³  18  ³  24  ³  30  ³  36  ³  42  ³  48  ³  54  ³\r
84 ÇÄÄÄ×ÄÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄ´\r
85 º 7 º   7   ³  14  ³  21  ³  28  ³  35  ³  42  ³  49  ³  56  ³  63  ³\r
86 ÇÄÄÄ×ÄÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄ´\r
87 º 8 º   8   ³  16  ³  24  ³  32  ³  40  ³  48  ³  56  ³  64  ³  72  ³\r
88 ÇÄÄÄ×ÄÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄ´\r
89 º 9 º   9   ³  18  ³  27  ³  36  ³  45  ³  54  ³  63  ³  72  ³  81  ³\r
90 ÈÍÍÍÊÄÄÄÄÄÄÄÁÄÄÄÄÄÄÁÄÄÄÄÄÄÁÄÄÄÄÄÄÁÄÄÄÄÄÄÁÄÄÄÄÄÄÁÄÄÄÄÄÄÁÄÄÄÄÄÄÁÄÄÄÄÄÄÙ\r
91 \r
92 This means that instead of calculating 9*4, you just find the 9 on the\r
93 top and the 4 on the side, and the resulting number is the answer.  This\r
94 type of table is very useful when the equations are very long to do.\r
95 \r
96 The example I am going to use for this part is that of circles. Cast\r
97 your minds back to Part 3 on lines and circles. The circle section took\r
98 quite a while to finish drawing, mainly because I had to calculate the\r
99 SIN and COS for EVERY SINGLE POINT. Calculating SIN and COS is obviously\r
100 very slow, and that was reflected in the speed of the section.\r
101 \r
102 \r
103 \r
104 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
105 þ  How do I generate a lookup table?\r
106 \r
107 This is very simple. In my example, I am drawing a circle. A circle has\r
108 360 degrees, but for greater accuracy, to draw my circle I will start\r
109 with zero and increase my degrees by 0.4. This means that in each circle\r
110 there need to be 8000 SINs and COSes (360/0.4=8000). Putting these into\r
111 the base 64k that Pascal allocates for normal variables is obviously not\r
112 a happening thing, so we define them as pointers in the following\r
113 manner: \r
114         TYPE   table = Array [1..8000] of real;\r
115 \r
116         VAR    sintbl : ^table;\r
117                costbl : ^table;\r
118 \r
119 Then in the program we get the memory for these two pointers. Asphyxia \r
120 was originally thinking of calling itself Creative Reboot Inc., mainly \r
121 because we always forgot to get the necessary memory for our pointers.\r
122 (Though a bit of creative assembly coding also contributed to this. We\r
123 wound up rating our reboots on a scale of 1 to 10 ;-)). The next obvious\r
124 step is to place our necessary answers into our lookup tables.  This can\r
125 take a bit of time, so in a demo, you would do it in the very beginning\r
126 (people just think it's slow disk access or something), or after you\r
127 have shown a picture (while the viewer is admiring it, you are\r
128 calculating pi to its 37th degree in the background ;-)) Another way of\r
129 doing it is, after calculating it once, you save it to a file which you\r
130 then load into the variable at the beginning of the program. Anyway,\r
131 this is how we will calculate the table for our circle :\r
132 \r
133     Procedure Setup;\r
134     VAR deg:real;\r
135     BEGIN\r
136       deg:=0;\r
137       for loop1:=1 to 8000 do BEGIN\r
138         deg:=deg+0.4;\r
139         costbl^[loop1]:=cos (rad(deg));\r
140         sintbl^[loop1]:=sin (rad(deg));\r
141       END;\r
142     END;\r
143 \r
144 This will calculate the needed 16000 reals and place them into our two\r
145 variables. The amount of time this takes is dependant on your computer.\r
146 \r
147 \r
148 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
149 þ  How do I use a lookup table?\r
150 \r
151 This is very easy. In your program, wherever you put\r
152                cos (rad(deg)),\r
153 you just replace it with :\r
154                costbl^[deg]\r
155 \r
156 Easy, no? Note that the new "deg" variable is now an integer, always\r
157 between 1 and 8000.\r
158 \r
159 \r
160 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
161 þ Where else do I use lookup tables?\r
162 \r
163 Lookup tables may be used in many different ways. For example, when\r
164 working out 3-dimensional objects, sin and cos are needed often, and are\r
165 best put in a lookup table. In a game, you may pregen the course an\r
166 enemy may take when attacking. Even saving a picture (for example, a\r
167 plasma screen) after generating it, then loading it up later is a form\r
168 of pregeneration.\r
169 \r
170 When you feel that your program is going much too slow, your problems\r
171 may be totally sorted out by using a table. Or, maybe not. ;-)\r
172 \r
173 \r
174 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
175 þ  In closing\r
176 \r
177 As you have seen above, lookup tables aren't all that exciting, but they\r
178 are useful and you need to know how to use them. The attached sample\r
179 program will demonstrate just how big a difference they can make.\r
180 \r
181 Keep on coding, and if you finish anything, let me know about it! I\r
182 never get any mail, so all mail is greatly appreciated ;-)\r
183 \r
184 Sorry, no quote today, it's hot and I'm tired. Maybe next time ;-)\r
185 \r
186   - Denthor\r
187 \r
188 \r
189 ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ\r
190 ³ TUTPROG6.PAS ³\r
191 ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ\r
192 \r
193 {$X+}\r
194 USES crt;\r
195 \r
196 CONST VGA = $a000;\r
197 \r
198 TYPE tbl = Array [1..8000] of real;\r
199              { This will be the shape of the 'table' where we look up\r
200                values, which is faster then calculating them }\r
201 \r
202 VAR loop1:integer;\r
203     Pall : Array [1..20,1..3] of byte;\r
204       { This is our temporary pallette. We ony use colors 1 to 20, so we\r
205         only have variables for those ones. }\r
206 \r
207 {ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ}\r
208 Procedure SetMCGA;  { This procedure gets you into 320x200x256 mode. }\r
209 BEGIN\r
210   asm\r
211      mov        ax,0013h\r
212      int        10h\r
213   end;\r
214 END;\r
215 \r
216 \r
217 {ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ}\r
218 Procedure SetText;  { This procedure returns you to text mode.  }\r
219 BEGIN\r
220   asm\r
221      mov        ax,0003h\r
222      int        10h\r
223   end;\r
224 END;\r
225 \r
226 {ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ}\r
227 Procedure Cls (Col : Byte);\r
228    { This clears the screen to the specified color }\r
229 BEGIN\r
230   Fillchar (Mem [VGA:0],64000,col);\r
231 END;\r
232 \r
233 \r
234 {ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ}\r
235 Procedure Putpixel (X,Y : Integer; Col : Byte);\r
236   { This puts a pixel on the screen by writing directly to memory. }\r
237 BEGIN\r
238   Mem [VGA:X+(Y*320)]:=Col;\r
239 END;\r
240 \r
241 \r
242 {ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ}\r
243 procedure WaitRetrace; assembler;\r
244   {  This waits for a vertical retrace to reduce snow on the screen }\r
245 label\r
246   l1, l2;\r
247 asm\r
248     mov dx,3DAh\r
249 l1:\r
250     in al,dx\r
251     and al,08h\r
252     jnz l1\r
253 l2:\r
254     in al,dx\r
255     and al,08h\r
256     jz  l2\r
257 end;\r
258 \r
259 \r
260 {ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ}\r
261 Procedure Pal(ColorNo : Byte; R,G,B : Byte);\r
262   { This sets the Red, Green and Blue values of a certain color }\r
263 Begin\r
264    Port[$3c8] := ColorNo;\r
265    Port[$3c9] := R;\r
266    Port[$3c9] := G;\r
267    Port[$3c9] := B;\r
268 End;\r
269 \r
270 \r
271 {ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ}\r
272 Function rad (theta : real) : real;\r
273   {  This calculates the degrees of an angle }\r
274 BEGIN\r
275   rad := theta * pi / 180\r
276 END;\r
277 \r
278 \r
279 \r
280 {ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ}\r
281 Procedure NormCirc;\r
282   { This generates a spireal without using a lookup table }\r
283 VAR deg,radius:real;\r
284     x,y:integer;\r
285 \r
286 BEGIN\r
287   gotoxy (1,1);\r
288   Writeln ('Without pregenerated arrays.');\r
289   for loop1:=60 downto 43 do BEGIN\r
290     deg:=0;\r
291     radius:=loop1;\r
292     repeat\r
293       X:=round(radius*COS (rad (deg)));\r
294       Y:=round(radius*sin (rad (deg)));\r
295       putpixel (x+160,y+100,61-loop1);\r
296       deg:=deg+0.4;           { Increase the degree so the circle is round }\r
297       radius:=radius-0.02;    { Decrease the radius for a spiral effect }\r
298     until radius<0; {  Continue till at the centre (the radius is zero) }\r
299   END;\r
300 END;\r
301 \r
302 \r
303 {ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ}\r
304 Procedure LookupCirc;\r
305   {  This draws a spiral using a lookup table }\r
306 VAR radius:real;\r
307     x,y,pos:integer;\r
308     costbl : ^tbl;\r
309     sintbl : ^tbl;\r
310 \r
311     Procedure Setupvars;\r
312       {  This is a nested procedure (a procedure in a procedure), and may\r
313          therefore only be used from within the main part of this procedure.\r
314          This section gets the memory for the table, then generates the\r
315          table. }\r
316     VAR deg:real;\r
317     BEGIN\r
318       getmem (costbl,sizeof(costbl^));\r
319       getmem (sintbl,sizeof(sintbl^));\r
320       deg:=0;\r
321       for loop1:=1 to 8000 do BEGIN         { There are 360 degrees in a    }\r
322         deg:=deg+0.4;                       { circle. If you increase the   }\r
323         costbl^[loop1]:=cos (rad(deg));     { degrees by 0.4, the number of }\r
324         sintbl^[loop1]:=sin (rad(deg));     { needed parts of the table is  }\r
325       END;                                  { 360/0.4=8000                  }\r
326     END;\r
327     { NB : For greater accuracy I increase the degrees by 0.4, because if I\r
328            increase them by one, holes are left in the final product as a\r
329            result of the rounding error margin. This means the pregen array\r
330            is bigger, takes up more memory and is slower to calculate, but\r
331            the finished product looks better.}\r
332 \r
333 BEGIN\r
334   cls (0);\r
335   gotoxy (1,1);\r
336   Writeln ('Generating variables....');\r
337   setupvars;\r
338   gotoxy (1,1);\r
339   Writeln ('With pregenerated arrays.');\r
340   for loop1:=60 downto 43 do BEGIN\r
341     pos:=1;\r
342     radius:=loop1;\r
343     repeat\r
344       X:=round (radius*costbl^[pos]);   { Note how I am not recalculating sin}\r
345       Y:=round (radius*sintbl^[pos]);   { and cos for each point.            }\r
346       putpixel (x+160,y+100,61-loop1);\r
347       radius:=radius-0.02;\r
348       inc (pos);\r
349       if pos>8000 then pos:=1;    { I only made a table from 1 to 8000, so it}\r
350                                   { must never exceed that, or the program   }\r
351                                   { will probably crash.                     }\r
352     until radius<0;\r
353   END;\r
354   freemem (costbl,sizeof(costbl^));   { Freeing the memory taken up by the   }\r
355   freemem (sintbl,sizeof(sintbl^));   { tables. This is very important.      }\r
356 END;\r
357 \r
358 \r
359 {ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ}\r
360 Procedure PalPlay;\r
361   { This procedure mucks about with our "virtual pallette", then shoves it\r
362     to screen. }\r
363 Var Tmp : Array[1..3] of Byte;\r
364   { This is used as a "temporary color" in our pallette }\r
365     loop1 : Integer;\r
366 BEGIN\r
367    Move(Pall[1],Tmp,3);\r
368      { This copies color 1 from our virtual pallette to the Tmp variable }\r
369    Move(Pall[2],Pall[1],18*3);\r
370      { This moves the entire virtual pallette down one color }\r
371    Move(Tmp,Pall[18],3);\r
372      { This copies the Tmp variable to no. 18 of the virtual pallette }\r
373    WaitRetrace;\r
374    For loop1:=1 to 18 do\r
375      pal (loop1,pall[loop1,1],pall[loop1,2],pall[loop1,3]);\r
376 END;\r
377 \r
378 \r
379 BEGIN\r
380   ClrScr;\r
381   writeln ('Hi there! This program will demonstrate the usefullness of ');\r
382   writeln ('pregenerated arrays, also known as lookup tables. The program');\r
383   writeln ('will first draw a spiral without using a lookup table, rotate');\r
384   writeln ('the pallette until a key is pressed, the calculate the lookup');\r
385   writeln ('table, then draw the same spiral using the lookup table.');\r
386   writeln;\r
387   writeln ('This is merely one example for the wide range of uses of a ');\r
388   writeln ('lookup table.');\r
389   writeln;\r
390   writeln;\r
391   Write ('  Hit any key to contine ...');\r
392   Readkey;\r
393   setmcga;\r
394   directvideo:=FALSE;  { This handy trick allows you to use GOTOXY and }\r
395                        { Writeln in GFX mode. Hit CTRL-F1 on it for more }\r
396                        { info/help }\r
397   For Loop1 := 1 to 18 do BEGIN\r
398     Pall[Loop1,1] := (Loop1*3)+9;\r
399     Pall[Loop1,2] := 0;\r
400     Pall[Loop1,3] := 0;\r
401   END;\r
402        { This sets colors 1 to 18 to values between 12 to 63. }\r
403 \r
404    WaitRetrace;\r
405    For loop1:=1 to 18 do\r
406      pal (loop1,pall[loop1,1],pall[loop1,2],pall[loop1,3]);\r
407         { This sets the true pallette to variable Pall }\r
408 \r
409   normcirc;         { This draws a spiral without lookups }\r
410   Repeat\r
411     PalPlay;\r
412   Until keypressed;\r
413   readkey;\r
414   lookupcirc;       { This draws a spiral with lookups }\r
415   Repeat\r
416     PalPlay;\r
417   Until keypressed;\r
418   Readkey;\r
419 \r
420   SetText;\r
421   Writeln ('All done. This concludes the sixth sample program in the ASPHYXIA');\r
422   Writeln ('Training series. You may reach DENTHOR under the name of GRANT');\r
423   Writeln ('SMITH on the MailBox BBS, or leave a message to ASPHYXIA on the');\r
424   Writeln ('ASPHYXIA BBS. I am also an avid Connectix BBS user.');\r
425   Writeln ('Get the numbers from Roblist, or write to :');\r
426   Writeln ('             Grant Smith');\r
427   Writeln ('             P.O. Box 270');\r
428   Writeln ('             Kloof');\r
429   Writeln ('             3640');\r
430   Writeln ('I hope to hear from you soon!');\r
431   Writeln; Writeln;\r
432   Write   ('Hit any key to exit ...');\r
433   Readkey;\r
434 END.\r