home *** CD-ROM | disk | FTP | other *** search
/ PC Underground / UNDERGROUND.ISO / graphic / flames.pas < prev    next >
Pascal/Delphi Source File  |  1995-07-28  |  4KB  |  133 lines

  1. {$G+}
  2. Uses Crt,ModeXLib;
  3. Type Block=Array[0..99,0..319] of Byte;
  4. Var
  5.   Src_Frame,                    {previous picture}
  6.   Dest_Frame:^Block;            {current picture}
  7.  
  8. Procedure Scroll_Up;assembler;
  9. {scrolls the picture one line up and interpolates}
  10. asm
  11.   push ds
  12.   les di,Dest_Frame             {load pointer to destination picture}
  13.   lds si,Src_Frame              {pointer to source picture}
  14.   add si,320                    {in source picture on line 1}
  15.   mov cx,320*98                 {scroll 99 lines}
  16.   xor bl,bl                     {required as dummy for High-Byte}
  17. @lp1:
  18.   xor ax,ax
  19.   xor bx,bx
  20.   mov al,[si-321]               {get first point}
  21.   mov bl,[si-320]               {add next point}
  22.   add ax,bx
  23.   mov bl,[si-319]               {add next point}
  24.   add ax,bx
  25.   mov bl,[si-1]                 {etc...}
  26.   add ax,bx
  27.   mov bl,[si+1]
  28.   add ax,bx
  29.   mov bl,[si+319]
  30.   add ax,bx
  31.   mov bl,[si+320]
  32.   adc ax,bx
  33.   mov bl,[si+321]
  34.   adc ax,bx
  35.   shr ax,3
  36.  
  37.   or ax,ax                      {already 0 ?}
  38.   je @null
  39.   dec al                        {if no, then decrease}
  40. @null:
  41.   stosb                         {value to destination}
  42.   inc si                        {next point}
  43.   dec cx                        {other points ?}
  44.   jne @lp1
  45.   pop ds
  46. End;
  47.  
  48. Procedure New_Line;             {rebuilds the bottom lines}
  49. Var i,x:Word;
  50. Begin
  51.   For x:=0 to 319 do Begin      {fill bottom 3 lines with random values}
  52.     Dest_Frame^[97,x]:=Random(15)+64;
  53.     Dest_Frame^[98,x]:=Random(15)+64;
  54.     Dest_Frame^[99,x]:=Random(15)+64;
  55.   End;
  56.   For i:=0 to Random(45) do Begin {insert random number Hotspots}
  57.     x:=Random(320);             {to random coordinates}
  58.     asm
  59.       les di,Dest_Frame         {address destination picture}
  60.       add di,98*320             {edit line 98 (second from bottom)}
  61.       add di,x                  {add x-coordinate}
  62.       mov al,0ffh               {brightest color}
  63.       mov es:[di-321],al        {generate large Hotspot (9 points)}
  64.       mov es:[di-320],al
  65.       mov es:[di-319],al
  66.       mov es:[di-1],al
  67.       mov es:[di],al
  68.       mov es:[di+1],al
  69.       mov es:[di+319],al
  70.       mov es:[di+320],al
  71.       mov es:[di+321],al
  72.     End;
  73.   End;
  74. End;
  75.  
  76. Procedure Show_Screen;          {copies finished screen to VGA}
  77. Var temp:Pointer;               {for exchanging pointers}
  78. Begin
  79. asm
  80.   push ds
  81.   lds si,Dest_Frame             {finished picture as source}
  82.   mov ax,0a000h                 {VGA as destination}
  83.   mov es,ax
  84.   mov di,320*100                {starting at line 100}
  85.   mov cx,320*100/4              {copy 100 lines as Dwords}
  86. db 66h                          {Operand Size Prefix (32 Bit)}
  87.   rep movsw                     {copy}
  88.   pop ds
  89. End;
  90.   temp:=Dest_Frame;             {exchange pointers to source and destination pictures}
  91.   Dest_Frame:=Src_Frame;
  92.   Src_Frame:=temp;
  93. End;
  94.  
  95. Procedure Prep_Pal;             {prepare palette for flames}
  96. Var i:Word;
  97. Begin
  98.   FillChar(Palette,80*3,0);     {foundation: all black}
  99.   For i:=0 to 7 do Begin
  100.     Palette[i*3+2]:=i*2;        {color 0-7: increase blue}
  101.     Palette[(i+8)*3+2]:=16-i*2; {color 0-7: decreasing blue}
  102.   End;
  103.   For i:=8 to 31 do             {color 8 -31: increase red}
  104.     Palette[i*3]:=(i-8)*63 div 23;
  105.   For i:=32 to 55 do Begin      {color 32-55: increase green, red constant}
  106.     Palette[i*3]:=63;
  107.     Palette[i*3+1]:=(i-32)*63 div 23;
  108.   End;
  109.   For i:=56 to 79 do Begin      {color 56-79: increase blue, red and blue const.}
  110.     Palette[i*3]:=63;
  111.     Palette[i*3+1]:=63;
  112.     Palette[i*3+2]:=(i-56)*63 div 23;
  113.   End;
  114.   FillChar(Palette[80*3],176*3,63);  {rest white}
  115.   SetPal;                       {set finished palette}
  116. End;
  117.  
  118. begin
  119.   Randomize;                    {determine Random Seed}
  120.   GetMem(Src_Frame,320*100);    {get memory for source picture and delete}
  121.   FillChar(Src_Frame^,320*100,0);
  122.   GetMem(Dest_Frame,320*100);   {get memory for destination picture and delete}
  123.   FillChar(Dest_Frame^,320*100,0);
  124.   Init_Mode13;                  {set Mode 13h}
  125.   Prep_Pal;                     {prepare palette}
  126.   Repeat
  127.     Scroll_Up;                  {flames up}
  128.     New_Line;                   {add new line at bottom}
  129.     Show_Screen;                {show finished screen}
  130.   Until KeyPressed;
  131.   TextMode(3);
  132. end.
  133.