//routestor2.bcpl

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

// last modified by E. McCreight, May 5, 1978 8:55 PM

// Editor’s comment: Those persons who designed this board do not receive my
// everlasting gratitude for making the trace-wired nets easy to characterize.

get "route.defs"

external [ IsConverter; InMosArea ]

static [ maxICs = 450; 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
firstTTLPin = firstEPin+92
firstTermPin = firstTTLPin+3520
firstEclPin = firstTermPin+192
firstUnusedPin = firstEclPin+768
]

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

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

unless OffsetLegal(x, 1, 0, 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
]

if y ge 49 & y ls 483 then // in the TTL or memory patch
[
let yOffset = y-49
let yRepeat = 0
if yOffset ge 18 then
[
test yOffset ls 416
ifnot
[
yRepeat = 21
yOffset = yOffset-416
]
ifso
[
yOffset = yOffset-18
yRepeat = 1+yOffset/20
yOffset = yOffset rem 20
]
]

let xOffset = x
let xRepeat = xOffset/256
xOffset = xOffset rem 256
unless OffsetLegal(xOffset, 1, 0, 220) do resultis 0
xRepeat = 5*xRepeat+(xOffset/48)
xOffset = xOffset rem 48

unless OffsetLegal(xOffset, 4, 0, 7)&OffsetLegal(yOffset, 12, 0, 1) do
resultis 0

let result = xRepeat*352+yRepeat*16+(yOffset eq 12? 8, 0)+
xOffset/4+firstTTLPin

test InMosArea(yRepeat, xRepeat)
ifso
[
if xOffset eq 28 & yOffset eq 12 then // GND pin is 16
[
@picclass = MustFindNamee("GND", typeIcclass)
@pPinNo = 73+22*xRepeat+yRepeat
]
if xOffset eq 0 & yOffset eq 12 then // VCC pin is 9
[
@picclass = MustFindNamee("VCC", typeIcclass)
@pPinNo = 1+22*xRepeat+yRepeat
]

// these other voltages only apply in the Mos area

xRepeat = xRepeat-1
yRepeat = yRepeat-1
if yRepeat ge 11 then yRepeat = yRepeat-2

if xOffset eq 0 & yOffset eq 0 then // VDD is pin 8
[
@picclass = MustFindNamee("VDD", typeIcclass)
@pPinNo = 1+18*xRepeat+yRepeat
]
if xOffset eq 28 & yOffset eq 0 then // VEE pin is 1
[
@picclass = MustFindNamee("VEE", typeIcclass)
@pPinNo = 49+18*xRepeat+yRepeat
]
]
ifnot
[
if xOffset eq 0 & yOffset eq 0 then // GND pin is 8
[
@picclass = MustFindNamee("GND", typeIcclass)
@pPinNo = 73+22*xRepeat+yRepeat
]
if yRepeat ge 10&yRepeat le 11&xOffset eq 4&yOffset eq 0 then
[ // pin 7 of rows 13&14
@picclass = MustFindNamee("GND", typeIcclass)
@pPinNo = 293+2*xRepeat+(yRepeat-10)
]
if xOffset eq 28 & yOffset eq 12 then // VCC pin is 16
[
@picclass = MustFindNamee("VCC", typeIcclass)
@pPinNo = 1+22*xRepeat+yRepeat
]
]
resultis result
]

let yOffset = y-7
let yRepeat = yOffset/476
yOffset = yOffset rem 476
unless OffsetLegal(yOffset, 1, 0, 36) do resultis 0

let xOffset = x
let xRepeat = xOffset/248
xOffset = xOffset rem 248
unless OffsetLegal(xOffset, 1, 0, 228) do resultis 0
xRepeat = 6*xRepeat+(xOffset/40)
xOffset = xOffset rem 40
unless OffsetLegal(xOffset, 4, 0, 7) do resultis 0

if yOffset eq 18 then // terminator row
[
if xOffset eq 28 then // pin 1 is VTT
[
@picclass = MustFindNamee("VTT", typeIcclass)
@pPinNo = 1+2*xRepeat+yRepeat
]
resultis xRepeat*16+yRepeat*8+(xOffset/4)+firstTermPin
]

yRepeat = 2*yRepeat+(yOffset/24)
yOffset = yOffset rem 24
unless OffsetLegal(yOffset, 12, 0, 1) do resultis 0

// Ecl IC

if xOffset eq 0 & yOffset eq 0 then // pin 8 is VEE
[
@picclass = MustFindNamee("VEE", typeIcclass)
@pPinNo = 1+4*xRepeat+yRepeat
]
if xOffset eq 0 & yOffset eq 12 & IsConverter(yRepeat, xRepeat) then
[ // pin 9 is VCC
@picclass = MustFindNamee("VCC", typeIcclass)
@pPinNo = 221
let pattern = 0
while true do
[
let row = pattern rem 4
let col = pattern/4
if row eq yRepeat & col eq xRepeat then break
if IsConverter(row, col) then @pPinNo = @pPinNo+1
pattern = pattern+1
]
]
if xOffset eq 28 then
[
let GND = MustFindNamee("GND", typeIcclass)
if yOffset eq 12 then // pin 16 is GND
[
@picclass = GND
@pPinNo = 1+4*xRepeat+yRepeat
]
if yOffset eq 0 & not IsConverter(yRepeat, xRepeat) then
[ // pin 1 is GND
@picclass = GND
@pPinNo = 49
let pattern = 0
while true do
[
let row = pattern rem 4
let col = pattern/4
if row eq yRepeat & col eq xRepeat then break
unless IsConverter(row, col) do @pPinNo = @pPinNo+1
pattern = pattern+1
]
]
]
resultis xRepeat*64+yRepeat*16+(yOffset eq 0? 0, 8)+xOffset/4+firstEclPin
]