program Mem_test;

uses Memory,crt,gifunit;

var xmsh : array[1..2] of XMSHandle;
    emsh : array[1..2] of EMSHandle;

procedure xms_test;
var ta : array[1..20] of word;
    li : integer;
begin;
  { Provide array with numbers & and output for testing purposes }
  gotoxy(1,5); write('Original: ');
  for li := 1 to 20 do begin;
    ta[li] := li;
    gotoxy(14,li+4);
    write(ta[li]);
  end;
  readln;

  { Store array in XMS, fill with 0 and output }
  gotoxy(21,5); write('Stored in XMS &');
  gotoxy(21,6); write('filled with 0:');
  Getmem_XMS(xmsh[1],40);
  RAM_2_XMS(@ta,xmsh[1],40);
  fillchar(ta,40,0);
  for li := 1 to 20 do begin;
    gotoxy(44,li+4);
    write(ta[li]);
  end;
  readln;

  { Copy memory to XMS, restore array from copy in XMS }
  gotoxy(54,5); write('Restored from');
  gotoxy(54,6); write('XMS: ');
  Getmem_XMS(xmsh[2],40);
  XMS_2_XMS(xmsh[1],xmsh[2],40);
  XMS_2_RAM(@ta,xmsh[2],40);
  for li := 1 to 20 do begin;
    gotoxy(74,li+4);
    write(ta[li]);
  end;
  readln;
  Freemem_XMS(xmsH[1]);
  Freemem_XMS(xmsH[2]);
end;

procedure Ems_test;
var ta : array[1..20] of word;
    li : integer;
    picptr : pointer;
begin;
  getmem(picptr,64000);
  Init_ModeX;
  blackpal;
  LoadGif('example.gif',picptr,0,0);
  Getmem_EMS(emsh[1],64000);
  RAM_2_EMS(picptr,emsh[1],64000);
  freemem(picptr,64000);

  getmem(vscreen,64000);
  fillchar(vscreen^,64000,123);
  EMS_2_RAM(vscreen,emsh[1],64000);
  p13_2_modex(0,16000);
  setpal;
  readln;

  freemem(vscreen,64000);
  Freemem_EMS(emsH[1]);
  asm mov ax,0003;  int 10h;  end;
end;

begin;
  clrscr;
  writeln('Program for demonstration of the  > MEMORY  < unit');
  writeln('(c) 1994 by DATA BECKER/ABACUS    Author: Boris Bertelsons');
  writeln;
  writeln('Free base memory  : ',Base_Free,' Bytes');
  writeln('Free XMS          : ',XMS_Free,' Bytes');
  writeln('Free EMS          : ',EMS_Free,' Bytes');
  writeln('XMS Version       : ',hi(XMS_Version),'.',lo(XMS_Version));
  writeln('EMS Version       : ',hi(EMS_Version),'.',lo(EMS_Version));
  readln;
  clrscr;
  writeln('Program for demonstration of the  > MEMORY  < unit');
  writeln('(c) 1994 by DATA BECKER/ABACUS    Author: Boris Bertelsons');
  writeln;
  writeln('                     X   M   S     -   T  E  S  T');
  if XMS_Available then
    xms_test
  else
    writeln('No XMS memory available !');
  clrscr;
  writeln('Program for demonstration of the  > MEMORY  < unit');
  writeln('(c) 1994 by DATA BECKER/ABACUS    Author: Boris Bertelsons');
  writeln;
  writeln('                     E   M   S     -   T  E  S  T');
  if EMS_Available then
    ems_test
  else
    writeln('No EMS memory available !');
end.
