'S2 tricks

Comnr = Sc.ButtonBox("Âáåð&ograve ;å íóæí ñì ðò:", vbDefaultButton4, "Óñòí Phoenix'a", "COM 1", "COM 2")
Comnr = "com" & Comnr & ":"
Call Config()

Sub Main()
Do
trick = Sc.ButtonBox("Âáåð&ograve ;å ðåæì:", vbDefaultButton4, "Måíþ", "ìåíò PBM", "ìåíò PPUA", "òåíå ðò", "ñò EMM", "Âõä")
If trick=1 then
Call PBM
End If
If trick=2 then
Call PPUA
End if
If trick=3 then
Call getpar
End if
If trick=4 then
Call EMM
End if
If trick=5 then
Exit Sub
End if
Loop
End Sub

Sub Config()
Wx.CommPort = Comnr
Wx.BaudRate = 9600
Wx.ResetBaudRate = 9600
Wx.Parity = 2
Wx.StopBits = 2
Wx.DTRControl = 1
Wx.RTSControl = 0
Wx.ResetDelay = 250
Wx.ByteDelay = 0
Wx.RxByteTimeout = 500
Wx.ResetMode = 1
Wx.ResetLine = 0
Wx.ByteConvention = 1
Wx.FlushEchoByte = 0
Wx.FlushBeforeWrite = 0
Wx.IgnoreTimeouts = 0
Wx.ResetAfterTimeout = 0
Wx.LogTransactions = 0
Wx.DisplayUSW = 0
Wx.DisplayFuse = 0
End Sub

Sub PBM()
Dim PBMlow(8)
Dim PBMhigh(8)
Dim PBMcur(8)
Loglow = Sc.InputBox("Âñò EMM òðóþ ìíìí åò", "Âåäåíå ã", "")
lenlow = htd (mid(Loglow, 13, 2))
Loghigh = Sc.InputBox("Âñò EMM òðóþ ìñìí åò", "Âåäåíå ã", "")
lenhigh = htd (mid(Loghigh, 13, 2))
Sc.Write (mid(Loghigh, 1, 14))
Sc.Read (6)
Sc.Write (mid(Loghigh, 16, lenhigh*3-1))
Sc.Read (lenhigh+2)
Sc.Write ("C1 34 00 00 03")
Sc.Read (6)
Sc.Write ("00 00 00")
Sc.Read (5)
Sc.Write ("C1 32 01 00 20")
Sc.Read (7)
For i=1 to 8
Sc.Read (1)
PBMhigh(i) = Sc.GetByte(0)
Next
Sc.Read (25)
Sc.Write (mid(Loglow, 1, 14))
Sc.Read (6)
Sc.Write (mid(Loglow, 16, lenlow*3-1))
Sc.Read (lenlow+2)
Sc.Write ("C1 34 00 00 03")
Sc.Read (6)
Sc.Write ("00 00 00")
Sc.Read (5)
Sc.Write ("C1 32 01 00 20")
Sc.Read (7)
For i=1 to 8
Sc.Read (1)
PBMlow(i) = Sc.GetByte(0)
Next
Sc.Read (25)
krok=10
For dly=0 to 500 step krok
Call Sc.ProgressBox("Âðåìÿ ððåøåí&yum l; í íåíå EMM-a: " & string(4-len(dly)," ") & dly & " ms", dly+1, 501, "Ñíðíå ðåìåí íåíÿ íí 0x80")
Sc.Write (mid(Loghigh, 1, 14))
Sc.Read (6)
Sc.Write (mid(Loghigh, 16, lenhigh*3-1))
Sc.Read (lenhigh)
Sc.Delay (dly)
Sc.Reset
Sc.Write ("C1 34 00 00 03")
Sc.Read (6)
Sc.Write ("00 00 00")
Sc.Read (5)
Sc.Write ("C1 32 01 00 20")
Sc.Read (7)
For i=1 to 8
Sc.Read (1)
PBMcur(i) = Sc.GetByte(0)
Next
Sc.Read (25)
chg=1
For i=1 to 8
If PBMcur(i) <> PBMhigh(i) then
chg=0
Else
krok=1
End If
Next
If chg=1 then
Call Sc.ProgressBox("", 0, 0)
Sc.MsgBox ("PBM &igrave;&aring;&iacute;&aring;&iacute;")
Exit Sub
End If
Next
Call Sc.ProgressBox("", 0, 0)
Sc.MsgBox ("&Euml;&atilde; &iacute;&aring; &igrave;&aring;&iacute;&yuml;&aring;&ograve; PBM")
End Sub

Sub PPUA()
Dim Dateold(2)
Dim Datenew(2)
Dim Datecur(2)
Logppua = Sc.InputBox("&Acirc;&ntilde;&ograve; EMM &igrave;&aring;&iacute;&yuml;&thorn; PPUA", "&Acirc;&aring;&auml;&aring;&iacute;&aring; &atilde;", "")
lenppua = htd (mid(Logppua, 13, 2))
Logmk01 = Sc.InputBox("&Acirc;&ntilde;&ograve; EMM &igrave;&aring;&iacute;&yuml;&thorn; MK01", "&Acirc;&aring;&auml;&aring;&iacute;&aring; &atilde;", "")
lenmk01 = htd (mid(Logmk01, 13, 2))
Sc.Write (mid(Logmk01, 1, 14))
Sc.Read (6)
Sc.Write (mid(Logmk01, 16, lenmk01*3-1))
Sc.Read (lenmk01+2)
Sc.Write ("C1 12 01 00 18")
Sc.Read (28)
For i=1 to 2
Sc.Read (1)
Datenew(i) = Sc.GetByte(0)
Next
Sc.Read (2)
Sc.Write (mid(Logppua, 1, 14))
Sc.Read (6)
Sc.Write (mid(Logppua, 16, lenppua*3-1))
Sc.Read (lenppua+2)
Sc.Write ("C1 12 01 00 18")
Sc.Read (28)
For i=1 to 2
Sc.Read (1)
Dateold(i) = Sc.GetByte(0)
Next
Sc.Read (2)
krok=10
For dly=0 to 500 step krok
Call Sc.ProgressBox("&Acirc;&eth;&aring;&igrave;&yuml; &eth;&eth;&aring;&oslash;&aring;&iacute;&yum l; &iacute; &iacute;&aring;&iacute;&aring; EMM-a: " & string(4-len(dly)," ") & dly & " ms", dly+1, 501, "Skanowanie czasu wykonania nano 0x80")
Sc.Write (mid(Logmk01, 1, 14))
Sc.Read (6)
Sc.Write (mid(Logmk01, 16, lenmk01*3-1))
Sc.Read (lenmk01)
Sc.Delay (dly)
Sc.Reset
Sc.Write ("C1 12 01 00 18")
Sc.Read (28)
For i=1 to 2
Sc.Read (1)
Datecur(i) = Sc.GetByte(0)
Next
Sc.Read (2)
chg=1
For i=1 to 2
If Datecur(i) <> Datenew(i) then
chg=0
Else
krok=1
End If
Next
If chg=1 then
Call Sc.ProgressBox("", 0, 0)
Sc.MsgBox ("PPUA &igrave;&aring;&iacute;&aring;&iacute;")
Exit Sub
End If
Next
Call Sc.ProgressBox("", 0, 0)
Sc.MsgBox ("&Euml;&atilde; &iacute;&aring; &igrave;&aring;&iacute;&yuml;&aring;&ograve; PPUA")
End Sub

Sub getpar
Dim PBM(8)
Dim PPUA(4)
Sc.Write ("C1 34 00 00 03")
Sc.Read (6)
Sc.Write ("00 00 00")
Sc.Read (5)
Sc.Write ("C1 32 01 00 20")
Sc.Read (7)
For i=1 to 8
Sc.Read (1)
PBM(i) = Sc.GetByte(0)
Next
Sc.Read (25)
Sc.Write ("C1 12 01 00 18")
Sc.Read (24)
For i=1 to 4
Sc.Read (1)
PPUA(i) = Sc.GetByte(0)
Next
Sc.Read (4)
Sc.MsgBox ("PBM: " & string(2-len(hex(PBM(1))), "0") & hex(PBM(1)) & " " & string(2-len(hex(PBM(2))), "0") & hex(PBM(2)) & " " & string(2-len(hex(PBM(3))), "0") & hex(PBM(3)) & " " & string(2-len(hex(PBM(4))), "0") & hex(PBM(4)) & " " & string(2-len(hex(PBM(5))), "0") & hex(PBM(5)) & " " & string(2-len(hex(PBM(6))), "0") & hex(PBM(6)) & " " & string(2-len(hex(PBM(7))), "0") & hex(PBM(7)) & " " & string(2-len(hex(PBM(8))), "0") & hex(PBM(8)) & " PPUA: " & string(2-len(hex(PPUA(1))), "0") & hex(PPUA(1)) & " " & string(2-len(hex(PPUA(2))), "0") & hex(PPUA(2)) & " " & string(2-len(hex(PPUA(3))), "0") & hex(PPUA(3)) & " " & string(2-len(hex(PPUA(4))), "0") & hex(PPUA(4)) & " ")
End Sub

Sub EMM
Dim s(2)
EMMlog = Sc.InputBox("&Acirc;&ntilde;&ograve; EMM, &ograve;&eth; &iacute;&aring;&oslash; &ntilde;&ograve; &eth;&ograve;&oacute;", "&Acirc;&aring;&auml;&aring;&iacute;&aring; &atilde;", "")
lenEMM = htd (mid(EMMlog, 13, 2))
Sc.Write (mid(EMMlog, 1, 14))
Sc.Read (6)
Sc.Write (mid(EMMlog, 16, lenEMM*3-1))
Sc.Read (lenEMM)
Sc.Read (1)
s(1) = Sc.GetByte(0)
Sc.Read (1)
s(2) = Sc.GetByte(0)
Sc.MsgBox ("&Icirc;&ograve;&aring;&ograve; &eth;&ograve;: " & string(2-len(hex(s(1))), "0") & hex(s(1)) & " " & string(2-len(hex(s(2))), "0") & hex(s(2)))
End Sub

Function htd (a)
dim cd(2)
for l=1 to 2
Select Case mid(a,l,1)
Case "0"
cd(l)=0
Case "1"
cd(l)=1
Case "2"
cd(l)=2
Case "3"
cd(l)=3
Case "4"
cd(l)=4
Case "5"
cd(l)=5
Case "6"
cd(l)=6
Case "7"
cd(l)=7
Case "8"
cd(l)=8
Case "9"
cd(l)=9
Case "A"
cd(l)=10
Case "B"
cd(l)=11
Case "C"
cd(l)=12
Case "D"
cd(l)=13
Case "E"
cd(l)=14
Case "F"
cd(l)=15
End Select
next
htd=cd(1)*16+cd(2)
End Function