Commodore64: Removed a lot of unnecessary function chains and converted unsigned types to int.

This commit is contained in:
saxxonpike 2013-08-14 05:05:17 +00:00
parent 18582d7c4f
commit 5c37b64eec
31 changed files with 478 additions and 500 deletions

View File

@ -99,7 +99,6 @@
<Compile Include="Computers\Commodore64\Disk\VIC1541.cs" /> <Compile Include="Computers\Commodore64\Disk\VIC1541.cs" />
<Compile Include="Computers\Commodore64\Disk\VIC1541.PLA.cs" /> <Compile Include="Computers\Commodore64\Disk\VIC1541.PLA.cs" />
<Compile Include="Computers\Commodore64\Media\PRG.cs" /> <Compile Include="Computers\Commodore64\Media\PRG.cs" />
<Compile Include="Computers\Commodore64\Memory.cs" />
<Compile Include="Computers\Commodore64\Cartridge\Cart.cs" /> <Compile Include="Computers\Commodore64\Cartridge\Cart.cs" />
<Compile Include="Computers\Commodore64\MOS\CartridgePort.cs" /> <Compile Include="Computers\Commodore64\MOS\CartridgePort.cs" />
<Compile Include="Computers\Commodore64\MOS\CassettePort.cs" /> <Compile Include="Computers\Commodore64\MOS\CassettePort.cs" />

View File

@ -106,7 +106,7 @@ namespace BizHawk.Emulation.Computers.Commodore64
static public class C64Util static public class C64Util
{ {
static public string ToBinary(uint n, uint charsmin) static public string ToBinary(int n, int charsmin)
{ {
string result = ""; string result = "";
@ -121,13 +121,13 @@ namespace BizHawk.Emulation.Computers.Commodore64
return result; return result;
} }
static public string ToHex(uint n, uint charsmin) static public string ToHex(int n, int charsmin)
{ {
string result = ""; string result = "";
while (n > 0 || charsmin > 0) while (n > 0 || charsmin > 0)
{ {
result = "0123456789ABCDEF".Substring((int)(n & 0xF), 1) + result; result = "0123456789ABCDEF".Substring((n & 0xF), 1) + result;
n >>= 4; n >>= 4;
if (charsmin > 0) if (charsmin > 0)
charsmin--; charsmin--;

View File

@ -61,9 +61,9 @@ namespace BizHawk.Emulation.Computers.Commodore64
byte joyA = 0xFF; byte joyA = 0xFF;
byte joyB = 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]) 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]) if (joystickPressed[1, i])
joyA &= inputBitMask[i]; joyA &= inputBitMask[i];
@ -89,6 +89,9 @@ namespace BizHawk.Emulation.Computers.Commodore64
cia0InputLatchA = resultA; cia0InputLatchA = resultA;
cia0InputLatchB = resultB; cia0InputLatchB = resultB;
// this joystick has special rules.
cia0.PortAMask = joyA;
} }
} }
} }

View File

@ -2,6 +2,9 @@
namespace BizHawk.Emulation.Computers.Commodore64 namespace BizHawk.Emulation.Computers.Commodore64
{ {
/// <summary>
/// Contains the onboard chipset and glue.
/// </summary>
public partial class Motherboard public partial class Motherboard
{ {
// chips // chips
@ -25,9 +28,11 @@ namespace BizHawk.Emulation.Computers.Commodore64
public UserPort userPort; public UserPort userPort;
// state // state
public ushort address; public int address;
public byte bus; public byte bus;
public bool inputRead; public bool inputRead;
public bool irq;
public bool nmi;
public Motherboard(Region initRegion) public Motherboard(Region initRegion)
{ {
@ -92,24 +97,31 @@ namespace BizHawk.Emulation.Computers.Commodore64
public void Init() public void Init()
{ {
cassPort.ReadDataOutput = CassPort_DeviceReadLevel; cartPort.ReadIRQ = Glue_ReadIRQ;
cassPort.ReadMotor = CassPort_DeviceReadMotor; 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.ReadPortA = Cia0_ReadPortA;
cia0.ReadPortB = Cia0_ReadPortB; 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.ReadPortA = Cia1_ReadPortA;
cia1.ReadPortB = Cia1_ReadPortB; cia1.ReadPortB = userPort.ReadData;
cia1.ReadSP = Cia1_ReadSP;
cpu.PeekMemory = pla.Peek; cpu.PeekMemory = pla.Peek;
cpu.PokeMemory = pla.Poke; cpu.PokeMemory = pla.Poke;
cpu.ReadAEC = vic.ReadAEC; cpu.ReadAEC = vic.ReadAECBuffer;
cpu.ReadIRQ = Cpu_ReadIRQ; cpu.ReadIRQ = Glue_ReadIRQ;
cpu.ReadNMI = cia1.ReadIRQ; cpu.ReadNMI = cia1.ReadIRQBuffer;
cpu.ReadPort = Cpu_ReadPort; cpu.ReadPort = Cpu_ReadPort;
cpu.ReadRDY = vic.ReadBA; cpu.ReadRDY = vic.ReadBABuffer;
cpu.ReadMemory = pla.Read; cpu.ReadMemory = pla.Read;
cpu.WriteMemory = pla.Write; cpu.WriteMemory = pla.Write;
@ -136,8 +148,8 @@ namespace BizHawk.Emulation.Computers.Commodore64
pla.PokeMemory = ram.Poke; pla.PokeMemory = ram.Poke;
pla.PokeSid = sid.Poke; pla.PokeSid = sid.Poke;
pla.PokeVic = vic.Poke; pla.PokeVic = vic.Poke;
pla.ReadAEC = vic.ReadAEC; pla.ReadAEC = vic.ReadAECBuffer;
pla.ReadBA = vic.ReadBA; pla.ReadBA = vic.ReadBABuffer;
pla.ReadBasicRom = Pla_ReadBasicRom; pla.ReadBasicRom = Pla_ReadBasicRom;
pla.ReadCartridgeHi = Pla_ReadCartridgeHi; pla.ReadCartridgeHi = Pla_ReadCartridgeHi;
pla.ReadCartridgeLo = Pla_ReadCartridgeLo; pla.ReadCartridgeLo = Pla_ReadCartridgeLo;
@ -167,21 +179,15 @@ namespace BizHawk.Emulation.Computers.Commodore64
pla.WriteSid = Pla_WriteSid; pla.WriteSid = Pla_WriteSid;
pla.WriteVic = Pla_WriteVic; pla.WriteVic = Pla_WriteVic;
// note: c64 serport lines are inverted serPort.ReadAtnOut = SerPort_ReadAtnOut;
serPort.DeviceReadAtn = SerPort_DeviceReadAtn; serPort.ReadClockOut = SerPort_ReadClockOut;
serPort.DeviceReadClock = SerPort_DeviceReadClock; serPort.ReadDataOut = SerPort_ReadDataOut;
serPort.DeviceReadData = SerPort_DeviceReadData;
serPort.DeviceReadReset = SerPort_DeviceReadReset;
serPort.DeviceWriteAtn = SerPort_DeviceWriteAtn;
serPort.DeviceWriteClock = SerPort_DeviceWriteClock;
serPort.DeviceWriteData = SerPort_DeviceWriteData;
serPort.DeviceWriteSrq = SerPort_DeviceWriteSrq;
sid.ReadPotX = Sid_ReadPotX; sid.ReadPotX = Sid_ReadPotX;
sid.ReadPotY = Sid_ReadPotY; sid.ReadPotY = Sid_ReadPotY;
vic.ReadMemory = Vic_ReadMemory; vic.ReadMemory = Vic_ReadMemory;
vic.ReadColorRam = Vic_ReadColorRam; vic.ReadColorRam = colorRam.Read;
} }
public void SyncState(Serializer ser) public void SyncState(Serializer ser)

View File

@ -9,19 +9,21 @@ namespace BizHawk.Emulation.Computers.Commodore64
{ {
public partial class Motherboard public partial class Motherboard
{ {
bool CassPort_DeviceReadLevel()
bool CassPort_ReadDataOutput()
{ {
return (cpu.PortData & 0x08) != 0; return (cpu.PortData & 0x08) != 0;
} }
bool CassPort_DeviceReadMotor() bool CassPort_ReadMotor()
{ {
return (cpu.PortData & 0x20) != 0; return (cpu.PortData & 0x20) != 0;
} }
bool Cia0_ReadFlag() bool Cia0_ReadCnt()
{ {
return cassPort.DataInput; return (userPort.ReadCounter1Buffer() && cia0.ReadCNTBuffer());
} }
byte Cia0_ReadPortA() byte Cia0_ReadPortA()
@ -36,55 +38,60 @@ namespace BizHawk.Emulation.Computers.Commodore64
return cia0InputLatchB; 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() byte Cia1_ReadPortA()
{ {
// the low bits are actually the VIC memory address. // 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; return (userPort.ReadSerial2Buffer() && cia1.ReadSPBuffer());
}
bool Cpu_ReadCassetteButton()
{
return true;
}
bool Cpu_ReadIRQ()
{
return cia0.IRQ & vic.IRQ & cartPort.IRQ;
} }
byte Cpu_ReadPort() byte Cpu_ReadPort()
{ {
byte data = 0x1F; byte data = 0x1F;
if (!cassPort.Sense) if (!cassPort.ReadSenseBuffer())
data &= 0xEF; data &= 0xEF;
return data; return data;
} }
byte Pla_ReadBasicRom(ushort addr) bool Glue_ReadIRQ()
{
return cia0.ReadIRQBuffer() & vic.ReadIRQBuffer() & cartPort.ReadIRQBuffer();
}
byte Pla_ReadBasicRom(int addr)
{ {
address = addr; address = addr;
bus = basicRom.Read(addr); bus = basicRom.Read(addr);
return bus; return bus;
} }
byte Pla_ReadCartridgeHi(ushort addr) byte Pla_ReadCartridgeHi(int addr)
{ {
address = addr; address = addr;
bus = cartPort.ReadHiRom(addr); bus = cartPort.ReadHiRom(addr);
return bus; return bus;
} }
byte Pla_ReadCartridgeLo(ushort addr) byte Pla_ReadCartridgeLo(int addr)
{ {
address = addr; address = addr;
bus = cartPort.ReadLoRom(addr); bus = cartPort.ReadLoRom(addr);
@ -96,14 +103,14 @@ namespace BizHawk.Emulation.Computers.Commodore64
return (cpu.PortData & 0x04) != 0; return (cpu.PortData & 0x04) != 0;
} }
byte Pla_ReadCharRom(ushort addr) byte Pla_ReadCharRom(int addr)
{ {
address = addr; address = addr;
bus = charRom.Read(addr); bus = charRom.Read(addr);
return bus; return bus;
} }
byte Pla_ReadCia0(ushort addr) byte Pla_ReadCia0(int addr)
{ {
address = addr; address = addr;
bus = cia0.Read(addr); bus = cia0.Read(addr);
@ -112,14 +119,14 @@ namespace BizHawk.Emulation.Computers.Commodore64
return bus; return bus;
} }
byte Pla_ReadCia1(ushort addr) byte Pla_ReadCia1(int addr)
{ {
address = addr; address = addr;
bus = cia1.Read(addr); bus = cia1.Read(addr);
return bus; return bus;
} }
byte Pla_ReadColorRam(ushort addr) byte Pla_ReadColorRam(int addr)
{ {
address = addr; address = addr;
bus &= 0xF0; bus &= 0xF0;
@ -127,14 +134,14 @@ namespace BizHawk.Emulation.Computers.Commodore64
return bus; return bus;
} }
byte Pla_ReadExpansionHi(ushort addr) byte Pla_ReadExpansionHi(int addr)
{ {
address = addr; address = addr;
bus = cartPort.ReadHiExp(addr); bus = cartPort.ReadHiExp(addr);
return bus; return bus;
} }
byte Pla_ReadExpansionLo(ushort addr) byte Pla_ReadExpansionLo(int addr)
{ {
address = addr; address = addr;
bus = cartPort.ReadLoExp(addr); bus = cartPort.ReadLoExp(addr);
@ -146,7 +153,7 @@ namespace BizHawk.Emulation.Computers.Commodore64
return (cpu.PortData & 0x02) != 0; return (cpu.PortData & 0x02) != 0;
} }
byte Pla_ReadKernalRom(ushort addr) byte Pla_ReadKernalRom(int addr)
{ {
address = addr; address = addr;
bus = kernalRom.Read(addr); bus = kernalRom.Read(addr);
@ -158,139 +165,112 @@ namespace BizHawk.Emulation.Computers.Commodore64
return (cpu.PortData & 0x01) != 0; return (cpu.PortData & 0x01) != 0;
} }
byte Pla_ReadMemory(ushort addr) byte Pla_ReadMemory(int addr)
{ {
address = addr; address = addr;
bus = ram.Read(addr); bus = ram.Read(addr);
return bus; return bus;
} }
byte Pla_ReadSid(ushort addr) byte Pla_ReadSid(int addr)
{ {
address = addr; address = addr;
bus = sid.Read(addr); bus = sid.Read(addr);
return bus; return bus;
} }
byte Pla_ReadVic(ushort addr) byte Pla_ReadVic(int addr)
{ {
address = addr; address = addr;
bus = vic.Read(addr); bus = vic.Read(addr);
return bus; return bus;
} }
void Pla_WriteCartridgeHi(ushort addr, byte val) void Pla_WriteCartridgeHi(int addr, byte val)
{ {
address = addr; address = addr;
bus = val; bus = val;
cartPort.WriteHiRom(addr, val); cartPort.WriteHiRom(addr, val);
} }
void Pla_WriteCartridgeLo(ushort addr, byte val) void Pla_WriteCartridgeLo(int addr, byte val)
{ {
address = addr; address = addr;
bus = val; bus = val;
cartPort.WriteLoRom(addr, val); cartPort.WriteLoRom(addr, val);
} }
void Pla_WriteCia0(ushort addr, byte val) void Pla_WriteCia0(int addr, byte val)
{ {
address = addr; address = addr;
bus = val; bus = val;
cia0.Write(addr, val); cia0.Write(addr, val);
} }
void Pla_WriteCia1(ushort addr, byte val) void Pla_WriteCia1(int addr, byte val)
{ {
address = addr; address = addr;
bus = val; bus = val;
cia1.Write(addr, val); cia1.Write(addr, val);
} }
void Pla_WriteColorRam(ushort addr, byte val) void Pla_WriteColorRam(int addr, byte val)
{ {
address = addr; address = addr;
bus = val; bus = val;
colorRam.Write(addr, val); colorRam.Write(addr, val);
} }
void Pla_WriteExpansionHi(ushort addr, byte val) void Pla_WriteExpansionHi(int addr, byte val)
{ {
address = addr; address = addr;
bus = val; bus = val;
cartPort.WriteHiExp(addr, val); cartPort.WriteHiExp(addr, val);
} }
void Pla_WriteExpansionLo(ushort addr, byte val) void Pla_WriteExpansionLo(int addr, byte val)
{ {
address = addr; address = addr;
bus = val; bus = val;
cartPort.WriteLoExp(addr, val); cartPort.WriteLoExp(addr, val);
} }
void Pla_WriteMemory(ushort addr, byte val) void Pla_WriteMemory(int addr, byte val)
{ {
address = addr; address = addr;
bus = val; bus = val;
ram.Write(addr, val); ram.Write(addr, val);
} }
void Pla_WriteSid(ushort addr, byte val) void Pla_WriteSid(int addr, byte val)
{ {
address = addr; address = addr;
bus = val; bus = val;
sid.Write(addr, val); sid.Write(addr, val);
} }
void Pla_WriteVic(ushort addr, byte val) void Pla_WriteVic(int addr, byte val)
{ {
address = addr; address = addr;
bus = val; bus = val;
vic.Write(addr, val); vic.Write(addr, val);
} }
bool SerPort_DeviceReadAtn() bool SerPort_ReadAtnOut()
{ {
return (cia1.PortBData & 0x08) == 0; return (cia1.PortBData & 0x08) == 0;
} }
bool SerPort_DeviceReadClock() bool SerPort_ReadClockOut()
{ {
return (cia1.PortAData & 0x10) == 0; return (cia1.PortAData & 0x10) == 0;
} }
bool SerPort_DeviceReadData() bool SerPort_ReadDataOut()
{ {
return (cia1.PortAData & 0x20) == 0; 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() byte Sid_ReadPotX()
{ {
return 0; return 0;
@ -301,7 +281,7 @@ namespace BizHawk.Emulation.Computers.Commodore64
return 0; return 0;
} }
byte Vic_ReadMemory(ushort addr) byte Vic_ReadMemory(int addr)
{ {
switch (cia1.PortAData & 0x3) switch (cia1.PortAData & 0x3)
{ {
@ -323,7 +303,7 @@ namespace BizHawk.Emulation.Computers.Commodore64
return bus; return bus;
} }
byte Vic_ReadColorRam(ushort addr) byte Vic_ReadColorRam(int addr)
{ {
address = addr; address = addr;
bus &= 0xF0; bus &= 0xF0;

View File

@ -146,12 +146,12 @@ namespace BizHawk.Emulation.Computers.Commodore64
{ {
// chips must be initialized before this code runs! // chips must be initialized before this code runs!
var domains = new List<MemoryDomain>(1); var domains = new List<MemoryDomain>(1);
domains.Add(new MemoryDomain("System Bus", 0x10000, Endian.Little, new Func<int, byte>(board.cpu.Peek), new Action<int, byte>(board.cpu.Poke))); domains.Add(new MemoryDomain("System Bus", 0x10000, Endian.Little, board.cpu.Peek, board.cpu.Poke));
domains.Add(new MemoryDomain("RAM", 0x10000, Endian.Little, new Func<int, byte>(board.ram.Peek), new Action<int, byte>(board.ram.Poke))); domains.Add(new MemoryDomain("RAM", 0x10000, Endian.Little, board.ram.Peek, board.ram.Poke));
domains.Add(new MemoryDomain("CIA0", 0x10, Endian.Little, new Func<int, byte>(board.cia0.Peek), new Action<int, byte>(board.cia0.Poke))); domains.Add(new MemoryDomain("CIA0", 0x10, Endian.Little, board.cia0.Peek, board.cia0.Poke));
domains.Add(new MemoryDomain("CIA1", 0x10, Endian.Little, new Func<int, byte>(board.cia1.Peek), new Action<int, byte>(board.cia1.Poke))); domains.Add(new MemoryDomain("CIA1", 0x10, Endian.Little, board.cia1.Peek, board.cia1.Poke));
domains.Add(new MemoryDomain("VIC", 0x40, Endian.Little, new Func<int, byte>(board.vic.Peek), new Action<int, byte>(board.vic.Poke))); domains.Add(new MemoryDomain("VIC", 0x40, Endian.Little, board.vic.Peek, board.vic.Poke));
domains.Add(new MemoryDomain("SID", 0x20, Endian.Little, new Func<int, byte>(board.sid.Peek), new Action<int, byte>(board.sid.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<int, byte>(disk.Peek), new Action<int, byte>(disk.Poke))); //domains.Add(new MemoryDomain("1541 Bus", 0x10000, Endian.Little, new Func<int, byte>(disk.Peek), new Action<int, byte>(disk.Poke)));
//domains.Add(new MemoryDomain("1541 VIA0", 0x10, Endian.Little, new Func<int, byte>(disk.PeekVia0), new Action<int, byte>(disk.PokeVia0))); //domains.Add(new MemoryDomain("1541 VIA0", 0x10, Endian.Little, new Func<int, byte>(disk.PeekVia0), new Action<int, byte>(disk.PokeVia0)));
//domains.Add(new MemoryDomain("1541 VIA1", 0x10, Endian.Little, new Func<int, byte>(disk.PeekVia1), new Action<int, byte>(disk.PokeVia1))); //domains.Add(new MemoryDomain("1541 VIA1", 0x10, Endian.Little, new Func<int, byte>(disk.PeekVia1), new Action<int, byte>(disk.PokeVia1)));

View File

@ -18,14 +18,14 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge
if (new string(reader.ReadChars(16)) == "C64 CARTRIDGE ") if (new string(reader.ReadChars(16)) == "C64 CARTRIDGE ")
{ {
List<uint> chipAddress = new List<uint>(); List<int> chipAddress = new List<int>();
List<uint> chipBank = new List<uint>(); List<int> chipBank = new List<int>();
List<byte[]> chipData = new List<byte[]>(); List<byte[]> chipData = new List<byte[]>();
List<uint> chipType = new List<uint>(); List<int> chipType = new List<int>();
uint headerLength = ReadCRTInt(reader); int headerLength = ReadCRTInt(reader);
uint version = ReadCRTShort(reader); int version = ReadCRTShort(reader);
uint mapper = ReadCRTShort(reader); int mapper = ReadCRTShort(reader);
bool exrom = (reader.ReadByte() != 0); bool exrom = (reader.ReadByte() != 0);
bool game = (reader.ReadByte() != 0); bool game = (reader.ReadByte() != 0);
@ -38,7 +38,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge
// skip extra header bytes // skip extra header bytes
if (headerLength > 0x40) if (headerLength > 0x40)
{ {
reader.ReadBytes((int)headerLength - 0x40); reader.ReadBytes(headerLength - 0x40);
} }
// read chips // read chips
@ -46,15 +46,15 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge
{ {
if (new string(reader.ReadChars(4)) == "CHIP") if (new string(reader.ReadChars(4)) == "CHIP")
{ {
uint chipLength = ReadCRTInt(reader); int chipLength = ReadCRTInt(reader);
chipType.Add(ReadCRTShort(reader)); chipType.Add(ReadCRTShort(reader));
chipBank.Add(ReadCRTShort(reader)); chipBank.Add(ReadCRTShort(reader));
chipAddress.Add(ReadCRTShort(reader)); chipAddress.Add(ReadCRTShort(reader));
uint chipDataLength = ReadCRTShort(reader); int chipDataLength = ReadCRTShort(reader);
chipData.Add(reader.ReadBytes((int)chipDataLength)); chipData.Add(reader.ReadBytes(chipDataLength));
chipLength -= (chipDataLength + 0x10); chipLength -= (chipDataLength + 0x10);
if (chipLength > 0) if (chipLength > 0)
reader.ReadBytes((int)chipLength); reader.ReadBytes(chipLength);
} }
} }
@ -96,21 +96,21 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge
return result; return result;
} }
static private uint ReadCRTShort(BinaryReader reader) static private int ReadCRTShort(BinaryReader reader)
{ {
uint result; int result;
result = (uint)reader.ReadByte() << 8; result = (int)reader.ReadByte() << 8;
result |= (uint)reader.ReadByte(); result |= (int)reader.ReadByte();
return result; return result;
} }
static private uint ReadCRTInt(BinaryReader reader) static private int ReadCRTInt(BinaryReader reader)
{ {
uint result; int result;
result = (uint)reader.ReadByte() << 24; result = (int)reader.ReadByte() << 24;
result |= (uint)reader.ReadByte() << 16; result |= (int)reader.ReadByte() << 16;
result |= (uint)reader.ReadByte() << 8; result |= (int)reader.ReadByte() << 8;
result |= (uint)reader.ReadByte(); result |= (int)reader.ReadByte();
return result; 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; return 0xFF;
} }
public virtual byte ReadA000(ushort addr) public virtual byte ReadA000(int addr)
{ {
return 0xFF; return 0xFF;
} }
public virtual byte ReadDE00(ushort addr) public virtual byte ReadDE00(int addr)
{ {
return 0xFF; return 0xFF;
} }
public virtual byte ReadDF00(ushort addr) public virtual byte ReadDF00(int addr)
{ {
return 0xFF; 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)
{ {
} }
} }

View File

@ -6,14 +6,14 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge
public class Mapper0000 : Cart public class Mapper0000 : Cart
{ {
private byte[] romA; private byte[] romA;
private uint romAMask; private int romAMask;
private byte[] romB; private byte[] romB;
private uint romBMask; private int romBMask;
// standard cartridge mapper (Commodore) // standard cartridge mapper (Commodore)
// note that this format also covers Ultimax carts // note that this format also covers Ultimax carts
public Mapper0000(List<uint> newAddresses, List<uint> newBanks, List<byte[]> newData, bool game, bool exrom) public Mapper0000(List<int> newAddresses, List<int> newBanks, List<byte[]> newData, bool game, bool exrom)
{ {
pinGame = game; pinGame = game;
pinExRom = exrom; pinExRom = exrom;
@ -83,12 +83,12 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge
return romB[addr & romBMask]; return romB[addr & romBMask];
} }
public override byte Read8000(ushort addr) public override byte Read8000(int addr)
{ {
return romA[addr & romAMask]; return romA[addr & romAMask];
} }
public override byte ReadA000(ushort addr) public override byte ReadA000(int addr)
{ {
return romB[addr & romBMask]; return romB[addr & romBMask];
} }

View File

@ -7,19 +7,19 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge
{ {
private byte[][] banksA = new byte[0][]; //8000 private byte[][] banksA = new byte[0][]; //8000
private byte[][] banksB = new byte[0][]; //A000 private byte[][] banksB = new byte[0][]; //A000
private uint bankMask; private int bankMask;
private uint bankNumber; private int bankNumber;
private byte[] currentBankA; private byte[] currentBankA;
private byte[] currentBankB; private byte[] currentBankB;
private byte[] dummyBank; private byte[] dummyBank;
public Mapper0005(List<uint> newAddresses, List<uint> newBanks, List<byte[]> newData) public Mapper0005(List<int> newAddresses, List<int> newBanks, List<byte[]> newData)
{ {
uint count = (uint)newAddresses.Count; int count = newAddresses.Count;
// build dummy bank // build dummy bank
dummyBank = new byte[0x2000]; 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 dummyBank[i] = 0xFF; // todo: determine if this is correct
if (count == 64) //512k if (count == 64) //512k
@ -80,9 +80,9 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge
} }
// for safety, initialize all banks to dummy // 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; banksA[i] = dummyBank;
for (uint i = 0; i < banksB.Length; i++) for (int i = 0; i < banksB.Length; i++)
banksB[i] = dummyBank; banksB[i] = dummyBank;
// now load in the banks // now load in the banks
@ -101,7 +101,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge
BankSet(0); BankSet(0);
} }
private void BankSet(uint index) private void BankSet(int index)
{ {
bankNumber = index & bankMask; bankNumber = index & bankMask;
if (!pinExRom) if (!pinExRom)
@ -131,17 +131,17 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge
BankSet(val); BankSet(val);
} }
public override byte Read8000(ushort addr) public override byte Read8000(int addr)
{ {
return currentBankA[addr]; return currentBankA[addr];
} }
public override byte ReadA000(ushort addr) public override byte ReadA000(int addr)
{ {
return currentBankB[addr]; return currentBankB[addr];
} }
public override void WriteDE00(ushort addr, byte val) public override void WriteDE00(int addr, byte val)
{ {
if (addr == 0x00) if (addr == 0x00)
BankSet(val); BankSet(val);

View File

@ -14,11 +14,11 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge
{ {
private byte[] rom = new byte[0x4000]; private byte[] rom = new byte[0x4000];
public Mapper000B(List<uint> newAddresses, List<uint> newBanks, List<byte[]> newData) public Mapper000B(List<int> newAddresses, List<int> newBanks, List<byte[]> newData)
{ {
validCartridge = false; validCartridge = false;
for (uint i = 0; i < 0x4000; i++) for (int i = 0; i < 0x4000; i++)
rom[i] = 0xFF; rom[i] = 0xFF;
if (newAddresses[0] == 0x8000) if (newAddresses[0] == 0x8000)
@ -38,17 +38,17 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge
return rom[addr | 0x2000]; return rom[addr | 0x2000];
} }
public override byte Read8000(ushort addr) public override byte Read8000(int addr)
{ {
return rom[addr]; return rom[addr];
} }
public override byte ReadA000(ushort addr) public override byte ReadA000(int addr)
{ {
return rom[addr | 0x2000]; return rom[addr | 0x2000];
} }
public override byte ReadDF00(ushort addr) public override byte ReadDF00(int addr)
{ {
pinGame = true; pinGame = true;
return base.ReadDF00(addr); return base.ReadDF00(addr);

View File

@ -13,21 +13,21 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge
public class Mapper000F : Cart public class Mapper000F : Cart
{ {
private byte[][] banks = new byte[0][]; //8000 private byte[][] banks = new byte[0][]; //8000
private uint bankMask; private int bankMask;
private uint bankNumber; private int bankNumber;
private byte[] currentBank; private byte[] currentBank;
private byte[] dummyBank; private byte[] dummyBank;
public Mapper000F(List<uint> newAddresses, List<uint> newBanks, List<byte[]> newData) public Mapper000F(List<int> newAddresses, List<int> newBanks, List<byte[]> newData)
{ {
uint count = (uint)newAddresses.Count; int count = newAddresses.Count;
pinGame = true; pinGame = true;
pinExRom = false; pinExRom = false;
// build dummy bank // build dummy bank
dummyBank = new byte[0x2000]; 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 dummyBank[i] = 0xFF; // todo: determine if this is correct
if (count == 64) //512k if (count == 64) //512k
@ -72,7 +72,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge
} }
// for safety, initialize all banks to dummy // 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; banks[i] = dummyBank;
// now load in the banks // now load in the banks
@ -87,7 +87,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge
BankSet(0); BankSet(0);
} }
protected void BankSet(uint index) protected void BankSet(int index)
{ {
bankNumber = index & bankMask; bankNumber = index & bankMask;
UpdateState(); UpdateState();
@ -100,10 +100,10 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge
public override void PokeDE00(int addr, byte val) 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]; return currentBank[addr];
} }
@ -113,9 +113,9 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge
currentBank = banks[bankNumber]; 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) public override void SyncState(Serializer ser)

View File

@ -9,7 +9,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge
public class Mapper0011 : Mapper000F public class Mapper0011 : Mapper000F
{ {
public Mapper0011(List<uint> newAddresses, List<uint> newBanks, List<byte[]> newData) public Mapper0011(List<int> newAddresses, List<int> newBanks, List<byte[]> newData)
: base(newAddresses, newBanks, newData) : base(newAddresses, newBanks, newData)
{ {
// required to pass information to base class // required to pass information to base class
@ -20,13 +20,13 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge
// do nothing // do nothing
} }
public override byte ReadDE00(ushort addr) public override byte ReadDE00(int addr)
{ {
BankSet((uint)addr); BankSet(addr);
return base.ReadDE00(addr); return base.ReadDE00(addr);
} }
public override void WriteDE00(ushort addr, byte val) public override void WriteDE00(int addr, byte val)
{ {
// do nothing // do nothing
} }

View File

@ -8,21 +8,21 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge
private byte[] bankMain; private byte[] bankMain;
private byte[][] bankHigh; private byte[][] bankHigh;
private byte[] bankHighSelected; private byte[] bankHighSelected;
private uint bankIndex; private int bankIndex;
private byte[] dummyBank; private byte[] dummyBank;
// Zaxxon and Super Zaxxon cartridges // Zaxxon and Super Zaxxon cartridges
// - read to 8xxx selects bank 0 in A000-BFFF // - read to 8xxx selects bank 0 in A000-BFFF
// - read to 9xxx selects bank 1 in A000-BFFF // - read to 9xxx selects bank 1 in A000-BFFF
public Mapper0012(List<uint> newAddresses, List<uint> newBanks, List<byte[]> newData) public Mapper0012(List<int> newAddresses, List<int> newBanks, List<byte[]> newData)
{ {
bankMain = new byte[0x2000]; bankMain = new byte[0x2000];
bankHigh = new byte[2][]; bankHigh = new byte[2][];
dummyBank = new byte[0x2000]; dummyBank = new byte[0x2000];
// create dummy bank just in case // create dummy bank just in case
for (uint i = 0; i < 0x2000; i++) for (int i = 0; i < 0x2000; i++)
dummyBank[i] = 0xFF; dummyBank[i] = 0xFF;
bankHigh[0] = dummyBank; bankHigh[0] = dummyBank;
@ -56,14 +56,14 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge
return bankHighSelected[addr]; 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]; bankHighSelected = bankHigh[bankIndex];
return bankMain[addr]; return bankMain[addr];
} }
public override byte ReadA000(ushort addr) public override byte ReadA000(int addr)
{ {
return bankHighSelected[addr]; return bankHighSelected[addr];
} }

View File

@ -14,15 +14,15 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge
public class Mapper0013 : Cart public class Mapper0013 : Cart
{ {
private byte[][] banks = new byte[0][]; //8000 private byte[][] banks = new byte[0][]; //8000
private uint bankMask; private int bankMask;
private uint bankNumber; private int bankNumber;
private byte[] currentBank; private byte[] currentBank;
private byte[] dummyBank; private byte[] dummyBank;
private bool romEnable; private bool romEnable;
public Mapper0013(List<uint> newAddresses, List<uint> newBanks, List<byte[]> newData) public Mapper0013(List<int> newAddresses, List<int> newBanks, List<byte[]> newData)
{ {
uint count = (uint)newAddresses.Count; int count = newAddresses.Count;
pinGame = true; pinGame = true;
pinExRom = false; pinExRom = false;
@ -30,7 +30,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge
// build dummy bank // build dummy bank
dummyBank = new byte[0x2000]; 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 dummyBank[i] = 0xFF; // todo: determine if this is correct
if (count == 16) //128k if (count == 16) //128k
@ -55,7 +55,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge
} }
// for safety, initialize all banks to dummy // 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; banks[i] = dummyBank;
// now load in the banks // now load in the banks
@ -70,7 +70,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge
BankSet(0); BankSet(0);
} }
private void BankSet(uint index) private void BankSet(int index)
{ {
bankNumber = index & bankMask; bankNumber = index & bankMask;
romEnable = ((index & 0x80) == 0); romEnable = ((index & 0x80) == 0);
@ -88,7 +88,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge
BankSet(val); BankSet(val);
} }
public override byte Read8000(ushort addr) public override byte Read8000(int addr)
{ {
return currentBank[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) if (addr == 0x00)
BankSet(val); BankSet(val);
@ -121,7 +121,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge
ser.Sync("bankNumber", ref bankNumber); ser.Sync("bankNumber", ref bankNumber);
ser.Sync("romEnable", ref romEnable); ser.Sync("romEnable", ref romEnable);
if (ser.IsReader) if (ser.IsReader)
BankSet(bankNumber | (uint)(romEnable ? 0x00 : 0x80)); BankSet(bankNumber | (romEnable ? 0x00 : 0x80));
} }
} }
} }

View File

@ -21,20 +21,20 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge
{ {
private byte[][] banksA = new byte[64][]; //8000 private byte[][] banksA = new byte[64][]; //8000
private byte[][] banksB = new byte[64][]; //A000 private byte[][] banksB = new byte[64][]; //A000
private uint bankNumber; private int bankNumber;
private bool boardLed; private bool boardLed;
private byte[] currentBankA; private byte[] currentBankA;
private byte[] currentBankB; private byte[] currentBankB;
private byte[] dummyBank; private byte[] dummyBank;
private byte[] ram = new byte[256]; private byte[] ram = new byte[256];
public Mapper0020(List<uint> newAddresses, List<uint> newBanks, List<byte[]> newData) public Mapper0020(List<int> newAddresses, List<int> newBanks, List<byte[]> newData)
{ {
uint count = (uint)newAddresses.Count; int count = newAddresses.Count;
// build dummy bank // build dummy bank
dummyBank = new byte[0x2000]; 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 dummyBank[i] = 0xFF; // todo: determine if this is correct
// force ultimax mode (the cart SHOULD set this // force ultimax mode (the cart SHOULD set this
@ -43,9 +43,9 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge
pinExRom = true; pinExRom = true;
// for safety, initialize all banks to dummy // for safety, initialize all banks to dummy
for (uint i = 0; i < 64; i++) for (int i = 0; i < 64; i++)
banksA[i] = dummyBank; banksA[i] = dummyBank;
for (uint i = 0; i < 64; i++) for (int i = 0; i < 64; i++)
banksB[i] = dummyBank; banksB[i] = dummyBank;
// load in all banks // load in all banks
@ -65,7 +65,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge
BankSet(0); BankSet(0);
} }
private void BankSet(uint index) private void BankSet(int index)
{ {
bankNumber = index & 0x3F; bankNumber = index & 0x3F;
UpdateState(); UpdateState();
@ -121,17 +121,17 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge
ram[addr] = val; ram[addr] = val;
} }
public override byte Read8000(ushort addr) public override byte Read8000(int addr)
{ {
return currentBankA[addr]; return currentBankA[addr];
} }
public override byte ReadA000(ushort addr) public override byte ReadA000(int addr)
{ {
return currentBankB[addr]; return currentBankB[addr];
} }
public override byte ReadDF00(ushort addr) public override byte ReadDF00(int addr)
{ {
return ram[addr]; return ram[addr];
} }
@ -150,7 +150,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge
currentBankB = banksB[bankNumber]; currentBankB = banksB[bankNumber];
} }
public override void WriteDE00(ushort addr, byte val) public override void WriteDE00(int addr, byte val)
{ {
if (addr == 0x00) if (addr == 0x00)
BankSet(val); BankSet(val);
@ -158,7 +158,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge
StateSet(val); StateSet(val);
} }
public override void WriteDF00(ushort addr, byte val) public override void WriteDF00(int addr, byte val)
{ {
ram[addr] = val; ram[addr] = val;
} }

View File

@ -1,9 +1,13 @@
using BizHawk.Emulation.Computers.Commodore64.Cartridge; using System;
using BizHawk.Emulation.Computers.Commodore64.Cartridge;
namespace BizHawk.Emulation.Computers.Commodore64.MOS namespace BizHawk.Emulation.Computers.Commodore64.MOS
{ {
public class CartridgePort public class CartridgePort
{ {
public Func<bool> ReadIRQ;
public Func<bool> ReadNMI;
private Cart cart; private Cart cart;
private bool connected; 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 ReadExRom() { if (connected) { return cart.ExRom; } else { return true; } }
public bool ReadGame() { if (connected) { return cart.Game; } 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 ReadHiExp(int addr) { if (connected) { return cart.ReadDF00((addr & 0x00FF)); } else { return 0xFF; } }
public byte ReadHiRom(ushort addr) { if (connected) { return cart.ReadA000((ushort)(addr & 0x1FFF)); } else { return 0xFF; } } public byte ReadHiRom(int addr) { if (connected) { return cart.ReadA000((addr & 0x1FFF)); } else { return 0xFF; } }
public byte ReadLoExp(ushort addr) { if (connected) { return cart.ReadDE00((ushort)(addr & 0x00FF)); } else { return 0xFF; } } public byte ReadLoExp(int addr) { if (connected) { return cart.ReadDE00((addr & 0x00FF)); } else { return 0xFF; } }
public byte ReadLoRom(ushort addr) { if (connected) { return cart.Read8000((ushort)(addr & 0x1FFF)); } 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 WriteHiExp(int addr, byte val) { if (connected) { cart.WriteDF00((addr & 0x00FF), val); } }
public void WriteHiRom(ushort addr, byte val) { if (connected) { cart.WriteA000((ushort)(addr & 0x1FFF), val); } } public void WriteHiRom(int addr, byte val) { if (connected) { cart.WriteA000((addr & 0x1FFF), val); } }
public void WriteLoExp(ushort addr, byte val) { if (connected) { cart.WriteDE00((ushort)(addr & 0x00FF), val); } } public void WriteLoExp(int addr, byte val) { if (connected) { cart.WriteDE00((addr & 0x00FF), val); } }
public void WriteLoRom(ushort addr, byte val) { if (connected) { cart.Write8000((ushort)(addr & 0x1FFF), 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 // note: this will not disconnect any attached media
} }
public bool IRQ
{
get
{
return true; //todo: hook this up to cartridge
}
}
public bool IsConnected public bool IsConnected
{ {
get get
@ -72,12 +68,14 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
} }
} }
public bool NMI public bool ReadIRQBuffer()
{ {
get return true;
{
return true; //todo: hook this up to cartridge
} }
public bool ReadNMIBuffer()
{
return true;
} }
public void SyncState(Serializer ser) public void SyncState(Serializer ser)

View File

@ -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;
} }
} }
}
} }

View File

@ -31,12 +31,12 @@
ram[addr & 0x3FF] = (byte)(val & 0xF); ram[addr & 0x3FF] = (byte)(val & 0xF);
} }
public byte Read(ushort addr) public byte Read(int addr)
{ {
return (byte)(ram[addr & 0x3FF]); 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)); return (byte)(ram[addr & 0x3FF] | (bus & 0xF0));
} }
@ -47,7 +47,7 @@
ser.Sync("ram", ref buffer); 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); ram[addr & 0x3FF] = (byte)(val & 0xF);
} }

View File

@ -43,7 +43,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
public byte Peek(int addr) public byte Peek(int addr)
{ {
return rom[addr & (int)addrMask]; return rom[addr & addrMask];
} }
public void Poke(int addr, byte val) public void Poke(int addr, byte val)
@ -51,7 +51,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
// do nothing (this is rom) // do nothing (this is rom)
} }
public byte Read(ushort addr) public byte Read(int addr)
{ {
return rom[addr & addrMask]; return rom[addr & addrMask];
} }
@ -62,7 +62,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
ser.Sync("rom", ref buffer); ser.Sync("rom", ref buffer);
} }
public void Write(ushort addr, byte val) public void Write(int addr, byte val)
{ {
// do nothing (this is rom) // do nothing (this is rom)
} }

View File

@ -30,15 +30,15 @@
public byte Peek(int addr) public byte Peek(int addr)
{ {
return ram[addr & 0xFFFF]; return ram[addr];
} }
public void Poke(int addr, byte val) 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]; return ram[addr];
} }
@ -49,7 +49,7 @@
ser.Sync("ram", ref buffer); ser.Sync("ram", ref buffer);
} }
public void Write(ushort addr, byte val) public void Write(int addr, byte val)
{ {
ram[addr] = val; ram[addr] = val;
} }

View File

@ -28,9 +28,9 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
public Func<bool> ReadIRQ; public Func<bool> ReadIRQ;
public Func<bool> ReadNMI; public Func<bool> ReadNMI;
public Func<bool> ReadRDY; public Func<bool> ReadRDY;
public Func<ushort, byte> ReadMemory; public Func<int, byte> ReadMemory;
public Func<byte> ReadPort; public Func<byte> ReadPort;
public Action<ushort, byte> WriteMemory; public Action<int, byte> WriteMemory;
// ------------------------------------ // ------------------------------------
@ -65,7 +65,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
cpu.FlagI = true; cpu.FlagI = true;
cpu.BCD_Enabled = true; cpu.BCD_Enabled = true;
if (ReadMemory != null) if (ReadMemory != null)
cpu.PC = (ushort)(ReadMemory(0xFFFC) | (ReadMemory(0xFFFD) << 8)); cpu.PC = (ushort)(ReadMemory(0x0FFFC) | (ReadMemory(0x0FFFD) << 8));
// configure data port defaults // configure data port defaults
port = new LatchedPort(); port = new LatchedPort();
@ -130,6 +130,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
public byte Peek(int addr) public byte Peek(int addr)
{ {
addr &= 0xFFFF;
if (addr == 0x0000) if (addr == 0x0000)
return port.Direction; return port.Direction;
else if (addr == 0x0001) else if (addr == 0x0001)
@ -140,6 +141,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
public void Poke(int addr, byte val) public void Poke(int addr, byte val)
{ {
addr &= 0xFFFF;
if (addr == 0x0000) if (addr == 0x0000)
port.Direction = val; port.Direction = val;
else if (addr == 0x0001) else if (addr == 0x0001)

View File

@ -45,6 +45,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
public Func<bool> ReadCNT; public Func<bool> ReadCNT;
public Func<bool> ReadFlag; public Func<bool> ReadFlag;
public Func<bool> ReadSP;
// ------------------------------------ // ------------------------------------
@ -60,9 +61,11 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
private bool intSP; private bool intSP;
private bool[] intTimer; private bool[] intTimer;
private bool pinCnt; private bool pinCnt;
private bool pinCntLast;
private bool pinPC; private bool pinPC;
private bool pinSP;
private byte sr; private byte sr;
private uint[] timerDelay; private int[] timerDelay;
private InMode[] timerInMode; private InMode[] timerInMode;
private OutMode[] timerOutMode; private OutMode[] timerOutMode;
private bool[] timerPortEnable; private bool[] timerPortEnable;
@ -72,8 +75,8 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
private byte[] tod; private byte[] tod;
private byte[] todAlarm; private byte[] todAlarm;
private bool todAlarmPM; private bool todAlarmPM;
private uint todCounter; private int todCounter;
private uint todCounterLatch; private int todCounterLatch;
private bool todIn; private bool todIn;
private bool todPM; private bool todPM;
@ -84,7 +87,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
chipRegion = region; chipRegion = region;
enableIntTimer = new bool[2]; enableIntTimer = new bool[2];
intTimer = new bool[2]; intTimer = new bool[2];
timerDelay = new uint[2]; timerDelay = new int[2];
timerInMode = new InMode[2]; timerInMode = new InMode[2];
timerOutMode = new OutMode[2]; timerOutMode = new OutMode[2];
timerPortEnable = new bool[2]; timerPortEnable = new bool[2];
@ -106,6 +109,10 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
public void ExecutePhase2() public void ExecutePhase2()
{ {
{ {
bool sumCnt = ReadCNT();
cntPos |= (!pinCntLast && sumCnt);
pinCntLast = sumCnt;
pinPC = true; pinPC = true;
TODRun(); TODRun();
@ -217,12 +224,12 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
{ {
{ {
uint lo; int lo;
uint hi; int hi;
uint result; int result;
lo = (i & (uint)0x0F) + (j & (uint)0x0F); lo = (i & 0x0F) + (j & 0x0F);
hi = (i & (uint)0x70) + (j & (uint)0x70); hi = (i & 0x70) + (j & 0x70);
if (lo > 0x09) if (lo > 0x09)
{ {
hi += 0x10; 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]) if (timerOn[index])
{ {
uint t = timer[index]; int t = timer[index];
bool u = false; 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) public byte Peek(int addr)
{ {
return ReadRegister((ushort)(addr & 0xF)); return ReadRegister((addr & 0xF));
} }
public void Poke(int addr, byte val) 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); return Read(addr, 0xFF);
} }
public byte Read(ushort addr, byte mask) public byte Read(int addr, byte mask)
{ {
addr &= 0xF; addr &= 0xF;
byte val; byte val;
@ -411,18 +407,28 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
return val; 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 byte val = 0x00; //unused pin value
uint timerVal; int timerVal;
switch (addr) switch (addr)
{ {
case 0x0: case 0x0:
val = portA.ReadInput(ReadPortA()); val = (byte)(portA.ReadInput(ReadPortA()) & PortAMask);
break; break;
case 0x1: case 0x1:
val = portB.ReadInput(ReadPortB()); val = (byte)(portB.ReadInput(ReadPortB()) & PortBMask);
break; break;
case 0x2: case 0x2:
val = portA.Direction; val = portA.Direction;
@ -512,7 +518,12 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
return val; return val;
} }
private uint ReadTimerValue(uint index) public bool ReadSPBuffer()
{
return pinSP;
}
private int ReadTimerValue(int index)
{ {
if (timerOn[index]) if (timerOn[index])
{ {
@ -592,12 +603,12 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
timerSPMode = (SPMode)timerSPModeInt; timerSPMode = (SPMode)timerSPModeInt;
} }
public void Write(ushort addr, byte val) public void Write(int addr, byte val)
{ {
Write(addr, val, 0xFF); Write(addr, val, 0xFF);
} }
public void Write(ushort addr, byte val, byte mask) public void Write(int addr, byte val, byte mask)
{ {
addr &= 0xF; addr &= 0xF;
val &= mask; 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; bool intReg;
@ -659,7 +670,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
break; break;
case 0x5: case 0x5:
timerLatch[0] &= 0x00FF; timerLatch[0] &= 0x00FF;
timerLatch[0] |= (uint)val << 8; timerLatch[0] |= val << 8;
break; break;
case 0x6: case 0x6:
timerLatch[1] &= 0xFF00; timerLatch[1] &= 0xFF00;
@ -667,7 +678,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
break; break;
case 0x7: case 0x7:
timerLatch[1] &= 0x00FF; timerLatch[1] &= 0x00FF;
timerLatch[1] |= (uint)val << 8; timerLatch[1] |= val << 8;
break; break;
case 0x8: case 0x8:
if (alarmSelect) if (alarmSelect)

View File

@ -34,34 +34,34 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
public Action<int, byte> PokeVic; public Action<int, byte> PokeVic;
public Func<bool> ReadAEC; public Func<bool> ReadAEC;
public Func<bool> ReadBA; public Func<bool> ReadBA;
public Func<ushort, byte> ReadBasicRom; public Func<int, byte> ReadBasicRom;
public Func<ushort, byte> ReadCartridgeLo; public Func<int, byte> ReadCartridgeLo;
public Func<ushort, byte> ReadCartridgeHi; public Func<int, byte> ReadCartridgeHi;
public Func<bool> ReadCharen; public Func<bool> ReadCharen;
public Func<ushort, byte> ReadCharRom; public Func<int, byte> ReadCharRom;
public Func<ushort, byte> ReadCia0; public Func<int, byte> ReadCia0;
public Func<ushort, byte> ReadCia1; public Func<int, byte> ReadCia1;
public Func<ushort, byte> ReadColorRam; public Func<int, byte> ReadColorRam;
public Func<ushort, byte> ReadExpansionLo; public Func<int, byte> ReadExpansionLo;
public Func<ushort, byte> ReadExpansionHi; public Func<int, byte> ReadExpansionHi;
public Func<bool> ReadExRom; public Func<bool> ReadExRom;
public Func<bool> ReadGame; public Func<bool> ReadGame;
public Func<bool> ReadHiRam; public Func<bool> ReadHiRam;
public Func<ushort, byte> ReadKernalRom; public Func<int, byte> ReadKernalRom;
public Func<bool> ReadLoRam; public Func<bool> ReadLoRam;
public Func<ushort, byte> ReadMemory; public Func<int, byte> ReadMemory;
public Func<ushort, byte> ReadSid; public Func<int, byte> ReadSid;
public Func<ushort, byte> ReadVic; public Func<int, byte> ReadVic;
public Action<ushort, byte> WriteCartridgeLo; public Action<int, byte> WriteCartridgeLo;
public Action<ushort, byte> WriteCartridgeHi; public Action<int, byte> WriteCartridgeHi;
public Action<ushort, byte> WriteCia0; public Action<int, byte> WriteCia0;
public Action<ushort, byte> WriteCia1; public Action<int, byte> WriteCia1;
public Action<ushort, byte> WriteColorRam; public Action<int, byte> WriteColorRam;
public Action<ushort, byte> WriteExpansionLo; public Action<int, byte> WriteExpansionLo;
public Action<ushort, byte> WriteExpansionHi; public Action<int, byte> WriteExpansionHi;
public Action<ushort, byte> WriteMemory; public Action<int, byte> WriteMemory;
public Action<ushort, byte> WriteSid; public Action<int, byte> WriteSid;
public Action<ushort, byte> WriteVic; public Action<int, byte> WriteVic;
// ------------------------------------ // ------------------------------------
@ -127,16 +127,16 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
bool aec; bool aec;
bool cas; bool cas;
private PLABank Bank(ushort addr, bool read) private PLABank Bank(int addr, bool read)
{ {
loram = ReadLoRam(); loram = ReadLoRam();
hiram = ReadHiRam(); hiram = ReadHiRam();
game = ReadGame(); game = ReadGame();
a15 = (addr & 0x8000) != 0; a15 = (addr & 0x08000) != 0;
a14 = (addr & 0x4000) != 0; a14 = (addr & 0x04000) != 0;
a13 = (addr & 0x2000) != 0; a13 = (addr & 0x02000) != 0;
a12 = (addr & 0x1000) != 0; a12 = (addr & 0x01000) != 0;
aec = !ReadAEC(); //active low aec = !ReadAEC(); //active low
p0 = loram && hiram && a15 && !a14 && a13 && !aec && read && game; p0 = loram && hiram && a15 && !a14 && a13 && !aec && read && game;
@ -228,7 +228,8 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
public byte Peek(int addr) public byte Peek(int addr)
{ {
switch (Bank((ushort)(addr & 0xFFFF), true)) addr &= 0x0FFFF;
switch (Bank(addr, true))
{ {
case PLABank.BasicROM: case PLABank.BasicROM:
return PeekBasicRom(addr); return PeekBasicRom(addr);
@ -250,8 +251,6 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
return PeekExpansionHi(addr); return PeekExpansionHi(addr);
case PLABank.KernalROM: case PLABank.KernalROM:
return PeekKernalRom(addr); return PeekKernalRom(addr);
case PLABank.None:
return 0xFF;
case PLABank.RAM: case PLABank.RAM:
return PeekMemory(addr); return PeekMemory(addr);
case PLABank.Sid: case PLABank.Sid:
@ -264,18 +263,15 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
public void Poke(int addr, byte val) 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: case PLABank.CartridgeHi:
PokeCartridgeHi(addr, val); PokeCartridgeHi(addr, val);
break; break;
case PLABank.CartridgeLo: case PLABank.CartridgeLo:
PokeCartridgeLo(addr, val); PokeCartridgeLo(addr, val);
break; break;
case PLABank.CharROM:
break;
case PLABank.Cia0: case PLABank.Cia0:
PokeCia0(addr, val); PokeCia0(addr, val);
break; break;
@ -291,10 +287,6 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
case PLABank.Expansion1: case PLABank.Expansion1:
PokeExpansionHi(addr, val); PokeExpansionHi(addr, val);
break; break;
case PLABank.KernalROM:
break;
case PLABank.None:
break;
case PLABank.RAM: case PLABank.RAM:
PokeMemory(addr, val); PokeMemory(addr, val);
break; 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)) switch (Bank(addr, true))
{ {
case PLABank.BasicROM: case PLABank.BasicROM:
@ -341,8 +334,9 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
return 0xFF; return 0xFF;
} }
public void Write(ushort addr, byte val) public void Write(int addr, byte val)
{ {
addr &= 0x0FFFF;
switch (Bank(addr, false)) switch (Bank(addr, false))
{ {
case PLABank.BasicROM: case PLABank.BasicROM:
@ -355,8 +349,6 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
WriteCartridgeLo(addr, val); WriteCartridgeLo(addr, val);
WriteMemory(addr, val); WriteMemory(addr, val);
break; break;
case PLABank.CharROM:
break;
case PLABank.Cia0: case PLABank.Cia0:
WriteCia0(addr, val); WriteCia0(addr, val);
break; break;
@ -372,10 +364,6 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
case PLABank.Expansion1: case PLABank.Expansion1:
WriteExpansionHi(addr, val); WriteExpansionHi(addr, val);
return; return;
case PLABank.KernalROM:
break;
case PLABank.None:
break;
case PLABank.RAM: case PLABank.RAM:
WriteMemory(addr, val); WriteMemory(addr, val);
break; break;

View File

@ -36,4 +36,39 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
return (byte)((Latch & Direction) | (Direction ^ 0xFF)); 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);
}
}
} }

View File

@ -7,48 +7,26 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
public class SerialPort public class SerialPort
{ {
public Func<bool> DeviceReadAtn; public Func<bool> ReadAtnOut;
public Func<bool> DeviceReadClock; public Func<bool> ReadClockOut;
public Func<bool> DeviceReadData; public Func<bool> ReadDataOut;
public Func<bool> DeviceReadReset;
public Action<bool> DeviceWriteAtn;
public Action<bool> DeviceWriteClock;
public Action<bool> DeviceWriteData;
public Action<bool> DeviceWriteSrq;
public Func<bool> SystemReadAtn;
public Func<bool> SystemReadClock;
public Func<bool> SystemReadData;
public Func<bool> SystemReadSrq;
public Action<bool> SystemWriteAtn;
public Action<bool> SystemWriteClock;
public Action<bool> SystemWriteData;
public Action<bool> SystemWriteReset;
// Connect() needs to set System functions above
public SerialPort() 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 void HardReset()
{ {
} }
public bool WriteClockIn()
{
return true;
}
public bool WriteDataIn()
{
return true;
}
} }
} }

View File

@ -419,9 +419,9 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
waveform = (value >> 4) & 0x0F; waveform = (value >> 4) & 0x0F;
wave = waveTable[waveform & 0x07]; wave = waveTable[waveform & 0x07];
ringMsbMask = ((~value >> 5) & (value >> 2) & 0x1) << 23; ringMsbMask = ((~value >> 5) & (value >> 2) & 0x1) << 23;
noNoise = ((waveform & 0x8) != 0) ? (int)0x000 : (int)0xFFF; noNoise = ((waveform & 0x8) != 0) ? 0x000 : 0xFFF;
noNoiseOrNoise = noNoise | noise; noNoiseOrNoise = noNoise | noise;
noPulse = ((waveform & 0x4) != 0) ? (int)0x000 : (int)0xFFF; noPulse = ((waveform & 0x4) != 0) ? 0x000 : 0xFFF;
if (!testPrev && test) if (!testPrev && test)
{ {
@ -503,7 +503,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
if (floatOutputTTL != 0 && --floatOutputTTL == 0) if (floatOutputTTL != 0 && --floatOutputTTL == 0)
output = 0x000; output = 0x000;
} }
pulse = ((accumulator >> 12) >= pulseWidth) ? (int)0xFFF : (int)0x000; pulse = ((accumulator >> 12) >= pulseWidth) ? 0xFFF : 0x000;
return output; return output;
} }
} }
@ -759,15 +759,15 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
public byte Peek(int addr) public byte Peek(int addr)
{ {
return ReadRegister((ushort)(addr & 0x1F)); return ReadRegister((addr & 0x1F));
} }
public void Poke(int addr, byte val) 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; addr &= 0x1F;
byte result = 0x00; byte result = 0x00;
@ -783,7 +783,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
return result; return result;
} }
private byte ReadRegister(ushort addr) private byte ReadRegister(int addr)
{ {
byte result = 0x00; byte result = 0x00;
@ -892,7 +892,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
return result; return result;
} }
public void Write(ushort addr, byte val) public void Write(int addr, byte val)
{ {
addr &= 0x1F; addr &= 0x1F;
switch (addr) 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) switch (addr)
{ {

View File

@ -6,11 +6,14 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
public abstract class Timer public abstract class Timer
{ {
public byte PortAMask = 0xFF;
public byte PortBMask = 0xFF;
protected bool pinIRQ; protected bool pinIRQ;
protected LatchedPort portA; protected LatchedPort portA;
protected LatchedPort portB; protected LatchedPort portB;
protected uint[] timer; protected int[] timer;
protected uint[] timerLatch; protected int[] timerLatch;
protected bool[] timerOn; protected bool[] timerOn;
protected bool[] underflow; protected bool[] underflow;
@ -21,8 +24,8 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
{ {
portA = new LatchedPort(); portA = new LatchedPort();
portB = new LatchedPort(); portB = new LatchedPort();
timer = new uint[2]; timer = new int[2];
timerLatch = new uint[2]; timerLatch = new int[2];
timerOn = new bool[2]; timerOn = new bool[2];
underflow = new bool[2]; underflow = new bool[2];
} }
@ -36,14 +39,6 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
pinIRQ = true; pinIRQ = true;
} }
public bool IRQ
{
get
{
return pinIRQ;
}
}
public byte PortAData public byte PortAData
{ {
get 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) protected void SyncInternal(Serializer ser)
{ {

View File

@ -4,51 +4,14 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
{ {
public class UserPort public class UserPort
{ {
private Func<int, byte> peekMemory; public Func<bool> ReadCounter1;
private Action<int, byte> pokeMemory; public Func<bool> ReadCounter2;
private Func<ushort, byte> readMemory; public Func<bool> ReadHandshake;
private Action<ushort, byte> writeMemory; public Func<bool> ReadSerial1;
public Func<bool> ReadSerial2;
public UserPort() public UserPort()
{ {
// start up with no media connected
Disconnect();
}
public void Connect(Func<int, byte> funcPeek, Action<int, byte> actPoke, Func<ushort, byte> funcRead, Action<ushort, byte> 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() public void HardReset()
@ -56,24 +19,49 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
// note: this will not disconnect any attached media // note: this will not disconnect any attached media
} }
public byte Peek(int addr) public bool ReadAtn()
{ {
return peekMemory(addr); return true;
} }
public void Poke(int addr, byte val) public bool ReadCounter1Buffer()
{ {
pokeMemory(addr, val); return true;
} }
public byte Read(ushort addr) public bool ReadCounter2Buffer()
{ {
return readMemory(addr); return true;
} }
public void Write(ushort addr, byte val) public byte ReadData()
{ {
writeMemory(addr, val); 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;
} }
} }
} }

View File

@ -105,6 +105,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
private int cycleIndex; private int cycleIndex;
private int dataC; private int dataC;
private int dataG; private int dataG;
private bool debugScreen;
private int displayC; private int displayC;
private bool displayEnable; private bool displayEnable;
private int displayIndex; private int displayIndex;
@ -159,8 +160,8 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
// ------------------------------------ // ------------------------------------
public Func<ushort, byte> ReadColorRam; public Func<int, byte> ReadColorRam;
public Func<ushort, byte> ReadMemory; public Func<int, byte> ReadMemory;
// ------------------------------------ // ------------------------------------
@ -168,13 +169,23 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
{ {
{ {
debugScreen = false;
totalCycles = newCycles; totalCycles = newCycles;
totalLines = newLines; totalLines = newLines;
pipeline = newPipeline; pipeline = newPipeline;
cyclesPerSec = newCyclesPerSec; cyclesPerSec = newCyclesPerSec;
pixelBufferDelay = 12; pixelBufferDelay = 12;
pixelBackgroundBufferDelay = 4; pixelBackgroundBufferDelay = 4;
if (debugScreen)
{
bufRect = new Rectangle(0, 0, totalCycles * 8, totalLines);
}
else
{
bufRect = new Rectangle(136 - 24, 51 - 24, 320 + 48, 200 + 48); bufRect = new Rectangle(136 - 24, 51 - 24, 320 + 48, 200 + 48);
}
buf = new int[bufRect.Width * bufRect.Height]; buf = new int[bufRect.Width * bufRect.Height];
bufLength = buf.Length; bufLength = buf.Length;
@ -425,7 +436,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
{ {
{ {
ushort addr = 0x3FFF; int addr = 0x3FFF;
int cycleBAsprite0; int cycleBAsprite0;
int cycleBAsprite1; int cycleBAsprite1;
int cycleBAsprite2; int cycleBAsprite2;
@ -443,7 +454,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
case 0x0100: case 0x0100:
// fetch R // fetch R
refreshCounter = (refreshCounter - 1) & 0xFF; refreshCounter = (refreshCounter - 1) & 0xFF;
addr = (ushort)(0x3F00 | refreshCounter); addr = (0x3F00 | refreshCounter);
ReadMemory(addr); ReadMemory(addr);
break; break;
case 0x0200: case 0x0200:
@ -452,7 +463,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
{ {
if (badline) if (badline)
{ {
addr = (ushort)((pointerVM << 10) | vc); addr = ((pointerVM << 10) | vc);
dataC = ReadMemory(addr); dataC = ReadMemory(addr);
dataC |= ((int)ReadColorRam(addr) & 0xF) << 8; dataC |= ((int)ReadColorRam(addr) & 0xF) << 8;
bufferC[vmli] = dataC; bufferC[vmli] = dataC;
@ -475,9 +486,9 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
else else
{ {
if (bitmapMode) if (bitmapMode)
addr = (ushort)(rc | (vc << 3) | ((pointerCB & 0x4) << 11)); addr = (rc | (vc << 3) | ((pointerCB & 0x4) << 11));
else else
addr = (ushort)(rc | ((dataC & 0xFF) << 3) | (pointerCB << 11)); addr = (rc | ((dataC & 0xFF) << 3) | (pointerCB << 11));
} }
if (extraColorMode) if (extraColorMode)
addr &= 0x39FF; addr &= 0x39FF;
@ -491,7 +502,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
break; break;
case 0x0400: case 0x0400:
// fetch I // fetch I
addr = (extraColorMode ? (ushort)0x39FF : (ushort)0x3FFF); addr = (extraColorMode ? 0x39FF : 0x3FFF);
dataG = ReadMemory(addr); dataG = ReadMemory(addr);
dataC = 0; dataC = 0;
break; break;
@ -504,7 +515,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
{ {
case 0x00: case 0x00:
// fetch P // fetch P
addr = (ushort)(0x3F8 | (pointerVM << 10) | cycleFetchSpriteIndex); addr = (0x3F8 | (pointerVM << 10) | cycleFetchSpriteIndex);
sprites[cycleFetchSpriteIndex].pointer = ReadMemory(addr); sprites[cycleFetchSpriteIndex].pointer = ReadMemory(addr);
sprites[cycleFetchSpriteIndex].shiftEnable = false; sprites[cycleFetchSpriteIndex].shiftEnable = false;
break; break;
@ -515,7 +526,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
if (sprites[cycleFetchSpriteIndex].dma) if (sprites[cycleFetchSpriteIndex].dma)
{ {
Sprite spr = sprites[cycleFetchSpriteIndex]; Sprite spr = sprites[cycleFetchSpriteIndex];
addr = (ushort)(spr.mc | (spr.pointer << 6)); addr = (spr.mc | (spr.pointer << 6));
spr.sr <<= 8; spr.sr <<= 8;
spr.sr |= ReadMemory(addr); spr.sr |= ReadMemory(addr);
spr.mc++; spr.mc++;
@ -878,13 +889,9 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
// ------------------------------------ // ------------------------------------
public bool AEC { get { return pinAEC; } } public bool ReadAECBuffer() { return pinAEC; }
public bool BA { get { return pinBA; } } public bool ReadBABuffer() { return pinBA; }
public bool IRQ { get { return pinIRQ; } } public bool ReadIRQBuffer() { return pinIRQ; }
public bool ReadAEC() { return pinAEC; }
public bool ReadBA() { return pinBA; }
public bool ReadIRQ() { return pinIRQ; }
// ------------------------------------ // ------------------------------------
@ -892,7 +899,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
{ {
get get
{ {
return (int)(totalCycles * totalLines); return (totalCycles * totalLines);
} }
} }
@ -908,15 +915,15 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
public byte Peek(int addr) public byte Peek(int addr)
{ {
return ReadRegister((ushort)(addr & 0x3F)); return ReadRegister((addr & 0x3F));
} }
public void Poke(int addr, byte val) 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; byte result;
addr &= 0x3F; addr &= 0x3F;
@ -930,13 +937,13 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
WriteRegister(addr, 0); WriteRegister(addr, 0);
break; break;
default: default:
result = ReadRegister((ushort)(addr & 0x3F)); result = ReadRegister((addr & 0x3F));
break; break;
} }
return result; return result;
} }
private byte ReadRegister(ushort addr) private byte ReadRegister(int addr)
{ {
byte result = 0xFF; //unused bit value byte result = 0xFF; //unused bit value
@ -1158,7 +1165,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
return result; return result;
} }
public void Write(ushort addr, byte val) public void Write(int addr, byte val)
{ {
addr &= 0x3F; addr &= 0x3F;
switch (addr) 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) switch (addr)
{ {

View File

@ -6,11 +6,11 @@ namespace BizHawk.Emulation.Computers.Commodore64.Media
{ {
static public void Load(MOSPLA pla, byte[] prgFile) static public void Load(MOSPLA pla, byte[] prgFile)
{ {
uint length = (uint)prgFile.Length; int length = prgFile.Length;
if (length > 2) if (length > 2)
{ {
ushort addr = (ushort)(prgFile[0] | (prgFile[1] << 8)); int addr = (prgFile[0] | (prgFile[1] << 8));
uint offset = 2; int offset = 2;
unchecked unchecked
{ {
while (offset < length) while (offset < length)

View File

@ -1,6 +0,0 @@
namespace BizHawk.Emulation.Computers.Commodore64
{
class Memory
{
}
}