
unit char
{
	//[i] linkinterface_map map;
	public link unit map {}

	->struct icon NFont;
	public struct icon
	{
		uint8 Line;
		uint8 Column;
		[uint8*?] buffer;
	}

	//---------------------------------------------------
	//提供的接口
	//[i] interface_char char;
	unit char
	{
		link void clear() {}
		link void clear_line( int32 l ) {}
		link void write_char( int32 l, int32 c, [#.code int8*?] string ) {}
		public const int8 PerWidth = 16;
	}
	char.clear = clear;
	char.clear_line = clear_line;
	char.write_char = print_line;
	
	//---------------------------------------------------
	//初始化
	//[i] function_void OS_init;
	public void OS_init()
	{
		
	}
	//---------------------------------------------------
	//清空
	//[i] function_void clear;
	public void clear()
	{
		int8 i = 0;
		loop( 64 ) {
			map.TBuffer[i] = 0;
			i + 1;
		}
	}
	//---------------------------------------------------
	//清空第 n 行
	//[i] function_void clear_line int32;
	public void clear_line( int32 line )
	{
		
	}
	//---------------------------------------------------
	//第 n 行显示
	//[i] function_void print_line int32 int32 Achar;
	public void print_line( int32 YY, int32 XX, int32 c )
	{
		XX = XX / 16 * 16;
		
		if( c >= '0' && c <= '9' ) {
			c - '0';
		}
		int16 X = (int16)XX;
		int16 Y = (int16)YY;
		int16 AreaX;
		uint8 OffsetX;
		SawToothMod16( X, AreaX, OffsetX );
		map.WTXN = AreaX;
		uint16 XBlockNumber = 10;
		
		uint8 line = NFont.Line;
		uint8 WN = NFont.Column / 80;
		
		//行列遍历输出图标
		uint16 BufferIndex = 0;
		for( uint8 i = 0; i < line; i + 1 ) {
			BufferIndex = (uint16)(uint)c * line  * WN + i;
			uint16 LastData = 0;
			uint16 XN;
			for( XN = 0; XN < WN; XN + 2 ) {
				uint32 data = 0;
				uint8 d = NFont.buffer[BufferIndex];
				BufferIndex + line;
				uint8 d1 = NFont.buffer[BufferIndex];
				if( c == ' ' ) {
					d = 0;
					d1 = 0;
				}
				data.24(uint8) = d;
				if( XN + 1 != XBlockNumber ) {
					data.16(uint8) = d1;
				}
				BufferIndex + line;
				data >> OffsetX;
				data.16(uint16) = data.16(uint16) | LastData;
				LastData = data.0(uint16);
				uint16 temp = data.16(uint16);
				//temp | map.get_uint8( Y + (int)i, AreaX + (int)XN/2 );
				temp = 0xFF;
				map.set_uint8( Y + (int)i, AreaX + (int)XN/2, temp );
			}
			if( OffsetX != 0 ) {
				LastData | map.get_uint8( Y + (int)i, AreaX + (int)XN/2 );
				map.set_uint8( Y + (int)i, AreaX + (int)XN/2, LastData );
			}
		}
		
		map.RTXN = map.WTXN;
	}
	//---------------------------------------------------
	//[i] function_void SetNumberFont bitmap;
	public void SetNumberFont( struct icon icon )
	{
		NFont -> icon;
	}
	//---------------------------------------------------
	//锯齿取模函数, 计算一个数除以8的锯齿除法和锯齿余数(不是内置除法和取余)
	void SawToothMod16( int16 n, #.base int16 Area, #.base uint8 Offset )
	{
		if( n > 0 ) {
			Area = n / 16;
			Offset = (uint)(int8)(n % 16);
		}
		else {
			Area = n / 16 - 1;
			Offset = 16 - (uint)(int8)(-n % 16);
		}
	}
}



