Omnimaga
Calculator Community => TI Calculators => Axe => Topic started by: XiiDraco on September 26, 2013, 01:46:19 am
-
Ok so my code is probably very bad because even though Ive been doing this for a while, I do know much. Please correct me if im wrong or doing this wrong. Thanks! :)
Right now Im handling the X and Y values of a couple sprites in a GDB (they hold data like an array right?)
I then retrieve this data and edit it store it then later retrieve it and draw a sprite with it.
I have absolutely no problems when drawing one sprite, but when drawing 2 sprites with different X and Y data one of them will edit the first two digits of the sprite's hex code. Like when I move it right the hex code counts up by one and changes the sprite to match that.
Is this supposed to happen?
-
Can you provide the code in question?
Also, it makes me cringe a bit inside when people refer to arbitrary data in Axe as "GDB's". The GDBX tokens are just a particular set of many equally allowable symbols in named pointers to any kind of data! You can call a pointer to any type of data whatever you want, whether it be GDB1, Str1XY, Pic789, °Stuff12345, or whatever.
Note: this isn't a personal thing, I'd just be happy to see a misleading and unfortunately common misconception due to archaic Axe syntax be made less common. (maybe even eradicated eventually?)
-
Oh ok, sorry abut that.
Here it's probably not perfect but It should do what I want to do right? (Unless I did something wrong.)
.test
1->X
1->Y
Fix 5
[01]->GDB1
[01]->GDB2
1->{GDB1}
1->{GDB2}
5->{GDB1+1}
1->{GDB2+1}
Repeat getKey(15)
If getKey(1)
Y+1->Y
End
If getKey(2)
X-1->X
End
If getKey(3)
X+1->X
End
If getKey(4)
Y-1->Y
End
X->{GDB1}
Y->{GDB2}
Y->{GDB1+1}
X->{GDB2+1}
ClrDraw
{GDB1}->A
{GDB2}->B
Pt-On(A/2,B/2,[FFFFFFFFFFFFFFFF])
{GDB1+1}->A
{GDB2+1}->B
Pt-On(A/2,B/2,[FFFFFFFFFFFFFFFF])
DispGraph
End
-
Erm, I can see problems in your code. I don't know if this is what causes your problem, but you are writing in GDB1+1 which is GDB2, and you are writing in GDB2+1 which is... undefined, so it is a random place in your program or even outside of your program.
-
I see the problem in the code:
GDBs are pointers
Pointers must be the same size as the number of bytes that you want to modify/be in it because if you overextend the writing, you write to the next bytes, or in this case, the first byte of GDB2.
The fix:
[0000]->GDB1
[0000]->GDB2
EDIT: :ninja: 'd
-
OH I get it! I've been experimenting with them to try and figure out how they work. Thought I had it. <_<
Edit OH!!
EVEN more understanding! Thanks guys!
-
Using custom names for this might make your life easier, since your data is really just 1-byte variables and there's an easy way to access 1-byte variables: Nameʳ. Here's how it would look converted to use them, also with some other minor optimizations:
.TEST
1→X→Y
Fix 5
L₄→°X1+1→°Y1+1→°X2+1→°Y2
.Initialization of vars above not necessary, will be set in first loop iteration
ClrDraw
While 1
If getKey(1)
Y+1→Y
End
If getKey(2)
X-1→X
End
If getKey(3)
X+1→X
End
If getKey(4)
Y-1→Y
End
X→X1ʳ→Y2ʳ
Y→Y1ʳ→X2ʳ
Pt-On(X1ʳ/2,Y1ʳ/2,[FFFFFFFFFFFFFFFF])
Pt-On(X2ʳ/2,Y2ʳ/2,[FFFFFFFFFFFFFFFF])
DispGraphClrDraw .for speeds!
EndIf getKey(15)
-
Is there anyway to change the size of the array after you make it like.
[01020405]->GDB1
[02030302]
[04050302]
Is there any way to change the size of this after I make it?
-
Also, it makes me cringe a bit inside when people refer to arbitrary data in Axe as "GDB's". The GDBX tokens are just a particular set of many equally allowable symbols in named pointers to any kind of data! You can call a pointer to any type of data whatever you want, whether it be GDB1, Str1XY, Pic789, °Stuff12345, or whatever.
i came here expecting a discussion about graphical debuggers for axe :P (although, that might not be the worst of ideas, and it wouldn't be all that hard to make as an axiom either...)
EDIT:
Is there anyway to change the size of the array after you make it like.
[01020405]->GDB1
[02030302]
[04050302]
Is there any way to change the size of this after I make it?
no, pointers set at compile time are static.
-
Um... That didn't exactly answer what I was wondering. Yes you can change it or No you can't change it?
-
Well, "size of an array" doesn't mean anything in Axe.
When you define [060203]->GDB1, what you are doing is
[06]->GDB1
[02]->GDB1+1
[03]->GDB1+2
And since you don't define anything at GDB1+3, the program sets what it wants there. That doesn't mean you can't read what's in GDB1+3, there is a value there, it will just be a bit unpredictable. That also means that if you write in GDB1+3, your program (or your calc) will have a problem some time, but that doesn't mean you can't write there.
But as shmibs said, what you create at compile time is quite restricting. What you can do is copying your "array" in L1 (for example) and then you'll be able to "add" or "remove" bytes from your array (as long as you don't have more than 768 bytes).
-
So if I wanted to store data into an "array" then add values for individual objects for instance a new object or pixlet was created. How would I "add" another value place to the "array". Btw thanks for the help.
Also I kinda figured out reading and writing to that GDB1 + 3 value the hard way. XD woops. May have crashed a couple times. it likes to change around my sprites if I write too far.
-
I recommend that you use the free RAM areas. L1 for example, is 768 bytes. You can use it as you like.
Another solution if you need more space is to dynamically allocate user RAM with GetCalc. ;)
-
Ok, so I aready know all of this, I just don't know HOW to do it.
-
[DATA -> L1
and just use L1 to call it.
-
so like gdb1-> L1
then how would I add more? (values)
(wow this is confusing) >.<
-
just use instead of the GDB your free ram space, L1.
What i always do is using instead of the GDB a variable, that also works.
-
oh wait so use it in he same way i would use gdb?
wos thats simple.
-
the fundamental difference between "L1" and "GDB1" is that the first is a pointer to a static position in RAM that is guaranteed to be usable to any program that wants it while that program is running (this is not strictly true of the other "Ln" pointers, but it's the same basic idea) while the second is a pointer to a position within your program. when you "store a value to GDB1", axe inserts the data directly into your program somewhere at compile time and returns a pointer to its position within your program during run time. it would technically be possible to do the same with "L1", but storing data to that location at compile time would be completely useless. it would only exist on your calculator, not the calculators of anyone else who may want to run your program, and it would be overwritten on your calculator as soon as some other process decided to store data there. thus, axe ensures that "L1" can only be written to during runtime. what this means is that, in order to accomplish what you want, your data has to first be stored somewhere else (which could be inside your program, in an external appvar or program, or anywhere else on the calculator) and then copied over to the chunk of RAM starting at L1 for manipulation there.
it is also possible to write to "GDB1" during runtime. bear in mind, though, that these pointers are pointing to a spot within your program itself, meaning that, if you write to an area outside of the space allotted for data at compile time, you will end up overwriting other things, including possibly even rewriting your own code as it executes. also, if your program is being executed directly from RAM, or if you are using a shell with writeback enabled, any changes you make to your program during runtime will be permanent, meaning that the next time the user launches your program he will be left using the values generated the last time it was run.
EDIT: syntax for the Copy( command, which you can use to copy a chunk of data into the space at one of the Ln vars
Copy(BUF) token: conj() Copies the 768 byte buffer to the main buffer. Same as Copy(BUF,L6,768)
Copy(BUF1,BUF2) token: conj() Copies the 768 byte buffer BUF1 to BUF2. Same as Copy(BUF1,BUF2,768)
Copy(PTR1,PTR2,SIZE) token: conj() SIZE bytes starting from PTR1 are copied to PTR2 onwards. 0 is not a valid SIZE.
Copy(PTR1,PTR2,SIZE)r token: conj() SIZE bytes ending at PTR1 are copied to PTR2 moving backwards. 0 is not a valid SIZE.
-
[DATA -> L1
and just use L1 to call it.
We are talking about Axe. An open bracket is an open door to potential bugs and doesn't save any space in the compiled program, on ly in the source. It is only useful for people like Matref who code on a regular 83+ with not so much memory.
Other than that XiiR3CR34T10N, seems like you didn't really understand how pointer works. "GDB1->L1" seems like you somehow think that GDB1 and L1 are variables and that you actually store the content of GDB1 in L1. But the sentence I just wrote doesn't make any sence since GDB1 doesn't have any content, it is just a number. As shmibs said, to have the data "in" GDB1 to go to L1, you can use Copy. That would work for the initialisation of your "array". Then if you want to "add objects to your array", keep a variable that knows the number of elements in your "array" (you know what is its value at the beginning since you initialized the "array" yourself) and then, increment it when you "add" an element to the "array" and decrement it when you "remove" one. That variable will in fact be useful for two reasons. First, it helps you not go further than 768 bytes. It also gives you (after an easy addition) the pointer to the last element in the "array". And if you use a For loop for your code on your elements, it is not a bad idea to know where the For must end.
(offtopic, shmibs, you have 28 post ratings)
-
Yeah, I just got how this all works when Shimbs just explained it. Thanks guys!
I'm still curious as to why the AND's (?) and OR's (?) aren't working in my program... :/
-
Those are bitwise operations in Axe.
In Basic, "4 and 2" equals "non-zero and non-zero" so it equals 1.
In Axe, "4 and 2" gives "100 and 010", and if you write this down, it gives:
100
010
000
So you might have a problem with your ANDs, depending on how and where you use them. To solve it, just to "4!=0 and (2!=0)" (where != is the "not equal to" sign).
Note that OR is bitwise too, but that doesn't cause that much problems in a If.
-
That's why ? and ?? were created. These are the logical AND and OR respectively.
-
Hm, that should work, but I never used them that way. I basically use ? and ?? to put a if/else/end in one line, not to do boolean operations.
-
I also use them as a terneary operator though I should avoid it cause it's a major pita to maintain. ;)
-
Man I'f I can't figure out why ? and ?? Aren't working, I might as well just drop the contest...