⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ncg.cpp

📁 WinCE5.0BSP for Renesas SH7770
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//
//  Copyright(C) Renesas Technology Corp. 1998-2005. All rights reserved.
//  Portions Copyright (c) 1997 Microsoft Corporation.
//
//  NCG Display Driver for ITS-DS7
//
//  FILE      : ncg.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
//              - Corrected pixel format.
//              2004.03.01
//              - Changed the initial setting value of DU-DSMR. CDE disable.
//              2004.09.02
//              - Changed the initial setting value of DU-DSMR. DIPM = CSYNC.
//              - Changed the way of setting up display timings.
//              2005.09.20
//              - Modified to configure primary surface format from registry.
//              2005.11.10
//              - Modified SetRegisters to support RGB1555 pixel format.
//

#include "precomp.h"
#include "palette.h"  // for 8Bpp we use the natural palette

#include <nkintr.h>
#include "oalintr.h"

// Exported event, to allow application waiting without stalling
// other DirectDraw calls.
#define EVENT_VERTICALBLANK_EXTERNAL	(TEXT("EVENT_DDVERTICALBLANKRG"))

HANDLE g_hVBlankExternal;
HANDLE g_hBltDoneExternal;

// string constant to display driver version and display mode
TCHAR* g_szModeString; // set in DrvEnableDriver

// display mode structure
ModeInit NCGMode[NUMDISPMODES];

// register and memory address, interrupt number
DWORD g_dwVideoMemoryAddress  = NCG_FBBASE;
DWORD g_dwVideoMemorySize     = NCG_FBSIZE;
DWORD g_dwDURegisterAddress   = NCGDU_REGBASE;
DWORD g_dwInterruptNumber     = SYSINTR_DU - SYSINTR_FIRMWARE;
DWORD g_dwIntrThreadPriority  = 130;

// These globals are set later.
DWORD g_dwReservedVideoMemorySize;

//DWORD g_dwFrameBufferBase;
DWORD g_dwFrameBufferOffset;
DWORD g_dwFrameBufferSize;

//DWORD g_dwCursorBufferBase;
DWORD g_dwCursorBufferOffset;
DWORD g_dwCursorBufferSize = CURSOR_BYTES;

// surface list
NCGSurf*	g_pNCGSurfList = NULL;

INSTANTIATE_PALETTE;

// The dpCurSettings structure
// 0:ERROR, 1:WARNING, 2:PERF, 3:TEMP, 4:ENTER, 5:INIT, 6:BLT_HI, 7:BLT_LO,
// 8:CREATE, 9:FLIP, 10:LINE, 11:HW, 12:POLY, 13:CURSOR
INSTANTIATE_GPE_ZONES(0x0003,"DDI Driver","unused1","unused2"); // Start with Errors and Warnings.

DWORD gCursorData[CURSOR_BYTES / 4];
DWORD gCursorMask[CURSOR_BYTES / 4];
DWORD gxHot;
DWORD gyHot;

void StartIntrThread_DU(NCG *pNCG);

static GPE *pGPE = (GPE *)NULL;

// Main entry point for a GPE-compliant driver
GPE *GetGPE()
{
	if( !pGPE )
        pGPE = new NCG();
    return pGPE;
}


NCG::NCG()
{
    int     n;

    m_pDURegs = NULL;

    RETAILMSG(1, (TEXT("%s %s built on %s\r\n"),
        SZDRIVERNAME, SZVERSION, SZBUILDDATE));

    /* virtual address allocation for DU registers */
    m_pDURegs = (volatile unsigned long *)
            VirtualAlloc(0, NCGDU_REGSIZE, MEM_RESERVE, PAGE_NOACCESS);
    if ( m_pDURegs == NULL ) {
        ERRORMSG(1, (TEXT("NCG: VirtualAlloc (DU register) failed.\r\n")));
        goto ALLOC_ERROR;
    }

    /* virtual address mapping for DU registers */
    if ( !VirtualCopy( (LPVOID)m_pDURegs, (LPVOID)NCGDU_REGBASE,
            NCGDU_REGSIZE, PAGE_READWRITE|PAGE_NOCACHE) ) {
        ERRORMSG(1, (TEXT("NCG: VirtualCopy (DU register) failed.\r\n")));
        goto ALLOC_ERROR;
    }

	/* Plane n */
	m_pDUPnRegs[0] = m_pDURegs + DU_P1;
	m_pDUPnRegs[1] = m_pDURegs + DU_P2;
	m_pDUPnRegs[2] = m_pDURegs + DU_P3;
	m_pDUPnRegs[3] = m_pDURegs + DU_P4;
	m_pDUPnRegs[4] = m_pDURegs + DU_P5;
	m_pDUPnRegs[5] = m_pDURegs + DU_P6;

	/* Color Palette n */
	m_pDUCPnRegs[0] = m_pDURegs + DU_CP1;
	m_pDUCPnRegs[1] = m_pDURegs + DU_CP2;
	m_pDUCPnRegs[2] = m_pDURegs + DU_CP3;
	m_pDUCPnRegs[3] = m_pDURegs + DU_CP4;

	DEBUGMSG(1, (TEXT("NCG: VideoMemory Address = 0x%08x, Size = 0x%08x\r\n"),
		g_dwVideoMemoryAddress, g_dwVideoMemorySize));

    m_nVideoMemorySize = g_dwVideoMemorySize;
    m_nLAWPhysical = g_dwVideoMemoryAddress;

    /* virtual address mapping for total video memory */
    m_pLAW = (volatile unsigned char *)
            VirtualAlloc(0, m_nVideoMemorySize, MEM_RESERVE, PAGE_NOACCESS );
    if (m_pLAW == NULL) {
        ERRORMSG(1, (TEXT("NCG: VirtualAlloc (frame memory) failed.\r\n")));
        goto ALLOC_ERROR;
        return;
    }

    /* user video memory mapping */
    if ( !VirtualCopy((LPVOID)m_pLAW, (LPVOID)m_nLAWPhysical, 
            m_nVideoMemorySize, PAGE_READWRITE|PAGE_NOCACHE) ) {
        ERRORMSG(1, (TEXT("NCG: VirtualCopy (frame memory) failed.\r\n")));
        goto ALLOC_ERROR;
        return;
    }

    /* Internal notification event creation */
    m_hVBlank =
        CreateEvent(NULL, TRUE, FALSE, NULL); // manual reset
    if (m_hVBlank == NULL) {
        RETAILMSG(1, (TEXT("Event creation failed. (vertical blank)\r\n")));
        goto EVENT_ERROR;
    }

    /* External notification event creation */
    g_hVBlankExternal =
        CreateEvent(NULL, TRUE, FALSE, EVENT_VERTICALBLANK_EXTERNAL); // manual reset
    if (g_hVBlankExternal == NULL) {
        RETAILMSG(1, (TEXT("Event creation failed. (external vertical blank)\r\n")));
        goto EVENT_ERROR;
    }

    /* Interrupt event creation */
    m_hIntrEvent_DU = CreateEvent(NULL, FALSE, FALSE, NULL);
    if (m_hIntrEvent_DU == NULL) {
        RETAILMSG(1, (TEXT("Event creation failed. (interrupt)\r\n")));
        goto EVENT_ERROR;
    }

    /* Initialization for interrupt service thread */
    m_dwIntrId_DU = SYSINTR_FIRMWARE + g_dwInterruptNumber;

    /* Interrupt initialization */
    if (!InterruptInitialize(m_dwIntrId_DU, m_hIntrEvent_DU, NULL, NULL)) {
        RETAILMSG(1, (TEXT("Interrupt initialization failed.\r\n")));
        goto EVENT_ERROR;
    }

    /* Interrupt thread creation */
    m_hIntrThread_DU = CreateThread(NULL, 0, 
                        (LPTHREAD_START_ROUTINE)StartIntrThread_DU, this, 0, NULL);
    if (m_hIntrThread_DU == NULL) {
        RETAILMSG(1, (TEXT("Interrupt thread creation failed.\r\n")));
        goto EVENT_ERROR;
    }

    /* Thread priority */
    CeSetThreadPriority(m_hIntrThread_DU, g_dwIntrThreadPriority);
    CeSetThreadPriority(GetCurrentThread(), 247);
    // check thread priority
    DEBUGMSG(GPE_ZONE_INIT,
//    RETAILMSG(1,
        (TEXT("NCG: Intr (0x%08x) : Thread Priority = %d\r\n"), 
        m_hIntrThread_DU, CeGetThreadPriority(m_hIntrThread_DU)));
    DEBUGMSG(GPE_ZONE_INIT,
//    RETAILMSG(1,
        (TEXT("NCG: Main (0x%08x) : Thread Priority = %d\r\n"), 
        GetCurrentThread(), CeGetThreadPriority(GetCurrentThread())));

    /* set some parameters */
	m_CursorRect.left = (NCGMode[0].gpeModeEx.modeInfo.width - CURSOR_XSIZE) >> 1;
	m_CursorRect.right = m_CursorRect.left + CURSOR_XSIZE;
	m_CursorRect.top = (NCGMode[0].gpeModeEx.modeInfo.height - CURSOR_YSIZE) >> 1;
	m_CursorRect.bottom = m_CursorRect.top + CURSOR_YSIZE;
    gxHot = gyHot = 0;

	for (n = 0; n < NCGDU_MAXPLANES; n++) {
		m_pVisiblePlane[n] = NULL;
		m_bFlippingPlane[n] = FALSE;
	}

    /* Set some parameters for cursor (mouse pointer) drawing. */
    memset (gCursorMask, 0xFF, sizeof(gCursorMask)); // blank pattern
    m_bCursorFlag = FALSE; // Initially, cursor is not displayed.

    return;


EVENT_ERROR:
    return;

ALLOC_ERROR:
	if (m_pDURegs)
        VirtualFree((PVOID)m_pDURegs, 0, MEM_RELEASE);
	if (m_pLAW)
        VirtualFree((PVOID)m_pLAW, 0, MEM_RELEASE);
    return;
}



void NCG::SetRegisters(int nModeId)
{
    DEBUGMSG(GPE_ZONE_INIT,
        (TEXT("NCG: Entering SetRegisters...\r\n")));

	/* DU */
	m_pDURegs[DU_DSYSR] = 0x00000200;	/* DRES=1, DEN=0 */
	m_pDURegs[DU_DSMR ] = 0x03001000;	/* DIPM = CSYNC, CSPM = HSYNC, CDE disable */
	m_pDURegs[DU_DSRCR] = DSRCR_ALL;
	m_pDURegs[DU_DIER ] = 0x00000000;
	m_pDURegs[DU_CPCR ] = 0x00000000;
	m_pDURegs[DU_DPPR ] = 0x76543210;

	m_pDURegs[DU_CP1TR   ] = 0;
	m_pDURegs[DU_CP2TR   ] = 0;
	m_pDURegs[DU_CP3TR   ] = 0;
	m_pDURegs[DU_CP4TR   ] = 0;
	m_pDURegs[DU_DOOR    ] = DEFAULTCOLOR_DISPLAYOFF;
	m_pDURegs[DU_CDER    ] = 0x00000000;
	m_pDURegs[DU_BPOR    ] = DEFAULTCOLOR_BACKGROUND;
	m_pDURegs[DU_RINTOFSR] = 0;

	m_pDURegs[DU_HDSR ] = NCGMode[nModeId].DURegs[DU_HDSR ];
	m_pDURegs[DU_HDER ] = NCGMode[nModeId].DURegs[DU_HDER ];
	m_pDURegs[DU_VDSR ] = NCGMode[nModeId].DURegs[DU_VDSR ];
	m_pDURegs[DU_VDER ] = NCGMode[nModeId].DURegs[DU_VDER ];
	m_pDURegs[DU_HCR  ] = NCGMode[nModeId].DURegs[DU_HCR  ];
	m_pDURegs[DU_HSWR ] = NCGMode[nModeId].DURegs[DU_HSWR ];

⌨️ 快捷键说明

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