/* $Id: srec.h,v 1.5 92/04/10 15:18:38 tomc Exp $ */	/* RCS data */

/**
*	SREC Definitions
**/

#define TRUE	1
#define FALSE	0
#define YES	1
#define NO	0
#define EOS	'\0'			/* end-of-string constant */
#define MAXSTR	256			/* maximum string size + 1 */
#define MAXFLD	16			/* maximum field value size */

/*
* The following definitions are for Macintosh Lightspeed C since that
* environment does not support command line DEFINEs.  Remove comments
* as necessary.
*/
/*
#define MAC		1
#define LSC		1
*/

/**
*	Environment Definitions (zero here; may be redefined at compile time)
**/

#ifndef MSDOS
#define MSDOS		0		/* MS-DOS operating system */
#endif
#ifndef VMS
#define VMS		0		/* VMS operating system */
#endif
#ifndef ATT
#define ATT		0		/* AT&T Unix */
#endif
#ifndef BSD
#define BSD		0		/* Berkeley Unix */
#endif
#ifndef MACH
#define MACH		0		/* NeXT Mach */
#endif
#ifdef UNIX
#undef UNIX
#endif
#define UNIX		(ATT || BSD || MACH)	/* generic Unix OS */
#ifndef MAC
#define MAC		0		/* Macintosh operating system */
#endif
#ifndef TOS
#define TOS		0		/* Atari ST operating system */
#endif

#ifndef D3100
#define D3100		0		/* DECsystem 3100 */
#endif
#ifndef I8086
#define I8086		0		/* Intel 8086/88 CPU */
#endif
#ifndef M68020
#define M68020		0		/* Motorola 68020 CPU */
#endif
#ifndef VAX
#define VAX		0		/* DEC VAX CPU */
#endif
#ifndef SPARC
#define SPARC		0		/* Sun SPARC CPU */
#endif

#ifndef MSC
#define MSC		0		/* Microsoft C compiler */
#endif
#ifndef VAXC
#define VAXC		0		/* VAX C compiler */
#endif
#ifndef LSC
#define LSC		0		/* Lightspeed C compiler */
#endif
#ifndef MPW
#define MPW		0		/* MPW C (Macintosh) */
#endif
#ifndef AZTEC
#define AZTEC		0		/* Aztec C (Macintosh) */
#endif
#ifndef ICC
#define ICC		0		/* Intel C Code Builder compiler */
#endif
#ifndef WATCOM
#define WATCOM		0		/* Watcom C 386 compiler */
#endif

#if BSD
#define strchr	index
#define strrchr	rindex
#else
#define index	strchr
#define rindex	strrchr
#endif

#if AZTEC		/* text file routine redefintion for Aztec */
#ifdef fgetc
#undef fgetc
#endif
#define	fgetc	agetc
#ifdef fputc
#undef fputc
#endif
#define	fputc	aputc
#endif

#if VMS				/* exit status values */
#define OK	0x18000001L
#define	ERR	0x1800FFFBL
#define CLI_ABSENT	CLI$_ABSENT
#else
#define OK	0
#define ERR	1
#define CLI_ABSENT	0
#endif

/*	Base filename lengths	*/
#if MSDOS || TOS
#define BASENAMLEN	12
#endif
#if ATT
#define BASENAMLEN	14
#endif
#if BSD || MACH
#define BASENAMLEN	255
#endif
#if VMS
#define	BASENAMLEN	78
#endif
#if MAC
#define BASENAMLEN	31
#endif
#define MAXEXTLEN	4		/* longest filename extension */

#define DSP56000	1
#define WSIZE5		3		/* bytes per 56000 word */
#define OVRHD5		3		/* 56000 S-record byte overhead */
#define WRDFMT5		"%06lx"		/* 56000 word format string */

#define DSP96000	2
#define WSIZE9		4		/* bytes per 96000 word */
#define OVRHD9		5		/* 96000 S-record byte overhead */
#define WRDFMT9		"%08lx"		/* 96000 word format string */

#define DSP56100	3
#define WSIZE6		2		/* bytes per 56100 word */
#define OVRHD6		3		/* 56100 S-record byte overhead */
#define WRDFMT6		"%04lx"		/* 56100 word format string */

#define S0OVRHD		3		/* S0 record overhead */
#define MAXBYTE		30		/* max data bytes per S-record */
#define MAXOVRHD	8		/* maximum S-record overhead */
#define MAXBUF	(MAXBYTE + MAXOVRHD) * 2/* maximum byte buffer size */

#define MSPACES	4			/* number of memory spaces */
#define XMEM	0			/* memory space array offsets */
#define YMEM	1
#define LMEM	2
#define PMEM	3

#define NONE	0			/* OMF record codes */
#define START	1
#define END	2
#define DATA	3
#define BDATA	4
#define SYMBOL	5
#define COMMENT	6

#define RECORD	1			/* OMF field types */
#define HEXVAL	2

#define NEWREC	'_'			/* new record indicator */

/*	File type designations	*/
#define FT_UNKNOWN	(-1)
#define FT_NONE		0
#define FT_LOD		1
#define FT_CLD		2

struct srec {				/* S-record structure */
		FILE *fp;
		unsigned checksum;
		char *p;
		char buf[MAXBUF + 1];
		};

union wrd {	/* word union for byte swapping */
	unsigned long l;
	unsigned char b[4];
};

char *strcpy (), *strncpy ();
char *strcat (), *strncat ();
#if BSD
char *index (), *rindex ();
#else
char *strchr (), *strrchr ();
#endif

#if MSDOS		/* reference DOS version number */
#if MSC
extern unsigned char _osmajor;
#endif
#endif

extern int main ( /* int argc,char *argv [] */ );
static int open_ifile ( /* void */ );
static void do_srec ( /* FILE *fp */ );
static void do_coff ( /* FILE *fp */ );
static void read_headers ( /* FILE *fp */ );
static void read_data ( /* XCNHDR *sh,int sn */ );
static void read_bdata ( /* XCNHDR *sh,int sn */ );
static void do_end ( /* void */ );
static void do_lod ( /* FILE *fp */ );
static int get_start ( /* FILE *fp */ );
static int get_record ( /* void */ );
static void get_data ( /* void */ );
static void get_bdata ( /* void */ );
static void get_end ( /* void */ );
static int sum_addr ( /* unsigned long addr */ );
static void get_bytes ( /* int space,char *fbp */ );
static void flush_rec ( /* int space,unsigned long addr,unsigned long count */ );
static void rev_bytes ( /* char *buf */ );
static void open_ofiles ( /* int space */ );
static int get_field ( /* void */ );
static int get_comment ( /* void */ );
static int get_line ( /* void */ );
static char *scan_field ( /* char *bp */ );
static void bld_s0 ( /* unsigned space */ );
static int setup_mach ( /* char *buf */ );
static int get_mem ( /* enum memory_mem mem */ );
static int get_space ( /* void */ );
static int get_memch ( /* int spc */ );
static int get_ftype ( /* char *fname */ );
static char *fix_fname ( /* char *fname */ );
static char *strup ( /* char *str */ );
static int fldhex ( /* void */ );
static char *basename ( /* char *str */ );
static int setfile ( /* char *fn,char *type,char *creator */ );
static int freads ( /* char *ptr,int size,int nitems,FILE *stream */ );
#if I8086 || VAX || D3100
static void swapw ( /* char *ptr,int size,int nitems */ );
#endif
static char *cmdarg (char arg, int argc, char **argv);
extern int getopts ( /* int argc,char *argv [],char *optstring */ );
#if VMS
static int dcl_getval ( /* struct dsc$descriptor_s *opt */ );
#else
static int dcl_getval ( /* int *opt */ );
#endif
static void onintr ( /* void */ );
static void usage ( /* void */ );
static void error ( /* char *str */ );
static void error2 ( /* char *fmt,char *str */ );

