/* Copyright (C) 1986 by M. J. Shannon, Jr.
** Permission to distribute for non-commercial uses granted as long as this
** notice is retained.  Violators will be prosecuted.
*/

/* Port addresses */
#define	MPUP_STAT	0x331	/* RO: status */
#define	MPUP_COMD	0x331	/* WO: command */
#define	MPUP_DATA	0x330	/* RW: data */

/* Bits in status port */
#define	MPUPS_DSR	0x80	/* mpu: ready to send */
#define	MPUPS_DRR	0x40	/* mpu: ready to receive */

/* MPU commands */
#define	CMD_UART	0x3F	/* become a dumb uart */
#define	CMD_INTCLOCK	0x80	/* MPU is master clock */
#define	CMD_EXTCLOCK	0x82	/* master clock is not MPU */
#define	CMD_FSKINT	0x92	/* set FSK sync res. to internal sync res. */
#define	CMD_FSKMIDI	0x93	/* set FSK sync res. to MIDI sync res. */
#define	CMD_RESET	0xFF	/* reset to default state */

/* Initialization switches */
#define	SWD_ALLOFF	0x30	/* disable automatic "ALL NOTES OFF" */
#define	SWD_REALTIME	0x32	/* disable automatic real time msgs */
#define	SWD_THRU	0x33	/* disable "thru" function */
#define	SWE_TIME	0x34	/* add timing bytes in "data in stop" mode */
#define	SWE_MODE	0x35	/* pass mode messages to host */
#define	SWE_TEXCL	0x37	/* pass exclusive msgs from in to out */
#define	SWE_COMMON	0x38	/* pass common messages to host */
#define	SWE_REALTIME	0x39	/* pass real time messages to host */
#define	SWE_FSKSYNC	0x81	/* enable FSK input/output & sync to it */
#define	SWE_METRO	0x83	/* metronome on - no accents */
#define	SWD_METRO	0x84	/* metronome off */
#define SWE_AMETRO	0x85	/* metronome on - w/accents */
#define	SWD_BENDER	0x86	/* disable continuous controller to host */
#define	SWE_BENDER	0x87	/* enable continuous controller msgs */
#define	SWD_VOXTHRU	0x88	/* disable voice "thru" function */
#define	SWE_VOXTHRU	0x89	/* enable voice "thru" function */
#define	SWD_DATAINSTOP	0x8A	/* disable "data in stop" mode */
#define	SWE_DATAINSTOP	0x8B	/* enable "data in stop" mode */
#define	SWD_MEASEND	0x8C	/* disable "measure end" to host */
#define	SWE_MEASEND	0x8D	/* enable "measure end" to host */
#define	SWD_CONDUCT	0x8E	/* disable conductor function */
#define	SWE_CONDUCT	0x8F	/* enable conductor function */
#define	SWD_RTAFFECT	0x90	/* disable real time affection */
#define	SWE_RTAFFECT	0x91	/* enable real time affection */
#define	SWD_CLKHOST	0x94	/* disable "clock to host" msgs */
#define	SWE_CLKHOST	0x95	/* enable "clock to host" msgs */
#define	SWD_HEXCL	0x96	/* don't pass exclusives to host */
#define	SWE_HEXCL	0x97	/* pass exclusives to host */
#define	SWD_CRTA	0x98	/* channel reference table A off */
#define	SWE_CRTA	0x99	/* channel reference table A on */
#define	SWD_CRTB	0x9A	/* channel reference table B off */
#define	SWE_CRTB	0x9B	/* channel reference table B on */
#define	SWD_CRTC	0x9C	/* channel reference table C off */
#define	SWE_CRTC	0x9D	/* channel reference table C on */
#define	SWD_CRTD	0x9E	/* channel reference table D off */
#define	SWE_CRTD	0x9F	/* channel reference table D on */

/* Information retrieving commands */
#define	GET_PC1		0xA0	/* get play counter for track 1 */
#define	GET_PC2		0xA1	/* get play counter for track 2 */
#define	GET_PC3		0xA2	/* get play counter for track 3 */
#define	GET_PC4		0xA3	/* get play counter for track 4 */
#define	GET_PC5		0xA4	/* get play counter for track 5 */
#define	GET_PC6		0xA5	/* get play counter for track 6 */
#define	GET_PC7		0xA6	/* get play counter for track 7 */
#define	GET_PC8		0xA7	/* get play counter for track 8 */
#define	GET_RC		0xAB	/* get record counter (& clear it) */
#define	GET_TEMPO	0xAF	/* get the tempo */
#define	GET_VERSION	0xAC	/* get firmware version */
#define	GET_REVISION	0xAD	/* get firmware revision */

/* Clear functions */
#define	CLR_RELTEMPO	0xB1	/* sets relative tempo to 1/1 */
#define	CLR_PC		0xB8	/* clears all play counters */
#define	CLR_PM		0xB9	/* clears all channel reference tables */
#define	CLR_RC		0xBA	/* clear the record counter */

/* Set functions (no operands) */
#define	SET_TB48	0xC2	/* set timebase to 48 clocks/beat */
#define	SET_TB72	0xC3	/* set timebase to 72 clocks/beat */
#define	SET_TB96	0xC4	/* set timebase to 96 clocks/beat */
#define	SET_TB120	0xC5	/* set timebase to 120 clocks/beat */
#define	SET_TB144	0xC6	/* set timebase to 144 clocks/beat */
#define	SET_TB168	0xC7	/* set timebase to 168 clocks/beat */
#define	SET_TB192	0xC8	/* set timebase to 192 clocks/beat */

/* Set functions (operand follows) */
#define	SET_TEMPO	0xE0	/* set tempo */
#define	SET_RTEMPO	0xE1	/* set relative tempo */
#define	SET_TGRAD	0xE2	/* set tempo graduation */
#define	SET_CMBEAT	0xE4	/* set # MIDI clocks / metronome beat */
#define	SET_MBMEAS	0xE6	/* set # metronome beats / measure */
#define	SET_ICCLOCK	0xE7	/* set # internal clocks (x4) / clock to host */
#define	SET_ACTIVE	0xEC	/* set active tracks bitmap */
#define	SET_PLAYCTRS	0xED	/* set play counter bitmap */
#define	SET_LACCCH	0xEE	/* set lo acceptable tracks bitmap */
#define	SET_HACCCH	0xEF	/* set hi acceptable tracks bitmap */

/* Request functions */
#define	REQ_SCH(n)	(0xD0 | ((n) & 0x07))
#define	REQ_SCH0	0xD0	/* want to send data on track 0 */
#define	REQ_SCH1	0xD1	/* want to send data on track 1 */
#define	REQ_SCH2	0xD2	/* want to send data on track 2 */
#define	REQ_SCH3	0xD3	/* want to send data on track 3 */
#define	REQ_SCH4	0xD4	/* want to send data on track 4 */
#define	REQ_SCH5	0xD5	/* want to send data on track 5 */
#define	REQ_SCH6	0xD6	/* want to send data on track 6 */
#define	REQ_SCH7	0xD7	/* want to send data on track 7 */
#define	REQ_SSYS	0xDF	/* want to send system message */

#define	CMD_ACK		0xFE	/* MPU's acknowledement of a command */

/* Interesting MIDI bytes */
#define	MIDI_EOX	0xF7	/* End Of eXclusive message */

/* Declarations for routines in mpu.c: */
extern int wait_drr();
extern int wait_dsr();
extern int mpu_get(unsigned char);
extern void mpu_put(unsigned char);
extern char *mpu_id();
extern void mpu_sexcl(unsigned char *);
extern int mpu_read(unsigned char *);
extern int mpu_dget();
extern void dxswremt(unsigned char, unsigned char);
extern void dxpachng(unsigned char, unsigned char);

/* Definitions for various macros */
#define	mpu_reset()	mpu_put(CMD_RESET)
