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

📄 util.c

📁 epson公司的一个关于s1d13706的低层驱动程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
**===========================================================================
**  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 "assert.h"
#include "show.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( "13706SHOW.EXE - Color depth 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);
}

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

void DisplayUsage( void )
   {
   printf("\nUsage:   13706SHOW [b=n] [/a] [/bigmem] [/g[=n]] [/noclkerr]\n" );
   printf(  "         [/noinit] [/r90 | /r180 | /r270] [/read] [/s] [/write] [/?]\n" );
   printf(  "    b=n        bits-per-pixel where n = ( 1, 2, 4, 8, 16 )\n" );
   printf(  "   /a          automatically cycle through all video modes\n" );
   printf(  "   /bigmem     assume memory is 2 MB instead of 80k (for testing)\n" );
   printf(  "   /g[=n]      show grid (n=white or black)\n");
   printf(  "   /noclkerr   allows invalid SwivelView clocks (for testing)\n" );
   printf(  "   /noinit     skips register initialization\n" );
   printf(  "   /r90        SwivelView 90 degree rotation\n" );
   printf(  "   /r180       SwivelView 180 degree rotation\n" );
   printf(  "   /r270       SwivelView 270 degree rotation\n" );
   printf(  "   /read       continually read dwords from entire memory\n" );
   printf(  "   /s          show vertical stripes\n" );
   printf(  "   /write      continually write to one word of offscreen memory\n" );
   printf(  "   /?          display help message\n" );
   }

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

void InitializeGlobalVariables(void)
   {
   int surface;

   ShowAllBppModes = TRUE;
   gnUseVertical     = FALSE;
   gnInitRegisters   = TRUE;
   gnAutoRun         = FALSE; 
   gnContinualScrnRead  = FALSE;
   gnContinualScrnWrite = FALSE;
   gnShowGrid        = FALSE;
   gnUpdateDisplayMemory = TRUE;
   NumberOfSurfaces  = 0;
   CommonMemoryBlockForAllDisplays = FALSE;
   LcdOrientation    = LANDSCAPE;
   CmdLineBitsPerPixel = 0;
   GridColor = 0xffff;
   UseBigMemory = FALSE;
   CheckForValidSwivelViewClocks = TRUE;

   for (surface = 0; surface < MAX_DISP_SURFACE; ++surface)
      SurfaceDisplayMode[surface] = 0;
   }

/*-----------------------------------------------------------------------*/
// 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], "A" ))
            {
            gnAutoRun = 1;
            }
         else if ((argv[i][0] == 'G') || (argv[i][0] == 'g'))
            {
            gnShowGrid = TRUE;

            if (argv[i][1] == '=')
               {
               if (!strcmpi(argv[i], "G=BLACK"))
                  GridColor = 0;
               else if (!strcmpi(argv[i], "G=WHITE"))
                  GridColor = 0xffff;
               else
                  {
                  DisplayUsage();
                  exit(0);
                  }
               }
            }
         else if (!strcmpi( argv[i], "S" ))
            {
            gnUseVertical = TRUE;
            }
         else if (!strcmpi( argv[i], "READ" ))
            {
            gnContinualScrnRead = TRUE;
            }
         else if (!strcmpi( argv[i], "WRITE" ))
            {
            gnContinualScrnWrite = TRUE;
            }
         else if ( !strcmpi( argv[i], "NOINIT" ))
            {
            gnInitRegisters = FALSE;
            }
         else if ( !strcmpi( argv[i], "R90" ))
            {
            LcdOrientation = ROTATE90;
            }
         else if ( !strcmpi( argv[i], "R180" ))
            {
            LcdOrientation = ROTATE180;
            }
         else if ( !strcmpi( argv[i], "R270" ))
            {
            LcdOrientation = ROTATE270;
            }
         else if ( !strcmpi( argv[i], "BIGMEM" ))
            {
            UseBigMemory = TRUE;
            }
         else if ( !strcmpi( argv[i], "NOCLKERR" ))
            {
            CheckForValidSwivelViewClocks = FALSE;
            }
         else
            {
            DisplayUsage( );
            return 1;
            }
         }
      else if (!strncmp(argv[i], "B=", 2))
         {
         CmdLineBitsPerPixel = atoi( &argv[i][2] );

         switch (CmdLineBitsPerPixel)
            {
            case 1:
            case 2:
            case 4:
            case 8:
            case 16:
               ShowAllBppModes = FALSE;
               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 WIN_PCI_DRIVER
      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;
      }
      
   if (UseBigMemory)
      {
      _MemorySize = 0x200000;  //2 MB of display memory

      printf("WARNING: /bigmem option selected!!!\n");
      printf(">>> FOR TESTING, PROGRAM WILL ATTEMPT TO    <<<\n"
             ">>> SHOW IMAGES WITH INSUFFICIENT MEMORY!!! <<<\n");
      }

   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;
   }

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

//
// returns TRUE if OK
// returns FALSE if SwivelView failed
//
int UpdateLcdOrientation(void)
   {
   // If the registers are not initialized, then keep the same register settings for SwivelView

   if (!gnInitRegisters)
      {
      switch (seReadRegByte(REG_SPECIAL_EFFECTS) & 0x03)
         {
         case 0:
            LcdOrientation = LANDSCAPE;
            break;
            
         case 1:
            LcdOrientation = ROTATE90;
            break;
            
         case 2:
            LcdOrientation = ROTATE180;
            break;
            
         case 3:
            LcdOrientation = ROTATE270;
            break;
         }
      }

   //
   // First check if valid clocks for given mode
   //
   if (!CheckSwivelViewClocks(seGetBitsPerPixel(), LcdOrientation))
      return FALSE;

   if (seSetSwivelViewMode(LcdOrientation) == ERR_OK)
      return TRUE;
   else
      {
      printf("ERROR: Not enough memory for %s mode.\n", szSwivelView[LcdOrientation]);
      return FALSE;
      }
   }

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

void DisplayResolution(void)
{
   unsigned x, y, bpp;
   unsigned regDisplayMode;
   int surface;

   regDisplayMode = seReadRegByte(REG_DISPLAY_MODE);
   bpp = seGetBitsPerPixel();

   surface = CalcDisplaySurfaceCombination();

   switch (surface)
      {
      case SURFACE_NONE:
         break;

⌨️ 快捷键说明

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