2011-02-20 19:18:27 +00:00
|
|
|
|
using System;
|
2012-03-19 03:39:56 +00:00
|
|
|
|
using System.Collections;
|
2011-02-20 19:18:27 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
2012-01-22 22:20:09 +00:00
|
|
|
|
using System.IO;
|
2011-02-20 19:18:27 +00:00
|
|
|
|
using LuaInterface;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using BizHawk.MultiClient.tools;
|
2012-01-22 23:44:53 +00:00
|
|
|
|
using System.Threading;
|
|
|
|
|
|
2011-02-20 19:18:27 +00:00
|
|
|
|
|
|
|
|
|
namespace BizHawk.MultiClient
|
|
|
|
|
{
|
2012-01-22 22:20:09 +00:00
|
|
|
|
public class LuaImplementation
|
2011-06-26 02:09:06 +00:00
|
|
|
|
{
|
2012-01-28 21:43:55 +00:00
|
|
|
|
Lua lua = new Lua();
|
2011-06-26 02:09:06 +00:00
|
|
|
|
LuaConsole Caller;
|
2012-03-17 02:18:09 +00:00
|
|
|
|
public string LuaLibraryList = "";
|
2012-01-28 21:43:55 +00:00
|
|
|
|
public EventWaitHandle LuaWait;
|
|
|
|
|
public bool isRunning;
|
|
|
|
|
private Thread LuaThread;
|
2012-01-22 22:42:40 +00:00
|
|
|
|
private int CurrentMemoryDomain = 0; //Main memory by default
|
2012-01-21 20:05:53 +00:00
|
|
|
|
|
|
|
|
|
public LuaImplementation(LuaConsole passed)
|
|
|
|
|
{
|
2012-01-28 21:43:55 +00:00
|
|
|
|
LuaWait = new AutoResetEvent(false);
|
2012-01-22 03:14:31 +00:00
|
|
|
|
LuaLibraryList = "";
|
2012-01-21 20:05:53 +00:00
|
|
|
|
Caller = passed.get();
|
2012-01-28 21:43:55 +00:00
|
|
|
|
LuaRegister(lua);
|
|
|
|
|
}
|
2012-01-28 21:51:01 +00:00
|
|
|
|
|
|
|
|
|
public void Close()
|
|
|
|
|
{
|
2012-03-07 00:58:41 +00:00
|
|
|
|
lua = new Lua();
|
2012-02-03 12:18:27 +00:00
|
|
|
|
LuaKillThread();
|
2012-01-28 22:00:51 +00:00
|
|
|
|
LuaWait.Dispose();
|
2012-01-28 21:51:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-28 21:43:55 +00:00
|
|
|
|
public void LuaRegister(Lua lua)
|
|
|
|
|
{
|
2012-01-21 20:05:53 +00:00
|
|
|
|
lua.RegisterFunction("print", this, this.GetType().GetMethod("print"));
|
2012-01-28 21:43:55 +00:00
|
|
|
|
|
2012-01-21 20:05:53 +00:00
|
|
|
|
//Register libraries
|
|
|
|
|
lua.NewTable("console");
|
|
|
|
|
for (int i = 0; i < ConsoleFunctions.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
lua.RegisterFunction("console." + ConsoleFunctions[i], this, this.GetType().GetMethod("console_" + ConsoleFunctions[i]));
|
2012-01-22 03:14:31 +00:00
|
|
|
|
LuaLibraryList += "console." + ConsoleFunctions[i] + "\n";
|
2012-01-21 20:05:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-28 22:44:48 +00:00
|
|
|
|
lua.NewTable("gui");
|
|
|
|
|
for (int i = 0; i < GuiFunctions.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
lua.RegisterFunction("gui." + GuiFunctions[i], this, this.GetType().GetMethod("gui_" + GuiFunctions[i]));
|
|
|
|
|
LuaLibraryList += "gui." + GuiFunctions[i] + "\n";
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-21 20:05:53 +00:00
|
|
|
|
lua.NewTable("emu");
|
|
|
|
|
for (int i = 0; i < EmuFunctions.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
lua.RegisterFunction("emu." + EmuFunctions[i], this, this.GetType().GetMethod("emu_" + EmuFunctions[i]));
|
2012-01-22 03:14:31 +00:00
|
|
|
|
LuaLibraryList += "emu." + EmuFunctions[i] + "\n";
|
2012-01-21 20:05:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lua.NewTable("memory");
|
|
|
|
|
for (int i = 0; i < MemoryFunctions.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
lua.RegisterFunction("memory." + MemoryFunctions[i], this, this.GetType().GetMethod("memory_" + MemoryFunctions[i]));
|
2012-01-22 03:14:31 +00:00
|
|
|
|
LuaLibraryList += "memory." + MemoryFunctions[i] + "\n";
|
2012-01-21 20:05:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-28 22:11:39 +00:00
|
|
|
|
lua.NewTable("mainmemory");
|
|
|
|
|
for (int i = 0; i < MainMemoryFunctions.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
lua.RegisterFunction("mainmemory." + MainMemoryFunctions[i], this, this.GetType().GetMethod("mainmemory_" + MainMemoryFunctions[i]));
|
|
|
|
|
LuaLibraryList += "mainmemory." + MainMemoryFunctions[i] + "\n";
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-21 20:05:53 +00:00
|
|
|
|
lua.NewTable("savestate");
|
|
|
|
|
for (int i = 0; i < SaveStateFunctions.Length; i++)
|
|
|
|
|
{
|
2012-02-03 12:18:27 +00:00
|
|
|
|
lua.RegisterFunction("savestate." + SaveStateFunctions[i], this, this.GetType().GetMethod("savestate_" + SaveStateFunctions[i]));
|
|
|
|
|
LuaLibraryList += "savestate." + SaveStateFunctions[i] + "\n";
|
2012-01-21 20:05:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lua.NewTable("movie");
|
|
|
|
|
for (int i = 0; i < MovieFunctions.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
lua.RegisterFunction("movie." + MovieFunctions[i], this, this.GetType().GetMethod("movie_" + MovieFunctions[i]));
|
2012-01-22 03:14:31 +00:00
|
|
|
|
LuaLibraryList += "movie." + MovieFunctions[i] + "\n";
|
2012-01-21 20:05:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lua.NewTable("joypad");
|
|
|
|
|
for (int i = 0; i < JoypadFunctions.Length; i++)
|
|
|
|
|
{
|
2012-01-22 03:14:31 +00:00
|
|
|
|
lua.RegisterFunction("joypad." + JoypadFunctions[i], this, this.GetType().GetMethod("joypad_" + JoypadFunctions[i]));
|
|
|
|
|
LuaLibraryList += "joypad." + JoypadFunctions[i] + "\n";
|
2012-01-21 20:05:53 +00:00
|
|
|
|
}
|
2012-01-22 22:20:09 +00:00
|
|
|
|
|
|
|
|
|
lua.NewTable("client");
|
|
|
|
|
for (int i = 0; i < MultiClientFunctions.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
lua.RegisterFunction("client." + MultiClientFunctions[i], this, this.GetType().GetMethod("client_" + MultiClientFunctions[i]));
|
|
|
|
|
LuaLibraryList += "client." + MultiClientFunctions[i] + "\n";
|
|
|
|
|
}
|
2012-01-21 20:05:53 +00:00
|
|
|
|
}
|
2012-01-28 21:43:55 +00:00
|
|
|
|
private void LuaThreadFunction(object File)
|
|
|
|
|
{
|
|
|
|
|
string F = File.ToString();
|
|
|
|
|
isRunning = true;
|
|
|
|
|
try
|
|
|
|
|
{
|
2012-03-12 01:57:38 +00:00
|
|
|
|
if (LuaThread != null)
|
|
|
|
|
lua.DoFile(F);
|
2012-01-28 21:43:55 +00:00
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
2012-03-13 21:36:20 +00:00
|
|
|
|
if (LuaThread.ThreadState.ToString() != "AbortRequested")
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Exception caught. " + e.ToString());
|
|
|
|
|
}
|
2012-01-28 21:43:55 +00:00
|
|
|
|
}
|
|
|
|
|
isRunning = false;
|
|
|
|
|
LuaWait.Set();
|
|
|
|
|
}
|
2012-02-03 12:18:27 +00:00
|
|
|
|
|
|
|
|
|
public void LuaKillThread()
|
|
|
|
|
{
|
|
|
|
|
if (LuaThread != null)
|
|
|
|
|
LuaThread.Abort();
|
|
|
|
|
}
|
2012-01-21 20:05:53 +00:00
|
|
|
|
|
2012-01-21 20:20:06 +00:00
|
|
|
|
public void DoLuaFile(string File)
|
|
|
|
|
{
|
2012-01-28 21:43:55 +00:00
|
|
|
|
LuaThread = new Thread(new ParameterizedThreadStart(LuaThreadFunction));
|
|
|
|
|
LuaThread.Start(File);
|
2012-01-21 20:20:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-03-11 09:16:09 +00:00
|
|
|
|
private int LuaInt(object lua_arg)
|
|
|
|
|
{
|
|
|
|
|
return Convert.ToInt32((double)lua_arg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private uint LuaUInt(object lua_arg)
|
|
|
|
|
{
|
|
|
|
|
return Convert.ToUInt32((double)lua_arg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* LuaInterface requires the exact match of parameter count,
|
|
|
|
|
* except optional parameters. So, if you want to support
|
|
|
|
|
* variable arguments, declare them as optional and pass
|
|
|
|
|
* them to this method.
|
|
|
|
|
*/
|
|
|
|
|
private object[] LuaVarArgs(params object[] lua_args)
|
|
|
|
|
{
|
|
|
|
|
int n = lua_args.Length;
|
|
|
|
|
int trim = 0;
|
|
|
|
|
for (int i = n-1; i >= 0; --i)
|
|
|
|
|
if (lua_args[i] == null) ++trim;
|
|
|
|
|
object[] lua_result = new object[n-trim];
|
|
|
|
|
Array.Copy(lua_args, lua_result, n-trim);
|
|
|
|
|
return lua_result;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-28 21:43:55 +00:00
|
|
|
|
|
2012-01-21 20:20:06 +00:00
|
|
|
|
public void print(string s)
|
|
|
|
|
{
|
2012-03-10 03:07:05 +00:00
|
|
|
|
Caller.AddText(s);
|
|
|
|
|
Caller.AddText("\n");
|
2012-01-21 20:20:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-21 20:05:53 +00:00
|
|
|
|
/****************************************************/
|
|
|
|
|
/*************library definitions********************/
|
|
|
|
|
/****************************************************/
|
2012-01-28 22:11:39 +00:00
|
|
|
|
public static string[] ConsoleFunctions = new string[]
|
|
|
|
|
{
|
2012-01-22 03:14:31 +00:00
|
|
|
|
"output",
|
|
|
|
|
"clear",
|
2012-03-11 05:13:12 +00:00
|
|
|
|
"getluafunctionslist",
|
2012-01-21 20:05:53 +00:00
|
|
|
|
};
|
|
|
|
|
|
2012-01-28 22:44:48 +00:00
|
|
|
|
public static string[] GuiFunctions = new string[]
|
|
|
|
|
{
|
2012-03-11 00:54:24 +00:00
|
|
|
|
"text",
|
2012-03-11 05:13:12 +00:00
|
|
|
|
"alert",
|
2012-01-28 22:44:48 +00:00
|
|
|
|
};
|
|
|
|
|
|
2012-01-28 22:11:39 +00:00
|
|
|
|
public static string[] EmuFunctions = new string[]
|
|
|
|
|
{
|
2012-01-22 03:14:31 +00:00
|
|
|
|
"frameadvance",
|
2011-06-26 02:09:06 +00:00
|
|
|
|
"pause",
|
|
|
|
|
"unpause",
|
2012-01-21 20:20:06 +00:00
|
|
|
|
"togglepause",
|
|
|
|
|
//"speedmode",
|
2012-01-22 03:14:31 +00:00
|
|
|
|
"framecount",
|
|
|
|
|
"lagcount",
|
|
|
|
|
"islagged",
|
2012-03-11 05:13:12 +00:00
|
|
|
|
"getsystemid",
|
2012-01-21 20:20:06 +00:00
|
|
|
|
//"registerbefore",
|
|
|
|
|
//"registerafter",
|
2012-03-11 05:13:12 +00:00
|
|
|
|
//"register",
|
2012-03-11 05:47:38 +00:00
|
|
|
|
"setrenderplanes",
|
2011-06-26 02:09:06 +00:00
|
|
|
|
};
|
2012-01-28 22:11:39 +00:00
|
|
|
|
|
|
|
|
|
public static string[] MemoryFunctions = new string[]
|
|
|
|
|
{
|
2012-01-28 22:30:04 +00:00
|
|
|
|
"usememorydomain",
|
|
|
|
|
"getmemorydomainlist",
|
|
|
|
|
"getcurrentmemorydomain",
|
2012-03-10 03:07:05 +00:00
|
|
|
|
"read_s8",
|
|
|
|
|
"read_u8",
|
|
|
|
|
"read_s16_le",
|
|
|
|
|
"read_s24_le",
|
|
|
|
|
"read_s32_le",
|
|
|
|
|
"read_u16_le",
|
|
|
|
|
"read_u24_le",
|
|
|
|
|
"read_u32_le",
|
|
|
|
|
"read_s16_be",
|
|
|
|
|
"read_s24_be",
|
|
|
|
|
"read_s32_be",
|
|
|
|
|
"read_u16_be",
|
|
|
|
|
"read_u24_be",
|
|
|
|
|
"read_u32_be",
|
|
|
|
|
"write_s8",
|
|
|
|
|
"write_u8",
|
|
|
|
|
"write_s16_le",
|
|
|
|
|
"write_s24_le",
|
|
|
|
|
"write_s32_le",
|
|
|
|
|
"write_u16_le",
|
|
|
|
|
"write_u24_le",
|
|
|
|
|
"write_u32_le",
|
|
|
|
|
"write_s16_be",
|
|
|
|
|
"write_s24_be",
|
|
|
|
|
"write_s32_be",
|
|
|
|
|
"write_u16_be",
|
|
|
|
|
"write_u24_be",
|
|
|
|
|
"write_u32_be",
|
2012-03-10 03:58:42 +00:00
|
|
|
|
"readbyte",
|
2012-03-11 05:13:12 +00:00
|
|
|
|
"writebyte",
|
2012-01-28 22:11:39 +00:00
|
|
|
|
//"registerwrite",
|
2012-03-11 05:13:12 +00:00
|
|
|
|
//"registerread",
|
2012-01-28 22:11:39 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public static string[] MainMemoryFunctions = new string[]
|
|
|
|
|
{
|
2012-03-10 03:07:05 +00:00
|
|
|
|
"read_s8",
|
|
|
|
|
"read_u8",
|
|
|
|
|
"read_s16_le",
|
|
|
|
|
"read_s24_le",
|
|
|
|
|
"read_s32_le",
|
|
|
|
|
"read_u16_le",
|
|
|
|
|
"read_u24_le",
|
|
|
|
|
"read_u32_le",
|
|
|
|
|
"read_s16_be",
|
|
|
|
|
"read_s24_be",
|
|
|
|
|
"read_s32_be",
|
|
|
|
|
"read_u16_be",
|
|
|
|
|
"read_u24_be",
|
|
|
|
|
"read_u32_be",
|
|
|
|
|
"write_s8",
|
|
|
|
|
"write_u8",
|
|
|
|
|
"write_s16_le",
|
|
|
|
|
"write_s24_le",
|
|
|
|
|
"write_s32_le",
|
|
|
|
|
"write_u16_le",
|
|
|
|
|
"write_u24_le",
|
|
|
|
|
"write_u32_le",
|
|
|
|
|
"write_s16_be",
|
|
|
|
|
"write_s24_be",
|
|
|
|
|
"write_s32_be",
|
|
|
|
|
"write_u16_be",
|
|
|
|
|
"write_u24_be",
|
|
|
|
|
"write_u32_be",
|
2012-03-10 03:58:42 +00:00
|
|
|
|
"readbyte",
|
2012-03-11 05:13:12 +00:00
|
|
|
|
"writebyte",
|
2011-06-26 02:09:06 +00:00
|
|
|
|
//"registerwrite",
|
2012-03-11 05:13:12 +00:00
|
|
|
|
//"registerread",
|
2012-01-28 22:11:39 +00:00
|
|
|
|
};
|
|
|
|
|
|
2011-06-26 02:09:06 +00:00
|
|
|
|
public static string[] SaveStateFunctions = new string[] {
|
2012-02-03 12:18:27 +00:00
|
|
|
|
"saveslot",
|
|
|
|
|
"loadslot",
|
2011-06-26 02:09:06 +00:00
|
|
|
|
"save",
|
2012-03-11 05:13:12 +00:00
|
|
|
|
"load",
|
2011-06-26 02:09:06 +00:00
|
|
|
|
};
|
2012-02-03 12:18:27 +00:00
|
|
|
|
|
2011-06-26 02:09:06 +00:00
|
|
|
|
public static string[] MovieFunctions = new string[] {
|
|
|
|
|
"mode",
|
2012-03-18 19:33:38 +00:00
|
|
|
|
"isloaded",
|
2011-06-26 02:09:06 +00:00
|
|
|
|
"rerecordcount",
|
2012-03-18 19:33:38 +00:00
|
|
|
|
"length",
|
2012-03-11 05:13:12 +00:00
|
|
|
|
"stop",
|
2012-03-18 19:52:28 +00:00
|
|
|
|
"filename",
|
|
|
|
|
"getreadonly",
|
|
|
|
|
"setreadonly",
|
2012-03-18 19:33:38 +00:00
|
|
|
|
//"rerecordcounting",
|
2011-06-26 02:09:06 +00:00
|
|
|
|
};
|
2012-02-03 12:18:27 +00:00
|
|
|
|
|
2011-06-26 02:09:06 +00:00
|
|
|
|
public static string[] JoypadFunctions = new string[] {
|
2012-03-18 19:14:50 +00:00
|
|
|
|
//"set",
|
|
|
|
|
"get",
|
2011-06-26 02:09:06 +00:00
|
|
|
|
};
|
2012-01-21 20:05:53 +00:00
|
|
|
|
|
2012-01-22 22:20:09 +00:00
|
|
|
|
public static string[] MultiClientFunctions = new string[] {
|
2012-01-22 22:42:40 +00:00
|
|
|
|
"openrom",
|
|
|
|
|
"closerom",
|
|
|
|
|
"opentoolbox",
|
|
|
|
|
"openramwatch",
|
|
|
|
|
"openramsearch",
|
|
|
|
|
"openrampoke",
|
|
|
|
|
"openhexeditor",
|
|
|
|
|
"opentasstudio",
|
2012-03-11 05:13:12 +00:00
|
|
|
|
"opencheats",
|
2012-01-22 22:20:09 +00:00
|
|
|
|
};
|
|
|
|
|
|
2012-01-21 20:05:53 +00:00
|
|
|
|
/****************************************************/
|
|
|
|
|
/*************function definitions********************/
|
|
|
|
|
/****************************************************/
|
2011-06-26 02:09:06 +00:00
|
|
|
|
|
2012-01-21 20:20:06 +00:00
|
|
|
|
//----------------------------------------------------
|
|
|
|
|
//Console library
|
|
|
|
|
//----------------------------------------------------
|
|
|
|
|
|
|
|
|
|
public void console_output(object lua_input)
|
2011-06-26 02:09:06 +00:00
|
|
|
|
{
|
2012-01-21 20:20:06 +00:00
|
|
|
|
Global.MainForm.LuaConsole1.WriteToOutputWindow(lua_input.ToString());
|
2011-06-26 02:09:06 +00:00
|
|
|
|
}
|
2012-01-21 20:20:06 +00:00
|
|
|
|
|
2012-03-10 03:07:05 +00:00
|
|
|
|
public void console_clear()
|
2012-01-22 03:14:31 +00:00
|
|
|
|
{
|
|
|
|
|
Global.MainForm.LuaConsole1.ClearOutputWindow();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string console_getluafunctionslist()
|
|
|
|
|
{
|
|
|
|
|
return LuaLibraryList;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-21 20:20:06 +00:00
|
|
|
|
//----------------------------------------------------
|
2012-01-28 22:44:48 +00:00
|
|
|
|
//Gui library
|
|
|
|
|
//----------------------------------------------------
|
2012-03-10 03:31:07 +00:00
|
|
|
|
public void gui_text(object luaX, object luaY, object luaStr)
|
2012-01-28 22:44:48 +00:00
|
|
|
|
{
|
2012-03-11 00:50:06 +00:00
|
|
|
|
Global.RenderPanel.AddGUIText(luaStr.ToString(), LuaInt(luaX), LuaInt(luaY), false);
|
2012-01-28 22:44:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-03-11 00:54:24 +00:00
|
|
|
|
public void gui_alert(object luaX, object luaY, object luaStr)
|
|
|
|
|
{
|
|
|
|
|
Global.RenderPanel.AddGUIText(luaStr.ToString(), LuaInt(luaX), LuaInt(luaY), true);
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-28 22:44:48 +00:00
|
|
|
|
//----------------------------------------------------
|
2012-01-21 20:20:06 +00:00
|
|
|
|
//Emu library
|
|
|
|
|
//----------------------------------------------------
|
2012-01-22 03:14:31 +00:00
|
|
|
|
public void emu_frameadvance()
|
|
|
|
|
{
|
2012-01-28 21:43:55 +00:00
|
|
|
|
LuaWait.Set();
|
|
|
|
|
Global.MainForm.MainWait.WaitOne();
|
2012-01-22 03:14:31 +00:00
|
|
|
|
}
|
2012-01-21 20:20:06 +00:00
|
|
|
|
|
|
|
|
|
public void emu_pause()
|
2011-06-26 02:09:06 +00:00
|
|
|
|
{
|
2012-01-21 20:20:06 +00:00
|
|
|
|
Global.MainForm.PauseEmulator();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void emu_unpause()
|
|
|
|
|
{
|
|
|
|
|
Global.MainForm.UnpauseEmulator();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void emu_togglepause()
|
|
|
|
|
{
|
|
|
|
|
Global.MainForm.TogglePause();
|
2011-06-26 02:09:06 +00:00
|
|
|
|
}
|
2012-01-21 20:20:06 +00:00
|
|
|
|
|
2012-01-22 03:14:31 +00:00
|
|
|
|
public int emu_framecount()
|
|
|
|
|
{
|
|
|
|
|
return Global.Emulator.Frame;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int emu_lagcount()
|
|
|
|
|
{
|
|
|
|
|
return Global.Emulator.LagCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool emu_islagged()
|
|
|
|
|
{
|
|
|
|
|
return Global.Emulator.IsLagFrame;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string emu_getsystemid()
|
|
|
|
|
{
|
|
|
|
|
return Global.Emulator.SystemId;
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-11 09:16:09 +00:00
|
|
|
|
// For now, it accepts arguments up to 5.
|
|
|
|
|
public void emu_setrenderplanes(
|
|
|
|
|
object lua_p0, object lua_p1 = null, object lua_p2 = null,
|
|
|
|
|
object lua_p3 = null, object lua_p4 = null)
|
|
|
|
|
{
|
|
|
|
|
emu_setrenderplanes_do(LuaVarArgs(lua_p0, lua_p1, lua_p2, lua_p3, lua_p4));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: error handling for argument count mismatch
|
|
|
|
|
private void emu_setrenderplanes_do(object[] lua_p)
|
2012-03-11 05:47:38 +00:00
|
|
|
|
{
|
|
|
|
|
if (Global.Emulator is BizHawk.Emulation.Consoles.Nintendo.NES)
|
|
|
|
|
{
|
2012-03-11 09:16:09 +00:00
|
|
|
|
Global.CoreInputComm.NES_ShowOBJ = Global.Config.NESDispSprites = (bool)lua_p[0];
|
|
|
|
|
Global.CoreInputComm.NES_ShowBG = Global.Config.NESDispBackground = (bool)lua_p[1];
|
2012-03-11 05:47:38 +00:00
|
|
|
|
}
|
2012-03-11 17:25:25 +00:00
|
|
|
|
else if (Global.Emulator is BizHawk.Emulation.Consoles.TurboGrafx.PCEngine)
|
2012-03-11 06:50:46 +00:00
|
|
|
|
{
|
2012-03-11 09:51:23 +00:00
|
|
|
|
Global.CoreInputComm.PCE_ShowOBJ1 = Global.Config.PCEDispOBJ1 = (bool)lua_p[0];
|
|
|
|
|
Global.CoreInputComm.PCE_ShowBG1 = Global.Config.PCEDispBG1 = (bool)lua_p[1];
|
|
|
|
|
if (lua_p.Length > 2)
|
|
|
|
|
{
|
|
|
|
|
Global.CoreInputComm.PCE_ShowOBJ2 = Global.Config.PCEDispOBJ2 = (bool)lua_p[2];
|
|
|
|
|
Global.CoreInputComm.PCE_ShowBG2 = Global.Config.PCEDispBG2 = (bool)lua_p[3];
|
|
|
|
|
}
|
2012-03-11 06:50:46 +00:00
|
|
|
|
}
|
2012-03-11 17:25:25 +00:00
|
|
|
|
else if (Global.Emulator is BizHawk.Emulation.Consoles.Sega.SMS)
|
|
|
|
|
{
|
|
|
|
|
Global.CoreInputComm.SMS_ShowOBJ = Global.Config.SMSDispOBJ = (bool)lua_p[0];
|
|
|
|
|
Global.CoreInputComm.SMS_ShowBG = Global.Config.SMSDispBG = (bool)lua_p[1];
|
|
|
|
|
}
|
2012-03-11 05:47:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-21 20:20:06 +00:00
|
|
|
|
//----------------------------------------------------
|
|
|
|
|
//Memory library
|
|
|
|
|
//----------------------------------------------------
|
2012-01-28 21:43:55 +00:00
|
|
|
|
|
2012-01-28 22:30:04 +00:00
|
|
|
|
public bool memory_usememorydomain(object lua_input)
|
|
|
|
|
{
|
|
|
|
|
if (lua_input.GetType() != typeof(string))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
for (int x = 0; x < Global.Emulator.MemoryDomains.Count; x++)
|
|
|
|
|
{
|
|
|
|
|
if (Global.Emulator.MemoryDomains[x].Name == lua_input.ToString())
|
|
|
|
|
{
|
|
|
|
|
CurrentMemoryDomain = x;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string memory_getmemorydomainlist()
|
|
|
|
|
{
|
|
|
|
|
string list = "";
|
|
|
|
|
for (int x = 0; x < Global.Emulator.MemoryDomains.Count; x++)
|
|
|
|
|
{
|
|
|
|
|
list += Global.Emulator.MemoryDomains[x].Name + '\n';
|
|
|
|
|
}
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string memory_getcurrentmemorydomain()
|
|
|
|
|
{
|
|
|
|
|
return Global.Emulator.MemoryDomains[CurrentMemoryDomain].Name;
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-10 03:58:42 +00:00
|
|
|
|
public uint memory_readbyte(object lua_addr)
|
2011-06-26 02:09:06 +00:00
|
|
|
|
{
|
2012-03-10 03:58:42 +00:00
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
return M_R_U8(addr);
|
2011-06-26 02:09:06 +00:00
|
|
|
|
}
|
2012-01-21 20:20:06 +00:00
|
|
|
|
|
2012-03-10 03:58:42 +00:00
|
|
|
|
public void memory_writebyte(object lua_addr, object lua_v)
|
2011-06-26 02:09:06 +00:00
|
|
|
|
{
|
2012-03-10 03:58:42 +00:00
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
uint v = LuaUInt(lua_v);
|
|
|
|
|
M_W_U8(addr, v);
|
2011-06-26 02:09:06 +00:00
|
|
|
|
}
|
2011-05-14 01:05:26 +00:00
|
|
|
|
|
2012-03-10 03:07:05 +00:00
|
|
|
|
public int memory_read_s8(object lua_addr)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
return (sbyte)M_R_U8(addr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public uint memory_read_u8(object lua_addr)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
return M_R_U8(addr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int memory_read_s16_le(object lua_addr)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
return M_R_S_LE(addr, 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int memory_read_s24_le(object lua_addr)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
return M_R_S_LE(addr, 3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int memory_read_s32_le(object lua_addr)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
return M_R_S_LE(addr, 4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public uint memory_read_u16_le(object lua_addr)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
return M_R_U_LE(addr, 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public uint memory_read_u24_le(object lua_addr)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
return M_R_U_LE(addr, 3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public uint memory_read_u32_le(object lua_addr)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
return M_R_U_LE(addr, 4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int memory_read_s16_be(object lua_addr)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
return M_R_S_BE(addr, 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int memory_read_s24_be(object lua_addr)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
return M_R_S_BE(addr, 3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int memory_read_s32_be(object lua_addr)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
return M_R_S_BE(addr, 4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public uint memory_read_u16_be(object lua_addr)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
return M_R_U_BE(addr, 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public uint memory_read_u24_be(object lua_addr)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
return M_R_U_BE(addr, 3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public uint memory_read_u32_be(object lua_addr)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
return M_R_U_BE(addr, 4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void memory_write_s8(object lua_addr, object lua_v)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
int v = LuaInt(lua_v);
|
|
|
|
|
M_W_U8(addr, (uint)v);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void memory_write_u8(object lua_addr, object lua_v)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
uint v = LuaUInt(lua_v);
|
|
|
|
|
M_W_U8(addr, v);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void memory_write_s16_le(object lua_addr, object lua_v)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
int v = LuaInt(lua_v);
|
|
|
|
|
M_W_S_LE(addr, v, 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void memory_write_s24_le(object lua_addr, object lua_v)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
int v = LuaInt(lua_v);
|
|
|
|
|
M_W_S_LE(addr, v, 3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void memory_write_s32_le(object lua_addr, object lua_v)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
int v = LuaInt(lua_v);
|
|
|
|
|
M_W_S_LE(addr, v, 4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void memory_write_u16_le(object lua_addr, object lua_v)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
uint v = LuaUInt(lua_v);
|
|
|
|
|
M_W_U_LE(addr, v, 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void memory_write_u24_le(object lua_addr, object lua_v)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
uint v = LuaUInt(lua_v);
|
|
|
|
|
M_W_U_LE(addr, v, 3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void memory_write_u32_le(object lua_addr, object lua_v)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
uint v = LuaUInt(lua_v);
|
|
|
|
|
M_W_U_LE(addr, v, 4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void memory_write_s16_be(object lua_addr, object lua_v)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
int v = LuaInt(lua_v);
|
|
|
|
|
M_W_S_BE(addr, v, 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void memory_write_s24_be(object lua_addr, object lua_v)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
int v = LuaInt(lua_v);
|
|
|
|
|
M_W_S_BE(addr, v, 3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void memory_write_s32_be(object lua_addr, object lua_v)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
int v = LuaInt(lua_v);
|
|
|
|
|
M_W_S_BE(addr, v, 4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void memory_write_u16_be(object lua_addr, object lua_v)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
uint v = LuaUInt(lua_v);
|
|
|
|
|
M_W_U_BE(addr, v, 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void memory_write_u24_be(object lua_addr, object lua_v)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
uint v = LuaUInt(lua_v);
|
|
|
|
|
M_W_U_BE(addr, v, 3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void memory_write_u32_be(object lua_addr, object lua_v)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
uint v = LuaUInt(lua_v);
|
|
|
|
|
M_W_U_BE(addr, v, 4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int M_R_S_LE(int addr, int size)
|
|
|
|
|
{
|
|
|
|
|
return U2S(M_R_U_LE(addr, size), size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private uint M_R_U_LE(int addr, int size)
|
|
|
|
|
{
|
|
|
|
|
uint v = 0;
|
|
|
|
|
for(int i = 0; i < size; ++i)
|
|
|
|
|
v |= M_R_U8(addr+i) << 8*i;
|
|
|
|
|
return v;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int M_R_S_BE(int addr, int size)
|
|
|
|
|
{
|
|
|
|
|
return U2S(M_R_U_BE(addr, size), size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private uint M_R_U_BE(int addr, int size)
|
|
|
|
|
{
|
|
|
|
|
uint v = 0;
|
|
|
|
|
for(int i = 0; i < size; ++i)
|
|
|
|
|
v |= M_R_U8(addr+i) << 8*(size-1-i);
|
|
|
|
|
return v;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void M_W_S_LE(int addr, int v, int size)
|
|
|
|
|
{
|
|
|
|
|
M_W_U_LE(addr, (uint)v, size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void M_W_U_LE(int addr, uint v, int size)
|
|
|
|
|
{
|
|
|
|
|
for(int i = 0; i < size; ++i)
|
|
|
|
|
M_W_U8(addr+i, (v>>(8*i)) & 0xFF);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void M_W_S_BE(int addr, int v, int size)
|
|
|
|
|
{
|
|
|
|
|
M_W_U_BE(addr, (uint)v, size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void M_W_U_BE(int addr, uint v, int size)
|
|
|
|
|
{
|
|
|
|
|
for(int i = 0; i < size; ++i)
|
|
|
|
|
M_W_U8(addr+i, (v>>(8*(size-1-i))) & 0xFF);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private uint M_R_U8(int addr)
|
|
|
|
|
{
|
|
|
|
|
return Global.Emulator.MemoryDomains[CurrentMemoryDomain].PeekByte(addr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void M_W_U8(int addr, uint v)
|
|
|
|
|
{
|
|
|
|
|
Global.Emulator.MemoryDomains[CurrentMemoryDomain].PokeByte(addr, (byte)v);
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-28 22:11:39 +00:00
|
|
|
|
//----------------------------------------------------
|
|
|
|
|
//Main Memory library
|
|
|
|
|
//----------------------------------------------------
|
|
|
|
|
|
2012-03-10 03:58:42 +00:00
|
|
|
|
public uint mainmemory_readbyte(object lua_addr)
|
2012-01-28 22:11:39 +00:00
|
|
|
|
{
|
2012-03-10 03:58:42 +00:00
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
return MM_R_U8(addr);
|
2012-01-28 22:11:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-03-10 03:58:42 +00:00
|
|
|
|
public void mainmemory_writebyte(object lua_addr, object lua_v)
|
2012-01-28 22:11:39 +00:00
|
|
|
|
{
|
2012-03-10 03:58:42 +00:00
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
uint v = LuaUInt(lua_v);
|
|
|
|
|
MM_W_U8(addr, v);
|
2012-01-28 22:11:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-03-10 03:07:05 +00:00
|
|
|
|
public int mainmemory_read_s8(object lua_addr)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
return (sbyte)MM_R_U8(addr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public uint mainmemory_read_u8(object lua_addr)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
return MM_R_U8(addr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int mainmemory_read_s16_le(object lua_addr)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
return MM_R_S_LE(addr, 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int mainmemory_read_s24_le(object lua_addr)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
return MM_R_S_LE(addr, 3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int mainmemory_read_s32_le(object lua_addr)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
return MM_R_S_LE(addr, 4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public uint mainmemory_read_u16_le(object lua_addr)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
return MM_R_U_LE(addr, 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public uint mainmemory_read_u24_le(object lua_addr)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
return MM_R_U_LE(addr, 3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public uint mainmemory_read_u32_le(object lua_addr)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
return MM_R_U_LE(addr, 4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int mainmemory_read_s16_be(object lua_addr)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
return MM_R_S_BE(addr, 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int mainmemory_read_s24_be(object lua_addr)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
return MM_R_S_BE(addr, 3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int mainmemory_read_s32_be(object lua_addr)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
return MM_R_S_BE(addr, 4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public uint mainmemory_read_u16_be(object lua_addr)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
return MM_R_U_BE(addr, 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public uint mainmemory_read_u24_be(object lua_addr)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
return MM_R_U_BE(addr, 3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public uint mainmemory_read_u32_be(object lua_addr)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
return MM_R_U_BE(addr, 4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void mainmemory_write_s8(object lua_addr, object lua_v)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
int v = LuaInt(lua_v);
|
|
|
|
|
MM_W_U8(addr, (uint)v);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void mainmemory_write_u8(object lua_addr, object lua_v)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
uint v = LuaUInt(lua_v);
|
|
|
|
|
MM_W_U8(addr, v);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void mainmemory_write_s16_le(object lua_addr, object lua_v)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
int v = LuaInt(lua_v);
|
|
|
|
|
MM_W_S_LE(addr, v, 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void mainmemory_write_s24_le(object lua_addr, object lua_v)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
int v = LuaInt(lua_v);
|
|
|
|
|
MM_W_S_LE(addr, v, 3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void mainmemory_write_s32_le(object lua_addr, object lua_v)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
int v = LuaInt(lua_v);
|
|
|
|
|
MM_W_S_LE(addr, v, 4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void mainmemory_write_u16_le(object lua_addr, object lua_v)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
uint v = LuaUInt(lua_v);
|
|
|
|
|
MM_W_U_LE(addr, v, 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void mainmemory_write_u24_le(object lua_addr, object lua_v)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
uint v = LuaUInt(lua_v);
|
|
|
|
|
MM_W_U_LE(addr, v, 3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void mainmemory_write_u32_le(object lua_addr, object lua_v)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
uint v = LuaUInt(lua_v);
|
|
|
|
|
MM_W_U_LE(addr, v, 4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void mainmemory_write_s16_be(object lua_addr, object lua_v)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
int v = LuaInt(lua_v);
|
|
|
|
|
MM_W_S_BE(addr, v, 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void mainmemory_write_s24_be(object lua_addr, object lua_v)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
int v = LuaInt(lua_v);
|
|
|
|
|
MM_W_S_BE(addr, v, 3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void mainmemory_write_s32_be(object lua_addr, object lua_v)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
int v = LuaInt(lua_v);
|
|
|
|
|
MM_W_S_BE(addr, v, 4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void mainmemory_write_u16_be(object lua_addr, object lua_v)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
uint v = LuaUInt(lua_v);
|
|
|
|
|
MM_W_U_BE(addr, v, 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void mainmemory_write_u24_be(object lua_addr, object lua_v)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
uint v = LuaUInt(lua_v);
|
|
|
|
|
MM_W_U_BE(addr, v, 3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void mainmemory_write_u32_be(object lua_addr, object lua_v)
|
|
|
|
|
{
|
|
|
|
|
int addr = LuaInt(lua_addr);
|
|
|
|
|
uint v = LuaUInt(lua_v);
|
|
|
|
|
MM_W_U_BE(addr, v, 4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int MM_R_S_LE(int addr, int size)
|
|
|
|
|
{
|
|
|
|
|
return U2S(MM_R_U_LE(addr, size), size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private uint MM_R_U_LE(int addr, int size)
|
|
|
|
|
{
|
|
|
|
|
uint v = 0;
|
|
|
|
|
for(int i = 0; i < size; ++i)
|
|
|
|
|
v |= MM_R_U8(addr+i) << 8*i;
|
|
|
|
|
return v;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int MM_R_S_BE(int addr, int size)
|
|
|
|
|
{
|
|
|
|
|
return U2S(MM_R_U_BE(addr, size), size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private uint MM_R_U_BE(int addr, int size)
|
|
|
|
|
{
|
|
|
|
|
uint v = 0;
|
|
|
|
|
for(int i = 0; i < size; ++i)
|
|
|
|
|
v |= MM_R_U8(addr+i) << 8*(size-1-i);
|
|
|
|
|
return v;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void MM_W_S_LE(int addr, int v, int size)
|
|
|
|
|
{
|
|
|
|
|
MM_W_U_LE(addr, (uint)v, size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void MM_W_U_LE(int addr, uint v, int size)
|
|
|
|
|
{
|
|
|
|
|
for(int i = 0; i < size; ++i)
|
|
|
|
|
MM_W_U8(addr+i, (v>>(8*i)) & 0xFF);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void MM_W_S_BE(int addr, int v, int size)
|
|
|
|
|
{
|
|
|
|
|
MM_W_U_BE(addr, (uint)v, size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void MM_W_U_BE(int addr, uint v, int size)
|
|
|
|
|
{
|
|
|
|
|
for(int i = 0; i < size; ++i)
|
|
|
|
|
MM_W_U8(addr+i, (v>>(8*(size-1-i))) & 0xFF);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private uint MM_R_U8(int addr)
|
|
|
|
|
{
|
|
|
|
|
return Global.Emulator.MainMemory.PeekByte(addr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void MM_W_U8(int addr, uint v)
|
|
|
|
|
{
|
|
|
|
|
Global.Emulator.MainMemory.PokeByte(addr, (byte)v);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int U2S(uint u, int size)
|
|
|
|
|
{
|
|
|
|
|
int s = (int)u;
|
|
|
|
|
s <<= 8*(4-size);
|
|
|
|
|
s >>= 8*(4-size);
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-21 20:20:06 +00:00
|
|
|
|
//----------------------------------------------------
|
|
|
|
|
//Savestate library
|
|
|
|
|
//----------------------------------------------------
|
2012-02-03 12:18:27 +00:00
|
|
|
|
public void savestate_saveslot(object lua_input)
|
|
|
|
|
{
|
|
|
|
|
int x = 0;
|
|
|
|
|
|
|
|
|
|
try //adelikat: This crap might not be necessary, need to test for a more elegant solution
|
|
|
|
|
{
|
|
|
|
|
x = int.Parse(lua_input.ToString());
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (x < 0 || x > 9)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
Global.MainForm.SaveState("QuickSave" + x.ToString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void savestate_loadslot(object lua_input)
|
|
|
|
|
{
|
|
|
|
|
int x = 0;
|
|
|
|
|
|
|
|
|
|
try //adelikat: This crap might not be necessary, need to test for a more elegant solution
|
|
|
|
|
{
|
|
|
|
|
x = int.Parse(lua_input.ToString());
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (x < 0 || x > 9)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
Global.MainForm.LoadState("QuickLoad" + x.ToString());
|
|
|
|
|
}
|
2011-05-14 01:05:26 +00:00
|
|
|
|
|
2012-01-21 20:20:06 +00:00
|
|
|
|
public void savestate_save(object lua_input)
|
|
|
|
|
{
|
2012-01-22 22:20:09 +00:00
|
|
|
|
if (lua_input.GetType() == typeof(string))
|
|
|
|
|
{
|
2012-03-18 18:24:24 +00:00
|
|
|
|
string path = lua_input.ToString();
|
|
|
|
|
var writer = new StreamWriter(path);
|
|
|
|
|
Global.MainForm.SaveStateFile(writer, path, true);
|
2012-01-22 22:20:09 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void savestate_load(object lua_input)
|
|
|
|
|
{
|
|
|
|
|
if (lua_input.GetType() == typeof(string))
|
|
|
|
|
{
|
|
|
|
|
Global.MainForm.LoadStateFile(lua_input.ToString(), Path.GetFileName(lua_input.ToString()));
|
|
|
|
|
}
|
2011-06-26 02:09:06 +00:00
|
|
|
|
}
|
2012-01-21 20:05:53 +00:00
|
|
|
|
|
2012-01-21 20:20:06 +00:00
|
|
|
|
//----------------------------------------------------
|
|
|
|
|
//Movie library
|
|
|
|
|
//----------------------------------------------------
|
2012-01-21 20:05:53 +00:00
|
|
|
|
public string movie_mode()
|
|
|
|
|
{
|
|
|
|
|
return Global.MovieSession.Movie.Mode.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-26 02:09:06 +00:00
|
|
|
|
public string movie_rerecordcount()
|
|
|
|
|
{
|
2012-01-21 20:05:53 +00:00
|
|
|
|
return Global.MovieSession.Movie.Rerecords.ToString();
|
2011-06-26 02:09:06 +00:00
|
|
|
|
}
|
2012-03-18 19:33:38 +00:00
|
|
|
|
|
2011-06-26 02:09:06 +00:00
|
|
|
|
public void movie_stop()
|
|
|
|
|
{
|
2012-01-21 20:05:53 +00:00
|
|
|
|
Global.MovieSession.Movie.StopMovie();
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-18 19:33:38 +00:00
|
|
|
|
public bool movie_isloaded()
|
|
|
|
|
{
|
|
|
|
|
if (Global.MovieSession.Movie.Mode == MOVIEMODE.INACTIVE)
|
|
|
|
|
return false;
|
|
|
|
|
else
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int movie_length()
|
|
|
|
|
{
|
|
|
|
|
return Global.MovieSession.Movie.Length();
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-18 19:52:28 +00:00
|
|
|
|
public string movie_filename()
|
|
|
|
|
{
|
|
|
|
|
return Global.MovieSession.Movie.Filename;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool movie_getreadonly()
|
|
|
|
|
{
|
|
|
|
|
return Global.MainForm.ReadOnly;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void movie_setreadonly(object lua_input)
|
|
|
|
|
{
|
|
|
|
|
int x = 0;
|
|
|
|
|
x++;
|
|
|
|
|
int y = x;
|
|
|
|
|
|
|
|
|
|
if (lua_input.ToString().ToUpper() == "TRUE" || lua_input.ToString() == "1")
|
|
|
|
|
Global.MainForm.SetReadOnly(true);
|
|
|
|
|
else
|
|
|
|
|
Global.MainForm.SetReadOnly(false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-21 20:20:06 +00:00
|
|
|
|
//----------------------------------------------------
|
|
|
|
|
//Joypad library
|
|
|
|
|
//----------------------------------------------------
|
|
|
|
|
|
2012-03-19 03:39:56 +00:00
|
|
|
|
public ControllerDefinition Type { get; set; }
|
|
|
|
|
string ControlType { get { return Type.Name; } }
|
|
|
|
|
|
2012-01-22 22:42:40 +00:00
|
|
|
|
//Currently sends all controllers, needs to control which ones it sends
|
|
|
|
|
public string joypad_get(object lua_input)
|
2012-01-21 20:05:53 +00:00
|
|
|
|
{
|
2012-01-22 22:42:40 +00:00
|
|
|
|
return Global.GetOutputControllersAsMnemonic();
|
2012-01-21 20:20:06 +00:00
|
|
|
|
}
|
2012-01-28 21:43:55 +00:00
|
|
|
|
|
2012-03-19 03:39:56 +00:00
|
|
|
|
public void joypad_set(object button, object value)
|
2012-01-21 20:20:06 +00:00
|
|
|
|
{
|
2012-03-19 03:39:56 +00:00
|
|
|
|
if (button.GetType() != typeof(string) || value.GetType() != typeof(bool))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(
|
|
|
|
|
"Invalid parameter types " + button.GetType().ToString() + ", " + button.GetType().ToString() + "."
|
|
|
|
|
);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Global.RenderPanel.AddMessage("Button: " + button + ", Value: " + value.ToString());
|
2011-06-26 02:09:06 +00:00
|
|
|
|
}
|
2012-01-22 22:20:09 +00:00
|
|
|
|
|
|
|
|
|
//----------------------------------------------------
|
|
|
|
|
//Client library
|
|
|
|
|
//----------------------------------------------------
|
2012-01-22 22:42:40 +00:00
|
|
|
|
public void client_openrom(object lua_input)
|
|
|
|
|
{
|
|
|
|
|
Global.MainForm.LoadRom(lua_input.ToString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void client_closerom()
|
|
|
|
|
{
|
|
|
|
|
Global.MainForm.CloseROM();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void client_opentoolbox()
|
|
|
|
|
{
|
|
|
|
|
Global.MainForm.LoadToolBox();
|
|
|
|
|
}
|
2012-01-22 22:20:09 +00:00
|
|
|
|
|
|
|
|
|
public void client_openramwatch()
|
|
|
|
|
{
|
|
|
|
|
Global.MainForm.LoadRamWatch();
|
|
|
|
|
}
|
2012-01-22 22:42:40 +00:00
|
|
|
|
|
|
|
|
|
public void client_openramsearch()
|
|
|
|
|
{
|
|
|
|
|
Global.MainForm.LoadRamSearch();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void client_openrampoke()
|
|
|
|
|
{
|
|
|
|
|
Global.MainForm.LoadRamPoke();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void client_openhexeditor()
|
|
|
|
|
{
|
|
|
|
|
Global.MainForm.LoadHexEditor();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void client_opentasstudio()
|
|
|
|
|
{
|
|
|
|
|
Global.MainForm.LoadTAStudio();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void client_opencheats()
|
|
|
|
|
{
|
|
|
|
|
Global.MainForm.LoadCheatsWindow();
|
|
|
|
|
}
|
2011-06-26 02:09:06 +00:00
|
|
|
|
}
|
2011-02-20 19:18:27 +00:00
|
|
|
|
}
|