
unit Text
{
	public const uint16 ID = 0;
	
	//---------------------------------------------------
	//[i] linkinterface_char char;
	link unit char {}
	
	[int8*11] number_buffer;
	
	int8 bchar;
	int8 number;
	
	//---------------------------------------------------
	//[i] function_void OS_init;
	public void OS_init()
	{
		bchar = ' ';
		number = 0;
	}
	//---------------------------------------------------
	//[i] function_void clear;
	public void clear()
	{
		char.clear();
	}
	//---------------------------------------------------
	//[i] function_void clear_line int32;
	public void clear_line( int32 line )
	{
		char.clear_line( line );
	}
	//---------------------------------------------------
	//[i] function_void show_text int32 int32 Cstring;
	public void show_text( int32 line, int32 column, [int8*?] string )
	{
		int16 i = 0;
		forever {
			uint8 ch = (uint)string[i];
			if( ch == 0 ) return;
			
			uint32 cc = ch;
			if( ch > 127 ) {
				i + 1;
				cc.0(uint8) = ch;
				cc.8(uint8) = (uint)string[i];
			}
			char.write_char( line, column, (int)cc );
			column + char.PerWidth;
			i + 1;
		}
	}
	//---------------------------------------------------
	//[i] function_void show_text_f int32 int32 Cstring;
	public void show_text_f( int32 line, int32 column, [int8*?] string )
	{
		int16 i = 0;
		forever {
			int8 ch = string[i];
			if( ch == 0 ) break;
			i + 1;
		}
		i - 1;
		column = column - i * char.PerWidth;
		i = 0;
		forever {
			uint8 ch = (uint)string[i];
			if( ch == 0 ) return;
			
			uint32 cc = ch;
			if( ch > 127 ) {
				i + 1;
				cc.0(uint8) = ch;
				cc.8(uint8) = (uint)string[i];
			}
			char.write_char( line, column, (int)cc );
			column + char.PerWidth;
			i + 1;
		}
	}
	//---------------------------------------------------
	//[i] function_void show_number_ff int32 int32 int32;
	//[i] function_void_old show_number_f int32 int32 int32;
	public void show_number_f( int32 line, int32 column, int32 data0 )
	{
		show_number_ff( line, column, data0 );
	}
	public void show_number_ff( int32 line, int32 column, int32 data0 )
	{
		//计算正负数
		bool isNeg;
		uint32 data;
		if( data0 >= 0 ) {
			data = (uint)data0;
			isNeg = false;
		} else {
			data = (uint)-data0;
			isNeg = true;
		}
		//解析数字到缓冲区中
		int8 i = 0;
		forever {
			int8 ch = '0' + (int)(uint8)(uint16)(data % 10);
			number_buffer[i] = ch;
			i + 1;
			data / 10;
			if( data == 0 ) {
				break;
			}
		}
		//补齐数字格式
		if( number != 0 && i < number ) {
			int8 x = number - i;
			int8 y = i;
			loop( x ) {
				number_buffer[y] = bchar;
				y + 1;
			}
			i = number;
		}
		if( isNeg ) {
			number_buffer[i] = '-';
			i + 1;
		}
		//显示缓冲区中的字符到屏幕上
		int8 j = 0;
		loop( i ) {
			int8 ch = number_buffer[j];
			char.write_char( line, column, ch );
			j + 1;
			column - char.PerWidth;
		}
	}
	//---------------------------------------------------
	//[i] function_void show_number int32 int32 int32;
	public void show_number( int32 line, int32 column, int32 data0 )
	{
		//计算正负数
		bool isNeg;
		uint32 data;
		if( data0 >= 0 ) {
			data = (uint)data0;
			isNeg = false;
		} else {
			data = (uint)-data0;
			isNeg = true;
		}
		//解析数字到缓冲区中
		int8 i = 0;
		forever {
			int8 ch = '0' + (int)(uint8)(uint16)(data % 10);
			number_buffer[i] = ch;
			i + 1;
			data / 10;
			if( data == 0 ) {
				break;
			}
		}
		//补齐数字格式
		if( number != 0 && i < number ) {
			int8 x = number - i;
			int8 y = i;
			loop( x ) {
				number_buffer[y] = bchar;
				y + 1;
			}
			i = number;
		}
		if( isNeg ) {
			number_buffer[i] = '-';
			i + 1;
		}
		//显示缓冲区中的字符到屏幕上
		column + (char.PerWidth*(i - 1));
		int8 j = 0;
		loop( i ) {
			int8 ch = number_buffer[j];
			char.write_char( line, column, ch );
			j + 1;
			column - char.PerWidth;
		}
	}
	//---------------------------------------------------
	//[i] function_void set_format int32 int32;
	public void set_format( int32 c, int32 n )
	{
		bchar = (int8)(int16)c;
		if( bchar < ' ' ) {
			bchar + '0';
		}
		number = (int8)(int16)n;
		if( number > 11 ) {
			number = 11;
		}
	}
	//---------------------------------------------------
	//[i] function_void clear_format;
	public void clear_format()
	{
		number = 0;
	}
}






