LibsnesCore reformating round 2 - sort out private fields vs pulbic properties

This commit is contained in:
adelikat 2017-04-19 12:19:16 -05:00
parent 808d03155a
commit e3ae4b1410
10 changed files with 149 additions and 141 deletions

View File

@ -660,8 +660,8 @@ namespace BizHawk.Client.EmuHawk
{
//wtf to do? now we need an api all the time
if (currentSnesCore != null)
return new SNESGraphicsDecoder(currentSnesCore.api, currentSnesCore.CurrPalette);
else return new SNESGraphicsDecoder(currentSnesCore.api, SnesColors.ColorType.BizHawk);
return new SNESGraphicsDecoder(currentSnesCore.Api, currentSnesCore.CurrPalette);
else return new SNESGraphicsDecoder(currentSnesCore.Api, SnesColors.ColorType.BizHawk);
}
void RenderPalette()

View File

@ -12,7 +12,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
_currCdl?.Pin();
// set it no matter what. if its null, the cdl will be unhooked from libsnes internally
api.QUERY_set_cdl(_currCdl);
Api.QUERY_set_cdl(_currCdl);
}
public void NewCDL(ICodeDataLog cdl)

View File

@ -10,7 +10,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
public IDictionary<string, RegisterValue> GetCpuFlagsAndRegisters()
{
LibsnesApi.CPURegs regs;
api.QUERY_peek_cpu_regs(out regs);
Api.QUERY_peek_cpu_regs(out regs);
bool fn = (regs.p & 0x80) != 0;
bool fv = (regs.p & 0x40) != 0;

View File

@ -22,18 +22,18 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
IsLagFrame = true;
if (!nocallbacks && _tracer.Enabled)
if (!_nocallbacks && _tracer.Enabled)
{
api.QUERY_set_trace_callback(tracecb);
Api.QUERY_set_trace_callback(_tracecb);
}
else
{
api.QUERY_set_trace_callback(null);
Api.QUERY_set_trace_callback(null);
}
// for deterministic emulation, save the state we're going to use before frame advance
// don't do this during nocallbacks though, since it's already been done
if (!nocallbacks && DeterministicEmulation)
if (!_nocallbacks && DeterministicEmulation)
{
var ms = new MemoryStream();
var bw = new BinaryWriter(ms);
@ -47,18 +47,18 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
}
// speedup when sound rendering is not needed
api.QUERY_set_audio_sample(rendersound ? soundcb : null);
Api.QUERY_set_audio_sample(rendersound ? _soundcb : null);
bool resetSignal = Controller.IsPressed("Reset");
if (resetSignal)
{
api.CMD_reset();
Api.CMD_reset();
}
bool powerSignal = Controller.IsPressed("Power");
if (powerSignal)
{
api.CMD_power();
Api.CMD_power();
}
var enables = new LibsnesApi.LayerEnables
@ -77,13 +77,13 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
Obj_Prio3 = _settings.ShowOBJ_3
};
api.SetLayerEnables(ref enables);
Api.SetLayerEnables(ref enables);
RefreshMemoryCallbacks(false);
// apparently this is one frame?
_timeFrameCounter++;
api.CMD_run();
Api.CMD_run();
// once upon a time we forwarded messages frmo bsnes here, by checking for queued text messages, but I don't think it's needed any longer
if (IsLagFrame)
@ -128,11 +128,11 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
_disposed = true;
api.CMD_unload_cartridge();
api.CMD_term();
Api.CMD_unload_cartridge();
Api.CMD_term();
resampler.Dispose();
api.Dispose();
_resampler.Dispose();
Api.Dispose();
_currCdl?.Unpin();
}

View File

@ -71,8 +71,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
"System Bus",
0x1000000,
MemoryDomain.Endian.Little,
addr => api.QUERY_peek(LibsnesApi.SNES_MEMORY.SYSBUS, (uint)addr),
(addr, val) => api.QUERY_poke(LibsnesApi.SNES_MEMORY.SYSBUS, (uint)addr, val), wordSize: 2));
addr => Api.QUERY_peek(LibsnesApi.SNES_MEMORY.SYSBUS, (uint)addr),
(addr, val) => Api.QUERY_poke(LibsnesApi.SNES_MEMORY.SYSBUS, (uint)addr, val), wordSize: 2));
}
else
{
@ -87,7 +87,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
private unsafe void MakeMemoryDomain(string name, LibsnesApi.SNES_MEMORY id, MemoryDomain.Endian endian, int byteSize = 1)
{
int size = api.QUERY_get_memory_size(id);
int size = Api.QUERY_get_memory_size(id);
int mask = size - 1;
bool pow2 = Util.IsPowerOfTwo(size);
@ -97,7 +97,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
return;
}
byte* blockptr = api.QUERY_get_memory_data(id);
byte* blockptr = Api.QUERY_get_memory_data(id);
MemoryDomain md;
@ -145,13 +145,13 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
private unsafe void MakeFakeBus()
{
int size = api.QUERY_get_memory_size(LibsnesApi.SNES_MEMORY.WRAM);
int size = Api.QUERY_get_memory_size(LibsnesApi.SNES_MEMORY.WRAM);
if (size != 0x20000)
{
throw new InvalidOperationException();
}
byte* blockptr = api.QUERY_get_memory_data(LibsnesApi.SNES_MEMORY.WRAM);
byte* blockptr = Api.QUERY_get_memory_data(LibsnesApi.SNES_MEMORY.WRAM);
var md = new MemoryDomainDelegate("System Bus", 0x1000000, MemoryDomain.Endian.Little,
addr =>
@ -190,14 +190,14 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
case LibsnesApi.SNES_MAPPER.LOROM:
if (low >= 0x8000)
{
return api.QUERY_peek(LibsnesApi.SNES_MEMORY.SYSBUS, (uint)addr);
return Api.QUERY_peek(LibsnesApi.SNES_MEMORY.SYSBUS, (uint)addr);
}
break;
case LibsnesApi.SNES_MAPPER.EXLOROM:
if ((bank >= 0x40 && bank <= 0x7f) || low >= 0x8000)
{
return api.QUERY_peek(LibsnesApi.SNES_MEMORY.SYSBUS, (uint)addr);
return Api.QUERY_peek(LibsnesApi.SNES_MEMORY.SYSBUS, (uint)addr);
}
break;
@ -205,7 +205,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
case LibsnesApi.SNES_MAPPER.EXHIROM:
if ((bank >= 0x40 && bank <= 0x7f) || bank >= 0xc0 || low >= 0x8000)
{
return api.QUERY_peek(LibsnesApi.SNES_MEMORY.SYSBUS, (uint)addr);
return Api.QUERY_peek(LibsnesApi.SNES_MEMORY.SYSBUS, (uint)addr);
}
break;
@ -213,21 +213,21 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
if ((bank >= 0x40 && bank <= 0x5f) || (bank >= 0xc0 && bank <= 0xdf) ||
(low >= 0x8000 && ((bank >= 0x00 && bank <= 0x3f) || (bank >= 0x80 && bank <= 0xbf))))
{
return api.QUERY_peek(LibsnesApi.SNES_MEMORY.SYSBUS, (uint)addr);
return Api.QUERY_peek(LibsnesApi.SNES_MEMORY.SYSBUS, (uint)addr);
}
break;
case LibsnesApi.SNES_MAPPER.SA1ROM:
if (bank >= 0xc0 || (low >= 0x8000 && ((bank >= 0x00 && bank <= 0x3f) || (bank >= 0x80 && bank <= 0xbf))))
{
return api.QUERY_peek(LibsnesApi.SNES_MEMORY.SYSBUS, (uint)addr);
return Api.QUERY_peek(LibsnesApi.SNES_MEMORY.SYSBUS, (uint)addr);
}
break;
case LibsnesApi.SNES_MAPPER.BSCLOROM:
if (low >= 0x8000 && ((bank >= 0x00 && bank <= 0x3f) || (bank >= 0x80 && bank <= 0xbf)))
{
return api.QUERY_peek(LibsnesApi.SNES_MEMORY.SYSBUS, (uint)addr);
return Api.QUERY_peek(LibsnesApi.SNES_MEMORY.SYSBUS, (uint)addr);
}
break;
@ -235,7 +235,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
if ((bank >= 0x40 && bank <= 0x5f) || (bank >= 0xc0 && bank <= 0xdf) ||
(low >= 0x8000 && ((bank >= 0x00 && bank <= 0x1f) || (bank >= 0x80 && bank <= 0x9f))))
{
return api.QUERY_peek(LibsnesApi.SNES_MEMORY.SYSBUS, (uint)addr);
return Api.QUERY_peek(LibsnesApi.SNES_MEMORY.SYSBUS, (uint)addr);
}
break;
@ -244,14 +244,14 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
(low >= 0x8000 && ((bank >= 0x00 && bank <= 0x3f) || (bank >= 0x80 && bank <= 0xbf))) ||
(low >= 0x6000 && low <= 0x7fff && (bank >= 0x20 && bank <= 0x3f)))
{
return api.QUERY_peek(LibsnesApi.SNES_MEMORY.SYSBUS, (uint)addr);
return Api.QUERY_peek(LibsnesApi.SNES_MEMORY.SYSBUS, (uint)addr);
}
break;
case LibsnesApi.SNES_MAPPER.STROM:
if (low >= 0x8000 && ((bank >= 0x00 && bank <= 0x5f) || (bank >= 0x80 && bank <= 0xdf)))
{
return api.QUERY_peek(LibsnesApi.SNES_MEMORY.SYSBUS, (uint)addr);
return Api.QUERY_peek(LibsnesApi.SNES_MEMORY.SYSBUS, (uint)addr);
}
break;

View File

@ -8,7 +8,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
{
get
{
if (api.Region == LibsnesApi.SNES_REGION.NTSC)
if (Api.Region == LibsnesApi.SNES_REGION.NTSC)
{
return DisplayType.NTSC;
}

View File

@ -8,17 +8,17 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
public unsafe partial class LibsnesCore : ISaveRam
{
public bool SaveRamModified =>
api.QUERY_get_memory_size(LibsnesApi.SNES_MEMORY.CARTRIDGE_RAM) != 0
|| api.QUERY_get_memory_size(LibsnesApi.SNES_MEMORY.SGB_CARTRAM) != 0;
Api.QUERY_get_memory_size(LibsnesApi.SNES_MEMORY.CARTRIDGE_RAM) != 0
|| Api.QUERY_get_memory_size(LibsnesApi.SNES_MEMORY.SGB_CARTRAM) != 0;
public byte[] CloneSaveRam()
{
byte* buf = api.QUERY_get_memory_data(LibsnesApi.SNES_MEMORY.CARTRIDGE_RAM);
var size = api.QUERY_get_memory_size(LibsnesApi.SNES_MEMORY.CARTRIDGE_RAM);
byte* buf = Api.QUERY_get_memory_data(LibsnesApi.SNES_MEMORY.CARTRIDGE_RAM);
var size = Api.QUERY_get_memory_size(LibsnesApi.SNES_MEMORY.CARTRIDGE_RAM);
if (buf == null)
{
buf = api.QUERY_get_memory_data(LibsnesApi.SNES_MEMORY.SGB_CARTRAM);
size = api.QUERY_get_memory_size(LibsnesApi.SNES_MEMORY.SGB_CARTRAM);
buf = Api.QUERY_get_memory_data(LibsnesApi.SNES_MEMORY.SGB_CARTRAM);
size = Api.QUERY_get_memory_size(LibsnesApi.SNES_MEMORY.SGB_CARTRAM);
}
var ret = new byte[size];
@ -28,12 +28,12 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
public void StoreSaveRam(byte[] data)
{
byte* buf = api.QUERY_get_memory_data(LibsnesApi.SNES_MEMORY.CARTRIDGE_RAM);
var size = api.QUERY_get_memory_size(LibsnesApi.SNES_MEMORY.CARTRIDGE_RAM);
byte* buf = Api.QUERY_get_memory_data(LibsnesApi.SNES_MEMORY.CARTRIDGE_RAM);
var size = Api.QUERY_get_memory_size(LibsnesApi.SNES_MEMORY.CARTRIDGE_RAM);
if (buf == null)
{
buf = api.QUERY_get_memory_data(LibsnesApi.SNES_MEMORY.SGB_CARTRAM);
size = api.QUERY_get_memory_size(LibsnesApi.SNES_MEMORY.SGB_CARTRAM);
buf = Api.QUERY_get_memory_data(LibsnesApi.SNES_MEMORY.SGB_CARTRAM);
size = Api.QUERY_get_memory_size(LibsnesApi.SNES_MEMORY.SGB_CARTRAM);
}
if (size == 0)

View File

@ -44,7 +44,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
public void LoadStateBinary(BinaryReader reader)
{
int size = api.QUERY_serialize_size();
int size = Api.QUERY_serialize_size();
byte[] buf = reader.ReadBytes(size);
CoreLoadState(buf);
@ -62,9 +62,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
ssc.DeSerialize(reader);
IController tmp = Controller;
Controller = ssc;
nocallbacks = true;
_nocallbacks = true;
FrameAdvance(false, false);
nocallbacks = false;
_nocallbacks = false;
Controller = tmp;
ssc.Serialize(bw);
}
@ -97,28 +97,28 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
// handle the unmanaged part of loadstating
private void CoreLoadState(byte[] data)
{
int size = api.QUERY_serialize_size();
int size = Api.QUERY_serialize_size();
if (data.Length != size)
{
throw new Exception("Libsnes internal savestate size mismatch!");
}
api.CMD_init();
Api.CMD_init();
// zero 01-sep-2014 - this approach isn't being used anymore, it's too slow!
// LoadCurrent(); //need to make sure chip roms are reloaded
fixed (byte* pbuf = &data[0])
api.CMD_unserialize(new IntPtr(pbuf), size);
Api.CMD_unserialize(new IntPtr(pbuf), size);
}
// handle the unmanaged part of savestating
private byte[] CoreSaveState()
{
int size = api.QUERY_serialize_size();
int size = Api.QUERY_serialize_size();
byte[] buf = new byte[size];
fixed (byte* pbuf = &buf[0])
api.CMD_serialize(new IntPtr(pbuf), size);
Api.CMD_serialize(new IntPtr(pbuf), size);
return buf;
}

View File

@ -61,7 +61,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
_settings = (SnesSettings)Settings ?? new SnesSettings();
_syncSettings = (SnesSyncSettings)SyncSettings ?? new SnesSyncSettings();
api = new LibsnesApi(GetDllPath())
Api = new LibsnesApi(GetDllPath())
{
ReadHook = ReadHook,
ExecHook = ExecHook,
@ -73,27 +73,27 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
_controllerDeck = new LibsnesControllerDeck(
_syncSettings.LeftPort,
_syncSettings.RightPort);
_controllerDeck.NativeInit(api);
_controllerDeck.NativeInit(Api);
api.CMD_init();
Api.CMD_init();
api.QUERY_set_video_refresh(snes_video_refresh);
api.QUERY_set_input_poll(snes_input_poll);
api.QUERY_set_input_state(snes_input_state);
api.QUERY_set_input_notify(snes_input_notify);
api.QUERY_set_path_request(snes_path_request);
Api.QUERY_set_video_refresh(snes_video_refresh);
Api.QUERY_set_input_poll(snes_input_poll);
Api.QUERY_set_input_state(snes_input_state);
Api.QUERY_set_input_notify(snes_input_notify);
Api.QUERY_set_path_request(snes_path_request);
scanlineStart_cb = new LibsnesApi.snes_scanlineStart_t(snes_scanlineStart);
tracecb = new LibsnesApi.snes_trace_t(snes_trace);
_scanlineStartCb = new LibsnesApi.snes_scanlineStart_t(snes_scanlineStart);
_tracecb = new LibsnesApi.snes_trace_t(snes_trace);
soundcb = new LibsnesApi.snes_audio_sample_t(snes_audio_sample);
api.QUERY_set_audio_sample(soundcb);
_soundcb = new LibsnesApi.snes_audio_sample_t(snes_audio_sample);
Api.QUERY_set_audio_sample(_soundcb);
RefreshPalette();
// start up audio resampler
InitAudio();
ser.Register<ISoundProvider>(resampler);
ser.Register<ISoundProvider>(_resampler);
// strip header
if ((romData?.Length & 0x7FFF) == 512)
@ -103,13 +103,13 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
romData = newData;
}
if (game["SGB"])
if (game["SGB"])
{
IsSGB = true;
SystemId = "SNES";
BoardName = "SGB";
CurrLoadParams = new LoadParams()
_currLoadParams = new LoadParams()
{
type = LoadParamType.SuperGameBoy,
rom_xml = null,
@ -128,14 +128,14 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
// we may need to get some information out of the cart, even during the following bootup/load process
if (xmlData != null)
{
romxml = new XmlDocument();
romxml.Load(new MemoryStream(xmlData));
_romxml = new XmlDocument();
_romxml.Load(new MemoryStream(xmlData));
// bsnes wont inspect the xml to load the necessary sfc file.
// so, we have to do that here and pass it in as the romData :/
if (romxml["cartridge"] != null && romxml["cartridge"]["rom"] != null)
if (_romxml["cartridge"] != null && _romxml["cartridge"]["rom"] != null)
{
romData = File.ReadAllBytes(CoreComm.CoreFileProvider.PathSubfile(romxml["cartridge"]["rom"].Attributes["name"].Value));
romData = File.ReadAllBytes(CoreComm.CoreFileProvider.PathSubfile(_romxml["cartridge"]["rom"].Attributes["name"].Value));
}
else
{
@ -144,7 +144,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
}
SystemId = "SNES";
CurrLoadParams = new LoadParams()
_currLoadParams = new LoadParams()
{
type = LoadParamType.Normal,
xml_data = xmlData,
@ -157,7 +157,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
}
}
if (api.Region == LibsnesApi.SNES_REGION.NTSC)
if (Api.Region == LibsnesApi.SNES_REGION.NTSC)
{
// similar to what aviout reports from snes9x and seems logical from bsnes first principles. bsnes uses that numerator (ntsc master clockrate) for sure.
CoreComm.VsyncNum = 21477272;
@ -170,7 +170,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
CoreComm.VsyncDen = 4 * 341 * 312;
}
api.CMD_power();
Api.CMD_power();
SetupMemoryDomains(romData, sgbRomData);
@ -188,7 +188,21 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
}
}
private GameInfo _game;
private readonly GameInfo _game;
private readonly LibsnesControllerDeck _controllerDeck;
private readonly ITraceable _tracer;
private readonly XmlDocument _romxml;
private readonly LibsnesApi.snes_scanlineStart_t _scanlineStartCb;
private readonly LibsnesApi.snes_trace_t _tracecb;
private readonly LibsnesApi.snes_audio_sample_t _soundcb;
private LoadParams _currLoadParams;
private SpeexResampler _resampler;
private int _timeFrameCounter;
private bool _nocallbacks; // disable all external callbacks. the front end should not even know the core is frame advancing
private bool _disposed;
public bool IsSGB { get; }
public string CurrentProfile
{
@ -204,38 +218,42 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
}
}
public bool IsSGB { get; }
public LibsnesApi Api { get; }
private LibsnesControllerDeck _controllerDeck;
public SnesColors.ColorType CurrPalette { get; private set; }
/// <summary>disable all external callbacks. the front end should not even know the core is frame advancing</summary>
private bool nocallbacks = false;
private readonly ITraceable _tracer;
public MyScanlineHookManager ScanlineHookManager { get; }
public class MyScanlineHookManager : ScanlineHookManager
{
private readonly LibsnesCore _core;
public MyScanlineHookManager(LibsnesCore core)
{
this.core = core;
_core = core;
}
LibsnesCore core;
public override void OnHooksChanged()
{
core.OnScanlineHooksChanged();
_core.OnScanlineHooksChanged();
}
}
private bool _disposed = false;
public MyScanlineHookManager ScanlineHookManager;
private void OnScanlineHooksChanged()
{
if (_disposed) return;
if (ScanlineHookManager.HookCount == 0) api.QUERY_set_scanlineStart(null);
else api.QUERY_set_scanlineStart(scanlineStart_cb);
if (_disposed)
{
return;
}
if (ScanlineHookManager.HookCount == 0)
{
Api.QUERY_set_scanlineStart(null);
}
else
{
Api.QUERY_set_scanlineStart(_scanlineStartCb);
}
}
private void snes_scanlineStart(int line)
@ -247,20 +265,20 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
{
// every rom requests msu1.rom... why? who knows.
// also handle msu-1 pcm files here
bool is_msu1_rom = hint == "msu1.rom";
bool is_msu1_pcm = Path.GetExtension(hint).ToLower() == ".pcm";
if (is_msu1_rom || is_msu1_pcm)
bool isMsu1Rom = hint == "msu1.rom";
bool isMsu1Pcm = Path.GetExtension(hint).ToLower() == ".pcm";
if (isMsu1Rom || isMsu1Pcm)
{
// well, check if we have an msu-1 xml
if (romxml != null && romxml["cartridge"] != null && romxml["cartridge"]["msu1"] != null)
if (_romxml != null && _romxml["cartridge"] != null && _romxml["cartridge"]["msu1"] != null)
{
var msu1 = romxml["cartridge"]["msu1"];
if (is_msu1_rom && msu1["rom"].Attributes["name"] != null)
var msu1 = _romxml["cartridge"]["msu1"];
if (isMsu1Rom && msu1["rom"].Attributes["name"] != null)
{
return CoreComm.CoreFileProvider.PathSubfile(msu1["rom"].Attributes["name"].Value);
}
if (is_msu1_pcm)
if (isMsu1Pcm)
{
// return @"D:\roms\snes\SuperRoadBlaster\SuperRoadBlaster-1.pcm";
// return "";
@ -326,19 +344,14 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
});
}
public SnesColors.ColorType CurrPalette { get; private set; }
public void SetPalette(SnesColors.ColorType pal)
private void SetPalette(SnesColors.ColorType pal)
{
CurrPalette = pal;
int[] tmp = SnesColors.GetLUT(pal);
fixed (int* p = &tmp[0])
api.QUERY_set_color_lut((IntPtr)p);
Api.QUERY_set_color_lut((IntPtr)p);
}
public LibsnesApi api;
private XmlDocument romxml;
private string GetDllPath()
{
var exename = "libsneshawk-32-" + CurrentProfile.ToLower() + ".dll";
@ -353,7 +366,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
return dllPath;
}
void ReadHook(uint addr)
private void ReadHook(uint addr)
{
MemoryCallbacks.CallReads(addr);
// we RefreshMemoryCallbacks() after the trigger in case the trigger turns itself off at that point
@ -377,10 +390,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
// RefreshMemoryCallbacks();
}
private LibsnesApi.snes_scanlineStart_t scanlineStart_cb;
private LibsnesApi.snes_trace_t tracecb;
private LibsnesApi.snes_audio_sample_t soundcb;
private enum LoadParamType
{
Normal, SuperGameBoy
@ -397,15 +406,13 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
public byte[] dmg_data;
}
private LoadParams CurrLoadParams;
private bool LoadCurrent()
{
bool result = CurrLoadParams.type == LoadParamType.Normal
? api.CMD_load_cartridge_normal(CurrLoadParams.xml_data, CurrLoadParams.rom_data)
: api.CMD_load_cartridge_super_game_boy(CurrLoadParams.rom_xml, CurrLoadParams.rom_data, CurrLoadParams.rom_size, CurrLoadParams.dmg_data);
bool result = _currLoadParams.type == LoadParamType.Normal
? Api.CMD_load_cartridge_normal(_currLoadParams.xml_data, _currLoadParams.rom_data)
: Api.CMD_load_cartridge_super_game_boy(_currLoadParams.rom_xml, _currLoadParams.rom_data, _currLoadParams.rom_size, _currLoadParams.dmg_data);
_mapper = api.Mapper;
_mapper = Api.Mapper;
return result;
}
@ -435,7 +442,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
// 0: signifies latch bit going to 0. should be reported as oninputpoll
// 1: signifies latch bit going to 1. should be reported as oninputpoll
if (index >= 0x4000)
{
IsLagFrame = false;
}
}
private void snes_video_refresh(int* data, int width, int height)
@ -511,8 +520,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
break;
}
int bonus = i * _videoWidth + xbonus;
int bonus = (i * _videoWidth) + xbonus;
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
int si = y * srcPitch + x + srcStart;
@ -520,6 +530,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
int rgb = data[si];
_videoBuffer[di] = rgb;
}
}
}
}
}
@ -527,13 +538,11 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
private void RefreshMemoryCallbacks(bool suppress)
{
var mcs = MemoryCallbacks;
api.QUERY_set_state_hook_exec(!suppress && mcs.HasExecutes);
api.QUERY_set_state_hook_read(!suppress && mcs.HasReads);
api.QUERY_set_state_hook_write(!suppress && mcs.HasWrites);
Api.QUERY_set_state_hook_exec(!suppress && mcs.HasExecutes);
Api.QUERY_set_state_hook_read(!suppress && mcs.HasReads);
Api.QUERY_set_state_hook_write(!suppress && mcs.HasWrites);
}
private int _timeFrameCounter;
//public byte[] snes_get_memory_data_read(LibsnesApi.SNES_MEMORY id)
//{
// var size = (int)api.snes_get_memory_size(id);
@ -542,6 +551,21 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
// return ret;
//}
private void InitAudio()
{
_resampler = new SpeexResampler(6, 64081, 88200, 32041, 44100);
}
private void snes_audio_sample(ushort left, ushort right)
{
_resampler.EnqueueSample((short)left, (short)right);
}
private void RefreshPalette()
{
SetPalette((SnesColors.ColorType)Enum.Parse(typeof(SnesColors.ColorType), _settings.Palette, false));
}
/// <summary>
/// can freeze a copy of a controller input set and serialize\deserialize it
/// </summary>
@ -561,7 +585,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
this.def = def;
}
WorkingDictionary<string, float> buttons = new WorkingDictionary<string,float>();
WorkingDictionary<string, float> buttons = new WorkingDictionary<string, float>();
/// <summary>
/// invalid until CopyFrom has been called
@ -596,7 +620,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
buttons.Add(k, v);
}
}
/// <summary>
/// this controller's definition changes to that of source
/// </summary>
@ -629,7 +653,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
{
buttons[button] = 1.0f;
}
public bool this[string button]
{
get { return buttons[button] != 0; }
@ -645,23 +669,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
return buttons[name];
}
}
private SpeexResampler resampler;
private void InitAudio()
{
resampler = new SpeexResampler(6, 64081, 88200, 32041, 44100);
}
private void snes_audio_sample(ushort left, ushort right)
{
resampler.EnqueueSample((short)left, (short)right);
}
private void RefreshPalette()
{
SetPalette((SnesColors.ColorType)Enum.Parse(typeof(SnesColors.ColorType), _settings.Palette, false));
}
}
public class ScanlineHookManager

View File

@ -42,6 +42,7 @@
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=PSP/@EntryIndexedValue">PSP</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=PSX/@EntryIndexedValue">PSX</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SG/@EntryIndexedValue">SG</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SGB/@EntryIndexedValue">SGB</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SGX/@EntryIndexedValue">SGX</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SNES/@EntryIndexedValue">SNES</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=TI/@EntryIndexedValue">TI</s:String>