/*****************************************************************************/
/*                                                                           */
/*      Notice: This file contains proprietary and copyrighted materials     */
/*      of Micronetics Design Corporation.  Please refer to your             */
/*      non-disclosure agreement and/or license agreements(s) with           */
/*      Micronetics Design Corporation for use of these materials.           */
/*                                                                           */
/*      Copyright (c) 1983, 1984, 1985, 1997 Micronetics Design Corporation  */
/*                                                                           */
/*****************************************************************************/
/* xcdef.h: xcall management 						     */
/*****************************************************************************/
/* Change history							     */
/* (2) 05/28/92 - (SES00404) XCALL's Version 1.0 at MSM-PC,Version 3.1	     */
/* (3) 03/18/93 - (RER90413) fix <undef> errors {DEB}			     */
/* (4) 08/17/94 - expand and correct the return status interpretation	     */
/* (5) 09/02/96 - RER91061: DBCS support				     */
/* (6) 11/28/96 - RERxxxxx: Unicode on Windows95                             */
/*****************************************************************************/

#ifndef MCHAR                   /*(5)(6)*/
#ifdef CHAR16BITS               /*(5)(6)*/
#define MCHAR unsigned short    /*(5)(6)*/
#else                           /*(5)(6)*/
#define MCHAR char              /*(5)(6)*/
#endif                          /*(5)(6)*/
#endif                          /*(5)(6)*/

#ifndef _M                      /*(5)(6)*/
#ifdef CHAR16BITS               /*(5)(6)*/
#define _M(x)      L##x         /*(5)(6)*/
#else                           /*(5)(6)*/
#define _M(x)         x         /*(5)(6)*/
#endif                          /*(5)(6)*/
#endif                          /*(5)(6)*/

/*
 *	Definitions for constants
 */

#define XCVERSION		"V00\0\0\0\0"
#define XCVERSION_LENGTH	8
#define XCFILE_LENGTH		23
#define XCPACKAGE_LENGTH	24
#define XCFILE_CLENGTH		(XCFILE_LENGTH + 1)
#define XCPACKAGE_CLENGTH 	(XCPACKAGE_LENGTH + 1)

/*
 *	Definitions for run mode (runmode)
 */
#define XCMUMPS		0
#define XCASSEMBLER	1

/*
 *	Definitions for parameter types (ioparm)
 */
#define XCRET		0x0			/* function return value */
#define XCIN		0x1			/* input */
#define XCOUT		0x2			/* output */
#define XCINOUT		(XCIN + XCOUT)		/* input and output */

/*
 *	Definitions for mechanisms (mechanism)
 */

#define	XCVALUE		0			/* by value */
#define	XCREFERENCE	1			/* by mechanism */
#define XCMAXMECHANISM 	1

/*
 *	Definitions for I/O varieties (variety)
 */

#define XCOPTIONAL	1		/* optional */
#define XCOPTIONAL_0	2		/* optional, default is 0 */
#define XCREQUIRED	3		/* required */
#define XCCONSTANT	4		/* constant */
#define XCDEFAULT	5		/* optional, has default value */

/*
 *	Definitions for data types (dparm)
 */

#define XCSTRING	0
#define	XCINTEGER	1
#define	XCUINTEGER	2
#define	XCFLOAT		3
#define XCMAXDPARM	3
#define XCASSISTANT	4
#define XCINTERNAL	5

/*
 *	Definitions for data types extension (sparm)
 */

#define XC0		0		/*(3) no parameters */
#define XCSI2_BYTES	0		/*(3) no parameters */
#define XCSI1B		0		/* 1 byte integer */
#define XCSI2B		1		/* 2 byte integer */
#define XCSI4B		2		/* 4 byte integer */
#define XCSIXB		3		/* sizeof(int) integer */
#define XCSR		4		/* single precision float */
#define XCSD		5		/* double precision float */
#define	XCSSO		6		/* opaque string */
#define XCSSC		7		/* null-terminated string */
#define XCSSC1		8		/* 1 byte counted string */
#define XCSSC2		9		/* 2 byte counted string */
#define XCSSC4		10		/* 4 byte counted string */
#define	XCSSA		11		/* mumps array */
#define XCMAXSPARM	11

/*
 *	Definitions for return interpretation (inter)
 */

#define XCRVALUE	0		/* valid value returned		*/
#define XCRIGNORED 	1		/* no return value		*/
#define XCRSTATUSZ	2		/* zero value = success		*/
#define XCRSTATUSOS	3		/* use os rule to check success */
#define XCRREFERENCE	4		/* return value by reference	*/
#define XCRSTATUSNZ	5		/* non-zero value = success	*/

/*
 *	Definitions for output string sizes (fparamlen,fretsize)
 */

#define XCVPC		0		/* constant */
#define XCVPM		1		/* mumps input parameter */
#define XCVPR		2		/* routine output parameter */

/*
 *	Definitions for call type of xcall mumps routine
 */

#define XCMDO		0
#define XCMEXTRINSIC	1

/*
 *	Definitions for typedef
 */

#define uchar unsigned char
#define ushort unsigned short


typedef int (*XCPTRFUNC)();
typedef int (*XCASSISTPTR)();


struct xcfiles {
        char xcversion[XCVERSION_LENGTH];	/* +0 Xcall version	*/
        struct xcpackages *ppack;		/* +8 First package	*/
        struct xcfiles *pfile;			/*+12 Forward link	*/
        ushort npack;				/*+16 Number of packages */
        ushort leng;				/*+18 Length name file	*/
        char fname[XCFILE_CLENGTH];		/*+20 Name of file	*/
        char *xc_reserved;			/*+44 reserved */
};


struct xcnames {
        char *name;				/*+0 Pointer name  	*/
        ushort indrout;				/*+4 Index routine 	*/
        uchar runmode;				/*+6 code for runmode 	*/
        uchar filler;				/*+7 filler		*/
};


struct xcassembl {
        ushort params;				/*+0 Max parameters	*/
        ushort optionals;			/*+2 Par. optionals	*/
        ushort values;				/*+4 Par. values cons	*/
        ushort paramid;				/*+6 Index xcparameters */
};


struct xcmumps {
        uchar calltype;				/* +0 Call type		*/
        uchar flags;				/* +1 flags		*/
        uchar name_length;			/* +2 name length	*/
        uchar label_length;			/* +3 label length	*/
        ushort ucinum;				/* +4 unusued		*/
        char *name;				/* +6 name		*/
        char *label;				/*+10 label		*/
};


struct xcpackages {
        struct xcpackages *ppack;		/* +0 Forward link	*/
        int (*pxcpackinit)();			/* +4 Init function	*/
        struct xcnames *pxcall;			/* +8 Pointers area	*/
        struct xcparameters *pxcparam;		/*+12			*/
        struct xcvalues *pxcval;		/*+16			*/
        XCPTRFUNC *ptrfunc;			/*+20			*/
        struct xcassembl *pxcass;		/*+24			*/
        struct xcmumps *pxcmumps;		/*+28			*/
        struct xcassistant *pxcassist;		/*+32			*/
        XCASSISTPTR *pxcassistptr;		/*+36			*/
        ushort flags;				/*+40 Flags		*/
#define XC386TOXC86 0x0001 /* Call XCALL's code 8086 from 80386,MSDOS (2)*/
        ushort numxcall;			/*+42 Num of xcall's    */
        uchar packlen;				/*+44 Package name length*/
        uchar compname;				/*+45 Package name hash */
        char packname[XCPACKAGE_CLENGTH];	/*+46 Package name	*/
        uchar filler;				/*+71 Filler		*/
        int (*pxcsyscall)();			/*+72 xcsyscall() funct */
        char *pxcsyscallname;			/*+76 xcsyscall() name  */
};


struct xcparameters {
        ushort position;			/* +0 External position	*/
        ushort valueind;			/* +2 Index xcvalues	*/
        ushort paramlen;			/* +4 Max size		*/
        ushort retsize;				/* +6 Ret size to MUMPS	*/
        ushort assistin;			/* +8 Index assistant in*/
        ushort assistout;			/*+10 Index assistant out*/
                                                /*+12 Parameters info:	*/
        unsigned ioparm:2;			/* input or output	*/
        unsigned mechanism:2;			/* by value or reference*/
        unsigned variety:4;			/* optional, default, etc */
        unsigned dparm:4;			/* data type		*/
        unsigned sparm:4;			/* data subtype		*/
        unsigned inter:4;			/* return interpretation */
        unsigned fparamlen:2;			/* output string size	*/
        unsigned fretsize:2;			/* return value size	*/
};


struct xcvalues {
        ushort length;				/*+0 Length string	*/
        ushort filler;				/*+2 Filler		*/
        MCHAR  *value;				/*+4 Pointer string data*/ /*(5)*/
};


struct xcassistant {
        unsigned inmech:2;			/*+0 Input mechanism	*/
        unsigned idtype:4;			/*   Input  data type	*/
        unsigned odtype:4;			/*   Output data type   */
        unsigned istype:4;			/*   Input  data stype	*/
        unsigned ostype:4;			/*   Output data stype  */
        ushort osize;				/*+3 Output size	*/
        ushort retsize;				/*+5 Return size	*/
};
