use inline out variables in Emulation.Cores

This commit is contained in:
adelikat 2020-02-18 15:10:29 -06:00
parent 4e03e14eea
commit cdcc1eabde
27 changed files with 43 additions and 96 deletions

View File

@ -104,9 +104,8 @@ namespace BizHawk.Emulation.Cores.Components.M6502
}; };
} }
int length;
string rawbytes = ""; string rawbytes = "";
string disasm = Disassemble(PC, out length); string disasm = Disassemble(PC, out var length);
for (int i = 0; i < length; i++) for (int i = 0; i < length; i++)
{ {

View File

@ -144,9 +144,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
// get samples from all the providers // get samples from all the providers
foreach (var sp in SoundProviders) foreach (var sp in SoundProviders)
{ {
int sampCount; sp.SoundProvider.GetSamplesSync(out var samp, out var sampCount);
short[] samp;
sp.SoundProvider.GetSamplesSync(out samp, out sampCount);
sp.NSamp = sampCount; sp.NSamp = sampCount;
sp.Buffer = samp; sp.Buffer = samp;
} }

View File

@ -132,8 +132,7 @@ namespace BizHawk.Emulation.Cores.Computers.AppleII
case JsonToken.Float: case JsonToken.Float:
return Convert.ToInt32(_v); return Convert.ToInt32(_v);
case JsonToken.String: case JsonToken.String:
int i; if (int.TryParse(_v.ToString(), out var i))
if (int.TryParse(_v.ToString(), out i))
{ {
return i; return i;
} }

View File

@ -222,9 +222,8 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Media
using var trackMem = new MemoryStream(); using var trackMem = new MemoryStream();
for (var j = 0; j < sectors; j++) for (var j = 0; j < sectors; j++)
{ {
int bitsWritten;
var sectorData = reader.ReadBytes(256); var sectorData = reader.ReadBytes(256);
var diskData = ConvertSectorToGcr(sectorData, (byte)j, (byte)(i + 1), formatA, formatB, StandardSectorGapLength[DensityTable[i]], errorType, out bitsWritten); var diskData = ConvertSectorToGcr(sectorData, (byte)j, (byte)(i + 1), formatA, formatB, StandardSectorGapLength[DensityTable[i]], errorType, out var bitsWritten);
trackMem.Write(diskData, 0, diskData.Length); trackMem.Write(diskData, 0, diskData.Length);
trackLengthBits += bitsWritten; trackLengthBits += bitsWritten;
} }

View File

@ -155,8 +155,7 @@ namespace BizHawk.Emulation.Cores.Atari.A7800Hawk
// if such a game is being played, tell the user and disable it // if such a game is being played, tell the user and disable it
if (dict.ContainsKey("No_HS")) if (dict.ContainsKey("No_HS"))
{ {
bool no_hs; bool.TryParse(dict["No_HS"], out var no_hs);
bool.TryParse(dict["No_HS"], out no_hs);
if (no_hs) if (no_hs)
{ {

View File

@ -39,10 +39,9 @@ namespace BizHawk.Emulation.Cores.Consoles.NEC.PCFX
} }
}).ToArray(); }).ToArray();
List<ControlDefUnMerger> tmp;
Definition = ControllerDefinitionMerger.GetMerged( Definition = ControllerDefinitionMerger.GetMerged(
_devices.Select(d => d.Definition), _devices.Select(d => d.Definition),
out tmp); out var tmp);
_cdums = tmp.ToArray(); _cdums = tmp.ToArray();
Definition.Name = "PC-FX Controller"; Definition.Name = "PC-FX Controller";

View File

@ -619,20 +619,10 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink4x
public void GetSamplesSync(out short[] samples, out int nsamp) public void GetSamplesSync(out short[] samples, out int nsamp)
{ {
short[] temp_samp_A; A.audio.GetSamplesSync(out var temp_samp_A, out var nsamp_A);
short[] temp_samp_B; B.audio.GetSamplesSync(out short[] temp_samp_B, out var nsamp_B);
short[] temp_samp_C; C.audio.GetSamplesSync(out var temp_samp_C, out var nsamp_C);
short[] temp_samp_D; D.audio.GetSamplesSync(out var temp_samp_D, out var nsamp_D);
int nsamp_A;
int nsamp_B;
int nsamp_C;
int nsamp_D;
A.audio.GetSamplesSync(out temp_samp_A, out nsamp_A);
B.audio.GetSamplesSync(out temp_samp_B, out nsamp_B);
C.audio.GetSamplesSync(out temp_samp_C, out nsamp_C);
D.audio.GetSamplesSync(out temp_samp_D, out nsamp_D);
if (Link4xSettings.AudioSet == GBLink4xSettings.AudioSrc.A) if (Link4xSettings.AudioSet == GBLink4xSettings.AudioSrc.A)
{ {

View File

@ -16,8 +16,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
public override string Disassemble(MemoryDomain m, uint addr, out int length) public override string Disassemble(MemoryDomain m, uint addr, out int length)
{ {
ushort tmp; string ret = LR35902.Disassemble((ushort)addr, a => m.PeekByte(a), out var tmp);
string ret = LR35902.Disassemble((ushort)addr, a => m.PeekByte(a), out tmp);
length = tmp; length = tmp;
return ret; return ret;
} }

View File

@ -1007,8 +1007,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64.NativeApi
public void DetachPlugin(m64p_plugin_type type) public void DetachPlugin(m64p_plugin_type type)
{ {
AttachedPlugin plugin; if (plugins.TryGetValue(type, out var plugin))
if (plugins.TryGetValue(type, out plugin))
{ {
plugins.Remove(type); plugins.Remove(type);
m64pCoreDetachPlugin(type); m64pCoreDetachPlugin(type);

View File

@ -107,8 +107,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
public void Transfer(string s) public void Transfer(string s)
{ {
string why; if (!ValidString(s, out var why))
if (!ValidString(s, out why))
throw new InvalidOperationException(why); throw new InvalidOperationException(why);
Reset(); Reset();

View File

@ -438,10 +438,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
public override byte ReadPRG(int addr) public override byte ReadPRG(int addr)
{ {
bool ram;
byte ret; byte ret;
int offs = addr & 0x1fff; int offs = addr & 0x1fff;
int bank = PRGGetBank(addr, out ram); int bank = PRGGetBank(addr, out var ram);
if (ram) if (ram)
ret = ReadWRAMActual(bank, offs); ret = ReadWRAMActual(bank, offs);
@ -463,10 +462,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
public byte PeekPRG(int addr) public byte PeekPRG(int addr)
{ {
bool ram;
byte ret; byte ret;
int offs = addr & 0x1fff; int offs = addr & 0x1fff;
int bank = PRGGetBank(addr, out ram); int bank = PRGGetBank(addr, out var ram);
if (ram) if (ram)
ret = ReadWRAMActual(bank, offs); ret = ReadWRAMActual(bank, offs);
@ -479,8 +477,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
public override void WritePRG(int addr, byte value) public override void WritePRG(int addr, byte value)
{ {
bool ram; int bank = PRGGetBank(addr, out var ram);
int bank = PRGGetBank(addr, out ram);
if (ram) if (ram)
WriteWRAMActual(bank, addr & 0x1fff, value); WriteWRAMActual(bank, addr & 0x1fff, value);
} }

View File

@ -781,8 +781,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
{ {
string Name = ((MapperPropAttribute)attrib).Name ?? field.Name; string Name = ((MapperPropAttribute)attrib).Name ?? field.Name;
string Value; if (board.InitialRegisterValues.TryGetValue(Name, out var Value))
if (board.InitialRegisterValues.TryGetValue(Name, out Value))
{ {
try try
{ {

View File

@ -138,8 +138,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
{ {
this.Left = Left; this.Left = Left;
this.Right = Right; this.Right = Right;
List<ControlDefUnMerger> cdum; Definition = ControllerDefinitionMerger.GetMerged(new[] { Left.GetDefinition(), Right.GetDefinition() }, out var cdum);
Definition = ControllerDefinitionMerger.GetMerged(new[] { Left.GetDefinition(), Right.GetDefinition() }, out cdum);
LeftU = cdum[0]; LeftU = cdum[0];
RightU = cdum[1]; RightU = cdum[1];
@ -684,9 +683,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
public FamicomDeck(IFamicomExpansion ExpSlot, LightgunDelegate PPUCallback) public FamicomDeck(IFamicomExpansion ExpSlot, LightgunDelegate PPUCallback)
{ {
Player3 = ExpSlot; Player3 = ExpSlot;
List<ControlDefUnMerger> cdum;
Definition = ControllerDefinitionMerger.GetMerged( Definition = ControllerDefinitionMerger.GetMerged(
new[] { Player1.GetDefinition(), Player2.GetDefinition(), Player3.GetDefinition() }, out cdum); new[] { Player1.GetDefinition(), Player2.GetDefinition(), Player3.GetDefinition() }, out var cdum);
Definition.BoolButtons.Add("P2 Microphone"); Definition.BoolButtons.Add("P2 Microphone");
Player1U = cdum[0]; Player1U = cdum[0];
Player2U = cdum[1]; Player2U = cdum[1];

View File

@ -23,8 +23,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
void TryAdd(Stream s, string key) void TryAdd(Stream s, string key)
{ {
byte[] data; if (!chunks.TryGetValue(key, out var data))
if (!chunks.TryGetValue(key, out data))
return; return;
s.Write(data, 0, data.Length); s.Write(data, 0, data.Length);
} }
@ -64,9 +63,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
ci.prg_size = (short)(prgrom.Length / 1024); ci.prg_size = (short)(prgrom.Length / 1024);
ci.chr_size = (short)(chrrom.Length / 1024); ci.chr_size = (short)(chrrom.Length / 1024);
byte[] tmp; if (chunks.TryGetValue("MIRR", out var tmp))
if (chunks.TryGetValue("MIRR", out tmp))
{ {
switch (tmp[0]) switch (tmp[0])
{ {

View File

@ -55,8 +55,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES
float g = to_float * inp[1]; float g = to_float * inp[1];
float b = to_float * inp[2]; float b = to_float * inp[2];
float y, i, q; RGB_TO_YIQ(r, g, b, out float y, out var i, out var q);
RGB_TO_YIQ(r, g, b, out y, out i, out q);
if (tint > 0 && color < 0x0d) if (tint > 0 && color < 0x0d)
{ {

View File

@ -203,8 +203,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES
if (controller.IsPressed("Reset")) if (controller.IsPressed("Reset"))
QN.qn_reset(Context, false); QN.qn_reset(Context, false);
int j1, j2; SetPads(controller, out var j1, out var j2);
SetPads(controller, out j1, out j2);
if (Tracer.Enabled) if (Tracer.Enabled)
QN.qn_set_tracecb(Context, _traceCb); QN.qn_set_tracecb(Context, _traceCb);

View File

@ -29,8 +29,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
public byte* QUERY_get_memory_data(SNES_MEMORY id) public byte* QUERY_get_memory_data(SNES_MEMORY id)
{ {
string name = QUERY_MemoryNameForId(id); string name = QUERY_MemoryNameForId(id);
IntPtr ret; _sharedMemoryBlocks.TryGetValue(name, out var ret);
_sharedMemoryBlocks.TryGetValue(name, out ret);
return (byte*)ret; return (byte*)ret;
} }

View File

@ -59,8 +59,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
Factory(ss.RightPort, ss) Factory(ss.RightPort, ss)
}; };
List<ControlDefUnMerger> tmp; Definition = ControllerDefinitionMerger.GetMerged(_ports.Select(p => p.Definition), out var tmp);
Definition = ControllerDefinitionMerger.GetMerged(_ports.Select(p => p.Definition), out tmp);
_mergers = tmp.ToArray(); _mergers = tmp.ToArray();
// add buttons that the core itself will handle // add buttons that the core itself will handle

View File

@ -552,8 +552,7 @@ namespace BizHawk.Emulation.Cores.PCEngine
// zero 07-jul-2015 - I may have broken this // zero 07-jul-2015 - I may have broken this
int totalLbaLength = disc.Session1.LeadoutLBA; int totalLbaLength = disc.Session1.LeadoutLBA;
byte m, s, f; DiscUtils.Convert_LBA_To_AMSF(totalLbaLength + 150, out var m, out var s, out var f);
DiscUtils.Convert_LBA_To_AMSF(totalLbaLength + 150, out m, out s, out f);
DataIn.Clear(); DataIn.Clear();
DataIn.Enqueue(m.BinToBCD()); DataIn.Enqueue(m.BinToBCD());
@ -577,8 +576,7 @@ namespace BizHawk.Emulation.Cores.PCEngine
else else
lbaPos = tracks[track].LBA; lbaPos = tracks[track].LBA;
byte m, s, f; DiscUtils.Convert_LBA_To_AMSF(lbaPos, out var m, out var s, out var f);
DiscUtils.Convert_LBA_To_AMSF(lbaPos, out m, out s, out f);
DataIn.Clear(); DataIn.Clear();
DataIn.Enqueue(m.BinToBCD()); DataIn.Enqueue(m.BinToBCD());

View File

@ -352,11 +352,8 @@ namespace BizHawk.Emulation.Cores.Sega.GGHawkLink
short[] temp_samp_L = new short[735 * 2]; short[] temp_samp_L = new short[735 * 2];
short[] temp_samp_R = new short[735 * 2]; short[] temp_samp_R = new short[735 * 2];
int nsamp_L = 735; L.GetSamplesSync(out temp_samp_L, out int nsamp_L);
int nsamp_R = 735; R.GetSamplesSync(out temp_samp_R, out int nsamp_R);
L.GetSamplesSync(out temp_samp_L, out nsamp_L);
R.GetSamplesSync(out temp_samp_R, out nsamp_L);
if (linkSettings.AudioSet == GGLinkSettings.AudioSrc.Left) if (linkSettings.AudioSet == GGLinkSettings.AudioSrc.Left)
{ {

View File

@ -49,9 +49,8 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.Saturn
.ToArray(); .ToArray();
_data = new byte[count * DataSize]; _data = new byte[count * DataSize];
List<ControlDefUnMerger> cdum;
Definition = ControllerDefinitionMerger.GetMerged(_devices.Select(d => d.Definition), Definition = ControllerDefinitionMerger.GetMerged(_devices.Select(d => d.Definition),
out cdum); out var cdum);
_unmerger = cdum.ToArray(); _unmerger = cdum.ToArray();
} }

View File

@ -90,8 +90,7 @@ namespace BizHawk.Emulation.Cores.Sony.PSX
if (discInterfaces.Count != 0) if (discInterfaces.Count != 0)
{ {
//determine region of one of the discs //determine region of one of the discs
OctoshockDll.ShockDiscInfo discInfo; OctoshockDll.shock_AnalyzeDisc(discInterfaces[0].OctoshockHandle, out var discInfo);
OctoshockDll.shock_AnalyzeDisc(discInterfaces[0].OctoshockHandle, out discInfo);
//try to acquire the appropriate firmware //try to acquire the appropriate firmware
if (discInfo.region == OctoshockDll.eRegion.EU) firmwareRegion = "E"; if (discInfo.region == OctoshockDll.eRegion.EU) firmwareRegion = "E";
@ -928,10 +927,8 @@ namespace BizHawk.Emulation.Cores.Sony.PSX
unsafe void SetMemoryDomains() unsafe void SetMemoryDomains()
{ {
var mmd = new List<MemoryDomain>(); var mmd = new List<MemoryDomain>();
IntPtr ptr;
int size;
OctoshockDll.shock_GetMemData(psx, out ptr, out size, OctoshockDll.eMemType.MainRAM); OctoshockDll.shock_GetMemData(psx, out var ptr, out var size, OctoshockDll.eMemType.MainRAM);
mmd.Add(new MemoryDomainIntPtr("MainRAM", MemoryDomain.Endian.Little, ptr, size, true, 4)); mmd.Add(new MemoryDomainIntPtr("MainRAM", MemoryDomain.Endian.Little, ptr, size, true, 4));
OctoshockDll.shock_GetMemData(psx, out ptr, out size, OctoshockDll.eMemType.GPURAM); OctoshockDll.shock_GetMemData(psx, out ptr, out size, OctoshockDll.eMemType.GPURAM);

View File

@ -167,8 +167,7 @@ namespace BizHawk.Emulation.Cores
if(job.Extension != null) if(job.Extension != null)
{ {
//first test everything associated with this extension //first test everything associated with this extension
ExtensionInfo handler = null; if (ExtensionHandlers.TryGetValue(ext, out var handler))
if (ExtensionHandlers.TryGetValue(ext, out handler))
{ {
foreach (var del in handler.Testers) foreach (var del in handler.Testers)
{ {

View File

@ -37,10 +37,8 @@ namespace BizHawk.Emulation.Cores.Sound
public void Fetch() public void Fetch()
{ {
int nsampl, nsampr; _left.GetSamplesSync(out var sampl, out int nsampl);
short[] sampl, sampr; _right.GetSamplesSync(out var sampr, out var nsampr);
_left.GetSamplesSync(out sampl, out nsampl);
_right.GetSamplesSync(out sampr, out nsampr);
int n = Math.Min(nsampl + _leftOverflowCount, nsampr + _rightOverflowCount); int n = Math.Min(nsampl + _leftOverflowCount, nsampr + _rightOverflowCount);

View File

@ -183,8 +183,7 @@ namespace BizHawk.Emulation.Cores.Components
void Part1_WriteRegister(byte register, byte value) void Part1_WriteRegister(byte register, byte value)
{ {
int chan, oper; GetChanOpP1(register, out var chan, out var oper);
GetChanOpP1(register, out chan, out oper);
switch (register & 0xF0) switch (register & 0xF0)
{ {
@ -203,8 +202,7 @@ namespace BizHawk.Emulation.Cores.Components
void Part2_WriteRegister(byte register, byte value) void Part2_WriteRegister(byte register, byte value)
{ {
int chan, oper; GetChanOpP2(register, out var chan, out var oper);
GetChanOpP2(register, out chan, out oper);
switch (register & 0xF0) switch (register & 0xF0)
{ {

View File

@ -511,8 +511,7 @@ namespace BizHawk.Emulation.Cores.Waterbox
[BizExport(CallingConvention.Cdecl, EntryPoint = "n2")] [BizExport(CallingConvention.Cdecl, EntryPoint = "n2")]
public int Open(string path, int flags, int mode) public int Open(string path, int flags, int mode)
{ {
IFileObject o; if (!_availableFiles.TryGetValue(path, out var o))
if (!_availableFiles.TryGetValue(path, out o))
return -1; return -1;
if (_openFiles.Contains(o)) if (_openFiles.Contains(o))
return -1; return -1;
@ -760,8 +759,7 @@ namespace BizHawk.Emulation.Cores.Waterbox
private T RemoveFileInternal<T>(string name) private T RemoveFileInternal<T>(string name)
where T : IFileObject where T : IFileObject
{ {
IFileObject o; if (!_availableFiles.TryGetValue(name, out var o))
if (!_availableFiles.TryGetValue(name, out o))
throw new InvalidOperationException("File was never registered!"); throw new InvalidOperationException("File was never registered!");
if (o.GetType() != typeof(T)) if (o.GetType() != typeof(T))
throw new InvalidOperationException("Object was not a the right kind of file"); throw new InvalidOperationException("Object was not a the right kind of file");
@ -1107,8 +1105,7 @@ namespace BizHawk.Emulation.Cores.Waterbox
// but it breaks xor state verification, so when we seal, nuke it. // but it breaks xor state verification, so when we seal, nuke it.
// this could be the responsibility of something else other than the PeRunner; I am not sure yet... // this could be the responsibility of something else other than the PeRunner; I am not sure yet...
IImportResolver libco; if (_exports.TryGetValue("libco.so", out var libco))
if (_exports.TryGetValue("libco.so", out libco))
{ {
Console.WriteLine("Calling co_clean()..."); Console.WriteLine("Calling co_clean()...");
CallingConventionAdapters.Waterbox.GetDelegateForFunctionPointer<Action>(libco.GetProcAddrOrThrow("co_clean"))(); CallingConventionAdapters.Waterbox.GetDelegateForFunctionPointer<Action>(libco.GetProcAddrOrThrow("co_clean"))();

View File

@ -247,8 +247,7 @@ namespace BizHawk.Emulation.Cores.Waterbox
// NB: Hints are not the same as Ordinals // NB: Hints are not the same as Ordinals
foreach (var import in _pe.ImportedFunctions) foreach (var import in _pe.ImportedFunctions)
{ {
Dictionary<string, IntPtr> module; if (!ImportsByModule.TryGetValue(import.DLL, out var module))
if (!ImportsByModule.TryGetValue(import.DLL, out module))
{ {
module = new Dictionary<string, IntPtr>(); module = new Dictionary<string, IntPtr>();
ImportsByModule.Add(import.DLL, module); ImportsByModule.Add(import.DLL, module);
@ -260,8 +259,7 @@ namespace BizHawk.Emulation.Cores.Waterbox
module.Add(import.Name, Z.US(dest)); module.Add(import.Name, Z.US(dest));
} }
Section midipix; if (_sectionsByName.TryGetValue(".midipix", out Section midipix))
if (_sectionsByName.TryGetValue(".midipix", out midipix))
{ {
var dataOffset = midipix.DiskStart; var dataOffset = midipix.DiskStart;
CtorList = Z.SS(BitConverter.ToInt64(fileData, (int)(dataOffset + 0x30)) + LoadOffset); CtorList = Z.SS(BitConverter.ToInt64(fileData, (int)(dataOffset + 0x30)) + LoadOffset);
@ -313,8 +311,7 @@ namespace BizHawk.Emulation.Cores.Waterbox
if (_everythingSealed && _imports != null) if (_everythingSealed && _imports != null)
Memory.Protect(_imports.Start, _imports.Size, MemoryBlockBase.Protection.RW); Memory.Protect(_imports.Start, _imports.Size, MemoryBlockBase.Protection.RW);
Dictionary<string, IntPtr> imports; if (ImportsByModule.TryGetValue(moduleName, out var imports))
if (ImportsByModule.TryGetValue(moduleName, out imports))
{ {
foreach (var kvp in imports) foreach (var kvp in imports)
{ {