📄 config.cpp
字号:
//
// Copyright(C) Renesas Technology Corp. 1998-2005. All rights reserved.
// Portions Copyright (c) 1997 Microsoft Corporation.
//
// NCG Display Driver for ITS-DS7
//
// FILE : config.cpp
// CREATED : 2003.08.28
// MODIFIED : 2005.11.10
// AUTHOR : Renesas Technology Corp.
// HARDWARE : RENESAS ITS-DS7
// HISTORY :
// 2003.08.28
// - Created prototype code.
// (based on Q2SD Display Driver for PFM-DS6C Ver.3.1.0)
// 2003.11.18
// - Added debug message.
// 2004.09.02
// - Changed the way of setting up display timings.
// 2005.09.21
// - Supported screen size configuration using registry.
// 2005.11.20
// - Corrected screen memory pitch setting.
#include "precomp.h"
BOOL APIENTRY GPEEnableDriver(
ULONG iEngineVersion,
ULONG cj,
DRVENABLEDATA *pded,
PENGCALLBACKS pEngCallbacks);
BOOL APIENTRY DrvEnableDriver(
ULONG iEngineVersion,
ULONG cj,
DRVENABLEDATA *pded,
PENGCALLBACKS pEngCallbacks)
{
HKEY hRegKey;
DWORD dwRet;
DWORD dwType;
DWORD dwLen;
DWORD dwScreenWidth;
DWORD dwScreenHeight;
DWORD dwPixelFormat;
DWORD dwBpp;
DWORD dwDisplayClock;
DWORD dwScanFrequency;
DWORD dwFrameRate;
DWORD dwDisplayMode;
DWORD dwDisplayWidth;
DWORD dwDisplayHeight;
DWORD dwScreenOffsetX;
DWORD dwScreenOffsetY;
DWORD dwScreenPitch;
DWORD dwSavedValue;
TCHAR* szPixelFormatString;
int hc, hsw, xs, xw;
int vc, vsw, ys, yw;
int i;
// These zeros means uses default settings.
dwScreenWidth = 0;
dwScreenHeight = 0;
dwBpp = 0;
dwDisplayClock = 0;
dwScanFrequency = 0;
dwFrameRate = 0;
dwScreenOffsetX = 0;
dwScreenOffsetY = 0;
dwDisplayMode = 0;
dwPixelFormat = DEFAULTPIXELFORMAT;
/* [ATTENTION] X6-DOTCLK must be changed. */
dwDisplayMode = 1; /* VGA : 25.0MHz */
// dwDisplayMode = 2; /* SVGA : 40.0MHz */
// dwDisplayMode = 3; /* XGA : 65.0MHz */
// dwDisplayMode = 4; /* WVGA : 33.3MHz */
// Open the NCG registry key.
dwRet = RegOpenKeyEx(
HKEY_LOCAL_MACHINE,
TEXT("Drivers\\Display\\NCG"),
0, 0, &hRegKey);
if (dwRet == ERROR_SUCCESS) {
RETAILMSG(1,
(TEXT("NCG: Registry key NCG found.\r\n")));
dwLen = sizeof(DWORD);
// Get screen width
dwRet = RegQueryValueEx(
hRegKey, TEXT("CxScreen"), NULL,
&dwType, (PBYTE)&dwScreenWidth, &dwLen);
if (dwRet == ERROR_SUCCESS) {
RETAILMSG(1,
(TEXT("NCG: CxScreen found, value is %d.\r\n"),
dwScreenWidth));
}
else {
DEBUGMSG(1,
(TEXT("NCG: CxScreen not found, using default.\r\n")));
dwScreenWidth = 0;
}
// Get screen height
dwRet = RegQueryValueEx(
hRegKey, TEXT("CyScreen"), NULL,
&dwType, (PBYTE)&dwScreenHeight, &dwLen);
if (dwRet == ERROR_SUCCESS) {
RETAILMSG(1,
(TEXT("NCG: CyScreen found, value is %d.\r\n"),
dwScreenHeight));
}
else {
DEBUGMSG(1,
(TEXT("NCG: CyScreen not found, using default.\r\n")));
dwScreenHeight = 0;
}
// Get pixel format
dwSavedValue = dwPixelFormat;
dwRet = RegQueryValueEx(
hRegKey, TEXT("PixelFormat"), NULL,
&dwType, (PBYTE)&dwPixelFormat, &dwLen);
if (dwRet == ERROR_SUCCESS) {
RETAILMSG(1,
(TEXT("NCG: PixelFormat found, value is %d.\r\n"),
dwPixelFormat));
}
else {
DEBUGMSG(1,
(TEXT("NCG: PixelFormat not found, using default.\r\n")));
dwPixelFormat = dwSavedValue;
}
// Get display mode
dwSavedValue = dwDisplayMode;
dwRet = RegQueryValueEx(
hRegKey, TEXT("DisplayMode"), NULL,
&dwType, (PBYTE)&dwDisplayMode, &dwLen);
if (dwRet == ERROR_SUCCESS) {
RETAILMSG(1,
(TEXT("NCG: DisplayMode found, value is %d.\r\n"),
dwDisplayMode));
}
else {
DEBUGMSG(1,
(TEXT("NCG: DisplayMode not found, using default.\r\n")));
dwDisplayMode = dwSavedValue;
}
// Get interrupt service thread priority level
dwSavedValue = g_dwIntrThreadPriority;
dwRet = RegQueryValueEx(
hRegKey, TEXT("Priority256"), NULL,
&dwType, (PBYTE)&g_dwIntrThreadPriority, &dwLen);
if (dwRet == ERROR_SUCCESS)
RETAILMSG(1,
(TEXT("NCG: Priority256 found, value is %d.\r\n"),
g_dwIntrThreadPriority));
else {
RETAILMSG(1,
(TEXT("NCG: Priority256 not found, using default.\r\n")));
g_dwIntrThreadPriority = dwSavedValue;
}
RegCloseKey(hRegKey);
}
else {
DEBUGMSG(1,
(TEXT("NCG: Registry key NCG not found.\r\n")));
}
// PixelFormat, Bpp
if ((dwPixelFormat != 0) && (dwPixelFormat != 1) && (dwPixelFormat != 2)) {
dwPixelFormat = DEFAULTPIXELFORMAT;
}
if (dwPixelFormat == 0) { // Currently 8bpp is not supported.
//dwBpp = 8;
//szPixelFormatString = TEXT("RGB : INDEX8");
dwPixelFormat = 1; // Forced to 16bpp.
dwBpp = 16;
szPixelFormatString = TEXT("RGB : RGB565");
}
else if (dwPixelFormat == 1) {
dwBpp = 16;
szPixelFormatString = TEXT("RGB : RGB565");
}
else if (dwPixelFormat == 2) {
dwBpp = 16;
szPixelFormatString = TEXT("RGB : ARGB1555");
}
NCGMode[0].nPixelFormat = (int)dwPixelFormat;
// Display timings setup
if (dwDisplayMode == 2) {
/* SVGA, 800x600@60Hz, 40.0MHz */
dwDisplayWidth = 800;
dwDisplayHeight = 600;
dwDisplayClock = 40000000;
dwScanFrequency = 37878;
dwFrameRate = 60;
hc = 1054; // 1056; /* TODO: check hc */
hsw = 128;
xs = 88;
vc = 628;
vsw = 4;
ys = 23;
}
else if (dwDisplayMode == 3) {
/* XGA, 1024x768@60Hz, 65.0MHz */
dwDisplayWidth = 1024;
dwDisplayHeight = 768;
dwDisplayClock = 65000000;
dwScanFrequency = 48363;
dwFrameRate = 60;
hc = 1344;
hsw = 144;
xs = 168;
vc = 806;
vsw = 6;
ys = 29;
}
else if (dwDisplayMode == 4) {
/* WVGA, 800x480@60Hz, 33.3MHz */
dwDisplayWidth = 800;
dwDisplayHeight = 480;
dwDisplayClock = 33333333;
dwScanFrequency = 31500;
dwFrameRate = 60;
hc = 1054; // 1056; /* TODO: check hc */
hsw = 128;
xs = 88;
vc = 525;
vsw = 2;
ys = 32;
}
else {
/* VGA, 640x480@60Hz, 25.0MHz */
dwDisplayWidth = 640;
dwDisplayHeight = 480;
dwDisplayClock = 25000000;
dwScanFrequency = 31500;
dwFrameRate = 60;
hc = 800;
hsw = 96;
xs = 40;
vc = 525;
vsw = 2;
ys = 32;
}
// dwDisplayWidth and dwDisplayHeight are active screen width and height
// available for displaying actual screen image. They limit the maximum
// value of dwScreenWidth and dwScreenHeight.
if (dwScreenWidth == 0 || dwScreenWidth > dwDisplayWidth)
dwScreenWidth = dwDisplayWidth;
if (dwScreenHeight == 0 || dwScreenHeight > dwDisplayHeight)
dwScreenHeight = dwDisplayHeight;
xw = dwScreenWidth;
yw = dwScreenHeight;
xs += (dwDisplayWidth - dwScreenWidth) / 2;
ys += (dwDisplayHeight - dwScreenHeight) / 2;
NCGMode[0].DURegs[DU_HDSR ] = hsw + xs - 19; /* HDS */
NCGMode[0].DURegs[DU_HDER ] = hsw + xs - 19 + xw; /* HDE */
NCGMode[0].DURegs[DU_VDSR ] = ys - 2; /* VDS */
NCGMode[0].DURegs[DU_VDER ] = ys - 2 + yw; /* VDE */
NCGMode[0].DURegs[DU_HCR ] = hc - 1; /* HC */
NCGMode[0].DURegs[DU_HSWR ] = hsw - 1; /* HSW */
NCGMode[0].DURegs[DU_VCR ] = vc - 1; /* VC */
NCGMode[0].DURegs[DU_VSPR ] = vc - vsw - 1; /* VSP */
dwScreenPitch = dwScreenWidth * dwBpp / 8;
// GPEModeEx parameter setup
// mode id
NCGMode[0].gpeModeEx.modeInfo.modeId = 0;
// screen width in pixels
NCGMode[0].gpeModeEx.modeInfo.width = dwScreenWidth;
// screen height in lines
NCGMode[0].gpeModeEx.modeInfo.height = dwScreenHeight;
// color depth, bit per pixel
NCGMode[0].gpeModeEx.modeInfo.Bpp = dwBpp;
// screen refresh rate
NCGMode[0].gpeModeEx.modeInfo.frequency = dwFrameRate;
// pixel format in GPE style
NCGMode[0].gpeModeEx.modeInfo.format =
dwBpp == 8 ? gpe8Bpp : gpe16Bpp;
// GPEModeEx structure size
NCGMode[0].gpeModeEx.dwSize = sizeof(GPEModeEx);
// driver signature, unused
NCGMode[0].gpeModeEx.dwDriverSignature = 0;
// GPEModeEx structure version
NCGMode[0].gpeModeEx.dwVersion = GPEMODEEX_CURRENTVERSION;
// reserved 0
NCGMode[0].gpeModeEx.dwReserved0 = 0;
// reserved 1
NCGMode[0].gpeModeEx.dwReserved1 = 0;
// reserved 2
NCGMode[0].gpeModeEx.dwReserved2 = 0;
// reserved 3
NCGMode[0].gpeModeEx.dwReserved3 = 0;
// detailed pixel format
if (NCGMode[0].nPixelFormat == 0)
NCGMode[0].gpeModeEx.ePixelFormat = ddgpePixelFormat_8bpp;
else if (NCGMode[0].nPixelFormat == 1)
NCGMode[0].gpeModeEx.ePixelFormat = ddgpePixelFormat_565;
else
NCGMode[0].gpeModeEx.ePixelFormat = ddgpePixelFormat_5551;
// pixel FourCC code
NCGMode[0].gpeModeEx.dwPixelFourCC = 0;
// pixel format user data, unused
NCGMode[0].gpeModeEx.dwPixelFormatData = 0;
// screen pitch in byte
NCGMode[0].gpeModeEx.lPitch = (LONG)dwScreenPitch;
// surface flags, should be 0
NCGMode[0].gpeModeEx.dwFlags = 0;
// RGB bitmask
if (NCGMode[0].nPixelFormat == 0) {
// INDEX8
NCGMode[0].gpeModeEx.dwRBitMask = 0;
NCGMode[0].gpeModeEx.dwGBitMask = 0;
NCGMode[0].gpeModeEx.dwBBitMask = 0;
}
else if (NCGMode[0].nPixelFormat == 1) {
// RGB565
NCGMode[0].gpeModeEx.dwRBitMask = 0xF800;
NCGMode[0].gpeModeEx.dwGBitMask = 0x07E0;
NCGMode[0].gpeModeEx.dwBBitMask = 0x001F;
}
else {
// ARGB1555
NCGMode[0].gpeModeEx.dwRBitMask = 0x7C00;
NCGMode[0].gpeModeEx.dwGBitMask = 0x03E0;
NCGMode[0].gpeModeEx.dwBBitMask = 0x001F;
}
// alpha bit mask
if (NCGMode[0].nPixelFormat == 2) {
NCGMode[0].gpeModeEx.dwAlphaBitMask = 0x8000;
}
else {
NCGMode[0].gpeModeEx.dwAlphaBitMask = 0x0000;
}
// print mode 0
RETAILMSG(1, (TEXT("%dx%d@%dHz (%dHz), %s\r\n"),
NCGMode[0].gpeModeEx.modeInfo.width,
NCGMode[0].gpeModeEx.modeInfo.height,
dwFrameRate,
dwDisplayClock,
szPixelFormatString));
// modeInfo initialization
for (i = 0; i < NUMDISPMODES; i++) {
modeInfo[i].dwWidth = NCGMode[i].gpeModeEx.modeInfo.width;
modeInfo[i].dwHeight = NCGMode[i].gpeModeEx.modeInfo.height;
modeInfo[i].lPitch = NCGMode[i].gpeModeEx.lPitch;
modeInfo[i].dwBPP = NCGMode[i].gpeModeEx.modeInfo.Bpp;
modeInfo[i].wFlags = (WORD)((modeInfo[i].dwBPP == 8) ? 1 : 0);
modeInfo[i].wRefreshRate = (WORD)NCGMode[i].gpeModeEx.modeInfo.frequency;
modeInfo[i].dwRBitMask = NCGMode[i].gpeModeEx.dwRBitMask;
modeInfo[i].dwGBitMask = NCGMode[i].gpeModeEx.dwGBitMask;
modeInfo[i].dwBBitMask = NCGMode[i].gpeModeEx.dwBBitMask;
modeInfo[i].dwAlphaBitMask = NCGMode[i].gpeModeEx.dwAlphaBitMask;
}
return GPEEnableDriver( iEngineVersion, cj, pded, pEngCallbacks );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -