<> <> <> <> DIRECTORY Basics USING [LongNumber], CrRPC USING [Handle], RapunzelP2200V2; RapunzelTestServer: CEDAR PROGRAM EXPORTS RapunzelP2200V2 ~ BEGIN OPEN Rapunzel: RapunzelP2200V2; memSize: CARD ~ 1024; Mem: TYPE ~ ARRAY [0..memSize) OF CARDINAL; mem: REF Mem _ NIL; shftAAddr: Rapunzel.Address _ 0; shftBAddr: Rapunzel.Address _ 0; Init: PROC ~ { IF mem = NIL THEN mem _ NEW[Mem _ ALL[0]] }; Fault: PUBLIC ERROR [code: Rapunzel.FaultCode, address: Rapunzel.Address] ~ CODE; DoCmds: PUBLIC PROC [h: CrRPC.Handle, cmdSeq: Rapunzel.SeqCmd] RETURNS [resultSeq: Rapunzel.SeqResult] ~ { resLength: CARDINAL; resIndex: CARDINAL _ 0; cmdIndex: CARDINAL _ 0; BEGIN this: Rapunzel.Cmd = cmdSeq[0]; WITH this: this SELECT FROM returnLength => resLength _ this.returnLength.returnLength; ENDCASE => resLength _ cmdSeq.length; END; resultSeq _ NEW[Rapunzel.SeqResultObject[resLength]]; WHILE cmdIndex < cmdSeq.length DO this: Rapunzel.Cmd = cmdSeq[cmdIndex]; cmdIndex _ cmdIndex + 1; WITH this: this SELECT FROM peekShort => { address: Rapunzel.Address = this.peekShort.address; IF address >= memSize THEN ERROR Fault[nonexistent, address]; TRUSTED { res: Rapunzel.PeekShortResult _ [mem[address]]; resultSeq[resIndex] _ [peekShort[res]]; resIndex _ resIndex + 1; }; }; pokeShort => { address: Rapunzel.Address = this.pokeShort.address; res: pokeShort Rapunzel.Result = NULL; IF address >= memSize THEN ERROR Fault[nonexistent, address]; mem[address] _ this.pokeShort.value; TRUSTED { resultSeq[resIndex] _ res }; resIndex _ resIndex + 1; }; shftRead => { address: Rapunzel.Address = this.shftRead.address; numRepeats: Rapunzel.Short = this.shftRead.numRepeats; res: Rapunzel.ShftReadResult = [numRepeats]; IF address >= memSize THEN ERROR Fault[nonexistent, address]; TRUSTED { resultSeq[resIndex] _ [shftRead[res]] }; resIndex _ resIndex + 1; FOR j: CARDINAL IN [0..numRepeats) DO res: Rapunzel.PeekShortResult; res _ [mem[shftAAddr]]; res _ [mem[shftBAddr]]; res _ [mem[address]]; TRUSTED { resultSeq[resIndex] _ [peekShort[res]] }; resIndex _ resIndex + 1; ENDLOOP; }; shftWrite => { address: Rapunzel.Address = this.shftWrite.address; numRepeats: Rapunzel.Short = this.shftWrite.numRepeats; res: Rapunzel.ShftWriteResult = [numRepeats]; IF address >= memSize THEN ERROR Fault[nonexistent, address]; TRUSTED { resultSeq[resIndex] _ [shftWrite[res]] }; resIndex _ resIndex + 1; FOR j: CARDINAL IN [0..numRepeats) DO writeVal: Rapunzel.Cmd = cmdSeq[cmdIndex]; cmdIndex _ cmdIndex + 1; WITH writeVal: writeVal SELECT FROM pokeShort => { res: Rapunzel.PeekShortResult; mem[address] _ writeVal.pokeShort.value; res _ [mem[shftAAddr]]; res _ [mem[shftBAddr]]; }; ENDCASE => ERROR Fault[nonexistent, 0]; ENDLOOP; }; returnLength => NULL; ENDCASE => ERROR Fault[nonexistent, 0]; ENDLOOP; }; SetShftAddrs: PUBLIC PROC [h: CrRPC.Handle, shftA, shftB: Rapunzel.Address] ~ { shftAAddr _ shftA; shftBAddr _ shftB; }; PeekShort: PUBLIC PROC [h: CrRPC.Handle, address: Rapunzel.Address] RETURNS [result: Rapunzel.Short] ~ { IF address >= memSize THEN ERROR Fault[nonexistent, address]; RETURN [mem[address]]; }; PokeShort: PUBLIC PROC[ h: CrRPC.Handle, address: Rapunzel.Address, value: Rapunzel.Short] ~ { IF address >= memSize THEN ERROR Fault[nonexistent, address]; mem[address] _ value; }; PeekSeqShort: PUBLIC PROC [h: CrRPC.Handle, address: Rapunzel.Address, count: CARDINAL] RETURNS [resultSeq: Rapunzel.SeqShort] ~ { ERROR Fault[nonexistent, 0]; }; PokeSeqShort: PUBLIC PROC [ h: CrRPC.Handle, address: Rapunzel.Address, valueSeq: Rapunzel.SeqShort] ~ { ERROR Fault[nonexistent, 0]; }; PeekLong: PUBLIC PROC [h: CrRPC.Handle, address: Rapunzel.Address] RETURNS [result: Rapunzel.Long] ~ { x: Basics.LongNumber; IF address >= (memSize - 1) THEN ERROR Fault[nonexistent, address]; TRUSTED { x.lo _ mem[address]; x.hi _ mem[address+1]; result _ x.lc }; }; PokeLong: PUBLIC PROC[ h: CrRPC.Handle, address: Rapunzel.Address, value: Rapunzel.Long] ~ { x: Basics.LongNumber; IF address >= (memSize - 1) THEN ERROR Fault[nonexistent, address]; x.lc _ value; mem[address] _ x.lo; mem[address+1] _ x.hi; }; Init[]; END... <<>>