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

📄 play.c

📁 一个图形显示芯片s1d13505的应用程序
💻 C
📖 第 1 页 / 共 3 页
字号:
            {
            DISPLAY_WHAT;
            return;
            }

         /*
         ** Find space or end of string.
         */
         while ((*szArg != 0) && (*szArg != ' '))
            ++szArg;

         /*
         ** Skip over spaces.
         */
         while (*szArg == ' ')
            ++szArg;

         if (*szArg == 0)
            break;
         }
      }


   if (NewDisplayMode != -1)
      DisplayMode = NewDisplayMode;

   if (seSetDisplayMode( gDevID, DisplayMode, DONT_CLEAR_MEM ) != ERR_OK)
      printf("\nERROR: Failed to change to %s mode.\n",
             szDispMode[DisplayMode]);
}

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

/*
**
*/
void HandleRead( PCHAR szArg )
{
   BOOL  bDoWordReads;
   DWORD dwOffset;
   DWORD dwLength;
   DWORD count;
   BYTE  byVal;
   WORD  wVal;

   bDoWordReads = FALSE;
   dwLength = 15;
   count = 0;

   /*
   ** Check if there is a command modifier for word reads.
   */
   if ('W' == toupper(*(szArg + 1)))
      bDoWordReads = TRUE;

   /*
   ** We MUST have an offset.
   */
   if (FALSE == FindNextArg( &szArg ))
   {
      DISPLAY_WHAT;
      return;
   }
   dwOffset = AscToLong( szArg );

   /*
   ** The next argument, if there is one, is the number of
   ** bytes/words to read. If nothing specified then we
   ** will read our default length (16) bytes.
   */
   if (TRUE == FindNextArg( &szArg ))
      dwLength = AscToLong( szArg );

   while (count < dwLength)
   {
      if (0 == (count & 0xF))
      {
         if (TRUE == ThrottleDisplay())
            break;
         printf( "\n %6lX ", dwOffset );
      }
      else
         if (0 == (count & 7))
            printf( " -" );

      if (bDoWordReads)
      {
         if (ERR_OK != seReadDisplayWord( gDevID, dwOffset, &wVal ))
         {
            printf( " Reached End Of Memory" );
            count = dwLength;
            break;
         }
         printf( " %04X", wVal );
         dwOffset +=2;
      }
      else
      {
         if (ERR_OK != seReadDisplayByte( gDevID, dwOffset, &byVal ))
         {
            printf( " Reached End Of Memory" );
            count = dwLength;
            break;
         }
         printf( " %02X", byVal );
         dwOffset++;
      }
      count++;
   }
}

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

void HandleWrite( PCHAR szArg )
{
   BOOL bDoWordWrites;
   DWORD dwOffset;
   BYTE byVal;
   WORD wVal;

   bDoWordWrites = FALSE;

   /*
   ** Check if there is a command modifier for Word writes.
   */
   if ('W' == toupper(*(szArg + 1)))
      bDoWordWrites = TRUE;

   /*
   ** We MUST have an offset.
   */
   if (FALSE == FindNextArg( &szArg ))
   {
      DISPLAY_WHAT;
      return;
   }
   dwOffset = AscToLong( szArg );

   /*
   ** For as long as we find arguments ... write to memory.
   */
   while (FindNextArg( &szArg ))
   {
      wVal = (WORD)AscToLong( szArg );
      byVal = (BYTE)wVal;

      if (bDoWordWrites)
      {
         seWriteDisplayWords( gDevID, dwOffset, wVal, 1 );
         dwOffset+=2;
      }
      else
      {
         seWriteDisplayBytes( gDevID, dwOffset, byVal, 1 );
         dwOffset++;
      }
   }
}

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

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


/*
** HandleModeSet()
**
** Call this funtion to set the colour depth.
*/
void HandleModeSet( PCHAR szArg )
{
   BYTE  by;
   UINT  byBpp;
   UINT  nWidth, nHeight;
   WORD  wNonDispWidth, wNonDispHeight;
   char* pWidth;
   DWORD dwMClk, dwPClk, dwFrameRate;
   WORD  wClkI_Int, wClkI_Frac;
   WORD  wMClk_Int, wMClk_Frac;
   WORD  wPClk_Int, wPClk_Frac;
   WORD  wFrameRate_Int, wFrameRate_Frac;
   DWORD dwRefresh;
   WORD  wRefresh_Int, wRefresh_Frac;
   WORD  wClkDiv;
   BYTE  byDualMode;
   BYTE  byPanelEnabled, byCrtEnabled;
   BYTE  byRegPanelType;
   BYTE  byRegDispMode;
   DWORD lSize;
   int   tmp;
   DWORD VirtWidth;
   BYTE  regInkCursorCtrl;
   BYTE  regInkCursorAddr;
   DWORD InkCursorAddr;
   DWORD MemSize;
   int   InkCursorMode;
   int   ratio;
   UINT  VerticalDisplayPeriod;
   UINT  HorzDisplayPeriod;
   BYTE  regVertDispHeight0;
   BYTE  regVertDispHeight1;
   UINT  BytesPerLine;

   enum
      {
      MODE_INACTIVE,
      MODE_CURSOR,
      MODE_INK
      };

   seGetScreenSize( gDevID, &nWidth, &nHeight );

   seGetReg(gDevID, REG_VERT_DISP_HEIGHT0, &regVertDispHeight0);
   seGetReg(gDevID, REG_VERT_DISP_HEIGHT1, &regVertDispHeight1);
   VerticalDisplayPeriod = ((regVertDispHeight1 << 8) | regVertDispHeight0) + 1;

   seGetReg( gDevID, REG_HORZ_DISP_WIDTH, &by );
   HorzDisplayPeriod = ((by + 1) * 8);


   /*
   ** If there is an argument for the pixel depth then set the mode.
   */
   if (TRUE == FindNextArg( &szArg ))
      {
      byBpp = (BYTE)AscToLong( szArg );

      if ((byBpp != 1) && (byBpp != 2)  && (byBpp != 4) &&
          (byBpp != 8) && (byBpp != 15) && (byBpp != 16))
         {
         DISPLAY_WHAT;
         return;
         }

      /*
      ** It was decided that the 13505 HAL would not refuse an attempt to set
      ** a color depth greater than can be supported by display memory. So...
      ** we have to check for ourselves whether we can fit into memory.
      */
      seGetLastUsableByte( gDevID, &lSize );

      tmp = (byBpp == 15) ? 16 : byBpp;

      if ((((DWORD) nWidth * nHeight * 2L * tmp) / 16)  > lSize)
         printf("\nERROR: Insufficient memory for %d bit-per-pixel.\n", byBpp);
      else
         {
         if (seSetBitsPerPixel(gDevID, byBpp) == ERR_FAILED)
            {
            printf("ERROR: Could not change to %d bit-per-pixel.\n", tmp);
            exit(1);
            }
         }
      }

   /*
   ** Read and interpret registers.
   */

   /*
   ** Display general dimensions.         eg.  "640 x 480 x 8 bpp"
   */
   seGetBitsPerPixel( gDevID, &byBpp );
   seGetReg( gDevID, REG_PANEL_TYPE, &byRegPanelType );
   seGetReg( gDevID, REG_DISPLAY_MODE, &byRegDispMode );


   if (byRegPanelType & 0x02)
      byDualMode = TRUE;
   else
      byDualMode = FALSE;

   printf( "\nResolution:     %d x %d x %d bpp",  nWidth, nHeight, byBpp );

   /*
   ** Display Virtual Width
   */
   seGetReg(gDevID, REG_MEM_ADDR_OFFSET0, &by);
   VirtWidth = by;

   seGetReg(gDevID, REG_MEM_ADDR_OFFSET1, &by);
   VirtWidth |= (by << 8);

   VirtWidth *= 2;  /* convert from words to bytes */

   switch (byBpp)
      {
      case 1:
         VirtWidth *= 8;
         break;

      case 2:
         VirtWidth *= 4;
         break;

      case 4:
         VirtWidth *= 2;
         break;

      case 8:
         break;

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

   printf("\nVirtual Width:  %ld", VirtWidth);

   seGetBytesPerScanline(gDevID, &BytesPerLine);
   printf("\nBytes/Line:     %u", BytesPerLine);

   printf("\nPortrait Mode:  ");

   if (byRegDispMode & 0x80)
      printf("ENABLED");
   else
      printf("DISABLED");

   /*
   ** Ink Layer/Cursor information
   */
   seGetReg(gDevID, REG_INK_CURSOR_CONTROL, &regInkCursorCtrl);

   printf("\nInk/Cursor:     ");
   switch (regInkCursorCtrl >> 6)
      {
      default:
         printf("INACTIVE");
         InkCursorMode = MODE_INACTIVE;
         break;

      case 1:
         printf("CURSOR");
         InkCursorMode = MODE_CURSOR;
         break;

      case 2:
         printf("INK");
         InkCursorMode = MODE_INK;
         break;
      }

   if (InkCursorMode != MODE_INACTIVE)
      {
      seGetReg(gDevID, REG_INK_CURSOR_START_ADDR, &regInkCursorAddr);
      seGetMemSize(gDevID, &MemSize);

      if (regInkCursorAddr == 0)
         InkCursorAddr = MemSize - 1024;
      else
         InkCursorAddr = MemSize - (regInkCursorAddr * 8192L);

      printf("\nInk/Cursr Addr: %06lX", InkCursorAddr);

      if (InkCursorMode == MODE_CURSOR)
         InkCursorAddr += 1024;
      else
         InkCursorAddr += ((DWORD) nWidth * nHeight) / 4;

      --InkCursorAddr;

      printf(" - %06lX", InkCursorAddr);
      }


   /*
   ** Display panel information.          eg.  "Dual 16-bit Color STN"
   */
   if (byRegPanelType & 1)
      pWidth = szWidthTFT[(byRegPanelType >> 4) & 3];
   else
      pWidth = szWidthSTN[(byRegPanelType >> 4) & 3];

   printf( "\nType:           %s %s-BIT %s %s", 
              szSnglDual[(byRegPanelType >> 1) & 1],
                     pWidth,
                     szMonoColor[(byRegPanelType >> 2) & 1],
                     szSTNTFT[byRegPanelType & 1] );

   /*
   ** Display enabled information.        eg.  "Panel: enabled  CRT: enabled"
   */

   if (byRegDispMode & 0x01)
      byPanelEnabled = TRUE;
   else
      byPanelEnabled = FALSE;

   if (byRegDispMode & 0x02)
      byCrtEnabled = TRUE;
   else
      byCrtEnabled = FALSE;

   printf( "\nPanel:          %s"
           "\nCRT:            %s", 
            szEnabled[byRegDispMode & 1],
            szEnabled[(byRegDispMode >> 1) & 1] );

   /*
   ** Display Clocking information.    eg.  "Based on 40MHz input clock:"
   **                                        "MClk = 20MHz  PClk = 20MHz"
   **                                        "Refresh = .5ms"
   */
   seGetReg( gDevID, REG_CLOCK_CONFIG, &by );

   dwMClk = (DWORD)( dwClkI / (((by >> 2) & 1) + 1));
   dwPClk = dwMClk / ((by & 3) + 1);

   wClkI_Int = (WORD) (dwClkI / 1000);
   wClkI_Frac = (WORD) (dwClkI - (wClkI_Int * 1000));

   wMClk_Int = (WORD) (dwMClk / 1000);
   wMClk_Frac = (WORD) (dwMClk - (wMClk_Int * 1000));

   wPClk_Int = (WORD) (dwPClk / 1000);
   wPClk_Frac = (WORD) (dwPClk - (wPClk_Int * 1000));

   printf( "\nInput Clock:    %d.%03d MHz", wClkI_Int, wClkI_Frac );
   printf( "\nMClk:           %d.%03d MHz"
           "\nPClk:           %d.%03d MHz", wMClk_Int, wMClk_Frac, wPClk_Int, wPClk_Frac );


   /*
   ** Display Frame Rate
   */
   seGetReg( gDevID, REG_HORZ_NONDISP_PERIOD, &by );
   wNonDispWidth = (WORD) (((by & 0x1f) + 1) * 8);

   seGetReg( gDevID, REG_VERT_NONDISP_PERIOD, &by );
   wNonDispHeight = (WORD) ((by & 0x3f) + 1);

   dwFrameRate = ((DWORD) dwPClk * 10000L) /
      (((DWORD) HorzDisplayPeriod + wNonDispWidth) *
                ((DWORD) VerticalDisplayPeriod + wNonDispHeight));

   wFrameRate_Int = (WORD) (dwFrameRate / 10);
   wFrameRate_Frac = (WORD) (dwFrameRate - (wFrameRate_Int * 10));

   if (byPanelEnabled && !byCrtEnabled)
      printf( "\nFrame Rate:     %d.%01d Hz (PANEL)", wFrameRate_Int, wFrameRate_Frac);
   else if (!byPanelEnabled && byCrtEnabled)
      printf( "\nFrame Rate:     %d.%01d Hz (CRT)", wFrameRate_Int, wFrameRate_Frac);
   else if (byPanelEnabled && byCrtEnabled)
      printf( "\nFrame Rate:     %d.%01d Hz", wFrameRate_Int, wFrameRate_Frac);

   /*
   ** Display Memory information.         e.g.  "DRAM - EDO - 4 ms refresh
   */
   seGetReg( gDevID, REG_MEMORY_CONFIG, &by );
   wClkDiv = (WORD)(1 << (((by >> 4) & 7) + 6));

   /*
   ** Multiplying by 10 gives one decimal of precision.
   **/
   dwRefresh = (wClkDiv * 256L * 10L) / dwClkI;
   wRefresh_Int = (WORD) (dwRefresh / 10);
   wRefresh_Frac = (WORD) ((dwRefresh - (wRefresh_Int * 10)));

   printf( "\nDRAM:           %s"
           "\nDRAM Refresh:   %d.%01d ms",
            szEDOFPM[by & 1], wRefresh_Int, wRefresh_Frac );

   /*
   ** Check if clocks are too fast for given mode.
   */
   if (CheckMaxPClkRatio(gDevID, &ratio) == ERR_FAILED)
      printf("\n*** WARNING: Clocks are too fast for given mode.");

   printf("\nMinimum PCLK divide required for given mode: PCLK/%d", ratio);


   printf( "\n" );
}

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

/*
** HandlePowerSet()
**
** Enables/disables HW suspend. This feature is accessed by reading or
** writing a particular memory address. The PC ISA PAL decodes this
** address and uses the read/write strobe to enable/disable HW suspend.
*/
void HandlePowerSet ( PCHAR szArg )
{
   /*
   ** We MUST have a power level specifier.
   */
   if (FALSE == FindNextArg( &szArg ))
   {
      DISPLAY_WHAT;
      return;
   }

   if ('0' == *szArg)
   {
      seHWSuspend( gDevID, FALSE );
      printf( "\n       HW Suspend disabled." );
      return;
   }

   if ('1' == *szArg)
   {
      seHWSuspend( gDevID, TRUE );
      printf( "\n       HW Suspend engaged." );
      return;
   }

   DISPLAY_WHAT;
}

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

/*
** HandleIsaBus()
**
** Selects 8 or 16 bit ISA bus. This feature is accessed by reading or
** writing a particular memory address. The PC ISA PAL decodes this
** address and uses the read/write strobe to select 8/16 bits.
*/
void HandleIsaBus ( PCHAR szArg )
{
   /*
   ** We MUST have a specifier for 8 or 16.
   */
   if (FALSE == FindNextArg( &szArg ))
   {
      DISPLAY_WHAT;
      return;
   }


   switch (atoi(szArg))
      {
      case 8:
         seSelectBusWidth(gDevID, 8);
         printf( "\n       8-bit ISA bus selected.");
         return;

      case 16:
         seSelectBusWidth(gDevID, 16);
         printf( "\n       16-bit ISA bus selected.");
         return;
      }

   DISPLAY_WHAT;
}

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

/*
** SetDisplayThrottle()
**
** This function is called to set the number of lines to display before
** ThrottleDisplay() halts the output.
*/
void SetDisplayThrottle( PCHAR szArg )
{
   int nTmp;

   if (TRUE == FindNextArg( &szArg ))
   {
      nTmp = (int)AscToLong( szArg );
      gnHaltCount = nTmp;
   }

   printf( "\nCurrent Halt setting: %d lines", gnHaltCount );
}

⌨️ 快捷键说明

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