How to make a "Doors" (kernel-based) program


  
To produce a "Doors" program, i.e. program which will need the DoorsOS kernel (or something similar like Universal OS, TeOS etc.) for executing, simply define the global preprocessor symbol USE_KERNEL at the begining of your program, before including any other header files from the library. This is a new method which works starting from release 2.2; alternatively, the old method (including doors.h header file before including any other header files from the library) still works. In fact, when USE_KERNEL is defined, including any header file from the library will include doors.h automatically (if it is not included explicitely before). So, explicite including doors.h is really necessary only if your program does not include any other header file from the library (which is extremely unlikely).

Here is a Kernighan & Ritchie "Hello world" example ("Doors" version), which works exactly like the example given in the previous section (making "nostub" programs):
#define USE_KERNEL          // include "DoorsOS" support

#include <stdio.h>          // standard ANSI C input/output support
#include <kbd.h>            // keyboard handling support, needed for ngetchx

int _ti89, _ti92plus;       // produce both .89z and .9xz files

void _main (void)           // main entry point is function _main
{
  clrscr ();                // clear the screen and reset print position
  printf ("Hello world!");  // do you know what is this?
  ngetchx ();               // wait for a keypress
}
Note that the directive SAVE_SCREEN is not included, in opposite to the "nostub" version. DoorsOS saves and restores the screen content by default, so any extra interventions are not necessary.

Of course, it is better again to use TIOS specific function than ANSI C console functions, so here is also an extended "Hello world" TI-specific example ("Doors" version), which does the same as in "nostub" case:
#define USE_KERNEL

#include <graph.h>
#include <kbd.h>

int _ti89, _ti92plus;

void _main (void)
{
  static WIN_RECT rect = {0, 0, 100, 14};
  ClrScr ();
  FontSetSys (F_8x10);
  DrawStr (3, 3, "Hello world!", A_NORMAL);
  DrawClipRect (&rect, ScrRect, A_NORMAL);
  ngetchx ();
}
See graph.h and kbd.h header files for detailed description of used functions and data types. Be aware of the slight difference between ClrScr defined in graph.h and clrscr defined in stdio.h.

To compile this program (named hello.c), you can use TIGCC Integrated Environment, or you can type from the command line:

tigcc -O2 hello.c

Include switch '-O2' always: it will force the optimization (click here to see much more about compiler command line options). See also notes given with the example in the previous section.

If you make programs spreaded in more than one file, you must define USE_KERNEL (or include doors.h) in each file!

The advantage of "Doors" programs is in fact that they are often (but not always) shorter than "nostub" programs if the program contains many ROM calls. "Doors" programs also can call routines from external files (often called "libraries"), which is not possible in "nostub" programs (without writing library support by yourself). Any other features supported with this library of header files work in both "Doors" and "nostub" mode, so if the difference in the program size is not enormous, and if no external libraries are needed, "nostub" mode is recommended. Note that routines defined in these header files contain the most of routines which are seen in various external libraries, sometimes maybe with different name and syntax.

If you make a "Doors" program, knowing the following facts may be useful:

Return to the main index