#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream.h>
char* menu_main[]={
"Блок параметров 1",
"Блок параметров 2",
"Блок параметров 3",
"Блок параметров 4"
};
//int  end_of_menu_main=0;//

/********************************************************************/
char *menu_1[]={
"M1 Первая строка ",
"M1 Вторая",
"M1 Третья",
"M1 Четвертая",
"M1 Пятая",
"M1 Шестая",
"M1 Седьмая",
"M1 Восьмая",
"M1 Девятая",
"M1 Десятая",
"M1 Одиннацатая",
//"" //пустая строка
};
//int end_of_menu_1=0;
/********************************************************************/
char *menu_2[]={
"M2 Первая строка ",
"M2 Вторая",
"M2 Третья",
"M2 Четвертая",
"M2 Пятая",
"M2 Шестая",
"M2 Седьмая",
"M2 Восьмая",
"M2 Девятая",
"M2 Десятая",
"M2 Одиннацатая",
//"" //пустая строка
};
//int end_of_menu_2=0;

/********************************************************************/
char *menu_3[]={
"M3 Первая строка ",
"M3 Вторая",
"M3 Третья",
"M3 Четвертая",
"M3 Пятая",
"M3 Шестая",
"M3 Седьмая",
"M3 Восьмая",
"M3 Девятая",
"M3 Десятая",
"M3 Одиннацатая",
//"" //пустая строка
};
//int end_of_menu_3=0;

/********************************************************************/
char *menu_4[]={
"M4 Первая строка ",
"M4 Вторая",
"M4 Третья",
"M4 Четвертая",
"M4 Пятая",
"M4 Шестая",
"M4 Седьмая",
"M4 Восьмая",
"M4 Девятая",
"M4 Десятая",
"M4 Одиннацатая",
//"" //пустая строка
};
//int end_of_menu_4=0;


/********************************************************************/
/********************************************************************/
/********************************************************************/
/********************************************************************/
/********************************************************************/
/********************************************************************/
/********************************************************************/
/********************************************************************/
/********************************************************************/



#define UP 0x48
#define DOWN 0x50
#define ESC 0x4b
#define ENTER 0x4d
#define  TERM 0x1b
#define MAX_E 2
#define MAX_P 2
#define REV_VIDEO 0

//#define  DEB 0
#define   DEBUG 0
/**************************************************************/
signed char GetResp( unsigned char count,unsigned char * menu[]);
write_video(char * menu);
/******************************************************************/
signed char  key,key_main;
void main()
{
clrscr();
#ifdef DEB
write_video(menu_main[0]);
write_video(menu_main[1]);
write_video(menu_main[2]);
#endif

for(;;){
/****************************************************************/
key=GetResp((sizeof(menu_main)/2),menu_main);
/****************************************************************/
switch(key)
{
case 0:
key=GetResp((sizeof(menu_1)/2),menu_1);
   switch(key){
      case 0:  clrscr(); cout<<"Выбор произведен :"<<menu_1[0]<<endl; getch(); break;
      case 1:  clrscr(); cout<<"Выбор произведен :"<<menu_1[1]<<endl; getch(); break;
      case 2:  clrscr(); cout<<"Выбор произведен :"<<menu_1[2]<<endl; getch(); break;
      case 3:  clrscr(); cout<<"Выбор произведен :"<<menu_1[3]<<endl; getch(); break;
      case 4:  clrscr(); cout<<"Выбор произведен :"<<menu_1[4]<<endl; getch(); break;
      case 5:  clrscr(); cout<<"Выбор произведен :"<<menu_1[5]<<endl; getch(); break;
      case 6:  clrscr(); cout<<"Выбор произведен :"<<menu_1[6]<<endl; getch(); break;
      case 7:  clrscr(); cout<<"Выбор произведен :"<<menu_1[7]<<endl; getch(); break;
      case 8:  clrscr(); cout<<"Выбор произведен :"<<menu_1[8]<<endl; getch(); break;
      case 9:  clrscr(); cout<<"Выбор произведен :"<<menu_1[9]<<endl; getch(); break;
      case 10:  clrscr(); cout<<"Выбор произведен :"<<menu_1[10]<<endl;getch(); break;
      default:  break;

   }
break;

case 1:
key=GetResp((sizeof(menu_2)/2),menu_2);
   switch(key){
      case 0:  clrscr(); cout<<"Выбор произведен :"<<menu_2[0]<<endl; getch(); break;
      case 1:  clrscr(); cout<<"Выбор произведен :"<<menu_2[1]<<endl; getch(); break;
      case 2:  clrscr(); cout<<"Выбор произведен :"<<menu_2[2]<<endl; getch(); break;
      case 3:  clrscr(); cout<<"Выбор произведен :"<<menu_2[3]<<endl; getch(); break;
      case 4:  clrscr(); cout<<"Выбор произведен :"<<menu_2[4]<<endl; getch(); break;
      case 5:  clrscr(); cout<<"Выбор произведен :"<<menu_2[5]<<endl; getch(); break;
      case 6:  clrscr(); cout<<"Выбор произведен :"<<menu_2[6]<<endl; getch(); break;
      case 7:  clrscr(); cout<<"Выбор произведен :"<<menu_2[7]<<endl; getch(); break;
      case 8:  clrscr(); cout<<"Выбор произведен :"<<menu_2[8]<<endl; getch(); break;
      case 9:  clrscr(); cout<<"Выбор произведен :"<<menu_2[9]<<endl; getch(); break;
      case 10:  clrscr(); cout<<"Выбор произведен :"<<menu_2[10]<<endl;getch(); break;
      default:  break;

   }

break;

case 2:  key=GetResp((sizeof(menu_3)/2),menu_3);
   switch(key){
      case 0:  clrscr(); cout<<"Выбор произведен :"<<menu_3[0]<<endl; getch(); break;
      case 1:  clrscr(); cout<<"Выбор произведен :"<<menu_3[1]<<endl; getch(); break;
      case 2:  clrscr(); cout<<"Выбор произведен :"<<menu_3[2]<<endl; getch(); break;
      case 3:  clrscr(); cout<<"Выбор произведен :"<<menu_3[3]<<endl; getch(); break;
      case 4:  clrscr(); cout<<"Выбор произведен :"<<menu_3[4]<<endl; getch(); break;
      case 5:  clrscr(); cout<<"Выбор произведен :"<<menu_3[5]<<endl; getch(); break;
      case 6:  clrscr(); cout<<"Выбор произведен :"<<menu_3[6]<<endl; getch(); break;
      case 7:  clrscr(); cout<<"Выбор произведен :"<<menu_3[7]<<endl; getch(); break;
      case 8:  clrscr(); cout<<"Выбор произведен :"<<menu_3[8]<<endl; getch(); break;
      case 9:  clrscr(); cout<<"Выбор произведен :"<<menu_3[9]<<endl; getch(); break;
      case 10:  clrscr(); cout<<"Выбор произведен :"<<menu_3[10]<<endl;getch(); break;
      default:  break;

   }

break;

case 3:     key=GetResp((sizeof(menu_4)/2),menu_4);
   switch(key){
      case 0:  clrscr(); cout<<"Выбор произведен :"<<menu_4[0]<<endl; getch(); break;
      case 1:  clrscr(); cout<<"Выбор произведен :"<<menu_4[1]<<endl; getch(); break;
      case 2:  clrscr(); cout<<"Выбор произведен :"<<menu_4[2]<<endl; getch(); break;
      case 3:  clrscr(); cout<<"Выбор произведен :"<<menu_4[3]<<endl; getch(); break;
      case 4:  clrscr(); cout<<"Выбор произведен :"<<menu_4[4]<<endl; getch(); break;
      case 5:  clrscr(); cout<<"Выбор произведен :"<<menu_4[5]<<endl; getch(); break;
      case 6:  clrscr(); cout<<"Выбор произведен :"<<menu_4[6]<<endl; getch(); break;
      case 7:  clrscr(); cout<<"Выбор произведен :"<<menu_4[7]<<endl; getch(); break;
      case 8:  clrscr(); cout<<"Выбор произведен :"<<menu_4[8]<<endl; getch(); break;
      case 9:  clrscr(); cout<<"Выбор произведен :"<<menu_4[9]<<endl; getch(); break;
      case 10:  clrscr(); cout<<"Выбор произведен :"<<menu_4[10]<<endl;getch(); break;
      default:  break;

   }


break;


default: break;

}
/****************************************************************/
//cout<<GetResp((sizeof(menu_main)/2),menu_main); //
//getch();
       }  //end for

}              //end main
/*******************************************************************/
write_video(char * menu1, char * menu2)   { cout<<menu1<<endl;
cout<<menu2<<endl;
    }
/*******************************************************************/

signed char GetResp(unsigned char count,  char  * menu[]  )
{
signed char arrow_choice=0,c;
/********************************/
clrscr();
write_video( menu[0] , menu[1] );



#ifdef DEBUG
cout<<"arrow_choice = "<<(int)arrow_choice<<" count="<<(int)count<<endl;
#endif
/*********************************/
while (1){
c=getch();
	   switch(c) {

case TERM:  exit(0); break;
/***********************************************************/
case DOWN:  arrow_choice++;
break;
/******************************************************************/
case UP:   arrow_choice--;
break;
/*******************************************************************/
case ESC:  return -1;
break;
/*******************************************************************/
case ENTER: return arrow_choice;
break;
/********************************************************************/
default: break;
		      } //end switch

clrscr();

if(arrow_choice==count)  arrow_choice=0;
if(arrow_choice<0)   arrow_choice=count-1;

if(arrow_choice==(count-1))
		   {
write_video(menu[arrow_choice],"");
		    }
		   else {
write_video(menu[arrow_choice],menu[arrow_choice+1]);
			 }



#ifdef DEBUG
cout<<"arrow_choice = "<<(int)arrow_choice<<" count="<<(int)count<<endl;
#endif
	     }//end while

}
/**/
