From 5c37b64eec272d2979c7cd1e5f5d5118f3a49d15 Mon Sep 17 00:00:00 2001 From: saxxonpike Date: Wed, 14 Aug 2013 05:05:17 +0000 Subject: [PATCH] Commodore64: Removed a lot of unnecessary function chains and converted unsigned types to int. --- BizHawk.Emulation/BizHawk.Emulation.csproj | 1 - .../Computers/Commodore64/C64.Core.cs | 6 +- .../Computers/Commodore64/C64.Input.cs | 9 +- .../Computers/Commodore64/C64.Motherboard.cs | 52 +++---- .../Commodore64/C64.MotherboardInterface.cs | 130 ++++++++---------- .../Computers/Commodore64/C64.cs | 12 +- .../Computers/Commodore64/Cartridge/Cart.cs | 58 ++++---- .../Commodore64/Cartridge/Mapper0000.cs | 10 +- .../Commodore64/Cartridge/Mapper0005.cs | 22 +-- .../Commodore64/Cartridge/Mapper000B.cs | 10 +- .../Commodore64/Cartridge/Mapper000F.cs | 22 +-- .../Commodore64/Cartridge/Mapper0011.cs | 8 +- .../Commodore64/Cartridge/Mapper0012.cs | 12 +- .../Commodore64/Cartridge/Mapper0013.cs | 20 +-- .../Commodore64/Cartridge/Mapper0020.cs | 24 ++-- .../Commodore64/MOS/CartridgePort.cs | 48 ++++--- .../Computers/Commodore64/MOS/CassettePort.cs | 14 +- .../Computers/Commodore64/MOS/Chip2114.cs | 6 +- .../Computers/Commodore64/MOS/Chip23XX.cs | 6 +- .../Computers/Commodore64/MOS/Chip4864.cs | 8 +- .../Computers/Commodore64/MOS/MOS6510.cs | 10 +- .../Computers/Commodore64/MOS/MOS6526.cs | 103 +++++++------- .../Computers/Commodore64/MOS/MOSPLA.cs | 84 +++++------ .../Computers/Commodore64/MOS/Port.cs | 35 +++++ .../Computers/Commodore64/MOS/SerialPort.cs | 48 ++----- .../Computers/Commodore64/MOS/Sid.cs | 18 +-- .../Computers/Commodore64/MOS/Timer.cs | 21 ++- .../Computers/Commodore64/MOS/UserPort.cs | 106 +++++++------- .../Computers/Commodore64/MOS/Vic.cs | 63 +++++---- .../Computers/Commodore64/Media/PRG.cs | 6 +- .../Computers/Commodore64/Memory.cs | 6 - 31 files changed, 478 insertions(+), 500 deletions(-) delete mode 100644 BizHawk.Emulation/Computers/Commodore64/Memory.cs diff --git a/BizHawk.Emulation/BizHawk.Emulation.csproj b/BizHawk.Emulation/BizHawk.Emulation.csproj index 466f4143d3..2af4bec652 100644 --- a/BizHawk.Emulation/BizHawk.Emulation.csproj +++ b/BizHawk.Emulation/BizHawk.Emulation.csproj @@ -99,7 +99,6 @@ - diff --git a/BizHawk.Emulation/Computers/Commodore64/C64.Core.cs b/BizHawk.Emulation/Computers/Commodore64/C64.Core.cs index 39e27d5680..4b28712634 100644 --- a/BizHawk.Emulation/Computers/Commodore64/C64.Core.cs +++ b/BizHawk.Emulation/Computers/Commodore64/C64.Core.cs @@ -106,7 +106,7 @@ namespace BizHawk.Emulation.Computers.Commodore64 static public class C64Util { - static public string ToBinary(uint n, uint charsmin) + static public string ToBinary(int n, int charsmin) { string result = ""; @@ -121,13 +121,13 @@ namespace BizHawk.Emulation.Computers.Commodore64 return result; } - static public string ToHex(uint n, uint charsmin) + static public string ToHex(int n, int charsmin) { string result = ""; while (n > 0 || charsmin > 0) { - result = "0123456789ABCDEF".Substring((int)(n & 0xF), 1) + result; + result = "0123456789ABCDEF".Substring((n & 0xF), 1) + result; n >>= 4; if (charsmin > 0) charsmin--; diff --git a/BizHawk.Emulation/Computers/Commodore64/C64.Input.cs b/BizHawk.Emulation/Computers/Commodore64/C64.Input.cs index 82de63cc60..87f9ab4015 100644 --- a/BizHawk.Emulation/Computers/Commodore64/C64.Input.cs +++ b/BizHawk.Emulation/Computers/Commodore64/C64.Input.cs @@ -61,9 +61,9 @@ namespace BizHawk.Emulation.Computers.Commodore64 byte joyA = 0xFF; byte joyB = 0xFF; - for (uint i = 0; i < 8; i++) + for (int i = 0; i < 8; i++) { - for (uint j = 0; j < 8; j++) + for (int j = 0; j < 8; j++) { if (keyboardPressed[i, j]) { @@ -76,7 +76,7 @@ namespace BizHawk.Emulation.Computers.Commodore64 } } - for (uint i = 0; i < 5; i++) + for (int i = 0; i < 5; i++) { if (joystickPressed[1, i]) joyA &= inputBitMask[i]; @@ -89,6 +89,9 @@ namespace BizHawk.Emulation.Computers.Commodore64 cia0InputLatchA = resultA; cia0InputLatchB = resultB; + + // this joystick has special rules. + cia0.PortAMask = joyA; } } } diff --git a/BizHawk.Emulation/Computers/Commodore64/C64.Motherboard.cs b/BizHawk.Emulation/Computers/Commodore64/C64.Motherboard.cs index a4880b9b71..4579f42ba8 100644 --- a/BizHawk.Emulation/Computers/Commodore64/C64.Motherboard.cs +++ b/BizHawk.Emulation/Computers/Commodore64/C64.Motherboard.cs @@ -2,6 +2,9 @@ namespace BizHawk.Emulation.Computers.Commodore64 { + /// + /// Contains the onboard chipset and glue. + /// public partial class Motherboard { // chips @@ -25,9 +28,11 @@ namespace BizHawk.Emulation.Computers.Commodore64 public UserPort userPort; // state - public ushort address; + public int address; public byte bus; public bool inputRead; + public bool irq; + public bool nmi; public Motherboard(Region initRegion) { @@ -92,25 +97,32 @@ namespace BizHawk.Emulation.Computers.Commodore64 public void Init() { - cassPort.ReadDataOutput = CassPort_DeviceReadLevel; - cassPort.ReadMotor = CassPort_DeviceReadMotor; + cartPort.ReadIRQ = Glue_ReadIRQ; + cartPort.ReadNMI = cia1.ReadIRQBuffer; - cia0.ReadFlag = Cia0_ReadFlag; + cassPort.ReadDataOutput = CassPort_ReadDataOutput; + cassPort.ReadMotor = CassPort_ReadMotor; + + cia0.ReadCNT = Cia0_ReadCnt; + cia0.ReadFlag = cassPort.ReadDataInputBuffer; cia0.ReadPortA = Cia0_ReadPortA; cia0.ReadPortB = Cia0_ReadPortB; + cia0.ReadSP = Cia0_ReadSP; - cia1.ReadFlag = Cia1_ReadFlag; + cia1.ReadCNT = Cia1_ReadCnt; + cia1.ReadFlag = userPort.ReadFlag2; cia1.ReadPortA = Cia1_ReadPortA; - cia1.ReadPortB = Cia1_ReadPortB; + cia1.ReadPortB = userPort.ReadData; + cia1.ReadSP = Cia1_ReadSP; cpu.PeekMemory = pla.Peek; cpu.PokeMemory = pla.Poke; - cpu.ReadAEC = vic.ReadAEC; - cpu.ReadIRQ = Cpu_ReadIRQ; - cpu.ReadNMI = cia1.ReadIRQ; + cpu.ReadAEC = vic.ReadAECBuffer; + cpu.ReadIRQ = Glue_ReadIRQ; + cpu.ReadNMI = cia1.ReadIRQBuffer; cpu.ReadPort = Cpu_ReadPort; - cpu.ReadRDY = vic.ReadBA; - cpu.ReadMemory = pla.Read; + cpu.ReadRDY = vic.ReadBABuffer; + cpu.ReadMemory = pla.Read; cpu.WriteMemory = pla.Write; pla.PeekBasicRom = basicRom.Peek; @@ -136,8 +148,8 @@ namespace BizHawk.Emulation.Computers.Commodore64 pla.PokeMemory = ram.Poke; pla.PokeSid = sid.Poke; pla.PokeVic = vic.Poke; - pla.ReadAEC = vic.ReadAEC; - pla.ReadBA = vic.ReadBA; + pla.ReadAEC = vic.ReadAECBuffer; + pla.ReadBA = vic.ReadBABuffer; pla.ReadBasicRom = Pla_ReadBasicRom; pla.ReadCartridgeHi = Pla_ReadCartridgeHi; pla.ReadCartridgeLo = Pla_ReadCartridgeLo; @@ -167,21 +179,15 @@ namespace BizHawk.Emulation.Computers.Commodore64 pla.WriteSid = Pla_WriteSid; pla.WriteVic = Pla_WriteVic; - // note: c64 serport lines are inverted - serPort.DeviceReadAtn = SerPort_DeviceReadAtn; - serPort.DeviceReadClock = SerPort_DeviceReadClock; - serPort.DeviceReadData = SerPort_DeviceReadData; - serPort.DeviceReadReset = SerPort_DeviceReadReset; - serPort.DeviceWriteAtn = SerPort_DeviceWriteAtn; - serPort.DeviceWriteClock = SerPort_DeviceWriteClock; - serPort.DeviceWriteData = SerPort_DeviceWriteData; - serPort.DeviceWriteSrq = SerPort_DeviceWriteSrq; + serPort.ReadAtnOut = SerPort_ReadAtnOut; + serPort.ReadClockOut = SerPort_ReadClockOut; + serPort.ReadDataOut = SerPort_ReadDataOut; sid.ReadPotX = Sid_ReadPotX; sid.ReadPotY = Sid_ReadPotY; vic.ReadMemory = Vic_ReadMemory; - vic.ReadColorRam = Vic_ReadColorRam; + vic.ReadColorRam = colorRam.Read; } public void SyncState(Serializer ser) diff --git a/BizHawk.Emulation/Computers/Commodore64/C64.MotherboardInterface.cs b/BizHawk.Emulation/Computers/Commodore64/C64.MotherboardInterface.cs index 8d989212fd..68696686bf 100644 --- a/BizHawk.Emulation/Computers/Commodore64/C64.MotherboardInterface.cs +++ b/BizHawk.Emulation/Computers/Commodore64/C64.MotherboardInterface.cs @@ -9,19 +9,21 @@ namespace BizHawk.Emulation.Computers.Commodore64 { public partial class Motherboard { - bool CassPort_DeviceReadLevel() + + + bool CassPort_ReadDataOutput() { return (cpu.PortData & 0x08) != 0; } - bool CassPort_DeviceReadMotor() + bool CassPort_ReadMotor() { return (cpu.PortData & 0x20) != 0; } - bool Cia0_ReadFlag() + bool Cia0_ReadCnt() { - return cassPort.DataInput; + return (userPort.ReadCounter1Buffer() && cia0.ReadCNTBuffer()); } byte Cia0_ReadPortA() @@ -36,55 +38,60 @@ namespace BizHawk.Emulation.Computers.Commodore64 return cia0InputLatchB; } - bool Cia1_ReadFlag() + bool Cia0_ReadSP() { - return true; + return (userPort.ReadSerial1Buffer() && cia0.ReadSPBuffer()); + } + + bool Cia1_ReadCnt() + { + return (userPort.ReadCounter2Buffer() && cia1.ReadCNTBuffer()); } byte Cia1_ReadPortA() { // the low bits are actually the VIC memory address. - return 0x3F; + byte result = 0xFF; + if (serPort.WriteDataIn()) + result &= 0x7F; + if (serPort.WriteClockIn()) + result &= 0xBF; + return result; } - byte Cia1_ReadPortB() + bool Cia1_ReadSP() { - return 0xFF; - } - - bool Cpu_ReadCassetteButton() - { - return true; - } - - bool Cpu_ReadIRQ() - { - return cia0.IRQ & vic.IRQ & cartPort.IRQ; + return (userPort.ReadSerial2Buffer() && cia1.ReadSPBuffer()); } byte Cpu_ReadPort() { byte data = 0x1F; - if (!cassPort.Sense) + if (!cassPort.ReadSenseBuffer()) data &= 0xEF; return data; } - byte Pla_ReadBasicRom(ushort addr) + 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(ushort addr) + byte Pla_ReadCartridgeHi(int addr) { address = addr; bus = cartPort.ReadHiRom(addr); return bus; } - byte Pla_ReadCartridgeLo(ushort addr) + byte Pla_ReadCartridgeLo(int addr) { address = addr; bus = cartPort.ReadLoRom(addr); @@ -96,14 +103,14 @@ namespace BizHawk.Emulation.Computers.Commodore64 return (cpu.PortData & 0x04) != 0; } - byte Pla_ReadCharRom(ushort addr) + byte Pla_ReadCharRom(int addr) { address = addr; bus = charRom.Read(addr); return bus; } - byte Pla_ReadCia0(ushort addr) + byte Pla_ReadCia0(int addr) { address = addr; bus = cia0.Read(addr); @@ -112,14 +119,14 @@ namespace BizHawk.Emulation.Computers.Commodore64 return bus; } - byte Pla_ReadCia1(ushort addr) + byte Pla_ReadCia1(int addr) { address = addr; bus = cia1.Read(addr); return bus; } - byte Pla_ReadColorRam(ushort addr) + byte Pla_ReadColorRam(int addr) { address = addr; bus &= 0xF0; @@ -127,14 +134,14 @@ namespace BizHawk.Emulation.Computers.Commodore64 return bus; } - byte Pla_ReadExpansionHi(ushort addr) + byte Pla_ReadExpansionHi(int addr) { address = addr; bus = cartPort.ReadHiExp(addr); return bus; } - byte Pla_ReadExpansionLo(ushort addr) + byte Pla_ReadExpansionLo(int addr) { address = addr; bus = cartPort.ReadLoExp(addr); @@ -146,7 +153,7 @@ namespace BizHawk.Emulation.Computers.Commodore64 return (cpu.PortData & 0x02) != 0; } - byte Pla_ReadKernalRom(ushort addr) + byte Pla_ReadKernalRom(int addr) { address = addr; bus = kernalRom.Read(addr); @@ -158,139 +165,112 @@ namespace BizHawk.Emulation.Computers.Commodore64 return (cpu.PortData & 0x01) != 0; } - byte Pla_ReadMemory(ushort addr) + byte Pla_ReadMemory(int addr) { address = addr; bus = ram.Read(addr); return bus; } - byte Pla_ReadSid(ushort addr) + byte Pla_ReadSid(int addr) { address = addr; bus = sid.Read(addr); return bus; } - byte Pla_ReadVic(ushort addr) + byte Pla_ReadVic(int addr) { address = addr; bus = vic.Read(addr); return bus; } - void Pla_WriteCartridgeHi(ushort addr, byte val) + void Pla_WriteCartridgeHi(int addr, byte val) { address = addr; bus = val; cartPort.WriteHiRom(addr, val); } - void Pla_WriteCartridgeLo(ushort addr, byte val) + void Pla_WriteCartridgeLo(int addr, byte val) { address = addr; bus = val; cartPort.WriteLoRom(addr, val); } - void Pla_WriteCia0(ushort addr, byte val) + void Pla_WriteCia0(int addr, byte val) { address = addr; bus = val; cia0.Write(addr, val); } - void Pla_WriteCia1(ushort addr, byte val) + void Pla_WriteCia1(int addr, byte val) { address = addr; bus = val; cia1.Write(addr, val); } - void Pla_WriteColorRam(ushort addr, byte val) + void Pla_WriteColorRam(int addr, byte val) { address = addr; bus = val; colorRam.Write(addr, val); } - void Pla_WriteExpansionHi(ushort addr, byte val) + void Pla_WriteExpansionHi(int addr, byte val) { address = addr; bus = val; cartPort.WriteHiExp(addr, val); } - void Pla_WriteExpansionLo(ushort addr, byte val) + void Pla_WriteExpansionLo(int addr, byte val) { address = addr; bus = val; cartPort.WriteLoExp(addr, val); } - void Pla_WriteMemory(ushort addr, byte val) + void Pla_WriteMemory(int addr, byte val) { address = addr; bus = val; ram.Write(addr, val); } - void Pla_WriteSid(ushort addr, byte val) + void Pla_WriteSid(int addr, byte val) { address = addr; bus = val; sid.Write(addr, val); } - void Pla_WriteVic(ushort addr, byte val) + void Pla_WriteVic(int addr, byte val) { address = addr; bus = val; vic.Write(addr, val); } - bool SerPort_DeviceReadAtn() + bool SerPort_ReadAtnOut() { return (cia1.PortBData & 0x08) == 0; } - bool SerPort_DeviceReadClock() + bool SerPort_ReadClockOut() { return (cia1.PortAData & 0x10) == 0; } - bool SerPort_DeviceReadData() + bool SerPort_ReadDataOut() { return (cia1.PortAData & 0x20) == 0; } - bool SerPort_DeviceReadReset() - { - // this triggers hard reset on ext device when low - return true; - } - - void SerPort_DeviceWriteAtn(bool val) - { - // currently not wired - } - - void SerPort_DeviceWriteClock(bool val) - { - //cia1DataA = Port.ExternalWrite(cia1DataA, (byte)((cia1DataA & 0xBF) | (val ? 0x00 : 0x40)), cia1DirA); - } - - void SerPort_DeviceWriteData(bool val) - { - //cia1DataA = Port.ExternalWrite(cia1DataA, (byte)((cia1DataA & 0x7F) | (val ? 0x00 : 0x80)), cia1DirA); - } - - void SerPort_DeviceWriteSrq(bool val) - { - //cia0FlagSerial = val; - //cia0.FLAG = cia0FlagCassette & cia0FlagSerial; - } - byte Sid_ReadPotX() { return 0; @@ -301,7 +281,7 @@ namespace BizHawk.Emulation.Computers.Commodore64 return 0; } - byte Vic_ReadMemory(ushort addr) + byte Vic_ReadMemory(int addr) { switch (cia1.PortAData & 0x3) { @@ -323,7 +303,7 @@ namespace BizHawk.Emulation.Computers.Commodore64 return bus; } - byte Vic_ReadColorRam(ushort addr) + byte Vic_ReadColorRam(int addr) { address = addr; bus &= 0xF0; diff --git a/BizHawk.Emulation/Computers/Commodore64/C64.cs b/BizHawk.Emulation/Computers/Commodore64/C64.cs index 8af0afae14..7f88868e02 100644 --- a/BizHawk.Emulation/Computers/Commodore64/C64.cs +++ b/BizHawk.Emulation/Computers/Commodore64/C64.cs @@ -146,12 +146,12 @@ namespace BizHawk.Emulation.Computers.Commodore64 { // chips must be initialized before this code runs! var domains = new List(1); - domains.Add(new MemoryDomain("System Bus", 0x10000, Endian.Little, new Func(board.cpu.Peek), new Action(board.cpu.Poke))); - domains.Add(new MemoryDomain("RAM", 0x10000, Endian.Little, new Func(board.ram.Peek), new Action(board.ram.Poke))); - domains.Add(new MemoryDomain("CIA0", 0x10, Endian.Little, new Func(board.cia0.Peek), new Action(board.cia0.Poke))); - domains.Add(new MemoryDomain("CIA1", 0x10, Endian.Little, new Func(board.cia1.Peek), new Action(board.cia1.Poke))); - domains.Add(new MemoryDomain("VIC", 0x40, Endian.Little, new Func(board.vic.Peek), new Action(board.vic.Poke))); - domains.Add(new MemoryDomain("SID", 0x20, Endian.Little, new Func(board.sid.Peek), new Action(board.sid.Poke))); + domains.Add(new MemoryDomain("System Bus", 0x10000, Endian.Little, board.cpu.Peek, board.cpu.Poke)); + domains.Add(new MemoryDomain("RAM", 0x10000, Endian.Little, board.ram.Peek, board.ram.Poke)); + domains.Add(new MemoryDomain("CIA0", 0x10, Endian.Little, board.cia0.Peek, board.cia0.Poke)); + domains.Add(new MemoryDomain("CIA1", 0x10, Endian.Little, board.cia1.Peek, board.cia1.Poke)); + domains.Add(new MemoryDomain("VIC", 0x40, Endian.Little, board.vic.Peek, board.vic.Poke)); + domains.Add(new MemoryDomain("SID", 0x20, Endian.Little, board.sid.Peek, board.sid.Poke)); //domains.Add(new MemoryDomain("1541 Bus", 0x10000, Endian.Little, new Func(disk.Peek), new Action(disk.Poke))); //domains.Add(new MemoryDomain("1541 VIA0", 0x10, Endian.Little, new Func(disk.PeekVia0), new Action(disk.PokeVia0))); //domains.Add(new MemoryDomain("1541 VIA1", 0x10, Endian.Little, new Func(disk.PeekVia1), new Action(disk.PokeVia1))); diff --git a/BizHawk.Emulation/Computers/Commodore64/Cartridge/Cart.cs b/BizHawk.Emulation/Computers/Commodore64/Cartridge/Cart.cs index 6664d39182..c54e245d82 100644 --- a/BizHawk.Emulation/Computers/Commodore64/Cartridge/Cart.cs +++ b/BizHawk.Emulation/Computers/Commodore64/Cartridge/Cart.cs @@ -18,14 +18,14 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge if (new string(reader.ReadChars(16)) == "C64 CARTRIDGE ") { - List chipAddress = new List(); - List chipBank = new List(); + List chipAddress = new List(); + List chipBank = new List(); List chipData = new List(); - List chipType = new List(); + List chipType = new List(); - uint headerLength = ReadCRTInt(reader); - uint version = ReadCRTShort(reader); - uint mapper = ReadCRTShort(reader); + int headerLength = ReadCRTInt(reader); + int version = ReadCRTShort(reader); + int mapper = ReadCRTShort(reader); bool exrom = (reader.ReadByte() != 0); bool game = (reader.ReadByte() != 0); @@ -38,7 +38,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge // skip extra header bytes if (headerLength > 0x40) { - reader.ReadBytes((int)headerLength - 0x40); + reader.ReadBytes(headerLength - 0x40); } // read chips @@ -46,15 +46,15 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge { if (new string(reader.ReadChars(4)) == "CHIP") { - uint chipLength = ReadCRTInt(reader); + int chipLength = ReadCRTInt(reader); chipType.Add(ReadCRTShort(reader)); chipBank.Add(ReadCRTShort(reader)); chipAddress.Add(ReadCRTShort(reader)); - uint chipDataLength = ReadCRTShort(reader); - chipData.Add(reader.ReadBytes((int)chipDataLength)); + int chipDataLength = ReadCRTShort(reader); + chipData.Add(reader.ReadBytes(chipDataLength)); chipLength -= (chipDataLength + 0x10); if (chipLength > 0) - reader.ReadBytes((int)chipLength); + reader.ReadBytes(chipLength); } } @@ -96,21 +96,21 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge return result; } - static private uint ReadCRTShort(BinaryReader reader) + static private int ReadCRTShort(BinaryReader reader) { - uint result; - result = (uint)reader.ReadByte() << 8; - result |= (uint)reader.ReadByte(); + int result; + result = (int)reader.ReadByte() << 8; + result |= (int)reader.ReadByte(); return result; } - static private uint ReadCRTInt(BinaryReader reader) + static private int ReadCRTInt(BinaryReader reader) { - uint result; - result = (uint)reader.ReadByte() << 24; - result |= (uint)reader.ReadByte() << 16; - result |= (uint)reader.ReadByte() << 8; - result |= (uint)reader.ReadByte(); + int result; + result = (int)reader.ReadByte() << 24; + result |= (int)reader.ReadByte() << 16; + result |= (int)reader.ReadByte() << 8; + result |= (int)reader.ReadByte(); return result; } @@ -206,22 +206,22 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge { } - public virtual byte Read8000(ushort addr) + public virtual byte Read8000(int addr) { return 0xFF; } - public virtual byte ReadA000(ushort addr) + public virtual byte ReadA000(int addr) { return 0xFF; } - public virtual byte ReadDE00(ushort addr) + public virtual byte ReadDE00(int addr) { return 0xFF; } - public virtual byte ReadDF00(ushort addr) + public virtual byte ReadDF00(int addr) { return 0xFF; } @@ -252,19 +252,19 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge } } - public virtual void Write8000(ushort addr, byte val) + public virtual void Write8000(int addr, byte val) { } - public virtual void WriteA000(ushort addr, byte val) + public virtual void WriteA000(int addr, byte val) { } - public virtual void WriteDE00(ushort addr, byte val) + public virtual void WriteDE00(int addr, byte val) { } - public virtual void WriteDF00(ushort addr, byte val) + public virtual void WriteDF00(int addr, byte val) { } } diff --git a/BizHawk.Emulation/Computers/Commodore64/Cartridge/Mapper0000.cs b/BizHawk.Emulation/Computers/Commodore64/Cartridge/Mapper0000.cs index faaccf0a9c..821233ad2b 100644 --- a/BizHawk.Emulation/Computers/Commodore64/Cartridge/Mapper0000.cs +++ b/BizHawk.Emulation/Computers/Commodore64/Cartridge/Mapper0000.cs @@ -6,14 +6,14 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge public class Mapper0000 : Cart { private byte[] romA; - private uint romAMask; + private int romAMask; private byte[] romB; - private uint romBMask; + private int romBMask; // standard cartridge mapper (Commodore) // note that this format also covers Ultimax carts - public Mapper0000(List newAddresses, List newBanks, List newData, bool game, bool exrom) + public Mapper0000(List newAddresses, List newBanks, List newData, bool game, bool exrom) { pinGame = game; pinExRom = exrom; @@ -83,12 +83,12 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge return romB[addr & romBMask]; } - public override byte Read8000(ushort addr) + public override byte Read8000(int addr) { return romA[addr & romAMask]; } - public override byte ReadA000(ushort addr) + public override byte ReadA000(int addr) { return romB[addr & romBMask]; } diff --git a/BizHawk.Emulation/Computers/Commodore64/Cartridge/Mapper0005.cs b/BizHawk.Emulation/Computers/Commodore64/Cartridge/Mapper0005.cs index a52ac9397d..ed19cb205b 100644 --- a/BizHawk.Emulation/Computers/Commodore64/Cartridge/Mapper0005.cs +++ b/BizHawk.Emulation/Computers/Commodore64/Cartridge/Mapper0005.cs @@ -7,19 +7,19 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge { private byte[][] banksA = new byte[0][]; //8000 private byte[][] banksB = new byte[0][]; //A000 - private uint bankMask; - private uint bankNumber; + private int bankMask; + private int bankNumber; private byte[] currentBankA; private byte[] currentBankB; private byte[] dummyBank; - public Mapper0005(List newAddresses, List newBanks, List newData) + public Mapper0005(List newAddresses, List newBanks, List newData) { - uint count = (uint)newAddresses.Count; + int count = newAddresses.Count; // build dummy bank dummyBank = new byte[0x2000]; - for (uint i = 0; i < 0x2000; i++) + for (int i = 0; i < 0x2000; i++) dummyBank[i] = 0xFF; // todo: determine if this is correct if (count == 64) //512k @@ -80,9 +80,9 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge } // for safety, initialize all banks to dummy - for (uint i = 0; i < banksA.Length; i++) + for (int i = 0; i < banksA.Length; i++) banksA[i] = dummyBank; - for (uint i = 0; i < banksB.Length; i++) + for (int i = 0; i < banksB.Length; i++) banksB[i] = dummyBank; // now load in the banks @@ -101,7 +101,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge BankSet(0); } - private void BankSet(uint index) + private void BankSet(int index) { bankNumber = index & bankMask; if (!pinExRom) @@ -131,17 +131,17 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge BankSet(val); } - public override byte Read8000(ushort addr) + public override byte Read8000(int addr) { return currentBankA[addr]; } - public override byte ReadA000(ushort addr) + public override byte ReadA000(int addr) { return currentBankB[addr]; } - public override void WriteDE00(ushort addr, byte val) + public override void WriteDE00(int addr, byte val) { if (addr == 0x00) BankSet(val); diff --git a/BizHawk.Emulation/Computers/Commodore64/Cartridge/Mapper000B.cs b/BizHawk.Emulation/Computers/Commodore64/Cartridge/Mapper000B.cs index d3d1496c71..c5602e0f6a 100644 --- a/BizHawk.Emulation/Computers/Commodore64/Cartridge/Mapper000B.cs +++ b/BizHawk.Emulation/Computers/Commodore64/Cartridge/Mapper000B.cs @@ -14,11 +14,11 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge { private byte[] rom = new byte[0x4000]; - public Mapper000B(List newAddresses, List newBanks, List newData) + public Mapper000B(List newAddresses, List newBanks, List newData) { validCartridge = false; - for (uint i = 0; i < 0x4000; i++) + for (int i = 0; i < 0x4000; i++) rom[i] = 0xFF; if (newAddresses[0] == 0x8000) @@ -38,17 +38,17 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge return rom[addr | 0x2000]; } - public override byte Read8000(ushort addr) + public override byte Read8000(int addr) { return rom[addr]; } - public override byte ReadA000(ushort addr) + public override byte ReadA000(int addr) { return rom[addr | 0x2000]; } - public override byte ReadDF00(ushort addr) + public override byte ReadDF00(int addr) { pinGame = true; return base.ReadDF00(addr); diff --git a/BizHawk.Emulation/Computers/Commodore64/Cartridge/Mapper000F.cs b/BizHawk.Emulation/Computers/Commodore64/Cartridge/Mapper000F.cs index 3d3c6e001f..c62422b85b 100644 --- a/BizHawk.Emulation/Computers/Commodore64/Cartridge/Mapper000F.cs +++ b/BizHawk.Emulation/Computers/Commodore64/Cartridge/Mapper000F.cs @@ -13,21 +13,21 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge public class Mapper000F : Cart { private byte[][] banks = new byte[0][]; //8000 - private uint bankMask; - private uint bankNumber; + private int bankMask; + private int bankNumber; private byte[] currentBank; private byte[] dummyBank; - public Mapper000F(List newAddresses, List newBanks, List newData) + public Mapper000F(List newAddresses, List newBanks, List newData) { - uint count = (uint)newAddresses.Count; + int count = newAddresses.Count; pinGame = true; pinExRom = false; // build dummy bank dummyBank = new byte[0x2000]; - for (uint i = 0; i < 0x2000; i++) + for (int i = 0; i < 0x2000; i++) dummyBank[i] = 0xFF; // todo: determine if this is correct if (count == 64) //512k @@ -72,7 +72,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge } // for safety, initialize all banks to dummy - for (uint i = 0; i < banks.Length; i++) + for (int i = 0; i < banks.Length; i++) banks[i] = dummyBank; // now load in the banks @@ -87,7 +87,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge BankSet(0); } - protected void BankSet(uint index) + protected void BankSet(int index) { bankNumber = index & bankMask; UpdateState(); @@ -100,10 +100,10 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge public override void PokeDE00(int addr, byte val) { - BankSet((uint)addr); + BankSet(addr); } - public override byte Read8000(ushort addr) + public override byte Read8000(int addr) { return currentBank[addr]; } @@ -113,9 +113,9 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge currentBank = banks[bankNumber]; } - public override void WriteDE00(ushort addr, byte val) + public override void WriteDE00(int addr, byte val) { - BankSet((uint)addr); + BankSet(addr); } public override void SyncState(Serializer ser) diff --git a/BizHawk.Emulation/Computers/Commodore64/Cartridge/Mapper0011.cs b/BizHawk.Emulation/Computers/Commodore64/Cartridge/Mapper0011.cs index 8e38932573..9958de8183 100644 --- a/BizHawk.Emulation/Computers/Commodore64/Cartridge/Mapper0011.cs +++ b/BizHawk.Emulation/Computers/Commodore64/Cartridge/Mapper0011.cs @@ -9,7 +9,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge public class Mapper0011 : Mapper000F { - public Mapper0011(List newAddresses, List newBanks, List newData) + public Mapper0011(List newAddresses, List newBanks, List newData) : base(newAddresses, newBanks, newData) { // required to pass information to base class @@ -20,13 +20,13 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge // do nothing } - public override byte ReadDE00(ushort addr) + public override byte ReadDE00(int addr) { - BankSet((uint)addr); + BankSet(addr); return base.ReadDE00(addr); } - public override void WriteDE00(ushort addr, byte val) + public override void WriteDE00(int addr, byte val) { // do nothing } diff --git a/BizHawk.Emulation/Computers/Commodore64/Cartridge/Mapper0012.cs b/BizHawk.Emulation/Computers/Commodore64/Cartridge/Mapper0012.cs index ed23fa559b..c6d64b9001 100644 --- a/BizHawk.Emulation/Computers/Commodore64/Cartridge/Mapper0012.cs +++ b/BizHawk.Emulation/Computers/Commodore64/Cartridge/Mapper0012.cs @@ -8,21 +8,21 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge private byte[] bankMain; private byte[][] bankHigh; private byte[] bankHighSelected; - private uint bankIndex; + private int bankIndex; private byte[] dummyBank; // Zaxxon and Super Zaxxon cartridges // - read to 8xxx selects bank 0 in A000-BFFF // - read to 9xxx selects bank 1 in A000-BFFF - public Mapper0012(List newAddresses, List newBanks, List newData) + public Mapper0012(List newAddresses, List newBanks, List newData) { bankMain = new byte[0x2000]; bankHigh = new byte[2][]; dummyBank = new byte[0x2000]; // create dummy bank just in case - for (uint i = 0; i < 0x2000; i++) + for (int i = 0; i < 0x2000; i++) dummyBank[i] = 0xFF; bankHigh[0] = dummyBank; @@ -56,14 +56,14 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge return bankHighSelected[addr]; } - public override byte Read8000(ushort addr) + public override byte Read8000(int addr) { - bankIndex = (addr & (uint)0x1000) >> 12; + bankIndex = (addr & 0x1000) >> 12; bankHighSelected = bankHigh[bankIndex]; return bankMain[addr]; } - public override byte ReadA000(ushort addr) + public override byte ReadA000(int addr) { return bankHighSelected[addr]; } diff --git a/BizHawk.Emulation/Computers/Commodore64/Cartridge/Mapper0013.cs b/BizHawk.Emulation/Computers/Commodore64/Cartridge/Mapper0013.cs index 65a2211bb7..4d343b4e6d 100644 --- a/BizHawk.Emulation/Computers/Commodore64/Cartridge/Mapper0013.cs +++ b/BizHawk.Emulation/Computers/Commodore64/Cartridge/Mapper0013.cs @@ -14,15 +14,15 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge public class Mapper0013 : Cart { private byte[][] banks = new byte[0][]; //8000 - private uint bankMask; - private uint bankNumber; + private int bankMask; + private int bankNumber; private byte[] currentBank; private byte[] dummyBank; private bool romEnable; - public Mapper0013(List newAddresses, List newBanks, List newData) + public Mapper0013(List newAddresses, List newBanks, List newData) { - uint count = (uint)newAddresses.Count; + int count = newAddresses.Count; pinGame = true; pinExRom = false; @@ -30,7 +30,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge // build dummy bank dummyBank = new byte[0x2000]; - for (uint i = 0; i < 0x2000; i++) + for (int i = 0; i < 0x2000; i++) dummyBank[i] = 0xFF; // todo: determine if this is correct if (count == 16) //128k @@ -55,7 +55,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge } // for safety, initialize all banks to dummy - for (uint i = 0; i < banks.Length; i++) + for (int i = 0; i < banks.Length; i++) banks[i] = dummyBank; // now load in the banks @@ -70,7 +70,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge BankSet(0); } - private void BankSet(uint index) + private void BankSet(int index) { bankNumber = index & bankMask; romEnable = ((index & 0x80) == 0); @@ -88,7 +88,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge BankSet(val); } - public override byte Read8000(ushort addr) + public override byte Read8000(int addr) { return currentBank[addr]; } @@ -108,7 +108,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge } } - public override void WriteDE00(ushort addr, byte val) + public override void WriteDE00(int addr, byte val) { if (addr == 0x00) BankSet(val); @@ -121,7 +121,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge ser.Sync("bankNumber", ref bankNumber); ser.Sync("romEnable", ref romEnable); if (ser.IsReader) - BankSet(bankNumber | (uint)(romEnable ? 0x00 : 0x80)); + BankSet(bankNumber | (romEnable ? 0x00 : 0x80)); } } } diff --git a/BizHawk.Emulation/Computers/Commodore64/Cartridge/Mapper0020.cs b/BizHawk.Emulation/Computers/Commodore64/Cartridge/Mapper0020.cs index a7c0f7dc1c..67458f4a36 100644 --- a/BizHawk.Emulation/Computers/Commodore64/Cartridge/Mapper0020.cs +++ b/BizHawk.Emulation/Computers/Commodore64/Cartridge/Mapper0020.cs @@ -21,20 +21,20 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge { private byte[][] banksA = new byte[64][]; //8000 private byte[][] banksB = new byte[64][]; //A000 - private uint bankNumber; + private int bankNumber; private bool boardLed; private byte[] currentBankA; private byte[] currentBankB; private byte[] dummyBank; private byte[] ram = new byte[256]; - public Mapper0020(List newAddresses, List newBanks, List newData) + public Mapper0020(List newAddresses, List newBanks, List newData) { - uint count = (uint)newAddresses.Count; + int count = newAddresses.Count; // build dummy bank dummyBank = new byte[0x2000]; - for (uint i = 0; i < 0x2000; i++) + for (int i = 0; i < 0x2000; i++) dummyBank[i] = 0xFF; // todo: determine if this is correct // force ultimax mode (the cart SHOULD set this @@ -43,9 +43,9 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge pinExRom = true; // for safety, initialize all banks to dummy - for (uint i = 0; i < 64; i++) + for (int i = 0; i < 64; i++) banksA[i] = dummyBank; - for (uint i = 0; i < 64; i++) + for (int i = 0; i < 64; i++) banksB[i] = dummyBank; // load in all banks @@ -65,7 +65,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge BankSet(0); } - private void BankSet(uint index) + private void BankSet(int index) { bankNumber = index & 0x3F; UpdateState(); @@ -121,17 +121,17 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge ram[addr] = val; } - public override byte Read8000(ushort addr) + public override byte Read8000(int addr) { return currentBankA[addr]; } - public override byte ReadA000(ushort addr) + public override byte ReadA000(int addr) { return currentBankB[addr]; } - public override byte ReadDF00(ushort addr) + public override byte ReadDF00(int addr) { return ram[addr]; } @@ -150,7 +150,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge currentBankB = banksB[bankNumber]; } - public override void WriteDE00(ushort addr, byte val) + public override void WriteDE00(int addr, byte val) { if (addr == 0x00) BankSet(val); @@ -158,7 +158,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge StateSet(val); } - public override void WriteDF00(ushort addr, byte val) + public override void WriteDF00(int addr, byte val) { ram[addr] = val; } diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/CartridgePort.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/CartridgePort.cs index 58260d3d56..ded620006a 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/CartridgePort.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/CartridgePort.cs @@ -1,9 +1,13 @@ -using BizHawk.Emulation.Computers.Commodore64.Cartridge; +using System; +using BizHawk.Emulation.Computers.Commodore64.Cartridge; namespace BizHawk.Emulation.Computers.Commodore64.MOS { public class CartridgePort { + public Func ReadIRQ; + public Func ReadNMI; + private Cart cart; private bool connected; @@ -27,15 +31,15 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS public bool ReadExRom() { if (connected) { return cart.ExRom; } else { return true; } } public bool ReadGame() { if (connected) { return cart.Game; } else { return true; } } - public byte ReadHiExp(ushort addr) { if (connected) { return cart.ReadDF00((ushort)(addr & 0x00FF)); } else { return 0xFF; } } - public byte ReadHiRom(ushort addr) { if (connected) { return cart.ReadA000((ushort)(addr & 0x1FFF)); } else { return 0xFF; } } - public byte ReadLoExp(ushort addr) { if (connected) { return cart.ReadDE00((ushort)(addr & 0x00FF)); } else { return 0xFF; } } - public byte ReadLoRom(ushort addr) { if (connected) { return cart.Read8000((ushort)(addr & 0x1FFF)); } else { return 0xFF; } } + public byte ReadHiExp(int addr) { if (connected) { return cart.ReadDF00((addr & 0x00FF)); } else { return 0xFF; } } + public byte ReadHiRom(int addr) { if (connected) { return cart.ReadA000((addr & 0x1FFF)); } else { return 0xFF; } } + public byte ReadLoExp(int addr) { if (connected) { return cart.ReadDE00((addr & 0x00FF)); } else { return 0xFF; } } + public byte ReadLoRom(int addr) { if (connected) { return cart.Read8000((addr & 0x1FFF)); } else { return 0xFF; } } - public void WriteHiExp(ushort addr, byte val) { if (connected) { cart.WriteDF00((ushort)(addr & 0x00FF), val); } } - public void WriteHiRom(ushort addr, byte val) { if (connected) { cart.WriteA000((ushort)(addr & 0x1FFF), val); } } - public void WriteLoExp(ushort addr, byte val) { if (connected) { cart.WriteDE00((ushort)(addr & 0x00FF), val); } } - public void WriteLoRom(ushort addr, byte val) { if (connected) { cart.Write8000((ushort)(addr & 0x1FFF), val); } } + public void WriteHiExp(int addr, byte val) { if (connected) { cart.WriteDF00((addr & 0x00FF), val); } } + public void WriteHiRom(int addr, byte val) { if (connected) { cart.WriteA000((addr & 0x1FFF), val); } } + public void WriteLoExp(int addr, byte val) { if (connected) { cart.WriteDE00((addr & 0x00FF), val); } } + public void WriteLoRom(int addr, byte val) { if (connected) { cart.Write8000((addr & 0x1FFF), val); } } // ------------------------------------------ @@ -56,14 +60,6 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS // note: this will not disconnect any attached media } - public bool IRQ - { - get - { - return true; //todo: hook this up to cartridge - } - } - public bool IsConnected { get @@ -72,15 +68,17 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS } } - public bool NMI - { - get - { - return true; //todo: hook this up to cartridge - } - } + public bool ReadIRQBuffer() + { + return true; + } - public void SyncState(Serializer ser) + public bool ReadNMIBuffer() + { + return true; + } + + public void SyncState(Serializer ser) { ser.Sync("connected", ref connected); if (connected) diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/CassettePort.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/CassettePort.cs index 9f39c9197b..a3d8ba9ed6 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/CassettePort.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/CassettePort.cs @@ -11,20 +11,14 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS { } - public bool DataInput + public bool ReadDataInputBuffer() { - get - { - return true; - } + return true; } - public bool Sense + public bool ReadSenseBuffer() { - get - { - return true; - } + return true; } } } diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/Chip2114.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/Chip2114.cs index 73fa907af4..16632be01c 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/Chip2114.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/Chip2114.cs @@ -31,12 +31,12 @@ ram[addr & 0x3FF] = (byte)(val & 0xF); } - public byte Read(ushort addr) + public byte Read(int addr) { return (byte)(ram[addr & 0x3FF]); } - public byte Read(ushort addr, byte bus) + public byte Read(int addr, byte bus) { return (byte)(ram[addr & 0x3FF] | (bus & 0xF0)); } @@ -47,7 +47,7 @@ ser.Sync("ram", ref buffer); } - public void Write(ushort addr, byte val) + public void Write(int addr, byte val) { ram[addr & 0x3FF] = (byte)(val & 0xF); } diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/Chip23XX.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/Chip23XX.cs index 7ccb1a542d..00a18b28b6 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/Chip23XX.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/Chip23XX.cs @@ -43,7 +43,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS public byte Peek(int addr) { - return rom[addr & (int)addrMask]; + return rom[addr & addrMask]; } public void Poke(int addr, byte val) @@ -51,7 +51,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS // do nothing (this is rom) } - public byte Read(ushort addr) + public byte Read(int addr) { return rom[addr & addrMask]; } @@ -62,7 +62,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS ser.Sync("rom", ref buffer); } - public void Write(ushort addr, byte val) + 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 f2d78a4d42..00effda4f7 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/Chip4864.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/Chip4864.cs @@ -30,15 +30,15 @@ public byte Peek(int addr) { - return ram[addr & 0xFFFF]; + return ram[addr]; } public void Poke(int addr, byte val) { - ram[addr & 0xFFFF] = val; + ram[addr] = val; } - public byte Read(ushort addr) + public byte Read(int addr) { return ram[addr]; } @@ -49,7 +49,7 @@ ser.Sync("ram", ref buffer); } - public void Write(ushort addr, byte val) + public void Write(int addr, byte val) { ram[addr] = val; } diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/MOS6510.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/MOS6510.cs index ce170f1349..5558191421 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/MOS6510.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/MOS6510.cs @@ -28,9 +28,9 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS public Func ReadIRQ; public Func ReadNMI; public Func ReadRDY; - public Func ReadMemory; + public Func ReadMemory; public Func ReadPort; - public Action WriteMemory; + public Action WriteMemory; // ------------------------------------ @@ -65,7 +65,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS cpu.FlagI = true; cpu.BCD_Enabled = true; if (ReadMemory != null) - cpu.PC = (ushort)(ReadMemory(0xFFFC) | (ReadMemory(0xFFFD) << 8)); + cpu.PC = (ushort)(ReadMemory(0x0FFFC) | (ReadMemory(0x0FFFD) << 8)); // configure data port defaults port = new LatchedPort(); @@ -130,6 +130,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS public byte Peek(int addr) { + addr &= 0xFFFF; if (addr == 0x0000) return port.Direction; else if (addr == 0x0001) @@ -140,7 +141,8 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS public void Poke(int addr, byte val) { - if (addr == 0x0000) + addr &= 0xFFFF; + if (addr == 0x0000) port.Direction = val; else if (addr == 0x0001) port.Latch = val; diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/MOS6526.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/MOS6526.cs index bc49f6d4be..1dec0ee427 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/MOS6526.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/MOS6526.cs @@ -45,6 +45,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS public Func ReadCNT; public Func ReadFlag; + public Func ReadSP; // ------------------------------------ @@ -60,9 +61,11 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS private bool intSP; private bool[] intTimer; private bool pinCnt; - private bool pinPC; + private bool pinCntLast; + private bool pinPC; + private bool pinSP; private byte sr; - private uint[] timerDelay; + private int[] timerDelay; private InMode[] timerInMode; private OutMode[] timerOutMode; private bool[] timerPortEnable; @@ -72,8 +75,8 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS private byte[] tod; private byte[] todAlarm; private bool todAlarmPM; - private uint todCounter; - private uint todCounterLatch; + private int todCounter; + private int todCounterLatch; private bool todIn; private bool todPM; @@ -84,7 +87,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS chipRegion = region; enableIntTimer = new bool[2]; intTimer = new bool[2]; - timerDelay = new uint[2]; + timerDelay = new int[2]; timerInMode = new InMode[2]; timerOutMode = new OutMode[2]; timerPortEnable = new bool[2]; @@ -106,8 +109,12 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS public void ExecutePhase2() { { - pinPC = true; - TODRun(); + bool sumCnt = ReadCNT(); + cntPos |= (!pinCntLast && sumCnt); + pinCntLast = sumCnt; + + pinPC = true; + TODRun(); if (timerPulse[0]) { @@ -217,12 +224,12 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS { { - uint lo; - uint hi; - uint result; + int lo; + int hi; + int result; - lo = (i & (uint)0x0F) + (j & (uint)0x0F); - hi = (i & (uint)0x70) + (j & (uint)0x70); + lo = (i & 0x0F) + (j & 0x0F); + hi = (i & 0x70) + (j & 0x70); if (lo > 0x09) { hi += 0x10; @@ -238,13 +245,13 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS } } - private void TimerRun(uint index) + private void TimerRun(int index) { { if (timerOn[index]) { - uint t = timer[index]; + int t = timer[index]; bool u = false; { @@ -356,33 +363,22 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS // ------------------------------------ - public bool CNT - { - get { return pinCnt; } - set { cntPos |= (!pinCnt && value); pinCnt = value; } - } - - public bool PC - { - get { return pinPC; } - } - public byte Peek(int addr) { - return ReadRegister((ushort)(addr & 0xF)); + return ReadRegister((addr & 0xF)); } public void Poke(int addr, byte val) { - WriteRegister((ushort)(addr & 0xF), val); + WriteRegister((addr & 0xF), val); } - public byte Read(ushort addr) + public byte Read(int addr) { return Read(addr, 0xFF); } - public byte Read(ushort addr, byte mask) + public byte Read(int addr, byte mask) { addr &= 0xF; byte val; @@ -411,18 +407,28 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS return val; } - private byte ReadRegister(ushort addr) + public bool ReadCNTBuffer() + { + return pinCnt; + } + + public bool ReadPCBuffer() + { + return pinPC; + } + + private byte ReadRegister(int addr) { byte val = 0x00; //unused pin value - uint timerVal; + int timerVal; switch (addr) { case 0x0: - val = portA.ReadInput(ReadPortA()); + val = (byte)(portA.ReadInput(ReadPortA()) & PortAMask); break; case 0x1: - val = portB.ReadInput(ReadPortB()); + val = (byte)(portB.ReadInput(ReadPortB()) & PortBMask); break; case 0x2: val = portA.Direction; @@ -512,7 +518,12 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS return val; } - private uint ReadTimerValue(uint index) + public bool ReadSPBuffer() + { + return pinSP; + } + + private int ReadTimerValue(int index) { if (timerOn[index]) { @@ -530,13 +541,13 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS public void SyncState(Serializer ser) { int chipRegionInt = (int)chipRegion; - int timerInModeInt0 = (int)timerInMode[0]; - int timerInModeInt1 = (int)timerInMode[1]; - int timerOutModeInt0 = (int)timerOutMode[0]; - int timerOutModeInt1 = (int)timerOutMode[1]; - int timerRunModeInt0 = (int)timerRunMode[0]; - int timerRunModeInt1 = (int)timerRunMode[1]; - int timerSPModeInt = (int)timerSPMode; + int timerInModeInt0 = (int)timerInMode[0]; + int timerInModeInt1 = (int)timerInMode[1]; + int timerOutModeInt0 = (int)timerOutMode[0]; + int timerOutModeInt1 = (int)timerOutMode[1]; + int timerRunModeInt0 = (int)timerRunMode[0]; + int timerRunModeInt1 = (int)timerRunMode[1]; + int timerSPModeInt = (int)timerSPMode; SyncInternal(ser); ser.Sync("alarmSelect", ref alarmSelect); @@ -592,12 +603,12 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS timerSPMode = (SPMode)timerSPModeInt; } - public void Write(ushort addr, byte val) + public void Write(int addr, byte val) { Write(addr, val, 0xFF); } - public void Write(ushort addr, byte val, byte mask) + public void Write(int addr, byte val, byte mask) { addr &= 0xF; val &= mask; @@ -635,7 +646,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS } } - public void WriteRegister(ushort addr, byte val) + public void WriteRegister(int addr, byte val) { bool intReg; @@ -659,7 +670,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS break; case 0x5: timerLatch[0] &= 0x00FF; - timerLatch[0] |= (uint)val << 8; + timerLatch[0] |= val << 8; break; case 0x6: timerLatch[1] &= 0xFF00; @@ -667,7 +678,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS break; case 0x7: timerLatch[1] &= 0x00FF; - timerLatch[1] |= (uint)val << 8; + timerLatch[1] |= val << 8; break; case 0x8: if (alarmSelect) diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/MOSPLA.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/MOSPLA.cs index 5473ce6381..339db45f0e 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/MOSPLA.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/MOSPLA.cs @@ -34,34 +34,34 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS public Action PokeVic; public Func ReadAEC; public Func ReadBA; - public Func ReadBasicRom; - public Func ReadCartridgeLo; - public Func ReadCartridgeHi; + public Func ReadBasicRom; + public Func ReadCartridgeLo; + public Func ReadCartridgeHi; public Func ReadCharen; - public Func ReadCharRom; - public Func ReadCia0; - public Func ReadCia1; - public Func ReadColorRam; - public Func ReadExpansionLo; - public Func ReadExpansionHi; + public Func ReadCharRom; + public Func ReadCia0; + public Func ReadCia1; + public Func ReadColorRam; + public Func ReadExpansionLo; + public Func ReadExpansionHi; public Func ReadExRom; public Func ReadGame; public Func ReadHiRam; - public Func ReadKernalRom; + public Func ReadKernalRom; public Func ReadLoRam; - public Func ReadMemory; - public Func ReadSid; - public Func ReadVic; - public Action WriteCartridgeLo; - public Action WriteCartridgeHi; - public Action WriteCia0; - public Action WriteCia1; - public Action WriteColorRam; - public Action WriteExpansionLo; - public Action WriteExpansionHi; - public Action WriteMemory; - public Action WriteSid; - public Action WriteVic; + public Func ReadMemory; + public Func ReadSid; + public Func ReadVic; + public Action WriteCartridgeLo; + public Action WriteCartridgeHi; + public Action WriteCia0; + public Action WriteCia1; + public Action WriteColorRam; + public Action WriteExpansionLo; + public Action WriteExpansionHi; + public Action WriteMemory; + public Action WriteSid; + public Action WriteVic; // ------------------------------------ @@ -127,16 +127,16 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS bool aec; bool cas; - private PLABank Bank(ushort addr, bool read) + private PLABank Bank(int addr, bool read) { loram = ReadLoRam(); hiram = ReadHiRam(); game = ReadGame(); - a15 = (addr & 0x8000) != 0; - a14 = (addr & 0x4000) != 0; - a13 = (addr & 0x2000) != 0; - a12 = (addr & 0x1000) != 0; + a15 = (addr & 0x08000) != 0; + a14 = (addr & 0x04000) != 0; + a13 = (addr & 0x02000) != 0; + a12 = (addr & 0x01000) != 0; aec = !ReadAEC(); //active low p0 = loram && hiram && a15 && !a14 && a13 && !aec && read && game; @@ -228,7 +228,8 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS public byte Peek(int addr) { - switch (Bank((ushort)(addr & 0xFFFF), true)) + addr &= 0x0FFFF; + switch (Bank(addr, true)) { case PLABank.BasicROM: return PeekBasicRom(addr); @@ -250,8 +251,6 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS return PeekExpansionHi(addr); case PLABank.KernalROM: return PeekKernalRom(addr); - case PLABank.None: - return 0xFF; case PLABank.RAM: return PeekMemory(addr); case PLABank.Sid: @@ -264,18 +263,15 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS public void Poke(int addr, byte val) { - switch (Bank((ushort)(addr & 0xFFFF), false)) + addr &= 0x0FFFF; + switch (Bank(addr, false)) { - case PLABank.BasicROM: - break; case PLABank.CartridgeHi: PokeCartridgeHi(addr, val); break; case PLABank.CartridgeLo: PokeCartridgeLo(addr, val); break; - case PLABank.CharROM: - break; case PLABank.Cia0: PokeCia0(addr, val); break; @@ -291,10 +287,6 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS case PLABank.Expansion1: PokeExpansionHi(addr, val); break; - case PLABank.KernalROM: - break; - case PLABank.None: - break; case PLABank.RAM: PokeMemory(addr, val); break; @@ -307,8 +299,9 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS } } - public byte Read(ushort addr) + public byte Read(int addr) { + addr &= 0x0FFFF; switch (Bank(addr, true)) { case PLABank.BasicROM: @@ -341,8 +334,9 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS return 0xFF; } - public void Write(ushort addr, byte val) + public void Write(int addr, byte val) { + addr &= 0x0FFFF; switch (Bank(addr, false)) { case PLABank.BasicROM: @@ -355,8 +349,6 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS WriteCartridgeLo(addr, val); WriteMemory(addr, val); break; - case PLABank.CharROM: - break; case PLABank.Cia0: WriteCia0(addr, val); break; @@ -372,10 +364,6 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS case PLABank.Expansion1: WriteExpansionHi(addr, val); return; - case PLABank.KernalROM: - break; - case PLABank.None: - break; case PLABank.RAM: WriteMemory(addr, val); break; diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/Port.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/Port.cs index f81db8b10b..c9db14bbd0 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/Port.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/Port.cs @@ -36,4 +36,39 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS return (byte)((Latch & Direction) | (Direction ^ 0xFF)); } } + + public class LatchedBooleanPort + { + public bool Direction; + public bool Latch; + + public LatchedBooleanPort() + { + Direction = false; + Latch = false; + } + + // data dir bus out + // 0 0 0 0 + // 0 0 1 1 + + // 0 1 0 0 + // 0 1 1 0 + + // 1 0 0 0 + // 1 0 1 1 + + // 1 1 0 1 + // 1 1 1 1 + + public bool ReadInput(bool bus) + { + return (Direction && Latch) || (!Direction && bus); + } + + public bool ReadOutput() + { + return (Latch || !Direction); + } + } } diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/SerialPort.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/SerialPort.cs index f1f9c287b8..fd95de24a2 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/SerialPort.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/SerialPort.cs @@ -7,48 +7,26 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS public class SerialPort { - public Func DeviceReadAtn; - public Func DeviceReadClock; - public Func DeviceReadData; - public Func DeviceReadReset; - public Action DeviceWriteAtn; - public Action DeviceWriteClock; - public Action DeviceWriteData; - public Action DeviceWriteSrq; - - public Func SystemReadAtn; - public Func SystemReadClock; - public Func SystemReadData; - public Func SystemReadSrq; - public Action SystemWriteAtn; - public Action SystemWriteClock; - public Action SystemWriteData; - public Action SystemWriteReset; - - // Connect() needs to set System functions above + public Func ReadAtnOut; + public Func ReadClockOut; + public Func ReadDataOut; public SerialPort() { - DeviceReadAtn = (() => { return true; }); - DeviceReadClock = (() => { return true; }); - DeviceReadData = (() => { return true; }); - DeviceReadReset = (() => { return true; }); - DeviceWriteAtn = ((bool val) => { }); - DeviceWriteClock = ((bool val) => { }); - DeviceWriteData = ((bool val) => { }); - DeviceWriteSrq = ((bool val) => { }); - SystemReadAtn = (() => { return true; }); - SystemReadClock = (() => { return true; }); - SystemReadData = (() => { return true; }); - SystemReadSrq = (() => { return true; }); - SystemWriteAtn = ((bool val) => { }); - SystemWriteClock = ((bool val) => { }); - SystemWriteData = ((bool val) => { }); - SystemWriteReset = ((bool val) => { }); } public void HardReset() { } + + public bool WriteClockIn() + { + return true; + } + + public bool WriteDataIn() + { + return true; + } } } diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/Sid.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/Sid.cs index 4d48581434..72caf10ea1 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/Sid.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/Sid.cs @@ -419,9 +419,9 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS waveform = (value >> 4) & 0x0F; wave = waveTable[waveform & 0x07]; ringMsbMask = ((~value >> 5) & (value >> 2) & 0x1) << 23; - noNoise = ((waveform & 0x8) != 0) ? (int)0x000 : (int)0xFFF; + noNoise = ((waveform & 0x8) != 0) ? 0x000 : 0xFFF; noNoiseOrNoise = noNoise | noise; - noPulse = ((waveform & 0x4) != 0) ? (int)0x000 : (int)0xFFF; + noPulse = ((waveform & 0x4) != 0) ? 0x000 : 0xFFF; if (!testPrev && test) { @@ -503,7 +503,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS if (floatOutputTTL != 0 && --floatOutputTTL == 0) output = 0x000; } - pulse = ((accumulator >> 12) >= pulseWidth) ? (int)0xFFF : (int)0x000; + pulse = ((accumulator >> 12) >= pulseWidth) ? 0xFFF : 0x000; return output; } } @@ -759,15 +759,15 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS public byte Peek(int addr) { - return ReadRegister((ushort)(addr & 0x1F)); + return ReadRegister((addr & 0x1F)); } public void Poke(int addr, byte val) { - WriteRegister((ushort)(addr & 0x1F), val); + WriteRegister((addr & 0x1F), val); } - public byte Read(ushort addr) + public byte Read(int addr) { addr &= 0x1F; byte result = 0x00; @@ -783,7 +783,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS return result; } - private byte ReadRegister(ushort addr) + private byte ReadRegister(int addr) { byte result = 0x00; @@ -892,7 +892,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS return result; } - public void Write(ushort addr, byte val) + public void Write(int addr, byte val) { addr &= 0x1F; switch (addr) @@ -912,7 +912,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS } } - private void WriteRegister(ushort addr, byte val) + private void WriteRegister(int addr, byte val) { switch (addr) { diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/Timer.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/Timer.cs index a6d78128cf..727c44094f 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/Timer.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/Timer.cs @@ -6,11 +6,14 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS public abstract class Timer { + public byte PortAMask = 0xFF; + public byte PortBMask = 0xFF; + protected bool pinIRQ; protected LatchedPort portA; protected LatchedPort portB; - protected uint[] timer; - protected uint[] timerLatch; + protected int[] timer; + protected int[] timerLatch; protected bool[] timerOn; protected bool[] underflow; @@ -21,8 +24,8 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS { portA = new LatchedPort(); portB = new LatchedPort(); - timer = new uint[2]; - timerLatch = new uint[2]; + timer = new int[2]; + timerLatch = new int[2]; timerOn = new bool[2]; underflow = new bool[2]; } @@ -36,14 +39,6 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS pinIRQ = true; } - public bool IRQ - { - get - { - return pinIRQ; - } - } - public byte PortAData { get @@ -60,7 +55,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS } } - public bool ReadIRQ() { return pinIRQ; } + public bool ReadIRQBuffer() { return pinIRQ; } protected void SyncInternal(Serializer ser) { diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/UserPort.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/UserPort.cs index 94a87f9f94..eef95a5af6 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/UserPort.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/UserPort.cs @@ -4,51 +4,14 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS { public class UserPort { - private Func peekMemory; - private Action pokeMemory; - private Func readMemory; - private Action writeMemory; + public Func ReadCounter1; + public Func ReadCounter2; + public Func ReadHandshake; + public Func ReadSerial1; + public Func ReadSerial2; public UserPort() { - // start up with no media connected - Disconnect(); - } - - public void Connect(Func funcPeek, Action actPoke, Func funcRead, Action actWrite) - { - peekMemory = funcPeek; - pokeMemory = actPoke; - readMemory = funcRead; - writeMemory = actWrite; - } - - public void Disconnect() - { - peekMemory = DummyPeek; - pokeMemory = DummyPoke; - readMemory = DummyRead; - writeMemory = DummyWrite; - } - - private byte DummyPeek(int addr) - { - return 0xFF; - } - - private void DummyPoke(int addr, byte val) - { - // do nothing - } - - private byte DummyRead(ushort addr) - { - return 0xFF; - } - - private void DummyWrite(ushort addr, byte val) - { - // do nothing } public void HardReset() @@ -56,24 +19,49 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS // note: this will not disconnect any attached media } - public byte Peek(int addr) - { - return peekMemory(addr); - } + public bool ReadAtn() + { + return true; + } - public void Poke(int addr, byte val) - { - pokeMemory(addr, val); - } + public bool ReadCounter1Buffer() + { + return true; + } - public byte Read(ushort addr) - { - return readMemory(addr); - } + public bool ReadCounter2Buffer() + { + return true; + } - public void Write(ushort addr, byte val) - { - writeMemory(addr, val); - } - } + public byte ReadData() + { + return 0xFF; + } + + public bool ReadFlag2() + { + return true; + } + + public bool ReadPA2() + { + return true; + } + + public bool ReadReset() + { + return true; + } + + public bool ReadSerial1Buffer() + { + return true; + } + + public bool ReadSerial2Buffer() + { + return true; + } + } } diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/Vic.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/Vic.cs index 33766123d3..c25b9fb7bc 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/Vic.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/Vic.cs @@ -105,7 +105,8 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS private int cycleIndex; private int dataC; private int dataG; - private int displayC; + private bool debugScreen; + private int displayC; private bool displayEnable; private int displayIndex; private bool enableIntLightPen; @@ -159,8 +160,8 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS // ------------------------------------ - public Func ReadColorRam; - public Func ReadMemory; + public Func ReadColorRam; + public Func ReadMemory; // ------------------------------------ @@ -168,13 +169,23 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS { { - totalCycles = newCycles; + debugScreen = false; + + totalCycles = newCycles; totalLines = newLines; pipeline = newPipeline; cyclesPerSec = newCyclesPerSec; pixelBufferDelay = 12; pixelBackgroundBufferDelay = 4; - bufRect = new Rectangle(136 - 24, 51 - 24, 320 + 48, 200 + 48); + + if (debugScreen) + { + bufRect = new Rectangle(0, 0, totalCycles * 8, totalLines); + } + else + { + bufRect = new Rectangle(136 - 24, 51 - 24, 320 + 48, 200 + 48); + } buf = new int[bufRect.Width * bufRect.Height]; bufLength = buf.Length; @@ -425,7 +436,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS { { - ushort addr = 0x3FFF; + int addr = 0x3FFF; int cycleBAsprite0; int cycleBAsprite1; int cycleBAsprite2; @@ -443,7 +454,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS case 0x0100: // fetch R refreshCounter = (refreshCounter - 1) & 0xFF; - addr = (ushort)(0x3F00 | refreshCounter); + addr = (0x3F00 | refreshCounter); ReadMemory(addr); break; case 0x0200: @@ -452,7 +463,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS { if (badline) { - addr = (ushort)((pointerVM << 10) | vc); + addr = ((pointerVM << 10) | vc); dataC = ReadMemory(addr); dataC |= ((int)ReadColorRam(addr) & 0xF) << 8; bufferC[vmli] = dataC; @@ -475,9 +486,9 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS else { if (bitmapMode) - addr = (ushort)(rc | (vc << 3) | ((pointerCB & 0x4) << 11)); + addr = (rc | (vc << 3) | ((pointerCB & 0x4) << 11)); else - addr = (ushort)(rc | ((dataC & 0xFF) << 3) | (pointerCB << 11)); + addr = (rc | ((dataC & 0xFF) << 3) | (pointerCB << 11)); } if (extraColorMode) addr &= 0x39FF; @@ -491,7 +502,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS break; case 0x0400: // fetch I - addr = (extraColorMode ? (ushort)0x39FF : (ushort)0x3FFF); + addr = (extraColorMode ? 0x39FF : 0x3FFF); dataG = ReadMemory(addr); dataC = 0; break; @@ -504,7 +515,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS { case 0x00: // fetch P - addr = (ushort)(0x3F8 | (pointerVM << 10) | cycleFetchSpriteIndex); + addr = (0x3F8 | (pointerVM << 10) | cycleFetchSpriteIndex); sprites[cycleFetchSpriteIndex].pointer = ReadMemory(addr); sprites[cycleFetchSpriteIndex].shiftEnable = false; break; @@ -515,7 +526,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS if (sprites[cycleFetchSpriteIndex].dma) { Sprite spr = sprites[cycleFetchSpriteIndex]; - addr = (ushort)(spr.mc | (spr.pointer << 6)); + addr = (spr.mc | (spr.pointer << 6)); spr.sr <<= 8; spr.sr |= ReadMemory(addr); spr.mc++; @@ -878,13 +889,9 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS // ------------------------------------ - public bool AEC { get { return pinAEC; } } - public bool BA { get { return pinBA; } } - public bool IRQ { get { return pinIRQ; } } - - public bool ReadAEC() { return pinAEC; } - public bool ReadBA() { return pinBA; } - public bool ReadIRQ() { return pinIRQ; } + public bool ReadAECBuffer() { return pinAEC; } + public bool ReadBABuffer() { return pinBA; } + public bool ReadIRQBuffer() { return pinIRQ; } // ------------------------------------ @@ -892,7 +899,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS { get { - return (int)(totalCycles * totalLines); + return (totalCycles * totalLines); } } @@ -908,15 +915,15 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS public byte Peek(int addr) { - return ReadRegister((ushort)(addr & 0x3F)); + return ReadRegister((addr & 0x3F)); } public void Poke(int addr, byte val) { - WriteRegister((ushort)(addr & 0x3F), val); + WriteRegister((addr & 0x3F), val); } - public byte Read(ushort addr) + public byte Read(int addr) { byte result; addr &= 0x3F; @@ -930,13 +937,13 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS WriteRegister(addr, 0); break; default: - result = ReadRegister((ushort)(addr & 0x3F)); + result = ReadRegister((addr & 0x3F)); break; } return result; } - private byte ReadRegister(ushort addr) + private byte ReadRegister(int addr) { byte result = 0xFF; //unused bit value @@ -1158,7 +1165,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS return result; } - public void Write(ushort addr, byte val) + public void Write(int addr, byte val) { addr &= 0x3F; switch (addr) @@ -1207,7 +1214,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS } } - private void WriteRegister(ushort addr, byte val) + private void WriteRegister(int addr, byte val) { switch (addr) { diff --git a/BizHawk.Emulation/Computers/Commodore64/Media/PRG.cs b/BizHawk.Emulation/Computers/Commodore64/Media/PRG.cs index 85839036b2..c90cb8e991 100644 --- a/BizHawk.Emulation/Computers/Commodore64/Media/PRG.cs +++ b/BizHawk.Emulation/Computers/Commodore64/Media/PRG.cs @@ -6,11 +6,11 @@ namespace BizHawk.Emulation.Computers.Commodore64.Media { static public void Load(MOSPLA pla, byte[] prgFile) { - uint length = (uint)prgFile.Length; + int length = prgFile.Length; if (length > 2) { - ushort addr = (ushort)(prgFile[0] | (prgFile[1] << 8)); - uint offset = 2; + int addr = (prgFile[0] | (prgFile[1] << 8)); + int offset = 2; unchecked { while (offset < length) diff --git a/BizHawk.Emulation/Computers/Commodore64/Memory.cs b/BizHawk.Emulation/Computers/Commodore64/Memory.cs deleted file mode 100644 index e3a52c7370..0000000000 --- a/BizHawk.Emulation/Computers/Commodore64/Memory.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace BizHawk.Emulation.Computers.Commodore64 -{ - class Memory - { - } -}