//routed1bp.bcpl

// Board-specific Route routines for the Dorado Backpanels

// last modified by E. McCreight, October 6, 1978 6:00 PM

get "route.defs"

static [ maxICs = 100; boardInterfaceVersion = interfaceVersion
zeroTableString; whichSide = $? ]

let DeclareInitialNets(BuildTWNet, BuildTermNet, BuildConnector, SetupICclass) be
[
BuildTWNet("GND", 2208, GNDPinPos)
BuildTWNet("POWER", 192, POWERPinPos)
SetupICclass("Conn", printUsedList, SocketOffset, 0, WirePower, 192)
zeroTableString = Allocate(SilZone, 20)
]

and ZeroTablePoint(point) = selecton point into
[
case 0: "DoradoBP" // board type
case 1: ExpandTemplate(zeroTableString, "#s1-$C.5", whichSide)
case 2: ExpandTemplate(zeroTableString, "#s1-$C.188", whichSide)
case 3: ExpandTemplate(zeroTableString, "#s24-$C.188", whichSide)
case 4: ExpandTemplate(zeroTableString, "#s24-$C.5", whichSide)
default: empty
]

and LevelTransform(level, x, y, px, py, pName, pPullComponents, pWire; numargs na) = valof
[
DefaultArgs(lv na, -1, 0, 0, lv na, lv na, lv na, lv na, lv na)
switchon level into
[
case TopLevel:
@px = x
@py = y
@pName = "Wiring side"
@pPullComponents = false
@pWire = true
resultis true

default: resultis false
]
]

and SocketOffset(icinst, pin, pv, ph) = valof
[
if (pin ls 1) % (pin gr 192) then resultis illegal
@ph = 5*(pin rem 2)
@pv = 5*((pin-1)/2)
resultis relative
]

and WirePower(icinst) be
[
let str = FindNameesString(icinst)
for i=1 to 4 do
PutTemplate(ImplicitFile, "*nPOWER: $S.$Dp", str, i)
for i=189 to 192 do
PutTemplate(ImplicitFile, "*nPOWER: $S.$Dp", str, i)
for toppin = 5 to 187 by 2 do
PutTemplate(ImplicitFile, "*nGND: $S.$Dp", str,
toppin+((toppin rem 4 eq (whichSide eq $C? 1,3))? 1, 0))
]

and GNDPinPos(icinst, pin, px, py, pInfo; numargs na) = valof
[
DefaultArgs(lv na, -4, lv na)
@pInfo = noDisconnect+noReconnect+TopLevel
if pin ls 1 % pin gr 2208 then resultis illegal
pin = pin-1
let yRepeat = pin/92
let xOffset = pin rem 92
let yOffset = ((xOffset rem 2) eq (whichSide eq $C? 0, 1))? 0,1
@px = 10+5*xOffset
@py = 25*yRepeat+5*yOffset
resultis absolute
]

and POWERPinPos(icinst, pin, px, py, pInfo; numargs na) = valof
[
DefaultArgs(lv na, -4, lv na)
@pInfo = noDisconnect+noReconnect+TopLevel
if pin ls 1 % pin gr 192 then resultis illegal
pin = pin-1
let yRepeat = pin/4
let xOffset = pin rem 4
@px = 5*(xOffset+(xOffset gr 1? 92, 0))
@py = 25*(yRepeat/2)+5*(yRepeat rem 2)
resultis absolute
]


and FindCoordFromString(s, px, py, vo, ho; numargs na) = valof
[ // vo is the "vertical offset", that is, the offset along the long
// spacing; ho is the "horizontal offset".

DefaultArgs(lv na, -3, 0, 0)
let next = 1
let alph = s>>str.char↑next
if alph eq $# then [ next = next+1; alph = s>>str.char↑next ]
if alph ne $s then resultis illegal
next = next+1
let row = 0
let c = 0
while next le s>>str.length do
[
c = s>>str.char↑next
if (c ls $0) % (c gr $9) then break
row = 10*row+(c-$0)
next = next+1
]

unless OffsetLegal(row, 1, 1, 24) do resultis illegal

if next le s>>str.length then
[
if c ne $- then resultis illegal
next = next+1
if next ne s>>str.length then resultis illegal
c = s>>str.char↑next
switchon c into
[
case $c:
c = $C
endcase

case $e:
c = $E
endcase

case $C:
case $E:
endcase

default: resultis illegal
]
whichSide = c
]

@py = 25*(row-1)+ho
@px = vo
resultis absolute
]

and FindIndexFromCoord(x, y, picclass, pPinNo; numargs na) = valof
[
manifest
[
firstCPin = 1
firstUnusedPin = firstCPin+4608
]

if x eq -1 & y eq -1 then resultis firstUnusedPin

DefaultArgs(lv na, -2, lv na, lv na)

unless OffsetLegal(x, 5, 0, 95)&OffsetLegal(y, 5, 0, 116) do resultis 0
x = x/5
y = y/5

let yRepeat = y/5
let yOffset = y rem 5
unless OffsetLegal(yOffset, 1, 0, 1) do resultis 0

test x ls 2 % x gr 93
ifso
[ // power pin
let xOffset = x gr 93? x-92, x
@picclass = MustFindNamee("POWER", typeIcclass)
@pPinNo = 1+x+4*yOffset+8*yRepeat
]
ifnot
[ // maybe ground pin; check C or E
if x+yOffset rem 2 eq (whichSide eq $C? 0,1) then
[
@picclass = MustFindNamee("GND", typeIcclass)
@pPinNo = 1+(x-2)+92*yRepeat
]
]

resultis 192*yRepeat+96*yOffset+x+firstCPin
]