0

Hi People,
I have been given to work on this program written some 15 years ago for data acquisition but i cannot figure out how to get this to compile as i am getting a lot of compilation errors.
Any insight would be highly appriciated.
Thanks in advance
argus

#define CS_USR_HOME
#define SPIKE_TIME_ARRAY_SIZE  1
#define EVENT_TIME_ARRAY_SIZE  1

#include <dos.h>
#include <string.h>
#include <conio.h>
#include <memory.h>
#include <time.h>
#include <math.h>
#include <stdlib.h>
#include <CMN_g.h>
#include <DACQ_g.h>
#include <clock_g.h>
#include <UI_g.h>
#include <CC_g.h>
#include <UFF_g.h>
#include "su_g.h"
#include "su_defs.h"
#include "su_types.h"
#include "su_vars.h"
#include "su_fref.h"
#include "su_ui.h"
#include "cs_l.h"
#include "tm__defs.h"   /* specific for this clocked sequence */
#include "tm__vars.h"   /* specific for this clocked sequence */
#include "tm__fref.h"   /* specific for this clocked sequence */

static int Template(int);
static int LickCS(int);

SEQUENCE_CONTROL_BLOCK	
			sequence_cb[] = {
			0,0L,0L,Template,		/* SEQUENCE 0 - not started from Keyboard */
			0,0L,0L,LickCS,  		/* SEQUENCE 1 */
			};
						
int nnum_clocked_sequences = 2;

static char *module = "cs_usr.c";
static char *version = "$Revision:   1.5  $$Date:   16 Sep 1988 18:30:48  $";


/*============== Start of functions for the Clocked Sequences ==============*/

int Template( int nprocessing_state )
/* This function is clocked sequence #0.
 * It is meant for a starting place for users to write a new clocked sequence.
 * It will just BEEP the computer speaker 3 times at two second intervals.
 */

{
    static int ncounter;

#define SECOND_STATE      2


    switch (nprocessing_state){

    case INITIAL_STATE:
        UI_Beep();
	ncounter = 0;
	vCS_SetNextState( SECOND_STATE , 2000L );
        break;

    case SECOND_STATE:
        UI_Beep();
        ncounter++;
	if (ncounter >1){
            vCS_SetNextState( TERMINATION_STATE , 1L );
        }
	break;

    case TERMINATION_STATE:
        UI_DisplayError(UI_NOTICE, "All done with the Template Sequence",
 	              "               Please hit RETURN                 ");
        vCS_SetNextState( IDLE_STATE, 0L);
	break;

    default:   /* this one should never never be executed */
        UI_DisplayError(UI_ERROR, "Clocked Sequence Error",
		        "  Template Sequence hit Default State       ");
        return(-1);   /* this will abort the sequence */
        break;
    }

    return(0);
}
/*======================================================================*/

int LickCS(int nprocessing_state)
{

	#define WATER_ON_STATE			2
	#define WATER_OFF_STATE			3	
	#define PROCESS_KEYS_STATE		4
	#define CLEAN_UP_STATE			5
	#define PULSE_STATE				6
	#define PREP_ON_STATE			7
	#define PREP_OFF_STATE			8

static int dis_track;

	/* register int i; */
	static int vidstart = 0;

	dwcurrent_time = (DWORD)lCTM05TSRead();
		
	switch( nprocessing_state ) {

		case INITIAL_STATE:
			if( vidstart ) {
				vCS_SetNextState( wstate, NO_DELAY );
				break;
			}
			if( !bfile_open ) {
        		UI_DisplayError( UI_ERROR, "  Clocked Sequence Error  ", 
				"         No UFF file open for data storage     " );
				return(-1);
			}
			if( tracker1.wtracker_type == TRACKER_NONE ){
				UI_DisplayError( UI_ERROR, " Tracker Test CS ",
				" No Tracker Type defined in Setup Editor " );
				return(-1);
			}
			if( wnum_user_windows < MAXWINDOWS ) {
				UI_DisplayError( UI_ERROR, "     User Windows Error         ",
				" Not Enough User Windows Defined in Current Setup File " );
				return(-1);
			}
			if( !init_vars() ) {
				UI_DisplayError( UI_ERROR, "     Random Times List Error         ",
				"   D:\\TALI\\RANDOM.TXT Does Not EXIST   " );
				return(-1);
			}

			vSU_DrawBox( user_windows[0].box, BLUE );
			vSU_DrawBox( user_windows[1].box, RED );
			vSU_DrawBox( user_windows[2].box, GREEN );

			sprintf(szprompt_buf,"Water ON = %lu mins; Water OFF = %lu mins; Pulses Each Water ON = %u; Pulse Duration = %u msec (y/n)?",
	        		 duration.dwh2o_on, duration.dwh2o_off, count.nh2o_pulse, duration.wh2o_pulse);
			nUI_Query(szprompt_buf, szuser_resp, 1, 0, 0);
			if( RESPONSE_IS_NO ) {
				while( prompt_user() ) 
					continue;
			}

			duration.wh2o_pulse *= CLOCK_SOURCE;
			duration.dwh2o_on *= BWMINS;
			duration.dwh2o_off *= BWMINS;

			do {
				sprintf(szprompt_buf,"Does Thalner Time on Monitor Read \"00:00:00.01\" (y/n)?");
				nUI_Query(szprompt_buf, szuser_resp, 1, 0, 0);
				vidstart = RESPONSE_IS_YES ? 1 : 0;
			}while( !RESPONSE_IS_YES && !RESPONSE_IS_NO );

			if( vidstart ) {
				if( nVideoStart() ) {
       				UI_DisplayError( UI_ERROR, "  Clocked Sequence Error  ",
						"         Thalner Reset Error                   " );
					return(-1);					
				}
			}
			else {
				UI_DisplayError( UI_NOTICE, " Turn Thalner OFF and ON Now To Reset It ",
						"  Hit Return and Ctrl-F1 to Restart Clocked Sequence  ");
				vCS_SetNextState( IDLE_STATE, TIME_DELAY );
				break;
			}

			SU_BhvFlagPrc("_B");
			wstate = KEYS;

			/* 
			 * User Window 1
			 */
			vst_color( screen->handle, npos_text_color );
			sprintf( szpos_out_buff, "WON = %3d  WOF = %3d  AP = %3d  MP = %3d  LI = %4d",
			         count.nh2o_on, count.nh2o_off, npulse_num, nmanual, list_index);
			v_gtext(screen->handle , user_windows[1].work[0], 
					user_windows[1].work[1], szpos_out_buff);
			/*
			 * User Window 2
			 */
			vst_color( screen->handle, npos_text_color );
			sprintf( szpos_out_buff, PERIODNULL );
			v_gtext(screen->handle, user_windows[2].work[0], 
					user_windows[2].work[1], szpos_out_buff);

			vCS_SetNextState( PROCESS_KEYS_STATE, TIME_DELAY );

    	dis_track = 1;

			break;

		case PREP_ON_STATE:
			dwstart_time = tdr_buff.dwtime_stamp = dwlast_time = dwcurrent_time;
			list_index = CAL_INDEX;
			STORE_EF('W','N');
			itoa(++count.nh2o_on, tdr_buff.sztdr_data[WATER], 10);
			nUffIt((WORD*)&tdr_buff);
			npulse_num = 0;			
			wstate = H2O_ON;

			/* 
			 * User Window 1
			 */
			vst_color( screen->handle, npos_text_color );
			sprintf( szpos_out_buff, "WON = %3d  WOF = %3d  AP = %3d  MP = %3d  LI = %4d",
			         count.nh2o_on, count.nh2o_off, npulse_num, nmanual, list_index);
			v_gtext(screen->handle , user_windows[1].work[0], 
					user_windows[1].work[1], szpos_out_buff);
			/*
			 * User Window 2
			 */
			vst_color( screen->handle, npos_text_color );
			sprintf( szpos_out_buff, PERIOD1 );
			v_gtext(screen->handle, user_windows[2].work[0], 
					user_windows[2].work[1], szpos_out_buff);

			vCS_SetNextState( wstate, TIME_DELAY );
			break;

		case WATER_ON_STATE:
			if( nlast_keystroke ) {
				vCS_SetNextState( PROCESS_KEYS_STATE, TIME_DELAY );
				break;
			}
			if( ELAPSED_TIME < duration.dwh2o_on )
				if( PULSE_NUM && PULSE_TIME )
					vCS_SetNextState( PULSE_STATE, NO_DELAY );
				else
					vCS_SetNextState( wstate, TIME_DELAY );
			else
				vCS_SetNextState( PREP_OFF_STATE, TIME_DELAY );

      if ( dis_track ) {
				vst_color( screen->handle, npos_text_color );
				sprintf(szpos_out_buff, "x:%3d  y:%3d", tracker1.wx1, tracker1.wy1);
				v_gtext(screen->handle, user_windows[0].work[0],user_windows[0].work[1], 
						szpos_out_buff);
				dis_track = 0;
			}
			else
				dis_track = 1;
			
			break;

		case PULSE_STATE:
			(void)nUFF_FlushBuffer(huff_filehandle);
			nCTM05_VarDutyClockOutputInit(3, COUNT_PERIOD_100US, FALSE, 3, duration.wh2o_pulse, 0);
			STORE_EF('A','P');
			nCTM05_VarDutyClockOutputStart(3);
			++npulse_num;
			++list_index;					
			dwlast_time = dwcurrent_time;

			/* 
			 * User Window 1
			 */
			vst_color( screen->handle, npos_text_color );
			sprintf( szpos_out_buff, "WON = %3d  WOF = %3d  AP = %3d  MP = %3d  LI = %4d",
			         count.nh2o_on, count.nh2o_off, npulse_num, nmanual, list_index);
			v_gtext(screen->handle , user_windows[1].work[0], 
					user_windows[1].work[1], szpos_out_buff);
			/*
			 * User Window 2
			 */
			vst_color( screen->handle, npos_text_color );
			if( nlastkey < 0 )
				sprintf( szpos_out_buff, CTRLS );
			else if( wstate == H2O_ON )
				sprintf( szpos_out_buff, PERIOD1 );
			else if( wstate == H2O_OFF )
				sprintf( szpos_out_buff, PERIOD0 );
			else
				sprintf( szpos_out_buff, PERIODNULL );
			v_gtext(screen->handle, user_windows[2].work[0], 
					user_windows[2].work[1], szpos_out_buff);
						
			vCS_SetNextState( wstate, TIME_DELAY );
			break;

		case PREP_OFF_STATE:
			dwstart_time = tdr_buff.dwtime_stamp = dwcurrent_time;
			STORE_EF('W','F');				
			itoa(--count.nh2o_off, tdr_buff.sztdr_data[WATER], 10);
			nUffIt((WORD*)&tdr_buff);			
			wstate = H2O_OFF;							

			/* 
			 * User Window 1
			 */
			vst_color( screen->handle, npos_text_color );
			sprintf( szpos_out_buff, "WON = %3d  WOF = %3d  AP = %3d  MP = %3d  LI = %4d",
			         count.nh2o_on, count.nh2o_off, npulse_num, nmanual, list_index);
			v_gtext(screen->handle , user_windows[1].work[0], 
					user_windows[1].work[1], szpos_out_buff);
			/*
			 * User Window 2
			 */
			vst_color( screen->handle, npos_text_color );
			sprintf( szpos_out_buff, PERIOD0 );
			v_gtext(screen->handle, user_windows[2].work[0], 
					user_windows[2].work[1], szpos_out_buff);

			vCS_SetNextState( wstate, TIME_DELAY );
			break;

		case WATER_OFF_STATE:
			if( nlast_keystroke ) {
				vCS_SetNextState( PROCESS_KEYS_STATE, TIME_DELAY );
				break;
			}
			if( ELAPSED_TIME >= duration.dwh2o_off )
				vCS_SetNextState( PREP_ON_STATE, TIME_DELAY );			
			else
				vCS_SetNextState( wstate, TIME_DELAY );

			if ( dis_track ) {
				vst_color( screen->handle, npos_text_color );
				sprintf(szpos_out_buff, "x:%3d  y:%3d", tracker1.wx1, tracker1.wy1);
				v_gtext(screen->handle, user_windows[0].work[0],user_windows[0].work[1], 
						szpos_out_buff);
				dis_track = 0;
			}
			else
				dis_track = 1;
		
			break;

		case CLEAN_UP_STATE:
			SU_BhvFlagPrc("_E");
			nVideoStop();
			vStopContAD();
			vSU_UFFClose();
			vSU_DrawGSAcqStatus(&gen_status_display, 0);
			vCS_SetNextState( IDLE_STATE, TIME_DELAY );
			break;
			
		case PROCESS_KEYS_STATE:
			switch( nlast_keystroke ) {
				case '&':
				case '$':
					if(nlastkey == -1) {
						wstate = (nlast_keystroke == '$') ? CLEAN_UP : wstate;
						nlastkey = (nlast_keystroke == '&') ? 0 : nlastkey;
					}					
					break;

				case STOP:
					nlastkey = -1;

					/* 
					 * User Window 1
					 */
					vst_color( screen->handle, npos_text_color );
					sprintf( szpos_out_buff, "WON = %3d  WOF = %3d  AP = %3d  MP = %3d  LI = %4d",
			         count.nh2o_on, count.nh2o_off, npulse_num, nmanual, list_index);
					v_gtext(screen->handle , user_windows[1].work[0], 
							user_windows[1].work[1], szpos_out_buff);
					/*
					 * User Window 2
					 */
					vst_color( screen->handle, npos_text_color );
					sprintf( szpos_out_buff, CTRLS );
					v_gtext(screen->handle, user_windows[2].work[0], 
							user_windows[2].work[1], szpos_out_buff);

					break;

				case START_WATER_ON_PERIOD:
				case START_WATER_OFF_PERIOD:
					if(wstate == H2O_ON || wstate == H2O_OFF)
						break;
					wstate = nlast_keystroke == START_WATER_ON_PERIOD ? PREP_ON : PREP_OFF;
					break;

				case BREAK_CYCLE:					
					tdr_buff.dwtime_stamp = dwcurrent_time;
					STORE_EF('B','R');
					itoa(0, tdr_buff.sztdr_data[WATER], 10);
					nUffIt((WORD*)&tdr_buff);
					npulse_num = 0;
					wstate = KEYS;

					/* 
					 * User Window 1
					 */
					vst_color( screen->handle, npos_text_color );
					sprintf( szpos_out_buff, "WON = %3d  WOF = %3d  AP = %3d  MP = %3d  LI = %4d",
			         count.nh2o_on, count.nh2o_off, npulse_num, nmanual, list_index);
					v_gtext(screen->handle , user_windows[1].work[0], 
							user_windows[1].work[1], szpos_out_buff);
					/*
					 * User Window 2
					 */
					vst_color( screen->handle, npos_text_color );
					sprintf( szpos_out_buff, PERIODNULL );
					v_gtext(screen->handle, user_windows[2].work[0], 
							user_windows[2].work[1], szpos_out_buff);

					break;

				case PULSE_DELIVERY:
					nCTM05_VarDutyClockOutputInit(3, COUNT_PERIOD_100US, FALSE, 3, duration.wh2o_pulse, 0);
					SU_BhvFlagPrc("MP");
					nCTM05_VarDutyClockOutputStart(3);
					++nmanual;

					/* 
					 * User Window 1
					 */
					vst_color( screen->handle, npos_text_color );
					sprintf( szpos_out_buff, "WON = %3d  WOF = %3d  AP = %3d  MP = %3d  LI = %4d",
			         count.nh2o_on, count.nh2o_off, npulse_num, nmanual, list_index);
					v_gtext(screen->handle , user_windows[1].work[0], 
							user_windows[1].work[1], szpos_out_buff);
					/*
					 * User Window 2
					 */
					vst_color( screen->handle, npos_text_color );
					if( nlastkey < 0 )
						sprintf( szpos_out_buff, CTRLS );
					else if( wstate == H2O_ON )
						sprintf( szpos_out_buff, PERIOD1 );
					else if( wstate == H2O_OFF )
						sprintf( szpos_out_buff, PERIOD0 );
					else
						sprintf( szpos_out_buff, PERIODNULL );
					v_gtext(screen->handle, user_windows[2].work[0], 
							user_windows[2].work[1], szpos_out_buff);

					break;
			}
			nlast_keystroke = 0;

			if ( dis_track ) {
				vst_color( screen->handle, npos_text_color );
				sprintf(szpos_out_buff, "x:%3d  y:%3d", tracker1.wx1, tracker1.wy1);
				v_gtext(screen->handle, user_windows[0].work[0],user_windows[0].work[1], 
						szpos_out_buff);
				dis_track = 0;
			}
			else
				dis_track = 1;

			vCS_SetNextState(wstate, TIME_DELAY);
			break;
	}
	
	return 0;
	
}

/*=====================================================================*/
/*=====================================================================*/
/*=====================================================================*/
	
int init_vars()
{
	FILE *in;
	register int i;
	char timestring[MAXSTRING];

	if( !(in = fopen("random.txt","rt") ) )  return 0;
	for(i=0; i<LISTSIZE; ++i) {
		do {
			fgets(timestring,MAXSTRING,in);
		}while( !atol(timestring) );
		curval[i] = (DWORD)atol(timestring) * BWMSECS;
	}
	fclose(in);
	
	list_index = npulse_num = nmanual = nlastkey = nlast_keystroke = 0;
	
	count.nh2o_pulse = 100;
	count.nh2o_on = count.nh2o_off = 0;
	duration.wh2o_pulse = 35;	
	duration.dwh2o_on = 15;
	duration.dwh2o_off = 5;

	tdr_buff.ufftype = SU_TDR_REC_UFFTYPE;
	tdr_buff.tdrtype = 0;	
	
	return 1;
}

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

int prompt_user()
{
	int i;

/*
 * Prompt for Duration of Water ON Period
 */
	sprintf(szprompt_buf,"Duration of Water ON Period [%lu mins] ([y]/n)?",
			duration.dwh2o_on);
	nUI_Query(szprompt_buf, szuser_resp, 1, 0, 0);
	while(RESPONSE_IS_NO) {
		sprintf(szprompt_buf,"Duration of Water ON Period [mins] ?");
		i = nUI_Query(szprompt_buf, szuser_resp, 2, 0, 0);
		duration.dwh2o_on = (DWORD)atol(szuser_resp);
		sprintf(szprompt_buf, "Duration of Water ON Period = %lu mins ([y]/n)", 
                duration.dwh2o_on);
	}
/*
 * Prompt for Duration of Water OFF Period
 */
 	sprintf(szprompt_buf,"Duration of Water OFF Period [%lu mins] ([y]/n)?",
			duration.dwh2o_off);
	nUI_Query(szprompt_buf, szuser_resp, 1, 0, 0);
 	while(RESPONSE_IS_NO) {
		sprintf(szprompt_buf,"Duration of Water OFF Period [mins] ?");
		i = nUI_Query(szprompt_buf, szuser_resp, 2, 0, 0);
		duration.dwh2o_off = (DWORD)atol(szuser_resp);
		sprintf(szprompt_buf, "Duration of Water OFF Period = %lu mins ([y]/n)", 
                duration.dwh2o_off);
	}
/*
 * Prompt for Number of Pulses During a Water ON Period
 */
 	sprintf(szprompt_buf,"Number of Pulses for Each Water ON Period [%u] ([y]/n)?",
			count.nh2o_pulse);
	nUI_Query(szprompt_buf, szuser_resp, 1, 0, 0);
 	while(RESPONSE_IS_NO) {
		sprintf(szprompt_buf,"Number of Pulses for Each Water ON Period ?");
		i = nUI_Query(szprompt_buf, szuser_resp, 3, 0, 0);
		count.nh2o_pulse = atoi(szuser_resp);
		sprintf(szprompt_buf, "Number of Pulses for Each Water ON Period = %u ([y]/n)", 
                count.nh2o_pulse);
	}
/*
 * Prompt for Water Pulse Duration
 */
 	sprintf(szprompt_buf,"Water Pulse Duration [%u msec] ([y]/n)?",
			duration.wh2o_pulse);
	nUI_Query(szprompt_buf, szuser_resp, 1, 0, 0);
 	while(RESPONSE_IS_NO) {
		sprintf(szprompt_buf,"Water Pulse Duration [msec] ?");
		nUI_Query(szprompt_buf, szuser_resp, 5, 0, 0);
		duration.wh2o_pulse = (WORD)atoi(szuser_resp);
		sprintf(szprompt_buf, "Water Pulse Duration = %u msec ([y]/n)", 
                duration.wh2o_pulse);
	}
/* 
 * Prompt for final confirmation to accept the above inputs
 */
 	do {
		sprintf(szprompt_buf,"Water ON = %lu mins; Water OFF = %lu mins; Pulses Each Water ON = %u; Pulse Duration = %u msec (y/n)?",
	       		 duration.dwh2o_on, duration.dwh2o_off, count.nh2o_pulse, duration.wh2o_pulse);
		nUI_Query(szprompt_buf, szuser_resp, 1, 0, 0);
	}while(!RESPONSE_IS_YES && !RESPONSE_IS_NO);
	
	if(RESPONSE_IS_NO)  
		return(1);
	else
		return(0);
}

/* ====================================================================== */
/* ====================================================================== */
/* ====================================================================== */
/* ====================================================================== */
/* ====================================================================== */
Attachments
/*==========================================================================
=	
=		Copyright (c) 1988-1994, DataWave Technologies Corporation 
=		___________________________________________________________
=		
=		OWNER:			DACQ Library
=
=		MODULE:			clock_g.h
=		
=		DESCRIPTION:	Header file for functions in DACQ librarys.
=							(clock.c)
=
=		AUTHOR:
=
=		REVISION:		3/11/94, Curt Ketner, broke into modules
=									-added extern of global struct to allow setting of
=									the clock board address
=
=							Rev 1.2	 05 Aug 1988 18:37:12	library
=									-Added new error code for bad timestamp clock.
=									-Added new forward references due to ATLAB
=									dependence elimination.
=
=							Rev 1.1	 17 Mar 1988 14:06:50	library
=									-Added forward reference for new function:
=									VOID vCTM05TSReset()
=
=							8-6-90  library
=									-Initial revision.
=
===========================================================================*/






/***********************************************************************/
/******************************* DEFINES *******************************/
/***********************************************************************/


 
/* bit values for manipulating registers and such    */
#define BIT0       0x0001       /* bit #0 value      */
#define BIT1       0x0002       /* bit #1 value      */
#define BIT2       0x0004       /* bit #2 value      */
#define BIT3       0x0008       /* bit #3 value      */
#define BIT4       0x0010       /* bit #4 value      */
#define BIT5       0x0020       /* bit #5 value      */
#define BIT6       0x0040       /* bit #6 value      */
#define BIT7       0x0080       /* bit #7 value      */
#define BBIT8      0x0100       /* bit #8 value      */
#define BIT9       0x0200       /* bit #9 value      */
#define BIT10      0x0400       /* bit #10 value     */
#define BIT11      0x0800       /* bit #11 value     */
#define BIT12      0x1000       /* bit #12 value     */
#define BIT13      0x2000       /* bit #13 value     */
#define BIT14      0x4000       /* bit #14 value     */
#define BIT15      0x8000       /* bit #15 value     */


/*** local definitions for the CTM05 clock board  ****/
#define CTM05_BASE	  0x0300 	/* base address for the CTM05 clock board 	 */

/* offsets */
#define CTM05DATA_OFFSET  0	/*CTM05 Clock Data port is at the base */
#define CTM05CTL_OFFSET   1	/*CTM05 Clock Control address */
#define CTM05PI_OFFSET	  2	/*CTM05 Parallel Input port */
#define CTM05PO_OFFSET	  3	/*CTM05 Parallel Output port */

/* local definitions for the CTM05 clock board */
/*#define CTM05DATA CTM05_BASE+CTM05DATA_OFFSET*/ /*in su_asm & dacq_asm */ /*CTM05 Clock Data port at base */
/*#define CTM05CTL	CTM05_BASE+CTM05CTL_OFFSET*/  /*in su_asm & dacq_asm */ /*CTM05 Clock Control address */
/*#define CTM05PI	CTM05_BASE+CTM05PI_OFFSET*/	 /*CTM05 Parallel Input port */
/*#define CTM05PO	CTM05_BASE+CTM05PO_OFFSET*/	 /*CTM05 Parallel Output port */

/* local definitions for CTM05 clock chip functions and codes */
#define	COUNTER_1		BIT0
#define	COUNTER_2		BIT1
#define	COUNTER_3		BIT2
#define	COUNTER_4		BIT3
#define	COUNTER_5		BIT4

#define	COUNTER_GROUP_1		1
#define	COUNTER_GROUP_2		2
#define	COUNTER_GROUP_3		3
#define	COUNTER_GROUP_4		4
#define	COUNTER_GROUP_5		5

/* these are the commands used for the CTM05 Control port                   */
#define	MASTER_RESET		0XFF
#define	ENTER_8BIT_MODE		0XE7
#define	ARM_COUNTERS		0X20
#define	LOAD_COUNTERS		0X40
#define	LOAD_AND_ARM_COUNTERS	0X60
#define	SAVE_COUNTERS		0XA0
#define	DISARM_COUNTERS		0XC0
#define	CLEAR_COUNTER_OUTPUT	0XE0
#define	SET_COUNTER_OUTPUT	0XE8
#define GATE_FOUT_ON            0xE6
#define GATE_FOUT_OFF           0xEE

/* internal register pointers used for individual counters on the chip */
#define	MODE_REGISTER		0X00
#define	LOAD_REGISTER		0X08
#define	HOLD_REGISTER		0X10
#define	LOAD_HOLD_REGISTER	0X18
#define	MASTER_MODE_REGISTER	0X17

/* individual counter configuration constants to customize a counter     */
#define	COUNT_SOURCE_PREV_TC	0X00
#define	COUNT_SOURCE_F1		0X0B
#define	COUNT_SOURCE_F2		0X0C
#define	COUNT_SOURCE_F3		0X0D
#define	COUNT_SOURCE_F4		0X0E
#define	COUNT_SOURCE_F5		0X0F
#define	COUNT_REPETITIVELY	0X20
#define	COUNT_UP		0X04
#define	FALLING_EDGE_COUNT	0X10
#define	GATE_TCN_PREV		0X20
#define	GATE_HI_LEVEL_GATE_N	0X80
#define	NO_GATING		0X00
#define	RISING_EDGE_COUNT	0X00
#define	TC_TOGGLE_OUTPUT	0X02
#define	USE_GATING		0X80
#define RELOAD_FROM_LOAD_OR_HOLD 0X40
#define STEP_COUNTER            0XF0

/* constants used for the CTM05 pulse output functions */
#define	COUNT_SOURCE_F1		0X0B
#define	COUNT_SOURCE_F2		0X0C
#define	COUNT_SOURCE_F3		0X0D
#define	COUNT_SOURCE_F4		0X0E
#define	COUNT_SOURCE_F5		0X0F
#define	COUNT_PERIOD_1US	COUNT_SOURCE_F1
#define	COUNT_PERIOD_10US	COUNT_SOURCE_F2
#define	COUNT_PERIOD_100US	COUNT_SOURCE_F3
#define	COUNT_PERIOD_1MS	COUNT_SOURCE_F4
#define	COUNT_PERIOD_10MS	COUNT_SOURCE_F5
#define	COUNT_SOURCE_S1		0X01
#define	COUNT_SOURCE_S2		0X02
#define	COUNT_SOURCE_S3		0X03
#define	COUNT_SOURCE_S4		0X04
#define	COUNT_SOURCE_S5		0X05
#define	COUNT_SOURCE_G1		0X06
#define	COUNT_SOURCE_G2		0X07
#define	COUNT_SOURCE_G3		0X08
#define	COUNT_SOURCE_G4		0X09
#define	COUNT_SOURCE_G5		0X0A

/* Gate Sources which are AND'd with the clock source when setting up a clock -
 * the HL means High-Level; LL means Low-Level; HE means High-Edge; and
 * LE means Low-Edge. 
 */
#define GATE_SOURCE_NO_GATE          0     /* no gating at all */
#define GATE_SOURCE_HL_PREV_CTR_TC   0x20  /* use prev ctr's terminal cnt out*/
#define GATE_SOURCE_HL_NEXT_CTR_GATE 0x40  /* use next ctr's gate input */
#define GATE_SOURCE_HL_PREC_CTR_GATE 0x60  /* use prev ctr's gate input */
#define GATE_SOURCE_HL_CTR_GATE      0x80  /* use this ctr's gate input-HL */
#define GATE_SOURCE_LL_CTR_GATE      0xA0  /* use this ctr's gate input-LL */
#define GATE_SOURCE_HE_CTR_GATE      0xC0  /* use this ctr's gate input-HE */
#define GATE_SOURCE_LE_CTR_GATE      0xE0  /* use this ctr's gate input-LE */

#define	DACQ_BAD_PULSE_OUT_COUNTER	-5
#define	DACQ_BAD_PULSE_COUNT_PERIOD	-6
#define DACQ_PULSE_DURATION_TOO_SMALL	-7
#define DACQ_BAD_CLOCK_NUMBER           -14
#define DACQ_BAD_CLOCK_SOURCE           -15
#define DACQ_BAD_PHASE_COUNT_VALUE		 -16



/* type definition for Time Stamp data from the CTM05TSRead function 		*/
typedef union{
	unsigned char cTS[4];
   int           iTS[2];
   DWORD         lTS;
} TimeStamp;


typedef struct { 
	WORD clk_base;
	WORD clk_data;
	WORD clk_ctl;
	WORD clk_pi;
	WORD clk_po;
}	DACQ_CLOCK_INFO;





/***********************************************************************/
/**************************** GLOBAL VALUES ****************************/
/***********************************************************************/


extern DACQ_CLOCK_INFO DACQ_clk_info;



/***********************************************************************/
/********************** FUNCTION PROTOTYPES ****************************/
/***********************************************************************/

/* function definitions for the MetraByte Clock board clockfunctions*/
void  vCTM05TSInit(void);        /*CTM05 Clock board Init function */
void  vCTM05TSPause(void);       /*CTM05 Clock board Pause function*/
DWORD lCTM05TSRead(void);        /*CTM05 Clock board Read function*/
void  vCTM05TSReset(void);       /*CTM05 Clock time stamp clock reset to zero*/
void  vCTM05TSStart(void);       /*CTM05 Clock board Start/Resume function*/
int   nCTM05TSTest(void);        /*CTM05 Clock board test function */

/* function definitions for the Metrabyte CTM05 PIO port functions */
int  nCTM05PIRead(void);         /*CTM05 Parallel Input port read func*/
void vCTM05POWrite(int);         /*CTM05 Parallel Output port write func*/
int  nCTM05PORead(void);         /*CTM05 PO port read emulation function*/
void vCTM05POResetBits(int);     /* CTM05 Parallel Output port bit Reset func*/
void vCTM05POSetBits(int);       /* CTM05 Parallel Output port bit Set func */

/* function definitions for the Metrabyte CTM05 timed pulse output functions*/
int nCTM05_Pulse_Output_Init(int, int );
int nCTM05_Pulse_Out( int, int );

/* function definitions for the Metrabyte CTM05 variable Duty Output pulse
 * train square wave output */
int nCTM05_VarDutyClockOutputInit( WORD wclock_num, WORD wclock_source, 
                                   BOOL bcontinuous_pulse_train, 
	  		           WORD wphase1_count,
			           WORD wphase2_count,
			           BOOL binitial_output_state);
int nCTM05_VarDutyClockOutputStart( WORD wclock_num );
int nCTM05_VarDutyClockOutputStop( WORD wclock_num, BOOL bfinal_output_state);
int nCTM05_SetClockOutput( WORD wclock_num, BOOL boutput_state );
int nCTM05_ReadClock16( WORD wclock_num , WORD *wvalue_read );
int nCTM05_SetupSingleClock( WORD wclock_num, WORD wmode_reg_hi_byte, 
                                   WORD wmode_reg_low_byte, 
	  		           WORD wload_reg_value,
			           WORD whold_reg_value);
int nCTM05_GateSingleClock( WORD wclock_num, BOOL benable );
int nCTM05_LoadSingleCounter( WORD wclock_num );    


/******** for functions in CLKAUDIO.C *********/
/* function definitions for the Metrabyte CTM05 Audio tone output setup */
void vCTM05_Audio_Init(void);
void vCTM05_Audio_Out (int,int);

/******** for functions in DACQ_ASM.ASM *********/
/* function definitions for the Cpuinterrupt on and off functions */
void vCpuIntOff(void);             /*turn the interrupt flag in cpu off */
void vCpuIntOn(void);              /*turn the interrupt flag in cpu on */
/***************************************************************************
*
*	DataWave Technologies Corporation
* ___________________________________
*
*	Copyright DataWave Technologies Corporation, 1988-1994
* _______________________________________________________
*
*	MODULE:	CMN_G.H
*
*	DESCRIPTION:	common header information
*
*	All software that includes this header file is considered to be
*	protected under the current copyright laws.	The Personal Scientific
*	Workstation, the DataWave software, and the are all considered
*	proprietary and protected by this statement.
*
****************************************************************************/


#ifdef USE_WIN
#include <windows.h>
#endif



/* DataWave-specific datatype definitions */

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

/* common return codes */

#define BW_OK		0
#define BW_FAIL	-1
#define BW_CHECK	1

#define	BW_MAXSTRLEN	80
#define	BW_MAXPATHLEN	128


/* NOTE Previous to MSC 5.1 NULL was defined as 0L, MSC 6.0 now
defines it as ((void *)0)
*/

#define	INULL   0	/* integer 0 */   

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


#ifndef USE_WIN
#define FAR 	far			/* Microsoft 'C' dependency */
#define NEAR near 			/* memory models */
#endif                
                
#ifndef USE_WIN                
#define LONG long  
#define VOID void 
#endif

/* Standard type definitions */

#ifndef USE_WIN
typedef unsigned char		BYTE;
typedef unsigned short int	WORD;
typedef unsigned long int	DWORD;
typedef short int  			BOOL; 
/* typedef int                HANDLE;  */
#endif

typedef short int          SHORT;
typedef float              REAL;
typedef int                HNDL;

#ifndef USE_WIN	
typedef BYTE               *PSTR;
#endif


typedef BYTE				BITFIELD;
typedef VOID			   *PTR;
typedef VOID NEAR		   *NPTR;
typedef VOID FAR		   *FPTR;

#ifndef USE_WIN
typedef BYTE FAR		   *LPBYTE;  
typedef BYTE NEAR		   *NPSTR;
typedef LPBYTE				LPSTR;
typedef short int FAR	   *LPINT;
typedef long FAR		   *LPLONG;
typedef WORD FAR		   *LPWORD;
typedef DWORD FAR		   *LPDWORD;
#endif

typedef BOOL FAR		   *LPBOOL;
typedef REAL FAR		   *LPREAL;


typedef struct tm			TIMEDATE;


typedef struct {
	union {
		short int	minlen;
		short int	iLow;
		WORD		wLow;
		DWORD		dwLow;
		REAL		rLow;
	} low;
	union {
		short int	maxlen;
		short int	iHi;
		WORD		wHi;
		DWORD		dwHi;
		REAL		rHi;
	} hi;
} RANGE;                    

typedef RANGE	   *PRANGE;

typedef RANGE NEAR *NPRANGE;
typedef RANGE FAR  *LPRANGE;
                
                
#ifndef USE_WIN
/* typedef struct Point { */

typedef struct {
	short int	x;
	short int	y;
} POINT;
                
typedef POINT 		   *PPOINT;

typedef POINT NEAR 	   *NPPOINT;
typedef POINT FAR 	   *LPPOINT;

#endif



/* Standard function type definitions */
typedef int (NEAR *NPROC)();
typedef int (FAR  *FPROC)();



/* Macro "functions" */

      
#ifndef USE_WIN
#define MAKELONG(a, b)  ((LONG)(((WORD)a) | ((DWORD)((WORD)b)) << 16))
#define LOWORD(l)       ((WORD)l)
#define HIWORD(l)       ((WORD)(((DWORD)l >> 16) & 0xffff))
#define LOBYTE(w)       ((BYTE)w)
#define HIBYTE(w)       (((WORD)w >> 8) & 0xff)
#endif



/*BER test it out*/
#define WORDHBLB(h,l)   (((WORD)h << 8) & 0xff00) + (WORD)l 


#ifndef USE_WIN
#define MAKEPOINT(l)    (*((PPOINT)&l))
#endif
/***
*conio.h - console and port I/O declarations
*
*	Copyright (c) 1985-1990, Microsoft Corporation.  All rights reserved.
*
*Purpose:
*	This include file contains the function declarations for
*	the MS C V2.03 compatible console and port I/O routines.
*
****/

#if defined(_DLL) && !defined(_MT)
#error Cannot define _DLL without _MT
#endif

#ifdef _MT
#define _FAR_ _far
#else
#define _FAR_
#endif

/* function prototypes */

char _FAR_ * _FAR_ _cdecl cgets(char _FAR_ *);
int _FAR_ _cdecl cprintf(const char _FAR_ *, ...);
int _FAR_ _cdecl cputs(const char _FAR_ *);
int _FAR_ _cdecl cscanf(const char _FAR_ *, ...);
int _FAR_ _cdecl getch(void);
int _FAR_ _cdecl getche(void);
int _FAR_ _cdecl inp(unsigned);
unsigned _FAR_ _cdecl inpw(unsigned);
int _FAR_ _cdecl kbhit(void);
int _FAR_ _cdecl outp(unsigned, int);
unsigned _FAR_ _cdecl outpw(unsigned, unsigned);
int _FAR_ _cdecl putch(int);
int _FAR_ _cdecl ungetch(int);
/*==========================================================================
=	
=		Copyright (c) 1988-1994, DataWave Technologies Corporation 
=		___________________________________________________________
=		
=		OWNER:			DACQ Library
=
=		MODULE:			dacq_g.h
=		
=		DESCRIPTION:	Header file for functions in DACQ librarys.
=
=		AUTHOR:
=                    3/21/94, Curt Ketner, added Global DACQ_errno for
=									handling errors																											
=		REVISION:		
=							3/11/94, Curt Ketner, broke into modules
=
=							Rev 1.0	 26 Feb 1988 11:35:32	library
=									Initial revision.
=
===========================================================================*/



/* bit values for manipulating registers and such    */
#define BIT0       0x0001       /* bit #0 value      */
#define BIT1       0x0002       /* bit #1 value      */
#define BIT2       0x0004       /* bit #2 value      */
#define BIT3       0x0008       /* bit #3 value      */
#define BIT4       0x0010       /* bit #4 value      */
#define BIT5       0x0020       /* bit #5 value      */
#define BIT6       0x0040       /* bit #6 value      */
#define BIT7       0x0080       /* bit #7 value      */
#define BBIT8      0x0100       /* bit #8 value      */
#define BIT9       0x0200       /* bit #9 value      */
#define BIT10      0x0400       /* bit #10 value     */
#define BIT11      0x0800       /* bit #11 value     */
#define BIT12      0x1000       /* bit #12 value     */
#define BIT13      0x2000       /* bit #13 value     */
#define BIT14      0x4000       /* bit #14 value     */
#define BIT15      0x8000       /* bit #15 value     */


/* Interrupt controller register address defines                           */
#define IRQMASTER  0x0020                /* Interrupt Master (low lines)reg*/
#define IRQSLAVE   0x00A0                /* interrupt Slave  (hi lines) reg*/
#define IRQEOI     0x20                  /* interrupt - END of INTERRUPT   */

/* Interrupt Defs for A/D using interrupt line 15  */
#define IRQMASKCSR 0x00A1        /*CSR port of slave 8259 int controller    */
#define IRQ15MASK  0x0080        /*bit for enable/disable of line 15        */
#define DOSISR15SETUP 0x0077       /* vector #77 for line 15    */
#define IRQ10MASK  0x0004        /*bit for enable/disable of line 10        */
#define DOSISR10SETUP 0x0072       /* vector #72 for line 10    */


/* constants used for reading the CMOS real time clock using the bios interrupt
 * 1A.  We will use this to read the real time and date */
#define	TIME_OF_DAY_INTERRUPT	0x1A
#define	READ_CMOS_TIME		2
#define	READ_CMOS_DATE		4
#define	SET_DOS_TIME		0x2D
#define	SET_DOS_DATE		0x2B

                                  
#define DACQ_OK  				0	                                
#define DACQ_FAIL    		-1
#define DACQ_NO_ERR_MSG    1
                                   
                                   
#define DACQ_INIT_READ_ERR	   		-20
#define DACQ_INIT_WRITE_ERR        	-21
#define DACQ_INIT_DFLT_WRITE_ERR   	-22
#define DACQ_SETUP_ALLOC_FAIL_ERR	-23 
                                   
#define DACQ_INIT_SM_ERR 				-24
                                  




/***********************************************************************/
/**************************** GLOBAL VALUES ****************************/
/***********************************************************************/

#ifdef DACQ_INIT_HOME
	int DACQ_errno=0;
#else
	extern int DACQ_errno;
#endif



/******************************************************************/
/************** FUNCTION PROTOTYPES *******************************/
/******************************************************************/

/*** function prototypes for PIO_SET.C ***/
int nDACQ_save_pio_addr_2_file(WORD);
int nDACQ_set_pio_addr_from_file(void);   


/*** function prototypes for CLK_SET.C ***/
int nDACQ_save_clk_addr_2_file(WORD);
int nDACQ_set_clk_addr_from_file(void);  


/*** function prototypes for DACQ_UI.C***/
int nDACQ_do_boards_setup(char *, char *);
/***
*memory.h - declarations for buffer (memory) manipulation routines
*
*	Copyright (c) 1985-1990, Microsoft Corporation.  All rights reserved.
*
*Purpose:
*	This include file contains the function declarations for the
*	buffer (memory) manipulation routines.
*	[System V]
*
****/

#if defined(_DLL) && !defined(_MT)
#error Cannot define _DLL without _MT
#endif

#ifdef _MT
#define _FAR_ _far
#else
#define _FAR_
#endif

#ifndef _SIZE_T_DEFINED
typedef unsigned int size_t;
#define _SIZE_T_DEFINED
#endif


/* function prototypes */

void _FAR_ * _FAR_ _cdecl memccpy(void _FAR_ *, const void _FAR_ *,
	int, unsigned int);
void _FAR_ * _FAR_ _cdecl memchr(const void _FAR_ *, int, size_t);
int _FAR_ _cdecl memcmp(const void _FAR_ *, const void _FAR_ *,
	size_t);
void _FAR_ * _FAR_ _cdecl memcpy(void _FAR_ *, const void _FAR_ *,
	size_t);
int _FAR_ _cdecl memicmp(const void _FAR_ *, const void _FAR_ *,
	unsigned int);
void _FAR_ * _FAR_ _cdecl memset(void _FAR_ *, int, size_t);
void _FAR_ _cdecl movedata(unsigned int, unsigned int, unsigned int,
	unsigned int, unsigned int);


/* model independent function prototypes */

void _far * _far _cdecl _fmemccpy(void _far *, const void _far *,
	int, unsigned int);
void _far * _far _cdecl _fmemchr(const void _far *, int, size_t);
int _far _cdecl _fmemcmp(const void _far *, const void _far *,
	size_t);
void _far * _far _cdecl _fmemcpy(void _far *, const void _far *,
	size_t);
int _far _cdecl _fmemicmp(const void _far *, const void _far *,
	unsigned int);
void _far * _far _cdecl _fmemset(void _far *, int, size_t);
/***
*string.h - declarations for string manipulation functions
*
*	Copyright (c) 1985-1990, Microsoft Corporation.  All rights reserved.
*
*Purpose:
*	This file contains the function declarations for the string
*	manipulation functions.
*	[ANSI/System V]
*
****/

#if defined(_DLL) && !defined(_MT)
#error Cannot define _DLL without _MT
#endif

#ifdef _MT
#define _FAR_ _far
#else
#define _FAR_
#endif

#ifndef _SIZE_T_DEFINED
typedef unsigned int size_t;
#define _SIZE_T_DEFINED
#endif

/* function prototypes */

void _FAR_ * _FAR_ _cdecl memccpy(void _FAR_ *, const void _FAR_ *,
	int, unsigned int);
void _FAR_ * _FAR_ _cdecl memchr(const void _FAR_ *, int, size_t);
int _FAR_ _cdecl memcmp(const void _FAR_ *, const void _FAR_ *,
	size_t);
int _FAR_ _cdecl memicmp(const void _FAR_ *, const void _FAR_ *,
	unsigned int);
void _FAR_ * _FAR_ _cdecl memcpy(void _FAR_ *, const void _FAR_ *,
	size_t);
void _FAR_ * _FAR_ _cdecl memmove(void _FAR_ *, const void _FAR_ *,
	size_t);
void _FAR_ * _FAR_ _cdecl memset(void _FAR_ *, int, size_t);
void _FAR_ _cdecl movedata(unsigned int, unsigned int, unsigned int,
	unsigned int, unsigned int);
char _FAR_ * _FAR_ _cdecl strcat(char _FAR_ *, const char _FAR_ *);
char _FAR_ * _FAR_ _cdecl strchr(const char _FAR_ *, int);
int _FAR_ _cdecl strcmp(const char _FAR_ *, const char _FAR_ *);
int _FAR_ _cdecl strcmpi(const char _FAR_ *, const char _FAR_ *);
int _FAR_ _cdecl strcoll(const char _FAR_ *, const char _FAR_ *);
int _FAR_ _cdecl stricmp(const char _FAR_ *, const char _FAR_ *);
char _FAR_ * _FAR_ _cdecl strcpy(char _FAR_ *, const char _FAR_ *);
size_t _FAR_ _cdecl strcspn(const char _FAR_ *, const char _FAR_ *);
char _FAR_ * _FAR_ _cdecl strdup(const char _FAR_ *);
char _FAR_ * _FAR_ _cdecl _strerror(const char _FAR_ *);
char _FAR_ * _FAR_ _cdecl strerror(int);
size_t _FAR_ _cdecl strlen(const char _FAR_ *);
char _FAR_ * _FAR_ _cdecl strlwr(char _FAR_ *);
char _FAR_ * _FAR_ _cdecl strncat(char _FAR_ *, const char _FAR_ *,
	size_t);
int _FAR_ _cdecl strncmp(const char _FAR_ *, const char _FAR_ *,
	size_t);
int _FAR_ _cdecl strnicmp(const char _FAR_ *, const char _FAR_ *,
	size_t);
char _FAR_ * _FAR_ _cdecl strncpy(char _FAR_ *, const char _FAR_ *,
	size_t);
char _FAR_ * _FAR_ _cdecl strnset(char _FAR_ *, int, size_t);
char _FAR_ * _FAR_ _cdecl strpbrk(const char _FAR_ *,
	const char _FAR_ *);
char _FAR_ * _FAR_ _cdecl strrchr(const char _FAR_ *, int);
char _FAR_ * _FAR_ _cdecl strrev(char _FAR_ *);
char _FAR_ * _FAR_ _cdecl strset(char _FAR_ *, int);
size_t _FAR_ _cdecl strspn(const char _FAR_ *, const char _FAR_ *);
char _FAR_ * _FAR_ _cdecl strstr(const char _FAR_ *,
	const char _FAR_ *);
char _FAR_ * _FAR_ _cdecl strtok(char _FAR_ *, const char _FAR_ *);
char _FAR_ * _FAR_ _cdecl strupr(char _FAR_ *);
size_t _FAR_ _cdecl strxfrm (char _FAR_ *, const char _FAR_ *,
	size_t);

/* model independent function prototypes */

void _far * _far _cdecl _fmemccpy(void _far *, const void _far *,
	int, unsigned int);
void _far * _far _cdecl _fmemchr(const void _far *, int, size_t);
int _far _cdecl _fmemcmp(const void _far *, const void _far *,
	size_t);
void _far * _far _cdecl _fmemcpy(void _far *, const void _far *,
	size_t);
int _far _cdecl _fmemicmp(const void _far *, const void _far *,
	unsigned int);
void _far * _far _cdecl _fmemmove(void _far *, const void _far *,
	size_t);
void _far * _far _cdecl _fmemset(void _far *, int, size_t);
char _far * _far _cdecl _fstrcat(char _far *, const char _far *);
char _far * _far _cdecl _fstrchr(const char _far *, int);
int _far _cdecl _fstrcmp(const char _far *, const char _far *);
int _far _cdecl _fstricmp(const char _far *, const char _far *);
char _far * _far _cdecl _fstrcpy(char _far *, const char _far *);
size_t _far _cdecl _fstrcspn(const char _far *, const char _far *);
char _far * _far _cdecl _fstrdup(const char _far *);
char _near * _far _cdecl _nstrdup(const char _far *);
size_t _far _cdecl _fstrlen(const char _far *);
char _far * _far _cdecl _fstrlwr(char _far *);
char _far * _far _cdecl _fstrncat(char _far *, const char _far *,
	size_t);
int _far _cdecl _fstrncmp(const char _far *, const char _far *,
	size_t);
int _far _cdecl _fstrnicmp(const char _far *, const char _far *,
	size_t);
char _far * _far _cdecl _fstrncpy(char _far *, const char _far *,
	size_t);
char _far * _far _cdecl _fstrnset(char _far *, int, size_t);
char _far * _far _cdecl _fstrpbrk(const char _far *,
	const char _far *);
char _far * _far _cdecl _fstrrchr(const char _far *, int);
char _far * _far _cdecl _fstrrev(char _far *);
char _far * _far _cdecl _fstrset(char _far *, int);
size_t _far _cdecl _fstrspn(const char _far *, const char _far *);
char _far * _far _cdecl _fstrstr(const char _far *,
	const char _far *);
char _far * _far _cdecl _fstrtok(char _far *, const char _far *);
char _far * _far _cdecl _fstrupr(char _far *);
/***
*time.h - definitions/declarations for time routines
*
*	Copyright (c) 1985-1990, Microsoft Corporation.  All rights reserved.
*
*Purpose:
*	This file contains the various declarations and definitions
*	for the time routines.
*	[ANSI/System V]
*
****/

#if defined(_DLL) && !defined(_MT)
#error Cannot define _DLL without _MT
#endif

#ifdef _MT
#define _FAR_ _far
#else
#define _FAR_
#endif

/* implementation defined time types */

#ifndef _TIME_T_DEFINED
typedef long time_t;
#define _TIME_T_DEFINED
#endif

#ifndef _CLOCK_T_DEFINED
typedef long clock_t;
#define _CLOCK_T_DEFINED
#endif

#ifndef _SIZE_T_DEFINED
typedef unsigned int size_t;
#define _SIZE_T_DEFINED
#endif

/* structure for use with localtime(), gmtime(), etc. */

#ifndef _TM_DEFINED
struct tm {
	int tm_sec;	/* seconds after the minute - [0,59] */
	int tm_min;	/* minutes after the hour - [0,59] */
	int tm_hour;	/* hours since midnight - [0,23] */
	int tm_mday;	/* day of the month - [1,31] */
	int tm_mon;	/* months since January - [0,11] */
	int tm_year;	/* years since 1900 */
	int tm_wday;	/* days since Sunday - [0,6] */
	int tm_yday;	/* days since January 1 - [0,365] */
	int tm_isdst;	/* daylight savings time flag */
	};
#define _TM_DEFINED
#endif


/* define NULL pointer value */

#ifndef NULL
#if (_MSC_VER >= 600)
#define NULL	((void *)0)
#elif (defined(M_I86SM) || defined(M_I86MM))
#define NULL	0
#else
#define NULL	0L
#endif
#endif


/* clock ticks macro - ANSI version */

#define CLOCKS_PER_SEC	1000

/* clock ticks macro - archaic version */

#define CLK_TCK 	1000


/* extern declarations for the global variables used by the ctime family of
 * routines.
 */

#ifdef _DLL
extern int _FAR_ _cdecl daylight;     /* non-zero if daylight savings time is used */
extern long _FAR_ _cdecl timezone;    /* difference in seconds between GMT and local time */
extern char _FAR_ * _FAR_ _cdecl tzname[2]; /* standard/daylight savings time zone names */
#else
extern int _near _cdecl daylight;     /* non-zero if daylight savings time is used */
extern long _near _cdecl timezone;    /* difference in seconds between GMT and local time */
extern char * _near _cdecl tzname[2]; /* standard/daylight savings time zone names */
#endif


/* function prototypes */

#ifdef _MT
double _FAR_ _pascal difftime(time_t, time_t);
#else
double _FAR_ _cdecl difftime(time_t, time_t);
#endif

char _FAR_ * _FAR_ _cdecl asctime(const struct tm _FAR_ *);
char _FAR_ * _FAR_ _cdecl ctime(const time_t _FAR_ *);
clock_t _FAR_ _cdecl clock(void);
struct tm _FAR_ * _FAR_ _cdecl gmtime(const time_t _FAR_ *);
struct tm _FAR_ * _FAR_ _cdecl localtime(const time_t _FAR_ *);
time_t _FAR_ _cdecl mktime(struct tm _FAR_ *);
size_t _FAR_ _cdecl strftime(char _FAR_ *, size_t, const char _FAR_ *,
	const struct tm _FAR_ *);
char _FAR_ * _FAR_ _cdecl _strdate(char _FAR_ *);
char _FAR_ * _FAR_ _cdecl _strtime(char _FAR_ *);
time_t _FAR_ _cdecl time(time_t _FAR_ *);
void _FAR_ _cdecl tzset(void);
/****************************************************************************
 * Function protoypes and macros header file for Lickn Clock		    *
 * Sequence written for Tali Mittler by Fred Gee on 16-June-92		    *
 *					REVISED: 16-June-92		    *
 ****************************************************************************/

	/* functions that are defined OUTSIDE of the cs_usr.c file */
void SU_BhvFlagPrc( char[] );
int nVideoStart(void);
int nVideoStop(void);

	/* functions that are defined INSIDE of the cs_usr.c file */
static int init_vars(void);
static int prompt_user(void);

		/*			Macros			*/
#define NOT_VALID_RESPONSE (toupper(szuser_resp[0]) != (BYTE)'Y' && toupper(szuser_resp[0]) != (BYTE)'N')
#define RESPONSE_IS_YES ( toupper(szuser_resp[0]) == (BYTE)'Y' )
#define RESPONSE_IS_NO  ( toupper(szuser_resp[0]) == (BYTE)'N' )
#define ELAPSED_TIME	(dwcurrent_time - dwstart_time)
#define PULSE_TIME	(dwcurrent_time - dwlast_time >= *(curval + list_index))
#define PULSE_NUM	(npulse_num < count.nh2o_pulse)
#define CAL_INDEX (count.nh2o_on % (LISTSIZE / count.nh2o_pulse) * count.nh2o_pulse - list_index + list_index)
#define STORE_EF(a,b) weflag_values = a + (b << 8);\
ef_ring_ptr = (SU_EF_REC*)lpSU_OpenRingRBforWrite(ef_ring_buff);\
ef_ring_ptr->ufftype = (BYTE)SU_EF_REC_UFFTYPE;\
ef_ring_ptr->unit = 0;\
ef_ring_ptr->dwtime_stamp = dwcurrent_time;\
*((WORD*)ef_ring_ptr->ef_values) = weflag_values;\
vSU_CloseRBforWrite( ef_ring_buff )


int nVideoStart()
{

	static DWORD dwstart_time;
	static SHORT i;
	static SHORT ncurr_output_port;
	
	vStopContAD();
	bacq_on = FALSE;
	/* Since the time stamp is reset to zero, any UFF file which has
	 * had data written to it would have multiple zero points.  Therefore
	 * the opened UFF file will be reset to assure only one zero point.
	 * However, since any data will be lost, the program will first query
	 * the user if this is truly what is desired.  If not, the sequence
	 * will be stoped here to allow the user to open a new file
	 */
	UI_DisplayError( UI_WARNING, "UFF file will be reset",
		"All existing data in UFF file will be ERASED");
	sprintf( szprompt_buf, 
		"Continue using existing UFF file? ([Y]/N):");
	i=nUI_Query( szprompt_buf, szuser_resp, 1,0,0);
	if (i==1 && (toupper(szuser_resp[0]) != (BYTE)'Y')){
		UI_DisplayError( UI_NOTICE, "User termination of Clocked Sequence",
			"Open new UFF file and restart");
		return( 1);
	}
	nSU_ResetUFFFile();	/* make sure UFF file is empty */
	vSU_RecordingOn();	/* turn on recording to UFF file */
	vSU_DrawGSAcqStatus(&gen_status_display, bacq_on);  /*draw status*/

	SU_BhvFlagPrc("VS");	/* UFF flag signifying video start */
		
	/* Setup clock 5 to use 10KHz clock (same clock as used by time stamp)
	 * to run as a single pulse with a .3 msec off followed by a 100 msec 
	 * on period (multiplied by 10 to account for 1/10's of msec, starting 
	 * with the low period.
	 */
	nCTM05_VarDutyClockOutputInit(5, COUNT_PERIOD_100US, FALSE, 3, 1000, 0);
	nCTM05_VarDutyClockOutputStart(5);
	
	/* pause for 200 msec */
	dwstart_time=lCTM05TSRead();
	while (lCTM05TSRead() < dwstart_time+2000);
	
	/* turn on BIT 1 (START) of PIO expansion board portA. */
/*	nPIO12Write(PORTA, BIT1);*/
	/* turn on BIT 6 (START) of DT2821 expansion board (PORT 1). */
	ncurr_output_port = (nDT2821_pio_read() & 0xFF00);	/* read PORT 1 (0xFF00) */
	/* leave current values high and turn BIT6 high (or the current values with BIT6 */
	vDT2821_pio_write (ncurr_output_port | BIT6); 
	
	/* pause for 100 msec */
	dwstart_time=lCTM05TSRead();
	while (lCTM05TSRead() < dwstart_time+1000);

	nCTM05_VarDutyClockOutputStart(5);

	/* pause for 200 msec */
	dwstart_time=lCTM05TSRead();
	while (lCTM05TSRead() < dwstart_time+2000);

/*	nPIO12Write(PORTA, 0); /* PORTA, 0 = turn off everything on porta */
	/* turn off BIT 6 (START) of DT2821 expansion board (PORT 1). */
	ncurr_output_port = (nDT2821_pio_read() & 0xFF00);	/* read PORT 1 (0xFF00) */
	/* exclusive or the current values with BIT 6 (if current values BIT 6 is
	 * also high, BIT 6 will now be set to low
	 */
	vDT2821_pio_write (ncurr_output_port ^ BIT6);

	/* pause for 100 msec */
	dwstart_time=lCTM05TSRead();
	while (lCTM05TSRead() < dwstart_time+1000);

	/* turn on port 0 (CLEAR) of PIO expansion board portA */
/*	nPIO12Write(PORTA, BIT0);*/
	/* turn on BIT 7 (CLEAR) of DT2821 expansion board (PORT 1). */
	ncurr_output_port = (nDT2821_pio_read() & 0xFF00);	/* read PORT 1 (0xFF00) */
	/* leave current values high and turn BIT7 high (or the current values with BIT7 */
	vDT2821_pio_write (ncurr_output_port | BIT7); 


	/* pause for 100 msec */
	dwstart_time=lCTM05TSRead();
	while (lCTM05TSRead() < dwstart_time+1000);

	/* leave PIO expansion portA BIT0 high and turn BIT1 high */
/*	nPIO12Write(PORTA, BIT0 | BIT1);*/
	/* turn on BIT 6 (START) of DT2821 expansion board (PORT 1). */
	ncurr_output_port = (nDT2821_pio_read() & 0xFF00);	/* read PORT 1 (0xFF00) */
	/* leave current values high and turn BIT6 high (or the current values with BIT6 */
	vDT2821_pio_write (ncurr_output_port | BIT6); 

	/* pause for 90 msec */
	dwstart_time=lCTM05TSRead();
	while (lCTM05TSRead() < dwstart_time+900);

	/* one pulse has already been sent to the thalner and its count now
	 * reads 00:00:00.01.  Therefore, brainwave's time stamp must be
	 * started 10 msec before the synch pulse to the thanlner is started.
	 * The synch pulse will start the thalner counting in 10 msec intervals
	 */
	vCTM05TSReset();	/* reset time stamp to 0.00 */
	vCTM05TSStart();

	/* pause for 10 msec */
	dwstart_time=lCTM05TSRead();
	while (lCTM05TSRead() < dwstart_time+100);

	/* start the synch pulse */
	nCTM05_VarDutyClockOutputInit(5,COUNT_PERIOD_100US, TRUE, 10, 90, 1);
	nCTM05_VarDutyClockOutputStart(5);
	
	nStartContAD();
	bacq_on=TRUE;
	vSU_DrawGSAcqStatus(&gen_status_display, bacq_on);

    return(0);
}


int nVideoStop()
{
	static SHORT ncurr_output_port;

	nCTM05_VarDutyClockOutputStop(5,0);
/*	nPIO12Write(PORTA, BIT0);
	nPIO12Write(PORTA, 0);
*/
	/* turn off BIT 6 (START) of DT2821 expansion board (PORT 1). */
	ncurr_output_port = (nDT2821_pio_read() & 0xFF00);	/* read PORT 1 (0xFF00) */
	/* exclusive or the current values with BIT 6 (if current values BIT 6 is
	 * also high, BIT 6 will now be set to low
	 */
	vDT2821_pio_write (ncurr_output_port ^ BIT6);

	/* turn off BIT 7 (CLEAR) of DT2821 expansion board (PORT 1). */
	ncurr_output_port = (nDT2821_pio_read() & 0xFF00);	/* read PORT 1 (0xFF00) */
	/* exclusive or the current values with BIT 7 (if current values BIT 7 is
	 * also high, BIT 7 will now be set to low
	 */
	vDT2821_pio_write (ncurr_output_port ^ BIT7);

	return (0);
}
/****************************************************************************
 *	Global variable header file for LickDiscrimination Clock Sequence   *
 *	written for Tali Mittler by Fred Gee on 16-June-92		    *
 *			REVISED: 17-June-92				    *
 ***************************************************************************/

	/*	All the counters */
static struct {
	int nh2o_pulse;
	int nh2o_on;
	int nh2o_off;
} count;

	/*	Durations of specific timed events	*/
static struct {
	WORD wh2o_pulse;
	DWORD dwh2o_on;	
	DWORD dwh2o_off;
} duration;

		/* Global variables */
static WORD  weflag_values, wstate = IDLE_STATE;
static DWORD dwstart_time, dwcurrent_time, dwtimer, dwlast_time;
static SU_TDR_REC tdr_buff;
static SU_EF_REC *ef_ring_ptr;
static int npulse_num, nmanual, nlastkey;

	/* 	Variables for writing to the TDRs 	*/
#define WATER		0  /* ...-4,-3,-2,-1,0,1,2,3,4... */

		/* User Window Use */
static COLOR npos_text_color = WHITE;
static char szpos_out_buff[81];


	/* Used for Time List Routine */
static unsigned int list_index;
static DWORD curval[LISTSIZE];
/*============================================================================
=
=	DataWave Technologies Corporation
= __________________________________
=
=	Copyright DataWave Technolgies Corporation 1988-1994
= ______________________________________________________
=
=	All software that includes this file is considered to be
=	protected under the current copyright laws.  The Personal Scientific
=	Workstation, the DataWave software, and the are all considered
=	proprietary and protected by this statement.
= _____________________________________________________________________
=
=	MODULE:			UI_G.H
=
=	DESCRIPTION:	Global header for User Interface library.
=
=		 4/3/1993
==============================================================================*/


/*****************************************************************************/
/************************ RGB COLOR VALUE FILENAME ***************************/
/*****************************************************************************/

#define UI_COLOR_FILE_NAME  "COLORS.DSC"  /* RGB color values filename */

/*****************************************************************************/
/************************* GLOBAL LIMITS   ***********************************/
/*****************************************************************************/

#define UI_MAXSTRLEN  70   /* Maximum error message title length */
#define UI_TITLE_LEN  100  /* Maximum screen window title length */

/*****************************************************************************/
/************************** ERROR CODES   ************************************/
/*****************************************************************************/

#define UI_SUCCESS               0  /* Successful execution */
#define UI_KEYTAG_NOT_FOUND     -1  /* Unable to access security keytag */
#define UI_LOAD_DRIVERS_FAILED  -2  /* Unable to load GSS device drivers */
#define UI_OPEN_SYSTEM_FAILED   -3  /* Unable to open graphics system */
#define UI_OPEN_SCREEN_FAILED   -4  /* Unable to open open screen window */
#define UI_OPEN_WINDOW_FAILED   -5  /* Unable to display screen window */
#define UI_SET_COLORS_FAILED    -6  /* Unable to set color table */
#define UI_DOS_DIR_FAILED       -7  /* Unable to get DOS directory listing */
#define UI_READ_INIT_FAILED     -8  /* Unable to read BNW setup file */

/*****************************************************************************/
/************************** ERROR LEVELS   ***********************************/
/*****************************************************************************/

#define UI_NOTICE   0  /* Notice error - for information only */
#define UI_WARNING  1  /* Warning error - continue execution */
#define UI_ERROR    2  /* Standard error - stop execution but don't abort */
#define UI_FATAL    3  /* Fatal error - stop exection and abort immediately */

/*****************************************************************************/
/*********************** USER INTERFACE COLORS   *****************************/
/*****************************************************************************/

#define UI_DIR_BKGD    BLACK    /* DOS directory background color */
#define UI_DIR_TEXT    LTGREEN  /* DOS directory text color */
#define UI_DIR_BORDER  WHITE    /* DOS directory border color */

#define UI_QUERY_BKGD    LTGREY  /* Query box background color */
#define UI_QUERY_TEXT    BLACK   /* Query box text color */
#define UI_QUERY_BORDER  BLUE    /* Query box border color */

#define UI_ERROR_BKGD    LTRED  /* Error box background color */
#define UI_ERROR_TEXT    WHITE  /* Error box text color */
#define UI_ERROR_TITLE   BLACK  /* Error box title color */
#define UI_ERROR_BORDER  BLUE   /* Error box border color */

#define UI_STATUS_BKGD    LTBLUE  /* Status message background color */
#define UI_STATUS_TEXT    WHITE   /* Status message text color */
#define UI_STATUS_TITLE   LTGREY  /* Status message title color */
#define UI_STATUS_BORDER  RED     /* Status message border color */

/*****************************************************************************/
/******************  VALUES RETURNED FROM VRD_CURKEYS()  *********************/
/*****************************************************************************/

/* Values returned indicating the type of key pressed */
#define UI_KBD_ERROR      -1  /* Some type of error occurred */
#define UI_KBD_NOKEY       0  /* No key was pressed */
#define UI_KBD_CURSORKEY   1  /* A cursor key was pressed */
#define UI_KBD_ASCIIKEY    2  /* An ASCII key was pressed */
#define UI_KBD_FNKEY       3  /* A function key was pressed */
#define UI_KBD_SPECIALKEY  4  /* A "special" key was pressed */

/* Values returned when cursor key pressed (type UI_KBD_CURSORKEY) */
#define UI_CUR_END     1  /* <End> key */
#define UI_CUR_DOWN    2  /* <Down> arrow key */
#define UI_CUR_PGDOWN  3  /* <PgDn> key */
#define UI_CUR_LEFT    4  /* <Left> arrow key */
#define UI_CUR_RIGHT   6  /* <Right> arrow key */
#define UI_CUR_HOME    7  /* <Home> key */
#define UI_CUR_UP      8  /* <Up> arrow key */
#define UI_CUR_PGUP    9  /* <PgUp> key */

/* Values returned when ASCII key pressed (type UI_KBD_ASCIIKEY) */
#define UI_BACKSPACE  8   /* <Backspace> key */
#define UI_ACCEPT     13  /* <Enter> key */
#define UI_CANCEL     27  /* <Esc> key */

/* Values returned when function key pressed (type UI_KBD_FNKEY) */
#define UI_F1   1   /* <F1> key */
#define UI_F2   2   /* <F2> key */
#define UI_F3   3   /* <F3> key */
#define UI_F4   4   /* <F4> key */
#define UI_F5   5   /* <F5> key */
#define UI_F6   6   /* <F6> key */
#define UI_F7   7   /* <F7> key */
#define UI_F8   8   /* <F8> key */
#define UI_F9   9   /* <F9> key */
#define UI_F10  10  /* <F10> key */

/* Values returned when "special" key pressed (type UI_KBD_SPECIALKEY) */
#define UI_DEL  6  /* <Del> key */

/*****************************************************************************/
/**************** CONSTANTS FOR READING CMOS REAL TIME CLOCK   ***************/
/*****************************************************************************/

#define UI_TIME_OF_DAY_INT  0x1A  /* DOS time-of-day interupt */
#define UI_READ_CMOS_TIME   2     /* Used to read current time from CMOS */
#define UI_READ_CMOS_DATE   4     /* Used to read current date from CMOS */
#define UI_SET_DOS_TIME     0x2D  /* Used to set time maintained by DOS */
#define UI_SET_DOS_DATE     0x2B  /* Used to set date maintained by DOS */

/*****************************************************************************/
/************************  GLOBAL VARIABLES  *********************************/
/*****************************************************************************/

#ifdef UI_STATIC_ARRAYS
  /* Declare and initialize UI static arrays */
/*  char huge *UI_drivers; */ /* Pointer to GSS graphics drivers */
  SINT16 nUI_msg_box[4]; /* Message box extents */
  SINT16 nUI_bit_box[4]; /* Message box bitmap extents */
  SINT16 nUI_bit_handle; /* Message box bitmap handle */
  BOOL bUI_bit_created; /* Has the message box bitmap been created ? */
/*  BOOL bUI_Mouse = FALSE; */ /* Is the mouse open ? */
/*  BOOL bUI_DisplayOpen = FALSE; */ /* Is the display open ? */
  SINT16 UI_errx; /* Error box location on X */
  SINT16 UI_erry; /* Error box location on Y */
  SINT16 UI_cellh; /* Character cell heigh */
  SINT16 UI_cellw; /* Character cell width */
  SINT16 UI_ScreenWidth; /* Display screen width */
  SINT16 UI_ScreenHeight; /* Display screen height */

  /* RGB color values for the screen (default if COLORS.DSC is not found) */
  SINT16 color_values[17][3] = {
    0,0,0,          /* Black */
    1000,1000,1000, /* White */
    600,0,0,        /* Red */
    0,600,0,        /* Green */
    0,0,600,        /* Blue */
    600,400,0,      /* Brown */
    0,1000,1000,    /* Cyan */
    600,400,1000,   /* Magenta */
    1000,1000,400,  /* Yellow */
    1000,400,0,     /* Orange */
    600,0,600,      /* Purple */
    600,600,600,    /* Light grey */
    0,400,1000,     /* Light blue */
    1000,0,0,       /* Light red */
    0,1000,0,       /* Light green */
    1000,400,1000,  /* Light magenta */
    400,600,1000 	  /* Used by GSS graphics */
  };

  char szUI_null[1] = {""}; /* Null (zero length) string */
/*  FILE *UI_init_fptr; */ /* BNW setup file pointer */
#else
  /* Declare UI static arrays externally */
/*  extern char huge *UI_drivers; */ /* Pointer to GSS graphics drivers */
  extern SINT16 nUI_msg_box[4]; /* Message box extents */
  extern SINT16 nUI_bit_box[4]; /* Message box bitmap extents */
  extern SINT16 nUI_bit_handle; /* Message box bitmap handle */
  extern BOOL bUI_bit_created; /* Has msg box bitmap been created ? */
/*  extern BOOL bUI_Mouse; */ /* Is the mouse open ? */
/*  extern BOOL bUI_DisplayOpen; */ /* Is the display open ? */
  extern SINT16 UI_errx; /* Error box location on X */
  extern SINT16 UI_erry; /* Error box location on Y */
  extern SINT16 UI_cellh; /* Character cell heigh */
  extern SINT16 UI_cellw; /* Character cell width */
  extern SINT16 UI_ScreenWidth; /* Display screen width */
  extern SINT16 UI_ScreenHeight; /* Display screen height */
  extern SINT16 color_values[17][3];  /* RGB color values for the screen */
  extern char szUI_null[]; /* Null (zero length) string */
/*  extern FILE *UI_init_fptr; */ /* BNW setup file pointer */
#endif

/*****************************************************************************/
/***********************  ALIAS FOR NUI_QUERY  *******************************/
/*****************************************************************************/

/* Alias for nUI_Query() to maintain compatability with clock sequence code */
#define nUI_Query(p,r,l,x,y) nUI_GetTextResponse(p,szUI_null,r,l,x,y)

/*****************************************************************************/
/*************************  FUNCTION PROTOTYPES  *****************************/
 /*****************************************************************************/

/* Function prototype - UI
2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by Ancient Dragon
0

What compiler are you tring to compile it with? And what operating system (version too)? That 15-year-old program was more than likely written with a 16-bit compiler -- especially seeing that it uses old obsolete dos.h header file.

What compiler errors? Or link errors?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.