/*-=-=-=-=-=-=-=-=-=-=-=- RCCL/RCI Notice of Copyright -=-=-=-=-=-=-=-=-=-=-*
 *									    *
 *	Copyright (C) 1991 by John E. Lloyd.				    *
 *									    *
 *	Information on copyright permissions, as well as a complete	    *
 *	disclaimer of warranty, is given in the file COPYRIGHT.		    *
 *									    *
 *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
/* Exercising/test program for the XYCOM XVME 203 clock timer board */

#include "../h/rci.h"
#include "xvme203.h"

extern unsigned char *rciIOpage;

doFxn(td, arg)
RCI_DESC *td;
int arg;
{
	XC_BLK *xcb;

	if ((xcb = (XC_BLK*)getMemByAddr ((void*)arg)) == NULL)
	 { rciAbort ("doFxn() -- can't get argument block\n");
	   return (-1);
	 }

	switch (xcb->command)
	 { case SET_CTRS:
	    { CTRS_COM_BUF = (unsigned char)xcb->addr;
	      CTRS_DATA_BUF = xcb->value.c[0];
	      CTRS_DATA_BUF = xcb->value.c[1];
	      break;
	    }
	   case GET_CTRS:
	    { CTRS_COM_BUF = (unsigned char)xcb->addr;
	      xcb->value.c[0] = CTRS_DATA_BUF;
	      xcb->value.c[1] = CTRS_DATA_BUF;
	      break;
	    }
	   case SAVE_CTRS:
	    { CTRS_COM_BUF = (unsigned char)(0xa0 | xcb->mask);
	      break;
	    }
	   case ARM_CTRS:
	    { CTRS_COM_BUF = (unsigned char)(0x20 | xcb->mask);
	      break;
	    }
	   case LOAD_CTRS:
	    { CTRS_COM_BUF = (unsigned char)(0x40 | xcb->mask);
	      break;
	    }
	   case LOAD_AND_ARM_CTRS:
	    { CTRS_COM_BUF = (unsigned char)(0x60 | xcb->mask);
	      break;
	    }
	   case DISARM_CTRS:
	    { CTRS_COM_BUF = (unsigned char)(0xc0 | xcb->mask);
	      break;
	    }
	   case READ_CTRS:
	    { CTRS_COM_BUF = (unsigned char)(0xa0 | (1<<(xcb->counter-1)) );
	      CTRS_COM_BUF = (unsigned char)xcb->addr;
	      xcb->value.c[0] = CTRS_DATA_BUF;
	      xcb->value.c[1] = CTRS_DATA_BUF;
	      break;
	    }
	   case GET_CTRS_STATUS:
	    { xcb->value.c[0] = CTRS_COM_BUF;
	      break;
	    }
	   case RESET_ICTL:
	    { ICTL_COM_BUF = 0;
	      break;
	    }
	   case SET_MODE_ICTL:
	    { ICTL_COM_BUF = (0x80 | (xcb->value.c[0] & 0x1f));
	      break;
	    }
	   case CLEAR_IMR_BIT:
	    { ICTL_COM_BUF = (0x28 | (xcb->value.c[0] & 0x7));
	      break;
	    }
	   case SET_IMR_BIT:
	    { ICTL_COM_BUF = (0x38 | (xcb->value.c[0] & 0x7));
	      break;
	    }
	   case CLEAR_IRR_BIT:
	    { ICTL_COM_BUF = (0x48 | (xcb->value.c[0] & 0x7));
	      break;
	    }
	   case SET_IRR_BIT:
	    { ICTL_COM_BUF = (0x58 | (xcb->value.c[0] & 0x7));
	      break;
	    }
	   case SET_ACR_ICTL:
	    { ICTL_COM_BUF = (0xc0);
	      ICTL_DATA_BUF = xcb->value.c[0];
	      break;
	    }
	   case GET_ICTL:
	    { ICTL_COM_BUF = (0xa0 | (xcb->addr << 2));
	      xcb->value.c[0] = ICTL_DATA_BUF;
	      break;
	    }
	   case GET_ICTL_STATUS:
	    { xcb->value.c[0] = ICTL_COM_BUF;
	      break;
	    }
	   case ENABLE_ICTL:
	    { ICTL_COM_BUF = 0xa1;
	      break;
	    }
	   case DISABLE_ICTL:
	    { ICTL_COM_BUF = 0xa2;
	      break;
	    }
	   case SET_VECTOR:
	    { ICTL_COM_BUF = (0xe0 | xcb->addr);
	      ICTL_DATA_BUF = xcb->value.c[0];
/*	      ICTL_DATA_BUF = 0x23;*/
	      break;
	    }
	   case GET_CSR:
	    { xcb->value.c[0] = CSR;
	      break;
	    }
	   case SET_CSR:
	    { CSR = xcb->value.c[0];
	      break;
	    }
	 }
	return (1);
}
