 Rem File: Dndcnfg for Dndbbs Version v5.0a Release r2.0 Tweak t6.0a
 Rem $Include: 'dndcnfg.inc'

 On Error Goto MainError
 Call Stdin(Var)
 If Chained=False Then
    Call Load.Config
 Endif
 Call Get.Config
 Call Load.Defaults(False)
 Call Init.Mouse
 If Chained=False Then
    Call Mouse.Driver(2)
    Call Save.Screen(False)
    Color 7,1 : Cls
    Call Mouse.Driver(1)
 Endif
 Call Passwrd4(Var)
 Close #TempFile1
 If Var=False Then
    Call Terminate.Program(True)
    End
 Endif
 If Len(Command$) Then
    If Chained=False Then
       Call Terminate.Program(1)
       End
    Endif
 Endif
 FileName=Nul
 Do While Lost.Carrier=False
    Call Display.Main.Screen
    Do While Lost.Carrier=False
       Strng3=Nul
       Do While Strng3=Nul
          If Lost.Carrier Then
             Exit Do
          Endif
	  Call Read.Keyboard(Strng3)
	  Call Mouse.Driver(3)
          If Mouse.Button Then
             Call Main.Mouse.Button
	     Exit Do
	  Endif
          If Mouse.Button2 Then
             Strng3=Chr$(27)
          Endif
          If Mouse.Button3 Then
             Call Terminate.Program(True)
             End
          Endif
          If Mouse.Row Or Mouse.Column Then
             Call Main.Mouse.Select
	  Endif
       Loop
       Select Case Len(Strng3)
       Case 1
	  Strng3=Ucase$(Strng3)
	  For Temp=1 To 8
             If Ucase$(Left$(Menu1(Temp),1))<>"*" Then
                If Strng3=Ucase$(Left$(Menu1(Temp),1)) Then
                   Call Main.Menu.Select
                   Call Main.Edit
                   Exit Do
                Endif
	     Endif
	  Next
	  Select Case Strng3
          Case Chr$(4) ' ^d
	     Call Load.Defaults(True)
	     Call Status.Line
             Call Main.Menu.Select2
          Case Chr$(8) ' ^h
             Call Help(19)
             Exit Do
          Case Chr$(9) ' tab
             Call Main.Select
          Case Chr$(13) ' <enter>
	     Call Main.Edit
	     Exit Do
          Case Chr$(18) ' ^r
             Call Read.Config
	     Call Status.Line
             Call Main.Menu.Select2
          Case Chr$(23) ' ^w
             Call Write.Config
	     Call Status.Line
             Call Main.Menu.Select2
          Case Chr$(27) ' <esc>
             Goto MainExit
	  End Select
       Case 2
          VarX=Asc(Right$(Strng3,1))
          If VarX=0 Then ' ctrl-break
             Goto MainExit
          Endif
	  Call Main.Select
	  If Strng3=Chr$(13) Then
	     Call Main.Edit
	     Exit Do
	  Endif
       End Select
    Loop
 Loop
MainExit:
 Call Terminate.Program(True)
 End
MainError:
 Resume MainExit

Function YN$(I%)
 If I%=False Then
    YN$="No"
 Else
    YN$="Yes"
 Endif
End Function

Sub Terminate.Program(Var)
 On Local Error Goto ErrorExit1
 Var$=Strng
 Call Mouse.Driver(2)
 If Var Then
    Call Clear.Screen
 Endif
 Erase Temp.ArrayS, Temp.Array1, Temp.Array2, Edit.Data,_
 Attack.Command, Command.Abbr, Command.Class, Command.Param,_
 Command.Set, Command.Limit, Command.Time, DMCommands, DMCommand.Param,_
 DM.Command.Class, Sysop.Commands, Sysop.Command.Class, Node.Commands,_
 Node.Command.Class, Letter.Command, Config.Array1, Config.Array2,_
 Config.Array3, Strip.Data
 If Chained Then
    Chain DND.Path+"DNDBBS.EXE"
 Endif
 If Chained=False Then
    Call Save.Screen(True)
 Endif
 Print
 If Var=0 Then
    Print
    Color 15,0
    Print "DndCnfg menu error:"
    Color 14,0
    Print
    Print Var$
    Print
 Endif
 If Var=1 Then
    Print
    Color 15,0
    Print "DndCnfg menu error:"
    Color 14,0
    Print
    Print "Error reading command line. Node not supported."
    Print
 Endif
 Color 15,0
 Print "Now exiting Dndcnfg.."
 Color 7,0
ErrorResume1:
 End
ErrorExit1:
 Resume ErrorResume1
End Sub

Sub Clear.Screen
 On Local Error Goto ErrorExit2
 Color 7,0
 Call ANSI(1,37,0)
 Cls
 Call ANSI(3,0,0)
 Locate Max.Row-1,1,1
 Call ANSI(2,Max.Row-1,1)
ErrorResume2:
 Exit Sub
ErrorExit2:
 Resume ErrorResume2
End Sub

Sub Init.Mouse
 On Local Error Goto ErrorExit3
 Call Mouse.Function(0,0) ' ax, bx
 Mouse.Present=False
 If OutregsX.AX=&HFFFF Then
    Mouse.Present=True
    Call Mouse.Function2(7,0,0,632) ' 80 columns
    M.Row=Max.Row*8-8
    Select Case Max.Row
    Case 25
       Call Mouse.Function2(8,0,0,192) ' 25 rows
    Case 41
       Call Mouse.Function2(8,0,0,336) ' 43 rows
    Case 48
       Call Mouse.Function2(8,0,0,392) ' 50 rows
    Case Else
       Call Mouse.Function2(8,0,0,192) ' 25 rows
    End Select
    Call Mouse.Function(1,0)
 Endif
ErrorResume3:
 Exit Sub
ErrorExit3:
 Resume ErrorResume3
End Sub

Sub Mouse.Driver(Var1)
 On Local Error Goto ErrorExit4
 Static Mouse.X As Integer, Mouse.Y As Integer
 If Mouse.Present=False Then
    Exit Sub
 Endif
 Select Case Var1
 Case 1
    Call Mouse.Function(1,0)
 Case 2
    Call Mouse.Function(2,0)
 Case 3
    Mouse.Button=False
    Call Mouse.Function(5,0)
    If (OutregsX.AX AND 1)=1 Then
       If OutregsX.BX>False Then
          Mouse.Button=True
          Mouse.Row=Int((OutregsX.DX)/8+1)
          Mouse.Column=Int((OutregsX.CX)/8+1)
          Exit Sub
       Endif
    Endif
    Mouse.Button2=False
    Call Mouse.Function(5,1)
    If (OutregsX.AX AND 2)=2 Then
       If OutregsX.BX>False Then
          Mouse.Button2=True
          Exit Sub
       Endif
    Endif
    Mouse.Button3=False
    Call Mouse.Function(5,2)
    If (OutregsX.AX AND 4)=4 Then
       If OutregsX.BX>False Then
          Mouse.Button3=True
          Call Terminate.Program(True)
          Exit Sub
       Endif
    Endif
    Call Mouse.Function(3,0)
    Var2=Int((OutregsX.CX)/8+1)
    Var3=Int((OutregsX.DX)/8+1)
    Mouse.Row=False
    Mouse.Column=False
    If Var2<>Mouse.Y Or Var3<>Mouse.X Then
       Mouse.X=Var3
       Mouse.Y=Var2
       Mouse.Row=Mouse.X
       Mouse.Column=Mouse.Y
    Endif
 End Select
ErrorResume4:
 Exit Sub
ErrorExit4:
 Resume ErrorResume4
End Sub

Sub Main.Mouse.Select
 On Local Error Goto ErrorExit5
 For Var=1 To 8
    If Mouse.Row=Menu2(Var,1) Then
       If Mouse.Column>=Menu2(Var,2) Then
          If Mouse.Column<=Menu2(Var,2)+Len(Rtrim$(Menu1(Var)))+2 Then
             If Var<>TempX Then
                Temp=Var
                Call Main.Menu.Select
             Endif
             Exit Sub
          Endif
       Endif
    Endif
 Next
ErrorResume5:
 Exit Sub
ErrorExit5:
 Resume ErrorResume5
End Sub

Sub Main.Mouse.Button
 On Local Error Goto ErrorExit6
 For Var=1 To 8
    If Mouse.Row=Menu2(Var,1) Then
       If Mouse.Column>=Menu2(Var,2) Then
          If Mouse.Column<=Menu2(Var,2)+Len(Rtrim$(Menu1(Var)))+2 Then
             If Var=TempX Then
                Strng3=Chr$(2)+Chr$(Var+58)
             Endif
             Exit Sub
          Endif
       Endif
    Endif
 Next
 If Mouse.Row=22 Then
    If Mouse.Column>=34 And Mouse.Column<=41 Then
       Strng3=Chr$(13)
    Endif
 Endif
 If Mouse.Row=22 Then
    If Mouse.Column>=61 And Mouse.Column<=68 Then
       Strng3=Chr$(27)
    Endif
 Endif
 If Mouse.Row=23 Then
    If Mouse.Column>=5 And Mouse.Column<=13 Then
       Strng3=Chr$(4) 
    Endif
    If Mouse.Column>=55 And Mouse.Column<=63 Then
       Strng3=Chr$(18)
    Endif
    If Mouse.Column>=30 And Mouse.Column<=39 Then
       Strng3=Chr$(23)
    Endif
 Endif
 If Mouse.Row=24 Then
    If Mouse.Column>=55 And Mouse.Column<=63 Then
       Strng3=Chr$(8)
    Endif
 Endif
ErrorResume6:
 Exit Sub
ErrorExit6:
 Resume ErrorResume6
End Sub

Sub Edit.Mouse.Button
 On Local Error Goto ErrorExit7
 If Mouse.Row=25 Then
    If Mouse.Column=21 Or Mouse.Column=22 Then
       Strng3=Chr$(0)+Chr$(72)
    Endif
    If Mouse.Column=24 Or Mouse.Column=25 Then
       Strng3=Chr$(0)+Chr$(80)
    Endif
    If Mouse.Column=42 Or Mouse.Column=43 Then
       Strng3=Chr$(0)+Chr$(73)
    Endif
    If Mouse.Column=45 Or Mouse.Column=46 Then
       Strng3=Chr$(0)+Chr$(81)
    Endif
    If Mouse.Column>=56 And Mouse.Column<=62 Then
       Strng3=Chr$(13)
    Endif
    If Mouse.Column>=72 And Mouse.Column<=77 Then
       Strng3=Chr$(27)
    Endif
 Endif
ErrorResume7:
 Exit Sub
ErrorExit7:
 Resume ErrorResume7
End Sub

Sub Open.Arrays
 On Local Error Goto ErrorExit14
 Data.Error=False
Redim Alignment.Name1(1 To MaxAlignment) As String*7,_
 Alignment.Name2(1 To MaxAlignment) As String*7,_
 Attack.Command(1 To MaxUserCommands) As Integer,_
 Class.Name(1 To MaxClassNames) As String*15,_
 Command.Abbr(1 To MaxUserCommands) As String*2,_
 Command.Class(1 To MaxUserCommands,1 To MaxClasses) As Integer,_
 Command.Param(1 To MaxUserCommands) As Integer,_
 Command.Set(1 To MaxUserCommands,1 To MaxCommands) As String*12,_
 Command.Limit(1 To MaxUserCommands) As Integer,_
 Command.Time(1 To MaxUserCommands,1 To MaxTimes) As Integer,_
 Config.Array1(1 To MaxConfigArray1) As Single,_
 Config.Array2(1 To MaxConfigArray2) As Integer,_
 Config.Array3(1 To MaxConfigArray3) As String,_
 Direction(1 To MaxDirections) As String*9,_
 DMCommands(1 To MaxDMCommands) As String*10,_
 DMCommand.Param(1 To MaxDMCommands) As Integer,_
 DM.Command.Class(1 To MaxDMCommands,1 To MaxDMClasses) As Integer,_
 High.Class.Name(1 To MaxClassNames) As String*15,_
 InventoryNames(1 To MaxItems) As String*8,_
 Letter.Command(1 To MaxLetters) As Integer,_
 Modem.Allow(1 To MaxModemBauds) As Integer,_
 Modem.Connect(1 To MaxModemBauds) As Single,_
 Modem.String(1 To MaxModemBauds) As String*20,_
 Node.Commands(1 To MaxNodeCommands) As String*10,_
 Node.Command.Class(1 To MaxNodeCommands,1 To MaxClasses) As Integer,_
 Numeral(1 To MaxNumerals) As String*5,_
 Race(1 To MaxRaces) As String*8,_
 Room.Array(1 To MaxRoomArrays) As String*40,_
 Stat(1 To MaxStats) As String*12,_
 Strip.Data(1 To MaxStrips) As String*5,_
 Sysop.Commands(1 To MaxSysopCommands) As String*10,_
 Sysop.Command.Class(1 To MaxSysopCommands) As Integer,_
 Temp.ArrayS(1 To 10) As String,_
 Temp.Array1(1 To 10) As Integer,_
 Temp.Array2(1 To 10) As Integer,_
 Training.Stats(1 To MaxClassNames,1 To MaxTrainStats) As Integer,_
 Weapon.Type.Name(1 To MaxWeapons) As String*9
ErrorResume14:
 If Data.Error Then
    Strng="Not enough RAM for arrays. Increase resident memory."
    Call Terminate.Program(False)
 Endif
 Exit Sub
ErrorExit14:
 Data.Error=True
 Resume ErrorResume14
End Sub

Sub ScreenEdit
 On Local Error Goto ErrorExit19
 Inserting=True
 Call ANSI(4,37,44)
 Call ANSI(2,2,72)
 Strng="Insert"
 Call Scrn(Strng)
 Call ANSI(4,37,40)
 Call ANSI(2,Xcoor,Ycoor)
 Locate Xcoor,Ycoor,1
 TempC$=Left$(TempC$,78)
 Call Scrn(TempC$)
 Ycoor=Ycoor+Len(TempC$)
 Do While Lost.Carrier=False
    Call ANSI(2,Xcoor,Ycoor)
    If Inserting=-3 Then
       Locate Xcoor,Ycoor,1,1,7
    Else
       If Inserting=-1 Then
          Locate Xcoor,Ycoor,1,3,7
       Else
          Locate Xcoor,Ycoor,1,7,7
       Endif
    Endif
    TempX$=Nul
    Do While TempX$=Nul
       If Lost.Carrier Then
          Exit Do
       Endif
       Call Read.Keyboard(TempX$)
       Call Mouse.Driver(3)
       If Mouse.Button2 Then
          TempX$=Chr$(27)
       Endif
       If Mouse.Button3 Then
          Call Terminate.Program(True)
          End
       Endif
       If Mouse.Button Then
          If Mouse.Row=Row Then
             If Mouse.Column>=Column Then
                If Mouse.Column<=Column+Line.Length-1 Then
                   Select Case Lcase$(Rtrim$(TempC$))
                   Case "yes"
                      TempC$="No"
                      Xcoor=Row
                      Ycoor=Column
                      Call ANSI(2,Xcoor,Ycoor)
                      Locate Xcoor,Ycoor,1
                      Call Scrn("No ")
                   Case "no"
                      TempC$="Yes"
                      Xcoor=Row
                      Ycoor=Column
                      Call ANSI(2,Xcoor,Ycoor)
                      Locate Xcoor,Ycoor,1
                      Call Scrn("Yes")
                   End Select
                Endif
             Endif
          Endif
       Endif
    Loop
    Select Case Len(TempX$)
    Case 1
       Select Case TempX$
       Case Chr$(13) ' exit
          Exit Do
       Case Chr$(27) ' abort
          Inserting=-2
          Exit Do
       Case Chr$(8) ' backspace
          If Ycoor-Column>False Then
             If Inserting=False Then
                Ycoor=Ycoor-1
             Else
                TempC$=Left$(TempC$,Ycoor-Column-1)+Mid$(TempC$,Ycoor-Column+1)
                Ycoor=Ycoor-1
                If Hidden=False Then
                   Call ANSI(2,Xcoor,Ycoor)
                   Strng=Mid$(TempC$,Ycoor-Column+1)+" "
                   Call Scrn(Strng)
                Else
                   If Hidden=-1 Then
                      Call ANSI(2,Row,Column)
                      VarX$=String$(Line.Length,Mask$)
                      Call Scrn(VarX$)
                   Else
                      Call ANSI(2,Row,Column)
                      VarX$=String$(Len(TempC$),Mask$)+" "
                      Call Scrn(VarX$)
                   Endif
                Endif
             Endif
          Endif
       Case Chr$(9) ' tab
          If Ycoor-Column+8<=Len(TempC$) Then
             Ycoor=Ycoor+8
          Else
             Ycoor=Len(TempC$)+Column
          Endif
       Case Else ' insert character
          If Asc(TempX$)>=32 And Asc(TempX$)<=127 Then
             If Ycoor-Column<Line.Length Then
                If Inserting=False Then
                   If Ycoor-Column+1>Len(TempC$) Then
                      TempC$=TempC$+TempX$
                   Else
                      Mid$(TempC$,Ycoor-Column+1,1)=TempX$
                   Endif
                   Strng=TempX$
                   If Hidden=False Then
                      Call ANSI(2,Xcoor,Ycoor)
                      Call Scrn(Strng)
                   Else
                      If Hidden=-1 Then
                         Call ANSI(2,Row,Column)
                         VarX$=String$(Line.Length,Mask$)
                         Call Scrn(VarX$)
                      Else
                         Call ANSI(2,Row,Column)
                         VarX$=String$(Len(TempC$),Mask$)
                         Call Scrn(VarX$)
                      Endif
                   Endif
                   Ycoor=Ycoor+1
                Else
                   TempC$=Left$(TempC$,Ycoor-Column)+TempX$+Mid$(TempC$,Ycoor-Column+1)
                   TempC$=Left$(TempC$,Line.Length)
                   Strng=Mid$(TempC$,Ycoor-Column+1)
                   If Hidden=False Then
                      Call ANSI(2,Xcoor,Ycoor)
                      Call Scrn(Strng)
                   Else
                      If Hidden=-1 Then
                         Call ANSI(2,Row,Column)
                         VarX$=String$(Line.Length,Mask$)
                         Call Scrn(VarX$)
                      Else
                         Call ANSI(2,Row,Column)
                         VarX$=String$(Len(TempC$),Mask$)
                         Call Scrn(VarX$)
                      Endif
                   Endif
                   Ycoor=Ycoor+1
                Endif
             Endif
          Endif
       End Select
    Case 2
       Temp=Asc(Mid$(TempX$,2,1))
       Select Case Temp
       Case 0 ' ctrl-break
          Inserting=-2
          Exit Do
       Case 82 ' insert
          Select Case Inserting
          Case 0
             Inserting=-1
          Case -1
             Inserting=-3
          Case -3
             Inserting=0
          End Select
          Call ANSI(4,37,44)
          Call ANSI(2,2,72)
          If Inserting=False Then
             Strng=Space$(6)
          Else
             Strng="Insert"
          Endif
          Call Scrn(Strng)
          Call ANSI(4,37,40)
       Case 83, 147 ' delete/control-delete
          If Ycoor-Column+1<=Len(TempC$) Then
             TempC$=Left$(TempC$,Ycoor-Column)+Mid$(TempC$,Ycoor-Column+2)
             If Hidden=False Then
                Call ANSI(2,Xcoor,Ycoor)
                Strng=Mid$(TempC$,Ycoor-Column+1)+" "
                Call Scrn(Strng)
             Else
                If Hidden=-1 Then
                   Call ANSI(2,Row,Column)
                   VarX$=String$(Line.Length,Mask$)
                   Call Scrn(VarX$)
                Else
                   Call ANSI(2,Row,Column)
                   VarX$=String$(Len(TempC$),Mask$)+" "
                   Call Scrn(VarX$)
                Endif
             Endif
          Endif
       Case 71, 119 ' home/ctrl-home
          Ycoor=Column
       Case 79, 117 ' end/ctrl-end
          Ycoor=Len(TempC$)+Column
       Case 15 ' tab
          If Ycoor-Column-8>False Then
             Ycoor=Ycoor-8
          Else
             Ycoor=Column
          Endif
       Case 77, 157 ' right/alt-right
          If Ycoor-Column+1<=Len(TempC$) Then
             Ycoor=Ycoor+1
          Endif
       Case 75, 155 ' left/alt-left
          If Ycoor-Column>False Then
             Ycoor=Ycoor-1
          Endif
       Case 116 ' control-right
          Do While Lost.Carrier=False
             For Temp2=Ycoor-Column+1 To Len(TempC$)-1
                If Mid$(TempC$,Temp2,1)=" " Then
                   If Mid$(TempC$,Temp2+1,1)<>" " Then
                      Ycoor=Temp2+Column
                      Exit Do
                   Endif
                Endif
             Next
             If Ycoor-Column+1<=Len(TempC$) Then
                Ycoor=Len(TempC$)+Column
             Endif
             Exit Do
          Loop
       Case 115 ' control-left
          Do While Lost.Carrier=False
             For Temp2=Ycoor-Column-1 To 1 Step -1
                If Mid$(TempC$,Temp2,1)=" " Then
                   Ycoor=Temp2+Column
                   Exit Do
                Endif
             Next
             Ycoor=Column
             Exit Do
          Loop
       End Select
    End Select
 Loop
 Call ANSI(4,37,44)
 Call ANSI(2,2,72)
 Strng=Space$(6)
 Call Scrn(Strng)
 Locate ,,1,7,7
ErrorResume19:
 Exit Sub
ErrorExit19:
 Resume ErrorResume19
End Sub

Function Config3$(Var)
 On Local Error Goto ErrorExit20
 Var$=Config.Array3(Var)
 If Right$(Var$,1)=Chr$(1) Then
    Var$=Left$(Var$,Len(Var$)-1)
 Endif
 Config3$=Var$
ErrorResume20:
 Exit Function
ErrorExit20:
 Resume ErrorResume20
End Function

Sub Get.Config
 On Local Error Goto Config.Error
 HelpRecLen4=Len(HelpRecord3)
 DND.Path=Ucase$(Environ$("DNDBBS"))
 If DND.Path<>Nul Then
    If Right$(DND.Path,1)<>"\" Then
       DND.Path=DND.Path+"\"
    Endif
 Endif
 FileName2$=DND.Path+"DND.CFG"
 Close #TempFile1
 Open FileName2$ For Input Shared As #TempFile1
 Line Input #TempFile1,Var$
 For Temp1=1 To MaxConfigArray1
    Input #TempFile1,Var!
 Next
 For Temp1=1 To MaxConfigArray2
    Input #TempFile1,Var%
 Next
 For Temp1=1 To MaxConfigArray3
    Line Input #TempFile1,Var$
    If Temp1=11 Then
       Data.Path1=Var$
    Endif
    If Temp1=15 Then
       File.Extension1=Var$
    Endif
    If Temp1=23 Then
       DataFile$=Var$
    Endif
 Next
 Help.FileName4=Data.Path1+DataFile$+File.Extension1
Config.Resume:
 Close #TempFile1
 Exit Sub
Config.Error:
 Help.Filename4="DNDCNFG.DAT"
 Resume Config.Resume
End Sub

Sub Load.Config
 On Local Error Goto Config.Error2
 Call Read.Rows(Var2)
 Max.Row=Var2
 Token=False
 Call Detect.Share
 Call Check.Local.ANSI
Config.Resume2:
 Exit Sub
Config.Error2:
 Resume Config.Resume2
End Sub

Sub Help(Var1)
 On Local Error Goto Error.Trap53
 VarX$=Ucase$(Environ$("BLIND"))
 If VarX$="ON" Or VarX$="-1" Or VarX$="TRUE" Then
    Border.Off=True
 Endif
 VarX$=Ucase$(Environ$("BLINDCHAR"))
 If VarX$="ON" Or VarX$="-1" Or VarX$="TRUE" Then
    Border.Char=-1
 Endif
 Close #HelpFile4
 FileName2$=Help.FileName4
 Open FileName2$ For Random Shared As #HelpFile4 Len=HelpRecLen4
 Call ANSI(4,37,44)
 Call ANSI(3,0,0)
 Call ANSI(4,36,44)
 Call Mouse.Driver(2)
 Color 7,1 : Cls
 Call Mouse.Driver(1)
 If Local.Mode Then
    Call Shell.ANSI.Program(1)
    Call ANSI(4,36,44)
    If Border.Off=False Then
       Call ANSI(2,1,1)
       If Border.Char=0 Then
          Strng = Chr$(201) + String$(78, 205) + Chr$(187)
       Else
          Strng = "+" + String$(78, "-") + "+"
       Endif
       Call Scrn(Strng)
       For Temp=2 To 24
          Call ANSI(2,Temp,1)
          If Border.Char=0 Then
             Strng = Chr$(186)
          Else
             Strng = "|"
          Endif
          Call Scrn(Strng)
          Call ANSI(2,Temp,80)
          If Border.Char=0 Then
             Strng = Chr$(186)
          Else
             Strng = "|"
          Endif
          Call Scrn(Strng)
       Next
       Call ANSI(2,25,1)
       If Border.Char=0 Then
          Strng = Chr$(200) + String$(78, 205) 
       Else
          Strng = "+" + String$(78, "-")
       Endif
       Call Scrn(Strng)
       Color 11,1
       Locate 25,80,0
       If Border.Char=0 Then
          Print Chr$(188);
       Else
          Print "+";
       Endif
       Locate 1,1,1
    Endif
 Endif
 Call ANSI(2,25,6)
 Call ANSI(4,37,44)
 Strng=" Next Screen: Cursor Up/Dn "
 Call Scrn(Strng)
 Call ANSI(2,25,35)
 Strng=" Next Topic: Page Up/Dn "
 Call Scrn(Strng)
 Call ANSI(2,25,61)
 Strng=" Quit: Escape "
 Call Scrn(Strng)
 Call ANSI(4,33,44)
 Temp2=1
 Temp1=False
 Gosub Read.Data
 Locate ,,0
 Do While Lost.Carrier=False
    TempX$=Nul
    Do While TempX$=Nul
       If Lost.Carrier Then
          Exit Do
       Endif
       Call Read.Keyboard(TempX$)
       If TempX$ = Chr$(21) Then ' ^U = pageup
          TempX$ = Chr$(0) + Chr$(73)
       Endif
       If TempX$ = Chr$(14) Then ' ^N = pagedown
          TempX$ = Chr$(0) + Chr$(81)
       Endif
       Call Mouse.Driver(3)
       If Mouse.Button2 Then
          TempX$=Chr$(27)
       Endif
       If Mouse.Button3 Then
          Call Terminate.Program(True)
          End
       Endif
       If Mouse.Button Then
          Call HelpMouseButton
          Exit Do
       Endif
    Loop
    If TempX$=Chr$(27) Then
       Exit Sub
    Endif
    If Len(TempX$)=2 Then
       Temp8=Asc(Mid$(TempX$,2,1))
       Select Case Temp8
       Case 71, 119 ' home/ctrl-home
          If Temp1 Then
             Temp2=1
             Temp1=Temp1-1
             Gosub Read.Data
          Endif
       Case 79, 117 ' end/ctrl-end
          Temp1=Temp1+1
          Temp3=Temp2
          Temp2=1
          Gosub Read.Data
          If Temp5<Temp1 Then
             Temp1=Temp5
             Temp2=Temp3
          Endif
       Case 72, 141, 152 ' up/ctrl-up/alt-up
          If Temp2<>1 Then
             Temp2=Temp2-1
             Gosub Read.Data
          Endif
       Case 80, 145, 160 ' down/ctrl-dn/alt-dn
          Temp2=Temp2+1
          Gosub Read.Data
          Temp2=Temp4
       Case 73, 132 ' pageup/ctrl-pageup
          If Temp1 Then
             Temp2=1
             Temp1=Temp1-1
             Gosub Read.Data
          Endif
       Case 81, 118 ' pagedown/ctrl-pagedn
          Temp1=Temp1+1
          Temp3=Temp2
          Temp2=1
          Gosub Read.Data
          If Temp5<Temp1 Then
             Temp1=Temp5
             Temp2=Temp3
          Endif
       End Select
       Locate ,,0
    Endif
 Loop
 Exit Sub

Read.Data:
 Restore HelpData
 Temp5=False
 Temp8=1
 Dat1=False
 Dat2=False
 Dat3=False
 Do While Lost.Carrier=False
    Read Dat1,Dat2,Dat3,VarZ$
    If Dat1=99 And Dat2=99 And Dat3=99 Then
       Exit Do
    Endif
    VarZ$=" "+VarZ$+" "
    If Dat1>False And Dat1>Var1 Then
       Return
    Endif
    If (Dat1=Var1 Or Dat1=False) And Dat2=Temp1 Then
       Temp5=Dat2
       Temp4=1
       Temp7=False
       For Temp9=1 To Dat3
          Call Read.Helpfile(HelpFile4,Temp8+Temp9)
          Temp7=Temp7+1
          If Temp4=Temp2 Then
             Call ANSI(4,HelpRecord3.TextColor,44)
             Call ANSI(2,Temp7+1,2)
             Strng=HelpRecord3.Text
             Call Scrn(Strng)
          Endif
          If Temp4=Temp2 And Temp7=1 Then
             If Local.Mode Then
                If Border.Off=False Then
                   Call ANSI(4,36,44)
                   Call ANSI(2,1,2)
                   If Border.Char = 0 Then
                      Strng=String$(78,205)
                   Else
                      Strng=String$(78,"-")
                   Endif
                   Call Scrn(Strng)
                Endif
             Endif
             Call ANSI(4,37,44)
             VarX=Int(40-Len(VarZ$)/2+1)
             Call ANSI(2,1,VarX)
             Strng=VarZ$
             Call Scrn(Strng)
          Endif
          If Temp7=22 Then
             If Temp4=Temp2 Then
                Return
             Else
                Temp4=Temp4+1
                Temp7=False
             Endif
          Endif
       Next
       If Temp7=False Then
          Temp4=Temp4-1
          Return
       Endif
       If Temp2>Temp4 Then
          Return
       Endif
       If Temp7<22 Then
          For Temp9=Temp7+1 To 22
             Call ANSI(2,Temp9+1,2)
             Strng=Space$(78)
             Call Scrn(Strng)
          Next
       Endif 
       Return
    Endif
    Temp8=Temp8+Dat3
    Temp5=Dat2
 Loop
 Return
Error.Resume53:
 Exit Sub
Error.Trap53:
 Resume Error.Resume53
End Sub

' adjusted 02/03/2021
Sub HelpMouseButton
 On Local Error Goto Error.Trap54
 If Mouse.Row=25 Then
    Select Case Mouse.Column
    Case 7 To 18 ' Next Screen:
       TempX$=Chr$(0)+Chr$(80) ' down
    Case 37 To 47 ' Next Topic:
       TempX$=Chr$(0)+Chr$(81) ' pgdn
    Case 20 To 28 ' cursor up
       TempX$=Chr$(0)+Chr$(72) ' up
    Case 30, 31 ' down
       TempX$=Chr$(0)+Chr$(80)
    Case 48 To 54 ' page up
       TempX$=Chr$(0)+Chr$(73) ' pgup
    Case 56, 57 ' pgdn
       TempX$=Chr$(0)+Chr$(81)
    Case 62 To 73 ' esc
       TempX$=Chr$(27)
    End Select
 Endif
Error.Resume54:
 Exit Sub
Error.Trap54:
 Resume Error.Resume54
End Sub

Sub Shell.ANSI.Program(Var%)
 On Local Error Goto ErrTrap9x2
 If Max.Row=41 Or Max.Row=48 Then
    If Max.Row=41 Then VarX=43
    If Max.Row=48 Then VarX=50
    Close #TempFile2
    Open DND.Path+"NODE"+NodeX+".DEF" For Output As #TempFile2
    Print #TempFile2,Config.Array3(11) ' c:\dnddat\
    Print #TempFile2,Config.Array3(51) ' dndusage
    Print #TempFile2,Config.Array3(15) ' .dat
    Print #TempFile2,VarX ' screen size
    Close #TempFile2
    ' get dndpath with filename
    Filename2$=DND.Path+"ANSI.EXE"
    If Dir$(Filename2$)<>Nul Then
       Filename2$=Filename2$+" /"+NodeX
       Shell Filename2$
    Endif
 Endif
ErrResume9x2:
 Exit Sub
ErrTrap9x2:
 Resume ErrResume9x2
End Sub

HelpData:
 Data 0,0,22,"Dndcnfg Keys Chart"
 Data 1,1,82,"Dndcnfg Logon Variables Page 1"
 Data 2,1,118,"Dndcnfg Logon Variables Page 2"
 Data 3,1,69,"Dndcnfg Process Variables Page 1"
 Data 4,1,80,"Dndcnfg Process Variables Page 2"
 Data 5,1,81,"Dndcnfg File Variables Page 1"
 Data 6,1,76,"Dndcnfg File Variables Page 2"
 Data 7,1,21,"Dndcnfg File Variables Page 3"
 Data 8,1,70,"Dndcnfg Rooms Variables Page 1"
 Data 9,1,88,"Dndcnfg Rooms Variables Page 2"
 Data 10,1,109,"Dndcnfg Command Variables Page 1"
 Data 11,1,96,"Dndcnfg Command Variables Page 2"
 Data 12,1,151,"Dndcnfg Modem Variables Page 1"
 Data 13,1,13,"Dndcnfg Modem Variables Page 2"
 Data 14,1,73,"Dndcnfg Equation Variables"
 Data 15,1,29,"Dndcnfg Security Variables Page 1"
 Data 16,1,9,"Dndcnfg Security Variables Page 2"
 Data 17,1,9,"Dndcnfg Security Variables Page 3"
 Data 18,1,9,"Dndcnfg Security Variables Page 4"
 Data 19,1,42,"Dndcnfg Main Page"
 Data 99,99,99,"EOF"

Sub Save.Screen(Var)
 On Local Error Goto Error.Trap62
 If Var=False Then
    VarX=(Max.Row-1)*80+80
    Redim Temp.ArrayY(VarX) As Long
    Redim Temp.ArrayZ(VarX) As Double
    For Var1=1 To Max.Row
       For Var2=1 To 80
          TempZ1=Screen(Var1,Var2)
          TempZ2=Screen(Var1,Var2,1)
          VarX2=(Var1-1)*80+Var2
          Temp.ArrayY(VarX2)=TempZ1
          Temp.ArrayZ(VarX2)=TempZ2
       Next
    Next
 Else
    Cls
    For VarX=Max.Row To 1 Step -1
       For VarY=1 To 80
          VarX2=(VarX-1)*80+VarY
          If Temp.ArrayY(VarX2)<>32 Then
             Goto Next.Line
          Endif
       Next
    Next
Next.Line:
    TempX=VarX
    For Var1=1 To VarX ' Max.Row
       For Var2=1 To 80
          VarX2=(Var1-1)*80+Var2
          VarB=Int(Temp.ArrayZ(VarX2)/16)
          VarF=Temp.ArrayZ(VarX2) Mod 16
          TempZ1=Temp.ArrayY(VarX2)
          Locate Var1,Var2,0
          Color VarF,VarB
          Print Chr$(TempZ1);
       Next
    Next
 Endif
Error.Resume62:
 Exit Sub
Error.Trap62:
 Resume Error.Resume62
End Sub

