
unit WaveBox
{
	link memory linka {} = #.linker.linka;

	//[i] linksysconst_uint8 ID;
	public const uint8 ID = 0;
	
	//[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_uint8( int16 Line, int16 area, uint16 d ) {}
		link uint8 get_uint8( int16 Line, int16 area ) {}
		public const int8 TYPE = 1;
	}
	map.AreaNumber = AreaNumber;
	map.LineNumber = LineNumber;
	map.BackData = BackData;
	map.ClearData = ClearData;
	map.set_uint8 = set_uint8;
	map.get_uint8 = get_uint8;
	map.Clear = Clear;
	
	//[i] var_int32 w;
	public int32 w;
	//[i] var_int32 h;
	public int32 h;
	
	//[i] var_uint8 BackData;
	public uint8 BackData;
	//[i] var_uint8 ClearData;
	public uint8 ClearData;
	
	//---------------------------------------------------
	//[i] function_void OS_init;
	public void OS_init()
	{
		BackData = 0x00;
		ClearData = 0x00;
	}
	//---------------------------------------------------
	//[i] function_void Clear;
	void Clear()
	{
		#.linker.SetValue( ID, 0x11, ClearData );
	}
	//---------------------------------------------------
	//[i] function_void SetPoint int32 int32;
	void SetPoint( int32 x, int32 y )
	{
		if( x < 0 || y < 0 || x >= LineNumber || y >= AreaNumber*8 ) {
			return;
		}
		int8 areadiv = (int8)(int16)(y / 8);
		int8 areamod = (int8)(int16)(y % 8);
		uint8 d = 0b00000001;
		uint8 dd = get_uint8( (int16)x, areadiv );
		dd = dd | d << (uint)areamod;
		set_uint8( (int16)x, areadiv, dd );
	}
	//---------------------------------------------------
	//[i] function_void ClearPoint int32 int32;
	void ClearPoint( int32 x, int32 y )
	{
		if( x < 0 || y < 0 || x >= LineNumber || y >= AreaNumber*8 ) {
			return;
		}
		int8 areadiv = (int8)(int16)(y / 8);
		int8 areamod = (int8)(int16)(y % 8);
		uint8 d = 0b00000001;
		uint8 dd = get_uint8( (int16)x, areadiv );
		dd = dd & ~(d << (uint)areamod);
		set_uint8( (int16)x, areadiv, dd );
	}
	//---------------------------------------------------
	//[i] function_void ReadPoint int32 int32;
	bool ReadPoint( int32 x, int32 y )
	{
		if( x < 0 || y < 0 || x >= LineNumber || y >= AreaNumber*8 ) {
			return false;
		}
		int8 areadiv = (int8)(int16)(y / 8);
		int8 areamod = (int8)(int16)(y % 8);
		uint8 d = 0b00000001;
		uint8 dd = get_uint8( (int16)x, areadiv );
		dd = dd & d << (uint)areamod;
		return d != 0;
	}
	//---------------------------------------------------
	
	void set_uint8( int16 Line, int16 area, uint16 d )
	{
		if( area < 0 || area >= AreaNumber || Line < 0 || Line >= LineNumber ) return;
		
		uint32 data = (uint)Line;
		data.16(uint8) = (uint8)(uint)area;
		data.24(uint8) = d.0(uint8);
		#.linker.SetValue( ID, 0x12, data );
	}
	uint8 get_uint8( int16 Line, int16 area )
	{
		if( area < 0 || area >= AreaNumber || Line < 0 || Line >= LineNumber ) return BackData;
		
		uint32 data = (uint)Line;
		data.16(uint8) = (uint8)(uint)area;
		data.24(uint8) = 0;
		#.linker.SetValue( ID, 0x13, data );
		return (uint8)(uint16)(uint)Value;
	}
	
	//[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;
	
	//[i] var_int32 Value;
	public linka int32 Value = #addr ID * 0x0100 + 0x10;
	
	//[i] var_int8 AreaNumber;
	public int8 AreaNumber;
	//[i] var_int16 LineNumber;
	public int16 LineNumber;
}







