eqhost.cpp

来自「声音均衡器的源代码程序」· C++ 代码 · 共 284 行

CPP
284
字号
/* Phimal Graphic Equalization System
 * Host Functions
 *
 * Kamal Swamidoss
 * 28 August 1996
 */

#include <hi54x.h>
#include <stdlib.h>
#include <conio.h>
#include <stdio.h>
#include "eqgrphcs.h" 						 /* graphics                */
#define	band1_addr		0x1100
#define	band2_addr 		0x1101
#define	band3_addr		0x1102
#define	band4_addr		0x1103
#define	band5_addr		0x1104
#define	t_data_addr		0x10ff

/* get_keyboard_command() waits for keyboard input and turns it into
 * a command used by the rest of the application
 */

extern int datareg[], statreg[], ctrlreg[];
extern int pport, portmode,Readdelay;
extern unsigned int  PCBASE;   /* PC base I/O address for hst-EVM comm. */
extern unsigned int  PC_CHA;   /* 0x0240 is the default value.          */
extern unsigned int  PC_CB1;
extern unsigned int  PC_CB2;
extern unsigned int  PC_ST1;
extern unsigned int  PC_ST2;


void hst_init(void);
int  get_keyboard_command(void);
void beep(void);
int current_band = 0;        /* which band is currently highlighted            */
int current_gain[NUM_BANDS]; /* current gain values of each band               */
int first_call   = 1;        /* flag to init. values in get_keyboard_command() */
int x_scale      = 2;        /* horizontal graph scale                         */
int y_scale      = 50;       /* vertical   graph scale                         */

void beep(void)
{
	printf("%c",(int) 7);
	return;
}

void main(void)
{

	int done=0;
	int i;
	unsigned int current_command=0; /* most recent command sent to the EVM */



	/* initialize communications with DSKplus   */
	hst_init();
	set_latch(1,1);
	/* initialize each band's gain value to 0 */
	send_word(t_data_addr,A_SEND);  /* write init values at t_data_addr+1 */
	for (i=0;i<NUM_BANDS;++i){
		send_word(BASE,D_SEND);
		current_gain[i] = (MAX_GAIN-MIN_GAIN)/2;}

	/* try to initialize graphics interface */
	if (!init_graphics()){
		backout(); exit(0);}
	else{}

	send_word(clearHINT,C_SEND);	/*clear HINT to start the DSP program */


	while (!done)
	{
		current_command = get_keyboard_command(); /* wait for user input */

		switch (current_command)
		{
			 case EDONE :               /* done with application */
							  done = 1;
			 case NOP   :               /* no operation          */
							  break;
			 case UP_1:
			 case DN_1:
							  send_word(clearHINT,C_SEND);
							  if(HINT(0xff00)== YES){
									error_message("Communications error.(No ACK)");}
							  else{update(current_command);}
							  ;break;
			 default:break;
	  }

	  if (current_command == EDONE)
		  done = 1;
	}

	close_graphics();
	send_word(clearHINT,C_SEND);	/* turn off DSP interrupts by placing */
	backout();                    /* DSP in a wait for new gain values  */
	exit(0);
}

int get_keyboard_command(void)
{
	char ch;
	int  i;
	unsigned int tmp;
	static int y_vals[TG_WINDOW_SIZE+1];   /* y values of time graph         */
	static int old_y_val;                  /* old y value                    */
	static int current_x;                  /* current x value in time graph  */
	int  current_data;                     /* current data received from EVM */

	if (first_call)
	{
		/* zero the time graph                    */
		for (i=0;i<TG_WINDOW_SIZE+1;++i)
			 y_vals[i] = (TG_BOX_Y2+TG_BOX_Y1)/2;

		current_x = 0;
		old_y_val = (TG_BOX_Y2+TG_BOX_Y1)/2;;
		first_call = 0;
	}

	while (!kbhit())
	{
		/* The following block of code draws the time graph.
		 * The graph is drawn segment by segment. A new segment
		 * (x0,ya)-(x1,yc) is drawn only after the current
		 * segment (x0,ya)-(x1,yb) is erased. The current
		 * y values are stored in the array y_vals[]. The integer
		 * old_y_val holds the value yb for the next erase operation.
		 *
		 * Example:
		 *    y0..y(PAGE_SIZE-1) are stored in y_vals[]
		 *
		 *            y2             y(PAGE_SIZE-1)
		 *        y1          y4
		 *    y0          y3     ...
		 *    x0  x1  x2  x3  x4 ... x(PAGE_SIZE-1)
		 *
		 * When current_x becomes x2:
		 * Set current_data to the next word from the EVM.
		 * Erase the old line (x2,old_y_val)-(x3,y3).
		 * Set old_y_val to y3.
		 * Draw the new line (x2,y2)-(x3,current_data).
		 * Increment current_x to x3.
		 */

		/* get a word from the EVM data channel (channel B)      */
		current_data = RD_HPI(t_data_addr);

		/* boundary condition: if you're at the end of the time
		 * graph window
		 */
		if (current_x == TG_WINDOW_SIZE)
		{
			/* go back to the beginning     */
			current_x = 0;
			/* reset old_y_val              */
			old_y_val = (TG_BOX_Y2+TG_BOX_Y1)/2;
			setcolor(MY_TG_BOXCOLOR);
			/* redraw the time graph window */
			rectangle(TG_BOX_X1,TG_BOX_Y1,TG_BOX_X2,TG_BOX_Y2);
		}

		/* erase the current line segment */
		setcolor(MY_BKGDCOLOR);
		line(x_scale*current_x+TG_BOX_X1,old_y_val,
			  x_scale*current_x+x_scale+TG_BOX_X1,y_vals[current_x+1]);

		/* assign the next y value in the time graph to old_y_val        */
		old_y_val = y_vals[current_x+1];

		/* assign current_data to the next y value in the time graph     */
		y_vals[current_x+1] = current_data;
		/* scale it */
		y_vals[current_x+1] /= y_scale;
		/* shift it */
		y_vals[current_x+1] = (TG_BOX_Y2+TG_BOX_Y1)/2 - y_vals[current_x+1];

		if (y_vals[current_x+1] < TG_BOX_Y1)
			y_vals[current_x+1] = TG_BOX_Y1;
		else if (y_vals[current_x+1] > TG_BOX_Y2)
			y_vals[current_x+1] = TG_BOX_Y2;

		setcolor(MY_TGCOLOR);
		/* draw the new line segment */
		line(x_scale*current_x+TG_BOX_X1,y_vals[current_x],
			  x_scale*current_x+x_scale+TG_BOX_X1,y_vals[current_x+1]);

		/* go to the next x value in the time graph */
		++current_x;
	}

	ch = getch();

	switch (ch)
	{
		case 'p'  :
		case 'P'  :
						error_message("PAUSED");
		case 'q'  :
		case 'Q'  :
		case 'e'  :
		case 'E'  :
		case '\x1B':return EDONE;
		case '\0':	ch = getch();break;
		default:		return NOP;
	}

	switch (ch)
	{
		case RIGHT:
						if (current_band < NUM_BANDS-1)
						{
							unhighlight(current_band,current_gain[current_band],1);
							++current_band;
							highlight(current_band,current_gain[current_band]);
						}
						else{	  beep(); }
						break;
		case LEFT :
						if (current_band > 0)
						{
							unhighlight(current_band,current_gain[current_band],1);
							--current_band;
							highlight(current_band,current_gain[current_band]);
						}
						else{ beep();}	break;
		case UP   :
						if (current_gain[current_band] < MAX_GAIN)
						{
							tmp = UP_1;
							return tmp;
						}
						else
							 beep();
						break;
		case DOWN :
						if (current_gain[current_band] > MIN_GAIN)
						{
							tmp = DN_1;
							return tmp;
						}
						else
							 beep();
						break;
		case PG_UP :
						if (y_scale <= 20)
							break;
						y_scale /= 2;
						setfillstyle(SOLID_FILL,MY_BKGDCOLOR);
						bar(TG_BOX_X1+1,TG_BOX_Y1+1,TG_BOX_X2-1,TG_BOX_Y2-1);
						first_call = 1;
						break;
		case PG_DN :
						if (y_scale >= 200)
							break;
						y_scale *= 2;
						setfillstyle(SOLID_FILL,MY_BKGDCOLOR);
						bar(TG_BOX_X1+1,TG_BOX_Y1+1,TG_BOX_X2-1,TG_BOX_Y2-1);
						first_call = 1;
						break;
	}

	moveto(home_x,home_y);
	return NOP;
}

void hst_init(void)
{
  if((pport=locate_port()) >= 4){
			printf("No DSKplus connection found.\n\n");
			backout();
			exit(0);
  }
  else{}

  return;
}

⌨️ 快捷键说明

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