/**
*	Title		ST-8000A Production Test Routines
*	Source		STA2.C	RD	1-14-91
*
*	This program is used to control the prom based production test
*	routines for the ST-8000A product.
*
*	V1.1	3-8-91		This revision added the debug option repeated ram test
*				Thid also added commands to the modem board test requested by MT
**/

#include "def.c"
#include <stdio.h>
#include <dos.h>
#include <bios.h>

/* This is the main control routine for the modulator output test routine */

mod_out()
{
	char 	ch;					/* character storage */
	int	stop1 = 0;				/* stop flag */

	while (stop1 != 1)
	{
	  ch = getch();					/* get a keyboard character */
	  if (ch == SP)					/* do the following if the key was the space bar */
	  {
	    mod2();					/* do the last part of the test */
	    if1();					/* setup for input filter test */
	    cur_test = 2;				/* set flag to go back to main menu */
	    stop1 = 1;					/* leave this routine */
	  }

	  if (ch == BS)					/* do the following for the backspace key */
	  {
	    mod2();					/* do the last part of the test */
	    cur_test = 0;				/* set flag to go back to main menu */
	    stop1 = 1;					/* set the stip flag */
	  }

	  if (ch == ESC)				/* do the following for the escape key */
	  {
	    mod2();					/* do the last part of the test */
	    cur_test = 0;				/* set flag to go back to main menu */
	    stop1 = 1;					/* set the stip flag */
	  }

	}
}


/* This routine is the 1st step in the modulator output test */

mod1()
{
	draw_window (MB_T,MB_B,MB_L,MB_R);		/* display the test options window */
	gotoxy (MB_L+2,MB_T+1);
	cprintf ("Modulator Output Test And Alignment");
	gotoxy (IDX,IDY);				/* display test id number */
	cprintf ("3.2.3");

	result_x = MB_L+1;
	result_y = MB_T+3;				/* set echo pointers */
	send_cmd (TC1);					/* send test command 1 */
	test_help();					/* display test window help information */
}

/* This is the modem board test help information */


test_help()
{
	gotoxy (MB_L+2,MB_T+5);
	cprintf ("SPACE To Continue  BS To Back Up  ESC To Quit");		/* display step instructions */
}

/* This routine is the modulator output test last step */

mod2()
{
	puttext (MB_L,MB_T,MB_R,MB_B,buf);		/* restore the display screen */
	gotoxy (MMENU_LEFT+39,MMENU_TOP+2);
	cprintf (" ----- Done");			/* mark test as completed */
}


/* This routine controls the input filter test */

if_test()
{
	int	stop1 = 0;				/* stop flag */
	char	ch;					/* character storage */

	while (stop1 != 1)
	{
	  ch = getch();					/* wait for a keypress */
	  if (ch == ESC)				/* do the following for the escape key */
	  {
	    puttext (MB_L,MB_T,MB_R,MB_B,buf);		/* erase if test window */
	    cur_test = 0;				/* set flag to exit the process test routine */
	    stop1 = 1;					/* set flag to exit this routine */
	  }

	  if (ch == BS || ch == SP)			/* do the following for bs and space keys */
	  {
	    if (ch == BS) sub_test--;			/* decrement test pointer for back space */
	    if (ch == SP) sub_test++;			/* increment test pointer for space bar */

	    switch (sub_test)
	    {
	      case 0:
	      puttext (MB_L,MB_T,MB_R,MB_B,buf);	/* erase if test window */
	      cur_test = 1;				/* set flag to go back to modulator test */
	      mod1();					/* display modulator test window */
	      stop1 = 1;				/* exit this test */
	      break;

	      case 1:
	      gotoxy (IDX,IDY);				/* display test id number */
	      cprintf ("3.3.2");
	      tc1_only();				/* send test command 1 */
	      if5();					/* set bit mode to to */
	      break;

	      case 2:
	      gotoxy (IDX,IDY);				/* display test id number */
	      cprintf ("3.3.3");
	      if2();					/* do step 2 in test */
	      break;

	      case 3:
	      if3();					/* do step 3 in the test */
	      break;

	      case 4:
	      if4();					/* do step 4 in the test */
	      break;

	      case 5:
	      gotoxy (IDX,IDY);				/* display test id number */
	      cprintf ("3.3.3");
	      if5();					/* do step 5 in the test */
	      break;

	      case 6:
	      gotoxy (IDX,IDY);				/* display test id number */
	      cprintf ("3.3.5");
	      tc1_only();				/* send test command 1 */
	      break;

	      case 7:
	      if6();					/* do last step in this test */
	      mark1();					/* set up for the mark filter test */
	      cur_test = 3;				/* go on to mark filter test */
	      stop1 = 1;
	      break;

	    }
	  }
	}
}

/* input filter test step 1 */

if1()
{
	draw_window (MB_T,MB_B,MB_L,MB_R);		/* display the test window */
	gotoxy (MB_L+2,MB_T+1);
	cprintf ("Bit CAL Alignment");			/* display the test header */
	gotoxy (IDX,IDY);				/* display test id number */
	cprintf ("3.3.2");
	result_x = MB_L+1;
	result_y = MB_T+3;				/* set command echo pointers */
	send_cmd (TC1);					/* send test command 1 */
	if5();						/* set bit mode to t0 */
	test_help();					/* display test help info */
	sub_test = 1;					/* set test in progress pointer */
}


/* Input filter test step 2 */

if2()
{
	erase_tc1();					/* clear the command line */
	gotoxy (MB_L+2,MB_T+3);
	cprintf ("Bit Mode Internal 0dBm");		/* display bit mode setting */
	result_x = MB_L+25;
	send_cmd (T5);					/* send the t5 command */
}

/* Input filter test step 3 */

if3()
{
	gotoxy (MB_L+2,MB_T+3);
	cprintf ("Bit Mode Internal -20dBm  ");		/* display bit mode setting */
	result_x = MB_L+28;
	send_cmd (T6);					/* send the t6 command */
}

/* Input filter test step 4 */

if4()
{
	gotoxy (MB_L+2,MB_T+3);
	cprintf ("Bit Mode Internal -45dBm  ");		/* display bit mode setting */
	result_x = MB_L+28;
	send_cmd (T7);					/* send the t7 command */
}

/* Input filter test step 5 */

if5()
{
	erase_tc1();					/* clear the command line */
	gotoxy (MB_L+2,MB_T+3);
	cprintf ("Bit Mode External ");			/* display bit mode setting */
	result_x = MB_L+20;
	send_cmd (T0);					/* send the t0 command */
}

/* This routine sends test command 1 only */

tc1_only()
{
	result_x = MB_L+1;
	send_cmd (TC1);					/* send test command 1 */
}


/* This routine sends test command 2 only */

tc2_only()
{
	erase_tc1();					/* clear the command line */
	result_x = MB_L+2;
	send_cmd (TC2);					/* send test command 2 */
}



/* This is the last step in the input filter test */

if6()
{
	puttext (MB_L,MB_T,MB_R,MB_B,buf);		/* restore the display screen */
	gotoxy (MMENU_LEFT+21,MMENU_TOP+3);
	cprintf (" ----------------------- Done");	/* mark test as completed */

}


/* This routine controls the mark filter alignment test */

mark_test()
{
	int	stop1 = 0;				/* stop flag */
	char	ch;					/* character storage */

	while (stop1 != 1)
	{
	  ch = getch();					/* wait for a keypress */
	  if (ch == ESC)				/* do the following for the escape key */
	  {
	    puttext (MB_L,MB_T,MB_R,MB_B,buf);		/* erase if test window */
	    cur_test = 0;				/* set flag to exit the process test routine */
	    stop1 = 1;					/* set flag to exit this routine */
	  }

	  if (ch == BS || ch == SP)			/* do the following for bs and space keys */
	  {
	    if (ch == BS) sub_test--;			/* decrement test pointer for back space */
	    if (ch == SP) sub_test++;			/* increment test pointer for space bar */

	    switch (sub_test)
	    {
	      case 0:
	      puttext (MB_L,MB_T,MB_R,MB_B,buf);		/* erase if test window */
	      draw_window (MB_T,MB_B,MB_L,MB_R);	/* display the test options window */
	      gotoxy (MB_L+2,MB_T+1);
	      cprintf ("Bit CAL Alignment");		/* display the test header */
	      tc1_only();
	      test_help();
	      cur_test = 2;				/* set flag to go back to input filter test */
	      sub_test = 6;				/* point to the last test in the if test */
	      gotoxy (IDX,IDY);				/* display test id number */
	      cprintf ("3.3.5");
	      stop1 = 1;				/* exit this test */
	      break;

	      case 1:
	      tc1_only();				/* send test command 1 */
	      break;

	      case 2:
	      baud30();					/* set baud rate to 30 */
	      break;

	      case 3:
	      baud86();					/* set baud rate to 86 */
	      break;

	      case 4:
	      baud114();				/* set baud rate to 114 */
	      break;

	      case 5:
	      baud145();				/* set baud rate to 145 */
	      break;

	      case 6:
	      baud170();				/* set baud rate to 170 */
	      break;

	      case 7:
	      baud202();				/* set the baud rate to 202 */
	      break;

	      case 8:
	      baud253();				/* set baud rate to 253 */
	      break;

	      case 9:
	      baud327();				/* set baud rate to 327 */
	      break;

	      case 10:
	      baud337();				/* set the baud rate to 337 */
	      break;

	      case 11:
	      baud443();				/* set baud rate to 443 */
	      break;

	      case 12:
	      baud540();				/* set baud rate to 540 */
	      break;

	      case 13:
	      baud625();				/* set baud rate to 625 */
	      break;

	      case 14:
	      baud689();				/* set baud rate to 689 */
	      break;

	      case 15:
	      baud760();				/* set baud rate to 760 */
	      break;

	      case 16:
	      baud854();				/* set baud rate to 854 */
	      break;

	      case 17:
	      baud952();				/* set baud rate to 952 */
	      break;

	      case 18:
	      tc1_only();				/* send test command 1 */
	      break;

	      case 19:
	      baud30();					/* set baud rate to 30 */
	      break;

	      case 20:
	      baud327();				/* set baud rate to 327 */
	      break;

	      case 21:
	      baud337();				/* set baud rate to 337 */
	      break;

	      case 22:
	      baud952();				/* set baud rate to 952 */
	      break;

	      case 23:
	      baud30();					/* set baud rate to 30 */
	      break;

	      case 24:
	      baud327();				/* set baud rate to 327 */
	      break;

	      case 25:
	      baud337();				/* set baud rate to 337 */
	      break;

	      case 26:
	      baud952();				/* set baud rate to 952 */
	      break;

	      case 27:
	      mark2();					/* finish the mark filter test */
	      cur_test = 4;
	      space1();					/* set up for space filter test */
	      stop1 = 1;
	      break;
	    }
	  }
	}
}

/* This is the 1st step in the mark filter test */

mark1()
{
	draw_window (MB_T,MB_B,MB_L,MB_R);		/* display the test options window */
	gotoxy (MB_L+2,MB_T+1);
	cprintf ("Mark Filter Alignment Test ");	/* display the test header */
	gotoxy (IDX,IDY);				/* display test id number */
	cprintf ("3.3.6");
	result_x = MB_L+1;
	result_y = MB_T+3;				/* set echo pointers */
	send_cmd (TC1);					/* send test command 1 */
	test_help();					/* display the test help information */
	sub_test = 1;					/* set the sub test pointer */
}

baud30()
{
	erase_tc1();
	gotoxy (MB_L+2,MB_T+3);
	cprintf ("Baud = 30 ");	      			/* display baud setting */
	result_x = MB_L+13;
	send_cmd (C01);					/* send the C01 command */
	result_x = MB_L+13;
	send_cmd (B30);					/* send the baud 30 command */
}

baud75()
{
	erase_tc1();					/* clear the command line */
	gotoxy (MB_L+2,MB_T+3);
	cprintf ("Baud = 75");				/* display the baud setting */
	result_x = MB_L+13;
	send_cmd (C01);
	result_x = MB_L+13;
	send_cmd (B75);
}


baud86()
{
	erase_tc1();					/* clear the command line */
	gotoxy (MB_L+2,MB_T+3);
	cprintf ("Baud = 86  ");      			/* display baud setting */
	result_x = MB_L+13;
	send_cmd (B86);					/* send the baud command */
}

baud114()
{
	gotoxy (MB_L+2,MB_T+3);
	cprintf ("Baud = 114");	      			/* display baud setting */
	result_x = MB_L+13;
	send_cmd (B114);				/* send the baud command */
}

baud145()
{
	gotoxy (MB_L+2,MB_T+3);
	cprintf ("Baud = 145");	      			/* display baud setting */
	result_x = MB_L+13;
	send_cmd (B145);				/* send the baud command */
}

baud170()
{
	gotoxy (MB_L+2,MB_T+3);
	cprintf ("Baud = 170");	      			/* display baud setting */
	result_x = MB_L+13;
	send_cmd (B170);				/* send the baud command */
}

baud202()
{
	gotoxy (MB_L+2,MB_T+3);
	cprintf ("Baud = 202");	      			/* display baud setting */
	result_x = MB_L+13;
	send_cmd (B202);				/* send the baud command */
}

baud253()
{
	gotoxy (MB_L+2,MB_T+3);
	cprintf ("Baud = 253");	      			/* display baud setting */
	result_x = MB_L+13;
	send_cmd (B253);				/* send the baud command */
}

baud327()
{
	gotoxy (MB_L+2,MB_T+3);
	cprintf ("Baud = 327");	      			/* display baud setting */
	result_x = MB_L+13;
	send_cmd (B327);				/* send the baud command */
}

baud337()
{
	gotoxy (MB_L+2,MB_T+3);
	cprintf ("Baud = 337");	      			/* display baud setting */
	result_x = MB_L+13;
	send_cmd (B337);				/* send the baud command */
}

baud443()
{
	gotoxy (MB_L+2,MB_T+3);
	cprintf ("Baud = 443");	      			/* display baud setting */
	result_x = MB_L+13;
	send_cmd (B443);				/* send the baud command */
}

baud540()
{
	gotoxy (MB_L+2,MB_T+3);
	cprintf ("Baud = 540");	      			/* display baud setting */
	result_x = MB_L+13;
	send_cmd (B540);				/* send the baud command */
}

baud625()
{
	gotoxy (MB_L+2,MB_T+3);
	cprintf ("Baud = 625");	      			/* display baud setting */
	result_x =MB_L+13;
	send_cmd (B625);				/* send the baud command */
}

baud689()
{
	gotoxy (MB_L+2,MB_T+3);
	cprintf ("Baud = 689");	      			/* display baud setting */
	result_x = MB_L+13;
	send_cmd (B689);				/* send the baud command */
}

baud760()
{
	gotoxy (MB_L+2,MB_T+3);
	cprintf ("Baud = 760");	      			/* display baud setting */
	result_x = MB_L+13;
	send_cmd (B760);				/* send the baud command */
}

baud854()
{
	gotoxy (MB_L+2,MB_T+3);
	cprintf ("Baud = 854");	      			/* display baud setting */
	result_x = MB_L+13;
	send_cmd (B854);				/* send the baud command */
}


baud952()
{
	erase_tc1();					/* clear the command line */
	gotoxy (MB_L+2,MB_T+3);
	cprintf ("Baud = 952");	      			/* display baud setting */
	result_x = MB_L+13;
	send_cmd (B952);				/* send the baud command */
}


baud1200()
{
	erase_tc1();					/* clear the command line */
	gotoxy (MB_L+2,MB_T+3);
	cprintf ("Baud = 1200");			/* display baud setting */
	result_x = MB_L+13;
	send_cmd (C01);
	send_cmd (B1200);				/* set channel 1 for 1200 baud */
}



/* This is the last step in mark filter test */

mark2()
{
	puttext (MB_L,MB_T,MB_R,MB_B,buf);		/* restore the display screen */
	gotoxy (MMENU_LEFT+30,MMENU_TOP+4);
	cprintf (" -------------- Done");		/* mark test as completed */

}


/* This routine controls the space filter alignment test */

space_test()
{
	int	stop1 = 0;				/* stop flag */
	char	ch;					/* character storage */

	while (stop1 != 1)
	{
	  ch = getch();					/* wait for a keypress */
	  if (ch == ESC)				/* do the following for the escape key */
	  {
	    puttext (MB_L,MB_T,MB_R,MB_B,buf);		/* erase if test window */
	    cur_test = 0;				/* set flag to exit the process test routine */
	    stop1 = 1;					/* set flag to exit this routine */
	  }

	  if (ch == BS || ch == SP)			/* do the following for bs and space keys */
	  {
	    if (ch == BS) sub_test--;			/* decrement test pointer for back space */
	    if (ch == SP) sub_test++;			/* increment test pointer for space bar */

	    switch (sub_test)
	    {
	      case 0:
	      puttext (MB_L,MB_T,MB_R,MB_B,buf);	/* erase if test window */
	      draw_window (MB_T,MB_B,MB_L,MB_R);	/* display the test options window */
	      gotoxy (MB_L+2,MB_T+1);
	      cprintf ("Mark Filter Alignment Test ");	/* display the test header */
	      gotoxy (IDX,IDY);				/* display test id number */
	      cprintf ("3.3.6");
	      baud952();
	      test_help();
	      cur_test = 3;				/* set flag to go back to mark filter test */
	      sub_test = 26;				/* point to the last test */
	      stop1 = 1;				/* exit this test */
	      break;

	      case 1:
	      tc1_only();				/* send test command 1 */
	      erase_tc1();				/* clear the command line */
	      result_x = MB_L+1;
	      send_cmd (C01);				/* send channel 1 command */
	      send_cmd (S2000);				/* set space to 2000 hz */
	      send_cmd (M3000);				/* set mark to 3000 hz */
	      break;

	      case 2:
	      baud30();					/* set baud rate to 30 */
	      break;

	      case 3:
	      baud86();					/* set baud rate to 86 */
	      break;

	      case 4:
	      baud114();				/* set baud rate to 114 */
	      break;

	      case 5:
	      baud145();				/* set baud rate to 145 */
	      break;

	      case 6:
	      baud170();				/* set baud rate to 170 */
	      break;

	      case 7:
	      baud202();				/* set the baud rate to 202 */
	      break;

	      case 8:
	      baud253();				/* set baud rate to 253 */
	      break;

	      case 9:
	      baud327();				/* set baud rate to 327 */
	      break;

	      case 10:
	      baud337();				/* set the baud rate to 337 */
	      break;

	      case 11:
	      baud443();				/* set baud rate to 443 */
	      break;

	      case 12:
	      baud540();				/* set baud rate to 540 */
	      break;

	      case 13:
	      baud625();				/* set baud rate to 625 */
	      break;

	      case 14:
	      baud689();				/* set baud rate to 689 */
	      break;

	      case 15:
	      baud760();				/* set baud rate to 760 */
	      break;

	      case 16:
	      baud854();				/* set baud rate to 854 */
	      break;

	      case 17:
	      baud952();				/* set baud rate to 952 */
	      break;

	      case 18:
	      baud30();					/* set baud rate to 30 */
	      break;

	      case 19:
	      baud327();				/* set baud rate to 327 */
	      break;

	      case 20:
	      baud337();				/* set baud rate to 337 */
	      break;

	      case 21:
	      baud952();				/* set baud rate to 952 */
	      break;

	      case 22:
	      baud30();					/* set baud rate to 30 */
	      break;

	      case 23:
	      baud327();				/* set baud rate to 327 */
	      break;

	      case 24:
	      baud337();				/* set baud rate to 337 */
	      break;

	      case 25:
	      baud952();				/* set baud rate to 952 */
	      break;

	      case 26:
	      space2();					/* finish the mark filter test */
	      cur_test = 5;
	      amh1();					/* set up for amh test */
	      stop1 = 1;
	      break;
	    }
	  }
	}
}

/* This is the 1st step in the space filter test */

space1()
{
	draw_window (MB_T,MB_B,MB_L,MB_R);		/* display the test options window */
	gotoxy (MB_L+2,MB_T+1);
	cprintf ("Space Filter Alignment Test ");	/* display the test header */
	gotoxy (IDX,IDY);				/* display test id number */
	cprintf ("3.3.7");
	result_x = MB_L+1;
	result_y = MB_T+3;				/* set echo pointers */
	send_cmd (TC1);					/* send test command 1 */
	erase_tc1();					/* clear command line */
	result_x = MB_L+1;				/* reset echo pointer */
	send_cmd (C01);					/* send channel 1 command */
	send_cmd (S2000);				/* set space to 2000 hz */
	send_cmd (M3000);				/* set mark to 3000 hz */
	test_help();					/* display the test help information */
	sub_test = 1;					/* set the sub test pointer */
}



/* This is the last step in space filter test */

space2()
{
	puttext (MB_L,MB_T,MB_R,MB_B,buf);		/* restore the display screen */
	gotoxy (MMENU_LEFT+31,MMENU_TOP+5);
	cprintf (" ------------- Done");		/* mark test as completed */

}



/* This routine controls the amh calibration  gain control tests */


amh_test()
{
	int	stop1 = 0;				/* stop flag */
	char	ch;					/* character storage */

	while (stop1 != 1)
	{
	  ch = getch();					/* wait for a keypress */
	  if (ch == ESC)				/* do the following for the escape key */
	  {
	    puttext (MB_L,MB_T,MB_R,MB_B,buf);		/* erase if test window */
	    cur_test = 0;				/* set flag to exit the process test routine */
	    stop1 = 1;					/* set flag to exit this routine */
	  }

	  if (ch == BS || ch == SP)			/* do the following for bs and space keys */
	  {
	    if (ch == BS) sub_test--;			/* decrement test pointer for back space */
	    if (ch == SP) sub_test++;			/* increment test pointer for space bar */

	    switch (sub_test)
	    {
	      case 0:
	      puttext (MB_L,MB_T,MB_R,MB_B,buf);	/* erase if test window */
	      draw_window (MB_T,MB_B,MB_L,MB_R);	/* display the test options window */
	      gotoxy (MB_L+2,MB_T+1);
	      cprintf ("Space Filter Alignment Test ");	/* display the test header */
	      gotoxy (IDX,IDY);				/* display test id number */
	      cprintf ("3.3.7");
	      baud952();
	      test_help();
	      cur_test = 4;				/* set flag to go back to space filter test */
	      sub_test = 25;				/* point to the last test */
	      stop1 = 1;				/* exit this test */
	      break;

	      case 1:
	      gotoxy (IDX,IDY);				/* display test id number */
	      cprintf ("3.3.8");
	      tc1_only();				/* send test command 1 */
	      baud75();					/* set for 75 baud */
	      break;

	      case 2:
	      gotoxy (IDX,IDY);				/* display test id number */
	      cprintf ("3.3.9 ");
	      amh2();					/* do step 2 in test */
	      break;

	      case 3:
	      amh3();					/* do step 3 in the test */
	      break;

	      case 4:
	      amh4();
	      cur_test = 6;				/* go back */
	      lpf1();					/* set up to go to lpf test */
	      stop1 = 1;
	      break;

	    }
	  }
	}
}

amh1()
{
	draw_window (MB_T,MB_B,MB_L,MB_R);		/* display the test window */
	gotoxy (MB_L+2,MB_T+1);
	cprintf ("AMH Calibration - Gain Control Test");	/* display the test header */
	gotoxy (IDX,IDY);				/* display test id number */
	cprintf ("3.3.8");
	result_x = MB_L+1;
	result_y = MB_T+3;				/* set echo pointers */
	send_cmd (TC1);					/* send test command 1 */
	erase_tc1();
	baud75();
	test_help();
	sub_test = 1;
}

amh2()
{
	tc1_only();					/* send test command 1 */
	baud75();					/* set for 75 baud */
}


amh3()
{
	tc1_only();					/* send test command 1 */
	erase_tc1();
	result_x = MB_L+2;
	send_cmd (C01);
	send_cmd (B75);					/* set channel 1 for 75 baud */
	send_cmd (S2000);				/* set space to 2000 hz */
	send_cmd (M3000);				/* set mark for 3000 hz */
}

amh4()
{
	puttext (MB_L,MB_T,MB_R,MB_B,buf);
	gotoxy (MMENU_LEFT+40,MMENU_TOP+6);
	cprintf (" ---- Done");

}

/* This routine controls the low pass filter - detect select - hs demod test */

lpf_test()
{
	int	stop1 = 0;				/* stop flag */
	char	ch;					/* character storage */

	while (stop1 != 1)
	{
	  ch = getch();					/* wait for a keypress */
	  if (ch == ESC)				/* do the following for the escape key */
	  {
	    puttext (MB_L,MB_T,MB_R,MB_B,buf);		/* erase if test window */
	    cur_test = 0;				/* set flag to exit the process test routine */
	    stop1 = 1;					/* set flag to exit this routine */
	  }

	  if (ch == BS || ch == SP)			/* do the following for bs and space keys */
	  {
	    if (ch == BS) sub_test--;			/* decrement test pointer for back space */
	    if (ch == SP) sub_test++;			/* increment test pointer for space bar */

	    switch (sub_test)
	    {
	      case 0:
	      puttext (MB_L,MB_T,MB_R,MB_B,buf);	/* erase if test window */
	      draw_window (MB_T,MB_B,MB_L,MB_R);	/* display the test options window */
	      gotoxy (MB_L+2,MB_T+1);
	      cprintf ("AMH Calibration - Gain Control Test");	/* display the test header */
	      gotoxy (IDX,IDY);				/* display test id number */
	      cprintf ("3.3.9 ");
	      amh3();
	      test_help();
	      cur_test = 5;				/* set flag to go back to space filter test */
	      sub_test = 3;				/* point to the last test */
	      stop1 = 1;				/* exit this test */
	      break;

	      case 1:
	      erase_tc1();				/* clear the command line */
	      tc1_only();				/* send test command 1 */
	      break;

	      case 2:
	      lpf2();					/* do step 2 */
	      break;

	      case 3:
	      gotoxy (IDX,IDY);				/* display test id number */
	      cprintf ("3.3.10");
	      tc1_only();				/* do step 3 */
	      break;

	      case 4:
	      gotoxy (IDX,IDY);				/* display test id number */
	      cprintf ("3.3.11");
	      tc2_only();				/* do step 4 */
	      break;

	      case 5:
	      lpf3();					/* do step 5 */
	      break;

	      case 6:
	      lpf4();					/* do step 6 */
	      break;

	      case 7:
	      gotoxy (IDX,IDY);				/* display test id number */
	      cprintf ("3.3.11");
	      lpf5();					/* do step 7 */
	      break;

	      case 8:
	      gotoxy (IDX,IDY);				/* display test id number */
	      cprintf ("3.3.12");
	      tc2_only();
	      baud1200();
	      send_cmd (C02);				/* 11 */
	      send_cmd (B1200);				/* 11 set channel 2 to 1200 baud */
	      break;

	      case 9:
	      lpf6();
	      mio1();					/* set up for mio test */
	      cur_test = 7;				/* do the last step */
	      stop1 = 1;
	      break;
	    }
	  }
	}
}


lpf1()
{
	draw_window (MB_T,MB_B,MB_L,MB_R);		/* display the test window */
	gotoxy (MB_L+2,MB_T+1);
	cprintf ("Low Pass Filter-Detect Select-HS Demod");	/* display the test header */
	gotoxy (IDX,IDY);				/* display test id number */
	cprintf ("3.3.10");
	result_x = MB_L+1;
	result_y = MB_T+3;				/* set the echo pointers */
	send_cmd (TC1);					/* send test command 1 */
	sub_test = 1;					/* set sub test pointer */
	test_help();					/* display test information */
}

lpf2()
{
	erase_tc1();					/* erase test command 1 */
	result_x = MB_L+2;
	send_cmd (S2000);
	send_cmd (M3000);
}


lpf3()
{
	erase_tc1();					/* erase command echo line */
	gotoxy (MB_L+2,MB_T+3);
	cprintf ("MK Only");
	result_x = MB_L+10;				/* set for mark only mode */
	send_cmd (J1);
}

lpf4()
{
	gotoxy (MB_L+2,MB_T+3);
	cprintf ("SP Only");
	result_x = MB_L+10;				/* set for space only mode */
	send_cmd (J2);
}


lpf5()
{
	erase_tc1();					/* clear the command line */
	gotoxy (MB_L+2,MB_T+3);
	cprintf ("FSK    ");
	result_x = MB_L+10;				/* set for fsk mode */
	send_cmd (J0);
}


lpf6()
{
	puttext (MB_L,MB_T,MB_R,MB_B,buf);
	gotoxy (MMENU_LEFT+42,MMENU_TOP+7);
	cprintf (" -- Done");
}

/* This routine controls the modem io test */

mio_test()
{
	int	stop1 = 0;				/* stop flag */
	char	ch;					/* character storage */

	while (stop1 != 1)
	{
	  ch = getch();					/* wait for a keypress */
	  if (ch == ESC)				/* do the following for the escape key */
	  {
	    puttext (MB_L,MB_T,MB_R,MB_B,buf);		/* erase if test window */
	    cur_test = 0;				/* set flag to exit the process test routine */
	    stop1 = 1;					/* set flag to exit this routine */
	  }

	  if (ch == BS || ch == SP)			/* do the following for bs and space keys */
	  {
	    if (ch == BS) sub_test--;			/* decrement test pointer for back space */
	    if (ch == SP) sub_test++;			/* increment test pointer for space bar */

	    switch (sub_test)
	    {
	      case 0:
	      puttext (MB_L,MB_T,MB_R,MB_B,buf);	/* erase if test window */
	      draw_window (MB_T,MB_B,MB_L,MB_R);	/* display the test options window */
	      gotoxy (MB_L+2,MB_T+1);
	      cprintf ("Low Pass Filter-Detect Select-HS Demod");	/* display the test header */
	      gotoxy (IDX,IDY);				/* display test id number */
	      cprintf ("3.3.12");
	      tc2_only();
	      baud1200();
	      test_help();
	      cur_test = 6;				/* set flag to go back to space filter test */
	      sub_test = 8;				/* point to the last test */
	      stop1 = 1;				/* exit this test */
	      break;

	      case 1:
	      tc2_only();				/* send test command 2 */
	      break;

	      case 2:
	      gotoxy (IDX,IDY);				/* display test id number */
	      cprintf ("3.4.1");
	      baud1200();
	      send_cmd (C02);				/* 11 */
	      send_cmd (B1200);				/* 11 set channel 2 to 1200 baud */
	      break;

	      case 3:
	      gotoxy (IDX,IDY);				/* display test id number */
	      cprintf ("3.4.2");
	      tc2_only();				/* do step 3 */
	      if2();
	      break;

	      case 4:
	      if3();
	      break;

	      case 5:
	      baud1200();
	      send_cmd (T6);
	      break;

	      case 6:
	      mio2();					/* do step 6 */
	      break;

	      case 7:
	      gotoxy (IDX,IDY);				/* display test id number */
	      cprintf ("3.4.2");
	      mio3();					/* do step 7 */
	      break;

	      case 8:
	      gotoxy (IDX,IDY);				/* display test id number */
	      cprintf ("3.4.3");
	      tc2_only();
	      break;

	      case 9:
	      gotoxy (IDX,IDY);				/* display test id number */
	      cprintf ("3.4.5");
	      tc2_only();
	      baud1200();				/*12 move from case 10 to here */
	      send_cmd (P1);				/*12 copy channel 1 settings to channel 2 */
	      break;

	      case 10:
	      send_cmd (C02);				/* 11 */
	      break;

	      case 11:					/*12 */
	      tc2_only();				/*12 send test command 2 */
	      break;					/*12 */

	      case 12:
	      gotoxy (IDX,IDY);				/* display test id number */
	      cprintf ("3.4.5");
	      send_cmd (C02);
	      break;

	      case 13:
	      gotoxy (IDX,IDY);				/* display test id number */
	      cprintf ("3.4.6");
	      tc2_only();
	      break;

	      case 14:
	      gotoxy (IDX,IDY);				/* display test id number */
	      cprintf ("3.4.7");
	      tc2_only();
	      break;

	      case 15:
	      gotoxy (IDX,IDY);				/* display test id number */
	      cprintf ("3.4.7");
	      mio4();
	      break;

	      case 16:
	      gotoxy (IDX,IDY);				/* display test id number */
	      cprintf ("3.4.8");
	      tc2_only();
	      break;

	      case 17:
	      mio5();
	      mcio1();
	      cur_test = 8;				/* do the last step */
	      stop1 = 1;
	      break;
	    }
	  }
	}
}


mio1()
{
	draw_window (MB_T,MB_B,MB_L,MB_R);		/* display the test window */
	gotoxy (MB_L+2,MB_T+1);
	cprintf ("Modem I/O Test");			/* display the test header */
	gotoxy (IDX,IDY);				/* display test id number */
	cprintf ("3.4.1");
	result_x = MB_L+2;
	result_y = MB_T+3;				/* set the echo pointers */
	send_cmd (TC2);					/* send test command 2 */
	sub_test = 1;
	test_help();
}


mio2()
{
	gotoxy (MB_L+2,MB_T+3);
	cprintf ("Mute On                    ");
	result_x = MB_L+14;
	send_cmd (U1);					/* set for mute on */
}

mio3()
{
	erase_tc1();					/* clear the command line */
	gotoxy (MB_L+2,MB_T+3);
	cprintf ("AMH Off   ");
	result_x = MB_L+14;
	send_cmd (A0);					/* set for amh off */
}


mio4()
{
	erase_tc1();					/* clear the command line */
	gotoxy (MB_L+2,MB_T+3);
	cprintf ("Synchronous Mode");
	result_x = MB_L+19;
	send_cmd (W0);
}


mio5()
{
	puttext (MB_L,MB_T,MB_R,MB_B,buf);
	gotoxy (MMENU_LEFT+19,MMENU_TOP+8);
	cprintf (" ------------------------- Done");
}


/* This routine controls the modem - control io tests */

mcio_test()
{
	int	stop1 = 0;				/* stop flag */
	char	ch;					/* character storage */

	while (stop1 != 1)
	{
	  ch = getch();					/* wait for a keypress */
	  if (ch == ESC)				/* do the following for the escape key */
	  {
	    puttext (MB_L,MB_T,MB_R,MB_B,buf);		/* erase if test window */
	    cur_test = 0;				/* set flag to exit the process test routine */
	    stop1 = 1;					/* set flag to exit this routine */
	  }

	  if (ch == BS || ch == SP)			/* do the following for bs and space keys */
	  {
	    if (ch == BS) sub_test--;			/* decrement test pointer for back space */
	    if (ch == SP) sub_test++;			/* increment test pointer for space bar */

	    switch (sub_test)
	    {
	      case 0:
	      puttext (MB_L,MB_T,MB_R,MB_B,buf);	/* erase if test window */
	      draw_window (MB_T,MB_B,MB_L,MB_R);	/* display the test options window */
	      gotoxy (MB_L+2,MB_T+1);
	      cprintf ("Modem I/O Test");			/* display the test header */
	      gotoxy (IDX,IDY);				/* display test id number */
	      cprintf ("3.4.8");
	      tc2_only();
	      test_help();
	      cur_test = 7;				/* set flag to go back to space filter test */
	      sub_test = 16;				/* point to the last test */
	      stop1 = 1;				/* exit this test */
	      break;

	      case 1:
	      gotoxy (IDX,IDY);				/* display test id number */
	      cprintf ("3.4.9 ");
	      tc1_only();				/* send test command 2 */
	      baud75();
	      break;

	      case 2:
	      gotoxy (IDX,IDY);				/* display test id number */
	      cprintf ("3.4.10");
	      mcio2();
	      break;

	      case 3:
	      mcio3();
	      cur_test = 0;
	      stop1 = 1;
	      break;

	    }
	  }
	}
}

mcio1()
{
	draw_window (MB_T,MB_B,MB_L,MB_R);	/* display the test window */
	gotoxy (MB_L+2,MB_T+1);
	cprintf ("Modem-Control I/O Test ");
	gotoxy (IDX,IDY);				/* display test id number */
	cprintf ("3.4.9 ");
	result_x = MB_L+1;
	result_y = MB_T+3;
	send_cmd (TC1);
	baud75();
	sub_test = 1;
	test_help();
}


mcio2()
{
	tc2_only();
	send_cmd (D1);
}

mcio3()
{
	puttext (MB_L,MB_T,MB_R,MB_B,buf);
	gotoxy (MMENU_LEFT+27,MMENU_TOP+9);
	cprintf (" ----------------- Done");
}


