Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: GreenFreak on July 03, 2011, 11:11:33 am

Title: Zeros(36)->{L1}
Post by: GreenFreak on July 03, 2011, 11:11:33 am
Hi!  :D

I've another problem: I store my data in L1
I tried to store zeros in it:
Code: [Select]
Zeros(36)->{L1}but it only stores zero in {L1+0}, but not in {L1+1}, {L1+2}, ... , {L1+36} :-\
My walkaround is:
Code: [Select]
For(X,0,36)
0->{L1+X}
End

Question: is there a better solution??

Thanks for your help!  ;)
Title: Re: Zeros(36)->{L1}
Post by: FinaleTI on July 03, 2011, 11:25:40 am
Fill() should work. If I'm not mistaken, this would be the correct code:
Code: [Select]
Fill(0->{L1},36)
Title: Re: Zeros(36)->{L1}
Post by: jnesselr on July 03, 2011, 11:30:22 am
Code: [Select]
0->{L1}
Fill(L1,35)
That should work.  It may be 36, though, I'm not to sure on that.  I'm pretty sure it's 35, though.

Zeros(36) stores 36 bytes of zero in the program and then whatever you store it to is a pointer to that.  So Zeros(36)->A would cause A to point to the first byte of that section of 36 zeros in your program.
Title: Re: Zeros(36)->{L1}
Post by: GreenFreak on July 03, 2011, 11:39:09 am
Aaaahh!
Thanks for the very fast answer ;)
Code: [Select]
0->{L1}
Fill(L1,35)
works fine ;)
Title: Re: Zeros(36)->{L1}
Post by: Runer112 on July 03, 2011, 11:51:54 am
I know I've been majorly ninja'd and you already have a working solution, but I'll post this anyways. I tried to go a lot more in depth of explaining how objects and data work in Axe, and how to properly manipulate them.



An important thing to remember about Axe is that the only data type it directly operates on is a 16-bit integer. In languages like TI-BASIC, something like :"HELLO" actually makes the last entry that string. However, in Axe, :"HELLO" will make the last entry a pointer to that string, which is stored inside of your program. This is because it cannot fit the whole string into its 16-bit data type, so it instead stores a 16-bit reference that tells where the real string is stored.


This means a few things. Most importantly for you, it means that Zeros(36)→{L₁} isn't actually storing the 36-byte object to {L₁}, it's storing a pointer to the object to {L₁}. And because there is no 2-byte r modifier after the closing brace, it's actually only storing the low byte (8 bits) of the pointer to {L₁}. But this is relatively unimportant, since either 8 or 16 bits of the pointer is not what you want.


Because using to store objects doesn't cut it, we want to use some commands specific to blocks of data. If you wanted to put a block of data at L₁, you would first need to define the data in your program. Then, you can move that data from your program to L₁ using the Copy() command. This is found under MATH ► CPX ► 1. Here is how you would create 36 bytes of zeros in your program and then move them to L₁:

Code: (Data copying method) [Select]
Zeros(36)→GDB0Z      .Add 36 bytes of zeros to the program and store a pointer to it in GDB0Z
Copy(GDB0Z,L₁,36)    .Copy 36 bytes of data starting at GDB0Z to L1


In most circumstances when you want to move data to an external location, the code above is the way to go. However, when you want to fill a location with one value, there's a slightly better way to go: the Fill() command. This is found under LIST ► OPS ► 4.You feed this a pointer and a size, and then it copies the byte pointed to ahead [size] times. Take note that because it copies the already existing byte [size] times, you'll be left with [size]+1 bytes. So as graphmastur posted, you would want to do this:

Code: (Data filling method) [Select]
0→{L₁}         .Give the fill a seed value of 0 to copy forwards
Fill(L₁,35)    .Copy the value pointed to by L₁ (which is 0) ahead for 35 bytes


Finally, the optimized code! :evillaugh: It uses some tricks that I've picked up from extensive experience with Axe and is 2 bytes smaller and a tiny bit faster. You don't need to know these tricks, but after enough practice with Axe you may pick up such tricks on your own.

Code: (Optimized data filling method) [Select]
and 0→{L₁}ʳ    .Give the fill a seed value of 0 to copy forwards
Fill(L₁,35)    .Copy the value pointed to by L₁ (which is 0) ahead for 35 bytes
Title: Re: Zeros(36)->{L1}
Post by: GreenFreak on July 03, 2011, 12:27:33 pm
wow...
thats a text  :D
Thanks a lot for the explanation! ;)
Title: Re: Zeros(36)->{L1}
Post by: GreenFreak on July 03, 2011, 12:36:51 pm
Can I store 8-bit data and 16-bit data both in {L1}?
My sprite x/y coordinates are stored as 8-bit numbers (because 16-bit aren't necessary for that^^) and I what to store the score in {L1+37}, but as a 16-bit number... ( {L1+37^r} )
is that possible?
I would say yes, or isn't that possible?
Title: Re: Zeros(36)->{L1}
Post by: Ashbad on July 03, 2011, 12:40:27 pm
Can I store 8-bit data and 16-bit data both in {L1}?
My sprite x/y coordinates are stored as 8-bit numbers (because 16-bit aren't necessary for that^^) and I what to store the score in {L1+37}, but as a 16-bit number... ( {L1+37^r} )
is that possible?
I would say yes, or isn't that possible?

Yes, you store 8 bit data by doing 0->{L1}, 16 bit little endian by doing 0->{L1}r.

Also, please don't double post, just edit your first post to include the contents of your last post.
Title: Re: Zeros(36)->{L1}
Post by: Darl181 on July 03, 2011, 12:40:48 pm
I can't help but wonder why storing to two bytes is smaller than storing to one byte (as in, 0→{L1}r being smaller than 0→{L1} ).  Is it because it doesn't have to limit or something?
Title: Re: Zeros(36)->{L1}
Post by: Ashbad on July 03, 2011, 12:43:45 pm
Well, I think it is due to having to only parse the expression that determines the place in memory to be pointed to, and then do a ld (place),hl since hl is the primary expression register for axe; I bet that for 8 bit storing it has to add an extra ld a,l and then do a ld (place),a.
Title: Re: Zeros(36)->{L1}
Post by: Deep Toaster on July 03, 2011, 12:46:32 pm
Code: (Optimized data filling method) [Select]
and 0→{L₁}ʳ    .Give the fill a seed value of 0 to copy forwards
Fill(L₁,35)    .Copy the value pointed to by L₁ (which is 0) ahead for 35 bytes

What's and for? O.O

EDIT: Whoa, loading 0 to L ... brilliant.

Can I store 8-bit data and 16-bit data both in {L1}?
My sprite x/y coordinates are stored as 8-bit numbers (because 16-bit aren't necessary for that^^) and I what to store the score in {L1+37}, but as a 16-bit number... ( {L1+37^r} )
is that possible?
I would say yes, or isn't that possible?

Of course, data is what you make of it. Even when you store something in {L₁+37}ʳ as 16 bits you can take it out the lower eight bits with {L₁+37}. If the value is less than 256, {L₁+37}ʳ and {L₁+37} are the same thing (just slightly more optimized to do it the first way).

But if you have the room, you don't need to keep x- and y-values as 8 bits. If you're dealing with constant pointers (something like {L₁+2} as opposed to {B+L₁}), it's faster and smaller to just use the full 16-bits. That's because when Axe gets an 8-bit value it extends it to 16 bits anyway, because all math operations are done in 16 bits.

EDIT2: Ninja'd.

I can't help but wonder why storing to two bytes is smaller than storing to one byte (as in, 0→{L1}r being smaller than 0→{L1} ).  Is it because it doesn't have to limit or something?

It's because when you load an 8-bit value from a constant pointer, Axe actually loads 16 bits, then masks off the higher eight. It's the most optimized way to load eight bits, but slower and more bloated than just loading the full sixteen bits.

Note that this doesn't apply to non-constant pointers. At all.
Title: Re: Zeros(36)->{L1}
Post by: GreenFreak on July 03, 2011, 12:48:09 pm
What does that mean?

EDIT: ok! thanks everyone! ;)

EDIT2: sorry... one last question :D should I store everything as 16-bit, because it's faster?
Title: Re: Zeros(36)->{L1}
Post by: Deep Toaster on July 03, 2011, 12:49:03 pm
What does that mean?

Which (at whose explanation)?
Title: Re: Zeros(36)->{L1}
Post by: GreenFreak on July 03, 2011, 01:31:00 pm
I added in my game everywhere the ^r..
but I did a mistake and I don't know where..

My problem is, that I don't want to publish the code  :-X
Is there something, that I could have done wrong? (except forgetting one ^r)

I need your help :P again ;D
Title: Re: Zeros(36)->{L1}
Post by: Darl181 on July 03, 2011, 02:11:56 pm
Could we have a screenie so we can better tell what's going wrong with this?
Does it freeze, does something display at the wrong place, etc.
Title: Re: Zeros(36)->{L1}
Post by: GreenFreak on July 03, 2011, 02:26:17 pm
I don't know how to create a screenie...
It doesn't freeze, but it does strange things (the main sprite)
Title: Re: Zeros(36)->{L1}
Post by: Darl181 on July 03, 2011, 02:29:55 pm
You make a screenie by making a rom (if you don't have one) with something like rom8x and using wabbitemu (backspace) but that's kind of a long process...

Anyway...
What's the line of code that displays the pic?  Do you happen to be using any of the flipping or rotating commands?
Title: Re: Zeros(36)->{L1}
Post by: GreenFreak on July 03, 2011, 02:37:26 pm
Anyway...
What's the line of code that displays the pic?  Do you happen to be using any of the flipping or rotating commands?

yeah.. I'm using one flipH( ...
Could that be the problem?!  ???
I think it's the comparision or the "and".. because everything was working fine before...
Title: Re: Zeros(36)->{L1}
Post by: Darl181 on July 03, 2011, 02:41:58 pm
Sometimes the flipping commands are broken...I'm assuming it's displaying an 8*8 bunch of random garbage instead of a sprite.

try this: put +8 at the end of the line where the flipH() is (but inside the parenthesis, like flipH(Pic1+8) ) and if that doesn't work, try -8
If that fixes it, it's just another temporary axe bug :P
Title: Re: Zeros(36)->{L1}
Post by: GreenFreak on July 03, 2011, 02:46:54 pm
no no...
The sprite is okay... but not how it moves...
I found one problem while trying to find the problem...
I think, I could post the code, of the menu, which don't work properly...
Wait a moment..

Code: [Select]
removed
It's just the menu...
It's the actual state...
And i must go now..
see you tomorrow..
Thanks for your help!  ;)
Title: Re: Zeros(36)->{L1}
Post by: GreenFreak on July 03, 2011, 03:35:12 pm
I noticed that, if I leave out the ^r in the code above, everything works properly... But I don't know why...

I'm sorry, but I can't edit posts with my mobile.
Title: Re: Zeros(36)->{L1}
Post by: calc84maniac on July 04, 2011, 12:10:26 am
16-bit variables take 2 bytes, so you shouldn't store two such variables 1 byte apart.
Title: Re: Zeros(36)->{L1}
Post by: GreenFreak on July 04, 2011, 08:24:01 am
ok.. that makes sense  ;D

ok it works, but I now have to fix that in my whole code :-/

Thank you for finding the issue ;)