// MakeDaffodilCard.bcpl  -- Program to generate tape of main logic array.
//  Last modified by Diebert August 18, 1983  9:09 AM

static [ OutFile; numLogic; numVCC; numGND ]
external [ PutTemplate; CallSwat; Closes; dsp; OpenFile; Ws; Wss ]

get "Streams.d"

let MakeDaffodilCard() be
[

// set up output file
   Ws("Daffodil Card of May 13, 1983")
   OutFile = OpenFile("DaffodilCard.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 4500 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 6400 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 8300 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)
   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
      [ PutRecord("Logic", x, i, numLogic); numLogic = numLogic + 1 ]
]

and MakeLineDecinX(x, y, pins) be
[
   for i = x to (x - ((pins - 1) * 100)) by -100 do
      [ PutRecord("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
[
   PutRecord("GND  ", x, y, numGND); numGND = numGND + 1
   PutRecord("VCC  ", x, y + 300, numVCC); numVCC = numVCC + 1
   PutRecord("GND  ", x, y + 2000, numGND); numGND = numGND + 1
   PutRecord("VCC  ", x, y + 2300, numVCC); numVCC = numVCC + 1
   PutRecord("GND  ", x, y + 4000, numGND); numGND = numGND + 1
   PutRecord("VCC  ", x, y + 4100, numVCC); numVCC = numVCC + 1
]

and Make14pinPowerGnd(x, y) be
[
   PutRecord("VCC  ", x, y, numVCC); numVCC = numVCC + 1
   PutRecord("GND  ", x, y + 300, numGND); numGND = numGND + 1
   PutRecord("VCC  ", x, y + 2000, numVCC); numVCC = numVCC + 1
   PutRecord("GND  ", x, y + 2300, numGND); numGND = numGND + 1
   PutRecord("VCC  ", x, y + 4000, numVCC); numVCC = numVCC + 1
   PutRecord("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
         [ PutRecord("GND  ", x, ((i eq 1) & (y eq 400)? 500, y + ((i - 1) * 500)), numGND)
         numGND = numGND + 1 ]
      if even eq 1 do
         [ PutRecord("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
         [ PutRecord("VCC  ", x, ((i eq 1) & (y eq 400)? 500, y + ((i - 1) * 500)), numVCC)
         numVCC = numVCC + 1 ]
      if even eq 1 do
         [ PutRecord("GND  ", x, y + ((i - 1) * 500), numGND)
         numGND = numGND + 1 ]
      ]
]

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

and PutRecord(text, x, y, num) be
[
   PutTemplate(OutFile, "$S     $5D     $5D     $5D *N", text, x, y, num)
]