You are right. Then...
Poke$? That is soooo 80's BASIC
Lets see what new ThinBASIC offers, it's time to release the Kraken... or Memory_Copy!:
Uses "Console"
%MAX_Tests = 1000000
Type data
byte0 As Byte
byte1 As Byte
byte2 As Byte
End Type
Union uData
AsByte As data
AsLong As Long
End Union
Type tData
Element As uData
End Type
Dim Midi As data
Long MidiWord
Quad tStart,tEnd
Double tTime 'for obtain elapsed time
' -- Initialize high precision timer
HiResTimer_Init
'---------------------------------------------------------------------
PrintL "MidiWord conversion speed test" + Str$(%Max_Tests) + " of executions:"
PrintL
PrintL "Press a Key to start method Midi_Decode_Max"
WaitKey
tStart = HiResTimer_Get
For MidiWord = 1 To %Max_Tests
Midi_Decode_Max (MidiWord)
''PrintL Midi.byte0 & $TAB & Midi.byte1 & $TAB & Midi.byte2
Next
tEnd = HiResTimer_Get : tTime = (tEnd-tStart)/1000000
PrintL CRLF & "Executed in " & Format$(tTime, "#.00") & " seconds" & CRLF
'---------------------------------------------------------------------
PrintL "Press a Key to start method Midi_Decode_Rene1"
WaitKey
tStart = HiResTimer_Get
For MidiWord = 1 To %Max_Tests
Midi_Decode_Rene1(MidiWord)
''PrintL Midi.byte0 & $TAB & Midi.byte1 & $TAB & Midi.byte2
Next
tEnd = HiResTimer_Get : tTime = (tEnd-tStart)/1000000
PrintL CRLF & "Executed in " & Format$(tTime, "#.00") & " seconds" & CRLF
'---------------------------------------------------------------------
PrintL "Press a Key to start method Midi_Decode_Rene2"
WaitKey
tStart = HiResTimer_Get
For MidiWord = 1 To %Max_Tests
Midi_Decode_Rene2(MidiWord)
''PrintL Midi.byte0 & $TAB & Midi.byte1 & $TAB & Midi.byte2
Next
tEnd = HiResTimer_Get : tTime = (tEnd-tStart)/1000000
PrintL CRLF & "Executed in " & Format$(tTime, "#.00") & " seconds" & CRLF
'---------------------------------------------------------------------
PrintL "Press a Key to start method Midi_Decode_Rene3"
WaitKey
tStart = HiResTimer_Get
For MidiWord = 1 To %Max_Tests
Midi_Decode_Rene3(MKL$(MidiWord))
'' PrintL Midi.byte0 & $TAB & Midi.byte1 & $TAB & Midi.byte2
Next
tEnd = HiResTimer_Get : tTime = (tEnd-tStart)/1000000
PrintL CRLF & "Executed in " & Format$(tTime, "#.00") & " seconds" & CRLF
'---------------------------------------------------------------------
PrintL "Press a Key to start method Midi_Decode_Rene4"
WaitKey
tStart = HiResTimer_Get
For MidiWord = 1 To %Max_Tests
Midi_Decode_Rene4(MKL$(MidiWord))
'' PrintL Midi.byte0 & $TAB & Midi.byte1 & $TAB & Midi.byte2
Next
tEnd = HiResTimer_Get : tTime = (tEnd-tStart)/1000000
PrintL CRLF & "Executed in " & Format$(tTime, "#.00") & " seconds" & CRLF
'---------------------------------------------------------------------
PrintL "Press a Key to start method Midi_Decode_Eros1"
WaitKey
tStart = HiResTimer_Get
Dim lData As tData
For MidiWord = 1 To %Max_Tests
lData.Element.AsLong = MidiWord
''PrintL lData.Element.AsByte.byte0 & $TAB & lData.Element.AsByte.byte1 & $TAB & lData.Element.AsByte.byte2
Next
tEnd = HiResTimer_Get : tTime = (tEnd-tStart)/1000000
PrintL CRLF & "Executed in " & Format$(tTime, "#.00") & " seconds" & CRLF
'---------------------------------------------------------------------
PrintL "Press a Key to start method Midi_Decode_Petr1 Tuned"
WaitKey
tStart = HiResTimer_Get
For MidiWord = 1 To %Max_Tests
Memory_Copy(VarPtr(MidiWord), VarPtr(Midi), SizeOf(Midi))
''PrintL Midi.byte0 & $TAB & Midi.byte1 & $TAB & Midi.byte2
Next
tEnd = HiResTimer_Get : tTime = (tEnd-tStart)/1000000
PrintL CRLF & "Executed in " & Format$(tTime, "#.00") & " seconds" & CRLF
'---------------------------------------------------------------------
PrintL "Press a Key to exit"
WaitKey
Sub Midi_Decode_Max (ByVal nVal As Long)
Dim temp0,temp1,temp2 As Long = nVal
Midi.byte0 = temp0 And 255
Midi.byte1 = (SHIFT SIGNED RIGHT temp1, 8) And 255
Midi.byte2 = (SHIFT SIGNED RIGHT temp2, 16) And 255
End Sub
Sub Midi_Decode_Rene1(ByVal anyValue As Long)
Midi.byte2 = Int(anyValue / &H10000)
Midi.byte1 = Int((anyValue - &H10000 * Midi.byte2)/ &H100)
Midi.byte0 = anyValue - Midi.byte2 * &H10000 - Midi.byte1 * &H100
End Sub
Sub Midi_Decode_Rene2(ByRef someVal As Long)
Midi.byte0 = Peek(Byte,VarPtr(someVal))
Midi.byte1 = Peek(Byte,VarPtr(someVal)+ 1)
Midi.byte2 = Peek(Byte,VarPtr(someVal)+ 2)
End Sub
Sub Midi_Decode_Rene3(ByVal someVal As String)
Midi.byte0 = Peek(Byte,StrPtr(someVal))
Midi.byte1 = Peek(Byte,StrPtr(someVal)+ 1)
Midi.byte2 = Peek(Byte,StrPtr(someVal)+ 2)
End Sub
Sub Midi_Decode_Rene4(ByVal someVal As String)
Local lByte As data At StrPtr(someVal)
Midi = lByte
End Sub
Petr
Bookmarks