📄 play.c
字号:
/*
**===========================================================================
** PLAY.C - Primary executable code for the 13706PLAY program.
**
** 13706Play is a program which allows a person to 'play' with 13706 memory
** and registers using relatively simple keystroke entries. Operation
** of this version of Play is based on previous Play programs.
**---------------------------------------------------------------------------
**
** Created 1999, Epson Research & Development (Vancouver Design Centre)
**
** Copyright (c) 1999, 2001 Epson Research and Development, Inc.
** All Rights Reserved.
**
**---------------------------------------------------------------------------
**
** $Header: /13706/play/play.c 15 11/29/01 5:29p Cindy $
**
** $Revision: 15 $
**
**
**===========================================================================
*/
#include <limits.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include "hal.h"
#include "play.h"
#include "appcfg.h"
#ifdef INCLUDE_CONIO_H
#include <conio.h>
#endif
#ifdef INCLUDE_TIME_H
#include <time.h>
#endif
#define SKIP_WHITESPACE( a ) while(isspace((int)(*(a))))(a)++
#define DISPLAY_WHAT printf(szWhat)
/*-- Constants ----------------------------------------------------------*/
#define MAX_CMD_LEN 256
#define NUM_LUT 256
#define CLK_VREG0 0x00
#define CLK_VREG1 0x01
#define CLK_VREG2 0x02
#define CLK_MREG 0x03
#define CLK_PWRDWN 0x04
#define CLK_CTRL 0x06
#define CLK_CHIP_FREQ_SCALE 100000L
/*
** FEATCLK can only be used in seProgramClockChip(), argument "reg"
*/
#define FEATCLK 0x07 /* FEATCLK is not programmable */
#define MAX_REG_INDEX 0x100
/*-- Globals ------------------------------------------------------------*/
/***************************/
char szVersion[] = "1.05";
/***************************/
char szWhat[] = "\a\nWhat?";
BOOL gbQuit = FALSE; /* Master quit-the-program flag. */
int gnLineCount = 0; /* Variables for HaltDisplay() */
int gnHaltCount;
DWORD dwClkiFreq;
DWORD dwClki2Freq;
DWORD dwBusClkFreq;
#ifdef LINEAR_ADDRESSES_SUPPORTED
DWORD regLinearAddr = 0;
#endif
//-----------------------------------------------------------------------
extern int _RegisterDevice(const LPHAL_STRUCT lpHalInfo);
/*== Start of Code ======================================================*/
/*
** main()
*/
int main( int argc, PCHAR argv[] )
{
int ChipId;
int nArg = 1;
char szArg[MAX_CMD_LEN];
/*
** Initialize the global variables.
*/
gbQuit = FALSE;
gnLineCount = 0;
gnHaltCount = 24;
DisplayCopyright();
//call _RegisterDevice() instead of seRegisterDevice() to avoid read/write to any register
switch (_RegisterDevice(&HalInfo))
{
case ERR_OK:
break;
#ifdef WIN_PCI_DRIVER
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
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;
#ifdef LINEAR_ADDRESSES_SUPPORTED
regLinearAddr = seGetLinearRegAddress();
#endif
if ( seGetId(&ChipId) != ERR_OK )
printf("\n>>> WARNING: DID NOT DETECT S1D13706 <<<\n");
//if ChipId==0, revision 0;
//if ChipId==0, revision 1;
/*
** Process any command line arguments.
*/
while ((nArg < argc) && !gbQuit)
{
ExecuteCommand(argv[nArg]);
nArg++;
}
/*
** 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 line count for (H)alt every time we go for user 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 CR:
case LF:
/*
** 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++;
}
break;
}
}
#endif
}
/*-----------------------------------------------------------------------*/
/*
** ExecuteCommand()
**
** Performs parsing of the argument passed in.
** After parsing the argument is dispatched to the appropriate routine.
*/
void ExecuteCommand(PCHAR szArg)
{
int RetVal;
int RepeatLastCommand = FALSE;
SKIP_WHITESPACE( szArg );
if (*szArg == '!')
{
RepeatLastCommand = TRUE;
++szArg;
SKIP_WHITESPACE( szArg );
}
do
{
switch (toupper(*szArg))
{
case 'C':
HandleClock( szArg );
break;
case 'F':
HandleFill(szArg);
break;
case 'H':
SetDisplayHalt( szArg );
break;
case 'I':
if (1 == strlen(szArg))
{
RetVal = seInitReg(0); //init hardware with default setting.
switch (RetVal)
{
case ERR_OK:
break;
case ERR_FAILED:
printf("Failed to init S1D13706\n");
break;
case ERR_NOT_ENOUGH_MEMORY:
printf("Not Enough Display Memory\n");
break;
case ERR_CLKI_NOT_IN_TABLE:
printf("WARNING: CLKI frequency not in HAL table.\n"
" Program assumes that external oscillator is used.\n");
break;
case ERR_CLKI2_NOT_IN_TABLE:
printf("WARNING: CLKI2 frequency not in HAL table.\n"
" Program assumes that external oscillator is used.\n");
break;
default:
break;
}
}
else
DISPLAY_WHAT;
break;
case 'L':
HandleLutIO(szArg);
break;
case 'M':
HandleModeSet(szArg);
break;
case 'P':
HandlePowersave(szArg);
break;
case 'Q':
gbQuit = TRUE;
break;
case 'R':
HandleRead(szArg);
break;
case 'T':
HandleTest(szArg);
break;
#ifdef INCLUDE_TIME_H
case 'V':
HandleVndp( szArg );
break;
#endif
case 'W':
HandleWrite(szArg);
break;
case 'X':
HandleRegIO(szArg);
break;
case ';':
break;
case '?':
DisplayMainHelp();
break;
case '/':
if (szArg[1] == '?')
exit(0);
else
DISPLAY_WHAT;
break;
default:
DISPLAY_WHAT;
break;
}
} while (RepeatLastCommand
#ifdef INCLUDE_CONIO_H
&& !kbhit()
#endif
);
}
/*------------------------------------------------------------------------*/
/*
** DisplayCopyright()
*/
void DisplayCopyright( void )
{
const char *szHALVer;
const char *szHALStatus;
const char *szHALStatusRev;
seGetHalVersion(&szHALVer, &szHALStatus, &szHALStatusRev);
printf("\n13706PLAY - test utility - version %s (HAL %s%s%s)",
szVersion, szHALVer, szHALStatus, szHALStatusRev);
printf("\nCopyright (c) 1999, 2001 Epson Research and Development, Inc.");
printf("\nAll Rights Reserved.");
printf("\n");
}
/*
** DisplayMainHelp() - displays the primary help screen.
*/
void DisplayMainHelp(void)
{
printf("\n 13706PLAY - General Command Format");
HaltDisplay();
printf("\n ");
HaltDisplay();
printf("\n X index [data] - Read/[Write] to register");
HaltDisplay();
printf("\n XW index [data] - Read/[Write] WORD(s) to reg" );
HaltDisplay();
printf("\n XD index [data] - Read/[Write] DWORD(s) to reg" );
HaltDisplay();
printf("\n XA - Read all registers");
HaltDisplay();
printf("\n L index [data] - Read/[Write] LUT values");
HaltDisplay();
printf("\n LA - read all LUT values");
HaltDisplay();
printf("\n ");
HaltDisplay();
printf("\n F addr1 addr2 data - Fill range with data (BYTE)");
HaltDisplay();
printf("\n FW addr1 addr2 data - Fill range with data (WORD)");
HaltDisplay();
printf("\n FD addr1 addr2 data - Fill range with data (DWORD)");
HaltDisplay();
printf("\n R addr [count] - Read [count] BYTES from addr");
HaltDisplay();
printf("\n RW addr [count] - Read [count] WORDS from addr");
HaltDisplay();
printf("\n RD addr [count] - Read [count] DWORDS from addr");
HaltDisplay();
printf("\n W addr data ... - Write BYTES of data to addr");
HaltDisplay();
printf("\n WW addr data ... - Write WORDS of data to addr");
HaltDisplay();
printf("\n WD addr data ... - Write DWORDS of data to addr");
HaltDisplay();
printf("\n ");
HaltDisplay();
printf("\n I - Initialize the chip");
HaltDisplay();
printf("\n M [bpp] - Get/Set the color depth; display mode information");
HaltDisplay();
printf("\n P [on|off] - Power on or power off the chip");
HaltDisplay();
printf("\n T xx - Test VNDP read for xx seconds");
HaltDisplay();
#ifdef INCLUDE_TIME_H
printf("\n V - Calc actual frame rate by pulling VNDP status bit");
HaltDisplay();
#endif
printf("\n CLKI [?] iFreq - select preset clock frequency for CLKI" );
HaltDisplay();
printf("\n CLKI2 [?] iFreq - select preset clock frequency for CLKI2" );
HaltDisplay();
printf("\n CW word - send 24 bit word to programmable clock" );
HaltDisplay();
printf("\n H [lines] - Halt after [lines] of display (0 to disable)");
HaltDisplay();
printf("\n Q - Quit");
HaltDisplay();
printf("\n ? - Help");
HaltDisplay();
printf("\n ");
HaltDisplay();
printf("\n\nNOTE: To repeat a command forever, put '!' in front of command.");
HaltDisplay();
printf("\n All values default to hexadecimal (or put h at end of number).");
HaltDisplay();
printf("\n To enter decimal numbers, put t at end of number (eg. 100t).");
HaltDisplay();
printf("\n To enter binary numbers, put 'b at end of number (eg. 11110000'b).");
}
/*-----------------------------------------------------------------------*/
/*
** HaltDisplay()
**
** Displays a prompt if more than gnLineCount lines have been displayed.
*/
BOOL HaltDisplay( void )
{
int ch;
BOOL bStop;
bStop = FALSE;
gnLineCount++;
if ((gnLineCount == gnHaltCount) && (0 != gnHaltCount))
{
gnLineCount = 0;
printf( "\nPress any key to continue..." );
ch = getch();
if ((0 == ch) || (0xE0 == ch)) /* We have an extended keystroke */
ch = getch();
if (ESC == ch)
bStop = TRUE;
}
return bStop;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -