📄 smi2d.c
字号:
/* src_X > dst_X */
/* +------+---+------+
|D | | S|
| | | |
| | | |
| | | |
+------+---+------+ */
nDirection = LEFT_TO_RIGHT;
}
}
if ((nDirection == BOTTOM_TO_TOP) || (nDirection == RIGHT_TO_LEFT))
{
src_X += dst_width - 1;
src_Y += dst_height - 1;
dst_X += dst_width - 1;
dst_Y += dst_height - 1;
opSign = (-1);
}
/* Workaround for 192 byte hw bug */
if ((nROP2 != 0x0C) && ((dst_width * (dst_BPP / 8)) >= 192))
{
/* Perform the ROP2 operation in chunks of (xWidth * dst_height) */
while (1)
{
deWaitForNotBusy();
regWrite32(DE_SOURCE,
FIELD_SET (0, DE_SOURCE, WRAP, DISABLE) |
FIELD_VALUE(0, DE_SOURCE, X_K1, src_X) |
FIELD_VALUE(0, DE_SOURCE, Y_K2, src_Y));
regWrite32(DE_DESTINATION,
FIELD_SET (0, DE_DESTINATION, WRAP, DISABLE) |
FIELD_VALUE(0, DE_DESTINATION, X, dst_X) |
FIELD_VALUE(0, DE_DESTINATION, Y, dst_Y));
regWrite32(DE_DIMENSION,
FIELD_VALUE(0, DE_DIMENSION, X, xWidth) |
FIELD_VALUE(0, DE_DIMENSION, Y_ET, dst_height));
de_ctrl = FIELD_VALUE(0, DE_CONTROL, ROP, nROP2) |
nTransparent |
FIELD_SET(0, DE_CONTROL, ROP_SELECT, ROP2) |
FIELD_SET(0, DE_CONTROL, COMMAND, BITBLT) |
((nDirection == 1) ? FIELD_SET(0, DE_CONTROL, DIRECTION, RIGHT_TO_LEFT)
: FIELD_SET(0, DE_CONTROL, DIRECTION, LEFT_TO_RIGHT)) |
FIELD_SET(0, DE_CONTROL, STATUS, START);
regWrite32(DE_CONTROL, de_ctrl);
src_X += (opSign * xWidth);
dst_X += (opSign * xWidth);
dst_width -= xWidth;
if (dst_width <= 0)
{
/* ROP2 operation is complete */
break;
}
if (xWidth > dst_width)
{
xWidth = dst_width;
}
}
}
else
{
deWaitForNotBusy();
regWrite32(DE_SOURCE,
FIELD_SET (0, DE_SOURCE, WRAP, DISABLE) |
FIELD_VALUE(0, DE_SOURCE, X_K1, src_X) |
FIELD_VALUE(0, DE_SOURCE, Y_K2, src_Y));
regWrite32(DE_DESTINATION,
FIELD_SET (0, DE_DESTINATION, WRAP, DISABLE) |
FIELD_VALUE(0, DE_DESTINATION, X, dst_X) |
FIELD_VALUE(0, DE_DESTINATION, Y, dst_Y));
regWrite32(DE_DIMENSION,
FIELD_VALUE(0, DE_DIMENSION, X, dst_width) |
FIELD_VALUE(0, DE_DIMENSION, Y_ET, dst_height));
de_ctrl = FIELD_VALUE(0, DE_CONTROL, ROP, nROP2) |
nTransparent |
FIELD_SET(0, DE_CONTROL, ROP_SELECT, ROP2) |
FIELD_SET(0, DE_CONTROL, COMMAND, BITBLT) |
((nDirection == 1) ? FIELD_SET(0, DE_CONTROL, DIRECTION, RIGHT_TO_LEFT)
: FIELD_SET(0, DE_CONTROL, DIRECTION, LEFT_TO_RIGHT)) |
FIELD_SET(0, DE_CONTROL, STATUS, START);
regWrite32(DE_CONTROL, de_ctrl);
}
SMI_de_busy = 1;
}
/**********************************************************************
*
* deSrcCopyHost
*
* Purpose
* Copy a rectangular area of the source surface in system memory to
* a destination surface in video memory
*
* Remarks
* Source bitmap must have the same color depth (BPP) as the destination bitmap.
*
**********************************************************************/
void deSrcCopyHost(unsigned long dst_base,
unsigned long dst_pitch,
unsigned long dst_BPP,
unsigned long dst_X,
unsigned long dst_Y,
unsigned long dst_width,
unsigned long dst_height,
unsigned long src_base,
unsigned long src_stride,
unsigned long src_X,
unsigned long src_Y,
pTransparent pTransp,
unsigned char nROP2)
{
int nBytes_per_scan;
int nBytes8_per_scan;
int nBytes_remain;
int nLong;
unsigned long nTransparent = 0;
unsigned long de_ctrl = 0;
unsigned long i;
int j;
unsigned long ulSrc;
unsigned long de_data_port_write_addr;
unsigned char abyRemain[8] = {0, 0, 0, 0, 0, 0, 0, 0};
unsigned char *pSrcBuffer;
pSrcBuffer = (unsigned char*)(src_base + src_Y * src_stride + src_X * (dst_BPP / 8));
nBytes_per_scan = dst_width * (dst_BPP / 8);
nBytes8_per_scan = (nBytes_per_scan + 7) & ~7;
nBytes_remain = nBytes_per_scan & 7;
nLong = nBytes_per_scan & ~7;
/* Program 2D Drawing Engine */
deWaitForNotBusy();
/* Set transparent bits if necessary */
if (pTransp != NULL)
{
nTransparent = pTransp->match | pTransp->select | pTransp->control;
/* Set color compare register */
regWrite32(DE_COLOR_COMPARE,
FIELD_VALUE(0, DE_COLOR_COMPARE, COLOR, pTransp->color));
}
regWrite32(DE_WINDOW_DESTINATION_BASE, FIELD_VALUE(0, DE_WINDOW_DESTINATION_BASE, ADDRESS, dst_base));
regWrite32(DE_WINDOW_SOURCE_BASE, FIELD_VALUE(0, DE_WINDOW_SOURCE_BASE, ADDRESS, 0));
regWrite32(DE_SOURCE,
FIELD_SET (0, DE_SOURCE, WRAP, DISABLE) |
FIELD_VALUE(0, DE_SOURCE, X_K1, 0) |
FIELD_VALUE(0, DE_SOURCE, Y_K2, src_Y));
regWrite32(DE_DESTINATION,
FIELD_SET (0, DE_DESTINATION, WRAP, DISABLE) |
FIELD_VALUE(0, DE_DESTINATION, X, dst_X) |
FIELD_VALUE(0, DE_DESTINATION, Y, dst_Y));
regWrite32(DE_DIMENSION,
FIELD_VALUE(0, DE_DIMENSION, X, dst_width) |
FIELD_VALUE(0, DE_DIMENSION, Y_ET, dst_height));
regWrite32(DE_PITCH,
FIELD_VALUE(0, DE_PITCH, DESTINATION, dst_width) |
FIELD_VALUE(0, DE_PITCH, SOURCE, dst_width));
regWrite32(DE_WINDOW_WIDTH,
FIELD_VALUE(0, DE_WINDOW_WIDTH, DESTINATION, dst_width) |
FIELD_VALUE(0, DE_WINDOW_WIDTH, SOURCE, dst_width));
de_ctrl = FIELD_VALUE(0, DE_CONTROL, ROP, nROP2) |
nTransparent |
FIELD_SET(0, DE_CONTROL, ROP_SELECT, ROP2) |
FIELD_SET(0, DE_CONTROL, COMMAND, HOST_WRITE) |
FIELD_SET(0, DE_CONTROL, STATUS, START);
regWrite32(DE_CONTROL, de_ctrl);
/* Write bitmap/image data (line by line) to 2D Engine data port */
de_data_port_write_addr = DE_DATA_PORT;
for (i = 1; i < dst_height; i++)
{
for (j = 0; j < (nBytes8_per_scan / 4); j++)
{
memcpy(&ulSrc, (pSrcBuffer + (j * 4)), 4);
regWrite32(de_data_port_write_addr, ulSrc);
}
pSrcBuffer += src_stride;
}
/* Special handling for last line of bitmap */
if (nLong)
{
for (j = 0; j < (nLong / 4); j++)
{
memcpy(&ulSrc, (pSrcBuffer + (j * 4)), 4);
regWrite32(de_data_port_write_addr, ulSrc);
}
}
if (nBytes_remain)
{
memcpy(abyRemain, (pSrcBuffer + nLong), nBytes_remain);
regWrite32(de_data_port_write_addr, *(unsigned long*)abyRemain);
regWrite32(de_data_port_write_addr, *(unsigned long*)(abyRemain + 4));
}
SMI_de_busy = 1;
}
/**********************************************************************
*
* deMonoSrcCopyHost
*
* Purpose
* Copy a rectangular area of the monochrome source surface in
* system memory to a destination surface in video memory
*
* Parameters
* [in]
* pSrcSurface - Pointer to DE_SURFACE structure containing
* source surface attributes
* pSrcBuffer - Pointer to source buffer (system memory)
* containing monochrome image
* src_X - X coordinate of source surface
* src_Y - Y coordinate of source surface
* pDestSurface - Pointer to DE_SURFACE structure containing
* destination surface attributes
* dst_X - X coordinate of destination surface
* dst_Y - Y coordinate of destination surface
* dst_width - Width (in pixels) of the area to be copied
* dst_height - Height (in lines) of the area to be copied
* nFgColor - Foreground color
* nBgColor - Background color
* pClipRect - Pointer to Rect structure describing clipping
* rectangle; NULL if no clipping required
* pTransp - Pointer to Transparent structure containing
* transparency settings; NULL if no transparency
* required
*
* [out]
* None
*
* Returns
* DDK_OK - function is successful
* DDK_ERROR_NULL_PSRCSURFACE - pSrcSurface is NULL
* DDK_ERROR_NULL_PDESTSURFACE - pDestSurface is NULL
*
**********************************************************************/
void deMonoSrcCopyHost(unsigned long dst_base,
unsigned long dst_pitch,
unsigned long dst_BPP,
unsigned long dst_X,
unsigned long dst_Y,
unsigned long dst_width,
unsigned long dst_height,
unsigned long src_base,
unsigned long src_stride,
unsigned long src_X,
unsigned long src_Y,
unsigned long nFgColor,
unsigned long nBgColor,
pTransparent pTransp)
{
int nLeft_bits_off;
int nBytes_per_scan;
int nBytes4_per_scan;
int nBytes_remain;
int nLong;
unsigned long nTransparent = 0;
unsigned long de_ctrl = 0;
unsigned long de_data_port_write_addr;
unsigned long i;
int j;
unsigned long ulSrc;
unsigned char * pSrcBuffer;
pSrcBuffer = (unsigned char *)src_base+(src_Y * src_stride) + (src_X / 8);
nLeft_bits_off = (src_X & 0x07);
nBytes_per_scan = (dst_width + nLeft_bits_off + 7) / 8;
nBytes4_per_scan = (nBytes_per_scan + 3) & ~3;
nBytes_remain = nBytes_per_scan & 3;
nLong = nBytes_per_scan & ~3;
deWaitForNotBusy();
/* Set transparent bits if necessary */
if (pTransp != NULL)
{
nTransparent = pTransp->match | pTransp->select | pTransp->control;
/* Set color compare register */
regWrite32(DE_COLOR_COMPARE,
FIELD_VALUE(0, DE_COLOR_COMPARE, COLOR, pTransp->color));
}
/* Program 2D Drawing Engine */
regWrite32(DE_WINDOW_DESTINATION_BASE, FIELD_VALUE(0, DE_WINDOW_DESTINATION_BASE, ADDRESS, dst_base));
regWrite32(DE_WINDOW_SOURCE_BASE, FIELD_VALUE(0, DE_WINDOW_SOURCE_BASE, ADDRESS, 0));
regWrite32(DE_PITCH,
FIELD_VALUE(0, DE_PITCH, DESTINATION, dst_pitch) |
FIELD_VALUE(0, DE_PITCH, SOURCE, dst_pitch));
regWrite32(DE_WINDOW_WIDTH,
FIELD_VALUE(0, DE_WINDOW_WIDTH, DESTINATION, dst_pitch) |
FIELD_VALUE(0, DE_WINDOW_WIDTH, SOURCE, dst_pitch));
regWrite32(DE_SOURCE,
FIELD_SET (0, DE_SOURCE, WRAP, DISABLE) |
FIELD_VALUE(0, DE_SOURCE, X_K1, nLeft_bits_off) |
FIELD_VALUE(0, DE_SOURCE, Y_K2, src_Y));
regWrite32(DE_DESTINATION,
FIELD_SET (0, DE_DESTINATION, WRAP, DISABLE) |
FIELD_VALUE(0, DE_DESTINATION, X, dst_X) |
FIELD_VALUE(0, DE_DESTINATION, Y, dst_Y));
regWrite32(DE_DIMENSION,
FIELD_VALUE(0, DE_DIMENSION, X, dst_width) |
FIELD_VALUE(0, DE_DIMENSION, Y_ET, dst_height));
regWrite32(DE_FOREGROUND,
FIELD_VALUE(0, DE_FOREGROUND, COLOR, nFgColor));
regWrite32(DE_BACKGROUND,
FIELD_VALUE(0, DE_BACKGROUND, COLOR, nBgColor));
de_ctrl = 0x0000000C |
FIELD_SET(0, DE_CONTROL, ROP_SELECT, ROP2) |
FIELD_SET(0, DE_CONTROL, COMMAND, HOST_WRITE) |
FIELD_SET(0, DE_CONTROL, HOST, MONO) |
nTransparent |
FIELD_SET(0, DE_CONTROL, STATUS, START);
regWrite32(DE_CONTROL, de_ctrl);
/* Write bitmap/image data (line by line) to 2D Engine data port */
de_data_port_write_addr = DE_DATA_PORT;
for (i = 1; i < dst_height; i++)
{
for (j = 0; j < (nBytes4_per_scan / 4); j++)
{
memcpy(&ulSrc, (pSrcBuffer + (j * 4)), 4);
regWrite32(de_data_port_write_addr, ulSrc);
}
pSrcBuffer += src_stride;
}
/* Special handling for last line of bitmap */
if (nLong)
{
for (j = 0; j < (nLong / 4); j++)
{
memcpy(&ulSrc, (pSrcBuffer + (j * 4)), 4);
regWrite32(de_data_port_write_addr, ulSrc);
}
}
if (nBytes_remain)
{
memcpy(&ulSrc, (pSrcBuffer + nLong), nBytes_remain);
regWrite32(de_data_port_write_addr, ulSrc);
}
SMI_de_busy = 1;
}
/**********************************************************************
*
* Misc. functions
*
**********************************************************************/
// Load 8x8 pattern into local video memory
void deLoadPattern(unsigned char* pattern, unsigned long write_addr)
{
int i;
for (i = 0; i < (8 * 8 * 2); i += 4)
{
memWrite32(write_addr, *(unsigned long*)(&pattern[i]));
write_addr += 4;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -