//   DDTapeServerDispUtil.bcpl -- Dual Density Tape Server Display utilities 
//  last modified by Tim Diebert, March 16, 1981  7:49 PM
//
get   "Pup.decl"
get   "DDTapes.d"
get   "AltoDefs.d"
get   "DDTapeServer.decl"

//---------------------------------------------------------------
external
//---------------------------------------------------------------
[
//From Timer
   SetTimer; TimerHasExpired; Dismiss
//From 'System'
   Gets; Resets; LoadRam; CallSwat; lvUserFinishProc; lvSwatContextProc
   FixedLeft; Usc; AddToZone; sysZone; GetFixed; SetBLV; StartIO
   Allocate; InitializeZone; Enqueue; InitializeContext; CallContextList
   Block; Unqueue; Dequeue; MoveBlock; Free; Ws; InitBcplRuntime; SetEndCode
   Zero
// To Tapes
   TapeWaitQuiet
// To DDTapeServer and DDTapeServerDOs
   InitDisplay; DWs; DWo; MonitorKeys
//From Pup
   InitPupLevel1; OpenLevel1Socket; OpenRTPSocket; CreateBSPStream
   BSPReadBlock; BSPWriteBlock; BSPForceOutput; ExchangePorts
   ReleasePBI; CompletePup; AppendStringToPup; BSPGetMark; PupChecksum
//From Streams 
   Wo; Endofs; Closes; keys
//Exported Globals
   rwBlock; kbdKey; rwKey; usedidnos; useddrives; ctxQ; currentVersionString
   numConnections
]

static
[
TimerValue
tempDCB
savedDCB
DispOnFlag
]

//---------------------------------------------------------------
let InitDisplay() be
//---------------------------------------------------------------
[
   // set up cursor
   cursorBitMap!0 = #177000
   cursorBitMap!1 = #111000
   cursorBitMap!2 = #010000
   cursorBitMap!3 = #010000
   cursorBitMap!4 = #011700
   cursorBitMap!5 = #012100
   cursorBitMap!6 = #012000
   cursorBitMap!7 = #011600
   cursorBitMap!8 = #000176
   cursorBitMap!9 = #002121
   cursorBitMap!10 = #002121
   cursorBitMap!11 = #001621
   cursorBitMap!12 = #000036
   cursorBitMap!13 = #000020
   cursorBitMap!14 = #000020
   cursorBitMap!15 = #000020
   savedDCB = @displayListHead
   tempDCB = Allocate(sysZone, lDCB, true, true)
   unless tempDCB then CallSwat(" Help")
   Zero(tempDCB, lDCB)
   tempDCB>>DCB.next = 0
   tempDCB>>DCB.background = 1
   tempDCB>>DCB.height = 500
   @displayListHead = tempDCB
   DDTapeVertIntFlag = false
   until DDTapeVertIntFlag do Block()
   DDTapeVertIntFlag = false
   until DDTapeVertIntFlag do Block()
   @displayListHead = 0
   DDTapeVertIntFlag = false
   until DDTapeVertIntFlag do Block()
   DispOnFlag = false
]

//---------------------------------------------------------------
and DWs(foo) be
//---------------------------------------------------------------
[
   while TapeActive do Dismiss(1)
   SetTimer(lv TimerValue, 3000)
   unless DispOnFlag then @displayListHead = savedDCB
   Ws(foo)
   DispOnFlag = true
]

//---------------------------------------------------------------
and DWo(foo) be
//---------------------------------------------------------------
[
   while TapeActive do Dismiss(1)
   SetTimer(lv TimerValue, 3000)
   unless DispOnFlag then @displayListHead = savedDCB
   Wo(foo)
   DispOnFlag = true
]

//---------------------------------------------------------------
and MonitorKeys() be
//---------------------------------------------------------------
[
   test DispOnFlag
      ifso
         [
         test TimerHasExpired(lv TimerValue)
            ifso
               [
               until @displayListHead ne 0 do Dismiss(1)
               while TapeActive do Dismiss(1)
               savedDCB = @displayListHead
               @displayListHead = tempDCB
               DDTapeVertIntFlag = false
               until DDTapeVertIntFlag do Block()
               DDTapeVertIntFlag = false
               until DDTapeVertIntFlag do Block()
               while TapeActive do Dismiss(1)
               @displayListHead = 0
               DDTapeVertIntFlag = false
               until DDTapeVertIntFlag do Block()
               DDTapeVertIntFlag = false
               until DDTapeVertIntFlag do Block()
               DispOnFlag = false
               ]
            ifnot
               [
               ]
         ]

      ifnot
         [
         ]

   if kbdKey eq -1 do
      [
      if @kbdAd ne #177777 do OnWithIT()
      if @(kbdAd + 1) ne #177777 do OnWithIT()
      if @(kbdAd + 2) ne #177777 do OnWithIT()
      if @(kbdAd + 3) ne #177777 do OnWithIT()
      if ( @(kbdAd + 1) eq #167767) & (numConnections eq 0) do
        [
        Resets(keys)
        finish
        ]
      Resets(keys)
      ]
   Dismiss(10)

] repeat

//---------------------------------------------------------------
and OnWithIT() be
//---------------------------------------------------------------
[
   while TapeActive do Dismiss(1)
   SetTimer(lv TimerValue, 1500)
   if @displayListHead eq 0 do
      [
      @displayListHead = savedDCB
      DispOnFlag = true
      ]
]