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:
- You can produce an external library file by defining the global symbol
_library
, i.e. by putting int _library
in your program. If the name of your library is for example MyLib,
all symbols with names like MyLib__nnnn will be exported as public. To make
life easier, use #define
directive. For example, if you
want to export function named MyFunc, you can, for example, put the directive
#define MyFunc MyLib__0005
at the beginning of
your library. The same directive must be included in the program which wants
to use function MyFunc from the library MyLib. Also, the prototype
of the imported function must be also defined.
-
You can put a global commentary in the .89z or .9xz file by defining the global
char array
_comment
, i.e. by putting
char _comment[] = "any_comment"
in the program.
-
The "Doors" programs may have an exit point. The function with name
_exit
will be executed after terminating of each program.