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

📄 hal_ink.c

📁 一个图形显示芯片s1d13505的应用程序
💻 C
字号:
/*
**===========================================================================
**	HAL_INK.C - Hardware ink layer support.
**---------------------------------------------------------------------------
** Copyright (c) 1998 Epson Research and Development, Inc.
** All Rights Reserved.
**===========================================================================
*/

#include "hal.h"
#include "assert.h"
#include "nonsefns.h"

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

int InkInitialized = FALSE;

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

int seInitInk(int seReserved1)
   {
   UINT width, height;
   int ratio;

   ASSERT(0 == seReserved1);


   InkInitialized = FALSE;
   CursorInitialized = FALSE;

   seGetScreenSize(seReserved1, &width, &height);

   if (InitInkCursorAddr(seReserved1, (DWORD) width * height / 4) != ERR_OK)
      return ERR_FAILED;

   InkInitialized = TRUE;

   /*
   ** Fill ink layer with transparent color.
   */
   seDrawInkRect(seReserved1, 0, 0, width-1, height-1, 0xaa, 1);

   seInkOn(seReserved1);

   if (CheckMaxPClkRatio(seReserved1, &ratio) == ERR_FAILED)
      {
      seInkOff(seReserved1);
      return ERR_FAILED;
      }

   return ERR_OK;
   }

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

int seInkOn(int seReserved1)
   {
   BYTE regInkCursorCtrl;

   ASSERT(0 == seReserved1);

   if (!InkInitialized)
      return ERR_FAILED;

   /*
   ** Turn on ink layer
   */
   regInkCursorCtrl = ReadRegister(seReserved1, REG_INK_CURSOR_CONTROL);
   regInkCursorCtrl &= ~0xc0;
   regInkCursorCtrl |= 0x80;
   WriteRegister(seReserved1, REG_INK_CURSOR_CONTROL, regInkCursorCtrl);

   return ERR_OK;
   }

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

int seInkOff(int seReserved1)
   {
   BYTE regInkCursorCtrl;

   ASSERT(0 == seReserved1);

   if (!InkInitialized)
      return ERR_FAILED;

   /*
   ** Turn off ink layer
   */
   regInkCursorCtrl = ReadRegister(seReserved1, REG_INK_CURSOR_CONTROL);
   regInkCursorCtrl &= ~0x80;
   WriteRegister(seReserved1, REG_INK_CURSOR_CONTROL, regInkCursorCtrl);

   return ERR_OK;
   }

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

int seGetInkStartAddr(int seReserved1, DWORD *addr)
   {
   ASSERT(0 == seReserved1);

   if (!InkInitialized)
      return ERR_FAILED;

   return seGetCursorStartAddr(seReserved1, addr);
   }   

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

int seSetInkColor(int seReserved1, int index, DWORD color)
   {
   if (!InkInitialized)
      return ERR_FAILED;

   return seSetCursorColor(seReserved1, index, color);
   }

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

int seSetInkPixel( int seReserved1, long x, long y, DWORD color )
   {
   DWORD StartLogicalAddr;
   UINT width;
   int err;

	ASSERT ( 0 == seReserved1 );

   if (!InkInitialized)
      return ERR_FAILED;

   if ((err = seGetInkStartAddr(seReserved1, &StartLogicalAddr)) != ERR_OK)
      return err;

   StartLogicalAddr += DispLogicalAddr[seReserved1];

   width = (ReadRegister( seReserved1, REG_HORZ_DISP_WIDTH ) + 1) * 8;


   /*
   ** Each line in the ink layer has the same number of pixels as the
   ** physical width of the display. Since the ink layer is in 2 bpp
   ** mode, there are width/4 bytes per line.
   */
	Pixel2bpp( StartLogicalAddr, width/4, x, y, color);

	return ERR_OK;
   }

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

int seDrawInkLine(int seReserved1, long x1, long y1, long x2, long y2, DWORD color)
   {
   DWORD StartLogicalAddr;
   UINT width;
   int err;

	ASSERT ( 0 == seReserved1 );

   if (!InkInitialized)
      return ERR_FAILED;

   if ((err = seGetInkStartAddr(seReserved1, &StartLogicalAddr)) != ERR_OK)
      return err;

   StartLogicalAddr += DispLogicalAddr[seReserved1];

   width = (ReadRegister( seReserved1, REG_HORZ_DISP_WIDTH ) + 1) * 8;


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


   /*
   ** Each line in the ink layer has the same number of pixels as the
   ** physical width of the display. Since the ink layer is in 2 bpp
   ** mode, there are width/4 bytes per line.
   */
   Line(StartLogicalAddr, width/4, x1, y1, x2, y2, color, Pixel2bpp);

	return ERR_OK;
   }

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

int seDrawInkRect( int seReserved1, long x1, long y1, long x2, long y2, DWORD color, BOOL SolidFill )
   {
   UINT BytesPerScanline;
   DWORD StartLogicalAddr;
   void (*linefn)(DWORD,int,long,long,long,long,DWORD);
   long y;
   UINT width, height;
   int err;

	ASSERT( 0 == seReserved1 );

	DPF( In seDrawInkRect() );

   if (!InkInitialized)
      return ERR_FAILED;

   if ((err = seGetInkStartAddr(seReserved1, &StartLogicalAddr)) != ERR_OK)
      return err;

   StartLogicalAddr += DispLogicalAddr[seReserved1];


   if (y1 > y2)
      {
      y = y2;
      y2 = y1;
      y1 = y;
      }


   linefn = Line2bpp;

/*
** Calculate Bytes Per Scanline for 2 bpp.
** Note that seGetBytesPerScanline() can't be used directly since it uses
** the current bpp mode, not 2 bpp.
*/
   seGetScreenSize(seReserved1, &width, &height);
   BytesPerScanline = (UINT) (width / 4L);


   /*
   ** Each line in the ink layer has the same number of pixels as the
   ** physical width of the display. Since the ink layer is in 2 bpp
   ** mode, there are width/4 bytes per line.
   */

	if (SolidFill)
      {
	   for (y = y1; y <= y2; y++)
		   (*linefn)(StartLogicalAddr, BytesPerScanline, x1, y, x2, y, color);
	   }
	else
      {
	   (*linefn)(StartLogicalAddr, BytesPerScanline, x1, y1, x2, y1, color);
	   (*linefn)(StartLogicalAddr, BytesPerScanline, x1, y2, x2, y2, color);
	   (*linefn)(StartLogicalAddr, BytesPerScanline, x1, y1, x1, y2, color);
	   (*linefn)(StartLogicalAddr, BytesPerScanline, x2, y1, x2, y2, color);
	   }

	return ERR_OK;
   }

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

int seDrawInkEllipse(int seReserved1, long xc, long yc, long xr, long yr, DWORD color, BOOL SolidFill)
   {
   DWORD StartLogicalAddr;
   UINT width;
   int err;

	ASSERT( 0 == seReserved1 );
	DPF( In seDrawInkEllipse() );

   if (!InkInitialized)
      return ERR_FAILED;

   if ((err = seGetCursorStartAddr(seReserved1, &StartLogicalAddr)) != ERR_OK)
      return err;

   width = (ReadRegister( seReserved1, REG_HORZ_DISP_WIDTH ) + 1) * 8;

   /*
   ** Solid fill not currently implemented
   */
   SolidFill = FALSE;

   /*
   ** Each line in the ink layer has the same number of pixels as the
   ** physical width of the display. Since the ink layer is in 2 bpp
   ** mode, there are width/4 bytes per line.
   */
   Ellipse(StartLogicalAddr, width/4, xc, yc, xr, yr, color, Pixel2bpp);

   return ERR_OK;
   }

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

int seDrawInkCircle( int seReserved1, long xCenter, long yCenter, long radius, DWORD color, BOOL SolidFill )
   {
	ASSERT( 0 == seReserved1 );
	DPF( In seDrawCircle() );

   if (!InkInitialized)
      return ERR_FAILED;

   return seDrawInkEllipse(seReserved1, xCenter, yCenter, radius, radius, color, SolidFill);
   }

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

⌨️ 快捷键说明

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