// TestDaffodilBR.bcpl  -- Program to test RouteDaffodil.br
//  Last modified by Diebert; June 15, 1983  2:57 PM

get "Streams.d"
get "route.defs"

external [ dsp; Ws; GNDPinPos; VCCPinPos ]
static [ OutFile; numLogic; numVCC; numGND; px; py; pPinNo; pInfo ]

manifest
   [
   GND = 0
   VCC = 1
   Logic = 2
   IO = 3

   firstGNDPin = 5588
   firstVCCPin = firstGNDPin + 826
   ]

let TestDaffodilBR() be
[

// set up output file
   Ws("Test Daffodil BR of June 15, 1983")
   OutFile = OpenFile("TestDaffodil.txt", ksTypeWriteOnly, charItem)
   if OutFile eq 0 then
      CallSwat("Bad Output FIle")

   numLogic = 1
   numVCC = 1
   numGND = 1

// Make upper left logic array
   for i = 700 to 5800 by 300 do
      MakeLineIncinY(i, 1200, 43)

// Add .4" array holes
   MakeLineIncinY(1800, 1200, 43)
   MakeLineIncinY(2400, 1200, 43)
   MakeLineIncinY(5700, 1200, 43)

// Make lower left logic array
   for i = 6100 to 12100 by 300 do
      MakeLineIncinY(i, 500, 50)

// Add .4" array holes
   MakeLineIncinY(6300, 500, 50)
   MakeLineIncinY(9300, 500, 50)
   MakeLineIncinY(9900, 500, 50)

// Make upper right logic array
   for i = 700 to 3100 by 300 do
      MakeLineIncinY(i, 5900, 57)

// Add .4' array holes
   MakeLineIncinY(1800, 5900, 57)
   MakeLineIncinY(2400, 5900, 57)

// Make 14x14 arrays
   for i = 3300 to 7100 by 1900 do
      [ for j = 5900 to 9900 by 2000 do
         Make14by14Array(i, j) ]

// Make lower right logic array
   for i = 8800 to 12100 by 300 do
      MakeLineIncinY(i, 5900, 57)

// Add .4" array holes
   MakeLineIncinY( 9300, 5900, 57)
   MakeLineIncinY( 9900, 5900, 57)

// Make card edge connectors
   MakeCardEdge()
   MakeCableConn(12500, 8400, 60)
   MakeDShell(5500, 1000, 25)
   MakeDShell(3000, 1000, 15)
   MakeTeleConn(1400, 1000, 4)
   MakeCableConn(500, 1700, 50)
   MakeCableConn(500, 5200, 50)
   MakeCableConn(500, 8900, 26)


// Make Power and Ground stuff

// Left Side Stuff

   for i = 800 to 1400 by 300 do
      [ MakeGndPower(i, 1400, 9)
      MakePowerGnd(i + 100, 1400, 9) ]

   MakeGnd(1700, 1400, 9)
   MakeGndPower(2000, 1400, 9)
   MakePowerGnd(2100, 1400, 9)
   MakeGnd(2300, 1400, 9)

   for i = 2600 to 5300 by 300 do
      [ MakeGndPower(i, 1400, 9)
      MakePowerGnd(i + 100, 1400, 9) ]

   MakeGnd(5600, 1400, 9)
   MakeGndPower(5900, 1400, 9)
   MakePowerGnd(6000, 1400, 9)

   MakeGnd(6200, 400, 11)

   for i = 6500 to 8900 by 300 do
      [ MakeGndPower(i, 400, 11)
      MakePowerGnd(i + 100, 400, 11) ]

   MakeGnd(9200, 400, 11)
   MakeGndPower(9500, 400, 11)
   MakePowerGnd(9600, 400, 11)
   MakeGnd(9800, 400, 11)

   for i = 10100 to 11900 by 300 do
      [ MakeGndPower(i, 400, 11)
      MakePowerGnd(i + 100, 400, 11) ]

// Right Side Stuff

   for i = 800 to 1400 by 300 do
      [ MakePowerGnd(i, 5900, 12)
      MakeGndPower(i + 100, 5900, 12) ]

   MakeGnd(1700, 5900, 12)
   MakePowerGnd(2000, 5900, 12)
   MakeGndPower(2100, 5900, 12)
   MakeGnd(2300, 5900, 12)

   for i = 2600 to 2900 by 300 do
      [ MakePowerGnd(i, 5900, 12)
      MakeGndPower(i + 100, 5900, 12) ]

   MakeGnd(3200, 5900, 12)
   for i = 3300 to 4600 by 200 do
      [ Make14pinGndPower(i, 7400)
      Make14pinPowerGnd(i + 100, 7400) ]

   for i = 4700 to 4900 by 200 do
      [ MakeGndPower(i, 5900, 12)
      MakePowerGnd(i + 100, 5900, 12) ]
   MakeGndPower(5100, 5900, 12)

   for i = 5200 to 6500 by 200 do
      [ Make14pinGndPower(i, 7400)
      Make14pinPowerGnd(i + 100, 7400) ]

   for i = 6600 to 6900 by 200 do
      [ MakeGndPower(i, 5900, 12)
      MakePowerGnd(i + 100, 5900, 12) ]
   MakeGndPower(7000, 5900, 12)

   for i = 7100 to 8400 by 200 do
      [ Make14pinGndPower(i, 7400)
      Make14pinPowerGnd(i + 100, 7400) ]

   MakeGndPower(8500, 5900, 12)
   for i = 8600 to 8900 by 300 do
      [ MakePowerGnd(i, 5900, 12)
      MakeGndPower(i + 100, 5900, 12) ]

   MakeGnd(9200, 5900, 12)
   MakePowerGnd(9500, 5900, 12)
   MakeGndPower(9600, 5900, 12)
   MakeGnd(9800, 5900, 12)

   for i = 10100 to 11900 by 300 do
      [ MakePowerGnd(i, 5900, 12)
      MakeGndPower(i + 100, 5900, 12) ]


   PutTemplate(dsp, "*n Num Logic $5D Num VCC $5D Num GND $5D", numLogic - 1, numVCC - 1, numGND - 1)
   Wss(OutFile, "*nDone")
   Closes(OutFile)

]

and MakeCardEdge() be
[
   MakeLineIncinY(12500, 1600, 5)
   MakeLineIncinY(12600, 1600, 5)

   MakeLineIncinY(12500, 2300, 5)
   MakeLineIncinY(12600, 2300, 5)

   MakeLineIncinY(12500, 3100, 5)
   MakeLineIncinY(12600, 3100, 5)

   MakeLineIncinY(12500, 3900, 5)
   MakeLineIncinY(12600, 3900, 5)

   MakeLineIncinY(12500, 4700, 5)
   MakeLineIncinY(12600, 4700, 5)

   MakeLineIncinY(12500, 5500, 6)
   MakeLineIncinY(12600, 5500, 6)

   MakeLineIncinY(12500, 1000, 2)
   MakeLineIncinY(12500, 6500, 2)

]

and MakeCableConn(x, y, pins) be
[
   MakeLineIncinY(x, y, pins/2)
   MakeLineIncinY(x + 100, y, pins/2)
]

and MakeDShell(x, y, pins) be
[
   MakeLineDecinX(x, y, (pins + 1)/ 2)
   MakeLineDecinX(x, y - 100, (pins - 1)/ 2)
]

and MakeTeleConn(x, y, pins) be
[
   MakeLineDecinX(x, y, pins)
]

and MakeLineIncinY(x, y, pins) be
[
   for i = y to (y + ((pins - 1) * 100)) by 100 do
      [ GenPoint(Logic, x, i, numLogic); numLogic = numLogic + 1 ]
]

and MakeLineDecinX(x, y, pins) be
[
   for i = x to (x - ((pins - 1) * 100)) by -100 do
      [ GenPoint(Logic, i, y, numLogic); numLogic = numLogic + 1 ]
]

and Make14by14Array(x, y) be
[
   for i = x to (x + 1300) by 100 do
      MakeLineIncinY(i, y, 14)
]

and Make14pinGndPower(x, y) be
[
   GenPoint(GND, x, y, numGND); numGND = numGND + 1
   GenPoint(VCC, x, y + 300, numVCC); numVCC = numVCC + 1
   GenPoint(GND, x, y + 2000, numGND); numGND = numGND + 1
   GenPoint(VCC, x, y + 2300, numVCC); numVCC = numVCC + 1
   GenPoint(GND, x, y + 4000, numGND); numGND = numGND + 1
   GenPoint(VCC, x, y + 4100, numVCC); numVCC = numVCC + 1
]

and Make14pinPowerGnd(x, y) be
[
   GenPoint(VCC, x, y, numVCC); numVCC = numVCC + 1
   GenPoint(GND, x, y + 300, numGND); numGND = numGND + 1
   GenPoint(VCC, x, y + 2000, numVCC); numVCC = numVCC + 1
   GenPoint(GND, x, y + 2300, numGND); numGND = numGND + 1
   GenPoint(VCC, x, y + 4000, numVCC); numVCC = numVCC + 1
   GenPoint(GND, x, y + 4100, numGND); numGND = numGND + 1
]

and MakeGndPower(x, y, count) be
[
   for i = 1 to count do
      [ let even = (i - 1) rem 2
      if even eq 0 do
         [ GenPoint(GND, x, ((i eq 1) & (y eq 400)? 500, y + ((i - 1) * 500)), numGND)
         numGND = numGND + 1 ]
      if even eq 1 do
         [ GenPoint(VCC, x, y + ((i - 1) * 500), numVCC)
         numVCC = numVCC + 1 ]
      ]
]

and MakePowerGnd(x, y, count) be
[
   for i = 1 to count do
      [ let even = (i - 1) rem 2
      if even eq 0 do
         [ GenPoint(VCC, x, ((i eq 1) & (y eq 400)? 500, y + ((i - 1) * 500)), numVCC)
         numVCC = numVCC + 1 ]
      if even eq 1 do
         [ GenPoint(GND, x, y + ((i - 1) * 500), numGND)
         numGND = numGND + 1 ]
      ]
]

and MakeGnd(x, y, count) be
[
   for i = 1 to count do
      [
      GenPoint(GND, x, ((i eq 1) & (y eq 400)? 500, y + ((i - 1) * 500)), numGND)
      numGND = numGND + 1
      ]
]

and GenPoint(type, x, y, num) be
[
   let v = vec 1; px = v
   let v = vec 1; py = v
   let v = vec 1; pPinNo = v
   let v = vec 1; pInfo = v
   @px = 0
   @py = 0
   @pPinNo = 0
   @pInfo = 0
   let okflag = true
   let text = vec 20
   let foo = 0
   let foo2 = 0
   let foo3 = 0
   switchon type into
      [
      case GND:
         [
         foo = GNDPinPos(0, num, px, py, pInfo)
         if (@px ne x/25) % (@py ne y/25) then okflag = false
         text = "GND  "
         foo2 = FindIndexFromCoord(x/25, y/25, foo3, pPinNo)
         if @pPinNo ne num then okflag = false
         if foo2 ne (num + firstGNDPin) then okflag = false
         endcase
         ]
      case VCC:
         [
         foo = VCCPinPos(0, num, px, py, pInfo)
         if (@px ne x/25) % (@py ne y/25) then okflag = false
         text = "VCC  "
         foo2 = FindIndexFromCoord(x/25, y/25, foo3, pPinNo)
         if @pPinNo ne num then okflag = false
         if foo2 ne (num + firstVCCPin) then okflag = false
         endcase
         ]
      case Logic:
         [
         foo = FindIndexFromCoord(x/25, y/25, foo3, pPinNo)
         if foo ne num then okflag = false
         text = "Logic"
         endcase
         ]
      ]
   unless okflag do
      PutTemplate(OutFile, "$S  $5D  $5D  $5D  $5D  $5D  $5D  $5D  $5D*N", text, x, y, num, foo, foo2, @px*25, @py*25, @pPinNo)
]

and MustFindNamee(a, b) = valof
[ resultis 0 ]