//routemlb2.bcpl

// Board-specific Route routines for the Dorado Main Logic Board
// part 2 of 2

// last modified by E. McCreight, January 11, 1979 5:35 PM

// all co-ordinates are described with respect to the bottom or
// wiring side of the board. LevelTransform fixes these as necessary.

get "route.defs"

static [ boardInterfaceVersion = interfaceVersion ]

let FindIndexFromCoord(x, y, picclass, pPinNo; numargs na) = valof
[
static [ hotIndex = -1; firstUnusedPin = 0 ]

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

if firstUnusedPin eq 0 then firstUnusedPin = FIFC(-1,-1)
let result = FIFC(x, y, picclass, pPinNo)
if result ls 0 % result gr firstUnusedPin then CallSwat("Illegal index..")
if result eq hotIndex then CallSwat("Hot index computed...")
resultis result
]

and FIFC(x, y, picclass, pPinNo; numargs na) = valof
[
manifest
[
firstCPin = 1
firstEPin = firstCPin+92
first6WidePin = firstEPin+92
firstSipPin = first6WidePin+800
first3WidePin = firstSipPin+1392
firstUnusedPin = first3WidePin+5568
]

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

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

unless OffsetLegal(x, 1, 1, 477)&OffsetLegal(y, 1, 0, 527) do resultis 0

if y eq 0 then // ..cable pin
[
if (x-12) rem 5 ne 0 then resultis 0
let vpin = (x-22)/5
unless OffsetLegal(vpin, 1, 0, 91) do resultis 0
resultis vpin+firstCPin
]

if y eq 525 then // ..edge pin
[
if (x-12) rem 5 ne 0 then resultis 0
let vpin = (x-22)/5
unless OffsetLegal(vpin, 1, 0, 91) do resultis 0
resultis vpin+firstEPin
]

let xHalfOffset = x-1
let xHalf = xHalfOffset/247
xHalfOffset = xHalfOffset rem 247
if xHalfOffset gr 228 then resultis 0
let yOffset = y-16
let yRepeat = yOffset/126
yOffset = yOffset rem 126
unless OffsetLegal(yRepeat, 1, 0, 3)&OffsetLegal(yOffset, 2, 0, 60) do
resultis 0

if (yOffset eq 48)%(yOffset eq 72) then // 0.6" wide socket
[
let xRepeat = 2*xHalf+(xHalfOffset/112)
let xOffset = (xHalfOffset rem 112)-10
unless OffsetLegal(xOffset, 4, 0, 24) do resultis 0

let row = yRepeat
let col = 2*xRepeat+xOffset/52
let vpin = 11-(xOffset rem 52)/4
let hpin = (yOffset eq 48)? 0, 1

if xOffset eq 48 then // VCC or VEE pin in 50-pin row
[
@picclass = MustFindNamee((hpin eq 0? "VCC", "VEE"),
typeIcclass)
@pPinNo = (hpin eq 0? 145, 321)+4*xRepeat+yRepeat
]
if (vpin eq 0) then // Pins 1 and 24 of 24-pin sockets have GND
[
@picclass = MustFindNamee("GND", typeIcclass)
@pPinNo = 577+8*col+2*row+hpin
]

if (vpin eq 11)&(hpin eq 0) then // Pin 12 of 24-pin sockets has VEE
[
@picclass = MustFindNamee("VEE", typeIcclass)
@pPinNo = 289+4*col+row
]

resultis xRepeat*200+yRepeat*50+
(yOffset eq 72? 25, 0)+xOffset/4+first6WidePin
]

unless OffsetLegal(xHalfOffset, 4, 0, 57) do resultis 0

yRepeat = 3*yRepeat+yOffset/42
yOffset = yOffset rem 42
if (yOffset eq 18) then // SIP socket column
[
test (xHalfOffset rem 112) ls 8
ifso // VCC or VDD pin below SIPs
[
let isVDD = ((xHalfOffset rem 112) eq 0) eqv
(xHalfOffset/112 le 1)
let isVEE = (xHalfOffset/112 gr 1)&(not isVDD)
@picclass = MustFindNamee(
(isVDD? "VDD", (isVEE? "VEE", "VCC")), typeIcclass)
@pPinNo = yRepeat+
(isVDD? 1+36*xHalf+12*(xHalfOffset/112),
isVEE? 481+12*xHalf, 1+24*xHalf+12*(xHalfOffset/112))
]
ifnot // real Sip socket or virtual pin between Sip sockets
[
let xRepeat = 2*xHalf+(xHalfOffset/112)
let xOffset = xHalfOffset rem 112
if ((xOffset-8) rem 36) eq 28 then // pin 1 has VTT
[
@picclass = MustFindNamee("VTT", typeIcclass)
@pPinNo = 1+12*(3*xRepeat+(xOffset-8)/36)+yRepeat
]
]
resultis xHalf*696+yRepeat*58+xHalfOffset/4+firstSipPin
]

// Should be 0.3" socket column

yRepeat = 2*yRepeat+yOffset/24
yOffset = yOffset rem 24
unless OffsetLegal(yOffset, 12, 0, 1) do resultis false
test (xHalfOffset rem 112) ls 8
ifso // bypass cap
[
let xOffset = xHalfOffset rem 112
let xRepeat = 3*xHalf+(xHalfOffset/112)
let pincode = 2*(xOffset/4)+yOffset/12
@picclass = MustFindNamee(selecton pincode into
[
case 0: "VEE"
case 1: "GND"

case 2: "GND"
case 3: "VCC"
], typeIcclass)
@pPinNo = selecton pincode into
[
case 0: 337
case 1: 737

case 2: 881
case 3: 161
]+24*xRepeat+yRepeat
]
ifnot
[
let xOffset = (xHalfOffset rem 112)-8
let xRepeat = 2*xHalf+(xHalfOffset/112)

test (xOffset rem 36) eq 32
ifso
[ // VTT bypass caps or VCC and VDD pins opposite them
let pinWithinGroup = 12*(2*xRepeat+xOffset/36)+yRepeat/2+1
test ((yRepeat rem 2) eq 0)
ifso
[
test yOffset eq 0
ifso // VDD pin
[
@picclass = MustFindNamee("VDD", typeIcclass)
@pPinNo = 72+pinWithinGroup
]
ifnot
// VTT pin
[
@picclass = MustFindNamee("VTT", typeIcclass)
@pPinNo = 144+pinWithinGroup
]
]
ifnot
[
test yOffset eq 0
ifso
// GND pin
[
@picclass = MustFindNamee("GND", typeIcclass)
@pPinNo = 640+pinWithinGroup
]
ifnot // VCC pin
[
@picclass = MustFindNamee("VCC", typeIcclass)
@pPinNo = 48+pinWithinGroup
]
]
]
ifnot
[ // 0.3" socket
let vpin = 7-((xOffset rem 36)/4)
let hpin = (yOffset eq 12)? 1, 0
if (vpin eq 0) then // Pins 1 and 16 have GND
[
@picclass = MustFindNamee("GND", typeIcclass)
@pPinNo = 1+48*(3*xRepeat+xOffset/36)+2*yRepeat+hpin
]
if (vpin eq 7)&(hpin eq 0) then // Pin 8 has VEE
[
@picclass = MustFindNamee("VEE", typeIcclass)
@pPinNo = 1+24*(3*xRepeat+xOffset/36)+yRepeat
]
]
]
resultis xHalf*2784+yRepeat*116+(yOffset gr 0? 58, 0)+
xHalfOffset/4+first3WidePin
]