2013-10-28 19:13:01 +00:00
using System ;
2014-06-03 02:19:13 +00:00
using System.ComponentModel ;
2017-07-10 04:51:02 +00:00
using NLua ;
2014-05-23 23:19:20 +00:00
using BizHawk.Emulation.Common ;
2014-09-01 18:43:41 +00:00
using BizHawk.Emulation.Common.IEmulatorExtensions ;
2013-10-28 19:13:01 +00:00
2013-11-01 14:51:51 +00:00
namespace BizHawk.Client.Common
2013-10-28 19:13:01 +00:00
{
2014-06-03 02:19:13 +00:00
[Description("Main memory library reads and writes from the Main memory domain (the default memory domain set by any given core)")]
2014-06-01 22:02:59 +00:00
public sealed class MainMemoryLuaLibrary : LuaMemoryBase
2013-10-28 19:13:01 +00:00
{
2013-10-31 16:10:20 +00:00
public MainMemoryLuaLibrary ( Lua lua )
2014-05-21 00:17:35 +00:00
: base ( lua ) { }
public MainMemoryLuaLibrary ( Lua lua , Action < string > logOutputCallback )
: base ( lua , logOutputCallback ) { }
2013-10-31 16:10:20 +00:00
2017-04-14 19:59:01 +00:00
public override string Name = > "mainmemory" ;
2013-10-31 16:10:20 +00:00
2017-04-15 20:37:30 +00:00
protected override MemoryDomain Domain
2013-10-28 19:13:01 +00:00
{
2014-09-01 18:43:41 +00:00
get
{
2015-01-01 20:19:20 +00:00
if ( MemoryDomainCore ! = null )
2014-09-01 18:43:41 +00:00
{
2015-01-14 21:55:48 +00:00
return MemoryDomainCore . MainMemory ;
2014-09-01 18:43:41 +00:00
}
else
{
2017-04-14 19:59:01 +00:00
var error = $"Error: {Emulator.Attributes().CoreName} does not implement memory domains" ;
2014-09-01 18:43:41 +00:00
Log ( error ) ;
throw new NotImplementedException ( error ) ;
}
}
2013-10-28 19:13:01 +00:00
}
2014-05-23 23:19:20 +00:00
#region Unique Library Methods
2013-10-28 19:13:01 +00:00
2018-03-14 01:05:30 +00:00
[LuaMethodExample("local stmaiget = mainmemory.getname( );")]
2017-07-10 19:02:00 +00:00
[LuaMethod("getname", "returns the name of the domain defined as main memory for the given core")]
2014-01-26 01:48:32 +00:00
public string GetName ( )
2013-10-28 19:13:01 +00:00
{
2014-05-23 23:19:20 +00:00
return Domain . Name ;
2013-10-28 19:13:01 +00:00
}
2018-03-14 01:05:30 +00:00
[LuaMethodExample("local uimaiget = mainmemory.getcurrentmemorydomainsize( );")]
2017-07-10 19:02:00 +00:00
[LuaMethod("getcurrentmemorydomainsize", "Returns the number of bytes of the domain defined as main memory")]
2015-01-18 17:28:02 +00:00
public uint GetSize ( )
2013-10-28 19:13:01 +00:00
{
2015-01-18 15:25:47 +00:00
return ( uint ) Domain . Size ;
2013-10-28 19:13:01 +00:00
}
2014-05-23 23:19:20 +00:00
#endregion
#region Common Special and Legacy Methods
2013-10-28 19:13:01 +00:00
2018-03-14 01:05:30 +00:00
[LuaMethodExample("local uimairea = mainmemory.readbyte( 0x100 );")]
2017-07-10 19:02:00 +00:00
[LuaMethod("readbyte", "gets the value from the given address as an unsigned byte")]
2014-05-23 23:19:20 +00:00
public uint ReadByte ( int addr )
2013-10-28 19:13:01 +00:00
{
2014-05-23 23:19:20 +00:00
return ReadUnsignedByte ( addr ) ;
2013-10-28 19:13:01 +00:00
}
2018-03-14 01:05:30 +00:00
[LuaMethodExample("mainmemory.writebyte( 0x100, 1000 );")]
2017-07-10 19:02:00 +00:00
[LuaMethod("writebyte", "Writes the given value to the given address as an unsigned byte")]
2014-01-27 01:15:56 +00:00
public void WriteByte ( int addr , uint value )
2013-10-28 19:13:01 +00:00
{
2014-01-27 01:15:56 +00:00
WriteUnsignedByte ( addr , value ) ;
2013-10-28 19:13:01 +00:00
}
2018-03-14 01:05:30 +00:00
[LuaMethodExample("local nlmairea = mainmemory.readbyterange( 0x100, 64 );")]
2017-07-10 19:02:00 +00:00
[LuaMethod("readbyterange", "Reads the address range that starts from address, and is length long. Returns the result into a table of key value pairs (where the address is the key).")]
2016-01-31 02:28:49 +00:00
public LuaTable ReadByteRange ( int addr , int length )
2014-05-23 23:19:20 +00:00
{
return base . ReadByteRange ( addr , length ) ;
2013-10-28 19:13:01 +00:00
}
2018-03-14 01:05:30 +00:00
[LuaMethodExample("")]
2017-07-10 19:02:00 +00:00
[LuaMethod("writebyterange", "Writes the given values to the given addresses as unsigned bytes")]
2016-01-31 02:28:49 +00:00
public void WriteByteRange ( LuaTable memoryblock )
2013-10-28 19:13:01 +00:00
{
2014-05-23 23:19:20 +00:00
base . WriteByteRange ( memoryblock ) ;
2013-10-28 19:13:01 +00:00
}
2018-03-14 01:05:30 +00:00
[LuaMethodExample("local simairea = mainmemory.readfloat(0x100, false);")]
2017-07-10 19:02:00 +00:00
[LuaMethod("readfloat", "Reads the given address as a 32-bit float value from the main memory domain with th e given endian")]
2016-01-31 02:28:49 +00:00
public float ReadFloat ( int addr , bool bigendian )
2013-10-28 19:13:01 +00:00
{
2014-05-23 23:19:20 +00:00
return base . ReadFloat ( addr , bigendian ) ;
2013-10-28 19:13:01 +00:00
}
2018-03-14 01:05:30 +00:00
[LuaMethodExample("mainmemory.writefloat( 0x100, 10.0, false );")]
2017-07-10 19:02:00 +00:00
[LuaMethod("writefloat", "Writes the given 32-bit float value to the given address and endian")]
2016-01-31 02:28:49 +00:00
public void WriteFloat ( int addr , double value , bool bigendian )
2013-10-28 19:13:01 +00:00
{
2014-05-23 23:19:20 +00:00
base . WriteFloat ( addr , value , bigendian ) ;
2013-10-28 19:13:01 +00:00
}
2014-05-23 23:19:20 +00:00
#endregion
#region 1 Byte
2018-03-14 01:05:30 +00:00
[LuaMethodExample("local inmairea = mainmemory.read_s8( 0x100 );")]
2017-07-10 19:02:00 +00:00
[LuaMethod("read_s8", "read signed byte")]
2014-05-23 23:19:20 +00:00
public int ReadS8 ( int addr )
2013-10-28 19:13:01 +00:00
{
2014-05-23 23:19:20 +00:00
return ( sbyte ) ReadUnsignedByte ( addr ) ;
2013-10-28 19:13:01 +00:00
}
2018-03-14 01:05:30 +00:00
[LuaMethodExample("mainmemory.write_s8( 0x100, 1000 );")]
2017-07-10 19:02:00 +00:00
[LuaMethod("write_s8", "write signed byte")]
2014-05-23 23:19:20 +00:00
public void WriteS8 ( int addr , uint value )
2013-10-28 19:13:01 +00:00
{
2014-05-23 23:19:20 +00:00
WriteUnsignedByte ( addr , value ) ;
2013-10-28 19:13:01 +00:00
}
2018-03-14 01:05:30 +00:00
[LuaMethodExample("local uimairea = mainmemory.read_u8( 0x100 );")]
2017-07-10 19:02:00 +00:00
[LuaMethod("read_u8", "read unsigned byte")]
2014-05-23 23:19:20 +00:00
public uint ReadU8 ( int addr )
2013-10-28 19:13:01 +00:00
{
2014-05-23 23:19:20 +00:00
return ReadUnsignedByte ( addr ) ;
2013-10-28 19:13:01 +00:00
}
2018-03-14 01:05:30 +00:00
[LuaMethodExample("mainmemory.write_u8( 0x100, 1000 );")]
2017-07-10 19:02:00 +00:00
[LuaMethod("write_u8", "write unsigned byte")]
2014-05-23 23:19:20 +00:00
public void WriteU8 ( int addr , uint value )
2013-10-28 19:13:01 +00:00
{
2014-05-23 23:19:20 +00:00
WriteUnsignedByte ( addr , value ) ;
2013-10-28 19:13:01 +00:00
}
2014-05-23 23:19:20 +00:00
#endregion
#region 2 Byte
2018-03-14 01:05:30 +00:00
[LuaMethodExample("local inmairea = mainmemory.read_s16_le( 0x100 );")]
2017-07-10 19:02:00 +00:00
[LuaMethod("read_s16_le", "read signed 2 byte value, little endian")]
2014-05-23 23:19:20 +00:00
public int ReadS16Little ( int addr )
2013-10-28 19:13:01 +00:00
{
2014-05-23 23:19:20 +00:00
return ReadSignedLittleCore ( addr , 2 ) ;
2013-10-28 19:13:01 +00:00
}
2018-03-14 01:05:30 +00:00
[LuaMethodExample("mainmemory.write_s16_le( 0x100, -1000 );")]
2017-07-10 19:02:00 +00:00
[LuaMethod("write_s16_le", "write signed 2 byte value, little endian")]
2014-05-23 23:19:20 +00:00
public void WriteS16Little ( int addr , int value )
2013-10-28 19:13:01 +00:00
{
2014-05-23 23:19:20 +00:00
WriteSignedLittle ( addr , value , 2 ) ;
2013-10-28 19:13:01 +00:00
}
2018-03-14 01:05:30 +00:00
[LuaMethodExample("local inmairea = mainmemory.read_s16_be( 0x100 );")]
2017-07-10 19:02:00 +00:00
[LuaMethod("read_s16_be", "read signed 2 byte value, big endian")]
2014-01-27 01:15:56 +00:00
public int ReadS16Big ( int addr )
2013-10-28 19:13:01 +00:00
{
2014-01-27 01:15:56 +00:00
return ReadSignedBig ( addr , 2 ) ;
2013-10-28 19:13:01 +00:00
}
2018-03-14 01:05:30 +00:00
[LuaMethodExample("mainmemory.write_s16_be( 0x100, -1000 );")]
2017-07-10 19:02:00 +00:00
[LuaMethod("write_s16_be", "write signed 2 byte value, big endian")]
2014-05-23 23:19:20 +00:00
public void WriteS16Big ( int addr , int value )
2013-10-28 19:13:01 +00:00
{
2014-05-23 23:19:20 +00:00
WriteSignedBig ( addr , value , 2 ) ;
2013-10-28 19:13:01 +00:00
}
2018-03-14 01:05:30 +00:00
[LuaMethodExample("local uimairea = mainmemory.read_u16_le( 0x100 );")]
2017-07-10 19:02:00 +00:00
[LuaMethod("read_u16_le", "read unsigned 2 byte value, little endian")]
2014-05-23 23:19:20 +00:00
public uint ReadU16Little ( int addr )
2013-10-28 19:13:01 +00:00
{
2014-05-23 23:19:20 +00:00
return ReadSignedLittle ( addr , 2 ) ;
2013-10-28 19:13:01 +00:00
}
2018-03-14 01:05:30 +00:00
[LuaMethodExample("mainmemory.write_u16_le( 0x100, 1000 );")]
2017-07-10 19:02:00 +00:00
[LuaMethod("write_u16_le", "write unsigned 2 byte value, little endian")]
2014-05-23 23:19:20 +00:00
public void WriteU16Little ( int addr , uint value )
{
WriteUnsignedLittle ( addr , value , 2 ) ;
}
2018-03-14 01:05:30 +00:00
[LuaMethodExample("local uimairea = mainmemory.read_u16_be( 0x100 );")]
2017-07-10 19:02:00 +00:00
[LuaMethod("read_u16_be", "read unsigned 2 byte value, big endian")]
2014-01-27 01:15:56 +00:00
public uint ReadU16Big ( int addr )
2013-10-28 19:13:01 +00:00
{
2014-01-27 01:15:56 +00:00
return ReadUnsignedBig ( addr , 2 ) ;
2013-10-28 19:13:01 +00:00
}
2018-03-14 01:05:30 +00:00
[LuaMethodExample("mainmemory.write_u16_be( 0x100, 1000 );")]
2017-07-10 19:02:00 +00:00
[LuaMethod("write_u16_be", "write unsigned 2 byte value, big endian")]
2014-05-23 23:19:20 +00:00
public void WriteU16Big ( int addr , uint value )
2013-10-28 19:13:01 +00:00
{
2014-05-23 23:19:20 +00:00
WriteUnsignedBig ( addr , value , 2 ) ;
2013-10-28 19:13:01 +00:00
}
2014-05-23 23:19:20 +00:00
#endregion
#region 3 Byte
2018-03-14 01:05:30 +00:00
[LuaMethodExample("local inmairea = mainmemory.read_s24_le( 0x100 );")]
2017-07-10 19:02:00 +00:00
[LuaMethod("read_s24_le", "read signed 24 bit value, little endian")]
2014-05-23 23:19:20 +00:00
public int ReadS24Little ( int addr )
2013-10-28 19:13:01 +00:00
{
2014-05-23 23:19:20 +00:00
return ReadSignedLittleCore ( addr , 3 ) ;
2013-10-28 19:13:01 +00:00
}
2018-03-14 01:05:30 +00:00
[LuaMethodExample("mainmemory.write_s24_le( 0x100, -1000 );")]
2017-07-10 19:02:00 +00:00
[LuaMethod("write_s24_le", "write signed 24 bit value, little endian")]
2014-05-23 23:19:20 +00:00
public void WriteS24Little ( int addr , int value )
2013-10-28 19:13:01 +00:00
{
2014-05-23 23:19:20 +00:00
WriteSignedLittle ( addr , value , 3 ) ;
2013-10-28 19:13:01 +00:00
}
2018-03-14 01:05:30 +00:00
[LuaMethodExample("local inmairea = mainmemory.read_s24_be( 0x100 );")]
2017-07-10 19:02:00 +00:00
[LuaMethod("read_s24_be", "read signed 24 bit value, big endian")]
2014-05-23 23:19:20 +00:00
public int ReadS24Big ( int addr )
2013-10-28 19:13:01 +00:00
{
2014-05-23 23:19:20 +00:00
return ReadSignedBig ( addr , 3 ) ;
2013-10-28 19:13:01 +00:00
}
2018-03-14 01:05:30 +00:00
[LuaMethodExample("mainmemory.write_s24_be( 0x100, -1000 );")]
2017-07-10 19:02:00 +00:00
[LuaMethod("write_s24_be", "write signed 24 bit value, big endian")]
2014-05-23 23:19:20 +00:00
public void WriteS24Big ( int addr , int value )
2013-10-28 19:13:01 +00:00
{
2014-05-23 23:19:20 +00:00
WriteSignedBig ( addr , value , 3 ) ;
2013-10-28 19:13:01 +00:00
}
2018-03-14 01:05:30 +00:00
[LuaMethodExample("local uimairea = mainmemory.read_u24_le( 0x100 );")]
2017-07-10 19:02:00 +00:00
[LuaMethod("read_u24_le", "read unsigned 24 bit value, little endian")]
2014-05-23 23:19:20 +00:00
public uint ReadU24Little ( int addr )
2013-10-28 19:13:01 +00:00
{
2014-05-23 23:19:20 +00:00
return ReadSignedLittle ( addr , 3 ) ;
2013-10-28 19:13:01 +00:00
}
2018-03-14 01:05:30 +00:00
[LuaMethodExample("mainmemory.write_u24_le( 0x100, 1000 );")]
2017-07-10 19:02:00 +00:00
[LuaMethod("write_u24_le", "write unsigned 24 bit value, little endian")]
2014-05-23 23:19:20 +00:00
public void WriteU24Little ( int addr , uint value )
2013-10-28 19:13:01 +00:00
{
2014-05-23 23:19:20 +00:00
WriteUnsignedLittle ( addr , value , 3 ) ;
2013-10-28 19:13:01 +00:00
}
2018-03-14 01:05:30 +00:00
[LuaMethodExample("local uimairea = mainmemory.read_u24_be( 0x100 );")]
2017-07-10 19:02:00 +00:00
[LuaMethod("read_u24_be", "read unsigned 24 bit value, big endian")]
2014-05-23 23:19:20 +00:00
public uint ReadU24Big ( int addr )
2013-10-28 19:13:01 +00:00
{
2014-05-23 23:19:20 +00:00
return ReadUnsignedBig ( addr , 3 ) ;
2013-10-28 19:13:01 +00:00
}
2018-03-14 01:05:30 +00:00
[LuaMethodExample("mainmemory.write_u24_be( 0x100, 1000 );")]
2017-07-10 19:02:00 +00:00
[LuaMethod("write_u24_be", "write unsigned 24 bit value, big endian")]
2014-05-23 23:19:20 +00:00
public void WriteU24Big ( int addr , uint value )
2013-10-28 19:13:01 +00:00
{
2014-05-23 23:19:20 +00:00
WriteUnsignedBig ( addr , value , 3 ) ;
2013-10-28 19:13:01 +00:00
}
2014-05-23 23:19:20 +00:00
#endregion
#region 4 Byte
2018-03-14 01:05:30 +00:00
[LuaMethodExample("local inmairea = mainmemory.read_s32_le( 0x100 );")]
2017-07-10 19:02:00 +00:00
[LuaMethod("read_s32_le", "read signed 4 byte value, little endian")]
2014-05-23 23:19:20 +00:00
public int ReadS32Little ( int addr )
2013-10-28 19:13:01 +00:00
{
2014-05-23 23:19:20 +00:00
return ReadSignedLittleCore ( addr , 4 ) ;
2013-10-28 19:13:01 +00:00
}
2018-03-14 01:05:30 +00:00
[LuaMethodExample("mainmemory.write_s32_le( 0x100, -1000 );")]
2017-07-10 19:02:00 +00:00
[LuaMethod("write_s32_le", "write signed 4 byte value, little endian")]
2014-05-23 23:19:20 +00:00
public void WriteS32Little ( int addr , int value )
2014-01-26 01:48:32 +00:00
{
2014-05-23 23:19:20 +00:00
WriteSignedLittle ( addr , value , 4 ) ;
2014-01-26 01:48:32 +00:00
}
2013-10-28 19:13:01 +00:00
2018-03-14 01:05:30 +00:00
[LuaMethodExample("local inmairea = mainmemory.read_s32_be( 0x100 );")]
2017-07-10 19:02:00 +00:00
[LuaMethod("read_s32_be", "read signed 4 byte value, big endian")]
2014-05-23 23:19:20 +00:00
public int ReadS32Big ( int addr )
2014-01-26 01:48:32 +00:00
{
2014-05-23 23:19:20 +00:00
return ReadSignedBig ( addr , 4 ) ;
2014-01-26 01:48:32 +00:00
}
2013-10-28 19:13:01 +00:00
2018-03-14 01:05:30 +00:00
[LuaMethodExample("mainmemory.write_s32_be( 0x100, -1000 );")]
2017-07-10 19:02:00 +00:00
[LuaMethod("write_s32_be", "write signed 4 byte value, big endian")]
2014-01-27 01:15:56 +00:00
public void WriteS32Big ( int addr , int value )
2014-01-26 01:48:32 +00:00
{
2014-01-27 01:15:56 +00:00
WriteSignedBig ( addr , value , 4 ) ;
2014-01-26 01:48:32 +00:00
}
2013-10-28 19:13:01 +00:00
2018-03-14 01:05:30 +00:00
[LuaMethodExample("local uimairea = mainmemory.read_u32_le( 0x100 );")]
2017-07-10 19:02:00 +00:00
[LuaMethod("read_u32_le", "read unsigned 4 byte value, little endian")]
2014-05-23 23:19:20 +00:00
public uint ReadU32Little ( int addr )
2014-01-26 01:48:32 +00:00
{
2014-05-23 23:19:20 +00:00
return ReadSignedLittle ( addr , 4 ) ;
2014-01-26 01:48:32 +00:00
}
2013-10-28 19:13:01 +00:00
2018-03-14 01:05:30 +00:00
[LuaMethodExample("mainmemory.write_u32_le( 0x100, 1000 );")]
2017-07-10 19:02:00 +00:00
[LuaMethod("write_u32_le", "write unsigned 4 byte value, little endian")]
2014-05-23 23:19:20 +00:00
public void WriteU32Little ( int addr , uint value )
2014-01-26 01:48:32 +00:00
{
2014-05-23 23:19:20 +00:00
WriteUnsignedLittle ( addr , value , 4 ) ;
2014-01-26 01:48:32 +00:00
}
2013-10-28 19:13:01 +00:00
2018-03-14 01:05:30 +00:00
[LuaMethodExample("local uimairea = mainmemory.read_u32_be( 0x100 );")]
2017-07-10 19:02:00 +00:00
[LuaMethod("read_u32_be", "read unsigned 4 byte value, big endian")]
2014-05-23 23:19:20 +00:00
public uint ReadU32Big ( int addr )
{
return ReadUnsignedBig ( addr , 4 ) ;
}
2018-03-14 01:05:30 +00:00
[LuaMethodExample("mainmemory.write_u32_be( 0x100, 1000 );")]
2017-07-10 19:02:00 +00:00
[LuaMethod("write_u32_be", "write unsigned 4 byte value, big endian")]
2014-01-27 01:15:56 +00:00
public void WriteU32Big ( int addr , uint value )
2014-01-26 01:48:32 +00:00
{
2014-01-27 01:15:56 +00:00
WriteUnsignedBig ( addr , value , 4 ) ;
2013-10-28 19:13:01 +00:00
}
2014-05-23 23:19:20 +00:00
#endregion
2013-10-28 19:13:01 +00:00
}
}