
unit SEG7X4A
{
	public const uint16 ID = 0;
	
	public link unit A {}
	public link unit B {}
	public link unit C {}
	public link unit D {}
	public link unit E {}
	public link unit F {}
	public link unit G {}
	public link unit H {}
	
	public link unit S1 {}
	public link unit S2 {}
	public link unit S3 {}
	public link unit S4 {}
	public link unit S5 {}
	public link unit S6 {}
	public link unit S7 {}
	public link unit S8 {}
	
	//[i] interface_map map;
	public unit map
	{
		link int8 AreaNumber;
		link int16 LineNumber;
		link uint8 BackData;
		link uint8 ClearData;
		link void Clear() {}
		link void set_pos( int16 Line, int16 area ) {}
		link void set_uint8( uint8 d ) {}
		link uint16 get_uint8() {}
		public const int8 TYPE = 1;
	}
	map.AreaNumber = AreaNumber;
	map.LineNumber = LineNumber;
	map.BackData = BackData;
	map.ClearData = ClearData;
	map.set_pos = set_pos;
	map.set_uint8 = set_uint8;
	map.get_uint8 = get_uint8;
	map.Clear = clear;
	
	//[i] var_uint8 OS_time;
	public uint8 OS_time;
	
	//四个显示单元和小数点位置
	[uint8*8] data;
	[uint8*8] data_show;
	bool is_changed;
	
	uint8 current_index;
	uint8 current_select;
	
	const uint8 SELECT_DATA0 = 0X80;
	const uint8 NO_SELECT = 0X00;
	const uint8 NO_SEG = 0X00;
	
	//---------------------------------------------------
	//[i] function_void OS_init;
	public void OS_init()
	{
		RunInit();
		
		is_changed = false;
		
		BackData = 0x00;
		ClearData = 0x00;
		
		clear();
		OS_time = 3;
		reset();
	}
	//---------------------------------------------------
	//[i] function_void OS_run;
	
	//...
	
	//---------------------------------------------------
	//[i] function_void OS_thread;
	public void OS_thread()
	{
		if( is_changed ) {
			is_changed = false;
			DataChanged();
		}
	}
	//---------------------------------------------------
	//[i] function_void clear;
	public void clear()
	{
		data[0] = NO_SEG;
		data[1] = NO_SEG;
		data[2] = NO_SEG;
		data[3] = NO_SEG;
		data[4] = NO_SEG;
		data[5] = NO_SEG;
		data[6] = NO_SEG;
		data[7] = NO_SEG;
		
		is_changed = true;
	}
	//---------------------------------------------------
	//[i] function_void open int32 int32;
	public void open( int32 l, int32 c )
	{
		int8 ll = (int8)(int16)l - 1;
		int8 cc = (int8)(int16)c - 1;
		if( ll < 0 || ll > 7 || cc < 0 || cc > 7 ) return;
		data[cc] = data[cc] | (0x01 << (uint)ll);
		is_changed = true;
	}
	//---------------------------------------------------
	//[i] function_void close int32 int32;
	public void close( int32 l, int32 c )
	{
		int8 ll = (int8)(int16)l - 1;
		int8 cc = (int8)(int16)c - 1;
		if( ll < 0 || ll > 7 || cc < 0 || cc > 7 ) return;
		data[cc] = data[cc] & ~(0x01 << (uint)ll);
		is_changed = true;
	}
	//---------------------------------------------------
	//[i] function_void swap int32 int32;
	public void swap( int32 l, int32 c )
	{
		int8 ll = (int8)(int16)l - 1;
		int8 cc = (int8)(int16)c - 1;
		if( ll < 0 || ll > 7 || cc < 0 || cc > 7 ) return;
		data[cc] = data[cc] ^ (0x01 << (uint)ll);
		is_changed = true;
	}
	//---------------------------------------------------
	//[i] function_bool is_open int32 int32;
	public bool is_open( int32 l, int32 c )
	{
		int8 ll = (int8)(int16)l - 1;
		int8 cc = (int8)(int16)c - 1;
		if( ll < 0 || ll > 7 || cc < 0 || cc > 7 ) return false;
		return data[cc] & (0x01 << (uint)ll) != 0;
	}
	
	//[i] var_int8 AreaNumber;
	public const int8 AreaNumber = 1;
	//[i] var_int16 LineNumber;
	public const int16 LineNumber = 8;
	//[i] var_uint8 BackData;
	public uint8 BackData;
	//[i] var_uint8 ClearData;
	public uint8 ClearData;
	
	int16 Line;
	int16 area;
	
	//---------------------------------------------------
	//[i] function_void set_pos int16 int16;
	void set_pos( int16 l, int16 a )
	{
		Line = l;
		area = a;
	}
	//---------------------------------------------------
	//[i] function_void set_uint8 uint8;
	void set_uint8( uint8 d )
	{
		if( area >= 0 && area < AreaNumber && Line >= 0 && Line < LineNumber ) {
			data[area*LineNumber + Line] = d;
			is_changed = true;
		}
		Line + 1;
	}
	
	//---------------------------------------------------
	//[i] function_uint8 get_uint8;
	uint16 get_uint8()
	{
		if( area < 0 || area >= AreaNumber || Line < 0 || Line >= LineNumber ) return BackData;
		return data[area*LineNumber + Line];
	}
	
	#include "$run$.txt"
}


