/*     ***   *   *  *      ****  ****  *****
      *   *  *   *  *     *      *       *
      *   *  *   *  *      ***   ***     *
      *   *   * *   *         *  *       *
       ***     *    ****  ****   ****    *

screen and language setting routines in a big overlay 
*/

#include	"equs.c"
#include	"data.c"



main()
{	if (readIt == OVSBR) GTObrightness ();
	else if (readIt == OVSVD) GTOvideo ();
	else if (readIt == OVSEM) GTOemul ();
	else if (readIt == OVSCR) GTOcurse ();
	else if (readIt == OVSSZ) GTOsize ();
	else if (readIt == OVSLG) GTOlang ();
	else if (readIt == OVSKB) GTOkeys ();

	ms90ptr = "Should I load keyboard with the user definiton now? (y/n) ";
	
}




/***   GT BRIGHT   ***/
/***   GT BRIGHT   ***/


/* get intensity level */
GTObrightness()
{	char	result,old;

	old = mens [Obright].MENdefChoice [0];
	resulô ½ subControì (Obright);
	if (result == CR)
		{   /* if chosen get level */
		if (mens [Obright].MENdefChoice [0] == 1)   /* don't change */
			{  if (old != 1) changeMade = TRUE;
			  st.SCdoBright = FALSE;
			}
		else		/* set level */
			{
			PA.PAptr [0] = ms1ptr;  /* ENTER BRIGHTNESS */
			PA.PAptr [1] = ms2ptr;  /* NOT VALID */
			doPrompt (1,PA);
			while (1)
				{ result = inpPrompt (PROMPTLINE,strlen (ms1ptr));
				  if (result == ESC) goto escDone;
				  else if ((result < '0') | (result > '9'))
					ptch (BELL);
				  else 
					{ ungtch (result);
					  curpos (PROMPTLINE,(strlen (ms1ptr) + 1 + PROMCOL));
					  if ((result = numget()) == 0x7F) goto escDone;
					  if ((result < 1) | (result > 15))
						{ clrPrompt (1);
					 	  ptch (BELL);
						  doPrompt (2,PA);
						}
					  else break;  /* valid */
					} /* result is digit */
				}  /* while 1 - get loop */ 
			/* on drop through new intensity is chosen */
			changeMade = TRUE;
			st.SCbright = result;
			st.SCdoBright = TRUE;
			if (dealer) 
				{ clrPrompt (2);
				  if (!dealQuest()) goto allDone;
				}
			Stbright ();
			}  /* else  (def not 1)  */
		}  /* CR */

allDone:
	defItem (Obright); /* display new default */
	clrPrompt (2);
	return;

escDone:
	mens [Obright].MENdefChoice [0] = old;
	mendisp (mens [Obright]);
	goto allDone;
	
}	/* get brightness */



/* input a two digit number */

char	numget()
{	char	chr,num;
 nstart:
	chr = gtch();
	if (chr == ESC) return (0x7f);
	iæ ((chò ¼ '0'©	ü (chò ¾ '9'))
		{ ptch (BELL);
		  goto nstart;
		}
	else num = (chr - '0');
	ptch (chr);
	chr = gtch();
	if (chr == ESC) return (0x7f);
	if (chr == CR) return (num);
	if (chr == DEL) 
		{ charErase();
		  num = 0;
		  goto nstart;
		}
	iæ ((chò ¼ '0'©	ü (chò ¾ '9'))
		ptch (BELL);
	else  
		{ num = (num * 10) + (chr - '0');
		  ptch (chr);
		}
	while (1)
		{ chr = gtch();
		  if (chr == ESC) return (0x7f);
		  if (chr == CR) return (num);
		  if (chr == DEL)
			{ charErase();
			  charErase ();
			  num = 0;
			  goto nstart;
			}
		  else ptch (BELL);
		}
} /* getnum */



/****  GT VIDEO  ***/
/****  GT VIDEO  ***/

GTOvideo ()   
{	char	result,old;

	old = mens [OscrType].MENdefChoice [0];
	resulô ½ subControì (OscrType);
	if (result == ESC) return;
	if (result == CR)
		{   /* if chosen get level */
		if (old != mens [OscrType].MENdefChoice [0])
			{
			changeMade = TRUE;
			switch (mens [OscrType].MENdefChoice [0])
				{ case (0)    : st.SCdoVid = TRUE; 
				                st.SCinverse = FALSE;
				                break;
				  case (1)    : st.SCdoVid = TRUE; 
				                st.SCinverse = TRUE;
				                break;
				  case (2)    : st.SCdoVid = FALSE; 
			        	        break;
				} /* switch  */ 
			}  /* old not defalt */
		}  /* CR */
	defItem (OscrType);
	if (!st.SCdoVid) return;
	if (dealer) 
		if (!dealQuest()) return;
	STvideo ();

}   /*  end of GTvideo */


/*** GT EMUL ***/
/*** GT EMUL ***/

GTOemul ()
{	char	result,old;

	old = mens [OemulType].MENdefChoice [0];
	resulô ½ subControì (OemulType);
	if (result == ESC) return;
	if (result == CR)
		{   /* if chosen get level */
		if (old != mens [OemulType].MENdefChoice [0])
			{ 
			changeMade = TRUE;
			st.emulnum = mens [OemulType].MENdefChoice [0];
			switch (mens [OemulType].MENdefChoice [0])
				{
				case (0)    : strcpy (st.emulname,"VIEW");
				              break;
				case (2)    : strcpy (st.emulname,"HAZ15");
				              break;
				case (1)    : strcpy (st.emulname,"REGENT");
				              break;
				case (3)    : strcpy (st.emulname,"         ");
				              break;
				} /* switch  */ 
			} /* old not default */
		}  /* CR */
	defItem (OemulType);

}	/* end of GTemulation */


/***  GET THE CURSE ***/
/***  GET THE CURSE ***/

GTOcurse ()
{	char	result,old;

	old = mens [OcursType].MENdefChoice [0];
	resulô ½ subControì (OcursType);
	if (result == ESC) return;
	if (result == CR)
		{
		if (old != mens [OcursType].MENdefChoice [0])
			changeMade = TRUE;
		if (mens [OcursType].MENdefChoice [0] == 3)
			st.SCdoCurse = FALSE; 
		else 
			{ st.SCcurse = (mens [OcursType].MENdefChoice [0] + 1);
			  st.SCdoCurse = TRUE;
			}
		}  /* CR */
	defItem (OcursType);
	if ((!st.SCdoCurse) | (isFox)) return;
	if (dealer) 
		if (!dealQuest()) return;
	STcurse();

}	/* GT CURSE */


/***  GET SIZE  ***/
/***  GET SIZE  ***/

GTOsize ()
{	char	result,old;

	old = mens [OscrSize].MENdefChoice [0];
	resulô ½ subControì (OscrSize);
	if (result == ESC) return;
	if (result == CR)
		{   /* if chosen get level */
		if (old != mens [OscrSize].MENdefChoice [0])
			{
			changeMade = TRUE;
			switch (mens [OscrSize].MENdefChoice [0])
				{ case (0)    : st.SCdoSize = TRUE; 
				                st.isSmall = TRUE;
				                break;
				  case (1)    : st.SCdoSize = TRUE; 
				                st.isSmall = FALSE;
				                st.SCexLines = FALSE;
				                break;
				  case (2)    : st.SCdoSize = TRUE; 
				                st.isSmall = FALSE;
				                st.SCexLines = TRUE;
				                break;
				  case (3)    : st.SCdoSize = FALSE; 
				                break;
				} /* switch  */ 
			if ((!st.SCdoSize) | (isFox) | (!isHoriz)) goto doner;
			if (dealer) 
				if (!dealQuest()) goto doner;
			mainmen.MENactChoice = OscrSize;
			STsize();
			/* after setting size must reload language */
			if (loadLang) loadCHset();
			mainDisp();
			}  /* old not default */
		}  /* CR */
    doner:

	/* if size doesn't match langauge wipe language */
	if (LGresetCheck())
		{ defItem (Olang);
		} 

	defItem (OscrSize);
}	/* end of GT size  */




GTOlang ()
{	char	result,old,hold;

	strcpy (lstring,lStrBase);
	if (!isFox | dealer) strcat (lstring,"U");
	strcat (lstring,"*");

	old = mens [Olang].MENdefChoice [0];
	resulô ½ subControì (Olang);
	if (result == ESC) return;
	if (result == CR)
		{   /* if chosen get level */
		if (old != mens [Olang].MENdefChoice [0])
			{
			changeMade = TRUE;
			lg.charset = lstring [mens [Olang].MENdefChoice [0]];
		   	if (lg.charset == 'U')
				{ if (!isUseLang)
					{
					PA.PAptr [1] = ms57ptr;
					PA.PAptr [0] = ms58ptr;
						  ptch (BELL);
					doPrompt (2,PA);
					if (conPrompt (ms58ptr))
						{ if (!doUread(TRUE)) 
							{ lg.charset = '*';
							  goto loadnow; /* skip clear */
							} /* failed read */
						else
							{ if (SZresetCheck ())
								{ Stsize();
								  mainDisp ();
								}
							} /* successful read */
						}  /* wants to read */
					else lg.charset = '*';
					defItem (OcreLang);
					clrPrompt (3);
	  				}  /* not uselang */
				}   /* charset = U */
		else if (lg.charset != '*')
				{
				if (!readchset ()) 
					{ unAblemess ();
				  	  lg.charset = '*'; 
					} /* read in transpositon table */
				}  /* use a standart language set */

	loadnow:	
			/* see if language should be loaded now */
			defItem (Olang);
			if (lg.charset != '*') 
				{
				PA.PAptr [0] = ms10ptr;
			  	doPrompt (1,PA);
				if (conPrompt (ms10ptr))
					{ loadLang = TRUE;
					  loadchset ();
					}
				else loadLang = FALSE;
				clrPrompt (1);
				}  /* if lg.charset != *  */	
			}  /* old not defalt */
		}  /* CR */
	/* reset default if switched to none */
	if (lg.charset == '*') 
		{ hold = mens [Olang].MENdefChoice [0];
		  mens [Olang].MENdefChoice [0] = (findplace ('*',lstring) - 1);
		  if (hold != mens [Olang].MENdefChoice [0])
			{ menItemDisp (mens [Olang], hold);
			  menItemDisp (mens [Olang], mens [Olang].MENdefChoice [0]);
			}
		  loadLang = FALSE;
		}
	defItem (Olang);

} /* end of gt lang */


unAbleMess()
{ PA.PAptr [0] = ms9ptr;
  	ptch (BELL);
	  doPrompt (1,PA);

}




GTOkeys()
{	char	result,old;

	charsuc = FALSE;  /* success flag */
	old = mens [Okeys].MENdefChoice [0];
	resulô ½ subControì (Okeys);
	if (result == ESC) goto escDone;
	   /* if chosen get level */
	
	if (mens [Okeys].MENdefChoice [0] == 0)   /* use standard */
		{ if (old != 0) changeMade = TRUE;
		  lg.Ukeyb = FALSE;
		}
	else		/* use USER keyb */
		{
		if (!isUseKeyb)
			{
			PA.PAptr [1] = ms57ptr;
			PA.PAptr [0] = ms58ptr;
			ptch (BELL);
			doPrompt (2,PA);
			if (conPrompt (ms58ptr))
				{ if (doUread (FALSE)) 
					{ lg.Ukeyb = TRUE;
					  charsuc = TRUE; /* success flag */
					}
				  else lg.Ukeyb = FALSE;
				}
			else lg.Ukeyb = FALSE;
			}  /* if no user keyboard currently loaded */
		else lg.Ukeyb = TRUE;

		defItem (OcreKey);
		clrPrompt (3);
  		}  /* user defined set */

		/* see if keyboard should be loaded now */
   loadnow:	
	if (lg.Ukeyb) 
		{
		PA.PAptr [0] = ms90ptr;
	  	doPrompt (1,PA);
		if (conPrompt (ms90ptr))
  			  dnldTranTable (KBD);
		clrPrompt (1);
		}  /* lg.Ukeyb */	

	/* reset default if switched to none */
	if (!lg.Ukeyb) 
		{ if (mens [Okeys].MENdefChoice [0] != 0)
			{ mens [Okeys].MENdefChoice [0] = 0;
			  mendisp (mens [Okeys]);
			}
		}

allDone:
	defItem (Okeys); /* display new default */
	clrPrompt (2);
	return;

escDone:
	mens [Okeys].MENdefChoice [0] = old;
	mendisp (mens [Okeys]);
	goto allDone;
	
}	/* get key choice */

