// AltIOImpInit.bcpl -- Maxc2 Alto Imp driver initialization

//	Last modified April 20, 1978  8:01 PM

get "Pup0.decl"
get "AltIOImp.decl"

external
[
// Outgoing procedures
InitAltoImp

// Incoming procedures
EncapsulateImpPup; SendImpPacket; ImpReset
ImpInputInterrupt; ImpOutputInterrupt; ImpProcess
InitializeInterrupt; FindInterruptMask; InitializeContext
Allocate; Zero; Enqueue; FalsePredicate

// Incoming statics
impNDB; ndbQ; impMaxcBuf
]

manifest
[
numInputIMBs = 2
numOutputIMBs = 2
lenIntStack = 75
lenProcStack = 75
]

//----------------------------------------------------------------------------
let InitAltoImp(zone, ctxQ) be
//----------------------------------------------------------------------------
[
impNDB = Allocate(zone, lenImpNDB)
Zero(impNDB, lenImpNDB)
impNDB>>ImpNDB.encapsulatePup = EncapsulateImpPup
impNDB>>ImpNDB.level0Transmit = SendImpPacket
impNDB>>ImpNDB.level0Stats = FalsePredicate
impNDB>>ImpNDB.netType = netTypeArpa
Enqueue(ndbQ, impNDB)

// Make some free Imp Message Buffers
for i = 1 to numInputIMBs do
   Enqueue(lv impNDB>>ImpNDB.freeInputIMBQ, Allocate(zone, lenIMB))
for i = 1 to numOutputIMBs do
   Enqueue(lv impNDB>>ImpNDB.freeOutputIMBQ, Allocate(zone, lenIMB))
impMaxcBuf = Allocate(zone, lenMaxcBuf)

// Set up Imp Control Block
let icb = Allocate(zone, lenICB, false, true)  // even word
impNDB>>ImpNDB.icb = icb
Zero(icb, lenICB)

// Initialize interrupts
icb>>ICB.inputChanMask = InitializeInterrupt(Allocate(zone, lenIntStack),
 lenIntStack, FindInterruptMask(#400), ImpInputInterrupt)
icb>>ICB.outputChanMask = InitializeInterrupt(Allocate(zone, lenIntStack),
 lenIntStack, FindInterruptMask(#400), ImpOutputInterrupt)

// Initialize Imp process
Enqueue(ctxQ, InitializeContext(Allocate(zone, lenProcStack), lenProcStack,
 ImpProcess))

// Initialize status
impNDB>>ImpNDB.iError = true
impNDB>>ImpNDB.oError = true
ImpReset()
]