
/*
*****************************************************************
*								*
*		hkinit.c - initialize heurikon hk68 for kiwi	*
*								*
*	12-04-84...created from bits of diag1.c.....J.Middleton	*
*								*
*****************************************************************
*/

#include "diag.h"

#define CIOCTRL (unsigned char *) 0xfef607
#define CIODATB (unsigned char *) 0xfef603
#define HK_BCL (unsigned char *) 0xfec000
#define WARM 0xfe0008

#define BUS_VEC 0x08
#define PRI_VEC 0x20
#define ILA_VEC 0x0C
#define NMI_VEC 0x7c
#define ILI_VEC 0x10


hk68init()
{
	static unsigned char	ciotbl1[] = {
		0x00, 	0x02, 		/* clr reset, right just */
		0x28, 	0x00, 		/* port b, bit cont mode */
		0x2a, 	0x00, 		/* port b, non-inverting */
		0x2b, 	0xff, 		/* port b, all inputs */
		0x2c, 	0x00, 		/* port b, normal inputs */

		0x20,	0x00,		/* port a, bit control mode */
		0x22,	0x00,		/* port a, non-inverting */
		0x23,	0xff,		/* port a, inputs */
		0x24,	0x01,		/* port a, 1's catcher on d0 (wdog) */

		0x01, 	0x94		/* enable port a, b, c */
	};

	*HK_BCL = 0x82;		/* init for intel bytes, hk RAM at 0 */

	initcio(ciotbl1, sizeof(ciotbl1));

}



/*------------------------------------------------------------------*/
hbugWarm()
{
		xprintf("\n\nReturning to HBUG");
		((int	(*)())WARM)();
}
/*------------------------------------------------------------------*/
	/* read the multibus interrupt lines */
irqLev()
{
	return(*CIODATB);
}
/*------------------------------------------------------------------*/
/*	Initialize the exception vectors */
initvect()
{
	*(int (**)()) (BUS_VEC << 2) = bus_ex;
	*(int (**)()) (PRI_VEC << 2) = pri_ex;
	*(int (**)()) (ILA_VEC << 2) = ila_ex;
	*(int (**)()) (NMI_VEC << 2) = nmi_ex;
	*(int (**)()) (ILI_VEC << 2) = ili_ex;
}


/*------------------------------------------------------------------*/
/*	Initialize CIO with table of length 'size' pointed to by 'table' */

initcio(table, size)
	register char	*table;
	register int size;
{
	register int	cnt;
	register unsigned char	c, zero;

	zero = 0;
	c = *CIOCTRL;
	*CIOCTRL = zero;
	c = *CIOCTRL;
	*CIOCTRL = zero;
	*CIOCTRL = 1;
	*CIOCTRL = zero;
	for (cnt = 0; cnt < size; cnt++)
		*CIOCTRL = *table++;
}

/*  */                                                                                                                                                                                                                                                            