The <compat.h> header file


  
This header file contains a set of various pseudo-constants (i.e. macros defined to look and work as constants), dedicated to increase compatibility between TI-89 and TI-92 Plus and between AMS versions. These "constants" have different values on TI-89 and TI-92 Plus (or on AMS 1.xx and AMS 2.xx). Using these pseudo-constants you can for example program keyboard reading and graphic applications on more unique way, check AMS version and perform some AMS-dependent actions (although this is not recommended if not really necessary), etc. The following table shows all defined pseudo-constants. A lot of them are known from DoorsOS, but they are defined here to work in both "nostub" and "Doors" mode.

NameTypeMeaning
TIOS_entriesunsigned longNumber of entries in TIOS jump table: may be used for determining actual AMS version (for example, it is 972 on AMS 1.05 and 1463 on AMS 2.03)
AMS_1xxshort (Boolean)TRUE on AMS 1.xx, FALSE on AMS 2.xx
AMS_2xxshort (Boolean)TRUE on AMS 2.xx, FALSE on AMS 1.xx
ROM_basevoid *Base address of the ROM (0x200000 on TI-89, 0x400000 on TI-92 Plus)
CALCULATORshortZero on TI-89, non-zero on TI-92 Plus
TI89short (Boolean)TRUE on TI-89, FALSE on TI-92 Plus
TI92short (Boolean)TRUE on TI-92 Plus, FALSE on TI-89
LCD_WIDTHunsigned shortWidth of the screen in pixels (160 on TI-89, 240 on TI-92 Plus)
LCD_HEIGHTunsigned shortHeight of the screen in pixels (100 on TI-89, 128 on TI-92 Plus)
LCD_LINE_BYTESunsigned shortNumber of bytes in the visible part of a screen line (20 on TI-89, 30 on TI-92 Plus)
KEY_LEFTshortKey code for the left arrow key (see ngetchx)
KEY_RIGHTshortKey code for the right arrow key
KEY_UPshortKey code for the up arrow key
KEY_DOWNshortKey code for the down arrow key
KEY_UPRIGHTshortKey code for simultaneous pressing on up and right arrow keys
KEY_DOWNLEFTshortKey code for simultaneous pressing on down and left arrow keys
KEY_DIAMONDshortThe number added to the key code if the Diamond key is pressed with it
KEY_SHIFTshortThe number added to the key code if the Shift key is pressed with it

NOTE: All these pseudo-constants are in fact macros. Although they expands to a relatively small code (in "Doors" mode they are mainly implemented as RAM_CALLs and managed by kernel), it is recommended to store a pseudo-constant in an ordinary variable if you use it often in the program (especially in "nostub" mode), and to use this variable instead. For example, if you used KEY_LEFT pseudo-constant too often, it is recommended to define
int key_left = KEY_LEFT;
somewhere at the begining of the program, and to use
if (key == key_left) ...
instead of
if (key == KEY_LEFT) ...
Such indirection will save a memory, but note that this is necessary only if you use the same pseudo-constant often in the program (say, more than 5 times).

There is yet another note. Pseudo-constants works as constants in nearly all cases, but they are not really constants, so they CAN NOT be used in case labels inside switch statement, i.e. the following is not legal:
switch (ngetchx ())
   {
      case KEY_LEFT:
         ...
      case KEY_RIGHT:
         ...
      ...
   }
Instead, use if...else constructions:
key = ngetchx ();
if (key == KEY_LEFT)
   {
      ...
   }
else if (key == KEY_RIGHT)
   {
      ...
   }
...

Return to the main index