📄 play.c
字号:
/*
**===========================================================================
** PLAY.C - Primary executable code for the 13505 PLAY program.
**
** Play is a program which allows a person to 'play' with 13505 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 1373 version of play.
**---------------------------------------------------------------------------
** Copyright (c) 1997, 2001 Epson Research and Development, Inc.
** All Rights Reserved.
**===========================================================================
*/
#include <limits.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#ifdef INTEL
#include <stdio.h>
#include <ctype.h>
#include <time.h>
#endif
#include "hal.h"
#include "play.h"
#include "appcfg.h"
#define SKIP_WHITESPACE( a ) while(isspace(*a))a++
#define DISPLAY_WHAT printf( szWhat )
/*-- Constants ----------------------------------------------------------*/
#define MAX_CMD_LEN 256
#define NUM_DAC 256
#define NUM_LUT 256
/*-- Globals ------------------------------------------------------------*/
/***************************/
char szVersion[] = "2.10";
/***************************/
char szWhat[] = "\a\nWhat?";
int gDevID; /* Required by most se????() fns. */
BOOL gbQuit = FALSE; /* Master quit flag. */
int gnLineCount = 0; /* Variables for ThrottleDisplay() */
int gnHaltCount = 0;
DWORD dwClkI;
int CheckMaxPClkRatio(int seReserved1, int *ratio);
/*== Start of Code ======================================================*/
/*
** main()
*/
int main( int argc, PCHAR argv[] )
{
int nArg = 1;
char szArg[MAX_CMD_LEN];
/*
** Set global variables.
*/
gDevID = SE_RESERVED;
gbQuit = FALSE;
gnLineCount = 0;
gnHaltCount = 0;
DPF( About to call seRegisterDevice() );
switch (seRegisterDevice( &HalInfo, &gDevID ))
{
case ERR_OK:
break;
case ERR_UNKNOWN_DEVICE:
printf( "WARNING: Did not find a 13505 device.\n" );
break;
case ERR_TOOMANY_DEVS:
printf( "ERROR: Too many devices registered.\n" );
return 1;
break;
default:
printf( "ERROR: Could not register S1D13505F0A device.\n" );
return 1;
break;
}
dwClkI = HalInfo.dwClkI;
DisplayCopyright();
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 )
{
char ch;
int len = 0;
PCHAR ptr = szArg;
BOOL bQuit = FALSE;
/*
** Reset the (H)alt line count every time we go after input.
*/
gnLineCount = 0;
printf( "\n=" );
/*
** Go until we hit a control character.
*/
while (!bQuit)
{
ch = (char)seGetChar();
switch (ch)
{
case ESC:
/*
** If 'ESC' pressed fill in a dummy return value.
*/
*szArg = '\0';
bQuit = TRUE;
break;
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 LF:
break;
case BS:
/*
** If 'BS' pressed and we have something in the buffer
** backup one charactor and draw a space.
*/
if (0 != len)
{
sePutChar( gDevID, ch );
sePutChar( gDevID, ' ' );
sePutChar( gDevID, ch );
ptr--;
len--;
}
break;
default:
/*
** If there's room add the charactor to the input buffer.
*/
if (len == MAX_CMD_LEN - 1)
sePutChar( gDevID, BEL );
else
{
*ptr = ch;
ptr++;
len++;
sePutChar( gDevID, ch );
}
break;
}
}
}
/*-----------------------------------------------------------------------*/
/*
** ExecuteCommand
**
** Performs parsing on the argument passed in.
** After parsing the argument is dispatched to
** the appropriate routine.
**
** Returns: Nothing.
*/
void ExecuteCommand( PCHAR szArg )
{
SKIP_WHITESPACE( szArg );
switch (toupper( *szArg ))
{
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':
HandlePowerSet( szArg );
break;
case 'B':
HandleIsaBus( szArg );
break;
case 'Q':
gbQuit = TRUE;
break;
case 'R':
HandleRead( szArg );
break;
case 'W':
HandleWrite( szArg );
break;
case 'X':
HandleRegIO( szArg );
break;
#ifdef INTEL
case 'V':
HandleVndp( szArg );
break;
#endif
case ';':
break;
case '?':
DisplayMainHelp();
break;
case '/':
if (szArg[1] == '?')
exit(0);
else
DISPLAY_WHAT;
break;
default:
DISPLAY_WHAT;
break;
}
}
/*-----------------------------------------------------------------------*/
/*
** DisplayCopyright()
*/
void DisplayCopyright( void )
{
const char *szHALVer;
const char *szHALStatus;
const char *szHALStatusRev;
char str[50];
int ver;
if (seGetLibseVersion(&ver) == ERR_OK)
sprintf(str, "[LIBSE %d]", ver);
else
str[0] = 0;
seGetHalVersion( &szHALVer, &szHALStatus, &szHALStatusRev );
printf( "\n13505PLAY - test utility - version %s [HAL %s%s%s] %s",
szVersion, szHALVer, szHALStatus, szHALStatusRev, str );
printf( "\nCopyright (c) 1997, 2001 Epson Research and Development, Inc.");
printf( "\nAll Rights Reserved.\n");
/*
printf( "\n <<<<<<<<<< BETA BETA BETA >>>>>>>>>" );
printf( "\n\n" );
*/
}
/*
** DisplayMainHelp() - displays the primary help screen.
*/
void DisplayMainHelp( void )
{
printf( "\n 13505PLAY - General Command Format" );
printf( "\n" );
printf( "\n B 8|16 - Set ISA bus to 8 or 16 bits" );
printf( "\n F[W] addr addr data - Fill [WORDS] range with data" );
printf( "\n H [lines] - Halt after [lines] of display (0 to disable)" );
printf( "\n I [LCD] [CRT] - Initialize the chip; select output device(s)" );
printf( "\n L index [red green blue] - Read/[Write] LUT values" );
printf( "\n LA - Read all LUT values" );
printf( "\n M [bpp] - Get/Set the pixel depth mode information" );
printf( "\n P 1|0 - 1=Set/0=reset HW suspend (power mode)" );
printf( "\n Q - Quit" );
printf( "\n R[W] addr [count] - Read [count] [WORDS] from addr" );
#ifdef INTEL
printf( "\n V - Calc frame rate from VNDP count");
#endif
printf( "\n W[W] addr data ... - Write[WORDS] of data to addr" );
printf( "\n X[W] index [data] - Read/[Write] byte(s)/word(s) to reg (XW=WORD)" );
printf( "\n XA - Read all registers" );
printf( "\n ? - Help" );
printf( "\n" );
}
/*
** ThrottleDisplay()
**
** Displays a prompt if more than gnLineCount lines have been displayed.
*/
BOOL ThrottleDisplay( void )
{
BOOL bStop;
bStop = FALSE;
gnLineCount++;
if ((gnLineCount == gnHaltCount) && (0 != gnHaltCount))
{
gnLineCount = 0;
if (ERR_OK != printf( "\nPress any key to continue." ))
exit( 1 );
if (ESC == seGetChar())
bStop = TRUE;
}
return bStop;
}
/*-- Conversion Functions -----------------------------------------------*/
/*
** IntToBin - INTeger TO BINary ASCII conversion.
**
** Returns a binary string representing the passed in
** integer (eg. '5' becomes '00000101')
*/
void IntToBin( DWORD nVal, int nWidth, PCHAR szStr )
{
nWidth--;
while (nWidth >= 0)
{
if (nVal & (1L << nWidth))
*szStr = '1';
else
*szStr = '0';
szStr++;
if ((nWidth > 1) && (nWidth % 4 == 0))
*szStr++ = '-';
nWidth--;
}
*szStr = '\0';
}
/*
** AscToUpper()
**
** This function converts an ASCII string to upper case.
*/
void AscToUpper(PCHAR szAscii)
{
while (*szAscii != 0)
{
if ((*szAscii <= 'z') && (*szAscii >= 'a'))
*szAscii -= 'a' - 'A';
++szAscii;
}
}
/*
** AscToLong()
**
** This function converts an ASCII string to a long integer.
** This function should work the same as atol() with the exception
** that the input string is scanned for radix modifiers and handled
** appropriately.
**
** If not specified the input value is assumed to be HEX.
** Octal values are not handled.
**
** Returns:
** 0 if the calls fails - A very broken interface but it follows atol().
*/
long AscToLong( PCHAR szAscii )
{
PCHAR ptr;
ptr = szAscii;
/*
** Scan for a radix modifier.
*/
while (!isspace( *ptr ) && ('\0' != *ptr))
ptr++;
/*
** Handle the appropriate base.
*/
switch (toupper( *(ptr - 1) ))
{
case 'T':
return atol( szAscii );
break;
case 'B':
if (DELIM == *(ptr - 2))
return btol( szAscii );
else
return htol( szAscii );
break;
case 'H':
default:
return htol( szAscii );
break;
}
}
/*
** btol() - Binary ASCII TO Long integer.
*/
long btol( PCHAR szAscii )
{
long lTmp = 0;
char ch;
SKIP_WHITESPACE( szAscii );
/*
** Check that we have no more than 32 'bits' of argument.
*/
if (ArgLen( szAscii ) > 32)
return 0;
while (DELIM != *szAscii)
{
ch = *szAscii;
if ((ch != '0') && (ch != '1'))
return 0;
lTmp = (lTmp << 1) + (ch - '0');
szAscii++;
}
return lTmp;
}
/*
** htol() - Hexadecimal ASCII to Long integer.
*/
long htol( PCHAR szAscii )
{
long lTmp;
char ch;
lTmp = 0;
SKIP_WHITESPACE( szAscii );
/*
** Check that we have no more than 32 'bits' of argument.
*/
if (ArgLen( szAscii ) > 32/4)
return 0;
while (!isspace( *szAscii ) && ('\0' != *szAscii))
{
ch = (char)toupper( *szAscii );
if (!isxdigit( ch ))
return 0;
if ((ch >= 'A') && (ch <= 'F'))
lTmp = lTmp * 16 + 10 + (ch - 'A');
else
lTmp = lTmp * 16 + (ch - '0');
szAscii++;
}
return lTmp;
}
/*
** ArgLen()
**
** Returns:
** The length of the argument pointed to by szArg but
** does not include the final delimiter in the length.
*/
int ArgLen( PCHAR szArg )
{
int nLen = 0;
while (!isspace( *szArg ) && ('\0' != *szArg))
{
szArg++;
nLen++;
}
return nLen;
}
/*-----------------------------------------------------------------------*/
/*
** FindNextArg()
**
** This function scans the input string to see if there is another argument,
** separated by a whitespace, in the string. If an argument is found szArg
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -