Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: collechess on November 02, 2011, 07:12:48 pm

Title: Array help
Post by: collechess on November 02, 2011, 07:12:48 pm
I'm trying to learn arrays.  I read Deep Thought's tutorial and I kind of understand them, but why doesn't this work?
Code: [Select]
.ARRAY
.L=length
0->L
20->X->Y
Repeat getkey(15)
ClrDraw
If getkey(54)
sub(MS,X,Y)
End
If getkey(4)
Y-1->Y
End
If getkey(2)
X-1->X
End
If getkey(3)
X+1->X
End
If getkey(1)
Y+1->Y
End
PxlOn(X-1,Y)
PxlOn(X+1,Y)
PxlOn(X,Y-1)
PxlOn(X,Y+1)
For(H,0,L)
PxlOn({H*2+L1},{H*2+L1+1})
End
DispGraph
End
Lbl MS
r1->{L1+L*2}
r2->{L1+L*2+1}
L+1->L
Return

And when exactly do you use the {} brackets?
Title: Re: Array help
Post by: Deep Toaster on November 02, 2011, 08:23:26 pm
Remember your order of operations don't exist in Axe -- L1+L*2 is really (L1+L)*2.

Any value in braces is treated as a pointer (http://clrhome.tk/tutorials/axe/02/), the address of a particular byte in the calculator's memory. Putting braces around a pointer grabs the value of the byte at that address rather than the value of the address.
Title: Re: Array help
Post by: jacobly on November 03, 2011, 01:38:54 am
Also remember that For loops loop up to and including the value of the last parameter, meaning that if L is 0, then For(H,0,L) loops from 0 to 0, or one time. This is incorrect because if the length is zero, it should not loop at all. For(H,0,L−1) doesn't work either, because if L is 0, then it loops from 0 to -1 (or 65535), which is not good. In the end you should do something like the following:
Code: [Select]
:For(H,1,L)
:Pxl-On({H−1∗2+L₁},{H−1∗2+L₁+1})
:End
or slightly more optimized:
Code: [Select]
:For(H,1,L)
:Pxl-On({H∗2+L₁−2},{H∗2+L₁+1−2})
:End
Title: Re: Array help
Post by: leafy on November 03, 2011, 02:03:26 am
Slightly more optimized :P

Code: [Select]
:For(H,1,L)
:Pxl-On({H∗2+L₁−2->r6},{r6+1})
:End
Title: Re: Array help
Post by: Builderboy on November 03, 2011, 02:41:03 am
Even more optimized is to offset your entire array so it starts at the next byte. :D
Title: Re: Array help
Post by: jacobly on November 03, 2011, 02:15:49 pm
Well in that case...
Code: [Select]
:For(H,1,L)
:Pxl-On({H∗2+L₁−2}ʳ,/256)
:End
or even
Code: [Select]
:For(H,1,L)
:Pxl-On({H∗2+L₁−2}ʳ,Asm(6C))
:End