more misc cleanup and removing some usings that should have been removed when moving things from one project to another

This commit is contained in:
adelikat 2013-11-15 01:52:03 +00:00
parent 00308de99a
commit e606429219
23 changed files with 1687 additions and 1716 deletions

View File

@ -2,115 +2,115 @@
namespace BizHawk.Emulation.Common.Components.M68000 namespace BizHawk.Emulation.Common.Components.M68000
{ {
public sealed class DisassemblyInfo public sealed class DisassemblyInfo
{ {
public int PC; public int PC;
public string Mnemonic; public string Mnemonic;
public string Args; public string Args;
public string RawBytes; public string RawBytes;
public int Length; public int Length;
public override string ToString() public override string ToString()
{ {
return string.Format("{0:X6}: {3,-20} {1,-8} {2}", PC, Mnemonic, Args, RawBytes); return string.Format("{0:X6}: {3,-20} {1,-8} {2}", PC, Mnemonic, Args, RawBytes);
} }
} }
partial class MC68000 partial class MC68000
{ {
public DisassemblyInfo Disassemble(int pc) public DisassemblyInfo Disassemble(int pc)
{ {
var info = new DisassemblyInfo { Mnemonic = "UNKNOWN", PC = pc, Length = 2 }; var info = new DisassemblyInfo { Mnemonic = "UNKNOWN", PC = pc, Length = 2 };
op = (ushort)ReadWord(pc); op = (ushort)ReadWord(pc);
if (Opcodes[op] == MOVE) MOVE_Disasm(info); if (Opcodes[op] == MOVE) MOVE_Disasm(info);
else if (Opcodes[op] == MOVEA) MOVEA_Disasm(info); else if (Opcodes[op] == MOVEA) MOVEA_Disasm(info);
else if (Opcodes[op] == MOVEQ) MOVEQ_Disasm(info); else if (Opcodes[op] == MOVEQ) MOVEQ_Disasm(info);
else if (Opcodes[op] == MOVEM0) MOVEM0_Disasm(info); else if (Opcodes[op] == MOVEM0) MOVEM0_Disasm(info);
else if (Opcodes[op] == MOVEM1) MOVEM1_Disasm(info); else if (Opcodes[op] == MOVEM1) MOVEM1_Disasm(info);
else if (Opcodes[op] == LEA) LEA_Disasm(info); else if (Opcodes[op] == LEA) LEA_Disasm(info);
else if (Opcodes[op] == CLR) CLR_Disasm(info); else if (Opcodes[op] == CLR) CLR_Disasm(info);
else if (Opcodes[op] == EXT) EXT_Disasm(info); else if (Opcodes[op] == EXT) EXT_Disasm(info);
else if (Opcodes[op] == PEA) PEA_Disasm(info); else if (Opcodes[op] == PEA) PEA_Disasm(info);
else if (Opcodes[op] == ANDI) ANDI_Disasm(info); else if (Opcodes[op] == ANDI) ANDI_Disasm(info);
else if (Opcodes[op] == EORI) EORI_Disasm(info); else if (Opcodes[op] == EORI) EORI_Disasm(info);
else if (Opcodes[op] == ORI) ORI_Disasm(info); else if (Opcodes[op] == ORI) ORI_Disasm(info);
else if (Opcodes[op] == ASLd) ASLd_Disasm(info); else if (Opcodes[op] == ASLd) ASLd_Disasm(info);
else if (Opcodes[op] == ASRd) ASRd_Disasm(info); else if (Opcodes[op] == ASRd) ASRd_Disasm(info);
else if (Opcodes[op] == LSLd) LSLd_Disasm(info); else if (Opcodes[op] == LSLd) LSLd_Disasm(info);
else if (Opcodes[op] == LSRd) LSRd_Disasm(info); else if (Opcodes[op] == LSRd) LSRd_Disasm(info);
else if (Opcodes[op] == ROXLd) ROXLd_Disasm(info); else if (Opcodes[op] == ROXLd) ROXLd_Disasm(info);
else if (Opcodes[op] == ROXRd) ROXRd_Disasm(info); else if (Opcodes[op] == ROXRd) ROXRd_Disasm(info);
else if (Opcodes[op] == ROLd) ROLd_Disasm(info); else if (Opcodes[op] == ROLd) ROLd_Disasm(info);
else if (Opcodes[op] == RORd) RORd_Disasm(info); else if (Opcodes[op] == RORd) RORd_Disasm(info);
else if (Opcodes[op] == SWAP) SWAP_Disasm(info); else if (Opcodes[op] == SWAP) SWAP_Disasm(info);
else if (Opcodes[op] == AND0) AND0_Disasm(info); else if (Opcodes[op] == AND0) AND0_Disasm(info);
else if (Opcodes[op] == AND1) AND1_Disasm(info); else if (Opcodes[op] == AND1) AND1_Disasm(info);
else if (Opcodes[op] == EOR) EOR_Disasm(info); else if (Opcodes[op] == EOR) EOR_Disasm(info);
else if (Opcodes[op] == OR0) OR0_Disasm(info); else if (Opcodes[op] == OR0) OR0_Disasm(info);
else if (Opcodes[op] == OR1) OR1_Disasm(info); else if (Opcodes[op] == OR1) OR1_Disasm(info);
else if (Opcodes[op] == NOT) NOT_Disasm(info); else if (Opcodes[op] == NOT) NOT_Disasm(info);
else if (Opcodes[op] == NEG) NEG_Disasm(info); else if (Opcodes[op] == NEG) NEG_Disasm(info);
else if (Opcodes[op] == JMP) JMP_Disasm(info); else if (Opcodes[op] == JMP) JMP_Disasm(info);
else if (Opcodes[op] == JSR) JSR_Disasm(info); else if (Opcodes[op] == JSR) JSR_Disasm(info);
else if (Opcodes[op] == Bcc) Bcc_Disasm(info); else if (Opcodes[op] == Bcc) Bcc_Disasm(info);
else if (Opcodes[op] == BRA) BRA_Disasm(info); else if (Opcodes[op] == BRA) BRA_Disasm(info);
else if (Opcodes[op] == BSR) BSR_Disasm(info); else if (Opcodes[op] == BSR) BSR_Disasm(info);
else if (Opcodes[op] == DBcc) DBcc_Disasm(info); else if (Opcodes[op] == DBcc) DBcc_Disasm(info);
else if (Opcodes[op] == Scc) Scc_Disasm(info); else if (Opcodes[op] == Scc) Scc_Disasm(info);
else if (Opcodes[op] == RTE) RTE_Disasm(info); else if (Opcodes[op] == RTE) RTE_Disasm(info);
else if (Opcodes[op] == RTS) RTS_Disasm(info); else if (Opcodes[op] == RTS) RTS_Disasm(info);
else if (Opcodes[op] == RTR) RTR_Disasm(info); else if (Opcodes[op] == RTR) RTR_Disasm(info);
else if (Opcodes[op] == TST) TST_Disasm(info); else if (Opcodes[op] == TST) TST_Disasm(info);
else if (Opcodes[op] == BTSTi) BTSTi_Disasm(info); else if (Opcodes[op] == BTSTi) BTSTi_Disasm(info);
else if (Opcodes[op] == BTSTr) BTSTr_Disasm(info); else if (Opcodes[op] == BTSTr) BTSTr_Disasm(info);
else if (Opcodes[op] == BCHGi) BCHGi_Disasm(info); else if (Opcodes[op] == BCHGi) BCHGi_Disasm(info);
else if (Opcodes[op] == BCHGr) BCHGr_Disasm(info); else if (Opcodes[op] == BCHGr) BCHGr_Disasm(info);
else if (Opcodes[op] == BCLRi) BCLRi_Disasm(info); else if (Opcodes[op] == BCLRi) BCLRi_Disasm(info);
else if (Opcodes[op] == BCLRr) BCLRr_Disasm(info); else if (Opcodes[op] == BCLRr) BCLRr_Disasm(info);
else if (Opcodes[op] == BSETi) BSETi_Disasm(info); else if (Opcodes[op] == BSETi) BSETi_Disasm(info);
else if (Opcodes[op] == BSETr) BSETr_Disasm(info); else if (Opcodes[op] == BSETr) BSETr_Disasm(info);
else if (Opcodes[op] == LINK) LINK_Disasm(info); else if (Opcodes[op] == LINK) LINK_Disasm(info);
else if (Opcodes[op] == UNLK) UNLK_Disasm(info); else if (Opcodes[op] == UNLK) UNLK_Disasm(info);
else if (Opcodes[op] == NOP) NOP_Disasm(info); else if (Opcodes[op] == NOP) NOP_Disasm(info);
else if (Opcodes[op] == ADD0) ADD_Disasm(info); else if (Opcodes[op] == ADD0) ADD_Disasm(info);
else if (Opcodes[op] == ADD1) ADD_Disasm(info); else if (Opcodes[op] == ADD1) ADD_Disasm(info);
else if (Opcodes[op] == ADDA) ADDA_Disasm(info); else if (Opcodes[op] == ADDA) ADDA_Disasm(info);
else if (Opcodes[op] == ADDI) ADDI_Disasm(info); else if (Opcodes[op] == ADDI) ADDI_Disasm(info);
else if (Opcodes[op] == ADDQ) ADDQ_Disasm(info); else if (Opcodes[op] == ADDQ) ADDQ_Disasm(info);
else if (Opcodes[op] == SUB0) SUB_Disasm(info); else if (Opcodes[op] == SUB0) SUB_Disasm(info);
else if (Opcodes[op] == SUB1) SUB_Disasm(info); else if (Opcodes[op] == SUB1) SUB_Disasm(info);
else if (Opcodes[op] == SUBA) SUBA_Disasm(info); else if (Opcodes[op] == SUBA) SUBA_Disasm(info);
else if (Opcodes[op] == SUBI) SUBI_Disasm(info); else if (Opcodes[op] == SUBI) SUBI_Disasm(info);
else if (Opcodes[op] == SUBQ) SUBQ_Disasm(info); else if (Opcodes[op] == SUBQ) SUBQ_Disasm(info);
else if (Opcodes[op] == CMP) CMP_Disasm(info); else if (Opcodes[op] == CMP) CMP_Disasm(info);
else if (Opcodes[op] == CMPM) CMPM_Disasm(info); else if (Opcodes[op] == CMPM) CMPM_Disasm(info);
else if (Opcodes[op] == CMPA) CMPA_Disasm(info); else if (Opcodes[op] == CMPA) CMPA_Disasm(info);
else if (Opcodes[op] == CMPI) CMPI_Disasm(info); else if (Opcodes[op] == CMPI) CMPI_Disasm(info);
else if (Opcodes[op] == MULU) MULU_Disasm(info); else if (Opcodes[op] == MULU) MULU_Disasm(info);
else if (Opcodes[op] == MULS) MULS_Disasm(info); else if (Opcodes[op] == MULS) MULS_Disasm(info);
else if (Opcodes[op] == DIVU) DIVU_Disasm(info); else if (Opcodes[op] == DIVU) DIVU_Disasm(info);
else if (Opcodes[op] == DIVS) DIVS_Disasm(info); else if (Opcodes[op] == DIVS) DIVS_Disasm(info);
else if (Opcodes[op] == MOVEtSR) MOVEtSR_Disasm(info); else if (Opcodes[op] == MOVEtSR) MOVEtSR_Disasm(info);
else if (Opcodes[op] == MOVEfSR) MOVEfSR_Disasm(info); else if (Opcodes[op] == MOVEfSR) MOVEfSR_Disasm(info);
else if (Opcodes[op] == MOVEUSP) MOVEUSP_Disasm(info); else if (Opcodes[op] == MOVEUSP) MOVEUSP_Disasm(info);
else if (Opcodes[op] == ANDI_SR) ANDI_SR_Disasm(info); else if (Opcodes[op] == ANDI_SR) ANDI_SR_Disasm(info);
else if (Opcodes[op] == EORI_SR) EORI_SR_Disasm(info); else if (Opcodes[op] == EORI_SR) EORI_SR_Disasm(info);
else if (Opcodes[op] == ORI_SR) ORI_SR_Disasm(info); else if (Opcodes[op] == ORI_SR) ORI_SR_Disasm(info);
else if (Opcodes[op] == MOVECCR) MOVECCR_Disasm(info); else if (Opcodes[op] == MOVECCR) MOVECCR_Disasm(info);
else if (Opcodes[op] == TRAP) TRAP_Disasm(info); else if (Opcodes[op] == TRAP) TRAP_Disasm(info);
var sb = new StringBuilder(); var sb = new StringBuilder();
for (int p = info.PC; p < info.PC + info.Length; p++) for (int p = info.PC; p < info.PC + info.Length; p++)
sb.AppendFormat("{0:X2}", ReadByte(p)); sb.AppendFormat("{0:X2}", ReadByte(p));
info.RawBytes = sb.ToString(); info.RawBytes = sb.ToString();
return info; return info;
} }
} }
} }

View File

@ -10,7 +10,7 @@ namespace BizHawk.Emulation.Common.Components.CP1610
private bool FlagS, FlagC, FlagZ, FlagO, FlagI, FlagD, IntRM, BusRq, BusAk, Interruptible, Interrupted; private bool FlagS, FlagC, FlagZ, FlagO, FlagI, FlagD, IntRM, BusRq, BusAk, Interruptible, Interrupted;
//private bool MSync; //private bool MSync;
private ushort[] Register = new ushort[8]; private readonly ushort[] Register = new ushort[8];
private ushort RegisterSP { get { return Register[6]; } set { Register[6] = value; } } private ushort RegisterSP { get { return Register[6]; } set { Register[6] = value; } }
private ushort RegisterPC { get { return Register[7]; } set { Register[7] = value; } } private ushort RegisterPC { get { return Register[7]; } set { Register[7] = value; } }
@ -21,7 +21,7 @@ namespace BizHawk.Emulation.Common.Components.CP1610
public Func<ushort, ushort, bool> WriteMemory; public Func<ushort, ushort, bool> WriteMemory;
private static bool Logging = true; private static bool Logging = true;
private static StreamWriter Log; private static readonly StreamWriter Log;
static CP1610() static CP1610()
{ {

View File

@ -185,7 +185,7 @@ namespace BizHawk.Emulation.Common.Components.CP1610
// Unknown opcode. // Unknown opcode.
throw new ArgumentException(); throw new ArgumentException();
} }
RegisterPC = (ushort)addr; RegisterPC = addr;
cycles = 12; cycles = 12;
Interruptible = true; Interruptible = true;
break; break;

View File

@ -6,398 +6,398 @@ using BizHawk.Common;
namespace BizHawk.Emulation.Common.Components.H6280 namespace BizHawk.Emulation.Common.Components.H6280
{ {
public sealed partial class HuC6280 public sealed partial class HuC6280
{ {
public HuC6280() public HuC6280()
{ {
Reset(); Reset();
} }
public void Reset() public void Reset()
{ {
A = 0; A = 0;
X = 0; X = 0;
Y = 0; Y = 0;
//P = 0x14; // Set I and B //P = 0x14; // Set I and B
P = 0x04; // Set I P = 0x04; // Set I
S = 0; S = 0;
PC = 0; PC = 0;
PendingCycles = 0; PendingCycles = 0;
TotalExecutedCycles = 0; TotalExecutedCycles = 0;
LagIFlag = true; LagIFlag = true;
LowSpeed = true; LowSpeed = true;
} }
public void ResetPC() public void ResetPC()
{ {
PC = ReadWord(ResetVector); PC = ReadWord(ResetVector);
} }
// ==== CPU State ==== // ==== CPU State ====
public byte A; public byte A;
public byte X; public byte X;
public byte Y; public byte Y;
public byte P; public byte P;
public ushort PC; public ushort PC;
public byte S; public byte S;
public byte[] MPR = new byte[8]; public byte[] MPR = new byte[8];
public bool LagIFlag; public bool LagIFlag;
public bool IRQ1Assert; public bool IRQ1Assert;
public bool IRQ2Assert; public bool IRQ2Assert;
public bool TimerAssert; public bool TimerAssert;
public byte IRQControlByte, IRQNextControlByte; public byte IRQControlByte, IRQNextControlByte;
public long TotalExecutedCycles; public long TotalExecutedCycles;
public int PendingCycles; public int PendingCycles;
public bool LowSpeed; public bool LowSpeed;
private bool InBlockTransfer = false; private bool InBlockTransfer = false;
private ushort btFrom; private ushort btFrom;
private ushort btTo; private ushort btTo;
private ushort btLen; private ushort btLen;
private int btAlternator; private int btAlternator;
// -- Timer Support -- // -- Timer Support --
public int TimerTickCounter; public int TimerTickCounter;
public byte TimerReloadValue; public byte TimerReloadValue;
public byte TimerValue; public byte TimerValue;
public bool TimerEnabled; public bool TimerEnabled;
public void SaveStateText(TextWriter writer) public void SaveStateText(TextWriter writer)
{ {
writer.WriteLine("[HuC6280]"); writer.WriteLine("[HuC6280]");
writer.WriteLine("A {0:X2}", A); writer.WriteLine("A {0:X2}", A);
writer.WriteLine("X {0:X2}", X); writer.WriteLine("X {0:X2}", X);
writer.WriteLine("Y {0:X2}", Y); writer.WriteLine("Y {0:X2}", Y);
writer.WriteLine("P {0:X2}", P); writer.WriteLine("P {0:X2}", P);
writer.WriteLine("PC {0:X4}", PC); writer.WriteLine("PC {0:X4}", PC);
writer.WriteLine("S {0:X2}", S); writer.WriteLine("S {0:X2}", S);
writer.Write("MPR "); writer.Write("MPR ");
MPR.SaveAsHex(writer); MPR.SaveAsHex(writer);
writer.WriteLine("LagIFlag {0}", LagIFlag); writer.WriteLine("LagIFlag {0}", LagIFlag);
writer.WriteLine("IRQ1Assert {0}", IRQ1Assert); writer.WriteLine("IRQ1Assert {0}", IRQ1Assert);
writer.WriteLine("IRQ2Assert {0}", IRQ2Assert); writer.WriteLine("IRQ2Assert {0}", IRQ2Assert);
writer.WriteLine("TimerAssert {0}", TimerAssert); writer.WriteLine("TimerAssert {0}", TimerAssert);
writer.WriteLine("IRQControlByte {0:X2}", IRQControlByte); writer.WriteLine("IRQControlByte {0:X2}", IRQControlByte);
writer.WriteLine("IRQNextControlByte {0:X2}", IRQNextControlByte); writer.WriteLine("IRQNextControlByte {0:X2}", IRQNextControlByte);
writer.WriteLine("ExecutedCycles {0}", TotalExecutedCycles); writer.WriteLine("ExecutedCycles {0}", TotalExecutedCycles);
writer.WriteLine("PendingCycles {0}", PendingCycles); writer.WriteLine("PendingCycles {0}", PendingCycles);
writer.WriteLine("LowSpeed {0}", LowSpeed); writer.WriteLine("LowSpeed {0}", LowSpeed);
writer.WriteLine("TimerTickCounter {0}", TimerTickCounter); writer.WriteLine("TimerTickCounter {0}", TimerTickCounter);
writer.WriteLine("TimerReloadValue {0}", TimerReloadValue); writer.WriteLine("TimerReloadValue {0}", TimerReloadValue);
writer.WriteLine("TimerValue {0}", TimerValue); writer.WriteLine("TimerValue {0}", TimerValue);
writer.WriteLine("TimerEnabled {0}", TimerEnabled); writer.WriteLine("TimerEnabled {0}", TimerEnabled);
writer.WriteLine("InBlockTransfer {0}", InBlockTransfer); writer.WriteLine("InBlockTransfer {0}", InBlockTransfer);
writer.WriteLine("BTFrom {0}", btFrom); writer.WriteLine("BTFrom {0}", btFrom);
writer.WriteLine("BTTo {0}", btTo); writer.WriteLine("BTTo {0}", btTo);
writer.WriteLine("BTLen {0}", btLen); writer.WriteLine("BTLen {0}", btLen);
writer.WriteLine("BTAlternator {0}", btAlternator); writer.WriteLine("BTAlternator {0}", btAlternator);
writer.WriteLine("[/HuC6280]\n"); writer.WriteLine("[/HuC6280]\n");
} }
public void LoadStateText(TextReader reader) public void LoadStateText(TextReader reader)
{ {
while (true) while (true)
{ {
string[] args = reader.ReadLine().Split(' '); string[] args = reader.ReadLine().Split(' ');
if (args[0].Trim() == "") continue; if (args[0].Trim() == "") continue;
if (args[0] == "[/HuC6280]") break; if (args[0] == "[/HuC6280]") break;
if (args[0] == "A") if (args[0] == "A")
A = byte.Parse(args[1], NumberStyles.HexNumber); A = byte.Parse(args[1], NumberStyles.HexNumber);
else if (args[0] == "X") else if (args[0] == "X")
X = byte.Parse(args[1], NumberStyles.HexNumber); X = byte.Parse(args[1], NumberStyles.HexNumber);
else if (args[0] == "Y") else if (args[0] == "Y")
Y = byte.Parse(args[1], NumberStyles.HexNumber); Y = byte.Parse(args[1], NumberStyles.HexNumber);
else if (args[0] == "P") else if (args[0] == "P")
P = byte.Parse(args[1], NumberStyles.HexNumber); P = byte.Parse(args[1], NumberStyles.HexNumber);
else if (args[0] == "PC") else if (args[0] == "PC")
PC = ushort.Parse(args[1], NumberStyles.HexNumber); PC = ushort.Parse(args[1], NumberStyles.HexNumber);
else if (args[0] == "S") else if (args[0] == "S")
S = byte.Parse(args[1], NumberStyles.HexNumber); S = byte.Parse(args[1], NumberStyles.HexNumber);
else if (args[0] == "MPR") else if (args[0] == "MPR")
MPR.ReadFromHex(args[1]); MPR.ReadFromHex(args[1]);
else if (args[0] == "LagIFlag") else if (args[0] == "LagIFlag")
LagIFlag = bool.Parse(args[1]); LagIFlag = bool.Parse(args[1]);
else if (args[0] == "IRQ1Assert") else if (args[0] == "IRQ1Assert")
IRQ1Assert = bool.Parse(args[1]); IRQ1Assert = bool.Parse(args[1]);
else if (args[0] == "IRQ2Assert") else if (args[0] == "IRQ2Assert")
IRQ2Assert = bool.Parse(args[1]); IRQ2Assert = bool.Parse(args[1]);
else if (args[0] == "TimerAssert") else if (args[0] == "TimerAssert")
TimerAssert = bool.Parse(args[1]); TimerAssert = bool.Parse(args[1]);
else if (args[0] == "IRQControlByte") else if (args[0] == "IRQControlByte")
IRQControlByte = byte.Parse(args[1], NumberStyles.HexNumber); IRQControlByte = byte.Parse(args[1], NumberStyles.HexNumber);
else if (args[0] == "IRQNextControlByte") else if (args[0] == "IRQNextControlByte")
IRQNextControlByte = byte.Parse(args[1], NumberStyles.HexNumber); IRQNextControlByte = byte.Parse(args[1], NumberStyles.HexNumber);
else if (args[0] == "ExecutedCycles") else if (args[0] == "ExecutedCycles")
TotalExecutedCycles = long.Parse(args[1]); TotalExecutedCycles = long.Parse(args[1]);
else if (args[0] == "PendingCycles") else if (args[0] == "PendingCycles")
PendingCycles = int.Parse(args[1]); PendingCycles = int.Parse(args[1]);
else if (args[0] == "LowSpeed") else if (args[0] == "LowSpeed")
LowSpeed = bool.Parse(args[1]); LowSpeed = bool.Parse(args[1]);
else if (args[0] == "TimerTickCounter") else if (args[0] == "TimerTickCounter")
TimerTickCounter = int.Parse(args[1]); TimerTickCounter = int.Parse(args[1]);
else if (args[0] == "TimerReloadValue") else if (args[0] == "TimerReloadValue")
TimerReloadValue = byte.Parse(args[1]); TimerReloadValue = byte.Parse(args[1]);
else if (args[0] == "TimerValue") else if (args[0] == "TimerValue")
TimerValue = byte.Parse(args[1]); TimerValue = byte.Parse(args[1]);
else if (args[0] == "TimerEnabled") else if (args[0] == "TimerEnabled")
TimerEnabled = bool.Parse(args[1]); TimerEnabled = bool.Parse(args[1]);
else if (args[0] == "InBlockTransfer") else if (args[0] == "InBlockTransfer")
InBlockTransfer = bool.Parse(args[1]); InBlockTransfer = bool.Parse(args[1]);
else if (args[0] == "BTFrom") else if (args[0] == "BTFrom")
btFrom = ushort.Parse(args[1]); btFrom = ushort.Parse(args[1]);
else if (args[0] == "BTTo") else if (args[0] == "BTTo")
btTo = ushort.Parse(args[1]); btTo = ushort.Parse(args[1]);
else if (args[0] == "BTLen") else if (args[0] == "BTLen")
btLen = ushort.Parse(args[1]); btLen = ushort.Parse(args[1]);
else if (args[0] == "BTAlternator") else if (args[0] == "BTAlternator")
btAlternator = int.Parse(args[1]); btAlternator = int.Parse(args[1]);
else else
Console.WriteLine("Skipping unrecognized identifier " + args[0]); Console.WriteLine("Skipping unrecognized identifier " + args[0]);
} }
} }
public void SaveStateBinary(BinaryWriter writer) public void SaveStateBinary(BinaryWriter writer)
{ {
writer.Write(A); writer.Write(A);
writer.Write(X); writer.Write(X);
writer.Write(Y); writer.Write(Y);
writer.Write(P); writer.Write(P);
writer.Write(PC); writer.Write(PC);
writer.Write(S); writer.Write(S);
writer.Write(MPR); writer.Write(MPR);
writer.Write(LagIFlag); writer.Write(LagIFlag);
writer.Write(IRQ1Assert); writer.Write(IRQ1Assert);
writer.Write(IRQ2Assert); writer.Write(IRQ2Assert);
writer.Write(TimerAssert); writer.Write(TimerAssert);
writer.Write(IRQControlByte); writer.Write(IRQControlByte);
writer.Write(IRQNextControlByte); writer.Write(IRQNextControlByte);
writer.Write(TotalExecutedCycles); writer.Write(TotalExecutedCycles);
writer.Write(PendingCycles); writer.Write(PendingCycles);
writer.Write(LowSpeed); writer.Write(LowSpeed);
writer.Write(TimerTickCounter); writer.Write(TimerTickCounter);
writer.Write(TimerReloadValue); writer.Write(TimerReloadValue);
writer.Write(TimerValue); writer.Write(TimerValue);
writer.Write(TimerEnabled); writer.Write(TimerEnabled);
writer.Write(InBlockTransfer); writer.Write(InBlockTransfer);
writer.Write(btFrom); writer.Write(btFrom);
writer.Write(btTo); writer.Write(btTo);
writer.Write(btLen); writer.Write(btLen);
writer.Write((byte)btAlternator); writer.Write((byte)btAlternator);
} }
public void LoadStateBinary(BinaryReader reader) public void LoadStateBinary(BinaryReader reader)
{ {
A = reader.ReadByte(); A = reader.ReadByte();
X = reader.ReadByte(); X = reader.ReadByte();
Y = reader.ReadByte(); Y = reader.ReadByte();
P = reader.ReadByte(); P = reader.ReadByte();
PC = reader.ReadUInt16(); PC = reader.ReadUInt16();
S = reader.ReadByte(); S = reader.ReadByte();
MPR = reader.ReadBytes(8); MPR = reader.ReadBytes(8);
LagIFlag = reader.ReadBoolean(); LagIFlag = reader.ReadBoolean();
IRQ1Assert = reader.ReadBoolean(); IRQ1Assert = reader.ReadBoolean();
IRQ2Assert = reader.ReadBoolean(); IRQ2Assert = reader.ReadBoolean();
TimerAssert = reader.ReadBoolean(); TimerAssert = reader.ReadBoolean();
IRQControlByte = reader.ReadByte(); IRQControlByte = reader.ReadByte();
IRQNextControlByte = reader.ReadByte(); IRQNextControlByte = reader.ReadByte();
TotalExecutedCycles = reader.ReadInt64(); TotalExecutedCycles = reader.ReadInt64();
PendingCycles = reader.ReadInt32(); PendingCycles = reader.ReadInt32();
LowSpeed = reader.ReadBoolean(); LowSpeed = reader.ReadBoolean();
TimerTickCounter = reader.ReadInt32(); TimerTickCounter = reader.ReadInt32();
TimerReloadValue = reader.ReadByte(); TimerReloadValue = reader.ReadByte();
TimerValue = reader.ReadByte(); TimerValue = reader.ReadByte();
TimerEnabled = reader.ReadBoolean(); TimerEnabled = reader.ReadBoolean();
InBlockTransfer = reader.ReadBoolean(); InBlockTransfer = reader.ReadBoolean();
btFrom = reader.ReadUInt16(); btFrom = reader.ReadUInt16();
btTo = reader.ReadUInt16(); btTo = reader.ReadUInt16();
btLen = reader.ReadUInt16(); btLen = reader.ReadUInt16();
btAlternator = reader.ReadByte(); btAlternator = reader.ReadByte();
} }
// ==== Interrupts ==== // ==== Interrupts ====
private const ushort ResetVector = 0xFFFE; private const ushort ResetVector = 0xFFFE;
private const ushort NMIVector = 0xFFFC; private const ushort NMIVector = 0xFFFC;
private const ushort TimerVector = 0xFFFA; private const ushort TimerVector = 0xFFFA;
private const ushort IRQ1Vector = 0xFFF8; private const ushort IRQ1Vector = 0xFFF8;
private const ushort IRQ2Vector = 0xFFF6; private const ushort IRQ2Vector = 0xFFF6;
private const byte IRQ2Selector = 0x01; private const byte IRQ2Selector = 0x01;
private const byte IRQ1Selector = 0x02; private const byte IRQ1Selector = 0x02;
private const byte TimerSelector = 0x04; private const byte TimerSelector = 0x04;
public void WriteIrqControl(byte value) public void WriteIrqControl(byte value)
{ {
// There is a single-instruction delay before writes to the IRQ Control Byte take effect. // There is a single-instruction delay before writes to the IRQ Control Byte take effect.
value &= 7; value &= 7;
IRQNextControlByte = value; IRQNextControlByte = value;
} }
public void WriteIrqStatus() public void WriteIrqStatus()
{ {
TimerAssert = false; TimerAssert = false;
} }
public byte ReadIrqStatus() public byte ReadIrqStatus()
{ {
byte status = 0; byte status = 0;
if (IRQ2Assert) status |= 1; if (IRQ2Assert) status |= 1;
if (IRQ1Assert) status |= 2; if (IRQ1Assert) status |= 2;
if (TimerAssert) status |= 4; if (TimerAssert) status |= 4;
return status; return status;
} }
public void WriteTimer(byte value) public void WriteTimer(byte value)
{ {
value &= 0x7F; value &= 0x7F;
TimerReloadValue = value; TimerReloadValue = value;
} }
public void WriteTimerEnable(byte value) public void WriteTimerEnable(byte value)
{ {
if (TimerEnabled == false && (value & 1) == 1) if (TimerEnabled == false && (value & 1) == 1)
{ {
TimerValue = TimerReloadValue; // timer value is reset when toggled from off to on TimerValue = TimerReloadValue; // timer value is reset when toggled from off to on
TimerTickCounter = 0; TimerTickCounter = 0;
} }
TimerEnabled = (value & 1) == 1; TimerEnabled = (value & 1) == 1;
} }
public byte ReadTimerValue() public byte ReadTimerValue()
{ {
if (TimerTickCounter + 5 > 1024) if (TimerTickCounter + 5 > 1024)
{ {
// There exists a slight delay between when the timer counter is decremented and when // There exists a slight delay between when the timer counter is decremented and when
// the interrupt fires; games can detect it, so we hack it this way. // the interrupt fires; games can detect it, so we hack it this way.
return (byte) ((TimerValue - 1) & 0x7F); return (byte)((TimerValue - 1) & 0x7F);
} }
return TimerValue; return TimerValue;
} }
// ==== Flags ==== // ==== Flags ====
/// <summary>Carry Flag</summary> /// <summary>Carry Flag</summary>
private bool FlagC private bool FlagC
{ {
get { return (P & 0x01) != 0; } get { return (P & 0x01) != 0; }
set { P = (byte)((P & ~0x01) | (value ? 0x01 : 0x00)); } set { P = (byte)((P & ~0x01) | (value ? 0x01 : 0x00)); }
} }
/// <summary>Zero Flag</summary> /// <summary>Zero Flag</summary>
private bool FlagZ private bool FlagZ
{ {
get { return (P & 0x02) != 0; } get { return (P & 0x02) != 0; }
set { P = (byte)((P & ~0x02) | (value ? 0x02 : 0x00)); } set { P = (byte)((P & ~0x02) | (value ? 0x02 : 0x00)); }
} }
/// <summary>Interrupt Disable Flag</summary> /// <summary>Interrupt Disable Flag</summary>
private bool FlagI private bool FlagI
{ {
get { return (P & 0x04) != 0; } get { return (P & 0x04) != 0; }
set { P = (byte)((P & ~0x04) | (value ? 0x04 : 0x00)); } set { P = (byte)((P & ~0x04) | (value ? 0x04 : 0x00)); }
} }
/// <summary>Decimal Mode Flag</summary> /// <summary>Decimal Mode Flag</summary>
private bool FlagD private bool FlagD
{ {
get { return (P & 0x08) != 0; } get { return (P & 0x08) != 0; }
set { P = (byte)((P & ~0x08) | (value ? 0x08 : 0x00)); } set { P = (byte)((P & ~0x08) | (value ? 0x08 : 0x00)); }
} }
/// <summary>Break Flag</summary> /// <summary>Break Flag</summary>
private bool FlagB private bool FlagB
{ {
get { return (P & 0x10) != 0; } get { return (P & 0x10) != 0; }
set { P = (byte)((P & ~0x10) | (value ? 0x10 : 0x00)); } set { P = (byte)((P & ~0x10) | (value ? 0x10 : 0x00)); }
} }
/// <summary>T... Flag</summary> /// <summary>T... Flag</summary>
private bool FlagT private bool FlagT
{ {
get { return (P & 0x20) != 0; } get { return (P & 0x20) != 0; }
set { P = (byte)((P & ~0x20) | (value ? 0x20 : 0x00)); } set { P = (byte)((P & ~0x20) | (value ? 0x20 : 0x00)); }
} }
/// <summary>Overflow Flag</summary> /// <summary>Overflow Flag</summary>
private bool FlagV private bool FlagV
{ {
get { return (P & 0x40) != 0; } get { return (P & 0x40) != 0; }
set { P = (byte)((P & ~0x40) | (value ? 0x40 : 0x00)); } set { P = (byte)((P & ~0x40) | (value ? 0x40 : 0x00)); }
} }
/// <summary>Negative Flag</summary> /// <summary>Negative Flag</summary>
private bool FlagN private bool FlagN
{ {
get { return (P & 0x80) != 0; } get { return (P & 0x80) != 0; }
set { P = (byte)((P & ~0x80) | (value ? 0x80 : 0x00)); } set { P = (byte)((P & ~0x80) | (value ? 0x80 : 0x00)); }
} }
// ==== Memory ==== // ==== Memory ====
public Func<int, byte> ReadMemory21; public Func<int, byte> ReadMemory21;
public Action<int, byte> WriteMemory21; public Action<int, byte> WriteMemory21;
public Action<int, byte> WriteVDC; public Action<int, byte> WriteVDC;
public Action<int> ThinkAction = delegate { }; public Action<int> ThinkAction = delegate { };
public byte ReadMemory(ushort address) public byte ReadMemory(ushort address)
{ {
byte page = MPR[address >> 13]; byte page = MPR[address >> 13];
return ReadMemory21((page << 13) | (address & 0x1FFF)); return ReadMemory21((page << 13) | (address & 0x1FFF));
} }
public void WriteMemory(ushort address, byte value) public void WriteMemory(ushort address, byte value)
{ {
byte page = MPR[address >> 13]; byte page = MPR[address >> 13];
WriteMemory21((page << 13) | (address & 0x1FFF), value); WriteMemory21((page << 13) | (address & 0x1FFF), value);
} }
private ushort ReadWord(ushort address) private ushort ReadWord(ushort address)
{ {
byte l = ReadMemory(address); byte l = ReadMemory(address);
byte h = ReadMemory(++address); byte h = ReadMemory(++address);
return (ushort)((h << 8) | l); return (ushort)((h << 8) | l);
} }
private void WriteWord(ushort address, ushort value) private void WriteWord(ushort address, ushort value)
{ {
byte l = (byte)(value & 0xFF); byte l = (byte)(value & 0xFF);
byte h = (byte)(value >> 8); byte h = (byte)(value >> 8);
WriteMemory(address, l); WriteMemory(address, l);
WriteMemory(++address, h); WriteMemory(++address, h);
} }
private ushort ReadWordPageWrap(ushort address) private ushort ReadWordPageWrap(ushort address)
{ {
ushort highAddress = (ushort)((address & 0xFF00) + ((address + 1) & 0xFF)); ushort highAddress = (ushort)((address & 0xFF00) + ((address + 1) & 0xFF));
return (ushort)(ReadMemory(address) | (ReadMemory(highAddress) << 8)); return (ushort)(ReadMemory(address) | (ReadMemory(highAddress) << 8));
} }
public string State() public string State()
{ {
int notused; int notused;
string a = string.Format("{0:X4} {1:X2} {2} ", PC, ReadMemory(PC), Disassemble(PC, out notused)).PadRight(41); string a = string.Format("{0:X4} {1:X2} {2} ", PC, ReadMemory(PC), Disassemble(PC, out notused)).PadRight(41);
string b = string.Format("A:{0:X2} X:{1:X2} Y:{2:X2} P:{3:X2} SP:{4:X2} Cy:{5}", A, X, Y, P, S, TotalExecutedCycles); string b = string.Format("A:{0:X2} X:{1:X2} Y:{2:X2} P:{3:X2} SP:{4:X2} Cy:{5}", A, X, Y, P, S, TotalExecutedCycles);
string val = a + b + " "; string val = a + b + " ";
if (FlagN) val = val + "N"; if (FlagN) val = val + "N";
if (FlagV) val = val + "V"; if (FlagV) val = val + "V";
if (FlagT) val = val + "T"; if (FlagT) val = val + "T";
if (FlagB) val = val + "B"; if (FlagB) val = val + "B";
if (FlagD) val = val + "D"; if (FlagD) val = val + "D";
if (FlagI) val = val + "I"; if (FlagI) val = val + "I";
if (FlagZ) val = val + "Z"; if (FlagZ) val = val + "Z";
if (FlagC) val = val + "C"; if (FlagC) val = val + "C";
return val; return val;
} }
private static readonly byte[] TableNZ = private static readonly byte[] TableNZ =
{ {
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@ -416,5 +416,5 @@ namespace BizHawk.Emulation.Common.Components.H6280
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80
}; };
} }
} }

View File

@ -29,7 +29,7 @@ namespace BizHawk.Emulation.Common.Components.M6502
mi = 0; mi = 0;
opcode = 256; opcode = 256;
iflag_pending = true; iflag_pending = true;
RDY = true; RDY = true;
} }
public void NESSoftReset() public void NESSoftReset()
@ -220,23 +220,23 @@ namespace BizHawk.Emulation.Common.Components.M6502
} }
private static readonly byte[] TableNZ = private static readonly byte[] TableNZ =
{ {
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80
}; };
} }
} }

View File

@ -12,8 +12,8 @@ namespace BizHawk.Emulation.Common.Components.M6502
/// </summary> /// </summary>
public class MOS6502XDouble public class MOS6502XDouble
{ {
MOS6502X m; readonly MOS6502X m;
MOS6502X_CPP n; readonly MOS6502X_CPP n;
public MOS6502XDouble(Action<System.Runtime.InteropServices.GCHandle> DisposeBuilder) public MOS6502XDouble(Action<System.Runtime.InteropServices.GCHandle> DisposeBuilder)
{ {

View File

@ -7,27 +7,27 @@ namespace BizHawk.Emulation.Common.Components.M6502
{ {
public static class MOS6502X_DLL public static class MOS6502X_DLL
{ {
[UnmanagedFunctionPointer(System.Runtime.InteropServices.CallingConvention.Cdecl)] [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate byte ReadMemoryD(ushort addr); public delegate byte ReadMemoryD(ushort addr);
[UnmanagedFunctionPointer(System.Runtime.InteropServices.CallingConvention.Cdecl)] [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void WriteMemoryD(ushort addr, byte value); public delegate void WriteMemoryD(ushort addr, byte value);
[DllImport("MOS6502XNative.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("MOS6502XNative.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr Create(); internal static extern IntPtr Create();
[DllImport("MOS6502XNative.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("MOS6502XNative.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void Destroy(IntPtr ptr); internal static extern void Destroy(IntPtr ptr);
[DllImport("MOS6502XNative.dll", CallingConvention = CallingConvention.ThisCall, EntryPoint = "?Reset@MOS6502X@@QAEXXZ")] [DllImport("MOS6502XNative.dll", CallingConvention = CallingConvention.ThisCall, EntryPoint = "?Reset@MOS6502X@@QAEXXZ")]
public static extern void Reset(IntPtr ptr); internal static extern void Reset(IntPtr ptr);
[DllImport("MOS6502XNative.dll", CallingConvention = CallingConvention.ThisCall, EntryPoint = "?NESSoftReset@MOS6502X@@QAEXXZ")] [DllImport("MOS6502XNative.dll", CallingConvention = CallingConvention.ThisCall, EntryPoint = "?NESSoftReset@MOS6502X@@QAEXXZ")]
public static extern void NESSoftReset(IntPtr ptr); internal static extern void NESSoftReset(IntPtr ptr);
[DllImport("MOS6502XNative.dll", CallingConvention = CallingConvention.ThisCall, EntryPoint = "?ExecuteOne@MOS6502X@@QAEXXZ")] [DllImport("MOS6502XNative.dll", CallingConvention = CallingConvention.ThisCall, EntryPoint = "?ExecuteOne@MOS6502X@@QAEXXZ")]
public static extern void ExecuteOne(IntPtr ptr); internal static extern void ExecuteOne(IntPtr ptr);
[DllImport("MOS6502XNative.dll", CallingConvention = CallingConvention.ThisCall, EntryPoint = "?SetTrampolines@MOS6502X@@QAEXP6AEG@Z0P6AXGE@Z@Z")] [DllImport("MOS6502XNative.dll", CallingConvention = CallingConvention.ThisCall, EntryPoint = "?SetTrampolines@MOS6502X@@QAEXP6AEG@Z0P6AXGE@Z@Z")]
public static extern void SetTrampolines(IntPtr ptr, ReadMemoryD Read, ReadMemoryD DummyRead, WriteMemoryD Write); internal static extern void SetTrampolines(IntPtr ptr, ReadMemoryD Read, ReadMemoryD DummyRead, WriteMemoryD Write);
} }
/// <summary> /// <summary>
@ -213,8 +213,6 @@ namespace BizHawk.Emulation.Common.Components.M6502
DisposeBuilder(h2); DisposeBuilder(h2);
DisposeBuilder(h3); DisposeBuilder(h3);
} }
} }
} }

View File

@ -1,7 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection;
using System.Text; using System.Text;
namespace BizHawk.Emulation.Common namespace BizHawk.Emulation.Common
@ -123,7 +122,7 @@ namespace BizHawk.Emulation.Common
public class InputCallbackSystem public class InputCallbackSystem
{ {
private List<Action> _list = new List<Action>(); private readonly List<Action> _list = new List<Action>();
public void Add(Action action) public void Add(Action action)
{ {
@ -159,14 +158,14 @@ namespace BizHawk.Emulation.Common
public class MemoryCallbackSystem public class MemoryCallbackSystem
{ {
private List<Action> _reads = new List<Action>(); private readonly List<Action> _reads = new List<Action>();
private List<uint?> _readAddrs = new List<uint?>(); private readonly List<uint?> _readAddrs = new List<uint?>();
private List<Action> _writes = new List<Action>(); private readonly List<Action> _writes = new List<Action>();
private List<uint?> _writeAddrs = new List<uint?>(); private readonly List<uint?> _writeAddrs = new List<uint?>();
private List<Action> _executes = new List<Action>(); private readonly List<Action> _executes = new List<Action>();
private List<uint> _execAddrs = new List<uint>(); private readonly List<uint> _execAddrs = new List<uint>();
public void AddRead(Action function, uint? addr) public void AddRead(Action function, uint? addr)
{ {

View File

@ -105,7 +105,7 @@ namespace BizHawk.Emulation.Common
public class MemoryDomainList : ReadOnlyCollection<MemoryDomain> public class MemoryDomainList : ReadOnlyCollection<MemoryDomain>
{ {
private int _mainMemoryIndex = 0; private readonly int _mainMemoryIndex;
public MemoryDomainList(IList<MemoryDomain> domains) public MemoryDomainList(IList<MemoryDomain> domains)
: base(domains) : base(domains)

View File

@ -4,7 +4,6 @@ using System.Globalization;
using System.IO; using System.IO;
using BizHawk.Common; using BizHawk.Common;
using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Common.Components namespace BizHawk.Emulation.Common.Components
{ {
@ -30,15 +29,15 @@ namespace BizHawk.Emulation.Common.Components
public PSGChannel[] Channels = new PSGChannel[8]; public PSGChannel[] Channels = new PSGChannel[8];
public byte VoiceLatch; public byte VoiceLatch;
byte WaveTableWriteOffset; private byte WaveTableWriteOffset;
Queue<QueuedCommand> commands = new Queue<QueuedCommand>(256); private readonly Queue<QueuedCommand> commands = new Queue<QueuedCommand>(256);
long frameStartTime, frameStopTime; private long frameStartTime, frameStopTime;
const int SampleRate = 44100; const int SampleRate = 44100;
const int PsgBase = 3580000; const int PsgBase = 3580000;
static byte[] LogScale = { 0, 0, 10, 10, 13, 13, 16, 16, 20, 20, 26, 26, 32, 32, 40, 40, 51, 51, 64, 64, 81, 81, 102, 102, 128, 128, 161, 161, 203, 203, 255, 255 }; static readonly byte[] LogScale = { 0, 0, 10, 10, 13, 13, 16, 16, 20, 20, 26, 26, 32, 32, 40, 40, 51, 51, 64, 64, 81, 81, 102, 102, 128, 128, 161, 161, 203, 203, 255, 255 };
static byte[] VolumeReductionTable = { 0x1F, 0x1D, 0x1B, 0x19, 0x17, 0x15, 0x13, 0x10, 0x0F, 0x0D, 0x0B, 0x09, 0x07, 0x05, 0x03, 0x00 }; static readonly byte[] VolumeReductionTable = { 0x1F, 0x1D, 0x1B, 0x19, 0x17, 0x15, 0x13, 0x10, 0x0F, 0x0D, 0x0B, 0x09, 0x07, 0x05, 0x03, 0x00 };
public byte MainVolumeLeft; public byte MainVolumeLeft;
public byte MainVolumeRight; public byte MainVolumeRight;
@ -49,7 +48,9 @@ namespace BizHawk.Emulation.Common.Components
MaxVolume = short.MaxValue; MaxVolume = short.MaxValue;
Waves.InitWaves(); Waves.InitWaves();
for (int i = 0; i < 8; i++) for (int i = 0; i < 8; i++)
{
Channels[i] = new PSGChannel(); Channels[i] = new PSGChannel();
}
} }
public void BeginFrame(long cycles) public void BeginFrame(long cycles)

View File

@ -1,8 +1,4 @@
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BizHawk.Common; using BizHawk.Common;
namespace BizHawk.Emulation.Common.Components namespace BizHawk.Emulation.Common.Components
@ -12,19 +8,19 @@ namespace BizHawk.Emulation.Common.Components
class Pulse class Pulse
{ {
// regs // regs
int V; private int V;
int T; private int T;
int L; private int L;
int D; private int D;
bool LenCntDisable; private bool LenCntDisable;
bool ConstantVolume; private bool ConstantVolume;
bool Enable; private bool Enable;
// envelope // envelope
bool estart; private bool estart;
int etime; private int etime;
int ecount; private int ecount;
// length // length
static int[] lenlookup = private static readonly int[] lenlookup =
{ {
10,254, 20, 2, 40, 4, 80, 6, 160, 8, 60, 10, 14, 12, 26, 14, 10,254, 20, 2, 40, 4, 80, 6, 160, 8, 60, 10, 14, 12, 26, 14,
12, 16, 24, 18, 48, 20, 96, 22, 192, 24, 72, 26, 16, 28, 32, 30 12, 16, 24, 18, 48, 20, 96, 22, 192, 24, 72, 26, 16, 28, 32, 30
@ -32,18 +28,18 @@ namespace BizHawk.Emulation.Common.Components
int length; int length;
// pulse // pulse
int sequence; private int sequence;
static int[,] sequencelookup = private static readonly int[,] sequencelookup =
{ {
{0,0,0,0,0,0,0,1}, {0,0,0,0,0,0,0,1},
{0,0,0,0,0,0,1,1}, {0,0,0,0,0,0,1,1},
{0,0,0,0,1,1,1,1}, {0,0,0,0,1,1,1,1},
{1,1,1,1,1,1,0,0} {1,1,1,1,1,1,0,0}
}; };
int clock; private int clock;
int output; private int output;
public Action<int> SendDiff; private readonly Action<int> SendDiff;
public Pulse(Action<int> SendDiff) public Pulse(Action<int> SendDiff)
{ {
@ -165,7 +161,7 @@ namespace BizHawk.Emulation.Common.Components
} }
} }
Pulse[] pulse = new Pulse[2]; private readonly Pulse[] pulse = new Pulse[2];
/// <summary> /// <summary>
/// ///
@ -245,15 +241,15 @@ namespace BizHawk.Emulation.Common.Components
RaiseIRQ(PCMEnableIRQ && PCMIRQTriggered); RaiseIRQ(PCMEnableIRQ && PCMIRQTriggered);
} }
Action<bool> RaiseIRQ; private readonly Action<bool> RaiseIRQ;
const int framereload = 7458; // ??? const int framereload = 7458; // ???
int frame = 0; private int frame;
bool PCMRead; private bool PCMRead;
bool PCMEnableIRQ; private bool PCMEnableIRQ;
bool PCMIRQTriggered; private bool PCMIRQTriggered;
byte PCMVal; private byte PCMVal;
byte PCMNextVal; private byte PCMNextVal;
public void SyncState(Serializer ser) public void SyncState(Serializer ser)
{ {
@ -288,14 +284,14 @@ namespace BizHawk.Emulation.Common.Components
} }
if (PCMNextVal != PCMVal) if (PCMNextVal != PCMVal)
{ {
enqueuer(20 * (int)(PCMVal - PCMNextVal)); enqueuer(20 * (PCMVal - PCMNextVal));
PCMVal = PCMNextVal; PCMVal = PCMNextVal;
} }
} }
Action<int> enqueuer; private readonly Action<int> enqueuer;
void PulseAddDiff(int value) private void PulseAddDiff(int value)
{ {
enqueuer(value * 370); enqueuer(value * 370);
//Console.WriteLine(value); //Console.WriteLine(value);

View File

@ -3,8 +3,6 @@ using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;
using BizHawk.Emulation.Common;
// TODO the freq->note translation should be moved to a separate utility class. // TODO the freq->note translation should be moved to a separate utility class.
namespace BizHawk.Emulation.Common.Components namespace BizHawk.Emulation.Common.Components
@ -26,7 +24,7 @@ namespace BizHawk.Emulation.Common.Components
public bool Right = true; public bool Right = true;
const int SampleRate = 44100; const int SampleRate = 44100;
static byte[] LogScale = { 0, 10, 13, 16, 20, 26, 32, 40, 51, 64, 81, 102, 128, 161, 203, 255 }; private static readonly byte[] LogScale = { 0, 10, 13, 16, 20, 26, 32, 40, 51, 64, 81, 102, 128, 161, 203, 255 };
public void Mix(short[] samples, int start, int len, int maxVolume) public void Mix(short[] samples, int start, int len, int maxVolume)
{ {
@ -52,7 +50,7 @@ namespace BizHawk.Emulation.Common.Components
public Channel[] Channels = new Channel[4]; public Channel[] Channels = new Channel[4];
public byte PsgLatch; public byte PsgLatch;
Queue<QueuedCommand> commands = new Queue<QueuedCommand>(256); private readonly Queue<QueuedCommand> commands = new Queue<QueuedCommand>(256);
int frameStartTime, frameStopTime; int frameStartTime, frameStopTime;
const int PsgBase = 111861; const int PsgBase = 111861;

View File

@ -1,8 +1,4 @@
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BizHawk.Common; using BizHawk.Common;
namespace BizHawk.Emulation.Common.Components namespace BizHawk.Emulation.Common.Components
@ -16,15 +12,15 @@ namespace BizHawk.Emulation.Common.Components
{ {
class Pulse class Pulse
{ {
Action<int> SendDiff; private readonly Action<int> SendDiff;
// regs // regs
int Period; private int Period;
bool Disable; private bool Disable;
int Volume; private int Volume;
// state // state
int clock; private int clock;
int sequence; private int sequence;
int output; private int output;
public void SyncState(Serializer ser) public void SyncState(Serializer ser)
{ {
@ -45,7 +41,10 @@ namespace BizHawk.Emulation.Common.Components
{ {
int newout = 1; int newout = 1;
if (!Disable) if (!Disable)
{
newout = sequence; newout = sequence;
}
newout *= Volume; newout *= Volume;
if (newout != output) if (newout != output)
{ {
@ -87,7 +86,7 @@ namespace BizHawk.Emulation.Common.Components
} }
int RegNum; int RegNum;
Pulse[] pulse = new Pulse[3]; readonly Pulse[] pulse = new Pulse[3];
public void RegSelect(byte val) public void RegSelect(byte val)
{ {
@ -132,8 +131,8 @@ namespace BizHawk.Emulation.Common.Components
ser.EndSection(); ser.EndSection();
} }
Action<int> enqueuer; private readonly Action<int> enqueuer;
void PulseAddDiff(int val) private void PulseAddDiff(int val)
{ {
enqueuer(val * 250); enqueuer(val * 250);
} }
@ -142,13 +141,17 @@ namespace BizHawk.Emulation.Common.Components
{ {
this.enqueuer = enqueuer; this.enqueuer = enqueuer;
for (int i = 0; i < pulse.Length; i++) for (int i = 0; i < pulse.Length; i++)
{
pulse[i] = new Pulse(PulseAddDiff); pulse[i] = new Pulse(PulseAddDiff);
}
} }
public void Clock() public void Clock()
{ {
for (int i = 0; i < pulse.Length; i++) foreach (Pulse p in pulse)
pulse[i].Clock(); {
p.Clock();
}
} }
} }
} }

View File

@ -1,7 +1,4 @@
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace BizHawk.Emulation.Common namespace BizHawk.Emulation.Common
@ -9,7 +6,7 @@ namespace BizHawk.Emulation.Common
/// <summary> /// <summary>
/// wrapper around blargg's unmanaged blip_buf /// wrapper around blargg's unmanaged blip_buf
/// </summary> /// </summary>
public class BlipBuffer : IDisposable public sealed class BlipBuffer : IDisposable
{ {
// this is transitional only. if the band-limited synthesis idea works out, i'll // this is transitional only. if the band-limited synthesis idea works out, i'll
// make a managed MIT implementation // make a managed MIT implementation

View File

@ -1,7 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Common namespace BizHawk.Emulation.Common
{ {
// Generates SEMI-synchronous sound, or "buffered asynchronous" sound. // Generates SEMI-synchronous sound, or "buffered asynchronous" sound.
@ -34,10 +32,10 @@ namespace BizHawk.Emulation.Common
{ {
public ISoundProvider BaseSoundProvider; public ISoundProvider BaseSoundProvider;
Queue<short> buffer = new Queue<short>(4096); readonly Queue<short> buffer = new Queue<short>(4096);
int SamplesInOneFrame = 1470; private int SamplesInOneFrame = 1470;
int TargetExtraSamples = 882; private int TargetExtraSamples = 882;
const int MaxExcessSamples = 4096; const int MaxExcessSamples = 4096;
/// <summary> /// <summary>
@ -72,11 +70,15 @@ namespace BizHawk.Emulation.Common
BaseSoundProvider.GetSamples(mySamples); BaseSoundProvider.GetSamples(mySamples);
for (int i = 0; i < mySamples.Length; i++) foreach (short s in mySamples)
buffer.Enqueue(mySamples[i]); {
buffer.Enqueue(s);
}
for (int i = 0; i < samples.Length; i++) for (int i = 0; i < samples.Length; i++)
{
samples[i] = buffer.Dequeue(); samples[i] = buffer.Dequeue();
}
} }
} }
} }

View File

@ -1,16 +1,11 @@
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Common namespace BizHawk.Emulation.Common
{ {
/// <summary> /// <summary>
/// implements a DC block filter on top of an ISoundProvider. rather simple. /// implements a DC block filter on top of an ISoundProvider. rather simple.
/// </summary> /// </summary>
public class DCFilter : ISoundProvider, ISyncSoundProvider sealed public class DCFilter : ISoundProvider, ISyncSoundProvider
{ {
/* /*
* A note about accuracy: * A note about accuracy:
@ -78,7 +73,7 @@ namespace BizHawk.Emulation.Common
PushThroughSamples(samples, samples, length); PushThroughSamples(samples, samples, length);
} }
void PushThroughSamples(short[] samplesin, short[] samplesout, int length) private void PushThroughSamples(short[] samplesin, short[] samplesout, int length)
{ {
for (int i = 0; i < length; i += 2) for (int i = 0; i < length; i += 2)
{ {

View File

@ -1,9 +1,6 @@
// C# port of C-based 3-band equalizer (C) Neil C / Etanza Systems / 2006 // C# port of C-based 3-band equalizer (C) Neil C / Etanza Systems / 2006
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BizHawk.Emulation.Common namespace BizHawk.Emulation.Common
{ {

View File

@ -1,8 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Common namespace BizHawk.Emulation.Common
{ {
/// <summary> /// <summary>
@ -10,8 +8,8 @@ namespace BizHawk.Emulation.Common
/// </summary> /// </summary>
public class MetaspuAsync : ISoundProvider public class MetaspuAsync : ISoundProvider
{ {
ISynchronizingAudioBuffer buffer; private readonly ISynchronizingAudioBuffer buffer;
ISyncSoundProvider input; private readonly ISyncSoundProvider input;
public MetaspuAsync(ISyncSoundProvider input, ESynchMethod method) public MetaspuAsync(ISyncSoundProvider input, ESynchMethod method)
{ {
buffer = Metaspu.metaspu_construct(method); buffer = Metaspu.metaspu_construct(method);
@ -49,7 +47,7 @@ namespace BizHawk.Emulation.Common
{ {
} }
short[] pullBuffer = new short[1470]; private readonly short[] pullBuffer = new short[1470];
public void PullSamples(ISoundProvider source) public void PullSamples(ISoundProvider source)
{ {
Array.Clear(pullBuffer, 0, 1470); Array.Clear(pullBuffer, 0, 1470);
@ -124,7 +122,7 @@ namespace BizHawk.Emulation.Common
} }
//adjustobuf(200,1000) //adjustobuf(200,1000)
bool mixqueue_go = false; bool mixqueue_go;
public void clear() public void clear()
{ {
@ -177,7 +175,7 @@ namespace BizHawk.Emulation.Common
return done; return done;
} }
Adjustobuf adjustobuf; private readonly Adjustobuf adjustobuf;
class Adjustobuf class Adjustobuf
{ {
public Adjustobuf(int _minLatency, int _maxLatency) public Adjustobuf(int _minLatency, int _maxLatency)

View File

@ -1,5 +1,4 @@
using System.Collections.Generic; using System.Collections.Generic;
using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Common namespace BizHawk.Emulation.Common
{ {
@ -7,7 +6,7 @@ namespace BizHawk.Emulation.Common
public sealed class SoundMixer : ISoundProvider public sealed class SoundMixer : ISoundProvider
{ {
List<ISoundProvider> SoundProviders; private readonly List<ISoundProvider> SoundProviders;
public SoundMixer(params ISoundProvider[] soundProviders) public SoundMixer(params ISoundProvider[] soundProviders)
{ {
@ -41,7 +40,9 @@ namespace BizHawk.Emulation.Common
{ {
int eachVolume = short.MaxValue / SoundProviders.Count; int eachVolume = short.MaxValue / SoundProviders.Count;
foreach (var source in SoundProviders) foreach (var source in SoundProviders)
{
source.MaxVolume = eachVolume; source.MaxVolume = eachVolume;
}
} }
// Not actually supported on mixer. // Not actually supported on mixer.

View File

@ -1,11 +1,6 @@
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Common namespace BizHawk.Emulation.Common
{ {
/// <summary> /// <summary>
@ -259,29 +254,29 @@ namespace BizHawk.Emulation.Common
/// <summary> /// <summary>
/// opaque pointer to state /// opaque pointer to state
/// </summary> /// </summary>
IntPtr st = IntPtr.Zero; private IntPtr st = IntPtr.Zero;
/// <summary> /// <summary>
/// function to call to dispatch output /// function to call to dispatch output
/// </summary> /// </summary>
Action<short[], int> drainer; private readonly Action<short[], int> drainer;
// TODO: this size is roughly based on how big you can make the buffer before the snes resampling (32040.5 -> 44100) gets screwed up // TODO: this size is roughly based on how big you can make the buffer before the snes resampling (32040.5 -> 44100) gets screwed up
short[] inbuf = new short[512]; //[8192]; // [512]; private short[] inbuf = new short[512]; //[8192]; // [512];
short[] outbuf; private short[] outbuf;
// for ISyncSoundProvider // for ISyncSoundProvider
short[] outbuf2 = new short[16]; private short[] outbuf2 = new short[16];
int outbuf2pos = 0; private int outbuf2pos = 0;
// to accept an ISyncSoundProvder input // to accept an ISyncSoundProvder input
ISyncSoundProvider input; private readonly ISyncSoundProvider input;
/// <summary> /// <summary>
/// in buffer position in samples (not sample pairs) /// in buffer position in samples (not sample pairs)
/// </summary> /// </summary>
int inbufpos = 0; private int inbufpos = 0;
/// <summary> /// <summary>
/// throw an exception based on error state /// throw an exception based on error state
@ -327,10 +322,7 @@ namespace BizHawk.Emulation.Common
if (drainer != null && input != null) if (drainer != null && input != null)
throw new ArgumentException("Can't autofetch without being an ISyncSoundProvider?"); throw new ArgumentException("Can't autofetch without being an ISyncSoundProvider?");
if (drainer != null) this.drainer = drainer ?? InternalDrain;
this.drainer = drainer;
else
this.drainer = InternalDrain;
this.input = input; this.input = input;
outbuf = new short[inbuf.Length * ratioden / rationum / 2 * 2 + 128]; outbuf = new short[inbuf.Length * ratioden / rationum / 2 * 2 + 128];

View File

@ -1,8 +1,4 @@
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BizHawk.Common; using BizHawk.Common;
namespace BizHawk.Emulation.Common.Components namespace BizHawk.Emulation.Common.Components

View File

@ -7,7 +7,6 @@
using System; using System;
using BizHawk.Common; using BizHawk.Common;
using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Common.Components namespace BizHawk.Emulation.Common.Components
{ {

File diff suppressed because it is too large Load Diff