home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / TUT1-9.ZIP / TUT4.TXT < prev    next >
Text File  |  1993-08-11  |  9KB  |  205 lines

  1.  
  2.                    ╒═══════════════════════════════╕
  3.                    │         W E L C O M E         │
  4.                    │  To the VGA Trainer Program   │ │
  5.                    │              By               │ │
  6.                    │      DENTHOR of ASPHYXIA      │ │ │
  7.                    ╘═══════════════════════════════╛ │ │
  8.                      ────────────────────────────────┘ │
  9.                        ────────────────────────────────┘
  10.  
  11.                            --==[ PART 4 ]==--
  12.  
  13.  
  14.  
  15. ■ Introduction
  16.  
  17.  
  18. Howdy all! Welcome to the fourth part of this trainer series! It's a
  19. little late, but I am sure you will find that the wait was worth it,
  20. becase today I am going to show you how to use a very powerful tool :
  21. Virtual Screens.
  22.  
  23. If you would like to contact me, or the team, there are many ways you
  24. can do it : 1) Write a message to Grant Smith in private mail here on
  25.                   the Mailbox BBS.
  26.             2) Write a message here in the Programming conference here
  27.                   on the Mailbox (Preferred if you have a general
  28.                   programming query or problem others would benefit from)
  29.             3) Write to ASPHYXIA on the ASPHYXIA BBS.
  30.             4) Write to Denthor, Eze or Livewire on Connectix.
  31.             5) Write to :  Grant Smith
  32.                            P.O.Box 270 Kloof
  33.                            3640
  34.             6) Call me (Grant Smith) at 73 2129 (leave a message if you
  35.                   call during varsity)
  36.  
  37. NB : If you are a representative of a company or BBS, and want ASPHYXIA
  38.        to do you a demo, leave mail to me; we can discuss it.
  39. NNB : If you have done/attempted a demo, SEND IT TO ME! We are feeling
  40.         quite lonely and want to meet/help out/exchange code with other demo
  41.         groups. What do you have to lose? Leave a message here and we can work
  42.         out how to transfer it. We really want to hear from you!
  43.  
  44.  
  45. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  46. ■  What is a Virtual Screen and why do we need it?
  47.  
  48. Let us say you are generating a complex screen numerous times on the fly
  49. (for example scrolling up the screen then redrawing all the sprites for
  50. each frame of a game you are writing.) Do you have any idea how awful it
  51. would look if the user could actually see you erasing and redrawing each
  52. sprite for each frame? Can you visualise the flicker effect this would
  53. give off? Do you realise that there would be a "sprite doubling" effect
  54. (where you see two copies of the same sprite next to each other)? In the
  55. sample program I have included a part where I do not use virtual screens
  56. to demonstrate these problems. Virtual screens are not the only way to
  57. solve these problems, but they are definately the easiest to code in.
  58.  
  59. A virtual screen is this : a section of memory set aside that is exactly
  60. like the VGA screen on which you do all your working, then "flip" it
  61. on to your true screen. In EGA 640x350x16 you automatically have a
  62. virtual page, and it is possible to have up to four on the MCGA using a
  63. particular tweaked mode, but for our puposes we will set one up using base
  64. memory.
  65.  
  66. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  67. ■  Setting up a virtual screen
  68.  
  69. As you will have seen in the first part of this trainer series, the MCGA
  70. screen is 64000 bytes big (320x200=64000). You may also have noticed that
  71. in TP 6.0 you arn't allowed too much space for normal variables. For
  72. example, saying :
  73.  
  74. VAR Virtual : Array [1..64000] of byte;
  75.  
  76. would be a no-no, as you wouldn't have any space for your other variables.
  77. What is the solution? I hear you enquiring minds cry. The answer : pointers!
  78. Pointers to not use up the base 64k allocated to you by TP 6.0, it gets
  79. space from somewhere else in the base 640k memory of your computer. Here is
  80. how you set them up :
  81.  
  82. Type Virtual = Array [1..64000] of byte;  { The size of our Virtual Screen }
  83.      VirtPtr = ^Virtual;                  { Pointer to the virtual screen }
  84.  
  85. VAR Virscr : VirtPtr;                      { Our first Virtual screen }
  86.     Vaddr  : word;                        { The segment of our virtual screen}
  87.  
  88. If you put this in a program as it stands, and try to acess VirScr, your
  89. machine will probably crash. Why? Because you have to get the memory for
  90. your pointers before you can acess them! You do that as follows :
  91.  
  92. Procedure SetUpVirtual;
  93. BEGIN
  94.   GetMem (VirScr,64000);
  95.   vaddr := seg (virscr^);
  96. END;
  97.  
  98. This procedure has got the memory for the screen, then set vaddr to the
  99. screens segment. DON'T EVER LEAVE THIS PROCEDURE OUT OF YOUR PROGRAM!
  100. If you leave it out, when you write to your virtual screen you will probably
  101. be writing over DOS or some such thing. Not a good plan ;-).
  102.  
  103. When you have finished your program, you will want to free the memory
  104. taken up by the virtual screen by doing the following :
  105.  
  106. Procedure ShutDown;
  107. BEGIN
  108.   FreeMem (VirScr,64000);
  109. END;
  110.  
  111. If you don't do this your other programs will have less memory to use for
  112. themselves.
  113.  
  114. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  115. ■  Putting a pixel to your virtual screen
  116.  
  117. This is very similar to putting a pixel to your normal MCGA screen, as
  118. discussed in part one... here is our origonal putpixel :
  119.  
  120. Procedure PutPixel (X,Y : Integer; Col : Byte);
  121. BEGIN
  122.   Mem [VGA:X+(Y*320)]:=col;
  123. END;
  124.  
  125. For our virtual screen, we do the following :
  126.  
  127. Procedure VirtPutPixel (X,Y : Integer; Col : Byte);
  128. BEGIN
  129.   Mem [Vaddr:X+(Y*320)]:=col;
  130. END;
  131.  
  132. It seems quite wasteful to have two procedures doing exactly the same thing,
  133. just to different screens, doesn't it? So why don't we combine the two like
  134. this :
  135.  
  136. Procedure PutPixel (X,Y : Integer; Col : Byte; Where : Word);
  137. BEGIN
  138.   Mem [Where:X+(Y*320)]:=col;
  139. END;
  140.  
  141. To use this, you will say something like :
  142.  
  143. Putpixel (20,20,32,VGA);
  144. PutPixel (30,30,64,Vaddr);
  145.  
  146. These two statements draw two pixels ... one to the VGA screen and one to
  147. the virtual screen! Doesn't that make you jump  with joy! ;-) You will
  148. have noticed that we still can't actually SEE the virtual screen, so on to
  149. the next part ...
  150.  
  151. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  152. ■  How to "Flip" your virtual screen on to the true screen
  153.  
  154. You in fact already have to tools to do this yourselves from information
  155. in the previous parts of this trainer series. We will of course use the
  156. Move command, like so :
  157.  
  158. Move (Virscr^,mem [VGA:0],64000);
  159.  
  160. simple, eh? Yuo may want to wait for a verticle retrace (Part 2) before you
  161. do that, as it may make the flip much smoother (and, alas, slower).
  162.  
  163. Note that most of our other procedures may be altered to support the
  164. virtual screen, such as Cls etc. (see Part 1 of this series), using the
  165. methoods described above (I have altered the CLS procedure in the sample
  166. program given at the end of this Part.)
  167.  
  168. We of ASPHYXIA have used virtual screens in almost all of our demos.
  169. Can you imagine how awful the SoftelDemo would have looked if you had to
  170. watch us redrawing the moving background, text and vectorballs for EACH
  171. FRAME? The flicker, doubling effects etc would have made it awful! So
  172. we used a virtual screen, and are very pleased with the result.
  173. Note, though, that to get the speed we needed to get the demo fast enough,
  174. we wrote our sprites routines, flip routines, pallette routines etc. all
  175. in assembly. The move command is very fast, but not as fast as ASM ;-)
  176.  
  177. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  178. ■  In closing
  179.  
  180. I am writing this on the varsity computers in between lectures. I prefer
  181. writing & coding between 6pm and 4am, but it isn't a good plan when
  182. varsity is on ;-), so this is the first part of the trainer series ever
  183. written before 9pm.
  184.  
  185. I have been asked to do a part on scrolling the screen, so that is
  186. probably what I will do for next week. Also, ASPHYXIA will soon be putting
  187. up a small demo with source on the local boards. It will use routines
  188. that we have discussed in this series, and demonstrate how powerful these
  189. routines can be if used in the correct manner.
  190.  
  191. Some projects for you to do :
  192.   1) Rewrite the flip statement so that you can say :
  193.         flip (Vaddr,VGA);
  194.         flip (VGA,Vaddr);
  195.       ( This is how ASPHYXIAS one works )
  196.  
  197.   2) Put most of the routines (putpixel, cls, pal etc.) into a unit,
  198.      so that you do not need to duplicate the procedures in each program
  199.      you write. If you need help, leave me mail.
  200.  
  201.  
  202. See you next week
  203.    - Denthor
  204.  
  205.