Advertisement
jargon

aa 0.06 blitzbasic.bb

Jul 3rd, 2013
2,981
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;aa 0.06
  2. ;Associative Array Module
  3. ;Blitz Basic Source Code
  4. ;Copyright Wednesday, November 14th 2007 Timothy Robert Keal
  5. ;requires "bi/bi 0.03.bb"
  6.  
  7. Const aa_sep=$2F
  8. Const aa_ptrmx=$26
  9. Const aa_bnkmx=$A4
  10. Const aa_chro=$0
  11. Const aa_valo=$98
  12. Const aa_ptro=$9C
  13. Const aa_lasto=$A0
  14. Global aa=aa_a(False)
  15.  
  16. ;re-allocate using given
  17. Function aa_a(aa)
  18.     Return aa_allocate(aa)
  19. End Function
  20.  
  21. ;seek pointer using master
  22. Function aa_p(label$)
  23.     Local temp=bi_sp(label)
  24.     Local ret=aa_seekptr(aa,temp,0)
  25.     FreeBank temp
  26.     Return ret
  27. End Function
  28.  
  29. ;set integer using master
  30. Function aa_s(label$,value)
  31.     Local temp=bi_sp(Upper(label))
  32.     aa_pokeint aa,temp,0,value
  33.     FreeBank temp
  34. End Function
  35.  
  36. ;get integer using master
  37. Function aa_g(label$)
  38.     Local temp=bi_sp(Upper(label))
  39.     Local ret=aa_peekint(aa,temp,0)
  40.     FreeBank temp
  41.     Return ret
  42. End Function
  43.  
  44. ;set float using master
  45. Function aa_sf(label$,value#)
  46.     Local temp=bi_sp(Upper(label))
  47.     aa_pokefloat aa,temp,0,value
  48.     FreeBank temp
  49. End Function
  50.  
  51. ;get float using master
  52. Function aa_gf#(label$)
  53.     Local temp=bi_sp(Upper(label))
  54.     Local ret#=aa_peekfloat(aa,temp,0)
  55.     FreeBank temp
  56.     Return ret
  57. End Function
  58.  
  59. ;re-allocate using given
  60. Function aa_allocate(aa)
  61.     If aa<>False Then aa_collapse(aa)
  62.     aa=CreateBank(aa_bnkmx)
  63.     PokeByte(aa,aa_lasto,True)
  64.     Return aa
  65. End Function
  66.  
  67. ;collapse using given
  68. Function aa_collapse(aa)
  69.     Local emptyflag=False
  70.     If aa=False Then Return False
  71.     If BankSize(aa)<>aa_bnkmx Then
  72.         FreeBank aa
  73.         Return aa
  74.     EndIf
  75.    
  76.     ptrbyte=$00
  77.     Repeat
  78.         If ptrbyte>=(aa_ptrmx Shl $2) Then Exit
  79.         aa_collapse PeekInt(aa,ptrbyte+aa_chro)
  80.         ptrbyte=ptrbyte+$04
  81.     Forever
  82.  
  83.     Local aa2=False
  84.  
  85.     aa2=PeekInt(aa,aa_ptro)
  86.     If aa2<>False Then aa_collapse aa2
  87.  
  88.     If PeekByte(aa,aa_lasto)=True
  89.         d3_collapse PeekInt(aa,aa_valo)
  90.     EndIf
  91.    
  92.     FreeBank aa
  93.     Return False
  94. End Function
  95.  
  96. ;seek pointer using given
  97. Function aa_seekptr(aa,ptr,offset)
  98.    
  99.     Local nullflag=False
  100.     If ptr=False Then nullflag=True
  101.     If nullflag=False Then
  102.         If offset>=BankSize(ptr) Then nullflag=True
  103.     EndIf
  104.        
  105.     Local emptyflag=False
  106.     If aa=0 Then emptyflag=True
  107.     If emptyflag=False Then
  108.         If BankSize(aa)<>aa_bnkmx Then emptyflag=True
  109.     EndIf
  110.    
  111.     If emptyflag=True Return False
  112.  
  113.     If nullflag=True Then
  114.         Return aa
  115.     EndIf
  116.  
  117.     Local ptrbyte=PeekByte(ptr,offset)
  118.  
  119.     Local aa2=False
  120.    
  121.     If ptrbyte=aa_sep Then
  122.         aa2=PeekInt(aa,aa_ptro)
  123.         If aa2=False Then Return False
  124.         Return aa_seekptr(aa2,ptr,offset+$1)
  125.     EndIf
  126.    
  127.     Return aa_seekptr(PeekInt(aa,(ptrbyte Shl $2)+aa_chro),ptr,offset+$1)
  128.  
  129. End Function
  130.  
  131. ;poke integer using given
  132. Function aa_pokeint(aa,ptr,offset,value)
  133.    
  134.     Local nullflag=False
  135.     If ptr=False Then nullflag=True
  136.     If nullflag=False Then
  137.         If offset>=BankSize(ptr) Then nullflag=True
  138.     EndIf
  139.        
  140.     Local emptyflag=False
  141.     If aa=0 Then
  142.         emptyflag=True
  143.         aa=CreateBank(aa_bnkmx)
  144.     EndIf
  145.     If emptyflag=False Then
  146.         If BankSize(aa)<>aa_bnkmx Then
  147.             emptyflag=True
  148.             ResizeBank aa,aa_bnkmx
  149.         EndIf
  150.     EndIf
  151.        
  152.     If nullflag=True Then
  153.         PokeInt aa,aa_valo,value
  154.         Return aa
  155.     EndIf
  156.  
  157.     Local ptrbyte=PeekByte(ptr,offset)
  158.  
  159.     Local aa2=False
  160.    
  161.     If ptrbyte=aa_sep Then
  162.         aa2=PeekInt(aa,aa_ptro)
  163.         If aa2=False Then
  164.             aa2=aa_allocate(aa2)
  165.             PokeInt aa,aa_ptro,aa2
  166.         EndIf      
  167.         Return aa_pokeint(aa2,ptr,offset+$1,value)
  168.     EndIf
  169.  
  170.     aa2=PeekInt(aa,(ptrbyte Shl $2)+aa_chro)
  171.     If aa2=False Then
  172.         aa2=aa_allocate(aa2)
  173.         PokeByte(aa2,aa_lasto,False)
  174.         PokeInt aa,(ptrbyte Shl $2)+aa_chro,aa2
  175.     EndIf
  176.        
  177.     Return aa_pokeint(aa2,ptr,offset+1,value)
  178. End Function
  179.  
  180. ;peek integer using given
  181. Function aa_peekint(aa,ptr,offset)
  182.  
  183.     Local nullflag=False
  184.     If ptr=False Then nullflag=True
  185.     If nullflag=False Then
  186.         If offset>=BankSize(ptr) Then nullflag=True
  187.     EndIf
  188.        
  189.     Local emptyflag=False
  190.     If aa=0 Then emptyflag=True
  191.     If emptyflag=False Then
  192.         If BankSize(aa)<>aa_bnkmx Then emptyflag=True
  193.     EndIf
  194.    
  195.     If emptyflag=True Return False
  196.  
  197.     If nullflag=True Then
  198.         Return PeekInt(aa,aa_valo)
  199.     EndIf
  200.  
  201.     Local ptrbyte=PeekByte(ptr,offset)
  202.  
  203.     Local aa2=False
  204.    
  205.     If ptrbyte=aa_sep Then
  206.         aa2=PeekInt(aa,aa_ptro)
  207.         If aa2=False Then Return False
  208.         Return aa_peekint(aa2,ptr,offset+$1)
  209.     EndIf
  210.    
  211.     aa2=PeekInt(aa,(ptrbyte Shl $2)+aa_chro)
  212.     If aa2=False Then Return False
  213.    
  214.     Return aa_peekint(aa2,ptr,offset+$1)
  215.  
  216. End Function
  217.  
  218. ;poke float using given
  219. Function aa_pokefloat(aa,ptr,offset,value#)
  220.         Return aa_pokeint(aa,ptr,offset,bi_fi(value))
  221. End Function
  222.  
  223. ;peek float using given
  224. Function aa_peekfloat#(aa,ptr,offset)
  225.         Return bi_if(aa_peekint(aa,ptr,offset))
  226. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement