So if somebody needs to create a list using
IF ... END IF or using random numbers, the preprocessor objects (like symbols or
match) can not be used for that task.
I wrote a small list-analogon for that.
MAX_NUMBER = 999'999'999'999'999'999
RndNum = %t AND 0xFFFF'FFFF
macro GetNewRandomNumber
{
RndNum = ((RndNum*214013+2531011) AND 0xFFFF'FFFF)
}
macro displayDecNum num* ; useful for debugging
{
dN1= num MOD 10
dN2= ((num-dN1)/10) MOD 10
dN3= ((num-dN1-dN2)/100) MOD 10
dN4= ((num-dN1-dN2-dN3)/1'000) MOD 10
dN5= ((num-dN1-dN2-dN3-dN4)/10'000) MOD 10
dN6= ((num-dN1-dN2-dN3-dN4-dN5)/100'000) MOD 10
dN7= ((num-dN1-dN2-dN3-dN4-dN5-dN6)/1'000'000) MOD 10
dN8= ((num-dN1-dN2-dN3-dN4-dN5-dN6-dN7)/10'000'000) MOD 10
dN9= ((num-dN1-dN2-dN3-dN4-dN5-dN6-dN7-dN8)/100'000'000) MOD 10
dN10=((num-dN1-dN2-dN3-dN4-dN5-dN6-dN7-dN8-dN9)/1'000'000'000) MOD 10
dN11=((num-dN1-dN2-dN3-dN4-dN5-dN6-dN7-dN8-dN9-dN10)/10'000'000'000) MOD 10
dN12=((num-dN1-dN2-dN3-dN4-dN5-dN6-dN7-dN8-dN9-dN10-dN11)/100'000'000'000) MOD 10
dN13=((num-dN1-dN2-dN3-dN4-dN5-dN6-dN7-dN8-dN9-dN10-dN11-dN12)/1'000'000'000'000) MOD 10
dN14=((num-dN1-dN2-dN3-dN4-dN5-dN6-dN7-dN8-dN9-dN10-dN11-dN12-dN13)/10'000'000'000'000) MOD 10
dN15=((num-dN1-dN2-dN3-dN4-dN5-dN6-dN7-dN8-dN9-dN10-dN11-dN12-dN13-dN14)/100'000'000'000'000) MOD 10
dN16=((num-dN1-dN2-dN3-dN4-dN5-dN6-dN7-dN8-dN9-dN10-dN11-dN12-dN13-dN14-dN15)/1'000'000'000'000'000) MOD 10
dN17=((num-dN1-dN2-dN3-dN4-dN5-dN6-dN7-dN8-dN9-dN10-dN11-dN12-dN13-dN14-dN15-dN16)/10'000'000'000'000'000) MOD 10
dN18=((num-dN1-dN2-dN3-dN4-dN5-dN6-dN7-dN8-dN9-dN10-dN11-dN12-dN13-dN14-dN15-dN16-dN17)/100'000'000'000'000'000) MOD 10
display dN18+'0',dN17+'0',dN16+'0',dN15+'0',dN14+'0',dN13+'0',dN12+'0',dN11+'0',dN10+'0',dN9+'0',dN8+'0',dN7+'0',dN6+'0',dN5+'0',dN4+'0',dN3+'0',dN2+'0',dN1+'0',13,10
}
macro displayList list*
{
display '0: '
displayDecNum list#0
display '1: '
displayDecNum list#1
display '2: '
displayDecNum list#2
display '3: '
displayDecNum list#3
display '4: '
displayDecNum list#4
display '5: '
displayDecNum list#5
display '6: '
displayDecNum list#6
display '7: '
displayDecNum list#7
display '8: '
displayDecNum list#8
display '9: '
displayDecNum list#9
}
macro appendToList list*, element*
{ ; Starts at 1, but should start at 0
if list#0<(MAX_NUMBER/1'000)
list#0=(list#0*1'000)+element
else if list#1<(MAX_NUMBER/1'000)
list#1=(list#1*1'000)+element
else if list#2<(MAX_NUMBER/1'000)
list#2=(list#2*1'000)+element
else if list#3<(MAX_NUMBER/1'000)
list#3=(list#3*1'000)+element
else if list#4<(MAX_NUMBER/1'000)
list#4=(list#4*1'000)+element
else if list#5<(MAX_NUMBER/1'000)
list#5=(list#5*1'000)+element
else if list#6<(MAX_NUMBER/1'000)
list#6=(list#6*1'000)+element
else if list#7<(MAX_NUMBER/1'000)
list#7=(list#7*1'000)+element
else if list#8<(MAX_NUMBER/1'000)
list#8=(list#8*1'000)+element
else if list#9<(MAX_NUMBER/1'000)
list#9=(list#9*1'000)+element
else
display "Too much elements added",13,10," for one list"
err
; 10*6+1=61 entries
end if
}
getListSizeRV = 0
macro getListSize list*
{
multiplicator=0
number=list#0
if list#9>0
multiplicator=9
number=list#9
else if list#8>0
multiplicator=8
number=list#8
else if list#7>0
multiplicator=7
number=list#7
else if list#6>0
multiplicator=6
number=list#6
else if list#5>0
multiplicator=5
number=list#5
else if list#4>0
multiplicator=4
number=list#4
else if list#3>0
multiplicator=3
number=list#3
else if list#2>0
multiplicator=2
number=list#2
else if list#1>0
multiplicator=1
number=list#1
end if
addend = 0
while number>0
addend=addend+1
number=number/1000
end while
getListSizeRV=(multiplicator*6+addend)
}
getItemRV=0
macro getItem list*, index*
{
; gives elements in a special order: starting from list#0[5]...list#0[0] -> list#1[5]...list#2[0]
getListSize list
number=0
if index<getListSizeRV
if (index/(9*6))>0
number=list#9
else if (index/(8*6))>0
number=list#8
else if (index/(7*6))>0
number=list#7
else if (index/(6*6))>0
number=list#6
else if (index/(5*6))>0
number=list#5
else if (index/(4*6))>0
number=list#4
else if (index/(3*6))>0
number=list#3
else if (index/(2*6))>0
number=list#2
else if (index/(1*6))>0
number=list#1
else
number=list#0
end if
newindex=index MOD 6
while newindex>0
number=number/1000
newindex=newindex-1
end while
getItemRV=number MOD 1000
else
display 'Tried to access an element',13,10,'that doesnt exist'
err
end if
}
macro getRandomItem list*
{
getListSize list
GetNewRandomNumber
RndElement = (RndNum SHR 16) MOD getListSizeRV
getItem list, RndElement
}
macro CreateEmptyList list*
{
list#0 = 0
list#1 = 0
list#2 = 0
list#3 = 0
list#4 = 0
list#5 = 0
list#6 = 0
list#7 = 0
list#8 = 0
list#9 = 0
}
CreateEmptyList TestList
appendToList TestList, 17
appendToList TestList, 42
getListSize TestList
displayDecNum getListSizeRV
getItem TestList, 1
displayDecNum getItemRV
Each list can save 60 byte-values. Just some small workaround. Can be expanded to more elements, the datatype can be changed, the code can be decreased (with macros), ...