//routeBackPanel.bcpl

// Backpanel & Other auxiliary descriptive files module

// last modified by McCreight, June 25, 1981 10:02 AM

get "streams.d"
get "route.defs"

static
[
BPFile
]


let MakeConnInstFile(icinst) be
[
unless Icclass(icinst)>>icclass.isConnector do return
let filename = vec 20
let connstr = FindNameesString(icinst)
ExpandTemplate(filename, "$S-$S.nl", nlFileName, connstr)
let file = GetFile(filename)
PutTemplate(file, "; Nets for connector $S of class $S on board located at $S*n@*n",
connstr, FindNameesString(Icclass(icinst)), boardLocation)
for pinNo=1 to Npins(icinst) do if icinst>>icinst.pin↑pinNo ne empty then
[
PutTemplate(file, "$S: #$S-$S.$D*n", FindNameesString(FindNet(icinst>>icinst.pin↑pinNo)),
boardLocation, connstr, pinNo)
]
TruncateAndClose(file)
]


and MakeOldBPFile() be
[
BPFile = GetFile(nlFileName, ".bp")
DoInSortOrder(typeNet, NameCompareFn, WriteBPLine)
TruncateAndClose(BPFile)
]

and MakeLoadingChart() be
[
BPFile = GetFile(nlFileName, ".lc")
DoInSortOrder(typeIcinst, TypeCompareFn, WriteLoadingLine)
TruncateAndClose(BPFile)
]

and WriteBPLine(net) be
[
let pin = net>>net.pinList
let connectorList = vec 50
connectorList>>str.length = 0
let needsComma = false
while @pin ne mark do
[
let icinst = pin-offset icinst.pin↑1/16
let pinNo = 1
pin = @pin
while icinst>>icinst.type ne typeIcinst do
[
icinst = icinst-1
pinNo = pinNo+1
]
unless Icclass(icinst)>>icclass.isConnector do loop
ExpandTemplate(connectorList, "$S$S$S$D", connectorList,
(needsComma? ",",""), FindNameesString(icinst), pinNo)
needsComma = true
]
if connectorList>>str.length ne 0 then
PutTemplate(BPFile, "$S: $S*n", FindNameesString(FindNet(net>>net.pinList)),
connectorList) // this circumlocution gets GND instead of GND45, for example
]

and TypeCompareFn(inst1, inst2) = valof
[
let t1 = inst1>>icinst.ictype
let t2 = inst2>>icinst.ictype

if t1>>namee.type ne typeIctype then resultis -1
if t2>>namee.type ne typeIctype then resultis 1

let result = NameCompareFn(t1, t2)
resultis (result ne 0)? result, NameCompareFn(inst1, inst2)
]

and WriteLoadingLine(icinst) be
[
static [ currentType = empty; loadCount; lastInstLen ]
if (icinst>>icinst.ictype)>>namee.type ne typeIctype then return
if currentType ne empty & icinst>>icinst.ictype ne currentType then
[
Wss(BPFile, "*n*n")
currentType = empty
]
if currentType eq empty then
[
currentType = icinst>>icinst.ictype
PutTemplate(BPFile, "$S:*n", FindNameesString(currentType))
loadCount = 0
]
test loadCount eq 0 % loadCount gr 7
ifso [ loadCount = 0; Wss(BPFile, "*n ") ]
ifnot for i=1 to 10-lastInstLen do Puts(BPFile, $*s)

Puts(BPFile, $*s)
Wss(BPFile, FindNameesString(icinst))
lastInstLen = FindNameesString(icinst)>>str.length
loadCount = loadCount+1
]

and TruncateAndClose(file) be
[
TruncateDiskStream(file)
Closes(file)
]