]> 4ch.mooo.com Git - 16.git/blob - 16/PCGPE10/TUT5.TXT
reverted my open watcom to 1.9 an recompiled everything~
[16.git] / 16 / PCGPE10 / TUT5.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 5 ]==--\r
12 \r
13 \r
14 \r
15 þ Introduction\r
16 \r
17 Hello! This is Denthor here with the 5 part of the ASPHYXIA VGA Trainer\r
18 Series : The Scrolling Saga. I have had many requests for information on\r
19 scrolling, so I decided to make it this weeks topic. Note that I do make\r
20 reference to my recently released program TEXTER5, which should be available\r
21 from wherever you get this message. (Note to Sysops : If you put the trainer\r
22 series up on your boards, please add WORMIE.ZIP and TEXTER5.ZIP as they\r
23 both suppliment this series)\r
24 \r
25 By the way, sorry for the delay in the appearance of this part. Tests,\r
26 projects and a few wild days of sin at the Wild Coast all conspired\r
27 against the prompt appearance of this part. Also note I need more input as\r
28 to what I should do future parts on, so leave me mail.\r
29 \r
30 If you would like to contact me, or the team, there are many ways you\r
31 can do it : 1) Write a message to Grant Smith in private mail here on\r
32                   the Mailbox BBS.\r
33             2) Write a message here in the Programming conference here\r
34                   on the Mailbox (Preferred if you have a general\r
35                   programming query or problem others would benefit from)\r
36             3) Write to ASPHYXIA on the ASPHYXIA BBS.\r
37             4) Write to Denthor, Eze or Livewire on Connectix.\r
38             5) Write to :  Grant Smith\r
39                            P.O.Box 270 Kloof\r
40                            3640\r
41                            Natal\r
42             6) Call me (Grant Smith) at 73 2129 (leave a message if you\r
43                   call during varsity)\r
44 \r
45 NB : If you are a representative of a company or BBS, and want ASPHYXIA\r
46        to do you a demo, leave mail to me; we can discuss it.\r
47 NNB : If you have done/attempted a demo, SEND IT TO ME! We are feeling\r
48         quite lonely and want to meet/help out/exchange code with other demo\r
49         groups. What do you have to lose? Leave a message here and we can work\r
50         out how to transfer it. We really want to hear from you!\r
51 \r
52 \r
53 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
54 þ  What is scrolling?\r
55 \r
56 If you have ever seen a demo, you have probably seen some form of scrolling.\r
57 Our SILKYDEMO has quite a nice example of scrolling. What it is is a long\r
58 row of text moving across your screen, usually from right to left, eg :\r
59 \r
60                                        H     : Step 1\r
61                                       He     : Step 2\r
62                                      Hel     : Step 3\r
63                                     Hell     : Step 4\r
64                                    Hello     : Step 5\r
65                                   Hello      : Step 6\r
66 \r
67 etc. etc. See the program attatched for an example of scrolling.\r
68 \r
69 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
70 þ  What do we scroll?\r
71 \r
72 Usually, letters. Most groups put greetings and information in their\r
73 'scrollies', as they are termed. You can also scroll and entire screen\r
74 using the scrolling technique. Scrolling your text is a hell of a lot\r
75 less boring then just having it appear on your screen. Unfortunately,\r
76 'scrollies' have been used so many times in demos they are wearing a\r
77 bit thin, so usually they are accompanied by a cool picture or some nice\r
78 routine happening at the same time (In our SILKYDEMO we had a moving\r
79 checkerboard and colour bars going at the same time).\r
80 \r
81 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
82 þ  How do we scroll from side to side?\r
83 \r
84 The theory behind scrolling is quite easy. Let us imagine that we are\r
85 scrolling a 16x16 font grabbed by TEXTER (;-)) across the top of the\r
86 screen (ie. 320 pixels) As we know, the VGA screen starts at zero at the\r
87 top left hand part of the screen, then counts up to the right to 319, then\r
88 goes back to the left hand side one pixel down at 320. (See Tut 1) This means\r
89 that a 16*320 scroller takes up the space 0 to 5119 on the screen. In ascii\r
90 this looks like this :\r
91 \r
92             (0)   .                                    .  (319)\r
93             (320) .                                    .  (639)\r
94                             "             "           "\r
95            (4800) .                                    .   (5119)\r
96 \r
97 Simple enough. Now what we do is we put down the first Y-line of the first\r
98 character onto the very right hand side of the screen , like so :\r
99 \r
100               For loop1:=1 to 16 do\r
101                 Putpixel (319,loop1-1,font['A',1,loop1],vga);\r
102 \r
103 This will draw some stuff on the very right hand side. Your screen should now\r
104 look like this :\r
105 \r
106             (0)   .                                   X.  (319)\r
107             (320) .                                   X.  (639)\r
108                             "             "           "\r
109            (4800) .                                   X.   (5119)\r
110 \r
111 Next, we move each line one to the left, ie :\r
112 \r
113               For loop1:=0 to 15 do\r
114                 Move (mem[VGA:loop1*320+1],mem[VGA:loop1*320],320);\r
115 \r
116 This scrolls the screen from right to left, which is the easiest to read.\r
117 To scroll the screen from left to right, swap the +1 onto the other side\r
118 of the command. Also, to increase the size of the portion scrolled, increase\r
119 the 15 to however many lines from the top you wish to scroll-1.\r
120 \r
121 After this move, your screen will look like this :\r
122 \r
123             (0)   .                                  X .  (319)\r
124             (320) .                                  X .  (639)\r
125                             "             "           "\r
126            (4800) .                                  X .   (5119)\r
127                                                       ^\r
128                                                 Note this space\r
129 \r
130 \r
131 What you then do is draw in the next line on the right hand side, move it,\r
132 draw the next line, move it etc. etc. Tah-Dah! You have a scrolly! Fairly\r
133 simple, isn't it?\r
134 \r
135 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
136 þ  How do we scroll up or down?\r
137 \r
138 To scroll up or down is also fairly simple. This can be used for 'movie\r
139 credit' endings (I once wrote a little game with a desert scrolling down\r
140 with you being a little robot on the bottom of the screen). The theory is\r
141 this : Draw the top line (or bottom line) then move the entire screen :\r
142 \r
143              Move (mem[vga:0],mem[vga:320],63680);\r
144                        { 64000 - 320 = 63680 }\r
145 \r
146 For scrolling down, or :\r
147 \r
148              Move (mem[vga:320],mem[vga:0],63680);\r
149 \r
150 For scrolling up. You then draw the next line and repeat.\r
151 \r
152 Because of the simplicity of coding in a scrolly, most demos have one. It\r
153 is usually best to have something extra happening on the screen so that\r
154 the viewer doesn't get too bored, even, as I say, if it is only a really nice\r
155 picture.\r
156 \r
157 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
158 þ  In closing\r
159 \r
160 The University of Natal, Durban, Science Dept., now has 10 new 486's!\r
161 This is a great boon, as now I can program nice routines during frees\r
162 (even though I am a Commerce Student (Shhhhh) ;-) ). I can now use those\r
163 previously wasted hours that I spent socialising and making friends\r
164 coding instead ;-)\r
165 \r
166 I suggest you get a copy of TEXTER, for coding demos with fonts, or in fact\r
167 almost any graphics application, it is an amazing help, and we have used it\r
168 for *ALL* our demos. (P.S. We have written many demos, but many have been\r
169 written for companies and have not been released for the general public)\r
170 NOTE : For TEXTER's test program TEST.PAS, add {$X+} {$R-} if you have range\r
171 checking on (I code with it off.)\r
172 \r
173             [  "I'm from the Computer Inspection Agency, sir,\r
174                    I'm here to check your computer. Here is\r
175                    my identification."\r
176                "Certainly. Have a look, I'm clean. I don't have\r
177                    any pirated software."\r
178                The C-man pushes past him and sits in front of the\r
179                    computer. He notes the fact that the computer\r
180                    is currently off with a look of disdain. He\r
181                    makes a note on his clipboard. He boots up.\r
182                "What is this?" he asks, pointing at the screen.\r
183                "It's MasterMenu" stutters the man. "I wrote it\r
184                    myself!"\r
185                "Do you know what the penalty is for using junk\r
186                    like this on a private machine?" The C-man smiles.\r
187                    "This is a two-month sentance in itself!"\r
188                "I'm sorry sir! It won't happen again!"\r
189                "I know. I'll make sure of that." He smiles again.\r
190                The C-man runs through the hard drive, checking for\r
191                    illeagal software, bad programs and anti-government\r
192                    propaganda. He notes with satisfaction that he has\r
193                    enough to put this weenie away for ten years, not that\r
194                    it mattered. He usually could just make something up.\r
195                He comes to the last entry on the aphebetised menu tree.\r
196                    His hands jerk away from the keyboard. Then, tentatively,\r
197                    he types in the three letters of doom. He looks at the\r
198                    man, who is backing away with wide eyes and his hands\r
199                    outstretched in front of him, as if to ward off a blow.\r
200                The C-man smiles, his lips a thin, hard line.\r
201                "Windows!"\r
202                                                                      ]\r
203                                                            - Grant Smith\r
204                                                                1:55pm\r
205                                                                  16/9/93\r
206 \r
207 Cheers,\r
208   - Denthor\r
209 \r
210 ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ\r
211 ³ TUTPROG5.PAS ³\r
212 ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ\r
213 \r
214 {$X+} {$R-}\r
215 Uses Crt;\r
216 \r
217 CONST VGA = $a000;\r
218       XSize = 16;\r
219       YSize = 16;\r
220 \r
221 TYPE\r
222         Letter = Array[1..xsize,1..ysize] of Byte;\r
223         Letters = Array[' '..']'] of Letter;\r
224 \r
225 VAR Font : ^Letters;\r
226 \r
227 {ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ}\r
228 Procedure SetMCGA;  { This procedure gets you into 320x200x256 mode. }\r
229 BEGIN\r
230   asm\r
231      mov        ax,0013h\r
232      int        10h\r
233   end;\r
234 END;\r
235 \r
236 \r
237 {ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ}\r
238 Procedure SetText;  { This procedure returns you to text mode.  }\r
239 BEGIN\r
240   asm\r
241      mov        ax,0003h\r
242      int        10h\r
243   end;\r
244 END;\r
245 \r
246 {ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ}\r
247 procedure WaitRetrace; assembler;\r
248   { This waits until you are in a Verticle Retrace }\r
249 \r
250 label\r
251   l1, l2;\r
252 asm\r
253     mov dx,3DAh\r
254 l1:\r
255     in al,dx\r
256     and al,08h\r
257     jnz l1\r
258 l2:\r
259     in al,dx\r
260     and al,08h\r
261     jz  l2\r
262 end;\r
263 \r
264 {ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ}\r
265 Procedure Pal(ColorNo : Byte; R,G,B : Byte);\r
266   { This sets the Red, Green and Blue values of a certain color }\r
267 Begin\r
268    Port[$3c8] := ColorNo;\r
269    Port[$3c9] := R;\r
270    Port[$3c9] := G;\r
271    Port[$3c9] := B;\r
272 End;\r
273 \r
274 \r
275 {ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ}\r
276 Procedure PutPixel (X,Y : Integer; Col : Byte; Where : Word);\r
277    { This puts a pixel at X,Y using color col, on VGA or the Virtual Screen}\r
278 BEGIN\r
279   Mem [Where:X+(Y*320)]:=col;\r
280 END;\r
281 \r
282 {ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ}\r
283 procedure LoadPal (FileName : string);\r
284    { This loads the Pallette file and puts it on screen }\r
285 type DACType = array [0..255] of record\r
286                                 R, G, B : byte;\r
287                               end;\r
288 var DAC : DACType;\r
289     Fil : file of DACType;\r
290     I : integer;\r
291 BEGIN\r
292   assign (Fil, FileName);\r
293   reset (Fil);\r
294   read (Fil, DAC);\r
295   close (Fil);\r
296   for I := 0 to 255 do Pal(I,Dac[I].R,Dac[I].G,Dac[I].B);\r
297 end;\r
298 \r
299 {ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ}\r
300 function Exist(FileName: string): Boolean;\r
301     { Checks to see if filename exits or not }\r
302 var f: file;\r
303 begin\r
304   {$I-}\r
305   Assign(f, FileName);\r
306   Reset(f);\r
307   Close(f);\r
308   {$I+}\r
309   Exist := (IOResult = 0) and\r
310    (FileName <> '');\r
311 end;\r
312 \r
313 \r
314 {ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ}\r
315 Procedure Setup;\r
316   { This loads the font and the pallette }\r
317 VAR f:file;\r
318     loop1:char;\r
319     loop2,loop3:integer;\r
320 BEGIN\r
321   getmem (font,sizeof (font^));\r
322   If exist ('softrock.fnt') then BEGIN\r
323     Assign (f,'softrock.fnt');\r
324     reset (f,1);\r
325     blockread (f,font^,sizeof (font^));\r
326     close (f);\r
327     Writeln ('SoftRock.FNT from TEXTER5 found in current directory. Using.');\r
328   END\r
329   ELSE BEGIN\r
330     Writeln ('SoftRock.FNT from TEXTER5 not found in current directory.');\r
331     For loop1:=' ' to ']' do\r
332       For loop2:=1 to 16 do\r
333         for loop3:=1 to 16 do\r
334           font^[loop1,loop2,loop3]:=loop2;\r
335   END;\r
336   If exist ('pallette.col') then\r
337     Writeln ('Pallette.COL from TEXTER5 found in current directory. Using.')\r
338   ELSE\r
339     Writeln ('Pallette.COL from TEXTER5 not found in current directory.');\r
340   Writeln;\r
341   Writeln;\r
342   Write ('Hit any key to continue ...');\r
343   readkey;\r
344   setmcga;\r
345   If exist ('pallette.col') then loadpal ('pallette.col');\r
346 END;\r
347 \r
348 \r
349 {ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ}\r
350 Procedure ScrollMsg (Msg : String);\r
351   { This scrolls the string in MSG across the screen }\r
352 Var Loop1,loop2,loop3 : Integer;\r
353 Begin\r
354   For loop1:=1 to length (msg) do BEGIN\r
355     For loop2:=1 to xsize do BEGIN\r
356 \r
357       { This bit scrolls the screen by one then puts in the new row of\r
358         letters }\r
359 \r
360       waitretrace;\r
361       For Loop3 := 100 to 99+ysize do\r
362         move (mem[vga:1+(loop3*320)],mem[vga:(loop3*320)],319);\r
363       for loop3:=100 to 99+ysize do\r
364         putpixel (319,loop3,font^[msg[loop1],loop2,loop3-99],vga);\r
365            { Change the -99 above to the minimum of loop3-1, which you\r
366              will change in order to move the position of the scrolly }\r
367     END;\r
368 \r
369     {This next bit scrolls by one pixel after each letter so that there\r
370       are gaps between the letters }\r
371 \r
372     waitretrace;\r
373     For Loop3 := 100 to 99+ysize do\r
374       move (mem[vga:1+(loop3*320)],mem[vga:(loop3*320)],319);\r
375       for loop3:=100 to 99+ysize do\r
376         putpixel (319,loop3,0,vga);\r
377   END;\r
378 End;\r
379 \r
380 \r
381 BEGIN\r
382   ClrScr;\r
383   Writeln ('This program will give you an example of a scrolly. If the file');\r
384   Writeln ('SOFTROCK.FNT is in the current directory, this program will scroll');\r
385   Writeln ('letters, otherwise it will only scroll bars. It also searches for');\r
386   Writeln ('PALLETTE.COL, which it uses for it''s pallette. Both SOFTROCK.FNT');\r
387   Writeln ('and PALLETTE.COL come with TEXTER5.ZIP, at a BBS near you.');\r
388   Writeln;\r
389   Writeln ('You will note that you can change what the scrolly says merely by');\r
390   Writeln ('changing the string in the program.');\r
391   Writeln;\r
392   Setup;\r
393   repeat\r
394     ScrollMsg ('ASPHYXIA RULZ!!!   ');\r
395   until keypressed;\r
396   Settext;\r
397   freemem (font, sizeof (font^));\r
398   Writeln ('All done. This concludes the fifth sample program in the ASPHYXIA');\r
399   Writeln ('Training series. You may reach DENTHOR under the name of GRANT');\r
400   Writeln ('SMITH on the MailBox BBS, or leave a message to ASPHYXIA on the');\r
401   Writeln ('ASPHYXIA BBS. Get the numbers from Roblist, or write to :');\r
402   Writeln ('             Grant Smith');\r
403   Writeln ('             P.O. Box 270');\r
404   Writeln ('             Kloof');\r
405   Writeln ('             3640');\r
406   Writeln ('I hope to hear from you soon!');\r
407   Writeln; Writeln;\r
408   Write   ('Hit any key to exit ...');\r
409   Readkey;\r
410 END.\r