Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: dinosteven on December 26, 2012, 12:30:17 pm

Title: Variable locations?
Post by: dinosteven on December 26, 2012, 12:30:17 pm
I have this:
{S}^5->C
{S}/5->D
{S+1}^5->E
{S+1}/5->F
{S+2}^5->G
{S+2}/5->H
{S+3}^5->I
{S+3}/5->J
.......on until {S+7}/5->R.
There's gotta be a way to optimize this; I know the variables are in some memory location... Can someone explain how to do this?
Title: Re: Variable locations?
Post by: Runer112 on December 26, 2012, 02:03:55 pm
Hold onto your pants.

Code: [Select]
°S→A
8
While 1
End!If Select(-1,Select({+S},*2/10Store())^5Store())

Lbl Store
→{A-2→A}ʳ
Return

If speed is important and you want to avoid the /10 B_CALL and doing both a divide and a modulus operation:

Code: [Select]
°S→A
8
While 1
End!If Select(-1,{+S}-(Select(/5,Store())*5)Store())

Lbl Store
→{A-2→A}ʳ
Return


EDIT: I do hope these actually work; I didn't test them.

EDIT 2: Now I did test them, fixed a small issue with the second one and now they both work.
Title: Re: Variable locations?
Post by: dinosteven on December 26, 2012, 04:11:48 pm
How are you using "Select()" and "Store()"? I don't understand...
Title: Re: Variable locations?
Post by: Runer112 on December 26, 2012, 06:34:32 pm
Select(EXPR1,EXPR2) is an optimized way (only 2 bytes!) of saving the value of EXPR1, then evaluating EXPR2, then restoring the value of EXPR1. The first Select(-1,blah) decrements one from the loop counter, which goes from 3 to 0, and then saves it while we do the actual work. The next Select({+S},blah) adds the loop counter to S, reads the value at that memory location, and saves it; this is so we can use it for the ^5 later, while we can also use it for *2/10 now. Each call to the Store() command stores the 2-byte value before it to the previous letter variable (starting with S/R), and because of how we ordered our calls to it, we store the value divided by 5 first to the later letter variable, and then the value modulo 5 second to the letter variable right before it.
Title: Re: Variable locations?
Post by: dinosteven on December 27, 2012, 08:06:35 am
Ok... didn't know you could create commands like that! Is the -1 a negative sign or a minus sign?
I used a minus sign (probably wrong); and when compiling, Axe 1.1.2 gave me "ERROR: WRONG # OF ARGS" and proceeded to crash. (This has been a recurring problem with my Axe; upon finding compile errors, it screws up my calc.)
Title: Re: Variable locations?
Post by: Hayleia on December 27, 2012, 08:49:35 am
Yes, it is a minus sign, like in 1-1=0. About your error, are you sure you put the "," after the "-1" ?
Title: Re: Variable locations?
Post by: dinosteven on December 27, 2012, 06:30:54 pm
Ok. I did it again, but something's not right. With a Data(18,24,16,9,6,8,15,19) - locations on a 5x5 grid, I extracted that from appvar to S to the variables.
But only the second one (24) is correct, and it looks like (it's an amalgam of sprites on top of each other) everything else is on 6 and 18.
Title: Re: Variable locations?
Post by: Runer112 on December 27, 2012, 08:10:00 pm
It seems to work fine when I run it; given Data(18,24,16,9,6,8,15,19)→S, I get:


Are you sure you copied the code correctly? I can understand copying it incorrectly because the code is a little strange.
Title: Re: Variable locations?
Post by: leafy on December 27, 2012, 08:17:35 pm
In addition, it'd be nice if you posted your sprite drawing code so we can make sure something's not off there.
Title: Re: Variable locations?
Post by: dinosteven on December 27, 2012, 08:30:28 pm
Yeah, should've got a camera... Anyways, I had the second one copied; I tried Runner's 1st code and it worked. Thanks for the help!
Title: Re: Variable locations?
Post by: Runer112 on December 27, 2012, 08:37:54 pm
My bad, I had a parenthesis issue with the second one. That's one of the reasons why I'm still not happy that Axe allows you to leave parentheses unclosed like TI-BASIC, otherwise it would have thrown an error and I would have caught it more easily.
Title: Re: Variable locations?
Post by: dinosteven on December 29, 2012, 02:04:27 pm
Ok, I have another thing I need to optimize. (idk why I named the topic var locations, the solution had nothing to do with that, and it really is just for optimizations that I can't do)
Code: [Select]
Pt-On(C*9+1,D*9+1,Pic1)
Pt-On(E*9+1,F*9+1,Pic1)
Pt-On(G*9+1,H*9+1,Pic2)
Pt-On(I*9+1,J*9+1,Pic2)
Pt-On(K*9+1,L*9+1,Pic3)
Pt-On(M*9+1,N*9+1,Pic3)
Pt-On(O*9+1,P*9+1,Pic4)
Pt-On(Q*9+1,R*9+1,Pic4)
I defined Pic1-Pic4 like this:
[stuff]->Pic1
[stuff]
[stuff]->Pic2
[stuff]
[stuff]->Pic3
[stuff]
[stuff]->Pic4
[stuff]