-- Rapunzel.mesa
-- Demo	 9-Jan-87 14:02:33 PST

DIRECTORY System;

Rapunzel: DEFINITIONS
 = {

  BindHandle: TYPE = LONG POINTER TO READONLY BindObject;
  BindObject: TYPE;

  Short: TYPE = CARDINAL;

  Long: TYPE = LONG CARDINAL;

  SeqShort: TYPE = LONG DESCRIPTOR FOR ARRAY SeqShortIndex OF Short;
  SeqShortIndex: TYPE = CARDINAL;

  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];

  OpCode: TYPE = MACHINE DEPENDENT {peekShort(0), pokeShort(1), shftRead(2), shftWrite(3), returnLength(4), (CARDINAL.LAST - 1)};

  Cmd: TYPE = RECORD[ 
    SELECT tag: OpCode FROM
      peekShort => [peekShort: PeekShortCmd], 
      pokeShort => [pokeShort: PokeShortCmd], 
      shftRead => [shftRead: ShftReadCmd], 
      shftWrite => [shftWrite: ShftWriteCmd], 
      returnLength => [returnLength: ReturnLengthCmd],
      ENDCASE];

  SeqCmd: TYPE = LONG DESCRIPTOR FOR ARRAY SeqCmdIndex OF Cmd;
  SeqCmdIndex: TYPE = CARDINAL;

  PeekShortResult: TYPE = RECORD [value: Short];

  PokeShortResult: TYPE = RECORD [];

  ShftReadResult: TYPE = RECORD [numRepeats: Short];

  ShftWriteResult: TYPE = RECORD [numRepeats: Short];

  ReturnLengthResult: TYPE = RECORD [];

  Result: TYPE = RECORD[ 
    SELECT tag: OpCode FROM
      peekShort => [peekShort: PeekShortResult], 
      pokeShort => [pokeShort: PokeShortResult], 
      shftRead => [shftRead: ShftReadResult], 
      shftWrite => [shftWrite: ShftWriteResult], 
      returnLength => [returnLength: ReturnLengthResult],
      ENDCASE];

  SeqResult: TYPE = LONG DESCRIPTOR FOR ARRAY SeqResultIndex OF Result;
  SeqResultIndex: TYPE = CARDINAL;

  Fault: ERROR [
    bH: BindHandle, code: FaultCode, address: Address];

  FaultCode: TYPE = MACHINE DEPENDENT {nonexistent(1), protection(2), alignmentShort(3), alignmentLong(4), (CARDINAL.LAST - 1)};

  PeekShort: PROCEDURE [
    bH: BindHandle, address: Address]
    RETURNS [result: Short];

  PokeShort: PROCEDURE [
    bH: BindHandle, address: Address, value: Short];

  PeekSeqShort: PROCEDURE [
    bH: BindHandle, address: Address, count: CARDINAL]
    RETURNS [resultSeq: LONG POINTER TO SeqShort];

  FreePeekSeqShortResults: PROCEDURE[bH: BindHandle, resultSeq: LONG POINTER TO SeqShort];

  PokeSeqShort: PROCEDURE [
    bH: BindHandle, address: Address, valueSeq: LONG POINTER TO SeqShort];

  PeekLong: PROCEDURE [
    bH: BindHandle, address: Address]
    RETURNS [result: Long];

  PokeLong: PROCEDURE [
    bH: BindHandle, address: Address, value: Long];

  DoCmds: PROCEDURE [
    bH: BindHandle, cmdSeq: LONG POINTER TO SeqCmd]
    RETURNS [resultSeq: LONG POINTER TO SeqResult];

  FreeDoCmdsResults: PROCEDURE[bH: BindHandle, resultSeq: LONG POINTER TO SeqResult];

  SetShftAddrs: PROCEDURE [
    bH: BindHandle, shftA, shftB: Address];

  RemoteBind: PROCEDURE [
    host: System.NetworkAddress, zone: UNCOUNTED ZONE ← NIL]
    RETURNS[bH: BindHandle];

  RemoteUnbind: PROCEDURE[bH: BindHandle] RETURNS [nil: BindHandle];



  }.