/*
 * Copyright (c) 1987, 1988 by
 * PARALLAX GRAPHICS, INCORPORATED, Santa Clara, California.
 * All rights reserved
 *
 * This software is furnished on an as-is basis, and may be used and copied
 * only with the inclusion of the above copyright notice.
 *
 * The information in this software is subject to change without notice.
 * No committment is made as to the usability or reliability of this
 * software.
 *
 * Parallax Graphics, Inc.
 * 2500 Condensa Street
 * Santa Clara, California  95051
 */

/* "@(#)plxmd.h	1.16 10/20/88 Parallax Graphics Inc" */

#ifndef PLXMD_H		/* included yet?? */
#define PLXMD_H

#define	OUTWORD(reg, value)	(reg) = (value)
#define	INWORD(reg)		(reg)
#define	DELAY(d)		{ long i = (d)>>1; while (i > 0) i--; }

#ifdef NOTDEF
#if defined(vax) || defined(sun) || defined(motorola131) || defined(is68k) || defined(interactive)
#define SUPPORT_INPUT
#endif

#if defined(vax) || defined(sun2) || defined(sun3) || defined(motorola131) || defined(is68k) || defined(ibm032)
#define SUPPORT_IO
#endif

#if defined(ibm032)
#define SUPPORT_IBMCONSOLE
#define RT_INT_BUG
#define RT_PLX
#endif

#if defined(vax)
#define SUPPORT_PLXCONSOLE
#define CONSOLEMAJOR	0
#define SUPPORT_RINGBUFFER
#endif

#if defined(sun)
#define SUPPORT_RINGBUFFER
#define SUPPORT_FRAMEBUFFER
#endif

#if defined(xenix) || defined(interactive) || defined(ibm032)
#define	SUPPORT_ATBUS
#endif
#if defined(vax)
#define	SUPPORT_QBUS
#define	SUPPORT_600
#endif
#if defined(sun3) || defined(sun4) || defined(is68k) || defined(motorola131)
#define	SUPPORT_VMEBUS
#define	SUPPORT_600
#endif

#if defined(sun2)
#define	SUPPORT_MULTIBUS
#define	SUPPORT_600
#endif

#if defined(vax) || defined(sun) || defined(is68k) || defined(ibm032)
#define	ONE_SECOND	hz
#endif /* vax || sun || is68k || ibm032 */
#if defined(xenix) || defined(interactive) || defined(motorola131)
#define	ONE_SECOND	HZ
#endif /* xenix || interactive || motorola131 */

#ifdef KERNEL
    
#ifdef vax
#include	"../h/param.h"
#include	"../h/types.h"
#include	"../h/map.h"
#include	"../h/buf.h"
#include	"../h/file.h"
#include	"../h/errno.h"
#include	"../h/ioctl.h"
#include	"../h/vm.h"
#include	"../h/uio.h"
#include	"../h/time.h"
#include	"../h/kernel.h"
#include	"../h/user.h"
#include	"../h/systm.h"
#include	"../h/tty.h"
#include	"../h/conf.h"
#include	"../machine/pte.h"
#include	"../machine/mtpr.h"
#include	"../machine/cpu.h"
#include	"../vaxuba/ubareg.h"
#include	"../vaxuba/ubavar.h"
#endif /* vax */


#ifdef ibm032
#include	"../h/param.h"
#include	"../h/types.h"
#include	"../h/map.h"
#include	"../h/buf.h"
#include	"../h/file.h"
#include	"../h/errno.h"
#include	"../h/ioctl.h"
#include	"../h/vm.h"
#include	"../h/uio.h"
#include	"../h/time.h"
#include	"../h/kernel.h"
#include	"../h/dir.h"
#include	"../h/user.h"
#include	"../h/systm.h"
#include	"../h/tty.h"
#include	"../h/conf.h"
#include	"../machine/pte.h"
#include	"../machine/mmu.h"
#include	"../machine/cpu.h"
#include	"../machine/io.h"
#include	"../machineio/ioccvar.h"
#include	"../machineio/dmareg.h"
#include	"../machineio/dmavar.h"
#endif

#endif /* KERNEL */
    
#ifdef SUPPORT_INPUT
#ifdef KERNEL
#ifdef vax
#include	"../vaxuba/qevent.h"
#else
#include	"../local/qevent.h"
#endif /* vax */
#else  /* KERNEL */
#ifdef vax
#include	<vaxuba/qevent.h>
#else
#include	<local/qevent.h>
#endif /* vax */
#endif /* KERNEL */
#endif

/* The following bits are included only when compiling the kernel... */
    
#if defined(KERNEL) || (defined(STANDALONE) && defined(ibm032))

/* Convert register address to base address (graphic context) */
#define PLXBASEADDR(reg)	\
    ((struct plx_device *)((int)(reg)&(0L - sizeof(struct plx_wholedevice))))

#ifdef vax
#define	TIME10MSEC()	((time.tv_sec * 100) + (time.tv_usec / 10000))
#define	BUSINFO		uba_device
#define	BUSUNIT(bus)	((bus)->ui_unit)
#define	BUSALIVE(bus)	((bus)->ui_alive)
#define	BUSADDR(bus)	((struct plx_device *)((bus)->ui_addr))

#define	OUTWORD(reg, value)	(reg) = (value)
#define	INWORD(reg)		(reg)
#endif /* vax */

#ifdef sun
#define	TIME10MSEC()	((time.tv_sec * 100) + (time.tv_usec / 10000))
#define	BUSINFO		mb_device
#define	BUSUNIT(bus)	((bus)->md_unit)
#define	BUSALIVE(bus)	((bus)->md_alive)
#define	BUSADDR(bus)	((struct plx_device *)((bus)->md_addr))

#define	OUTWORD(reg, value)	(reg) = (value)
#define	INWORD(reg)		(reg)
#endif /* sun */

#ifdef is68k
#define	TIME10MSEC()	((time.tv_sec * 100) + (time.tv_usec / 10000))
#define	BUSINFO		qb_device
#define	BUSUNIT(bus)	((bus)->qi_unit)
#define	BUSALIVE(bus)	((bus)->qi_alive)
#define	BUSADDR(bus)	((struct plx_device *)((bus)->qi_mi->qm_addr))

#define	OUTWORD(reg, value)	(reg) = (value)
#define	INWORD(reg)		(reg)
#endif /* is68k */

#ifdef ibm032
#define	TIME10MSEC()	((time.tv_sec * 100) + (time.tv_usec / 10000))
#define	BUSINFO		iocc_device
#define	BUSUNIT(bus)	((bus)->iod_unit)
#define	BUSALIVE(bus)	((bus)->iod_alive)
#define	BUSADDR(bus)	((struct plx_device *)((bus)->iod_mi->ic_addr))

#define	OUTBYTE(reg, value)	*(u_char *)&(reg) = (value)
#define	INBYTE(reg)		*(u_char *)&(reg)

#define	OUTWORD(reg, value)	\
				*(u_char *)((u_char *)&(reg)+1) = \
								(value)>>8, \
				*(u_char *)((u_char *)&(reg)  ) = \
								(value)

#define	INWORD(reg)		( \
				((*(u_char *)((u_char *)&(reg)+1)) << 8) | \
				((*(u_char *)((u_char *)&(reg)  ))     ) \
				)

#endif /* ibm032 */

#ifdef xenix
#define	DELAY(d)		{ long i = (d)>>1; while (i > 0) i--; }
#define	TIME10MSEC()		((time * 100) + ((10 * lbolt) % HZ))
#define	OUTBYTE(reg, value)	outb(&(reg), value)
#define	INBYTE(reg)		inb(&(reg))
#define	OUTWORD(reg, value)	out(&(reg), value)
#define	INWORD(reg)		in(&(reg))
#endif /* xenix */

#ifdef interactive
#define	DELAY(d)		{ long i = (d)>>1; while (i > 0) i--; }
#define	TIME10MSEC()		((time * 100) + ((10 * lbolt) % HZ))
#define	OUTBYTE(reg, value)	outb(&(reg), value)
#define	INBYTE(reg)		inb(&(reg))
#define	OUTWORD(reg, value)	outw(&(reg), value)
#define	INWORD(reg)		inw(&(reg))
#endif /* interactive */

#endif /* KERNEL || STANDALONE */
#endif /* NOTDEF */
#endif /* PLXMD_H */
