

unit inter
{
	bit last_keyA_press;
	bit last_keyB_press;
	
	void init()
	{
		last_keyA_press = 1;
		last_keyB_press = 1;
	}
}

void sim()
{
	bit KEY0_IN = SW.DA_IN;
	bit key_down = ~KEY0_IN & inter.last_keyA_press;
	if( key_down == 1 ) {
		OS_EventFlag.0(bit) = 1;
		tick + 1;
	}
	inter.last_keyA_press = KEY0_IN;
	
	KEY0_IN = SW.DB_IN;
	key_down = ~KEY0_IN & inter.last_keyB_press;
	if( key_down == 1 ) {
		OS_EventFlag.1(bit) = 1;
		tick - 1;
	}
	inter.last_keyB_press = KEY0_IN;
}

SW = surport;

surport.ID = ID;
unit surport
{
	public const uint16 ID = 0;
	
	public bit D0_DIR;
	public bit D0_OUT;
	public my_bit bit D0_IN = #addr ID * 0x00010000 + 0x0000;
	
	public my_bit bit DA_IN = #addr ID * 0x00010000 + 0x0001;
	public my_bit bit DB_IN = #addr ID * 0x00010000 + 0x0002;
	
	memory my_bit { type = [ uint32] uint8; }
	uint8 get_uint8( uint32 addr )
	{
		return (uint8)(uint16)(uint)#.OS.REMO_ModuleRead( (int)addr );
	}
}


