Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;aa 0.06
- ;Associative Array Module
- ;Blitz Basic Source Code
- ;Copyright Wednesday, November 14th 2007 Timothy Robert Keal
- ;requires "bi/bi 0.03.bb"
- Const aa_sep=$2F
- Const aa_ptrmx=$26
- Const aa_bnkmx=$A4
- Const aa_chro=$0
- Const aa_valo=$98
- Const aa_ptro=$9C
- Const aa_lasto=$A0
- Global aa=aa_a(False)
- ;re-allocate using given
- Function aa_a(aa)
- Return aa_allocate(aa)
- End Function
- ;seek pointer using master
- Function aa_p(label$)
- Local temp=bi_sp(label)
- Local ret=aa_seekptr(aa,temp,0)
- FreeBank temp
- Return ret
- End Function
- ;set integer using master
- Function aa_s(label$,value)
- Local temp=bi_sp(Upper(label))
- aa_pokeint aa,temp,0,value
- FreeBank temp
- End Function
- ;get integer using master
- Function aa_g(label$)
- Local temp=bi_sp(Upper(label))
- Local ret=aa_peekint(aa,temp,0)
- FreeBank temp
- Return ret
- End Function
- ;set float using master
- Function aa_sf(label$,value#)
- Local temp=bi_sp(Upper(label))
- aa_pokefloat aa,temp,0,value
- FreeBank temp
- End Function
- ;get float using master
- Function aa_gf#(label$)
- Local temp=bi_sp(Upper(label))
- Local ret#=aa_peekfloat(aa,temp,0)
- FreeBank temp
- Return ret
- End Function
- ;re-allocate using given
- Function aa_allocate(aa)
- If aa<>False Then aa_collapse(aa)
- aa=CreateBank(aa_bnkmx)
- PokeByte(aa,aa_lasto,True)
- Return aa
- End Function
- ;collapse using given
- Function aa_collapse(aa)
- Local emptyflag=False
- If aa=False Then Return False
- If BankSize(aa)<>aa_bnkmx Then
- FreeBank aa
- Return aa
- EndIf
- ptrbyte=$00
- Repeat
- If ptrbyte>=(aa_ptrmx Shl $2) Then Exit
- aa_collapse PeekInt(aa,ptrbyte+aa_chro)
- ptrbyte=ptrbyte+$04
- Forever
- Local aa2=False
- aa2=PeekInt(aa,aa_ptro)
- If aa2<>False Then aa_collapse aa2
- If PeekByte(aa,aa_lasto)=True
- d3_collapse PeekInt(aa,aa_valo)
- EndIf
- FreeBank aa
- Return False
- End Function
- ;seek pointer using given
- Function aa_seekptr(aa,ptr,offset)
- Local nullflag=False
- If ptr=False Then nullflag=True
- If nullflag=False Then
- If offset>=BankSize(ptr) Then nullflag=True
- EndIf
- Local emptyflag=False
- If aa=0 Then emptyflag=True
- If emptyflag=False Then
- If BankSize(aa)<>aa_bnkmx Then emptyflag=True
- EndIf
- If emptyflag=True Return False
- If nullflag=True Then
- Return aa
- EndIf
- Local ptrbyte=PeekByte(ptr,offset)
- Local aa2=False
- If ptrbyte=aa_sep Then
- aa2=PeekInt(aa,aa_ptro)
- If aa2=False Then Return False
- Return aa_seekptr(aa2,ptr,offset+$1)
- EndIf
- Return aa_seekptr(PeekInt(aa,(ptrbyte Shl $2)+aa_chro),ptr,offset+$1)
- End Function
- ;poke integer using given
- Function aa_pokeint(aa,ptr,offset,value)
- Local nullflag=False
- If ptr=False Then nullflag=True
- If nullflag=False Then
- If offset>=BankSize(ptr) Then nullflag=True
- EndIf
- Local emptyflag=False
- If aa=0 Then
- emptyflag=True
- aa=CreateBank(aa_bnkmx)
- EndIf
- If emptyflag=False Then
- If BankSize(aa)<>aa_bnkmx Then
- emptyflag=True
- ResizeBank aa,aa_bnkmx
- EndIf
- EndIf
- If nullflag=True Then
- PokeInt aa,aa_valo,value
- Return aa
- EndIf
- Local ptrbyte=PeekByte(ptr,offset)
- Local aa2=False
- If ptrbyte=aa_sep Then
- aa2=PeekInt(aa,aa_ptro)
- If aa2=False Then
- aa2=aa_allocate(aa2)
- PokeInt aa,aa_ptro,aa2
- EndIf
- Return aa_pokeint(aa2,ptr,offset+$1,value)
- EndIf
- aa2=PeekInt(aa,(ptrbyte Shl $2)+aa_chro)
- If aa2=False Then
- aa2=aa_allocate(aa2)
- PokeByte(aa2,aa_lasto,False)
- PokeInt aa,(ptrbyte Shl $2)+aa_chro,aa2
- EndIf
- Return aa_pokeint(aa2,ptr,offset+1,value)
- End Function
- ;peek integer using given
- Function aa_peekint(aa,ptr,offset)
- Local nullflag=False
- If ptr=False Then nullflag=True
- If nullflag=False Then
- If offset>=BankSize(ptr) Then nullflag=True
- EndIf
- Local emptyflag=False
- If aa=0 Then emptyflag=True
- If emptyflag=False Then
- If BankSize(aa)<>aa_bnkmx Then emptyflag=True
- EndIf
- If emptyflag=True Return False
- If nullflag=True Then
- Return PeekInt(aa,aa_valo)
- EndIf
- Local ptrbyte=PeekByte(ptr,offset)
- Local aa2=False
- If ptrbyte=aa_sep Then
- aa2=PeekInt(aa,aa_ptro)
- If aa2=False Then Return False
- Return aa_peekint(aa2,ptr,offset+$1)
- EndIf
- aa2=PeekInt(aa,(ptrbyte Shl $2)+aa_chro)
- If aa2=False Then Return False
- Return aa_peekint(aa2,ptr,offset+$1)
- End Function
- ;poke float using given
- Function aa_pokefloat(aa,ptr,offset,value#)
- Return aa_pokeint(aa,ptr,offset,bi_fi(value))
- End Function
- ;peek float using given
- Function aa_peekfloat#(aa,ptr,offset)
- Return bi_if(aa_peekint(aa,ptr,offset))
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement