Partially migrate NesLuaLibrary to ApiHawk delegation
nes.setdispbackground and nes.setscanlines now throw when the core is neither NesHawk or QuickNES (the latter is still silently ignored by these functions)
This commit is contained in:
parent
29ac251f34
commit
08d0f462fc
|
@ -13,38 +13,36 @@ using BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES;
|
||||||
namespace BizHawk.Client.Common
|
namespace BizHawk.Client.Common
|
||||||
{
|
{
|
||||||
[Description("Functions related specifically to Nes Cores")]
|
[Description("Functions related specifically to Nes Cores")]
|
||||||
public sealed class NesLuaLibrary : LuaLibraryBase
|
public sealed class NesLuaLibrary : DelegatingLuaLibrary
|
||||||
{
|
{
|
||||||
// TODO:
|
// TODO:
|
||||||
// perhaps with the new core config system, one could
|
// perhaps with the new core config system, one could
|
||||||
// automatically bring out all of the settings to a lua table, with names. that
|
// automatically bring out all of the settings to a lua table, with names. that
|
||||||
// would be completely arbitrary and would remove the whole requirement for this mess
|
// would be completely arbitrary and would remove the whole requirement for this mess
|
||||||
public NesLuaLibrary(Lua lua)
|
|
||||||
: base(lua) { }
|
|
||||||
|
|
||||||
[OptionalService]
|
|
||||||
private NES Neshawk { get; set; }
|
|
||||||
|
|
||||||
[OptionalService]
|
|
||||||
private QuickNES Quicknes { get; set; }
|
|
||||||
|
|
||||||
[OptionalService]
|
[OptionalService]
|
||||||
private IMemoryDomains MemoryDomains { get; set; }
|
private IMemoryDomains MemoryDomains { get; set; }
|
||||||
|
|
||||||
private bool NESAvailable => Neshawk != null || Quicknes != null;
|
public NesLuaLibrary(Lua lua)
|
||||||
|
: base(lua) { }
|
||||||
private bool HasMemoryDomains => MemoryDomains != null;
|
|
||||||
|
|
||||||
public NesLuaLibrary(Lua lua, Action<string> logOutputCallback)
|
public NesLuaLibrary(Lua lua, Action<string> logOutputCallback)
|
||||||
: base(lua, logOutputCallback) { }
|
: base(lua, logOutputCallback) { }
|
||||||
|
|
||||||
public override string Name => "nes";
|
public override string Name => "nes";
|
||||||
|
|
||||||
|
private bool NESAvailable => APIs.Emu.GetSystemId() == "NES";
|
||||||
|
|
||||||
|
private object Settings
|
||||||
|
{
|
||||||
|
get => APIs.Emu.GetSettings();
|
||||||
|
set => APIs.Emu.PutSettings(value);
|
||||||
|
}
|
||||||
|
|
||||||
[LuaMethodExample("nes.addgamegenie( \"GXXZZLVI\" );")]
|
[LuaMethodExample("nes.addgamegenie( \"GXXZZLVI\" );")]
|
||||||
[LuaMethod("addgamegenie", "Adds the specified game genie code. If an NES game is not currently loaded or the code is not a valid game genie code, this will have no effect")]
|
[LuaMethod("addgamegenie", "Adds the specified game genie code. If an NES game is not currently loaded or the code is not a valid game genie code, this will have no effect")]
|
||||||
public void AddGameGenie(string code)
|
public void AddGameGenie(string code)
|
||||||
{
|
{
|
||||||
if (NESAvailable && HasMemoryDomains)
|
if (NESAvailable && MemoryDomains != null)
|
||||||
{
|
{
|
||||||
var decoder = new NESGameGenieDecoder(code);
|
var decoder = new NESGameGenieDecoder(code);
|
||||||
var watch = Watch.GenerateWatch(
|
var watch = Watch.GenerateWatch(
|
||||||
|
@ -64,109 +62,57 @@ namespace BizHawk.Client.Common
|
||||||
|
|
||||||
[LuaMethodExample("if ( nes.getallowmorethaneightsprites( ) ) then\r\n\tconsole.log( \"Gets the NES setting 'Allow more than 8 sprites per scanline' value\" );\r\nend;")]
|
[LuaMethodExample("if ( nes.getallowmorethaneightsprites( ) ) then\r\n\tconsole.log( \"Gets the NES setting 'Allow more than 8 sprites per scanline' value\" );\r\nend;")]
|
||||||
[LuaMethod("getallowmorethaneightsprites", "Gets the NES setting 'Allow more than 8 sprites per scanline' value")]
|
[LuaMethod("getallowmorethaneightsprites", "Gets the NES setting 'Allow more than 8 sprites per scanline' value")]
|
||||||
public bool GetAllowMoreThanEightSprites()
|
public bool GetAllowMoreThanEightSprites() => Settings switch
|
||||||
{
|
{
|
||||||
if (Quicknes != null)
|
NES.NESSettings nhs => nhs.AllowMoreThanEightSprites,
|
||||||
{
|
QuickNES.QuickNESSettings qns => qns.NumSprites != 8,
|
||||||
return Quicknes.GetSettings().NumSprites != 8;
|
_ => throw new InvalidOperationException()
|
||||||
}
|
};
|
||||||
|
|
||||||
if (Neshawk != null)
|
|
||||||
{
|
|
||||||
return Neshawk.GetSettings().AllowMoreThanEightSprites;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new InvalidOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
[LuaMethodExample("local innesget = nes.getbottomscanline( false );")]
|
[LuaMethodExample("local innesget = nes.getbottomscanline( false );")]
|
||||||
[LuaMethod("getbottomscanline", "Gets the current value for the bottom scanline value")]
|
[LuaMethod("getbottomscanline", "Gets the current value for the bottom scanline value")]
|
||||||
public int GetBottomScanline(bool pal = false)
|
public int GetBottomScanline(bool pal = false) => Settings switch
|
||||||
{
|
{
|
||||||
if (Quicknes != null)
|
NES.NESSettings nhs => pal ? nhs.PAL_BottomLine : nhs.NTSC_BottomLine,
|
||||||
{
|
QuickNES.QuickNESSettings qns => qns.ClipTopAndBottom ? 231 : 239,
|
||||||
return Quicknes.GetSettings().ClipTopAndBottom ? 231 : 239;
|
_ => throw new InvalidOperationException()
|
||||||
}
|
};
|
||||||
|
|
||||||
if (Neshawk != null)
|
|
||||||
{
|
|
||||||
return pal
|
|
||||||
? Neshawk.GetSettings().PAL_BottomLine
|
|
||||||
: Neshawk.GetSettings().NTSC_BottomLine;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new InvalidOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
[LuaMethodExample("if ( nes.getclipleftandright( ) ) then\r\n\tconsole.log( \"Gets the current value for the Clip Left and Right sides option\" );\r\nend;")]
|
[LuaMethodExample("if ( nes.getclipleftandright( ) ) then\r\n\tconsole.log( \"Gets the current value for the Clip Left and Right sides option\" );\r\nend;")]
|
||||||
[LuaMethod("getclipleftandright", "Gets the current value for the Clip Left and Right sides option")]
|
[LuaMethod("getclipleftandright", "Gets the current value for the Clip Left and Right sides option")]
|
||||||
public bool GetClipLeftAndRight()
|
public bool GetClipLeftAndRight() => Settings switch
|
||||||
{
|
{
|
||||||
if (Quicknes != null)
|
NES.NESSettings nhs => nhs.ClipLeftAndRight,
|
||||||
{
|
QuickNES.QuickNESSettings qns => qns.ClipLeftAndRight,
|
||||||
return Quicknes.GetSettings().ClipLeftAndRight;
|
_ => throw new InvalidOperationException()
|
||||||
}
|
};
|
||||||
|
|
||||||
if (Neshawk != null)
|
|
||||||
{
|
|
||||||
return Neshawk.GetSettings().ClipLeftAndRight;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new InvalidOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
[LuaMethodExample("if ( nes.getdispbackground( ) ) then\r\n\tconsole.log( \"Indicates whether or not the bg layer is being displayed\" );\r\nend;")]
|
[LuaMethodExample("if ( nes.getdispbackground( ) ) then\r\n\tconsole.log( \"Indicates whether or not the bg layer is being displayed\" );\r\nend;")]
|
||||||
[LuaMethod("getdispbackground", "Indicates whether or not the bg layer is being displayed")]
|
[LuaMethod("getdispbackground", "Indicates whether or not the bg layer is being displayed")]
|
||||||
public bool GetDisplayBackground()
|
public bool GetDisplayBackground() => Settings switch
|
||||||
{
|
{
|
||||||
if (Quicknes != null)
|
NES.NESSettings nhs => nhs.DispBackground,
|
||||||
{
|
QuickNES.QuickNESSettings _ => true,
|
||||||
return true;
|
_ => throw new InvalidOperationException()
|
||||||
}
|
};
|
||||||
|
|
||||||
if (Neshawk != null)
|
|
||||||
{
|
|
||||||
return Neshawk.GetSettings().DispBackground;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new InvalidOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
[LuaMethodExample("if ( nes.getdispsprites( ) ) then\r\n\tconsole.log( \"Indicates whether or not sprites are being displayed\" );\r\nend;")]
|
[LuaMethodExample("if ( nes.getdispsprites( ) ) then\r\n\tconsole.log( \"Indicates whether or not sprites are being displayed\" );\r\nend;")]
|
||||||
[LuaMethod("getdispsprites", "Indicates whether or not sprites are being displayed")]
|
[LuaMethod("getdispsprites", "Indicates whether or not sprites are being displayed")]
|
||||||
public bool GetDisplaySprites()
|
public bool GetDisplaySprites() => Settings switch
|
||||||
{
|
{
|
||||||
if (Quicknes != null)
|
NES.NESSettings nhs => nhs.DispSprites,
|
||||||
{
|
QuickNES.QuickNESSettings qns => qns.NumSprites > 0,
|
||||||
return Quicknes.GetSettings().NumSprites > 0;
|
_ => throw new InvalidOperationException()
|
||||||
}
|
};
|
||||||
|
|
||||||
if (Neshawk != null)
|
|
||||||
{
|
|
||||||
return Neshawk.GetSettings().DispSprites;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new InvalidOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
[LuaMethodExample("local innesget = nes.gettopscanline(false);")]
|
[LuaMethodExample("local innesget = nes.gettopscanline(false);")]
|
||||||
[LuaMethod("gettopscanline", "Gets the current value for the top scanline value")]
|
[LuaMethod("gettopscanline", "Gets the current value for the top scanline value")]
|
||||||
public int GetTopScanline(bool pal = false)
|
public int GetTopScanline(bool pal = false) => Settings switch
|
||||||
{
|
{
|
||||||
if (Quicknes != null)
|
NES.NESSettings nhs => pal ? nhs.PAL_TopLine : nhs.NTSC_TopLine,
|
||||||
{
|
QuickNES.QuickNESSettings qns => qns.ClipTopAndBottom ? 8 : 0,
|
||||||
return Quicknes.GetSettings().ClipTopAndBottom ? 8 : 0;
|
_ => throw new InvalidOperationException()
|
||||||
}
|
};
|
||||||
|
|
||||||
if (Neshawk != null)
|
|
||||||
{
|
|
||||||
return pal
|
|
||||||
? Neshawk.GetSettings().PAL_TopLine
|
|
||||||
: Neshawk.GetSettings().NTSC_TopLine;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new InvalidOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
[LuaMethodExample("nes.removegamegenie( \"GXXZZLVI\" );")]
|
[LuaMethodExample("nes.removegamegenie( \"GXXZZLVI\" );")]
|
||||||
[LuaMethod("removegamegenie", "Removes the specified game genie code. If an NES game is not currently loaded or the code is not a valid game genie code, this will have no effect")]
|
[LuaMethod("removegamegenie", "Removes the specified game genie code. If an NES game is not currently loaded or the code is not a valid game genie code, this will have no effect")]
|
||||||
|
@ -184,17 +130,18 @@ namespace BizHawk.Client.Common
|
||||||
[LuaMethod("setallowmorethaneightsprites", "Sets the NES setting 'Allow more than 8 sprites per scanline'")]
|
[LuaMethod("setallowmorethaneightsprites", "Sets the NES setting 'Allow more than 8 sprites per scanline'")]
|
||||||
public void SetAllowMoreThanEightSprites(bool allow)
|
public void SetAllowMoreThanEightSprites(bool allow)
|
||||||
{
|
{
|
||||||
if (Neshawk != null)
|
switch (Settings)
|
||||||
{
|
{
|
||||||
var s = Neshawk.GetSettings();
|
case NES.NESSettings nhs:
|
||||||
s.AllowMoreThanEightSprites = allow;
|
nhs.AllowMoreThanEightSprites = allow;
|
||||||
Neshawk.PutSettings(s);
|
Settings = nhs;
|
||||||
}
|
break;
|
||||||
else if (Quicknes != null)
|
case QuickNES.QuickNESSettings qns:
|
||||||
{
|
qns.NumSprites = allow ? 64 : 8;
|
||||||
var s = Quicknes.GetSettings();
|
Settings = qns;
|
||||||
s.NumSprites = allow ? 64 : 8;
|
break;
|
||||||
Quicknes.PutSettings(s);
|
default:
|
||||||
|
throw new InvalidOperationException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,17 +149,18 @@ namespace BizHawk.Client.Common
|
||||||
[LuaMethod("setclipleftandright", "Sets the Clip Left and Right sides option")]
|
[LuaMethod("setclipleftandright", "Sets the Clip Left and Right sides option")]
|
||||||
public void SetClipLeftAndRight(bool leftandright)
|
public void SetClipLeftAndRight(bool leftandright)
|
||||||
{
|
{
|
||||||
if (Neshawk != null)
|
switch (Settings)
|
||||||
{
|
{
|
||||||
var s = Neshawk.GetSettings();
|
case NES.NESSettings nhs:
|
||||||
s.ClipLeftAndRight = leftandright;
|
nhs.ClipLeftAndRight = leftandright;
|
||||||
Neshawk.PutSettings(s);
|
Settings = nhs;
|
||||||
}
|
break;
|
||||||
else if (Quicknes != null)
|
case QuickNES.QuickNESSettings qns:
|
||||||
{
|
qns.ClipLeftAndRight = leftandright;
|
||||||
var s = Quicknes.GetSettings();
|
Settings = qns;
|
||||||
s.ClipLeftAndRight = leftandright;
|
break;
|
||||||
Quicknes.PutSettings(s);
|
default:
|
||||||
|
throw new InvalidOperationException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -220,11 +168,16 @@ namespace BizHawk.Client.Common
|
||||||
[LuaMethod("setdispbackground", "Sets whether or not the background layer will be displayed")]
|
[LuaMethod("setdispbackground", "Sets whether or not the background layer will be displayed")]
|
||||||
public void SetDisplayBackground(bool show)
|
public void SetDisplayBackground(bool show)
|
||||||
{
|
{
|
||||||
if (Neshawk != null)
|
switch (Settings)
|
||||||
{
|
{
|
||||||
var s = Neshawk.GetSettings();
|
case NES.NESSettings nhs:
|
||||||
s.DispBackground = show;
|
nhs.DispBackground = show;
|
||||||
Neshawk.PutSettings(s);
|
Settings = nhs;
|
||||||
|
break;
|
||||||
|
case QuickNES.QuickNESSettings _:
|
||||||
|
return;
|
||||||
|
default:
|
||||||
|
throw new InvalidOperationException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,17 +185,18 @@ namespace BizHawk.Client.Common
|
||||||
[LuaMethod("setdispsprites", "Sets whether or not sprites will be displayed")]
|
[LuaMethod("setdispsprites", "Sets whether or not sprites will be displayed")]
|
||||||
public void SetDisplaySprites(bool show)
|
public void SetDisplaySprites(bool show)
|
||||||
{
|
{
|
||||||
if (Neshawk != null)
|
switch (Settings)
|
||||||
{
|
{
|
||||||
var s = Neshawk.GetSettings();
|
case NES.NESSettings nhs:
|
||||||
s.DispSprites = show;
|
nhs.DispSprites = show;
|
||||||
Neshawk.PutSettings(s);
|
Settings = nhs;
|
||||||
}
|
break;
|
||||||
else if (Quicknes != null)
|
case QuickNES.QuickNESSettings qns:
|
||||||
{
|
qns.NumSprites = show ? 8 : 0;
|
||||||
var s = Quicknes.GetSettings();
|
Settings = qns;
|
||||||
s.NumSprites = show ? 8 : 0;
|
break;
|
||||||
Quicknes.PutSettings(s);
|
default:
|
||||||
|
throw new InvalidOperationException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,40 +204,44 @@ namespace BizHawk.Client.Common
|
||||||
[LuaMethod("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. Not supported in the Quick Nes core")]
|
[LuaMethod("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. Not supported in the Quick Nes core")]
|
||||||
public void SetScanlines(int top, int bottom, bool pal = false)
|
public void SetScanlines(int top, int bottom, bool pal = false)
|
||||||
{
|
{
|
||||||
if (Neshawk != null)
|
switch (Settings)
|
||||||
{
|
{
|
||||||
if (top > 127)
|
case NES.NESSettings nhs:
|
||||||
{
|
if (top > 127)
|
||||||
top = 127;
|
{
|
||||||
}
|
top = 127;
|
||||||
else if (top < 0)
|
}
|
||||||
{
|
else if (top < 0)
|
||||||
top = 0;
|
{
|
||||||
}
|
top = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (bottom > 239)
|
if (bottom > 239)
|
||||||
{
|
{
|
||||||
bottom = 239;
|
bottom = 239;
|
||||||
}
|
}
|
||||||
else if (bottom < 128)
|
else if (bottom < 128)
|
||||||
{
|
{
|
||||||
bottom = 128;
|
bottom = 128;
|
||||||
}
|
}
|
||||||
|
|
||||||
var s = Neshawk.GetSettings();
|
if (pal)
|
||||||
|
{
|
||||||
|
nhs.PAL_TopLine = top;
|
||||||
|
nhs.PAL_BottomLine = bottom;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
nhs.NTSC_TopLine = top;
|
||||||
|
nhs.NTSC_BottomLine = bottom;
|
||||||
|
}
|
||||||
|
|
||||||
if (pal)
|
Settings = nhs;
|
||||||
{
|
break;
|
||||||
s.PAL_TopLine = top;
|
case QuickNES.QuickNESSettings _:
|
||||||
s.PAL_BottomLine = bottom;
|
return;
|
||||||
}
|
default:
|
||||||
else
|
throw new InvalidOperationException();
|
||||||
{
|
|
||||||
s.NTSC_TopLine = top;
|
|
||||||
s.NTSC_BottomLine = bottom;
|
|
||||||
}
|
|
||||||
|
|
||||||
Neshawk.PutSettings(s);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue