 |
InitArgPtr |
Function (Macro) |
Initializes a pointer to the first argument passed to the program.
InitArgPtr is a macro which initializes ap (which is a pointer of type
ESI) to point to the first argument passed to the assembly
program. Principally, calling
InitArgPtr (argptr);
is equal to doing
argptr = top_estack;
See top_estack for more info.
InitArgPtr must be used before the first call to GetStrnArg etc.
Here is an example of a program which reads string or integer arguments passed to it,
and displays them on the screen, one by one (called "Argument Test"):
// An example of passing arguments to C program
// Try this program calling argtest(arg1,arg2,...)
#define USE_TI89
#define USE_TI92PLUS
#define USE_V200
#define MIN_AMS 100
#include <graph.h>
#include <printf.h>
#include <kbd.h>
#include <args.h>
void _main(void)
{
ESI argptr;
int argtype;
long num;
InitArgPtr (argptr);
while ((argtype = GetArgType (argptr)) != END_TAG)
{
DrawStr (0, 30, " ", A_REPLACE);
if (argtype == STR_TAG)
DrawStr (0, 30, GetStrnArg (argptr), A_REPLACE);
else if (argtype == POSINT_TAG || argtype == NEGINT_TAG)
{
num = GetIntArg (argptr);
if (argtype == NEGINT_TAG)
num = -num;
printf_xy (0, 30, "%ld", num);
}
else
{
DrawStr (0, 30, "Wrong arg type!", A_REPLACE);
ngetchx ();
break;
}
ngetchx ();
}
}
If the name of this program is example.89z, try to call it on the calculator using
example ("strarg1", 123, -12, "strarg2")
to see how it works in practice.
Note: I used notation "&ap" in the prototype description, although passing by
reference does not exist in ordinary C (only in C++). However, this macro is implemented
in such a way that it simulates "passing by reference".
Uses: top_estack