2011-02-20 19:18:27 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using LuaInterface;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using BizHawk.MultiClient.tools;
|
|
|
|
|
|
|
|
|
|
namespace BizHawk.MultiClient
|
|
|
|
|
{
|
2011-06-26 02:09:06 +00:00
|
|
|
|
class LuaImplementation
|
|
|
|
|
{
|
|
|
|
|
Lua lua = new Lua();
|
|
|
|
|
LuaConsole Caller;
|
2012-01-21 20:05:53 +00:00
|
|
|
|
|
|
|
|
|
public LuaImplementation(LuaConsole passed)
|
|
|
|
|
{
|
|
|
|
|
Caller = passed.get();
|
|
|
|
|
lua.RegisterFunction("print", this, this.GetType().GetMethod("print"));
|
|
|
|
|
|
|
|
|
|
//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]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lua.NewTable("emu");
|
|
|
|
|
for (int i = 0; i < EmuFunctions.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
lua.RegisterFunction("emu." + EmuFunctions[i], this, this.GetType().GetMethod("emu_" + EmuFunctions[i]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lua.NewTable("memory");
|
|
|
|
|
for (int i = 0; i < MemoryFunctions.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
lua.RegisterFunction("memory." + MemoryFunctions[i], this, this.GetType().GetMethod("memory_" + MemoryFunctions[i]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lua.NewTable("savestate");
|
|
|
|
|
for (int i = 0; i < SaveStateFunctions.Length; i++)
|
|
|
|
|
{
|
2012-01-21 20:20:06 +00:00
|
|
|
|
//lua.RegisterFunction("statestate." + SaveStateFunctions[i], this, this.GetType().GetMethod("savestate_" + SaveStateFunctions[i]));
|
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]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lua.NewTable("joypad");
|
|
|
|
|
for (int i = 0; i < JoypadFunctions.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
lua.RegisterFunction("joypad." + MemoryFunctions[i], this, this.GetType().GetMethod("joypad_" + JoypadFunctions[i]));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-21 20:20:06 +00:00
|
|
|
|
public void DoLuaFile(string File)
|
|
|
|
|
{
|
|
|
|
|
lua.DoFile(File);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void print(string s)
|
|
|
|
|
{
|
|
|
|
|
Caller.AddText(string.Format(s));
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-21 20:05:53 +00:00
|
|
|
|
/****************************************************/
|
|
|
|
|
/*************library definitions********************/
|
|
|
|
|
/****************************************************/
|
|
|
|
|
public static string[] ConsoleFunctions = new string[] {
|
|
|
|
|
"output"
|
|
|
|
|
};
|
|
|
|
|
|
2011-06-26 02:09:06 +00:00
|
|
|
|
public static string[] EmuFunctions = new string[] {
|
2012-01-21 20:20:06 +00:00
|
|
|
|
//"frameadvance",
|
2011-06-26 02:09:06 +00:00
|
|
|
|
"pause",
|
|
|
|
|
"unpause",
|
2012-01-21 20:20:06 +00:00
|
|
|
|
"togglepause",
|
|
|
|
|
//"speedmode",
|
|
|
|
|
//"framecount",
|
|
|
|
|
//"lagcount",
|
|
|
|
|
//"islagged",
|
|
|
|
|
//"registerbefore",
|
|
|
|
|
//"registerafter",
|
|
|
|
|
//"register"
|
2011-06-26 02:09:06 +00:00
|
|
|
|
};
|
|
|
|
|
public static string[] MemoryFunctions = new string[] {
|
|
|
|
|
"readbyte",
|
|
|
|
|
//"readbytesigned",
|
|
|
|
|
//"readword",
|
|
|
|
|
//"readwordsigned",
|
|
|
|
|
//"readdword",
|
|
|
|
|
//"readdwordsigned",
|
|
|
|
|
//"readbyterange",
|
|
|
|
|
//"writebyte",
|
|
|
|
|
//"writeword",
|
|
|
|
|
//"writedword",
|
|
|
|
|
//"registerwrite",
|
|
|
|
|
//"registerread",
|
|
|
|
|
};
|
|
|
|
|
public static string[] SaveStateFunctions = new string[] {
|
2012-01-21 20:20:06 +00:00
|
|
|
|
//"create",
|
2011-06-26 02:09:06 +00:00
|
|
|
|
"save",
|
2012-01-21 20:20:06 +00:00
|
|
|
|
//"load",
|
|
|
|
|
//"write"
|
2011-06-26 02:09:06 +00:00
|
|
|
|
};
|
|
|
|
|
public static string[] MovieFunctions = new string[] {
|
|
|
|
|
"mode",
|
|
|
|
|
"rerecordcount",
|
|
|
|
|
"stop"
|
|
|
|
|
};
|
|
|
|
|
public static string[] JoypadFunctions = new string[] {
|
|
|
|
|
"set",
|
|
|
|
|
//"get",
|
|
|
|
|
};
|
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
|
|
|
|
|
|
|
|
|
//----------------------------------------------------
|
|
|
|
|
//Emu library
|
|
|
|
|
//----------------------------------------------------
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
//----------------------------------------------------
|
|
|
|
|
//Memory library
|
|
|
|
|
//----------------------------------------------------
|
|
|
|
|
|
2011-06-26 02:09:06 +00:00
|
|
|
|
public string memory_readbyte(object lua_input)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
byte x;
|
|
|
|
|
if (lua_input.GetType() == typeof(string))
|
|
|
|
|
{
|
|
|
|
|
x = Global.Emulator.MainMemory.PeekByte(int.Parse((string)lua_input));
|
|
|
|
|
return x.ToString();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
double y = (double)lua_input;
|
|
|
|
|
x = Global.Emulator.MainMemory.PeekByte(Convert.ToInt32(y));
|
|
|
|
|
return x.ToString();
|
2011-02-20 23:41:51 +00:00
|
|
|
|
}
|
2011-05-07 01:06:01 +00:00
|
|
|
|
|
2011-06-26 02:09:06 +00:00
|
|
|
|
}
|
2012-01-21 20:20:06 +00:00
|
|
|
|
|
2011-06-26 02:09:06 +00:00
|
|
|
|
public void memory_writebyte(object lua_input)
|
|
|
|
|
{
|
|
|
|
|
Global.Emulator.MainMemory.PokeByte((int)lua_input, (byte)lua_input);
|
|
|
|
|
}
|
2011-05-14 01:05:26 +00:00
|
|
|
|
|
2012-01-21 20:20:06 +00:00
|
|
|
|
//----------------------------------------------------
|
|
|
|
|
//Savestate library
|
|
|
|
|
//----------------------------------------------------
|
2011-05-14 01:05:26 +00:00
|
|
|
|
|
2012-01-21 20:20:06 +00:00
|
|
|
|
public void savestate_save(object lua_input)
|
|
|
|
|
{
|
|
|
|
|
//
|
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
|
|
|
|
}
|
|
|
|
|
public void movie_stop()
|
|
|
|
|
{
|
2012-01-21 20:05:53 +00:00
|
|
|
|
Global.MovieSession.Movie.StopMovie();
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-21 20:20:06 +00:00
|
|
|
|
//----------------------------------------------------
|
|
|
|
|
//Joypad library
|
|
|
|
|
//----------------------------------------------------
|
|
|
|
|
|
|
|
|
|
public void joypad_get(object lua_input)
|
2012-01-21 20:05:53 +00:00
|
|
|
|
{
|
2012-01-21 20:20:06 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void joypad_set(object lua_input)
|
|
|
|
|
{
|
|
|
|
|
|
2011-06-26 02:09:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2011-02-20 19:18:27 +00:00
|
|
|
|
}
|