Just a few functions to allow the PICAXE to use a makeshift 2 dimensional array. I could only find scraps of code so developed this for those who want it.
The array is stored in the scratchpad and has variable length so be carefull when using it along side put/get/etc.
The array is stored in the scratchpad and has variable length so be carefull when using it along side put/get/etc.
Code:
SYMBOL x=b0 'x location to insert/remove value
SYMBOL y=b1 'y location to insert/remove value
SYMBOL arrayData=b2 'data to insert/data removed/data grabed
SYMBOL temp2=b3 'internal use (use if you want)
SYMBOL width=10 'the width of the array
SYMBOL temp1=w2 'internal use (use if you want)
SYMBOl length=w3 'length of the array
insert: 'overwrite block x,y
temp1=width*y
temp1=temp1+x
put temp1,arrayData
return
grab: 'get block x,y
temp1=width*y
temp1=temp1+x
get temp1,arrayData
return
append: 'add to end
temp1=length+1
put length,arrayData
inc length
return
push: 'add to start
for temp1=length to 0 step -1
get temp1,temp2
temp1=temp1+1
put temp1,temp2
temp1=temp1-1
next temp1
put 0,arrayData
inc length
return
pop: 'remove (+return) fisrt block
get 0,arraydata
for temp1=0 to length
temp1=temp1+1
get temp1,temp2
temp1=temp1-1
put temp1,temp2
next temp1
dec length
return
remove: 'remove (+return) block at x,y
temp1=width*y
temp1=temp1+x
get temp1,arrayData
for temp1=temp1 to length
temp1=temp1+1
get temp1,temp2
temp1=temp1-1
put temp1,temp2
next temp1
dec length
return
delete: 'delete (+return) last block
temp1=length-1
get temp1,arrayData
put temp1,0
dec length
return