-- Rapunzel0.cr
	-- Copyright c 1986 by Xerox Corporation.  All rights reserved.
	-- Demers, September 18, 1986 5:39:53 pm PDT
	-- Willie-Sue, September 22, 1986 1:26:35 pm PDT

Rapunzel: PROGRAM 2200 VERSION 0
	= 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;
		SeqLong: TYPE = SEQUENCE OF Long;
		
		Address: TYPE = LONG CARDINAL;
		
		OpCode: TYPE = { pokeShort(0), peekShort(1) };
		
		PokeShortCmd: TYPE = RECORD [address: Address, value: Short];
		PeekShortCmd: TYPE = RECORD [address: Address];
		
		Cmd: TYPE = CHOICE OpCode OF {
			pokeShort => PokeShortCmd,
			peekShort => PeekShortCmd };
		SeqCmd: TYPE = SEQUENCE OF Cmd;
		
		PokeShortResult: TYPE = RECORD [];
		PeekShortResult: TYPE = RECORD [value: Short];
		
		Result: TYPE = CHOICE OpCode OF {
			pokeShort => PokeShortResult,
			peekShort => PeekShortResult };
		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
		DoCmds: PROCEDURE [cmds: SeqCmd]
			RETURNS [results: SeqResult]
			REPORTS [Fault]
			= 0;
			
		PeekShort: PROCEDURE [address: Address]
			RETURNS [result: Short]
			REPORTS [Fault]
			= 1;
			
		PokeShort: PROCEDURE [address: Address, arg: Short]
			REPORTS [Fault]
			= 2;
		
		PeekSeqShort: PROCEDURE [address: Address, count: CARDINAL]
			RETURNS [results: SeqShort]
			REPORTS [Fault]
			= 3;
			
		PokeSeqShort: PROCEDURE [address: Address, args: SeqShort]
			REPORTS [Fault]
			= 4;
		
		PeekLong: PROCEDURE [address: Address]
			RETURNS [result: Long]
			REPORTS [Fault]
			= 5;
			
		PokeLong: PROCEDURE [address: Address, arg: Long]
			REPORTS [Fault]
			= 6;
			
	END.