6502: added RDY pin, required for C64 and possibly others

This commit is contained in:
saxxonpike 2013-08-15 06:08:21 +00:00
parent af9bbd9ae4
commit 459368dd5b
3 changed files with 798 additions and 339 deletions

File diff suppressed because it is too large Load Diff

View File

@ -27,6 +27,7 @@ namespace BizHawk.Emulation.CPUs.M6502
mi = 0;
opcode = 256;
iflag_pending = true;
RDY = true;
}
public void NESSoftReset()
@ -82,6 +83,7 @@ namespace BizHawk.Emulation.CPUs.M6502
public bool IRQ;
public bool NMI;
public bool RDY;
public void SyncState(Serializer ser)
{
@ -94,6 +96,7 @@ namespace BizHawk.Emulation.CPUs.M6502
ser.Sync("S", ref S);
ser.Sync("NMI", ref NMI);
ser.Sync("IRQ", ref IRQ);
ser.Sync("RDY", ref RDY);
ser.Sync("TotalExecutedCycles", ref TotalExecutedCycles);
ser.Sync("opcode", ref opcode);
ser.Sync("opcode2", ref opcode2);

View File

@ -13,14 +13,9 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
private MOS6502X cpu;
private List<GCHandle> disposeList = new List<GCHandle>();
private bool freezeCpu;
//private bool freezeCpu;
private bool pinNMILast;
private LatchedPort port;
private bool unusedPin0;
private bool unusedPin1;
private uint unusedPinTTL0;
private uint unusedPinTTL1;
private uint unusedPinTTLCycles;
public Func<int, byte> PeekMemory;
public Action<int, byte> PokeMemory;
@ -43,9 +38,6 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
cpu.ReadMemory = Read;
cpu.WriteMemory = Write;
// todo: verify this value (I only know that unconnected bits fade after a number of cycles)
unusedPinTTLCycles = 40;
// perform hard reset
HardReset();
}
@ -74,10 +66,6 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
// NMI is high on startup (todo: verify)
pinNMILast = true;
// reset unused IO pin TTLs
unusedPinTTL0 = 0;
unusedPinTTL1 = 0;
}
// ------------------------------------
@ -88,35 +76,20 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
public void ExecutePhase2()
{
if (ReadAEC() && !freezeCpu)
{
// the 6502 core expects active high
// so we reverse the polarity here
bool thisNMI = ReadNMI();
if (!thisNMI && pinNMILast)
cpu.NMI = true;
else
cpu.NMI = false;
pinNMILast = thisNMI;
cpu.RDY = ReadRDY();
cpu.IRQ = !ReadIRQ();
cpu.ExecuteOne();
}
// the 6502 core expects active high
// so we reverse the polarity here
bool thisNMI = ReadNMI();
if (!thisNMI && pinNMILast)
cpu.NMI = true;
else
cpu.NMI = false;
pinNMILast = thisNMI;
// unfreeze cpu if BA is high
if (ReadRDY()) freezeCpu = false;
// process unused pin TTL
if (unusedPinTTL0 == 0)
unusedPin0 = false;
else
unusedPinTTL0--;
if (unusedPinTTL1 == 0)
unusedPin1 = false;
else
unusedPinTTL1--;
}
cpu.IRQ = !ReadIRQ();
cpu.ExecuteOne();
}
// ------------------------------------
@ -162,10 +135,6 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
public byte Read(ushort addr)
{
// cpu freezes after first read when RDY is low
if (!ReadRDY())
freezeCpu = true;
if (addr == 0x0000)
return port.Direction;
else if (addr == 0x0001)
@ -177,13 +146,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
public void SyncState(Serializer ser)
{
cpu.SyncState(ser);
ser.Sync("freezeCpu", ref freezeCpu);
ser.Sync("pinNMILast", ref pinNMILast);
ser.Sync("unusedPin0", ref unusedPin0);
ser.Sync("unusedPin1", ref unusedPin1);
ser.Sync("unusedPinTTL0", ref unusedPinTTL0);
ser.Sync("unusedPinTTL1", ref unusedPinTTL1);
ser.Sync("unusedPinTTLCycles", ref unusedPinTTLCycles);
}
public void Write(ushort addr, byte val)