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

📄 gpeflat.cpp

📁 wince.net板级支持包BSP for EP9315
💻 CPP
📖 第 1 页 / 共 3 页
字号:
//**********************************************************************
//                                                                      
// Filename: gpeflat.cpp
//                                                                      
// Description: Flat driver for the EP9312.
//
// 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.
//
// Use of this source code is subject to the terms of the Cirrus 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 
// EULA.RTF on your install media.
//
// Copyright(c) Cirrus Logic Corporation 2002, All Rights Reserved                       
//                                                                      
//**********************************************************************
                   
#include    "precomp.h"
#include    "..\common\palette.h" // for 8Bpp we use the natural palette

INSTANTIATE_PALETTE

//
// Set up the debug zones.
//
INSTANTIATE_GPE_ZONES(0x0003,"Flat DDI Driver","Palette","unused2")    // Start with errors and warnings
#define     GPE_ZONE_PALETTE    DEBUGZONE(14)


static  GPE *gGPE = (GPE*)NULL;

// This prototype avoids problems exporting from .lib
BOOL APIENTRY GPEEnableDriver(ULONG engineVersion, ULONG cj, DRVENABLEDATA *data,
                              PENGCALLBACKS  engineCallbacks);


//****************************************************************************
// DrvEnableDriver
//****************************************************************************
//
BOOL APIENTRY DrvEnableDriver(ULONG engineVersion, ULONG cj, DRVENABLEDATA *data,
                              PENGCALLBACKS  engineCallbacks)
{
    return GPEEnableDriver(engineVersion, cj, data, engineCallbacks);
}

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

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

    return gGPE;
}


//****************************************************************************
// GPEFlat::GPEFlat
//****************************************************************************
// GPEFlat Constructor
//
GPEFlat::GPEFlat (void)
{
    DWORD       oldMode;
    ULONG       fbSize;
    StartStop   StartStopTemp;


    DEBUGMSG(GPE_ZONE_INIT,(TEXT("GPEFlat::GPEFlat\r\n")));
    RETAILMSG(1,(TEXT("Init Raster engine\r\n")));

    oldMode = SetKMode(TRUE);

    //
    // Read in the settings from the registry.
    //
    GetDisplayRegistrySettings(&m_Registry);

    //
    // Initialize the values that are being used.
    //
    m_VirtualFrameBuffer    = FRAMEBUF_VIRTUAL_MEMORY;
    m_pvFlatFrameBuffer     = FRAMEBUF_PHYSICAL_MEMORY;
    m_ulColorDepth          = m_Registry.ulColorDepth;
    m_nScreenWidth          = m_Registry.ulScreenWidth;
    m_nScreenHeight         = m_Registry.ulScreenHeight;


    //
    // If the flag Set Directly is used then take the Raster values directly
    // from the registry.
    //
    if(m_Registry.ulSetDirectly)
    {
        //
        // Use the values from the registry to setup the display.
        //       
        GenericDisplaySetup(&m_Registry, FRAMEBUF_PHYSICAL_MEMORY, &StartStopTemp);
    }
    else
    {
        //
        // Use the generic CRT setup.
        //
        CRTVideoSetup
        (
            m_nScreenWidth,
            m_nScreenHeight,
            m_ulColorDepth,
            m_Registry.ulFrequency, 
            m_pvFlatFrameBuffer,
            &StartStopTemp
        );
    }

    //
    // Save off the video attributes register.
    //
    m_ulVideoAttrib = *RASTER_VIDEOATTRIBS | VIDEOATTRIBS_SDSEL_CS3;
    
    //
    // Program the proper color depth settings.
    //
    switch(m_ulColorDepth)
    {
        case  8:
        
            //
            // Set up the Color Look up table.   There are two LUT's in hardware.
            // the lookup table that is visible is not the one that is accessable.
            //
            SetPalette(_rgbIdentity, 0 , PALETTE_SIZE);
            
            //
            // Set up the Pixel mode.
            //
            *RASTER_PIXELMODE       = PIXELMODE_C_LUT | PIXELMODE_M_BLINKDISABLED |
                                      PIXELMODE_S_MODE1 | PIXELMODE_P_8BITS;
            m_ModeInfo.format       = gpe8Bpp;
            break;                                       
            
        case 16:
            *RASTER_PIXELMODE        = PIXELMODE_C_565 | PIXELMODE_M_BLINKDISABLED | PIXELMODE_S_MODE1 | 
                                       PIXELMODE_P_16BITS;
                                       
            //
            // Since we are not using a palette, setup red, green and blue masks.
            //                                       
            m_RedMaskSize           = 5;
            m_RedMaskPosition       = 11;
            m_GreenMaskSize         = 6;
            m_GreenMaskPosition     = 5;
            m_BlueMaskSize          = 5;
            m_BlueMaskPosition      = 0;
            m_ModeInfo.format       = gpe16Bpp;
            break;            
            
        case 24:
            *RASTER_PIXELMODE        = PIXELMODE_C_TRIPLE8 | PIXELMODE_M_BLINKDISABLED | PIXELMODE_S_MODE1 | 
                                       PIXELMODE_P_24BITS;
            //
            // Since we are not using a palette, setup red, green and blue masks.
            //                                       
            m_RedMaskSize           = 8;
            m_RedMaskPosition       = 16;
            m_GreenMaskSize         = 8;
            m_GreenMaskPosition     = 8;
            m_BlueMaskSize          = 8;
            m_BlueMaskPosition      = 0;
            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;    



    //
    //  Copy a few more variables.
    //
    m_cxPhysicalScreen  = m_nScreenWidth;
    m_cyPhysicalScreen  = m_nScreenHeight;
    m_cbScanLineLength  = m_cxPhysicalScreen * (m_ulColorDepth /8);


    //
    // set rest of ModeInfo values
    //
    m_ModeInfo.modeId       = 0;
    m_ModeInfo.width        = m_nScreenWidth;
    m_ModeInfo.height       = m_nScreenHeight;
    m_ModeInfo.Bpp          = m_ulColorDepth;
    m_ModeInfo.frequency    = m_Registry.ulFrequency;
    

    m_pPrimarySurface = new GPESurf
        (
            m_nScreenWidth, 
            m_nScreenHeight, 
            (void*)m_VirtualFrameBuffer, 
            m_cbScanLineLength, 
            m_ModeInfo.format
        );
    
    //
    // Clear the screen.
    //
    RETAILMSG(1,(TEXT("Clearing screen\r\n")));
    fbSize = m_cyPhysicalScreen * m_cbScanLineLength ;     
    memset ((void*)m_VirtualFrameBuffer, 0x0, fbSize);
    RETAILMSG(1,(TEXT("memset of video\r\n")));


    //
    // Setup the cursor stuff.
    //
    m_CursorVisible = FALSE;
    m_CursorDisabled = TRUE;
    m_CursorForcedOff = FALSE;
    memset (&m_CursorRect, 0x0, sizeof(m_CursorRect));
    m_CursorBackingStore = NULL;
    m_CursorXorShape = NULL;
    m_CursorAndShape = NULL;
    RETAILMSG(1,(TEXT("Returning from DDI init\r\n")));
}

//****************************************************************************
// GPEFlat::SetMode
//****************************************************************************
// Sets the Graphics mode and the palette.
//
SCODE   GPEFlat::SetMode (INT modeId, HPALETTE *palette)
{
    DEBUGMSG(GPE_ZONE_INIT,(TEXT("GPEFlat::SetMode\r\n")));

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

    if (palette)
    {
        switch (m_ulColorDepth)
        {
            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;
}

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

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

    *mode = m_ModeInfo;

    return S_OK;
}

//****************************************************************************
// GPEFlat::NumModes
//****************************************************************************
// Only one graphics mode currently supported.
// 
//
int  GPEFlat::NumModes()
{
    DEBUGMSG (GPE_ZONE_INIT, (TEXT("GPEFlat::NumModes\r\n")));
    return  1;
}

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

    if (!m_CursorForcedOff && !m_CursorDisabled && !m_CursorVisible)
    {
        if (!m_CursorBackingStore)
        {
            DEBUGMSG (GPE_ZONE_ERROR, (TEXT("GPEFlat::CursorOn - No backing store available\r\n")));
            return;
        }

        for (y = m_CursorRect.top; y < m_CursorRect.bottom; y++)
        {
            if (y < 0)
            {
                continue;
            }
            if (y >= m_nScreenHeight)
            {
                break;
            }

            ptrLine = &ptrScreen[y * m_pPrimarySurface->Stride()];
            cbsLine = &m_CursorBackingStore[(y - m_CursorRect.top) * (m_CursorSize.x * (m_ulColorDepth >> 3))];
            xorLine = &m_CursorXorShape[(y - m_CursorRect.top) * m_CursorSize.x];
            andLine = &m_CursorAndShape[(y - m_CursorRect.top) * m_CursorSize.x];

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

                cbsLine[(x - m_CursorRect.left) * (m_ulColorDepth >> 3)] = ptrLine[x * (m_ulColorDepth >> 3)];
                ptrLine[x * (m_ulColorDepth >> 3)] &= andLine[x - m_CursorRect.left];
                ptrLine[x * (m_ulColorDepth >> 3)] ^= xorLine[x - m_CursorRect.left];
                if (m_ulColorDepth > 8)
                {
                    cbsLine[(x - m_CursorRect.left) * (m_ulColorDepth >> 3) + 1] = ptrLine[x * (m_ulColorDepth >> 3) + 1];
                    ptrLine[x * (m_ulColorDepth >> 3) + 1] &= andLine[x - m_CursorRect.left];
                    ptrLine[x * (m_ulColorDepth >> 3) + 1] ^= xorLine[x - m_CursorRect.left];
                    if (m_ulColorDepth > 16)
                    {
                        cbsLine[(x - m_CursorRect.left) * (m_ulColorDepth >> 3) + 2] = ptrLine[x * (m_ulColorDepth >> 3) + 2];
                        ptrLine[x * (m_ulColorDepth >> 3) + 2] &= andLine[x - m_CursorRect.left];
                        ptrLine[x * (m_ulColorDepth >> 3) + 2] ^= xorLine[x - m_CursorRect.left];

⌨️ 快捷键说明

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