BSNESv115+: actually provide IBoardInfo properly

This commit is contained in:
Morilli 2022-11-24 16:07:48 +01:00
parent abeaa2a106
commit 10ba45d462
6 changed files with 51 additions and 84 deletions

Binary file not shown.

View File

@ -33,7 +33,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.BSNES
[BizImport(CallingConvention.Cdecl)]
public abstract BsnesApi.SNES_REGION snes_get_region();
[BizImport(CallingConvention.Cdecl)]
public abstract BsnesApi.SNES_MAPPER snes_get_mapper();
public abstract IntPtr snes_get_board();
[BizImport(CallingConvention.Cdecl)]
public abstract IntPtr snes_get_memory_region(int id, out int size, out int wordSize);
[BizImport(CallingConvention.Cdecl)]

View File

@ -151,21 +151,6 @@
High
}
public enum SNES_MAPPER : byte
{
LOROM = 0,
HIROM = 1,
EXLOROM = 2,
EXHIROM = 3,
SUPERFXROM = 4,
SA1ROM = 5,
SPC7110ROM = 6,
BSCLOROM = 7,
BSCHIROM = 8,
BSXROM = 9,
STROM = 10
}
public enum SNES_REGION : uint
{
NTSC = 0,

View File

@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Runtime.InteropServices;
using BizHawk.Common;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Common.Base_Implementations;
@ -12,7 +13,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.BSNES
{
[PortedCore(CoreNames.Bsnes115, "bsnes team", "v115+", "https://github.com/bsnes-emu/bsnes")]
[ServiceNotApplicable(new[] { typeof(IDriveLight) })]
public partial class BsnesCore : IEmulator, IDebuggable, IVideoProvider, ISaveRam, IStatable, IInputPollable, IRegionable, ISettable<BsnesCore.SnesSettings, BsnesCore.SnesSyncSettings>, IBSNESForGfxDebugger
public partial class BsnesCore : IEmulator, IDebuggable, IVideoProvider, ISaveRam, IStatable, IInputPollable, IRegionable, ISettable<BsnesCore.SnesSettings, BsnesCore.SnesSyncSettings>, IBSNESForGfxDebugger, IBoardInfo
{
[CoreConstructor(VSystemID.Raw.SGB)]
[CoreConstructor(VSystemID.Raw.SNES)]
@ -85,8 +86,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.BSNES
if (IsSGB)
{
ser.Register<IBoardInfo>(new SGBBoardInfo());
Api.core.snes_load_cartridge_super_gameboy(sgbRomData, loadParameters.Roms[0].RomData,
sgbRomData!.Length, loadParameters.Roms[0].RomData.Length);
}
@ -95,6 +94,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.BSNES
Api.core.snes_load_cartridge_normal(loadParameters.Roms[0].RomData, loadParameters.Roms[0].RomData.Length);
}
using (Api.EnterExit()) this.BoardName = Marshal.PtrToStringAnsi(Api.core.snes_get_board());
_region = Api.core.snes_get_region();
if (_region == BsnesApi.SNES_REGION.NTSC)
{
@ -130,11 +130,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.BSNES
private bool _disposed;
public bool IsSGB { get; }
private class SGBBoardInfo : IBoardInfo
{
public string BoardName => "SGB";
}
public string BoardName { get; }
internal BsnesApi Api { get; }

View File

@ -26,16 +26,12 @@ namespace BizHawk.Emulation.Cores.Nintendo.BSNES
ser.Register(_bsnesCore.ServiceProvider.GetService<IInputPollable>());
ser.Register(_bsnesCore.ServiceProvider.GetService<IRegionable>());
ser.Register(_bsnesCore.ServiceProvider.GetService<ISettable<BsnesCore.SnesSettings, BsnesCore.SnesSyncSettings>>());
ser.Register(_bsnesCore.ServiceProvider.GetService<IBSNESForGfxDebugger>());
ser.Register(_bsnesCore.ServiceProvider.GetService<IBoardInfo>());
ser.Register(_bsnesCore.ServiceProvider.GetService<ISoundProvider>());
ser.Register(_bsnesCore.ServiceProvider.GetService<IMemoryDomains>());
ser.Register(_bsnesCore.ServiceProvider.GetService<IDisassemblable>());
ser.Register(_bsnesCore.ServiceProvider.GetService<ITraceable>());
ser.Register(_bsnesCore.ServiceProvider.GetService<IBSNESForGfxDebugger>());
if (IsSGB)
{
// board info is only set in SGB mode
ser.Register(_bsnesCore.ServiceProvider.GetService<IBoardInfo>());
}
ServiceProvider = ser;
}
@ -50,45 +46,45 @@ namespace BizHawk.Emulation.Cores.Nintendo.BSNES
public bool FrameAdvance(IController controller, bool render, bool renderSound = true)
{
using (_bsnesCore.Api.EnterExit())
{
_bsnesCore.FrameAdvancePre(controller, render, renderSound);
_bsnesCore.IsLagFrame = true;
bool framePassed = false;
bool resetSignal = controller.IsPressed("Reset");
bool powerSignal = controller.IsPressed("Power");
if (resetSignal || powerSignal)
{
int resetInstruction = controller.AxisValue("Reset Instruction");
for (int i = 0; i < resetInstruction; i++)
{
framePassed = _bsnesCore.Api.core.snes_cpu_step();
if (framePassed) break;
}
if (resetSignal)
{
_bsnesCore.Api.core.snes_reset();
}
if (powerSignal)
{
_bsnesCore.Api.core.snes_power();
}
}
else
{
// run the core for one (sub-)frame
bool subFrameRequested = controller.IsPressed("Subframe");
framePassed = _bsnesCore.Api.core.snes_run(subFrameRequested);
}
if (!framePassed) _bsnesCore.IsLagFrame = false;
_bsnesCore.FrameAdvancePost();
return true;
{
_bsnesCore.FrameAdvancePre(controller, render, renderSound);
_bsnesCore.IsLagFrame = true;
bool framePassed = false;
bool resetSignal = controller.IsPressed("Reset");
bool powerSignal = controller.IsPressed("Power");
if (resetSignal || powerSignal)
{
int resetInstruction = controller.AxisValue("Reset Instruction");
for (int i = 0; i < resetInstruction; i++)
{
framePassed = _bsnesCore.Api.core.snes_cpu_step();
if (framePassed) break;
}
if (resetSignal)
{
_bsnesCore.Api.core.snes_reset();
}
if (powerSignal)
{
_bsnesCore.Api.core.snes_power();
}
}
else
{
// run the core for one (sub-)frame
bool subFrameRequested = controller.IsPressed("Subframe");
framePassed = _bsnesCore.Api.core.snes_run(subFrameRequested);
}
if (!framePassed) _bsnesCore.IsLagFrame = false;
_bsnesCore.FrameAdvancePost();
return true;
}
}

View File

@ -312,22 +312,12 @@ EXPORT short* snes_get_audiobuffer_and_size(int& out_size) {
return audioBuffer.data();
}
EXPORT char snes_get_mapper(void) {
string board = program->superFamicom.document["game/board"].text();
string mapper = board.split('-', 1)[0];
if (mapper == "LOROM") return 0;
if (mapper == "HIROM") return 1;
if (mapper == "EXLOROM") return 2;
if (mapper == "EXHIROM") return 3;
if (mapper == "SUPERFXROM") return 4;
if (mapper == "SA1ROM") return 5;
if (mapper == "SPC7110ROM") return 6;
if (mapper == "BSCLOROM") return 7;
if (mapper == "BSCHIROM") return 8;
if (mapper == "BSXROM") return 9;
if (mapper == "STROM") return 10;
const char* board;
EXPORT const char* snes_get_board(void)
{
if (!board) board = program->superFamicom.document["game/board"].text().data();
return -1;
return board;
}
EXPORT void* snes_get_memory_region(int id, int* size, int* word_size)