/*-=-=-=-=-=-=-=-=-=-=-=- RCCL/RCI Notice of Copyright -=-=-=-=-=-=-=-=-=-=-*
 *									    *
 *	Copyright (C) 1987, 1991 by John E. Lloyd.			    *
 *									    *
 *	Information on copyright permissions, as well as a complete	    *
 *	disclaimer of warranty, is given in the file COPYRIGHT.		    *
 *									    *
 *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/

#include "../h/rci.h"
#include "../h/errorCodes.h"

#include "rciProbe.h"

doPeek(td, arg)
RCI_DESC *td;
int arg;
{
	PROBE_BLK *pbk;
	unsigned char *addr;

	if ((pbk = (PROBE_BLK*)getMemByAddr((void*)arg)) == NULL)
	 { rciAbort (EInternal, "can't find parameter block\n");
	   return (-1);
	 }
	addr = pbk->base + pbk->addr;
	if (rciBadAddr (addr, pbk->accessSize))
	 { return (0);
	 }
	switch (pbk->accessSize)
	 { case 1:
	    { pbk->value = *(unsigned char*)(addr);
	      break;
	    }
	   case 2:
	    { pbk->value = *(unsigned short*)(addr);
	      break;
	    }
	   case 4:
	    { pbk->value = *(unsigned long*)(addr);
	      break;
	    }
	 }
	return (1);
}

doPoke(td, arg)
RCI_DESC *td;
int arg;
{
	PROBE_BLK *pbk;
	unsigned char *addr;

	if ((pbk = (PROBE_BLK*)getMemByAddr((void*)arg)) == NULL)
	 { rciAbort (EInternal, "can't find parameter block\n");
	   return (-1);
	 }
	addr = pbk->base + pbk->addr;
	if (rciBadAddr (addr, pbk->accessSize))
	 { return (0);
	 }
	switch (pbk->accessSize)
	 { case 1:
	    { *(unsigned char*)(addr) = (unsigned char)pbk->value;
	      pbk->value = *(unsigned char*)(addr);
	      break;
	    }
	   case 2:
	    { *(unsigned short*)(addr) = (unsigned short)pbk->value;
	      pbk->value = *(unsigned short*)(addr);
	      break;
	    }
	   case 4:
	    { *(unsigned long*)(addr) = pbk->value;
	      pbk->value = *(unsigned long*)(addr);
	      break;
	    }
	 }
	return (1);
}
