Advertisement
jargon

bi 0.03 blitzbasic.bb

Jul 3rd, 2013
3,227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;bi 0.03
  2. ;Binary Data Module
  3. ;Blitz Basic Source Code
  4. ;Copyright Wednesday, November 14th 2007 Timothy Robert Keal
  5. ;requires (none)
  6.  
  7. ;string to pointer
  8. Function bi_sp(value$)
  9.     value=Upper(value)
  10.     Local ptr=CreateBank(Len(value))
  11.     Local offset=0
  12.     Repeat
  13.         If offset>=BankSize(ptr) Then Exit
  14.         PokeByte ptr,offset,bi_a(Asc(Mid(value,offset+1,1)))
  15.         offset=offset+1
  16.     Forever
  17.     Return ptr
  18. End Function
  19.  
  20. ;transcode ascii char
  21. Function bi_a(ascii)
  22.     If ascii>=48 And ascii<=57 Then
  23.         Return ascii-48
  24.     ElseIf ascii>=65 And ascii<=90 Then
  25.         Return ascii-55
  26.     ElseIf ascii>=97 And ascii<=122 Then
  27.         Return ascii-87
  28.     ElseIf ascii=46 Then
  29.         Return 36
  30.     Else
  31.         Return 37
  32.     EndIf
  33. End Function
  34.  
  35. ;int to float
  36. Function bi_if#(value)
  37.     Local temp=CreateBank($4)
  38.     PokeInt temp,0,value
  39.     Local ret#=PeekFloat(temp,0)
  40.     FreeBank temp
  41.     Return ret
  42. End Function
  43.  
  44. ;float to int
  45. Function bi_fi(value#)
  46.     Local temp=CreateBank($4)
  47.     PokeFloat temp,0,value
  48.     Local ret=PeekInt(temp,0)
  49.     FreeBank temp
  50.     Return ret
  51. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement