From 6a60657199a3da9ed6df7b4e3b3949910e79fa30 Mon Sep 17 00:00:00 2001 From: Asnivor Date: Thu, 20 Dec 2018 10:40:54 +0000 Subject: [PATCH] Z80: optimization testing --- BizHawk.Emulation.Cores/CPUs/Z80A/Execute.cs | 2 +- .../CPUs/Z80A/Interrupts.cs | 8 +- .../CPUs/Z80A/Tables_Direct.cs | 84 +++++++++---------- .../CPUs/Z80A/Tables_Indirect.cs | 58 ++++++------- BizHawk.Emulation.Cores/CPUs/Z80A/Z80A.cs | 16 ++-- 5 files changed, 84 insertions(+), 84 deletions(-) diff --git a/BizHawk.Emulation.Cores/CPUs/Z80A/Execute.cs b/BizHawk.Emulation.Cores/CPUs/Z80A/Execute.cs index b8b65bdf39..17ff24af0d 100644 --- a/BizHawk.Emulation.Cores/CPUs/Z80A/Execute.cs +++ b/BizHawk.Emulation.Cores/CPUs/Z80A/Execute.cs @@ -27,7 +27,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A public ushort[] cur_instr; public ushort[] BUSRQ; public ushort[] MEMRQ; - public ushort[] IRQS; + public int IRQS; public byte opcode; public bool NO_prefix, CB_prefix, IX_prefix, EXTD_prefix, IY_prefix, IXCB_prefix, IYCB_prefix; public bool halted; diff --git a/BizHawk.Emulation.Cores/CPUs/Z80A/Interrupts.cs b/BizHawk.Emulation.Cores/CPUs/Z80A/Interrupts.cs index 5eec6cf45f..08ed963128 100644 --- a/BizHawk.Emulation.Cores/CPUs/Z80A/Interrupts.cs +++ b/BizHawk.Emulation.Cores/CPUs/Z80A/Interrupts.cs @@ -51,7 +51,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A BUSRQ = new ushort[] { 0, 0, 0, 0, 0, SPh, 0, 0, SPh, 0, 0 }; MEMRQ = new ushort[] { 0, 0, 0, 0, 0, SPh, 0, 0, SPh, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }; } // Mode 0 interrupts only take effect if a CALL or RST is on the data bus @@ -72,7 +72,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A BUSRQ = new ushort[] { 0, 0, 0, 0, PCh, 0, 0 }; MEMRQ = new ushort[] { 0, 0, 0, 0, PCh, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 0, 0, 0, 1 }; } // Just jump to $0038 @@ -95,7 +95,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A BUSRQ = new ushort[] { 0, 0, 0, 0, I, 0, 0, SPh, 0, 0, SPh, 0, 0 }; MEMRQ = new ushort[] { 0, 0, 0, 0, I, 0, 0, SPh, 0, 0, SPh, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }; } // Interrupt mode 2 uses the I vector combined with a byte on the data bus @@ -124,7 +124,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A BUSRQ = new ushort[] { 0, 0, 0, 0, I, 0, 0, SPh, 0, 0, SPh, 0, 0, W, 0, 0, W, 0 ,0 }; MEMRQ = new ushort[] { 0, 0, 0, 0, I, 0, 0, SPh, 0, 0, SPh, 0, 0, W, 0, 0, W, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }; } private void ResetInterrupts() diff --git a/BizHawk.Emulation.Cores/CPUs/Z80A/Tables_Direct.cs b/BizHawk.Emulation.Cores/CPUs/Z80A/Tables_Direct.cs index 6af37ce302..1b7fddac66 100644 --- a/BizHawk.Emulation.Cores/CPUs/Z80A/Tables_Direct.cs +++ b/BizHawk.Emulation.Cores/CPUs/Z80A/Tables_Direct.cs @@ -14,7 +14,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A BUSRQ = new ushort[] { 0 }; MEMRQ = new ushort[] { 0 }; - IRQS = new ushort[] { 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 1 }; } // NOTE: In a real Z80, this operation just flips a switch to choose between 2 registers @@ -26,7 +26,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A BUSRQ = new ushort[] { 0 }; MEMRQ = new ushort[] { 0 }; - IRQS = new ushort[] { 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 1 }; } private void EXX_() @@ -36,7 +36,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A BUSRQ = new ushort[] { 0 }; MEMRQ = new ushort[] { 0 }; - IRQS = new ushort[] { 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 1 }; } // this exchanges 2 16 bit registers @@ -47,7 +47,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A BUSRQ = new ushort[] { 0 }; MEMRQ = new ushort[] { 0 }; - IRQS = new ushort[] { 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 1 }; } private void INC_16(ushort src_l, ushort src_h) @@ -59,7 +59,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A BUSRQ = new ushort[] { 0, I, I }; MEMRQ = new ushort[] { 0, 0, 0 }; - IRQS = new ushort[] { 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 1 }; } @@ -72,7 +72,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A BUSRQ = new ushort[] { 0, I, I }; MEMRQ = new ushort[] { 0, 0, 0 }; - IRQS = new ushort[] { 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 1 }; } // this is done in two steps technically, but the flags don't work out using existing funcitons @@ -91,7 +91,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A BUSRQ = new ushort[] { 0, I, I, I, I, I, I, I }; MEMRQ = new ushort[] { 0, 0, 0, 0, 0, 0, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 0, 0, 0, 0, 1}; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 0, 0, 0, 0, 1}; } private void REG_OP(ushort operation, ushort dest, ushort src) @@ -101,7 +101,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A BUSRQ = new ushort[] { 0 }; MEMRQ = new ushort[] { 0 }; - IRQS = new ushort[] { 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 1 }; } // Operations using the I and R registers take one T-cycle longer @@ -113,7 +113,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A BUSRQ = new ushort[] { 0, I }; MEMRQ = new ushort[] { 0, 0 }; - IRQS = new ushort[] { 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 1 }; } // note: do not use DEC here since no flags are affected by this operation @@ -135,7 +135,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A BUSRQ = new ushort[] { 0, I, PCh, 0, 0, PCh, PCh, PCh, PCh, PCh }; MEMRQ = new ushort[] { 0, 0, PCh, 0, 0, 0, 0, 0, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }; } else { @@ -148,7 +148,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A BUSRQ = new ushort[] { 0, I, PCh, 0, 0 }; MEMRQ = new ushort[] { 0, 0, PCh, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 0, 1 }; } } @@ -159,7 +159,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A BUSRQ = new ushort[] { 0 }; MEMRQ = new ushort[] { 0 }; - IRQS = new ushort[] { 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 1 }; } private void JR_COND(bool cond) @@ -179,7 +179,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A BUSRQ = new ushort[] { 0, PCh, 0, 0, PCh, PCh, PCh, PCh, PCh }; MEMRQ = new ushort[] { 0, PCh, 0, 0, 0, 0, 0, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 0, 0, 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 0, 0, 0, 0, 0, 1 }; } else { @@ -191,7 +191,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A BUSRQ = new ushort[] { 0, PCh, 0, 0 }; MEMRQ = new ushort[] { 0, PCh, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 1 }; } } @@ -210,7 +210,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A BUSRQ = new ushort[] { 0, PCh, 0, 0, PCh, 0, 0 }; MEMRQ = new ushort[] { 0, PCh, 0, 0, PCh, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 0, 0, 0, 1 }; } else { @@ -225,7 +225,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A BUSRQ = new ushort[] { 0, PCh, 0, 0, PCh, 0, 0 }; MEMRQ = new ushort[] { 0, PCh, 0, 0, PCh, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 0, 0, 0, 1 }; } } @@ -242,7 +242,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A BUSRQ = new ushort[] { 0, SPh, 0, 0, SPh, 0, 0 }; MEMRQ = new ushort[] { 0, SPh, 0, 0, SPh, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 0, 0, 0, 1 }; } private void RETI_() @@ -258,7 +258,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A BUSRQ = new ushort[] { 0, SPh, 0, 0, SPh, 0, 0 }; MEMRQ = new ushort[] { 0, SPh, 0, 0, SPh, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 0, 0, 0, 1 }; } private void RETN_() @@ -274,7 +274,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A BUSRQ = new ushort[] { 0, SPh, 0, 0, SPh, 0, 0 }; MEMRQ = new ushort[] { 0, SPh, 0, 0, SPh, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 0, 0, 0, 1 }; } @@ -294,7 +294,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A BUSRQ = new ushort[] { 0, I, SPh, 0, 0, SPh, 0, 0 }; MEMRQ = new ushort[] { 0, 0, SPh, 0, 0, SPh, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 0, 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 0, 0, 0, 0, 1 }; } else { @@ -304,7 +304,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A BUSRQ = new ushort[] { 0, I }; MEMRQ = new ushort[] { 0, 0 }; - IRQS = new ushort[] { 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 1 }; } } @@ -330,7 +330,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A BUSRQ = new ushort[] { 0, PCh, 0, 0, PCh, 0, 0, PCh, SPh, 0, 0, SPh, 0, 0 }; MEMRQ = new ushort[] { 0, PCh, 0, 0, PCh, 0, 0, 0, SPh, 0, 0, SPh, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }; } else { @@ -345,7 +345,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A BUSRQ = new ushort[] { 0, PCh, 0, 0, PCh, 0, 0 }; MEMRQ = new ushort[] { 0, PCh, 0, 0, PCh, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 0, 0, 0, 1 }; } } @@ -356,7 +356,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A BUSRQ = new ushort[] { 0 }; MEMRQ = new ushort[] { 0 }; - IRQS = new ushort[] { 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 1 }; } private void BIT_OP(ushort operation, ushort bit, ushort src) @@ -366,7 +366,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A BUSRQ = new ushort[] { 0 }; MEMRQ = new ushort[] { 0 }; - IRQS = new ushort[] { 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 1 }; } private void PUSH_(ushort src_l, ushort src_h) @@ -383,7 +383,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A BUSRQ = new ushort[] { 0, I, SPh, 0, 0, SPh, 0, 0 }; MEMRQ = new ushort[] { 0, 0, SPh, 0, 0, SPh, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 0, 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 0, 0, 0, 0, 1 }; } @@ -400,7 +400,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A BUSRQ = new ushort[] { 0, SPh, 0, 0, SPh, 0, 0 }; MEMRQ = new ushort[] { 0, SPh, 0, 0, SPh, 0, 0 }; - IRQS = new ushort[] {0, 0, 0, 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] {0, 0, 0, 0, 0, 0, 1 }; } private void RST_(ushort n) @@ -417,7 +417,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A BUSRQ = new ushort[] { 0, I, SPh, 0, 0, SPh, 0, 0 }; MEMRQ = new ushort[] { 0, 0, SPh, 0, 0, SPh, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 0, 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 0, 0, 0, 0, 1 }; } private void PREFIX_(ushort src) @@ -432,7 +432,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A BUSRQ = new ushort[] { 0, PCh, 0, 0 }; MEMRQ = new ushort[] { 0, PCh, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 0 }; // prefix does not get interrupted + IRQS = -1;// new ushort[] { 0, 0, 0, 0 }; // prefix does not get interrupted } private void PREFETCH_(ushort src) @@ -464,7 +464,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A BUSRQ = new ushort[] { 0, PCh, 0, 0, PCh, 0, 0, PCh }; MEMRQ = new ushort[] { 0, PCh, 0, 0, PCh, 0, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 0, 0, 0, 0, 0 }; // prefetch does not get interrupted + IRQS = -1;// new ushort[] { 0, 0, 0, 0, 0, 0, 0, 0 }; // prefetch does not get interrupted } private void DI_() @@ -474,7 +474,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A BUSRQ = new ushort[] { 0 }; MEMRQ = new ushort[] { 0 }; - IRQS = new ushort[] { 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 1 }; } private void EI_() @@ -484,7 +484,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A BUSRQ = new ushort[] { 0 }; MEMRQ = new ushort[] { 0 }; - IRQS = new ushort[] { 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 1 }; } private void JP_16(ushort src_l, ushort src_h) @@ -494,7 +494,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A BUSRQ = new ushort[] { 0 }; MEMRQ = new ushort[] { 0 }; - IRQS = new ushort[] { 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 1 }; } private void LD_SP_16(ushort src_l, ushort src_h) @@ -506,7 +506,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A BUSRQ = new ushort[] { 0, I, I }; MEMRQ = new ushort[] { 0, 0, 0 }; - IRQS = new ushort[] { 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 1 }; } private void OUT_() @@ -523,7 +523,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A BUSRQ = new ushort[] { 0, PCh, 0, 0, WIO1, WIO2, WIO3, WIO4 }; MEMRQ = new ushort[] { 0, PCh, 0, 0, WIO1, WIO2, WIO3, WIO4 }; - IRQS = new ushort[] { 0, 0, 0, 0, 0, 0, 0, 1}; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 0, 0, 0, 0, 1}; } private void OUT_REG_(ushort dest, ushort src) @@ -537,7 +537,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A BUSRQ = new ushort[] { 0, BIO1, BIO2, BIO3, BIO4 }; MEMRQ = new ushort[] { 0, BIO1, BIO2, BIO3, BIO4 }; - IRQS = new ushort[] { 0, 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 0, 1 }; } private void IN_() @@ -554,7 +554,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A BUSRQ = new ushort[] { 0, PCh, 0, 0, WIO1, WIO2, WIO3, WIO4 }; MEMRQ = new ushort[] { 0, PCh, 0, 0, WIO1, WIO2, WIO3, WIO4 }; - IRQS = new ushort[] { 0, 0, 0, 0, 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 0, 0, 0, 0, 1 }; } private void IN_REG_(ushort dest, ushort src) @@ -568,7 +568,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A BUSRQ = new ushort[] { 0, BIO1, BIO2, BIO3, BIO4 }; MEMRQ = new ushort[] { 0, BIO1, BIO2, BIO3, BIO4 }; - IRQS = new ushort[] { 0, 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 0, 1 }; } private void REG_OP_16_(ushort op, ushort dest_l, ushort dest_h, ushort src_l, ushort src_h) @@ -585,7 +585,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A BUSRQ = new ushort[] { 0, I, I, I, I, I, I, I }; MEMRQ = new ushort[] { 0, 0, 0, 0, 0, 0, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 0, 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 0, 0, 0, 0, 1 }; } private void INT_MODE_(ushort src) @@ -595,7 +595,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A BUSRQ = new ushort[] { 0 }; MEMRQ = new ushort[] { 0 }; - IRQS = new ushort[] { 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 1 }; } private void RRD_() @@ -615,7 +615,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A BUSRQ = new ushort[] { 0, H, 0, 0, H, H, H, H, W, 0, 0 }; MEMRQ = new ushort[] { 0, H, 0, 0, 0, 0, 0, 0, W, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }; } private void RLD_() @@ -635,7 +635,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A BUSRQ = new ushort[] { 0, H, 0, 0, H, H, H, H, W, 0, 0 }; MEMRQ = new ushort[] { 0, H, 0, 0, 0, 0, 0, 0, W, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }; } } } diff --git a/BizHawk.Emulation.Cores/CPUs/Z80A/Tables_Indirect.cs b/BizHawk.Emulation.Cores/CPUs/Z80A/Tables_Indirect.cs index 65e0b607f5..c611444d99 100644 --- a/BizHawk.Emulation.Cores/CPUs/Z80A/Tables_Indirect.cs +++ b/BizHawk.Emulation.Cores/CPUs/Z80A/Tables_Indirect.cs @@ -16,7 +16,7 @@ BUSRQ = new ushort[] { 0, src_h, 0, 0, src_h, src_h, 0, 0 }; MEMRQ = new ushort[] { 0, src_h, 0, 0, 0, src_h, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 0, 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 0, 0, 0, 0, 1 }; } private void BIT_OP_IND(ushort operation, ushort bit, ushort src_l, ushort src_h) @@ -33,7 +33,7 @@ BUSRQ = new ushort[] { 0, src_h, 0, 0, src_h, src_h, 0, 0 }; MEMRQ = new ushort[] { 0, src_h, 0, 0, 0, src_h, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 0, 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 0, 0, 0, 0, 1 }; } // Note that this operation uses I_BIT, same as indexed BIT. @@ -51,7 +51,7 @@ BUSRQ = new ushort[] { 0, src_h, 0, 0, src_h }; MEMRQ = new ushort[] { 0, src_h, 0, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 0, 1 }; } private void REG_OP_IND_INC(ushort operation, ushort dest, ushort src_l, ushort src_h) @@ -64,7 +64,7 @@ BUSRQ = new ushort[] { 0, src_h, 0, 0 }; MEMRQ = new ushort[] { 0, src_h, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 1}; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 1}; } private void REG_OP_IND(ushort operation, ushort dest, ushort src_l, ushort src_h) @@ -77,7 +77,7 @@ BUSRQ = new ushort[] { 0, src_h, 0, 0 }; MEMRQ = new ushort[] { 0, src_h, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 1 }; } // different because HL doesn't effect WZ @@ -91,7 +91,7 @@ BUSRQ = new ushort[] { 0, H, 0, 0 }; MEMRQ = new ushort[] { 0, H, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 1 }; } private void LD_16_IND_nn(ushort src_l, ushort src_h) @@ -113,7 +113,7 @@ BUSRQ = new ushort[] { 0, PCh, 0, 0, PCh, 0, 0, W, 0, 0, W, 0, 0 }; MEMRQ = new ushort[] { 0, PCh, 0, 0, PCh, 0, 0, W, 0, 0, W, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }; } private void LD_IND_16_nn(ushort dest_l, ushort dest_h) @@ -135,7 +135,7 @@ BUSRQ = new ushort[] { 0, PCh, 0, 0, PCh, 0, 0, W, 0, 0, W, 0, 0 }; MEMRQ = new ushort[] { 0, PCh, 0, 0, PCh, 0, 0, W, 0, 0, W, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }; } private void LD_8_IND_nn(ushort src) @@ -154,7 +154,7 @@ BUSRQ = new ushort[] { 0, PCh, 0, 0, PCh, 0, 0, W, 0, 0 }; MEMRQ = new ushort[] { 0, PCh, 0, 0, PCh, 0, 0, W, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }; } private void LD_IND_8_nn(ushort dest) @@ -173,7 +173,7 @@ BUSRQ = new ushort[] { 0, PCh, 0, 0, PCh, 0, 0, W, 0, 0 }; MEMRQ = new ushort[] { 0, PCh, 0, 0, PCh, 0, 0, W, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }; } private void LD_8_IND(ushort dest_l, ushort dest_h, ushort src) @@ -186,7 +186,7 @@ BUSRQ = new ushort[] { 0, dest_h, 0, 0 }; MEMRQ = new ushort[] { 0, dest_h, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 1 }; } // seperate HL needed since it doesn't effect the WZ pair @@ -200,7 +200,7 @@ BUSRQ = new ushort[] { 0, H, 0, 0 }; MEMRQ = new ushort[] { 0, H, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 1 }; } private void LD_8_IND_IND(ushort dest_l, ushort dest_h, ushort src_l, ushort src_h) @@ -216,7 +216,7 @@ BUSRQ = new ushort[] { 0, src_h, 0, 0, dest_h, 0, 0 }; MEMRQ = new ushort[] { 0, src_h, 0, 0, dest_h, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 0, 0, 0, 1 }; } private void LD_IND_8_INC(ushort dest, ushort src_l, ushort src_h) @@ -229,7 +229,7 @@ BUSRQ = new ushort[] { 0, src_h, 0, 0 }; MEMRQ = new ushort[] { 0, src_h, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 1 }; } private void LD_IND_16(ushort dest_l, ushort dest_h, ushort src_l, ushort src_h) @@ -245,7 +245,7 @@ BUSRQ = new ushort[] { 0, src_h, 0, 0, src_h, 0, 0 }; MEMRQ = new ushort[] { 0, src_h, 0, 0, src_h, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 0, 0, 0, 1 }; } private void INC_8_IND(ushort src_l, ushort src_h) @@ -262,7 +262,7 @@ BUSRQ = new ushort[] { 0, src_h, 0, 0, src_h, src_h, 0, 0 }; MEMRQ = new ushort[] { 0, src_h, 0, 0, 0, src_h, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 0, 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 0, 0, 0, 0, 1 }; } private void DEC_8_IND(ushort src_l, ushort src_h) @@ -279,7 +279,7 @@ BUSRQ = new ushort[] { 0, src_h, 0, 0, src_h, src_h, 0, 0 }; MEMRQ = new ushort[] { 0, src_h, 0, 0, 0, src_h, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 0, 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 0, 0, 0, 0, 1 }; } // NOTE: WZ implied for the wollowing 3 functions @@ -297,7 +297,7 @@ BUSRQ = new ushort[] { 0, W, 0, 0, W, W, 0, 0 }; MEMRQ = new ushort[] { 0, W, 0, 0, 0, W, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 0, 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 0, 0, 0, 0, 1 }; } private void I_BIT_OP(ushort operation, ushort bit, ushort dest) @@ -314,7 +314,7 @@ BUSRQ = new ushort[] { 0, W, 0, 0, W, W, 0, 0 }; MEMRQ = new ushort[] { 0, W, 0, 0, 0, W, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 0, 0, 0, 0, 1}; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 0, 0, 0, 0, 1}; } private void I_BIT_TE(ushort bit) @@ -328,7 +328,7 @@ BUSRQ = new ushort[] { 0, W, 0, 0, W }; MEMRQ = new ushort[] { 0, W, 0, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 0, 1 }; } private void I_OP_n(ushort operation, ushort src_l, ushort src_h) @@ -353,7 +353,7 @@ BUSRQ = new ushort[] { 0, PCh, 0, 0, PCh, PCh, PCh, PCh, PCh, W, 0, 0, W, W, 0, 0 }; MEMRQ = new ushort[] { 0, PCh, 0, 0, 0, 0, 0, 0, 0, W, 0, 0, 0, W, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }; } private void I_OP_n_n(ushort src_l, ushort src_h) @@ -374,7 +374,7 @@ BUSRQ = new ushort[] { 0, PCh, 0, 0, PCh, 0, 0, PCh, PCh, W, 0, 0 }; MEMRQ = new ushort[] { 0, PCh, 0, 0, PCh, 0, 0, 0, 0, W, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }; } private void I_REG_OP_IND_n(ushort operation, ushort dest, ushort src_l, ushort src_h) @@ -395,7 +395,7 @@ BUSRQ = new ushort[] { 0, PCh, 0, 0, PCh, PCh, PCh, PCh, PCh, W, 0, 0 }; MEMRQ = new ushort[] { 0, PCh, 0, 0, 0, 0, 0, 0, 0, W, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }; } private void I_LD_8_IND_n(ushort dest_l, ushort dest_h, ushort src) @@ -416,7 +416,7 @@ BUSRQ = new ushort[] { 0, PCh, 0, 0, PCh, PCh, PCh, PCh, PCh, Z, 0, 0 }; MEMRQ = new ushort[] { 0, PCh, 0, 0, 0, 0, 0, 0, 0, Z, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }; } private void LD_OP_R(ushort operation, ushort repeat_instr) @@ -434,7 +434,7 @@ BUSRQ = new ushort[] { 0, H, 0, 0, D, 0, 0, D, D }; MEMRQ = new ushort[] { 0, H, 0, 0, D, 0, 0, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 0, 0, 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 0, 0, 0, 0, 0, 1 }; } private void CP_OP_R(ushort operation, ushort repeat_instr) @@ -452,7 +452,7 @@ BUSRQ = new ushort[] { 0, H, 0, 0, H, H, H, H, H }; MEMRQ = new ushort[] { 0, H, 0, 0, 0, 0, 0, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 0, 0, 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 0, 0, 0, 0, 0, 1 }; } private void IN_OP_R(ushort operation, ushort repeat_instr) @@ -470,7 +470,7 @@ BUSRQ = new ushort[] { 0, I, BIO1, BIO2, BIO3, BIO4, H, 0, 0}; MEMRQ = new ushort[] { 0, 0, BIO1, BIO2, BIO3, BIO4, H, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 0, 0, 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 0, 0, 0, 0, 0, 1 }; } private void OUT_OP_R(ushort operation, ushort repeat_instr) @@ -488,7 +488,7 @@ BUSRQ = new ushort[] { 0, I, H, 0, 0, BIO1, BIO2, BIO3, BIO4 }; MEMRQ = new ushort[] { 0, 0, H, 0, 0, BIO1, BIO2, BIO3, BIO4 }; - IRQS = new ushort[] { 0, 0, 0, 0, 0, 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 0, 0, 0, 0, 0, 1 }; } // this is an indirect change of a a 16 bit register with memory @@ -514,7 +514,7 @@ BUSRQ = new ushort[] { 0, dest_h, 0, 0, dest_h, 0, 0, dest_h, dest_h, 0, 0, dest_h, 0, 0, dest_h, dest_h }; MEMRQ = new ushort[] { 0, dest_h, 0, 0, dest_h, 0, 0, 0, dest_h, 0, 0, dest_h, 0, 0, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }; } } } diff --git a/BizHawk.Emulation.Cores/CPUs/Z80A/Z80A.cs b/BizHawk.Emulation.Cores/CPUs/Z80A/Z80A.cs index 6c7c9f3e50..9572660737 100644 --- a/BizHawk.Emulation.Cores/CPUs/Z80A/Z80A.cs +++ b/BizHawk.Emulation.Cores/CPUs/Z80A/Z80A.cs @@ -111,7 +111,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A BUSRQ = new ushort[] { 0, 0, 0 }; MEMRQ = new ushort[] { 0, 0, 0 }; - IRQS = new ushort[] { 0, 0, 1 }; + IRQS = 3;// new ushort[] { 0, 0, 1 }; instr_pntr = mem_pntr = bus_pntr = irq_pntr = 0; NO_prefix = true; } @@ -468,7 +468,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A BUSRQ = new ushort[] { D, D, D, D, D }; MEMRQ = new ushort[] { 0, 0, 0, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 0, 1 }; instr_pntr = mem_pntr = bus_pntr = irq_pntr = 0; I_skip = true; @@ -497,7 +497,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A BUSRQ = new ushort[] { H, H, H, H, H }; MEMRQ = new ushort[] { 0, 0, 0, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 0, 1 }; instr_pntr = mem_pntr = bus_pntr = irq_pntr = 0; I_skip = true; @@ -571,7 +571,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A BUSRQ = new ushort[] { H, H, H, H, H }; MEMRQ = new ushort[] { 0, 0, 0, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 0, 1 }; instr_pntr = mem_pntr = bus_pntr = irq_pntr = 0; I_skip = true; @@ -622,7 +622,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A BUSRQ = new ushort[] { B, B, B, B, B }; MEMRQ = new ushort[] { 0, 0, 0, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 0, 1 }; instr_pntr = mem_pntr = bus_pntr = irq_pntr = 0; I_skip = true; @@ -638,7 +638,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A { I_skip = false; } - else if (IRQS[irq_pntr++] == 1) + else if (++irq_pntr == IRQS) { if (EI_pending > 0) { @@ -715,7 +715,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A BUSRQ = new ushort[] { PCh, 0, 0, 0 }; MEMRQ = new ushort[] { PCh, 0, 0, 0 }; - IRQS = new ushort[] { 0, 0, 0, 1 }; + IRQS = BUSRQ.Length;// new ushort[] { 0, 0, 0, 1 }; instr_pntr = mem_pntr = bus_pntr = irq_pntr = 0; } @@ -802,7 +802,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A ser.Sync("irq_pntr", ref irq_pntr); ser.Sync("cur_instr", ref cur_instr, false); ser.Sync("BUSRQ", ref BUSRQ, false); - ser.Sync("IRQS", ref IRQS, false); + ser.Sync("IRQS", ref IRQS); ser.Sync("MEMRQ", ref MEMRQ, false); ser.Sync("opcode", ref opcode); ser.Sync("FlagI", ref FlagI);