largo_winch
27-09-2012, 10:47
last not least, I have finished this little "cast" convertion from freebasic. it's only the byte ptr problem ( chapter b) ) here to solve. the second result should be -128 -128, the first part is correct. any help for the part b) is welcome here again. the original code from freebasic is below thinbasic example. bye, largo
Uses "console"
Function TBMain () As Long
Dim i As Integer, ip As Integer 'Ptr
Dim b As Byte, bp As Byte 'Ptr
'a) ------------------------------
i = &h0080 '128
'b = CAST(BYTE, i) ''freebasic
b=(Peek(Byte,VarPtr(i)))
'ip = @i ''freebasic
ip=VarPtr(i)
'b) ---------------------------------
bp=VarPtr(b) ' my idea: add this one ?
bp=(Peek(Byte,VarPtr(ip))) 'BYTE PTR not possible
'bp = CAST(BYTE PTR, ip) ''freebasic
'------------------------------------
' a)
MsgBox 0, "i+b"+Str$(i)+Str$(b) ' correct
' b)
MsgBox 0, "ip+bp"+Str$(VarPtr(ip))+Str$(VarPtr(bp)) ' not correct
' correct result from freebasic looks like:
'128 -128
'128 -128
End Function
'
' freebasic original code example:
'
' DIM i AS INTEGER, ip AS INTEGER PTR
' DIM b AS BYTE, bp AS BYTE PTR
' i = &h0080
' b = CAST(BYTE, i)
' ip = @i
' bp = CAST(BYTE PTR, ip)
' PRINT i, b
' PRINT *ip, *bp
' Sleep
'result
'128 -128
'128 -128
Uses "console"
Function TBMain () As Long
Dim i As Integer, ip As Integer 'Ptr
Dim b As Byte, bp As Byte 'Ptr
'a) ------------------------------
i = &h0080 '128
'b = CAST(BYTE, i) ''freebasic
b=(Peek(Byte,VarPtr(i)))
'ip = @i ''freebasic
ip=VarPtr(i)
'b) ---------------------------------
bp=VarPtr(b) ' my idea: add this one ?
bp=(Peek(Byte,VarPtr(ip))) 'BYTE PTR not possible
'bp = CAST(BYTE PTR, ip) ''freebasic
'------------------------------------
' a)
MsgBox 0, "i+b"+Str$(i)+Str$(b) ' correct
' b)
MsgBox 0, "ip+bp"+Str$(VarPtr(ip))+Str$(VarPtr(bp)) ' not correct
' correct result from freebasic looks like:
'128 -128
'128 -128
End Function
'
' freebasic original code example:
'
' DIM i AS INTEGER, ip AS INTEGER PTR
' DIM b AS BYTE, bp AS BYTE PTR
' i = &h0080
' b = CAST(BYTE, i)
' ip = @i
' bp = CAST(BYTE PTR, ip)
' PRINT i, b
' PRINT *ip, *bp
' Sleep
'result
'128 -128
'128 -128