home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / PCGPEV10.ZIP / TUT10.TXT < prev    next >
Text File  |  1994-05-05  |  19KB  |  515 lines

  1.                    ╒═══════════════════════════════╕
  2.                    │         W E L C O M E         │
  3.                    │  To the VGA Trainer Program   │ │
  4.                    │              By               │ │
  5.                    │      DENTHOR of ASPHYXIA      │ │ │
  6.                    ╘═══════════════════════════════╛ │ │
  7.                      ────────────────────────────────┘ │
  8.                        ────────────────────────────────┘
  9.  
  10.                            --==[ PART 10 ]==--
  11.  
  12.  
  13.  
  14. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  15. ■ Introduction
  16.  
  17. Wow! The trainer has finally reached part 10! This will also be the
  18. first part introduced simultaneously to local BBS's and the INTERNET at
  19. the same time! Yes folks, I put up a copy of previous tutorials onto
  20. various ftp sites, and awaited the flames saying that the net.gurus
  21. already knew this stuff, and why was I wasting disk space! The flames
  22. did not appear (well, except for one), and I got some messages saying
  23. keep it up, so from now on I will upload all future trainers to ftp
  24. sites too (wasp.eng.ufl.edu , cs.uwp.edu etc.). I will also leave a
  25. notice in the USENET groups comp.lang.pascal and comp.sys.ibm.pc.demos
  26. when a new part is finished (Until enough people say stop ;-))
  27.  
  28. I can also be reached at my new E-Mail address,
  29.                  smith9@batis.bis.und.ac.za
  30.  
  31. Well, this tutorial is on Chain-4. When asked to do a trainer on
  32. Chain-4, I felt that I would be walking on much travelled ground (I have
  33. seen numerous trainers on the subject), but the people who asked me said
  34. that they hadn't seen any, so could I do one anyway? Who am I to say no?
  35.  
  36. The sample program attached isn't that great, but I am sure that all you
  37. people out there can immediately see the potential that Chain-4 holds.
  38.  
  39.  
  40. If you would like to contact me, or the team, there are many ways you
  41. can do it : 1) Write a message to Grant Smith/Denthor/Asphyxia in private mail
  42.                   on the ASPHYXIA BBS.
  43.             2) Write to Denthor, EzE or Goth on Connectix.
  44.             3) Write to :  Grant Smith
  45.                            P.O.Box 270 Kloof
  46.                            3640
  47.                            Natal
  48.                            South Africa
  49.             4) Call me (Grant Smith) at (031) 73 2129 (leave a message if you
  50.                   call during varsity). Call +27-31-73-2129 if you call
  51.                   from outside South Africa. (It's YOUR phone bill ;-))
  52.             5) Write to smith9@batis.bis.und.ac.za in E-Mail.
  53.  
  54. NB : If you are a representative of a company or BBS, and want ASPHYXIA
  55.        to do you a demo, leave mail to me; we can discuss it.
  56. NNB : If you have done/attempted a demo, SEND IT TO ME! We are feeling
  57.         quite lonely and want to meet/help out/exchange code with other demo
  58.         groups. What do you have to lose? Leave a message here and we can work
  59.         out how to transfer it. We really want to hear from you!
  60.  
  61.  
  62.  
  63. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  64. ■ What is Chain-4?
  65.  
  66. You people out there all have at least 256k vga cards. Most of you have
  67. 512k vga cards, and some have 1MB vga cards. But what you see on your
  68. screen, as discussed in previous trainers, is 64k of data! What happened
  69. to the other 192k??? Chain-4 is a method of using all 256k at one time.
  70.  
  71. The way this is done is simple. 1 screen = 64k. 64k * 4 = 256k.
  72. Therefore, chain-4 allows you to write to four screens, while displaying
  73. one of them. You can then move around these four screens to see the data
  74. on them. Think of the Chain-4 screen as a big canvas. The viewport,
  75. the bit you see out of, is a smaller rectangle which can be anywhere
  76. over the bigger canvas.
  77.  
  78.      +----------------------------+ Chain-4 screen
  79.      |          +--+              |
  80.      |          |  | <- Viewport  |
  81.      |          +--+              |
  82.      |                            |
  83.      +----------------------------+
  84.  
  85.  
  86. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  87. ■ The size of the chain-4 screen
  88.  
  89. The Chain-4 screen, can be any size that adds up to 4 screens.
  90.  
  91. For example, it can be 4 screens across and one screen down, or one
  92. screen across and 4 screens down, or two screens across and two screens
  93. down, and any size in between.
  94.  
  95. In the sample program, the size is a constant. The size * 8 is how many
  96. pixels across there are on the chain-4 screen, ie
  97.    Size = 40   = 320 pixels across = 1 screen across, 4 screens down
  98.    Size = 80   = 640 pixels across = 2 screens across, 2 screens down
  99. etc.
  100.  
  101. We need to know the size of the screen for almost all dealings with the
  102. Chain-4 screen, for obvious reasons.
  103.  
  104.  
  105. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  106. ■ Layout of the chain-4 screen, and accessing it
  107.  
  108. If you will remember all the way back to Part 1 of this series, I
  109. explained that the memory layout of the MCGA screen is linear. Ie, the
  110. top left hand pixel was pixel zero, the one to the right of it was
  111. number one, the next one was number two etc. With Chain-4, things are
  112. very different.
  113.  
  114. Chain-4 gets the 4 screens and chains them together (hence the name :)).
  115. Each screen has a different plane value, and must be accessed
  116. differently. The reason for this is that a segment of memory is only 64k
  117. big, so that we could not fit the entire Chain-4 screen into one
  118. segment.
  119.  
  120. All Chain-4 screens are accessed from $a000, just like in MCGA mode.
  121. What we do is, before we write to the screen, find out what plane we are
  122. writing to, set that plane, then plot the pixel. Here is how we find out
  123. how far in to plot the pixel and what plane it is on :
  124.  
  125.  Instead of the linear model of MCGA mode, ie :
  126.         ┌──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┐
  127.         │00│01│02│03│04│05│06│07│08│09│10│11│ ...
  128.  
  129.  Each plane of the Chain-4 screen accesses the memory in this way :
  130.  
  131.        Plane 0 :
  132.         ┌──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┐
  133.         │00│  │  │  │01│  │  │  │02│  │  │  │ ...
  134.  
  135.        Plane 1 :
  136.         ┌──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┐
  137.         │  │00│  │  │  │01│  │  │  │02│  │  │ ...
  138.  
  139.        Plane 2 :
  140.         ┌──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┐
  141.         │  │  │00│  │  │  │01│  │  │  │02│  │ ...
  142.  
  143.        Plane 3 :
  144.         ┌──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┐
  145.         │  │  │  │00│  │  │  │01│  │  │  │02│ ...
  146.  
  147. In this way, by choosing the right plane to write to, we can access all
  148. of the 256k of memory available to us. The plane that we write to can
  149. easily be found by the simple calculation of  x mod 4, and the x
  150. coordinate is also found by  x div 4. We work out our y by multiplying
  151. it by the size of our chain-4 screen.
  152.  
  153. NOTE : It is possible to write to all four planes at once by setting the
  154.        correct port values.
  155.  
  156. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  157. ■ Uses of Chain-4
  158.  
  159. The uses of Chain-4 are many. One could write data to one screen, then
  160. flip to it (the move_to command is almost instantaneous). This means
  161. that 64k of memory does not need to be set aside for a virtual screen,
  162. you are using the vga cards memory instead!
  163.  
  164. Scrolling is much easier to code for in Chain-4 mode.
  165.  
  166. It is possible to "tweak" the mode into other resolutions. In our demo,
  167. our vectors were in 320x240 mode, and our dot vectors were in 320x400
  168. mode.
  169.  
  170. The main disadvantage of chain-4 as I see it is the plane swapping,
  171. which can be slow. With a bit of clever coding however, these can be
  172. kept down to a minimum.
  173.  
  174. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  175. ■ The sample programs
  176.  
  177. The first sample program is GFX.PAS. This is a until in which I have
  178. placed most of our routines from previous tuts. All the procedures and
  179. variables you can see under the INTERFACE section can be used in any
  180. program with GFX in the USES clause. In other words, I could do this :
  181.  
  182. USES GFX,crt;
  183.  
  184. BEGIN
  185.   Setupvirtual;
  186.   cls (vaddr,0);
  187.   Shutdown;
  188. END.
  189.  
  190. This program would compile perfectly. What I suggest you do is this :
  191. Rename the file to a name that suites you (eg your group name), change
  192. the first line of the unit to that name, then add all useful procedures
  193. etc. to the unit. Make it grow :-).
  194.  
  195. The second file is the sample program (note the USES GFX,crt; up near
  196. the top!). The program is easy to understand and is documented. The bit
  197. that I want to draw your attention to is the constant, BIT. Because I
  198. am distributing this file to many places in text form, not binary form,
  199. I could not just add a .CEL file with the program. So what I did was
  200. write some text in one color then saved it as a .CEL . I then wrote a
  201. ten line program that did the following : Moving from left to right, it
  202. counted how many pixels were of color zero, then saved the byte value to
  203. an array. When it came across color one, is counted for how long that
  204. went on then saved the byte value and saved it to an array and so on.
  205. When it was finished, I converted the array into a text file in the
  206. CONST format. Not too cunning, but I thought I had better explain it ;-)
  207.  
  208. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  209. ■ In closing
  210.  
  211. There are other documents and sample programs available on Chain-4 and
  212. it's like : Try XLIB for one...
  213.  
  214. Finally! Some BBS's have joined my BBS list! (Okay, only two new ones,
  215. but it's a start ;-)) All you international BBS's! If you will regularly
  216. download the tuts from an FTP site, give me your names!
  217.  
  218. I own a car. The car's name is Bob. A few days ago, Bob was in an
  219. accident, and now has major damage to his front. Knowing insurance, I
  220. probably won't get much, probably nothing (the other guy wasn't insured,
  221. and I am only 18 :( ). I will probably have to find work in order to pay
  222. for my repairs. The point to this meandering is this : I am upset, so if
  223. you think you are getting a quote, you can just forget it.
  224.  
  225. Oh, well. Life goes on!
  226.  
  227. See you next time,
  228.   - Denthor
  229.  
  230. These fine BBS's carry the ASPHYXIA DEMO TRAINER SERIES : (alphabetical)
  231.  
  232. ╔══════════════════════════╦════════════════╦═════╦═══╦════╦════╗
  233. ║BBS Name                  ║Telephone No.   ║Open ║Msg║File║Past║
  234. ╠══════════════════════════╬════════════════╬═════╬═══╬════╬════╣
  235. ║ASPHYXIA BBS #1           ║(031) 765-5312  ║ALL  ║ * ║ *  ║ *  ║
  236. ║ASPHYXIA BBS #2           ║(031) 765-6293  ║ALL  ║ * ║ *  ║ *  ║
  237. ║Connectix BBS             ║(031) 266-9992  ║ALL  ║   ║ *  ║ *  ║
  238. ║POP!                      ║(012) 661-1257  ║ALL  ║   ║ *  ║ *  ║
  239. ║Pure Surf BBS             ║(031) 561-5943  ║A/H  ║   ║ *  ║ *  ║
  240. ╚══════════════════════════╩════════════════╩═════╩═══╩════╩════╝
  241.  
  242. For international users : If you live outside the Republic of South
  243. Africa, do the following : Dial +27, dont dial the first 0, but dial
  244. the rest of the number. Eg, for the ASPHYXIA BBS : +27-31-765-5312
  245.  
  246. Open = Open at all times or only A/H
  247. Msg  = Available in message base
  248. File = Available in file base
  249. Past = Previous Parts available
  250.  
  251.  
  252. ┌───────────┬────────────────────────────────────────────────────────────────
  253. │ C4TUT.PAS │
  254. └───────────┘
  255.  
  256. (*
  257. Well folks, here it is - the long awaited for Chain-4 trainer. The
  258. routines are commented so I'm not going to say too much more here,
  259. except a few things.
  260.  
  261. 1: If ya don't understand this (not suprising its bloody cryptic!)
  262.    then if ur serious go out and buy - Programming the EGA & VGA Cards
  263.    I don't know who the book is by, so don't ask. Perhaps you know Greg?
  264.  
  265. 2: The code is unoptimised. I wrote it specifically for this conf. and
  266.    I'm buggered if I'm gonna give out my wholely (sp? ahh stuff it :-))
  267.    optimised code. If you want it faster, OPTIMISE IT!!
  268.    HINT: Its faster to load ax, with a low byte/high byte combination
  269.          and out a word instead of a byte at a time. If u don't know
  270.          what I'm talking about, too bad :-)
  271.  
  272. 3: If you use/like/whatever this code, please give Asphyxia a mention.
  273.    It wos bloody hard work figuring out how all this cr*p works, we
  274.    couldn't have done it with out a little guidence (thanx Gregie Poo).
  275.  
  276. 4: LiveWire got interested in the whole tut/trainer idea and MAY be
  277.    putting together a doc on how the whole thing works, including
  278.    Pel-Panning which I haven't included here.
  279.  
  280.  
  281. 5: Good luck with the code, and if you write anything with it, I'd
  282.    appreciate having a look at it :-). Feel free to direct any comments
  283.    about the code to me in this conf. Or at one of the contact addresses
  284.    given in the code.
  285.  
  286.  
  287. l8rs
  288. EzE / Asphyxia
  289.  
  290.  
  291.  
  292. --------------------------------=[ Cut Here ]=-------------------------
  293. *)
  294. {$X+,G+}
  295. Program Chain4_Tut;
  296. Uses
  297.    Crt;
  298.  
  299.  
  300. Const
  301.    Size : Byte = 80;
  302.  
  303.  
  304. Var Loop : Integer;
  305.  
  306.  
  307.  
  308. Procedure Init_C4; Assembler;
  309. Asm
  310.    mov   ax, 0013h
  311.    int   10h               { set up bios initially for 13h            }
  312.  
  313.    mov   dx, 03c4h         { Sequencer Address Register               }
  314.    mov   al, 4             { Index 4 - Memory mode                    }
  315.    out   dx, al            { select it.                               }
  316.    inc   dx                { 03c5h - here we set the mem mode.        }
  317.    in    al, dx            { get whats already inside the reg         }
  318.    and   al, 11110111b     { un-set 4th bit - chain4                  }
  319.    out   dx, al
  320.  
  321.    mov   dx, 3d4h
  322.    mov   al, 13h           { Offset Register - allocates amt. mem for }
  323.    out   dx, al            { 1 displayable line as - length div 8, so }
  324.    inc   dx                { we use 80 (80*8) = 640 = 2 pages across  }
  325.    mov   al, [Size]        { and cause of chain-4 i.e. 256k display   }
  326.    out   dx, al            { mem, 2 pages down for four pages         }
  327.  
  328.                            { NOTE: setting AL above to 40 selects 1   }
  329.                            { page across and four down (nice for      }
  330.                            { 1942 type scrolling games) and setting   }
  331.                            { AL to 160 selects 4 pages across and 1   }
  332.                            { down, nice for horizontal scrolling      }
  333.  
  334. End;
  335.  
  336.  
  337.  
  338. Procedure Cls_C4; Assembler;
  339. Asm
  340.    mov   dx, 03c4h         { 03c4h                                    }
  341.    mov   al, 2             { Map Mask Register                        }
  342.    out   dx, al
  343.    inc   dx
  344.    mov   al, 00001111b     { Select all planes to write to            }
  345.    out   dx, al            { Doing this to clear all planes at once   }
  346.  
  347.    mov   ax, 0a000h
  348.    mov   es, ax
  349.    xor   di, di            { set es:di = Screen Mem                   }
  350.    mov   ax, 0000h         { colour to put = black                    }
  351.    mov   cx, 32768         { 32768 (words) *2 = 65536 bytes - vga mem }
  352.    cld
  353.    rep   stosw             { clear it                                 }
  354. End;
  355.  
  356.  
  357.  
  358. Procedure PutPixel_C4(X, Y : Integer; Col : Byte); Assembler;
  359. Asm
  360.    mov   ax, [Y]           { Y val multiplied by...                   }
  361.    xor   bx, bx
  362.    mov   bl, [Size]        { Size....                                 }
  363.    shl   bx, 1             { *2 - just 'cause! (I can't remember why!)}
  364.    mul   bx
  365.    mov   bx, ax
  366.  
  367.    mov   ax, [X]
  368.    mov   cx, ax
  369.    shr   ax, 2
  370.    add   bx, ax            { add X val div 4 (four planes)            }
  371.  
  372.    and   cx, 00000011b     { clever way of finding x mod 4, i.e.      }
  373.    mov   dx, 03c4h         { which plane we're in.                    }
  374.    mov   al, 2             { then use 03c4h index 2 - write plane sel.}
  375.    out   dx, al            { to set plane to write to.                }
  376.    mov   al, 1             { plane to write to = 1 shl (X mod 4)      }
  377.    shl   al, cl
  378.    inc   dx
  379.    out   dx, al
  380.  
  381.    mov   ax, 0a000h
  382.    mov   es, ax
  383.    mov   al, [Col]
  384.    mov   es: [bx], al      { then write pixel.                        }
  385. End;
  386.  
  387.  
  388. Function GetPixel_C4(X, Y : Integer): Byte; Assembler;
  389. Asm
  390.    mov   ax, [Y]           { Y val multiplied by...                   }
  391.    xor   bx, bx
  392.    mov   bl, [Size]        { Size....                                 }
  393.    shl   bx, 1             { *2 - just 'cause! (I can't remember why!)}
  394.    mul   bx
  395.    mov   bx, ax
  396.  
  397.    mov   ax, [X]
  398.    mov   cx, ax
  399.    shr   ax, 2
  400.    add   bx, ax            { add X val div 4 (four planes)            }
  401.  
  402.    and   cx, 00000011b     { clever way of finding x mod 4, i.e.      }
  403.    mov   dx, 03c4h         { which plane we're in.                    }
  404.    mov   al, 4h            { then use 03c4h index 4 - read plane sel. }
  405.    out   dx, al            { to set plane to read from.               }
  406.    mov   al, cl            { Plane to read from = X mod 4             }
  407.    inc   dx
  408.    out   dx, al
  409.  
  410.    mov   ax, 0a000h
  411.    mov   es, ax
  412.    mov   al, es: [bx]      { then return pixel read                   }
  413. End;
  414.  
  415.  
  416.  
  417. Procedure MoveScr_C4(X,Y : Integer); Assembler;
  418. Asm
  419.    mov   ax, [Y]           { Y val multiplied by...                   }
  420.    xor   bx, bx
  421.    mov   bl, [Size]        { Size....                                 }
  422.    shl   bx, 1             { *2 - just 'cause! (I can't remember why!)}
  423.    mul   bx
  424.    mov   bx, ax
  425.  
  426.    add   bx, [X]           { Add X val                                }
  427.  
  428.    mov   dx, 03d4h
  429.    mov   al, 0ch           { CRTC address reg.                        }
  430.    out   dx, al            { Start Address High Reg.                  }
  431.    inc   dx
  432.    mov   al, bh            { send high byte of start address.         }
  433.    out   dx, al
  434.  
  435.    dec   dx
  436.    mov   al, 0dh           { Start Address Low Reg.                   }
  437.    out   dx, al
  438.    inc   dx
  439.    mov   al, bl            { send low byte of start address.          }
  440.    out   dx, al
  441.  
  442. End;
  443.  
  444.  
  445. Procedure SetText; Assembler;
  446. Asm
  447.    mov   ax, 0003h
  448.    int   10h
  449. End;
  450.  
  451. Procedure Creds;
  452. Begin
  453.    SetText;
  454.    While KeyPressed do ReadKey;
  455.  
  456.    Asm
  457.       mov   ah, 1
  458.       mov   ch, 1
  459.       mov   cl, 0
  460.       int   10h
  461.    End;
  462.  
  463.    WriteLn('Chain-4 Trainer...');
  464.    WriteLn('By EzE of Asphyxia.');
  465.    WriteLn;
  466.    WriteLn('Contact Us on ...');
  467.    WriteLn;
  468.    WriteLn;
  469.    WriteLn('the Asphyxia BBS (031) - 7655312');
  470.    WriteLn;
  471.    WriteLn('Email :       eze@');
  472.    WriteLn('         asphyxia@');
  473.    WriteLn('          edwards@');
  474.    WriteLn('           bailey@');
  475.    WriteLn('          mcphail@');
  476.    WriteLn('                  beastie.cs.und.ac.za');
  477.    WriteLn;
  478.    WriteLn('or  peter.edwards@datavert.co.za');
  479.    WriteLn;
  480.    WriteLn('Write me snail-mail at...');
  481.    WriteLn('P.O. Box 2313');
  482.    WriteLn('Hillcrest');
  483.    WriteLn('Natal');
  484.    WriteLn('3650');
  485.    Asm
  486.       mov   ah, 1
  487.       mov   ch, 1
  488.       mov   cl, 0
  489.       int   10h
  490.    End;
  491.  
  492. End;
  493.  
  494.  
  495.  
  496.  
  497. Begin
  498.    Init_C4;
  499.    Cls_C4;
  500.    Repeat
  501.       Putpixel_C4(Random(320),Random(200),Random(256)+1);
  502.    Until KeyPressed;
  503.    For Loop := 0 to 80 do
  504.    begin
  505.       MoveScr_C4(0,Loop);
  506.       Delay(10);
  507.    End;
  508.    ReadKey;
  509.    Loop := GetPixel_C4(100,100);
  510.    Creds;
  511.    WriteLn('Colour at location X:100, Y:100 was: ',Loop);
  512. End.
  513.  
  514. --------------------------------=[ Cut Here ]=-------------------------
  515.