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

📄 r2d_vertical_lcd_i.c

📁 是一个手机功能的模拟程序
💻 C
📖 第 1 页 / 共 5 页
字号:
               IND_rvf_send_trace("R2D : Framebuffer overflow 4",28, NULL_PARAM, 
				   RV_TRACE_LEVEL_ERROR, R2D_USE_ID );
            #endif
            goto r2d_fail_get_pixel;
          }


        // Get the pixel position into the memory word
        y=y & R2D_WORD_POSITION_MASK;
		y=y << R2D_PIXEL_POS_TO_BIT_POS;
        pixel_cache=*p;

        result=(pixel_cache >> y) & R2D_PIXEL_MASK;
        return((~IND_r2d_lcd_to_color(result)) & 0x00FFFFFF);
		}
    break;
    case R2D_LCD_KIND: // LCD format with any size
    {
      INT16 height,width;
      height=((T_R2D_FRAMEBUFFER*)(gc->p_frame_buffer))->height;
      width=((T_R2D_FRAMEBUFFER*)(gc->p_frame_buffer))->width;
     
#if (R2D_REFRESH == R2D_VERTICAL)
        // Get position of the memory word containing the pixel
        p+=((x*R2D_ALIGNED_MWLENGTH(height)+(y>>R2D_PIXELS_PER_MEMORY_WORD)));
#else
		p+=((x*R2D_ALIGNED_MWLENGTH(width)+(y>>R2D_PIXELS_PER_MEMORY_WORD)));
#endif


          if ((y<0) || (x<0) || ((p<((T_R2D_FRAMEBUFFER*)(gc->p_frame_buffer))->p_memory_words) 
          || (p>((T_R2D_FRAMEBUFFER*)(gc->p_frame_buffer))->p_frame_buffer_end)))
          {
            #if (R2D_DEBUG == R2D_ON)
               IND_rvf_send_trace("R2D : Framebuffer overflow 5",28, NULL_PARAM, 
				   RV_TRACE_LEVEL_ERROR, R2D_USE_ID );
            #endif
            goto r2d_fail_get_pixel;
          }


        // Get the pixel position into the memory word
        y=y & R2D_WORD_POSITION_MASK;
		y=y << R2D_PIXEL_POS_TO_BIT_POS;
        pixel_cache=*p;

        result=(pixel_cache >> y) & R2D_PIXEL_MASK;
        
        return(~IND_r2d_lcd_to_color(result) & 0x00FFFFFF);
    }
    break;
    case R2D_FULL_KIND:
    {
      INT16 height,width;
      height=((T_R2D_FRAMEBUFFER*)(gc->p_frame_buffer))->height;
      width=((T_R2D_FRAMEBUFFER*)(gc->p_frame_buffer))->width;
     
       //printf("%08X\n",p);
        // Get position of the memory word containing the pixel
#if (R2D_REFRESH == R2D_VERTICAL)
        p+=(x*height+y);
#else
		p+=(x*width+y);
#endif

       //printf(" --> %08X for x=%d and y=%d\n",p,x,y);


          if ((y<0) || (x<0) || ((p<((T_R2D_FRAMEBUFFER*)(gc->p_frame_buffer))->p_memory_words) 
          || (p>((T_R2D_FRAMEBUFFER*)(gc->p_frame_buffer))->p_frame_buffer_end)))
          {
            #if (R2D_DEBUG == R2D_ON)
               IND_rvf_send_trace("R2D : Framebuffer overflow 6",28, NULL_PARAM, 
				   RV_TRACE_LEVEL_ERROR, R2D_USE_ID );
            #endif
            goto r2d_fail_get_pixel;
          }


        // Get the pixel position into the memory word
        y=0;
        pixel_cache=*p;

        result=(~pixel_cache) & 0x00FFFFFF;
	}
    break;
  }
r2d_fail_get_pixel:return(0);
}

void r2d_draw_lcd_pixel(T_R2D_GC* gc,INT16 x,INT16 y,UINT16 pixel_value,T_R2D_DRAWING_MODE mode)
{
	UINT16 *p, value;

	p= (UINT16 *)( ((T_R2D_FRAMEBUFFER*)(gc->p_frame_buffer))->p_memory_words);

	//glowing,2004-07-10, to draw the pixel in continuous memory
	//p+=((x*(R2D_WIDTH+2)+y));   ///x :height y:width
	p+=((x*(R2D_WIDTH)+y));   ///x :height y:width
	
	switch(mode){
		case R2D_COPY_MODE:		
			*p = pixel_value;
			break;
		case R2D_OR_MODE:
			value = *p;
			*p = value | pixel_value;
			break;	
		case R2D_AND_MODE:
			value = *p;
			*p = value & pixel_value;
			break;	
		case R2D_XOR_MODE:
			value = *p;
			*p = value ^ pixel_value;
			break;	
	}

}

void r2d_draw_lcd_rect(T_R2D_GC* gc,int px, int py, int sx, int sy, UINT16 * bm){

	UINT16 *p ,*ptr ,*ptrbmp,lcdy ;

	p= (UINT16 *)( ((T_R2D_FRAMEBUFFER*)(gc->p_frame_buffer))->p_memory_words);
    
for(lcdy=0;(lcdy<sy)&&((lcdy+py)<R2D_HEIGHT);lcdy++){ 
	//glowing,2004-07-10, draw the pixel in continous memory
	//ptr = p + (py + lcdy) * (R2D_WIDTH+2) +px; //modified by ljq from 122 to R2D_WIDTH+2 2003/4/11
	ptr = p + (py + lcdy) * (R2D_WIDTH) +px; //modified by ljq from 122 to R2D_WIDTH+2 2003/4/11
	ptrbmp = bm + sx *lcdy;
	
	if((px+sx)<R2D_WIDTH)
		memcpy(ptr ,ptrbmp ,sx*2);
	else
		if(px<R2D_WIDTH)
			memcpy(ptr,ptrbmp,(R2D_WIDTH-px)*2);
     }
}

void r2d_new_write_lcd_pixel(T_R2D_GC* gc,INT16 x,INT16 y,UINT32 pixel_value, T_R2D_DRAWING_MODE mode)
{
	UINT32 *p;
	UINT16 tmp;
	UINT32 pixel_cache,new_value;
	T_R2D_DRAWING_OP dop;

	switch(mode)
	{
		case R2D_COPY_MODE:
			dop = r2d_g_lcd_operators[R2D_COPY_MODE];   //dop is function below :static UINT32 r2d_lcd_copy_operator(UINT32 old,UINT32 value) 
			break;
		case R2D_OR_MODE:
			dop = r2d_g_lcd_operators[R2D_OR_MODE];
			break;
		case R2D_AND_MODE:
			dop = r2d_g_lcd_operators[R2D_AND_MODE];
			break;
		case R2D_XOR_MODE:
			dop = r2d_g_lcd_operators[R2D_XOR_MODE];
			break;
		default:
			dop=gc->drawing_op;
			break;
	}
	p=((T_R2D_FRAMEBUFFER*)(gc->p_frame_buffer))->p_memory_words;

	p+=((x*R2D_MWWIDTH+(y>>R2D_PIXELS_PER_MEMORY_WORD)));   ///x :height y:width

	if ((y<0) || (x<0) || ((p<((T_R2D_FRAMEBUFFER*)(gc->p_frame_buffer))->p_memory_words) 
	|| (p>((T_R2D_FRAMEBUFFER*)(gc->p_frame_buffer))->p_frame_buffer_end)))
	{
		#if (R2D_DEBUG == R2D_ON)
		IND_rvf_send_trace("R2D : Framebuffer overflow 7",28, NULL_PARAM, 
		RV_TRACE_LEVEL_ERROR, R2D_USE_ID );
		#endif
		goto r2d_fail_pixel;
	}


	// Get the pixel position into the memory word
	y=y & R2D_WORD_POSITION_MASK;  //R2D_WORD_POSITION_MASK == 1  judge y is odd or even number
	y=y << R2D_PIXEL_POS_TO_BIT_POS;  //R2D_PIXEL_POS_TO_BIT_POS == 4
	pixel_cache=*p;

	new_value=dop((pixel_cache >> y) & R2D_PIXEL_MASK,pixel_value) & R2D_PIXEL_MASK;  //R2D_PIXEL_MASK == 0xffff
	pixel_cache &= ~(R2D_PIXEL_MASK << y) ;

	// Write new value
	pixel_cache |= (new_value << y);
	*p=pixel_cache;

r2d_fail_pixel:tmp=0; // Just because one needs code after a label


}



// Low level pixel drawing
// (Note that for filling a more efficient version is used
// taking into account the fact that the position
// in the framebuffer has not to be recomputed from the coordinates
// for each pixel)
void r2d_write_lcd_pixel(T_R2D_GC* gc,INT16 x,INT16 y,UINT32 pixel_value, T_R2D_DRAWING_MODE mode)
{
  UINT32 *p;
  UINT16 tmp;
  UINT32 pixel_cache,new_value;
  T_R2D_DRAWING_OP dop;

  //dop = r2d_get_drawing_op(gc, mode);
 // gc->drawing_mode = mode;
 // gc->drawing_op = dop;  
//pre_dop = gc->drawing_op;
  
switch(mode)
{
case R2D_COPY_MODE:
	dop = r2d_g_lcd_operators[R2D_COPY_MODE];   //dop is function below :static UINT32 r2d_lcd_copy_operator(UINT32 old,UINT32 value) 
//	gc->drawing_op = dop;
	break;
case R2D_OR_MODE:
	dop = r2d_g_lcd_operators[R2D_OR_MODE];
//	gc->drawing_op = dop;
	break;
case R2D_AND_MODE:
	dop = r2d_g_lcd_operators[R2D_AND_MODE];
//	gc->drawing_op = dop;
	break;
case R2D_XOR_MODE:
	dop = r2d_g_lcd_operators[R2D_XOR_MODE];
//	gc->drawing_op = dop;
	break;
//case R2D_ALPHA_MODE:
	//dop = ((T_R2D_DRAWING_OP*)&r2d_alpha(color)
	//break;
default:
	dop=gc->drawing_op;
	break;
}

// dop=gc->drawing_op;

  p=((T_R2D_FRAMEBUFFER*)(gc->p_frame_buffer))->p_memory_words;

  switch(((T_R2D_FRAMEBUFFER*)(gc->p_frame_buffer))->kind)
  {
    case 0: // LCD format with hard coded dimensions
		{
        // Get position of the memory word containing the pixel
#if (R2D_REFRESH == R2D_VERTICAL)
        p+=((x*R2D_MWHEIGHT+(y>>R2D_PIXELS_PER_MEMORY_WORD)));
#else
		p+=((x*R2D_MWWIDTH+(y>>R2D_PIXELS_PER_MEMORY_WORD)));
#endif

          if ((y<0) || (x<0) || ((p<((T_R2D_FRAMEBUFFER*)(gc->p_frame_buffer))->p_memory_words) 
          || (p>((T_R2D_FRAMEBUFFER*)(gc->p_frame_buffer))->p_frame_buffer_end)))
          {
            #if (R2D_DEBUG == R2D_ON)
               IND_rvf_send_trace("R2D : Framebuffer overflow 7",28, NULL_PARAM, 
				   RV_TRACE_LEVEL_ERROR, R2D_USE_ID );
            #endif
            goto r2d_fail_pixel;
          }


        // Get the pixel position into the memory word
        y=y & R2D_WORD_POSITION_MASK;
		y=y << R2D_PIXEL_POS_TO_BIT_POS;
        pixel_cache=*p;

        new_value=dop((pixel_cache >> y) & R2D_PIXEL_MASK,pixel_value) & R2D_PIXEL_MASK;
        pixel_cache &= ~(R2D_PIXEL_MASK << y) ;

        // Write new value
        pixel_cache |= (new_value << y);
        *p=pixel_cache;
		}
    break;
    case R2D_LCD_KIND: // LCD format with any size
    {
      INT16 height,width;
      height=((T_R2D_FRAMEBUFFER*)(gc->p_frame_buffer))->height;
      width=((T_R2D_FRAMEBUFFER*)(gc->p_frame_buffer))->width;
     
#if (R2D_REFRESH == R2D_VERTICAL)
        // Get position of the memory word containing the pixel
        p+=((x*R2D_ALIGNED_MWLENGTH(height)+(y>>R2D_PIXELS_PER_MEMORY_WORD)));
#else
		p+=((x*R2D_ALIGNED_MWLENGTH(width)+(y>>R2D_PIXELS_PER_MEMORY_WORD)));
#endif


          if ((y<0) || (x<0) || ((p<((T_R2D_FRAMEBUFFER*)(gc->p_frame_buffer))->p_memory_words) 
          || (p>((T_R2D_FRAMEBUFFER*)(gc->p_frame_buffer))->p_frame_buffer_end)))
          {
            #if (R2D_DEBUG == R2D_ON)
               IND_rvf_send_trace("R2D : Framebuffer overflow 8",28, NULL_PARAM, 
				   RV_TRACE_LEVEL_ERROR, R2D_USE_ID );
            #endif
            goto r2d_fail_pixel;
          }


        // Get the pixel position into the memory word
        y=y & R2D_WORD_POSITION_MASK;
		y=y << R2D_PIXEL_POS_TO_BIT_POS;
        pixel_cache=*p;

        new_value=dop((pixel_cache >> y) & R2D_PIXEL_MASK,pixel_value) & R2D_PIXEL_MASK;
        pixel_cache &= ~(R2D_PIXEL_MASK << y) ;

        // Write new value
        pixel_cache |= (new_value << y);
        *p=pixel_cache;
     
    }
    break;
    case R2D_FULL_KIND:
    {
      INT16 height,width;
      height=((T_R2D_FRAMEBUFFER*)(gc->p_frame_buffer))->height;
      width=((T_R2D_FRAMEBUFFER*)(gc->p_frame_buffer))->width;
     
       //printf("%08X\n",p);
        // Get position of the memory word containing the pixel
#if (R2D_REFRESH == R2D_VERTICAL)
        p+=(x*height+y);
#else
		p+=(x*width+y);
#endif

       //printf(" --> %08X for x=%d and y=%d\n",p,x,y);


          if ((y<0) || (x<0) || ((p<((T_R2D_FRAMEBUFFER*)(gc->p_frame_buffer))->p_memory_words) 
          || (p>((T_R2D_FRAMEBUFFER*)(gc->p_frame_buffer))->p_frame_buffer_end)))
          {
            #if (R2D_DEBUG == R2D_ON)
               IND_rvf_send_trace("R2D : Framebuffer overflow A",28, NULL_PARAM, 
				   RV_TRACE_LEVEL_ERROR, R2D_USE_ID );
            #endif
            goto r2d_fail_pixel;
          }


        // Get the pixel position into the memory word
        y=0;
        pixel_cache=*p;

        new_value=dop(pixel_cache,pixel_value);
        pixel_cache = new_value;
        *p=pixel_cache;
	}
    break;
  }
  r2d_fail_pixel:tmp=0; // Just because one needs code after a label
}




#if (R2D_ASM == R2D_OFF)



// For blitting, two scanning direction are required because of possible
// overlaps between src and dst

// Shift new pixel from srcstream to dststream using variable srccache
// as a pixel cache.dstcounter allows to keep track of number
// of pixels written
// (scanning direction is down)

#define r2d_shift_pixel_down(dststream,srccache,srccounter,srcstream) {dststream =R2D_PIXEL_DOWN_OUT(dststream); \
               dststream|=((srccache & R2D_PIXEL_MASK) \
               << ((1<<R2D_MEMORY_WORD) - R2D_PIXEL_DEPTH)) ; \
               srccache=R2D_PIXEL_DOWN_OUT(srccache); \
               srccounter--; \
               if (srccounter==0) \
               { \
                 srccounter=(1<<R2D_PIXELS_PER_MEMORY_WORD); \
                 srccache=*++srcstream;  \
               } }


// Scanning direction is up
#define r2d_shift_pixel_up(dststream,srccache,srccounter,srcstream) {dststream =R2D_PIXEL_UP_OUT(dststream); \
               dststream |=(srccache >> ((1<<R2D_MEMORY_WORD) - R2D_PIXEL_DEPTH)) & R2D_PIXEL_MASK; \
               srccache=R2D_PIXEL_UP_OUT(srccache); \
               srccounter--; \
               if (srccounter==0) \
               { \
                 srccounter=(1<<R2D_PIXELS_PER_MEMORY_WORD); \
                 srccache=*--srcstream;  \
               } }

#endif

// Check overlap of src and dst rectangle and return the
// horizontal and vertical scanning direction required to do the
// blit rect
 
// A positive value means standard direction (increasing x and increasing y)
// When that routine is called, both rectangles are expressed in framebuffer
// coordinates and come from the same framebuffer.
// The routine is never called if dstGc and srcGc are not using the same framebuffer.
//
// INT32 used because of stack bug ?
void r2d_check_rectangle_overlap(INT16 src_x,INT16 src_y,INT16 dst_x,INT16 dst_y,
INT32 width,INT32 height,
INT32 *h_direction,INT32 *v_direction)
{
   INT16 h,v;
   INT16 rx,ry;
   rx=dst_x-src_x;
   ry=dst_y-src_y;

   h=1;
   v=1;

   if ((rx>-width) && (rx < width) && (ry>-height) && (ry<height))

⌨️ 快捷键说明

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