📄 s3c2443disp.cpp
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
/*++
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
Module Name:
Abstract:
Functions:
Notes:
--*/
#include "precomp.h"
#include <nkintr.h>
#include <syspal.h> // for 8Bpp we use the natural palette
#include <gxinfo.h>
#define DISPPERF_DECLARE
#include "dispperf.h"
INSTANTIATE_GPE_ZONES(0x3,"MGDI Driver","unused1","unused2") // Start with errors and warnings
DDGPE * gGPE = (DDGPE *)NULL;
EGPEFormat eFormat[] =
{
gpe8Bpp,
gpe16Bpp,
gpe24Bpp,
gpe32Bpp,
};
EDDGPEPixelFormat ePixelFormat[4] =
{
ddgpePixelFormat_8bpp,
ddgpePixelFormat_565,
ddgpePixelFormat_8880,
ddgpePixelFormat_8888,
};
ULONG BitMasks[][3] =
{
{ 0, 0, 0 },
{ 0xF800, 0x07E0, 0x001F },
{ 0xFF0000, 0x00FF00, 0x0000FF },
{ 0x00FF0000, 0x0000FF00, 0x000000FF }
};
// This prototype avoids problems exporting from .lib
BOOL
APIENTRY
GPEEnableDriver(
ULONG engineVersion,
ULONG cj,
DRVENABLEDATA * data,
PENGCALLBACKS engineCallbacks
);
BOOL
APIENTRY
DrvEnableDriver(
ULONG engineVersion,
ULONG cj,
DRVENABLEDATA * data,
PENGCALLBACKS engineCallbacks
)
{
return GPEEnableDriver(engineVersion, cj, data, engineCallbacks);
}
// this routine converts a string into a GUID and returns TRUE if the
// conversion was successful.
BOOL
ConvertStringToGuid (LPCTSTR pszGuid, GUID *pGuid)
{
UINT Data4[8];
int Count;
BOOL fOk = FALSE;
TCHAR *pszGuidFormat = _T("{%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}");
DEBUGCHK(pGuid != NULL && pszGuid != NULL);
__try
{
if (_stscanf(pszGuid, pszGuidFormat, &pGuid->Data1,
&pGuid->Data2, &pGuid->Data3, &Data4[0], &Data4[1], &Data4[2], &Data4[3],
&Data4[4], &Data4[5], &Data4[6], &Data4[7]) == 11)
{
for(Count = 0; Count < (sizeof(Data4) / sizeof(Data4[0])); Count++)
{
pGuid->Data4[Count] = (UCHAR) Data4[Count];
}
}
fOk = TRUE;
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
}
return fOk;
}
// This routine notifies the OS that we support the Power Manager IOCTLs (through
// ExtEscape(), which calls DrvEscape()).
BOOL
AdvertisePowerInterface(HMODULE hInst)
{
BOOL fOk = FALSE;
HKEY hk;
DWORD dwStatus;
TCHAR szTemp[MAX_PATH];
GUID gClass;
// assume we are advertising the default class
fOk = ConvertStringToGuid(PMCLASS_DISPLAY, &gClass);
DEBUGCHK(fOk);
// check for an override in the registry
dwStatus = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("System\\GDI\\Drivers"), 0, 0, &hk);
if(dwStatus == ERROR_SUCCESS)
{
DWORD dwType, dwSize;
dwSize = sizeof(szTemp);
dwStatus = RegQueryValueEx(hk, _T("DisplayPowerClass"), NULL, &dwType, (LPBYTE) szTemp, &dwSize);
szTemp[MAX_PATH-1] = 0;
if(dwStatus == ERROR_SUCCESS && dwType == REG_SZ)
{
// got a guid string, convert it to a guid
GUID gTemp;
fOk = ConvertStringToGuid(szTemp, &gTemp);
DEBUGCHK(fOk);
if(fOk)
{
gClass = gTemp;
}
}
// release the registry key
RegCloseKey(hk);
}
// figure out what device name to advertise
if(fOk)
{
fOk = GetModuleFileName(hInst, szTemp, sizeof(szTemp) / sizeof(szTemp[0]));
DEBUGCHK(fOk);
}
// now advertise the interface
if(fOk)
{
fOk = AdvertiseInterface(&gClass, szTemp, TRUE);
DEBUGCHK(fOk);
}
return fOk;
}
//
// Main entry point for a GPE-compliant driver
//
GPE *
GetGPE()
{
if (!gGPE)
{
gGPE = new S3C2443DISP();
}
return gGPE;
}
ULONG gBitMasks[] = { 0xf800,0x07e0,0x001f};
S3C2443DISP::S3C2443DISP()
{
DWORD oldMode;
ULONG fbSize;
ULONG fbOffset;
ULONG offsetX;
ULONG offsetY;
m_InDDraw = FALSE;
DEBUGMSG(GPE_ZONE_INIT,(TEXT("S3C2443DISP::S3C2443DISP\r\n")));
m_pIntrReg = (S3C2443_INTR_REG *)VirtualAlloc(0, sizeof(S3C2443_INTR_REG), MEM_RESERVE, PAGE_NOACCESS);
if (m_pIntrReg == NULL)
{
return;
}
if (!VirtualCopy((PVOID)m_pIntrReg, (PVOID)(S3C2443_BASE_REG_PA_INTR >> 8), sizeof(S3C2443_INTR_REG), PAGE_PHYSICAL | PAGE_READWRITE | PAGE_NOCACHE)) {
return;
}
m_pLCDReg = (S3C2443_LCD_REG *)VirtualAlloc(0, sizeof(S3C2443_LCD_REG), MEM_RESERVE, PAGE_NOACCESS);
if (m_pLCDReg == NULL)
{
return;
}
if (!VirtualCopy((PVOID)m_pLCDReg, (PVOID)(S3C2443_BASE_REG_PA_LCD >> 8), sizeof(S3C2443_LCD_REG), PAGE_PHYSICAL | PAGE_READWRITE | PAGE_NOCACHE)) {
return;
}
// regist LCD Interrupt
m_dwVSYNCIrq = IRQ_LCD_VSYNC;
if (!KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, &m_dwVSYNCIrq, sizeof(DWORD), &m_dwVSYNCSysIntr, sizeof(DWORD), NULL))
{
m_dwVSYNCSysIntr = SYSINTR_UNDEFINED;
return;
}
m_hVSYNCInterruptEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
if(NULL == m_hVSYNCInterruptEvent)
{
return;
}
if (!(InterruptInitialize(m_dwVSYNCSysIntr, m_hVSYNCInterruptEvent, 0, 0)))
{
return;
}
m_pLCDReg->VIDINTCON &= ~((0x3)<<15 | (0x3)<<13 | (0x1) <<12 | (0x1) ); // FRAMESEL0, INTFRMEN Bit clear
m_pLCDReg->VIDINTCON |= ((0x1)<<15 | /*(0x0)<<13 |*/ (0x1)<<12); /// Video Frame Disalbe
m_pIntrReg->INTSUBMSK |= 1 << IRQ_SUB_LCD3; // Disable Interrupt
m_pIntrReg->INTMSK |= 1 << IRQ_LCD; // Disable Interrupt
DisableInterrupt();
fpVisibleOverlay = 0;
fpOverlayFlipFrom = 0;
InitializeCriticalSection(&m_CS);
oldMode = SetKMode(TRUE);
m_RedMaskSize = 5;
m_RedMaskPosition = 11;
m_GreenMaskSize = 6;
m_GreenMaskPosition = 5;
m_BlueMaskSize = 5;
m_BlueMaskPosition = 0;
gBitMasks[0] =((1<<m_RedMaskSize) -1) << m_RedMaskPosition;
gBitMasks[1] =((1<<m_GreenMaskSize)-1) << m_GreenMaskPosition;
gBitMasks[2] =((1<<m_BlueMaskSize) -1) << m_BlueMaskPosition;
m_VesaMode = 0;
m_nScreenWidth = LCD_XSIZE_TFT;
m_nScreenHeight = LCD_YSIZE_TFT;
m_colorDepth = 16;
m_cxPhysicalScreen = LCD_XSIZE_TFT;
m_cyPhysicalScreen = LCD_YSIZE_TFT;
////// m_pvFlatFrameBuffer = 0xac100000;
m_pvFlatFrameBuffer = 0x30100000;
m_cbScanLineLength = m_nScreenWidth * 2;
m_FrameBufferSize = m_nScreenHeight * m_cbScanLineLength;
m_VideoPowerState = VideoPowerOn;
m_iRotate = GetRotateModeFromReg();
SetRotateParams();
SetKMode(oldMode);
//APR check
m_pModeEx = &m_ModeInfoEx;
m_pMode = &m_ModeInfoEx.modeInfo;
memset(m_pModeEx, 0, sizeof(GPEModeEx));
m_pModeEx->dwSize = sizeof(GPEModeEx);
m_pModeEx->dwVersion = GPEMODEEX_CURRENTVERSION;
// Setup main ModeInfo
m_pMode->modeId = 0;
m_pMode->Bpp = m_colorDepth;
m_pMode->frequency = 60;
m_pMode->width = m_nScreenWidth;
m_pMode->height = m_nScreenHeight;
int nBPP = m_pMode->Bpp/8 - 1;
switch (m_pMode->Bpp)
{
// case 8:
case 16:
case 24:
case 32:
m_pMode->format = eFormat[nBPP];
m_pModeEx->ePixelFormat = ePixelFormat[nBPP];
m_pModeEx->lPitch = m_pMode->width * m_pMode->Bpp / 8;
m_pModeEx->dwRBitMask = BitMasks[nBPP][0];
m_pModeEx->dwGBitMask = BitMasks[nBPP][1];
m_pModeEx->dwBBitMask = BitMasks[nBPP][2];
break;
default:
RETAILMSG(1,(TEXT("Invalid BPP value passed to driver - Bpp = %d\r\n"), m_pMode->Bpp));
m_pMode->format = gpeUndefined;
break;
}
// compute frame buffer displayable area offset
offsetX = (m_cxPhysicalScreen - m_nScreenWidthSave) / 2;
offsetY = (m_cyPhysicalScreen - m_nScreenHeightSave) / 2;
fbOffset = (offsetY * m_cbScanLineLength) + offsetX;
// compute physical frame buffer size
fbSize = m_cyPhysicalScreen * m_cbScanLineLength;
// for DDraw enabled, make sure we also have some off-screen video memory available for surface allocations
fbSize = 0x100000;
// Use CreateFileMapping/MapViewOfFile to guarantee the VirtualFrameBuffer
// pointer is allocated in shared memory.
m_hVFBMapping = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, fbSize, NULL);
if (m_hVFBMapping != NULL) {
m_VirtualFrameBuffer = (DWORD)MapViewOfFile(m_hVFBMapping, FILE_MAP_WRITE, 0, 0, 0);
} else {
m_VirtualFrameBuffer = NULL;
}
////// if (m_VesaMode != 0)
////// {
if (VirtualCopy((void *)m_VirtualFrameBuffer, (void *)(m_pvFlatFrameBuffer >> 8), fbSize, PAGE_READWRITE | PAGE_NOCACHE | PAGE_PHYSICAL)) {
CeSetMemoryAttributes ((void *)m_VirtualFrameBuffer, (void *)(m_pvFlatFrameBuffer >> 8), fbSize, PAGE_WRITECOMBINE);
}
////// }
////// else
////// {
////// if (VirtualCopy((void *)m_VirtualFrameBuffer, (void *)m_pvFlatFrameBuffer, fbSize, PAGE_READWRITE | PAGE_NOCACHE)) {
////// // since we don't know if the physical address under is contiguious or not, we have to settle with
////// // PHYSICAL_ADDRESS_UNKNOWN and hope that the CPU supports it.
////// CeSetMemoryAttributes ((void *)m_VirtualFrameBuffer, PHYSICAL_ADDRESS_UNKNOWN, fbSize, PAGE_WRITECOMBINE);
////// }
////// }
PREFAST_ASSERT(m_VirtualFrameBuffer);
////// {
////// DWORD index;
////// volatile PUSHORT ptr = (PUSHORT)m_VirtualFrameBuffer;
//////
////// for (index = 0; index < 320*240; index++)
////// {
////// if(index < 240*80)
////// {
////// ptr[index] = 0xf800;
////// }
////// else if(index < 240*160)
////// {
////// ptr[index] = 0x07e0;
////// }
////// else if(index < 240*240)
////// {
////// ptr[index] = 0x001f;
////// }
////// else
////// {
////// ptr[index] = 0xffff;
////// }
////// }
//////
////// }
memset ((void*)m_VirtualFrameBuffer, 0x0, fbSize);
m_VirtualFrameBuffer += fbOffset;
fbSize -= fbOffset;
m_pVideoMemoryHeap = new SurfaceHeap(fbSize, m_VirtualFrameBuffer, NULL, NULL);
if(!m_pVideoMemoryHeap)
{
RETAILMSG (1, (L"Failed to create surface heap on internal SRAM memory\n"));
return;
}
m_CursorVisible = FALSE;
m_CursorDisabled = TRUE;
m_CursorForcedOff = FALSE;
memset (&m_CursorRect, 0x0, sizeof(m_CursorRect));
AdvertisePowerInterface(g_hmodDisplayDll);
}
S3C2443DISP::~S3C2443DISP()
{
if (m_VirtualFrameBuffer != NULL)
UnmapViewOfFile((LPVOID)m_VirtualFrameBuffer);
if (m_hVFBMapping != NULL)
CloseHandle(m_hVFBMapping);
if (m_pLCDReg)
{
VirtualFree((PVOID)m_pLCDReg, 0, MEM_RELEASE);
m_pLCDReg = NULL;
}
if (m_pIntrReg)
{
VirtualFree((PVOID)m_pIntrReg, 0, MEM_RELEASE);
m_pIntrReg = NULL;
}
}
SCODE S3C2443DISP::SetMode (INT modeId, HPALETTE *palette)
{
DEBUGMSG(GPE_ZONE_INIT,(TEXT("S3C2443DISP::SetMode\r\n")));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -