(* * * * * * * * * * * * * * * * * * *
 *
 * prog4-1.pas
 *
 *      Demonstrates
 *          - Get number of mappable pages
 *          - Get addresses of mappable pages
 *
 * * * * * * * * * * * * * * * * * * *)

program prog4_1;

uses    _globals,
        _ems;


var
    ems:                EMS_Ems;

    numMappablePages:   Word;
    numMappablePages2:  Word;

    i:                  Word;


    pageAddress:       ^EMS_MappablePagesInfoArr;

begin

    (*
     *  First check for presence of EMS
     *)
    if ems.init then begin
        writeln('EMS is not present');
        Halt;
        end;

    (*
     *  Find out how many mappable pages we have all together. In
     *  4.0, we do not have a fixed size page frame, we may have
     *  many more than 4 mappable pages.
     *)
    if ems.getNumMappable40(numMappablePages) then begin
        ems_demoError('EMS_Ems.getNumMappable40');
        end;

    (*
     *  Now allocate a buffer big enough to hold the addresses
     *  of these pages.
     *)
    GetMem(pageAddress, sizeof(EMS_MappablePagesInfo) * numMappablePages);

    (*
     *  Get the info
     *)
    if ems.getAddrsMappable40(pageAddress^, numMappablePages2) then begin
        ems_demoError('EMS_Ems.getAddrsMappable40');
        end;

    (*
     *  Sanity check that the page counts match.
     *)
    if numMappablePages <> numMappablePages2 then begin
        writeln('There is something really wrong here!');
        Halt;
        end;

    (*
     *  Now print the info out:
     *)
    writeln('ÉÍÍÍÍSegmentÍAddressÍÍÍÍÍÑÍÍÍÍPhysicalÍPageÍ#ÍÍÍÍÍ»');

    for i:= 0 to numMappablePages-1 do begin
        writeln('º         0x',
                hex(pageAddress^[i].pageSegment, 4),
                '         ³          ',
                pageAddress^[i].physNumber:4,
                '          º');

        if i < numMappablePages-1 then begin
            writeln('ÇÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¶');
            end;
        end;
    writeln('ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÏÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ¼');
end.

