From 46ff936d41c7cded598a45b7045c183e6cc12faf Mon Sep 17 00:00:00 2001 From: saxxonpike Date: Thu, 15 Nov 2012 15:58:26 +0000 Subject: [PATCH] commodore64: 1541 disk drive CPU emulated when a D64 or G64 is loaded, not attached to serial bus and no mechanical emulation yet --- BizHawk.Emulation/Computers/Commodore64/1541.cs | 12 ++++++++++-- .../Computers/Commodore64/C64.PeekPoke.cs | 13 +++++++++++++ BizHawk.Emulation/Computers/Commodore64/C64.cs | 1 + BizHawk.Emulation/Computers/Commodore64/Cia.cs | 2 ++ 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/BizHawk.Emulation/Computers/Commodore64/1541.cs b/BizHawk.Emulation/Computers/Commodore64/1541.cs index b5f4ebedf4..4196cc9d7b 100644 --- a/BizHawk.Emulation/Computers/Commodore64/1541.cs +++ b/BizHawk.Emulation/Computers/Commodore64/1541.cs @@ -49,6 +49,11 @@ namespace BizHawk.Emulation.Computers.Commodore64 public void HardReset() { cpu = new MOS6502X(); + cpu.PC = (ushort)(Read(0xFFFC) + (Read(0xFFFD) << 8)); + cpu.ReadMemory = Read; + cpu.WriteMemory = Write; + cpu.DummyReadMemory = Read; + ram = new byte[0x800]; via0 = new Via(); via1 = new Via(); @@ -60,8 +65,9 @@ namespace BizHawk.Emulation.Computers.Commodore64 disk = newDisk; } - public byte Peek(ushort addr) + public byte Peek(int addr) { + addr &= 0xFFFF; if (addr < 0x0800) { return ram[addr]; @@ -83,10 +89,12 @@ namespace BizHawk.Emulation.Computers.Commodore64 public void PerformCycle() { + cpu.ExecuteOne(); } - public void Poke(ushort addr, byte val) + public void Poke(int addr, byte val) { + addr &= 0xFFFF; if (addr < 0x0800) { ram[addr] = val; diff --git a/BizHawk.Emulation/Computers/Commodore64/C64.PeekPoke.cs b/BizHawk.Emulation/Computers/Commodore64/C64.PeekPoke.cs index 1b2287d4f1..c114799dcc 100644 --- a/BizHawk.Emulation/Computers/Commodore64/C64.PeekPoke.cs +++ b/BizHawk.Emulation/Computers/Commodore64/C64.PeekPoke.cs @@ -22,6 +22,13 @@ namespace BizHawk.Emulation.Computers.Commodore64 return (byte)((mem.colorRam[addr & 0x3FF] & 0xF) | mem.busData); } + public byte PeekDiskDrive(int addr) + { + if (diskDriveAttached) + return diskDrive.Peek(addr); + return 0xFF; + } + public byte PeekMemory(ushort addr) { return mem.Peek(addr); @@ -62,6 +69,12 @@ namespace BizHawk.Emulation.Computers.Commodore64 mem.colorRam[addr & 0x3FF] = (byte)(val & 0xF); } + public void PokeDiskDrive(int addr, byte val) + { + if (diskDriveAttached) + diskDrive.Poke(addr, val); + } + public void PokeMemoryInt(int addr, byte val) { mem.Poke((ushort)(addr & 0xFFFF), val); diff --git a/BizHawk.Emulation/Computers/Commodore64/C64.cs b/BizHawk.Emulation/Computers/Commodore64/C64.cs index 0139966dc8..5ff3d25fce 100644 --- a/BizHawk.Emulation/Computers/Commodore64/C64.cs +++ b/BizHawk.Emulation/Computers/Commodore64/C64.cs @@ -124,6 +124,7 @@ namespace BizHawk.Emulation.Computers.Commodore64 domains.Add(new MemoryDomain("SID", 0x20, Endian.Little, new Func(PeekSid), new Action(PokeSid))); domains.Add(new MemoryDomain("VIC", 0x40, Endian.Little, new Func(PeekVic), new Action(PokeVic))); domains.Add(new MemoryDomain("CRAM", 0x400, Endian.Little, new Func(PeekColorRAM), new Action(PokeColorRAM))); + domains.Add(new MemoryDomain("DISKRAM", 0x10000, Endian.Little, new Func(PeekDiskDrive), new Action(PokeDiskDrive))); memoryDomains = domains.AsReadOnly(); } diff --git a/BizHawk.Emulation/Computers/Commodore64/Cia.cs b/BizHawk.Emulation/Computers/Commodore64/Cia.cs index 0e903e2524..69f45bb91b 100644 --- a/BizHawk.Emulation/Computers/Commodore64/Cia.cs +++ b/BizHawk.Emulation/Computers/Commodore64/Cia.cs @@ -447,6 +447,7 @@ namespace BizHawk.Emulation.Computers.Commodore64 // reading this reg clears it result = regs[0x0D]; regs[0x0D] = 0x00; + UpdateInterrupt(); return result; default: return regs[addr]; @@ -581,6 +582,7 @@ namespace BizHawk.Emulation.Computers.Commodore64 regs.EIALARM = ((intMask & 0x04) != 0x00); regs.EISP = ((intMask & 0x08) != 0x00); regs.EIFLAG = ((intMask & 0x10) != 0x00); + UpdateInterrupt(); break; default: regs[addr] = val;