platform_win32.c

来自「betaplayer_0.096源码 tcpmp老版本」· C语言 代码 · 共 2,601 行 · 第 1/5 页

C
2,601
字号
		*(FARPROC*)&FuncSHGetDocumentsFolder = GetProcAddress(CEShellDLL,MAKEINTRESOURCE(75));

	if (FuncSHGetSpecialFolderPath)
		FuncSHGetSpecialFolderPath(NULL,SysPath,0x24/*CSIDL_WINDOWS*/,FALSE);

	if (!FuncSHGetDocumentsFolder || !FuncSHGetDocumentsFolder(T("\\"),DocPath))
		DocPath[0] = 0;

	if (SystemParametersInfo(SPI_GETPLATFORMTYPE,sizeof(p->PlatformType),p->PlatformType,0)!=0)
	{
		if (tcsicmp(p->PlatformType,T("PocketPC"))==0)
			p->Type = TYPE_POCKETPC;
		else
		if (tcsicmp(p->PlatformType,T("Smartphone"))==0)
			p->Type = TYPE_SMARTPHONE;
	}
	else
	if (GetLastError()==ERROR_ACCESS_DENIED)
	{
		tcscpy(p->PlatformType,T("Smartphone"));
		p->Type = TYPE_SMARTPHONE;
	}
	else
		tcscpy(p->PlatformType,T("Windows CE"));

	SystemParametersInfo(SPI_GETOEMINFO,sizeof(p->OemInfo),p->OemInfo,0);

	if (!AygShellDLL && p->Ver < 300)
		p->Caps |= CAPS_OLDSHELL;

	// detect fake navigator bar and use old style menu
	if (p->Type != TYPE_SMARTPHONE && AygShellDLL && 
		SystemParametersInfo(SPI_GETWORKAREA,0,&WorkArea,0) && WorkArea.top==0)
		p->Caps |= CAPS_OLDSHELL;

	tcscpy(OemUpper,p->OemInfo);
	tcsupr(OemUpper);

	BacklightEvent = CreateEvent(NULL, FALSE, FALSE, T("TIMEOUTDISPLAYOFF"));
#endif

	p->Model = MODEL_DEFAULT;

#if defined(ARM)
	tcscpy(p->CPU,T("ARM"));
	SafeGetCpuId(0,CpuId);

	if (CpuId[0])
	{
		p->ICache = 512 << ((CpuId[1] >> 6) & 7);
		p->DCache = 512 << ((CpuId[1] >> 18) & 7);
	}
	else
	{
		// when need to detect cpu features somehow
		TRY_BEGIN
		{	
			if (CheckARM5E())
			{
				int XScale;
				p->Caps |= CAPS_ARM_5E;

				XScale = CheckARMXScale();
				if (XScale)
				{
					p->ICache = p->DCache = 32768;
					p->Caps |= CAPS_ARM_XSCALE;
					if (XScale > 1)
						p->Caps |= CAPS_ARM_WMMX;
				}
			}
		}
		TRY_END
	}

	if ((CpuId[0] & 0xFF000000) == 0x54000000) //TI
	{
		tcscat(p->CPU,T(" TI"));
		switch ((CpuId[0] >> 4) & 0xFFF)
		{
		case 0x915: tcscat(p->CPU,T("915T")); break;
		case 0x925: tcscat(p->CPU,T("925T")); break;
		case 0x926: tcscat(p->CPU,T("926T")); break;
		}
	}
	else
	if ((CpuId[0] & 0xFF000000) == 0x41000000) //arm
	{
		switch ((CpuId[0] >> 4) & 0xFFF)
		{
		case 0x920: tcscat(p->CPU,T(" 920T")); break;
		case 0x922: tcscat(p->CPU,T(" 922T")); break;
		case 0x926: tcscat(p->CPU,T(" 926E")); break;
		case 0x940: tcscat(p->CPU,T(" 940T")); break;
		case 0x946: tcscat(p->CPU,T(" 946E")); break;
		case 0xA22: tcscat(p->CPU,T(" 1020E")); break;
		}
	}
	else
	if ((CpuId[0] & 0xFF000000) == 0x69000000) //intel
	{
		tcscat(p->CPU,T(" Intel"));

		if ((CpuId[0] & 0xFF0000) == 0x050000) //intel arm5e
			p->Caps |= CAPS_ARM_5E|CAPS_ARM_XSCALE;

		if (((CpuId[0] >> 4) & 0xFFF) == 0xB11)
		{
			tcscat(p->CPU,T(" SA1110"));
		}
		else
		{
			switch ((CpuId[0] >> 13) & 7)
			{
			case 0x2: p->Caps |= CAPS_ARM_WMMX; break;
			}

			switch ((CpuId[0] >> 4) & 31)
			{
			case 0x10: 
				tcscat(p->CPU,T(" PXA25x/26x")); break;
				break;
			case 0x11: 
				tcscat(p->CPU,T(" PXA27x")); break;
				break;
			case 0x12:
				tcscat(p->CPU,T(" PXA210"));
				break;
			}
		}
	}

#if defined(_WIN32_WCE)

	if (tcsstr(OemUpper,T("TYPHOON")))
		p->Model = MODEL_SPV_C500_ORIGROM;
	else
	if (tcsstr(OemUpper,T("PW10B")) ||
		tcsstr(OemUpper,T("PW10A")))
	{
		p->Model = MODEL_O2_XDA;
		p->Caps |= CAPS_ONLY12BITRGB;
	}
	else
	if (tcsstr(OemUpper,T("Compal P6C")))
		p->Model = MODEL_AMIGO_600C;
	else
	if (tcsstr(OemUpper,T("Pocket PC J710")))
		p->Model = MODEL_CASIO_E200;
	else
	if (tcsstr(OemUpper,T("JORNADA")))
	{
		p->Caps |= CAPS_LANDSCAPE;
		if (tcsstr(OemUpper,T("680")))
			p->Model = MODEL_JORNADA_680;
		else
		if (tcsstr(OemUpper,T("690")))
			p->Model = MODEL_JORNADA_690;
		else
		if (tcsstr(OemUpper,T("710")))
			p->Model = MODEL_JORNADA_710;
		else
		if (tcsstr(OemUpper,T("720")))
			p->Model = MODEL_JORNADA_720;
	}
	else
	if (tcsstr(OemUpper,T("IPAQ")))
	{
		p->Caps |= CAPS_PORTRAIT;
		if (tcsstr(OemUpper,T("H3600")))
		{
			p->Model = MODEL_IPAQ_H3600;
			p->Caps |= CAPS_ONLY12BITRGB;
		}
		else
		if (tcsstr(OemUpper,T("H3700")))
		{
			p->Model = MODEL_IPAQ_H3700;
			p->Caps |= CAPS_ONLY12BITRGB;
		}
		else
		if (tcsstr(OemUpper,T("H3800")))
			p->Model = MODEL_IPAQ_H3800;
		else
		if (tcsstr(OemUpper,T("H3900")))
			p->Model = MODEL_IPAQ_H3900;
		else
		if (tcsstr(OemUpper,T("HX4700")))
			p->Model = MODEL_IPAQ_HX4700;
	}
	else
	if (tcsstr(OemUpper,T("TOSHIBA")))
	{
		p->Caps |= CAPS_PORTRAIT;
		if (tcsstr(OemUpper,T("E740")))
			p->Model = MODEL_TOSHIBA_E740;
		else
		if (tcsstr(OemUpper,T("E750")))
			p->Model = MODEL_TOSHIBA_E750;
		else
		if (tcsstr(OemUpper,T("E80")))
			p->Model = MODEL_TOSHIBA_E800;
	}
	else
	if (tcsstr(OemUpper,T("AXIM")))
	{
		if (tcscmp(OemUpper+tcslen(OemUpper)-2,T("X5"))==0)
			p->Model = MODEL_AXIM_X5;

		if (tcscmp(OemUpper+tcslen(OemUpper)-3,T("X50"))==0)
			p->Model = MODEL_AXIM_X50;
	}
	else
	if (tcsstr(OemUpper,T("LOOX")))
	{
		if (tcsstr(OemUpper,T("720")))
			p->Model = MODEL_LOOX_720;
	}

#endif

#elif defined(MIPS)
	SafeGetCpuId(0,CpuId);
	tcscpy(p->CPU,T("MIPS"));

	if (((CpuId[0] >> 8) & 255) == 0x0c)
	{
		p->Caps |= CAPS_MIPS_VR41XX;
		tcscat(p->CPU,T(" VR41XX"));
	}

#if defined(_WIN32_WCE)

	if (tcsstr(OemUpper,T("BSQUARE")))
	{
		tcscpy(OemUpper,p->PlatformType);
		tcsupr(OemUpper);

		if (tcsstr(OemUpper,T("ALCHEMY")))
			p->Model = MODEL_BSQUARE_ALCHEMY;

		tcscpy(OemUpper,p->OemInfo);
		tcsupr(OemUpper);
	}

	if (tcsstr(OemUpper,T("POCKET")))
	{
		if (tcsstr(OemUpper,T(" J74")))
		{
			p->Model = MODEL_CASIO_BE300;
			p->Caps |= CAPS_OLDSHELL;
		}
	}

	if (tcsstr(OemUpper,T("POCKET PC")))
	{
		p->Caps |= CAPS_PORTRAIT;
		if (tcsstr(OemUpper,T(" J67")))
			p->Model = MODEL_CASIO_E125;
		else
		if (tcsstr(OemUpper,T(" J76")))
			p->Model = MODEL_CASIO_EM500;
		else
		if (tcsstr(OemUpper,T(" J58")))
			p->Model = MODEL_CASIO_E115;
		else
		if (tcsstr(OemUpper,T(" J53")) || tcsstr(OemUpper,T(" JX53")))
			p->Model = MODEL_CASIO_E105;
	}

	if (tcsstr(OemUpper,T("JVC")))
	{
		if (tcsstr(OemUpper,T("C33")))
			p->Model = MODEL_JVC_C33;
	}
#endif

#elif defined(SH3)
	tcscpy(p->CPU,T("SH3"));

#if defined(_WIN32_WCE)
	if (tcsstr(OemUpper,T("JORNADA")))
	{
		if (tcsstr(OemUpper,T(" 43")))
		{
			p->Caps |= CAPS_ONLY12BITRGB;
		}
		if (tcsstr(OemUpper,T(" 54")))
		{
			p->Model = MODEL_JORNADA_540;
			p->Caps |= CAPS_ONLY12BITRGB | CAPS_PORTRAIT;
		}
	}
#endif

#elif defined(_M_IX86)
	tcscpy(p->CPU,T("x86"));
	SafeGetCpuId(0,CpuId);

    if (CpuId[1] == 0x756e6547 &&
        CpuId[3] == 0x49656e69 &&
        CpuId[2] == 0x6c65746e) 
	{
		tcscat(p->CPU,T(" Intel"));

Intel:
		SafeGetCpuId(1,CpuId);
        if (CpuId[3] & 0x00800000)
		{
			p->Caps |= CAPS_X86_MMX;
			if (CpuId[3] & 0x02000000) 
				p->Caps |= CAPS_X86_MMX2 | CAPS_X86_SSE;
			if (CpuId[3] & 0x04000000) 
				p->Caps |= CAPS_X86_SSE2;
		}
    } 
	else if (CpuId[1] == 0x68747541 &&
             CpuId[3] == 0x69746e65 &&
             CpuId[2] == 0x444d4163) 
	{
		tcscat(p->CPU,T(" AMD"));

		SafeGetCpuId(0x80000000,CpuId);
        if (CpuId[0] < 0x80000001)
            goto Intel;

		SafeGetCpuId(0x80000001,CpuId);
        if (CpuId[3] & 0x00800000)
		{
			p->Caps |= CAPS_X86_MMX;
			if (CpuId[3] & 0x80000000)
				p->Caps |= CAPS_X86_3DNOW;
			if (CpuId[3] & 0x00400000)
				p->Caps |= CAPS_X86_MMX2;
		}
    } 
	else if (CpuId[1] == 0x746e6543 &&
             CpuId[3] == 0x48727561 &&
             CpuId[2] == 0x736c7561) 
	{
		tcscat(p->CPU,T(" VIA C3"));

		SafeGetCpuId(0x80000000,CpuId);
        if (CpuId[0] < 0x80000001)
            goto Intel;

		SafeGetCpuId(0x80000001,CpuId);
		if (CpuId[3] & (1<<31))
			p->Caps |= CAPS_X86_3DNOW;
		if (CpuId[3] & (1<<23))
			p->Caps |= CAPS_X86_MMX;
		if (CpuId[3] & (1<<24))
			p->Caps |= CAPS_X86_MMX2;
	}
	else if (CpuId[1] == 0x69727943 &&
             CpuId[3] == 0x736e4978 &&
             CpuId[2] == 0x64616574) 
	{
		tcscat(p->CPU,T(" Cyrix"));

        if (CpuId[0] != 2) 
            goto Intel;

		SafeGetCpuId(0x80000001,CpuId);
        if (CpuId[3] & 0x00800000)
		{
			p->Caps |= CAPS_X86_MMX;
			if (CpuId[3] & 0x01000000)
				p->Caps |= CAPS_X86_MMX2;
		}
    }

#endif

	if (GetLocaleInfo(LOCALE_USER_DEFAULT,LOCALE_SABBREVLANGNAME,Lang,sizeof(Lang)/sizeof(tchar_t)) >= 2)
	{
		tcsupr(Lang);
		if (tcscmp(Lang,T("JPN"))==0) tcscpy(Lang,T("JA"));
		if (tcscmp(Lang,T("GER"))==0) tcscpy(Lang,T("DE"));
		if (tcscmp(Lang,T("SPA"))==0) tcscpy(Lang,T("ES"));

		// special three letter cases: Chinese traditional (CHT) and Chinese simplified (CHS)
		if (tcscmp(Lang,T("CHS"))==0 || tcscmp(Lang,T("ZHI"))==0 || tcscmp(Lang,T("ZHM"))==0)
			StringLang = FOURCC('C','H','S','_');
		else
		if (tcscmp(Lang,T("CHT"))==0 || tcscmp(Lang,T("ZHH"))==0)
			StringLang = FOURCC('C','H','T','_');
		else
		{
			// two letter version
			TcsToStr(Lang8,Lang,sizeof(Lang8));
			StringLang = FOURCC(Lang8[0],Lang8[1],'_','_');
		}
	}

	NodeRegister(&p->VMT,PRI_MAXIMUM+650);

	BacklightTimeout(0); // restore backlight settings (example if last time crashed)
}

void Platform_Done()
{
	NodeUnRegister(&Platform.VMT);

	UnlockFrameBuffer();
	SetDisplayPower(1,0);

#if defined(_WIN32_WCE)
	{
		phymem* p;
		for (p=PhyMem;p!=PhyMem+MAXPHY;++p)
			if (p->Length)
			{
				Free(p->Blocks);
				VirtualFree(p->Virt,0,MEM_RELEASE);
				memset(p,0,sizeof(phymem));
			}
	}

	if (BacklightEvent) CloseHandle(BacklightEvent);
	if (AygShellDLL) FreeLibrary(AygShellDLL);
	if (CoreDLL) FreeLibrary(CoreDLL);
	if (CEShellDLL) FreeLibrary(CEShellDLL);
#endif

#ifndef NDEBUG
	assert(BlockCount==0);
#endif
}

bool_t IsOrientationChanged()
{
	int Old = Orientation;
	Orientation = -1;
	return QueryOrientation() != Old;
}

int QueryOrientation()
{
#if defined(_WIN32_WCE)
	if (Orientation < 0)
	{
		HKEY Key;
		char Buffer[256];
		DEVMODE* Mode = (DEVMODE*)Buffer;
		int i,No;
		node* Node;

		Mode->dmSize = 192;
		Mode->dmFields = DM_DISPLAYQUERYORIENTATION;

		if (Platform.Ver >= 421 && // we don't trust this method on pre wm2003se systems
			FuncChangeDisplaySettingsEx &&
			FuncChangeDisplaySettingsEx(NULL, Mode, NULL, CDS_TEST, NULL) == DISP_CHANGE_SUCCESSFUL)
		{
			Mode->dmFields = DM_DISPLAYORIENTATION;
			FuncChangeDisplaySettingsEx(NULL, Mode, NULL, CDS_TEST, NULL);

			switch ((&Mode->dmDisplayFrequency)[1]) //(Mode->dmDisplayOrientation)
			{
			case DMDO_0: Orientation = 0; break;
			case DMDO_90: Orientation = DIR_SWAPXY | DIR_MIRRORUPDOWN; break;
			case DMDO_270: Orientation = DIR_SWAPXY | DIR_MIRRORLEFTRIGHT; break;
			case DMDO_180: Orientation = DIR_MIRRORUPDOWN | DIR_MIRRORLEFTRIGHT; break;
			}
		}

		if (Orientation < 0)
			for (No=0;(Node = NodeEnum(VOUT_CLASS,No))!=NULL;++No)
				if (Node->Get(Node,VOUT_ORIENTATION,&i,sizeof(int))==ERR_NONE)
				{
					Orientation = i;
					break;
				}

		if (Orientation < 0 && RegOpenKeyEx( HKEY_LOCAL_MACHINE, T("System\\GDI\\ROTATION"), 0, ACCESS_LOAD, &Key ) == ERROR_SUCCESS)
		{
			DWORD Value;
			DWORD RegSize = sizeof(Value);
			DWORD RegType;

			if (RegQueryValueEx(Key, T("Angle"), 0, &RegType, (LPBYTE) &Value, &RegSize) == ERROR_SUCCESS)
				switch (Value)
				{
				case 0: Orientation = 0; break;
				case 90: Orientation = DIR_SWAPXY | DIR_MIRRORUPDOWN; break;
				case 270: Orientation = DIR_SWAPXY | DIR_MIRRORLEFTRIGHT; break;
				case 180: Orientation = DIR_MIRRORUPDOWN | DIR_MIRRORLEFTRIGHT; break;
				}

			RegCloseKey( Key );
		}

		if (Orientation < 0)
			Orientation = 0;
	}
#else
	Orientation = 0;
#endif
	return Orientation;
}

void QueryDesktop( video* p )
{
	HDC DC = GetDC(0);

	memset(p,0,sizeof(video));

	p->Width = GetDeviceCaps(DC,HORZRES);
	p->Height = GetDeviceCaps(DC,VERTRES);
	p->Aspect = ASPECT_ONE;
	p->Direction = 0;

	if (GetDeviceCaps(DC,BITSPIXEL)*GetDeviceCaps(DC,PLANES) <= 8)
	{
		int n,i;

		p->Pixel.Flags = PF_PALETTE;
		p->Pixel.BitCount = 1;

		n=GetSystemPaletteEntries(DC,0,256,NULL);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?