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

📄 show.c

📁 一个图形显示芯片s1d13505的应用程序
💻 C
📖 第 1 页 / 共 4 页
字号:
   seDisplayFifo(gDevID, FALSE);

   /*
   ** Cannot show 1, 2, or 4 bpp if in portrait mode.
   */
   if (PortraitMode && (BitsPerPixel < 8))
      {
      printf("UNSUPPORTED MODE: Cannot show %d BPP in portrait mode.\n", BitsPerPixel);
      return;
      }

   if (gnInitRegisters)
      {
      if (seSetBitsPerPixel(gDevID, BitsPerPixel) == ERR_FAILED)
         {
         printf(szModeFailed, BitsPerPixel);
         return;
         }

      /*
      ** Use 1024 virtual width if 800x600x15 or 16 bpp,
      ** or if in portrait mode.
      */
      if (PortraitMode ||
            ((nWidth >= 800) && (nHeight >= 600) &&
             ((BitsPerPixel == 15) || (BitsPerPixel == 16)) ) )
         seVirtInit(gDevID, 1024, &yVirt);
      }


   if (gnUpdateDisplayMemory)
      UpdateScreen( BitsPerPixel );

   seDisplayFifo(gDevID, TRUE);

   if (str != NULL)
      printf("%s", str);

#ifdef LCEVBSH3
   if (gnContinualScrnRead)
      {
      dwPtr = (DWORD *) HalInfo.dwDispMemAddr;
      printf("Continual DWORD read from %08lXh...\n", HalInfo.dwDispMemAddr);
      }

   while (gnContinualScrnRead)
      {
      dwVal = *dwPtr;
      dwVal = *dwPtr;
      dwVal = *dwPtr;
      dwVal = *dwPtr;
      dwVal = *dwPtr;
      dwVal = *dwPtr;
      dwVal = *dwPtr;
      dwVal = *dwPtr;
      dwVal = *dwPtr;
      dwVal = *dwPtr;
      }
#else
   while (gnContinualScrnRead)
      {
      for (addr = 0; addr < lSize; addr += 4)
         seReadDisplayDword(gDevID, addr, &dwVal);

#ifdef INTEL
      if (kbhit())
         break;
#endif
      }
#endif


   if (gnContinualScrnWrite)
      {
      seGetLastUsableByte(gDevID, &addr);
      addr &= ~0x01;  // word align
      printf("Continually writing 0x1234 to %06lX...\n", addr);
      }

   while (gnContinualScrnWrite)
      {
      seWriteDisplayWords(gDevID, addr, 0x1234, 1);

#ifdef INTEL
      if (kbhit())
         break;
#endif
      }
   }

/*-------------------------------------------------------------------------*/

void UpdateScreen( UINT BitsPerPixel )
{
   int RepeatC;
   int x, y, i, j;
   long x_step, y_step;
   int Cx1, Cx2, Cy1, Cy2;
   UINT Color, White;

#define BPP_FACTOR   ( 1000000L )
#define BPP_ROUNDUP  ( BPP_FACTOR/2 )

   Color = 0x00;
   White = 0xFFFF;

   seGetScreenSize( gDevID, (UINT *) &x, (UINT *) &y );
   printf( "%d * %d * %d Bpp\n", x, y, BitsPerPixel );

   if ( gnUseVertical )
   {
      RepeatC = 8 / BitsPerPixel + 1;

      for (i = 0; i < x; i++)
      {
         seDrawLine( gDevID, i, 1, i, y-1, Color );

         if (i % RepeatC == 0 )
            Color = GetNextColor( Color, BitsPerPixel );
      }
   }
   else
   {
      switch (BitsPerPixel)
      {
         /*
         ** Subtract 2 from x and y so that I don't overwrite
         ** the borders. Multiply by BPP_FACTOR for more digits
         ** of precision. Add BPP_ROUNDUP to round up from the
         ** given number of digits of precision.
         */
         case 1:
            // Show a 4x4 screen of white/black rectangles
            x_step = (x * BPP_FACTOR) /4;
            y_step = (y * BPP_FACTOR) /4;
            
            for ( i = 0; i < 4; i++ )
            {
               Cy1 = (int) ((i * y_step) / BPP_FACTOR);
               Cy2 = (int) (((i + 1) * y_step) / BPP_FACTOR) - 1;

               for ( j = 0; j < 4; j++ )
               {
                  Cx1 = (int) ((j * x_step) / BPP_FACTOR);
                  Cx2 = (int) (((j + 1) * x_step) / BPP_FACTOR) - 1;

                  seDrawRect( gDevID, Cx1, Cy1, Cx2, Cy2, Color, 1 );
                  Color = GetNextColor( Color, BitsPerPixel );
               }
               // alternate colors vertically
               Color = GetNextColor( Color, BitsPerPixel );
            }


#ifdef DONT_USE
            // Show a 4x4 screen of white/black rectangles
            x_step = (x * BPP_FACTOR) /2;
            y_step = (y * BPP_FACTOR);
            i = 0;

            for (j = 0; j < 2; j++)
            {
               Cx1 = (int) (( j * x_step) / BPP_FACTOR);
               Cx2 = (int) (((j + 1) * x_step) / BPP_FACTOR) - 1;
               Cy1 = (int) (( i * y_step) / BPP_FACTOR);
               Cy2 = (int) (((i + 1) * y_step) / BPP_FACTOR) - 1;

               seDrawRect( gDevID, Cx1, Cy1, Cx2, Cy2, Color, 1 );
               Color = GetNextColor( Color, BitsPerPixel );
            }
#endif            
            break;

         case 2:
            x_step = (x * BPP_FACTOR) /2;
            y_step = (y * BPP_FACTOR) /2;
            
            for (i = 0; i < 2; i++)
            {
               Cy1 = (int) ((i * y_step) / BPP_FACTOR);
               Cy2 = (int) (((i + 1) * y_step) / BPP_FACTOR) - 1;

               for ( j = 0; j < 2; j++ )
               {
                  Cx1 = (int) ((j * x_step) / BPP_FACTOR);
                  Cx2 = (int) (((j + 1) * x_step) / BPP_FACTOR) - 1;

                  seDrawRect( gDevID, Cx1, Cy1, Cx2, Cy2, Color, 1 );
                  Color = GetNextColor( Color, BitsPerPixel );
               }
            }
            break;

         case 4:
            x_step = (x * BPP_FACTOR) /4;
            y_step = (y * BPP_FACTOR) /4;

            for ( i = 0; i < 4; i++ )
            {
               Cy1 = (int) ((i * y_step) / BPP_FACTOR);
               Cy2 = (int) (((i + 1) * y_step) / BPP_FACTOR) - 1;

               for ( j = 0; j < 4; j++ )
               {
                  Cx1 = (int) ((j * x_step) / BPP_FACTOR);
                  Cx2 = (int) (((j + 1) * x_step) / BPP_FACTOR) - 1;

                  seDrawRect( gDevID, Cx1, Cy1, Cx2, Cy2, Color, 1 );
                  Color = GetNextColor( Color, BitsPerPixel );
               }
            }
            break;

         case 8:
         case 15:
         case 16:
            DrawHslScreen();
            break;
      }
   }

   /*
   ** Draw border if resolution is large enough
   */
   if ((BitsPerPixel < 8) && ValidResolutionForBorder(x, y))
      {
      seDrawLine( gDevID, 0,   0, x,   0, White );
      seDrawLine( gDevID, 0, y-1, x, y-1, White );
      seDrawLine( gDevID, 0,   0, 0,   y, White );
      seDrawLine( gDevID, x-1, 0, x-1, y, White );
      }
   
   /*
   ** Draw diagonal lines if resolution is large enough
   */
   if ((BitsPerPixel < 8) && (BitsPerPixel > 1) && ValidResolutionForDiagonalLines(x, y))
      {
      seDrawLine( gDevID, 0, 0, x-1, y-1, White );
      seDrawLine( gDevID, x, 0,   0, y-1, White );
      }

   if (gnShowGrid)
      {
      /*
      ** Draw vertical lines
      */
      for (Cx1 = 0; Cx1 < x; Cx1 += 20)
         seDrawLine(gDevID, Cx1, 0, Cx1, y-1, White);

      /*
      ** Draw horizontal lines
      */
      for (Cy1 = 0; Cy1 < y; Cy1 += 20)
         seDrawLine(gDevID, 0, Cy1, x-1, Cy1, White);
      }
}

/*-------------------------------------------------------------------------*/

UINT GetNextColor( UINT Color, UINT BPP )
{
   UINT NewColor;
   UINT Red,Green,Blue;

   switch (BPP)
   {
      case 1:
         return ((++Color) & 1);
         break;

      case 2:
         return ((++Color) & 3);
         break;

      case 4:
         return ((++Color) & 0x0F);
         break;

      case 8:
         return ((++Color) & 0xFF);
         break;

      case 15:
         if (!Color)
            NewColor = Color + 0x20;
         else
            {
            Red = Color & 0x7c00;
            Green = Color & 0x03e0;
            Blue = Color & 0x1f;
            if (Red)
                  {
                  Red = (Red + 0x0400) & 0x7c00;
                  if (!Red)
                     Green += 0x20;
                  }
            else if (Green)
                  {
                  Green = (Green + 0x20) & 0x3e0;
                  if (!Green)
                     Blue += 1;
                  }
            else if (Blue)
                  {
                  Blue = (Blue + 1) & 0x1f;
                  if (!Blue)
                     Red +=0x0400;
                  }
            NewColor = Red | Green | Blue;
            }
         return NewColor;

      case 16:
         if (!Color)
            NewColor = Color + 0x20;
         else
            {
            Red = Color & 0xf800;
            Green = Color & 0x07e0;
            Blue = Color & 0x1f;
            if (Red)
                  {
                  Red = (Red + 0x0800) & 0xf800;
                  if (!Red)
                     Green += 0x20;
                  }
            else if (Green)
                  {
                  Green = (Green + 0x20) & 0x07e0;
                  if (!Green)
                     Blue += 1;
                  }
               else if (Blue)
                  {
                  Blue = (Blue + 1) & 0x1f;
                  if (!Blue)
                     Red +=0x0800;
                  }
            NewColor = Red | Green | Blue;
            }
         return NewColor;
   }
   return 0;
}

/*-------------------------------------------------------------------------*/
// Function to display  color scale bars for red, blue, gray, green colors.
// Should only be used for the 16/15 bpp.

int seDrawColorScale( int seReserved1, long x2, long y2, long barcolorsteps )
{
UINT BytesPerScanline;
UINT BitsPerPixel;
long x;
long y;
long colorstep=40;
long delta=1;
void (*linefn)(DWORD,int,long,long,long,long,DWORD);
DWORD color;

  ASSERT( 0 == seReserved1 );

  DPF( In seDrawRect() );

  seGetBytesPerScanline( seReserved1, &BytesPerScanline );
  seGetBitsPerPixel(seReserved1, &BitsPerPixel);

//  printf ( "BytesPerScanline %d\n", BytesPerScanline);
//  printf ( "BitsPerPixels %d\n", BitsPerPixel);
// calculate a colorstep which is a number of pixels for the same depth color
  if (barcolorsteps != 0) 
  {
    colorstep = x2/barcolorsteps;
//  calculate delta for color depth increase
#define MAXCOLORSTEPS 32
    delta = MAXCOLORSTEPS/barcolorsteps;
  }
  linefn = Line16bpp;

  for (y = 1; y <= y2; y++)
  {
    color = 1; // color depth 
    for (x = 1; x< x2; x=x+colorstep)
    {
      color += delta; //color depth increment //
//      safety		
      color = (color > 0x1f) ? 0x1f : color;
      color = (color < 1) ? 1 : color;
      switch (BitsPerPixel)
	  {
	    case 16:
        (*linefn) (DispLogicalAddr[seReserved1], BytesPerScanline, x, y, x+colorstep-1, y, color << 11); // red
        (*linefn) (DispLogicalAddr[seReserved1], BytesPerScanline, x, y+y2, x+colorstep-1, y+y2, color ); //blue
        (*linefn) (DispLogicalAddr[seReserved1], BytesPerScanline, x, y+2*y2, x+colorstep-1, y+2*y2, 
                                                    (color << 11) | (color << 6) | color );             //gray
            
        (*linefn) (DispLogicalAddr[seReserved1], BytesPerScanline, x, y+3*y2, x+colorstep-1, y+3*y2, color << 6);//green
        break;

		case 15:
	  	(*linefn) (DispLogicalAddr[seReserved1], BytesPerScanline, x, y, x+colorstep-1, y, color << 10); // red
		(*linefn) (DispLogicalAddr[seReserved1], BytesPerScanline, x, y+y2, x+colorstep-1, y+y2, color ); //blue
	    (*linefn) (DispLogicalAddr[seReserved1], BytesPerScanline, x, y+2*y2, x+colorstep-1, y+2*y2, 
                                                    (color << 10) | (color << 5) | color );
            
		(*linefn) (DispLogicalAddr[seReserved1], BytesPerScanline, x, y+3*y2, x+colorstep-1, y+3*y2, color << 5);
		break;
		default:
		printf (" should never be here\n");
		break;
     }
    }
  }

  return ERR_OK;
}

/*-------------------------------------------------------------------------*/

⌨️ 快捷键说明

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