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