2012-07-08 00:36:16 +00:00
|
|
|
|
using System;
|
2012-07-22 17:18:11 +00:00
|
|
|
|
using System.IO;
|
2016-12-07 15:55:25 +00:00
|
|
|
|
using BizHawk.Common;
|
2016-11-11 22:17:35 +00:00
|
|
|
|
using BizHawk.Emulation.Common;
|
|
|
|
|
|
2014-01-22 01:14:36 +00:00
|
|
|
|
namespace BizHawk.Emulation.Cores.Components.CP1610
|
2012-07-08 00:36:16 +00:00
|
|
|
|
{
|
|
|
|
|
public sealed partial class CP1610
|
|
|
|
|
{
|
2012-08-06 15:51:35 +00:00
|
|
|
|
private const ushort RESET = 0x1000;
|
|
|
|
|
private const ushort INTERRUPT = 0x1004;
|
|
|
|
|
|
2017-04-23 16:46:37 +00:00
|
|
|
|
internal bool FlagS, FlagC, FlagZ, FlagO, FlagI, FlagD, IntRM, BusRq, BusAk, Interruptible, Interrupted;
|
2012-09-22 05:01:04 +00:00
|
|
|
|
//private bool MSync;
|
2017-04-23 16:46:37 +00:00
|
|
|
|
internal ushort[] Register = new ushort[8];
|
2020-01-25 04:53:45 +00:00
|
|
|
|
|
|
|
|
|
private ushort RegisterSP
|
|
|
|
|
{
|
|
|
|
|
get => Register[6];
|
|
|
|
|
set => Register[6] = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ushort RegisterPC
|
|
|
|
|
{
|
|
|
|
|
get => Register[7];
|
|
|
|
|
set => Register[7] = value;
|
|
|
|
|
}
|
2012-07-08 00:36:16 +00:00
|
|
|
|
|
2020-02-17 22:54:51 +00:00
|
|
|
|
public string TraceHeader => "CP1610: PC, machine code, mnemonic, operands, flags (SCZOID)";
|
2016-11-11 22:17:35 +00:00
|
|
|
|
|
|
|
|
|
public Action<TraceInfo> TraceCallback;
|
2017-04-23 18:28:40 +00:00
|
|
|
|
public IMemoryCallbackSystem MemoryCallbacks { get; set; }
|
|
|
|
|
|
|
|
|
|
public ushort ReadMemoryWrapper(ushort addr, bool peek)
|
|
|
|
|
{
|
|
|
|
|
if (MemoryCallbacks != null && !peek)
|
|
|
|
|
{
|
2019-06-06 09:04:47 +00:00
|
|
|
|
uint flags = (uint)(MemoryCallbackFlags.AccessRead);
|
|
|
|
|
MemoryCallbacks.CallMemoryCallbacks(addr, 0, flags, "System Bus");
|
2017-04-23 18:28:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ReadMemory(addr, peek);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void WriteMemoryWrapper(ushort addr, ushort value, bool poke)
|
|
|
|
|
{
|
|
|
|
|
if (MemoryCallbacks != null && !poke)
|
|
|
|
|
{
|
2019-06-06 09:04:47 +00:00
|
|
|
|
uint flags = (uint)(MemoryCallbackFlags.AccessWrite);
|
|
|
|
|
MemoryCallbacks.CallMemoryCallbacks(addr, value, flags, "System Bus");
|
2017-04-23 18:28:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WriteMemory(addr, value, poke);
|
|
|
|
|
}
|
2016-11-11 22:17:35 +00:00
|
|
|
|
|
2012-07-08 00:36:16 +00:00
|
|
|
|
public int TotalExecutedCycles;
|
|
|
|
|
public int PendingCycles;
|
|
|
|
|
|
2017-02-09 17:53:55 +00:00
|
|
|
|
public Func<ushort, bool, ushort> ReadMemory;
|
|
|
|
|
public Func<ushort, ushort, bool, bool> WriteMemory;
|
2012-07-22 17:18:11 +00:00
|
|
|
|
|
2017-02-08 23:26:30 +00:00
|
|
|
|
private static bool Logging = false;
|
2013-11-15 01:52:03 +00:00
|
|
|
|
private static readonly StreamWriter Log;
|
2012-07-22 17:18:11 +00:00
|
|
|
|
|
2016-12-07 15:55:25 +00:00
|
|
|
|
public void SyncState(Serializer ser)
|
|
|
|
|
{
|
2019-03-28 03:18:58 +00:00
|
|
|
|
ser.BeginSection(nameof(CP1610));
|
|
|
|
|
|
|
|
|
|
ser.Sync(nameof(Register), ref Register, false);
|
|
|
|
|
ser.Sync(nameof(FlagS), ref FlagS);
|
|
|
|
|
ser.Sync(nameof(FlagC), ref FlagC);
|
|
|
|
|
ser.Sync(nameof(FlagZ), ref FlagZ);
|
|
|
|
|
ser.Sync(nameof(FlagO), ref FlagO);
|
|
|
|
|
ser.Sync(nameof(FlagI), ref FlagI);
|
|
|
|
|
ser.Sync(nameof(FlagD), ref FlagD);
|
|
|
|
|
ser.Sync(nameof(IntRM), ref IntRM);
|
|
|
|
|
ser.Sync(nameof(BusRq), ref BusRq);
|
|
|
|
|
ser.Sync(nameof(BusAk), ref BusAk);
|
2020-02-16 19:30:17 +00:00
|
|
|
|
ser.Sync("Duplicate_Bus_Rq", ref BusRq); // Can't remove this or it will break backward compatibility with binary states
|
2019-03-28 03:18:58 +00:00
|
|
|
|
ser.Sync(nameof(Interruptible), ref Interruptible);
|
|
|
|
|
ser.Sync(nameof(Interrupted), ref Interrupted);
|
2016-12-07 15:55:25 +00:00
|
|
|
|
ser.Sync("Toal_executed_cycles", ref TotalExecutedCycles);
|
2016-12-14 23:35:03 +00:00
|
|
|
|
ser.Sync("Pending_Cycles", ref PendingCycles);
|
2016-12-07 15:55:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ser.EndSection();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static CP1610()
|
2012-07-22 17:18:11 +00:00
|
|
|
|
{
|
2012-09-05 04:42:49 +00:00
|
|
|
|
if (Logging)
|
2012-12-17 04:23:59 +00:00
|
|
|
|
{
|
2012-09-05 04:42:49 +00:00
|
|
|
|
Log = new StreamWriter("log_CP1610.txt");
|
2012-12-17 04:23:59 +00:00
|
|
|
|
}
|
2012-07-22 17:18:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-08-13 08:10:15 +00:00
|
|
|
|
public void Reset()
|
2012-08-06 15:51:35 +00:00
|
|
|
|
{
|
2012-08-13 08:10:15 +00:00
|
|
|
|
BusAk = true;
|
|
|
|
|
Interruptible = false;
|
|
|
|
|
FlagS = FlagC = FlagZ = FlagO = FlagI = FlagD = false;
|
|
|
|
|
for (int register = 0; register <= 6; register++)
|
2012-12-17 04:23:59 +00:00
|
|
|
|
{
|
2012-08-13 08:10:15 +00:00
|
|
|
|
Register[register] = 0;
|
2012-12-17 04:23:59 +00:00
|
|
|
|
}
|
2012-08-06 15:51:35 +00:00
|
|
|
|
RegisterPC = RESET;
|
2017-03-05 23:44:34 +00:00
|
|
|
|
PendingCycles = 0;
|
2012-08-06 15:51:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-08-14 03:58:11 +00:00
|
|
|
|
public bool GetBusAk()
|
|
|
|
|
{
|
|
|
|
|
return BusAk;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetIntRM(bool value)
|
|
|
|
|
{
|
|
|
|
|
IntRM = value;
|
2012-12-17 04:23:59 +00:00
|
|
|
|
if (IntRM)
|
|
|
|
|
{
|
|
|
|
|
Interrupted = false;
|
|
|
|
|
}
|
2012-08-14 03:58:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-09-04 06:26:08 +00:00
|
|
|
|
public void SetBusRq(bool value)
|
2012-08-14 03:58:11 +00:00
|
|
|
|
{
|
2016-12-13 21:47:21 +00:00
|
|
|
|
BusRq = !value;
|
2012-08-14 03:58:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-09-04 06:26:08 +00:00
|
|
|
|
public int GetPendingCycles()
|
2012-08-14 03:58:11 +00:00
|
|
|
|
{
|
2012-09-04 06:26:08 +00:00
|
|
|
|
return PendingCycles;
|
2012-08-14 03:58:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AddPendingCycles(int cycles)
|
|
|
|
|
{
|
|
|
|
|
PendingCycles += cycles;
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-22 17:18:11 +00:00
|
|
|
|
public void LogData()
|
|
|
|
|
{
|
2012-09-05 04:42:49 +00:00
|
|
|
|
if (!Logging)
|
2012-12-17 04:23:59 +00:00
|
|
|
|
{
|
2012-07-22 17:18:11 +00:00
|
|
|
|
return;
|
2012-12-17 04:23:59 +00:00
|
|
|
|
}
|
|
|
|
|
Log.WriteLine("Total Executed Cycles = {0}", TotalExecutedCycles);
|
2012-07-22 17:18:11 +00:00
|
|
|
|
for (int register = 0; register <= 5; register++)
|
2012-12-17 04:23:59 +00:00
|
|
|
|
{
|
2012-09-05 04:42:49 +00:00
|
|
|
|
Log.WriteLine("R{0:d} = {1:X4}", register, Register[register]);
|
2012-12-17 04:23:59 +00:00
|
|
|
|
}
|
2012-09-05 04:42:49 +00:00
|
|
|
|
Log.WriteLine("SP = {0:X4}", RegisterSP);
|
|
|
|
|
Log.WriteLine("PC = {0:X4}", RegisterPC);
|
|
|
|
|
Log.WriteLine("S = {0}", FlagS);
|
|
|
|
|
Log.WriteLine("C = {0}", FlagC);
|
|
|
|
|
Log.WriteLine("Z = {0}", FlagZ);
|
|
|
|
|
Log.WriteLine("O = {0}", FlagO);
|
|
|
|
|
Log.WriteLine("I = {0}", FlagI);
|
|
|
|
|
Log.WriteLine("D = {0}", FlagD);
|
|
|
|
|
Log.WriteLine("INTRM = {0}", IntRM);
|
|
|
|
|
Log.WriteLine("BUSRQ = {0}", BusRq);
|
|
|
|
|
Log.WriteLine("BUSAK = {0}", BusAk);
|
2012-12-17 07:17:18 +00:00
|
|
|
|
// Log.WriteLine("MSYNC = {0}", MSync);
|
2012-09-05 04:42:49 +00:00
|
|
|
|
Log.Flush();
|
2012-07-22 17:18:11 +00:00
|
|
|
|
}
|
2016-11-12 17:58:10 +00:00
|
|
|
|
|
|
|
|
|
|
2012-07-08 00:36:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|