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

📄 util.c

📁 epson公司的一个关于s1d13706的低层驱动程序
💻 C
字号:
/*
**===========================================================================
**  util.c
**---------------------------------------------------------------------------
**  Copyright (c) 2000, 2001 Epson Research and Development, Inc.
**  All Rights Reserved.
**===========================================================================
*/

#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <limits.h>

#include "hal.h"
#include "virt.h"

#ifdef INCLUDE_CONIO_H   // Check if it's OK to include conio.h
#include <conio.h>
#endif

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

static char *szSwivelView[4] =
   { "landscape", "SwivelView 90", "SwivelView 180", "SwivelView 270" };

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

void DisplayCopyright( void )
{
   const char *szHalVer;
   const char *szHalStatus;
   const char *szHalStatusRev;

   seGetHalVersion( &szHalVer, &szHalStatus, &szHalStatusRev );

   printf( "13706VIRT.EXE - virtual image testing utility - Version %s  [HAL %s%s%s]\n", szVersion, szHalVer, szHalStatus, szHalStatusRev );
   printf( "Copyright (c) 2000, 2001 Epson Research and Development, Inc.\n");
   printf( "All Rights Reserved.\n\n");

   printf("Register Start Addr:       ");
   if (HalInfo.dwRegisterAddress == 0)
      printf("Configured by system\n");
   else
      printf("%08lX\n", HalInfo.dwRegisterAddress);

   printf("Display Memory Start Addr: ");
   if (HalInfo.dwDisplayMemoryAddress == 0)
      printf("Configured by system\n");
   else
      printf("%08lX\n", HalInfo.dwDisplayMemoryAddress);

   printf("\n");
}

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

void DisplayUsage( void )
   {
   printf("\nUsage:   13706VIRT [b=n] [/noclkerror] [/pan width=n] [/scroll] [/subwin] [?]\n");
   printf(  "    b=n        bits-per-pixel where n = ( 4, 8, 16 )\n" );
   printf(  "   /noclkerror allows invalid SwivelView clocks (for testing)\n" );
   printf(  "   /pan        enable interactive panning test\n");
   printf(  "    width=n    virtual width for panning test\n");
   printf(  "   /scroll     enable scroll test\n");
   printf(  "   /subwin     show sub-window\n");
   printf(  "   /?          display help message\n\n" );
   printf(  "NOTE: When showing sub-window, main window will\n");
   printf(  "      look strange because both windows are showing\n");
   printf(  "      the same image but at different address offsets.\n\n");
   }

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

void InitializeGlobalVariables(void)
   {
   CurrentColor = WHITE_16BPP;
   MaxX = 0;
   MaxY = 0;
   KeyStep = 1;
   VirtualWidth = 0;
   mode = MODE_NONE;
   ShowSubWindow = FALSE;
   CmdLineBitsPerPixel = 0;
   CheckForValidSwivelViewClocks = TRUE;
   }

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

int ParseCommandLine(int argc, char *argv[])
   {
   int i;

   /*
   ** Parse the command line.
   */
   for (i = 1; i < argc; ++i)
      {
      strupr(argv[i]);

      if (('/' == *argv[i]) || ('-' == *argv[i]))
         {
         argv[i]++;

         if (!strcmpi( argv[i], "?" ))
            {
            DisplayUsage( );
            exit(0);
            }
         else if (!strcmpi( argv[i], "PAN" ))
            {
            if (mode == MODE_NONE)
               mode = MODE_PAN;
            else
               {
               DisplayUsage();
               printf("ERROR: Can only choose one mode for testing.\n");
               exit(1);
               }
            }
         else if (!strcmpi( argv[i], "SCROLL" ))
            {
            if (mode == MODE_NONE)
               mode = MODE_SCROLL;
            else
               {
               DisplayUsage();
               printf("ERROR: Can only choose one mode for testing.\n");
               exit(1);
               }
            }
         else if (!strcmpi( argv[i], "SUBWIN" ))
            {
            ShowSubWindow = TRUE;
            }
         else if ( !strcmpi( argv[i], "NOCLKERROR" ))
            {
            CheckForValidSwivelViewClocks = FALSE;
            }
         else
            {
            DisplayUsage( );
            return 1;
            }
         }
      else if (!strncmp(argv[i], "WIDTH=", 3))
         {
         VirtualWidth = atoi(&argv[i][6]);
         }
      else if (!strncmp(argv[i], "B=", 2))
         {
         CmdLineBitsPerPixel = atoi( &argv[i][2] );

         switch (CmdLineBitsPerPixel)
            {
            case 4:
            case 8:
            case 16:
               break;

            default:
               DisplayUsage( );
               return 1;
            }
         }
      else
         {
         DisplayUsage( );
         return 1;
         }
      }
      
   return 0;
   }

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

int RegisterDevice(LPHAL_STRUCT info)
   {
   extern DWORD _MemorySize;   // Internal HAL variable

   switch (seRegisterDevice(info))
      {
      case ERR_OK:
         break;

#ifdef INTEL_W32
      case ERR_PCI_DRIVER_NOT_FOUND:
         printf("ERROR: PCI driver not found.\n");
         return 1;

      case ERR_PCI_BRIDGE_ADAPTER_NOT_FOUND:
         printf("ERROR: PCI bridge adapter not found.\n");
         return 1;
#endif

      case ERR_UNKNOWN_DEVICE:
         printf("ERROR: Could not detect S1D13706.\n");
         return 1;
      
      default:
         printf("ERROR: Could not map memory from evaluation board to host platform.\n");
         return 1;
      }
      

   // Declare more memory than is available.
   // This will force the HAL to run functions even if there is insufficient memory.
   _MemorySize = 0x200000;  // 2 MB of display memory

   return 0;
   }

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

int InitRegisters(void)
   {
   switch (seInitReg(CLEAR_MEM | DISP_BLANK))
      {
      case ERR_OK:
         break;

      case ERR_CLKI_NOT_IN_TABLE:
         printf("WARNING: CLKI frequency not in HAL table.\n"
                "         Program assumes that external oscillator is used.\n");
         break;

      case ERR_CLKI2_NOT_IN_TABLE:
         printf("WARNING: CLKI2 frequency not in HAL table.\n"
                "         Program assumes that external oscillator is used.\n");
         break;

      case ERR_NOT_ENOUGH_MEMORY:
         printf("\nERROR: Not enough display buffer memory.\n");
         return 1;
         break;
      }
      
   return 0;
   }

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

//
// Returns FALSE if error generated
//
int CheckSwivelViewClocks(unsigned BitsPerPixel, unsigned SwivelViewMode)
   {
   //
   // First check if valid clocks for given mode
   //
   if (seCheckSwivelViewClocks(BitsPerPixel, SwivelViewMode) != ERR_OK)
      {
      if (CheckForValidSwivelViewClocks)
         {
         printf("\nERROR: Clocks not configured for %s mode.\n", szSwivelView[SwivelViewMode]);
         return FALSE;
         }
      else
         printf("\nWARNING: Clocks not configured for %s mode.\n", szSwivelView[SwivelViewMode]);
      }

   return TRUE;
   }

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

⌨️ 快捷键说明

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