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

📄 ncg.cpp

📁 WinCE5.0BSP for Renesas SH7770
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	m_pDURegs[DU_VCR  ] = NCGMode[nModeId].DURegs[DU_VCR  ];
	m_pDURegs[DU_VSPR ] = NCGMode[nModeId].DURegs[DU_VSPR ];

	m_pDURegs[DU_DSYSR  ] = 0x00000100;	/* DRES=0, DEN=1, master mode, non-interlace */

	/* Plane 1 : Primary Surface */
	DEBUGMSG(1, (TEXT("FrameBufferBase : 0x%08x\r\n"), NCG_FBBASE + g_dwFrameBufferOffset));
    if (NCGMode[0].nPixelFormat == 1) {
	    m_pDUPnRegs[0][DU_PnMR    ] = PnMR_DDF_565 | PnMR_SPIM_OPAQUE;
    }
    else if (NCGMode[0].nPixelFormat == 2) {
        m_pDUPnRegs[0][DU_PnMR    ] = PnMR_DDF_1555 | PnMR_SPIM_OPAQUE;
    }
    else {
        // Assuming RGB565. 8bpp is currently not supported.
	    m_pDUPnRegs[0][DU_PnMR    ] = PnMR_DDF_565 | PnMR_SPIM_OPAQUE;
    }
	m_pDUPnRegs[0][DU_PnMWR   ] = NCGMode[0].gpeModeEx.lPitch * 8 / 16;
	m_pDUPnRegs[0][DU_PnALPHAR] = 255;	/* 100% */
	m_pDUPnRegs[0][DU_PnDSXR  ] = NCGMode[0].gpeModeEx.modeInfo.width;
	m_pDUPnRegs[0][DU_PnDSYR  ] = NCGMode[0].gpeModeEx.modeInfo.height;
	m_pDUPnRegs[0][DU_PnDPXR  ] = 0;
	m_pDUPnRegs[0][DU_PnDPYR  ] = 0;
	m_pDUPnRegs[0][DU_PnDSA0R ] = (NCG_FBBASE + g_dwFrameBufferOffset) & 0x1FFFFFF0;
	m_pDUPnRegs[0][DU_PnDSA1R ] = (NCG_FBBASE + g_dwFrameBufferOffset) & 0x1FFFFFF0;
	m_pDUPnRegs[0][DU_PnDSA2R ] = (NCG_FBBASE + g_dwFrameBufferOffset) & 0x1FFFFFF0;
	m_pDUPnRegs[0][DU_PnSPXR  ] = 0;
	m_pDUPnRegs[0][DU_PnSPYR  ] = 0;
	m_pDUPnRegs[0][DU_PnWASPR ] = 0;
	m_pDUPnRegs[0][DU_PnWAMWR ] = 1024;
	m_pDUPnRegs[0][DU_PnBTR   ] = 0;
	m_pDUPnRegs[0][DU_PnTC1R  ] = 0;
	m_pDUPnRegs[0][DU_PnTC2R  ] = 0;
	m_pDUPnRegs[0][DU_PnMLR   ] = 0;

	/* Plane 6 : Cursor */
	DEBUGMSG(1, (TEXT("CursorBufferBase : 0x%08x\r\n"), NCG_FBBASE + g_dwCursorBufferOffset));
	m_pDUPnRegs[5][DU_PnMR    ] = PnMR_DDF_8 | PnMR_CPSL_4 | PnMR_SPIM_TRANS | PnMR_TC_PALETTE;
	m_pDUPnRegs[5][DU_PnMWR   ] = CURSOR_XSIZE;
	m_pDUPnRegs[5][DU_PnALPHAR] = 255;	/* 100% */
	m_pDUPnRegs[5][DU_PnDSXR  ] = CURSOR_XSIZE;
	m_pDUPnRegs[5][DU_PnDSYR  ] = CURSOR_YSIZE;
	m_pDUPnRegs[5][DU_PnDPXR  ] = 0;
	m_pDUPnRegs[5][DU_PnDPYR  ] = 0;
	m_pDUPnRegs[5][DU_PnDSA0R ] = (NCG_FBBASE + g_dwCursorBufferOffset) & 0x1FFFFFF0;
	m_pDUPnRegs[5][DU_PnDSA1R ] = (NCG_FBBASE + g_dwCursorBufferOffset) & 0x1FFFFFF0;
	m_pDUPnRegs[5][DU_PnDSA2R ] = (NCG_FBBASE + g_dwCursorBufferOffset) & 0x1FFFFFF0;
	m_pDUPnRegs[5][DU_PnSPXR  ] = 0;
	m_pDUPnRegs[5][DU_PnSPYR  ] = 0;
	m_pDUPnRegs[5][DU_PnWASPR ] = 0;
	m_pDUPnRegs[5][DU_PnWAMWR ] = 1024;
	m_pDUPnRegs[5][DU_PnBTR   ] = 0;
	m_pDUPnRegs[5][DU_PnTC1R  ] = 0;
	m_pDUPnRegs[5][DU_PnTC2R  ] = 0;
	m_pDUPnRegs[5][DU_PnMLR   ] = 0;

	m_pDURegs[DU_DPPR] = 0x76800000;

	/* enable interrupt */
	m_pDURegs[DU_DIER] = DIER_VBE;

    /* clear frame buffer */
    memset((void*)m_pLAW, 0x00, m_nVideoMemorySize);

    DEBUGMSG(GPE_ZONE_INIT,
        (TEXT("NCG: SetRegisters finished.\r\n")));
}



SCODE NCG::SetMode( int modeId, HPALETTE *pPalette )
{
    SCODE sc;
    int nCurrMode;
    EGPEFormat          format;
    EDDGPEPixelFormat	pixelFormat;

    DEBUGMSG(GPE_ZONE_ENTER,
        (TEXT("NCG::SetMode(%d, 0x%X)\r\n"), modeId, pPalette));

    nCurrMode = 0;
    while (nCurrMode < NUMDISPMODES) {
        if (modeId == NCGMode[nCurrMode].gpeModeEx.modeInfo.modeId) {
            DEBUGMSG(GPE_ZONE_INIT,
                (TEXT("SetMode: Mode %d found on NCGMode[%d].\r\n"),
                modeId, nCurrMode));
            break;
        }
        nCurrMode++;
    }
    if (nCurrMode >= NUMDISPMODES) {
        DEBUGMSG(GPE_ZONE_ERROR,
            (TEXT("SetMode: Mode %d required but not found.\r\n"), modeId));
        return E_INVALIDARG;
    }

    if( m_pMode ) { // The mode is already set, just return
        DEBUGMSG(GPE_ZONE_TEMP,
            (TEXT("SetMode: Mode already set.\r\n")));
        return S_OK;
    }

    m_pMode = &NCGMode[nCurrMode].gpeModeEx.modeInfo;
    m_pModeEx = &NCGMode[nCurrMode].gpeModeEx;
    m_nScreenWidth = m_pMode->width;
    m_nScreenHeight = m_pMode->height;
    m_dwPhysicalModeID = modeId;

	g_dwReservedVideoMemorySize =	g_dwCursorBufferSize;

    m_pVideoMemoryHeap = new SurfaceHeap(m_nVideoMemorySize - g_dwReservedVideoMemorySize, NULL);

    // primary surface
	if (NCGMode[nCurrMode].nPixelFormat == 0) {
		format = gpe8Bpp;
		pixelFormat = ddgpePixelFormat_8bpp;
	}
	else if (NCGMode[nCurrMode].nPixelFormat == 1) {
		format = gpe16Bpp;
		pixelFormat = ddgpePixelFormat_565;
	}
	else {
		format = gpe16Bpp;
		pixelFormat = ddgpePixelFormat_5551;
	}

    sc = AllocSurface(
            (DDGPESurf**)&m_pPrimarySurface,
            m_nScreenWidth,
            m_nScreenHeight,
            format,
            pixelFormat,
            GPE_REQUIRE_VIDEO_MEMORY);
    if (FAILED(sc))
        return sc;

	g_dwFrameBufferOffset = m_pPrimarySurface->OffsetInVideoMemory();
	DEBUGMSG(GPE_ZONE_INIT, (TEXT("PrimarySurface(0x%08x) : 0x%08x (0x%08x)\r\n"),
		m_pPrimarySurface, NCG_FBBASE + g_dwFrameBufferOffset, g_dwFrameBufferOffset));

	// cursor
	g_dwCursorBufferOffset = m_nVideoMemorySize - g_dwReservedVideoMemorySize;	// must be 16 byte align
	DEBUGMSG(GPE_ZONE_INIT, (TEXT("CursorBuffer : 0x%08x (0x%08x)\r\n"),
		NCG_FBBASE + g_dwCursorBufferOffset, g_dwCursorBufferOffset));

    /* Register initialization, also clears up video memory. */
    SetRegisters(modeId);

    /* Video memory is already cleared in register initialization part. */
    /* Let the primary surface visible. */
    SetVisibleSurface(m_pPrimarySurface);

    // Here, we use EngCreatePalette to create a palette that that MGDI will use as a
    // stock palette

    if (pPalette) {
        DEBUGMSG(GPE_ZONE_CREATE,
            (TEXT("SetMode: creating palette...\r\n")));

        if (m_pMode->Bpp == 8) {
            *pPalette = EngCreatePalette(
                PAL_INDEXED,
                PALETTE_SIZE,
                (ULONG *)_rgbIdentity,
                0,
                0,
                0 );
            DEBUGMSG(GPE_ZONE_CREATE,
                (TEXT("SetMode: 8bpp indexed palette is created.\r\n")));
        }
        else { // 16bpp
            *pPalette = EngCreatePalette(
                PAL_BITFIELDS,
                0,
                NULL,
                m_pModeEx->dwRBitMask,
                m_pModeEx->dwGBitMask,
                m_pModeEx->dwBBitMask );
            DEBUGMSG(GPE_ZONE_CREATE,
                (TEXT("SetMode: 16bpp bitfield palette is created.\r\n")));
        }
    }
    // Because the color palette is a shared resource, palette setting is
    // required even the screen mode is set to 16bpp.
    SetPalette(_rgbIdentity, 0, PALETTE_SIZE); // PALETTE_SIZE = 256

    DEBUGMSG( GPE_ZONE_ENTER,(TEXT("Leaving NCG::SetMode\r\n")));
    return S_OK;
}


SCODE NCG::GetModeInfo(
	GPEMode *pMode,
	int modeNo )
{
    DEBUGMSG(GPE_ZONE_TEMP,
        (TEXT("GetModeInfo: Requested mode %d.\r\n"), modeNo));

    if( modeNo < 0 || modeNo >= NUMDISPMODES )
        return E_INVALIDARG;
	
    *pMode = NCGMode[modeNo].gpeModeEx.modeInfo;
    return S_OK;
}


int NCG::NumModes()
{
    return NUMDISPMODES;
}


SCODE NCG::GetModeInfoEx(
    GPEModeEx *pModeEx,
    int modeNo )
{
    DEBUGMSG(GPE_ZONE_TEMP,
        (TEXT("GetModeInfoEx: Requested mode %d.\r\n"), modeNo));

    if (modeNo < 0 || modeNo >= NUMDISPMODES)
        return E_INVALIDARG;

    *pModeEx = NCGMode[modeNo].gpeModeEx;
    return S_OK;
}



/* In fact, contrast control is not supported by hardware. */
BOOL NCG::ContrastControl(ULONG cmd,ULONG *pValue)
{
    if ( pValue == NULL )
    {
        SetLastError(ERROR_INVALID_PARAMETER);
        return FALSE;
    }
    DEBUGMSG (GPE_ZONE_ENTER,
        (TEXT("NCG::ContrastControl, cmd=%d *pValue=%d\r\n"),cmd,*pValue));
    switch ( cmd ) {
    case CONTRAST_CMD_GET:
        *pValue = m_nContrastCurrent;
        return TRUE;

    case CONTRAST_CMD_SET:
        m_nContrastCurrent = (UCHAR)*pValue;
        return TRUE;

    case CONTRAST_CMD_INCREASE:
        if (m_nContrastCurrent<255) m_nContrastCurrent++;
        *pValue = m_nContrastCurrent;
        return TRUE;

    case CONTRAST_CMD_DECREASE:
        if (m_nContrastCurrent>0) m_nContrastCurrent--;
        *pValue = m_nContrastCurrent;
        return TRUE;
    case CONTRAST_CMD_DEFAULT:
        m_nContrastCurrent=0;
        return TRUE;

    default:
        SetLastError(ERROR_INVALID_PARAMETER);
    }

    return FALSE;
}

⌨️ 快捷键说明

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