-- Copyright (C) 1983, 1985  by Xerox Corporation. All rights reserved. 
-- RealMemoryImplDicentra.mesa, HGM,  3-Jul-85  3:35:39

DIRECTORY
  Environment USING [bitsPerWord, PageCount, PageNumber],
  PageMap USING [flagsVacant, GetState, RealPageNumber, State],
  RealMemory USING [],
  RealMemoryExtras USING [],
  
  DicentraInputOutput USING [numberVirtualPages];

RealMemoryImplDicentra: PROGRAM
  IMPORTS PageMap EXPORTS RealMemory, RealMemoryExtras SHARES PageMap =
  BEGIN

  maxDicentraRealPages: CARDINAL = 4096;  -- More requires Map format changes

  allocMap: PUBLIC DESCRIPTOR FOR ARRAY OF WORD ← DESCRIPTOR[allocMapArray];
  allocMapArray: ARRAY [
    0..(maxDicentraRealPages + Environment.bitsPerWord - 1)/Environment.bitsPerWord)
    OF WORD;  -- initial state not important

  Bug: ERROR [type: BugType] = CODE;
  BugType: TYPE = {allocMapTooSmall};
  
  
  Initialize: PUBLIC PROCEDURE = {};  -- initializes exported array desc.
  
  --RealMemory.--Count: PUBLIC PROCEDURE
    RETURNS [
      count: Environment.PageCount,
      realPageMin, realPageMax: PageMap.RealPageNumber] =
    BEGIN
    virtual: Environment.PageNumber;
    state: PageMap.State;
    real: PageMap.RealPageNumber;
    count ← 0;
    realPageMin ← LAST[PageMap.RealPageNumber];
    realPageMax ← FIRST[PageMap.RealPageNumber];
    FOR virtual IN [0..DicentraInputOutput.numberVirtualPages) DO
      [state, real] ← PageMap.GetState[virtual];
      IF state.flags~=PageMap.flagsVacant THEN {
	count ← SUCC[count];
        realPageMin ← MIN[realPageMin, real];
        realPageMax ← MAX[realPageMax, real] };
      ENDLOOP;
    IF realPageMax >= maxDicentraRealPages THEN Bug[allocMapTooSmall];
    END;

  FreeReservedMemory: PUBLIC PROCEDURE [
     keep: Environment.PageCount, bufferPage: Environment.PageNumber] = {};
  -- This procedure is a no-op on all processors other than the Dandelion.

  MoveIntervalToDisplayMemory: PUBLIC PROCEDURE [
    page: Environment.PageNumber, count: Environment.PageCount,
    bufferPage: Environment.PageNumber] = {};
  -- This procedure is a no-op on all processors other than the Dandelion.

  SpecialResidentCodeHandle: PUBLIC PROCEDURE = {};
  -- This procedure's only purpose is to provide a handle on the Heads CODE PACK
  -- which contains resident code which may be moved to reserved memory.

  PCBank: PUBLIC --RealMemoryExtras.-- PROC RETURNS [
    firstPCBankPage: PageMap.RealPageNumber, lastPCBankPagePlusOne: PageMap.RealPageNumber] =
    BEGIN
    firstPCBankPage ← lastPCBankPagePlusOne ← 0;
    END;

  END.