// AltIOImp.decl -- Maxc2 Alto Imp driver definitions
// This version supports 96-bit leaders, NCP, Internet/TCP, Pup

//	Last modified April 23, 1981  1:08 PM

manifest
[
maxImpMessBits = 8160+	// Maximum leader+data bits per message
		16	// Imp end-of-message padding
maxImpMessWords = (maxImpMessBits+15)/16  // Maximum Alto words per message
maxMaxcWords = (maxImpMessBits+31)/32  // Maximum Maxc words per message
lenMaxcBuf = 3*maxMaxcWords  // Buffer size for Maxc memory transfers
maxLinkNCP = 71		// Highest NCP link
linkPup = 152		// Pup link number in Arpanet
linkInternet = 155	// Arpa Internet link
firstFakeHost = 252	// Fake host numbers start here

// Message Format codes
mfHost36 = 0		// Host-Host protocol, 36-bit format
mfHost32 = 1		// Host-Host protocol, 32-bit format
mfPup = 2		// Pup protocol, 32-bit format
mfRaw32 = 3		// Raw 32-bit format (e.g., Arpa Internet)
]


// Imp message structures

//----------------------------------------------------------------------------
structure ImpLeader:	// Imp-Host protocol leader (new format)
//----------------------------------------------------------------------------
[
blank bit 4		// word 0
format bit 4
net bit 8
blank bit 4		// word 1
trace bit 1
leaderFlags bit 3
messageType bit 8
handlingType bit 8 =	// word 2
   [ highPriority bit ]
host bit 8
imp bit 16		// word 3
messageID bit 12 =	// word 4
   [ link bit 8; linkX bit 4 ]
subType bit 4
messageLength bit 16	// word 5
]
manifest lenImpLeader = size ImpLeader/16

//----------------------------------------------------------------------------
structure HostLeader:	// Host-Host protocol leader
//----------------------------------------------------------------------------
[
impLeader word lenImpLeader = @ImpLeader  // words 0-5
blank byte		// word 6
byteSize byte
byteCount word		// word 7B
blank byte		// word 10B
]
// Note that HostLeader does not end on an Alto word boundary.

// Host-Host protocol message as seen by Maxc
// (AltIO must convert to and from this format):
// impLeader @ImpLeader	// 96 bits in 36-bit format (i.e., 2 words + 24 bits)
// blank bit 12		// fill out rest of Maxc word
// blank bit 4		// remnant of H-H "M1" field; 4 bits crunched out
// byteSize bit 8
// byteCount bit 16
// blank bit 8		// H-H "M2" field
// Body of message (36- or 32-bit format)

// Pup, Internet, and raw 32-bit messages as seen by Maxc
// (AltIO must convert to and from this format):
// impLeader @ImpLeader	// 96 bits in 36-bit format (i.e., 2 words + 24 bits)
// blank bit 12		// fill out rest of Maxc word
// Pup or Internet packet (always 32-bit format)

// Data structures

//----------------------------------------------------------------------------
structure IMB:		// Imp Message Buffer
//----------------------------------------------------------------------------
[
next word		// -> next IMB
length word		// Message length (words)
message word maxImpMessWords+3 =  // Extra 3 words for ImpConvFrom** slop
   @HostLeader =	// Host-Host protocol message
   [ @ImpLeader; pup @Pup ]  // Encapsulated Pup
]
manifest lenIMB = size IMB/16

//----------------------------------------------------------------------------
structure ImpPBI:	// Arpanet Pup encapsulation (well, not really....)
//----------------------------------------------------------------------------
[
blank word offset PBI.pup/16-2
blank byte
pupHost byte		// Aligned with source host of Ethernet encapsulation
blank word
pup @Pup
]

//----------------------------------------------------------------------------
structure Q: [ head word; tail word ]  // Queue header (for Queue Package)
//----------------------------------------------------------------------------

//----------------------------------------------------------------------------
structure ImpNDB:	// Arpanet NDB
//----------------------------------------------------------------------------
[
@NDB			// standard portion

inputIMB word		// -> current input Imp Message Buffer (0 = none)
outputIMB word		// -> current output Imp Message Buffer (0 = none)

freeInputIMBQ @Q	// Queue of free input IMBs
hostInputIMBQ @Q	// Queue of pending input Host-Host protocol IMBs
pupInputIMBQ @Q		// Queue of pending input Pup IMBs
freeOutputIMBQ @Q	// Queue of free output IMBs
hostOutputIMBQ @Q	// Queue of pending output Host-Host protocol IMBs
pupOQ @Q		// Queue of pending Pup output PBIs

flags word =
   [
   oActive bit		// Output is in progress
   iError bit		// Ready line dropped during input packet
   oError bit		// Ready line dropped during output packet
   sendingNop bit	// Nop being transmitted
   ]
status word =		// Bits 16-31 of status word reported to Maxc
   [
   blank bit 3
   powerOn bit		// Maxc bit 19 -- always one
   hostNotReady bit	// Maxc bit 20
   blank bit
   impNotReady bit	// Maxc bit 22
   ]
icb word		// -> Imp Control Block
]
manifest lenImpNDB = size ImpNDB/16

// Imp interface hardware and microcode definitions

//----------------------------------------------------------------------------
structure ImpStatus:	// Imp status word
//----------------------------------------------------------------------------
[
microcode byte		// microcode status
hardware byte =		// hardware status
   [
   blank bit 5
   impWasDown bit
   impNotReady bit
   hostNotReady bit
   ]
]

//----------------------------------------------------------------------------
structure ICB:		// Imp Control Block -- must be even-word aligned
//----------------------------------------------------------------------------
[
control word		// Control command
blank word
inputPointer word	// -> beginning of input buffer
inputEnd word		// -> word beyond end of input buffer
outputPointer word	// -> beginning of output buffer
outputEnd word		// -> word beyond end of output buffer
controlPost @ImpStatus	// Control post location
controlChanMask word	// Control interrupt channel mask
inputPost @ImpStatus	// Input post location
inputChanMask word	// Input interrupt channel mask
outputPost @ImpStatus	// Output post location
outputChanMask word	// Output interrupt channel mask
]
manifest lenICB = size ICB/16

manifest
[
// SIO commands for Imp control
impStartOutput = #1000	// Start output
impStartInput = #2000	// Start input
impControlStatus = #3000  // Control/Status

// Imp Control commands
icNoop = 0
icMasterReset = 1	// Clear wakeups, turn off transfers, but don't
			// touch the Host Ready relay
icSetLastWord = 2	// Set Last Word flipflop -- for microcode use only
icClearImpWasDown = 3	// Try to clear Imp Was Down flipflop
icLoopBackOn = 4	// Turn on Loop Back mode
icLoopBackOff = 5	// Turn off Loop Back mode
icHostReadyOn = 6	// Turn on Host Ready relay
icHostReadyOff = 7	// Turn off Host Ready relay
icDiscardOn = #2000	// Turn on Discard flipflop
icDiscardOff = #1000	// Turn off Discard flipflop

// Microcode status byte values
isDone = 1		// Input or output completed normally
isInputOverflow = 2	// Input buffer overflowed
isInputLengthZero = 3	// Input buffer length was zero at start of packet
]