
//**********************************************
//定义内部字节地址存储器

public unit vbasetype
{
	public memory base
	{
		target = base_instance;
		type = [ uint16 0x0060, 0x045f ] uint8;
	}
	unit base_instance
	{
		//uint8 写入和读出
		public uint8 get_uint8( uint16 addr )
		{
			#asm "ldd r30,y+0"
			#asm "ldd r31,y+1"
			#asm "andi r31,15"
			#asm "ld r27,z"
			#asm "mov r31,r27"
		}
		public void set_uint8( uint16 addr, uint8 data )
		{
			#asm "ldd r30,y+0"
			#asm "ldd r31,y+1"
			#asm "andi r31,15"
			#asm "ldd r27,y+2"
			#asm "st z,r27"
		}
		//uint16 写入和读出
		public uint16 get_uint16( uint16 addr )
		{
			#asm "ldd r30,y+0"
			#asm "ldd r31,y+1"
			#asm "andi r31,15"
			#asm "ld r26,z+"
			#asm "ld r27,z"
			#asm "mov r30,r26"
			#asm "mov r31,r27"
		}
		public void set_uint16( uint16 addr, uint16 data )
		{
			#asm "ldd r30,y+0"
			#asm "ldd r31,y+1"
			#asm "andi r31,15"
			#asm "ldd r26,y+2"
			#asm "ldd r27,y+3"
			#asm "st z+,r26"
			#asm "st z,r27"
		}
		//L32 写入和读出
		public uint32 get_uint32( uint16 addr )
		{
			#asm "ldd r30,y+0"
			#asm "ldd r31,y+1"
			#asm "andi r31,15"
			#asm "ld r26,z+"
			#asm "ld r27,z+"
			#asm "ld r0,z+"
			#asm "ld r1,z"
			#asm "mov r30,r0"
			#asm "mov r31,r1"
		}
		public void set_uint32( uint16 addr, uint32 data )
		{
			#asm "ldd r30,y+0"
			#asm "ldd r31,y+1"
			#asm "andi r31,15"
			#asm "ldd r26,y+2"
			#asm "ldd r27,y+3"
			#asm "ldd r0,y+4"
			#asm "ldd r1,y+5"
			#asm "st z+,r26"
			#asm "st z+,r27"
			#asm "st z+,r0"
			#asm "st z,r1"
		}
	}
}
//**********************************************
//代码区存储器
public unit vcodetype
{
	public memory code
	{
		target = code_instance;
		type = [ uint16 0x0080, 0xffff ] uint8;  //[0x0080, 0x1fff],
	}
	unit code_instance
	{
		public uint8 get_uint8( uint16 addr )
		{
			#asm "ldd r30,y+0"
			#asm "ldd r31,y+1"
			#asm "andi r31,15"
			#asm "lpm r27,z"
			#asm "mov r31,r27"
		}
		public uint16 get_uint16( uint16 addr )
		{
			#asm "ldd r30,y+0"
			#asm "ldd r31,y+1"
			#asm "andi r31,15"
			#asm "lpm r26,z+"
			#asm "lpm r27,z"
			#asm "mov r30,r26"
			#asm "mov r31,r27"
		}
		public uint32 get_uint32( uint16 addr )
		{
			#asm "ldd r30,y+0"
			#asm "ldd r31,y+1"
			#asm "andi r31,15"
			#asm "lpm r26,z+"
			#asm "lpm r27,z+"
			#asm "lpm r0,z+"
			#asm "lpm r1,z"
			#asm "mov r30,r0"
			#asm "mov r31,r1"
		}
	}
}





