Today on SAX, the ONSCRIPT and OFFSCRIPT functions in the z80 and ez80 calculators' TI-OS were being discussed. For the uninitiated, these respectively contain code that is copied to (appData + 1) (that is, $8001 on the z80 calculators) and executed when the calculator is turning on after APD, or turning off. They're commonly used for things like automatically launching programs or Apps when the calculator is turned on. The discussion today revealed a few things that should be recorded for posterity:
  • As long-known, ONSCRIPT is unreliable. Specifically, it only triggered after an APD poweroff, not a 2nd-OFF (user) poweroff. MateoConLechuga indicated that this is because the OS checks the apdWarm flag before launching an ONSCRRIPT
  • OFFSCRPTs + RawKeyHooks are usually used to simulate ONSCRIPTs, including in Doors CS/CSE/CE. An OFFSCRPT installs a single-use RawKeyHook that fires when the calculator is turned on again. The hook uninstalls itself, then launches the program or App or performs the task the programmer desired.

Anything else you guys wish to add to this?
Looking at the OS's implementation of these, there's an important bug that doesn't seem to be accurately documented anywhere. When reading the size header of the appvar to know how many bytes to copy, the pointer is never actually incremented past the second byte of the size. So the correct number of bytes are copied to appData, but the bytes copied start one byte before the actual appvar data. So the first byte copied and executed is the high size byte, and the last byte of the appvar isn't copied at all.

For those creating an ONSCRPT or OFFSCRPT variable, this means a couple things:
  • Use an origin of appData+1.
  • Add an extra byte at the end.
  • Be aware that if your variable is larger than 255 bytes, besides the expected problems of running past the end of appData and into other RAM areas, the first byte executed will no longer be a nop. Plan accordingly.
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