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

📄 s3c2440disp.cpp

📁 绝对原创!三星2440基于优龙的板子
💻 CPP
📖 第 1 页 / 共 3 页
字号:
//
// 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 "Gradiation24Bpp.h" //320x240x24BPP LOGO
//#include "barnyard16bpp.h"
#include "precomp.h"
#include <syspal.h>    // for 8Bpp we use the natural palette
#include <gxinfo.h>
#define DISPPERF_DECLARE
#include "dispperf.h"
#include "s3c2440a_lcd.h"

INSTANTIATE_GPE_ZONES(0x3,"MGDI Driver","unused1","unused2")    // Start with errors and warnings

DDGPE * gGPE = (DDGPE *)NULL;

// 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);
}

//
// Main entry point for a GPE-compliant driver
//

GPE *
GetGPE()
{
    if (!gGPE)
    {
        gGPE = new S3C2440DISP();
    }

    return gGPE;
}

ULONG gBitMasks[] = { 0xff0000,0x00ff0,0x0000ff};
//ULONG gBitMasks[] = { 0xf800,0x07e0,0x001f};

S3C2440DISP::S3C2440DISP()
{
    DWORD      oldMode;
    ULONG      fbSize;
    ULONG      fbOffset;
    ULONG      offsetX;
    ULONG      offsetY;

    m_InDDraw = FALSE;

    DEBUGMSG(GPE_ZONE_INIT,(TEXT("S3C2440DISP::S3C2440DISP\r\n")));

    oldMode = SetKMode(TRUE);

                m_RedMaskSize = 8;
                m_RedMaskPosition = 16;
                m_GreenMaskSize = 8;
                m_GreenMaskPosition = 8;
                m_BlueMaskSize = 8;
                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 = 32;
    m_cxPhysicalScreen = LCD_XSIZE_TFT;
    m_cyPhysicalScreen = LCD_YSIZE_TFT;
//////    m_pvFlatFrameBuffer = 0xac100000;
    m_pvFlatFrameBuffer = 0x30100000;
    //m_cbScanLineLength = m_nScreenWidth * 2;
	m_cbScanLineLength = m_nScreenWidth * 4;

    m_iRotate = GetRotateModeFromReg();
    SetRotateParams();

    SetKMode(oldMode);

    // set rest of ModeInfo values
    m_ModeInfo.modeId = 0;
    m_ModeInfo.width = m_nScreenWidth;
    m_ModeInfo.height = m_nScreenHeight;
    m_ModeInfo.Bpp = m_colorDepth;
    m_ModeInfo.frequency = 60;    // ?
    switch (m_colorDepth)
    {
        case    8:
            m_ModeInfo.format = gpe8Bpp;
            break;

        case    16:
            m_ModeInfo.format = gpe16Bpp;
            break;

        case    24:
            m_ModeInfo.format = gpe24Bpp;
            break;

        case    32:
            m_ModeInfo.format = gpe32Bpp;
            break;

        default:
            DEBUGMSG(GPE_ZONE_ERROR,(TEXT("Invalid BPP value passed to driver - %d\r\n"), m_ModeInfo.Bpp));
            m_ModeInfo.format = gpeUndefined;
            break;
    }
    m_pMode = &m_ModeInfo;

    // 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 < LCD_YSIZE_TFT*LCD_XSIZE_TFT; 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);
	//memcpy((void*)m_VirtualFrameBuffer,gImage_barnyard16bpp, 153600);
	//memcpy((void*)m_VirtualFrameBuffer,gImage_Gradiation24Bpp, 307200);

    m_VirtualFrameBuffer += fbOffset;
    fbSize -= fbOffset;

    m_p2DVideoMemory = new Node2D(m_cbScanLineLength * 8UL / m_pMode->Bpp, fbSize / m_cbScanLineLength, 0, 0, 4);
    if(!m_p2DVideoMemory)
    {
        RETAILMSG (1, (L"new Node2D failed\n"));
        return;
    }

    if(FAILED(AllocSurface(&m_pPrimarySurface, m_nScreenWidthSave, m_nScreenHeightSave, m_pMode->format, GPE_REQUIRE_VIDEO_MEMORY)))
    {
        RETAILMSG (1, (L"Couldn't allocate primary surface\n"));
        return;
    }

    m_pPrimarySurface->SetRotation(m_nScreenWidth, m_nScreenHeight, m_iRotate);

    m_CursorVisible = FALSE;
    m_CursorDisabled = TRUE;
    m_CursorForcedOff = FALSE;
    memset (&m_CursorRect, 0x0, sizeof(m_CursorRect));
}

S3C2440DISP::~S3C2440DISP()
{
    if (m_VirtualFrameBuffer != NULL)
        UnmapViewOfFile((LPVOID)m_VirtualFrameBuffer);
    if (m_hVFBMapping != NULL)
        CloseHandle(m_hVFBMapping);
}

SCODE    S3C2440DISP::SetMode (INT modeId, HPALETTE *palette)
{
    DEBUGMSG(GPE_ZONE_INIT,(TEXT("S3C2440DISP::SetMode\r\n")));

    if (modeId != 0)
    {
        DEBUGMSG(GPE_ZONE_ERROR,(TEXT("S3C2440DISP::SetMode Want mode %d, only have mode 0\r\n"),modeId));
        return    E_INVALIDARG;
    }

    if (palette)
    {
        switch (m_colorDepth)
        {
            case    8:
                *palette = EngCreatePalette (PAL_INDEXED,
                                             PALETTE_SIZE,
                                             (ULONG*)_rgbIdentity,
                                             0,
                                             0,
                                             0);
                break;

            case    16:
            case    24:
            case    32:
                *palette = EngCreatePalette (PAL_BITFIELDS,
                                             0,
                                             NULL,
                                             ((1 << m_RedMaskSize) - 1) << m_RedMaskPosition,
                                             ((1 << m_GreenMaskSize) - 1) << m_GreenMaskPosition,
                                             ((1 << m_BlueMaskSize) - 1) << m_BlueMaskPosition);
                break;
        }
    }

    return S_OK;
}

SCODE    S3C2440DISP::GetModeInfo(GPEMode *mode,    INT modeNumber)
{
    DEBUGMSG (GPE_ZONE_INIT, (TEXT("S3C2440DISP::GetModeInfo\r\n")));

    if (modeNumber != 0)
    {
        return E_INVALIDARG;
    }

    *mode = m_ModeInfo;

    return S_OK;
}

int        S3C2440DISP::NumModes()
{
    DEBUGMSG (GPE_ZONE_INIT, (TEXT("S3C2440DISP::NumModes\r\n")));
    return    1;
}

void    S3C2440DISP::CursorOn (void)
{
    UCHAR    *ptrScreen = (UCHAR*)m_pPrimarySurface->Buffer();
    UCHAR    *ptrLine;
    UCHAR    *cbsLine;
    int        x, y;

    if (!m_CursorForcedOff && !m_CursorDisabled && !m_CursorVisible)
    {
        RECTL cursorRectSave = m_CursorRect;
        int   iRotate;
        RotateRectl(&m_CursorRect);
        for (y = m_CursorRect.top; y < m_CursorRect.bottom; y++)
        {
            if (y < 0)
            {
                continue;
            }
            if (y >= m_nScreenHeightSave)
            {
                break;
            }

            ptrLine = &ptrScreen[y * m_pPrimarySurface->Stride()];
            cbsLine = &m_CursorBackingStore[(y - m_CursorRect.top) * (m_CursorSize.x * (m_colorDepth >> 3))];

            for (x = m_CursorRect.left; x < m_CursorRect.right; x++)
            {
                if (x < 0)
                {
                    continue;
                }
                if (x >= m_nScreenWidthSave)
                {
                    break;
                }

                // x' = x - m_CursorRect.left; y' = y - m_CursorRect.top;
                // Width = m_CursorSize.x;   Height = m_CursorSize.y;
                switch (m_iRotate)
                {
                    case DMDO_0:
                        iRotate = (y - m_CursorRect.top)*m_CursorSize.x + x - m_CursorRect.left;
                        break;
                    case DMDO_90:
                        iRotate = (x - m_CursorRect.left)*m_CursorSize.x + m_CursorSize.y - 1 - (y - m_CursorRect.top);   
                        break;
                    case DMDO_180:
                        iRotate = (m_CursorSize.y - 1 - (y - m_CursorRect.top))*m_CursorSize.x + m_CursorSize.x - 1 - (x - m_CursorRect.left);
                        break;
                    case DMDO_270:
                        iRotate = (m_CursorSize.x -1 - (x - m_CursorRect.left))*m_CursorSize.x + y - m_CursorRect.top;
                        break;

⌨️ 快捷键说明

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