RapunzelTestServer.mesa
Copyright © 1986 by Xerox Corporation. All rights reserved.
Demers, September 18, 1986 6:09:28 pm PDT
Willie-Sue, January 8, 1987 3:33:02 pm PST
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...