2013-11-12 19:22:09 +00:00
|
|
|
|
using System;
|
2013-08-09 05:34:38 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
2013-11-12 19:22:09 +00:00
|
|
|
|
namespace BizHawk.Emulation.Cores.Computers.Commodore64
|
2013-08-09 05:34:38 +00:00
|
|
|
|
{
|
2016-02-22 23:50:11 +00:00
|
|
|
|
public sealed partial class Motherboard
|
2013-11-12 19:22:09 +00:00
|
|
|
|
{
|
2016-02-22 23:50:11 +00:00
|
|
|
|
private int _lastReadVicAddress = 0x3FFF;
|
|
|
|
|
private int _lastReadVicData = 0xFF;
|
|
|
|
|
private int _vicBank = 0xC000;
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2016-02-22 23:50:11 +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
|
|
|
|
}
|
|
|
|
|
|
2016-02-22 23:50:11 +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
|
|
|
|
}
|
|
|
|
|
|
2016-02-22 23:50:11 +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;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-22 23:50:11 +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
|
|
|
|
}
|
|
|
|
|
|
2016-02-22 23:50:11 +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
|
|
|
|
}
|
2016-02-22 23:50:11 +00:00
|
|
|
|
*/
|
2013-11-12 19:22:09 +00:00
|
|
|
|
|
2016-02-22 23:50:11 +00:00
|
|
|
|
private int Cia1_ReadPortA()
|
2013-11-12 19:22:09 +00:00
|
|
|
|
{
|
2016-02-22 23:50:11 +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
|
|
|
|
}
|
|
|
|
|
|
2016-02-22 23:50:11 +00:00
|
|
|
|
private int Cia1_ReadPortB()
|
|
|
|
|
{
|
|
|
|
|
return 0xFF;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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())
|
2013-11-12 19:22:09 +00:00
|
|
|
|
data &= 0xEF;
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-22 23:50:11 +00:00
|
|
|
|
private void Cpu_WriteMemoryPort(int addr, int val)
|
2014-10-09 02:14:15 +00:00
|
|
|
|
{
|
2016-02-22 23:50:11 +00:00
|
|
|
|
Pla.WriteMemory(addr, Bus);
|
2014-10-09 02:14:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-02-22 23:50:11 +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
|
|
|
|
}
|
|
|
|
|
|
2016-02-22 23:50:11 +00:00
|
|
|
|
private bool Glue_ReadNMI()
|
|
|
|
|
{
|
|
|
|
|
return !_restorePressed && Cia1.ReadIrq() && CartPort.ReadNmi();
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-01 22:03:20 +00:00
|
|
|
|
private bool[] Input_ReadJoysticks()
|
|
|
|
|
{
|
|
|
|
|
return _joystickPressed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool[] Input_ReadKeyboard()
|
|
|
|
|
{
|
|
|
|
|
return _keyboardPressed;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-22 23:50:11 +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
|
|
|
|
}
|
|
|
|
|
|
2016-02-22 23:50:11 +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
|
|
|
|
}
|
|
|
|
|
|
2016-02-22 23:50:11 +00:00
|
|
|
|
private int Pla_ReadColorRam(int addr)
|
2013-11-12 19:22:09 +00:00
|
|
|
|
{
|
2016-02-22 23:50:11 +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;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-22 23:50:11 +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
|
|
|
|
}
|
|
|
|
|
|
2016-02-22 23:50:11 +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
|
|
|
|
}
|
|
|
|
|
|
2016-02-22 23:50:11 +00:00
|
|
|
|
private int Pla_ReadExpansion0(int addr)
|
|
|
|
|
{
|
|
|
|
|
return CartPort.IsConnected ? CartPort.ReadLoExp(addr) : _lastReadVicData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int Pla_ReadExpansion1(int addr)
|
|
|
|
|
{
|
|
|
|
|
return CartPort.IsConnected ? CartPort.ReadHiExp(addr) : _lastReadVicData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2016-02-22 23:50:11 +00:00
|
|
|
|
private bool SerPort_ReadClockOut()
|
|
|
|
|
{
|
|
|
|
|
return !((Cia1.DdrA & 0x10) != 0 && (Cia1.PrA & 0x10) != 0);
|
2013-11-12 19:22:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-02-22 23:50:11 +00:00
|
|
|
|
private bool SerPort_ReadDataOut()
|
2013-11-12 19:22:09 +00:00
|
|
|
|
{
|
2016-02-22 23:50:11 +00:00
|
|
|
|
return !((Cia1.DdrA & 0x20) != 0 && (Cia1.PrA & 0x20) != 0);
|
|
|
|
|
}
|
2013-11-12 19:22:09 +00:00
|
|
|
|
|
2016-02-22 23:50:11 +00:00
|
|
|
|
private int Sid_ReadPotX()
|
2013-11-12 19:22:09 +00:00
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-22 23:50:11 +00:00
|
|
|
|
private int Sid_ReadPotY()
|
2013-11-12 19:22:09 +00:00
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-22 23:50:11 +00:00
|
|
|
|
private int Vic_ReadMemory(int addr)
|
2013-11-12 19:22:09 +00:00
|
|
|
|
{
|
2016-02-22 23:50:11 +00:00
|
|
|
|
// the system sees (cia1.PortAData & 0x3) but we use a shortcut
|
|
|
|
|
_lastReadVicAddress = addr | _vicBank;
|
|
|
|
|
_lastReadVicData = Pla.VicRead(_lastReadVicAddress);
|
|
|
|
|
return _lastReadVicData;
|
2013-11-12 19:22:09 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-08-09 05:34:38 +00:00
|
|
|
|
}
|