As I am constantly frustrated at the inaccessibility of the string manipulation commands, particularly sub(, length(, and inString( when writing TI Basic programs, I wanted to see if it was possible to modify a menu to have these commands and more. Turns out it is! I found this page on WikiTI, but I need a little help understanding the hook works and how to implement it.

I suppose I should mention that I have very limited experience writing ez80 asm.

I know I need a program to install the hook, but I don't know where to put the hook code (I've seen a deleted appvar suggested). If I am not mistaken, I can use the LDIR instruction (or maybe one of its variants) to copy the hook code from the source program to wherever it gets run from when a certain menu is opened.

I am also unsure what the hook code should look like. Should it just be one of those example tables, or do I have to write some additional code to handle when A is all those values.

As of this posting, I am currently reading other posts about hooks, hopefully I can find more info there, but I'd still appreciate any help.

Edit: I found this which adds a string menu to the vars menu, but I'd like to replace the [2nd] [vars] menu and not be dependant on Cap'n Hook (nice name btw)
pi644721 wrote:
I know I need a program to install the hook, but I don't know where to put the hook code (I've seen a deleted appvar suggested).

If you leave the program in archive and don't enable compression, you don't need to use a deleted variable, you can just have it live in the program variable. You just need to calculate the address by finding the start of the program with ChkFindSym, then adding the offset of the hook within the program.

pi644721 wrote:
If I am not mistaken, I can use the LDIR instruction (or maybe one of its variants) to copy the hook code from the source program to wherever it gets run from when a certain menu is opened.

Most existing hooks aren't copied before being run - they're written in position-independent assembly. For something relatively small like this program, it's definitely easier to write the entire thing to execute-in-place rather than writing something that copies a payload into a fixed location in RAM and then executes that.
Making assembly position-independent is somewhat tricky, but boils down to not using any absolute labels in your program. This limits you to only using jr or jp (hl), not call or the immediate form of jp to labels in your code. I forget whether any of the registers contain the address of the hook when TI-OS calls it (I want to say IX does but that might just be capnhook), but if not you can always determine the current value of pc by sticking a pop hl \ push hl \ ret at a location like scrapMem and then calling that address.

pi644721 wrote:
and not be dependant on Cap'n Hook

It's possible to install a hook in a way that uses Cap'n Hook's chaining when the library is available and falls back to installing the hook directly when it's not. I thought the example you linked included that, but taking another look at it I guess not - I'll have to make another example that does that.


For posterity, I'll also include a link that TIny_Hacker shared in the chat to a CE hook template repo that he and Roccolox wrote.
I have successfully created a menu hook with quite a lot of help from RoccoLox Programs (thank you!) from their and TIny_Hacker's template and "borrowing" most of the hook code from commandblockguy's cap'n hook example program. Here's the sourcecoder project for those interested. My only gripes are that I was unable to find the key code equates for the toString( and eval( tokens even with lots of trying random key codes. Very misleadingly, kEval does not correspond to eval(. If anyone finds those equates that'd be nice, but overall I am satisfied with the results of my foray into assembly.
Can u make it for BASM and include example code and help me here:
https://www.cemetech.net/forum/viewtopic.php?t=19834&highlight=
I also made a token hook that shortens tokens:
* "eval(" into "str("
* "expr(" into "num("
* "toString(" into "toS("
* "length(" into "len("
* "inString(" into "inS("
* " and " into " & "
* " or " into " | "
* " xor " into " ^ "
* "not(" into "!("

You can find the code in the SourceCoder project here
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement