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

📄 modeset.c

📁 epson 13506 driver code
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
**===========================================================================
** MODESET.C
**
** Show/change bit-per-pixel mode of LCD controller
**---------------------------------------------------------------------------
** Copyright (c) 1997, 2001 Epson Research and Development, Inc.
** All Rights Reserved.
**===========================================================================
*/

#include <limits.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <ctype.h>

#include "hal.h"
#include "play.h"

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

static char * szSnglDual[2]  = { "SINGLE", "DUAL" };
static char * szSTNTFT[2]    = { "STN", "TFT" };
static char * szWidthSTN[4]  = { "4", "8", "16", "*ERR*" };
static char * szWidthTFT[4]  = { "9", "12", "16", "*ERR*" };
static char * szMonoColor[2] = { "MONO", "COLOR" };

static char * szSource[4] = { "CLKI", "BUSCLK", "CLKI2", "MCLK" };

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

static unsigned  bpp, LcdBpp, CrtTvBpp;
static unsigned  LcdWidth, LcdHeight;
static unsigned  CrtTvWidth, CrtTvHeight;
static char* pWidth;

static WORD  wSrcClk_Int, wSrcClk_Frac;

static DWORD dwMClkFreq;
static WORD  wMClk_Int, wMClk_Frac;
static int   MClkUsingBusClk;

static DWORD dwLcdPClkFreq;
static WORD  wLcdPClk_Int, wLcdPClk_Frac;

static DWORD dwCrtTvPClkFreq;
static WORD  wCrtTvPClk_Int, wCrtTvPClk_Frac;

static DWORD dwLcdFrameRate;
static WORD  wLcdFrameRate_Int, wLcdFrameRate_Frac;

static DWORD dwCrtTvFrameRate;
static WORD  wCrtTvFrameRate_Int, wCrtTvFrameRate_Frac;

static unsigned  nWidth, nHeight;

static unsigned  regDisplayMode;
static DWORD VirtWidth;
static unsigned  regInkCursorAddress;
static DWORD InkCursorAddress;
static DWORD MemSize;
static int   LcdInkCursorMode, CrtTvInkCursorMode;
static unsigned  LcdHDP, LcdHNDP, LcdVDP, LcdVNDP;
static unsigned  CrtTvHDP, CrtTvHNDP, CrtTvVDP, CrtTvVNDP;
static unsigned  regLcdPClkCfg, regCrtTvPClkCfg;
static unsigned regTvOutputCtrl;
static int GotMCCommand;

static char str[50];

enum
   {
   MODE_INACTIVE,
   MODE_CURSOR,
   MODE_INK
   };

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

/*
** HandleModeSet()
**
** Call this funtion to set the color depth.
*/
void HandleModeSet( PCHAR szArg )
{
   DWORD PeriodMClk = 0;
   DWORD PeriodBusClk = 0;
   unsigned regPanelType = 0;
   unsigned regLcdMisc = 0;
   DWORD n = 0;
   unsigned val;
   int SurfaceDisplayMode = 0;
   DWORD (* pSetBitsPerPixel)(unsigned nBitsPerPixel);

   AscToUpper(szArg);

   pSetBitsPerPixel = seSetBitsPerPixel;

   GotMCCommand = FALSE;

   regLcdPClkCfg = seReadRegByte(REG_LCD_PCLK_CFG);
   regCrtTvPClkCfg = seReadRegByte(REG_CRTTV_PCLK_CFG);
   regPanelType = seReadRegByte(REG_PANEL_TYPE);
   regLcdMisc = seReadRegByte(REG_LCD_MISC);

   seGetLcdResolution(&LcdWidth, &LcdHeight);
   seGetCrtResolution(&CrtTvWidth, &CrtTvHeight);

   LcdBpp = seGetLcdBitsPerPixel();
   CrtTvBpp = seGetCrtBitsPerPixel();

   regPanelType = seReadRegByte(REG_PANEL_TYPE);
   regDisplayMode = seReadRegByte(REG_DISPLAY_MODE);


   /*
   ** LCD HDP
   */
   LcdHDP = ((seReadRegByte(REG_LCD_HDP) + 1) * 8);

   /*
   ** LCD HNDP
   */
   LcdHNDP = ((seReadRegByte(REG_LCD_HNDP) + 1) * 8);

   /*
   ** LCD VDP
   */
   LcdVDP = seReadRegWord(REG_LCD_VDP0) + 1;

   /*
   ** LCD VNDP
   */
   LcdVNDP = (seReadRegByte(REG_LCD_VNDP) & 0x3f) + 1;


   /*
   ** CRT/TV HDP
   */
   CrtTvHDP = ((seReadRegByte(REG_CRTTV_HDP) + 1) * 8);

   /*
   ** CRT/TV HNDP
   */
   if (regDisplayMode & TV)  /* TV */
      {
      if (seReadRegByte(REG_TV_OUTPUT_CTRL) & 0x01)
         CrtTvHNDP = ((seReadRegByte(REG_CRTTV_HNDP) * 8) + 7);    /* PAL */
      else
         CrtTvHNDP = ((seReadRegByte(REG_CRTTV_HNDP) * 8) + 6);    /* NTSC */
      }
   else
      CrtTvHNDP = ((seReadRegByte(REG_CRTTV_HNDP) + 1) * 8);


   /*
   ** CRT/TV VDP
   */
   CrtTvVDP = seReadRegWord(REG_CRTTV_VDP0) + 1;


   /*
   ** CRT/TV VNDP
   */
   CrtTvVNDP = seReadRegByte(REG_CRTTV_VNDP) + 1;


   /*
   ** Check for "MC" command
   */
   if ('C' == toupper(*(szArg+1)))
      {
      printf("\n"
             "Register Linear Address: %08lX\n"
             "Display Linear Address:  %08lX\n",
#ifdef INTEL_DOS
             HalInfo.dwRegisterAddress,
             HalInfo.dwDisplayMemoryAddress);
#else
             seGetLinearRegAddress(), seGetLinearDisplayAddress());
#endif


      printf("\n"
             "                 LCD Parameters           CRT/TV Parameters\n"
             "-----------------------------------------------------------\n");

      /*
      ** "Resolution:      640 x 480 x 8 bpp        640 x 480 x 8 bpp"
      */
      printf("Resolution:      ");
   
      sprintf(str, "%u x %u x %u bpp", LcdWidth, LcdHeight, LcdBpp);
      printf("%-23s  ", str);
   
      sprintf(str, "%u x %u x %u bpp", CrtTvWidth, CrtTvHeight, CrtTvBpp);
      printf("%s\n", str);
   

      
      /*
      ** "Display:         LCD ENABLED              CRT ENABLED"
      */
      printf("Display:         ");

      if (regDisplayMode & LCD)
         printf("LCD ENABLED ");
      else
         printf("LCD DISABLED");

      printf("             ");

      switch (regDisplayMode & (CRT | TV))
         {
         case CRT:
            printf("CRT ENABLED\n");
            break;

         case TV:
            printf("TV ENABLED (FLICKER FILTER OFF)\n");
            break;

         case (CRT | TV):
            printf("TV ENABLED (FLICKER FILTER ON)\n");
            break;

         default:
            printf("CRT/TV DISABLED\n");
            break;
         }


      /*
      ** "Chrom Filter:    ---                      TV CHROMINANCE FILTER ENABLED"
      */
      printf("Chrom Filter:    ---                      TV CHROMINANCE FILTER ");

      regTvOutputCtrl = seReadRegByte(REG_TV_OUTPUT_CTRL);

      if (regTvOutputCtrl & 0x20)
         printf("ENABLED\n");
      else
         printf("DISABLED\n");


      /*
      ** "Lumin Filter:    ---                      TV LUMINANCE FILTER ENABLED"
      */
      printf("Lumin Filter:    ---                      TV LUMINANCE FILTER ");

      if (regTvOutputCtrl & 0x10)
         printf("ENABLED\n");
      else
         printf("DISABLED\n");


      /*
      ** "TV Output:       ---                      NTSC, S-VIDEO"
      */
      printf("TV Output:       ---                      ");

      if (regTvOutputCtrl & 0x01)
         printf("PAL, ");
      else
         printf("NTSC, ");

      if (regTvOutputCtrl & 0x02)
         printf("S-VIDEO\n");
      else
         printf("COMPOSITE\n");


      /*
      ** "Virtual Width:   640                      640"
      */
      printf("Virtual Width:   ");

      /*
      ** Convert from words to bytes
      */
      VirtWidth = seReadRegWord(REG_LCD_MEM_ADDR_OFFSET0) * 2;

      switch (LcdBpp)
         {
         case 4:
            VirtWidth *= 2;
            break;

         case 8:
         default:
            break;

         case 15:
         case 16:
            VirtWidth /= 2;
            break;
         }

      printf("%-10lu               ", VirtWidth);

      /*
      ** Convert from words to bytes
      */
      VirtWidth = seReadRegWord(REG_CRTTV_MEM_ADDR_OFFSET0) * 2;

      switch (CrtTvBpp)
         {
         case 4:
            VirtWidth *= 2;
            break;

         case 8:
         default:
            break;

         case 15:
         case 16:
            VirtWidth /= 2;
            break;
         }

      printf("%lu\n", VirtWidth);


      /*
      ** "Bytes/Line:      640                      640"
      */
      printf("Bytes/Line:      %-10u               ", seGetLcdBytesPerScanline());
      printf("%u\n", seGetCrtBytesPerScanline());


      /*
      ** "Ink/Cursor:      NO INK/CURSOR            NO INK/CURSOR"
      */
      printf("Ink/Cursor:      ");

      switch (seReadRegByte(REG_LCD_INK_CURS_CTRL) & 0x03)
         {
         case 0x00:
         default:
            printf("NO INK/CURSOR");
            LcdInkCursorMode = MODE_INACTIVE;
            break;

         case 0x01:
            printf("CURSOR       ");
            LcdInkCursorMode = MODE_CURSOR;
            break;

         case 0x02:
            printf("INK LAYER    ");
            LcdInkCursorMode = MODE_INK;
            break;

         case 0x03:
            printf("*ERROR*      ");
            LcdInkCursorMode = MODE_INACTIVE;
            break;
         }

      printf("            ");

      switch (seReadRegByte(REG_CRTTV_INK_CURS_CTRL) & 0x03)
         {
         case 0x00:
         default:
            printf("NO INK/CURSOR\n");
            CrtTvInkCursorMode = MODE_INACTIVE;
            break;

         case 0x01:
            printf("CURSOR\n");
            CrtTvInkCursorMode = MODE_CURSOR;
            break;

         case 0x02:
            printf("INK LAYER\n");
            CrtTvInkCursorMode = MODE_INK;
            break;

         case 0x03:
            printf("*ERROR*\n");
            CrtTvInkCursorMode = MODE_INACTIVE;
            break;
         }


      /*
      ** "Ink/Cursr Addr:  1FF000-1FFFFF            1FF000-1FFFFF"
      */
      regInkCursorAddress = seReadRegByte(REG_LCD_INK_CURS_START_ADDR);
      MemSize = seGetInstalledMemorySize();

      if (regInkCursorAddress == 0)
         InkCursorAddress = MemSize - 1024;
      else
         InkCursorAddress = MemSize - (regInkCursorAddress * 8192L);

      printf("Ink/Cursr Addr:  %06lX-", InkCursorAddress);

      if (LcdInkCursorMode == MODE_INK)
         InkCursorAddress += ((DWORD) LcdWidth * LcdHeight) / 4;
      else
         InkCursorAddress += 1024;    

      --InkCursorAddress;

      printf("%06lX            ", InkCursorAddress);


      regInkCursorAddress = seReadRegByte(REG_CRTTV_INK_CURS_START_ADDR);

      if (regInkCursorAddress == 0)
         InkCursorAddress = MemSize - 1024;
      else
         InkCursorAddress = MemSize - (regInkCursorAddress * 8192L);

      printf("%06lX-", InkCursorAddress);

      if (CrtTvInkCursorMode == MODE_INK)
         InkCursorAddress += ((DWORD) CrtTvWidth * CrtTvHeight) / 4;
      else
         InkCursorAddress += 1024;

      --InkCursorAddress;

      printf("%06lX\n", InkCursorAddress);

      GotMCCommand = TRUE;
      }


   /*
   ** If there is an argument for the pixel depth then set the mode.
   */
   if (TRUE == FindNextArg( &szArg ))
      {
      if ('?' == szArg[0])
         {
         printf("\nM[C] [?] {LCD|CRT|TV} [bpp]"
                "\n"
                "\nThis command will get or set the pixel mode."
                "\n"
                "\nTyping \"M\" will display detailed hardware information (see note below)."
                "\nTyping \"MC\" will display info on cursor/ink layer(s) and TV settings."
                "\n"
                "\nTyping \"M {LCD|CRT|TV} bpp\" will change the bits-per-pixel mode for the"
                "\nselected surface."
                "\nbpp: integer selecting 4, 8, 15, or 16"
                "\n"
                "\nNOTE: When displaying \"PCLK Source for CRT/TV\", \"FF\" refers to the"
                "\n      flicker filter.");
         return;
         }


      if (!strncmp(szArg, "LCD", 3))
         pSetBitsPerPixel = seSetLcdBitsPerPixel;
      else if (!strncmp(szArg, "CRT", 3))
         pSetBitsPerPixel = seSetCrtBitsPerPixel;
      else if (!strncmp(szArg, "TV", 2))
         pSetBitsPerPixel = seSetTvBitsPerPixel;
      else
         {
         DISPLAY_WHAT;
         return;

⌨️ 快捷键说明

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