// ResistDisInit.bcpl -- Display initialization

// Last modified December 6, 1979  12:21 PM

get "Resist.decl"
get "Streams.d"
get "AltoDefs.d"

external
[
// outgoing procedures
InitDisplay1; InitDisplay2

// incoming procedures
CreateDisplayStream; ShowDisplayStream; SetBitPos
Wss; Puts
Allocate; Zero; DefaultArgs

// incoming statics
dsp; lastShownDsp; statusDsp; singleDsp; dipDsp
bar1DCB; bar2DCB; lastIC; lastSingleOhms
maxNPins
TimesRoman12; TimesRoman18
sysZone
]

structure AL:
[
height word
proportional bit
baseLine bit 7
charWidth bit 8
]

// ---------------------------------------------------------------------------
let InitDisplay1() be
// ---------------------------------------------------------------------------
[
FixupFont(TimesRoman12)
FixupFont(TimesRoman18)

lastShownDsp = 0
dsp = MakeWindow(4, TimesRoman12, 38, 20)

lastShownDsp = dsp
MakeBar(1, 0)
lastShownDsp = dsp
bar1DCB = MakeBar(2, 1)>>DS.ldcb
bar2DCB = MakeBar(4, 0)>>DS.fdcb
bar1DCB>>DCB.next = 0
statusDsp = MakeWindow(2, TimesRoman18, 32)
MakeBar(4, 0)
MakeBar(2, 1)

MakeBar(4, 0)
let tempDsp = MakeWindow(1, TimesRoman12, 10)
IndentWindow(tempDsp, 14)
Wss(tempDsp, "Single probe:")
MakeBar(4, 0)
singleDsp = MakeWindow(1, TimesRoman18, 4)
IndentWindow(singleDsp, 15)
MakeBar(4, 0)
MakeBar(2, 1)

MakeBar(4, 0)
tempDsp = MakeWindow(1, TimesRoman12, 24)
Wss(tempDsp, "Pin")
SetBitPos(tempDsp, 65)
Wss(tempDsp, "Expected")
SetBitPos(tempDsp, 140)
Wss(tempDsp, "Measured")
SetBitPos(tempDsp, 225)
Wss(tempDsp, "Net")
IndentWindow(tempDsp, 8)
]

// ---------------------------------------------------------------------------
and InitDisplay2() be
// ---------------------------------------------------------------------------
[
MakeBar(4, 0)
dipDsp = MakeWindow(maxNPins, TimesRoman12, 24)
for i = 0 to maxNPins-1 do Puts(dipDsp, $*n)
IndentWindow(dipDsp, 8)

lastIC = Allocate(sysZone, lenIC + lenPin*maxNPins)
Zero(lastIC, lenIC + lenPin*maxNPins)
lastSingleOhms = -1
]

// ---------------------------------------------------------------------------
and MakeWindow(nLines, font, wWidth, allocWWidth; numargs na) = valof
// ---------------------------------------------------------------------------
[
DefaultArgs(lv na, -3, wWidth)
let fontHeight = ((font-2)>>AL.height +1) & -2
let words = lDCB*nLines + fontHeight*allocWWidth*nLines +10
let ds = CreateDisplayStream(nLines, Allocate(sysZone, words), words,
 font, wWidth, (allocWWidth eq wWidth? DSstopright+DSstopbottom, 0))
ShowDisplayStream(ds, (lastShownDsp eq 0? DSalone, DSbelow), lastShownDsp)
lastShownDsp = ds
resultis ds
]

// ---------------------------------------------------------------------------
and IndentWindow(ds, indentation) be
// ---------------------------------------------------------------------------
[
let dcb = ds>>DS.fdcb
   [ // repeat
   dcb>>DCB.indentation = indentation
   if dcb eq ds>>DS.ldcb break
   dcb = dcb>>DCB.next
   ] repeat
]

// ---------------------------------------------------------------------------
and MakeBar(height, color) = valof
// ---------------------------------------------------------------------------
// Makes a black bar 2*height scan lines high
[
structure Bar: [ firstDCB word; lastDCB word; dcb: @DCB ]
manifest lenBar = size Bar/16
let bar = Allocate(sysZone, lenBar, false, true)
Zero(bar, lenBar)
bar>>Bar.firstDCB = lv bar>>Bar.dcb
bar>>Bar.lastDCB = lv bar>>Bar.dcb
bar>>Bar.dcb.background = color
bar>>Bar.dcb.height = height
ShowDisplayStream(bar, DSbelow, lastShownDsp)
lastShownDsp = bar
resultis bar
]

// ---------------------------------------------------------------------------
and FixupFont(font) be font!($*s + font!$*s) = font!($0 + font!$0)
// ---------------------------------------------------------------------------
// Fixes the space character in the font so that it is the same
// width as digits.