You can help CodeWalrus stay online by donating here. | New CodeWalrus | Old (dark mode) | Old (light) | Discord server

Some super crappy Axe code...

b/Calculator Talk Started by p2, August 24, 2016, 11:41:43 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

u/p2 August 29, 2016, 09:06:12 PM
whatfor should I even want to have a 7byte hex var? xD
gonna try it but dont see wheee to use it ^^
Last Edit: August 29, 2016, 09:09:18 PM by p2
u/E37 August 29, 2016, 09:15:26 PM
Oh... and another thing... Endiness... I you have no clue what that is then consider yourself lucky...
Suffice it to say that {L1}r+256 is the same thing as {L1+1}+1
and {L1}+512 is the same as {L1+1}+2 and so on...
Don't ever use this trick if you want you code to be readable (and I am pretty sure Axe does it for you during compile anyway)

I meant above that you could:
:[0000000000000000]->pic1
:[FFFFFFFFFFFFFF]
:pt-on(0,,Pic1+5)
The only time you are going to have variables other that 1 or 2 bytes is 9-byte floating point (that is what the OS uses)
you can use float{var} to use it. (again, I've never used it for anything useful)
Last Edit: August 29, 2016, 09:19:18 PM by E37
u/p2 August 30, 2016, 07:40:43 AM
Quote from: E37 on August 29, 2016, 09:15:26 PMOh... and another thing... Endiness... I you have no clue what that is then consider yourself lucky...
@E37: I must be super lucky as this makes almost no sense to me...  :thumbsup:

Quote from: E37 on August 29, 2016, 09:15:26 PMSuffice it to say that {L1}r+256 is the same thing as {L1+1}+1
and {L1}+512 is the same as {L1+1}+2 and so on...
Don't ever use this trick if you want you code to be readable (and I am pretty sure Axe does it for you during compile anyway)
{L1}r+256 == {L1+1}+1
Okeyy and you're sure you didn't mean this?:
{L1+256}^r == {L1+1}^r
It still wouldn't make that super much sense but at least it would look like valid Axe code to me then... ([axe] L₁: 768 bytes (saveSScreen) <----no 256)
what's the effect of adding a +... after the {...}^r and how comes {L1}r+256 (obviously 2 bytes) coule ever be the same as {L1+1}+1 since this got no ^r to mark it as two bytes ???








{L1}Adress of first byte (number 0) "in" L1 (I know L1 is just a fix position in memory but I'll stick to the "in L1")
{L1+5}Adress of Byte number 5 in L1
{L1}^r Adres of byte number 0 in L1 again but this tyme marked as 2Byte (no difference in storage since I could also rut a 50byte thing there and it'd just overwrite the following bytes but huge one in reading ince it returns 2 bytes not just 1)
{L1}+1Maybe Adress of Byte number 0 but marked as 2 bytes? (same as ^r)
{L1}+5Maybe Adress of Byte number 0 but marked as 6 bytes?
{L1}+256Maybe Adress of Byte number 0 but marked as 2 bytes? (max length for a single thing maybe 256byte so it takes like modulo(256) or something?)
At all the stuff marked in red I'm just guessing now, didn't even know until just now you could write stuff that way ^^
But I guess that's not what it means anyways? ^^



By the way, would this work? (using 8.8 for everything)

BdirY=1*0.05+0.97*BmovY->BmovY

isntead of:
If BdirY=1:1.02:Else:0.97:End:*BmovY->BmovY



And if I use this:
L1->°BposX
15.123->BposX
{L1}^r->A
{L1}->B
{L1+1}->C

then the results should be:
BposX = 15.123
A = 0000 1111 0111 1011 = 3963
B = 0000 1111 = 15
C = 0111 1011 = 123
But is there any way to create a new custom named var with only 1 byte?
i need B very often but always typing {L1} or {L1+4} or whatever is annoying...
Can I somehow modify L1->BPosXEinByte so it really only returns one byte ?
what I want is something like this:
L1->°BposX
???->°BPosXEinByte
15.123->BposX
12->BPosXEinByte
//now BposX should be "12.123"
18.3->BposX
//now BPosXEinByte should be "18"

Last Edit: August 30, 2016, 08:10:20 AM by p2
u/Hayleia August 30, 2016, 11:19:56 AM
Quote from: p2 on August 30, 2016, 07:40:43 AM
{L1}r+256 == {L1+1}+1
Okeyy and you're sure you didn't mean this?:
{L1+256}^r == {L1+1}^r
It still wouldn't make that super much sense but at least it would look like valid Axe code to me then... ([axe] L₁: 768 bytes (saveSScreen) <----no 256)
what's the effect of adding a +... after the {...}^r and how comes {L1}r+256 (obviously 2 bytes) coule ever be the same as {L1+1}+1 since this got no ^r to mark it as two bytes ???
No, he meant that {L1}r+256->{L1}r is the same as {L1+1}+1->{L1+1}. But it doesn't matter, write readable code only for now :P

Quote from: p2 on August 30, 2016, 07:40:43 AM







{L1}Adress of first byte (number 0) "in" L1 (I know L1 is just a fix position in memory but I'll stick to the "in L1")
{L1+5}Adress of Byte number 5 in L1
{L1}^r Adres of byte number 0 in L1 again but this tyme marked as 2Byte (no difference in storage since I could also rut a 50byte thing there and it'd just overwrite the following bytes but huge one in reading ince it returns 2 bytes not just 1)
{L1}+1Maybe Adress of Byte number 0 but marked as 2 bytes? (same as ^r)
{L1}+5Maybe Adress of Byte number 0 but marked as 6 bytes?
{L1}+256Maybe Adress of Byte number 0 but marked as 2 bytes? (max length for a single thing maybe 256byte so it takes like modulo(256) or something?)
At all the stuff marked in red I'm just guessing now, didn't even know until just now you could write stuff that way ^^
But I guess that's not what it means anyways? ^^
Most of the stuff here is false.
{Whatever} is the value that is at the address Whatever. It's a value, not an address.
Well, obviously, it can also be an address for something else, but {L1} is not the address of the first byte in L1, it's the first byte in L1. The address of the first byte in L1 is... L1.
You should be able to correct the rest.

Quote from: p2 on August 30, 2016, 07:40:43 AM
By the way, would this work? (using 8.8 for everything)

BdirY=1*0.05+0.97*BmovY->BmovY

isntead of:
If BdirY=1:1.02:Else:0.97:End:*BmovY->BmovY
Well, I don't see why it wouldn't work, but we're not in Basic, so it's actually not more efficient (most likely takes more space and is slower).
Though I understand that the line with the If is ugly and too long, so you should use "COND?EXP1,EXP2" instead.
In your exact example, it would give
BdirY=1?1.02,0.97
*BmovY->BmovY

or even in one line (BdirY=1?1.02,0.97)*BmovY->BmovY
u/p2 August 30, 2016, 12:08:42 PM
Quote from: Hayleia on August 30, 2016, 11:19:56 AM
Quote from: p2 on August 30, 2016, 07:40:43 AM
{L1}r+256 == {L1+1}+1
Okeyy and you're sure you didn't mean this?:
{L1+256}^r == {L1+1}^r
It still wouldn't make that super much sense but at least it would look like valid Axe code to me then... ([axe] L₁: 768 bytes (saveSScreen) <----no 256)
what's the effect of adding a +... after the {...}^r and how comes {L1}r+256 (obviously 2 bytes) coule ever be the same as {L1+1}+1 since this got no ^r to mark it as two bytes ???
No, he meant that {L1}r+256->{L1}r is the same as {L1+1}+1->{L1+1}. But it doesn't matter, write readable code only for now :P
okey ^^ +256 is too much (1 byte) so it's moved to the next one... just like when doing 0+10 results in a 0, too (but a 1 in the next place)

Command         {L1}    {L1+1}       
0 -> {L1}^r00
1 -> {L1}^r10
20 -> {L1}^r200
255 -> {L1}^r2550
256 -> {L1}^r01
257 -> {L1}^r11
276 -> {L1}^r201
511 -> {L1}^r2551
Command         {L1}    {L1+1}
0 -> {L1}042
1 -> {L1}142
20 -> {L1}2042
255 -> {L1}25542
256 -> {L1}042
257 -> {L1}142
276 -> {L1}2042
511 -> {L1}25542
Left side: using ^rOnly because I did 42->{L1+1} before that. This means the byte is not affected.




Quote from: Hayleia on August 30, 2016, 11:19:56 AM
Quote from: p2 on August 30, 2016, 07:40:43 AM







{L1}Adress of first byte (number 0) "in" L1 (I know L1 is just a fix position in memory but I'll stick to the "in L1")
{L1+5}Adress of Byte number 5 in L1
{L1}^r Adres of byte number 0 in L1 again but this tyme marked as 2Byte (no difference in storage since I could also rut a 50byte thing there and it'd just overwrite the following bytes but huge one in reading ince it returns 2 bytes not just 1)
{L1}+1Maybe Adress of Byte number 0 but marked as 2 bytes? (same as ^r)
{L1}+5Maybe Adress of Byte number 0 but marked as 6 bytes?
{L1}+256Maybe Adress of Byte number 0 but marked as 2 bytes? (max length for a single thing maybe 256byte so it takes like modulo(256) or something?)
At all the stuff marked in red I'm just guessing now, didn't even know until just now you could write stuff that way ^^
But I guess that's not what it means anyways? ^^
Most of the stuff here is false.
{Whatever} is the value that is at the address Whatever. It's a value, not an address.
Well, obviously, it can also be an address for something else, but {L1} is not the address of the first byte in L1, it's the first byte in L1. The address of the first byte in L1 is... L1.
You should be able to correct the rest.
Ok I guess I thought the right stuff but messed up when putting it into words:
L1 is an adress, like a single stupid number. So what L1 adresses is a single byte.
But after that byte comes a field of 768 bytes that are free to use, too.
So we do {L1+1} to adress the others. Doing this, L1+1 is the adress and {L1+1} is the value of that adress.
Aaand {L1} is not the first byte in RAM since $0000 - $8000 (hex adresses) is Flash memory so the RAM begins with $8001 aaaand L1 is somewhere within it xD (dont know the adress by heart sorry).


Quote from: p2 on August 30, 2016, 07:40:43 AM... first byte (number 0) "in" L1 (I know L1 is just a fix position in memory but I'll stick to the "in L1")
And with this I ment that since this field of 768 free-to-use bytes begins with the adress L1, it'd be easier to just speak of "adresses IN L1" (ignoring that L1 is just a single adress)



Quote from: Hayleia on August 30, 2016, 11:19:56 AM
Though I understand that the line with the If is ugly and too long, so you should use "COND?EXP1,EXP2" instead.
In your exact example, it would give
BdirY=1?1.02,0.97
*BmovY->BmovY

or even in one line (BdirY=1?1.02,0.97)*BmovY->BmovY
I never knew this was possible *-* Sooo much gonna use that *-* <3
u/Hayleia August 30, 2016, 01:33:13 PM
I won't quote everything, I'll just say that I don't have anything to say, everything is right :D

Quote from: p2 on August 30, 2016, 12:08:42 PM
I never knew this was possible *-* Sooo much gonna use that *-* <3
Yeah, that's awesome. Check out the Commands.html file, you can also use "?" only (without ","), and you also have "??" as a negative option. That's great when you need a quick If or If/Else in a calculation but don't want to waste 3 lines or even 5 for that ;)
u/p2 August 30, 2016, 01:45:27 PM
great :D Then it's time for some guessing again... >.>
Are those codes each the same as the line above? :)
if N= 0:5->X:End
  N??:*5->X

if N!=0:5->X:End
  N?:*5->X

if N=10: ->X:End
  (N=10?)*5->X

if N=2:5->X:Else:10->X:End
  N=2?5,10:->X

if N=2:5*A->X:Else:10*A->X:End
  (N=2?5,10)*A->X
u/Hayleia August 30, 2016, 03:07:23 PM
No for the first one. Because "N??" is equivalent to "!If N", not to "If N=0". Because N=0 puts either 1 or 0 in HL (depending on if N=0 or not, obviously), while N puts N obviously.
Second reason, the code with the If only changes the value of X when N is 0, where the second one always does (and it's not even what you expected due to the previous sentence).

Same for the second one.

I think you made a mistake on the third one so I won't answer :P

Yes and no for the fourth one. I mean that yeah, from the user's point of view, yes. But the following are more equivalent:

If N=2:5->X:Else:10->X:End
  N=2?5->X,10->X


If N=2:5:Else:10:End:->X
  N=2?5,10:->X


Same as the fourth one for the last one.

(or at least, from what I can tell, maybe I made mistakes :P)

And as a general rule, putting either "?" or "??" on a line and doing nothing of it does nothing at all (I mean, stuff like "N??:*5->X", that's just "N*5->X").
u/E37 August 30, 2016, 06:35:43 PM
A couple things:
First, you don't need the : in most cases. you can simply do X?*5->X since the ? ends the statement.
I'll try to go over all the ways to do and and or statements. Ill bring in to account the size, speed and problems with the statement.
With all of them I am going to take into account the worst case for them. (slowest and largest)
But first... a little math. Pause 1 takes up 3349 cycles. Pause 1800 is about a second in slow speed mode. 3349*1800=6028200 cycles a second. Just to give you an idea when I talk about speed.


1. " and " and " or "
Speed: 33 cycles - that's pretty quick.
Size: up to 7 bytes - not to bad.
Pitfalls: it only compares the lower byte of each argument. That means if number mod 256 is 0, it will treat it as 0. Only use if you are sure if this won't matter or if neither of the arguments can exceed 255.

2. "*" and "+"
Speed (for "*"): It can get up to 800 cycles - by far the slowest!
Speed (for "+"): It can get up to 32 cycles - not too bad.
Size: up to 5 bytes for "+" and 7 for "*" not bad.
Pitfalls: It has a chance that the math operations can wrap around and =0. It's not very likely though.

3. "?" and "??"
Speed: 18 cycles - that's screaming fast!
Size: always 5 bytes - that's really small!
Pitfalls: None really. Just watch the short circuiting as it can cause a headache if you forget it!
Note: since it is a short circuit operator, it has a chance to increase speed even more - even a large amount!

4. plot style tokens
Speed: 45 cycles - not the fastest.
Size: up to 10 bytes - pretty small!
Pitfalls: They can be hard to differentiate, "That's 'or' right... no, its 'and'!"
Notes: It functions the same way as " or " and " and" but doesn't have the >255 problem.

5. nested 'If" statements
Speed: who cares?
Size: does it matter?
Pitfalls/notes: ... just no. Don't do it. Any coder who tries to read your code where you made a separate 'If' for each and and calls the same routine for each 'or', will HATE you (and you probably won't be able to read it anyway) That kind of code is for assembly! NOT Axe!

That is all of the ways I can think of. Read over all of them and decide which is best for yourself.
Last Edit: August 30, 2016, 06:39:21 PM by E37
u/Hayleia August 31, 2016, 06:44:52 AM
Quote from: E37 on August 30, 2016, 06:35:43 PM
5. nested 'If" statements
Speed: who cares?
Size: does it matter?
Pitfalls/notes: ... just no. Don't do it. Any coder who tries to read your code where you made a separate 'If' for each and and calls the same routine for each 'or', will HATE you (and you probably won't be able to read it anyway) That kind of code is for assembly! NOT Axe!
(Note however that he only says this isn't good in the case where you're using them as "operators" for 'and'/'or' operations, but if you're doing "real code", using Ifs and stuff is perfectly ok).

(And lol, I actually used some of these "ugly" Ifs in Smash, and I agree it's stupid but I "had to" since my conditions were too long to be readable on one line only (and they were all "ands") :P).
u/p2 August 31, 2016, 08:19:32 AM
Quote from: E37 on August 30, 2016, 06:35:43 PM
First, you don't need the : in most cases. you can simply do X?*5->X since the ? ends the statement.
Then it's like this:
A=B?5->A,10->A
now using HL for it, too:
A=B?5,10:->A
but how about multiple expressions? Will this be accepted? And fo I have to put an "End" then or is it just not possible uing the "?" stuff?
A=B?5->A:10->B,10->A:5->B
u/Hayleia August 31, 2016, 09:11:35 AM
Quote from: p2 on August 31, 2016, 08:19:32 AM
Then it's like this:
A=B?5->A,10->A
now using HL for it, too:
A=B?5,10:->A
Yes, that works. If you want just one optimization here though, you may want to use "-" and "??" rather than "=" and "?", giving this:
A-B??5,10:->A
Notice though that this is only possible here since you don't care about the value of HL after the "?" or "??" (you immediately replace it with 5 or 10), but "A-B??" and "A=B?" don't "return" the same thing at all.

Quote from: p2 on August 31, 2016, 08:19:32 AM
but how about multiple expressions? Will this be accepted? And fo I have to put an "End" then or is it just not possible uing the "?" stuff?
A=B?5->A:10->B,10->A:5->B
No, that's not possible this way. There are stupid ways to make it possible sometimes, like putting a "useless" Select (such as "A=B?Select(5->A,10->B),Select(10->A,5->B)", which quickly becomes ugly as soon as you have more than 2 expressions on one side of the ","), or having luck (I think for example that 5->Br1->A does put 5 in B and r1 in A even without a newline, but that wouldn't work if you replaced r1 with C since it would read "BC" as one variable name), but otherwise this kind of stuff isn't supposed to be possible.
u/E37 August 31, 2016, 02:52:15 PM
You think more than one line of conditionals is bad? For one of my games I wrote an entire subroutine on one line using ?? And ? !
You can chain statements though like:
A-B??1->A:7->B,0->A->B
That is perfectly legal to do.
u/Hayleia August 31, 2016, 03:02:51 PM
The problem isn't that it's bad, it's less readable :P
I have this exactly in Smash:

{r1+°PX}^^r/64->X
{r1+°PY}^^r/64->Y
{r1+°Character}^^r->VCharacter
./collision
{{{r1+°State}^^r+°StateSprite+{r1+°Direction}}^^r+VCharacter->r4}*8->r2/4->r5
{r4+1}->r4
If Y>={r3+r6+2}^^r
If {r1+°OldPY}^^r/64<={r3+r6+2}^^r
If X+r5>={r3+r6+0}^^r
If W+{r3+r6+0}^^r>=(X-r5)
{r3+r6+2}^^r*64Select(,->{r1+°PY}^^r)->{r1+°OldPY}^^r
If r6
{r3+8}^^r*64->{r1+°GroundSpeedX}^^r
{r3+10}^^r*64->{r1+°GroundSpeedY}^^r
End
1->{r1+°OnTheGround}
End
End
End
End
If Y-r4>{r3+r6+2}^^r
If {r1+°OldPY}^^r/64-r4<{r3+r6+2}^^r
If X<={r3+r6+0}^^r
If X+r2>=({r3+r6+0}^^r-8)
If {r3-1} and °LeftLedge!=0
{VCharacter+°LedgeState}^^r+VCharacter
sub(ChangeState)
°DirRight->{r1+°Direction}
{r3+r6+0}^^r-({{{r1+°State}^^r+°StateSprite+{r1+°Direction}}^^r+VCharacter->r4}*8->r2/2)*64->{r1+°PX}^^r
{r3+r6+2}^^r+({r4+1}->r4)*64->{r1+°PY}^^r
1->{r1+°OnTheGround} ./sert à reinitialiser les jumps
End
End
End
End
End
If Y-r4>{r3+r6+2}^^r
If {r1+°OldPY}^^r/64-r4<{r3+r6+2}^^r
If X>=({r3+r6+0}^^r+W)
If X-r2<=({r3+r6+0}^^r+W+8)
If {r3-1} and °RightLedge!=0
{VCharacter+°LedgeState}^^r+VCharacter
sub(ChangeState)
°DirLeft->{r1+°Direction}
{r3+r6+0}^^r+({{{r1+°State}^^r+°StateSprite+{r1+°Direction}}^^r+VCharacter->r4}*8->r2/2)+W*64->{r1+°PX}^^r
{r3+r6+2}^^r+({r4+1}->r4)*64->{r1+°PY}^^r
1->{r1+°OnTheGround} ./sert à reinitialiser les jumps
End
End
End
End
End

And this allows me to read very quickly each component of the detection.

But otherwise, when I don't care about readability, I'm not afraid of long lines at all. I wrote that line in a TI-Concours line of code :P
   Pt-Change(Select(,+(*~1+Xp*(abs()>°MaxC*2-1)//256+{r3+4}^^r+RandPM128()min(max(,~°MaxV)^^r,°MaxV)^^r->r4->{r3+4}^^r)r4+{r3}^^r(??+1)->{r3}^^r)/256, and 0,°Hrt,{r3+2}^^rSelect(,+(*~1+Yp+(31*256)*(abs()>°MaxC*2-1)//256+{r3+6}^^r+RandPM128()min(max(,~°MaxV)^^r,°MaxV)^^r->r4->{r3+6}^^r)r4+{r3+2}^^r->{r3+2}^^r)/256+(*2)*2*2+A)
And yes it works, and you see it uses "?"-like statements :P
u/Dream of Omnimaga August 31, 2016, 05:29:32 PM
That last line reminds me Javascript O.O. Even Z80 ASM looks more readable lol. That said, CE Textlib could get really confusing too because it's all numbers XD
Website statistics


MyCalcs | Ticalc.org | Cemetech | Omnimaga | TI-Basic Developer | MaxCoderz | TI-Story | Casiocalc.org | Casiopeia | The Museum of HP Calculators | HPCalc.org | CnCalc.org | Music 2000 Community | TI Education | Casio Education | HP Calcs | NumWorks | SwissMicros | Sharp Calculators
Powered by EzPortal