//  RouteDaffodilC.bcpl
//  Route description of Daffodil Board part C (3 of 4)
//  Last modified June 15, 1983  1:05 PM by Diebert

get "route.defs"
external [ VCCPinPos; UpperLeft; LowerLeft; Right; PinGridPower; InArray; Center ]

manifest
   [
   firstDipPin = 1
   firstJ1Pin = firstDipPin + 5292
   firstJ2Pin = firstJ1Pin + 66
   firstJ3Pin = firstJ2Pin + 60
   firstJ4Pin = firstJ3Pin + 25
   firstJ5Pin = firstJ4Pin + 15
   firstJ6Pin = firstJ5Pin + 4
   firstJ7Pin = firstJ6Pin + 50
   firstJ8Pin = firstJ7Pin + 50
   firstGNDPin = firstJ8Pin + 26
   firstVCCPin = firstGNDPin + 826
   NextIndex  = firstVCCPin + 706
   ]
 manifest
   [
   GND = 0
   VCC = 1
   ]

let 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

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

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

   x = x * 25; y = y * 25	// convert to .001

   // Check for J1 & J2
   if x gr 12100 do
      [ if x eq 12500 do
         [
         if InArray(y, 100, 1600, 2000) then resultis (y-1600)/100  +  firstJ1Pin
         if InArray(y, 100, 2300, 2700) then resultis (y-2300)/100 + firstJ1Pin + 10
         if InArray(y, 100, 3100, 3500) then resultis (y-3100)/100 + firstJ1Pin + 20
         if InArray(y, 100, 3900, 4300) then resultis (y-3900)/100 + firstJ1Pin + 30
         if InArray(y, 100, 4700, 5100) then resultis (y-4700)/100 + firstJ1Pin + 40
         if InArray(y, 100, 5500, 6000) then resultis (y-5500)/100 + firstJ1Pin + 50
         if InArray(y, 100, 1000, 1100) then resultis (y-1000)/100 + firstJ1Pin + 62
         if InArray(y, 100, 6500, 6600) then resultis (y-6500)/100 + firstJ1Pin + 64
         if InArray(y, 100, 8400, 11300) then resultis (y-8400)/100 + firstJ2Pin
         ]

      if x eq 12600 do
         [
         if InArray(y, 100, 1600, 2000) then resultis (y-1600)/100 + firstJ1Pin + 5
         if InArray(y, 100, 2300, 2700) then resultis (y-2300)/100 + firstJ1Pin + 15
         if InArray(y, 100, 3100, 3500) then resultis (y-3100)/100 + firstJ1Pin + 25
         if InArray(y, 100, 3900, 4300) then resultis (y-3900)/100 + firstJ1Pin + 35
         if InArray(y, 100, 4700, 5100) then resultis (y-4700)/100 + firstJ1Pin + 45
         if InArray(y, 100, 5500, 6000) then resultis (y-5500)/100 + firstJ1Pin + 56
         if InArray(y, 100, 8400, 11300) then resultis (y-8400)/100 + firstJ2Pin  +  30
         ]
      resultis 0
      ]

   // Check for J3-J5
   if x ls 6100 & y ls 1200 do
      [
      if y eq 1000 do
         [
         if InArray(x, 100, 4300, 5500) then resultis firstJ3Pin + (5500-x) / 100
         if InArray(x, 100, 2300, 3000) then resultis firstJ4Pin + (3000-x) / 100
         if InArray(x, 100, 1100, 1400) then resultis firstJ5Pin + (1400-x) / 100
         ]
      if y eq 900 do
         [
         if InArray(x, 100, 4400, 5500) then resultis firstJ3Pin + 13 + (5500-x) / 100
         if InArray(x, 100, 2400, 3000) then resultis firstJ4Pin + 8 + (3000-x) / 100
         ]
      resultis 0
      ]

   // Check for J6-J8
   if x ls 700 do
      [ if x eq 500 do
         [ if InArray(y, 100, 1700,4100) then resultis (y-1700) / 100 + firstJ6Pin
         if InArray(y, 100, 5200, 7600) then resultis (y-5200) / 100 + firstJ7Pin
         if InArray(y, 100, 8900, 10100) then resultis (y-8900) / 100 + firstJ8Pin ]
      if x eq 600 do
         [ if InArray(y, 100, 1700,4100) then resultis (y-1700) / 100 + firstJ6Pin + 25
         if InArray(y, 100, 5200, 7600) then resultis (y-5200) / 100 + firstJ7Pin + 25
         if InArray(y, 100, 8900, 10100) then resultis (y-8900) / 100 + firstJ8Pin + 13 ]
      resultis 0
      ]

// do main logic array
   if (x ge 700) & (x le 6000) & (y ge 1200) & (y le 5400) do
      [ 
      if InArray(x, 300, 700, 6000) then
         resultis (y-1200)/100 + firstDipPin + ((x-700)/300) * 43
      if x eq 1800 then resultis (y-1200)/100 + firstDipPin + 774
      if x eq 2400 then resultis (y-1200)/100 + firstDipPin + 817
      if x eq 5700 then resultis (y-1200)/100 + firstDipPin + 860
      unless InArray(y, 500, 1400, 5400) do resultis 0

      if (x ge 800) & (x le 1500) then resultis UpperLeft(x-800, y, 1, 1, pPinNo, picclass)
      if x eq 1700 do
         [ @pPinNo = (y-1400)/500 + 28
         @picclass = MustFindNamee("GND",typeIcclass)
         resultis @pPinNo + firstGNDPin -1 ]
      if x le 2100 then resultis UpperLeft(x-2000, y, 37, 28, pPinNo, picclass)
      if x eq 2300 do
         [ @pPinNo = (y-1400)/500 + 46
         @picclass = MustFindNamee("GND",typeIcclass)
         resultis @pPinNo + firstGNDPin -1 ]
      if x le 5400 then resultis UpperLeft(x-2600, y, 55, 37, pPinNo, picclass)
      if x eq 5600 do
         [ @pPinNo = (y-1400)/500 + 145
         @picclass = MustFindNamee("GND",typeIcclass)
         resultis @pPinNo + firstGNDPin -1 ]
      if x le 6000 then resultis UpperLeft(x-5900, y, 154, 127, pPinNo, picclass)
      resultis 0
      ]


   if (x ge 6100) & (x le 12100) & (y ge 500) & (y le 5400) do
      [
      if InArray(x, 300, 6100, 12100) then
         resultis (y-500)/100 + firstDipPin + ((x-6100)/300)*50 + 903
      if x eq 6300 then resultis (y-500)/100 + firstDipPin + 1953
      if x eq 9300 then resultis (y-500)/100 + firstDipPin + 2003
      if x eq 9900 then resultis (y-500)/100 + firstDipPin + 2053
      unless (y eq 500) % (InArray(y, 500, 900, 5900)) then resultis 0
      if x eq 6200 do
         [ if y eq 500 then y = 400
         @pPinNo = (y-400)/500 + 163
         @picclass = MustFindNamee("GND",typeIcclass)
         resultis @pPinNo + firstGNDPin -1 ]
      if x le 9000 then resultis LowerLeft(x-6500, y, 174, 136, pPinNo, picclass)
      if x eq 9200 do
         [ if y eq 500 then y = 400
         @pPinNo = (y-400)/500 + 273
         @picclass = MustFindNamee("GND",typeIcclass)
         resultis @pPinNo + firstGNDPin -1 ]
      if x le 9600 then resultis LowerLeft(x-9500, y, 284, 235, pPinNo, picclass)
      if x eq 9800 do
         [ if y eq 500 then y = 400
         @pPinNo = (y-400)/500 + 295
         @picclass = MustFindNamee("GND",typeIcclass)
         resultis @pPinNo + firstGNDPin -1 ]
      if x le 12000 then resultis LowerLeft(x-10100, y, 306, 246, pPinNo, picclass)
      resultis 0
      ]


   if (x ge 700) & (x le 3200) & (y ge 5900) & (y le 11500) do
      [
      if InArray(x, 300, 700, 3100) then
         resultis (y-5900)/100 + firstDipPin + ((x-700)/300)*57 + 2103
      if x eq 1800 then resultis (y-5900)/100 + firstDipPin + 2616
      if x eq 2400 then resultis (y-5900)/100 + firstDipPin + 2673
      unless InArray(y, 500, 5900, 11400) do resultis 0
      if x le 1500 then resultis Right(x-800, y, 383, 323, pPinNo, picclass)
      if x eq 1700 do
         [ @pPinNo = (y-5900)/500 + 419
         @picclass = MustFindNamee("GND",typeIcclass)
         resultis @pPinNo + firstGNDPin -1 ]
      if x le 2100 then resultis Right(x-2000, y, 431, 359, pPinNo, picclass)
      if x eq 2300 do
         [ @pPinNo = (y-5900)/500 + 443
         @picclass = MustFindNamee("GND",typeIcclass)
         resultis @pPinNo + firstGNDPin -1 ]
      if x le 3000 then resultis Right(x-2600, y, 455, 371, pPinNo, picclass)
      if x eq 3200 do
         [ @pPinNo = (y-5900)/500 + 479
         @picclass = MustFindNamee("GND",typeIcclass)
         resultis @pPinNo + firstGNDPin -1 ]
      resultis 0
      ]

   if (x ge 3300) & (x le 8700) & (y ge 5900) & (y le 11500) do
      [
      if (x ge 3300) & (x le 4600) & (y ge 5900) & (y le 7200) then
         resultis (y-5900)/100 + ((x-3300)/100)*14 + firstDipPin + 2730
      if (x ge 3300) & (x le 4600) & (y ge 7900) & (y le 9200) then
         resultis (y-7900)/100 + ((x-3300)/100)*14 + firstDipPin + 2926
      if (x ge 3300) & (x le 4600) & (y ge 9900) & (y le 11200) then
         resultis (y-9900)/100 + ((x-3300)/100)*14 + firstDipPin + 3122
      if (x ge 5200) & (x le 6500) & (y ge 5900) & (y le 7200) then
         resultis (y-5900)/100 + ((x-5200)/100)*14 + firstDipPin + 3318
      if (x ge 5200) & (x le 6500) & (y ge 7900) & (y le 9200) then
         resultis (y-7900)/100 + ((x-5200)/100)*14 + firstDipPin + 3514
      if (x ge 5200) & (x le 6500) & (y ge 9900) & (y le 11200) then
         resultis (y-9900)/100 + ((x-5200)/100)*14 + firstDipPin + 3710
      if (x ge 7100) & (x le 8400) & (y ge 5900) & (y le 7200) then
         resultis (y-5900)/100 + ((x-7100)/100)*14 + firstDipPin + 3906
      if (x ge 7100) & (x le 8400) & (y ge 7900) & (y le 9200) then
         resultis (y-7900)/100 + ((x-7100)/100)*14 + firstDipPin + 4102
      if (x ge 7100) & (x le 8400) & (y ge 9900) & (y le 11200) then
         resultis (y-9900)/100 + ((x-7100)/100)*14 + firstDipPin + 4298

      unless (y eq 7700) % (y eq 9700) % (y eq 11500) % 
         InArray(y, 500, 5900, 11400) do resultis 0
      if x le 4600 then resultis PinGridPower(x-3300, y, 491, 395, pPinNo, picclass)
      if x le 5100 then resultis Center(x-4700, y, 533, 437, pPinNo, picclass)
      if x le 6500 then resultis PinGridPower(x-5200, y, 563, 467, pPinNo, picclass)
      if x le 7000 then resultis Center(x-6600, y, 605, 509, pPinNo, picclass)
      if x le 8400 then resultis PinGridPower(x-7100, y, 635, 539, pPinNo, picclass)
      if x le 8700 then resultis Center(x-8500, y, 677, 581, pPinNo, picclass)
      resultis 0
      ]
   
   if (x ge 8800) & (x le 12100) & (y ge 5900) & (y le 11500) do
      [
      if InArray(x, 300, 8800, 12100) then
         resultis (y-5900)/100 + firstDipPin + ((x-8800)/300)*57 + 4494
      if x eq 9300 then resultis (y-5900)/100 + firstDipPin + 5178
      if x eq 9900 then resultis (y-5900)/100 + firstDipPin + 5235
      unless InArray(y, 500, 5900, 11400) then resultis 0
      if x le 9000 then resultis Right(x-8900, y, 695, 599, pPinNo, picclass)
      if x eq 9200 do
         [ @pPinNo = (y-5900)/500 + 707
         @picclass = MustFindNamee("GND",typeIcclass)
         resultis @pPinNo + firstGNDPin -1 ]
      if x le 9600 then resultis Right(x-9500, y, 719, 611, pPinNo, picclass)
      if x eq 9800 do
         [ @pPinNo = (y-5900)/500 + 731
         @picclass = MustFindNamee("GND",typeIcclass)
         resultis @pPinNo + firstGNDPin -1 ]
      if x le 12000 then resultis Right(x-10100, y, 743, 623, pPinNo, picclass)
      resultis 0
      ]
   resultis 0

   ]