INTV: clean up CPU, fix trace logger and throw less exceptions

This commit is contained in:
alyosha-tas 2021-11-22 15:50:03 -05:00
parent fba8e52be6
commit d8356670ed
2 changed files with 12 additions and 56 deletions

View File

@ -32,7 +32,7 @@ namespace BizHawk.Emulation.Cores.Components.CP1610
FlagO ? "O" : "o",
FlagI ? "I" : "i",
FlagD ? "D" : "d")
}.Concat(Register.Select((r, i) => $"R{i}:{4:X4}"))));
}.Concat(Register.Select((r, i) => $"R{i}:{r:X4}"))));
private void Calc_FlagC(int result)
{
@ -132,13 +132,7 @@ namespace BizHawk.Emulation.Cores.Components.CP1610
*/
if (FlagI && Interruptible && !IntRM && !Interrupted)
{
if (Logging)
{
Log.WriteLine("------");
Log.WriteLine();
Log.WriteLine("Interrupt");
Log.Flush();
}
TraceCallback?.Invoke(new(disassembly: "====IRQ====", registerInfo: string.Empty));
Interrupted = true;
Interruptible = false;
Indirect_Set(6, 7);
@ -156,16 +150,6 @@ namespace BizHawk.Emulation.Cores.Components.CP1610
return 1;
}
if (Logging)
{
int addrToAdvance;
Log.WriteLine("------");
Log.WriteLine();
Log.WriteLine(Disassemble(RegisterPC, out addrToAdvance));
Log.Flush();
}
byte dest, src, mem;
ushort dest_value, src_value, mem_read, addr, addr_read, offset;
int decle2, decle3, result = 0, twos, status_word, lower, sign, cond, ext;
@ -185,7 +169,11 @@ namespace BizHawk.Emulation.Cores.Components.CP1610
switch (opcode)
{
case 0x000: // HLT
throw new ArgumentException(UNEXPECTED_HLT);
// CPU is in an unrecoverable state
RegisterPC--;
cycles = 4;
Interruptible = false;
break;
case 0x001: // SDBD
FlagD = true;
cycles = 4;
@ -362,7 +350,10 @@ namespace BizHawk.Emulation.Cores.Components.CP1610
// SIN
case 0x036:
case 0x037:
throw new ArgumentException(UNEXPECTED_SIN);
// pin that this opcode uses is not connected on intellivision, so treat it as a nop for now
cycles = 6;
Interruptible = false;
break;
// RSWD
case 0x038:
case 0x039:

View File

@ -60,9 +60,6 @@ namespace BizHawk.Emulation.Cores.Components.CP1610
public Func<ushort, bool, ushort> ReadMemory;
public Func<ushort, ushort, bool, bool> WriteMemory;
private static readonly bool Logging = false;
private static readonly StreamWriter Log;
public void SyncState(Serializer ser)
{
ser.BeginSection(nameof(CP1610));
@ -87,13 +84,7 @@ namespace BizHawk.Emulation.Cores.Components.CP1610
ser.EndSection();
}
static CP1610()
{
if (Logging)
{
Log = new StreamWriter("log_CP1610.txt");
}
}
static CP1610() {}
public void Reset()
{
@ -137,32 +128,6 @@ namespace BizHawk.Emulation.Cores.Components.CP1610
PendingCycles += cycles;
}
public void LogData()
{
if (!Logging)
{
return;
}
Log.WriteLine("Total Executed Cycles = {0}", TotalExecutedCycles);
for (int register = 0; register <= 5; register++)
{
Log.WriteLine("R{0:d} = {1:X4}", register, Register[register]);
}
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);
// Log.WriteLine("MSYNC = {0}", MSync);
Log.Flush();
}
public IDictionary<string, RegisterValue> GetCpuFlagsAndRegisters()
{
return new Dictionary<string, RegisterValue>