Difference between revisions of "Offscrpt"

From WikiTI
Jump to: navigation, search
(Documented important copying bug)
m
 
Line 1: Line 1:
OFFSCRPT is an appvar used by the TI-OS to run an assembly program when the calculator turns off. There is also another appvar called ONSCRPT that runs code when the calculator powers on. ONSCRPT is less stable than OFFSCRPT, and it is possible to do what ONSCRPT does using an OFFSCRPT appvar.
+
OFFSCRPT is an appvar used by the TI-OS to run an assembly program when the calculator turns off. There is also another appvar called ONSCRPT that runs code when the calculator powers on. However, ONSCRPT only triggers after turning on after APD/power loss, not a manual power off.
  
Some applications that use this appvar are:
+
Some applications that use the OFFSCRPT appvar are:
 
* CalcUtil
 
* CalcUtil
 
* DoorsCS
 
* DoorsCS
Line 7: Line 7:
 
* zStart
 
* zStart
 
* Krolypto
 
* Krolypto
These applications use a getKey hook to run something on startup (like the ONSCRPT appvar, but more stable).
+
These applications install a getKey hook with OFFSCRPT to run something on startup (like the ONSCRPT appvar, but more reliable).
  
 
To install an OFFSCRPT appvar, a program or application must create the appvar with bcall(_createappvar) and set bit 1 of (iy+33h) to indicate that an OFFSCRPT appvar is installed. To uninstall the OFFSCRPT, the OFFSCRPT appvar must be deleted or bit 1 of (iy+33h) must be reset, or both.
 
To install an OFFSCRPT appvar, a program or application must create the appvar with bcall(_createappvar) and set bit 1 of (iy+33h) to indicate that an OFFSCRPT appvar is installed. To uninstall the OFFSCRPT, the OFFSCRPT appvar must be deleted or bit 1 of (iy+33h) must be reset, or both.

Latest revision as of 11:30, 30 January 2016

OFFSCRPT is an appvar used by the TI-OS to run an assembly program when the calculator turns off. There is also another appvar called ONSCRPT that runs code when the calculator powers on. However, ONSCRPT only triggers after turning on after APD/power loss, not a manual power off.

Some applications that use the OFFSCRPT appvar are:

  • CalcUtil
  • DoorsCS
  • TI's Startup App
  • zStart
  • Krolypto

These applications install a getKey hook with OFFSCRPT to run something on startup (like the ONSCRPT appvar, but more reliable).

To install an OFFSCRPT appvar, a program or application must create the appvar with bcall(_createappvar) and set bit 1 of (iy+33h) to indicate that an OFFSCRPT appvar is installed. To uninstall the OFFSCRPT, the OFFSCRPT appvar must be deleted or bit 1 of (iy+33h) must be reset, or both.

Variable Format

Looking at the OS's implementation of these, there's an important bug to be aware of. 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.