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

📄 cim_gp.c

📁 LX 800 WindowsCE 6.0 BSP
💻 C
📖 第 1 页 / 共 5 页
字号:
 * This is generally the first routine called when programming a BLT.  This
 * routine performs the following functions:
 *   - Sets the initial value of the GP3_RASTER_MODE register in the buffer.
 *   - Clears any 8x8 pattern if the ROP does not involve pattern data.
 *-------------------------------------------------------------------------*/

void gp_set_raster_operation (unsigned char ROP)
{
	gp3_cmd_header |= GP3_BLT_HDR_RASTER_ENABLE;

	/* WRITE THE RASTER MODE REGISTER                                   */
	/* This register is in the same location in BLT and vector commands */

	gp3_raster_mode = gp3_bpp | (unsigned long)ROP;
	WRITE_COMMAND32 (GP3_BLT_RASTER_MODE, gp3_raster_mode);

	/* CHECK IF DESTINATION IS REQUIRED */

	if ((ROP & 0x55) ^ ((ROP >> 1) & 0x55))
	{
		gp3_blt_mode = GP3_BM_DST_REQ;
		gp3_vec_mode = GP3_VM_DST_REQ;
	}
	else
	{
		gp3_blt_mode = gp3_vec_mode = 0;
	}
}

/*----------------------------------------------------------------------------
 * gp_set_alpha_operation
 *
 * BLTs are generally one of two types, a ROPed BLT or a BLT composited using
 * alpha blending.  For the latter, this routine is used to configure the
 * mathematical function used to create the blended output.  This routine
 * should generally be called first when programming a BLT.  The available
 * parameters mirror the hardware and are described as follows:
 *
 * alpha_operation =
 *   0 - alpha * A
 *   1 - (1 - alpha) * B
 *   2 - A + (1 - alpha)*B
 *   3 - alpha*A + (1 - alpha)*B
 *
 * alpha_type =
 *   0 - alpha component of channel A
 *   1 - alpha component of channel B
 *   2 - Constant alpha
 *   3 - Constant 1
 *   4 - The color components of channel A
 *   5 - The color components of channel B
 *   6 - Alpha comes from the alpha channel of the source before the source undergoes
 *       color conversion.
 *
 * channel =
 *   0 - Channel A = source, channel B = destination
 *   1 - Channel B = source, channel A = destination
 *
 * apply_alpha =
 *   1 - Apply alpha blend to only the RGB portion of the pixel.  This must be
 *       set when the source or destination format do not include an alpha channel.
 *   2 - Apply alpha blend only to the alpha portion of the pixel.  This implies
 *       that both destination and source include an alpha channel.
 *   3 - Apply alpha blend to both the RGB and alpha portions of the pixel.
 *
 * Alpha-blended vectors are not currently supported.
 *-------------------------------------------------------------------------*/

void gp_set_alpha_operation (int alpha_operation, int alpha_type, int channel,
	int apply_alpha, unsigned char alpha)
{
	gp3_cmd_header |= GP3_BLT_HDR_RASTER_ENABLE;
	
	/* THE AVAILABLE ALPHA DEFINITIONS FOLLOW THE HARDWARE       */
	/* This allows us to avoid giant switch structures, but it   */
	/* also implies that there is no mechanism to detect invalid */
	/* parameters.                                               */

	gp3_raster_mode = gp3_bpp | (unsigned long)alpha |
		((unsigned long)apply_alpha     << 22) |
		((unsigned long)alpha_operation << 20) |
		((unsigned long)alpha_type      << 17) |
		((unsigned long)channel         << 16);
	
	WRITE_COMMAND32 (GP3_BLT_RASTER_MODE, gp3_raster_mode);

	/* CHECK IF DESTINATION IS REQUIRED */

	if ( (alpha_operation == CIMGP_ALPHA_TIMES_A &&
          channel == CIMGP_CHANNEL_A_SOURCE &&
          alpha_type != CIMGP_CHANNEL_B_ALPHA &&
          alpha_type != CIMGP_ALPHA_FROM_RGB_B)  ||
         (alpha_operation == CIMGP_BETA_TIMES_B &&
          channel == CIMGP_CHANNEL_A_DEST &&
          alpha_type != CIMGP_CHANNEL_A_ALPHA &&
          alpha_type != CIMGP_ALPHA_FROM_RGB_A))
    {
        gp3_blt_mode = 0;
    }
    else
        gp3_blt_mode = GP3_BM_DST_REQ;
}

/*---------------------------------------------------------------------------
 * gp_set_solid_pattern
 *
 * This routine is called to program the hardware for a solid pattern.  It need
 * not be called for any other reason.  As a side effect, this routine will
 * clear any 8x8 pattern data.
 *-------------------------------------------------------------------------*/

void gp_set_solid_pattern (unsigned long color)
{
	/* CHANNEL 3 IS NOT NEEDED FOR SOLID PATTERNS */

	gp3_ch3_pat = 0;

	/* SET SOLID PATTERN IN COMMAND BUFFER */
	/* We are assuming that only one pattern type is ever set for a */
	/* BLT.  We are also assuming that gp_set_raster_operation will */
	/* be called before this routine.  With these assumptions, we   */
	/* will thus never have to change the raster mode register for  */
	/* solid patterns.                                              */

	if (gp3_blt)
	{
		gp3_cmd_header |= GP3_BLT_HDR_PAT_CLR0_ENABLE;

		WRITE_COMMAND32 (GP3_BLT_PAT_COLOR_0, color);
	}
	else
	{
		gp3_cmd_header |= GP3_VEC_HDR_PAT_CLR0_ENABLE;

		WRITE_COMMAND32 (GP3_VECTOR_PAT_COLOR_0, color);
	}
}

/*---------------------------------------------------------------------------
 * gp_set_mono_pattern
 *
 * This routine is called to program the hardware for a monochrome pattern.
 * As a side effect, this routine will clear any 8x8 pattern data.
 *-------------------------------------------------------------------------*/

void gp_set_mono_pattern (unsigned long bgcolor, unsigned long fgcolor,
	unsigned long data0, unsigned long data1, int transparent, int x, int y)
{
	/* CHANNEL 3 IS NOT NEEDED FOR MONOCHROME PATTERNS */

	gp3_ch3_pat = 0;

	/* UPDATE RASTER MODE REGISTER */

	if (transparent) gp3_raster_mode |= GP3_RM_PAT_MONO | GP3_RM_PAT_TRANS;
	else             gp3_raster_mode |= GP3_RM_PAT_MONO;
		
	gp3_cmd_header |= GP3_BLT_HDR_RASTER_ENABLE;

	WRITE_COMMAND32 (GP3_BLT_RASTER_MODE, gp3_raster_mode);	

	/* SET MONOCHROME PATTERN DATA AND COLORS */

	if (gp3_blt)
	{
		gp3_cmd_header |= (GP3_BLT_HDR_PAT_CLR0_ENABLE | GP3_BLT_HDR_PAT_CLR1_ENABLE |
			GP3_BLT_HDR_PAT_DATA0_ENABLE | GP3_BLT_HDR_PAT_DATA1_ENABLE);

		WRITE_COMMAND32 (GP3_BLT_PAT_COLOR_0, bgcolor);
		WRITE_COMMAND32 (GP3_BLT_PAT_COLOR_1, fgcolor);
		WRITE_COMMAND32 (GP3_BLT_PAT_DATA_0,  data0);
		WRITE_COMMAND32 (GP3_BLT_PAT_DATA_1,  data1);
	}
	else
	{
		gp3_cmd_header |= (GP3_VEC_HDR_PAT_CLR0_ENABLE | GP3_VEC_HDR_PAT_CLR1_ENABLE |
			GP3_VEC_HDR_PAT_DATA0_ENABLE | GP3_VEC_HDR_PAT_DATA1_ENABLE);

		WRITE_COMMAND32 (GP3_VECTOR_PAT_COLOR_0, bgcolor);
		WRITE_COMMAND32 (GP3_VECTOR_PAT_COLOR_1, fgcolor);
		WRITE_COMMAND32 (GP3_VECTOR_PAT_DATA_0,  data0);
		WRITE_COMMAND32 (GP3_VECTOR_PAT_DATA_1,  data1);
	}

	/* SAVE PATTERN ORIGIN */

	gp3_pat_origin = ((unsigned long)y << 29) | (((unsigned long)x & 7) << 26);
}

/*---------------------------------------------------------------------------
 * gp_set_pattern_origin
 *
 * This routine overrides the pattern origins set in gp_set_mono_pattern or
 * gp_set_color_pattern.  It is generally used to override the original
 * pattern origin due to a change in clipping.
 *-------------------------------------------------------------------------*/

void gp_set_pattern_origin (int x, int y)
{
	/* SAVE PATTERN ORIGIN */

	gp3_pat_origin = ((unsigned long)y << 29) | (((unsigned long)x & 7) << 26);
}

/*---------------------------------------------------------------------------
 * gp_set_color_pattern
 *
 * This routine is called to program a 8x8 color pattern into the LUT hardware.
 * Unlike the other pattern routines, this routine must be called before
 * any gp_declare_xxxx routines.  The pattern that is programmed into the
 * hardware will stay persistent for all subsequent primitives until one of
 * the following conditions happens.
 *   - Another pattern type is programmed.
 *   - A color-conversion BLT rotation BLT.
 *-------------------------------------------------------------------------*/

void gp_set_color_pattern (unsigned long *pattern, int format, int x, int y)
{
	unsigned long size_dwords, temp;
	
	gp3_ch3_pat = 1;

	/* SAVE COLOR PATTERN SOURCE INFO */
	/* Color patterns can be in a format different than the primary display. */
	/* 4BPP patterns are not supported.                                      */
	
	gp3_pat_pix_shift = (unsigned long)((format >> 2) & 3);
	gp3_pat_format = (((unsigned long)format & 0xF)  << 24) |
		             (((unsigned long)format & 0x10) << 17) |
					 GP3_CH3_COLOR_PAT_ENABLE               |
					 GP3_CH3_C3EN;

	size_dwords = (64 << gp3_pat_pix_shift) >> 2;

	/* CHECK FOR WRAP AFTER LUT LOAD                 */
	/* Primitive size is 12 plus the amount of data. */

	gp3_cmd_next = gp3_cmd_current + (size_dwords << 2) + 12;
	
	if ((gp3_cmd_bottom - gp3_cmd_next) <= GP3_MAX_COMMAND_SIZE)
	{
		gp3_cmd_next   = gp3_cmd_top;
		gp3_cmd_header = GP3_LUT_HDR_TYPE | GP3_LUT_HDR_WRAP | GP3_LUT_HDR_DATA_ENABLE;

		/* WAIT FOR HARDWARE           */
		/* Same logic as BLT wrapping. */

		GP3_WAIT_WRAP(temp);
	}
	else
	{
		gp3_cmd_header = GP3_LUT_HDR_TYPE | GP3_LUT_HDR_DATA_ENABLE;

		/* WAIT FOR AVAILABLE SPACE */

		GP3_WAIT_PRIMITIVE(temp);
	}

	/* SAVE CURRENT BUFFER POINTER */

	cim_cmd_ptr = cim_cmd_base_ptr + gp3_cmd_current;

	/* PREPARE FOR COMMAND BUFFER DATA WRITES                 */
	/* Pattern data is contiguous DWORDs at LUT address 0x100 */

	WRITE_COMMAND32 (0, gp3_cmd_header);
	WRITE_COMMAND32 (4, 0x100);
	WRITE_COMMAND32 (8, size_dwords | GP3_LUT_DATA_TYPE);	

	/* WRITE ALL DATA */

	WRITE_COMMAND_STRING32 (12, pattern, 0, size_dwords);

	/* START OPERATION */

	WRITE_GP32 (GP3_CMD_WRITE, gp3_cmd_next);
	gp3_cmd_current = gp3_cmd_next;

	/* SAVE PATTERN ORIGIN */

	gp3_pat_origin = ((unsigned long)y << 29) | (((unsigned long)x & 7) << 26);
}

/*---------------------------------------------------------------------------
 * gp_set_mono_source
 *
 * This routine is called to program the colors for monochrome source data.
 *-------------------------------------------------------------------------*/

void gp_set_mono_source (unsigned long bgcolor, unsigned long fgcolor,
	int transparent)
{
	/* UPDATE RASTER MODE REGISTER IF TRANSPARENT */

	if (transparent)
	{
		gp3_cmd_header  |= GP3_BLT_HDR_RASTER_ENABLE;
		gp3_raster_mode |= GP3_RM_SRC_TRANS;

		WRITE_COMMAND32 (GP3_BLT_RASTER_MODE, gp3_raster_mode);	
	}

	/* SET MONOCHROME SOURCE COLORS */
	/* Note that this routine only sets the colors.  The actual */
	/* source type is determined by the final output routine    */
	/* (gp_mono_bitmap_xxx, gp_color_bitmap_xxx, etc.)          */

	gp3_cmd_header |= GP3_BLT_HDR_SRC_FG_ENABLE | GP3_BLT_HDR_SRC_BG_ENABLE;

	WRITE_COMMAND32 (GP3_BLT_SRC_COLOR_FG, fgcolor);
	WRITE_COMMAND32 (GP3_BLT_SRC_COLOR_BG, bgcolor);
}

/*---------------------------------------------------------------------------
 * gp_set_solid_source
 *
 * This routine is called to program a solid source color.  A solid source
 * color is used primarily for vectors or antialiased text.
 *-------------------------------------------------------------------------*/

void gp_set_solid_source (unsigned long color)
{
	/* SET SOLID SOURCE COLOR */
	/* The solid source register is in the same place for both BLTs and */
	/* vectors.                                                         */

	gp3_cmd_header |= GP3_BLT_HDR_SRC_FG_ENABLE;

	WRITE_COMMAND32 (GP3_BLT_SRC_COLOR_FG, color);
}

/*---------------------------------------------------------------------------
 * gp_set_source_transparency
 *
 * This routine sets the source transparency and mask to be used in future
 * rendering operations.  Transparency is cleared by gp_set_raster_operation,
 * so this routine should never be called first.
 *-------------------------------------------------------------------------*/

void gp_set_source_transparency (unsigned long color, unsigned long mask)
{
	gp3_raster_mode |= GP3_RM_SRC_TRANS;
	gp3_cmd_header  |= GP3_BLT_HDR_RASTER_ENABLE | GP3_BLT_HDR_SRC_FG_ENABLE |
		GP3_BLT_HDR_SRC_BG_ENABLE;
	
	WRITE_COMMAND32 (GP3_BLT_RASTER_MODE, gp3_raster_mode);	
	WRITE_COMMAND32 (GP3_BLT_SRC_COLOR_FG, color);
	WRITE_COMMAND32 (GP3_BLT_SRC_COLOR_BG, mask);
}

/*---------------------------------------------------------------------------
 * gp_program_lut
 *
 * This routine is called to program the hardware LUT with color-conversion
 * information.  This routine should be called before any gp_declare_xxxx
 * routines.
 *
 * colors   - Pointer to an array of DWORDs for color expansion.
 *
 * full_lut - Selector between 4BPP and 8BPP expansion. The hardware is
 *            initialized with 16 dwords for 4BPP expansion and 256 dwords
 *            for 8BPP expansion.
 *-------------------------------------------------------------------------*/

void gp_program_lut (unsigned long *colors, int full_lut)
{
	unsigned long size_dwords, temp;
	
	/* SIZE IS EITHER 16 DWORDS (4BPP) or 256 DWORDS (8BPP) */

	if (full_lut) size_dwords = 256;
	else          size_dwords = 16;

	/* CHECK FOR WRAP AFTER LUT LOAD                 */

⌨️ 快捷键说明

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