-- File: [Indigo]<Sakura>Dragon>DragonMapImpl.sak
-- 14-Mar-82 19:37:18

DIRECTORY
  DragonCache: TYPE, 
  DragonMap: TYPE, 
  SakuraRT: TYPE;

DragonMapImpl: MONITOR
  IMPORTS SakuraRT
  EXPORTS DragonMap
  
  = BEGIN
  MapProcessor: PUBLIC PROC
       [ClockA, ClockB, CMDIn: SakuraRT.Handle, MDataIn: SakuraRT.Handle, 
        CMDOut: SakuraRT.Handle, MDataOut: SakuraRT.Handle] = {
    {ENABLE {ABORTED => GO TO Aborted};
     DO SakuraRT.GetNew[ClockB, TRUE]; NULL; 
        IF NARROW[SakuraRT.Get[CMDIn], REF BOOLEAN]↑ THEN 
           WITH m: NARROW[SakuraRT.Get[MDataIn], REF DragonCache.MbusType]↑ SELECT FROM 
             Instruction => 
               SELECT m.command FROM 
                 ReadQuad => NULL;
                 WriteQuad => NULL;
                 WriteSingle => NULL;
                 NotReady => ERROR;
                 ReadMap => ERROR;
                 ReadMapAndSetRpDirty => ERROR;
                 DoMapOp => ERROR;
                 SetRpDirty => 
                   {SakuraRT.GetNew[ClockA, TRUE];
                     SakuraRT.Put[CMDOut, NEW[BOOLEAN ← TRUE]]; 
                    SakuraRT.Put[MDataOut, NEW
                      [DragonCache.MbusType ← [MapCommand[MapOpDone, , , , ]]]]; 
                    SakuraRT.GetNew[ClockA, TRUE];
                     SakuraRT.Put[CMDOut, NEW[BOOLEAN ← FALSE]]};
                 MapOpDone => ERROR
                 ENDCASE;
             MapCommand => 
               SELECT m.command FROM 
                 ReadMap => 
                   {SakuraRT.GetNew[ClockB, TRUE];
                     SakuraRT.Put[CMDOut, NEW[BOOLEAN ← TRUE]]; 
                    SakuraRT.Put[MDataOut, NEW
                      [DragonCache.MbusType ← 
                         [MapCommand[MapOpDone, , FALSE, FALSE, m.vp]]]]; 
                    SakuraRT.GetNew[ClockA, TRUE];
                     SakuraRT.Put[CMDOut, NEW[BOOLEAN ← FALSE]]};
                 ReadMapAndSetRpDirty => 
                   {SakuraRT.GetNew[ClockB, TRUE];
                     SakuraRT.Put[CMDOut, NEW[BOOLEAN ← TRUE]]; 
                    SakuraRT.Put[MDataOut, NEW
                      [DragonCache.MbusType ← 
                         [MapCommand[MapOpDone, , FALSE, TRUE, m.vp]]]]; 
                    SakuraRT.GetNew[ClockA, TRUE];
                     SakuraRT.Put[CMDOut, NEW[BOOLEAN ← FALSE]]};
                 ReadQuad => NULL;
                 MapOpDone => NULL
                 ENDCASE => ERROR;
             Data => ERROR
             ENDCASE => ERROR
        ENDLOOP; 
     SakuraRT.ProcessEnd[]}
    EXITS
      Aborted => SakuraRT.Abort[]};
  
  END.