mlib_h

/*
**	Copyright 1991, Universities Research Association.  All rights reserved.
*/
/******************************************************************************/
/* mlib.h
**
**	This is a the include file for MLIB.C.
**
**	V0.0	B S Hendricks / Accelerator Controls		20-Feb-89
**	Created
**
**	V0.1	B S Hendricks / Accelerator Controls		11-Aug-89
**	Added WRDSPH, WRDSPI, and RDSPx.C routines
*/
/******************************************************************************/

#ifndef MLIB_DEFINED				/* do this only once */
#define	MLIB_DEFINED

#include "pccns.h"
#include "tvlib34.h"

/******************************************************************************/
/* 
**	defined constants
*/
/******************************************************************************/

#define		MAXCHR		10		/* max chars for RDxxxx routines */
#define		DELAY		10		/* return delay for INPUTx routines */
#define		MINMESROW	3		/* min rows for MESWIN */
#define		MINMESCOL	6		/* min columns for MESWIN */
#define		MAX_STRING	60		/* max string length for INPTXT */
#define		FILNAMLEN	13		/* # of chars in a file name */
#define		FILDATLEN	17		/* # of chars in a file date */
#define		MAX_FILES	20		/* max number of opened files */
#define		MAX_REC_SIZ	2048		/* max record size in bytes */
#define		FSID		"FSF"		/* Filesharing file identifier */
#define		READ_ACCESS	1		/* Filesharing read only access */
#define		WRITE_ACCESS	2		/* Filesharing read/write access */
#define		DIRECT		1		/* Filesharing direct access */
#define		SEQUENTIAL	2		/* Filesharing sequential access */
#define		E_O_F		-1L		/* End Of File */

/*	Filesharing routine errors */

#define		INVALID_VUN	-1
#define		CREATE_ERR	-2		/* error creating a file */
#define		OPEN_ERR	-3		/* error opening a file */
#define		NOT_FSHARE	-4		/* not a Filesharing file */
#define		CLOSE_ERR	-5		/* error closing a file */
#define		NOT_OPEN	-6		/* file has not been opened */
#define		FILPOS_ERR	-7		/* error positioning file pointer */
#define		READ_ERR	-8		/* error reading a file */
#define		NO_WRITE	-9		/* file is not opened for write access */
#define		WRITE_ERR	-10		/* error writing a file */
#define		ILLEGAL_ACCESS	-11		/* illegal access for this type of file */
#define		EOF_ERR		-12		/* End Of File error */
#define		REC_NOT_FND	-13		/* record not found */
#define		KEY_MISMATCH	-14		/* indexed record has the wrong key data */
#define		ALREADY_DELETED	-15		/* attempted to delete deleted record */
#define		NO_PREVIOUS	-16		/* noninitialized sequential access */
#define		UNLOCK_ERR	-17		/* error unlocking a file */

/*
	TSLD Interface Board Addresses
*/

#define		BASE		0x300
#define		SLDA0		BASE+0x00	/* Block Transfer NAF */
#define		SLDA1		BASE+0x02	/* Block Transfer Word Count */
#define		SLDA2		BASE+0x04	/* Block Transfer Maximum No Q */
#define		SLDA3		BASE+0x06	/* Arbitration and Crate Address */
#define		SLDA4		BASE+0x08	/* NAF */
#define		SLDA5		BASE+0x0A	/* Write Data - Middle, Low */
#define		SLDA6		BASE+0x0C	/* Write Data - High */
#define		SLDA7		BASE+0x0E	/* Trigger Serial Transmissions */
#define		SLDA8		BASE+0x10	/* Link Driver Status */
#define		SLDA9		BASE+0x12	/* Response Data - Middle, Low */
#define		SLDAA		BASE+0x14	/* Response Data - High */
#define		SLDAB		BASE+0x16	/* TSCC Status */
#define		SLDAC		BASE+0x18	/* TSCC Status and Echo Crate Address */
#define		SLDAD		BASE+0x1A	/* Echo NAF */
#define		PORT_A		0x10

/*
	TSCC Responses
*/

#define		SLD_BUSY	0x8000
#define		Q_X_SRP		0x4000
#define		SLD_NO_Q	0x2000
#define		OP_DENIED	0x1000
#define		ARBCON		0x0800
#define		NO_Q_OR_X	0x0400
#define		TIMEOUT		0x0200
#define		LINK_ERROR	0x0100
#define		RF1CK		0x0080
#define		RF2CK		0x0040
#define		RF3CK		0x0020
#define		CACK		0x0010
#define		NAFCK		0x0008
#define		EDCK		0x0004
#define		PADRV		0x0002
#define		CRLAM		0x0001

#define		NO_X_POSSIBLE	0x9C00

/* TSLD Constants */

#define		MAXRETRY	150
#define		MAXTRY		2
#define		SLD_TIMEOUT	1000
#define		ARB_BITS	0x0C00
#define		CAMAC_WRITE	0x0010

/* Arbitration bits */

#define		SCRA		0x800
#define		SNRA		0x400
#define		SCRB		0x000
#define		SNRB		0x000
#define		RCRB		0x200
#define		RNRB		0x100

#define		DEF_ARB		0x10
#define		DEF_RETRY	3

/* GAS routine defines */

#define		MODULE_170	170
#define		MODULE_080	80
#define		MAX_GAS_LIST	33
#define		HEADER		0x300000
#define		GSLIST_HEADER	10

/* 170 status bits */

#define		READ_IDLE	0x10000
#define		WRITE_IDLE	0x20000
#define		IDLE_170	0x30000
#define		HEARTBEAT_170	0x1000
#define		ENABLE_170	0x8000
#define		INIBIT_170	0x100
#define		HUMBIT_170	0x200
#define		RUMBIT_170	0x10
#define		ICTI_170	0x20

/* 080 status bits */

#define		HEARTBEAT_80	0x1000
#define		INIBIT_80	0x100
#define		HUMBIT_80	0x200
#define		RUMBIT_80	0x400
#define		ICTI_80		0x800

/* Stanc constants */

#define		ASPECT_SEQ	1
#define		ENTRY_SEQ	0
#define		BYTES_PER_WORD	3
#define		WORDS_PER_STANC	3
#define		HEADER_WORDS	3
#define		BYTES_PER_STANC	8

/* GAS command types */

#define		LS_TYPE_CODE	0x4C		/* list setup type code */
#define		LR_TYPE_CODE	0x54		/* list read type code */
#define		LD_TYPE_CODE	0x44		/* list delete type code */
#define		S_TYPE_CODE	0x48		/* set type code */
#define		R_TYPE_CODE	0x40		/* read type code */

/* GAS frequency time descriptors */

#define		FREQ_15HZ	1

/* Error codes */

#define		NO_Q		1		/* simple no Q */
#define		F20_FAILED	2		/* no Q on initial F20 */
#define		F22_FAILED	3		/* no Q on F22 */
#define		NO_ROOM		4		/* all list IDs already allocated */
#define		NO_STANCS	5		/* list setup request with no STANCs */
#define		BAD_LID		6		/* list read request with inactive list ID */
#define		LID_OOR		7		/* list read request with out of range list ID */
#define		DMA_TIMEOUT	8
#define		CANT_TAKE_IT	9		/* module can't take it */
#define		SM_OFFSET	9
/* Codes 10-17 are reserved for smart module generated errors. */
#define		INIT_FAILED	21		/* F26 enable failed */
#define		F1_FAILED	22		/* F1 status read failed */

typedef struct
    {
    int		listactive;			/* list active flag */
    int		listsize;			/* # of F0's required to read list */
    int		crate;				/* smart module crate # */
    int		slot;				/* smart module slot # */
    int		modtyp;				/* smart module type */
    int		seq;				/* data sequence # */
    } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ GAS_LIST;

typedef struct					/* CAMAC data structure */
    {
    int		crate;				/* CAMAC crate # */
    int		slot;				/* CAMAC slot # */
    int		retry;				/* # of retries */
    int		arb;				/* arbitration */
    unsigned int	status;			/* last status */
    int		exstat[3];			/* extended TSCC status */
    } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ CAMDAT;

typedef struct					/* Filesharing data structure */
    {
    int		fid;				/* file ID */
    int		readwrite;			/* read/write status */
    int		access;				/* access mode */
    int		recsiz;				/* record size */
    int	currec;				/* current record */
    int	filsiz;				/* file size in bytes */
    int		ftype;				/* file type */
    int	first_rec;			/* first record # */
    } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ FILSAV;

typedef struct					/* file header structure */
    {
    char	idstr[4];			/* Fshare identifier string */
    int		vernum;				/* version # */
    int		recsiz;				/* record size */
    int		filtyp;				/* type of file */
    int	first_rec;			/* first record (indexed file only) */
    int		dummy;				/* unused */
    } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ FILEHEAD;

typedef struct					/* indexed file record header structure */
    {
    int	next_rec;			/* next record */
    int	prev_rec;			/* previous record */
    int		rec_in_use;			/* record in use flag */
    int		rec_len;			/* record length (variable length records only) */
    int		dummy;				/* unused */
    } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ INDEXHEAD;

typedef struct					/* indexed file record header structure (including the key) */
    {
    int	next_rec;			/* next record */
    int	prev_rec;			/* previous record */
    int		rec_in_use;			/* record in use flag */
    int		rec_len;			/* record length (variable length records only) */
    int		dummy;				/* unused */
    int	key;				/* search key */
    } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ INDEXHEAD2;


/******************************************************************************/
/*
**	function prototypes
*/
/******************************************************************************/

int	calc_indexed_read(int, long, int *);
int	calc_indexed_write(int, long, int *, int *);
void	CAMBTR(short *, short *, short *, short *);
void	CAMEXT(short *);
unsigned int	CAMIO(short *, short *, int *, short *, short *);
void	CCCC(short *);
void	CCCI(short *, short *);
void	CCCZ(short *);
void	CDREG(short *, short *, short *, short *, short *);
void	CFSA(short *, short *, int *, short *);
#ifndef CBSLIB_DEFINED
#define	chkcmp	CHKCMP
int	CHKCMP(short *, short *, short *, short *);
#endif
int	CHKKBD(void);
int	CKHTBT(short *, short *, short *);
int	CKTSLD(void);
void	CNVDAT(unsigned short *, unsigned short *, char *);
#ifndef CLIB_DEFINED
#define	cprstv	CPRSTV
void	CPRSTV(XCHAR *, short *, TVCOMPRESS *, short *, short *);
#endif
void	CSSA(short *, short *, short *, short *);
#ifndef CBSLIB_DEFINED
#define	decide	DECIDE
int	DECIDE(short *, short *, char *, short *);
#endif
int	find_indexed_insert(int);
int	find_indexed_rec(int, long, int);
int	FLOAD(char *, char *, short *);
#ifndef CBSLIB_DEFINED
#define	fndfst	FNDFST
int	FNDFST(char *, short *);
#endif
int	fndfstc(char *, int);
int	FSTORE(char *, char *, short *);
#ifndef CLIB_DEFINED
#define	fsclos	FSCLOS
void	FSCLOS(short *vun, short *status, int *ext_status);
#endif
#if PC_CONSOLE_ENV
void	FSCREA(short *vun, char *file_name, short *access, short *status,
	       int *ext_status, short *record_size);
#endif
#ifndef CLIB_DEFINED
#define	fsdel	FSDEL
void	FSDEL(short *vun, short *status, int *ext_status, int *record);
#define	fsopen	FSOPEN
void	FSOPEN(short *vun, char *file_name, short *access, short *status,
	       int *ext_status, short *read_only);
#define	fsread	FSREAD
void	FSREAD(short *vun, char *io_buffer, short *num_bytes, short *status,
	       int *ext_status, int *record, short *num_returned);
#define	fsrew	FSREW
void	FSREW(short *vun, short *status, int *ext_status);
#define	fsunlk	FSUNLK
void	FSUNLK(short *vun, short *status, int *ext_status);
#define	fswrit	FSWRIT
void	FSWRIT(short *vun, char *io_buffer, short *num_bytes, short *status,
	       int *ext_status, int *record);
#endif
int	gas_clear(int);
int	gas_init(void);
int	GETDIR(char *, char *, int *, char *, short *);
#ifndef CLIB_DEFINED
#define	gsboot	GSBOOT
void	GSBOOT(short *, short *, short *, short *);
#define	gsget	GSGET
void	GSGET(char *, char *, short *, short *, short *, short *);
#define	gslend	GSLEND
void	GSLEND(char *, short *);
#define	gslist	GSLIST
void	GSLIST(short *, short *, short *, short *, short *, char *, short *,
	       short *, short *);
#define	gsread	GSREAD
void	GSREAD(short *, short *, short *, char *, short *, short *, short *);
#define	gsset	GSSET
void	GSSET(short *, short *, short *, char *, short *, short *, short *);
#define	gstanc	GSTANC
void	GSTANC(short *, short *, short *, short *, short *, short *, short *);
#endif
int	initial_f20(int, int *);
#ifndef CBSLIB_DEFINED
#define	inptxt	INPTXT
int	INPTXT(short *, short *, char *, short *, char *, short *);
#endif
int	inptxtc(int, int, char *, int, char *, int);
void	INPUTH(short *, short *, char *, short *, short *);
void	inputhc(int, int, char *, int, short *);
void	INPUTI(short *, short *, char *, short *, short *);
void	inputic(int, int, char *, int, short *);
#ifndef CBSLIB_DEFINED
#define	justfy	JUSTFY
void	JUSTFY(char *, short *);
#endif
void	justfyc(char *, int);
#ifndef CBSLIB_DEFINED
#define	meswin	MESWIN
void	MESWIN(short *, short *, short *, short *, char *, short *);
#endif
void	meswinc(int, int, int, int, char *, int);
unsigned int	MCAMIO(short *, short *, int *, short *, short *, short *);
void	NQR(short *);
#if PC_CONSOLE_ENV
unsigned short	pclib_get_front_end(void);
int	pclib_set_front_end(int node);
#endif
void	RDSPH(short *, short *, short *, short *, short *, short *, short *);
void	rdsphc(int row, int column, int num_chars, int minimum,
	       int maximum, short *value, short *status);
#ifndef CLIB_DEFINED
#define	rdspi	RDSPI
void	RDSPI(short *, short *, short *, short *, short *, short *, short *);
#endif
void	rdspic(int row, int column, int num_chars, int minimum,
	       int maximum, short *value, short *status);
void	RDSPI4(short *, short *, short *, int *, int *, int *, short *);
void	rdspi4c(int row, int column, int num_chars, int minimum,
		int maximum, int *value, short *status);
#ifndef CLIB_DEFINED
#define	rdspr	RDSPR
void	RDSPR(short *, short *, short *, float *, float *, float *, short *);
#endif
void	rdsprc(int row, int column, int num_chars, float *minimum,
	       float *maximum, float *value, short *status);
int	read_file_header(int, FILEHEAD *);
int	read_index_header(int, long, INDEXHEAD *);
int	send_header(int, int *);
void	SETARB(short *);
void	SETCS(short *, short *);
void	SETTRY(short *);
void	SHODIR(char *, char *);
void	SOUND(short *, short *);
#ifndef CBSLIB_DEFINED
#define	timmes	TIMMES
void	TIMMES(short *, short *, char *, short *, short *);
#endif
void	timmesc(int, int, char *, int, int);
#ifndef CLIB_DEFINED
#define	tvdisp	TVDISP
void	TVDISP(short *, short *, short *, short *, short *);
#endif
#ifndef CBSLIB_DEFINED
#define	tvmess	TVMESS
void	TVMESS(short *, short *, char *, short *);
#endif
#ifndef CLIB_DEFINED
#define	tvsave	TVSAVE
void	TVSAVE(short *, short *, short *, short *, short *, short *, short *,
	       short *);
#endif
#ifndef CBSLIB_DEFINED
int	winput(char *, int, int, char *, int, float *, float *,
	       void *[], int, short *);
#endif
void	WRDSPH(short *, short *, char *, short *, short *, short *, short *);
void	wrdsphc(int, int, char *, int, short, short, short *);
#ifndef CBSLIB_DEFINED
#define	wrdspi	WRDSPI
void	WRDSPI(short *, short *, char *, short *, short *, short *, short *);
#endif
void	wrdspic(int, int, char *, int, short, short, short *);
#ifndef CBSLIB_DEFINED
#define	wrdspr	WRDSPR
int	WRDSPR(short *, short *, char *, short *, float *, float *,
	       float *, short *);
#endif
int	wrdsprc(int, int, char *, int, float *, float *, float *, int);
int	write_file_header(int, FILEHEAD *);
int	write_index_header(int, long, INDEXHEAD *);
#ifndef CLIB_DEFINED
#define	xpndtv	XPNDTV
void	XPNDTV(TVCOMPRESS *, XCHAR *, short *, short *);
#endif

#endif