-- Rapunzel0.cr
	-- Copyright c 1986 by Xerox Corporation.  All rights reserved.
	-- Demers, September 18, 1986 5:39:53 pm PDT
	-- Willie-Sue, January 8, 1987 11:32:03 am PST

Rapunzel: PROGRAM 2200 VERSION 2
	= BEGIN
	-- Introduction
		-- This package provides generic remote peek and poke operations for 16-bit and 32-bit entities.
		-- Word Order: For either Short (n = 16) or Long (n = 32), an n-bit number on the source machine is mapped to (the same) n-bit number in standard representation on the wire, which is mapped to (the same) n-bit number on the target machine.
	-- Types
		Short: TYPE = CARDINAL;
		Long: TYPE = LONG CARDINAL;
		
		SeqShort: TYPE = SEQUENCE OF Short;
		
		Address: TYPE = LONG CARDINAL;
		
		PeekShortCmd: TYPE = RECORD [address: Address];
		PokeShortCmd: TYPE = RECORD [address: Address, value: Short];
		ShftReadCmd: TYPE = RECORD [address: Address, numRepeats: Short];
		ShftWriteCmd: TYPE = RECORD [address: Address, numRepeats: Short];
		ReturnLengthCmd: TYPE = RECORD [returnLength: Short];	-- ignored if not the first Cmd
		
		OpCode: TYPE = { peekShort(0), pokeShort(1), shftRead(2), shftWrite(3), returnLength(4) };
		
		Cmd: TYPE = CHOICE OpCode OF {
			peekShort => PeekShortCmd,
			pokeShort => PokeShortCmd,
			shftRead => ShftReadCmd,
			shftWrite => ShftWriteCmd,
			returnLength => ReturnLengthCmd
			};
		SeqCmd: TYPE = SEQUENCE OF Cmd;
		
		PeekShortResult: TYPE = RECORD [value: Short];
		PokeShortResult: TYPE = RECORD [];
		ShftReadResult: TYPE = RECORD [numRepeats: Short];
		ShftWriteResult: TYPE = RECORD [numRepeats: Short];
		ReturnLengthResult: TYPE = RECORD [];
		
		Result: TYPE = CHOICE OpCode OF {
			peekShort => PeekShortResult,
			pokeShort => PokeShortResult,
			shftRead => ShftReadResult,
			shftWrite => ShftWriteResult,
			returnLength => ReturnLengthResult
			};
		SeqResult: TYPE = SEQUENCE OF Result;
	-- Errors
		Fault: ERROR [code: FaultCode, address: Address] = 0;
		FaultCode: TYPE = {
			nonexistent(1),	-- the referenced memory location does not exist
			protection(2),	-- access denied (can't happen with Softcard?)
			alignmentShort(3),	-- alignment error for Short (can't happen with 6085)
			alignmentLong(4)	-- alignment error for Long
			};
		
	-- Procedures
		-- Procedure 0 is reserved for address lookup - not used at the moment
		
		PeekShort: PROCEDURE [address: Address]
			RETURNS [result: Short]
			REPORTS [Fault]
			= 1;
			
		PokeShort: PROCEDURE [address: Address, value: Short]
			REPORTS [Fault]
			= 2;
		
		PeekSeqShort: PROCEDURE [address: Address, count: CARDINAL]
			RETURNS [resultSeq: SeqShort]
			REPORTS [Fault]
			= 3;
			
		PokeSeqShort: PROCEDURE [address: Address, valueSeq: SeqShort]
			REPORTS [Fault]
			= 4;
		
		PeekLong: PROCEDURE [address: Address]
			RETURNS [result: Long]
			REPORTS [Fault]
			= 5;
			
		PokeLong: PROCEDURE [address: Address, value: Long]
			REPORTS [Fault]
			= 6;
		
		DoCmds: PROCEDURE [cmdSeq: SeqCmd]
			RETURNS [resultSeq: SeqResult]
			REPORTS [Fault]
			= 7;
			
		SetShftAddrs: PROCEDURE[shftA, shftB: Address]
			REPORTS [Fault]
			= 8;
		
	END.