Example #1
0
void PadInitPads(void)
{
	padInit(0);
	padPortOpen(0, 0, padArea[0]);
	padPortOpen(1, 0, padArea[1]);

	memset(old_pad, 0, sizeof(old_pad));
}
Example #2
0
Ps2Pad::Ps2Pad(OSystem_PS2 *system) {
	_system = system;
	_padBuf = (uint8 *)memalign(64, 256);
	_padStatus = STAT_NONE;

	padInit(0); // initialize library
	_port = _slot = 0; // first controller, no multitap
	initPad();
}
Example #3
0
void init_basic_modules(const char *path)
{

	char *gz;
	int gz_size;

	module_t basic_modules[7] =
	{
		{              "sio2man", "freesio2.irx", NULL, 0, 0 },
		{                "mcman",    "mcman.irx", NULL, 0, 0 },
		{               "mcserv",   "mcserv.irx", NULL, 0, 0 },
		{              "mtapman", "freemtap.irx", NULL, 0, 0 },
		{               "padman",  "freepad.irx", NULL, 0, 0 },
		{     "IOX/File_Manager",   "iomanX.irx", NULL, 0, 0 },
		{ "IOX/File_Manager_Rpc",  "fileXio.irx", NULL, 0, 0 }
	};

	gz = init_modules_tgz(path,&gz_size);

	init_load_irx(gz, gz_size, basic_modules, 7);

	// Init various libraries
	mcInit(MC_TYPE_MC);

	mtapInit();

	padInit(0);

	mtapPortOpen(0);
	mtapPortOpen(1);

	if (!basic_modules[6].result)
	{
		fileXioInit();
	}
	else
	{
		// Problem initializing fileXio modules
		fioInit();
	}

	if (gz != (char*)modules_tgz)
	{
		free(gz);
	}

}
Example #4
0
void initalise(void)
{
	int ret;
	
	// load all modules
	loadModules();
	// init pad
	padInit(0);
	if((ret = padPortOpen(0, 0, padBuf)) == 0) {
		#if defined DEBUG
			scr_printf("padOpenPort failed: %d\n", ret);
		#endif
		SleepThread();
	}

	if(!initializePad(0, 0)) {
		#if defined DEBUG
			scr_printf("pad initalization failed!\n");
		#endif
		SleepThread();
	}
}
Example #5
0
static void frontend_ps2_init(void *data)
{
   char cwd[FILENAME_MAX];
   int bootDeviceID;

   SifInitRpc(0);
#if !defined(DEBUG)
   /* Comment this line if you don't wanna debug the output */
   while(!SifIopReset(NULL, 0)){};
#endif

   while(!SifIopSync()){};
   SifInitRpc(0);
   sbv_patch_enable_lmb();

   /* I/O Files */
   SifExecModuleBuffer(&iomanX_irx, size_iomanX_irx, 0, NULL, NULL);
   SifExecModuleBuffer(&fileXio_irx, size_fileXio_irx, 0, NULL, NULL);
   SifExecModuleBuffer(&freesio2_irx, size_freesio2_irx, 0, NULL, NULL);

   /* Memory Card */
   SifExecModuleBuffer(&mcman_irx, size_mcman_irx, 0, NULL, NULL);
   SifExecModuleBuffer(&mcserv_irx, size_mcserv_irx, 0, NULL, NULL);

   /* Controllers */
   SifExecModuleBuffer(&freemtap_irx, size_freemtap_irx, 0, NULL, NULL);
   SifExecModuleBuffer(&freepad_irx, size_freepad_irx, 0, NULL, NULL);

   /* USB */
   SifExecModuleBuffer(&usbd_irx, size_usbd_irx, 0, NULL, NULL);
   SifExecModuleBuffer(&usbhdfsd_irx, size_usbhdfsd_irx, 0, NULL, NULL);

   /* Audio */
   SifExecModuleBuffer(&freesd_irx, size_freesd_irx, 0, NULL, NULL);
   SifExecModuleBuffer(&audsrv_irx, size_audsrv_irx, 0, NULL, NULL);

   /* CDVD */
   SifExecModuleBuffer(&cdvd_irx, size_cdvd_irx, 0, NULL, NULL);

   if (mcInit(MC_TYPE_XMC)) {
      RARCH_ERR("mcInit library not initalizated\n");
   }

   /* Initializes audsrv library */
   if (audsrv_init()) {
      RARCH_ERR("audsrv library not initalizated\n");
   }

   /* Initializes pad libraries
      Must be init with 0 as parameter*/
   if (mtapInit() != 1) {
      RARCH_ERR("mtapInit library not initalizated\n");
   }
   if (padInit(0) != 1) {
      RARCH_ERR("padInit library not initalizated\n");
   }
   if (mtapPortOpen(0) != 1) {
      RARCH_ERR("mtapPortOpen library not initalizated\n");
   }

   /* Initializes CDVD library */
   /* SCECdINoD init without check for a disc. Reduces risk of a lockup if the drive is in a erroneous state. */
   sceCdInit(SCECdINoD);
   if (CDVD_Init() != 1) {
      RARCH_ERR("CDVD_Init library not initalizated\n");
   }

   _init_ps2_io();

   /* Prepare device */
   getcwd(cwd, sizeof(cwd));
   bootDeviceID=getBootDeviceID(cwd);
   waitUntilDeviceIsReady(bootDeviceID);

#if defined(HAVE_FILE_LOGGER)
   retro_main_log_file_init("retroarch.log");
   verbosity_enable();
#endif
}
Example #6
0
void InitPS2()
{
    int i, sometime;
    static char hddarg[] = "-o" "\0" "4" "\0" "-n" "\0" "20";
    static char pfsarg[] = "-m" "\0" "4" "\0" "-o" "\0" "10" "\0" "-n" "\0" "40";

    SifInitRpc(0);
    // Reset IOP borrowed from uLaunchelf
    while (!SifIopReset(NULL, 0)){};
    while (!SifIopSync()){};
    SifInitRpc(0);

    sbv_patch_enable_lmb();

    SifExecModuleBuffer(&iomanX_irx, size_iomanX_irx, 0, NULL, NULL);
    SifExecModuleBuffer(&fileXio_irx, size_fileXio_irx, 0, NULL, NULL);
    SifExecModuleBuffer(&freesio2_irx, size_freesio2_irx, 0, NULL, NULL);

 /* SifLoadModule("rom0:XSIO2MAN", 0, NULL);
    SifLoadModule("rom0:XMCMAN", 0, NULL);
    SifLoadModule("rom0:XMCSERV", 0, NULL);
    SifLoadModule("rom0:XMTAPMAN", 0, NULL);
    SifLoadModule("rom0:XPADMAN", 0, NULL); */

    SifExecModuleBuffer(&mcman_irx, size_mcman_irx, 0, NULL, NULL);
    SifExecModuleBuffer(&mcserv_irx, size_mcserv_irx, 0, NULL, NULL);
    SifExecModuleBuffer(&freemtap_irx, size_freemtap_irx, 0, NULL, NULL);
    SifExecModuleBuffer(&freepad_irx, size_freepad_irx, 0, NULL, NULL);

#ifdef SOUND_ON
    SifExecModuleBuffer(&freesd_irx, size_freesd_irx, 0, NULL, NULL);
    SifExecModuleBuffer(&audsrv_irx, size_audsrv_irx, 0, NULL, NULL);
#endif
    SifExecModuleBuffer(&SMSUTILS_irx, size_SMSUTILS_irx, 0, NULL, NULL);
    SifExecModuleBuffer(&usbd_irx, size_usbd_irx, 0, NULL, NULL);
    SifExecModuleBuffer(&usbhdfsd_irx, size_usbhdfsd_irx, 0, NULL, NULL);
    for (i = 0; i < 3; i++) { // Taken from ulaunchelf
        sometime = 0x01000000;
        while (sometime--) asm("nop\nnop\nnop\nnop");
    }

    SifExecModuleBuffer(&poweroff_irx, size_poweroff_irx, 0, NULL, NULL);
    SifExecModuleBuffer(&ps2dev9_irx, size_ps2dev9_irx, 0, NULL, NULL);
    SifExecModuleBuffer(&ps2atad_irx, size_ps2atad_irx, 0, NULL, NULL);
    SifExecModuleBuffer(&ps2hdd_irx, size_ps2hdd_irx, sizeof(hddarg), hddarg, NULL);
    SifExecModuleBuffer(&ps2fs_irx, size_ps2fs_irx, sizeof(pfsarg), pfsarg, NULL);

    mcInit(MC_TYPE_XMC);

#ifdef CDSUPPORT
    SifExecModuleBuffer(&cdvd_irx, size_cdvd_irx, 0, NULL, NULL);
    cdInit(CDVD_INIT_INIT);
    CDVD_Init();
#endif

#ifdef SOUND_ON
    audsrv_init();
#endif

    mtapInit();
    padInit(0);
    mtapPortOpen(0);
}
Example #7
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;
}
Example #8
0
File: padx.c Project: jur/ps2sdk
int main(int argc, char **argv)
{
	u32 port;
	struct padButtonStatus buttons;
	int dualshock[2];
	int acts[2];

	SifInitRpc(0);
 
	printf("libpadx sample");
	
	if((argc == 2) && (strncmp(argv[1], "free", 4) == 0))
	{
		printf(" - Using PS2SDK freesio2.irx and freepad.irx modules.\n");
		loadmodules(1);	
	}
	else
	{
		printf(" - Using ROM XSIO2MAN and XPADMAN modules.\n");
		printf("Start this sample with 'free' as an argument to load freesio2.irx and freepad.irx\n");
		printf("Example: ps2client execee host:padx_sample.elf free\n");
		loadmodules(0);
	}


	

	padInit(0);
	
	padBuf[0] = memalign(64, 256);
	padBuf[1] = memalign(64, 256);

	old_pad[0] = 0;
	old_pad[1] = 0;	

	portConnected[0] = 0;
	portConnected[1] = 0;

	dualshock[0] = 0;
	dualshock[1] = 0;

	acts[0] = 0;
	acts[1] = 0;

	padPortOpen(0, 0, padBuf[0]);
	padPortOpen(1, 0, padBuf[1]);

	while(1)
	{	
		for(port=0; port < 2; port++)
		{
			s32 state = padGetState(port, 0);

			if((state == PAD_STATE_STABLE) && (portConnected[port] == 0)) 
			{
				u32 i;
				u8 mTable[8];
				u32 ModeCurId;
				u32 ModeCurOffs;
				u32 ModeCurExId;
				u32 ModeTableNum = padInfoMode(port, 0, PAD_MODETABLE, -1);
				
				printf("Controller (%i) connected\n", port);

				/* Check if dualshock and if so, activate analog mode */
				for(i = 0; i < ModeTableNum; i++)
					mTable[i] = padInfoMode(port, 0, PAD_MODETABLE, i);
				
				/* Works for dualshock2 */
				if((mTable[0] == 4) && (mTable[1] == 7) && (ModeTableNum == 2))
					dualshock[port] = 1;

				/* Active and lock analog mode */
				if(dualshock[port] == 1)
				{
					padSetMainMode(port, 0, PAD_MMODE_DUALSHOCK, PAD_MMODE_LOCK);
					padWait(port);
				}
				
				ModeCurId = padInfoMode(port, 0, PAD_MODECURID, 0);
				ModeCurOffs = padInfoMode(port, 0, PAD_MODECUROFFS, 0);
				ModeCurExId = padInfoMode(port, 0, PAD_MODECUREXID, 0);
				ModeTableNum = padInfoMode(port, 0, PAD_MODETABLE, -1);
				acts[port] = padInfoAct(port, 0, -1, 0);		

				printf("  ModeCurId      : %i (%s)\n", (int)ModeCurId, padTypeStr[ModeCurId]);
				printf("  ModeCurExId    : %i\n", (int)ModeCurExId);
				printf("  ModeTable      : ");
		
				for(i = 0; i < ModeTableNum; i++)
				{
					mTable[i] = padInfoMode(port, 0, PAD_MODETABLE, i);
					printf("%i ", (int)mTable[i]);
				}	

				printf("\n");
				printf("  ModeTableNum   : %i\n", (int)ModeTableNum);
				printf("  ModeCurOffs    : %i\n", (int)ModeCurOffs);
				printf("  NumOfAct       : %i\n", (int)acts[port]);
				printf("  PressMode      : %i\n", (int)padInfoPressMode(port, 0));

	
				if(acts[port] > 0)
				{
					u8 actAlign[6] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
					u32 i;

					/* Set offsets for motor parameters for SetActDirect. */
					for(i=0; i < acts[port]; i++)
						actAlign[i] = i;

					padSetActAlign(port, 0, actAlign);
					padWait(port);
				}

				printf("  EnterPressMode : %i\n", (int)padEnterPressMode(port, 0));
				padWait(port);

				printf("Ready\n");

				portConnected[port] = 1;
			}

			if((state == PAD_STATE_DISCONN) && (portConnected[port] == 1))
			{ 
				printf("Controller (%i) disconnected\n", port);
				portConnected[port] = 0;
			}

			if(portConnected[port] == 1)
			{
				s32 ret = padRead(port, 0, &buttons);

				if(ret != 0)
				{
					paddata[port] = 0xffff ^ buttons.btns;
	
					new_pad[port] = paddata[port] & ~old_pad[port];
					old_pad[port] = paddata[port];

					// Values 50 and 200 used because my controllers are worn out :-)
					if((buttons.ljoy_h <= 50) || (buttons.ljoy_h >= 200)) printf("Left Analog  X: %i\n", (int)buttons.ljoy_h);
					if((buttons.ljoy_v <= 50) || (buttons.ljoy_v >= 200)) printf("Left Analog  Y: %i\n", (int)buttons.ljoy_v);
					if((buttons.rjoy_h <= 50) || (buttons.rjoy_h >= 200)) printf("Right Analog X: %i\n", (int)buttons.rjoy_h);
					if((buttons.rjoy_v <= 50) || (buttons.rjoy_v >= 200)) printf("Right Analog Y: %i\n", (int)buttons.rjoy_v);

				
					if(new_pad[port]) printf("Controller (%i) button(s) pressed: ", (int)port);
	            	if(new_pad[port] & PAD_LEFT)		printf("LEFT ");
					if(new_pad[port] & PAD_RIGHT) 		printf("RIGHT ");
					if(new_pad[port] & PAD_UP) 			printf("UP ");		
					if(new_pad[port] & PAD_DOWN) 		printf("DOWN ");
					if(new_pad[port] & PAD_START) 		printf("START ");
					if(new_pad[port] & PAD_SELECT) 		printf("SELECT ");
					if(new_pad[port] & PAD_SQUARE) 		printf("SQUARE (Pressure: %i) ", (int)buttons.square_p);
					if(new_pad[port] & PAD_TRIANGLE)	printf("TRIANGLE (Pressure: %i) ", (int)buttons.triangle_p);
					if(new_pad[port] & PAD_CIRCLE)		printf("CIRCLE (Pressure: %i) ", (int)buttons.circle_p);
					if(new_pad[port] & PAD_CROSS)		printf("CROSS (Pressure: %i) ", (int)buttons.cross_p);
					if(new_pad[port] & PAD_L1)			
					{	
						printf("L1 (Start Little Motor) ");	
						padStartAct(port, 0, 1); 
					}
					if(new_pad[port] & PAD_L2)			
					{	
						printf("L2 (Stop Little Motor) ");	
						padStartAct(port, 0, 0); 
					}
					if(new_pad[port] & PAD_L3)			printf("L3 ");
					if(new_pad[port] & PAD_R1)
					{
						printf("R1 (Start Big Motor) ");
						padStartAct(port, 1, 255);
					}
					if(new_pad[port] & PAD_R2)			
					{
						printf("R2 (Stop Big Motor) ");
						padStopAct(port, 1);
					}
					if(new_pad[port] & PAD_R3)			printf("R3 ");

					if(new_pad[port]) printf("\n");
				}	
	
			}
		}
		wait_vsync();
	}

	return 0;
}