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

📄 hal_draw.c

📁 epson 13506 driver code
💻 C
📖 第 1 页 / 共 3 页
字号:
   bpt = StartOffset;
   _WRITEXB(bpt, (BYTE) color);
#else
   bpt = (BYTE*) StartOffset;
   *bpt = (BYTE) color;
#endif
   }

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

/*
** For horizontal/vertical lines only
*/
void _Line8bpp(DWORD StartLinearAddress, int BytesPerScanline, long x1, long y1, long x2, long y2, DWORD color)
   {
   long y;

   long StartOffset;
   long Offset = (long)y1 * BytesPerScanline + (long)(x1);

#ifdef INTEL_DOS
   DWORD bpt;
#else
   BYTE *bpt;
   long x;
#endif

   StartOffset = StartLinearAddress + Offset;
   color &= 0xff;

#ifdef INTEL_DOS
   bpt = StartOffset;
#else
   bpt = (BYTE*) StartOffset;
#endif

   if (y1 == y2)  /* horiz. line */
      {
      ++x2;  /* include the last point in the line */

#ifdef INTEL_DOS
      _asmWriteBytes(bpt, (unsigned) color, (DWORD) (x2 - x1));
#else
      for (x = x1; x < x2; x++)
         *bpt++ = (BYTE)color;
#endif

      bpt += (x2 - x1 + 1);

      return;
      }

   if (x1 == x2)  /* vert. line */
      {
      for (y = y1; y < y2; y++, bpt += BytesPerScanline)
         {
#ifdef INTEL_DOS
         _WRITEXB(bpt, (BYTE) color);
#else
         *bpt = (BYTE) color;
#endif
         }

      return;
      }
   }

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

void _Pixel16bpp(DWORD StartLinearAddress, int BytesPerScanline, long x, long y, DWORD color)
   {
   long StartOffset = (long)y * BytesPerScanline + (long)(x*2);

#ifdef INTEL_DOS
   DWORD wpt;
#else
   WORD *wpt;
#endif


   StartOffset += StartLinearAddress;

#ifdef INTEL_DOS
   wpt = StartOffset;
#else
   wpt = (WORD*) StartOffset;

   if (_EndianReverseBytes)
      color =  ((color & 0xFF) << 8) | ((color >> 8) & 0xFF);
#endif


#ifdef INTEL_DOS
   _WRITEXW(wpt, (WORD) color);
#else
   *wpt = (WORD) color;
#endif
   }

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

/*
** For horizontal/vertical lines only
*/
void _Line16bpp(DWORD StartLinearAddress, int BytesPerScanline,long x1,long y1,long x2,long y2,DWORD color)
   {
   long StartOffset = (long)y1 * BytesPerScanline + 
                       (long)(x1*2);

#ifdef INTEL_DOS
   long y;
   DWORD wpt;
#else
   WORD *wpt;
   long x, y;
   int WordsPerScanline;
#endif


   StartOffset += StartLinearAddress;

#ifdef INTEL_DOS
   wpt = StartOffset;
#else
   wpt = (WORD *) StartOffset;

   if (_EndianReverseBytes)
      color =  ((color & 0xFF) << 8) | ((color >> 8) & 0xFF);
#endif

   if (y1 == y2)  /* horiz. line */
      {
      ++x2;  /* include the last point in the line */

#ifdef INTEL_DOS
      _asmWriteWords(wpt, (unsigned) color, (WORD) (x2 - x1));
#else
      for (x = x1; x < x2; x++)
         *wpt++ = (WORD)color;
#endif
      return;
      }


#ifdef INTEL_DOS
   if (x1 == x2)  /* vert. line */
      {
      for (y = y1; y < y2; y++, wpt += BytesPerScanline)
         {
         _WRITEXW(wpt, (WORD) color);
         }
      return;
      }

#else

   WordsPerScanline = BytesPerScanline / 2;

   if (x1 == x2)  /* vert. line */
      {
      for (y = y1; y < y2; y++, wpt += WordsPerScanline)
         {
         *wpt = (WORD) color;
         }
      return;
      }
#endif
   }

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

void seSetLcdPixel(long x, long y, DWORD color)
   {
	unsigned BytesPerScanline;
   unsigned BitsPerPixel;
   DWORD LinearAddress;

	BytesPerScanline = seGetLcdBytesPerScanline();


	/*
	** Switch based on the pixel depth (BPP)
	*/
   BitsPerPixel = seGetLcdBitsPerPixel();

   if (BitsPerPixel == 15)
      BitsPerPixel = 16;

   // Adjust for ROTATE90 and ROTATE270
   if (seReadRegByte(REG_DISPLAY_MODE) & 0x40)
      LinearAddress = _DispLinearAddress + (_LcdSurface.OffsetAddress / 1024);
   else
   	LinearAddress = _LcdSurface.LinearAddress;

#ifdef INTEL_DOS
   if (LinearAddress == -1)
      return;
#else
   if (LinearAddress == 0)
      return;
#endif


   /*
   ** If horizontal or vertical lines, use the following optimized
   ** functions.
   */
	switch (BitsPerPixel)
      {
	   case 4:
		   _Pixel4bpp(LinearAddress, BytesPerScanline, x, y, color);
		   break;

	   case 8:
		   _Pixel8bpp(LinearAddress, BytesPerScanline, x, y, color);
		   break;

	   case 15:
	   case 16:
		   _Pixel16bpp(LinearAddress, BytesPerScanline, x, y, color);
		   break;
      }
   }

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

void seSetCrtPixel(long x, long y, DWORD color)
   {
	unsigned BytesPerScanline;
   unsigned BitsPerPixel;
   DWORD LinearAddress;
   unsigned regDisplayMode;


   // If in rotate90 mode, get into landscape mode
   regDisplayMode = seReadRegByte(REG_DISPLAY_MODE);
   seWriteRegByte(REG_DISPLAY_MODE, regDisplayMode & ~0x40);


	BytesPerScanline = seGetCrtBytesPerScanline();


	/*
	** Switch based on the pixel depth (BPP)
	*/
   BitsPerPixel = seGetCrtBitsPerPixel();

   if (BitsPerPixel == 15)
      BitsPerPixel = 16;

   // Adjust for ROTATE90 and ROTATE270
 	LinearAddress = _CrtTvSurface.LinearAddress;


#ifdef INTEL_DOS
   if (LinearAddress == -1)
      {
      // Restore previous mode (rotate90 or landscape)
      seWriteRegByte(REG_DISPLAY_MODE, regDisplayMode);
      return;
      }
#else
   if (LinearAddress == 0)
      {
      // Restore previous mode (rotate90 or landscape)
      seWriteRegByte(REG_DISPLAY_MODE, regDisplayMode);
      return;
      }
#endif


   /*
   ** If horizontal or vertical lines, use the following optimized
   ** functions.
   */
	switch (BitsPerPixel)
      {
	   case 4:
		   _Pixel4bpp(LinearAddress, BytesPerScanline, x, y, color);
		   break;

	   case 8:
		   _Pixel8bpp(LinearAddress, BytesPerScanline, x, y, color);
		   break;

	   case 15:
	   case 16:
		   _Pixel16bpp(LinearAddress, BytesPerScanline, x, y, color);
		   break;
      }

   // Restore previous mode (rotate90 or landscape)
   seWriteRegByte(REG_DISPLAY_MODE, regDisplayMode);
   }

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

void seSetTvPixel(long x, long y, DWORD color)
   {
   seSetCrtPixel(x, y, color);
   }

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

void seSetPixel(long x, long y, DWORD color)
   {
	unsigned BytesPerScanline;
   unsigned BitsPerPixel;
   unsigned regDisplayMode;
   DWORD LinearAddress;

   // If in rotate90 mode for CRT/TV, get into landscape mode
   regDisplayMode = seReadRegByte(REG_DISPLAY_MODE);

   if (_ActiveImageSurface->DisplayMode & (CRT | TV))
      seWriteRegByte(REG_DISPLAY_MODE, regDisplayMode & ~0x40);


	BytesPerScanline = seGetBytesPerScanline();


	/*
	** Switch based on the pixel depth (BPP)
	*/
   BitsPerPixel = seGetBitsPerPixel();

   if (BitsPerPixel == 15)
      BitsPerPixel = 16;

   // Adjust for ROTATE90 and ROTATE270
   if (seReadRegByte(REG_DISPLAY_MODE) & 0x40)
      LinearAddress = _DispLinearAddress + (_ActiveImageSurface->OffsetAddress / 1024);
   else
   	LinearAddress = _ActiveImageSurface->LinearAddress;


#ifdef INTEL_DOS
   if (LinearAddress == -1)
      {
      // Restore previous mode (rotate90 or landscape)
      seWriteRegByte(REG_DISPLAY_MODE, regDisplayMode);
      return;
      }
#else
   if (LinearAddress == 0)
      {
      // Restore previous mode (rotate90 or landscape)
      seWriteRegByte(REG_DISPLAY_MODE, regDisplayMode);
      return;
      }
#endif


   /*
   ** If horizontal or vertical lines, use the following optimized
   ** functions.
   */
	switch (BitsPerPixel)
      {
	   case 4:
		   _Pixel4bpp(LinearAddress, BytesPerScanline, x, y, color);
		   break;

	   case 8:
		   _Pixel8bpp(LinearAddress, BytesPerScanline, x, y, color);
		   break;

	   case 15:
	   case 16:
		   _Pixel16bpp(LinearAddress, BytesPerScanline, x, y, color);
		   break;
      }

   // Restore previous mode (rotate90 or landscape)
   seWriteRegByte(REG_DISPLAY_MODE, regDisplayMode);
   }

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

void seDrawLcdLine(long x1, long y1, long x2, long y2, DWORD color)
   {
	unsigned BytesPerScanline;
   unsigned BitsPerPixel;
   DWORD LinearAddress;

	BytesPerScanline = seGetBytesPerScanline();


   if (x1 > x2)
      {
      _Swap(&x1, &x2);
      _Swap(&y1, &y2);
      }


	/*
	** Switch based on the pixel depth (BPP)
	*/
   BitsPerPixel = seGetBitsPerPixel();

   if (BitsPerPixel == 15)
      BitsPerPixel = 16;

   // Adjust for ROTATE90 and ROTATE270
   if (seReadRegByte(REG_DISPLAY_MODE) & 0x40)
      LinearAddress = _DispLinearAddress + (_LcdSurface.OffsetAddress / 1024);
   else
   	LinearAddress = _LcdSurface.LinearAddress;

#ifdef INTEL_DOS
   if (LinearAddress == -1)
      return;
#else
   if (LinearAddress == 0)
      return;
#endif


/*
** Diagonal lines
*/
	switch (BitsPerPixel)
      {
	   case 4:
   	   _Line(LinearAddress, BytesPerScanline, x1, y1, x2, y2, color, _Pixel4bpp);
		   break;

	   case 8:
		   _Line(LinearAddress, BytesPerScanline, x1, y1, x2, y2, color, _Pixel8bpp);
		   break;

	   case 15:
	   case 16:
		   _Line(LinearAddress, BytesPerScanline, x1, y1, x2, y2, color, _Pixel16bpp);
		   break;
      }
   }

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

void seDrawCrtLine(long x1, long y1, long x2, long y2, DWORD color)
   {
	unsigned BytesPerScanline;
   unsigned BitsPerPixel;
   DWORD LinearAddress;
   unsigned regDisplayMode;


   // If in rotate90 mode, get into landscape mode
   regDisplayMode = seReadRegByte(REG_DISPLAY_MODE);
   seWriteRegByte(REG_DISPLAY_MODE, regDisplayMode & ~0x40);


	BytesPerScanline = seGetBytesPerScanline();


   if (x1 > x2)
      {
      _Swap(&x1, &x2);
      _Swap(&y1, &y2);
      }


	/*
	** Switch based on the pixel depth (BPP)
	*/
   BitsPerPixel = seGetBitsPerPixel();

   if (BitsPerPixel == 15)
      BitsPerPixel = 16;

   // Adjust for ROTATE90 and ROTATE270
  	LinearAddress = _CrtTvSurface.LinearAddress;

#ifdef INTEL_DOS
   if (LinearAddress == -1)
      {
      // Restore previous mode (rotate90 or landscape)
      seWriteRegByte(REG_DISPLAY_MODE, regDisplayMode);
      return;
      }
#else
   if (LinearAddress == 0)
      {
      // Restore previous mode (rotate90 or landscape)
      seWriteRegByte(REG_DISPLAY_MODE, regDisplayMode);
      return;
      }
#endif


/*
** Diagonal lines
*/
	switch (BitsPerPixel)
      {
	   case 4:
   	   _Line(LinearAddress, BytesPerScanline, x1, y1, x2, y2, color, _Pixel4bpp);
		   break;

	   case 8:
		   _Line(LinearAddress, BytesPerScanline, x1, y1, x2, y2, color, _Pixel8bpp);
		   break;

	   case 15:
	   case 16:
		   _Line(LinearAddress, BytesPerScanline, x1, y1, x2, y2, color, _Pixel16bpp);
		   break;
      }

   // Restore previous mode (rotate90 or landscape)
   seWriteRegByte(REG_DISPLAY_MODE, regDisplayMode);
   }

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

void seDrawTvLine(long x1, long y1, long x2, long y2, DWORD color)
   {
   seDrawCrtLine(x1, y1, x2, y2, color);
   }

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

void seDrawLine(long x1, long y1, long x2, long y2, DWORD color)
   {
	unsigned BytesPerScanline;
   unsigned BitsPerPixel;
   unsigned regDisplayMode;
   DWORD LinearAddress;

   // If in rotate90 mode for CRT/TV, get into landscape mode
   regDisplayMode = seReadRegByte(REG_DISPLAY_MODE);

   if (_ActiveImageSurface->DisplayMode & (CRT | TV))
      seWriteRegByte(REG_DISPLAY_MODE, regDisplayMode & ~0x40);

⌨️ 快捷键说明

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