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

📄 show.c

📁 一个图形显示芯片s1d13505的应用程序
💻 C
📖 第 1 页 / 共 4 页
字号:
/*
**===========================================================================
**  SHOW.C - Source to the SHOW demo program. This program sets all
**               available display modes and draws a pattern in each.
**---------------------------------------------------------------------------
** Copyright (c) 1997, 2001 Epson Research and Development, Inc.
** All Rights Reserved.
**===========================================================================
*/

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

#ifdef INTEL
#include <conio.h>
#include <time.h>
#endif

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

/*============================ global variables ===========================*/

/****************************/
char szVersion[] = "2.1";
/****************************/

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

// for HSLtoRGB
#define MAX_COLOR  2000

// Don't show diagonals if display smaller than 64x64
#define DX_DIAGONALS    64
#define DY_DIAGONALS    64


enum
{
   LUT_RED_BAR,
   LUT_GREEN_BAR,
   LUT_BLUE_BAR,
   LUT_GRAY_BAR,
   LUT_HUE
};

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

int gDevID;

int gnAutoRun;
int gnUseVertical;
int gnContinualScrnRead;
int gnContinualScrnWrite;
int gnInitRegisters;
int gnDisplayMode;
int gnShowGrid;
int gnUpdateDisplayMemory;

int PortraitMode;
UINT white = 0xffff;
UINT black = 0;


char szModeFailed[] = "ERROR: Could not change to %d bit-per-pixel.\n";

/*=============================== functions ===============================*/

void DisplayCopyright( void );
void DisplayUsage( void );

void ShowOneMode( int BitsPerPixel, char *str );
void UpdateScreen( UINT BitsPerPixel );

UINT GetNextColor( UINT Color, UINT Bpp );
int  InitLut( int Bpp );
static int seDrawColorScale( int seReserved1, long barcolorwidth, long barcolorhight, long barcolorstep);

extern BOOL test(int);
// do not need following externals because we included nonsefns.h 
#if 0
extern void Line(int seReserved1, int BytesPerScanline, int x1, int y1, int x2, int y2, DWORD color, void (*pSetPixel)(int seReserved1, int BytesPerScanline, int x, int y, DWORD color));
extern void Pixel1bpp(int seReserved1, int BytesPerScanline, int x, int y, DWORD color);
extern void Ellipse(int seReserved1, int BytesPerScanline, int xc, int yc, int a0, int b0, DWORD color, void (*pSetPixel)(int seReserved1, int BytesPerScanline, int x, int y, DWORD color));
extern void Line16bpp(DWORD StartLogicalAddr, int BytesPerScanline,long x1,long y1,long x2,long y2,DWORD color);
#endif

/*================================== code =================================*/

int main( int argc, char *argv[] )
   {
   int nBitsPerPixel = 0;     /* 0 means show all bit-per-pixel. */
   int i;

   int *bpp;
   int BppSize;
   int LandscapeBpp[] = { 16, 15, 8, 4, 2, 1 };
   int PortraitBpp[] = { 16, 15, 8 };
   int k;
   int ch;
   BYTE RegDisplayMode;
   UINT nWidth, nHeight;
   char *szDispMode[MAX_DISP_MODE] = { "LCD", "CRT", "SIMULTANEOUS" };
   char *szPressKey = "Press any key to continue...\n";
   char *pStr;
   static const char strUnknownCmd[] = "ERROR: Unknown command line argument.\n";

   bpp = LandscapeBpp;
   BppSize = sizeof(LandscapeBpp) / sizeof(LandscapeBpp[0]);

   gnUseVertical     = FALSE;
   gnInitRegisters   = TRUE;
   gnAutoRun         = FALSE; 
   gnContinualScrnRead  = FALSE;
   gnContinualScrnWrite = FALSE;
   gnDisplayMode     = MAX_DISP_MODE;  /* set to invalid number */
   gnShowGrid        = FALSE;
   gnUpdateDisplayMemory = TRUE;

   PortraitMode = FALSE;


   DisplayCopyright();

   switch (seRegisterDevice( &HalInfo, &gDevID ))
      {
      case ERR_OK:
         break;

      case ERR_UNKNOWN_DEVICE:
         printf( "ERROR: Did not find a 13505 device.\n" );
         return 1;
         break;

      case ERR_TOOMANY_DEVS:
         printf( "ERROR: Too many devices registered.\n" );
         return 1;
         break;

      default:
         printf( "ERROR: Could not register S1D13505 device.\n" );
         return 1;
         break;
      }


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

         if (!strcmpi( argv[i], "?" ))
            {
            DisplayUsage( );
            return 0;
            }
         else if (!strcmpi( argv[i], "A" ))
            {
            gnAutoRun = 1;
            }
         else if (!strcmpi( argv[i], "G" ))
            {
            gnShowGrid = TRUE;
            }
         else if (!strcmpi( argv[i], "LCD" ))
            {
            if (gnDisplayMode == DISP_MODE_CRT)
               gnDisplayMode = DISP_MODE_LCDCRT;
            else
               gnDisplayMode = DISP_MODE_LCD;
            }
         else if (!strcmpi( argv[i], "CRT" ))
            {
            if (gnDisplayMode == DISP_MODE_LCD)
               gnDisplayMode = DISP_MODE_LCDCRT;
            else
               gnDisplayMode = DISP_MODE_CRT;
            }
         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], "P" ))
            {
            PortraitMode = TRUE;

            seGetReg(gDevID, REG_DISPLAY_MODE, &RegDisplayMode);
            seSetReg(gDevID, REG_DISPLAY_MODE, (BYTE) (RegDisplayMode | 0x80));
            }
         else
            {
            DisplayUsage();
            printf(strUnknownCmd);
            return 1;
            }
         }
      else if (((*argv[i] == 'b') || (*argv[i] == 'B')) && (argv[i][1] == '='))
         {
         nBitsPerPixel = atoi( &argv[i][2] );

         switch (nBitsPerPixel)
            {
            case 1:
            case 2:
            case 4:
            case 8:
            case 15:
            case 16:
            break;

            default:
               DisplayUsage( );
               return 1;
            }
         }
      else
         {
         DisplayUsage( );
         printf(strUnknownCmd);
         return 1;
         }
      }

   if (gnContinualScrnRead)
      {
      if (gnAutoRun)
         {
         DisplayUsage( );
         printf( "ERROR: Continual screen read will not work with the /a switch.\n" );
         return 1;
         }
      }

   if (gnContinualScrnWrite)
      {
      if (gnAutoRun)
         {
         DisplayUsage( );
         printf( "ERROR: Continual screen write will not work with the /a switch.\n" );
         return 1;
         }
      }


   if ((nBitsPerPixel != 0) && !gnInitRegisters)
      {
      printf("WARNING: b= option used with /noinit, so bit-per-pixel\n"
             "         and display memory will NOT be changed.\n");
      gnUpdateDisplayMemory = FALSE;
      }


   /*
   ** If the display mode is invalid, use the default mode
   */
   if (gnDisplayMode >= MAX_DISP_MODE)
      {
      if (HalInfo.dwFlags & fDEFAULT_CRT)
         gnDisplayMode = DISP_MODE_CRT;
      else if (HalInfo.dwFlags & fDEFAULT_LCDCRT)
         gnDisplayMode = DISP_MODE_LCDCRT;
      else
         gnDisplayMode = DISP_MODE_LCD;
      }

   printf("Display Mode:  %s\n", szDispMode[gnDisplayMode]);


   if (gnInitRegisters)
      {
      if (ERR_OK != seSetDisplayMode( gDevID, gnDisplayMode, CLEAR_MEM | DISP_FIFO_OFF))
         {
         printf( "ERROR: Could not initialize device.\n" );
         return 1;
         }
      }
   else
      {
      seGetReg(gDevID, REG_DISPLAY_MODE, &RegDisplayMode);

      if (RegDisplayMode & 0x80)
         PortraitMode = TRUE;
      else
         PortraitMode = FALSE;
      }

   printf("Portrait Mode: ");

   seGetReg(gDevID, REG_DISPLAY_MODE, &RegDisplayMode);

   if (PortraitMode)
      {
      printf("ENABLED\n");
      RegDisplayMode |= 0x80;
      seSetReg(gDevID, REG_DISPLAY_MODE, RegDisplayMode);

      bpp = PortraitBpp;
      BppSize = sizeof(PortraitBpp) / sizeof(PortraitBpp[0]);
      }
   else
      {
      printf("DISABLED\n");
      RegDisplayMode &= ~0x80;
      seSetReg(gDevID, REG_DISPLAY_MODE, RegDisplayMode);

      bpp = LandscapeBpp;
      BppSize = sizeof(LandscapeBpp) / sizeof(LandscapeBpp[0]);
      }

   printf("\n");

   seGetScreenSize(gDevID, &nWidth, &nHeight);

   if (nBitsPerPixel == 0)
      {
      for (k = 0; k < BppSize; k++)
         {
         if (!gnAutoRun)
            pStr = szPressKey;
         else
            pStr = NULL;

         ShowOneMode( bpp[k], pStr );

         if (!gnAutoRun)
            {
            ch = seGetChar( );
            if ((0x03 == ch) || (0x1B == ch))
               exit(0);
            }
#ifdef INTEL
         else
            {
            seDelay( gDevID, 5 );    
            }
#endif
         }
      }
   else
      ShowOneMode( nBitsPerPixel, NULL );

   return 0;
   }

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

void DisplayCopyright( void )
{
   const char *szHalVer;
   const char *szHalStatus;
   const char *szHalStatusRev;
   char str[50];
   int  ver;

   if (seGetLibseVersion(&ver) == ERR_OK)
      sprintf(str, "[LIBSE %d]", ver);
   else
      str[0] = 0;

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

   printf( "13505SHOW.EXE - Color depth testing Utility - Version %s [HAL %s%s%s] %s\n",
            szVersion, szHalVer, szHalStatus, szHalStatusRev, str );
   printf( "Copyright (c) 1997, 2001 Epson Research and Development, Inc.\n");
   printf( "All Rights Reserved.\n");
}

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

void DisplayUsage( void )
   {
   printf("\nUsage:   13505SHOW [b=n] [/a] [/crt] [/g] [/lcd] [/noinit] [/p]\n" );
   printf(  "                  [/read] [/s] [/write] [/?]\n" );
   printf(  "    b=n       bit-per-pixel where n = ( 1, 2, 4, 8, 15, 16 )\n" );
   printf(  "   /a         automatically cycle through all video modes\n" );
   printf(  "   /crt       show on CRT\n");
   printf(  "   /g         show grid\n");
   printf(  "   /lcd       show on LCD\n");
   printf(  "   /noinit    skips register initialization\n" );
   printf(  "   /p         portrait mode\n" );
   printf(  "   /read      continually read from screen\n" );
   printf(  "   /s         show vertical stripes\n" );
   printf(  "   /write     write to one word of offscreen memory\n" );
   printf(  "   /?         display help message\n\n" );
   printf(  "NOTE: Combine /lcd and /crt for simultaneous display.\n");
   }

/*-------------------------------------------------------------------------*/
//
// hue: 0 to 2000
// sat: 0 to 2000
// red: 0 to 2000
// green: 0 to 2000
// blue: 0 to 2000
//

void HSLtoRGB(long hue, long sat, long *red, long *green, long *blue, long width)
{
#define LUM       (MAX_COLOR / 2)

⌨️ 快捷键说明

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