Lua - memory domain - if a domain isn't writable, error when attempting to write to it

This commit is contained in:
adelikat 2015-01-25 20:20:43 +00:00
parent 2c09c10721
commit 0d54298f02
2 changed files with 43 additions and 22 deletions

View File

@ -109,14 +109,14 @@ namespace BizHawk.Client.Common
}
else
{
Log(string.Format("Unable to find domain: ", domain));
Log(string.Format("Unable to find domain: {0}", domain));
return false;
}
}
catch // Just in case
{
Log(string.Format("Unable to find domain: ", domain));
Log(string.Format("Unable to find domain: {0}", domain));
}
return false;

View File

@ -55,14 +55,21 @@ namespace BizHawk.Client.Common
protected void WriteUnsignedByte(int addr, uint v)
{
if (addr < Domain.Size)
if (Domain.CanPoke())
{
Domain.PokeByte(addr, (byte)v);
if (addr < Domain.Size)
{
Domain.PokeByte(addr, (byte)v);
}
else
{
Log("Warning: attempted write to " + addr +
" outside the memory size of " + Domain.Size);
}
}
else
{
Log("Warning: attempted write to " + addr +
" outside the memory size of " + Domain.Size);
Log(string.Format("Error: the domain {0} is not writable", Domain.Name));
}
}
@ -170,19 +177,26 @@ namespace BizHawk.Client.Common
protected void WriteByteRange(LuaTable memoryblock)
{
foreach (var address in memoryblock.Keys)
if (Domain.CanPoke())
{
var addr = LuaInt(address);
if (addr < Domain.Size)
foreach (var address in memoryblock.Keys)
{
Domain.PokeByte(addr, (byte)LuaInt(memoryblock[address]));
}
else
{
Log("Warning: Attempted write " + addr + " outside memory domain size of " +
Domain.Size + " in writebyterange()");
var addr = LuaInt(address);
if (addr < Domain.Size)
{
Domain.PokeByte(addr, (byte)LuaInt(memoryblock[address]));
}
else
{
Log("Warning: Attempted write " + addr + " outside memory domain size of " +
Domain.Size + " in writebyterange()");
}
}
}
else
{
Log(string.Format("Error: the domain {0} is not writable", Domain.Name));
}
}
protected float ReadFloat(int addr, bool bigendian)
@ -204,17 +218,24 @@ namespace BizHawk.Client.Common
protected void WriteFloat(int addr, double value, bool bigendian)
{
if (addr < Domain.Size)
if (Domain.CanPoke())
{
var dv = (float)value;
var bytes = BitConverter.GetBytes(dv);
var v = BitConverter.ToUInt32(bytes, 0);
Domain.PokeDWord(addr, v, bigendian);
if (addr < Domain.Size)
{
var dv = (float)value;
var bytes = BitConverter.GetBytes(dv);
var v = BitConverter.ToUInt32(bytes, 0);
Domain.PokeDWord(addr, v, bigendian);
}
else
{
Log("Warning: Attempted write " + addr +
" outside memory size of " + Domain.Size);
}
}
else
{
Log("Warning: Attempted write " + addr +
" outside memory size of " + Domain.Size);
Log(string.Format("Error: the domain {0} is not writable", Domain.Name));
}
}