Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: MGOS on October 30, 2011, 07:28:39 am

Title: Some questions: Toggle button, Buffers, Appvars
Post by: MGOS on October 30, 2011, 07:28:39 am
Planning my new project I'm going to make in axe, I came across some questions about how to do stuff in axe (V 1.0.5)

1. How can you make it that a variable toggles from 0 to 1 and vice versa if you press a special key, but it doesn't keep toggling when you hold it?
It shouldn't influence the other getkeys for movement, etc. in the same loop.

2. Is it possible to display two buffers on top of each other (or / xor) without having greyscale?

3. Is there a short way of letting to user chose from a bunch of saved files (appvars) to reload or chose the file to save the data, without having that many If-statements?
Title: Re: Some questions: Toggle button, Buffers, Appvars
Post by: Xeda112358 on October 30, 2011, 08:46:08 am
1. How can you make it that a variable toggles from 0 to 1 and vice versa if you press a special key, but it doesn't keep toggling when you hold it?
It shouldn't influence the other getkeys for movement, etc. in the same loop.
What I would do is something like this:
Code: [Select]
0→D
Repeat getKey(15)
getKey(9)→C
!If C
0→D
End
If C+D=1
1→D
End
....
End
I am not sure if this will work, but you should be able to use D to get the Enter key. It should only return 1 when you press it, but if you keep holding it, you should get 0.
*I have not tested this and I have almost no experience with Axe, so backup your data before using this code!
EDIT: Here is my attempt at further analysing my code XD Don't try this at home, kids O.O
Code: [Select]
0→D
Repeat getKey(15)
getKey(9)→C
C*D+C and 1→D
....
End

EDIT2:And even more O.O
Code: [Select]
0→D
Repeat getKey(15)
getKey(9)→C
C and D or C and 1→D
....
End
I think is the fastest method and smallest, but I am not sure...
Title: Re: Some questions: Toggle button, Buffers, Appvars
Post by: MGOS on October 30, 2011, 09:07:38 am
Thanks Xeda for your attempt solving my problem, but I think it isn't exactly that what I'm looking for.

I will explain what I need:
Let's say D is our toggle variable (at the beginning 0), and Enter the key.
So if I press Enter, D toggles to 1.
If I hold down the button, nothing should happen.
If I release the button, nothing should happen.
If I press Enter again, D toggles back to 0.
If I hold down the button, nothing should happen.
If I release the button again, nothing should happen.

Edit:
This is the way I do not want it:
Code: [Select]
0->D
Repeat getkey(15)
If getkey(9)
  If D
    0->D
  Else
    1->D
  End
End
...
End
Title: Re: Some questions: Toggle button, Buffers, Appvars
Post by: jacobly on October 30, 2011, 03:41:03 pm
The easiest way would be to use another variable.
Code: [Select]
0➔D+1➔E .this stores 0 to D and 1 to E
Repeat getKey(15)
 If getKey(9) and E
  D xor 1➔D .this toggles D
  0➔E
 Else
  1➔E
 End
...
End
Title: Re: Some questions: Toggle button, Buffers, Appvars
Post by: MGOS on October 30, 2011, 05:27:12 pm
Thanks jacobly. I will try that out.

Has someone any idea to solve the other problems?
Title: Re: Some questions: Toggle button, Buffers, Appvars
Post by: FinaleTI on October 30, 2011, 05:35:27 pm
Perhaps this might:
Code: [Select]
Repeat getKey(15)
  getKey➔C
  If C=9
    D xor 1➔D
  End
End
getKey➔Var uses the same kind of getKey as BASIC, meaning only the arrows and DEL repeat, so D shouldn't toggle if ENTER is held, though I haven't actually tested this code yet.
Title: Re: Some questions: Toggle button, Buffers, Appvars
Post by: MGOS on October 30, 2011, 05:43:03 pm
Ok, but then I cannot use the other keys the same time, right?
Title: Re: Some questions: Toggle button, Buffers, Appvars
Post by: chattahippie on October 30, 2011, 05:52:33 pm
2. Is it possible to display two buffers on top of each other (or / xor) without having greyscale?

Code: [Select]
For(Y,0,63)
For(X,0,95)
If pxl-test(X,Y)^r
Pxl-On(X,Y)      // Pxl-On for or, Pxl-Change for xor
End
End
End

This is slow, but it gets the task done
Title: Re: Some questions: Toggle button, Buffers, Appvars
Post by: jacobly on October 30, 2011, 06:19:24 pm
Code: [Select]
For(A,L₃,L₃+767)
 {A} or {A−L₃+L₆}➔{A}
End

This is much faster!
Edit: even faster!
Title: Re: Some questions: Toggle button, Buffers, Appvars
Post by: MGOS on October 30, 2011, 06:29:47 pm
Thanks a lot, jacobly! - I think that is fast enough, and you can use arbitary buffers too.
Title: Re: Some questions: Toggle button, Buffers, Appvars
Post by: LincolnB on October 30, 2011, 06:52:11 pm
3. Is there a short way of letting to user chose from a bunch of saved files (appvars) to reload or chose the file to save the data, without having that many If-statements?

You have two options - you can either use Memkit to get the names of all the appvars in memory, and then display them as a scrolling list, and have the user choose between them, or you can use or write a custom input function, like the one in Firefall, that one's pretty good.
Title: Re: Some questions: Toggle button, Buffers, Appvars
Post by: ztrumpet on October 30, 2011, 07:22:41 pm
Code: [Select]
For(A,L?,L?+767)
 {A} or {A?L?+L?}?{A}
End

This is much faster!
Edit: even faster!
I believe this would do it even faster:
http://ourl.ca/4050/123594
Title: Re: Some questions: Toggle button, Buffers, Appvars
Post by: MGOS on October 31, 2011, 05:05:08 am
[...] I calculated that the following loop runs about 40 times per second at 6MHz:

Code: [Select]
Repeat getKey(15)
For(A,0,383)
.That ﹢ symbol is the 16-bit OR operator
{A*2+L₆}ʳ﹢{A*2+L₃}ʳ→{A*2+L₆}ʳ
End
C+1→C
End

Yeah, I will try that.

3. Is there a short way of letting to user chose from a bunch of saved files (appvars) to reload or chose the file to save the data, without having that many If-statements?

You have two options - you can either use Memkit to get the names of all the appvars in memory, and then display them as a scrolling list, and have the user choose between them, or you can use or write a custom input function, like the one in Firefall, that one's pretty good.
I think I'm going to make a custom menu with limited amout of Appvars - that's enough for the beginning - maybe I canm fix that later if Axe has new features to do that more easily.

Thanks a lot, guys!
Title: Re: Some questions: Toggle button, Buffers, Appvars
Post by: Quigibo on November 04, 2011, 08:17:58 am
1. jacobly's solution is what I would do too.

2. You can do it even faster with the new speed loop: ;D
Code: [Select]
L₆
For(383)
 {➔A}ʳ﹢{A+L₃-L₆}ʳ➔{A}ʳ+1
End

3. If your saved data takes a standard form like "appvSAVE1", "appvSAVE2", "appvSAVE3", etc.  Then you can construct the first part of the string in some memory by doing copy("appvSAVE0",L1,7) and then make the string the Nth file by doing N+'0'➔{L1+5}.  Now all you have to do to load the file is just GetCalc(L1) which uses the string you just constructed.  If you want to list all the appvars on the calculator that start with your custom header and choose from those, you'll have to use memkit.
Title: Re: Some questions: Toggle button, Buffers, Appvars
Post by: MGOS on November 04, 2011, 08:48:01 am
1. jacobly's solution is what I would do too.
I did that and it works quite good.


Quote from: Quigibo
2. You can do it even faster with the new speed loop: ;D
Code: [Select]
L₆
For(383)
 {➔A}ʳ﹢{A+L₃-L₆}ʳ➔{A}ʳ+2
End
I just realized that there is this cool new loop. It might be useful for something, but for my problem I found another way avoiding drawing two buffers over each other.


Quote from: Quigibo
3. If your saved data takes a standard form like "appvSAVE1", "appvSAVE2", "appvSAVE3", etc.  Then you can construct the first part of the string in some memory by doing copy("appvSAVE0",L1,7) and then make the string the Nth file by doing N+'0'➔{L1+5}.  Now all you have to do to load the file is just GetCalc(L1) which uses the string you just constructed.  If you want to list all the appvars on the calculator that start with your custom header and choose from those, you'll have to use memkit.
Due to the big program size I reached I think it's better to use a simple way, so I will just have some default save files the user can choose from. But still thanks Quigibo.
Title: Re: Some questions: Toggle button, Buffers, Appvars
Post by: aeTIos on November 04, 2011, 09:31:09 am
Wait, does for(number) loop (number) times? O.o
I haven't read the 1.0.5 documentation yet :/
Title: Re: Some questions: Toggle button, Buffers, Appvars
Post by: parserp on November 04, 2011, 09:32:46 am
the for( loops in 1.0.5 are just like in BASIC- except for the incrament
is that what you mean?
Title: Re: Some questions: Toggle button, Buffers, Appvars
Post by: aeTIos on November 04, 2011, 09:34:42 am
no. Quigibo posted for(383):[ code ]:End
Title: Re: Some questions: Toggle button, Buffers, Appvars
Post by: MGOS on November 04, 2011, 10:01:46 am
Yeah, for(number) loops (number) times. But (number) has to be a constant.
Title: Re: Some questions: Toggle button, Buffers, Appvars
Post by: aeTIos on November 04, 2011, 10:02:25 am
Yeah, you mean you cant use for(A):...:end
Title: Re: Some questions: Toggle button, Buffers, Appvars
Post by: MGOS on November 04, 2011, 11:19:41 am
Yeah, you mean you cant use for(A):...:end
I'm not sure, but I think you cannot do that.
Title: Re: Some questions: Toggle button, Buffers, Appvars
Post by: Quigibo on November 04, 2011, 03:52:07 pm
By the way, I had to make a correction to the buffer xoring routine earlier.  The value returned after storing a 2 byte number to an address is the address plus one.  So only one a +1 is required to get to the next byte.

I cannot make the repeater loop (one argument for loop) work with a variable.  The reason is that the registers that are used as counters in the loop change depending on the the number of times to loop for maximum optimization.  If you don't know the value ahead of time, the parser can't know which method to use, and you end up forcing a more unoptimized one to account for this.  Also, you wouldn't be able to bring in a value into the loop, like in my example, unless I add some extra code to it.  Lastly, the format of the loop counter's register is NOT the same as the number of loops that need to be made.  I would have to include code to convert the value into the right format.  This is done at compile time for constants so conversions aren't needed at runtime.  Add all of these extra bytes together, and you get code that is just as big as a regular for loop.

I could add it anyway because it would still be slightly faster than a typical for loop, but you certainly lose any size optimization.