
unit SerialPort
{
	link memory linka {} = #.linker.linka;
	
	//[i] linksysconst_uint8 ID;
	public const uint8 ID = 0;
	
	//[i] interface_reader reader0;
	unit reader0
	{
		public link bool IsReady() {}
		public link int32 GetData() {}
		public link void SetData( int32 d ) {}
		public link void SetStart() {}
		public link int32 ReadBuffer( int32 i ) {}
	}
	reader0.IsReady = is_ready;
	reader0.GetData = get_data;
	reader0.SetData = print_char;
	reader0.SetStart = SetStart;
	reader0.ReadBuffer = ReadBuffer;
	
	//[i] var_uint8 OS_EventFlag;
	public uint8 OS_EventFlag;
	
	//[i] event ReceiveEvent;
	
	//[i] var_int32 X;
	public linka int32 X = #addr ID * 0x0100 + 0x01;
	//[i] var_int32 Y;
	public linka int32 Y = #addr ID * 0x0100 + 0x02;
	//[i] var_int32 Width;
	public linka int32 Width = #addr ID * 0x0100 + 0x03;
	//[i] var_int32 Height;
	public linka int32 Height = #addr ID * 0x0100 + 0x04;
	//[i] var_int32 BackColor;
	public linka int32 BackColor = #addr ID * 0x0100 + 0x05;
	//[i] var_int32 ForeColor;
	public linka int32 ForeColor = #addr ID * 0x0100 + 0x06;

	linka int32 Data = #addr ID * 0x0100 + 0x20;
	linka int32 Number = #addr ID * 0x0100 + 0x21;
	linka int32 CData = #addr ID * 0x0100 + 0x22;

	//---------------------------------------------------
	//初始化
	//[i] function_void OS_init;
	public void OS_init()
	{
		OS_EventFlag = 0;
	}
	//---------------------------------------------------
	//[i] function_void OS_thread;
	public void OS_thread()
	{
		if( is_ready() ) {
			OS_EventFlag.0(bit) = 1;
		}
	}
	//---------------------------------------------------
	//[i] function_void print_string Astring;
	//[i] function_void print_number int32;
	#include <system\common\uart\uart_extend.txt>
	
	public void print_byte( int8 d )
	{
		print_char( d );
	}
	//---------------------------------------------------
	//发送字符
	//[i] function_void print_char int32;
	public void print_char( int32 d )
	{
		#.linker.SetValue( ID, 0x11, (uint)d );
	}
	//---------------------------------------------------
	//读取一个数据
	//[i] function_int32 get_data;
	public int32 get_data()
	{
		return (int)#.linker.GetValue( ID, 0x20 );
	}
	//---------------------------------------------------
	//[i] function_bool is_ready;
	public bool is_ready()
	{
		return #.linker.GetValue( ID, 0x21 ) != 0;
	}
	//---------------------------------------------------
	//设置扩展参数
	//[i] function_void SetValue Cstring;
	public void SetValue( [#.code uint16*?] string )
	{
		#.linker.SetString( ID, 0x10, string );
	}

	void SetStart()
	{
		#.linker.SetValue( ID, 0x13, 0 );
	}
	int32 ReadBuffer( int32 n )
	{
		#.linker.SetValue( ID, 0x14, (uint)n );
		return CData;
	}
	//---------------------------------------------------
	//[i] function_void SetFont Cstring;
	public void SetFont( [#.code uint16*?] string )
	{
		#.linker.SetString( ID, 0x15, string );
	}
}








