Exemple #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;
		}
	}
}
/*
 Callback triggered when the video mode is set (or changed)
 It will recalibrate the mouse boundaries according to video mode width and height
 */
void PS2_UpdateMouse(_THIS)
{
	if (mouseState == MOUSE_AVAILABLE)
	{
		//recalibrate PS2 mouse depending on video resolution, must be called at resolution change...
		int width = this->screen->w;
		int height = this->screen->h;

		// Set mouse boundaries
		PS2MouseSetBoundary(0, width, 0 , height);
		PS2MouseSetReadMode(PS2MOUSE_READMODE_DIFF);

		// Set initial mouse position, threshold and acceleration
		PS2MouseSetPosition(width/2, height/2);
		PS2MouseSetAccel(ACC_DEF);
		PS2MouseSetThres(THRES_DEF);

		printf("[PS2] Mouse calibrated for (0,0,%d,%d)\n[P22] with threshold %d and acceleration %f\n", width, height, THRES_DEF, ACC_DEF);
	}
	else if (mouseState == PAD_AVAILABLE)
	{
		//recalibrate PS2 pad depending on video resolution, must be called at resolution change...
		int width = this->screen->w;
		int height = this->screen->h;

		PADSTEP = width >> 7;
		printf("[PS2] Mouse Pad calibrated for (0,0,%d,%d)\n[P22] with threshold %d and acceleration %f\n", width, height, PADSTEP, 1.0);
	}