/****************************************************************************/
/** Copyright (c) Quest Engineering Technologies, 1991                     **/
/**                                                                        **/
/** All Rights Reserved.  Unpublished rights reserved under the  copyright **/
/** laws of the United States.                                             **/
/**                                                                        **/
/** The software contained on this media is proprietary  to  and  embodies **/
/** the   confidential   technology  of  Quest  Engineering  Technologies. **/
/** Possession, use, duplication or  dissemination  of  the  software  and **/
/** media  is  authorized  only  pursuant  to a valid written license from **/
/** Quest Engineering Technologies.                                        **/
/**                                                                        **/
/** RESTRICTED RIGHTS LEGEND Use, duplication, or disclosure by  the  U.S. **/
/** Government  is  subject  to  restrictions as set forth in Subparagraph **/
/** (c)(1)(ii) of DFARS 252.227-7013, or in FAR 52.227-19, as applicable.  **/
/****************************************************************************/

/*
File name:             Project:
----------             --------
   ez_inter.h          EZDSP in C++ under Windows.

Description:
------------
   General C-interface file - avoid using any C++ in this intercae
   common header file for the dll16/32 and the app16/32
   should be made independant of the compiler (important)
   COMPILE_FOR_MV32SRV1 is defined when the interface is dynamically loaded

*/

#ifndef ez_inter_h
#define ez_inter_h

#if defined(__WINDOWS_386__) || defined(WIN32)

	#if defined(WIN32)
		#include "windef.h"		  // for defining FAR PASCAL
	#endif  // WIN32

	#define COMPILE_FOR_MV32
	#define W32WRAPBEGIN   {     // WATCOMC doesnt line constructors in case statements without these pair
	#define W32WRAPEND     }     //
	#include "windows.h"

	#define DELIMS      ";"          // Environment filepath delimiter(s) for MSDOS

#elif __unix__

	#include <sys/param.h>

	#ifndef MAX_PATH
	#define   MAX_PATH MAXPATHLEN
	#endif

	#define FAR 
	#define PASCAL 
	#define HINSTANCE long
	#define DWORD     unsigned long
	#define W32WRAPBEGIN {
	#define W32WRAPEND   }

	typedef void  (*FARPROC) ();

	#define DELIMS      ":"          // Environment filepath delimiter(s) for MSDOS

#else
	// #include "winclass.h"
	#define W32WRAPBEGIN
	#define W32WRAPEND
#endif

/* defines */
/***********/

// DLL32 Entry Points for WATCOM
#define EZDSP_INIT        1
#define EZDSP_CLOSE       2
#define EZDSP_EVALUATE    3
#define EZDSP_GETVALUE    4
#define EZDSP_SETVALUE    5
#define EZDSP_ABORT       6
#define EZDSP_GETERROR    7
#define EZDSP_SETOPTION   8
#define EZDSP_SETCALLBACK 9
#define EZDSP_DELVAR     10

// SetDebug() values
#define DEBUG_OFF              0    // must be zero (FALSE)
#define DEBUG_ON               1
#define DEBUG_ANIMATE          2

// EzdspGetValue types
#define PROGRAM_VAR          0
#define PROGRAM_VERSION      1
#define PROGRAM_KEYBOARD     2
#define PROGRAM_FILELIST     3
#define PROGRAM_LINENUM      4
#define PROGRAM_WHO          5
#define PROGRAM_VAR_PROP     6
#define PROGRAM_VAR_DEP_LST  7

/* defines */
/***********/

#define EPHES  1.0e-12

#define DIM(x) (sizeof(x)/sizeof(x[0]))
#define MAX_SYMBOL_NAME       50
#define MAX_INPUT_LINE      1024
#define MAX_PATH_LEN        1024
#define MAX_MVPATH_LEN      4096
#define MAX_FILE_NAME_LEN     64
#define MAX_FILE_EXT_LEN       5    // including dot and terminating NULL
#define MAX_MFILE_PATH       MAX_PATH_LEN
#define MAX_DIR_LEN          120
#define MAX_CRLF_STRING       32
#define USE(x)               if (x) {;}
#define PRECISION              6
#define MAX_ERROR_MESSAGE   1024
#define PATH_ENV_VAR        "MVPATH"
#define PATH_VARIABLE       "_MVPATH"
#define PWD_VARIABLE        "_MVPWD"
#define OUTPUT_CONTROL        50
// 51 for clc, 52 for home, 53 for beginwait, 54 for endwait

/* structures and typedefs */
/***************************/

// also look at eztypes.h
#if defined(__WATCOMC__) || defined(__WINDOWS_386__) || defined(WIN32)

	typedef long           INDINT;     // in 32-bit environment
	typedef unsigned long  uint32;
	typedef short          int16;
	typedef long           int32;

#elif defined(__unix__)

	typedef long           INDINT;     // in 32-bit environment
	typedef unsigned long  uint32;
	typedef short          int16;
	typedef long           int32;

#else

	typedef long           INDINT;     // in 16-bit environment
	typedef unsigned long  uint32;
	typedef int            int16;
	typedef long           int32;

#endif

// #pragma pack(push, 1)
typedef struct {
    INDINT        m;
    INDINT        n;
    int16         Type;
    char          Name [MAX_SYMBOL_NAME + 1];
    void         *lpData;
}  DATUM, *PtrDATUM;
// #pragma pack(pop)

enum {APP_NUMBER=1,   // datum types
      APP_DARRAY=2,
      APP_CMPLX=3,
      APP_CARRAY=4,
      APP_STRING=5,
      APP_EMPTY=6,
      APP_UNDEF=7,
      APP_UNDEF_EMPTY=8,
      APP_SYM_ARRAY=9,    // list of arrays
      APP_I16ARRAY=10,    // int16 array
      APP_I8ARRAY=11,     // int8  array
      APP_FUNCTION=12};   // m-file, built-in

typedef enum {OPTION_CASE, OPTION_BASE, OPTION_PRECISION,
             OPTION_DEBUG, OPTION_RUN, OPTION_STRING,
             OPTION_SAFETY
             } EZDSP_OPTION;

typedef enum {SAFETY_HIGH=2, SAFETY_MED=1, SAFETY_LOW=0} APPLET_SAFETY;

typedef enum {CALLBACK_GETLINE, CALLBACK_GETINPUT, CALLBACK_GETKEYBOARD,
              CALLBACK_ERROR, CALLBACK_PRINT, CALLBACK_PAUSE, CALLBACK_YIELD,
              CALLBACK_CHGVAR, CALLBACK_HELP, CALLBACK_DIARY, CALLBACK_FORMAT,
              CALLBACK_STEP, CALLBACK_INFO,
              CALLBACK_RE_EVAL, CALLBACK_STATUS,
              CALLBACK_GUI, CALLBACK_GUI_UI
             } EZDSP_CALLBACK;

/* error codes */
#define EZ_OK  0
#define EZ_ERR 1

#define EZ_ERR_STACK_OVERFLOW   2
#define EZ_ERR_SYNTAX           3
#define EZ_ERR_VAR_UNDEF        4
#define EZ_ERR_MEMORY           5
#define EZ_ERR_ZERODIVIDE       6
#define EZ_ERR_CONST            7

#define EZ_BUG 1000

#define EZ_ERR_NEGALLOC         (EZ_BUG+1)
#define EZ_ERR_STACK_UNDERFLOW  (EZ_BUG+2)

#define SYM_NOT_FOUND -1

// Engine (DLL) requested to quit
#define QUIT_CODE         0x1000   // see other codes in ezdsp.h

// SetDebug() values
#define DEBUG_OFF              0    // must be zero (FALSE)
#define DEBUG_ON               1
#define DEBUG_ANIMATE          2


// AppInfo -> EzdspStep communication - information codes
#define INFO_NULL_NAME         0    // invalid filename (AppInfo)
#define INFO_COMPILE           1    // should be negative (invalid line number)
#define INFO_EXECUTE           2
#define INFO_DEBUG_BREAK       3
#define INFO_COMPILE_START     4    // used with valid file name
#define INFO_COMPILE_END       5
#define INFO_POP_STACK         6    // used with valid file name
#define INFO_PUSH_STACK        7    // used with valid file name
#define INFO_MESSAGE           8    // filename is used as the message

// AppStep -> EzdspStep communication - use old file name with line number
#define STEP_PREV_FILE         0    // invalid filename (AppStep overloading)

// read and write file errors
#define READ_SUCCESS        0
#define READ_OPEN_FAILED    1
#define READ_TOO_LONG       2
#define READ_MEMORY         3
#define READ_FAILED         4

#define WRITE_SUCCESS       0
#define WRITE_OPEN_FAILED   1
#define WRITE_FAILED        2
#define DCONST              const   // declartion constant
#define RETVAL                      // return value

typedef int Inst;

typedef int  (*PROC_PTR)();
typedef int  (*GETLINE_PROC)(RETVAL char *line, DCONST void *win);
typedef int  (*ERROR_PROC)  (DCONST char *line, DCONST void *win);
typedef int  (*PRINT_PROC)  (long flag, DCONST DATUM *Result, DCONST char *line, DCONST void *win);
typedef int  (*PAUSE_PROC)  (int seconds, DCONST void *win, int opt, DCONST char *title, DCONST char *mess);
typedef int  (*CHGVAR_PROC) (DCONST char *VarName, DCONST DATUM *Result, DCONST void *win);
typedef int  (*STEP_PROC)   (DCONST char *filename, int linenum, DCONST void *win);
typedef long (*GUI_PROC)    (long Option, long lParam, RETVAL long *Result, DCONST void *win);
typedef long (*GUI_UI_PROC) (DCONST char *name, RETVAL int *, RETVAL void **, int, DCONST void **, DCONST void *win);

// WaveForm DSP 2.0 definitions
#define ULong           int  // under 32-bit compiler that is all we need
#define ULONG_VALUE          // used to be a complex definition!!

#endif    // ez_inter_h

