diff --git a/BizHawk.Emulation/Computers/Commodore64/C64.Motherboard.cs b/BizHawk.Emulation/Computers/Commodore64/C64.Motherboard.cs index 4579f42ba8..4eeb742da9 100644 --- a/BizHawk.Emulation/Computers/Commodore64/C64.Motherboard.cs +++ b/BizHawk.Emulation/Computers/Commodore64/C64.Motherboard.cs @@ -150,34 +150,34 @@ namespace BizHawk.Emulation.Computers.Commodore64 pla.PokeVic = vic.Poke; pla.ReadAEC = vic.ReadAECBuffer; pla.ReadBA = vic.ReadBABuffer; - pla.ReadBasicRom = Pla_ReadBasicRom; - pla.ReadCartridgeHi = Pla_ReadCartridgeHi; - pla.ReadCartridgeLo = Pla_ReadCartridgeLo; + pla.ReadBasicRom = basicRom.Read; + pla.ReadCartridgeHi = cartPort.ReadHiRom; + pla.ReadCartridgeLo = cartPort.ReadLoRom; pla.ReadCharen = Pla_ReadCharen; - pla.ReadCharRom = Pla_ReadCharRom; + pla.ReadCharRom = charRom.Read; pla.ReadCia0 = Pla_ReadCia0; - pla.ReadCia1 = Pla_ReadCia1; + pla.ReadCia1 = cia1.Read; pla.ReadColorRam = Pla_ReadColorRam; - pla.ReadExpansionHi = Pla_ReadExpansionHi; - pla.ReadExpansionLo = Pla_ReadExpansionLo; + pla.ReadExpansionHi = cartPort.ReadHiExp; + pla.ReadExpansionLo = cartPort.ReadLoExp; pla.ReadExRom = cartPort.ReadExRom; pla.ReadGame = cartPort.ReadGame; pla.ReadHiRam = Pla_ReadHiRam; - pla.ReadKernalRom = Pla_ReadKernalRom; + pla.ReadKernalRom = kernalRom.Read; pla.ReadLoRam = Pla_ReadLoRam; - pla.ReadMemory = Pla_ReadMemory; - pla.ReadSid = Pla_ReadSid; - pla.ReadVic = Pla_ReadVic; - pla.WriteCartridgeHi = Pla_WriteCartridgeHi; - pla.WriteCartridgeLo = Pla_WriteCartridgeLo; - pla.WriteCia0 = Pla_WriteCia0; - pla.WriteCia1 = Pla_WriteCia1; - pla.WriteColorRam = Pla_WriteColorRam; - pla.WriteExpansionHi = Pla_WriteExpansionHi; - pla.WriteExpansionLo = Pla_WriteExpansionLo; - pla.WriteMemory = Pla_WriteMemory; - pla.WriteSid = Pla_WriteSid; - pla.WriteVic = Pla_WriteVic; + pla.ReadMemory = ram.Read; + pla.ReadSid = sid.Read; + pla.ReadVic = vic.Read; + pla.WriteCartridgeHi = cartPort.WriteHiRom; + pla.WriteCartridgeLo = cartPort.WriteLoRom; + pla.WriteCia0 = cia0.Write; + pla.WriteCia1 = cia1.Write; + pla.WriteColorRam = colorRam.Write; + pla.WriteExpansionHi = cartPort.WriteHiExp; + pla.WriteExpansionLo = cartPort.WriteLoExp; + pla.WriteMemory = ram.Write; + pla.WriteSid = sid.Write; + pla.WriteVic = vic.Write; serPort.ReadAtnOut = SerPort_ReadAtnOut; serPort.ReadClockOut = SerPort_ReadClockOut; diff --git a/BizHawk.Emulation/Computers/Commodore64/C64.MotherboardInterface.cs b/BizHawk.Emulation/Computers/Commodore64/C64.MotherboardInterface.cs index 68696686bf..154ada88a9 100644 --- a/BizHawk.Emulation/Computers/Commodore64/C64.MotherboardInterface.cs +++ b/BizHawk.Emulation/Computers/Commodore64/C64.MotherboardInterface.cs @@ -9,8 +9,6 @@ namespace BizHawk.Emulation.Computers.Commodore64 { public partial class Motherboard { - - bool CassPort_ReadDataOutput() { return (cpu.PortData & 0x08) != 0; @@ -64,6 +62,14 @@ namespace BizHawk.Emulation.Computers.Commodore64 return (userPort.ReadSerial2Buffer() && cia1.ReadSPBuffer()); } + byte Cpu_ReadMemory(int addr) + { + byte result = pla.ReadMemory(addr); + address = addr; + bus = result; + return result; + } + byte Cpu_ReadPort() { byte data = 0x1F; @@ -72,80 +78,36 @@ namespace BizHawk.Emulation.Computers.Commodore64 return data; } + void Cpu_WriteMemory(int addr, byte val) + { + pla.WriteMemory(addr, val); + address = addr; + bus = val; + } + bool Glue_ReadIRQ() { return cia0.ReadIRQBuffer() & vic.ReadIRQBuffer() & cartPort.ReadIRQBuffer(); } - byte Pla_ReadBasicRom(int addr) - { - address = addr; - bus = basicRom.Read(addr); - return bus; - } - - byte Pla_ReadCartridgeHi(int addr) - { - address = addr; - bus = cartPort.ReadHiRom(addr); - return bus; - } - - byte Pla_ReadCartridgeLo(int addr) - { - address = addr; - bus = cartPort.ReadLoRom(addr); - return bus; - } - bool Pla_ReadCharen() { return (cpu.PortData & 0x04) != 0; } - byte Pla_ReadCharRom(int addr) - { - address = addr; - bus = charRom.Read(addr); - return bus; - } - byte Pla_ReadCia0(int addr) { - address = addr; - bus = cia0.Read(addr); - if (!inputRead && (addr == 0xDC00 || addr == 0xDC01)) + if (addr == 0xDC00 || addr == 0xDC01) inputRead = true; - return bus; - } - - byte Pla_ReadCia1(int addr) - { - address = addr; - bus = cia1.Read(addr); - return bus; + return cia0.Read(addr); } byte Pla_ReadColorRam(int addr) { + int result; address = addr; - bus &= 0xF0; - bus |= colorRam.Read(addr); - return bus; - } - - byte Pla_ReadExpansionHi(int addr) - { - address = addr; - bus = cartPort.ReadHiExp(addr); - return bus; - } - - byte Pla_ReadExpansionLo(int addr) - { - address = addr; - bus = cartPort.ReadLoExp(addr); - return bus; + result = colorRam.Read(addr) | (bus & 0xF0); + return (byte)result; } bool Pla_ReadHiRam() @@ -153,109 +115,11 @@ namespace BizHawk.Emulation.Computers.Commodore64 return (cpu.PortData & 0x02) != 0; } - byte Pla_ReadKernalRom(int addr) - { - address = addr; - bus = kernalRom.Read(addr); - return bus; - } - bool Pla_ReadLoRam() { return (cpu.PortData & 0x01) != 0; } - byte Pla_ReadMemory(int addr) - { - address = addr; - bus = ram.Read(addr); - return bus; - } - - byte Pla_ReadSid(int addr) - { - address = addr; - bus = sid.Read(addr); - return bus; - } - - byte Pla_ReadVic(int addr) - { - address = addr; - bus = vic.Read(addr); - return bus; - } - - void Pla_WriteCartridgeHi(int addr, byte val) - { - address = addr; - bus = val; - cartPort.WriteHiRom(addr, val); - } - - void Pla_WriteCartridgeLo(int addr, byte val) - { - address = addr; - bus = val; - cartPort.WriteLoRom(addr, val); - } - - void Pla_WriteCia0(int addr, byte val) - { - address = addr; - bus = val; - cia0.Write(addr, val); - } - - void Pla_WriteCia1(int addr, byte val) - { - address = addr; - bus = val; - cia1.Write(addr, val); - } - - void Pla_WriteColorRam(int addr, byte val) - { - address = addr; - bus = val; - colorRam.Write(addr, val); - } - - void Pla_WriteExpansionHi(int addr, byte val) - { - address = addr; - bus = val; - cartPort.WriteHiExp(addr, val); - } - - void Pla_WriteExpansionLo(int addr, byte val) - { - address = addr; - bus = val; - cartPort.WriteLoExp(addr, val); - } - - void Pla_WriteMemory(int addr, byte val) - { - address = addr; - bus = val; - ram.Write(addr, val); - } - - void Pla_WriteSid(int addr, byte val) - { - address = addr; - bus = val; - sid.Write(addr, val); - } - - void Pla_WriteVic(int addr, byte val) - { - address = addr; - bus = val; - vic.Write(addr, val); - } - bool SerPort_ReadAtnOut() { return (cia1.PortBData & 0x08) == 0; diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/Chip2114.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/Chip2114.cs index 16632be01c..f7260516ff 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/Chip2114.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/Chip2114.cs @@ -21,11 +21,6 @@ return ram[addr & 0x3FF]; } - public byte Peek(int addr, byte bus) - { - return (byte)(ram[addr & 0x3FF] | (bus & 0xF0)); - } - public void Poke(int addr, byte val) { ram[addr & 0x3FF] = (byte)(val & 0xF); @@ -33,12 +28,7 @@ public byte Read(int addr) { - return (byte)(ram[addr & 0x3FF]); - } - - public byte Read(int addr, byte bus) - { - return (byte)(ram[addr & 0x3FF] | (bus & 0xF0)); + return ram[addr & 0x3FF]; } public void SyncState(Serializer ser) diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/Chip23XX.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/Chip23XX.cs index 00a18b28b6..5bb2ee78f3 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/Chip23XX.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/Chip23XX.cs @@ -46,11 +46,6 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS return rom[addr & addrMask]; } - public void Poke(int addr, byte val) - { - // do nothing (this is rom) - } - public byte Read(int addr) { return rom[addr & addrMask]; @@ -61,10 +56,5 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS ByteBuffer buffer = new ByteBuffer(rom); ser.Sync("rom", ref buffer); } - - public void Write(int addr, byte val) - { - // do nothing (this is rom) - } } } diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/Chip4864.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/Chip4864.cs index 00effda4f7..92bff2f947 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/Chip4864.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/Chip4864.cs @@ -30,17 +30,17 @@ public byte Peek(int addr) { - return ram[addr]; + return ram[addr & 0xFFFF]; } public void Poke(int addr, byte val) { - ram[addr] = val; + ram[addr & 0xFFFF] = val; } public byte Read(int addr) { - return ram[addr]; + return ram[addr & 0xFFFF]; } public void SyncState(Serializer ser) @@ -51,7 +51,7 @@ public void Write(int addr, byte val) { - ram[addr] = val; + ram[addr & 0xFFFF] = val; } } } diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/MOS6526.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/MOS6526.cs index 1dec0ee427..320e6845d9 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/MOS6526.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/MOS6526.cs @@ -365,7 +365,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS public byte Peek(int addr) { - return ReadRegister((addr & 0xF)); + return ReadRegister(addr & 0xF); } public void Poke(int addr, byte val) diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/Sid.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/Sid.cs index 72caf10ea1..504d668e1f 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/Sid.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/Sid.cs @@ -630,8 +630,8 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS private bool filterSelectLoPass; private bool filterSelectHiPass; private int potCounter; - private byte potX; - private byte potY; + private int potX; + private int potY; private int[] voiceOutput; private Voice[] voices; private int volume; diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/Vic.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/Vic.cs index c25b9fb7bc..56a6f1cb22 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/Vic.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/Vic.cs @@ -983,12 +983,12 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS break; case 0x11: result = (byte)( - (byte)(yScroll & 0x7) | - (rowSelect ? (byte)0x08 : (byte)0x00) | - (displayEnable ? (byte)0x10 : (byte)0x00) | - (bitmapMode ? (byte)0x20 : (byte)0x00) | - (extraColorMode ? (byte)0x40 : (byte)0x00) | - (byte)((rasterLine & 0x100) >> 1) + (yScroll & 0x7) | + (rowSelect ? 0x08 : 0x00) | + (displayEnable ? 0x10 : 0x00) | + (bitmapMode ? 0x20 : 0x00) | + (extraColorMode ? 0x40 : 0x00) | + ((rasterLine & 0x100) >> 1) ); break; case 0x12: @@ -1015,9 +1015,9 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS case 0x16: result &= 0xC0; result |= (byte)( - (byte)(xScroll & 0x7) | - (columnSelect ? (byte)0x08 : (byte)0x00) | - (multicolorMode ? (byte)0x10 : (byte)0x00) + (xScroll & 0x7) | + (columnSelect ? 0x08 : 0x00) | + (multicolorMode ? 0x10 : 0x00) ); break; case 0x17: