diff --git a/BizHawk.Emulation/Computers/Commodore64/C64.Core.cs b/BizHawk.Emulation/Computers/Commodore64/C64.Core.cs index c5ca386b37..f638daee42 100644 --- a/BizHawk.Emulation/Computers/Commodore64/C64.Core.cs +++ b/BizHawk.Emulation/Computers/Commodore64/C64.Core.cs @@ -96,15 +96,15 @@ namespace BizHawk.Emulation.Computers.Commodore64 chips.HardReset(); } - private byte Peek(int addr) - { - return chips.cpu.Peek(addr); - } + //private byte Peek(int addr) + //{ + // return chips.cpu.Peek(addr); + //} - private void Poke(int addr, byte val) - { - chips.cpu.Poke(addr, val); - } + //private void Poke(int addr, byte val) + //{ + // chips.cpu.Poke(addr, val); + //} // ------------------------------------ } diff --git a/BizHawk.Emulation/Computers/Commodore64/C64.cs b/BizHawk.Emulation/Computers/Commodore64/C64.cs index 423e64ac9a..36ea23dd8a 100644 --- a/BizHawk.Emulation/Computers/Commodore64/C64.cs +++ b/BizHawk.Emulation/Computers/Commodore64/C64.cs @@ -17,12 +17,12 @@ namespace BizHawk.Emulation.Computers.Commodore64 { inputFile = rom; extension = romextension; - SetupMemoryDomains(); CoreOutputComm = new CoreOutputComm(); CoreInputComm = new CoreInputComm(); Init(Region.PAL); cyclesPerFrame = (uint)chips.vic.CyclesPerFrame; CoreOutputComm.UsesDriveLed = true; + SetupMemoryDomains(); } // internal variables @@ -117,8 +117,14 @@ namespace BizHawk.Emulation.Computers.Commodore64 private void SetupMemoryDomains() { + // chips must be initialized before this code runs! var domains = new List(1); - domains.Add(new MemoryDomain("System Bus", 0x10000, Endian.Little, new Func(Peek), new Action(Poke))); + domains.Add(new MemoryDomain("System Bus", 0x10000, Endian.Little, new Func(chips.cpu.Peek), new Action(chips.cpu.Poke))); + domains.Add(new MemoryDomain("RAM", 0x10000, Endian.Little, new Func(chips.ram.Peek), new Action(chips.ram.Poke))); + domains.Add(new MemoryDomain("CIA0", 0x10, Endian.Little, new Func(chips.cia0.Peek), new Action(chips.cia0.Poke))); + domains.Add(new MemoryDomain("CIA1", 0x10, Endian.Little, new Func(chips.cia1.Peek), new Action(chips.cia1.Poke))); + domains.Add(new MemoryDomain("VIC", 0x40, Endian.Little, new Func(chips.vic.Peek), new Action(chips.vic.Poke))); + domains.Add(new MemoryDomain("SID", 0x20, Endian.Little, new Func(chips.sid.Peek), new Action(chips.sid.Poke))); memoryDomains = domains.AsReadOnly(); } } diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/MOS6510.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/MOS6510.cs index 9d8aee1c80..edac0a3973 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/MOS6510.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/MOS6510.cs @@ -26,6 +26,11 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS private bool pinNMI; private bool pinRDY; private byte portDir; + private bool unusedPin0; + private bool unusedPin1; + private uint unusedPinTTL0; + private uint unusedPinTTL1; + private uint unusedPinTTLCycles; // ------------------------------------ @@ -42,6 +47,11 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS // configure data port defaults portDir = 0x2F; SetPortData(0x37); + + // todo: verify this value (I only know that unconnected bits fade after a number of cycles) + unusedPinTTLCycles = 40; + unusedPinTTL0 = 0; + unusedPinTTL1 = 0; } public void HardReset() @@ -71,6 +81,17 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS cpu.IRQ = !pinIRQ; cpu.ExecuteOne(); } + + // process unused pin TTL + if (unusedPinTTL0 == 0) + unusedPin0 = false; + else + unusedPinTTL0--; + + if (unusedPinTTL1 == 0) + unusedPin1 = false; + else + unusedPinTTL1--; } private void UpdatePins() @@ -102,8 +123,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS portDir = val; else if (addr == 0x0001) SetPortData(val); - else - chips.pla.Poke(addr, val); + chips.pla.Poke(addr, val); } public byte Read(ushort addr) @@ -126,8 +146,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS PortDirection = val; else if (addr == 0x0001) PortData = val; - else - chips.pla.Write(addr, val); + chips.pla.Write(addr, val); } // ------------------------------------ @@ -164,7 +183,8 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS result |= pinCassetteOutput ? (byte)0x08 : (byte)0x00; result |= pinCassetteButton ? (byte)0x10 : (byte)0x00; result |= pinCassetteMotor ? (byte)0x20 : (byte)0x00; - + result |= unusedPin0 ? (byte)0x40 : (byte)0x00; + result |= unusedPin1 ? (byte)0x80 : (byte)0x00; return result; } set @@ -195,6 +215,11 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS chips.pla.HiRam = pinHiram; chips.pla.Charen = pinCharen; } + + unusedPin0 = ((val & 0x40) != 0); + unusedPin1 = ((val & 0x80) != 0); + unusedPinTTL0 = unusedPinTTLCycles; + unusedPinTTL1 = unusedPinTTLCycles; } // ------------------------------------