home *** CD-ROM | disk | FTP | other *** search
/ Power CD-ROM!! 7 / POWERCD7.ISO / prgmming / vgfx10 / emsdemo.pas < prev    next >
Pascal/Delphi Source File  |  1994-11-30  |  8KB  |  267 lines

  1. { EMS unit demo program - (C) Copyright 1994 Brian Manning }
  2.  
  3. {$I-,D-,S+,X+}
  4.  
  5. program EMS_Demo;
  6.  
  7. uses dos,crt,vgfx,ems;
  8.  
  9. { Declare our variables }
  10. var emsver : word;
  11.     bytes  : longint;
  12.     pages,
  13.     i,
  14.     handle : integer;
  15.     x, y   : array[1..25] of integer;
  16.     hit    : array[1..25] of byte;
  17.     hitY   : array[1..25] of byte;
  18.     m      : byte;
  19.  
  20.  
  21. { Main Procedure! }
  22. begin
  23.      clrscr;
  24.      writeln;
  25.  
  26.      { Initialize the EMS driver }
  27.      EMSVer := EMS_Init;
  28.  
  29.      if (EMSResult >= $80) then
  30.      begin
  31.           { There was an EMS error, so display the description }
  32.           writeln('EMS Error:  ', EMS_ErrDesc[EMSResult]);
  33.           halt(1);
  34.      end
  35.      else if (EMSVer <> 0) then
  36.          writeln('EMS version: ', (EMSVer div 10), '.', (EMSVer mod 10))
  37.      else
  38.      begin
  39.           writeln('EMS Demo:  No EMS driver found!');
  40.           halt(1);
  41.      end;
  42.  
  43.  
  44.      { Get the amount of free pages of EMS memory }
  45.      pages:=EMSFreePages;
  46.  
  47.      { Display the EMS memory status on the screen }
  48.      writeln(pages, ' pages available (', (longint(16384)*pages) div 1024,
  49.                     'k of total storage)');
  50.  
  51.  
  52.      { Allocate 3 pages of EMS memory (49152 bytes) }
  53.      handle:=EMSAlloc(3);
  54.  
  55.      if (EMSResult>=$80) then
  56.      begin
  57.           { There was an EMS error, so display the description }
  58.           writeln('EMS Alloc Error:  ', EMS_ErrDesc[EMSResult]);
  59.           halt(1);
  60.      end;
  61.  
  62.  
  63.      { Map these pages so we can use them }
  64.      for i:=0 to 2 do
  65.      begin
  66.           if not(EMSMap(Handle, i, i)) then
  67.           begin
  68.                { There was an EMS error, so display the description }
  69.                writeln('EMS Map Error:  ', EMS_ErrDesc[EMSResult],i);
  70.                EMSFree(handle);
  71.                halt(1);
  72.           end;
  73.      end;
  74.  
  75.      writeln;
  76.      writeln('3 pages of EMS memory allocated and ready!');
  77.      writeln;
  78.      write('Press any key to begin ...');
  79.      readkey;
  80.  
  81.  
  82.      { Initialize VGFX }
  83.      VGFX_Init;
  84.  
  85.      { Tell VGFX to use DEMO.GFX for all it's file handling }
  86.      SetWorkLib('demo.gfx');
  87.  
  88.  
  89.      { Set our work page to 4 (so the user cannot see the image loaded) }
  90.      SetWorkPage(4);
  91.  
  92.      { Load up our images }
  93.      ShowPcx ('balls.pcx', 0, 4);
  94.  
  95.      { Get images into EMS memory }
  96.      GetImage (EMSPage(0)^, 10, 7, 15, 13);
  97.      GetImage (EMSPage(1)^, 45, 7, 25, 21);
  98.      GetImage (EMSPage(2)^, 96, 7, 33, 27);
  99.  
  100.      { Clear the screen }
  101.      clearscreen(0);
  102.  
  103.      { Set our work page to 1 }
  104.      SetWorkPage(1);
  105.  
  106.      { Show the PCX on page 3 (the background page) }
  107.      ShowPcx('frac.pcx',0,3);
  108.  
  109.      randomize;
  110.      for i := 1 to 25 do
  111.      begin
  112.           x[i]   := random(300);
  113.           y[i]   := random(175);
  114.           hit[i] := random(2);
  115.           hitY[i]:= random(2);
  116.      end;  { end for\do }
  117.  
  118.      repeat
  119.            { All of the FOR/DO loops from here on are checking the ball's
  120.              boundaries and moving them accordingly }
  121.  
  122.            for m := 1 to 5 do
  123.            begin
  124.                 if (x[m] > 274) then hit[m] := 0;
  125.                 if (x[m] < 1)   then hit[m] := 1;
  126.                 if (y[m] > 186) then hitY[m]:= 0;
  127.                 if (y[m] < 1)   then hitY[m]:= 1;
  128.  
  129.                 Case hit[m] of
  130.                      1 : inc(x[m],2);
  131.                      0 : dec(x[m],2);
  132.                 end; { end case }
  133.  
  134.                 Case hitY[m] of
  135.                      1 : inc(y[m],2);
  136.                      0 : dec(y[m],2);
  137.                 end; { end case }
  138.            end;  { end for\do }
  139.  
  140.            for m := 6 to 10 do
  141.            begin
  142.                 if (x[m] > 274) then hit[m] := 0;
  143.                 if (x[m] < 1)   then hit[m] := 1;
  144.                 if (y[m] > 186) then hitY[m]:= 0;
  145.                 if (y[m] < 1)   then hitY[m]:= 1;
  146.  
  147.                 Case hit[m] of
  148.                      1 : inc(x[m],1);
  149.                      0 : dec(x[m],1);
  150.                 end; { end case }
  151.  
  152.                 Case hitY[m] of
  153.                      1 : inc(y[m],1);
  154.                      0 : dec(y[m],1);
  155.                 end; { end case }
  156.            end;  { end for\do }
  157.  
  158.            for m := 11 to 14 do
  159.            begin
  160.                 if (x[m] > 294) then hit[m] := 0;
  161.                 if (x[m] < 1)   then hit[m] := 1;
  162.                 if (y[m] > 179) then hitY[m]:= 0;
  163.                 if (y[m] < 1)   then hitY[m]:= 1;
  164.  
  165.                 Case hit[m] of
  166.                      1 : inc(x[m],1);
  167.                      0 : dec(x[m],1);
  168.                 end; { end case }
  169.  
  170.                 Case hitY[m] of
  171.                      1 : inc(y[m],1);
  172.                      0 : dec(y[m],1);
  173.                 end; { end case }
  174.            end;  { end for\do }
  175.  
  176.            for m := 15 to 18 do
  177.            begin
  178.                 if (x[m] > 294) then hit[m] := 0;
  179.                 if (x[m] < 1)   then hit[m] := 1;
  180.                 if (y[m] > 179) then hitY[m]:= 0;
  181.                 if (y[m] < 1)   then hitY[m]:= 1;
  182.  
  183.                 Case hit[m] of
  184.                      1 : inc(x[m],2);
  185.                      0 : dec(x[m],2);
  186.                 end; { end case }
  187.  
  188.                 Case hitY[m] of
  189.                      1 : inc(y[m],2);
  190.                      0 : dec(y[m],2);
  191.                 end; { end case }
  192.            end;  { end for\do }
  193.  
  194.            for m := 19 to 21 do
  195.            begin
  196.                 if (x[m] > 294) then hit[m] := 0;
  197.                 if (x[m] < 1)   then hit[m] := 1;
  198.                 if (y[m] > 179) then hitY[m]:= 0;
  199.                 if (y[m] < 1)   then hitY[m]:= 1;
  200.  
  201.                 Case hit[m] of
  202.                      1 : inc(x[m],4);
  203.                      0 : dec(x[m],4);
  204.                 end; { end case }
  205.  
  206.                 Case hitY[m] of
  207.                      1 : inc(y[m],4);
  208.                      0 : dec(y[m],4);
  209.                 end; { end case }
  210.            end;  { end for\do }
  211.  
  212.            for m := 22 to 25 do
  213.            begin
  214.                 if (x[m] > 286) then hit[m] := 0;
  215.                 if (x[m] < 1)   then hit[m] := 1;
  216.                 if (y[m] > 172) then hitY[m]:= 0;
  217.                 if (y[m] < 1)   then hitY[m]:= 1;
  218.  
  219.                 Case hit[m] of
  220.                      1 : inc(x[m],3);
  221.                      0 : dec(x[m],3);
  222.                 end; { end case }
  223.  
  224.                 Case hitY[m] of
  225.                      1 : inc(y[m],3);
  226.                      0 : dec(y[m],3);
  227.                 end; { end case }
  228.            end;  { end for\do }
  229.  
  230.            { Put the images on the screen! }
  231.            for m:=1 to 10 do
  232.                PutClip(EMSPage(0)^, x[m], y[m], 15, 13);
  233.  
  234.            for m:=11 to 21 do
  235.                PutClip(EMSPage(1)^, x[m], y[m], 25, 21);
  236.  
  237.            for m:=22 to 25 do
  238.                PutClip(EMSPage(2)^, x[m], y[m], 33, 27);
  239.  
  240.            { Now update the screen with all of our new stuff }
  241.            Update;
  242.  
  243.      until keypressed;
  244.  
  245.      readkey;
  246.  
  247.      { Cleanup our mess and set the video mode back to text! }
  248.      VGFX_Done;
  249.  
  250.      { Free the EMS memory we allocated earlier }
  251.      EMSFree(handle);
  252.  
  253.      { Check for EMS error }
  254.      if (EMSResult>=$80) then
  255.      begin
  256.           { There was an EMS error, so display the description }
  257.           writeln('EMS Free Error:  ', EMS_ErrDesc[EMSResult]);
  258.           halt(1);
  259.      end
  260.      else
  261.          writeln('EMS memory freed, demo completed successfully.');
  262.  
  263.      writeln;
  264.      halt(0);
  265.  
  266. end.
  267.