-- Rapunzel0.cr
	-- Copyright c 1986 by Xerox Corporation.  All rights reserved.
	-- Demers, September 18, 1986 5:39:53 pm PDT
	-- Willie-Sue, October 9, 1986 5:56:52 pm PDT

Rapunzel: PROGRAM 2200 VERSION 1
	= 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;
		
		OpCode: TYPE = { peekShort(0), pokeShort(1) };
		
		PeekShortCmd: TYPE = RECORD [address: Address];
		PokeShortCmd: TYPE = RECORD [address: Address, value: Short];
		
		Cmd: TYPE = CHOICE OpCode OF {
			peekShort => PeekShortCmd,
			pokeShort => PokeShortCmd };
		SeqCmd: TYPE = SEQUENCE OF Cmd;
		
		PeekShortResult: TYPE = RECORD [value: Short];
		PokeShortResult: TYPE = RECORD [];
		
		Result: TYPE = CHOICE OpCode OF {
			peekShort => PeekShortResult,
			pokeShort => PokeShortResult };
		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
		Foo: PROCEDURE
		   REPORTS [Fault]
		   = 0;
		
		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;
			
	END.