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

📄 virt.c

📁 epson公司的一个关于s1d13706的低层驱动程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
**===========================================================================
**  VIRT.C - Test for virtual displays
**---------------------------------------------------------------------------
**  Copyright (c) 2000, 2001 Epson Research and Development, Inc.
**  All Rights Reserved.
**===========================================================================
*/

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

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

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

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

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


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

int mode;
unsigned VirtualWidth;
DWORD CurrentColor;
long MaxX, MaxY;
long KeyStep;
int ShowSubWindow;
int CmdLineBitsPerPixel;
int CheckForValidSwivelViewClocks;

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

BYTE LUT_4bpp[] =
   { 0x00, 0x00, 0x00,  // black
     0xb0, 0x68, 0x00,  // brown
     0xfc, 0x00, 0x00,  // red
     0xfc, 0x80, 0x00,  // orange
     0xfc, 0xfc, 0x00,  // yellow
     0x00, 0xfc, 0x00,  // green
     0x00, 0x00, 0xfc,  // blue
     0xfc, 0x00, 0xfc,  // violet
     0x80, 0x80, 0x80,  // gray
     0xfc, 0xfc, 0xfc   // white
   };

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

static const char Revision[] = "13706VIRT.C=$Revision: 4 $";

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

void DisplayKeys(void)
{
   printf("\n");
   printf("KEY   DESCRIPTION\n");
   printf(" 8    UP (only for scroll mode)\n");
   printf(" 2    DOWN (only for scroll mode)\n");
   printf(" 6    RIGHT (only for pan mode)\n");
   printf(" 4    LEFT (only for pan mode)\n");
   printf(" +    increase key steps for direction keys\n");
   printf(" -    decrease key steps for direction keys\n");
   printf(" ?    help (this screen)\n");
   printf("ESC   quit program\n\n");
}

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

void DisplayInfo(void)
{
   DWORD y;
   DWORD StartAddr, Offset;

   if (ShowSubWindow)
      {
      StartAddr = seReadRegDword(REG_SUB_WIN_DISP_START_ADDR0);
      Offset = (DWORD) seReadRegWord(REG_SUB_WIN_ADDR_OFFSET0);

      y = StartAddr / Offset;

      printf("Sub Win Start Addr=%05lXh %6lu  (line=%4lu)  Offset=%04lXh %6lu\n",
             StartAddr, StartAddr, y, Offset, Offset);
      }
   else
      {
      StartAddr = seReadRegDword(REG_MAIN_WIN_DISP_START_ADDR0);
      Offset = (DWORD) seReadRegWord(REG_MAIN_WIN_ADDR_OFFSET0);

      y = StartAddr / Offset;

      printf("Main Win Start Addr=%05lXh %6lu  (line=%4lu)  Offset=%04lXh %6lu\n",
             StartAddr, StartAddr, y, Offset, Offset);
      }
}

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

void PanScroll(long x, long *y)
{
   int      nPPan;
   DWORD    dwAddr;
   unsigned nBPP;
   unsigned val;
   DWORD    BytesPerScanline;
   unsigned nPhysWidth;
   unsigned nPhysLines;
   int      DisplayMode;

   nBPP = seGetBitsPerPixel();
   seGetResolution(&nPhysWidth, &nPhysLines);
   BytesPerScanline = seGetBytesPerScanline();

   dwAddr = (*y * BytesPerScanline + seGetSurfaceOffsetAddress()) / 4L;


   switch (nBPP)
      {
      case 4:
         nPPan   = (BYTE)(x & 0x03);
         dwAddr += (x & 0xFFFC) >> 3;
         break;
   
      case 8:
         nPPan   = (BYTE)(x & 0x01);
         dwAddr += (x & 0xFFFE) >> 2;
         break;
   
      case 16:
         nPPan   = 0;
         dwAddr += x >> 1;
         break;

      default:
         printf("ERROR: Cannot run at %d bits-per-pixel\n", nBPP);
         exit(1);
         break;
      }


   DisplayMode = seGetSurfaceDisplayMode();


   /*
   ** Wait until current non-display ends
   */
   do
      val = seReadRegByte(REG_POWER_SAVE_CONFIG);
   while (val & 0x80);

   /*
   ** Wait if we are in display
   */
   do
      val = seReadRegByte(REG_POWER_SAVE_CONFIG);
   while (!(val & 0x80));


   /*
   ** Write new start address
   */
   if (ShowSubWindow)
      seWriteRegDword(REG_SUB_WIN_DISP_START_ADDR0, dwAddr);
   else
      seWriteRegDword(REG_MAIN_WIN_DISP_START_ADDR0, dwAddr);
}

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

void HandleKeyboard(void)
   {
   int forever = TRUE;
   int ch;
   long x = 0;
   long y = 0;

   int PixelsPerDword = 32 / seGetBitsPerPixel();

   DisplayKeys();

   /*
   ** Move image with keys
   */

   while (forever)
      {
      ch = getch();

      if ((ch == 0) || (ch == 0xe0))  // extended keystroke
         ch = getch();

      switch (ch)
         {
         /*
         ** UP
         */
         case '8':
            if (mode == MODE_SCROLL)
               {
               y -= KeyStep;

               PanScroll(x, &y);
               DisplayInfo();
               }
            break;

         /*
         ** RIGHT
         */
         case '6':
            if (mode == MODE_PAN)
               {
               x += (PixelsPerDword * KeyStep);
   
               if (x > MaxX)
                  x = MaxX;

               PanScroll(x, &y);
               DisplayInfo();
               }
            break;

         /*
         ** LEFT
         */
         case '4':
            if (mode == MODE_PAN)
               {
               if (x - (PixelsPerDword * KeyStep) >= 0)
                  x -= (PixelsPerDword * KeyStep);
               else
                  x = 0;
   
               PanScroll(x, &y);
               DisplayInfo();
               }
            break;

         /*
         ** DOWN
         */
         case '2':
            if (mode == MODE_SCROLL)
               {
               y += KeyStep;

               PanScroll(x, &y);
               DisplayInfo();
               }
            break;

         /*
         ** Increase KeyStep
         */
         case '+':
            ++KeyStep;
            printf("Key Step: %ld\n", KeyStep);
            break;

         /*
         ** Decrease KeyStep
         */
         case '-':
            if (KeyStep > 1)
               --KeyStep;

            printf("Key Step: %ld\n", KeyStep);
            break;

         /*
         ** HELP
         */
         case '?':
            DisplayKeys();
            break;

         /* QUIT */
         case ESC:
            exit(0);
            break;
         }
      }
   }

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

DWORD GetNextColor(void)
   {
   switch (seGetBitsPerPixel())
      {
      case 4:
      case 8:
         switch (CurrentColor)
            {
            case BLACK_4BPP:
               CurrentColor = BROWN_4BPP;
               break;

            case BROWN_4BPP:
               CurrentColor = RED_4BPP;
               break;
      
            case RED_4BPP:
               CurrentColor = ORANGE_4BPP;
               break;
      
            case ORANGE_4BPP:
               CurrentColor = YELLOW_4BPP;
               break;
      
            case YELLOW_4BPP:
               CurrentColor = GREEN_4BPP;
               break;
      
            case GREEN_4BPP:
               CurrentColor = BLUE_4BPP;
               break;
      
            case BLUE_4BPP:
               CurrentColor = VIOLET_4BPP;
               break;
      
            case VIOLET_4BPP:
               CurrentColor = GRAY_4BPP;
               break;
      
            case GRAY_4BPP:
               CurrentColor = WHITE_4BPP;
               break;
      
            case WHITE_4BPP:
            default:
               CurrentColor = BLACK_4BPP;
               break;
            }
         break;

      case 16:
         switch (CurrentColor)
            {
            case BLACK_16BPP:
               CurrentColor = BROWN_16BPP;
               break;
      
            case BROWN_16BPP:
               CurrentColor = RED_16BPP;
               break;
      
            case RED_16BPP:
               CurrentColor = ORANGE_16BPP;
               break;
      
            case ORANGE_16BPP:
               CurrentColor = YELLOW_16BPP;
               break;
      
            case YELLOW_16BPP:
               CurrentColor = GREEN_16BPP;
               break;
      
            case GREEN_16BPP:
               CurrentColor = BLUE_16BPP;
               break;
      
            case BLUE_16BPP:
               CurrentColor = VIOLET_16BPP;
               break;
      
            case VIOLET_16BPP:
               CurrentColor = GRAY_16BPP;
               break;
      
            case GRAY_16BPP:
               CurrentColor = WHITE_16BPP;
               break;
      
            case WHITE_16BPP:
            default:
               CurrentColor = BLACK_16BPP;
               break;
            }
         break;
      }

   return CurrentColor;
   }

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

void InitializeVirtualDisplay(unsigned width, unsigned height)
{
   DWORD size;
   static char szErrNotEnoughMem[] = "Not enough memory for virtual display.";

   size = width * height * seGetBitsPerPixel() / 8;

   if (size > DISPLAY_BUFFER_SIZE)
      printf(">>>> WARNING: %s <<<\n", szErrNotEnoughMem);


   switch (seVirtInit(width, height))
      {
      case ERR_OK:
         break;

      case ERR_HAL_BAD_ARG:
         printf("ERROR: Width must be >= physical display width and < 2048 pixels.\n");

⌨️ 快捷键说明

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