/* File: simcom.h: Common part of the SIMSCRIPT (SIM-TO-C) header file.
 *
 * Before this, simcfg.h (machine dependent) must be included to define
 * some macros.
 *
 */

#if !defined (__SIMCOM_H__)
#define __SIMCOM_H__


/*=============================================================*/

/*  SIMSCRIPT TYPES  */

typedef unsigned char   S_A;          /*  alpha            */
#define S_C             char          /*  signed alpha     */
typedef long            S_I;          /*  integer          */
typedef short int       S_H;          /*  signed integer2  */ 
typedef unsigned short  S_X;          /*  integer2         */
typedef float           S_R;          /*  real             */
typedef double          S_D;          /*  double           */
typedef char FAR *      S_P;          /*  pointer          */
typedef long            S_W;          /*  entity word      */
typedef long            S_F;          /*  file token       */
typedef char FAR *      S_T;          /*  text             */
typedef char FAR *      S_Z;          /*  zero termntd str */
typedef VOID            (SIMCALL *S_S)(); /* subprogram    */

/*#ifndef solar */

#if !defined(solar) 
typedef void *          S_V;          /*  pointer to anything  - like z_PTR */
				      /*  11/1/94 - Ana - needed for OPEN_DIR*/
#endif
                                      /*  SUBPROGRAM TYPES */
typedef VOID            (SIMCALL *S_SN)();    /*  no return value  */
typedef S_A             (SIMCALL *S_SA)();    /*  alpha            */
typedef S_I             (SIMCALL *S_SI)();    /*  integer          */
typedef S_H             (SIMCALL *S_SH)();    /*  signed integer2  */ 
typedef S_X             (SIMCALL *S_SX)();    /*  integer2         */
typedef S_R             (SIMCALL *S_SR)();    /*  real             */
typedef S_D             (SIMCALL *S_SD)();    /*  double           */
typedef S_P             (SIMCALL *S_SP)();    /*  pointer          */
typedef S_T             (SIMCALL *S_ST)();    /*  text             */
typedef S_Z             (SIMCALL *S_SZ)();    /*  string           */

                                      /*  SPECIAL TYPES    */

typedef unsigned long   S_U;          /*  unsigned type for right shift */

typedef S_A FAR * pS_A;
typedef S_C FAR * pS_C;
typedef S_I FAR * pS_I;
typedef S_H FAR * pS_H;
typedef S_X FAR * pS_X;
typedef S_R FAR * pS_R;
typedef S_D FAR * pS_D;
typedef S_P FAR * pS_P;
typedef S_T FAR * pS_T;
typedef S_W FAR * pS_W;
typedef S_Z FAR * pS_Z;
typedef S_F FAR * pS_F;
typedef S_U FAR * pS_U;
typedef S_S FAR * pS_S;

typedef union tagS_UN { S_I i; S_P p; } S_UN ;

#ifndef MAIN_C
	/* NOT [] !!! not equivalent */
#ifdef alphaosf
extern S_D FAR *global;
#else
extern	S_I FAR *global;
#endif
#endif

/*-- define equiv. type for header (entities and arrays) --*/
typedef long  	S_HDR;		/* 32 bit on this machine */
typedef S_HDR*	pS_HDR;


/****************************************************************/
/*      SIMSCRIPT runtime library prototypes                    */
/****************************************************************/


/*-- Define PROTO to allow one header definition ---*/

#if defined(ANSI) && !defined(NO_PROTOTYPE)
# define PROTO(x)       x
#else
# define PROTO(x)       ()
#endif



S_T	SIMCALL concat_f PROTO((S_I, ...)) ;
S_I	SIMCALL imax_f PROTO((S_I, ...)) ;
S_I	SIMCALL imin_f PROTO((S_I, ...)) ;
S_D	SIMCALL fmax_f PROTO((S_D, ...)) ;
S_D  	SIMCALL fmin_f PROTO((S_D, ...)) ;


S_D     SIMCALL HARCCOS_F  PROTO((S_D)) ;
S_D     SIMCALL HARCSIN_F  PROTO((S_D)) ;
S_D     SIMCALL HARCTAN_F  PROTO((S_D , S_D )) ;
S_P     SIMCALL HARR_CHK_F  PROTO((S_P , S_X , S_X )) ;
S_T     SIMCALL HATOT_F  PROTO((S_I )) ;
S_D     SIMCALL HBETA_F  PROTO((S_D , S_D , S_I )) ;
S_I     SIMCALL HBINOMIAL_F  PROTO((S_I , S_D , S_I )) ;
S_VOID    SIMCALL HCLOSE_R  PROTO((S_I , S_I , S_Z )) ;
S_T     SIMCALL HCONCAT_F  PROTO((S_Z , S_Z )) ;
S_D     SIMCALL HCOS_F  PROTO((S_D )) ;
S_P     SIMCALL HCRE_BLK_F  PROTO((S_I , S_I )) ;
S_P     SIMCALL HCRE_F  PROTO((S_I )) ;
S_T     SIMCALL HCRETX_F  PROTO((S_I )) ;
S_VOID    SIMCALL HCSV_R  PROTO((S_S , S_S , S_S )) ;
S_VOID    SIMCALL HCVAL_R  PROTO((S_P , S_P , S_D , S_I , pS_P , pS_D )) ; 
S_I     SIMCALL HDATE_F  PROTO((S_I , S_I , S_I )) ;
S_VOID    SIMCALL HDATE_R  PROTO((S_T *, S_T *)) ;
S_I     SIMCALL HDAY_F  PROTO((S_D )) ;

#ifdef vms	/* Vax and Alpha VMS */
extern S_P HIDESCR_F();
extern S_P HDDESCR_F();
extern S_P HRDESCR_F();
extern S_P HSDESCR_F();
#endif

S_VOID    SIMCALL HDES_BLK_R  PROTO((S_P )) ;
S_VOID    SIMCALL HDEVINIT_R  PROTO((S_T , S_P *)) ;
S_VOID    SIMCALL HD_IOREQ_E PROTO((S_P )) ; 
S_I     SIMCALL HDIM_F  PROTO((S_P )) ;
S_P     SIMCALL HDREF_F  PROTO((S_D )) ;
S_I     SIMCALL HDTE_F  PROTO((S_D , S_I )) ;
S_I     SIMCALL HEFIELD_F  PROTO((VOID_ARGS)) ;
S_P     SIMCALL HENT_CHK0_F  PROTO((S_X , S_P , S_X )) ;
S_P     SIMCALL HENT_CHK_F  PROTO((S_X , S_P , S_X )) ;
S_VOID    SIMCALL HERASE_R  PROTO((S_P )) ;
S_D     SIMCALL HERLANG_F  PROTO((S_D , S_I , S_I )) ;
S_T     SIMCALL HERROR2000_F  PROTO((S_I )) ;
S_VOID    SIMCALL HEVSTAT_R  PROTO((VOID_ARGS)) ;
S_VOID    SIMCALL EXPORT HEXIT_R  PROTO((S_I STATUS)) ;
S_D     SIMCALL HEXP_F  PROTO((S_D DOUBLE_ARG)) ;
S_D     SIMCALL HEXPONENTIAL_F  PROTO((S_D MU, S_I STREAM)) ;
S_D     SIMCALL HFABS_F  PROTO((S_D DBLARG)) ;
S_VOID    SIMCALL HFEOF_F  PROTO((VOID_ARGS)) ;
S_I     SIMCALL HFERROR_F  PROTO((S_P FILEDES)) ;
S_T     SIMCALL HFIXED_F  PROTO((S_Z TEXT_ARG, S_I RESULT_LEN)) ;
S_D     SIMCALL HFMAX_F  PROTO((S_D DBLARG1, S_D DBLARG2)) ;
S_D     SIMCALL HFMIN_F  PROTO((S_D DBLARG1, S_D DBLARG2)) ;
S_D     SIMCALL HFMOD_F  PROTO((S_D DBLARG1, S_D DBLARG2)) ;
S_D     SIMCALL HFRAC_F  PROTO((S_D DOUBLE_ARG)) ;
S_D     SIMCALL HGAMMA_F  PROTO((S_D MEAN, S_D K, S_I STREAM)) ;
S_VOID    SIMCALL HGET_R  PROTO((S_I WIDTH, S_I FILE_TYPE, S_P *yp3)) ;
S_T     SIMCALL HGET_PATH_F  PROTO((S_T prog)) ;
S_D     SIMCALL HGMAJ_F  PROTO((S_D MEAN, S_D K, S_I STREAM)) ;
S_I     SIMCALL HHOUR_F  PROTO((S_D EXP)) ;
S_VOID    SIMCALL HHANDLE_EVENTS_R  PROTO((VOID_ARGS)) ;
S_I     SIMCALL HIABS_F  PROTO((S_I INTARG)) ;
S_I     SIMCALL HIDE_F  PROTO((VOID_ARGS)) ;
S_I     SIMCALL HIMAX_F  PROTO((S_I INTARG1, S_I INTARG2)) ;
S_I     SIMCALL HIMIN_F  PROTO((S_I INTARG1, S_I INTARG2)) ;
S_I     SIMCALL HIMOD_F  PROTO((S_I INTARG1, S_I INTARG2)) ;
S_VOID    SIMCALL HINIT_R  PROTO((VOID_ARGS)) ;
S_I     SIMCALL HINR_F  PROTO((VOID_ARGS)) ;
S_VOID    SIMCALL HIOSTAT_R  PROTO((S_I SAVEWRITE)) ;
S_P     SIMCALL HIREF_F  PROTO((S_I VALUE)) ;
S_I     SIMCALL HISTEP_F  PROTO((S_P FSET, S_I STREAM)) ;
S_I     SIMCALL HITOA_F  PROTO((S_I INT_ARG)) ;
S_T     SIMCALL HITOT_F  PROTO((S_I INT_ARG)) ;
S_D     SIMCALL HIXP_F  PROTO((S_D DOUBLE_BASE, S_I INTEGER_EXPONENT)) ;
S_I     SIMCALL HLENGTH_F  PROTO((S_P TEXT_PTR)) ;
S_D     SIMCALL HLIN_F  PROTO((S_P FSET, S_I STREAM)) ;
S_D     SIMCALL HLOG_10_F  PROTO((S_D DOUBLE_ARG)) ;
S_D     SIMCALL HLOG_E_F  PROTO((S_D DOUBLE_ARG)) ;
S_D     SIMCALL HLOG_NORMAL_F  PROTO((S_D MU, S_D SIGMA, S_I STREAM)) ;
S_T     SIMCALL HLOWER_F  PROTO((S_Z TEXT_ARG)) ;
S_I     SIMCALL HMATCH_F  PROTO((S_Z String, S_Z Pattern, S_I Offset)) ;
S_VOID    SIMCALL HMEMORY_R  PROTO((VOID_ARGS)) ;
S_I     SIMCALL HMINUTE_F  PROTO((S_D EXP)) ;
S_I     SIMCALL HMODE_F  PROTO((VOID_ARGS)) ;
S_I     SIMCALL HMONTH_F  PROTO((S_D TIME)) ;
S_I     SIMCALL HNDAY_F  PROTO((S_D EXP)) ;
S_I     SIMCALL HN_EV_S  PROTO((S_I CLASS)) ;
S_D     SIMCALL HNORMAL_F  PROTO((S_D MU, S_D SIGMA, S_I STREAM)) ;
S_VOID    SIMCALL HOPEN_R  PROTO((S_I , S_I , S_P , S_I , S_Z )) ;
S_VOID    SIMCALL HORIGIN_R  PROTO((S_I MM, S_I DD, S_I YY)) ;

/*----- OS calls by categories ---*/
S_T   	SIMCALL HOS_GET_OSTYPE_F PROTO((VOID_ARGS));
S_T   	SIMCALL HOS_GET_WINDOWSYSTYPE_F PROTO((VOID_ARGS));
S_T   	SIMCALL HOS_GET_COMPUTERTYPE_F PROTO((VOID_ARGS));
S_T   	SIMCALL HOS_GET_HOSTNAME_F PROTO((VOID_ARGS));
S_T   	SIMCALL HOS_GET_ENVVAR_F PROTO((S_T));
S_I   	SIMCALL HOS_SYSTEMTIME_F PROTO((VOID_ARGS));
S_T   	SIMCALL HOS_TIME2STRING_F PROTO((S_I));
S_I   	SIMCALL HOS_VIEWHELP_F PROTO((S_T, S_I));

S_I   	SIMCALL HOS_MAX_FNAMELEN_F PROTO((VOID_ARGS));
S_A   	SIMCALL HOS_GET_DIRSEPCHAR_F PROTO((VOID_ARGS));
S_T   	SIMCALL HOS_GET_CWD_F PROTO((VOID_ARGS));
S_T   	SIMCALL HOS_GET_CURDRIVE_F PROTO((VOID_ARGS));
S_T   	SIMCALL HOS_GET_PROG_DIR_F PROTO((S_T));
S_I   	SIMCALL HOS_MAKE_DIR_F PROTO((S_T));
S_I   	SIMCALL HOS_CHANGE_DIR_F PROTO((S_T));
S_I   	SIMCALL HOS_REMOVE_DIR_F PROTO((S_T));
S_I   	SIMCALL HOS_FILE_EXISTS_F PROTO((S_T));
S_I   	SIMCALL HOS_DELETE_FILE_F PROTO((S_T));
S_I   	SIMCALL HOS_RENAME_FILE_F PROTO((S_T));

#if defined(alphaosf) || defined(solar) || defined(OS_HPUNIX) || defined(OS_SUNOS) 
/*#if defined(solar) || defined(OS_SUNOS) */
S_P   SIMCALL HOS_OPEN_DIR_F PROTO((S_T));
#else
S_V   	SIMCALL HOS_OPEN_DIR_F PROTO((S_T));
#endif

S_T   	SIMCALL HOS_NEXT_DIRENTRY_F PROTO((S_P));
S_I   	SIMCALL HOS_CLOSE_DIR_F PROTO((S_P));
S_I   	SIMCALL HOS_FILE_TYPE_F PROTO((S_T));
S_I   	SIMCALL HOS_FILE_ACCESS_F PROTO((S_T));
S_I   	SIMCALL HOS_FILE_MODTIME_F PROTO((S_T));
S_I   	SIMCALL HOS_FILE_ACCESSTIME_F PROTO((S_T));
S_I   	SIMCALL HOS_FILE_SIZE_F PROTO((S_T));
S_I   	SIMCALL HOS_MAKE_EMPTY_FILE_F PROTO((S_T));
S_T   	SIMCALL HOS_MAKE_TEMP_FILE_F PROTO((S_T));
S_I   	SIMCALL HOS_COPY_FILE_F PROTO((S_T, S_T));
S_I   	SIMCALL HOS_MATCHES_FILEPATTERN_F PROTO((S_T,S_T));
S_I   	SIMCALL HOS_IS_LEGAL_FNAMECHAR_F PROTO((S_A));
S_T   	SIMCALL HOS_INCR_FNAME_IFEX_F PROTO((S_T));
S_T   	SIMCALL HOS_MAP2LEGALFNAME_F PROTO((S_T));
S_T   	SIMCALL HOS_APPEND_SLASH_F PROTO((S_T));
S_T   	SIMCALL HOS_REMOVE_FINAL_SLASH_F PROTO((S_T));
S_T   	SIMCALL HOS_DIRNAME_F PROTO((S_T));
S_T   	SIMCALL HOS_BASENAME_F PROTO((S_T));

S_I   	SIMCALL HOS_SYSTEMCALL_F PROTO((S_T, S_I));
S_I   	SIMCALL HOS_START_BGTASK_F PROTO((S_T));
S_I   	SIMCALL HOS_CHECK_BGTASK_F PROTO((S_I *, S_I *));
S_I   	SIMCALL HOS_KILL_BGTASK_F PROTO((S_I));
S_I   	SIMCALL HOS_GET_PID_F PROTO((VOID_ARGS));
S_I   	SIMCALL HOS_GET_PPID_F PROTO((VOID_ARGS));
/*------- end OS calls --------------*/

S_I     SIMCALL HOUT_F  PROTO((S_I COLPOS)) ;
S_I     SIMCALL HPOISSON_F  PROTO((S_D MU, S_I STREAM)) ;
S_VOID    SIMCALL HPOLL_R  PROTO((VOID_ARGS)) ;
S_VOID    SIMCALL HPRQ_R  PROTO((S_I STATUS, S_D TIME)) ;
S_VOID    SIMCALL HPSU_R  PROTO((VOID_ARGS)) ;
S_VOID    SIMCALL HPSUSP_R  PROTO((VOID_ARGS)) ;
S_T     SIMCALL HPTOT_F  PROTO((S_P)) ;
S_VOID    SIMCALL HPUT_R  PROTO((S_I WIDTH, S_I FILE_TYPE, S_P *yp3)) ;
S_I     SIMCALL HRANDI_F  PROTO((S_I LOW, S_I HIGH, S_I STREAM)) ;
S_D     SIMCALL HRANDOM_F  PROTO((S_I STREAM)) ;
S_D     SIMCALL HRBB_F  PROTO((VOID_ARGS)) ;
S_T     SIMCALL HRBT_F  PROTO((VOID_ARGS)) ;
S_I     SIMCALL HRDA_F  PROTO((S_I WIDTH)) ;
S_I     SIMCALL HRDB_F  PROTO((VOID_ARGS)) ;
S_I     SIMCALL HRDC_F  PROTO((S_I WIDTH)) ;
S_D     SIMCALL HRDD_F  PROTO((S_I WIDTH, S_I FRACWIDTH)) ;
S_I     SIMCALL HRDI_F  PROTO((S_I WIDTH)) ;
S_VOID    SIMCALL HRDL_R  PROTO((S_I NUM_CARDS)) ;
S_VOID    SIMCALL HRDM_R  PROTO((S_I RMODE, S_I FLAG, S_P *yp3)) ;
S_VOID    SIMCALL HRDR_R  PROTO((VOID_ARGS)) ;
S_VOID    SIMCALL HRDS_R  PROTO((S_I WIDTH)) ;
S_T     SIMCALL HRDT_F  PROTO((S_I WIDTH)) ;
S_VOID    SIMCALL HRDU_R  PROTO((S_I COLPOS)) ;
S_I     SIMCALL HRECORD_F  PROTO((S_I UNIT_NO)) ;
S_I     SIMCALL HRECORD_V  PROTO((S_I UNIT_NO)) ;
S_VOID    SIMCALL HRELH_R  PROTO((S_P DSPLYENT)) ;
S_T     SIMCALL HREPEAT_F  PROTO((S_Z TEXT_ARG, S_I COUNT)) ;
S_VOID    SIMCALL HREQ_R  PROTO((S_I , S_I , S_P , S_S , S_S , S_I , S_I )) ;
S_P     SIMCALL HRES_F  PROTO((S_P , S_I , S_I , S_I )) ;
S_VOID    SIMCALL HRESH_R  PROTO((S_D , S_D , S_D , S_T , S_I , S_P , pS_P )) ;
S_VOID    SIMCALL HRESTORE_R  PROTO((S_I UNIT_NO, S_I CHECKPOINT)) ;
S_I     SIMCALL HRFA_F  PROTO((VOID_ARGS)) ;
S_D     SIMCALL HRFD_F  PROTO((VOID_ARGS)) ;
S_I     SIMCALL HRFI_F  PROTO((VOID_ARGS)) ;
S_T     SIMCALL HRFT_F  PROTO((VOID_ARGS)) ;
S_I     SIMCALL HRHB_F  PROTO((VOID_ARGS)) ;
S_VOID    SIMCALL HRNQ_R  PROTO((S_I, S_I, S_P, S_I, S_I, S_S, S_S, S_S )) ;
S_D     SIMCALL HRRB_F  PROTO((VOID_ARGS)) ;
S_P     SIMCALL HRREF_F  PROTO((S_D VALUE)) ;
S_D     SIMCALL HRSTEP_F  PROTO((S_P FSET, S_I STREAM)) ;
S_T     SIMCALL HRTS_F  PROTO((VOID_ARGS)) ;
S_VOID    SIMCALL HRUNGE_KUTTA_R  PROTO((S_D TLIMIT)) ;
S_D     SIMCALL HRXP_F  PROTO((S_D DOUBLE_BASE, S_D DOUBLE_EXPONENT)) ;
S_VOID    SIMCALL HSET_MEM_R  PROTO((VOID_ARGS)) ;
S_VOID    SIMCALL HSET_OPEN_R  PROTO((VOID_ARGS)) ;
S_VOID    SIMCALL HSET_PARM_R  PROTO((S_I ARGC, S_P ARGV)) ;
S_VOID    SIMCALL HSET_R  PROTO((S_I ARGC, S_P ARGV)) ;
S_VOID    SIMCALL HSET_SEED_R  PROTO((VOID_ARGS)) ;
S_VOID    SIMCALL HSET_SIM_R  PROTO((VOID_ARGS)) ;
S_VOID    SIMCALL HSET_TIME_ARR_R  PROTO((S_I *)) ;
S_VOID    SIMCALL HSETUP_R  PROTO((VOID_ARGS)) ;
S_I     SIMCALL HSFIELD_F  PROTO((VOID_ARGS)) ;
S_VOID    SIMCALL HSIGBUS_HANDLER_R  PROTO((S_I , S_I)) ;
S_VOID    SIMCALL HSIGFPE_HANDLER_R  PROTO((S_I , S_I)) ;
S_VOID    SIMCALL HSIGINT_HANDLER_R  PROTO((S_I , S_I)) ;
S_I     SIMCALL HSIGN_F  PROTO((S_D DOUBLE_ARG)) ;
S_VOID    SIMCALL HSIGSEGV_HANDLER_R  PROTO((S_I , S_I , S_I )) ;
S_VOID    SIMCALL HSIGTERM_HANDLER_R  PROTO((S_I , S_I , S_I )) ;
S_D     SIMCALL HSIN_F  PROTO((S_D DOUBLE_ARG)) ;
S_VOID    SIMCALL HSKIP_R  PROTO((S_I NUM_FIELDS)) ;
S_VOID    SIMCALL HSNAP_R  PROTO((VOID_ARGS)) ;
S_D     SIMCALL HSQRT_F  PROTO((S_D DOUBLE_ARG)) ;
S_I     SIMCALL HSTDERR_F  PROTO((VOID)) ;
S_I     SIMCALL HSTDIN_F  PROTO((VOID)) ;
S_I     SIMCALL HSTDOUT_F  PROTO((VOID)) ;
S_VOID    SIMCALL HSUBP_CHK_R  PROTO((S_P SUBP_PTR)) ;
S_T     SIMCALL HSUBSTR_F  PROTO((S_Z , S_I , S_I )) ;
S_T     SIMCALL HSUBSTRL_F  PROTO((S_Z , S_I , S_I , S_Z )) ;
S_VOID    SIMCALL HSYSTIME_R  PROTO((pS_I yi1)) ;
S_D     SIMCALL HTAN_F  PROTO((S_D DOUBLE_ARG)) ;
S_I     SIMCALL HTCMP_F  PROTO((S_Z TEXT_ARG1, S_Z TEXT_ARG2)) ;
S_P     SIMCALL HTCOPY_F  PROTO((S_P TEXT_PTR)) ;
S_VOID    SIMCALL HT_EV_S  PROTO((S_P NOTICE, S_I CLASS)) ;
S_VOID    SIMCALL HTIM0_R  PROTO((S_S MOTION, S_P *yp2)) ;
S_VOID    SIMCALL HTIM1_R  PROTO((S_P *yp1)) ;
S_VOID    SIMCALL HTIM2_R  PROTO((VOID_ARGS)) ;
S_VOID    SIMCALL HTIM3_R  PROTO((S_T *yt1, S_I *yi2, S_D *yd3)) ;
S_D     SIMCALL HTIM4_F  PROTO((VOID_ARGS)) ;
S_VOID    SIMCALL HTRACE_R  PROTO((S_I UNIT_NO)) ;
S_VOID    SIMCALL HTRACEBACK_R  PROTO((VOID_ARGS)) ;
S_VOID    SIMCALL HTRCPTR_R  PROTO((S_T DESCRIPT, S_P ADDR)) ;
S_VOID    SIMCALL HTRCTRIM_R  PROTO((S_T DESCRIPT, S_P TEXT_PTR)) ;
S_D     SIMCALL HTRIANG_F  PROTO((S_D A, S_D B, S_D C, S_I STREAM)) ;
S_T     SIMCALL HTRIM_F  PROTO((S_Z TEXT_ARG, S_I FLAG)) ;
S_VOID    SIMCALL HT_RS_S  PROTO((S_P E1, S_P M2)) ;
S_I     SIMCALL HTTOA_F  PROTO((S_Z TEXT_ARG)) ;
S_P     SIMCALL HTTOP_F  PROTO((S_T TEXT_PTR)) ;
S_T     SIMCALL HPTOT_F  PROTO((S_P)) ;
S_I     SIMCALL HTTOI_F  PROTO((S_T)) ;
/*S_R     SIMCALL HTTOR_F  PROTO((S_T)) ; */
S_D     SIMCALL HTTOR_F  PROTO((S_T)) ;
S_D     SIMCALL HTTOD_F  PROTO((S_T)) ;
S_VOID    SIMCALL HU_EV_S  PROTO((S_P NOTICE, S_I CLASS)) ;
S_D     SIMCALL HUNIFORM_F  PROTO((S_D A, S_D B, S_I STREAM)) ;
S_T     SIMCALL HUNIX_STRING_F  PROTO((S_P C_STRING)) ;
S_T     SIMCALL HUPPER_F  PROTO((S_Z TEXT_ARG)) ;
S_VOID    SIMCALL HUSE_R  PROTO((S_I UNIT_NO, S_I USE_FLAG)) ;
S_VOID    SIMCALL HWBB_R  PROTO((S_D DOUBLE_ARG)) ;
S_VOID    SIMCALL HWBT_R  PROTO((S_Z TEXT_ARG)) ;
S_I     SIMCALL HWEEKDAY_F  PROTO((S_D EXP)) ;
S_D     SIMCALL HWEIBULL_F  PROTO((S_D SHAPE, S_D SCALE, S_I STREAM)) ;
S_VOID    SIMCALL HWHB_R  PROTO((S_I wgx1)) ;
S_VOID    SIMCALL HWLA_R  PROTO((S_Z VARNAME, S_I wga2)) ;
S_VOID    SIMCALL HWLC_R  PROTO((S_Z VARNAME, S_P POINTER_ARG)) ;
S_VOID    SIMCALL HWLD_R  PROTO((S_Z VARNAME, S_D DOUBLE_ARG)) ;
S_VOID    SIMCALL HWLI_R  PROTO((S_Z VARNAME, S_I INTEGER_ARG)) ;
S_VOID    SIMCALL HWLS_R  PROTO((S_Z VARNAME, S_S SUBPROG_ARG)) ;
S_VOID    SIMCALL HWLT_R  PROTO((S_Z VARNAME, S_Z TEXT_ARG)) ;
S_VOID    SIMCALL HWLY_R  PROTO((S_Z TEXT, S_P ARYPTR)) ;
S_VOID    SIMCALL HWRB_R  PROTO((S_D REAL_ARG)) ;
S_VOID    SIMCALL HWSETUP_R  PROTO((VOID_ARGS)) ;
S_VOID    SIMCALL HWTA_R  PROTO((S_I WIDTH, S_I wga2)) ;
S_VOID    SIMCALL HWTB_R  PROTO((S_I INTEGER_ARG)) ;
S_VOID    SIMCALL HWTC_R  PROTO((S_I WIDTH, S_I INTEGER_ARG)) ;
S_VOID    SIMCALL HWTD_R  PROTO((S_I WIDTH, S_I FRACWIDTH, S_D NUMBER)) ;
S_VOID    SIMCALL HWTE_R  PROTO((S_I WIDTH, S_I FRACWIDTH, S_D NUMBER)) ;
S_VOID    SIMCALL HWTI_R  PROTO((S_I WIDTH, S_I INTEGER_ARG)) ;
S_VOID    SIMCALL HWTP_R  PROTO((VOID_ARGS)) ;
S_VOID    SIMCALL HWTR_R  PROTO((VOID_ARGS)) ;
S_VOID    SIMCALL HWTS_R  PROTO((S_I WIDTH)) ;
S_VOID    SIMCALL HWTT_R  PROTO((S_I WIDTH, S_Z TEXT_ARG)) ;
S_VOID    SIMCALL HWTU_R  PROTO((S_I COLPOS)) ;
S_VOID    SIMCALL HWTX_R  PROTO((S_Z TEXT_ARG)) ;
S_VOID    SIMCALL HX_EV_S  PROTO((S_I CLASS, pS_P yp2)) ;
S_I     SIMCALL HYEAR_F  PROTO((S_D TIME)) ;
S_VOID    SIMCALL HZ_EV_S  PROTO((S_P NOTICE, S_I CLASS)) ;
S_VOID    SIMCALL HZ_RS_S  PROTO((S_P E1, S_I M2)) ;
S_VOID    SIMCALL QDES_F  PROTO((S_P fnval, S_I ENTITY_ID)) ;
S_VOID    SIMCALL QERR_F  PROTO((S_I wfnval)) ;
S_VOID    SIMCALL QFRAME_PTR_F  PROTO((S_P lpSusp)) ;
S_VOID    SIMCALL QOUT_F  PROTO((S_I wfnval, S_I COLPOS)) ;
S_VOID    SIMCALL QREAD_V  PROTO((S_I wfnval)) ;
S_VOID    SIMCALL QREL_F  PROTO((S_P fnval)) ;
S_VOID    SIMCALL QWRITE_V  PROTO((S_I wfnval)) ;
S_VOID    SIMCALL RPCALL  PROTO((S_S, S_P)) ;
S_I     SIMCALL RPSIZE  PROTO((VOID_ARGS)) ;
S_VOID    SIMCALL RPSUSP  PROTO((S_P)) ;
S_VOID    SIMCALL HPCALL_R PROTO((S_SN Process)) ;

S_I STDCALL zgetmaxint () ;


/*
 *  Macro definitions
 */

#define RACHAR_F(p,i)	*(((pS_A)p)+(int)i-1)
#define QACHAR_F(e,p,i) *(((pS_A)p)+(int)i-1)=e;
#define HDIV_F(i,j)	((S_I)(i)/(S_I)(j))
#define DIV_F(i,j)	((S_I)(i)/(S_I)(j))

/* old (vms) and new version of round (new didn't work on vms) */
#ifdef vms
#define round_f(i)      (S_I)((td=(i))>(S_D)0.0?td+(S_D)0.5:td-(S_D)0.5)
#else
#define round_f(i) 	(td=i,((S_I)((td)>(S_D)0.0?td+(S_D)0.5:td-(S_D)0.5)))
#endif


/*
 *  Macros for function name mappings
 */

#ifndef SIMRTLDEBUG

#include <math.h>
#define zatan2	atan2
#define zmodf	modf
#define	zabs	abs	
#define	zfabs	fabs	
#define	zasin	asin	
#define zacos	acos
#define zsin	sin
#define zcos	cos
#define ztan	tan
#define zlog	log
#define zsqrt	sqrt
#define zlog10	log10
#define zpow	pow
#define zexp	exp
#define zfloor	floor

#endif




/*-- in OS/2 we don't need an address checking function */
#if defined(__OS2__)
#define chkadr_f(a) ((S_I)1)
#endif

#if defined(alphaosf)
#define sizeof_header 8 
#else
#define sizeof_header 4		/*-- headers are always 4 bytes --*/
				/*-- be consistent with S_HDR   --*/
#endif


/*                                              */      
/*      Array accessing substitutions           */
/*                                              */      

#ifndef RUNCHK
#   define aaary(p,i)   ((pS_A)p+i-1)          /* alpha                */
#   define axary(p,i)   ((pS_X)p+i-1)          /* signed halfint       */
#   define ahary(p,i)   ((pS_H)p+i-1)          /* unsigned halfint     */
#   define aiary(p,i)   ((pS_I)p+i-1)          /* integer              */
#   define arary(p,i)   ((pS_R)p+i-1)          /* real                 */
#   define adary(p,i)   ((pS_D)p+i-1)          /* double               */
#   define apary(p,i)   ((pS_P)p+i-1)          /* pointer              */
#   define atary(p,i)   ((pS_T)p+i-1)          /* text                 */
#   define asary(p,i)   ((pS_S)p+i-1)          /* subprogram           */
#else
#   define aaary(p,i)   (pS_A)HARR_CHK_F(p,i,0)    /* log2 sizeof(S_A) */
#   define axary(p,i)   (pS_X)HARR_CHK_F(p,i,1)    /* log2 sizeof(S_X) */
#   define ahary(p,i)   (pS_H)HARR_CHK_F(p,i,1)    /* log2 sizeof(S_H) */
#   define aiary(p,i)   (pS_I)HARR_CHK_F(p,i,2)    /* log2 sizeof(S_I) */
#   define arary(p,i)   (pS_R)HARR_CHK_F(p,i,2)    /* log2 sizeof(S_R) */
#   define adary(p,i)   (pS_D)HARR_CHK_F(p,i,3)    /* log2 sizeof(S_D) */
#   define apary(p,i)   (pS_P)HARR_CHK_F(p,i,2)    /* log2 sizeof(S_P) */
#   define atary(p,i)   (pS_T)HARR_CHK_F(p,i,2)    /* log2 sizeof(S_T) */
#   define asary(p,i)   (pS_S)HARR_CHK_F(p,i,2)    /* log2 sizeof(S_S) */
#endif

/*                                              */
/*      Packed Array accessing substitution     */
/*              (permanent entities)            */
/*                                              */

#define apiary(p,i,j)           ((pS_I)((pS_A)aiary(p,i)+j))
#define apxary(p,i,j)           ((pS_X)((pS_A)aiary(p,i)+j))
#define apaary(p,i,j)           ((pS_A)aiary(p,i)+j)
#define ubnary(p,i,j,s,m)       ((*apiary(p,i,j)>>s)&m)
#define sbnary(p,i,j,s,m,sm)    (S_I)(( (wpck=(*apiary(p,i,j)>>s)&m) & sm)? \
                                    wpck|~((S_I)m) : wpck)

#define ub1ary(p,i,j,s,m)       ubnary(p,i,j,s,m)
#define sb1ary(p,i,j,s,m,sm)    sbnary(p,i,j,s,m,1)

#define ub0ary(p,i,j,s,m)       (*apiary(p,i,j)&m)
#define sb0ary(p,i,j,s,m,sm)    (S_I)(( (wpck=(*apiary(p,i,j))) & sm)? \
                                    wpck|~((S_I)m) : wpck&m)

#define lbnary(e,p,i,j,s,m)     *apiary(p,i,j) = \
                                    (*apiary(p,i,j)&~((S_I)m)) | (m& ((S_I)e<<s))
#define lb1ary(e,p,i,j,s,m)     if ((S_I)e&1) *apiary(p,i,j) |= m; else \
                                    *apiary(p,i,j) &= (~((S_I)m))
#define lb0ary(e,p,i,j,s,m)     *apiary(p,i,j) = \
                                    (*apiary(p,i,j) & (~((S_I)m))) | ((S_I)e & m)

/*      field-packed n/4        */

#ifdef S_C
#    define uf4ary(p,i,j)       (S_I)*apaary(p,i,j)
#    define sf4ary(p,i,j)       *(pS_C)apaary(p,i,j)
#else
#    define uf4ary(p,i,j)       (S_I)*apaary(p,i,j)
#    define sf4ary(p,i,j)       (S_I)(((wpck=(*apaary(p,i,j)))&0x80)? \
                                    wpck|0xffffff00 : wpck)
#endif
#define lf4ary(e,p,i,j)         *apaary(p,i,j) = e

/*      field-packed n/2        */

#define uf2ary(p,i,j)           *apxary(p,i,j)
#define sf2ary(p,i,j)           *(pS_H)apxary(p,i,j)
#define lf2ary(e,p,i,j)         *apxary(p,i,j) = e

/*      selected intra-packed           */
/*      (others treated as alpha        */
/*      or halfint as appropriate       */

#ifdef S_C
#    define si4ary(p,i)         *((pS_C)aaary(p,i))
#else
#    define si4ary(p,i)         (S_I)(((wpck = *aaary(p,i))&0x80)? \
                                    wpck|0xffffff00 : wpck)
#endif
#define li4ary(e,p,i)           *aaary(p,i) = e
#define li2ary(e,p,i)           *axary(p,i) = e


/*                                                      */
/*      Attribute accessing routine substitutions       */
/*                                                      */

#ifndef RUNCHK
#   define aatr(c,p,i)          (pS_A)((p)+i)
#else
#   ifdef ENTCLASSCHK
#       define aatr(c,p,i)      HENT_CHK_F((S_X)c,(p),(S_X)i)
#   else
#       define aatr(c,p,i)      HENT_CHK0_F((S_X)c,(p),(S_X)i)
#   endif
#endif

#define riatr(c,p,i)            *(pS_I)aatr(c,(p),i)
#define ubnatr(c,p,i,s,m)       (S_I)((riatr(c,(p),i)>>s)&m)
#define sbnatr(c,p,i,s,m,sm)    (S_I)(((wpck=riatr(c,(p),i)>>s)&sm)? \
                                    wpck|~((S_I)m) : wpck&m)
#define ub1atr(c,p,i,s,m)       ubnatr(c,(p),i,s,m)
#define sb1atr(c,p,i,s,m,sm)    sbnatr(c,(p),i,s,m,1)
#define ub0atr(c,p,i,s,m)       (S_I)(riatr(c,(p),i)&m)
#define sb0atr(c,p,i,s,m,sm)    (S_I)(((wpck=riatr(c,(p),i))&sm)? \
                                    wpck|~((S_I)m) : wpck&m)

#define lbnatr(c,e,p,i,s,m)     riatr(c,(p),i) = ( riatr(c,(p),i) & (~((S_I)m)) ) | \
                                    (m & ((S_I)e<<s ))
#define lb1atr(c,e,p,i,s,m)     if ((S_I)e&1) riatr(c,(p),i) |= m; else \
                                    riatr(c,(p),i) &= (~((S_I)m))
#define lb0atr(c,e,p,i,s,m)     riatr(c,(p),i) = (riatr(c,(p),i) & (~((S_I)m))) | \
                                    ((S_I)e & m)

#define lf4atr(c,e,p,i)         *(pS_A)aatr(c,(p),i) = e
#define sf4atr(c,p,i)           (S_I)*(pS_C)aatr(c,(p),i)
#define uf4atr(c,p,i)           (S_I)*(pS_A)aatr(c,(p),i)

#define lf2atr(c,e,p,i)         *(pS_X)aatr(c,(p),i) = e
#define sf2atr(c,p,i)           (S_I)*(pS_H)aatr(c,(p),i)
#define uf2atr(c,p,i)           (S_I)*(pS_X)aatr(c,(p),i)


/************************  simpdb.h *****************************/


/* File: simpdb.h
 * Definitions for the inline SIMSCRIPT debugger 
 *
 */

#ifndef OS_SUNOS
#ifndef NULL
#define NULL ((void *)0)
#endif
#endif

#ifndef TRUE
#define TRUE 1
#define FALSE 0
#endif

  /*-- all debug info needed at runtime must be here */
typedef struct trcstrT_tag {
  S_P       *pprte;     /* &staticprte, ptr to prte rtn-descr for routines */
  S_T       rtnname;    /* routine name (when prte=0) */
  S_I       curline;    /* current line number */
  struct trcstrT_tag *next; /* next in chain */
} trcstrT;

extern trcstrT *trctop;

  /*** must correspond to what's used in dbg_walkstack as frame base ***/
#define dbg_FRAMEBASE &trcstr


  /*---- basic type codes -----*/
  /***** These must match the .MODE codes defined in RTL Preamble!!!! */

#define btc_no_type 0   /*-- integer */
#define btc_a   1   /*-- alpha */
#define btc_x   2   /*-- integer 2 */
#define btc_h   3   /*-- signed integer 2 */
#define btc_i   4   /*-- integer */
#define btc_r   5   /*-- real (float) */
#define btc_d   6   /*-- double */
#define btc_p   7   /*-- pointer */
#define btc_s   9   /*-- subprogram type */
#define btc_t   10  /*-- text / string */
#define btc_z   10  /*-- text also */


/***************  for generated source code   ****************************/

  /*--- define calls and variables used in macros below ---*/

/**** these vars are internal only, never passed to SS. Can be int ***/

extern int dbg_special;
extern int dbg_doingss;
extern int dbg_definertn_flag;  
extern int dbg_defineframe_flag;    

extern char dbgbpa[];

/**** SIMSCRIPT Debugger routines called from the generated C level. Need
 * prototypes. For Windows (3.1) we must use full ANSI prototypes so that
 * arguments and constants (especially int = 16 bit) are coerced correctly.
 */

/*** indirect call to debugger saves link time. dbg_bpcall is local static
 * routine in each module (dbg_DEFBPA() ) **/

void static dbg_bpcall();

/* Some C compilers have problems with static forward declarations as used
 * for dbgbpa. Therefore, we use a call getdbgbpa() to return the address
 * of the dbgbpa.
 */

static char *getdbgbpa();



#ifdef ANSI

extern S_VOID SIMCALL HSSDB_BPCALL_R();
extern S_P  SIMCALL HRT_NEW_F(S_I, S_T, S_T, S_I, S_I, S_S, S_P, S_P);
extern S_VOID SIMCALL HDS_ADDVAR_R(S_P, S_T, S_P, S_P, S_I, S_I, S_I);
extern S_T  SIMCALL HUNIX_STRING_F(char *);
extern S_VOID SIMCALL HBPA_FILLTEMP_R(S_P);
extern S_P  SIMCALL HRT_MKPRE_F (S_I, S_T, S_I, S_I) ;
extern S_P  SIMCALL HDS_MKPRE_F (S_P) ;
extern S_VOID SIMCALL HEDS_DCLATTR_R(S_T, S_I, S_I, S_I);
extern S_VOID SIMCALL HEDS_DCLENT_R(S_T, S_I);

#else

extern S_VOID SIMCALL HSSDB_BPCALL_R();
extern S_P  SIMCALL HRT_NEW_F();
extern S_VOID SIMCALL HDS_ADDVAR_R();
extern S_T  SIMCALL HUNIX_STRING_F();
extern S_VOID SIMCALL HBPA_FILLTEMP_R();
extern S_P  SIMCALL HRT_MKPRE_F () ;
extern S_P  SIMCALL HDS_MKPRE_F () ;
extern S_VOID SIMCALL HEDS_DCLATTR_R();
extern S_VOID SIMCALL HEDS_DCLENT_R();

#endif


/*** slbpa: static local copy of dbgbpa.
 * SInce the code still passes 'dbgbpa' as an argument to the RTNDEF call
 * we must declare a dummy dbgbpa to satisfy that reference (never used).
 */
#define dbg_RTN_DEFS trcstrT trcstr; \
		static char *staticprte=NULL; \
		static int tried_to_reg=0; \
		static char *slbpa=NULL; \
		static char *dbgbpa=NULL


/*-------------------------------------------------------------------------
 * RTNPROLOG, EPILOG ... that differ depending on the compile mode:
 * see section 4.15 in debugger documentation
 * Cases: SIMDEBUG, SIMTRACE, SIMNODEBUG, 'nothing' defined.
 * SIMDEBUG supersedes SIMTRACE, SIMNODEBUG supersedes 'nothing'.
 * Logic:  #ifdef SIMDEBUG
 *             macros for full debug mode
 *         #else
 *         #ifdef SIMTRACE
 *             macros for trace mode
 *         #else
 *         #ifdef SIMNODEBUG
 *             macros for maximum speed mode (libraries); no rtn registr.
 *         #else
 *             macros for maximum speed mode (libraries); no rtn registr.
 *         #endif
 *         #endif
 *         #endif
 *
 * Only when we really go into the rtn body (after the "if"s) we must 
 * update the trcstr chain. Before we call any libraray routine we must
 * turn off dbg_special temporarily. See 4.15 in DBGDOC.
 * When we turn off and then on dbg_special we must be absolutely sure that
 * it was set in the first place (!) and the caller takes care of turning
 * it off after all is done. Otherwise nothing will ever happen again
 * after turning dbg_special on.
 *
 *
 * PROBLEM: endless recursion in flooding call chain for scripted rtns
 *
 *  These rtns won't get registered (debugon==-1) since they are internal.
 *  We cannot simply not do the flooding calls for the internal rtns, since
 *  e.g. TIME.R is a scripted rtn and calls all the process routines to be
 *  registered. But when there is a recursive scripted rtn, the flooding
 *  calls will recurse since RT.NEW.F returns 0 into staticprte which is
 *  checked for 'registered yet'. We have to also remember that WE TRIED
 *  to register and then break the call chain. This can be done safely
 *  only in a separate variable 'tried_to_reg'.
 *
 *
 * CMR: 
 */

/* &trcstr: needed to be in () for vax C compiler */

#ifdef SIMDEBUG

/*============ full DEBUG mode =================*/

  /* prte and rtnname must be defined in call cases. */
  /* BPA_FILL_TEMP_R: Gets called upon routine entry when we are doing 
   * a single-step, i.e. when a 'next instruction' was a call. In that
   * case the called routine gets its BPA flooded. But after that 
   * WE MUST NOT RESET dbg_special to 1 !!! since we will run into the
   * user code right away.
   */
#define dbg_RTNPROLOG(rname) \
		trcstr.rtnname = rname; \
		trcstr.pprte = &staticprte;\
		trcstr.curline = 0;\
		if (!slbpa) slbpa=getdbgbpa(); \
		if (dbg_special) { \
		  if (dbg_definertn_flag) goto dbg_defrtn_lbl; \
		  if (dbg_defineframe_flag) goto dbg_defframe_lbl; \
		  if (dbg_doingss && staticprte) { dbg_special=0; \
			HBPA_FILLTEMP_R(staticprte); \
		  };    \
		} ; \
		trcstr.next = trctop;   \
		trctop = (&trcstr)

#define dbg_RTNEPILOG trctop=trcstr.next 

#define dbg_SRCLINE(n) trcstr.curline=(n); if(slbpa[n]) dbg_bpcall() 

/* see comment on BPA_FILLTEMP_R above */
#define dbg_CONTEXTSW(n) trctop = (&trcstr); \
		if (dbg_doingss && staticprte) { dbg_special=0; \
		HBPA_FILLTEMP_R(staticprte); } 


/* We just reuse the routine name set in the PROLOG before we jumped here.
 * Since that is a string constant we don't need HTCOPY_F for it.
 * We also set slbpa here (static local access to bpa).
 * Don't add "return" at end since the flooding calls are behind this macro.
 * 
 * See comment about getdbgbpa above: we cannot use the bpa argument since
 * it is a dummy arg. Get the true value from the call.
 */
#define dbg_RTNDEF(debugon, fn, sl, el, fp, esl, bpa)\
		if (staticprte || tried_to_reg) return; \
		slbpa=getdbgbpa(); \
		tried_to_reg=1 ;\
		dbg_special=0; \
		staticprte=HRT_NEW_F(debugon, trcstr.rtnname ,\
			  HUNIX_STRING_F(fn),sl,el,fp,esl,slbpa); \
		dbg_special=1


#else

#ifdef SIMTRACE

/*================ TRACE mode =================*/
/*-- No single stepping, no slbpa assigment */

#define dbg_RTNPROLOG(rname) \
		trcstr.rtnname=rname;   \
		trcstr.pprte=&staticprte;\
		trcstr.curline = 0;\
		if (dbg_special) { \
		  if (dbg_definertn_flag) goto dbg_defrtn_lbl; \
		  if (dbg_defineframe_flag) goto dbg_defframe_lbl; \
		} ; \
		trcstr.next=trctop; \
		trctop=(&trcstr)

#define dbg_RTNEPILOG trctop=trcstr.next 

#define dbg_SRCLINE(n) trcstr.curline=(n)

#define dbg_CONTEXTSW(n) trctop=(&trcstr)

#define dbg_RTNDEF(debugon, fn, sl, el, fp, esl, bpa)\
		if (staticprte || tried_to_reg) return; \
		tried_to_reg=1; \
		dbg_special=0; \
		staticprte=HRT_NEW_F(debugon, trcstr.rtnname ,\
			  HUNIX_STRING_F(fn),sl,el,fp,esl,slbpa); \
		dbg_special=1


#else    

#ifdef SIMNODEBUG

/*============ SIMNODEBUG mode ==================*/
/*-- Just rtnname assignment for traceback, no rtn or frame reg. */

/* Library routines should never be called when dbg_special is on!! But
 * just in case: When a flooding call to a routine compiled with SIMNODEBUG
 * gets by, we must immediately return.
 * THIS CHECK DOESN'T WORK RIGHT NOW! TAKEN OUT !!!
 * 		if (dbg_special) return;
 */

#define dbg_RTNPROLOG(rname)    \
		trcstr.rtnname=rname;   \
		trcstr.curline = 0;\
		trcstr.pprte=&staticprte;   \
		trcstr.next=trctop; \
		trctop=(&trcstr)

#define dbg_RTNEPILOG trctop=trcstr.next 
#define dbg_SRCLINE(n)
#define dbg_CONTEXTSW(n) trctop=(&trcstr)

#define dbg_RTNDEF(debugon, fn, sl, el, fp, esl, bpa)


#else

/*================ standard compile mode =================*/
/*-- At least rtn registration in all cases. We also need the check for
 *-- defineframe_flag in case the routine gets called to define the
 *-- frame (shouldn't happen; check in DS.INIT.R)
 */


#define dbg_RTNPROLOG(rname) \
		trcstr.rtnname = rname; \
		trcstr.pprte = &staticprte;\
		trcstr.curline = 0;\
		if (dbg_special) { \
		  if (dbg_definertn_flag) goto dbg_defrtn_lbl; \
		  if (dbg_defineframe_flag) goto dbg_defrtn_lbl; \
		} ; \
		trcstr.next = trctop;   \
		trctop = (&trcstr)

#define dbg_RTNEPILOG trctop=trcstr.next 

#define dbg_SRCLINE(n) 

#define dbg_CONTEXTSW(n) trctop=(&trcstr)

#define dbg_RTNDEF(debugon, fn, sl, el, fp, esl, bpa)\
		if (staticprte || tried_to_reg) return; \
		dbg_special=0; \
      		tried_to_reg=1; \
		staticprte=HRT_NEW_F(debugon, trcstr.rtnname ,\
			  HUNIX_STRING_F(fn),sl,el,fp,esl,bpa); \
		dbg_special=1

#endif
#endif
#endif


/*------------------------ common macros --------------------------*/

  /*** currently no action needed; vars go with rtn descriptor ***/
#define dbg_FRAMEDEF 

 /*** DEFVAR and DEFGLB are needed for SIMDEBUG and SIMTRACE case.
 * Also for ADDVAR: We must turn off the defineframe_flag to get the
 * real work don in the ADDVAR call. Otherwise it will just try to define
 * the frame for ADDVAR. Actually we can just toggle dbg_special.
 * We pass in FRAMEBASE seperately (&trcstr) since SAVED vars must not get
 * framebase subtracted.
 */
#define dbg_DEFVAR(vname,addr,mode, ndim, type) \
		dbg_special=0; \
		HDS_ADDVAR_R(staticprte, HUNIX_STRING_F(vname), \
		  addr, dbg_FRAMEBASE, mode, ndim, type);\
		dbg_special=1

 /*** for globals dbg_defineframe_flag is not set anyway. We cannot enclose
 * the ADDVAR call with flag=0, flag=1 since setting the flag 'back to 1'
 * will result in no routine doing anything anymore.
 * Passed in framebase = global !!!! Must be in the same segment for Windows!!
 */
#define dbg_DEFGLB(vname,addr,mode, ndim, type)  \
		HDS_ADDVAR_R(staticprte, HUNIX_STRING_F(vname), \
			addr, (S_P)global, mode, ndim, type)


  /************** entity declarations *************/
#define dbg_DCLATT(name, offset, pack, tc)  \
	HEDS_DCLATTR_R(HUNIX_STRING_F(name), offset, pack, tc)
#define dbg_DCLENT(name, cid)   HEDS_DCLENT_R(HUNIX_STRING_F(name), cid)

  /*************** for preamble_dbginit ********************/
#define dbg_PREDEFS     void *staticprte; void *dclptr

#define dbg_PRE_INIT(debugon, rname, fname, sl, el) \
		staticprte=HRT_MKPRE_F(debugon, HUNIX_STRING_F(fname),sl,el); \
		HDS_MKPRE_F(staticprte)


  /************** static BPA (per file) ********************/

/*-- +3: for safety */


#define dbg_DEFBPA(n) static char *getdbgbpa(){ \
      static char dbgbpa[n+3] = {'\0'}; return dbgbpa; } \
      static void dbg_bpcall(){HSSDB_BPCALL_R();}



#endif /* __SIMCOM_H__ */
