1 ÕÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͸
\r
3 ³ To the VGA Trainer Program ³ ³
\r
5 ³ DENTHOR of ASPHYXIA ³ ³ ³
\r
6 ÔÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ; ³ ³
\r
7 ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ³
\r
8 ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
\r
14 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
\r
17 Wow! The trainer has finally reached part 10! This will also be the
\r
18 first part introduced simultaneously to local BBS's and the INTERNET at
\r
19 the same time! Yes folks, I put up a copy of previous tutorials onto
\r
20 various ftp sites, and awaited the flames saying that the net.gurus
\r
21 already knew this stuff, and why was I wasting disk space! The flames
\r
22 did not appear (well, except for one), and I got some messages saying
\r
23 keep it up, so from now on I will upload all future trainers to ftp
\r
24 sites too (wasp.eng.ufl.edu , cs.uwp.edu etc.). I will also leave a
\r
25 notice in the USENET groups comp.lang.pascal and comp.sys.ibm.pc.demos
\r
26 when a new part is finished (Until enough people say stop ;-))
\r
28 I can also be reached at my new E-Mail address,
\r
29 smith9@batis.bis.und.ac.za
\r
31 Well, this tutorial is on Chain-4. When asked to do a trainer on
\r
32 Chain-4, I felt that I would be walking on much travelled ground (I have
\r
33 seen numerous trainers on the subject), but the people who asked me said
\r
34 that they hadn't seen any, so could I do one anyway? Who am I to say no?
\r
36 The sample program attached isn't that great, but I am sure that all you
\r
37 people out there can immediately see the potential that Chain-4 holds.
\r
40 If you would like to contact me, or the team, there are many ways you
\r
41 can do it : 1) Write a message to Grant Smith/Denthor/Asphyxia in private mail
\r
42 on the ASPHYXIA BBS.
\r
43 2) Write to Denthor, EzE or Goth on Connectix.
\r
44 3) Write to : Grant Smith
\r
49 4) Call me (Grant Smith) at (031) 73 2129 (leave a message if you
\r
50 call during varsity). Call +27-31-73-2129 if you call
\r
51 from outside South Africa. (It's YOUR phone bill ;-))
\r
52 5) Write to smith9@batis.bis.und.ac.za in E-Mail.
\r
54 NB : If you are a representative of a company or BBS, and want ASPHYXIA
\r
55 to do you a demo, leave mail to me; we can discuss it.
\r
56 NNB : If you have done/attempted a demo, SEND IT TO ME! We are feeling
\r
57 quite lonely and want to meet/help out/exchange code with other demo
\r
58 groups. What do you have to lose? Leave a message here and we can work
\r
59 out how to transfer it. We really want to hear from you!
\r
63 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
\r
66 You people out there all have at least 256k vga cards. Most of you have
\r
67 512k vga cards, and some have 1MB vga cards. But what you see on your
\r
68 screen, as discussed in previous trainers, is 64k of data! What happened
\r
69 to the other 192k??? Chain-4 is a method of using all 256k at one time.
\r
71 The way this is done is simple. 1 screen = 64k. 64k * 4 = 256k.
\r
72 Therefore, chain-4 allows you to write to four screens, while displaying
\r
73 one of them. You can then move around these four screens to see the data
\r
74 on them. Think of the Chain-4 screen as a big canvas. The viewport,
\r
75 the bit you see out of, is a smaller rectangle which can be anywhere
\r
76 over the bigger canvas.
\r
78 +----------------------------+ Chain-4 screen
\r
83 +----------------------------+
\r
86 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
\r
87 þ The size of the chain-4 screen
\r
89 The Chain-4 screen, can be any size that adds up to 4 screens.
\r
91 For example, it can be 4 screens across and one screen down, or one
\r
92 screen across and 4 screens down, or two screens across and two screens
\r
93 down, and any size in between.
\r
95 In the sample program, the size is a constant. The size * 8 is how many
\r
96 pixels across there are on the chain-4 screen, ie
\r
97 Size = 40 = 320 pixels across = 1 screen across, 4 screens down
\r
98 Size = 80 = 640 pixels across = 2 screens across, 2 screens down
\r
101 We need to know the size of the screen for almost all dealings with the
\r
102 Chain-4 screen, for obvious reasons.
\r
105 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
\r
106 þ Layout of the chain-4 screen, and accessing it
\r
108 If you will remember all the way back to Part 1 of this series, I
\r
109 explained that the memory layout of the MCGA screen is linear. Ie, the
\r
110 top left hand pixel was pixel zero, the one to the right of it was
\r
111 number one, the next one was number two etc. With Chain-4, things are
\r
114 Chain-4 gets the 4 screens and chains them together (hence the name :)).
\r
115 Each screen has a different plane value, and must be accessed
\r
116 differently. The reason for this is that a segment of memory is only 64k
\r
117 big, so that we could not fit the entire Chain-4 screen into one
\r
120 All Chain-4 screens are accessed from $a000, just like in MCGA mode.
\r
121 What we do is, before we write to the screen, find out what plane we are
\r
122 writing to, set that plane, then plot the pixel. Here is how we find out
\r
123 how far in to plot the pixel and what plane it is on :
\r
125 Instead of the linear model of MCGA mode, ie :
\r
126 ÚÄÄÂÄÄÂÄÄÂÄÄÂÄÄÂÄÄÂÄÄÂÄÄÂÄÄÂÄÄÂÄÄÂÄÄ¿
\r
127 ³00³01³02³03³04³05³06³07³08³09³10³11³ ...
\r
129 Each plane of the Chain-4 screen accesses the memory in this way :
\r
132 ÚÄÄÂÄÄÂÄÄÂÄÄÂÄÄÂÄÄÂÄÄÂÄÄÂÄÄÂÄÄÂÄÄÂÄÄ¿
\r
133 ³00³ ³ ³ ³01³ ³ ³ ³02³ ³ ³ ³ ...
\r
136 ÚÄÄÂÄÄÂÄÄÂÄÄÂÄÄÂÄÄÂÄÄÂÄÄÂÄÄÂÄÄÂÄÄÂÄÄ¿
\r
137 ³ ³00³ ³ ³ ³01³ ³ ³ ³02³ ³ ³ ...
\r
140 ÚÄÄÂÄÄÂÄÄÂÄÄÂÄÄÂÄÄÂÄÄÂÄÄÂÄÄÂÄÄÂÄÄÂÄÄ¿
\r
141 ³ ³ ³00³ ³ ³ ³01³ ³ ³ ³02³ ³ ...
\r
144 ÚÄÄÂÄÄÂÄÄÂÄÄÂÄÄÂÄÄÂÄÄÂÄÄÂÄÄÂÄÄÂÄÄÂÄÄ¿
\r
145 ³ ³ ³ ³00³ ³ ³ ³01³ ³ ³ ³02³ ...
\r
147 In this way, by choosing the right plane to write to, we can access all
\r
148 of the 256k of memory available to us. The plane that we write to can
\r
149 easily be found by the simple calculation of x mod 4, and the x
\r
150 coordinate is also found by x div 4. We work out our y by multiplying
\r
151 it by the size of our chain-4 screen.
\r
153 NOTE : It is possible to write to all four planes at once by setting the
\r
154 correct port values.
\r
156 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
\r
159 The uses of Chain-4 are many. One could write data to one screen, then
\r
160 flip to it (the move_to command is almost instantaneous). This means
\r
161 that 64k of memory does not need to be set aside for a virtual screen,
\r
162 you are using the vga cards memory instead!
\r
164 Scrolling is much easier to code for in Chain-4 mode.
\r
166 It is possible to "tweak" the mode into other resolutions. In our demo,
\r
167 our vectors were in 320x240 mode, and our dot vectors were in 320x400
\r
170 The main disadvantage of chain-4 as I see it is the plane swapping,
\r
171 which can be slow. With a bit of clever coding however, these can be
\r
172 kept down to a minimum.
\r
174 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
\r
175 þ The sample programs
\r
177 The first sample program is GFX.PAS. This is a until in which I have
\r
178 placed most of our routines from previous tuts. All the procedures and
\r
179 variables you can see under the INTERFACE section can be used in any
\r
180 program with GFX in the USES clause. In other words, I could do this :
\r
190 This program would compile perfectly. What I suggest you do is this :
\r
191 Rename the file to a name that suites you (eg your group name), change
\r
192 the first line of the unit to that name, then add all useful procedures
\r
193 etc. to the unit. Make it grow :-).
\r
195 The second file is the sample program (note the USES GFX,crt; up near
\r
196 the top!). The program is easy to understand and is documented. The bit
\r
197 that I want to draw your attention to is the constant, BIT. Because I
\r
198 am distributing this file to many places in text form, not binary form,
\r
199 I could not just add a .CEL file with the program. So what I did was
\r
200 write some text in one color then saved it as a .CEL . I then wrote a
\r
201 ten line program that did the following : Moving from left to right, it
\r
202 counted how many pixels were of color zero, then saved the byte value to
\r
203 an array. When it came across color one, is counted for how long that
\r
204 went on then saved the byte value and saved it to an array and so on.
\r
205 When it was finished, I converted the array into a text file in the
\r
206 CONST format. Not too cunning, but I thought I had better explain it ;-)
\r
208 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
\r
211 There are other documents and sample programs available on Chain-4 and
\r
212 it's like : Try XLIB for one...
\r
214 Finally! Some BBS's have joined my BBS list! (Okay, only two new ones,
\r
215 but it's a start ;-)) All you international BBS's! If you will regularly
\r
216 download the tuts from an FTP site, give me your names!
\r
218 I own a car. The car's name is Bob. A few days ago, Bob was in an
\r
219 accident, and now has major damage to his front. Knowing insurance, I
\r
220 probably won't get much, probably nothing (the other guy wasn't insured,
\r
221 and I am only 18 :( ). I will probably have to find work in order to pay
\r
222 for my repairs. The point to this meandering is this : I am upset, so if
\r
223 you think you are getting a quote, you can just forget it.
\r
225 Oh, well. Life goes on!
\r
230 These fine BBS's carry the ASPHYXIA DEMO TRAINER SERIES : (alphabetical)
\r
232 ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍËÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍËÍÍÍÍÍËÍÍÍËÍÍÍÍËÍÍÍÍ»
\r
233 ºBBS Name ºTelephone No. ºOpen ºMsgºFileºPastº
\r
234 ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÎÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÎÍÍÍÍÍÎÍÍÍÎÍÍÍÍÎÍÍÍ͹
\r
235 ºASPHYXIA BBS #1 º(031) 765-5312 ºALL º * º * º * º
\r
236 ºASPHYXIA BBS #2 º(031) 765-6293 ºALL º * º * º * º
\r
237 ºConnectix BBS º(031) 266-9992 ºALL º º * º * º
\r
238 ºPOP! º(012) 661-1257 ºALL º º * º * º
\r
239 ºPure Surf BBS º(031) 561-5943 ºA/H º º * º * º
\r
240 ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÊÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÊÍÍÍÍÍÊÍÍÍÊÍÍÍÍÊÍÍÍͼ
\r
242 For international users : If you live outside the Republic of South
\r
243 Africa, do the following : Dial +27, dont dial the first 0, but dial
\r
244 the rest of the number. Eg, for the ASPHYXIA BBS : +27-31-765-5312
\r
246 Open = Open at all times or only A/H
\r
247 Msg = Available in message base
\r
248 File = Available in file base
\r
249 Past = Previous Parts available
\r
252 ÚÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
\r
257 Well folks, here it is - the long awaited for Chain-4 trainer. The
\r
258 routines are commented so I'm not going to say too much more here,
\r
259 except a few things.
\r
261 1: If ya don't understand this (not suprising its bloody cryptic!)
\r
262 then if ur serious go out and buy - Programming the EGA & VGA Cards
\r
263 I don't know who the book is by, so don't ask. Perhaps you know Greg?
\r
265 2: The code is unoptimised. I wrote it specifically for this conf. and
\r
266 I'm buggered if I'm gonna give out my wholely (sp? ahh stuff it :-))
\r
267 optimised code. If you want it faster, OPTIMISE IT!!
\r
268 HINT: Its faster to load ax, with a low byte/high byte combination
\r
269 and out a word instead of a byte at a time. If u don't know
\r
270 what I'm talking about, too bad :-)
\r
272 3: If you use/like/whatever this code, please give Asphyxia a mention.
\r
273 It wos bloody hard work figuring out how all this cr*p works, we
\r
274 couldn't have done it with out a little guidence (thanx Gregie Poo).
\r
276 4: LiveWire got interested in the whole tut/trainer idea and MAY be
\r
277 putting together a doc on how the whole thing works, including
\r
278 Pel-Panning which I haven't included here.
\r
281 5: Good luck with the code, and if you write anything with it, I'd
\r
282 appreciate having a look at it :-). Feel free to direct any comments
\r
283 about the code to me in this conf. Or at one of the contact addresses
\r
292 --------------------------------=[ Cut Here ]=-------------------------
\r
295 Program Chain4_Tut;
\r
304 Var Loop : Integer;
\r
308 Procedure Init_C4; Assembler;
\r
311 int 10h { set up bios initially for 13h }
\r
313 mov dx, 03c4h { Sequencer Address Register }
\r
314 mov al, 4 { Index 4 - Memory mode }
\r
315 out dx, al { select it. }
\r
316 inc dx { 03c5h - here we set the mem mode. }
\r
317 in al, dx { get whats already inside the reg }
\r
318 and al, 11110111b { un-set 4th bit - chain4 }
\r
322 mov al, 13h { Offset Register - allocates amt. mem for }
\r
323 out dx, al { 1 displayable line as - length div 8, so }
\r
324 inc dx { we use 80 (80*8) = 640 = 2 pages across }
\r
325 mov al, [Size] { and cause of chain-4 i.e. 256k display }
\r
326 out dx, al { mem, 2 pages down for four pages }
\r
328 { NOTE: setting AL above to 40 selects 1 }
\r
329 { page across and four down (nice for }
\r
330 { 1942 type scrolling games) and setting }
\r
331 { AL to 160 selects 4 pages across and 1 }
\r
332 { down, nice for horizontal scrolling }
\r
338 Procedure Cls_C4; Assembler;
\r
340 mov dx, 03c4h { 03c4h }
\r
341 mov al, 2 { Map Mask Register }
\r
344 mov al, 00001111b { Select all planes to write to }
\r
345 out dx, al { Doing this to clear all planes at once }
\r
349 xor di, di { set es:di = Screen Mem }
\r
350 mov ax, 0000h { colour to put = black }
\r
351 mov cx, 32768 { 32768 (words) *2 = 65536 bytes - vga mem }
\r
353 rep stosw { clear it }
\r
358 Procedure PutPixel_C4(X, Y : Integer; Col : Byte); Assembler;
\r
360 mov ax, [Y] { Y val multiplied by... }
\r
362 mov bl, [Size] { Size.... }
\r
363 shl bx, 1 { *2 - just 'cause! (I can't remember why!)}
\r
370 add bx, ax { add X val div 4 (four planes) }
\r
372 and cx, 00000011b { clever way of finding x mod 4, i.e. }
\r
373 mov dx, 03c4h { which plane we're in. }
\r
374 mov al, 2 { then use 03c4h index 2 - write plane sel.}
\r
375 out dx, al { to set plane to write to. }
\r
376 mov al, 1 { plane to write to = 1 shl (X mod 4) }
\r
384 mov es: [bx], al { then write pixel. }
\r
388 Function GetPixel_C4(X, Y : Integer): Byte; Assembler;
\r
390 mov ax, [Y] { Y val multiplied by... }
\r
392 mov bl, [Size] { Size.... }
\r
393 shl bx, 1 { *2 - just 'cause! (I can't remember why!)}
\r
400 add bx, ax { add X val div 4 (four planes) }
\r
402 and cx, 00000011b { clever way of finding x mod 4, i.e. }
\r
403 mov dx, 03c4h { which plane we're in. }
\r
404 mov al, 4h { then use 03c4h index 4 - read plane sel. }
\r
405 out dx, al { to set plane to read from. }
\r
406 mov al, cl { Plane to read from = X mod 4 }
\r
412 mov al, es: [bx] { then return pixel read }
\r
417 Procedure MoveScr_C4(X,Y : Integer); Assembler;
\r
419 mov ax, [Y] { Y val multiplied by... }
\r
421 mov bl, [Size] { Size.... }
\r
422 shl bx, 1 { *2 - just 'cause! (I can't remember why!)}
\r
426 add bx, [X] { Add X val }
\r
429 mov al, 0ch { CRTC address reg. }
\r
430 out dx, al { Start Address High Reg. }
\r
432 mov al, bh { send high byte of start address. }
\r
436 mov al, 0dh { Start Address Low Reg. }
\r
439 mov al, bl { send low byte of start address. }
\r
445 Procedure SetText; Assembler;
\r
454 While KeyPressed do ReadKey;
\r
463 WriteLn('Chain-4 Trainer...');
\r
464 WriteLn('By EzE of Asphyxia.');
\r
466 WriteLn('Contact Us on ...');
\r
469 WriteLn('the Asphyxia BBS (031) - 7655312');
\r
471 WriteLn('Email : eze@');
\r
472 WriteLn(' asphyxia@');
\r
473 WriteLn(' edwards@');
\r
474 WriteLn(' bailey@');
\r
475 WriteLn(' mcphail@');
\r
476 WriteLn(' beastie.cs.und.ac.za');
\r
478 WriteLn('or peter.edwards@datavert.co.za');
\r
480 WriteLn('Write me snail-mail at...');
\r
481 WriteLn('P.O. Box 2313');
\r
482 WriteLn('Hillcrest');
\r
501 Putpixel_C4(Random(320),Random(200),Random(256)+1);
\r
503 For Loop := 0 to 80 do
\r
505 MoveScr_C4(0,Loop);
\r
509 Loop := GetPixel_C4(100,100);
\r
511 WriteLn('Colour at location X:100, Y:100 was: ',Loop);
\r
514 --------------------------------=[ Cut Here ]=-------------------------
\r