Exemplo n.º 1
0
/** Starts all pads. 
* @return Count of dual shock compatible pads. 0 if none present. */
int startPads() {
	// scan for pads that exist... at least one has to be present
	pad_count = 0;

	int maxports = padGetPortMax();

	int port; // 0 -> Connector 1, 1 -> Connector 2
	int slot; // Always zero if not using multitap
		
	for (port = 0; port < maxports; ++port) {
		int maxslots = padGetSlotMax(port);
		
		for (slot = 0; slot < maxslots; ++slot) {
		
			struct pad_data_t* cpad = &pad_data[pad_count];
			
			cpad->port = port;
			cpad->slot = slot;
			
			if (startPad(cpad))
				++pad_count;
		}
		
		if (pad_count >= MAX_PADS)
			break; // enough already!
	}
	
	int n;
	for(n=0; n<16; ++n) {
		delaycnt[n]=DEFAULT_PAD_DELAY;
		paddelay[n]=DEFAULT_PAD_DELAY;
	}
	
	return pad_count;
}
Exemplo n.º 2
0
/* Function to scan the system for joysticks.
 * This function should set SDL_numjoysticks to the number of available
 * joysticks.  Joystick 0 should be the system default joystick.
 * It should return number of joysticks, or -1 on an unrecoverable fatal error.
 */
int SDL_SYS_JoystickInit(void)
{
	int ret;
	int mtap_enabled;
	int index;
	int numports, numdevs;
	int port, slot;

	printf("SDL_Joystick: JoystickInit begins\n");

#ifdef PS2SDL_ENABLE_MTAP
	ret = SifLoadModule("rom0:XSIO2MAN", 0, NULL);
	if (ret < 0)
	{
		SDL_SetError("Failed to load XSIO2MAN");
		return 0;
	}

	ret = SifLoadModule("rom0:XPADMAN", 0, NULL);
	if (ret < 0)
	{
		SDL_SetError("Failed to load XPADMAN");
		return 0;
	}

	ret = SifLoadModule("rom0:XMTAPMAN", 0, NULL);
	if (ret < 0)
	{
		SDL_SetError("Failed to load XMTAPMAN");
		return 0;
	}
#else
	ret = SifLoadModule("rom0:SIO2MAN", 0, NULL);
	if (ret < 0)
	{
		SDL_SetError("Failed to load SIO2MAN");
		return 0;
	}

	ret = SifLoadModule("rom0:PADMAN", 0, NULL);
	if (ret < 0)
	{
		SDL_SetError("Failed to load PADMAN");
		return 0;
	}
#endif

	ret = padInit(0);
	printf("SDL_Joystick: padInit: %d\n", ret);

#ifdef PS2SDL_ENABLE_MTAP
	ret = mtapInit();
	printf("SDL_Joystick: mtapInit: %d\n", ret);
#endif

	numdevs = 0;
	numports = padGetPortMax();
	
	printf("SDL_Joystick: numports %d\n", numports);
	
	index = 0;

#ifdef PS2SDL_ENABLE_MTAP
	/* gawd: look for mtap connection on one of the ports. if it's there,
	 * then don't support the only interface.
	 */
	if (mtapPortOpen(0) == 1 && mtapGetConnection(0) == 1)
	{
		/* found on port 0 */
		mtap_enabled = 1;
		mtapPortClose(0);
		printf("SDL_Joystick: found mtap on port 0\n");
	}
	else if (mtapPortOpen(1) == 1 && mtapGetConnection(1) == 1)
	{
		/* found on port 1 */
		mtap_enabled = 1;
		mtapPortClose(1);
		printf("SDL_Joystick: found mtap on port 1\n");
	}
	else
	{
		mtap_enabled = 0;
		printf("SDL_Joystick: mtap adapter not found on either ports\n");
	}
#endif

	for (port=0; port<numports; port++)
	{
		int maxslots;

#ifdef PS2SDL_ENABLE_MTAP
		if (mtap_enabled)
		{
			ret = mtapPortOpen(port);
			printf("\nSDL_Joystick: Port: %d, mtapPortOpen: %d\n", port, ret);

			ret = mtapGetConnection(port);
			printf("SDL_Joystick: Port: %d, mtapGetConnection: %d\n", port, ret);

			if (ret != 1)
			{
				/* failed */
				mtapPortClose(port);
				continue;
			}
		}
#endif

		maxslots = padGetSlotMax(port);
		printf("SDL_Joystick: Port %d, MaxSlots: %d\n", port, maxslots);

		for (slot=0; slot<maxslots; slot++)
		{
			ret = padPortOpen(port, slot, &padbufs[256*index]);
			if (ret < 0)
			{
				//SDL_SetError("padPortOpen %d, %d failed\n", port, slot);
				//return 0;
				continue;
			}

			printf("Joystick %d at port=%d slot=%d\n", index, port, slot);
			joyports[index] = port;
			joyslots[index] = slot;
			index++;
		}
	}
 	
	SDL_numjoysticks = index;
	printf("SDL_Joystick: JoystickInit ends with %d joysticks\n", SDL_numjoysticks);
	return SDL_numjoysticks;
}