Author Topic: Axe Parser  (Read 495009 times)

0 Members and 1 Guest are viewing this topic.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55942
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Axe Parser
« Reply #1500 on: November 15, 2010, 12:45:45 am »
Here's the description from the commands list:

inData(BYTE,PTR)
Key: inString()
   
Searches for the byte in the zero-terminated data. If found, it returns the position it was found in (starting at 1). If not found, 0 is returned.

The first argument accepts a byte value. Because Axe variables and math functions return two-byte values, this means that the high byte will be discarded. This argument essentially accepts whatever you enter mod 256.

The second argument accepts a pointer to data. In this data should be a series of byte values which will be stepped through one by one and checked to see if they are equal to the first argument (mod 256). The end of the data is signified by a zero so the search doesn't continue infinitely. For this reason, zero has to be reserved for the terminator and cannot be a value you want to compare.



Breaking down a more specific example, like: If inData(A+1,Data(2,7,17,0))

In the first argument, A represents whatever 0-based number, say an item ID, that you want to check. However, because 0 is reserved for the terminator of the data, we add 1 to it to shift all the item IDs to essentially be 1-based.

The second argument isn't really data itself. The data is defined somewhere in the bottom of the program, and this argument is instead given the value of a pointer to that data. As noted earlier, this data that is pointed to should be a list of nonzero byte values to check if the first argument is equal with, and the data should be terminated with a 0. Because 1 was added to our first argument to account for the fact that 0 is reserved for the terminator, 1 would also be added to the values we want to compare against. In this case, I wanted to compare against the values 1, 6, and 16, which turn into 2, 7, and 17 when 1 is added to them.

Finally, when the routine is run, the data is stepped through byte by byte, checking to see if a byte from the data equals the first argument (mod 256). Let's say we wanted to check if a selected item was a consumable potion, and item IDs 1, 6, and 16 were the potions present in our game. If the selected item ID (A) was 16, this value would be increased by 1, giving 17 for the first argument. This would then be checked to see if it equals 2, 7, or 17, which are the item IDs of the potions all plus 1. It doesn't equal 2 or 7, but it does equal 16. The routine would return the position of the match value, in this case 3, because the third element matched. For our purposes, all we really needed to know is whether or not a match was present, but inData() returning the match position works for this. Any match position returned will be greater than or equal to 1, which will make our IF statement true. If the item ID were 5, it wouldn't match any of the three values in our list. Once the routine hit a zero byte, it would know the searching was done and return a 0 for no match, making our IF statement false.


I hope this helps clarify things a bit :)
Ah ok, I was mostly confused at the InData(A+1,Data(1,2,3,4,0)) part. So we need to manually offset the Data stuff by 1 except the last 0?
Now active at https://discord.gg/cuZcfcF (CodeWalrus server)

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Axe Parser
« Reply #1501 on: November 15, 2010, 01:01:07 am »
If you're checking a 0-based value, you need to add 1 to everything (except the null terminator). You could alternatively just use a 1-based value instead and not have to worry about this.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55942
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Axe Parser
« Reply #1502 on: November 15, 2010, 03:02:58 am »
Yeah, I think if I ever do a RPG, I'll just use 1-based value for empty item slots and stuff. It will solve most problems. I'll just need to fill those slots with 1 instead of 0 when starting a new game.

I think in Illusiat 13, empty item slot is 20 :P. For some reasons, the engine won't support 0.
« Last Edit: November 15, 2010, 03:03:38 am by DJ Omnimaga »
Now active at https://discord.gg/cuZcfcF (CodeWalrus server)

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Axe Parser
« Reply #1503 on: November 15, 2010, 03:45:13 pm »
I think in Illusiat 13, empty item slot is 20 :P. For some reasons, the engine won't support 0.
I believe it was because you did a SortA() on the item list and wanted the blank items to be in the middle. :)

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55942
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Axe Parser
« Reply #1504 on: November 15, 2010, 10:17:20 pm »
Oh right, I remember now! I wanted empty item slots after useable items and key items at the very bottom of the list.
Now active at https://discord.gg/cuZcfcF (CodeWalrus server)

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Axe Parser
« Reply #1505 on: November 15, 2010, 11:21:53 pm »
This isn't a bug and doesn't need to be urgently fixed or anything, so I'm posting it here instead of in the Bug Reports thread. But this always bugs the OCD side of me when I see it. The p_Rand function in the Commands.inc is classified under the Input section with p_GetKey and p_DKey. Perhaps move it to Advanced Math or something similar? :P

Offline Michael_Lee

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1019
  • Rating: +124/-9
    • View Profile
Re: Axe Parser
« Reply #1506 on: November 17, 2010, 03:12:11 pm »
Is there a way to switch the buffer and the back-buffer?  It looks like Axe comes with the ability to copy one to the other, not exchange.
My website: Currently boring.

Projects:
Axe Interpreter
   > Core: Done
   > Memory: Need write code to add constants.
   > Graphics: Rewritten.  Needs to integrate sprites with constants.
   > IO: GetKey done.  Need to add mostly homescreen IO stuff.
Croquette:
   > Stomping bugs
   > Internet version: On hold until I can make my website less boring/broken.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55942
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Axe Parser
« Reply #1507 on: November 17, 2010, 03:13:27 pm »
Does Exch(L3,L6,768) works? L3 is the back-buffer and L6 the main buffer.
« Last Edit: November 17, 2010, 03:13:41 pm by DJ Omnimaga »
Now active at https://discord.gg/cuZcfcF (CodeWalrus server)

Offline Michael_Lee

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1019
  • Rating: +124/-9
    • View Profile
Re: Axe Parser
« Reply #1508 on: November 17, 2010, 03:15:04 pm »
Sweet.  I didn't know that.  It should work, thanks.

Quick question - do I have to add brackets to anything, or will it work just as written?
My website: Currently boring.

Projects:
Axe Interpreter
   > Core: Done
   > Memory: Need write code to add constants.
   > Graphics: Rewritten.  Needs to integrate sprites with constants.
   > IO: GetKey done.  Need to add mostly homescreen IO stuff.
Croquette:
   > Stomping bugs
   > Internet version: On hold until I can make my website less boring/broken.

Offline nemo

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1203
  • Rating: +95/-11
    • View Profile
Re: Axe Parser
« Reply #1509 on: November 17, 2010, 03:31:22 pm »
Sweet.  I didn't know that.  It should work, thanks.

Quick question - do I have to add brackets to anything, or will it work just as written?

for Exch(L3,L6,768)? that'll work as written. don't add brackets around L3 or L6.


Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55942
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Axe Parser
« Reply #1510 on: November 17, 2010, 03:44:49 pm »
I wonder if stuff like {L1+5->{L1+6 will work like {L1+5}->{L1+6 and {L1+5}->{L1+6}? I remember some topics about this before, but I totally forgot.
« Last Edit: November 17, 2010, 03:45:23 pm by DJ Omnimaga »
Now active at https://discord.gg/cuZcfcF (CodeWalrus server)

Offline nemo

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1203
  • Rating: +95/-11
    • View Profile
Re: Axe Parser
« Reply #1511 on: November 17, 2010, 03:48:18 pm »
i think {L1+5->{L1+6 would evaluate to {L1+5->{L1+6}} which ultimately put the address of L1+5 into the byte at L1+6, however, because L1+5 is not a value between 0-255, L1+5^256 would be stored in L1+6.


Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55942
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Axe Parser
« Reply #1512 on: November 17, 2010, 03:50:12 pm »
Ah ok, thanks for the info. :)

I wonder if this is documented? That might be something to add in tutorials or Axe doc in the future otherwise.
Now active at https://discord.gg/cuZcfcF (CodeWalrus server)

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Axe Parser
« Reply #1513 on: November 17, 2010, 05:57:57 pm »
If I were Quigibo and I were to add something to the documentation about this, I would add a note stressing that, although leaving off ending parentheses/brackets often works, the practice is best avoided. There are multiple reasons for this:
  • Unlike in TI-BASIC, the few extra bytes saved in your source file from open parentheses and brackets will have no positive effect, whether it be size or speed, on the compiled program.
  • Omitting closing parentheses or brackets can have a negative effect by causing expressions to evaluate in unexpected ways, which certainly would not be fun to debug.
  • Omitting closing parenthesis and brackets can cause compiling errors.
  • Code that is properly parenthesized is easier to understand and looks cleaner.
« Last Edit: November 22, 2010, 02:30:14 pm by Runer112 »

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: Axe Parser
« Reply #1514 on: November 17, 2010, 06:12:53 pm »
The main thing to remember is the unlike TI-Basic, the STO symbol does not automatically close all previous parentheses. Instead, the value inside the parentheses is what gets stored.
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman