/*
 * $Header: /smsa/bsd:include/dev/econetmc.h:bsd  1.14  $
 * $Source: /smsa/bsd:include/dev/econetmc.h: $
 *
 * Copyright (c) 1988 Acorn Computers Ltd., Cambridge, England
 */
/* econetmc.h <- Common things between econet.c and econetmc.s -> econetmc.h */

#ifndef __dev_econetmc_h
#define __dev_econetmc_h

/* this file generally describes things which are shared between the C code
 * in econet.c and the assembler code in econetmc.s.
 */

/* now structures for controlling enabled receptions */

#ifdef __C_econet

typedef struct rx_control {
  struct rx_control *next;
  unsigned char station, net, dummy, port; /* to make four of them == one int */
  int anyone_waiting;
  int minor_device;
  int max_buffers, used_buffers;
  int wait_timeout;
  struct rx_control *rx_group;
} *rx_control_list;

#endif

#ifdef __S_econet

#define rx_control_next             0
#define rx_control_station          4
#define rx_control_net              5
#define rx_control_port             7
#define rx_control_anyone_waiting   8
#define rx_control_minor_device    12
#define rx_control_max_buffers     16
#define rx_control_used_buffers    20

#endif

/* structures for controlling the status of the array of buffers we use
 * for reception.
 */

#ifdef __C_econet

typedef struct buffer {
  struct buffer *next;
  int status;
  unsigned char station, net, control, port;
  struct rx_control *receiver;
  int data_length;
  int time_received;
  int dataBytes;
} *buffer_control_ptr;

#endif

#ifdef __S_econet

#define buffer_next                 0
#define buffer_status               4
#define buffer_things               8
#define buffer_station              8
#define buffer_net                  9
#define buffer_control             10
#define buffer_port                11
#define buffer_receiver            12
#define buffer_data_length         16
#define buffer_time_received       20
#define buffer_data                24

#endif

/* it will help if we constrain both these to multiples of four */
/* and nice data-op immediable constants.                       */
#define SmallBufferSize  200
#define LargeBufferSize 1280


/*  receptionstatus =
 *    ( TxAllOK, TxInitialValue, TxStartedOK, TxNotListening, TxFiqsLost,
 *      ReadyToReceive, Receiving, Signalling, Received, Reserved
 *    );
 * the Tx ones can be returned by Transmit, in a CARDINAL.
 */


#define TxStatus_AllOk          1
#define TxStatus_InitialValue   2
#define TxStatus_StartedOK      3
#define TxStatus_NoClock        4
#define TxStatus_NotListening   5
#define TxStatus_FiqsLost       6

#define RxStatus_RxReady       20
#define RxStatus_Receiving     21
#define RxStatus_Signalling    22
#define RxStatus_Received      23
#define RxStatus_Reserved      24

/* now the record used to start a transmission off */

#ifdef __C_econet

typedef struct tx {
  int status;
  unsigned char station, net, control, port;
  unsigned char *data;
  int length;
} *tx_ptr;

#endif

#ifdef __S_econet

#define tx_status               0
#define tx_station              4
#define tx_net                  5
#define tx_control              6
#define tx_port                 7
#define tx_data                 8
#define tx_length              12

#endif

/* and the static record containing all our workspace etc. */

#ifdef __C_econet

struct econet_state {
  unsigned char thisStation, thisNet, rxMode, dummy;
  rx_control_list aliveChain;
  buffer_control_ptr largeBuffers;
  buffer_control_ptr smallBuffers;
  int thisLargeB,
      thisSmallB,
      thisRecord,
      nextJump,
      scoutBuffer;
  char
      broadcastBuffer[1024];
};

#endif

#ifdef __S_econet

#define BroadcastSize 1024
#define LongScoutSize    8
#define ScoutSize        4

#define WORD + 4
#define BYTE + 1
#define EQUAL

thisStation_O		.equ 0
thisNet_O		.equ thisStation_O		BYTE /* so we might use similar code for bridges? */
rxMode_O		.equ thisNet_O			BYTE /* flags */

aliveChain_O		.equ 4
largeBuffers_O		.equ aliveChain_O		WORD
smallBuffers_O		.equ largeBuffers_O		WORD
thisLargeB_O		.equ smallBuffers_O		WORD
thisSmallB_O		.equ thisLargeB_O		WORD
thisRecord_O		.equ thisSmallB_O		WORD
nextJump_O	 	.equ thisRecord_O		WORD
scoutBuffer_O		.equ nextJump_O			WORD
scoutFromStation_O	.equ scoutBuffer_O		EQUAL
scoutFromNet_O		.equ scoutFromStation_O		BYTE
scoutControl_O		.equ scoutFromNet_O		BYTE
scoutPort_O		.equ scoutControl_O		BYTE
broadcastBuffer_O	.equ scoutPort_O		BYTE /* these must be contiguous! */
endBroadcastBuffer_O	.equ broadcastBuffer_O		BYTE * BroadcastSize /* Apparently 1k broadcasts are de rigeur */

#endif

/* bits in RxMode */
#define TxBit		(0x01)
#define RxBit		(0x02)
#define BroadcastBit	(0x04)
#define ThisRecValid	(0x08)
#define ImmedOpBit	(0x10)
/* spare                (0x20) */
#define NoClockBit      (0x40)
#define NoHardwareBit	(0x80)
/* nb outside we assume that zero in rxMode means quietly waiting to Rx */
#define RxModeClearBits (0x3F)

#endif/*__dev_econetmc_h*/

/* EOF econetmc.h */
