 Rem File: Share.bas .lib file. for dndbbs, cmd*.bas
 Rem $Include: 'dndbbs.inc'

Sub Write.Record(Var,Var!)
 On Local Error Goto Write.Record.Error
 Dim Locked As Integer
 Dim Lock.Count As Single
 If Var!<=0! Then
    Exit Sub
 Endif
 Locked=False
 Lock.Count=Timeit!
Write.Record.Resume1:
 If Share.Installed Then
    Select Case Var
    Case BankFile
       Lock TempFile1,Var!
    Case ObjDescFile
       Lock TempFile1,Var!
    Case Else
       Lock Var,Var!
       Locked=True
    End Select
 Endif
Write.Record.Resume2:
 Select Case Var
 Case SicFile
    Put SicFile,Var!,UserProfile
 Case AutomateFile
    Put AutomateFile,Var!,AutomateRecord
 Case TempFile1
    Put TempFile1,Var!,AutomateRecord
 Case BankFile
    Put TempFile1,Var!,BankRecord
 Case ObjDescFile
    Put TempFile1,Var!,BufferRecord
 Case RoomFile
    Put RoomFile,Var!,RoomRecord
 Case RoomDescFile
    Put RoomDescFile,Var!,BufferRecord
 Case ActionFile
    Put ActionFile,Var!,ActionRecord
 Case MonClassFile
    Put MonClassFile,Var!,MonClassRecord
 Case NonPlayerFile
    Put NonPlayerFile,Var!,MonsterRecord
 Case MonsterFile
    Put MonsterFile,Var!,MonsterRecord
 Case UserFile
    Put UserFile,Var!,UserRecord
 Case UserFile2
    Put UserFile2,Var!,UserRecord2
 Case SpellFile
    Put SpellFile,Var!,SpellRecord
 Case ObjectFile
    Put ObjectFile,Var!,ObjectRecord
 Case TreasureFile
    Put TreasureFile,Var!,TreasureRecord
 Case MessWorkFile1
    Put MessWorkFile1,Var!,MessWorkRecord1
 Case MessWorkFile2
    Put MessWorkFile2,Var!,MessWorkRecord2
 Case MessWorkFile3
    Put MessWorkFile3,Var!,MessWorkRecord3
 Case MessWorkFile4
    Put MessWorkFile4,Var!,MessWorkRecord4
 Case MessWorkFile5
    Put MessWorkFile5,Var!,MessWorkRecord5
 Case MessWorkFile6
    Put MessWorkFile6,Var!,MessWorkRecord6
 Case MonClassFile
    Put MonClassFile,Var!,MonClassRecord
 Case MonTalkFile
    Put MonTalkFile,Var!,BufferRecord
 Case ContainerFile
    Put ContainerFile,Var!,ContainerRecord
 Case TeamInvFile
    Put TeamInvFile,Var!,MessWorkRecord6
 Case UserInvFile
    Put UserInvFile,Var!,MessWorkRecord6
 Case CtnInvFile
    Put CtnInvFile,Var!,MessWorkRecord6
 Case RoomInvFile
    Put RoomInvFile,Var!,MessWorkRecord6
 Case MonInvFile
    Put MonInvFile,Var!,MessWorkRecord6
 Case MessBaseFile
    Put MessBaseFile,Var!,MessageBaseRecord
 Case MessageFile
    Put MessageFile,Var!,BufferRecord
 Case NewFile
    Put NewFile,Var!,NewMessages
 Case TableFile
    Put TableFile,Var!,TableRecord
 Case TeamFile
    Put TeamFile,Var!,TeamRecord
 Case DayFile1
    Put DayFile1,Var!,BufferRecord
 Case LogFile
    Put LogFile,Var!,LogRecord
 End Select
 If Share.Installed Then
    Select Case Var
    Case BankFile
       Unlock TempFile1,Var!
    Case ObjDescFile
       Unlock TempFile1,Var!
    Case Else
       UnLock Var,Var!
    End Select
 Endif
Write.Record.Exit:
 Exit Sub
Write.Record.Error:
 Data.Error=Err
 If Share.Installed Then
    If Data.Error=70 Then
       If Time.Elapsed(Lock.Count,10!)=False Then
          If Locked=False Then
             Resume Write.Record.Resume1
          Else
             Resume Write.Record.Resume2
          Endif
       Endif
    Endif
 Endif
 If Debug.Mode Then
    Call Display.Share.Error("Write lock",Var,Var!)
 Endif
 Resume Write.Record.Exit
End Sub

Sub Write.Message.Record(Var,Var2)
 On Local Error Goto Write.Message.Error
 Dim Locked As Integer
 Dim Lock.Count As Single
 If Var2<=0 Then
    Exit Sub
 Endif
 Locked=False
 Lock.Count=Timeit!
Write.Message.Resume1:
 If Share.Installed Then
    Lock Var,Var2
    Locked=True
 Endif
Write.Message.Resume2:
 Select Case Var
 Case MessWorkFile1
    Put MessWorkFile1,Var2,MessWorkRecord1
 Case MessWorkFile7
    Put MessWorkFile7,Var2,MessWorkRecord7
 Case MessWorkFile8
    Put MessWorkFile8,Var2,UserCommandRecord
 Case MessWorkFile9
    Put MessWorkFile9,Var2,UserConfigRecord
 End Select
 If Share.Installed Then
    UnLock Var,Var2
 Endif
Write.Message.Exit:
 Exit Sub
Write.Message.Error:
 Data.Error=Err
 If Share.Installed Then
    If Data.Error=70 Then
       If Time.Elapsed(Lock.Count,10!)=False Then
          If Locked=False Then
             Resume Write.Message.Resume1
          Else
             Resume Write.Message.Resume2
          Endif
       Endif
    Endif
 Endif
 If Debug.Mode Then
    Call Display.Share.Error2("Message write lock",Var,Var2)
 Endif
 Resume Write.Message.Exit
End Sub

Sub Read.Record(Var,Var!)
 On Local Error Goto Read.Record.Error
 Dim Lock.Count As Single
 If Var!<=0! Then
    Exit Sub
 Endif
 Lock.Count=Timeit!
Read.Record.Resume:
 Select Case Var
 Case SicFile
    Get SicFile,Var!,UserProfile
 Case BankFile
    Get TempFile1,Var!,BankRecord
 Case ObjDescFile
    Get TempFile1,Var!,BufferRecord
 Case AutomateFile
    Get AutomateFile,Var!,AutomateRecord
 Case TempFile1
    Get TempFile1,Var!,AutomateRecord
 Case RoomFile
    Get RoomFile,Var!,RoomRecord
 Case RoomDescFile
    Get RoomDescFile,Var!,BufferRecord
 Case ActionFile
    Get ActionFile,Var!,ActionRecord
 Case MonClassFile
    Get MonClassFile,Var!,MonClassRecord
 Case NonPlayerFile
    Get NonPlayerFile,Var!,MonsterRecord
 Case MonsterFile
    Get MonsterFile,Var!,MonsterRecord
 Case UserFile
    Get UserFile,Var!,UserRecord
 Case UserFile2
    Get UserFile2,Var!,UserRecord2
 Case SpellFile
    Get SpellFile,Var!,SpellRecord
 Case ObjectFile
    Get ObjectFile,Var!,ObjectRecord
 Case TreasureFile
    Get TreasureFile,Var!,TreasureRecord
 Case MessWorkFile1
    Get MessWorkFile1,Var!,MessWorkRecord1
 Case MessWorkFile2
    Get MessWorkFile2,Var!,MessWorkRecord2
 Case MessWorkFile3
    Get MessWorkFile3,Var!,MessWorkRecord3
 Case MessWorkFile4
    Get MessWorkFile4,Var!,MessWorkRecord4
 Case MessWorkFile5
    Get MessWorkFile5,Var!,MessWorkRecord5
 Case MessWorkFile6
    Get MessWorkFile6,Var!,MessWorkRecord6
 Case MonClassFile
    Get MonClassFile,Var!,MonClassRecord
 Case MonTalkFile
    Get MonTalkFile,Var!,BufferRecord
 Case ContainerFile
    Get ContainerFile,Var!,ContainerRecord
 Case TeamInvFile
    Get TeamInvFile,Var!,MessWorkRecord6
 Case UserInvFile
    Get UserInvFile,Var!,MessWorkRecord6
 Case CtnInvFile
    Get CtnInvFile,Var!,MessWorkRecord6
 Case RoomInvFile
    Get RoomInvFile,Var!,MessWorkRecord6
 Case MonInvFile
    Get MonInvFile,Var!,MessWorkRecord6
 Case MessBaseFile
    Get MessBaseFile,Var!,MessageBaseRecord
 Case MessageFile
    Get MessageFile,Var!,BufferRecord
 Case NewFile
    Get NewFile,Var!,NewMessages
 Case TableFile
    Get TableFile,Var!,TableRecord
 Case TeamFile
    Get TeamFile,Var!,TeamRecord
 Case DayFile1
    Get DayFile1,Var!,BufferRecord
 Case LogFile
    Get LogFile,Var!,LogRecord
 End Select
Read.Record.Exit:
 Exit Sub
Read.Record.Error:
 Data.Error=Err
 If Share.Installed Then
    If Data.Error=70 Then
       If Time.Elapsed(Lock.Count,10!)=False Then
          Resume Read.Record.Resume
       Endif
    Endif
 Endif
 If Debug.Mode Then
    Call Display.Share.Error("Read lock",Var,Var!)
 Endif
 Resume Read.Record.Exit
End Sub

Sub Read.Message.Record(Var,Var2)
 On Local Error Goto Read.Message.Error
 Dim Lock.Count As Single
 If Var2<=0 Then
    Exit Sub
 Endif
 Lock.Count=Timeit!
Read.Message.Resume:
 Select Case Var
 Case MessWorkFile1
    Get MessWorkFile1,Var2,MessWorkRecord1
 Case MessWorkFile7
    Get MessWorkFile7,Var2,MessWorkRecord7
 Case MessWorkFile8
    Get MessWorkFile8,Var2,UserCommandRecord
 Case MessWorkFile9
    Get MessWorkFile9,Var2,UserConfigRecord
 End Select
Read.Message.Exit:
 Exit Sub
Read.Message.Error:
 Data.Error=Err
 If Share.Installed Then
    If Data.Error=70 Then
       If Time.Elapsed(Lock.Count,10!)=False Then
          Resume Read.Message.Resume
       Endif
    Endif
 Endif
 If Debug.Mode Then
    Call Display.Share.Error2("Message read lock",Var,Var2)
 Endif
 Resume Read.Message.Exit
End Sub

Sub Read.Helpfile(Var,Var2)
 On Local Error Goto Read.Help.Error
 Dim Lock.Count As Single
 If Var2<=0 Then
    Exit Sub
 Endif
 Lock.Count=Timeit!
Read.Help.Resume:
 Select Case Var
 Case HelpFile1
    Get HelpFile1,Var2,HelpRecord1
 Case HelpFile2
    Get HelpFile2,Var2,HelpRecord2
 Case HelpFile3
    Get HelpFile3,Var2,HelpRecord3
 Case HelpFile4
    Get HelpFile4,Var2,HelpRecord3
 End Select
Read.Help.Exit:
 Exit Sub
Read.Help.Error:
 Data.Error=Err
 If Share.Installed Then
    If Data.Error=70 Then
       If Time.Elapsed(Lock.Count,10!)=False Then
          Resume Read.Help.Resume
       Endif
    Endif
 Endif
 If Debug.Mode Then
    Call Display.Share.Error2("Help read lock",Var,Var2)
 Endif
 Resume Read.Help.Exit
End Sub

Sub Display.Share.Error(Var2$,Var,Var!)
 On Local Error Goto Display.Record.Error1
 If Var=16 Or Var=24 Then
    If Data.Error=52 Then
       exit sub
    Endif
 Endif
 Color 15
 Var$=Nul
 If Chained=-2 Then
    Var$="CMD"+Right$("000"+Mid$(Str$(Last.Module.Number),2),3)+":"
 Endif
 Var$=Var$+Var2$+" error:"+Str$(Data.Error)
 Var$=Var$+" file#"+Str$(Var)+" record#"+Str$(Var!)
 Var$=Chr$(13)+Chr$(10)+Var$+Chr$(13)+Chr$(10)
 Call Scrn(Var$)
Display.Record.Exit1:
 Exit Sub
Display.Record.Error1:
 Resume Display.Record.Exit1
End Sub

Sub Display.Share.Error2(Var2$,Var,Var2)
 On Local Error Goto Display.Record.Error2
 If Var=16 Or Var=24 Then
    If Data.Error=52 Then
       exit sub
    Endif
 Endif
 Color 15
 Var$=Nul
 If Chained=-2 Then
    Var$="CMD"+Right$("000"+Mid$(Str$(Last.Module.Number),2),3)+":"
 Endif
 Var$=Var$+Var2$+" error:"+Str$(Data.Error)
 Var$=Var$+" file#"+Str$(Var)+" record#"+Str$(Var2)
 Var$=Chr$(13)+Chr$(10)+Var$+Chr$(13)+Chr$(10)
 Call Scrn(Var$)
Display.Record.Exit2:
 Exit Sub
Display.Record.Error2:
 Resume Display.Record.Exit2
End Sub

Sub VideoInt(Var,Var1)
 Select Case Var
 Case 2 ' set cursor
    InregsX.AX=&H0200
    InregsX.BX=Video.Page
    InregsX.DX=Var1
 Case 3 ' get cursor
    InregsX.AX=&H0300
    InregsX.BX=Video.Page
 Case 6 ' scroll
    InregsX.AX=&H0601
    InregsX.BX=&H0700
    InregsX.CX=&H0000
    InregsX.DX=Var1
 Case 15 ' get mode
    InregsX.AX=&H0F00
 End Select
 Call InterruptX(&H10,InregsX,OutregsX)
End Sub

Sub StdinInt(Var,VarY)
 Select Case Var
 Case 6 ' output
    InregsX.AX=&H0600
    InregsX.DX=VarY
 Case 7 ' input
    InregsX.AX=&H0600
    InregsX.DX=&H00FF
 Case 48 ' get os version
    InregsX.AX=&H3001
 Case 54 ' get disk space
    InregsX.AX=&H3600
    InregsX.DX=&H0000
 Case 62 ' get psp segment
    InregsX.AX=&H6200
 Case 68 ' ioctl
    InregsX.AX=&H4400+VarY
    InregsX.BX=&H01
 End Select
 Call InterruptX(&H21,InregsX,OutregsX)
End Sub

Sub Mouse.Function(Var1,Var2)
 InregsX.AX=Var1
 InregsX.BX=Var2
 Call InterruptX(&H33,InregsX,OutregsX)
End Sub

Sub Mouse.Function2(Var1,Var2,Var3,Var4)
 InregsX.AX=Var1
 InregsX.BX=Var2
 InregsX.CX=Var3
 InregsX.DX=Var4
 Call InterruptX(&H33,InregsX,OutregsX)
End Sub

Sub Slice.Function
 InregsX.AX=&H1680
 InregsX.BX=&H0000
 Call InterruptX(&H2F,InregsX,OutregsX)
End Sub

Sub Plex.Function(Var1)
 Select Case Var1
 Case 16 ' detect share
    InregsX.AX=&H1000
 Case 22 ' detect windows
    InregsX.AX=&H160A
 Case 26 ' detect ansi
    InregsX.AX=&H1A00
 Case 27 ' detect avatar
    InregsX.AX=&H1A00
    InregsX.BX=&H4156
    InregsX.CX=&H4154
    InregsX.DX=&H4152
 Case 74 ' detect dos
    InregsX.AX=&H4A33
 End Select
 Call InterruptX(&H2F,InregsX,OutregsX)
End Sub
