home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / MISC / MAG05.ZIP / TUNNEL.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1995-11-05  |  4.0 KB  |  192 lines

  1. Program Tunnel;
  2.  
  3. Uses Crt;                       { CRT has some good general routines in it }
  4.  
  5. Const VGA=$A000;
  6.  
  7. Type RgbItem=Record
  8.                    R,G,B:Byte;
  9.              End;
  10.      RgbList=Array[0..255] of RgbItem;
  11.  
  12.      Table=Array[0..1799] Of Real;
  13.      PTable=^Table;
  14.  
  15. Var Pal1:RgbList;
  16.     R:Word;
  17.  
  18.     Sines:Ptable;
  19.     Cosines:Ptable;
  20.  
  21.  
  22. Procedure Initgraph; Assembler;
  23. Asm
  24.    Mov AH,0
  25.    Mov AL,13h
  26.    Int 10h
  27. End;
  28.  
  29. Procedure Closegraph; Assembler;
  30. Asm
  31.    Mov AH,0
  32.    Mov AL,03h
  33.    Int 10h
  34. End;
  35.  
  36. Procedure WaitVBL; Assembler;
  37. Label A1,A2;
  38. Asm
  39.    Mov DX,3DAh
  40.    A1:
  41.       In AL,DX
  42.       And AL,08h
  43.       Jnz A1
  44.    A2:
  45.       In AL,DX
  46.       And AL,08h
  47.       Jz A2
  48. End;
  49.  
  50. Procedure InitTables;
  51. Var A:Word;
  52.     B:Real;
  53. Begin
  54.      Getmem(Sines,Sizeof(Sines^));
  55.      Getmem(Cosines,Sizeof(Cosines^));
  56.      B:=0;
  57.      For A:=0 To 1799 Do
  58.      Begin
  59.           Sines^[A]:=Sin(B);
  60.           Cosines^[A]:=Cos(B);
  61.           B:=B+0.005;
  62.      End;
  63. End;
  64.  
  65. Procedure ClearTables;
  66. Begin
  67.      Freemem(Sines,Sizeof(Sines^));
  68.      Freemem(Cosines,Sizeof(Cosines^));
  69. End;
  70.  
  71. Procedure PutPixel(X,Y,C:Word);
  72. Begin
  73.      Mem[VGA:(Y*320)+X]:=C;
  74. End;
  75.  
  76. Procedure GetColor(Col:Byte;Var R,G,B:Byte);
  77. Begin
  78.      Port[$3C7]:=Col;
  79.      R:=Port[$3C9];
  80.      G:=Port[$3C9];
  81.      B:=Port[$3C9];
  82. End;
  83.  
  84. Procedure SetColor(Col,R,B,G:Byte);
  85. Begin
  86.      Port[$3C8]:=Col;
  87.      Port[$3C9]:=R;
  88.      Port[$3C9]:=G;
  89.      Port[$3C9]:=B;
  90. End;
  91.  
  92. Procedure GetPalette(Var Pal:RgbList);
  93. Var A:Byte;
  94. Begin
  95.      For A:=0 To 255 do GetColor(A,Pal[A].R,Pal[A].G,Pal[A].B);
  96. End;
  97.  
  98. Procedure SetPalette(Pal:RgbList);
  99. Var A:Byte;
  100. Begin
  101.      WaitVBL;
  102.      For A:=0 To 255 do SetColor(A,Pal[A].R,Pal[A].G,Pal[A].B);
  103. End;
  104.  
  105. Procedure SetBlack(Var Pal:RgbList);
  106. Var A:Byte;
  107. Begin
  108.      For A:=0 to 255 Do
  109.      Begin
  110.           Pal[A].R:=0;
  111.           Pal[A].G:=0;
  112.           Pal[A].B:=0;
  113.      End;
  114. End;
  115.  
  116. Procedure Cls(Col:Byte);
  117. Begin
  118.      FillChar(Mem[$A000:0000],64000,Col);
  119. End;
  120.  
  121. Procedure RotatePal(Var Pal:RgbList;First,Last:Byte);
  122. Var Temp:RgbItem;
  123.     A:Byte;
  124. Begin
  125.      Temp:=Pal[Last];
  126.      For A:=Last-1 DownTo First Do
  127.      Begin
  128.           Pal[A+1]:=Pal[A];
  129.      End;
  130.      Pal[First]:=Temp;
  131. End;
  132.  
  133. Procedure LoadPal(Filename:String;Var Pal:RgbList); { This loads a palette    }
  134. Var F:File;                                         { from disk... I will     }
  135. Begin                                               { explain it in a future  }
  136.      Assign(F,Filename);                            { article, all about disk }
  137.      Reset(F,1);                                    { access...               }
  138.      Blockread(F,Ptr(Seg(Pal[0].R),Ofs(Pal[0].R))^,768);
  139.      Close(F);
  140. End;
  141.  
  142. Procedure Circle(X,Y,R:Integer;Col:Byte);
  143. Var Px,Py:Integer;
  144.     Deg:Word;
  145. Begin
  146.      For Deg:=0 to 1799 Do
  147.      Begin
  148.           Px:=Trunc(R*Sines^[Deg]+X);
  149.           Py:=Trunc(R*Cosines^[Deg]+Y);
  150.           PutPixel(Px,Py,Col);
  151.      End;
  152. End;
  153.  
  154. Procedure Circles;
  155. Begin
  156.      LoadPal('Tunnel.Pal',Pal1);
  157.      SetPalette(Pal1);
  158.      For R:=1 To 99 Do Circle(160,100,R,R*2);
  159.      Repeat
  160.            If Keypressed Then If Readkey=Chr(27) Then Exit;
  161.            RotatePal(Pal1,1,255);
  162.            SetPalette(Pal1);
  163.      Until False;
  164. End;
  165.  
  166. Begin
  167.      Randomize;                       { Resets the random number generator }
  168.      Clrscr;
  169.      Writeln('Hello to another SpellCaster production...');
  170.      Writeln('This one only has circles... ');
  171.      Writeln;
  172.      Writeln('Press ESC to exit any of the program...');
  173.      Repeat Until Keypressed;
  174.      Initgraph;
  175.      InitTables;
  176.      Circles;
  177.      ClearTables;
  178.      Closegraph;
  179.      Writeln('Did you liked it ?... ');
  180.      Writeln('I hope you did.');
  181.      Writeln('Write to ''The Mag'':');
  182.      Writeln('Snail Mail: Praceta Carlos Manito Torres, nº4 / 6ºC');
  183.      Writeln('            2900 Setúbal');
  184.      Writeln('                 Portugal');
  185.      Writeln;
  186.      Writeln('E-Mail: Dgan@rnl.ist.utl.pt');
  187.      Writeln;
  188.      Writeln;
  189.      Writeln;
  190.      Repeat Until Keypressed;
  191. End.
  192.