/**************************************************************************/
/**	File:  		Monitor.C										                **/
/**	Author:  	Terry W. Jackson													 **/
/**	Company:		U. S. Nuclear Regulatory Comm.								 **/
/**	Date:			March 4, 1997													    **/
/**----------------------------------------------------------------------**/
/**	Description:  This file contains the monitor function which        **/
/**     controls all the related monitor activities including screen     **/
/**     refresh, switching, variable updates, and message printing.      **/
/**----------------------------------------------------------------------**/
/**	Functions Called:											                   **/
/**                                                                      **/
/**	RCP_Turbine_Screen - Displays RCP and Turbine variables.           **/
/**   Coolant_SG_Screen - Displays Coolant and Steam Gen. variables.     **/
/**   Temp_Press_Screen - Displays Temperature and Pressure variables.   **/
/**   Neutron_Flux_Screen - Displays Neutron Flux variables.             **/
/**************************************************************************/
#include "gwrps.h"

/********************* External Function Prototypes ***********************/
extern void RCP_Turbine_Screen(void);	/* Draws RCP and Turbine Screen    */
extern void Coolant_SG_Screen(void);	/* Draws Cool. and Steam Gen. Scn. */
extern void Temp_Press_Screen(void);	/* Draws Temp. and Press. Screen   */
extern void Neutron_Flux_Screen(void);	/* Draws Neutron Flux Screen       */

#include <math.h>

/*********************** External Global Variables ************************/
extern int Update_Screen_1;				/* 1st screen update flag     	  */
extern int Update_Screen_2;				/* 2nd screen update flag		     */
extern int Update_Screen_3;				/* 3rd screen update flag          */
extern int Update_Screen_4;				/* 4th screen update flag          */
extern int Screen_Select;					/* Indicator for screen to display */

#include <conio.h>

extern SRNF_Type A_Source_Range_Neutron_Flux;
extern SRNF_Type B_Source_Range_Neutron_Flux;
extern int A_Intermed_Range_Flux;
extern int B_Intermed_Range_Flux;
extern int A_Power_Range_Flux;
extern int B_Power_Range_Flux;
extern int C_Power_Range_Flux;
extern int D_Power_Range_Flux;
extern int A_Delta_Neutron_Flux;
extern int B_Delta_Neutron_Flux;
extern int C_Delta_Neutron_Flux;
extern int D_Delta_Neutron_Flux;
extern int A_Delta_Temperature;
extern int B_Delta_Temperature;
extern int C_Delta_Temperature;
extern int D_Delta_Temperature;
extern int A_Press;
extern int B_Press;
extern int C_Press;
extern int D_Press;
extern int A_Press_Level;
extern int B_Press_Level;
extern int C_Press_Level;
extern int A1_Cool_Flow;
extern int B1_Cool_Flow;
extern int C1_Cool_Flow;
extern int A2_Cool_Flow;
extern int B2_Cool_Flow;
extern int C2_Cool_Flow;
extern int A3_Cool_Flow;
extern int B3_Cool_Flow;
extern int C3_Cool_Flow;
extern int A4_Cool_Flow;
extern int B4_Cool_Flow;
extern int C4_Cool_Flow;
extern int A1_SG_Level;
extern int B1_SG_Level;
extern int C1_SG_Level;
extern int A2_SG_Level;
extern int B2_SG_Level;
extern int C2_SG_Level;
extern int A3_SG_Level;
extern int B3_SG_Level;
extern int C3_SG_Level;
extern int A4_SG_Level;
extern int B4_SG_Level;
extern int C4_SG_Level;
extern int A1_Feed_Flow;
extern int B1_Feed_Flow;
extern int A2_Feed_Flow;
extern int B2_Feed_Flow;
extern int A3_Feed_Flow;
extern int B3_Feed_Flow;
extern int A4_Feed_Flow;
extern int B4_Feed_Flow;
extern int A1_Steam_Flow;
extern int B1_Steam_Flow;
extern int A2_Steam_Flow;
extern int B2_Steam_Flow;
extern int A3_Steam_Flow;
extern int B3_Steam_Flow;
extern int A4_Steam_Flow;
extern int B4_Steam_Flow;
extern int RCP_1A_Volt;
extern int RCP_1B_Volt;
extern int RCP_2A_Volt;
extern int RCP_2B_Volt;
extern int RCP_1A_Freq;
extern int RCP_1B_Freq;
extern int RCP_2A_Freq;
extern int RCP_2B_Freq;
extern int A_Oil_Press;
extern int B_Oil_Press;
extern int C_Oil_Press;
extern int A_Stop_Valve;
extern int B_Stop_Valve;
extern int C_Stop_Valve;
extern int D_Stop_Valve;

extern SRNF_Type Source_Range_Setpoint;
extern int Intermed_Range_Setpoint;
extern int Low_Power_Range_Setpoint;
extern int High_Power_Range_Setpoint;
extern int Neg_Delta_Flux_Setpoint;
extern int Pos_Delta_Flux_Setpoint;
extern int OT_Delta_Setpoint;
extern int OP_Delta_Setpoint;
extern int Low_Press_Setpoint;
extern int High_Press_Setpoint;
extern int High_Press_Level_Setpoint;
extern int Cool_Flow_Setpoint;
extern int Low_Low_SG_Level_Setpoint;
extern int Low_SG_Level_Setpoint;
extern int Bus_UVolt_Setpoint;
extern int Bus_UFreq_Setpoint;
extern int Oil_Press_Setpoint;

extern int P_6;
extern int P_7;
extern int P_8;
extern int P_9;
extern int P_10;

extern int Block_Source;
extern int Block_Intermed;
extern int Block_Power;

extern int Source_Range_Trip;
extern int Intermed_Range_Trip;
extern int Low_Power_Range_Trip;
extern int High_Power_Range_Trip;
extern int Neg_Delta_Flux_Trip;
extern int Pos_Delta_Flux_Trip;
extern int OT_Delta_T_Trip;
extern int OP_Delta_T_Trip;
extern int Low_Press_Trip;
extern int High_Press_Trip;
extern int High_Press_Level_Trip;
extern int Low_Cool_Flow_Trip;
extern int Low_Low_SG_Level_Trip;
extern int Low_SG_Level_Trip;
extern int Bus_UVolt_Trip;
extern int Bus_UFreq_Trip;
extern int Turbine_Trip;
extern int ESF_Trip;
extern int Manual_Trip;

/********************* Internal Function Prototypes ***********************/
void Monitor(void);							/* Main monitor function           */
void Update_1st_Screen(void);				/* Updates the first screen        */
void Update_2nd_Screen(void);				/* Updates the second screen       */
void Update_3rd_Screen(void);				/* Updates the third screen        */
void Update_4th_Screen(void);				/* Updates the fourth screen       */
void Print_Double_Num(int x_coord, int y_coord, double value);
													/* Display double values           */
void Print_Int_Num(int x_coord, int y_coord, int value, int space);
													/* Display integer values          */
void display(message_type *message, char *command);
													/* Display message and commands    */


/**************************************************************************/
/******************************** Monitor *********************************/
/**************************************************************************/
/*  Inputs:  none																			  */
/*                                                                        */
/*  Outputs:  none                                                        */
/*                                                                        */
/*  Description:  Controls the monitor activities.                        */
/**************************************************************************/

void Monitor(void)
{
	if (Screen_Select == 0)				/* Determine which screen is current  */
		Update_1st_Screen();
	else if (Screen_Select == 1)
		Update_2nd_Screen();
	else if (Screen_Select == 2)
		Update_3rd_Screen();
	else if (Screen_Select == 3)
		Update_4th_Screen();
	else
		Update_1st_Screen();
	gotoxy(58,10);
}


/**************************************************************************/
/*************************** Update_1st_Screen ****************************/
/**************************************************************************/
/*  Inputs:  none																			  */
/*                                                                        */
/*  Outputs:  none                                                        */
/*                                                                        */
/*  Description:  Updates the variables in the first screen.              */
/**************************************************************************/

void Update_1st_Screen(void)
{
	if (Update_Screen_1)						/* See if user changed screen      */
	{
		Neutron_Flux_Screen();				/* Draw the first screen           */
		Update_Screen_1 = FALSE;         /* Do not need to redraw next time */
		Update_Screen_2 = TRUE;          /* Other screens need to be drawed */
		Update_Screen_3 = TRUE;
		Update_Screen_4 = TRUE;
	}

	textbackground(BLACK);					/* Set background to black         */
	textcolor(YELLOW);						/* Set text color to yellow        */

	/****************** Update Source Range Neutron Block ******************/
	if (!P_10)
	{
		Print_Double_Num(5, 2, A_Source_Range_Neutron_Flux.mantissa);
		Print_Int_Num(10, 2, A_Source_Range_Neutron_Flux.exponent, 1);
		Print_Double_Num(5, 3, B_Source_Range_Neutron_Flux.mantissa);
		Print_Int_Num(10, 3, B_Source_Range_Neutron_Flux.exponent, 1);
		Print_Double_Num(31, 2, Source_Range_Setpoint.mantissa);
		Print_Int_Num(36, 2, Source_Range_Setpoint.exponent, 1);
	}
	else
	{
		gotoxy(5,2);   cprintf("----");
		gotoxy(10,2);  cprintf("-");
		gotoxy(5,3);   cprintf("----");
		gotoxy(10,3);  cprintf("-");
		gotoxy(31,2);  cprintf("----");
		gotoxy(36,2);  cprintf("-");
	}

	textbackground(BLUE);					/* Update P-6 indicator            */
	if (P_6)
		textcolor(GREEN);
	else
		textcolor(LIGHTGRAY);
	gotoxy(20,3);
	putch(0x04);

	if (Block_Source)							/* Update Block indicator          */
	{
		textbackground(GREEN);
		textcolor(BLACK);
	}
	else
	{
		textbackground(LIGHTGRAY);
		textcolor(WHITE);
	}
	gotoxy(29,3);
	cprintf("BLOCK");

	if (Source_Range_Trip)					/* Update Trip indicator           */
	{
		textbackground(RED);
		textcolor(BLACK);
	}
	else
	{
		textbackground(LIGHTGRAY);
		textcolor(WHITE);
	}
	gotoxy(37,3);
	cprintf("TRIP");

	/************** Update Intermediate Range Neutron Block ****************/
	textbackground(BLACK);					/* Set background to black         */
	textcolor(YELLOW);						/* Set text color to yellow        */

	Print_Int_Num(5, 6, A_Intermed_Range_Flux, 2);
	Print_Int_Num(5, 7, B_Intermed_Range_Flux, 2);
	Print_Int_Num(37, 6, Intermed_Range_Setpoint, 2);

	textbackground(BLUE);					/* Update P-10 indicator           */
	if (P_10)
		textcolor(GREEN);
	else
		textcolor(LIGHTGRAY);
	gotoxy(20,7);
	putch(0x04);

	if (Block_Intermed)							/* Update Block indicator       */
	{
		textbackground(GREEN);
		textcolor(BLACK);
	}
	else
	{
		textbackground(LIGHTGRAY);
		textcolor(WHITE);
	}
	gotoxy(29,7);
	cprintf("BLOCK");

	if (Intermed_Range_Trip)					/* Update Trip indicator        */
	{
		textbackground(RED);
		textcolor(BLACK);
	}
	else
	{
		textbackground(LIGHTGRAY);
		textcolor(WHITE);
	}
	gotoxy(37,7);
	cprintf("TRIP");

	/****************** Update Power Range Neutron Block *******************/
	textbackground(BLACK);					/* Set background to black         */
	textcolor(YELLOW);						/* Set text color to yellow        */

	Print_Int_Num(5, 10, A_Power_Range_Flux, 3);
	Print_Int_Num(5, 11, B_Power_Range_Flux, 3);
	Print_Int_Num(5, 12, C_Power_Range_Flux, 3);
	Print_Int_Num(5, 13, D_Power_Range_Flux, 3);
	Print_Int_Num(37, 10, Low_Power_Range_Setpoint, 2);
	Print_Int_Num(36, 13, High_Power_Range_Setpoint, 3);

	textbackground(BLUE);					/* Update P-10 indicator           */
	if (P_10)
		textcolor(GREEN);
	else
		textcolor(LIGHTGRAY);
	gotoxy(20,11);
	putch(0x04);

	if (Block_Power)							/* Update Block indicator          */
	{
		textbackground(GREEN);
		textcolor(BLACK);
	}
	else
	{
		textbackground(LIGHTGRAY);
		textcolor(WHITE);
	}
	gotoxy(29,11);
	cprintf("BLOCK");

	if (Low_Power_Range_Trip)					/* Update Low Power Trip ind.   */
	{
		textbackground(RED);
		textcolor(BLACK);
	}
	else
	{
		textbackground(LIGHTGRAY);
		textcolor(WHITE);
	}
	gotoxy(37,11);
	cprintf("TRIP");

	if (High_Power_Range_Trip)					/* Update High Power Trip ind.  */
	{
		textbackground(RED);
		textcolor(BLACK);
	}
	else
	{
		textbackground(LIGHTGRAY);
		textcolor(WHITE);
	}
	gotoxy(37,14);
	cprintf("TRIP");

	/******************* Update Delta Neutron Flux Block *******************/
	textbackground(BLACK);					/* Set background to black         */
	textcolor(YELLOW);						/* Set text color to yellow        */

	gotoxy(5,17);
	if (A_Delta_Neutron_Flux < 0)
		putch('-');
	else
		putch('+');
	Print_Int_Num(6, 17, abs(A_Delta_Neutron_Flux), 2);

	gotoxy(5,18);
	if (B_Delta_Neutron_Flux < 0)
		putch('-');
	else
		putch('+');
	Print_Int_Num(6, 18, abs(B_Delta_Neutron_Flux), 2);

	gotoxy(5,19);
	if (C_Delta_Neutron_Flux < 0)
		putch('-');
	else
		putch('+');
	Print_Int_Num(6, 19, abs(C_Delta_Neutron_Flux), 2);

	gotoxy(5,20);
	if (D_Delta_Neutron_Flux < 0)
		putch('-');
	else
		putch('+');
	Print_Int_Num(6, 20, abs(D_Delta_Neutron_Flux), 2);

	gotoxy(36,17);  putch('-');
	Print_Int_Num(37, 17, abs(Neg_Delta_Flux_Setpoint), 2);
	gotoxy(36,20);  putch('+');
	Print_Int_Num(37, 20, abs(Pos_Delta_Flux_Setpoint), 2);

	if (Neg_Delta_Flux_Trip)					/* Update Low Power Trip ind.   */
	{
		textbackground(RED);
		textcolor(BLACK);
	}
	else
	{
		textbackground(LIGHTGRAY);
		textcolor(WHITE);
	}
	gotoxy(37,18);
	cprintf("TRIP");

	if (Pos_Delta_Flux_Trip)					/* Update High Power Trip ind.  */
	{
		textbackground(RED);
		textcolor(BLACK);
	}
	else
	{
		textbackground(LIGHTGRAY);
		textcolor(WHITE);
	}
	gotoxy(37,21);
	cprintf("TRIP");
}


/**************************************************************************/
/*************************** Update_2nd_Screen ****************************/
/**************************************************************************/
/*  Inputs:  none																			  */
/*                                                                        */
/*  Outputs:  none                                                        */
/*                                                                        */
/*  Description:  Updates the variables in the second screen.             */
/**************************************************************************/

void Update_2nd_Screen(void)
{
	if (Update_Screen_2)						/* See if user changed screen      */
	{
		Temp_Press_Screen();					/* Draw the second screen          */
		Update_Screen_1 = TRUE;          /* Do not need to redraw next time */
		Update_Screen_2 = FALSE;         /* Other screens need to be drawed */
		Update_Screen_3 = TRUE;
		Update_Screen_4 = TRUE;
	}

	textbackground(BLACK);					/* Set background to black         */
	textcolor(YELLOW);						/* Set text color to yellow        */

	/******************** Update Delta Temperature Block *******************/
	Print_Int_Num(5, 2, A_Delta_Temperature, 3);
	Print_Int_Num(5, 3, B_Delta_Temperature, 3);
	Print_Int_Num(5, 4, C_Delta_Temperature, 3);
	Print_Int_Num(5, 5, D_Delta_Temperature, 3);
	Print_Int_Num(32, 2, OT_Delta_Setpoint, 3);
	Print_Int_Num(32, 5, OP_Delta_Setpoint, 3);

	if (OT_Delta_T_Trip)						/* Update OT Trip indicator        */
	{
		textbackground(RED);
		textcolor(BLACK);
	}
	else
	{
		textbackground(LIGHTGRAY);
		textcolor(WHITE);
	}
	gotoxy(37,3);
	cprintf("TRIP");

	if (OP_Delta_T_Trip)						/* Update OP Trip indicator        */
	{
		textbackground(RED);
		textcolor(BLACK);
	}
	else
	{
		textbackground(LIGHTGRAY);
		textcolor(WHITE);
	}
	gotoxy(37,6);
	cprintf("TRIP");

	/***************** Update Pressurizer Pressure Block *******************/
	textbackground(BLACK);					/* Set background to black         */
	textcolor(YELLOW);						/* Set text color to yellow        */

	Print_Int_Num(5, 9, A_Press, 4);		/* Display pressure variables      */
	Print_Int_Num(5, 10, B_Press, 4);
	Print_Int_Num(5, 11, C_Press, 4);
	Print_Int_Num(5, 12, D_Press, 4);
	Print_Int_Num(32, 9, Low_Press_Setpoint, 4);
	Print_Int_Num(32, 12, High_Press_Setpoint, 4);

	textbackground(BLUE);					/* Update P-10 indicator           */
	if (P_10)
		textcolor(GREEN);
	else
		textcolor(LIGHTGRAY);
	gotoxy(18,10);
	putch(0x04);

	if (Low_Press_Trip)						/* Update Low Press. Trip ind.     */
	{
		textbackground(RED);
		textcolor(BLACK);
	}
	else
	{
		textbackground(LIGHTGRAY);
		textcolor(WHITE);
	}
	gotoxy(37,10);
	cprintf("TRIP");

	if (High_Press_Trip)					   /* Update High Press. Trip ind.    */
	{
		textbackground(RED);
		textcolor(BLACK);
	}
	else
	{
		textbackground(LIGHTGRAY);
		textcolor(WHITE);
	}
	gotoxy(37,13);
	cprintf("TRIP");

	/**************** Update Pressurizer Water Level Block *****************/
	textbackground(BLACK);					/* Set background to black         */
	textcolor(YELLOW);						/* Set text color to yellow        */

	Print_Int_Num(5, 16, A_Press_Level, 3);
	Print_Int_Num(5, 17, B_Press_Level, 3);
	Print_Int_Num(5, 18, C_Press_Level, 3);
	Print_Int_Num(37, 16, High_Press_Level_Setpoint, 2);

	textbackground(BLUE);					/* Update P-7 indicator            */
	if (P_7)
		textcolor(GREEN);
	else
		textcolor(LIGHTGRAY);
	gotoxy(18,17);
	putch(0x04);

	if (High_Press_Level_Trip)					/* Update High Level Trip ind.  */
	{
		textbackground(RED);
		textcolor(BLACK);
	}
	else
	{
		textbackground(LIGHTGRAY);
		textcolor(WHITE);
	}
	gotoxy(37,17);
	cprintf("TRIP");
}


/**************************************************************************/
/*************************** Update_3rd_Screen ****************************/
/**************************************************************************/
/*  Inputs:  none																			  */
/*                                                                        */
/*  Outputs:  none                                                        */
/*                                                                        */
/*  Description:  Updates the variables in the third screen.              */
/**************************************************************************/

void Update_3rd_Screen(void)
{
	if (Update_Screen_3)						/* See if user changed screen      */
	{
		Coolant_SG_Screen();             /* Draw the third screen           */
		Update_Screen_1 = TRUE;          /* Do not need to redraw next time */
		Update_Screen_2 = TRUE;          /* Other screens need to be drawed */
		Update_Screen_3 = FALSE;
		Update_Screen_4 = TRUE;
	}

	textbackground(BLACK);					/* Set background to black         */
	textcolor(YELLOW);						/* Set text color to yellow        */

	/****************** Update Reactor Coolant Flow Block ******************/
	Print_Int_Num(5, 2, A1_Cool_Flow, 3);
	Print_Int_Num(5, 3, B1_Cool_Flow, 3);
	Print_Int_Num(5, 4, C1_Cool_Flow, 3);
	Print_Int_Num(16, 2, A2_Cool_Flow, 3);
	Print_Int_Num(16, 3, B2_Cool_Flow, 3);
	Print_Int_Num(16, 4, C2_Cool_Flow, 3);
	Print_Int_Num(27, 2, A3_Cool_Flow, 3);
	Print_Int_Num(27, 3, B3_Cool_Flow, 3);
	Print_Int_Num(27, 4, C3_Cool_Flow, 3);
	Print_Int_Num(38, 2, A4_Cool_Flow, 3);
	Print_Int_Num(38, 3, B4_Cool_Flow, 3);
	Print_Int_Num(38, 4, C4_Cool_Flow, 3);
	Print_Int_Num(11, 6, Cool_Flow_Setpoint, 3);

	textbackground(BLUE);					/* Update P-7 indicator            */
	if (P_7)
		textcolor(GREEN);
	else
		textcolor(LIGHTGRAY);
	gotoxy(20,6);
	putch(0x04);

	textbackground(BLUE);					/* Update P-8 indicator            */
	if (P_8)
		textcolor(GREEN);
	else
		textcolor(LIGHTGRAY);
	gotoxy(29,6);
	putch(0x04);

	if (Low_Cool_Flow_Trip)						/* Update Cool. Flow Trip ind.     */
	{
		textbackground(RED);
		textcolor(BLACK);
	}
	else
	{
		textbackground(LIGHTGRAY);
		textcolor(WHITE);
	}
	gotoxy(37,6);
	cprintf("TRIP");


	/************* Update Steam Generator Water Level Block ****************/
	textbackground(BLACK);					/* Set background to black         */
	textcolor(YELLOW);						/* Set text color to yellow        */

	Print_Int_Num(5, 9, A1_SG_Level, 3);		/* Display pressure variables      */
	Print_Int_Num(5, 10, B1_SG_Level, 3);
	Print_Int_Num(5, 11, C1_SG_Level, 3);
	Print_Int_Num(16, 9, A2_SG_Level, 3);
	Print_Int_Num(16, 10, B2_SG_Level, 3);
	Print_Int_Num(16, 11, C2_SG_Level, 3);
	Print_Int_Num(27, 9, A3_SG_Level, 3);
	Print_Int_Num(27, 10, B3_SG_Level, 3);
	Print_Int_Num(27, 11, C3_SG_Level, 3);
	Print_Int_Num(38, 9, A4_SG_Level, 3);
	Print_Int_Num(38, 10, B4_SG_Level, 3);
	Print_Int_Num(38, 11, C4_SG_Level, 3);
	Print_Int_Num(19, 12, Low_Low_SG_Level_Setpoint, 3);

	Print_Int_Num(5, 15, A1_Feed_Flow, 3);		/* Display pressure variables      */
	Print_Int_Num(5, 16, B1_Feed_Flow, 3);
	Print_Int_Num(16, 15, A2_Feed_Flow, 3);
	Print_Int_Num(16, 16, B2_Feed_Flow, 3);
	Print_Int_Num(27, 15, A3_Feed_Flow, 3);
	Print_Int_Num(27, 16, B3_Feed_Flow, 3);
	Print_Int_Num(38, 15, A4_Feed_Flow, 3);
	Print_Int_Num(38, 16, B4_Feed_Flow, 3);

	Print_Int_Num(5, 19, A1_Steam_Flow, 3);		/* Display pressure variables      */
	Print_Int_Num(5, 20, B1_Steam_Flow, 3);
	Print_Int_Num(16, 19, A2_Steam_Flow, 3);
	Print_Int_Num(16, 20, B2_Steam_Flow, 3);
	Print_Int_Num(27, 19, A3_Steam_Flow, 3);
	Print_Int_Num(27, 20, B3_Steam_Flow, 3);
	Print_Int_Num(38, 19, A4_Steam_Flow, 3);
	Print_Int_Num(38, 20, B4_Steam_Flow, 3);
	Print_Int_Num(15, 21, Low_SG_Level_Setpoint, 3);

	if (Low_Low_SG_Level_Trip)						/* Update Low Press. Trip ind.     */
	{
		textbackground(RED);
		textcolor(BLACK);
	}
	else
	{
		textbackground(LIGHTGRAY);
		textcolor(WHITE);
	}
	gotoxy(37,12);
	cprintf("TRIP");

	if (Low_SG_Level_Trip)					   /* Update High Press. Trip ind.    */
	{
		textbackground(RED);
		textcolor(BLACK);
	}
	else
	{
		textbackground(LIGHTGRAY);
		textcolor(WHITE);
	}
	gotoxy(37,21);
	cprintf("TRIP");
}


/**************************************************************************/
/*************************** Update_4th_Screen ****************************/
/**************************************************************************/
/*  Inputs:  none																			  */
/*                                                                        */
/*  Outputs:  none                                                        */
/*                                                                        */
/*  Description:  Updates the variables in the fourth screen.             */
/**************************************************************************/

void Update_4th_Screen(void)
{
	if (Update_Screen_4)						/* See if user changed screen      */
	{
		RCP_Turbine_Screen();				/* Draw the fourth screen          */
		Update_Screen_1 = TRUE;         /* Do not need to redraw next time */
		Update_Screen_2 = TRUE;          /* Other screens need to be drawed */
		Update_Screen_3 = TRUE;
		Update_Screen_4 = FALSE;
	}

	textbackground(BLACK);					/* Set background to black         */
	textcolor(YELLOW);						/* Set text color to yellow        */

	/************** Update RCP Bus Voltage and Frequency Block *************/
	Print_Int_Num(5, 2, RCP_1A_Volt, 4);
	Print_Int_Num(5, 3, RCP_1B_Volt, 4);
	Print_Int_Num(5, 4, RCP_2A_Volt, 4);
	Print_Int_Num(5, 5, RCP_2B_Volt, 4);
	Print_Int_Num(13, 2, RCP_1A_Freq, 2);
	Print_Int_Num(13, 3, RCP_1B_Freq, 2);
	Print_Int_Num(13, 4, RCP_2A_Freq, 2);
	Print_Int_Num(13, 5, RCP_2B_Freq, 2);
	Print_Int_Num(17, 6, Bus_UVolt_Setpoint, 4);
	Print_Int_Num(19, 7, Bus_UFreq_Setpoint, 2);

	textbackground(BLUE);					/* Update P-7 indicator            */
	if (P_7)
		textcolor(GREEN);
	else
		textcolor(LIGHTGRAY);
	gotoxy(27,6);  putch(0x04);
	gotoxy(27,7);  putch(0x04);

	if (Bus_UVolt_Trip)					/* Update Trip indicator           */
	{
		textbackground(RED);
		textcolor(BLACK);
	}
	else
	{
		textbackground(LIGHTGRAY);
		textcolor(WHITE);
	}
	gotoxy(36,6);
	cprintf("TRIP");

	if (Bus_UFreq_Trip)					/* Update Trip indicator           */
	{
		textbackground(RED);
		textcolor(BLACK);
	}
	else
	{
		textbackground(LIGHTGRAY);
		textcolor(WHITE);
	}
	gotoxy(36,7);
	cprintf("TRIP");


	/************************ Update Turbine Block *************************/
	textbackground(BLACK);					/* Set background to black         */
	textcolor(YELLOW);						/* Set text color to yellow        */

	Print_Int_Num(5, 10, A_Oil_Press, 2);
	Print_Int_Num(5, 11, B_Oil_Press, 2);
	Print_Int_Num(5, 12, C_Oil_Press, 2);
	Print_Int_Num(28, 10, Oil_Press_Setpoint, 2);

	textbackground(BLUE);					/* Update A_Stop_Valve           */
	if (A_Stop_Valve)
		textcolor(GREEN);
	else
		textcolor(LIGHTGRAY);
	gotoxy(4,15);  putch(0x04);

	if (B_Stop_Valve)							/* Update B_Stop_Valve				*/
		textcolor(GREEN);
	else
		textcolor(LIGHTGRAY);
	gotoxy(16,15);  putch(0x04);

	if (C_Stop_Valve)							/* Update C_Stop_Valve				*/
		textcolor(GREEN);
	else
		textcolor(LIGHTGRAY);
	gotoxy(28,15);  putch(0x04);

	if (D_Stop_Valve)							/* Update D_Stop_Valve				*/
		textcolor(GREEN);
	else
		textcolor(LIGHTGRAY);
	gotoxy(40,15);  putch(0x04);

	if (Turbine_Trip)							/* Update Turbine Trip ind.  */
	{
		textbackground(RED);
		textcolor(BLACK);
	}
	else
	{
		textbackground(LIGHTGRAY);
		textcolor(WHITE);
	}
	gotoxy(36,10);
	cprintf("TRIP");

	/******************* Update ESF and Manual Trip Block ******************/
	textbackground(BLACK);					/* Set background to black         */
	textcolor(YELLOW);						/* Set text color to yellow        */

	if (ESF_Trip)					/* Update Low Power Trip ind.   */
	{
		textbackground(RED);  textcolor(BLACK);
		gotoxy(36,18);  cprintf("TRIP");
		textbackground(BLUE); textcolor(GREEN);
		gotoxy(16, 18);  putch(0x04);
	}
	else
	{
		textbackground(LIGHTGRAY);  textcolor(WHITE);
		gotoxy(36,18);  cprintf("TRIP");
		textbackground(BLUE);  textcolor(LIGHTGRAY);
		gotoxy(16, 18); putch(0x04);
	}

	if (Manual_Trip)					/* Update High Power Trip ind.  */
	{
		textbackground(RED);  textcolor(BLACK);
		gotoxy(36,21);  cprintf("TRIP");
		textbackground(BLUE);  textcolor(GREEN);
		gotoxy(14,21);  putch(0x04);
	}
	else
	{
		textbackground(LIGHTGRAY);  textcolor(WHITE);
		gotoxy(36,21);  cprintf("TRIP");
		textbackground(BLUE);  textcolor(LIGHTGRAY);
		gotoxy(14,21);  putch(0x04);
	}
}


/**************************************************************************/
/***************************** Print_Int_Num ******************************/
/**************************************************************************/
/*  Inputs:  x_coord - x coordinate to print number.							  */
/*				 y_coord - y coordinate to print number.							  */
/*				 value - integer value to print.										  */
/*				 space - number of spaces to print the number.					  */
/*                                                                        */
/*  Outputs:  none                                                        */
/*                                                                        */
/*  Description:  Prints integers at specified locations with size of     */
/*						space to print into.												  */
/**************************************************************************/

void Print_Int_Num(int x_coord, int y_coord, int value, int space)
{
	gotoxy(x_coord, y_coord);				/* Goto assigned coordinates		  */
	switch(space)
	{
	case 1:										/* One space to print integer		  */
		cprintf("%1d", value);
		break;
	case 2:										/* Two spaces to print integer	  */
		cprintf("%2d", value);
		break;
	case 3:										/* Three spaces to print integer	  */
		cprintf("%3d", value);
		break;
	case 4:										/* Four spaces to print integer	  */
		cprintf("%4d", value);
		break;
	case 5:										/* Just something extra				  */
   	break;
		/*  This does nothing */
	}
}


/**************************************************************************/
/*************************** Print_Double_Num *****************************/
/**************************************************************************/
/*  Inputs:  x_coord - x coordinate to print double value					  */
/*				 y_coord - y coordinate to print double value					  */
/*				 value - double value to print										  */
/*                                                                        */
/*  Outputs:  none                                                        */
/*                                                                        */
/*  Description:  Prints double values at specified locations.            */
/**************************************************************************/

void Print_Double_Num(int x_coord, int y_coord, double value)
{
	if (value < 10)					/* See if value needs to be configured	  */
	{
		gotoxy(x_coord, y_coord);
		cprintf("    ");
		x_coord++;
   }
	gotoxy(x_coord, y_coord);		/* Goto desired coordinate					  */
	cprintf("%2.1f", value);		/* Print value									  */
}


/**************************************************************************/
/******************************** Display *********************************/
/**************************************************************************/
/*  Inputs:  *message - pointer to a message_type structure					  */
/*				 *command - pointer to the desired command line string 		  */
/*  Outputs:  none                                                        */
/*                                                                        */
/*  Description:  Displays messages in the message window and strings in  */
/*						the command line window.										  */
/**************************************************************************/

void display(message_type *message, char *command)
{
	textbackground(BLACK);							/* Set text colors			  */
	textcolor(LIGHTGRAY);
	gotoxy(58,5); cprintf(message->line_1);	/* Print strings				  */
	gotoxy(58,6); cprintf(message->line_2);
	gotoxy(58,7); cprintf(message->line_3);
	gotoxy(58,8); cprintf(message->line_4);
	gotoxy(58,10); cprintf(command);
}

