Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: alex99 on April 20, 2013, 01:11:56 pm

Title: question for searching
Post by: alex99 on April 20, 2013, 01:11:56 pm
2. is it possible to see progs, i mean that i put (for example) a "--" at the beginning of a prog and the axe prog see it and use it??? i know that it is possible in asm but in axe???mean something like .xy to show that it is an axe prog or :DCS for a picture

can you help me ???
 
Title: Re: question for searching
Post by: Runer112 on April 20, 2013, 02:07:22 pm
I believe you want to search for all programs on the calculator that start with some certain pattern? Once you've located a program, checking for a certain pattern should be fairly straightforward: just compare the first few bytes read from the program to values/ranges you want them to be in. But the key to being able to do what you want is being able to search through the VAT, a list of all variables on the calculator, to find programs. Probably the easiest way to do this is with MemKit, an Axiom included in the Tools folder in the Axe release. How to include the Axiom and use the individual commands is explained fairly well in the readme, so I'll get right to generally how you want to use MemKit. You generally want to loop through all items in the VAT in a style like this:

Code: [Select]
Load()         .Start at beginning of VAT
While 1        .Start loop
If dim()=5     .If this VAT entry is a program
.The next line is a little hacky and will not work in versions lower than 1.2.1
.This manually sets up Y₀ to be used to access this variable
(dim()ʳʳ→{°Y₀+2}??dim()ʳ,dim()ʳ-16384)→{°Y₀}ʳ
.Here you perform whatever checks to see if the variable fits your pattern and act accordingly
End
End!If Next()  .Continue loop if there are more VAT entries to process
Title: Re: question for searching
Post by: alex99 on April 24, 2013, 02:39:48 pm
"Here you perform whatever checks to see if the variable fits your pattern and act accordingly"
sorry but actually where to locate the letters between dim()or there where the question mark is???
Title: Re: question for searching
Post by: Runer112 on April 24, 2013, 10:47:33 pm
Are you asking what those tokens are? The ʳ and ° are both found in the ANGLE menu, accessible from 2nd + APPS. And you probably knew these already, but just to be complete, dim( is accessible from 2nd + STAT + right, and Y₀ is accessible from VARS + right + 1/enter. Everything else on that line can be found directly on the keypad.

But what does the comment from the line below it have to do with it? That comment is a placeholder saying that you want to replace it with the actual logic of testing if programs match your pattern and processing them accordingly.
Title: Re: question for searching
Post by: alex99 on April 25, 2013, 12:54:42 am
no where to write my mark like fore axeparser .xy i want to makethis mark++as++ but where i have to locate it  in this code above???
Title: Re: question for searching
Post by: Runer112 on April 25, 2013, 01:03:56 am
In the code I gave, you'd replace that comment with your code to check for the pattern you want. How you check for the pattern is up to you, and depends on the pattern you want to match. For whatever pattern you're checking, you'll probably end up using multiple instances {n+Y₀} to read the nth byte (0-indexed) of the program and compare the value to the expected byte/range.
Title: Re: question for searching
Post by: alex99 on April 29, 2013, 04:38:43 am
first another question i hope you are runner 112 from cametech
i said to to you the copy problem:
Code: [Select]
:"A"→Str1
:length(Str1)→L
:If GetCalc("prgmASDF",L)→A
:Copy(Str1,A,L)
:Else
:Disp "Creation error"
:End
and that it is only copiing the d from disp...
now i made another code
Code: [Select]
:getcalc("str1"-->A
:length(A)→L
:If GetCalc("prgmASDF",L)→B
:Copy(A,B,L)
:Else
:Disp "Creation error"
:End
now is all fine it is copiing all from str1 to a prog
but there is one bug it is copiing something like pton( or dec at the end so there is one command that i don´t want to have! :mad: how can i fix this bug????
Title: Re: question for searching
Post by: TheMachine02 on April 29, 2013, 10:09:53 am
you can simply do :

Code: [Select]
getcalc("str1"-->A
length(A)→L
If GetCalc("prgmASDF",L-1)→B
Copy(A,B,L-1)
Else
Disp "Creation error"
End

the bug came from the last byte, that is not a part of the string

EDIT : oops, I corrupt data with copy(A,B,L)
Title: Re: question for searching
Post by: Runer112 on April 29, 2013, 02:00:25 pm
The first issue I see is the omitted closing parenthesis after GetCalc( on the first line. Unlike in TI-BASIC, a store operation in Axe does not automatically close all unmatched parentheses before it, so that code would really be storing the pointer to the raw string data "Str1" rather than the result of calling GetCalc("Str1"). Close your parenthesis in Axe!

The other issue is that the length() command is for finding the length of null-terminated strings of data. But OS variables that can have a variable size, including OS strings, don't use null termination to mark their size, but instead have the size stored as a 2-byte header immediately before the data. So if you have a pointer to an OS program, appvar, picture, equation, or string in the variable A, then the size of the data (not including the 2-byte size header) can be accessed with {A-2}r.'

With those two changes applied to your code, hopefully this should work:

Code: [Select]
:GetCalc("Str1")→A
:{A-2}ʳ→L
:If GetCalc("prgmASDF",L)→B
:Copy(A,B,L)
:Else
:Disp "Creation error"
:End
Title: Re: question for searching
Post by: alex99 on April 30, 2013, 04:52:15 am
the method from themachine02 is working but thanks for both answears

another question :
i want build something like xlib and i dont know how to make that it then runs when a hook is includet.i mean xlib alweas answear when there is a real( .is it possible to make something like that in axe. whenyes how ???
Title: Re: question for searching
Post by: Runer112 on April 30, 2013, 11:33:47 am
Hooks cannot be made with pure Axe. You'd need to mix in a fair amount of assembly for the hook management.
Title: Re: question for searching
Post by: Joshuasm32 on April 30, 2013, 06:16:22 pm
Axe technically is assembly.  I would add stuff like that to a new addition of axe, though, so that Axe will remain pure.
Title: Re: question for searching
Post by: Runer112 on April 30, 2013, 06:32:28 pm
Axe is not assembly, just like C is not assembly. And Axe doesn't natively support things like hooks for a couple of reasons. Hooks don't really interface with languages other than assembly well, because it's common for inputs/outputs to be in specific CPU registers, or even flags. And different hooks have different inputs/outputs, so it's not really easy to handle them all. Also, because most hooks deal with core OS functionalities, it's common that the hook needs to use OS constant definitions, which are readily available to assembly programmers, but not Axe programmers. And this one isn't a deal-breaker, but generally hooks should be fast; a slow hook can really bog down a calculator. Assembly code can be made to be far faster than Axe, and I don't want to encourage the production of bulky and slow hooks.


tl;dr Hooks are best left to assembly, in my opinion.
Title: Re: question for searching
Post by: Joshuasm32 on April 30, 2013, 06:38:54 pm
Right.  Axe compiles into ASM.
Title: Re: question for searching
Post by: DJ Omnimaga on May 02, 2013, 02:02:42 am
It compiles into bulky, slower and extremely unoptimized machine code (although far less than it used to), because it's an high-level language, it would be nearly impossible to write an Axe compiler that achieves speed and size as fast as pure ASM. It's not as bad as with C, though, because Axe was designed with Z80 processors in mind, unlike C. Don't get me started on BASIC to ASM converters.


I bet that a good Axe programmer would be able to achieve hooks with no ASM, but it would be a major PITA to code and the resulting code would be massive and considerably slower. Some languages are just not done for lower level stuff (for example, good luck erasing the OS certificate from a pure BASIC program). There is also the issue of trying to keep Axe compiler as small as possible. People don't want a 10 pages APP on their calc just to compile Axe code into machine language.

(On a side note, Runer112 is the one in charge of Axe Parser development and given his history of crazy optimizations to any ASM sources he finds, he knows very well what he's talking about.)
Title: Re: question for searching
Post by: alex99 on May 02, 2013, 08:35:23 am

(On a side note, Runer112 is the one in charge of Axe Parser development and given his history of crazy optimizations to any ASM sources he finds, he knows very well what he's talking about.)
i agree to you
but isn´t there another possibility than to laern a new big languege(maby a hex code...)
Title: Re: question for searching
Post by: mapar007 on May 02, 2013, 09:27:30 am

(On a side note, Runer112 is the one in charge of Axe Parser development and given his history of crazy optimizations to any ASM sources he finds, he knows very well what he's talking about.)
i agree to you
but isn´t there another possibility than to laern a new big languege(maby a hex code...)

Hex codes are just preassembled assembly instructions. So no, that's not going to change anything. By the way, writing hooks is a fairly complicated process involving lots and lots of options. Including that in a language like axe would be impractical and (probably) cause a significant increase in compiler size. Might as well just write asm.


On an off-topic note: No offence, but would you mind paying a little more attention to grammar and spelling? You don't have to write perfect Oxford English, but even a small effort will make your posts more pleasant to read, people will be more inclined to help you. :) Note: I'm no native speaker myself (English is my third language), so that's no excuse.
Title: Re: question for searching
Post by: DJ Omnimaga on May 02, 2013, 10:53:12 pm
On an off-topic note: No offence, but would you mind paying a little more attention to grammar and spelling?

You spelled offense wrong :trollface:
Title: Re: question for searching
Post by: mapar007 on May 03, 2013, 07:07:55 am
On an off-topic note: No offence, but would you mind paying a little more attention to grammar and spelling?

You spelled offense wrong :trollface:
British spelling :trollface:

http://grammarist.com/spelling/offence-offense/
Title: Re: question for searching
Post by: alex99 on May 04, 2013, 02:21:09 pm
okok
then i´m learning asm
@mapar007
jes miztel
:P
Title: Re: question for searching
Post by: alex99 on May 06, 2013, 11:32:12 am

i made this code:

Code: [Select]
:getcalc("str4"-->J
:getcalc("str1"-->A
:length(A)→L
:If GetCalc(J,L-1)→B
:Copy(A,B,L)
:Else
:Disp "Creation error"
:End

in string 4 the program should been stored in that str1 should been copied
but it isn´t working...Why?










Title: Re: question for searching
Post by: Hayleia on May 06, 2013, 12:50:05 pm
First of all, close your parentheses, here the program ubderstands getcalc("str1"->j) which is not what you want.
Secondly, i don't get the getcalc in the if.
Title: Re: question for searching
Post by: Streetwalrus on May 06, 2013, 12:55:10 pm
Secondly, i don't get the getcalc in the if.
It's there so that the copy doesn't happen to a random place if the variable isn't created.
BTW the size of the variable should be L, not L-1.
Title: Re: question for searching
Post by: Hayleia on May 06, 2013, 12:56:48 pm
Secondly, i don't get the getcalc in the if.
It's there so that the copy doesn't happen to a random place if the variable isn't created.
BTW the size of the variable should be L, not L-1.
yeah i understand the if, but why is it j in that getcalc ? If that getcalc tries to create str4, what is the use of the first getcalc then ? In any case there is something weird.
Title: Re: question for searching
Post by: alex99 on May 06, 2013, 01:08:31 pm
str1 shall bestored in a prog.and the progname is standing in str4.so how i make the code???
Title: Re: question for searching
Post by: Hayleia on May 06, 2013, 01:12:55 pm
Ok then closing your parentheses should solve the problem. But now, it is the second getcalc that I don't understand. Why is the size of the program you are creating given by the size of the string in str1 ?

Edit: nvm understood. Close all the parentheses and you should be ok
Title: Re: question for searching
Post by: alex99 on May 06, 2013, 01:16:24 pm
sorry but how i´m closing it?i´m anew programmer..
the code whith lenth of str1 is fro calc84maniac and not from me so i don´t know..
Title: Re: Axe Programming
Post by: alex99 on May 06, 2013, 01:24:05 pm
how do i close this parethese ???
Code: [Select]
::getcalc("str4")-->J
:getcalc("str1")-->A
:length(A)→L
:If GetCalc(J,L-1)→B
:Copy(A,B,L)
:Else
:Disp "Creation error"
:End

 ??? ??? ???
Title: Re: Axe Programming
Post by: alex99 on May 06, 2013, 02:03:04 pm
checked my code 3 times doesn´t work :(
Title: Re: Axe Programming
Post by: Hayleia on May 06, 2013, 02:03:30 pm
how do i close this parethese ???
Code: [Select]
::getcalc("str4")-->J
:getcalc("str1")-->A
:length(A)→L
:If GetCalc(J,L-1)→B
:Copy(A,B,L)
:Else
:Disp "Creation error"
:End

 ??? ??? ???
Yeah, like that.
Title: Re: Axe Programming
Post by: alex99 on May 06, 2013, 02:04:16 pm
look at my last post:do you  mabey know another code???
Title: Re: Axe Programming
Post by: Hayleia on May 06, 2013, 02:06:06 pm
Avoid double posting within 6 hours. Use the edit button instead.
What exactly do you have in Str4 ? Dou you have just "PROGNAME" in it or do you have "prgmPROGNAME" (where PROGNAME is the name of your program) ?
Title: Re: Axe Programming
Post by: Streetwalrus on May 06, 2013, 02:22:16 pm
You should do :
If GetCalc("Str1")->A
.The two bytes preceding the pointer are the size of the variable
{A-2}^^r->L
If GetCalc("Str4",L)->B
Copy(A,B,L)
Else
Disp "Creation error"
End
Else
Disp "Str1 does not exist"
End

This will copy Str1 to Str4, overwriting the previous content of Str4.
And note that ^^r is the small radian r in the angle menu.
Title: Re: Axe Programming
Post by: Darl181 on May 06, 2013, 02:24:13 pm
Just did a little test program.

.TEST

"BLARG"→Str1
.Str1 is data to be copied

"prgmSTORE"→Str2
.Str2 is program to be searched for

GetCalc(Str2)→P
.P is pointer

!If P
Disp "Error"
Return
.handle error etc
End

Length(Str1)→A
Copy(Str1,P,A)


If the program is 10 bytes when you first made it, it should look something like this when viewed in the editor:
(http://clrhome.org/homer/PROGRAM%3ASTORE%D6%3ABLARG%3F%3F%3F%3F%3F%D6%3A%D6.gif)
Title: Re: Axe Programming
Post by: alex99 on May 06, 2013, 02:24:34 pm
it shall copy to a prog and not to a string
Title: Re: Axe Programming
Post by: Streetwalrus on May 06, 2013, 02:26:58 pm
Oh then just replace "StrX" with "prgmWHATEVER".
Title: Re: Axe Programming
Post by: Hayleia on May 06, 2013, 02:27:17 pm
it shall copy to a prog and not to a string
Well his program copied to a program, not a string. But it didn't copy to a program whose name was in an external string.
Title: Re: Axe Programming
Post by: Runer112 on May 06, 2013, 03:15:28 pm
As far as I can understand, you want to create a program with the name stored in the OS variable Str4 and the contents stored in the OS variable Str1? If so, here's what I've come up with. I made two different versions: one is larger and allows you to handle each error that could occur individually, while the other is smaller and doesn't support error handling (errors are still caught and avoided, they just cannot be acted upon). The source for both versions is included as text below and as programs attached at the bottom of this post.


With error handling:
Code: [Select]
!If GetCalc("Str1")→S
 .Str1 not found
Else
 !If GetCalc("Str4")→N
  .Str4 not found
 Else
  .L₁ can be replaced with any section of safe RAM at least 9 bytes large
  'prgm'→{L₁}ʳ
  Fill(L₁+1,8)
  Copy(N,L₁+1,{N-2}ʳ)
  !If GetCalc(L₁,{S-2}ʳ→L)→P
   .Creation error
  Else
   Copy(S,P,L)
  End
 End
End

Without error handling:
Code: [Select]
If GetCalc("Str4")→N
 .L₁ can be replaced with any section of safe RAM at least 9 bytes large
 'prgm'→{L₁}ʳ
 Fill(L₁+1,8)
 Copy(N,L₁+1,{N-2}ʳ)
 If GetCalc("Str1")→S
  Copy(S,GetCalc(L₁,{S-2}ʳ→L),L)
 End
End