I want to add syntax highlighting to TI-basic using hooks, I would like to write the hook in ASM using Beck's on-calc assembler. I want example code and noob friendly documentation.
What type hook are you planning to use to accomplish this? There's a number of different types of hooks which TI-OS supports, which are triggered by different events. There's probably a few different hooks you could hijack for this purpose, but given that there's no specific "highlighting hook" you'll have to get a little creative. A good source of documentation for each individual type of hook is at WikiTI, under both the TI-83 Plus and TI-84 Plus CE / 83 PCE sections. Basically all TI-83 Plus hooks will still work and should work the same as documented, but if you encounter any unexpected behavior feel free to ask!

Writing a hook will consist of two parts - the code to install the hook and the code of the hook. The code of the hook should be stored in as safe of a location as possible - the best location is an app, but that's might be outside of the scope of what BASM can do. Because of this, your next best option is storing the hook code in an AppVar file in the archive of the calculator.

The reason you do not want the hook code to be in RAM is because data in RAM frequently moves around. When installing a hook, TI-OS is given a pointer in memory to jump to whenever the hook is triggered, and if your code has moved away from that pointer, it will jump to whatever random stuff is now stored at that location instead, likely causing the calculator to crash. To ensure that the AppVar is in archive when the hook is installed, it's a good practice to do a check in your installation code which will prevent it from installing if the AppVar is in RAM. You can also add to the code to archive it if it is in RAM, but you will need to locate the file's data pointer again with ChkFindSym afterwards since it has changed location.

For the installer, you'll want to create a separate program from the hook AppVar. Starting your code with this line will tell BASM to assemble it into a program file.

Code:
FORMAT ASM "INSTALL"

After this, you'll want to include the ti84pceg include file. You can do that with this:

Code:
INCLUDE "TI84PCEG" TI.

There's some more complicated stuff which would go into properly chaining your hook (in case other hooks of the same type as yours is installed), but I'm not going to go into that for this.

Next, you'll want to locate your hook AppVar to check if it is in archive or not. Add the following data to the end of your program:

Code:
APPVARNAME:
DB TI.APPVAROBJ,"HOOK",0 // Or replace HOOK with whatever the name of your AppVar is

Now, back after the include line, add this (anything after '//' is a comment and can just be ignored):

Code:
MAIN:
LD HL,APPVARNAME
CALL TI.MOV9TOOP1  // Load the AppVar name (pointed to by HL) into OP1
CALL TI.CHKFINDSYM // Detect the information of the file whose name is currently in OP1
RET C              // If the file isn't found, exit the installer
CALL TI.CHKINRAM
RET Z              // Return if the file is in RAM
LD HL,12
ADD HL,DE          // Add 12 to the data pointer (stored in DE after ChkFindSym) to make it point to the name length byte
LD A,C
LD BC,0
LD C,A
ADD HL,BC          // Add to make DE point to the actual start of data
JP TI.<whatever the call is associated with setting the type of hook you plan on using>

All in all, your code should look like this:

Code:
FORMAT ASM "PROGRAM"
INCLUDE "TI84PCEG" TI.
MAIN:
LD HL,APPVARNAME
CALL TI.MOV9TOOP1
CALL TI.CHKFINDSYM
RET C
CALL TI.CHKINRAM
RET Z
LD HL,12
ADD HL,DE
LD A,C
LD BC,0
LD C,A
ADD HL,BC
JP TI.<whatever the call is associated with setting the type of hook you plan on using>
APPVARNAME:
DB TI.APPVAROBJ,"HOOK",0

Provided that I didn't make a dumb mistake or forget how BASM works, this should be the simplest way for you to install a hook (with a few safety features).

Now for the hook itself! You'll want to make a separate program for this, and at the top make sure BASM will assemble it to an AppVar with this line:

Code:
FORMAT APPVAR ARCHIVED "HOOK"

You should also use the same include line as before.
The only difference between a hook and a regular assembly program is that the hook code must start with the hex byte $83. Your total hook code should look like this:

Code:
FORMAT APPVAR ARCHIVED "HOOK"
INCLUDE "TI84PCEG" TI.
MAIN:
DB |EX83 // Where |E is the scientific notation E. |EX is how BASM signifies hex
// Put whatever code you want in your hook here
RET

Hopefully this helps!
Thx, to answer your question I want token hook so to I can display for example a blue version of the “disp“ token or a red version of the “if” token for example

Edit: how do I get this character "|" on my CE
Edit 2: When I assemble the program I get this error:
(begin error message)
Number format Error
"▪▪▪▪▪μh≤"
Error on line 4


LD HL,ICEHOOKS
(end error message)
note: I'm using icehooks as a pre built test appvar, that might be the problem
Quote:
|E is the scientific notation E
I'm using ICEHOOKS as the test app var and I keep getting an error please help. Also I want token hook so to I can display for example a blue version of the “disp(“ token or a red version of the “if” token. Thank to anyone who can help.
It's probably safer to use your own AppVar (just leave the hook code section empty for now) than use a different AppVar. I think the issue is that APPVARNAME is the name of the label with the data (at the end of the program) and should stay whatever that label is called.

To change the name of the AppVar you're using, change this line:

Code:
DB TI.APPVAROBJ,"HOOK",0

And to change the name of the AppVar you make with BASM change this one in the second source program:

Code:
FORMAT APPVAR ARCHIVED "HOOK"
thx i'll try it when I get the chance.

Edit: I get this error when I try to assemble the appvar:
(begin error message)
Undefined word/label
"EX83"
(end error message)

Edit: is this the proper way to use token hook

Code:
FORMAT APPVAR ARCHIVED "HOOK"
INCLUDE "TI84PCEG" TI.
MAIN:
DB EX83
HL EF //EF is the HEX code for the "disp" token
HL 7,"Display"
RET
You need to use the scientific notation E, not the letter E.
I have changed it to scientific notation E

Code:
FORMAT APPVAR ARCHIVED "HOOK"
INCLUDE "TI84PCEG" TI.
MAIN:
DB |EX83
HL EF //EF is the HEX code for the "disp" token
HL 7,"Display" //"Display" is what I want to replace the "disp" token
RET

now I have this error:
(begin error message)
Undefined word/label
"HL EF"
Error on line 4


HL EF
(end error message)
Edit: also how do I change the color of the displayed string using token hook
Edit: please help
  
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