//  RouteDaffodilA.bcpl
//  Route description of Daffodil Board part A (1 of 4)
//  Last modified August 18, 1983  9:06 AM by Diebert

get "route.defs"
static   [ maxICs = 500; boardInterfaceVersion = interfaceVersion ]
external [ VCCPinPos; GNDPinPos ]

let ZeroTablePoint(point) = selecton point into
//  If point = 0 then the string name of the board is returned.
//  If point is from 1 to 4 the string name of the calibration 
//    point is returned. The calibration points should form a  
//    cw rectangle on the board.
//  Machine is set up so that y increases to the right and x down
//  Board is clamped on top on the 3 card edge connector edge
[
   case 0: "Daffodil"   //Board type
   case 1: "#aa111"     //Upper left  (wiring side)
   case 2: "#aa8"       //Upper right (wiring side)
   case 3: "#el8"       //Lower right (wiring side)
   case 4: "#el111"     //Lower left  (wiring side)
   default: empty
]


and LevelTransform(level, x, y, px, py, pName, pPullComponents, pWire; numargs na) = valof
//  A given pin is described by different co-ordinates according to
//    whether a board is positioned wiring-side up or component-side up.
//  For each value of level, this subroutine implements a transformation 
//    from internal co-ordinates x,y to printing co-ordinates @px,@py. 
//  @pName is set to a string giving the name of this level. @pPull is 
//    set according to whether components can be removed at this level. 
//  @pWire is set according to whether wiring can be done at this
//    level.
   [
   DefaultArgs(lv na, -1, 0, 0,lv na, lv na, lv na, lv na, lv na)
   switchon level into [
      case TopLevel:
         @px = x
         @py = y
         @pName = "Component side"
         @pPullComponents = true
         @pWire = false
         resultis true
      case BottomLevel:
         @px = x
         @py = 480 - y
         @pName = "Wiring side"
         @pPullComponents = false
         @pWire = true
         resultis true
      default:  resultis false ]
   ]


and DeclareInitialNets(BuildTWNet, BuildTermNet, BuildConnector) be
//This routine declares all the trace wired nets, terminator 
//sets, and connectors that the board has.
   [
   BuildConnector("E", 260, EPinPos)
   BuildConnector("C", 826, CPinPos)
   BuildTWNet("GND", 826, GNDPinPos)
   BuildTWNet("VCC", 706, VCCPinPos)
   ]


and EPinPos(icinst, pin, px, py) = valof
   [
   let connIndex = pin/100
   let pinIndex = pin rem 100
   let even = (pinIndex rem 2) eq 0
   if (connIndex ls 1) % (connIndex gr 2) then resultis illegal
   @px =  even ? (126 * 4), (125 * 4)
   if connIndex eq 1 then // J1
      [
      if (pinIndex ls 13) % (pinIndex gr 72) then
         switchon pinIndex into [
            case 7:   @py = 10 * 4; resultis absolute // +12V
            case 9:   @py = 11 * 4; resultis absolute
            case 73:
            case 74:  @py = 60 * 4; resultis absolute // Pin 73 & 74
            case 77:  @py = 65 * 4; resultis absolute
            case 79:  @py = 66 * 4; resultis absolute // -12V
            default: resultis illegal ]
      let yoffset = (((pinIndex - 13) rem 10) /2) * 4
      switchon (pinIndex - 13) / 10 into [
         case 0: @py = 16 * 4 + yoffset; resultis absolute
         case 1: @py = 23 * 4 + yoffset; resultis absolute
         case 2: @py = 31 * 4 + yoffset; resultis absolute
         case 3: @py = 39 * 4 + yoffset; resultis absolute
         case 4: @py = 47 * 4 + yoffset; resultis absolute
         case 5: @py = 55 * 4 + yoffset; resultis absolute
         default: resultis illegal ]
      ]
   if connIndex eq 2 then [  // J2 
      if (pinIndex ls 1) % (pinIndex gr 60) then resultis illegal
      @py = 84 * 4 + ((pinIndex-1)/2) * 4; resultis absolute ]
   resultis illegal
   ]


and CPinPos(icinst, pin, px, py) = valof
   [
   let connIndex = pin/100
   let pinIndex = pin rem 100
   let even = (pinIndex rem 2) eq 0
   if (connIndex ls 3) % (connIndex gr 8) then resultis illegal
   @px =  even ? (6 * 4), (5 * 4)
   switchon connIndex into
      [
      case 3:
         [ if (pinIndex ls 1) % (pinIndex gr 25) then resultis illegal
         test pinIndex ls 14
            ifso [ @py = 10 * 4; @px = 55 * 4 - ((pinIndex - 1) * 4) ]
            ifnot [ @py = 9 * 4; @px = 55 * 4 - ((pinIndex - 14) * 4) ]
         resultis absolute ]
      case 4:
         [ if (pinIndex ls 1) % (pinIndex gr 15) then resultis illegal
         test pinIndex ls 9
            ifso [ @py = 10 * 4; @px = 30 * 4 - ((pinIndex - 1) * 4) ]
            ifnot [ @py = 9 * 4; @px = 30 * 4 - ((pinIndex - 9) * 4) ]
         resultis absolute ]
      case 5:
         [ if (pinIndex ls 1) % (pinIndex gr 4) then resultis illegal
         @py = 10 * 4; @px = 14 * 4 - ((pinIndex - 1) * 4)
         resultis absolute ]
      case 6: resultis CableConnectors(py, pinIndex, 50, 41)
      case 7: resultis CableConnectors(py, pinIndex, 50, 76)
      case 8: resultis CableConnectors(py, pinIndex, 26, 101)
      default: resultis illegal
      ]
   ]

and CableConnectors(pyy, index, connsize, bias) = valof
   [
   if (index ls 1) % (index gr connsize) then resultis illegal
   @pyy = bias * 4 - ((index - 1) / 2) * 4; resultis absolute
   ]

and GNDPinPos(icinst, pin, px, py, pInfo; numargs na) = valof
   [
   DefaultArgs(lv na, -4, lv na)
   @pInfo = noDisconnect + noReconnect + BottomLevel
   if (pin ls 1) % (pin gr 826) then resultis illegal

   if pin ls 28 do
      [ let group = (pin - 1) / 9
      let subpin = (pin - 1) rem 9
      let xoffset = nil
      test subpin ls 5
         ifso [ xoffset = 0; @py = ((subpin) * 10 * 4) + (14 * 4) ]
         ifnot [ xoffset = 4; @py = ((subpin - 5) * 10 * 4) + (19 * 4) ]
      @px = 8 * 4 + (group * 3 * 4) + xoffset
      resultis absolute ]

   if pin ls 37 do
      [ @px = 17 * 4; @py = ((pin - 28) * 5 * 4) + (14 * 4)
      resultis absolute ]

   if pin ls 42 do
      [ @px = 20 * 4; @py = ((pin - 37) * 10 * 4) + (14 * 4)
      resultis absolute ]

   if pin ls 46 do
      [ @px = 21 * 4; @py = ((pin - 42) * 10 * 4) + (19 * 4)
      resultis absolute ]

   if pin ls 55 do
      [ @px = 23 * 4; @py = ((pin - 46) * 5 * 4) + (14 * 4)
      resultis absolute ]

   if pin ls 145 do
      [ let group = (pin - 55) / 9
      let subpin = (pin - 55) rem 9
      let xoffset = nil
      test subpin ls 5
         ifso [ xoffset = 0; @py = ((subpin) * 10 * 4) + (14 * 4) ]
         ifnot [ xoffset = 4; @py = ((subpin - 5) * 10 * 4) + (19 * 4) ]
      @px = 26 * 4 + (group * 3 * 4) + xoffset
      resultis absolute ]

   if pin ls 154 do
      [ @px = 56 * 4; @py = ((pin - 145) * 5 * 4) + (14 * 4)
      resultis absolute ]

   if pin ls 159 do
      [ @px = 59 * 4; @py = ((pin - 154) * 10 * 4) + (14 * 4)
      resultis absolute ]

   if pin ls 163 do
      [ @px = 60 * 4; @py = ((pin - 159) * 10 * 4) + (19 * 4)
      resultis absolute ]

   if pin ls 174 do
      [ @px = 62 * 4; @py = ((pin - 163) * 5 * 4) + (4 * 4)
      if @py eq (4 * 4) then @py = 5 * 4
      resultis absolute ]

   if pin ls 273 do
      [ let group = (pin - 174) / 11
      let subpin = (pin - 174) rem 11
      let xoffset = nil
      test subpin ls 6
         ifso [ xoffset = 0; @py = ((subpin) * 40) + (4 * 4) ]
         ifnot [ xoffset = 4; @py = ((subpin - 6) * 40) + (9 * 4) ]
      @px = 65 * 4 + (group * 3 * 4) + xoffset
      if @py eq (4 * 4) then @py = 5 * 4
      resultis absolute ]

   if pin ls 284 do
      [ @px = 92 * 4; @py = ((pin - 273) * 5 * 4) + (4 * 4)
      if @py eq (4 * 4) then @py = 5 * 4
      resultis absolute ]

   if pin ls 290 do
      [ @px = 95 * 4; @py = ((pin - 284) * 10 * 4) + (4 * 4)
      if @py eq (4 * 4) then @py = 5 * 4
      resultis absolute ]

   if pin ls 295 do
      [ @px = 96 * 4; @py = ((pin - 290) * 10 * 4) + (9 * 4)
      if @py eq (4 * 4) then @py = 5 * 4
      resultis absolute ]

   if pin ls 306 do
      [ @px = 98 * 4; @py = ((pin - 295) * 5 * 4) + (4 * 4)
      if @py eq (4 * 4) then @py = 5 * 4
      resultis absolute ]

   if pin ls 383 do
      [ let group = (pin - 306) / 11
      let subpin = (pin - 306) rem 11
      let xoffset = nil
      test subpin ls 6
         ifso [ xoffset = 0; @py = ((subpin) * 10 * 4) + (4 * 4) ]
         ifnot [ xoffset = 4; @py = ((subpin - 6) * 10 * 4) + (9 * 4) ]
      @px = 101 * 4 + (group * 3 * 4) + xoffset
      if @py eq (4 * 4) then @py = 5 * 4
      resultis absolute ]


// Right Side

   if pin ls 419 do
      [ let group = (pin - 383) / 12
      let subpin = (pin - 383) rem 12
      let xoffset = nil
      test subpin ls 6
         ifso [ xoffset = 0; @py = ((subpin) * 10 * 4) + (64 * 4) ]
         ifnot [ xoffset = 4; @py = ((subpin - 6) * 10 * 4) + (59 * 4) ]
      @px = 8 * 4 + (group * 3 * 4) + xoffset
      resultis absolute ]

   if pin ls 431 do
      [ @px = 17 * 4; @py = ((pin - 419) * 5 * 4) + (59 * 4)
      resultis absolute ]

   if pin ls 437 do
      [ @px = 20 * 4; @py = ((pin - 431) * 10 * 4) + (64 * 4)
      resultis absolute ]

   if pin ls 443 do
      [ @px = 21 * 4; @py = ((pin - 437) * 10 * 4) + (59 * 4)
      resultis absolute ]

   if pin ls 455 do
      [ @px = 23 * 4; @py = ((pin - 443) * 5 * 4) + (59 * 4)
      resultis absolute ]

   if pin ls 479 do
      [ let group = (pin - 455) / 12
      let subpin = (pin - 455) rem 12
      let xoffset = nil
      test subpin ls 6
         ifso [ xoffset = 0; @py = ((subpin) * 10 * 4) + (64 * 4) ]
         ifnot [ xoffset = 4; @py = ((subpin - 6) * 10 * 4) + (59 * 4) ]
      @px = 26 * 4 + (group * 3 * 4) + xoffset
      resultis absolute ]

   if pin ls 491 do
      [ @px = 32 * 4; @py = ((pin - 479) * 5 * 4) + (59 * 4)
      resultis absolute ]

   if pin ls 533 do
      [ let group = (pin - 491) / 6
      let subpin = (pin - 491) rem 6
      let xoffset = nil
      test subpin ls 3
         ifso [ xoffset = 0; @py = ((subpin) * 20 * 4) + (74 * 4) ]
         ifnot [ xoffset = 4; @py = ((subpin - 3) * 20 * 4) + (77 * 4) ]
      if @py eq (117 * 4) then @py = 115 * 4
      @px = 33 * 4 + (group * 2 * 4) + xoffset
      resultis absolute ]

   if pin ls 563 do
      [ let group = (pin - 533) / 12
      let subpin = (pin - 533) rem 12
      let xoffset = nil
      test subpin ls 6
         ifso [ xoffset = 0; @py = ((subpin) * 10 * 4) + (59 * 4) ]
         ifnot [ xoffset = 4; @py = ((subpin - 6) * 10 * 4) + (64 * 4) ]
      @px = 47 * 4 + (group * 2 * 4) + xoffset
      resultis absolute ]

   if pin ls 605 do
      [ let group = (pin - 563) / 6
      let subpin = (pin - 563) rem 6
      let xoffset = nil
      test subpin ls 3
         ifso [ xoffset = 0; @py = ((subpin) * 20 * 4) + (74 * 4) ]
         ifnot [ xoffset = 4; @py = ((subpin - 3) * 20 * 4) + (77 * 4) ]
      if @py eq (117 * 4) then @py = 115 * 4
      @px = 52 * 4 + (group * 2 * 4) + xoffset
      resultis absolute ]

   if pin ls 635 do
      [ let group = (pin - 605) / 12
      let subpin = (pin - 605) rem 12
      let xoffset = nil
      test subpin ls 6
         ifso [ xoffset = 0; @py = ((subpin) * 10 * 4) + (59 * 4) ]
         ifnot [ xoffset = 4; @py = ((subpin - 6) * 10 * 4) + (64 * 4) ]
      @px = 66 * 4 + (group * 2 * 4) + xoffset
      resultis absolute ]

   if pin ls 677 do
      [ let group = (pin - 635) / 6
      let subpin = (pin - 635) rem 6
      let xoffset = nil
      test subpin ls 3
         ifso [ xoffset = 0; @py = ((subpin) * 20 * 4) + (74 * 4) ]
         ifnot [ xoffset = 4; @py = ((subpin - 3) * 20 * 4) + (77 * 4) ]
      if @py eq (117 * 4) then @py = 115 * 4
      @px = 71 * 4 + (group * 2 * 4) + xoffset
      resultis absolute ]

   if pin ls 683 do
      [ @px = 85 * 4; @py = ((pin - 677) * 10 * 4) + (59 * 4)
      resultis absolute ]

   if pin ls 707 do
      [ let group = (pin - 683) / 12
      let subpin = (pin - 683) rem 12
      let xoffset = nil
      test subpin ls 6
         ifso [ xoffset = 0; @py = ((subpin) * 40) + (64 * 4) ]
         ifnot [ xoffset = 4; @py = ((subpin - 6) * 40) + (59 * 4) ]
      @px = 86 * 4 + (group * 3 * 4) + xoffset
      resultis absolute ]

   if pin ls 719 do
      [ @px = 92 * 4; @py = ((pin - 707) * 5 * 4) + (59 * 4)
      resultis absolute ]

   if pin ls 725 do
      [ @px = 95 * 4; @py = ((pin - 719) * 10 * 4) + (64 * 4)
      if @py eq (4 * 4) then @py = 5 * 4
      resultis absolute ]

   if pin ls 731 do
      [ @px = 96 * 4; @py = ((pin - 725) * 10 * 4) + (59 * 4)
      resultis absolute ]

   if pin ls 743 do
      [ @px = 98 * 4; @py = ((pin - 731) * 5 * 4) + (59 * 4)
      resultis absolute ]

   if pin ls 827 do
      [ let group = (pin - 743) / 12
      let subpin = (pin - 743) rem 12
      let xoffset = nil
      test subpin ls 6
         ifso [ xoffset = 0; @py = ((subpin) * 10 * 4) + (64 * 4) ]
         ifnot [ xoffset = 4; @py = ((subpin - 6) * 10 * 4) + (59 * 4) ]
      @px = 101 * 4 + (group * 3 * 4) + xoffset
      resultis absolute ]

   resultis illegal

   ]