
unit CrossRol
{
	public const uint16 ID = 0;
	
	public link unit CLK {}
	public link unit DT {}
	public link unit SW {}
	
	//[i] var_uint8 OS_EventFlag;
	uint8 OS_EventFlag;
	
	//[i] var_uint8 OS_time;
	uint8 OS_time;
	
	//---------------------
	//[i] var_int32_w tick;
	public int32 tick;
	
	//---------------------
	//[i] var_bool key0_press;
	public bool key0_press;
	//---------------------
	//[i] var_bool key0_notpress;
	public bool key0_notpress;
	
	bit last_key0_press;
	
	//[i] event rol_right_event;
	//[i] event rol_left_event;
	//[i] event down_event;
	//[i] event up_event;
	
	#include "$run$.txt"
	
	//---------------------------------------------------
	//[i] function_void OS_init;
	void OS_init()
	{
		CLK.D0_DIR = 0;
		CLK.D0_OUT = 1;
		DT.D0_DIR = 0;
		DT.D0_OUT = 1;
		SW.D0_DIR = 0;
		SW.D0_OUT = 1;
		inter.init();
		
		OS_time = 1;
		OS_EventFlag = 0;
		
		key0_press = false;
		key0_notpress = true;
		last_key0_press = 1;
		
		tick = 0;
	}
	//---------------------------------------------------
	//[i] function_void OS_run;
	void OS_run()
	{
		bit KEY0_IN = SW.D0_IN;
		
		bit key0_down = ~KEY0_IN & last_key0_press;
		bit key0_up = KEY0_IN & ~last_key0_press;
		if( key0_down == 1 ) OS_EventFlag.2(bit) = 1;
		if( key0_up == 1 ) OS_EventFlag.3(bit) = 1;
		last_key0_press = KEY0_IN;
		
		if( KEY0_IN == 0 ) {
			key0_press = true;
			key0_notpress = false;
		}
		else {
			key0_press = false;
			key0_notpress = true;
		}
		sim();
	}
}




