Exemple #1
0
/******************************************************************
  Function: GetKeys
  Purpose:  To get the current state of the controllers buttons.
  input:    - Controller Number (0 to 3)
            - A pointer to a BUTTONS structure to be filled with 
			the controller state.
  output:   none
*******************************************************************/  	
EXPORT void CALL GetKeys(int Control, BUTTONS * Keys )
{
#ifdef ENABLE_RAWPAK_DEBUG
	DebugWriteA("CALLED: GetKeys\n");
#endif
	if( g_bConfiguring )
		Keys->Value = 0;
	else
	{
		EnterCriticalSection( &g_critical );
		
		if( g_pcControllers[Control].fPlugged ) {
			if (Control == g_iFirstController )
			{
				GetDeviceDatas();
				CheckShortcuts();
			}
			if( g_pcControllers[Control].xiController.bConnected && g_pcControllers[Control].fXInput )	// reads the xinput controller keys, if connected --tecnicors
				GetXInputControllerKeys( &g_pcControllers[Control].xiController, &Keys->Value );
			else
				GetNControllerInput( Control, &Keys->Value );
		}
		LeaveCriticalSection( &g_critical );
	}
	return;
}
Exemple #2
0
/******************************************************************
  Function: ReadController
  Purpose:  To process the raw data in the pif ram that is about to
            be read.
  input:    - Controller Number (0 to 3) and -1 signalling end of 
              processing the pif ram.
			- Pointer of data to be processed.
  output:   none  
  note:     This function is only needed if the DLL is allowing raw
            data.
*******************************************************************/
EXPORT void CALL ReadController( int Control, BYTE * Command )
{
#ifdef ENABLE_RAWPAK_DEBUG
	DebugWriteA("CALLED: ReadController\n");
#endif
	if( Control == -1 )
		return;

	EnterCriticalSection( &g_critical );

	if( !g_pcControllers[Control].fPlugged )
	{
		Command[1] |= RD_ERROR;
		LeaveCriticalSection( &g_critical );
		return;
	}

	
	switch( Command[2] )
	{
	case RD_RESETCONTROLLER:
		WriteDatasA( "ResetController-PreProcessing", Control, Command, 0);
	case RD_GETSTATUS:
		// expected: controller gets 1 byte (command), controller sends back 3 bytes
		// should be:	Command[0] == 0x01
		//				Command[1] == 0x03
#ifdef ENABLE_RAWPAK_DEBUG
		WriteDatasA( "GetStatus-PreProcessing", Control, Command, 0);
#endif
		Command[3] = RD_GAMEPAD | RD_ABSOLUTE;
		Command[4] = RD_NOEEPROM;

		if( g_pcControllers[Control].fPakInitialized && g_pcControllers[Control].pPakData )
		{
			if( *(BYTE*)g_pcControllers[Control].pPakData == PAK_ADAPTOID )
			{
				Command[5] = GetAdaptoidStatus( Control );

				if( Command[5] & RD_NOTINITIALIZED )
					((ADAPTOIDPAK*)g_pcControllers[Control].pPakData)->fRumblePak = true;
			}
			else
			{
				Command[5] = ( *(BYTE*)g_pcControllers[Control].pPakData != PAK_NONE ) ? RD_PLUGIN : RD_NOPLUGIN;
				if( g_pcControllers[Control].fPakCRCError )
				{
					Command[5] = Command[5] | RD_ADDRCRCERR;
					g_pcControllers[Control].fPakCRCError = false;
				}
			}
		}
		else
		{
			if( !g_bConfiguring && InitControllerPak( Control ) && g_pcControllers[Control].pPakData )
			{
				g_pcControllers[Control].fPakInitialized = true;

				if( *(BYTE*)g_pcControllers[Control].pPakData == PAK_ADAPTOID )
					Command[5] = GetAdaptoidStatus( Control );
				else
				{
					Command[5] = ( *(BYTE*)g_pcControllers[Control].pPakData ) ? RD_PLUGIN : RD_NOPLUGIN;
					Command[5] = Command[5] | ( g_pcControllers[Control].fPakCRCError ? RD_ADDRCRCERR : 0 );
				}
			}
			else
				Command[5] = RD_NOPLUGIN | RD_NOTINITIALIZED;
		}

		if( g_pcControllers[Control].fPakCRCError )
		{
			Command[5] = Command[5] | RD_ADDRCRCERR;
			g_pcControllers[Control].fPakCRCError = false;
		}

#ifdef ENABLE_RAWPAK_DEBUG
		WriteDatasA( "GetStatus-PostProcessing", Control, Command, 0);
		DebugWriteA( NULL );
#endif
		break;

	case RD_READKEYS:
		// expected: controller gets 1 byte (command), controller sends back 4 bytes
		// should be:	Command[0] == 0x01
		//				Command[1] == 0x04
		if( g_bConfiguring )
			Command[3] = Command[4] = Command[5] = Command[6] = 0;
		else
		{
			if (Control == g_iFirstController )
			{
				GetDeviceDatas();
				CheckShortcuts();
			}
			if( g_pcControllers[Control].xiController.bConnected && g_pcControllers[Control].fXInput )	// reads xinput controller kesy, if connected --tecnicors
				GetXInputControllerKeys( &g_pcControllers[Control].xiController, (LPDWORD)&Command[3] );
			else
				GetNControllerInput( Control, (DWORD*)&Command[3] );
		}
		break;
		

	case RD_READPAK:
#ifdef ENABLE_RAWPAK_DEBUG
		WriteDatasA( "ReadPak-PreProcessing", Control, Command, 0);
#endif
		if( g_pcControllers[Control].fPakInitialized )
			//Command[1] = Command[1] | ReadControllerPak( Control, &Command[3] );
			ReadControllerPak( Control, &Command[3] );
		else
		{
			DebugWriteA("Tried to read, but pak wasn't initialized!!\n");
			// InitControllerPak( Control );
			Command[1] |= RD_ERROR;
			//ZeroMemory( &Command[5], 32 );
		}
#ifdef ENABLE_RAWPAK_DEBUG
		WriteDatasA( "ReadPak-PostProcessing", Control, Command, 0);
		DebugWriteA( NULL );
#endif
		break;

	case RD_WRITEPAK:
#ifdef ENABLE_RAWPAK_DEBUG
		WriteDatasA( "WritePak-PreProcessing", Control, Command, 0);
#endif
		if( g_pcControllers[Control].fPakInitialized )
			//Command[1] = Command[1] | WriteControllerPak( Control, &Command[3] );
			WriteControllerPak( Control, &Command[3] );
		else
		{
			DebugWriteA("Tried to write, but pak wasn't initialized! (paktype was %u)\n", g_pcControllers[Control].PakType);
			// InitControllerPak( Control );
			Command[1] |= RD_ERROR;
		}
#ifdef ENABLE_PAK_WRITES_DEBUG
		WriteDatasA( "WritePak-PostProcessing", Control, Command, 0);
		DebugWriteA( NULL );
#endif
		break;

	case RD_READEEPROM:
		// Should be handled by the Emulator
		WriteDatasA( "ReadEeprom-PreProcessing", Control, Command, 0);
		WriteDatasA( "ReadEeprom-PostProcessing", Control, Command, 0);
		DebugWriteA( NULL );
		break;
	case RD_WRITEEPROM:
		// Should be handled by the Emulator
		WriteDatasA( "WriteEeprom-PreProcessing", Control, Command, 0);
		WriteDatasA( "WriteEeprom-PostProcessing", Control, Command, 0);
		DebugWriteA( NULL );
		break;

	default:
		// only accessible if the Emulator has bugs.. or maybe the Rom is flawed
		WriteDatasA( "ReadController: Bad read", Control, Command, 0);
		DebugWriteA( NULL );
		Command[1] = Command[1] | RD_ERROR;
	}

	LeaveCriticalSection( &g_critical );
	return;
}
Exemple #3
0
//-------------------------------------------------
LRESULT CALLBACK MyKeyHook(int code, WPARAM wParam, LPARAM lParam)
{
	int keyType;
	unsigned short charBuf;

	if (!pShMem->Initialized) return 0;
	if (code < 0) 
		return CallNextHookEx(pShMem->keyHook,code,wParam,lParam);

	// determine if current window is a console, if so returns
	TCHAR className[128];
	className[0] = 0;
	GetClassName(GetForegroundWindow(), className, 128);
	if (_tcscmp(className, _T("ConsoleWindowClass")) == 0)
		return CallNextHookEx(pShMem->keyHook,code,wParam,lParam);
	
	GetKeyboardState(KeyState);
	HKL curLayout = GetKeyboardLayout(0);

	if (curLayout != OriginalLayout && curLayout != ViKeyboardLayout)
		OriginalLayout = curLayout;

	if (CheckSwitchKey(wParam,lParam) || CheckShortcuts(wParam, lParam))
		return 1;
	
	if ((pShMem->vietKey || (pShMem->options.macroEnabled && pShMem->options.alwaysMacro)) && 
		code == HC_ACTION && !ClipboardIsEmpty) {

		if (wParam != PasteKey1 && wParam != PasteKey2 && !(lParam & IsReleased)) {
			// postpone this key
			keybd_event(wParam, 
						HIBYTE(LOWORD(lParam)), 
						(lParam & IsExtended)? KEYEVENTF_EXTENDEDKEY : 0,
						0);
			return 1;
		}
		if (wParam == PasteKey2 && (lParam & IsReleased)) {
			ClearClipboard();
		}
	}

	if (CheckBack(wParam))	return 1;
	if ((pShMem->vietKey  || (pShMem->options.macroEnabled && pShMem->options.alwaysMacro)) && 
		(code == HC_ACTION) && !(lParam & IsReleased)) {
//		if (CheckBack(wParam))	return 1;
		if (PuttingBacks) {
			if (wParam != VK_BACK) {
				keybd_event(wParam, 
						HIBYTE(LOWORD(lParam)), 
						(lParam & IsExtended)? KEYEVENTF_EXTENDEDKEY : 0,
						0);
				return 1;
			}
			return CallNextHookEx(pShMem->keyHook,code,wParam,lParam);
		}

		if (pShMem->keyMode != WINCP1258_CHARSET &&	LayoutChangeForced) {
			ActivateKeyboardLayout(OriginalLayout, 0);
			LayoutChangeForced = 0;
		}

		//		HKL curLayout = GetKeyboardLayout(0);
		if (((KeyState[VK_CONTROL] & 0x80) == 0 && (KeyState[VK_MENU] & 0x80) == 0) ||
			( curLayout != UsKeyboardLayout && ClipboardIsEmpty)) {
			 //(pShMem->inMethod == VIQR_INPUT || pShMem->inMethod == VIQR_STAR_INPUT) &&
			int remap = 0;
			keyType = ToAscii(wParam,UINT(HIWORD(lParam)),KeyState, &charBuf, 0);

			if (keyType == 1 && UsKeyboardLayout && ViKeyboardLayout && 
				(KeyState[VK_CONTROL] & 0x80) == 0 && 
				(KeyState[VK_MENU] & 0x80) == 0 &&
				curLayout == ViKeyboardLayout) {
				//need to remap
				unsigned short mappedChar;
				int res = ToAsciiEx(wParam, UINT(HIWORD(lParam)), KeyState, &mappedChar, 0, UsKeyboardLayout);
				if (res == 1 && ((unsigned char)mappedChar) != ((unsigned char)charBuf)) {
					charBuf = mappedChar;
					remap = 1;
				}
			}

			if (keyType == 1 || keyType < 0) {
				unsigned char c = (unsigned char)charBuf;
				if (wParam >= VK_NUMPAD0 && wParam <= VK_NUMPAD9)
					VnKbd.putChar(c); // don't process numeric keypad
				else {
					VnKbd.process(c);
					if (VnKbd.backs!=0 || VnKbd.keysPushed!=0) {
						if (keyType < 0) //dead key, one more back
							VnKbd.backs++;
						PushBacks();
						return 1;
					}
					if (remap) {
						SHORT scanCode = VkKeyScan((unsigned char)charBuf);
						lParam = (scanCode << 16) + 1;
						PostMessage(GetFocus(), (pShMem->options.useIME)? WM_IME_CHAR : WM_CHAR,
									(unsigned char)charBuf, lParam);
						return 1;
					}
				}
			}
			else {
				if (wParam!=VK_SHIFT && wParam!=VK_INSERT && 
					  wParam != VK_MENU &&
					  wParam != VK_CONTROL &&
					  ClipboardIsEmpty) {
					ResetBuffer();
				}
			}
		}
		else {
			if (wParam != VK_MENU && wParam != VK_CONTROL && ClipboardIsEmpty) {
				ResetBuffer();
			}
		}
	}
	else if ((code == HC_ACTION) && !(lParam & IsReleased)) {
		if (LayoutChangeForced && OriginalLayout && 
			GetKeyboardLayout(0) == ViKeyboardLayout && 
			OriginalLayout != ViKeyboardLayout) {

			ActivateKeyboardLayout(OriginalLayout, 0);
			LayoutChangeForced = 0;

			if (ToAsciiEx(wParam, UINT(HIWORD(lParam)), KeyState, &charBuf, 0, OriginalLayout) == 1) {
				SHORT scanCode = VkKeyScan((unsigned char)charBuf);
				lParam = (scanCode << 16) + 1;
				PostMessage(GetFocus(), (pShMem->options.useIME)? WM_IME_CHAR : WM_CHAR,
							(unsigned char)charBuf, lParam);
				return 1;
			}
		}
	}

	return CallNextHookEx(pShMem->keyHook,code,wParam,lParam);
}