//routemwlb2.bcpl

// Board-specific Route routines for the Multi-Wire version of the
// Dorado Main Logic Board

// part 2 of 2

// last modified by E. McCreight, January 13, 1979 7:03 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"

manifest
[
repeatRows = 12
repeatColsPerSide = 3
repeatCols = 2*repeatColsPerSide
fullRepeatColsPerSide = 2
fullRepeatCols = 2*fullRepeatColsPerSide
repeats = repeatRows*repeatCols
fullRepeats = repeatRows*fullRepeatCols
rowOffset = 16
leftColsOffset = 0
rightColsOffset = 246
rowHeight = 42
fullColWidth = 112
patternGrounds = 3*repeats+6*fullRepeats
Sockets16pin = 6*fullRepeats
Sockets24pin = 2*fullRepeats
Sockets50pin = fullRepeats
SocketsSip = 3*fullRepeats
]

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
[
firstEPin = 1
firstSocketGround = firstEPin+92+92
firstPatternPin = firstSocketGround+92+92
firstUnusedPin = firstPatternPin+repeatRows*(fullRepeatCols*7*26+
repeatCols*5*2)
]

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

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

unless OffsetLegal(x, 1, 0, 476)&OffsetLegal(y, 1, 0, 524) do resultis 0

if y eq 0 % y eq 524 then // ..connector signal pin
[
if (x-21) rem 5 ne 0 then resultis 0
let vpin = (x-21)/5
unless OffsetLegal(vpin, 1, 0, 91) do resultis 0
resultis vpin+92*(y/524)+firstEPin
]

if y eq 4 % y eq 520 then // ..connector ground pin
[
if (x-21) rem 5 ne 0 then resultis 0
let vpin = (x-21)/5
unless OffsetLegal(vpin, 1, 0, 91) do resultis 0
let cgp = vpin+92*(y/520)
@picclass = MustFindNamee("GND", typeIcclass)
@pPinNo = patternGrounds+1+cgp
resultis cgp+firstSocketGround
]

let side = 0
if x ge rightColsOffset then
[
side = 1
x = x-(rightColsOffset-leftColsOffset)
]
let xOffset = x-leftColsOffset
unless OffsetLegal(xOffset, 4, 0, 57) do resultis 0
let xRepeat = repeatColsPerSide*side+(xOffset/fullColWidth)
xOffset = xOffset rem fullColWidth
unless OffsetLegal(xOffset, 4, 0, 27) do resultis 0
let yOffset = y-rowOffset
let yRepeat = yOffset/rowHeight
yOffset = yOffset rem rowHeight
unless OffsetLegal(yRepeat, 1, 0, 11)&OffsetLegal(yOffset, 6, 0, 6) do
resultis 0

let pinInGroup = 1
let prevGroups = repeatRows*xRepeat+yRepeat
let prevFullGroups = repeatRows*(xRepeat-(xRepeat/repeatColsPerSide))+
(xRepeat rem repeatColsPerSide ne fullRepeatColsPerSide? yRepeat, 0)

switchon yOffset into
[
case 0:
switchon xOffset into
[
case 80: pinInGroup = pinInGroup+2
case 44: pinInGroup = pinInGroup+2
case 4:
@picclass = MustFindNamee("VEE", typeIcclass)
@pPinNo = 2*prevGroups+4*prevFullGroups+
pinInGroup
endcase

case 76: pinInGroup = pinInGroup+3
case 40:
pinInGroup = pinInGroup+3
@picclass = MustFindNamee("GND", typeIcclass)
@pPinNo = 3*prevGroups+6*prevFullGroups+
pinInGroup
endcase
default:
]
endcase

case 6:
case 30:
if xOffset ls 8 then resultis 0
endcase

case 12:
switchon xOffset into
[
case 76: pinInGroup = pinInGroup+2
case 72: pinInGroup = pinInGroup+1
case 40: pinInGroup = pinInGroup+4
case 0:
@picclass = MustFindNamee("GND", typeIcclass)
@pPinNo = 3*prevGroups+6*prevFullGroups+
pinInGroup
endcase
default:
]
endcase

case 18:
switchon xOffset into
[
case 4:
@picclass = MustFindNamee("VDD", typeIcclass)
@pPinNo = prevGroups+pinInGroup
endcase

case 108:
pinInGroup = pinInGroup+2
@picclass = MustFindNamee("VTT", typeIcclass)
@pPinNo = 3*prevFullGroups+pinInGroup
endcase
default:
]
endcase

case 24:
switchon xOffset into
[
case 0:
pinInGroup = pinInGroup+1
@picclass = MustFindNamee("GND", typeIcclass)
@pPinNo = 3*prevGroups+6*prevFullGroups+
pinInGroup
endcase

case 80: pinInGroup = pinInGroup+2
case 44: pinInGroup = pinInGroup+2
case 4:
pinInGroup = pinInGroup+1
@picclass = MustFindNamee("VEE", typeIcclass)
@pPinNo = 2*prevGroups+4*prevFullGroups+
pinInGroup
endcase

case 76: pinInGroup = pinInGroup+1
case 40:
@picclass = MustFindNamee("VTT", typeIcclass)
@pPinNo = 3*prevFullGroups+pinInGroup
endcase
default:
]
endcase

case 36:
switchon xOffset into
[
case 0:
@picclass = MustFindNamee("VCC", typeIcclass)
@pPinNo = prevGroups+pinInGroup
endcase

case 108: pinInGroup = pinInGroup+6
case 4:
pinInGroup = pinInGroup+2
@picclass = MustFindNamee("GND", typeIcclass)
@pPinNo = 3*prevGroups+6*prevFullGroups+
pinInGroup
endcase
default:
]
endcase

default: resultis 0
]

let colBase = (xRepeat/3)*repeatRows*((fullRepeatCols/2)*7*26+
(repeatCols/2)*5*2)+(xRepeat rem 3)*repeatRows*(7*26+5*2)
let rowBase = yRepeat*((xRepeat rem 3 eq 2)? 5*2, 7*26+5*2)

resultis firstPatternPin+colBase+rowBase+(xOffset/4)+
(xRepeat rem 3 ls 2?
selecton yOffset into
[
case 0: 0
case 6: 28-2
case 12: 28+26
case 18: 28+26+28
case 24: 28+26+28+28
case 30: 28+26+28+28+28-2
case 36: 28+26+28+28+28+26
],
selecton yOffset into
[
case 0: 0
case 6: 2-2
case 12: 2
case 18: 2+2
case 24: 2+2+2
case 30: 2+2+2+2-2
case 36: 2+2+2+2
]
)
]