1 ÕÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͸
\r
3 ³ To the VGA Trainer Program ³ ³
\r
5 ³ DENTHOR of ASPHYXIA ³ ³ ³
\r
6 ÔÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ; ³ ³
\r
7 ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ³
\r
8 ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
\r
18 Hi there! This is Denthor of ASPHYXIA, AKA Grant Smith. This training
\r
19 program is aimed at all those budding young demo coders out there. I am
\r
20 assuming that the reader is fairly young, has a bit of basic Std. 6 math
\r
21 under his belt, has done a bit of programming before, probably in BASIC,
\r
22 and wants to learn how to write a demo all of his/her own.
\r
24 This I what I am going to do. I am going to describe how certain routines
\r
25 work, and even give you working source code on how you do it. The source
\r
26 code will assume that you have a VGA card that can handle the
\r
27 320x200x256 mode. I will also assume that you have Turbo Pascal 6.0 or
\r
28 above (this is because some of the code will be in Assembly language,
\r
29 and Turbo Pascal 6.0 makes this incredibly easy to use). By the end of
\r
30 the first "run" of sections, you will be able to code some cool demo
\r
31 stuff all by yourself. The info you need, I will provide to you, but it
\r
32 will be you who decides on the most spectacular way to use it.
\r
34 Why not download some of our demos and see what I'm trying to head you
\r
37 I will be posting one part a week on the Mailbox BBS. I have the first
\r
38 "run" of sections worked out, but if you want me to also do sections on
\r
39 other areas of coding, leave a message to Grant Smith in private E-Mail,
\r
40 or start a conversation here in this conference. I will do a bit of
\r
41 moderating of a sort, and point out things that have been done wrong.
\r
43 In this, the first part, I will show you how you are supposed to set up
\r
44 your Pascal program, how to get into 320x200x256 graphics mode without a
\r
45 BGI file, and various methods of putpixels and a clearscreen utility.
\r
47 NOTE : I drop source code all through my explanations. You needn't try
\r
48 to grab all of it from all over the place, at the end of each part I
\r
49 add a little program that uses all the new routines that we have
\r
50 learned. If you do not fully understand a section, leave me
\r
51 private mail telling me what you don't understand or asking how I
\r
52 got something etc, and I will try to make myself clearer. One
\r
53 last thing : When you spot a mistake I have made in one of my
\r
54 parts, leave me mail and I will correct it post-haste.
\r
56 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
\r
61 Hi again, sorry that I have to add this, but here goes. All source code
\r
62 obtained from this series of instruction programs is used at your own
\r
63 risk. Denthor and the ASPHYXIA demo team hold no responsibility for any
\r
64 loss or damage suffered by anyone through the use of this code. Look
\r
65 guys, the code I'm going to give you has been used by us before in
\r
66 Demos, Applications etc, and we have never had any compliants of machine
\r
67 damage, but if something does go wrong with your computer, don't blame
\r
68 us. Sorry, but that's the way it is.
\r
71 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
\r
72 þ The MCGA mode and how you get into it in Pascal without a BGI
\r
75 Lets face it. BGI's are next to worthless for demo coding. It is
\r
76 difficult to find something that is slower then the BGI units for doing
\r
77 graphics. Another thing is, they wern't really meant for 256 color
\r
78 screens anyhow. You have to obtain a specific external 256VGA BGI to get
\r
79 into it in Pascal, and it just doesn't make the grade.
\r
81 So the question remains, how do we get into MCGA 320x200x256 mode in
\r
82 Pascal without a BGI? The answer is simple : Assembly language.
\r
83 Obviously assembly language has loads of functions to handle the VGA
\r
84 card, and this is just one of them. If you look in Norton Gides to
\r
85 Assembly Language, it says this ...
\r
87 ____________________________________________________________________
\r
88 INT 10h, 00h (0) Set Video Mode
\r
90 Sets the video mode.
\r
97 Registers destroyed: AX, SP, BP, SI, DI
\r
98 ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
\r
100 This is all well and good, but what does it mean? It means that if you
\r
101 plug in the video mode into AL and call interrupt 10h, SHAZAM! you are
\r
102 in the mode of your choice. Now, the MCGA video mode is mode 13h, and
\r
103 here is how we do it in Pascal.
\r
113 There you have it! One call to that procedure, and BANG you are in
\r
114 320x200x256 mode. We can't actually do anything in it yet, so to go back
\r
115 to text mode, you make the video mode equal to 03h, as seen below :
\r
126 BANG! We are back in text mode! Now, cry all your enquiring minds, what
\r
127 use is this? We can get into the mode, but how do we actually SHOW
\r
128 something on the screen? For that, you must move onto the next section
\r
131 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
\r
132 þ Clearing the screen to a specific color
\r
134 Now that we are in MCGA mode, how do we clear the screen. The answer is
\r
135 simple : you must just remember that the base adress of the screen is
\r
136 $a000. From $a000, the next 64000 bytes are what is actually displayed on
\r
137 the screen (Note : 320 * 200 = 64000). So to clear the screen, you just use
\r
138 the fillchar command (a basic Pascal command) like so :
\r
140 FillChar (Mem [$a000:0],64000,Col);
\r
142 What the mem command passes the Segment base and the Offset of a part of
\r
143 memory : in this case the screen base is the Segment, and we are starting
\r
144 at the top of the screen; Offset 0. The 64000 is the size of the screen
\r
145 (see above), and Col is a value between 0 and 255, which represents the
\r
146 color you want to clear the screen to.
\r
148 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
\r
149 þ Putting a pixel on the screen (two different methoods)
\r
151 If you look in Norton Guides about putting a pixel onto the screen, you
\r
155 ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
\r
156 Writes a pixel dot of a specified color at a specified screen
\r
161 CX Horizontal position of pixel
\r
162 DX Vertical position of pixel
\r
163 BH Display page number (graphics modes with more
\r
168 Registers destroyed: AX, SP, BP, SI, DI
\r
169 ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
\r
171 As seen from our SetMCGA example, you would write this by doing the following:
\r
173 Procedure INTPutpixel (X,Y : Integer; Col : Byte);
\r
185 The X would be the X-Coordinate, the Y would be the Y-Coordinate, and the Col
\r
186 would be the color of the pixel to place. Note that MCGA has 256 colors,
\r
187 numbered 0 to 255. The startoff pallette is pretty grotty, and I will show
\r
188 you how to alter it in my next lesson, but for now you will have to hunt for
\r
189 colors that fit in for what you want to do. Luckily, a byte is 0 to 255, so
\r
190 that is what we pass to the col variable. Have a look at the following.
\r
197 Therefore an EGA is a CGA squared, and a VGA is an EGA squared ;-)
\r
199 Anyway, back to reality. Even though the abouve procedure is written in
\r
200 assembly language, it is slooow. Why? I hear your enquiring minds cry. The
\r
201 reason is simple : It uses interrupts (It calls INT 10h). Interrupts are
\r
202 sloooow ... which is okay for getting into MCGA mode, but not for trying
\r
203 to put down a pixel lickety-split. So, why not try the following ...
\r
205 Procedure MEMPutpixel (X,Y : Integer; Col : Byte);
\r
207 Mem [VGA:X+(Y*320)]:=Col;
\r
211 The Mem command, as we have seen above, allows you to point at a certain
\r
212 point in memory ... the starting point is $a000, the base of the VGA's
\r
213 memory, and then we specify how far into this base memory we start.
\r
214 Think of the monitor this way. It starts in the top left hand corner at
\r
215 0. As you increase the number, you start to move across the screen to your
\r
216 right, until you reach 320. At 320, you have gone all the way across the
\r
217 screen and come back out the left side, one pixel down. This carries on
\r
218 until you reach 63999, at the bottom right hand side of the screen. This
\r
219 is how we get the equation X+(Y*320). For every increased Y, we must
\r
220 increment the number by 320. Once we are at the beginning of the Y line
\r
221 we want, we add our X by how far out we want to be. This gives us the
\r
222 exact point in memory that we want to be at, and then we set it equal to
\r
223 the pixel value we want.
\r
225 The MEM methood of putpixel is much faster, and it is shown in the sample
\r
226 program at the end of this lesson. The ASPHYXIA team uses neither putpixel;
\r
227 we use a DMA-Straight-To-Screen-Kill-Yer-Momma-With-An-Axe type putipixel
\r
228 which is FAST. We will give it out, but only to those of you who show us
\r
229 you are serious about coding. If you do do anything, upload it to me,
\r
230 I will be very interested to see it. Remember : If you do glean anything
\r
231 from these training sessions, give us a mention in your demos and UPLOAD
\r
234 Well, after this is the sample program; have fun with it, UNDERSTAND it,
\r
235 and next week I will start on fun with the pallette.
\r
241 ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
\r
246 {$X+} (* This is a handy little trick to know. If you put this at the top
\r
247 of your program, you do not have to set a variable when calling
\r
248 a function, i.e. you may just say 'READKEY' instead of
\r
251 USES Crt; (* This has a few nice functions in it, such as the
\r
252 READKEY command. *)
\r
254 CONST VGA = $a000; (* This sets the constant VGA to the segment of the
\r
257 {ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ}
\r
258 Procedure SetMCGA; { This procedure gets you into 320x200x256 mode. }
\r
267 {ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ}
\r
268 Procedure SetText; { This procedure returns you to text mode. }
\r
277 {ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ}
\r
278 Procedure Cls (Col : Byte);
\r
279 { This clears the screen to the specified color }
\r
281 Fillchar (Mem [$a000:0],64000,col);
\r
285 {ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ}
\r
286 Procedure INTPutpixel (X,Y : Integer; Col : Byte);
\r
287 { This puts a pixel on the screen using interrupts. }
\r
300 {ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ}
\r
301 Procedure TestINTPutpixel;
\r
302 { This tests out the speed of the INTPutpixel procedure. }
\r
303 VAR loop1,loop2 : Integer;
\r
305 For loop1:=0 to 319 do
\r
306 For loop2:=0 to 199 do
\r
307 INTPutpixel (loop1,loop2,Random (256));
\r
314 {ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ}
\r
315 Procedure MEMPutpixel (X,Y : Integer; Col : Byte);
\r
316 { This puts a pixel on the screen by writing directly to memory. }
\r
318 Mem [VGA:X+(Y*320)]:=Col;
\r
322 {ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ}
\r
323 Procedure TestMEMPutpixel;
\r
324 { This tests out the speed of the MEMPutpixel procedure. }
\r
325 VAR loop1,loop2 : Integer;
\r
327 For loop1:=0 to 319 do
\r
328 For loop2:=0 to 199 do
\r
329 MEMPutpixel (loop1,loop2,Random (256));
\r
336 {ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ}
\r
337 BEGIN (* Of the main program *)
\r
338 ClrScr; { This clears the text Screen (CRT unit) }
\r
339 Writeln ('What will happen is that I will clear the screen twice. After');
\r
340 Writeln ('each clear screen you will have to hit a key. I will then fill');
\r
341 Writeln ('the screen twice with randomlly colored pixels using two different');
\r
342 Writeln ('methoods, after each of which you will have to hit a key. I will');
\r
343 Writeln ('then return you to text mode.');
\r
345 Write ('Hit any kay to continue ...');
\r
357 Writeln ('All done. This concludes the first sample program in the ASPHYXIA');
\r
358 Writeln ('Training series. You may reach DENTHOR under the name of GRANT');
\r
359 Writeln ('SMITH on the MailBox BBS, or leave a message to ASPHYXIA on the');
\r
360 Writeln ('ASPHYXIA BBS. Get the numbers from Roblist, or write to :');
\r
361 Writeln (' Grant Smith');
\r
362 Writeln (' P.O. Box 270');
\r
363 Writeln (' Kloof');
\r
365 Writeln ('I hope to hear from you soon!');
\r
367 Write ('Hit any key to exit ...');
\r
369 END. (* Of the main program *)