#ifndef __QNXNTO__

#include "driver.h"

#define	IRQ_TABLE_SIZE	16

static struct _irq_entry {

	pid_t			proxy;
	struct snd_stru_irq 	irq;
} irq_table[IRQ_TABLE_SIZE];


static pid_t far handler(int irq) 
{
        
        if (irq < 8)
                outp(IMR1, inp(IMR1) | (1 << irq));
        else
                outp(IMR2, inp(IMR2) | (1 << (irq - 8)));

	return(irq_table[irq].proxy);
}

static pid_t far handler0(void) 
{
	return handler(0);
}

static pid_t far handler1(void) 
{
	return handler(1);
}

static pid_t far handler2(void) 
{
	return handler(2);
}

static pid_t far handler3(void) 
{
	return handler(3);
}

static pid_t far handler4(void) 
{
	return handler(4);
}

static pid_t far handler5(void) 
{
	return handler(5);
}

static pid_t far handler6(void) 
{
	return handler(6);
}

static pid_t far handler7(void) 
{
	return handler(7);
}

static pid_t far handler8(void) 
{
	return handler(8);
}

static pid_t far handler9(void) 
{
	return handler(9);
}

static pid_t far handler10(void) 
{
	return handler(10);
}

static pid_t far handler11(void) 
{
	return handler(11);
}

static pid_t far handler12(void) 
{
	return handler(12);
}

static pid_t far handler13(void) 
{
	return handler(13);
}

static pid_t far handler14(void) 
{
	return handler(14);
}

static pid_t far handler15(void) 
{
	return handler(15);
}

static pid_t far (*irq_func[])(void) = {
	handler0,	handler1,	handler2,	handler3,
	handler4,	handler5,	handler6,	handler7,
	handler8,	handler9,	handler10,	handler11,
	handler12,	handler13,	handler14,	handler15,
};

int 
hint_disconnect(int irq)
{
        int 				rval;
        struct _irq_entry 		*ip;

        ip = &irq_table[irq];

        qnx_proxy_detach(ip->proxy);
	rval = qnx_hint_detach(ip->irq.iid);
        memset(ip, 0, sizeof(struct _irq_entry));

        return (rval);
}


int 
hint_connect(int irq, struct snd_stru_irq *irqp)
{
	struct sched_param 		param;
        struct _irq_entry		*ip;

	sched_getparam(0, &param);
        ip = &irq_table[irq];

	printf("Attaching to irq: %d\n", irq);

        memcpy(&ip->irq, irqp, sizeof(struct snd_stru_irq));
	ip->proxy = qnx_proxy_attach(irqp->tid, NULL, 0, 
				     param.sched_priority + 5);

	if (ip->proxy < 0) {
		perror("qnx_proxy_attach");
		return (-1);
	}

	if ((ip->irq.iid = 
             qnx_hint_attach(irq, irq_func[irq], my_ds())) < 0) {

		perror("qnx_hint_attach");
		return (-1);
	}

	return (irq);
}

#endif
