 Rem File: IO7.bas - Dndcnfg,bas
 Rem $Include: 'dndcnfg.inc'

Function Timeit!
 t1$ = Format$(Now, "hh:mm:ss") ' seconds past midnight
 t1! = CSNG(INT(VAL(MID$(t1$, 1, 2)))) * 3600! + CSNG(INT(VAL(MID$(t1$, 4, 2)))) * 60! + CSNG(INT(VAL(MID$(t1$, 7, 2))))
 Timeit!=t1!
End Function

Function Time.Elapsed(Start.Time!,Wait.Time!)
 Elapsed.Time!=Timeit!-Start.Time!
 If Elapsed.Time!<SFalse Then
    Elapsed.Time!=Elapsed.Time!+86400!
 Endif
 If Elapsed.Time!>=Wait.Time! Then
    Time.Elapsed=True
 Else
    Time.Elapsed=False
 Endif
End Function

Function DateS$
 DateS$=Format$(Now,"mm-dd-yyyy")
End Function

Function FClock$
 FClock$=Format$(Now,"ddd dd mmm yyyy\, hh:mma/p")
End Function

Sub Stdin(Var)
 Var=0
 ' check stdin length
 InregsX.AX = &H4202 ' eof
 InregsX.BX = 0 ' stdin
 InregsX.CX = 0
 InregsX.DX = 0
 CALL InterruptX(&H21, InregsX, OutregsX)
 IF OutregsX.AX = 0 THEN ' no input found
     EXIT SUB
 END IF
 Print "Illegal standard input attempted."
 END
End Sub

Sub Read.Keyboard(Var$)
 On Local Error Goto ErrorExit8
 Call Read.Node.Mess(Prompt$)
 Var$=Inkey$
 If Len(Var$) Then
    Exit Sub
 Endif
 If Local.Mode Then
    Call Release.Time(1)
    Exit Sub
 Endif
 Call Check.Carrier
 Call Driver(3)
 If (OutregsX.AX And &H0100)=&H0100 Then
    Call Driver(2)
    Char=(OutregsX.AX And &HFF)
    If Char<>False Then
       Buffer=Buffer+Chr$(Char)
    Endif
 Endif
 Select Case Len(Buffer)
 Case 0
    Eat$ = Nul
 Case 1
    Select Case Buffer
    Case Chr$(22) ' insert ^v
       Var$=Chr$(0)+Chr$(82)
       Buffer=Nul
    Case Chr$(127) ' delete
       Var$=Chr$(0)+Chr$(83)
       Buffer=Nul
    Case Chr$(21) ' ^U = pageup
       Var$=Chr$(0)+Chr$(73)
       Buffer=Nul
    Case Chr$(14) ' ^N = pagedown
       Var$=Chr$(0)+Chr$(81)
       Buffer=Nul
    Case Chr$(27)
       Eat$ = Nul
    Case Else
       Var$=Buffer
       Buffer=Nul
    End Select
 Case 2
    Select Case Ucase$(Buffer)
    Case Chr$(27)+"I" ' up
       Var$=Chr$(0)+Chr$(72)
       Buffer=Nul
    Case Chr$(27)+"M" ' down
       Var$=Chr$(0)+Chr$(80)
       Buffer=Nul
    Case Chr$(27)+"K" ' right
       Var$=Chr$(0)+Chr$(77)
       Buffer=Nul
    Case Chr$(27)+"J" ' left
       Var$=Chr$(0)+Chr$(75)
       Buffer=Nul
    Case Chr$(27)+"O" ' home
       Var$=Chr$(0)+Chr$(71)
       Buffer=Nul
    Case Chr$(27)+"L" ' end
       Var$=Chr$(0)+Chr$(79)
       Buffer=Nul
    Case Chr$(27)+"U" ' pageup
       Var$=Chr$(0)+Chr$(73)
       Buffer=Nul
    Case Chr$(27)+"N" ' pagedown
       Var$=Chr$(0)+Chr$(81)
       Buffer=Nul
    Case Chr$(27)+Chr$(27) ' exit
       Var$=Chr$(27)
       Buffer=Nul
    Case Chr$(27)+"["
       Eat$ = Nul
    Case Chr$(27)+Chr$(13) ' ^x override
       Eat$ = Nul
    Case Else
       Buffer=Nul
    End Select
 Case 3
    Select Case Buffer
    Case Chr$(27)+"[A" ' Up ^[[A
       Var$=Chr$(0)+Chr$(72)
       Buffer=Nul
    Case Chr$(27)+"[B" ' Down ^[[B
       Var$=Chr$(0)+Chr$(80)
       Buffer=Nul
    Case Chr$(27)+"[C" ' Right ^[[C
       Var$=Chr$(0)+Chr$(77)
       Buffer=Nul
    Case Chr$(27)+"[D" ' Left ^[[D
       Var$=Chr$(0)+Chr$(75)
       Buffer=Nul
    Case Chr$(27)+"[H" ' Home ^[[H
       Var$=Chr$(0)+Chr$(71)
       Buffer=Nul
    Case Chr$(27)+"[K" ' End ^[[K
       Var$=Chr$(0)+Chr$(79)
       Buffer=Nul
    Case Else
       If Left$(Buffer,2)=Chr$(27)+Chr$(13) Then
          V$=Ucase$(Right$(Buffer,1))
          If V$>="A" And V$<="Z" Then
             Var$=Chr$(Asc(V$)-64) ' ^a - ^z
             Buffer=Nul
             Exit Sub
          Endif
       Endif
       Buffer=Nul
    End Select
 Case Else
    Var$=Nul
    Buffer=Nul
 End Select
ErrorResume8:
 Exit Sub
ErrorExit8:
 Resume ErrorResume8
End Sub

' adds dndpack detection 10/10/2024.
Sub Read.Node.Mess(VarX$)
 On Local Error Goto ErrorTrap13x
    DND.Path=Environ$("DNDBBS")
    If DND.Path<>Nul Then
       If Right$(DND.Path,1)<>"\" Then
          DND.Path=DND.Path+"\"
       Endif
    Endif
    FilenameX$=DND.Path+"NODEEXIT.OUT"
    If Dir$(FilenameX$)<>"" Then
       Color 7, 0
       Locate Max.Row-1,1,1
       Print
       Call Hang.Up
    Endif
ErrorResume13x:
 Exit Sub
ErrorTrap13x:
 Resume ErrorResume13x
End Sub

Sub Release.Time(Var)
 On Local Error Goto ErrorExit9
 If Supported.Call=False Then
    For Var2=1 To Var
       Call Slice.Function
       If (OutregsX.AX And &HFF)=&H80 Then
	  Supported.Call=True
	  Exit For
       Endif
    Next
 Endif
ErrorResume9:
 Exit Sub
ErrorExit9:
 Resume ErrorResume9
End Sub

Sub Check.Carrier
 On Local Error Goto ErrorExit10
 If Lost.Carrier Then
    Exit Sub
 Endif
 Call Driver(3)
 If (OutregsX.AX And &H80)=False Then
    Call Hang.Up
    Exit Sub
 Endif
ErrorResume10:
 Exit Sub
ErrorExit10:
 Resume ErrorResume10
End Sub

Sub Driver(Var)
 On Local Error Goto ErrorExit11
 If Local.Mode Then
    Exit Sub
 Endif
 Select Case Var
 Case 1
    InregsX.AX=InregsX.AX Or &H0100
 Case 2 To 5
    InregsX.AX=&H100*Var
 End Select
 InregsX.DX=Port
 Call InterruptX(&H14,InregsX,OutregsX)
ErrorResume11:
 Exit Sub
ErrorExit11:
 Resume ErrorResume11
End Sub

Sub Hang.Up
 On Local Error Goto ErrorExit12
 Buffer=Nul
 Func.Buffer=Nul
 Out2=Nul
 Strng=Nul
 Time.Left=180!
 Lost.Carrier=True
 Security.Guard=False
ErrorResume12:
 Exit Sub
ErrorExit12:
 Resume ErrorResume12
End Sub

Sub Check.Local.ANSI
 On Local Error Goto ErrorExit13
 Local.Mode=True
 Lost.Carrier=False
 Call Plex.Function(26)
 If (OutregsX.AX And &HFF)=&HFF Then
    Local.ANSI.Color=True
 Else
    Local.ANSI.Color=False
 Endif
 Call VideoInt(15,0)
 Video.Page=OutregsX.BX
ErrorResume13:
 Exit Sub
ErrorExit13:
 Resume ErrorResume13
End Sub

Sub ANSI(VarX,VarY,VarZ)
 On Local Error Goto ErrorExit15
 Var$=Nul
 Select Case VarX
 Case 1
    Var$=Chr$(27)+"[0;"+Mid$(Str$(VarY),2)+";"+Mid$(Str$(VarZ),2)+"m"
 Case 2
    Var$=Chr$(27)+"["+Mid$(Str$(VarY),2)+";"+Mid$(Str$(VarZ),2)+"H"
 Case 3
    Var$=Chr$(27)+"[2J"
 Case 4
    Var$=Chr$(27)+"[1;"+Mid$(Str$(VarY),2)+";"+Mid$(Str$(VarZ),2)+"m"
 Case 5
    TempD$=Chr$(27)+"["+Mid$(Str$(VarY),2)+"m"
 End Select
 Call Modem(Var$)
 If Local.ANSI.Color Then
    Call Scrn(Var$)
    Exit Sub
 Endif
 Select Case VarX
 Case 1
    Call Convert.Color(VarY,VarZ,True)
 Case 2
    Locate VarY,VarZ,1
 Case 3
    Cls
 Case 4
    Call Convert.Color(VarY,VarZ,False)
 Case 5
    Call Convert.Color(VarY,VarZ,False)
 End Select
ErrorResume15:
 Exit Sub
ErrorExit15:
 Resume ErrorResume15
End Sub

Sub Scrn(Var$)
 On Local Error Goto ErrorExit16
 Call Modem(Var$)
 Call Mouse.Driver(2)
 If Local.ANSI.Color Then
    For VarX=1 To Len(Var$)
       VarY=Asc(Mid$(Var$,VarX,1))
       Call StdinInt(6,VarY)
    Next
 Else
    Print Var$;
 Endif
 Call Mouse.Driver(1)
ErrorResume16:
 Exit Sub
ErrorExit16:
 Resume ErrorResume16
End Sub

Sub Modem(Var$)
 On Local Error Goto ErrorExit17
 If Lost.Carrier Then
    Exit Sub
 Endif
 If Local.Mode Then
    Exit Sub
 Endif
 For VarX=1 To Len(Var$)
    Var=Asc(Mid$(Var$,VarX,1))
    Do
       Call Driver(3)
       If (OutregsX.AX And &H4000)=&H4000 Then
          InregsX.AX=Var
          Call Driver(1) ' put char w/ wait
          Exit Do
       Endif
    Loop
 Next
 Do
    Call Driver(3) ' get line status
    If (OutregsX.AX And &H4000)=&H4000 Then ' empty buffer
       Exit Do
    Endif
 Loop
ErrorResume17:
 Exit Sub
ErrorExit17:
 Resume ErrorResume17
End Sub

Sub Convert.Color(VarX,VarY,VarZ)
 On Local Error Goto ErrorExit18
 Select Case VarX
 Case 30
    VarF=8
 Case 31
    VarF=12
 Case 32
    VarF=10
 Case 33
    VarF=14
 Case 34
    VarF=9
 Case 35
    VarF=13
 Case 36
    VarF=11
 Case 37
    VarF=15
 End Select
 Select Case VarY
 Case 40
    VarB=8
 Case 41
    VarB=12
 Case 42
    VarB=10
 Case 43
    VarB=14
 Case 44
    VarB=9
 Case 45
    VarB=13
 Case 46
    VarB=11
 Case 47
    VarB=15
 End Select
 If VarZ Then
    VarF=VarF-8
    VarB=VarB-8
 Endif
 Color VarF,VarB
ErrorResume18:
 Exit Sub
ErrorExit18:
 Resume ErrorResume18
End Sub
