#include "src\eng_comm.h"
#include <iostream>
int ex = 0;
int ey = 0;
int qing = 4;

/*
void (*handle[INPUT_MAX])();

void input_up() { dy--; }
void input_down() { dy++; }
// ...

handle[80] = input_down;
handle[72] = input_up;
// ...

Now in your main loop:

handle[input]();


// Complexity O(1)
*/

namespace engine {

	/*engine_message do_communication()
	{
		//communication here
//====		std::cout << "COMMUNICATION HERE" << std::endl;
		int msg;
		std::cout << "Enter 1 for continue." << std::endl;
		std::cin >> msg;
		return msg == 1 ? ENGINE_RUN : ENGINE_QUIT;
	}*/
	/*engine_message do_communication(bool *input)
	{
		//communication here
//====		std::cout << "COMMUNICATION HERE" << std::endl;
		return input['e'] == true ? ENGINE_QUIT : ENGINE_RUN;
	}*/
	engine_message do_communication(byte input)
	{
		//communication here
//====		std::cout << "COMMUNICATION HERE" << std::endl;
		if(input == 44){
			FMKeyOn(0, 0x106, 4);
		}else if(input == 172) FMKeyOff(0);
		if(input == 2) qing = 1;
		if(input == 3) qing = 2;
		if(input == 4) qing = 3;
		if(input == 5) qing = 4;
		if(input == 6) qing = 5;
		if(input == 7) qing = 6;
		if(input == 8) qing = 7;
		if(input == 9) qing = 8;
		if(input == 10) qing = 9;
		if(input == 57) qing = 0;
		if(qing > 0){
			ding(qing);
		}else{
			qtesuto(ex, ey, 0);
			if(keyp(KEY_UP)){
				if(--ey < 0) ey = 0;
			}else if(keyp(KEY_DOWN)){
				if(++ey >= SH) ey = SH - 1;
			}
			if(keyp(KEY_LEFT)){
				if(--ex < 0) ex = 0;
			}else if(keyp(KEY_RIGHT)){
				if(++ex >= SW) ex = SW - 1;
			}
			ctesuto(ex, ey);
		}
		//if(input) printf("%03d\n", input);
		return input == 1 ? ENGINE_QUIT : ENGINE_RUN;
	}

}