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

#include "soh.h"
#include "joy.h"

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

JOYENV joy[4];
NJS_PERIPHERAL *per[4];
/*--------------------------------------------------------------------------*/
void ixJoyServer(void)
{
	SLONG i;
	
	for(i=0; i<1; i++) {
		per[i] = njGetPeripheral(i2p[i]);
		
		sxMemSetB(&joy[i], 0, sizeof(JOYENV));
		if (per[i]->on & NJD_DGT_TA) joy[i].on |= JOY_BTN_A;
		if (per[i]->on & NJD_DGT_TB) joy[i].on |= JOY_BTN_B;
/*		if (per[i]->on & NJD_DGT_TC) joy[i].on |= JOY_BTN_C;*/
/*		if (per[i]->on & NJD_DGT_TX) joy[i].on |= JOY_BTN_X;*/
/*		if (per[i]->on & NJD_DGT_TY) joy[i].on |= JOY_BTN_Y;*/
/*		if (per[i]->on & NJD_DGT_TZ) joy[i].on |= JOY_BTN_Z;*/
		if (per[i]->on & NJD_DGT_TL) joy[i].on |= JOY_BTN_L;
		if (per[i]->on & NJD_DGT_TR) joy[i].on |= JOY_BTN_R;
		if (per[i]->on & NJD_DGT_KU) joy[i].on |= JOY_DIR_U;
		if (per[i]->on & NJD_DGT_KD) joy[i].on |= JOY_DIR_D;
		if (per[i]->on & NJD_DGT_KL) joy[i].on |= JOY_DIR_L;
		if (per[i]->on & NJD_DGT_KR) joy[i].on |= JOY_DIR_R;
		
		if (per[i]->press & NJD_DGT_TA) joy[i].push |= JOY_BTN_A;
		if (per[i]->press & NJD_DGT_TB) joy[i].push |= JOY_BTN_B;
/*		if (per[i]->press & NJD_DGT_TC) joy[i].push |= JOY_BTN_C;*/
/*		if (per[i]->press & NJD_DGT_TX) joy[i].push |= JOY_BTN_X;*/
/*		if (per[i]->press & NJD_DGT_TY) joy[i].push |= JOY_BTN_Y;*/
/*		if (per[i]->press & NJD_DGT_TZ) joy[i].push |= JOY_BTN_Z;*/
		if (per[i]->press & NJD_DGT_TL) joy[i].push |= JOY_BTN_L;
		if (per[i]->press & NJD_DGT_TR) joy[i].push |= JOY_BTN_R;
		if (per[i]->press & NJD_DGT_KU) joy[i].push |= JOY_DIR_U;
		if (per[i]->press & NJD_DGT_KD) joy[i].push |= JOY_DIR_D;
		if (per[i]->press & NJD_DGT_KL) joy[i].push |= JOY_DIR_L;
		if (per[i]->press & NJD_DGT_KR) joy[i].push |= JOY_DIR_R;
	}
}
/*--------------------------------------------------------------------------*/
long ixJoyOnCheck(long n, u_short f)
{
	if (joy[n].on & f) return 1;
	return 0;
}
/*--------------------------------------------------------------------------*/
long ixJoyPushCheck(long n, u_short f)
{
	if (joy[n].push & f) return 1;
	return 0;
}
/*--------------------------------------------------------------------------*/
