Lua - implement memory.readfloat() and memory.writefloat() and equivlant mainmemory functions
This commit is contained in:
parent
bcfe4ff576
commit
7e0e8ed51d
|
@ -445,9 +445,9 @@ namespace BizHawk.MultiClient
|
|||
"write_u24_be",
|
||||
"write_u32_be",
|
||||
"readbyte",
|
||||
"writebyte"
|
||||
//"registerwrite",
|
||||
//"registerread",
|
||||
"writebyte",
|
||||
"readfloat",
|
||||
"writefloat"
|
||||
};
|
||||
|
||||
public static string[] MainMemoryFunctions = new[]
|
||||
|
@ -481,7 +481,9 @@ namespace BizHawk.MultiClient
|
|||
"write_u24_be",
|
||||
"write_u32_be",
|
||||
"readbyterange",
|
||||
"writebyterange"
|
||||
"writebyterange",
|
||||
"readfloat",
|
||||
"writefloat"
|
||||
};
|
||||
|
||||
public static string[] SaveStateFunctions = new[]
|
||||
|
@ -628,6 +630,7 @@ namespace BizHawk.MultiClient
|
|||
"unregisterbyid",
|
||||
"unregisterbyname"
|
||||
};
|
||||
|
||||
/****************************************************/
|
||||
/*************function definitions********************/
|
||||
/****************************************************/
|
||||
|
@ -1609,6 +1612,25 @@ namespace BizHawk.MultiClient
|
|||
M_W_U_BE(addr, v, 4);
|
||||
}
|
||||
|
||||
public float memory_readfloat(object lua_addr, bool bigendian)
|
||||
{
|
||||
int addr = LuaInt(lua_addr);
|
||||
uint val = Global.Emulator.MemoryDomains[CurrentMemoryDomain].PeekDWord(addr, bigendian ? Endian.Big : Endian.Little);
|
||||
|
||||
byte[] bytes = BitConverter.GetBytes(val);
|
||||
float _float = BitConverter.ToSingle(bytes, 0);
|
||||
return _float;
|
||||
}
|
||||
|
||||
public void memory_writefloat(object lua_addr, object lua_v, bool bigendian)
|
||||
{
|
||||
int addr = LuaInt(lua_addr);
|
||||
float dv = (float)(double)lua_v;
|
||||
byte[] bytes = BitConverter.GetBytes(dv);
|
||||
uint v = BitConverter.ToUInt32(bytes, 0);
|
||||
Global.Emulator.MemoryDomains[CurrentMemoryDomain].PokeDWord(addr, v, bigendian ? Endian.Big : Endian.Little);
|
||||
}
|
||||
|
||||
private int M_R_S_LE(int addr, int size)
|
||||
{
|
||||
return U2S(M_R_U_LE(addr, size), size);
|
||||
|
@ -1959,6 +1981,25 @@ namespace BizHawk.MultiClient
|
|||
return s;
|
||||
}
|
||||
|
||||
public float mainmemory_readfloat(object lua_addr, bool bigendian)
|
||||
{
|
||||
int addr = LuaInt(lua_addr);
|
||||
uint val = Global.Emulator.MainMemory.PeekDWord(addr, bigendian ? Endian.Big : Endian.Little);
|
||||
|
||||
byte[] bytes = BitConverter.GetBytes(val);
|
||||
float _float = BitConverter.ToSingle(bytes, 0);
|
||||
return _float;
|
||||
}
|
||||
|
||||
public void mainmemory_writefloat(object lua_addr, object lua_v, bool bigendian)
|
||||
{
|
||||
int addr = LuaInt(lua_addr);
|
||||
float dv = (float)(double)lua_v;
|
||||
byte[] bytes = BitConverter.GetBytes(dv);
|
||||
uint v = BitConverter.ToUInt32(bytes, 0);
|
||||
Global.Emulator.MainMemory.PokeDWord(addr, v, bigendian ? Endian.Big : Endian.Little);
|
||||
}
|
||||
|
||||
//----------------------------------------------------
|
||||
//Bitwise Operator library
|
||||
//----------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue