-- Rapunzel.mesa
-- BJackson	11-Jan-88 11:13:00 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;

  SeqLong: TYPE = LONG DESCRIPTOR FOR ARRAY SeqLongIndex OF Long;
  SeqLongIndex: TYPE = CARDINAL;

  Address: TYPE = LONG CARDINAL;

  PeekShortCmd: TYPE = RECORD [address: Address];

  PokeShortCmd: TYPE = RECORD [address: Address, value: Short];

  PokeLongCmd: TYPE = RECORD [address: Address, value: Long];

  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), pokeLong(2), shftRead(3), shftWrite(4), returnLength(5), (CARDINAL.LAST - 1)};

  Cmd: TYPE = RECORD[ 
    SELECT tag: OpCode FROM
      peekShort => [peekShort: PeekShortCmd], 
      pokeShort => [pokeShort: PokeShortCmd], 
      pokeLong => [pokeLong: PokeLongCmd], 
      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 [];

  PokeLongResult: 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], 
      pokeLong => [pokeLong: PokeLongResult], 
      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];

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

  FreePeekSeqLongResults: PROCEDURE[bH: BindHandle, resultSeq: LONG POINTER TO SeqLong];

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

  WriteSequential: PROCEDURE [
    bH: BindHandle, startingAddress: Address, count: CARDINAL, seq: LONG POINTER TO SeqLong];

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

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



  }.