Esempio n. 1
0
Ps2Input::Ps2Input(OSystem_PS2 *system, bool mouseLoaded, bool kbdLoaded) {
	_system = system;
	_mouseLoaded = mouseLoaded;
	_kbdLoaded = kbdLoaded;
	_pad = new Ps2Pad(system);
	_lastPadCheck = 0;
	_posX = _posY = _mButtons = _padLastButtons = 0;
	_padAccel = 0;
	_minx = _miny = 0;
	_maxy = 239;
	_maxx = 319;
	_keyFlags = 0;
	if (_mouseLoaded) {
		if (PS2MouseInit() >= 0) {
			PS2MouseSetReadMode(PS2MOUSE_READMODE_ABS);
			printf("PS2Mouse initialized\n");
		} else { // shouldn't happen if the drivers were correctly loaded
			printf("unable to initialize PS2Mouse!\n");
			_mouseLoaded = false;
		}
	}
	if (_kbdLoaded) {
		if (PS2KbdInit() >= 0) {
			PS2KbdSetReadmode(PS2KBD_READMODE_RAW);
			printf("PS2Kbd initialized\n");
		} else {
			printf("unable to initialize PS2Kbd!\n");
			_kbdLoaded = false;
		}
	}
}
/*
 Load the embedded USB mouse driver and then initialize the mouse
 */
int PS2_InitMouse(_THIS)
{
	int ret;

	printf("[PS2] Init USB Mouse\n");

	// the mouse driver is embedded in the library....
	SifExecModuleBuffer(ps2mouse_irx_start, ps2mouse_irx_size, 0, NULL, &ret);
	if (ret < 0)
	{
		SDL_SetError("[PS2] Failed to load module: PS2MOUSE.IRX\n");

		if(PS2_InitPad() == 0)
		{
			mouseState = PAD_AVAILABLE;
			printf("[PS2] Init PAD Mouse emulation done\n");
			return 0;
		}

		mouseState = MOUSE_NOT_AVAILABLE;
		printf("[PS2] No mouse or pad available\n");
		return -1;
	}
	else
	{
		// Initialize the mouse
		if(PS2MouseInit() < 0) 
		{
			SDL_SetError("[PS2] PS2MouseInit failed\n");

			if (PS2_InitPad() > 0)
			{
				mouseState = PAD_AVAILABLE;
				printf("[PS2] Init PAD Mouse emulation done\n");
			}
			else
			{
				printf("[PS2] Init USB Mouse and Pad emulation failed\n");
				mouseState = MOUSE_NOT_AVAILABLE;
				return -1;
			}
		}
		else
		{
			mouseState = MOUSE_AVAILABLE;
			printf("[PS2] Init USB Mouse done\n");
		}
	}

	return 0;
}