BizHawk/BizHawk.Emulation.Cores/Computers/Commodore64/C64.MotherboardInterface.cs

182 lines
3.5 KiB
C#
Raw Normal View History

using System;
namespace BizHawk.Emulation.Cores.Computers.Commodore64
{
2016-02-22 23:50:11 +00:00
public sealed partial class Motherboard
2013-11-12 19:22:09 +00:00
{
2017-04-24 13:35:05 +00:00
private int _lastReadVicAddress = 0x3FFF;
private int _lastReadVicData = 0xFF;
private int _vicBank = 0xC000;
2016-02-22 23:50:11 +00:00
2017-04-24 13:35:05 +00:00
private bool CassPort_ReadDataOutput()
2013-11-12 19:22:09 +00:00
{
2016-02-22 23:50:11 +00:00
return (Cpu.PortData & 0x08) != 0;
2013-11-12 19:22:09 +00:00
}
2017-04-24 13:35:05 +00:00
private bool CassPort_ReadMotor()
2013-11-12 19:22:09 +00:00
{
2016-02-22 23:50:11 +00:00
return (Cpu.PortData & 0x20) != 0;
2013-11-12 19:22:09 +00:00
}
2017-04-24 13:35:05 +00:00
/*
private bool Cia0_ReadCnt()
2013-11-12 19:22:09 +00:00
{
2016-02-22 23:50:11 +00:00
return User.ReadCounter1() && Cia0.ReadCntBuffer();
2013-11-12 19:22:09 +00:00
}
2017-04-24 13:35:05 +00:00
private int Cia0_ReadPortA()
2013-11-12 19:22:09 +00:00
{
return cia0InputLatchA;
}
2016-02-22 23:50:11 +00:00
private int Cia0_ReadPortB()
2013-11-12 19:22:09 +00:00
{
return cia0InputLatchB;
}
2017-04-24 13:35:05 +00:00
private bool Cia0_ReadSP()
2013-11-12 19:22:09 +00:00
{
2016-02-22 23:50:11 +00:00
return User.ReadSerial1() && Cia0.ReadSpBuffer();
2013-11-12 19:22:09 +00:00
}
2017-04-24 13:35:05 +00:00
private bool Cia1_ReadSP()
2013-11-12 19:22:09 +00:00
{
2016-02-22 23:50:11 +00:00
return User.ReadSerial2() && Cia1.ReadSpBuffer();
2013-11-12 19:22:09 +00:00
}
2016-02-22 23:50:11 +00:00
private bool Cia1_ReadCnt()
2013-11-12 19:22:09 +00:00
{
2016-02-22 23:50:11 +00:00
return User.ReadCounter2() && Cia1.ReadCntBuffer();
2013-11-12 19:22:09 +00:00
}
2017-04-24 13:35:05 +00:00
*/
2013-11-12 19:22:09 +00:00
2017-04-24 13:35:05 +00:00
private int Cia1_ReadPortA()
2013-11-12 19:22:09 +00:00
{
2017-04-24 13:35:05 +00:00
// the low bits are actually the VIC memory address.
return (SerPort_ReadDataOut() && Serial.ReadDeviceData() ? 0x80 : 0x00) |
(SerPort_ReadClockOut() && Serial.ReadDeviceClock() ? 0x40 : 0x00);
2013-11-12 19:22:09 +00:00
}
2017-04-24 13:35:05 +00:00
private int Cia1_ReadPortB()
{
return 0xFF;
}
2016-02-22 23:50:11 +00:00
2017-04-24 13:35:05 +00:00
private int Cpu_ReadPort()
2013-11-12 19:22:09 +00:00
{
2016-02-22 23:50:11 +00:00
var data = 0x1F;
if (!Cassette.ReadSenseBuffer())
2017-05-30 17:09:46 +00:00
{
2013-11-12 19:22:09 +00:00
data &= 0xEF;
2017-05-30 17:09:46 +00:00
}
2013-11-12 19:22:09 +00:00
return data;
}
2017-04-24 13:35:05 +00:00
private void Cpu_WriteMemoryPort(int addr, int val)
{
2016-02-22 23:50:11 +00:00
Pla.WriteMemory(addr, Bus);
}
2017-04-24 13:35:05 +00:00
private bool Glue_ReadIRQ()
2013-11-12 19:22:09 +00:00
{
2016-02-22 23:50:11 +00:00
return Cia0.ReadIrq() && Vic.ReadIrq() && CartPort.ReadIrq();
2013-11-12 19:22:09 +00:00
}
2017-04-24 13:35:05 +00:00
private bool Glue_ReadNMI()
{
return !_restorePressed && Cia1.ReadIrq() && CartPort.ReadNmi();
}
2016-02-22 23:50:11 +00:00
2017-04-24 13:35:05 +00:00
private bool[] Input_ReadJoysticks()
{
return _joystickPressed;
}
2017-04-24 13:35:05 +00:00
private bool[] Input_ReadKeyboard()
{
return _keyboardPressed;
}
2017-04-24 13:35:05 +00:00
private bool Pla_ReadCharen()
2013-11-12 19:22:09 +00:00
{
2016-02-22 23:50:11 +00:00
return (Cpu.PortData & 0x04) != 0;
2013-11-12 19:22:09 +00:00
}
2017-04-24 13:35:05 +00:00
private int Pla_ReadCia0(int addr)
2013-11-12 19:22:09 +00:00
{
if (addr == 0xDC00 || addr == 0xDC01)
{
2016-02-22 23:50:11 +00:00
InputRead = true;
2013-11-12 19:22:09 +00:00
}
2016-02-22 23:50:11 +00:00
return Cia0.Read(addr);
2013-11-12 19:22:09 +00:00
}
2017-04-24 13:35:05 +00:00
private int Pla_ReadColorRam(int addr)
2013-11-12 19:22:09 +00:00
{
2017-04-24 13:35:05 +00:00
var result = Bus;
2013-11-12 19:22:09 +00:00
result &= 0xF0;
2016-02-22 23:50:11 +00:00
result |= ColorRam.Read(addr);
2013-11-12 19:22:09 +00:00
return result;
}
2017-04-24 13:35:05 +00:00
private bool Pla_ReadHiRam()
2013-11-12 19:22:09 +00:00
{
2016-02-22 23:50:11 +00:00
return (Cpu.PortData & 0x02) != 0;
2013-11-12 19:22:09 +00:00
}
2017-04-24 13:35:05 +00:00
private bool Pla_ReadLoRam()
2013-11-12 19:22:09 +00:00
{
2016-02-22 23:50:11 +00:00
return (Cpu.PortData & 0x01) != 0;
2013-11-12 19:22:09 +00:00
}
2017-04-24 13:35:05 +00:00
private int Pla_ReadExpansion0(int addr)
{
return CartPort.IsConnected ? CartPort.ReadLoExp(addr) : _lastReadVicData;
}
2016-02-22 23:50:11 +00:00
2017-04-24 13:35:05 +00:00
private int Pla_ReadExpansion1(int addr)
{
return CartPort.IsConnected ? CartPort.ReadHiExp(addr) : _lastReadVicData;
}
2016-02-22 23:50:11 +00:00
2017-04-24 13:35:05 +00:00
private bool SerPort_ReadAtnOut()
2013-11-12 19:22:09 +00:00
{
2016-02-22 23:50:11 +00:00
return !((Cia1.DdrA & 0x08) != 0 && (Cia1.PrA & 0x08) != 0);
2013-11-12 19:22:09 +00:00
}
2017-04-24 13:35:05 +00:00
private bool SerPort_ReadClockOut()
{
return !((Cia1.DdrA & 0x10) != 0 && (Cia1.PrA & 0x10) != 0);
2013-11-12 19:22:09 +00:00
}
2017-04-24 13:35:05 +00:00
private bool SerPort_ReadDataOut()
2013-11-12 19:22:09 +00:00
{
2017-04-24 13:35:05 +00:00
return !((Cia1.DdrA & 0x20) != 0 && (Cia1.PrA & 0x20) != 0);
}
2013-11-12 19:22:09 +00:00
2017-04-24 13:35:05 +00:00
private int Sid_ReadPotX()
2013-11-12 19:22:09 +00:00
{
return 255;
2013-11-12 19:22:09 +00:00
}
2017-04-24 13:35:05 +00:00
private int Sid_ReadPotY()
2013-11-12 19:22:09 +00:00
{
return 255;
2013-11-12 19:22:09 +00:00
}
2017-04-24 13:35:05 +00:00
private int Vic_ReadMemory(int addr)
2013-11-12 19:22:09 +00:00
{
2017-04-24 13:35:05 +00:00
// the system sees (cia1.PortAData & 0x3) but we use a shortcut
_lastReadVicAddress = addr | _vicBank;
2016-02-22 23:50:11 +00:00
_lastReadVicData = Pla.VicRead(_lastReadVicAddress);
2017-04-24 13:35:05 +00:00
return _lastReadVicData;
2013-11-12 19:22:09 +00:00
}
2017-04-24 13:35:05 +00:00
private int ReadOpenBus()
{
return _lastReadVicData;
}
2013-11-12 19:22:09 +00:00
}
}