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

📄 util.c

📁 epson公司的一个关于s1d13706的低层驱动程序
💻 C
📖 第 1 页 / 共 2 页
字号:

int CalcDisplaySurfaceCombination(void)
{
   if ((SurfaceDisplayMode[0] & MAIN_WIN) && (SurfaceDisplayMode[1] & SUB_WIN))
      return SURFACE_MAIN_WIN0_SUB_WIN1;
   else if ((SurfaceDisplayMode[0] & MAIN_WIN) && (SurfaceDisplayMode[0] & SUB_WIN))
      return SURFACE_MAIN_AND_SUB_WIN0;
   else
      return SURFACE_MAIN_WIN0;
}

/*-----------------------------------------------------------------------*/
// returns -1 if no active surface
// otherwise returns number of active surface

int GetActiveSurfaceNumber(void)
{
   int CurrentDisplayMode;

   CurrentDisplayMode = seGetSurfaceDisplayMode();

   switch (CalcDisplaySurfaceCombination())
      {
      case SURFACE_NONE:
         return -1;

      case SURFACE_MAIN_WIN0:
         if (CurrentDisplayMode & MAIN_WIN)
            return 0;
         break;

      case SURFACE_MAIN_WIN0_SUB_WIN1:
         if (CurrentDisplayMode & MAIN_WIN)
            return 0;
         else if (CurrentDisplayMode & SUB_WIN)
            return 1;
         break;

      case SURFACE_MAIN_AND_SUB_WIN0:
         if (CurrentDisplayMode & (MAIN_WIN | SUB_WIN))
            return 0;
         break;
      }

   return -1;
}

/*-----------------------------------------------------------------------*/
// returns surface number given the desired display mode

int GetSurfaceNumber(unsigned DisplayMode)
{
   switch (CalcDisplaySurfaceCombination())
      {
      case SURFACE_NONE:
         break;

      case SURFACE_MAIN_WIN0:
         if (DisplayMode & MAIN_WIN)
            return 0;
         break;

      case SURFACE_MAIN_WIN0_SUB_WIN1:
         if (DisplayMode & MAIN_WIN)
            return 0;
         else if (DisplayMode & SUB_WIN)
            return 1;
         break;

      case SURFACE_MAIN_AND_SUB_WIN0:
         if (DisplayMode & (MAIN_WIN | SUB_WIN))
            return 0;
         break;
      }

   return -1;
}

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

void SetActiveSurfaceNumber(int surface)
{
   switch (CalcDisplaySurfaceCombination())
      {
      case SURFACE_NONE:
         break;

      case SURFACE_MAIN_WIN0:
         if (surface == 0)
            seSetMainWinAsActiveSurface();
         break;

      case SURFACE_MAIN_WIN0_SUB_WIN1:
         if (surface == 0)
            seSetMainWinAsActiveSurface();
         else if (surface == 1)
            seSetSubWinAsActiveSurface();
         break;

      case SURFACE_MAIN_AND_SUB_WIN0:
         if (surface == 0)
            seSetMainWinAsActiveSurface();
         break;
      }
}

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

int VirtInit(int surface, DWORD width, DWORD height)
{
   switch (CalcDisplaySurfaceCombination())
      {
      case SURFACE_NONE:
         break;

      case SURFACE_MAIN_WIN0:
         if (surface == 0)
            return seMainWinVirtInit(width, height);
         break;

      case SURFACE_MAIN_WIN0_SUB_WIN1:
         if (surface == 0)
            return seMainWinVirtInit(width, height);
         else if (surface == 1)
            return seSubWinVirtInit(width, height);
         break;

      case SURFACE_MAIN_AND_SUB_WIN0:
         if ((surface == 0) || (surface == 1))
            return seMainAndSubWinVirtInit(width, height);
         break;
      }

   return ERR_FAILED;
}

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

void ExitBadConfiguration(void)
{
   printf("\nERROR: Program not configured for LCD.");
   printf("\n       Run 13706CFG and configure for LCD.\n");

   exit(1);
}

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

void DisplayErrorNotEnoughMemory(unsigned BitsPerPixel)
{
   unsigned count = 0;
   unsigned DisplayMode = 0;
   char szErr[50];
   DisplayMode = GetSurfaceDisplayMode(GetActiveSurfaceNumber());
   szErr[0] = 0;
   count = 0;

   if (DisplayMode & MAIN_WIN)
      {
      strcat(szErr, "MAIN WINDOW");
      ++count;
      }

   if (DisplayMode & SUB_WIN)
      {
      if (count > 0)
         strcat(szErr, " & ");

      strcat(szErr, "SUB-WINDOW");
      ++count;
      }

   if (count == 0)
      strcpy(szErr, "NONE");

   printf(szModeFailed, szErr, BitsPerPixel);
}

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

static void FailBpp(int bpp)
{
   printf("\nERROR: Could not change to %d bits-per-pixel.\n", bpp);
   printf(  "       Check if there is sufficient memory for image(s).\n");
   exit(1);
}

/*-------------------------------------------------------------------------*/
//
// bpp0=bits-per-pixel for first surface
// bpp1=bits-per-pixel for second surface
//
void SetBitsPerPixel(void)
   {
   DWORD addr;
   WORD bppMainWin, bppSubWin;
   DWORD ImgWidth, ImgHeight;
   unsigned offset = 0;
   DWORD size;
   DWORD x1, y1, x2, y2;
   unsigned width, height;
   unsigned side;
   unsigned SubWinWidth, SubWinHeight;

   SubWinWidth = 0;
   SubWinHeight = 0;

   seSubWinDisplayEnable(FALSE);

   GetBMPInfo(filename[0], &ImgWidth, &ImgHeight, &bppMainWin, MainWinLut);

   if (bppMainWin == 24)
      bppMainWin = 16;

   //
   // First check if valid clocks for given mode
   //
   if (!CheckSwivelViewClocks(bppMainWin, seGetSwivelViewMode()))
      exit(1);

   if (seSetMode(bppMainWin) != ERR_OK)
      FailBpp(bppMainWin);

   if (seSetSwivelViewMode(LcdOrientation) != ERR_OK)
      printf("WARNING: Could not change SwivelView mode.\n");


   //
   // Allocate space if separate sub-window image
   //
   if (SurfaceDisplayMode[1] & SUB_WIN)
      {
      if (BmpCount == 2)
         {
         GetBMPInfo(filename[1], &ImgWidth, &ImgHeight, &bppSubWin, SubWinLut);

         if (bppSubWin == 24)
            bppSubWin = 16;

         if (bppMainWin != bppSubWin)
            {
            printf("ERROR: bmpfile1 and bmpfile2 must have the same bits-per-pixel mode.\n");

            printf("       %s has %d bpp, and %s has %d bpp.\n",
                    filename[0], bppMainWin, filename[1], bppSubWin);
            exit(1);
            }
         else if (memcmp(MainWinLut, SubWinLut, 1 << bppMainWin))
            {
            printf("WARNING: %s and %s use different Look-Up Tables (LUT).\n", filename[0], filename[1]);
            printf("         The LUT from %s will be used for both files.\n", filename[1]);
            }
         }


      GetSubWinBmpSize();

      //
      // The following calculations assume LANDSCAPE mode
      //

      //
      // Update position registers
      //
      // Put sub-window against bottom side of display.
      //
      seGetMainWinResolution(&width, &height);

      if (width > height)
         side = height;
      else
         side = width;
      
      SubWinWidth = width - side;
      SubWinHeight = height;

      // width must be a multiple of 32 / bpp
      offset = (width - side) / (32 / bppMainWin);  // round up

      if (SubWinWidth != (offset * (32 / bppMainWin)))
         ++offset;

      SubWinWidth = offset * (32 / bppMainWin);

      x1 = side;
      x2 = width;
      y1 = 0;
      y2 = height;


      // Reallocate memory for main window to not take up side*side
      size = side * side * bppMainWin / 8;
      addr = seAllocMainWinSurface(size);

#ifdef LINEAR_ADDRESSES_SUPPORTED
      if (addr == 0)
         FailBpp(bppMainWin);
#else
      if (addr == -1)
         FailBpp(bppMainWin);
#endif



      //
      // Update start address registers
      //
      seSetSubWinAsActiveSurface();

      size = (SubWinWidth * SubWinHeight * bppMainWin) / 8;
      addr = seAllocSubWinSurface(size);

#ifdef LINEAR_ADDRESSES_SUPPORTED
      if (addr == 0)
         FailBpp(bppMainWin);
#else
      if (addr == -1)
         FailBpp(bppMainWin);
#endif

      seSetSubWinCoordinates(x1, y1, x2, y2);

      // Sub-Window coordinates must be updated before calling VirtInit
      // Note that for this demo, the sub-window must occupy the full
      // width of the display.
      seSubWinVirtInit(SubWinWidth, SubWinHeight);
      seSubWinDisplayEnable(TRUE);

      seSetMainWinAsActiveSurface();
      }
   }

/*-------------------------------------------------------------------------*/
// returns 0 if OK
// otherwise returns error value to be returned by main()

int HandleSelectedSurface(void)
   {
   int i;
   unsigned bpp;
   
   bpp = seGetBitsPerPixel();

   seWriteRegDword(REG_MAIN_WIN_DISP_START_ADDR0, 0);
   seWriteRegDword(REG_SUB_WIN_DISP_START_ADDR0, 0);


   /*
   ** Surface 0: MAIN WINDOW
   ** Surface 1: SUB-WINDOW
   */
   if (!(HalInfo.dwFlags & fVALID_LCD))
      ExitBadConfiguration();

   seMainWinDisplayEnable(FALSE);
   seSubWinDisplayEnable(TRUE);

   NumberOfSurfaces = 2;
   SurfaceDisplayMode[0] = MAIN_WIN;
   SurfaceDisplayMode[1] = SUB_WIN;

   seWriteRegWord(REG_SUB_WIN_ADDR_OFFSET0, seReadRegWord(REG_MAIN_WIN_ADDR_OFFSET0));

   if (gbInitRegisters)
      SetBitsPerPixel();

   printf("\n");


   for (i = 0; i < MAX_DISP_SURFACE; ++i)
      {
      if (SurfaceDisplayMode[i] == 0)
         SurfaceDisplayMode[i] = GetSurfaceDisplayMode(i);
      }

   return 0;
   }

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

⌨️ 快捷键说明

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