//routepm2.bcpl

// Board-specific Route routines for the PimLico Logic Board
// Part 2 of 2, last modified by S. Tom Chang, February 22, 1979 8:40 AM

get "route.defs"

external [ Check; Pin1of3W; Pin1of6W; VCCPinPos ]

static [ boardInterfaceVersion = interfaceVersion ]

let Pin1of3W(row, col, px, py) = valof
[
@px = col*44+((col ge $e-$a)?16,0)-((col eq $f-$a)?8,0)-((col eq $g-$a)?16,0)
@py = 528 - row*24 -(row ge 7?12,0)-(row ge 11?12,0)-(row ge 14?12,0)
if (row eq 7)%(row eq 11)%(row eq 14) then
@px = @px + 4 + (col ge $e-$a?8,0) + (col eq $f-$a?4,0)
resultis true
]

and Pin1of6W(row, col, px, py) = valof
[
@px = col*56 + 16 - (col ge $e-$a?44,0) - (col eq $f-$a?4,0)
@py = 360 - (row eq 11?108,0) - (row eq 14?192,0)
resultis true
]

and VCCPinPos(icinst, pin, px, py, pInfo; numargs na) = valof
[
DefaultArgs(lv na, -4, lv na)
@pInfo = Disconnect+noReconnect+TopLevel
@px = 350; @py = 550 // outside of the board
if (pin ls 1)%(pin gr 526) then resultis illegal
let alph =
(pin - 1) rem 26
let num =
(pin - 1)/26 + 1
let alf = alph + $a
let Col7s = ((num eq 7)%(num eq 11)%(num eq 14))
let Top = (((alf ge $a)&(alf le $d))%((alf ge $h)&(alf le $k)))&(num ge 2)&(num le 20)
let preBot = (not Col7s)&((((alf ge $e)&(alf le $g))%((alf ge $l)&(alf le $m)))&(num ge 1)&(num le 20))
let Bot = preBot %(Col7s &(alf ge $e)&(alf le $f))
if ((not Top)&(not Bot))%(Col7s &((alf eq $d)%(alf ge $g))) then resultis illegal
@px = alph*44
// basic coords for dips in Top and Regular
@py = 516 - num*24 - ((num ge 8)?12,0) - ((num ge 12)?12,0) - ((num ge 15)?12,0)
if (Bot &(not Col7s)) then @px = @px +16 - (alf - $e)*8
if (not Col7s)&(alf ge $h)&(alf le $m) then
[
@px = 40 + (alf - $h)*44 + (alf eq $l?8,0)
]
if (Col7s) then
[
@px = alph*52 +(alf ge $b?24,0)-(alf ge $e?36,0)
let cmpsat = (num eq 11?108,0) + (num eq 14?192,0)
@py = 340 - cmpsat
]
resultis absolute
]

and 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
[
firstEPin = 1
firstGNDPin = firstEPin + 100
firstVCCPin = firstGNDPin+508
firstVDDPin = firstVCCPin+508
firstVEEPin = firstVDDPin+500
firstDIPPin = firstVEEPin+500
firstUnusedPin = firstDIPPin+70*43
]

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

DefaultArgs(lv na, -2, lv na, lv na)
@picclass = empty

unless OffsetLegal(x, 1, 0, 308)&OffsetLegal(y, 1, 0, 504) do resultis 0

let xoff = 0
let yoff = 0
let xcd = x
if x eq 304 % x eq 308 then //...edge pins
[
if (((y - 132) rem 5) ne 0)%(y le 137)%(y ge 382) then resultis 0
yoff = (y -132)/5
if (yoff eq 42)%(yoff eq 47)%(yoff eq 48) then resultis 0 // +5, -5 V
if (yoff eq 5)%(yoff eq 25) then resultis 0 // GND Pins
resultis (51 - yoff + (x eq 304?50,0))
]

if (x le 172)&(y gr 480) then resultis 0 // near cable area in TOP
if (x gr 172)&(x ls 192) then resultis 0 // +5 power bus area
if x ge 192 then xcd = x - 16
if (y eq 152)%(y eq 236)%(y eq 344) then // ..VEE pins in jumbo columns
[
unless ((x eq 36)%(x eq 96)%(x eq 140)%(x eq 208)%(x eq 260)) do
resultis 0
@picclass = MustFindNamee("VEE", typeIcclass)
xoff = (xcd - 36)/52
yoff = 6 + (y eq 236?4,0) + (y eq 152?7,0)
@pPinNo = yoff*26 + xoff + (xoff ge 3?1,0) + 1
resultis firstVEEPin + yoff*26 + xoff + (xoff ge 3?1,0)
]
if (y eq 164)%(y eq 248)%(y eq 356) then // ..VDD pins in jumbo columns
[
unless ((x eq 44)%(x eq 96)%(x eq 148)%(x eq 216)%(x eq 268)) do
resultis 0
@picclass = MustFindNamee("VDD", typeIcclass)
xoff = (xcd - 44)/52
yoff = 6 + (y eq 248?4,0) + (y eq 164?7,0)
@pPinNo = yoff*26 + xoff + (xoff ge 3?1,0) + 1
resultis firstVDDPin + yoff*26 + xoff + (xoff ge 3?1,0)
]
if (y eq 148)%(y eq 232)%(y eq 340) then // ..VCC pins in jumbo columns
[
unless ((x eq 0)%(x eq 76)%(x eq 128)%(x eq 196)%(x eq 248)) do
resultis 0
@picclass = MustFindNamee("VCC", typeIcclass)
xoff = xcd/52
yoff = 6 + (y eq 232?4,0) + (y eq 148?7,0)
@pPinNo = yoff*26 + xoff + (xoff ge 3?1,0) + 1
resultis firstVCCPin + yoff*26 + xoff + (xoff ge 3?1,0)
]
if (y eq 160)%(y eq 244)%(y eq 352) then // ..GND pins in jumbo columns
[
unless ((x eq 0)%(x eq 76)%(x eq 128)%(x eq 196)%(x eq 248)) do
resultis 0
@picclass = MustFindNamee("GND", typeIcclass)
xoff = xcd/52
yoff = 6 + (y eq 244?4,0) + (y eq 160?7,0)
@pPinNo = yoff*26 + xoff + (xoff ge 3?1,0) + 1
resultis firstGNDPin + yoff*26 + xoff + (xoff ge 3?1,0)
]
let temp1 = (y eq 156)%(y eq 240)%(y eq 348)
let temp2 = (y eq 168)%(y eq 252)%(y eq 360)
let xtemp = (x eq 68)%(x eq 120)%(x eq 240)%(x eq 292)
if xtemp & (temp1 % temp2) then // ..extra GND pins in jumbo columns
[
@picclass = MustFindNamee("GND", typeIcclass)
xoff = (xcd - 16)/52
yoff = 6 + (y le 252?4,0) + (y le 168?3,0)
@pPinNo = yoff*26 + xoff + 7 + (temp2?2,0) + (xoff ge 4?1,0)
resultis firstGNDPin + yoff*26 + xoff + 6 + (temp2?2,0) + (xoff ge 4?1,0)
]
let temp3 = (y eq 144)%(y eq 228)%(y eq 336)
let temp4 = ((y ge 144)&(y le 168))%((y ge 228)&(y le 252))
if temp4 % ((y ge 336)&(y le 360)) then // ..pins in jumpbo columns
[
unless (temp1 % temp2 % temp3) do resultis 0
if ((x rem 4) ne 0) then resultis 0
xoff = (xcd + 4)/4
if temp2 then
[ @pPinNo = 2800 + xoff + (y le 252?70,0) + (y le 168?70,0)
resultis firstDIPPin + 2800 + xoff + (y le 252?70,0) + (y le 168?70,0) - 1
]
yoff = 6 + (y le 252?4,0) + (y le 168?3,0)
@pPinNo = yoff*140 + (temp3?70,0) + xoff
resultis firstDIPPin + yoff*140 + (temp3?70,0) + xoff - 1

]

y = y - (y ge 180?12,0) - (y ge 264?12,0) - (y ge 372?12,0)
if ((y + 16) rem 24) eq 0 then // ..VDD in columns for regular Dips
[
if (((x + 40) rem 44) ne 0)%(x gr 136) then resultis 0
xoff = (x + 40)/44
yoff = 19 - ((y - 8)/24)
@picclass = MustFindNamee("VDD", typeIcclass)
@pPinNo = yoff*26 + xoff
resultis firstVDDPin + yoff*26 + xoff - 1
]
if ((y + 20) rem 24) eq 0 then // ..VEE in columns for regular Dips
[
if (((x + 8) rem 44) ne 0)%(x gr 168) then resultis 0
xoff = (x + 8)/44
yoff = 19 - ((y - 4)/24)
@picclass = MustFindNamee("VEE", typeIcclass)
@pPinNo = yoff*26 + xoff
resultis firstVEEPin + yoff*26 + xoff - 1
]

if (y rem 12) ne 0 then resultis 0 // all pins must be on the pins-column
if ((y rem 24) eq 0) then
[
unless OffsetLegal(x, 4, 0, 73) do resultis 0
temp1 = (x le 172)&((x rem 44) eq 0)
temp2 = (x le 172)&(((x + 4) rem 44) eq 0)
temp3 = (x ge 192)&(((x - 156) rem 36) eq 0)
temp4 = (x ge 192)&(((x - 188) rem 36) eq 0)
yoff = 19 - (y/24)
if temp1 % temp2 % temp3 % temp4 then // regular VCC pins
[
xoff = x/44 + ((temp2 % temp4)?7,0) - (x eq 224?1,0)
@picclass = MustFindNamee("VCC", typeIcclass)
@pPinNo = yoff*26 + xoff + 1
resultis firstVCCPin + yoff*26 + xoff
]
x = x - (x ge 192?16,0)
xoff = (x+4)/4
@pPinNo = yoff*140 + 70 + xoff // Dip pins
resultis firstDIPPin + yoff*140 + 70 + xoff - 1 // Dip pins
]

if (((y + 12) rem 24) eq 0) then
[
unless OffsetLegal(x, 4, 0, 73) do resultis 0
temp1 = (x le 172)&(((x + 8) rem 44) eq 0)
temp2 = (x le 172)&(((x + 4) rem 44) eq 0)
temp3 = (x ge 192)&(((x - 184) rem 36) eq 0)
temp4 = (x ge 192)&(((x - 188) rem 36) eq 0)
yoff = 19 - ((y - 12)/24)
if temp1 % temp2 % temp3 % temp4 then // regular GND pins
[
xoff = (x + 8)/44 + ((temp2 % temp4)?7,0) + (x eq 292?1,0)
@picclass = MustFindNamee("GND", typeIcclass)
@pPinNo = yoff*26 + xoff
resultis firstGNDPin + yoff*26 + xoff - 1
]
x = x - (x ge 192?16,0)
xoff = (x+4)/4
@pPinNo = yoff*140 + xoff // Dip pins
resultis firstDIPPin + yoff*140 + xoff - 1
]
resultis 0
]