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

📄 sdk7a404_peg_lcd_driver.cpp

📁 含t h r e a d x,u c o s 的b s p
💻 CPP
📖 第 1 页 / 共 2 页
字号:
                wCury += y_sign;
                wNexty -= y_sign;
            }
            for (wpy = wCury - iWidth / 2;
                 wpy <= wCury + iWidth / 2; wpy++)
            {
                if (wCurx >= View.wLeft &&
                    wCurx <= View.wRight &&
                    wpy >= View.wTop &&
                    wpy <= View.wBottom)
                {
                    PlotPointView(wCurx, wpy, Color.uForeground);
                }
            }

            for (wpy = wNexty - iWidth / 2;
                 wpy <= wNexty + iWidth / 2; wpy++)
            {
                if (wNextx >= View.wLeft &&
                    wNextx <= View.wRight &&
                    wpy >= View.wTop &&
                    wpy <= View.wBottom)
                {
                    PlotPointView(wNextx, wpy, Color.uForeground);
                }
            }
        }
    }
    else
    {
        for (wCurx = xStart, wCury = yStart, wNextx = xEnd,
                wNexty = yEnd, decision = (dy >> 1);
            wCury <= wNexty; wCury++, wNexty--, decision += dx)
        {
            if (decision >= dy)
            {
                decision -= dy;
                wCurx += x_sign;
                wNextx -= x_sign;
            }
            for (wpx = wCurx - iWidth / 2;
                 wpx <= wCurx + iWidth / 2; wpx++)
            {
                if (wpx >= View.wLeft &&
                    wpx <= View.wRight &&
                    wCury >= View.wTop &&
                    wCury <= View.wBottom)
                {
                    PlotPointView(wpx, wCury, Color.uForeground);
                }
            }

            for (wpx = wNextx - iWidth / 2;
                 wpx <= wNextx + iWidth / 2; wpx++)
            {
                if (wpx >= View.wLeft &&
                    wpx <= View.wRight &&
                    wNexty >= View.wTop &&
                    wNexty <= View.wBottom)
                {
                    PlotPointView(wpx, wNexty, Color.uForeground);
                }
            }
        }
    }
}

/*--------------------------------------------------------------------------*/
void SDK7A400_LCD::BitmapView(const PegPoint Where,
            const PegBitmap *pMap, const PegRect &View)
{
    if (IS_RLE(pMap))
    {
        DrawRleBitmap(Where, View, pMap);
    }
    else
    {
        if (pMap->uBitsPix == 8)
        {
            Draw8BitBitmap(Where, View, pMap);
        }
        else
        {
            COLORVAL *Get = (COLORVAL *) pMap->pStart;
            Get += (View.wTop - Where.y) * pMap->wWidth;
            Get += View.wLeft - Where.x;

            if (HAS_TRANS(pMap))
            {
                for (SIGNED wLine = View.wTop; wLine <= View.wBottom; wLine++)
                {
                    COLORVAL *Put = mpScanPointers[wLine] + View.wLeft;
                    for (SIGNED wLoop1 = View.wLeft; wLoop1 <= View.wRight; wLoop1++)
                    {
                        COLORVAL uVal = *Get++;

                        if (uVal != pMap->dTransColor)
                        {
                            *Put = uVal;
                        }
                        Put++;
                    }
                    Get += pMap->wWidth - View.Width();
                }
            }
            else
            {
                for (SIGNED wLine = View.wTop; wLine <= View.wBottom; wLine++)
                {
                    COLORVAL *Put = mpScanPointers[wLine] + View.wLeft;
                    for (SIGNED wLoop1 = View.wLeft; wLoop1 <= View.wRight; wLoop1++)
                    {
                        *Put++ = *Get++;
                    }
                    Get += pMap->wWidth - View.Width();
                }
            }
        }
    }
}

/*--------------------------------------------------------------------------*/
void SDK7A400_LCD::RectMoveView(PegThing *Caller, const PegRect &View,
     const SIGNED xMove, const SIGNED yMove)
{
    // software emulated RectMove using Capture and Bitmap
    PegCapture BlockCapture;
    PegRect CaptureRect = View;
    Capture(&BlockCapture, CaptureRect);
    BlockCapture.Shift(xMove, yMove);
    Bitmap(Caller, BlockCapture.Point(), BlockCapture.Bitmap(), TRUE);
}

/*--------------------------------------------------------------------------*/
void SDK7A400_LCD::HorizontalLine(SIGNED xStart, SIGNED xEnd,
            SIGNED y, COLORVAL cColor, SIGNED iWidth)
{
    SIGNED iLen = xEnd - xStart + 1;

    if (iLen <= 0)
    {
        return;
    }
    while(iWidth-- > 0)
    {
        COLORVAL *Put = mpScanPointers[y] + xStart;
        SIGNED iLen1 = iLen;

        while(iLen1--)
        {
            *Put++ = cColor;
        }
        y++;
    }
}

/*--------------------------------------------------------------------------*/
void SDK7A400_LCD::VerticalLine(SIGNED yStart, SIGNED yEnd,
            SIGNED x, COLORVAL cColor, SIGNED iWidth)
{
    while(yStart <= yEnd)
    {
        SIGNED lWidth = iWidth;
        COLORVAL *Put = mpScanPointers[yStart] + x;

        while (lWidth-- > 0)
        {
            *Put++ = cColor;
        }
        yStart++;
    }
}

/*--------------------------------------------------------------------------*/
void SDK7A400_LCD::HorizontalLineXOR(SIGNED xs, SIGNED xe, SIGNED y)
{
    COLORVAL *Put = mpScanPointers[y] + xs;

    while (xs <= xe)
    {
        *Put ^= 0xffff;
        Put += 2;
        xs += 2;
    }
}

/*--------------------------------------------------------------------------*/
void SDK7A400_LCD::VerticalLineXOR(SIGNED ys, SIGNED ye, SIGNED x)
{
    COLORVAL uVal;

    while (ys <= ye)
    {
        COLORVAL *Put = mpScanPointers[ys] + x;
        uVal = *Put;
        uVal ^= 0xffff;
        *Put = uVal;
        ys += 2;
    }
}

/*--------------------------------------------------------------------------*/
void SDK7A400_LCD::DrawRleBitmap(const PegPoint Where, const PegRect View,
    const PegBitmap *Getmap)
{
    UCHAR *Get = Getmap->pStart;
    UCHAR uVal;
    SIGNED uCount;

    SIGNED wLine = Where.y;

    uCount = 0;

    while (wLine < View.wTop)
    {
        uCount = 0;

        while(uCount < Getmap->wWidth)
        {
            uVal = *Get++;
            if (uVal & 0x80)
            {
                uVal = (uVal & 0x7f) + 1;
                uCount += uVal;
                Get += uVal;
            }
            else
            {
                Get++;
                uCount += uVal + 1;
            }
        }
        wLine++;
    }

    while (wLine <= View.wBottom)
    {
        COLORVAL *Put = mpScanPointers[wLine] + Where.x;
        SIGNED wLoop1 = Where.x;

        while (wLoop1 < Where.x + Getmap->wWidth)
        {
            uVal = *Get++;

            if (uVal & 0x80)        // raw packet?
            {
                uCount = (uVal & 0x7f) + 1;
                
                while (uCount--)
                {
                    uVal = *Get++;
                    if (wLoop1 >= View.wLeft &&
                        wLoop1 <= View.wRight &&
                        uVal != 0xff)
                    {
                        *Put = mcHiPalette[uVal];
                    }
                    Put++;
                    wLoop1++;
                }
            }
            else
            {
                uCount = uVal + 1;
                uVal = *Get++;

                if (uVal == 0xff)
                {
                    wLoop1 += uCount;
                    Put += uCount;
                }
                else
                {
                    while(uCount--)
                    {
                        if (wLoop1 >= View.wLeft &&
                            wLoop1 <= View.wRight)
                        {
                            *Put++ = mcHiPalette[uVal];
                        }
                        else
                        {
                            Put++;
                        }
                        wLoop1++;
                    }
                }
            }
        }
        wLine++;
    }
}

/*--------------------------------------------------------------------------*/
void SDK7A400_LCD::Draw8BitBitmap(const PegPoint Where, const PegRect View,
    const PegBitmap *Getmap)
{
    
    UCHAR *Get = Getmap->pStart;
    Get += (View.wTop - Where.y) * Getmap->wWidth;
    Get += View.wLeft - Where.x;

    for (SIGNED wLine = View.wTop; wLine <= View.wBottom; wLine++)
    {
        COLORVAL *Put = mpScanPointers[wLine] + View.wLeft;
        for (SIGNED wLoop1 = View.wLeft; wLoop1 <= View.wRight; wLoop1++)
        {
            UCHAR uVal = *Get++;
            if (uVal != 0xff)
            {
                *Put = mcHiPalette[uVal];
            }
            Put++;
        }
        Get += Getmap->wWidth - View.Width();
    }
}

/*--------------------------------------------------------------------------*/
PegBitmap *SDK7A400_LCD::CreateBitmap(SIGNED wWidth, SIGNED wHeight)
{
   PegBitmap *pMap = NULL;

    if (wWidth && wHeight)
    {
        pMap = new PegBitmap;
        pMap->wWidth = wWidth;
        pMap->wHeight = wHeight;
        pMap->uFlags = BMF_HAS_TRANS;
        pMap->uBitsPix = 16;

        DWORD dSize = (DWORD) wWidth * (DWORD) wHeight * sizeof(COLORVAL);

        pMap->pStart = (UCHAR PEGFAR *) new COLORVAL[dSize];

        if (!pMap->pStart)
        {
            delete pMap;
            return NULL;
        }
        memset(pMap->pStart, 0, dSize);
    }
    return pMap;
}
 
/*--------------------------------------------------------------------------*/
void SDK7A400_LCD::MemoryToScreen(void)
{
    if (!miInvalidCount)
    {
        return;
    }

    PegRect Copy;
    Copy.wTop = 0;
    Copy.wLeft = 0;
    Copy.wRight = mwHRes - 1;
    Copy.wBottom = mwVRes - 1;
    Copy &= mInvalid;
}

/*--------------------------------------------------------------------------*/
// Return a pointer to the video buffer
/*--------------------------------------------------------------------------*/
UCHAR PEGFAR *SDK7A400_LCD::GetVideoAddress(void)
{
    UCHAR *pMem;

#if defined(STATIC_VBUF)
    pMem = (UCHAR PEGFAR *) gbVMemory;

#else
    pMem = (UCHAR PEGFAR *) VBUF_ADDR;
#endif

    return pMem; 
}

/*--------------------------------------------------------------------------*/
void SDK7A400_LCD::ConfigureController(void)
{
    INT_32 lcddev, regionsize;

    /* Setup LCD muxing for all 16 data bits */
    gpio_lcd_signal_select(GPIO_LCDV_0_15);

    /* Get handle to LCD device */
    lcddev = lcd_open (CLCDC, (INT_32) &LCDPANEL);

    /* Also make sure that the CPLD_JTAG_OE signal is in the
       correct state */
    gpio_set_data_dir (GPIO_PORT_A, 0x04, GPIO_OUTPUT);
    gpio_data_write (GPIO_PORT_A, 0x04);

    /* Set color depth to 16 bits per pixel */
    lcd_ioctl(lcddev, LCD_SET_BPP, 16);
 
    /* For displays that require more bandwidth, set DMA to request
       a transfer on 4 words empty instead of the default 8. This may
       help prevent 'display tearing' due to a starved LCD controller */
    regionsize = lcd_ioctl(lcddev, LCD_GET_STATUS, LCD_XSIZE) *
        lcd_ioctl(lcddev, LCD_GET_STATUS, LCD_YSIZE) * 2;
    if (regionsize >= (800 * 600 * 2))
    {
        /* Displays of 800x600 pixels and 16-bits of color (or larger)
           will use faster DMA requests */
        lcd_ioctl(lcddev, LCD_DMA_ON_4MT, 1);
    }

    /* HRTFT/TFT panel board initialization only */
    if ((lcd_ioctl (lcddev, LCD_GET_STATUS, LCD_PANEL_TYPE) == HRTFT) ||
        (lcd_ioctl (lcddev, LCD_GET_STATUS, LCD_PANEL_TYPE) == ADTFT) ||
        (lcd_ioctl (lcddev, LCD_GET_STATUS, LCD_PANEL_TYPE) == TFT))
    {
        /* Enable power to the LCD panel (sets VDDEN on PC3) */
        gpio_set_data_dir (GPIO_PORT_C, 0x08, GPIO_OUTPUT);
        gpio_data_write (GPIO_PORT_C, 0x08);
    }
    else
    {
        /* Other displays - do nothing (yet) */
        ;
    }

    /* Set frame buffer address - even in double buffering modes, the
       visible frame buffer always points to the first buffer. */
    lcd_ioctl(lcddev, LCD_SET_UP_FB,
        (INT_32) cp15_map_virtual_to_physical (GetVideoAddress ()));

    /* Enable LCD controller and power signals */
    lcd_ioctl(lcddev, LCD_PWENABLE, 1);
}

/*--------------------------------------------------------------------------*/
SDK7A400_LCD::SDK7A400_LCD(PegRect &Rect) : PegScreen(Rect)
{    
    mdNumColors = PEG_NUM_COLORS;

    mwHRes = Rect.Width();
    mwVRes = Rect.Height();

    mpScanPointers = new COLORVAL PEGFAR *[Rect.Height()];

    /* The working video buffer is always the non-visible buffer in double
       buffering mode, or the only (visible) buffer in single buffer mode */
    COLORVAL *CurrentPtr = (COLORVAL *) GetVideoAddress();
    CurrentPtr = CurrentPtr + ACTVID_OFFS;
    SetPalette(0, 232, DefPalette256);

    /* This loop clears the working video memory */
    for (SIGNED iLoop = 0; iLoop < mwVRes; iLoop++)
    {
        mpScanPointers[iLoop] = CurrentPtr;

        /* Clear video memory */
        for (SIGNED xLoop = 0; xLoop < mwHRes; xLoop++)
        {
            *CurrentPtr = BLACK;
            CurrentPtr++;
        }
    }

#if defined(DOUBLE_BUFFER)
    /* If double buffering is enabled, clear the visible memory */
    for (SIGNED iLoop = 0; iLoop < mwVRes; iLoop++)
    {
        CurrentPtr = (COLORVAL *) (mpScanPointers[iLoop] +
            VIDEOBUFF_SIZE);

        /* Clear video memory */
        for (SIGNED xLoop = 0; xLoop < mwHRes; xLoop++)
        {
            *CurrentPtr = BLACK;
            CurrentPtr++;
        }
    }
#endif

    mLastPointerPos.x = Rect.Width() / 2;
    mLastPointerPos.y = Rect.Height() / 2;
    mbPointerHidden = FALSE;
    mwDrawNesting = 0;

    ConfigureController();        // set up controller registers
}

/*--------------------------------------------------------------------------*/
SDK7A400_LCD::~SDK7A400_LCD()
{
    delete mpScanPointers;
}

/*--------------------------------------------------------------------------*/
// CreatePegScreen- Called by startup code to instantiate the PegScreen
// class we are going to run with.
/*--------------------------------------------------------------------------*/
PegScreen *CreatePegScreen(void)
{
    PegRect Rect;
    Rect.Set(0, 0, PEG_VIRTUAL_XSIZE - 1, PEG_VIRTUAL_YSIZE - 1);
    PegScreen *pScreen = new SDK7A400_LCD(Rect);
    return pScreen;
}



 

⌨️ 快捷键说明

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