// RouteMultiBusB.bcpl - part 2 of 2
// Route description of Interconnection Technology Inc. Multibus Board
// P/N 50062 -- DJ Curry March 16, 1982 3:44 PM
// The V1 and V4 buses are not used (pins are too near edge)
//
A1 is A1x,A1y = 24,20 with X in the short dimension
//
"VB" currently set to "VEE" see locations with //// VB -> VEE

get "route.defs"
manifest [ A1x = 24; A1y = 20 ]
static [ maxICs=300; boardInterfaceVersion=interfaceVersion ]

let
FindCoordFromString(s, px, py, vop1, hop1; numargs na) = valof
// This routine takes the string name of a board location and computes
// the internal co-ordinates x,y of that position.
// It then adds vop1 and hop1 as the offsets assuming that pin 1 is
// installed at x,y.
// The result is placed in@px,@py.
// The result is absolute if the pin is legal, and illegal otherwise.
// vop1 is the +y column vertical long way offset from pin 1;
// hop1 is the -x row horizontal short way offset from pin 1,
// In a standard 16 pin DIP,
// pin 2 vop1=4 and hop1=0,
// pin 16 vop1=0 and hop1= - 12
[
DefaultArgs(lv na, -3, 0, 0)
let columny = -1
and rowx = -1
and next = 1
let getlc(ss, idx) = valof [
let cc = ss>>str.char↑idx
if (cc ge $A) & (cc le $Z) then cc = cc - $A + $a
resultis cc ]
let c = getlc(s, next)
if c eq $# then [ next = next+1; c = getlc(s, next) ]

if (c ls $a) % (c gr $z) then resultis illegal
switchon c into [
case $g: case $i: case $j: case $o: case $u: case $v:
resultis illegal; endcase;
case $h: rowx = 18; endcase;
case $k: rowx = 20; endcase;
case $l: rowx = 21; endcase;
case $m: rowx = 24; endcase;
case $n: rowx = 26; endcase;
default: ]
if (c ge $a) & (c le $f) then rowx = (c-$a)*3
if (c ge $p) & (c le $t) then rowx = (c-$p)*3 + 27
if (c ge $w) & (c le $z) then rowx = (c-$w)*3 + 42
next = next+1; if getlc(s, next) eq $a then
[ if c ne $a then resultis illegal; rowx = 54; next = next+1]
rowx = A1x + rowx*4 - hop1
if not InArray(rowx,12, A1x , A1x+54*4) &
not InArray(rowx,24, A1x+20*4, A1x+26*4) then resultis illegal

let columny = 0
for i=next to s>>str.length do
[
let c = getlc(s, i)
if (c ls $0) % (c gr $9) then resultis illegal
columny = (10*columny)+(c-$0)
]
columny = A1y + ((columny-1)*4) + vop1
if not InArray(columny, 4, A1y, A1y+111*4) then resultis illegal
@px = rowx
@py = columny
resultis absolute
]

and InArray(x, inc, min, max) = valof [
if (x ls min) % (x gr max) then resultis false
resultis ((x-min) rem inc) eq 0 ]


and
FindIndexFromCoord(
x, y, picclass, pPinNo; numargs na) = valof
// Returns index [1..NextIndex=nofpins+1] of pin at x,y (.025" units)
// Returns 0 if not a legal position
// Returns NextIndex=nofpins+1 if x=y=-1
// If pin is part of trace wired net (TWnet) then
// @picclass ← icclass
// @pPinNo ← pin number in net
[
manifest
[
firstDipPin = 1
firstJ1Pin = firstDipPin +21*111
firstJ2Pin = firstJ1Pin +86
firstJ3Pin = firstJ2Pin +60
firstJ4Pin = firstJ3Pin +50
firstJ5Pin = firstJ4Pin +50
firstGNDPin = firstJ5Pin +26
firstVCCPin = firstGNDPin +25*15
firstVBPin = firstVCCPin +25*9
firstVDPin = firstVBPin +25
firstVFPin = firstVDPin +25
firstVHPin = firstVFPin +25
firstVKPin = firstVHPin +25
firstVMPin = firstVKPin +25
firstVPPin = firstVMPin +25
firstVRPin = firstVPPin +25
firstVTAPin = firstVRPin +25
firstVTBPin = firstVTAPin +14
firstVVAPin = firstVTBPin +12
firstVVBPin = firstVVAPin +14
firstV2Pin = firstVVBPin +12
firstV3Pin = firstV2Pin +11
NextIndex = firstV3Pin +11
]
let cindex = -1
and rindex = -1
and pin = -1
and vclass = -1
if x eq -1 & y eq -1 then resultis NextIndex

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

// Test inside main grid
test InArray(x,4,A1x,A1x+54*4) & InArray(y,4,A1y,A1y+110*4)
ifso // inside grid .. Dip pins, GND, VCC, VB-VR, VT A-B, VV A-B
[
// check dip pins
x = (x-A1x)/4; y = (y-A1y)/4;// now in .1" units
if InArray(x,3,0,18) then rindex = x/3
if InArray(x,3,27,54) then rindex = x/3 + 2
rindex = selecton x into [
case 20: 7
case 21: 8
case 24: 9
case 26: 10
default: rindex ]
if rindex ne -1 then resultis rindex*111 + y + firstDipPin

// check columns for voltages and ground
cindex = -1
if InArray(y,5,4,109) then cindex = y/5 + 2
cindex = selecton y into [
case 0: 0
case 1: 1
case 110: 24
case 58: 25 // VTA14 or VVA14
default: cindex ]
if (cindex eq -1) then resultis 0

// check VT A-B and VV A-B
pin = 0; vclass = 0
if (x eq 52) % (x eq 53) then
[
if InArray(cindex,1,0, 12) then
[ pin = cindex; vclass = ((x eq 52)?1,3) ]
if cindex eq 25 then
[ pin = 13; vclass = ((x eq 52)?1,3) ]
if InArray(cindex,1,13,24) then
[ pin = cindex-13; vclass = ((x eq 52)?2,4) ]
if (vclass eq 0) then resultis 0
@pPinNo = pin+1
switchon vclass into [
case 1: @picclass = MustFindNamee("VTA",typeIcclass);
resultis pin + firstVTAPin
case 2: @picclass = MustFindNamee("VTB",typeIcclass);
resultis pin + firstVTBPin
case 3: @picclass = MustFindNamee("VVA",typeIcclass);
resultis pin + firstVVAPin
default: @picclass = MustFindNamee("VVB",typeIcclass);
resultis pin + firstVVBPin ]
]
if (cindex eq 25) then resultis 0


// check rows for ground
let rindex = -1
if InArray(x,3,2,17) then rindex = x/3
if InArray(x,3,29,50) then rindex = x/3 - 2
if x eq 23 then rindex = 6
if rindex ne -1 then
[
pin = rindex*25 + cindex + 1
@pPinNo = pin
@picclass = MustFindNamee("GND",typeIcclass);
pin = pin + firstGNDPin - 1
resultis pin
]

// check rows for VCC
if InArray(x,6,1,49) then
[
@pPinNo = (x/6)*25 + cindex+1
@picclass = MustFindNamee("VCC",typeIcclass);
resultis (x/6)*25 + cindex + firstVCCPin
]

// check rows for VB..VR
if InArray(x,6,4,46) then
[
@pPinNo = cindex+1
switchon x/6 into [
//// VB -> VEE
case 0: @picclass = MustFindNamee("VEE",typeIcclass);
resultis cindex + firstVBPin
case 1: @picclass = MustFindNamee("VD",typeIcclass);
resultis cindex + firstVDPin
case 2: @picclass = MustFindNamee("VF",typeIcclass);
resultis cindex + firstVFPin
case 3: @picclass = MustFindNamee("VH",typeIcclass);
resultis cindex + firstVHPin
case 4: @picclass = MustFindNamee("VK",typeIcclass);
resultis cindex + firstVKPin
case 5: @picclass = MustFindNamee("VM",typeIcclass);
resultis cindex + firstVMPin
case 6: @picclass = MustFindNamee("VP",typeIcclass);
resultis cindex + firstVPPin
default: @picclass = MustFindNamee("VR",typeIcclass);
resultis cindex + firstVRPin ]
]
]

ifnot // Outside grid .. V2, V3, J1, J2, J3, J4, J5
[
// Check V2, V3
if (y eq (A1y-11)) % (y eq (A1y+110*4+11)) then [
if not InArray(x,4,A1x+4,A1x+53*4) then resultis 0
x = (x-A1x)/4// x now in .1" units
rindex = -1
if InArray(x,6,4,52) then rindex = x/6 +1
if x eq 1 then rindex = 0
if x eq 53 then rindex = 10
if rindex eq -1 resultis 0
@pPinNo = rindex+1
test ((A1y-11) eq y)
ifso [ @picclass = MustFindNamee("V2",typeIcclass);
resultis rindex + firstV2Pin ]
ifnot [ @picclass = MustFindNamee("V3",typeIcclass);
resultis rindex + firstV3Pin ] ]

// Check Connectors
if not InArray(y,4,A1y+5*4,A1y+108*4) then resultis 0
cindex = (y-A1y)/4
switchon x into [
case A1x+54*4+17:rindex = 0; endcase;
case A1x+54*4+13:rindex = 1; endcase;
case A1x-5:rindex = 2; endcase;
case A1x-9:rindex = 3; endcase;
default: resultis 0; ]

// Check J1 or J2
if (rindex eq 0) % (rindex eq 1) then [
switchon cindex into [ // J1
case 5: pin = 7; if rindex eq 0 then resultis 0; endcase
case 6: pin = 9; if rindex eq 0 then resultis 0; endcase
case 60: pin =79; if rindex eq 0 then resultis 0; endcase
case 61: pin =81; if rindex eq 0 then resultis 0; endcase
default: pin = (rindex eq 1) ? 1, 2 ]
if InArray(cindex,1,11,15) then pin=(cindex-11)*2+pin+12
if InArray(cindex,1,19,23) then pin=(cindex-19)*2+pin+22
if InArray(cindex,1,26,30) then pin=(cindex-26)*2+pin+32
if InArray(cindex,1,34,38) then pin=(cindex-34)*2+pin+42
if InArray(cindex,1,42,46) then pin=(cindex-42)*2+pin+52
if InArray(cindex,1,50,55) then pin=(cindex-50)*2+pin+62
if pin gr 2 then resultis pin-1 + firstJ1Pin
if InArray(cindex,1,79,108) then // J2
resultis (cindex-79)*2 + pin-1 + firstJ2Pin
resultis 0 ]

// Check if J3, J4, J5
pin = (rindex eq 3) ? 1, 2 ] // 3 means odd
if InArray(cindex,1,12,36) then
resultis (36-cindex)*2 + pin-1 + firstJ3Pin
if InArray(cindex,1,47,71) then
resultis (71-cindex)*2 + pin-1 + firstJ4Pin
if InArray(cindex,1,84,96) then
resultis (96-cindex)*2 + pin-1 + firstJ5Pin
resultis 0
]