/*--------------------------------------------------------------------------*/

#include "soh.h"
#include "ipx.h"
/*#include <sg_pdvib.h> Remove the vibration feature*/

static const SLONG i2p[] = {
	PDD_PORT_A0,
	PDD_PORT_B0,
	PDD_PORT_C0,
	PDD_PORT_D0,
};

static NJS_PERIPHERAL *PL[4];
/*--------------------------------------------------------------------------*/
/* ペリフェラル初期化														*/
void sxInitPeripheral(void)
{
	SDX->peri[0].input = SX_JOYSTICK1;
	SDX->peri[1].input = SX_JOYSTICK2;
	SDX->peri[2].input = SX_JOYSTICK3;
	SDX->peri[3].input = SX_JOYSTICK4;
	
	PL[0] = njGetPeripheral(i2p[0]);
	PL[1] = njGetPeripheral(i2p[1]);
	PL[2] = njGetPeripheral(i2p[2]);
	PL[3] = njGetPeripheral(i2p[3]);
}
/*--------------------------------------------------------------------------*/
/* ペリフェラルサーバー														*/
void sxGetPeripheral(void)
{
	SLONG i;
	SX_PERIPHERAL *P = &SDX->peri[0];
	
	for(i=0; i<1; i++) {
		P->on    = ixTraceDoing(PL[i]->on);
		P->press = P->on    & (~P->back);
		P->back  =(P->press ^   P->back)&P->on;
		P++;
	}
}
/*--------------------------------------------------------------------------*/
BOOL sxKeyStatus(SLONG no, ULONG keys, ULONG flag)
{
	ULONG stat,all;

	switch (flag) {
	case SX_KEY_ON:       stat = SDX->peri[no].on;    all=0; break;
	case SX_KEY_OFF:      stat =~SDX->peri[no].on;    all=0; break;
	case SX_KEY_PRESS:    stat = SDX->peri[no].press; all=0; break;
	case SX_KEY_ALLON:    stat = SDX->peri[no].on;    all=1; break;
	case SX_KEY_ALLOFF:   stat =~SDX->peri[no].on;    all=1; break;
	case SX_KEY_ALLPRESS: stat = SDX->peri[no].press; all=1; break;
	}
	
	if (all) {
		if ((stat&keys)==flag) return TRUE;
	} else {
		if ((stat&keys)!=0) return TRUE;
	}
	return FALSE;
}
/*--------------------------------------------------------------------------*/
BOOL sxCheckSoftReset(void)
{
	if ((PL[0]->press&SX_BTN_ST)&&(PL[0]->on&SX_BTN_TA)&&(PL[0]->on&SX_BTN_TB))
		return TRUE;
	return FALSE;
}
/*--------------------------------------------------------------------------*/
void sxVibrate(ULONG md, ULONG dir, SLONG vol)
{
/*	PDS_VIBPARAM param;
	
	if (!pdVibMxIsReady(PDD_PORT_A2)) return;
	
	switch (md) {
	case VIB_MODE_STOP:
		pdVibMxStop(PDD_PORT_A2);
		return;
	case VIB_MODE_ONE:
		param.flag = 0;
		break;
	case VIB_MODE_CONT:
		param.flag = PDD_VIB_FLAG_CONTINUOUS;
		break;
	case VIB_MODE_CONV:
		param.flag = PDD_VIB_FLAG_CONVERGENCE;
		break;
	}
	
	param.unit = 1;
	param.power = vol;
	param.freq = 7;
	param.inc = 1;
	pdVibMxStart(PDD_PORT_A2, &param);
*/
}
/*--------------------------------------------------------------------------*/
