Added lua bitwise operators, AND, LSHIFT, RSHIFT, OR, XOR, NOT, ROTATE LEFT, ROTATE RIGHT.

This commit is contained in:
pasky1382 2012-09-02 00:56:50 +00:00
parent c91c001093
commit ff218af117
1 changed files with 305 additions and 224 deletions

View File

@ -16,15 +16,15 @@ namespace BizHawk.MultiClient
public class LuaImplementation public class LuaImplementation
{ {
public LuaDocumentation docs = new LuaDocumentation(); public LuaDocumentation docs = new LuaDocumentation();
Lua lua = new Lua(); private Lua lua = new Lua();
LuaConsole Caller; private LuaConsole Caller;
public EventWaitHandle LuaWait; public EventWaitHandle LuaWait;
public bool isRunning; public bool isRunning;
private int CurrentMemoryDomain = 0; //Main memory by default private int CurrentMemoryDomain = 0; //Main memory by default
public bool FrameAdvanceRequested; public bool FrameAdvanceRequested;
Lua currThread; private Lua currThread;
LuaFunction savestate_registersavefunc; private LuaFunction savestate_registersavefunc;
LuaFunction savestate_registerloadfunc; private LuaFunction savestate_registerloadfunc;
public void SavestateRegisterSave(string name) public void SavestateRegisterSave(string name)
{ {
@ -36,7 +36,8 @@ namespace BizHawk.MultiClient
} }
catch (SystemException e) catch (SystemException e)
{ {
Global.MainForm.LuaConsole1.WriteToOutputWindow("error running function attached by lua function savestate.registersave" + Global.MainForm.LuaConsole1.WriteToOutputWindow(
"error running function attached by lua function savestate.registersave" +
"\nError message: " + e.Message); "\nError message: " + e.Message);
} }
} }
@ -52,7 +53,8 @@ namespace BizHawk.MultiClient
} }
catch (SystemException e) catch (SystemException e)
{ {
Global.MainForm.LuaConsole1.WriteToOutputWindow("error running function attached by lua function savestate.registerload" + Global.MainForm.LuaConsole1.WriteToOutputWindow(
"error running function attached by lua function savestate.registerload" +
"\nError message: " + e.Message); "\nError message: " + e.Message);
} }
} }
@ -79,7 +81,8 @@ namespace BizHawk.MultiClient
lua.NewTable("console"); lua.NewTable("console");
for (int i = 0; i < ConsoleFunctions.Length; i++) for (int i = 0; i < ConsoleFunctions.Length; i++)
{ {
lua.RegisterFunction("console." + ConsoleFunctions[i], this, this.GetType().GetMethod("console_" + ConsoleFunctions[i])); lua.RegisterFunction("console." + ConsoleFunctions[i], this,
this.GetType().GetMethod("console_" + ConsoleFunctions[i]));
docs.Add("console", ConsoleFunctions[i], this.GetType().GetMethod("console_" + ConsoleFunctions[i])); docs.Add("console", ConsoleFunctions[i], this.GetType().GetMethod("console_" + ConsoleFunctions[i]));
} }
@ -107,14 +110,16 @@ namespace BizHawk.MultiClient
lua.NewTable("mainmemory"); lua.NewTable("mainmemory");
for (int i = 0; i < MainMemoryFunctions.Length; i++) for (int i = 0; i < MainMemoryFunctions.Length; i++)
{ {
lua.RegisterFunction("mainmemory." + MainMemoryFunctions[i], this, this.GetType().GetMethod("mainmemory_" + MainMemoryFunctions[i])); lua.RegisterFunction("mainmemory." + MainMemoryFunctions[i], this,
this.GetType().GetMethod("mainmemory_" + MainMemoryFunctions[i]));
docs.Add("mainmemory", MainMemoryFunctions[i], this.GetType().GetMethod("mainmemory_" + MainMemoryFunctions[i])); docs.Add("mainmemory", MainMemoryFunctions[i], this.GetType().GetMethod("mainmemory_" + MainMemoryFunctions[i]));
} }
lua.NewTable("savestate"); lua.NewTable("savestate");
for (int i = 0; i < SaveStateFunctions.Length; i++) for (int i = 0; i < SaveStateFunctions.Length; i++)
{ {
lua.RegisterFunction("savestate." + SaveStateFunctions[i], this, this.GetType().GetMethod("savestate_" + SaveStateFunctions[i])); lua.RegisterFunction("savestate." + SaveStateFunctions[i], this,
this.GetType().GetMethod("savestate_" + SaveStateFunctions[i]));
docs.Add("savestate", SaveStateFunctions[i], this.GetType().GetMethod("savestate_" + SaveStateFunctions[i])); docs.Add("savestate", SaveStateFunctions[i], this.GetType().GetMethod("savestate_" + SaveStateFunctions[i]));
} }
@ -142,7 +147,8 @@ namespace BizHawk.MultiClient
lua.NewTable("client"); lua.NewTable("client");
for (int i = 0; i < MultiClientFunctions.Length; i++) for (int i = 0; i < MultiClientFunctions.Length; i++)
{ {
lua.RegisterFunction("client." + MultiClientFunctions[i], this, this.GetType().GetMethod("client_" + MultiClientFunctions[i])); lua.RegisterFunction("client." + MultiClientFunctions[i], this,
this.GetType().GetMethod("client_" + MultiClientFunctions[i]));
docs.Add("client", MultiClientFunctions[i], this.GetType().GetMethod("client_" + MultiClientFunctions[i])); docs.Add("client", MultiClientFunctions[i], this.GetType().GetMethod("client_" + MultiClientFunctions[i]));
} }
@ -153,6 +159,14 @@ namespace BizHawk.MultiClient
docs.Add("forms", FormsFunctions[i], this.GetType().GetMethod("forms_" + FormsFunctions[i])); docs.Add("forms", FormsFunctions[i], this.GetType().GetMethod("forms_" + FormsFunctions[i]));
} }
lua.NewTable("bit");
for (int i = 0; i < BitwiseFunctions.Length; i++)
{
lua.RegisterFunction("bit." + BitwiseFunctions[i], this, this.GetType().GetMethod("bit_" + BitwiseFunctions[i]));
docs.Add("bit", BitwiseFunctions[i], this.GetType().GetMethod("bit_" + BitwiseFunctions[i]));
}
docs.Sort(); docs.Sort();
} }
@ -167,20 +181,22 @@ namespace BizHawk.MultiClient
private int LuaInt(object lua_arg) private int LuaInt(object lua_arg)
{ {
return Convert.ToInt32((double)lua_arg); return Convert.ToInt32((double) lua_arg);
} }
private uint LuaUInt(object lua_arg) private uint LuaUInt(object lua_arg)
{ {
return Convert.ToUInt32((double)lua_arg); return Convert.ToUInt32((double) lua_arg);
} }
public Color GetColor(object color) public Color GetColor(object color)
{ {
if (color.GetType() == typeof(Double)) if (color.GetType() == typeof (Double))
{ {
return System.Drawing.Color.FromArgb(int.Parse(long.Parse(color.ToString()).ToString("X"), System.Globalization.NumberStyles.HexNumber)); return
System.Drawing.Color.FromArgb(int.Parse(long.Parse(color.ToString()).ToString("X"),
System.Globalization.NumberStyles.HexNumber));
} }
else else
{ {
@ -192,6 +208,7 @@ namespace BizHawk.MultiClient
{ {
return new System.Drawing.SolidBrush(GetColor(color)); return new System.Drawing.SolidBrush(GetColor(color));
} }
public Pen GetPen(object color) public Pen GetPen(object color)
{ {
return new System.Drawing.Pen(GetColor(color)); return new System.Drawing.Pen(GetColor(color));
@ -204,6 +221,7 @@ namespace BizHawk.MultiClient
* variable arguments, declare them as optional and pass * variable arguments, declare them as optional and pass
* them to this method. * them to this method.
*/ */
private object[] LuaVarArgs(params object[] lua_args) private object[] LuaVarArgs(params object[] lua_args)
{ {
int n = lua_args.Length; int n = lua_args.Length;
@ -250,185 +268,204 @@ namespace BizHawk.MultiClient
/****************************************************/ /****************************************************/
/*************library definitions********************/ /*************library definitions********************/
/****************************************************/ /****************************************************/
public static string[] ConsoleFunctions = new string[] public static string[] ConsoleFunctions = new string[]
{ {
"output", "output",
"log", "log",
"clear", "clear",
"getluafunctionslist", "getluafunctionslist",
}; };
public static string[] GuiFunctions = new string[] public static string[] GuiFunctions = new string[]
{ {
"text", "text",
"alert", "alert",
"cleartext", "cleartext",
"drawPixel", "drawPixel",
"drawLine", "drawLine",
"drawRectangle", "drawRectangle",
"drawEllipse", "drawEllipse",
"drawPolygon", "drawPolygon",
"drawBezier", "drawBezier",
"drawPie", "drawPie",
"drawIcon", "drawIcon",
"drawImage", "drawImage",
}; };
public static string[] EmuFunctions = new string[] public static string[] EmuFunctions = new string[]
{ {
"frameadvance", "frameadvance",
"yield", "yield",
"pause", "pause",
"unpause", "unpause",
"togglepause", "togglepause",
"ispaused", "ispaused",
"speedmode", "speedmode",
"framecount", "framecount",
"lagcount", "lagcount",
"islagged", "islagged",
"getsystemid", "getsystemid",
"setrenderplanes", "setrenderplanes",
"frameskip", "frameskip",
"minimizeframeskip", "minimizeframeskip",
"limitframerate", "limitframerate",
"displayvsync", "displayvsync",
"enablerewind" "enablerewind"
}; };
public static string[] MemoryFunctions = new string[] public static string[] MemoryFunctions = new string[]
{ {
"usememorydomain", "usememorydomain",
"getmemorydomainlist", "getmemorydomainlist",
"getcurrentmemorydomain", "getcurrentmemorydomain",
"read_s8", "read_s8",
"read_u8", "read_u8",
"read_s16_le", "read_s16_le",
"read_s24_le", "read_s24_le",
"read_s32_le", "read_s32_le",
"read_u16_le", "read_u16_le",
"read_u24_le", "read_u24_le",
"read_u32_le", "read_u32_le",
"read_s16_be", "read_s16_be",
"read_s24_be", "read_s24_be",
"read_s32_be", "read_s32_be",
"read_u16_be", "read_u16_be",
"read_u24_be", "read_u24_be",
"read_u32_be", "read_u32_be",
"write_s8", "write_s8",
"write_u8", "write_u8",
"write_s16_le", "write_s16_le",
"write_s24_le", "write_s24_le",
"write_s32_le", "write_s32_le",
"write_u16_le", "write_u16_le",
"write_u24_le", "write_u24_le",
"write_u32_le", "write_u32_le",
"write_s16_be", "write_s16_be",
"write_s24_be", "write_s24_be",
"write_s32_be", "write_s32_be",
"write_u16_be", "write_u16_be",
"write_u24_be", "write_u24_be",
"write_u32_be", "write_u32_be",
"readbyte", "readbyte",
"writebyte", "writebyte",
//"registerwrite", //"registerwrite",
//"registerread", //"registerread",
}; };
public static string[] MainMemoryFunctions = new string[] public static string[] MainMemoryFunctions = new string[]
{ {
"read_s8", "read_s8",
"read_u8", "read_u8",
"read_s16_le", "read_s16_le",
"read_s24_le", "read_s24_le",
"read_s32_le", "read_s32_le",
"read_u16_le", "read_u16_le",
"read_u24_le", "read_u24_le",
"read_u32_le", "read_u32_le",
"read_s16_be", "read_s16_be",
"read_s24_be", "read_s24_be",
"read_s32_be", "read_s32_be",
"read_u16_be", "read_u16_be",
"read_u24_be", "read_u24_be",
"read_u32_be", "read_u32_be",
"write_s8", "write_s8",
"write_u8", "write_u8",
"write_s16_le", "write_s16_le",
"write_s24_le", "write_s24_le",
"write_s32_le", "write_s32_le",
"write_u16_le", "write_u16_le",
"write_u24_le", "write_u24_le",
"write_u32_le", "write_u32_le",
"write_s16_be", "write_s16_be",
"write_s24_be", "write_s24_be",
"write_s32_be", "write_s32_be",
"write_u16_be", "write_u16_be",
"write_u24_be", "write_u24_be",
"write_u32_be", "write_u32_be",
//"registerwrite", //"registerwrite",
//"registerread", //"registerread",
}; };
public static string[] SaveStateFunctions = new string[] { public static string[] SaveStateFunctions = new string[]
"saveslot", {
"loadslot", "saveslot",
"save", "loadslot",
"load", "save",
"registersave", "load",
"registerload", "registersave",
}; "registerload",
};
public static string[] MovieFunctions = new string[] { public static string[] MovieFunctions = new string[]
"mode", {
"isloaded", "mode",
"rerecordcount", "isloaded",
"length", "rerecordcount",
"stop", "length",
"filename", "stop",
"getreadonly", "filename",
"setreadonly", "getreadonly",
"getrerecordcounting", "setreadonly",
"setrerecordcounting", "getrerecordcounting",
"getinput", "setrerecordcounting",
}; "getinput",
};
public static string[] InputFunctions = new string[] { public static string[] InputFunctions = new string[]
"get", {
"getmouse", "get",
}; "getmouse",
};
public static string[] JoypadFunctions = new string[] { public static string[] JoypadFunctions = new string[]
"set", {
"get", "set",
"getimmediate" "get",
}; "getimmediate"
};
public static string[] MultiClientFunctions = new string[] { public static string[] MultiClientFunctions = new string[]
"setwindowsize", {
"openrom", "setwindowsize",
"closerom", "openrom",
"opentoolbox", "closerom",
"openramwatch", "opentoolbox",
"openramsearch", "openramwatch",
"openrampoke", "openramsearch",
"openhexeditor", "openrampoke",
"opentasstudio", "openhexeditor",
"opencheats", "opentasstudio",
}; "opencheats",
};
public static string[] FormsFunctions = new string[] { public static string[] FormsFunctions = new string[]
"newform", {
"destroy", "newform",
"destroyall", "destroy",
"button", "destroyall",
"label", "button",
"textbox", "label",
"setlocation", "textbox",
"setsize", "setlocation",
"settext", "setsize",
"addclick", "settext",
"clearclicks", "addclick",
"gettext", "clearclicks",
}; "gettext",
};
public static string[] BitwiseFunctions = new string[]
{
"band",
"lshift",
"rshift",
"rol",
"ror",
"bor",
"bxor",
"bnot",
};
/****************************************************/ /****************************************************/
/*************function definitions********************/ /*************function definitions********************/
@ -467,14 +504,15 @@ namespace BizHawk.MultiClient
{ {
list += l.name + "\n"; list += l.name + "\n";
} }
return list; return list;
} }
//---------------------------------------------------- //----------------------------------------------------
//Gui library //Gui library
//---------------------------------------------------- //----------------------------------------------------
private void do_gui_text(object luaX, object luaY, object luaStr, bool alert, object background = null, object forecolor = null, object anchor = null) private void do_gui_text(object luaX, object luaY, object luaStr, bool alert, object background = null,
object forecolor = null, object anchor = null)
{ {
if (!alert) if (!alert)
{ {
@ -503,10 +541,12 @@ namespace BizHawk.MultiClient
a = LuaInt(anchor); a = LuaInt(anchor);
} }
} }
Global.OSD.AddGUIText(luaStr.ToString(), LuaInt(luaX), LuaInt(luaY), alert, GetColor(background), GetColor(forecolor), a); Global.OSD.AddGUIText(luaStr.ToString(), LuaInt(luaX), LuaInt(luaY), alert, GetColor(background), GetColor(forecolor),
a);
} }
public void gui_text(object luaX, object luaY, object luaStr, object background = null, object forecolor = null, object anchor = null) public void gui_text(object luaX, object luaY, object luaStr, object background = null, object forecolor = null,
object anchor = null)
{ {
do_gui_text(luaX, luaY, luaStr, false, background, forecolor, anchor); do_gui_text(luaX, luaY, luaStr, false, background, forecolor, anchor);
} }
@ -578,7 +618,7 @@ namespace BizHawk.MultiClient
g.FillRectangle(brush, int_x, int_y, int_width, int_height); g.FillRectangle(brush, int_x, int_y, int_width, int_height);
} }
} }
catch(Exception) catch (Exception)
{ {
// need to stop the script from here // need to stop the script from here
return; return;
@ -595,7 +635,7 @@ namespace BizHawk.MultiClient
{ {
if (color == null) if (color == null)
color = "black"; color = "black";
using(var pen = GetPen(color)) using (var pen = GetPen(color))
g.DrawLine(pen, LuaInt(X), LuaInt(Y), x, LuaInt(Y)); g.DrawLine(pen, LuaInt(X), LuaInt(Y), x, LuaInt(Y));
} }
catch (Exception) catch (Exception)
@ -604,6 +644,7 @@ namespace BizHawk.MultiClient
} }
} }
} }
public void gui_drawLine(object x1, object y1, object x2, object y2, object color = null) public void gui_drawLine(object x1, object y1, object x2, object y2, object color = null)
{ {
using (var g = luaSurface.GetGraphics()) using (var g = luaSurface.GetGraphics())
@ -612,7 +653,7 @@ namespace BizHawk.MultiClient
{ {
if (color == null) if (color == null)
color = "black"; color = "black";
using(var pen = GetPen(color)) using (var pen = GetPen(color))
g.DrawLine(pen, LuaInt(x1), LuaInt(y1), LuaInt(x2), LuaInt(y2)); g.DrawLine(pen, LuaInt(x1), LuaInt(y1), LuaInt(x2), LuaInt(y2));
} }
catch (Exception) catch (Exception)
@ -694,7 +735,7 @@ namespace BizHawk.MultiClient
if (i >= 4) if (i >= 4)
break; break;
} }
using(var pen = GetPen(color)) using (var pen = GetPen(color))
g.DrawBezier(pen, Points[0], Points[1], Points[2], Points[3]); g.DrawBezier(pen, Points[0], Points[1], Points[2], Points[3]);
} }
catch (Exception) catch (Exception)
@ -704,18 +745,19 @@ namespace BizHawk.MultiClient
} }
} }
public void gui_drawPie(object X, object Y, object width, object height, object startangle, object sweepangle, object line, object background = null) public void gui_drawPie(object X, object Y, object width, object height, object startangle, object sweepangle,
object line, object background = null)
{ {
using (var g = luaSurface.GetGraphics()) using (var g = luaSurface.GetGraphics())
{ {
try try
{ {
using(var pen = GetPen(line)) using (var pen = GetPen(line))
{ {
g.DrawPie(pen, LuaInt(X), LuaInt(Y), LuaInt(width), LuaInt(height), LuaInt(startangle), LuaInt(sweepangle)); g.DrawPie(pen, LuaInt(X), LuaInt(Y), LuaInt(width), LuaInt(height), LuaInt(startangle), LuaInt(sweepangle));
if (background != null) if (background != null)
{ {
using(var brush = GetBrush(background)) using (var brush = GetBrush(background))
g.FillPie(brush, LuaInt(X), LuaInt(Y), LuaInt(width), LuaInt(height), LuaInt(startangle), LuaInt(sweepangle)); g.FillPie(brush, LuaInt(X), LuaInt(Y), LuaInt(width), LuaInt(height), LuaInt(startangle), LuaInt(sweepangle));
} }
} }
@ -744,10 +786,10 @@ namespace BizHawk.MultiClient
{ {
icon = new Icon(Path.ToString()); icon = new Icon(Path.ToString());
} }
g.DrawIcon(icon, LuaInt(x), LuaInt(y)); g.DrawIcon(icon, LuaInt(x), LuaInt(y));
} }
catch(Exception) catch (Exception)
{ {
return; return;
} }
@ -762,9 +804,9 @@ namespace BizHawk.MultiClient
{ {
Image img = Image.FromFile(Path.ToString()); Image img = Image.FromFile(Path.ToString());
if (width == null || width.GetType() != typeof(int)) if (width == null || width.GetType() != typeof (int))
width = img.Width.ToString(); width = img.Width.ToString();
if (height == null || height.GetType() != typeof(int)) if (height == null || height.GetType() != typeof (int))
height = img.Height.ToString(); height = img.Height.ToString();
g.DrawImage(img, LuaInt(x), LuaInt(y), int.Parse(width.ToString()), int.Parse(height.ToString())); g.DrawImage(img, LuaInt(x), LuaInt(y), int.Parse(width.ToString()), int.Parse(height.ToString()));
@ -959,23 +1001,23 @@ namespace BizHawk.MultiClient
{ {
if (Global.Emulator is BizHawk.Emulation.Consoles.Nintendo.NES) if (Global.Emulator is BizHawk.Emulation.Consoles.Nintendo.NES)
{ {
Global.CoreInputComm.NES_ShowOBJ = Global.Config.NESDispSprites = (bool)lua_p[0]; Global.CoreInputComm.NES_ShowOBJ = Global.Config.NESDispSprites = (bool) lua_p[0];
Global.CoreInputComm.NES_ShowBG = Global.Config.NESDispBackground = (bool)lua_p[1]; Global.CoreInputComm.NES_ShowBG = Global.Config.NESDispBackground = (bool) lua_p[1];
} }
else if (Global.Emulator is BizHawk.Emulation.Consoles.TurboGrafx.PCEngine) else if (Global.Emulator is BizHawk.Emulation.Consoles.TurboGrafx.PCEngine)
{ {
Global.CoreInputComm.PCE_ShowOBJ1 = Global.Config.PCEDispOBJ1 = (bool)lua_p[0]; Global.CoreInputComm.PCE_ShowOBJ1 = Global.Config.PCEDispOBJ1 = (bool) lua_p[0];
Global.CoreInputComm.PCE_ShowBG1 = Global.Config.PCEDispBG1 = (bool)lua_p[1]; Global.CoreInputComm.PCE_ShowBG1 = Global.Config.PCEDispBG1 = (bool) lua_p[1];
if (lua_p.Length > 2) if (lua_p.Length > 2)
{ {
Global.CoreInputComm.PCE_ShowOBJ2 = Global.Config.PCEDispOBJ2 = (bool)lua_p[2]; Global.CoreInputComm.PCE_ShowOBJ2 = Global.Config.PCEDispOBJ2 = (bool) lua_p[2];
Global.CoreInputComm.PCE_ShowBG2 = Global.Config.PCEDispBG2 = (bool)lua_p[3]; Global.CoreInputComm.PCE_ShowBG2 = Global.Config.PCEDispBG2 = (bool) lua_p[3];
} }
} }
else if (Global.Emulator is BizHawk.Emulation.Consoles.Sega.SMS) else if (Global.Emulator is BizHawk.Emulation.Consoles.Sega.SMS)
{ {
Global.CoreInputComm.SMS_ShowOBJ = Global.Config.SMSDispOBJ = (bool)lua_p[0]; Global.CoreInputComm.SMS_ShowOBJ = Global.Config.SMSDispOBJ = (bool) lua_p[0];
Global.CoreInputComm.SMS_ShowBG = Global.Config.SMSDispBG = (bool)lua_p[1]; Global.CoreInputComm.SMS_ShowBG = Global.Config.SMSDispBG = (bool) lua_p[1];
} }
} }
@ -985,7 +1027,7 @@ namespace BizHawk.MultiClient
public bool memory_usememorydomain(object lua_input) public bool memory_usememorydomain(object lua_input)
{ {
if (lua_input.GetType() != typeof(string)) if (lua_input.GetType() != typeof (string))
return false; return false;
for (int x = 0; x < Global.Emulator.MemoryDomains.Count; x++) for (int x = 0; x < Global.Emulator.MemoryDomains.Count; x++)
@ -1031,7 +1073,7 @@ namespace BizHawk.MultiClient
public int memory_read_s8(object lua_addr) public int memory_read_s8(object lua_addr)
{ {
int addr = LuaInt(lua_addr); int addr = LuaInt(lua_addr);
return (sbyte)M_R_U8(addr); return (sbyte) M_R_U8(addr);
} }
public uint memory_read_u8(object lua_addr) public uint memory_read_u8(object lua_addr)
@ -1116,7 +1158,7 @@ namespace BizHawk.MultiClient
{ {
int addr = LuaInt(lua_addr); int addr = LuaInt(lua_addr);
int v = LuaInt(lua_v); int v = LuaInt(lua_v);
M_W_U8(addr, (uint)v); M_W_U8(addr, (uint) v);
} }
public void memory_write_u8(object lua_addr, object lua_v) public void memory_write_u8(object lua_addr, object lua_v)
@ -1219,7 +1261,7 @@ namespace BizHawk.MultiClient
{ {
uint v = 0; uint v = 0;
for (int i = 0; i < size; ++i) for (int i = 0; i < size; ++i)
v |= M_R_U8(addr + i) << 8 * i; v |= M_R_U8(addr + i) << 8*i;
return v; return v;
} }
@ -1232,30 +1274,30 @@ namespace BizHawk.MultiClient
{ {
uint v = 0; uint v = 0;
for (int i = 0; i < size; ++i) for (int i = 0; i < size; ++i)
v |= M_R_U8(addr + i) << 8 * (size - 1 - i); v |= M_R_U8(addr + i) << 8*(size - 1 - i);
return v; return v;
} }
private void M_W_S_LE(int addr, int v, int size) private void M_W_S_LE(int addr, int v, int size)
{ {
M_W_U_LE(addr, (uint)v, size); M_W_U_LE(addr, (uint) v, size);
} }
private void M_W_U_LE(int addr, uint v, int size) private void M_W_U_LE(int addr, uint v, int size)
{ {
for (int i = 0; i < size; ++i) for (int i = 0; i < size; ++i)
M_W_U8(addr + i, (v >> (8 * i)) & 0xFF); M_W_U8(addr + i, (v >> (8*i)) & 0xFF);
} }
private void M_W_S_BE(int addr, int v, int size) private void M_W_S_BE(int addr, int v, int size)
{ {
M_W_U_BE(addr, (uint)v, size); M_W_U_BE(addr, (uint) v, size);
} }
private void M_W_U_BE(int addr, uint v, int size) private void M_W_U_BE(int addr, uint v, int size)
{ {
for (int i = 0; i < size; ++i) for (int i = 0; i < size; ++i)
M_W_U8(addr + i, (v >> (8 * (size - 1 - i))) & 0xFF); M_W_U8(addr + i, (v >> (8*(size - 1 - i))) & 0xFF);
} }
private uint M_R_U8(int addr) private uint M_R_U8(int addr)
@ -1265,7 +1307,7 @@ namespace BizHawk.MultiClient
private void M_W_U8(int addr, uint v) private void M_W_U8(int addr, uint v)
{ {
Global.Emulator.MemoryDomains[CurrentMemoryDomain].PokeByte(addr, (byte)v); Global.Emulator.MemoryDomains[CurrentMemoryDomain].PokeByte(addr, (byte) v);
} }
//---------------------------------------------------- //----------------------------------------------------
@ -1288,7 +1330,7 @@ namespace BizHawk.MultiClient
public int mainmemory_read_s8(object lua_addr) public int mainmemory_read_s8(object lua_addr)
{ {
int addr = LuaInt(lua_addr); int addr = LuaInt(lua_addr);
return (sbyte)MM_R_U8(addr); return (sbyte) MM_R_U8(addr);
} }
public uint mainmemory_read_u8(object lua_addr) public uint mainmemory_read_u8(object lua_addr)
@ -1373,7 +1415,7 @@ namespace BizHawk.MultiClient
{ {
int addr = LuaInt(lua_addr); int addr = LuaInt(lua_addr);
int v = LuaInt(lua_v); int v = LuaInt(lua_v);
MM_W_U8(addr, (uint)v); MM_W_U8(addr, (uint) v);
} }
public void mainmemory_write_u8(object lua_addr, object lua_v) public void mainmemory_write_u8(object lua_addr, object lua_v)
@ -1476,7 +1518,7 @@ namespace BizHawk.MultiClient
{ {
uint v = 0; uint v = 0;
for (int i = 0; i < size; ++i) for (int i = 0; i < size; ++i)
v |= MM_R_U8(addr + i) << 8 * i; v |= MM_R_U8(addr + i) << 8*i;
return v; return v;
} }
@ -1489,30 +1531,30 @@ namespace BizHawk.MultiClient
{ {
uint v = 0; uint v = 0;
for (int i = 0; i < size; ++i) for (int i = 0; i < size; ++i)
v |= MM_R_U8(addr + i) << 8 * (size - 1 - i); v |= MM_R_U8(addr + i) << 8*(size - 1 - i);
return v; return v;
} }
private void MM_W_S_LE(int addr, int v, int size) private void MM_W_S_LE(int addr, int v, int size)
{ {
MM_W_U_LE(addr, (uint)v, size); MM_W_U_LE(addr, (uint) v, size);
} }
private void MM_W_U_LE(int addr, uint v, int size) private void MM_W_U_LE(int addr, uint v, int size)
{ {
for (int i = 0; i < size; ++i) for (int i = 0; i < size; ++i)
MM_W_U8(addr + i, (v >> (8 * i)) & 0xFF); MM_W_U8(addr + i, (v >> (8*i)) & 0xFF);
} }
private void MM_W_S_BE(int addr, int v, int size) private void MM_W_S_BE(int addr, int v, int size)
{ {
MM_W_U_BE(addr, (uint)v, size); MM_W_U_BE(addr, (uint) v, size);
} }
private void MM_W_U_BE(int addr, uint v, int size) private void MM_W_U_BE(int addr, uint v, int size)
{ {
for (int i = 0; i < size; ++i) for (int i = 0; i < size; ++i)
MM_W_U8(addr + i, (v >> (8 * (size - 1 - i))) & 0xFF); MM_W_U8(addr + i, (v >> (8*(size - 1 - i))) & 0xFF);
} }
private uint MM_R_U8(int addr) private uint MM_R_U8(int addr)
@ -1522,18 +1564,57 @@ namespace BizHawk.MultiClient
private void MM_W_U8(int addr, uint v) private void MM_W_U8(int addr, uint v)
{ {
Global.Emulator.MainMemory.PokeByte(addr, (byte)v); Global.Emulator.MainMemory.PokeByte(addr, (byte) v);
} }
private int U2S(uint u, int size) private int U2S(uint u, int size)
{ {
int s = (int)u; int s = (int) u;
s <<= 8 * (4 - size); s <<= 8*(4 - size);
s >>= 8 * (4 - size); s >>= 8*(4 - size);
return s; return s;
} }
//---------------------------------------------------- //----------------------------------------------------
//Bitwise Operator library
//----------------------------------------------------
public uint bit_band(uint lua_v, uint amt)
{
return lua_v & amt;
}
public uint bit_lshift(uint lua_v, int amt)
{
return lua_v << amt;
}
public uint bit_rshift(uint lua_v, int amt)
{
return lua_v >> amt;
}
public uint bit_rol(uint lua_v, int amt)
{
return (uint) ((lua_v << amt) | (lua_v >> (32 -amt)));
}
public uint bit_ror(uint lua_v, int amt)
{
return (uint) ((lua_v >> amt) | (lua_v << (32 - amt)));
}
public uint bit_bor(uint lua_v, uint amt)
{
return lua_v | amt;
}
public uint bit_bxor(uint lua_v, uint amt)
{
return lua_v ^ amt;
}
public uint bit_bnot(uint lua_v)
{
return ~ lua_v;
}
//----------------------------------------------------
//Savestate library //Savestate library
//---------------------------------------------------- //----------------------------------------------------
public void savestate_saveslot(object lua_input) public void savestate_saveslot(object lua_input)