2013-10-28 20:57:25 +00:00
|
|
|
|
using System.Linq;
|
2013-10-28 19:13:01 +00:00
|
|
|
|
using BizHawk.Client.Common;
|
|
|
|
|
using BizHawk.Emulation.Consoles.Nintendo;
|
|
|
|
|
|
|
|
|
|
namespace BizHawk.MultiClient
|
|
|
|
|
{
|
2013-10-31 00:31:25 +00:00
|
|
|
|
public class NESLuaLibrary : LuaLibraryBase
|
2013-10-28 19:13:01 +00:00
|
|
|
|
{
|
2013-10-31 00:31:25 +00:00
|
|
|
|
public override string Name { get { return "nes"; } }
|
|
|
|
|
public override string[] Functions
|
2013-10-29 16:03:06 +00:00
|
|
|
|
{
|
2013-10-31 00:31:25 +00:00
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return new[]
|
|
|
|
|
{
|
|
|
|
|
"addgamegenie",
|
|
|
|
|
"getallowmorethaneightsprites",
|
|
|
|
|
"getbottomscanline",
|
|
|
|
|
"getclipleftandright",
|
|
|
|
|
"getdispbackground",
|
|
|
|
|
"getdispsprites",
|
|
|
|
|
"gettopscanline",
|
|
|
|
|
"removegamegenie",
|
|
|
|
|
"setallowmorethaneightsprites",
|
|
|
|
|
"setclipleftandright",
|
|
|
|
|
"setdispbackground",
|
|
|
|
|
"setdispsprites",
|
2013-11-02 01:48:35 +00:00
|
|
|
|
"setscanlines"
|
2013-10-31 00:31:25 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-10-29 16:03:06 +00:00
|
|
|
|
|
|
|
|
|
public static void nes_addgamegenie(string code)
|
2013-10-28 19:13:01 +00:00
|
|
|
|
{
|
|
|
|
|
if (Global.Emulator is NES)
|
|
|
|
|
{
|
2013-11-02 01:48:35 +00:00
|
|
|
|
var decoder = new NESGameGenieDecoder(code);
|
|
|
|
|
Watch watch = Watch.GenerateWatch(
|
|
|
|
|
Global.Emulator.MemoryDomains[1],
|
|
|
|
|
decoder.Address,
|
|
|
|
|
Watch.WatchSize.Byte,
|
|
|
|
|
Watch.DisplayType.Hex,
|
|
|
|
|
code,
|
|
|
|
|
false
|
|
|
|
|
);
|
|
|
|
|
Global.CheatList.Add(new Cheat(
|
|
|
|
|
watch,
|
|
|
|
|
decoder.Value,
|
|
|
|
|
decoder.Compare
|
|
|
|
|
));
|
2013-10-28 19:13:01 +00:00
|
|
|
|
ToolHelpers.UpdateCheatRelatedTools();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-29 16:03:06 +00:00
|
|
|
|
public static bool nes_getallowmorethaneightsprites()
|
2013-10-28 19:13:01 +00:00
|
|
|
|
{
|
|
|
|
|
return Global.Config.NESAllowMoreThanEightSprites;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-29 16:03:06 +00:00
|
|
|
|
public static int nes_getbottomscanline(bool pal = false)
|
2013-10-28 19:13:01 +00:00
|
|
|
|
{
|
|
|
|
|
if (pal)
|
|
|
|
|
{
|
|
|
|
|
return Global.Config.PAL_NESBottomLine;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return Global.Config.NTSC_NESBottomLine;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-29 16:03:06 +00:00
|
|
|
|
public static bool nes_getclipleftandright()
|
2013-10-28 19:13:01 +00:00
|
|
|
|
{
|
|
|
|
|
return Global.Config.NESClipLeftAndRight;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-29 16:03:06 +00:00
|
|
|
|
public static bool nes_getdispbackground()
|
2013-10-28 19:13:01 +00:00
|
|
|
|
{
|
|
|
|
|
return Global.Config.NESDispBackground;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-29 16:03:06 +00:00
|
|
|
|
public static bool nes_getdispsprites()
|
2013-10-28 19:13:01 +00:00
|
|
|
|
{
|
|
|
|
|
return Global.Config.NESDispSprites;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-29 16:03:06 +00:00
|
|
|
|
public static int nes_gettopscanline(bool pal = false)
|
2013-10-28 19:13:01 +00:00
|
|
|
|
{
|
|
|
|
|
if (pal)
|
|
|
|
|
{
|
|
|
|
|
return Global.Config.PAL_NESTopLine;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return Global.Config.NTSC_NESTopLine;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-29 16:03:06 +00:00
|
|
|
|
public static void nes_removegamegenie(string code)
|
2013-10-28 19:13:01 +00:00
|
|
|
|
{
|
|
|
|
|
if (Global.Emulator is NES)
|
|
|
|
|
{
|
2013-11-02 01:48:35 +00:00
|
|
|
|
var decoder = new NESGameGenieDecoder(code);
|
|
|
|
|
Global.CheatList.RemoveRange(
|
|
|
|
|
Global.CheatList.Where(x => x.Address == decoder.Address)
|
|
|
|
|
);
|
2013-10-28 19:13:01 +00:00
|
|
|
|
ToolHelpers.UpdateCheatRelatedTools();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-29 16:03:06 +00:00
|
|
|
|
public static void nes_setallowmorethaneightsprites(bool allow)
|
2013-10-28 19:13:01 +00:00
|
|
|
|
{
|
|
|
|
|
Global.Config.NESAllowMoreThanEightSprites = allow;
|
|
|
|
|
if (Global.Emulator is NES)
|
|
|
|
|
{
|
|
|
|
|
(Global.Emulator as NES).CoreComm.NES_UnlimitedSprites = allow;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-29 16:03:06 +00:00
|
|
|
|
public static void nes_setclipleftandright(bool leftandright)
|
2013-10-28 19:13:01 +00:00
|
|
|
|
{
|
|
|
|
|
Global.Config.NESClipLeftAndRight = leftandright;
|
|
|
|
|
if (Global.Emulator is NES)
|
|
|
|
|
{
|
|
|
|
|
(Global.Emulator as NES).SetClipLeftAndRight(leftandright);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-29 16:03:06 +00:00
|
|
|
|
public static void nes_setdispbackground(bool show)
|
2013-10-28 19:13:01 +00:00
|
|
|
|
{
|
|
|
|
|
Global.Config.NESDispBackground = show;
|
2013-11-01 23:17:30 +00:00
|
|
|
|
CoreFileProvider.SyncCoreCommInputSignals();
|
2013-10-28 19:13:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-10-29 16:03:06 +00:00
|
|
|
|
public static void nes_setdispsprites(bool show)
|
2013-10-28 19:13:01 +00:00
|
|
|
|
{
|
|
|
|
|
Global.Config.NESDispSprites = show;
|
2013-11-01 23:17:30 +00:00
|
|
|
|
CoreFileProvider.SyncCoreCommInputSignals();
|
2013-10-28 19:13:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-10-29 16:03:06 +00:00
|
|
|
|
public static void nes_setscanlines(object top, object bottom, bool pal = false)
|
2013-10-28 19:13:01 +00:00
|
|
|
|
{
|
|
|
|
|
|
2013-10-31 00:31:25 +00:00
|
|
|
|
int first = LuaInt(top);
|
|
|
|
|
int last = LuaInt(bottom);
|
2013-10-28 19:13:01 +00:00
|
|
|
|
if (first > 127)
|
|
|
|
|
{
|
|
|
|
|
first = 127;
|
|
|
|
|
}
|
|
|
|
|
else if (first < 0)
|
|
|
|
|
{
|
|
|
|
|
first = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (last > 239)
|
|
|
|
|
{
|
|
|
|
|
last = 239;
|
|
|
|
|
}
|
|
|
|
|
else if (last < 128)
|
|
|
|
|
{
|
|
|
|
|
last = 128;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pal)
|
|
|
|
|
{
|
|
|
|
|
Global.Config.PAL_NESTopLine = first;
|
|
|
|
|
Global.Config.PAL_NESBottomLine = last;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Global.Config.NTSC_NESTopLine = first;
|
|
|
|
|
Global.Config.NTSC_NESBottomLine = last;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Global.Emulator is NES)
|
|
|
|
|
{
|
|
|
|
|
if (pal)
|
|
|
|
|
{
|
|
|
|
|
(Global.Emulator as NES).PAL_FirstDrawLine = first;
|
|
|
|
|
(Global.Emulator as NES).PAL_LastDrawLine = last;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
(Global.Emulator as NES).NTSC_FirstDrawLine = first;
|
|
|
|
|
(Global.Emulator as NES).NTSC_LastDrawLine = last;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|