home *** CD-ROM | disk | FTP | other *** search
/ The Equalizer BBS / equalizer-bbs-collection_2004.zip / equalizer-bbs-collection / DEMOSCENE-STUFF / HQ_WATER.ZIP / DROPS.PAS < prev    next >
Pascal/Delphi Source File  |  1994-09-19  |  5KB  |  278 lines

  1. {
  2.    DROPS.PAS  //  ARM 12/93
  3.  
  4.    rain drops / credits for <NONAME> (Iguana demo #2)
  5. }
  6.  
  7. {$X+,G+,N-,S-,R-}
  8.  
  9. {x$DEFINE Stat }   { define stat to print frame count on exit }
  10. {x$DEFINE Show }   { define show to show timer and WScp,SScp  }
  11. {x$DEFINE fromX }  { define if starting in mode x }
  12.  
  13. Uses  PASDVT, GLOBAL, COLORS, BACKGRND, SKY, WATER;
  14.  
  15. procedure BRAND; assembler;
  16. asm
  17.   db '[[ ARM 12/93 ]]'
  18. end;
  19.  
  20.  
  21. function KeyPressed : boolean; assembler;
  22. asm
  23.   mov ah,1
  24.   int $16
  25.   mov al,0
  26.   jz @1
  27.   mov ah, 0
  28.   int $16      { absorb key }
  29.   mov al,1
  30. @1:
  31. end;
  32.  
  33.  
  34. procedure UpdateTable; external;
  35. procedure DrawSurf; external;
  36. {$L surf.obj}
  37.  
  38. procedure InitTable;
  39. var i : integer;
  40. begin
  41.   FillChar( U^, sizeof(TU), 0 );
  42.   for i := 0 to NX-1 do TOPS[i] := 199*320+2*i;
  43. end;
  44.  
  45. procedure WaitVR;
  46. begin
  47.   repeat until (Port[$3da] and 8)=0;
  48.   while (Port[$3da] and 8)=0 do ;
  49. end;
  50.  
  51.  
  52. procedure FilterPalette;
  53. var i : byte;
  54. begin               { quirk: red component must be <63 for fade routine }
  55.   for i := 0 to 255 do if RGB[i,0]=63 then RGB[i,0]:=62;
  56. end;
  57.  
  58. { ... }
  59. procedure tweak;
  60. begin
  61.   PortW[ $3c4 ] := $0404;
  62.   PortW[ $3d4 ] := $0014;
  63.   PortW[ $3d4 ] := $e317;
  64.   PortW[ $3ce ] := $ff08;
  65.   PortW[ $3c4 ] := $0f02;
  66. end;
  67. procedure untweak;
  68. begin
  69.   PortW[ $3d4 ] := $000c;
  70.   PortW[ $3d4 ] := $000d;
  71.   PortW[ $3ce ] := $ff08;
  72.   PortW[ $3c4 ] := $0f02;
  73.   PortW[ $3c4 ] := $0c04;
  74.   PortW[ $3d4 ] := $4014;
  75.   PortW[ $3d4 ] := $a317;
  76. end;
  77.  
  78. procedure Startup;
  79. var P : PAL;
  80.     C : CRGB;
  81.     x : word;
  82. begin
  83. {
  84.   asm
  85.     mov ax,$13
  86.     int $10
  87.   end;
  88.   for x := 0 to 320*200 do Mem[$a000:x] := x mod 320;
  89.   readln;
  90.   tweak;
  91. }
  92.   GetPalette( P, 0, 256 );
  93.   FadeToColor  ( P, 63,63,63, 63 );
  94. {$IFDEF fromX}  untweak;  {$ENDIF}
  95.   C[0] := 63;  C[1] := 63;  C[2] := 63;
  96.   for x := 0 to 255 do P[x] := C;
  97.   FadeToColor  ( P, 16,16, 0, 63 );
  98. end;
  99.  
  100. { ... }
  101.  
  102. var
  103.   timer,lastT: longint;
  104.   thiscount : word;
  105.   update_allowed : boolean;
  106.   tmp  : pointer;
  107.   vol  : byte;
  108.   col  : byte;
  109.   WScP : byte;
  110.   SScP : byte;
  111.  
  112. BEGIN
  113. {$IFNDEF fromX }
  114.    asm
  115.      mov ah,$0f
  116.      int $10
  117.      cmp al,$13
  118.      je @@1
  119.      mov ax,$13
  120.      int $10
  121.  @@1:
  122.    end;
  123. {$ENDIF}
  124.  
  125.    Startup;
  126.  
  127.    tmp := @BRAND;
  128.    getmem( U, sizeof(TU) );
  129.    getmem( tmp, sizeof(TB)+16 );
  130.    asm
  131.       mov dx, [word ptr tmp+2]
  132.       mov ax, [word ptr tmp]
  133.       or ax,ax
  134.       jz @1
  135.       xor ax,ax
  136.       inc dx
  137.     @1:                          { Make ofs(B^) be 0, so that     }
  138.       mov [word ptr B], ax       {  we can use the same register  }
  139.       mov [word ptr B+2], dx     {  for video-buf and B^ offsets. }
  140.    end;
  141.  
  142.    InitTable;
  143.    Leaving := False;
  144.    Count := 1;
  145.    CT := 1;
  146.  
  147.    if not VT_Init then halt(1);
  148.  
  149.    InitColors;
  150.    InitBackground;
  151.    FilterPalette;
  152.  
  153.    asm
  154.      push ds
  155.      lds si, B
  156.      mov ax, $a000
  157.      mov es, ax
  158.      xor di,di
  159.      mov cx, (200-NY)*160
  160.      cld
  161.      rep movsw
  162.      pop ds
  163.    end;
  164.    DrawSurf;
  165.  
  166.    VT_AutoOn;
  167.    VT_Start;
  168.  
  169.    while keypressed do ;  { absorb previous key strokes }
  170.  
  171.    FadeFromColor( RGB, 63,63, 0, 63 );
  172.  
  173.    vol := VT_GetVolume and not 15;
  174.    col := 32;
  175.  
  176.    WScP := 0;
  177.    SScP := 0;
  178.    Damp := WScript[ 0 ].dens;
  179.    SScript[ 0 ].first;
  180.  
  181.    lastT := -1;
  182.    thiscount := 0;
  183.  
  184.    REPEAT
  185.  
  186.      timer := VT_Timer;
  187.  
  188.      { ----
  189.        Weird way to limit speed of water while avoiding the jerkiness
  190.        of DemoVT's timer... only problem is I can't really test it!
  191.      }
  192.  
  193.      if timer <= lastT + 1 then
  194.        inc( thiscount )
  195.      else begin
  196.        thiscount := 0;
  197.        lastT := timer;
  198.      end;
  199.      update_allowed := (thiscount<2);
  200.  
  201.      { update_allowed := true; }
  202.  
  203.      { ---- }
  204.  
  205.      if update_allowed then begin
  206.        UpdateTable;
  207.        CT := 1-CT;
  208.      end;
  209.  
  210. {$IFDEF Show}
  211.      { print status to screen }
  212.  
  213.      gotoxy(1,1); write(timer:8);
  214.      gotoxy(5,2); write(WScp:4);
  215.      gotoxy(1,2); write(SScp:4);
  216. {$ENDIF}
  217.  
  218.      { water script }
  219.  
  220.      if update_allowed then WScript[ WScP ].what;
  221.      if WScp<NWScript-1 then
  222.        if timer > WScript[ WScp+1 ].when then begin
  223.          inc( WScP );
  224.          Damp := WScript[ WScP ].dens;
  225.      end;
  226.  
  227.  
  228.      { sky script }
  229.  
  230.      DrawSurf;
  231.  
  232.      SScript[ SScP ].what;
  233.      if SScp<NSScript-1 then
  234.        if timer > SScript[ SScp+1 ].when then begin
  235.          SScript[ SScp ].last;
  236.          inc( SScP );
  237.          SScript[ SScp ].first;
  238.      end;
  239.  
  240.  
  241.      inc( count );
  242.  
  243.      if not Leaving then begin
  244.         if ( count and $0f ) = 0 then Leaving := KeyPressed;
  245.      end else begin
  246.         DimPalette( RGB, col );
  247.         dec(col);
  248.         if vol <> 0 then dec(vol,16);
  249.         VT_SetVolume( vol );
  250.      end;
  251.  
  252.   UNTIL col=0;
  253.  
  254.   if Leaving then VT_Abort;
  255.  
  256.   while vol <> 0 do begin
  257.     dec(vol,4);
  258.     VT_SetVolume(vol);
  259.     DrawSurf;
  260.   end;
  261.  
  262. {  VT_Delay(50); }
  263.  
  264.   asm
  265.     mov ax,3
  266.     int $10
  267.   end;
  268.  
  269.  
  270. {$IFDEF Stat}
  271.   writeln( count );
  272. {$ENDIF}
  273.  
  274.   FreeMem( tmp, sizeof(TB) );
  275.   FreeMem( U, sizeof(TU) );
  276. END.
  277.  
  278.