Lua - clean up a lot of params by making them strongly typed numbers instead of object, and simplify a lot of logic as a result

This commit is contained in:
adelikat 2014-01-27 01:15:56 +00:00
parent 055c08179f
commit ce9f282d67
6 changed files with 159 additions and 255 deletions

View File

@ -161,11 +161,11 @@ namespace BizHawk.Client.Common
"onmemoryexecute", "onmemoryexecute",
"Fires after the given address is executed by the core" "Fires after the given address is executed by the core"
)] )]
public string OnMemoryExecute(LuaFunction luaf, object address, string name = null) public string OnMemoryExecute(LuaFunction luaf, uint address, string name = null)
{ {
var nlf = new NamedLuaFunction(luaf, "OnMemoryExecute", LogOutputCallback, CurrentThread, name); var nlf = new NamedLuaFunction(luaf, "OnMemoryExecute", LogOutputCallback, CurrentThread, name);
_luaFunctions.Add(nlf); _luaFunctions.Add(nlf);
Global.CoreComm.MemoryCallbackSystem.AddExecute(nlf.Callback, LuaUInt(address)); Global.CoreComm.MemoryCallbackSystem.AddExecute(nlf.Callback, address);
return nlf.Guid.ToString(); return nlf.Guid.ToString();
} }
@ -173,11 +173,11 @@ namespace BizHawk.Client.Common
"onmemoryread", "onmemoryread",
"Fires after the given address is read by the core. If no address is given, it will attach to every memory read" "Fires after the given address is read by the core. If no address is given, it will attach to every memory read"
)] )]
public string OnMemoryRead(LuaFunction luaf, object address = null, string name = null) public string OnMemoryRead(LuaFunction luaf, uint? address = null, string name = null)
{ {
var nlf = new NamedLuaFunction(luaf, "OnMemoryRead", LogOutputCallback, CurrentThread, name); var nlf = new NamedLuaFunction(luaf, "OnMemoryRead", LogOutputCallback, CurrentThread, name);
_luaFunctions.Add(nlf); _luaFunctions.Add(nlf);
Global.CoreComm.MemoryCallbackSystem.AddRead(nlf.Callback, address != null ? LuaUInt(address) : (uint?)null); Global.CoreComm.MemoryCallbackSystem.AddRead(nlf.Callback, address);
return nlf.Guid.ToString(); return nlf.Guid.ToString();
} }
@ -185,11 +185,11 @@ namespace BizHawk.Client.Common
"onmemorywrite", "onmemorywrite",
"Fires after the given address is written by the core. If no address is given, it will attach to every memory write" "Fires after the given address is written by the core. If no address is given, it will attach to every memory write"
)] )]
public string OnMemoryWrite(LuaFunction luaf, object address = null, string name = null) public string OnMemoryWrite(LuaFunction luaf, uint? address = null, string name = null)
{ {
var nlf = new NamedLuaFunction(luaf, "OnMemoryWrite", LogOutputCallback, CurrentThread, name); var nlf = new NamedLuaFunction(luaf, "OnMemoryWrite", LogOutputCallback, CurrentThread, name);
_luaFunctions.Add(nlf); _luaFunctions.Add(nlf);
Global.CoreComm.MemoryCallbackSystem.AddWrite(nlf.Callback, address != null ? LuaUInt(address) : (uint?)null); Global.CoreComm.MemoryCallbackSystem.AddWrite(nlf.Callback, address);
return nlf.Guid.ToString(); return nlf.Guid.ToString();
} }

View File

@ -106,22 +106,20 @@ namespace BizHawk.Client.Common
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"readbyte", "readbyte", "gets the value from the given address as an unsigned byte"
"gets the value from the given address as an unsigned byte"
)] )]
public uint ReadByte(object addr) public uint ReadByte(int addr)
{ {
return ReadUnsignedByte(LuaInt(addr)); return ReadUnsignedByte(addr);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"readbyterange", "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)." "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)."
)] )]
public LuaTable ReadByteRange(object address, object length) public LuaTable ReadByteRange(int addr, int length)
{ {
var addr = LuaInt(address); var lastAddr = length + addr;
var lastAddr = LuaInt(length) + addr;
var table = _lua.NewTable(); var table = _lua.NewTable();
for (var i = addr; i <= lastAddr; i++) for (var i = addr; i <= lastAddr; i++)
{ {
@ -138,25 +136,20 @@ namespace BizHawk.Client.Common
"readfloat", "readfloat",
"Reads the given address as a 32-bit float value from the main memory domain with th e given endian" "Reads the given address as a 32-bit float value from the main memory domain with th e given endian"
)] )]
public float ReadFloat(object addr, bool bigendian) public float ReadFloat(int addr, bool bigendian)
{ {
var val = Global.Emulator.MemoryDomains.MainMemory.PeekDWord(LuaInt(addr), bigendian); var val = Global.Emulator.MemoryDomains.MainMemory.PeekDWord(addr, bigendian);
var bytes = BitConverter.GetBytes(val); var bytes = BitConverter.GetBytes(val);
var _float = BitConverter.ToSingle(bytes, 0); return BitConverter.ToSingle(bytes, 0);
return _float;
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"writebyte", "writebyte",
"Writes the given value to the given address as an unsigned byte" "Writes the given value to the given address as an unsigned byte"
)] )]
public void WriteByte(object addr, object value) public void WriteByte(int addr, uint value)
{ {
WriteUnsignedByte( WriteUnsignedByte(addr, value);
LuaInt(addr),
LuaUInt(value)
);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
@ -178,306 +171,264 @@ namespace BizHawk.Client.Common
"writefloat", "writefloat",
"Writes the given 32-bit float value to the given address and endian" "Writes the given 32-bit float value to the given address and endian"
)] )]
public void WriteFloat(object address, object value, bool bigendian) public void WriteFloat(int address, double value, bool bigendian)
{ {
var dv = (float)(double)value; var dv = (float)value;
var bytes = BitConverter.GetBytes(dv); var bytes = BitConverter.GetBytes(dv);
var v = BitConverter.ToUInt32(bytes, 0); var v = BitConverter.ToUInt32(bytes, 0);
Global.Emulator.MemoryDomains.MainMemory.PokeDWord(LuaInt(address), v, bigendian); Global.Emulator.MemoryDomains.MainMemory.PokeDWord(address, v, bigendian);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"read_s8", "read_s8",
"read signed byte" "read signed byte"
)] )]
public int ReadS8(object addr) public int ReadS8(int addr)
{ {
return (sbyte)ReadUnsignedByte(LuaInt(addr)); return (sbyte)ReadUnsignedByte(addr);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"read_u8", "read_u8",
"read unsigned byte" "read unsigned byte"
)] )]
public uint ReadU8(object addr) public uint ReadU8(int addr)
{ {
return ReadUnsignedByte(LuaInt(addr)); return ReadUnsignedByte(addr);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"read_s16_le", "read_s16_le",
"read signed 2 byte value, little endian" "read signed 2 byte value, little endian"
)] )]
public int ReadS16Little(object addr) public int ReadS16Little(int addr)
{ {
return ReadSignedLittleCore(LuaInt(addr), 2); return ReadSignedLittleCore(addr, 2);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"read_s24_le", "read_s24_le",
"read signed 24 bit value, little endian" "read signed 24 bit value, little endian"
)] )]
public int ReadS24Little(object addr) public int ReadS24Little(int addr)
{ {
return ReadSignedLittleCore(LuaInt(addr), 3); return ReadSignedLittleCore(addr, 3);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"read_s32_le", "read_s32_le",
"read signed 4 byte value, little endian" "read signed 4 byte value, little endian"
)] )]
public int ReadS32Little(object addr) public int ReadS32Little(int addr)
{ {
return ReadSignedLittleCore(LuaInt(addr), 4); return ReadSignedLittleCore(addr, 4);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"read_u16_le", "read_u16_le",
"read unsigned 2 byte value, little endian" "read unsigned 2 byte value, little endian"
)] )]
public uint ReadU16Little(object addr) public uint ReadU16Little(int addr)
{ {
return ReadSignedLittle(LuaInt(addr), 2); return ReadSignedLittle(addr, 2);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"read_u24_le", "read_u24_le",
"read unsigned 24 bit value, little endian" "read unsigned 24 bit value, little endian"
)] )]
public uint ReadU24Little(object addr) public uint ReadU24Little(int addr)
{ {
return ReadSignedLittle(LuaInt(addr), 3); return ReadSignedLittle(addr, 3);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"read_u32_le", "read_u32_le",
"read unsigned 4 byte value, little endian" "read unsigned 4 byte value, little endian"
)] )]
public uint ReadU32Little(object addr) public uint ReadU32Little(int addr)
{ {
return ReadSignedLittle(LuaInt(addr), 4); return ReadSignedLittle(addr, 4);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"read_s16_be", "read_s16_be",
"read signed 2 byte value, big endian" "read signed 2 byte value, big endian"
)] )]
public int ReadS16Big(object addr) public int ReadS16Big(int addr)
{ {
return ReadSignedBig(LuaInt(addr), 2); return ReadSignedBig(addr, 2);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"read_s24_be", "read_s24_be",
"read signed 24 bit value, big endian" "read signed 24 bit value, big endian"
)] )]
public int ReadS24Big(object addr) public int ReadS24Big(int addr)
{ {
return ReadSignedBig(LuaInt(addr), 3); return ReadSignedBig(addr, 3);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"read_s32_be", "read_s32_be",
"read signed 4 byte value, big endian" "read signed 4 byte value, big endian"
)] )]
public int ReadS32Big(object addr) public int ReadS32Big(int addr)
{ {
return ReadSignedBig(LuaInt(addr), 4); return ReadSignedBig(addr, 4);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"read_u16_be", "read_u16_be",
"read unsigned 2 byte value, big endian" "read unsigned 2 byte value, big endian"
)] )]
public uint ReadU16Big(object addr) public uint ReadU16Big(int addr)
{ {
return ReadUnsignedBig(LuaInt(addr), 2); return ReadUnsignedBig(addr, 2);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"read_u24_be", "read_u24_be",
"read unsigned 24 bit value, big endian" "read unsigned 24 bit value, big endian"
)] )]
public uint ReadU24Big(object addr) public uint ReadU24Big(int addr)
{ {
return ReadUnsignedBig(LuaInt(addr), 3); return ReadUnsignedBig(addr, 3);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"read_u32_be", "read_u32_be",
"read unsigned 4 byte value, big endian" "read unsigned 4 byte value, big endian"
)] )]
public uint ReadU32Big(object addr) public uint ReadU32Big(int addr)
{ {
return ReadUnsignedBig(LuaInt(addr), 4); return ReadUnsignedBig(addr, 4);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"write_s8", "write_s8",
"write signed byte" "write signed byte"
)] )]
public void WriteS8(object addr, object value) public void WriteS8(int addr, uint value)
{ {
WriteUnsignedByte( WriteUnsignedByte(addr, value);
LuaInt(addr),
(uint)LuaInt(value)
);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"write_u8", "write_u8",
"write unsigned byte" "write unsigned byte"
)] )]
public void WriteU8(object addr, object value) public void WriteU8(int addr, uint value)
{ {
WriteUnsignedByte( WriteUnsignedByte(addr, value);
LuaInt(addr),
LuaUInt(value)
);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"write_s16_le", "write_s16_le",
"write signed 2 byte value, little endian" "write signed 2 byte value, little endian"
)] )]
public void WriteS16Little(object addr, object value) public void WriteS16Little(int addr, int value)
{ {
WriteSignedLittle( WriteSignedLittle(addr, value, 2);
LuaInt(addr),
LuaInt(value),
2);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"write_s24_le", "write_s24_le",
"write signed 24 bit value, little endian" "write signed 24 bit value, little endian"
)] )]
public void WriteS24Little(object addr, object value) public void WriteS24Little(int addr, int value)
{ {
WriteSignedLittle( WriteSignedLittle(addr, value, 3);
LuaInt(addr),
LuaInt(value),
3);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"write_s32_le", "write_s32_le",
"write signed 4 byte value, little endian" "write signed 4 byte value, little endian"
)] )]
public void WriteS32Little(object addr, object value) public void WriteS32Little(int addr, int value)
{ {
WriteSignedLittle( WriteSignedLittle(addr, value, 4);
LuaInt(addr),
LuaInt(value),
4);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"write_u16_le", "write_u16_le",
"write unsigned 2 byte value, little endian" "write unsigned 2 byte value, little endian"
)] )]
public void WriteU16Little(object addr, object value) public void WriteU16Little(int addr, uint value)
{ {
WriteUnsignedLittle( WriteUnsignedLittle(addr, value, 2);
LuaInt(addr),
LuaUInt(value),
2);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"write_u24_le", "write_u24_le",
"write unsigned 24 bit value, little endian" "write unsigned 24 bit value, little endian"
)] )]
public void WriteU24Little(object addr, object value) public void WriteU24Little(int addr, uint value)
{ {
WriteUnsignedLittle( WriteUnsignedLittle(addr, value, 3);
LuaInt(addr),
LuaUInt(value),
3);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"write_u32_le", "write_u32_le",
"write unsigned 4 byte value, little endian" "write unsigned 4 byte value, little endian"
)] )]
public void WriteU32Little(object addr, object value) public void WriteU32Little(int addr, uint value)
{ {
WriteUnsignedLittle( WriteUnsignedLittle(addr, value, 4);
LuaInt(addr),
LuaUInt(value),
4);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"write_s16_be", "write_s16_be",
"write signed 2 byte value, big endian" "write signed 2 byte value, big endian"
)] )]
public void WriteS16Big(object addr, object value) public void WriteS16Big(int addr, int value)
{ {
WriteSignedBig( WriteSignedBig(addr, value, 2);
LuaInt(addr),
LuaInt(value),
2);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"write_s24_be", "write_s24_be",
"write signed 24 bit value, big endian" "write signed 24 bit value, big endian"
)] )]
public void WriteS24Big(object addr, object value) public void WriteS24Big(int addr, int value)
{ {
WriteSignedBig( WriteSignedBig(addr, value, 3);
LuaInt(addr),
LuaInt(value),
3);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"write_s32_be", "write_s32_be",
"write signed 4 byte value, big endian" "write signed 4 byte value, big endian"
)] )]
public void WriteS32Big(object addr, object value) public void WriteS32Big(int addr, int value)
{ {
WriteSignedBig( WriteSignedBig(addr, value, 4);
LuaInt(addr),
LuaInt(value),
4);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"write_u16_be", "write_u16_be",
"write unsigned 2 byte value, big endian" "write unsigned 2 byte value, big endian"
)] )]
public void WriteU16Big(object addr, object value) public void WriteU16Big(int addr, uint value)
{ {
WriteUnsignedBig( WriteUnsignedBig(addr, value, 2);
LuaInt(addr),
LuaUInt(value),
2);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"write_u24_be", "write_u24_be",
"write unsigned 24 bit value, big endian" "write unsigned 24 bit value, big endian"
)] )]
public void WriteU24Big(object addr, object value) public void WriteU24Big(int addr, uint value)
{ {
WriteUnsignedBig( WriteUnsignedBig(addr, value, 3);
LuaInt(addr),
LuaUInt(value),
3);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"write_u32_be", "write_u32_be",
"write unsigned 4 byte value, big endian" "write unsigned 4 byte value, big endian"
)] )]
public void WriteU32Big(object addr, object value) public void WriteU32Big(int addr, uint value)
{ {
WriteUnsignedBig( WriteUnsignedBig(addr, value, 4);
LuaInt(addr),
LuaUInt(value),
4);
} }
} }
} }

View File

@ -120,18 +120,18 @@ namespace BizHawk.Client.Common
"readbyte", "readbyte",
"gets the value from the given address as an unsigned byte" "gets the value from the given address as an unsigned byte"
)] )]
public uint ReadByte(object addr) public uint ReadByte(int addr)
{ {
return ReadUnsignedByte(LuaInt(addr)); return ReadUnsignedByte(addr);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"readfloat", "readfloat",
"Reads the given address as a 32-bit float value from the main memory domain with th e given endian" "Reads the given address as a 32-bit float value from the main memory domain with th e given endian"
)] )]
public float ReadFloat(object addr, bool bigendian) public float ReadFloat(int addr, bool bigendian)
{ {
var val = Global.Emulator.MemoryDomains[_currentMemoryDomain].PeekDWord(LuaInt(addr), bigendian); var val = Global.Emulator.MemoryDomains[_currentMemoryDomain].PeekDWord(addr, bigendian);
var bytes = BitConverter.GetBytes(val); var bytes = BitConverter.GetBytes(val);
return BitConverter.ToSingle(bytes, 0); return BitConverter.ToSingle(bytes, 0);
} }
@ -140,24 +140,21 @@ namespace BizHawk.Client.Common
"writebyte", "writebyte",
"Writes the given value to the given address as an unsigned byte" "Writes the given value to the given address as an unsigned byte"
)] )]
public void WriteByte(object addr, object value) public void WriteByte(int addr, uint value)
{ {
WriteUnsignedByte( WriteUnsignedByte(addr, value);
LuaInt(addr),
LuaUInt(value)
);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"writefloat", "writefloat",
"Writes the given 32-bit float value to the given address and endian" "Writes the given 32-bit float value to the given address and endian"
)] )]
public void WriteFloat(object addr, object value, bool bigendian) public void WriteFloat(int addr, double value, bool bigendian)
{ {
var dv = (float)(double)value; var dv = (float)value;
var bytes = BitConverter.GetBytes(dv); var bytes = BitConverter.GetBytes(dv);
var v = BitConverter.ToUInt32(bytes, 0); var v = BitConverter.ToUInt32(bytes, 0);
Global.Emulator.MemoryDomains[_currentMemoryDomain].PokeDWord(LuaInt(addr), v, bigendian); Global.Emulator.MemoryDomains[_currentMemoryDomain].PokeDWord(addr, v, bigendian);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
@ -182,294 +179,252 @@ namespace BizHawk.Client.Common
"read_s8", "read_s8",
"read signed byte" "read signed byte"
)] )]
public int ReadS8(object addr) public int ReadS8(int addr)
{ {
return (sbyte)ReadUnsignedByte(LuaInt(addr)); return (sbyte)ReadUnsignedByte(addr);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"read_u8", "read_u8",
"read unsigned byte" "read unsigned byte"
)] )]
public uint ReadU8(object addr) public uint ReadU8(int addr)
{ {
return ReadUnsignedByte(LuaInt(addr)); return ReadUnsignedByte(addr);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"read_s16_le", "read_s16_le",
"read signed 2 byte value, little endian" "read signed 2 byte value, little endian"
)] )]
public int ReadS16Little(object addr) public int ReadS16Little(int addr)
{ {
return ReadSignedLittleCore(LuaInt(addr), 2); return ReadSignedLittleCore(addr, 2);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"read_s24_le", "read_s24_le",
"read signed 24 bit value, little endian" "read signed 24 bit value, little endian"
)] )]
public int ReadS24Little(object addr) public int ReadS24Little(int addr)
{ {
return ReadSignedLittleCore(LuaInt(addr), 3); return ReadSignedLittleCore(addr, 3);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"read_s32_le", "read_s32_le",
"read signed 4 byte value, little endian" "read signed 4 byte value, little endian"
)] )]
public int ReadS32Little(object addr) public int ReadS32Little(int addr)
{ {
return ReadSignedLittleCore(LuaInt(addr), 4); return ReadSignedLittleCore(addr, 4);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"read_u16_le", "read_u16_le",
"read unsigned 2 byte value, little endian" "read unsigned 2 byte value, little endian"
)] )]
public uint ReadU16Little(object addr) public uint ReadU16Little(int addr)
{ {
return ReadUnsignedLittle(LuaInt(addr), 2); return ReadUnsignedLittle(addr, 2);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"read_u24_le", "read_u24_le",
"read unsigned 24 bit value, little endian" "read unsigned 24 bit value, little endian"
)] )]
public uint ReadU24Little(object addr) public uint ReadU24Little(int addr)
{ {
return ReadUnsignedLittle(LuaInt(addr), 3); return ReadUnsignedLittle(addr, 3);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"read_u32_le", "read_u32_le",
"read unsigned 4 byte value, little endian" "read unsigned 4 byte value, little endian"
)] )]
public uint ReadU32Little(object addr) public uint ReadU32Little(int addr)
{ {
return ReadUnsignedLittle(LuaInt(addr), 4); return ReadUnsignedLittle(addr, 4);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"read_s16_be", "read_s16_be",
"read signed 2 byte value, big endian" "read signed 2 byte value, big endian"
)] )]
public int ReadS16Big(object addr) public int ReadS16Big(int addr)
{ {
return ReadSignedBig(LuaInt(addr), 2); return ReadSignedBig(addr, 2);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"read_s24_be", "read_s24_be",
"read signed 24 bit value, big endian" "read signed 24 bit value, big endian"
)] )]
public int ReadS24Big(object addr) public int ReadS24Big(int addr)
{ {
return ReadSignedBig(LuaInt(addr), 3); return ReadSignedBig(addr, 3);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"read_s32_be", "read_s32_be",
"read signed 4 byte value, big endian" "read signed 4 byte value, big endian"
)] )]
public int ReadS32Big(object addr) public int ReadS32Big(int addr)
{ {
return ReadSignedBig(LuaInt(addr), 4); return ReadSignedBig(addr, 4);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"read_u16_be", "read_u16_be",
"read unsigned 2 byte value, big endian" "read unsigned 2 byte value, big endian"
)] )]
public uint ReadU16Big(object addr) public uint ReadU16Big(int addr)
{ {
return ReadUnsignedBig(LuaInt(addr), 2); return ReadUnsignedBig(addr, 2);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"read_u24_be", "read_u24_be",
"read unsigned 24 bit value, big endian" "read unsigned 24 bit value, big endian"
)] )]
public uint ReadU24Big(object addr) public uint ReadU24Big(int addr)
{ {
return ReadUnsignedBig(LuaInt(addr), 3); return ReadUnsignedBig(addr, 3);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"u32_be", "u32_be",
"read unsigned 4 byte value, big endian" "read unsigned 4 byte value, big endian"
)] )]
public uint ReadU32Big(object addr) public uint ReadU32Big(int addr)
{ {
return ReadUnsignedBig(LuaInt(addr), 4); return ReadUnsignedBig(addr, 4);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"write_s8", "write_s8",
"write signed byte" "write signed byte"
)] )]
public void WriteS8(object addr, object value) public void WriteS8(int addr, uint value)
{ {
WriteUnsignedByte( WriteUnsignedByte(addr, value);
LuaInt(addr),
(uint)LuaInt(value)
);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"write_s8", "write_s8",
"write unsigned byte" "write unsigned byte"
)] )]
public void WriteU8(object addr, object value) public void WriteU8(int addr, uint value)
{ {
WriteUnsignedByte( WriteUnsignedByte(addr, value);
LuaInt(addr),
LuaUInt(value)
);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"write_s16_le", "write_s16_le",
"write signed 2 byte value, little endian" "write signed 2 byte value, little endian"
)] )]
public void WriteS16Little(object addr, object value) public void WriteS16Little(int addr, int value)
{ {
WriteSignedLittle( WriteSignedLittle(addr, value, 2);
LuaInt(addr),
LuaInt(value),
2);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"write_s24_le", "write_s24_le",
"write signed 24 bit value, little endian" "write signed 24 bit value, little endian"
)] )]
public void WriteS24Little(object addr, object value) public void WriteS24Little(int addr, int value)
{ {
WriteSignedLittle( WriteSignedLittle(addr, value, 3);
LuaInt(addr),
LuaInt(value),
3);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"write_s32_le", "write_s32_le",
"write signed 4 byte value, little endian" "write signed 4 byte value, little endian"
)] )]
public void WriteS32Little(object addr, object value) public void WriteS32Little(int addr, int value)
{ {
WriteSignedLittle( WriteSignedLittle(addr, value, 4);
LuaInt(addr),
LuaInt(value),
4);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"write_u16_le", "write_u16_le",
"write unsigned 2 byte value, little endian" "write unsigned 2 byte value, little endian"
)] )]
public void WriteU16Little(object addr, object value) public void WriteU16Little(int addr, uint value)
{ {
WriteUnsignedLittle( WriteUnsignedLittle(addr, value, 2);
LuaInt(addr),
LuaUInt(value),
2);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"write_u24_le", "write_u24_le",
"write unsigned 24 bit value, little endian" "write unsigned 24 bit value, little endian"
)] )]
public void WriteU24Little(object addr, object value) public void WriteU24Little(int addr, uint value)
{ {
WriteUnsignedLittle( WriteUnsignedLittle(addr, value, 3);
LuaInt(addr),
LuaUInt(value),
3);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"write_u32_le", "write_u32_le",
"write unsigned 4 byte value, little endian" "write unsigned 4 byte value, little endian"
)] )]
public void WriteU32Little(object addr, object value) public void WriteU32Little(int addr, uint value)
{ {
WriteUnsignedLittle( WriteUnsignedLittle(addr, value, 4);
LuaInt(addr),
LuaUInt(value),
4);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"write_s16_be", "write_s16_be",
"write signed 2 byte value, big endian" "write signed 2 byte value, big endian"
)] )]
public void WriteS16Big(object addr, object value) public void WriteS16Big(int addr, int value)
{ {
WriteSignedBig( WriteSignedBig(addr, value, 2);
LuaInt(addr),
LuaInt(value),
2);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"write_s24_be", "write_s24_be",
"write signed 24 bit value, big endian" "write signed 24 bit value, big endian"
)] )]
public void WriteS24Big(object addr, object value) public void WriteS24Big(int addr, int value)
{ {
WriteSignedBig( WriteSignedBig(addr, value, 3);
LuaInt(addr),
LuaInt(value),
3);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"write_s32_be", "write_s32_be",
"write signed 4 byte value, big endian" "write signed 4 byte value, big endian"
)] )]
public void WriteS32Big(object addr, object value) public void WriteS32Big(int addr, int value)
{ {
WriteSignedBig( WriteSignedBig(addr, value, 4);
LuaInt(addr),
LuaInt(value),
4);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"write_u16_be", "write_u16_be",
"write unsigned 2 byte value, big endian" "write unsigned 2 byte value, big endian"
)] )]
public void WriteU16Big(object addr, object value) public void WriteU16Big(int addr, uint value)
{ {
WriteUnsignedBig( WriteUnsignedBig(addr, value, 2);
LuaInt(addr),
LuaUInt(value),
2);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"write_u24_be", "write_u24_be",
"write unsigned 24 bit value, big endian" "write unsigned 24 bit value, big endian"
)] )]
public void WriteU24Big(object addr, object value) public void WriteU24Big(int addr, uint value)
{ {
WriteUnsignedBig( WriteUnsignedBig(addr, value, 3);
LuaInt(addr),
LuaUInt(value),
3);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"write_u32_be", "write_u32_be",
"write unsigned 4 byte value, big endian" "write unsigned 4 byte value, big endian"
)] )]
public void WriteU32Big(object addr, object value) public void WriteU32Big(int addr, uint value)
{ {
WriteUnsignedBig( WriteUnsignedBig(addr, value, 4);
LuaInt(addr),
LuaUInt(value),
4);
} }
} }
} }

View File

@ -26,13 +26,13 @@ namespace BizHawk.Client.Common
"getinput", "getinput",
"Returns a table of buttons pressed on a given frame of the loaded movie" "Returns a table of buttons pressed on a given frame of the loaded movie"
)] )]
public LuaTable GetInput(object frame) public LuaTable GetInput(int frame)
{ {
var input = _lua.NewTable(); var input = _lua.NewTable();
var m = new MovieControllerAdapter { Type = Global.MovieSession.MovieControllerAdapter.Type }; var m = new MovieControllerAdapter { Type = Global.MovieSession.MovieControllerAdapter.Type };
m.SetControllersAsMnemonic( m.SetControllersAsMnemonic(
Global.MovieSession.Movie.GetInput(LuaInt(frame)) Global.MovieSession.Movie.GetInput(frame)
); );
foreach (var button in m.Type.BoolButtons) foreach (var button in m.Type.BoolButtons)

View File

@ -179,41 +179,39 @@ namespace BizHawk.Client.Common
"setscanlines", "setscanlines",
"sets the top and bottom scanlines to be drawn (same values as in the graphics options dialog). Top must be in the range of 0 to 127, bottom must be between 128 and 239" "sets the top and bottom scanlines to be drawn (same values as in the graphics options dialog). Top must be in the range of 0 to 127, bottom must be between 128 and 239"
)] )]
public static void SetScanlines(object top, object bottom, bool pal = false) public static void SetScanlines(int top, int bottom, bool pal = false)
{ {
if (Global.Emulator is NES) if (Global.Emulator is NES)
{ {
var first = LuaInt(top); if (top > 127)
var last = LuaInt(bottom);
if (first > 127)
{ {
first = 127; top = 127;
} }
else if (first < 0) else if (top < 0)
{ {
first = 0; top = 0;
} }
if (last > 239) if (bottom > 239)
{ {
last = 239; bottom = 239;
} }
else if (last < 128) else if (bottom < 128)
{ {
last = 128; bottom = 128;
} }
var s = (NES.NESSettings)Global.Emulator.GetSettings(); var s = (NES.NESSettings)Global.Emulator.GetSettings();
if (pal) if (pal)
{ {
s.PAL_TopLine = first; s.PAL_TopLine = top;
s.PAL_BottomLine = last; s.PAL_BottomLine = bottom;
} }
else else
{ {
s.NTSC_TopLine = first; s.NTSC_TopLine = top;
s.NTSC_BottomLine = last; s.NTSC_BottomLine = bottom;
} }
Global.Emulator.PutSettings(s); Global.Emulator.PutSettings(s);

View File

@ -86,18 +86,18 @@ namespace BizHawk.Client.Common
"substring", "substring",
"Returns a string that represents a substring of str starting at position for the specified length" "Returns a string that represents a substring of str starting at position for the specified length"
)] )]
public static string SubString(string str, object position, object length) public static string SubString(string str, int position, int length)
{ {
return str.Substring((int)position, (int)length); return str.Substring(position, length);
} }
[LuaMethodAttributes( [LuaMethodAttributes(
"remove", "remove",
"Returns a string that represents str with the given position and count removed" "Returns a string that represents str with the given position and count removed"
)] )]
public static string Remove(string str, object position, object count) public static string Remove(string str, int position, int count)
{ {
return str.Remove((int)position, (int)count); return str.Remove(position, count);
} }
[LuaMethodAttributes( [LuaMethodAttributes(