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

📄 play.c

📁 epson 13506 driver code
💻 C
📖 第 1 页 / 共 5 页
字号:
/*
**===========================================================================
** PLAY.C - Primary executable code for the 13506 PLAY program.
**
** Play is a program which allows a person to 'play' with 13506 memory
** and registers using relatively simple keystroke entries. Operation
** of this version of Play is based on previous Play programs.
**
** This code is based on the 13505 version of play.
**---------------------------------------------------------------------------
** Copyright (c) 1997, 2001 Epson Research and Development, Inc.
** All Rights Reserved.
**===========================================================================
*/

#include <limits.h>
#include <stdarg.h>
#include <string.h>
#include <time.h>

#if !defined(__GNUC__)

#pragma warning(disable:4032)  // disable warning: formal parameter 1 has different type when promoted
#include <conio.h>

#elif !defined(strcmpi)
#define strcmpi stricmp
#endif


#if defined(INTEL_W32) || defined(INTEL_DOS)

#ifndef __GNUC__
#include <conio.h>
#endif

#include <time.h>
#endif

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

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

/*-- Constants ----------------------------------------------------------*/

#define MAX_CMD_LEN  256
#define NUM_LUT      256

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


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

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

static const char Revision[] = "PLAY.C=$Revision: 17 $";

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

#if defined(INTEL_W32) || defined(INTEL_DOS) || defined(MPC8xx)
char *szWhat = "\a\nWhat?";
#else
char *szWhat = "\a\rWhat?";
#endif

BOOL gbQuit = FALSE;                         /* Master quit flag. */

int   gnLineCount = 0;                       /* Variables for ThrottleDisplay() */
int   gnHaltCount = 0;

DWORD dwClkiFreq;
DWORD dwClki2Freq;
DWORD dwBusClkFreq;

#ifndef INTEL_DOS
DWORD regLinearAddr = 0;
#endif

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

/*
** The following definitions are for CalcDisplaySurfaceCombination()
*/
enum
   {
   SURFACE_NONE = -1,
   SURFACE_LCD0_CRTTV1 = 0,
   SURFACE_CRTTV0_LCD1,
   SURFACE_LCD0,
   SURFACE_CRTTV0,
   SURFACE_LCDCRTTV0,

   MAX_SURFACE_COMBINATIONS
   };

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

int CheckMaxPClkRatio(int seReserved1, int *ratio);

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

extern int _RegisterDevice(const LPHAL_STRUCT lpHalInfo);

/*--------------------- Programmable Clock Chip Support ------------------*/

#define CLK_VREG0   0x00
#define CLK_VREG1   0x01
#define CLK_VREG2   0x02
#define CLK_MREG    0x03
#define CLK_PWRDWN  0x04
#define CLK_CTRL    0x06

/*
** FEATCLK can only be used in seProgramClockChip(), argument "reg"
*/
#define FEATCLK     0x07  /* FEATCLK is not programmable */

/*
** seClockChipBits2Freq() uses 5 decimal points
*/
#define CLK_CHIP_FREQ_SCALE   100000L

/*== Start of Code ======================================================*/

int GetSurfaceDisplayMode(int surface)
{
   unsigned regDisplayMode;

   regDisplayMode = seReadRegByte(REG_DISPLAY_MODE);

   switch (CalcDisplaySurfaceCombination())
      {
      case SURFACE_NONE:
         return 0;
         break;

      case SURFACE_LCD0:
         if (surface == 0)
            return LCD;
         break;

      case SURFACE_CRTTV0:
         if (surface == 0)
            return regDisplayMode & (CRT | TV);
         break;

      case SURFACE_LCD0_CRTTV1:
         if (surface == 0)
            return LCD;
         else if (surface == 1)
            return regDisplayMode & (CRT | TV);
         break;

      case SURFACE_CRTTV0_LCD1:
         if (surface == 0)
            return regDisplayMode & (CRT | TV);
         else if (surface == 1)
            return LCD;
         break;

      case SURFACE_LCDCRTTV0:
         if (surface == 0)
            return regDisplayMode & (LCD | CRT | TV);
         break;
      }

   return 0;
}

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

/*
** Note that for 13506PLAY, SURFACE_CRTTV0_LCD1 and SURFACE_LCDCRTTV0 are not supported.
*/
int CalcDisplaySurfaceCombination(void)
{
   unsigned regDisplayMode;

   regDisplayMode = seReadRegByte(REG_DISPLAY_MODE);

   if ((regDisplayMode & LCD) && !(regDisplayMode & (CRT | TV)))
      return SURFACE_LCD0;
   else if (!(regDisplayMode & LCD) && (regDisplayMode & (CRT | TV)))
      return SURFACE_CRTTV0;
   else if ((regDisplayMode & LCD) && (regDisplayMode & (CRT | TV)))
      return SURFACE_LCD0_CRTTV1;

   return SURFACE_NONE;
}

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

void SetActiveSurfaceNumber(int surface)
{
   unsigned regDisplayMode;

   regDisplayMode = seReadRegByte(REG_DISPLAY_MODE);

   switch (CalcDisplaySurfaceCombination())
      {
      case SURFACE_NONE:
         break;

      case SURFACE_LCD0:
         if (surface == 0)
            seSetLcdAsActiveSurface();
         break;

      case SURFACE_CRTTV0:
         if (surface == 0)
            {
            if (regDisplayMode & TV)
               seSetTvAsActiveSurface();
            else
               seSetCrtAsActiveSurface();
            }
         break;

      case SURFACE_LCD0_CRTTV1:
         if (surface == 0)
            seSetLcdAsActiveSurface();
         else if (surface == 1)
            {
            if (regDisplayMode & TV)
               seSetTvAsActiveSurface();
            else
               seSetCrtAsActiveSurface();
            }
         break;

      case SURFACE_CRTTV0_LCD1:
         if (surface == 0)
            {
            if (regDisplayMode & TV)
               seSetTvAsActiveSurface();
            else
               seSetCrtAsActiveSurface();
            }
         else if (surface == 1)
            seSetLcdAsActiveSurface();
         break;

      case SURFACE_LCDCRTTV0:
         if (surface == 0)
            seSetLcdAsActiveSurface();
         break;
      }
}

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

/*
** main()
*/
int main( int argc, PCHAR argv[] )
{
   int  nArg = 1;
   char szArg[MAX_CMD_LEN];

   /*
   ** Set global variables.
   */
   gbQuit = FALSE; 
   gnLineCount = 0;
   gnHaltCount = 0;

   DisplayCopyright();

   switch (_RegisterDevice(&HalInfo))
   {
      case ERR_OK:
         break;

#ifdef INTEL_W32
      case ERR_PCI_DRIVER_NOT_FOUND:
         printf("\nERROR: PCI driver not found.\n");
         return 1;

      case ERR_PCI_BRIDGE_ADAPTER_NOT_FOUND:
         printf("\nERROR: PCI bridge adapter not found.\n");
         return 1;
#endif

      case ERR_UNKNOWN_DEVICE:
         printf("\nERROR: Could not detect S1D13506.\n");
         return 1;
      
      default:
         printf("\nERROR: Could not map memory from evaluation board to host platform.\n");
         return 1;
   }

   dwClkiFreq = HalInfo.dwClkI;
   dwClki2Freq = HalInfo.dwClkI2;
   dwBusClkFreq = HalInfo.dwBusClk;

#ifndef INTEL_DOS
   regLinearAddr = seGetLinearRegAddress();
#endif

DPF( Processing command line arguments );

   /*
   ** Process any command line arguments.
   */
   while ((nArg < argc) && !gbQuit)
   {
      ExecuteCommand( argv[nArg] );
      nArg++;
   }

//DPF( Processing user requests );

   /*
   ** Process user input.
   */
   while (!gbQuit)
   {
      GetNextCommand( szArg );
      ExecuteCommand( szArg );
   }

   return 0;
}

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

/*
** GetNextCommand
**
** Allows the user to enter a string from stdin.
** Returns when the user presses either 'ENTER' or 'ESCAPE'.
**
** Returns:
** Nothing.
** The string pointed at by szArg is modified to contain the
**  user entered string. If 'ESCAPE' is pressed the returned
** string is modified to contain '\0'.
*/
void GetNextCommand( PCHAR szArg )
{
   int   len = 0;

#ifndef BUSTED_UART
   char  ch;
   PCHAR ptr = szArg;
   BOOL  bQuit = FALSE;
#endif

   /*
   ** Reset the (H)alt line count every time we go after input.
   */
   gnLineCount = 0;

   printf( "\n=" );

#ifdef BUSTED_UART
    len = Read (0, szArg, MAX_CMD_LEN-2)-1;
    /*
    ** If 'CR' pressed then if there is no command buffer simply
    ** re-display the user prompt else append a NULL and return.
    */

    if (len == 0)
        {
        printf( "\n=" );
        }
    else
        {
        szArg[len] = '\0';
        }
#else

   /*
   ** Go until we hit a control character.
   */
   while (!bQuit)
   {

      ch = (char) getchar();

      switch (ch)
      {
         case ESC:
            /*
            ** If 'ESC' pressed fill in a dummy return value.
            */
            *szArg = '\0';
            bQuit = TRUE;
            break;

         case LF:
         case CR:
            /*
            ** If 'CR' pressed then if there is no command buffer simply
            ** re-display the user prompt else append a NULL and return.
            */
            if (0 == len)
            {
               printf( "\n=" );
            }
            else
            {
               *ptr = '\0';
               bQuit = TRUE;
            }
            break;

         case BS:
            /*
            ** If 'BS' pressed and we have something in the buffer 
            ** backup one charactor and draw a space.
            */
            if (0 != len)
            {
               putchar(ch);
               putchar(' ');
               putchar(ch);
               ptr--;
               len--;
            }
            break;

         default:
            /*
            ** If there's room add the charactor to the input buffer.
            */
            if (len == MAX_CMD_LEN - 1)
               putchar(BEL);
            else
            {
               *ptr = ch;
               ptr++;
               len++;
//               putchar(ch);
            }
            break;
      }
   }
#endif
}

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

/*
** ExecuteCommand
**
** Performs parsing on the argument passed in.
** After parsing the argument is dispatched to
** the appropriate routine.
**
** Returns: Nothing.
*/
void ExecuteCommand( PCHAR szArg )
{
   int RepeatLastCommand = FALSE;

   SKIP_WHITESPACE( szArg );

   if (*szArg == '!')
      {
      RepeatLastCommand = TRUE;
      ++szArg;
      SKIP_WHITESPACE( szArg );
      }
   else
      RepeatLastCommand = FALSE;

   do
      {
      switch (toupper( *szArg ))
         {
         case 'C':
            HandleClock( szArg );
            break;
   
         case 'S':
            HandleSetFreq( szArg );
            break;
   
         case 'F':
            HandleFill( szArg );
            break;
   
         case 'H':
            SetDisplayThrottle( szArg );
            break;
   
         case 'I':
            HandleInit( szArg );
            break;
   
         case 'L':
            HandleLutIO( szArg );
            break;

         case 'M':
            HandleModeSet( szArg );
            break;

         case 'P':
            HandlePowersave( szArg );
            break;

         case 'Q':
            gbQuit = TRUE;
            RepeatLastCommand = FALSE;
            break;
   
         case 'R':
            HandleRead( szArg );
            break;
   
         case 'W':
            HandleWrite( szArg );
            break;
   
         case 'X':
            HandleRegIO( szArg );
            break;
   
#if defined(INTEL_W32) || defined(INTEL_DOS)
         case 'V':
            HandleVndp( szArg );
            break;
#endif

         case ';':
            break;
   
         case '?':
            DisplayMainHelp();
            RepeatLastCommand = FALSE;
            break;
   
         case '/':

⌨️ 快捷键说明

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