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

📄 virt.c

📁 一个图形显示芯片s1d13505的应用程序
💻 C
字号:
/*
**===========================================================================
** VIRT.C - A utility program to demonstrate and test panning and
**                   scrolling of the 13505.
**--------------------------------------------------------------------------
** Copyright (c) 1997, 2000 Epson Research and Development, Inc.
** All Rights Reserved.
**==========================================================================
*/

#include <stdlib.h>
#include <time.h>

#ifdef INTEL
#include <stdio.h>
#include <conio.h>
#include <ctype.h>
#endif

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

/*-- Globals ------------------------------------------------------------*/

#define VIRT_BORDER    64

/**********************************/
const char szVersion[] = "1.06";
/**********************************/

int  gDevID;

int  gnBPPArray[] = {16, 15, 8, 4, 2, 1};
BOOL gbAutoMode;

/* 14 back spaces */
char BS14[] = { BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, 0 };
                                   
/*-----------------------------------------------------------------------*/

int main( int argc, char *argv[] )
{
   int  nBppIdx    = -1;
   long lVirtWidth;
   UINT nWidth;
   UINT nHeight;

   gbAutoMode = MANUAL;
   lVirtWidth = 0;

   DisplayCopyright();

   /*
   ** Register with the HAL and initialize the 13505.
   */
   switch (seRegisterDevice( &HalInfo, &gDevID ))
   {
      case ERR_OK:
         break;

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

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

      default:
         printf( "\nERROR: Could not register S1D13505FOA device." );
         return 1;
         break;
   }


   /*
   ** Look for command line arguments.
   */
   while (argc > 1)
   {
      char * ptr = argv[argc - 1];

      if (('/' == *ptr) || ('-' == *ptr))
      {
         switch( toupper(*(ptr + 1)))
         {
            case 'A':
               gbAutoMode = AUTO;
               break;

            default:
               DisplayUsage();
               return 0;
         }
      }
      else if ( toupper(*ptr) == 'W' )
      {
         if ('=' != *(ptr + 1))
         {
            DisplayUsage();
            return 0;
         }
         ptr += 2;
         lVirtWidth = atol( ptr );
      }
      else
      {
         DisplayUsage();
         return 1;
      }

      argc--;
   }

   if (ERR_OK != seSetInit( gDevID ))
      return 2;

   if (lVirtWidth == 0)
      {
      seGetScreenSize( gDevID, &nWidth, &nHeight );
      lVirtWidth = nWidth + VIRT_BORDER;
      }


   /*
   ** Test all the color depths.
   */
   do
   {
      if (++nBppIdx >= sizeof(gnBPPArray)/sizeof(gnBPPArray[0]))
         break;
   }
   while (TRUE == TestMode( gnBPPArray[nBppIdx], lVirtWidth ));

   return 0;
}

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

void DisplayCopyright( void )
{
   const char *szHALVer;
   const char *szHALStatus;
   const char *szHALRevision;
   char str[50];
   int  ver;

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

   seGetHalVersion( &szHALVer, &szHALStatus, &szHALRevision );

   printf( "\n13505VIRT.EXE - Virtual Screen Test Utility - Version %s [HAL %s%s%s] %s",
              szVersion, szHALVer, szHALStatus, szHALRevision, str );

   printf( "\nCopyright (c) 1997, 2001 Epson Research and Development, Inc.");
   printf( "\nAll Rights Reserved.");
   printf( "\n" );

/*
   printf( "\n>>>>>>>>>>>>>> BETA - FOR INTERNAL USE ONLY <<<<<<<<<<<<<<" );
   printf( "\n>>>>>>>>>>>>>>      DO NOT DISTRIBUTE       <<<<<<<<<<<<<<" );
   printf( "\n" );
*/
}

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

void DisplayUsage( void )
{
   printf( "\nUsage: 13505VIRT [w=n] [/a] [/?]" );
   printf( "\n" );
   printf( "\nWhere:            w=n  Specify the virtual width (in pixels)." );
   printf( "\n                  /a   Automatic scrolling mode." );
   printf( "\n                  /?   Display help message" );
   printf( "\n" );
   printf( "\nIn manual mode:    Arrow keys move the display about the virtual screen" );
   printf( "\n                   CTRL plus the arrow keys moves faster." );
   printf( "\n                   HOME returns to the upper left corner." );
   printf( "\n                   END  moves to the lower right corner." );
   printf( "\n" );
   printf( "\nIn automatic mode: Pressing any key will change direction" );
   printf( "\n" );
   printf( "\nIn any mode:       ESC quits the program" );
   printf( "\n                   'B' changes the color depth (bit-per-pixel)" );
   printf( "\n" );
}

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

BOOL TestMode( int nBPP, long lVirtWidth )
{
   DWORD lVirtHeight, dwHeight;
   UINT nWidth;
   UINT nHeight;
   DWORD LastByte;
   int  tmp;

   seDisplayFifo(gDevID, OFF);

   if (ERR_OK != seSetBitsPerPixel( gDevID, nBPP ))
      exit( 2 );

   seGetScreenSize( gDevID, &nWidth, &nHeight );

   /*
   ** Calculate the greatest virtual height. H = Mem / BytesPerScanline
   ** If it's less than the panel height ...
   **   we have a problem. Display an error message and return.
   */
   seGetLastUsableByte( gDevID, &LastByte );

   if (nBPP == 15)
      tmp = 16;
   else
      tmp = nBPP;

   lVirtHeight = LastByte / (lVirtWidth / (16 / tmp) * 2);

   if (lVirtHeight > nHeight+VIRT_BORDER)
      lVirtHeight = nHeight+VIRT_BORDER;

   if (lVirtHeight < nHeight)
   {
      printf( "\nERROR: Not enough display buffer memory for %d BPP.", nBPP );
      return TRUE;
   }

   seVirtInit( gDevID, (WORD)lVirtWidth, &dwHeight );
   seVirtMove( gDevID, 1, 0, 0 );

   lVirtHeight = (lVirtHeight / PAT_HEIGHT) * PAT_HEIGHT;

   printf( "\nFilling %2d BPP", nBPP );

   FillDisplayMem( nBPP, lVirtWidth, lVirtHeight );
   seDisplayFifo(gDevID, ON);

   printf( "%s              %s%d BPP", BS14, BS14, nBPP );

   return KbdHandler( nBPP, lVirtWidth, lVirtHeight );
}

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

/*
** FillDisplayMem()
**
** The fill pattern is a simple checkerboard of alternating colors.
*/
void FillDisplayMem( int nBPP, long lVirtWidth, long lVirtHeight )
{
   int      x, y;
   WORD  wColor = 0;
   WORD  baseColor = 0;

   /*
   ** Fill the pattern and draw a box around the display.
   */
   for (y = 0; y <= lVirtHeight - PAT_HEIGHT; y += PAT_HEIGHT)
   {
      for (x = 0; x <= lVirtWidth - PAT_WIDTH; x += PAT_WIDTH)
      {
         seDrawRect( gDevID, x, y, x + PAT_WIDTH, y + PAT_HEIGHT, wColor, TRUE );
         wColor = GetNextColor( nBPP, wColor );
      }
      wColor = (baseColor = GetNextColor( nBPP, baseColor ));
   }

   seDrawRect( gDevID, 0, 0, (int)lVirtWidth, (int)lVirtHeight, 0xFFFFFFFF, 0 );
}

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

/*
** GetNextColor()
**
** This routine is optimized for 13505VIRT such that the return color
** is replicated across the byte for color depths less than 8bpp.
*/
WORD GetNextColor( int nBPP, WORD Color )
{
   switch (nBPP)
   {
      case 1:
         return (0xFF - Color);
         break;

      case 2:
         Color++;
         Color &= 0x03;
         return Color |= Color << 2 | Color << 4 | Color << 6;
         break;

      case 4:
         Color++;
         Color &= 0x0F;
         return Color |= Color << 4;
         break;

      case 8:
         return ++Color;
         break;

      case 15:
         if (!(Color & 0x7fe0))  /* red and green not used, so show blue */
            {
            Color += 4;            /* inc blue */
            }
         else if (!(Color & 0x7c1f))  /* red and blue not used, so show green */
            {
            Color &= ~0x60;      /* remove first two bits of green */
            Color += 0x80;       /* inc green */
            }
         else
            {
            Color &= ~0xc00;      /* remove first two bits of red */
            Color += 0x1000;      /* inc red */
            }

         Color &= ~0x8000;  /* remove unused bit */
         return Color;
         break;

      case 16:
         if (!(Color & 0xffe0))  /* red and green not used, so show blue */
            {
            Color += 4;          /* inc blue */
            }
         else if (!(Color & 0xf81f))  /* red and blue not used, so show green */
            {
            Color &= ~0x60;      /* remove first two bits of green */
            Color += 0x80;       /* inc green */
            }
         else
            {
            Color &= ~0x1800;    /* remove first two bits of red */
            Color += 0x2000;     /* inc red */
            }

         return Color;
         break;
   }
   return Color;
}

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

BOOL KbdHandler( int nBPP, long lVirtWidth, long lVirtHeight )
{
   int nKbd = 0;
   int nDirection = RIGHT;
   int JustStarted = TRUE;
   int x = 0, y = 0;
   int nMaxX, nMaxY;
   int nXstep = 1;

   UINT nWidth, nHeight;

   nBPP;  /* prevent compiler from saying that nBPP is not used */

   seGetScreenSize( gDevID, &nWidth, &nHeight );

   nMaxX = (int)(lVirtWidth / PAT_WIDTH) * PAT_WIDTH - nWidth + 1;
   nMaxY = (int)(lVirtHeight - nHeight + 1);


   while (1)
   {
      if (gbAutoMode)
      {
      /*
      ** seDelay( gDevID, 1 );
      */

#ifdef INTEL
         if (kbhit())
         {
            nKbd = seGetChar();

            if ((0 == nKbd) || (0xE0 == nKbd))  /* We have an extended keystroke */
               nKbd = seGetChar();

            switch ( nKbd )
            {
               case ESC:
                  return FALSE;
                  break;

               case 'b':
               case 'B':
                  return TRUE;
                  break;

               default:
                  break;
            }
         }
#endif
      }
      else                                                  /* Manual mode */
      {
         nKbd = seGetChar();

         if ((0 == nKbd) || (0xE0 == nKbd))  /* We have an extended keystroke. */
            nKbd = seGetChar();

         nDirection = nKbd;
      }


      switch ( nKbd )
      {
         case ESC:
            return FALSE;
            break;

         case 'b':
         case 'B':
            return TRUE;
            break;

         default:
            switch ( nDirection )
            {
               case UP:
               case 'U':
                  if (y > 0)
                     y--;
                  else
                  {
                     nDirection = RIGHT;

                     if (gbAutoMode && !JustStarted)
                        return TRUE;
                     else
                        JustStarted = FALSE;
                  }
                  break;

               case DOWN:
               case 'D':
                  if (y < nMaxY)
                     y++;
                  else
                     nDirection = LEFT;
                  break;

               case RIGHT:
               case 'R':
                  if (x < nMaxX)
                     x += nXstep;
                  else
                     nDirection = DOWN;
                  break;

               case LEFT:
               case 'L':
                  if (x > 0)
                     x -= nXstep;
                  else
                     nDirection = UP;
                  break;

               case CTRL_UP:
                  if (y > 16)
                     y -= 16;
                  else
                     y = 0;
                  break;

               case CTRL_DOWN:
                  if ((long)y < (nMaxY - 16))
                     y += 16;
                  else
                     y = nMaxY;
                  break;

               case CTRL_RIGHT:
                  if (x < (nMaxX - 16))
                     x += 16;
                  else
                     x = nMaxX;
                  break;

               case CTRL_LEFT:
                  if (x > 16)
                     x -= 16;
                  else
                     x = 0;
                  break;

               case HOME:
                  x = 0;
                  y = 0;
                  break;

               case END:
                  x = nMaxX;
                  y = nMaxY;
                  break;

               default:
                  break;
            }
            break;
      }
      seVirtMove( gDevID, 1, x, y );
   }
}

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

⌨️ 快捷键说明

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