From 8ce71f8ab8e49c3f78d7512814c94008a6f4d7a0 Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Sun, 8 Sep 2019 16:41:04 +0100 Subject: [PATCH] Sync with latest C++ version. Fixes a couple of Z80 issues. Signed-off-by: Adrian Conlon --- Z80/Disassembler.cs | 7 ++++++- Z80/Z80.cs | 46 ++++++++++++++++++++++++--------------------- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/Z80/Disassembler.cs b/Z80/Disassembler.cs index 7a7c33b..ffd1843 100644 --- a/Z80/Disassembler.cs +++ b/Z80/Disassembler.cs @@ -56,7 +56,12 @@ namespace EightBit + $"D={d:x2} E={e:x2} " + $"H={h:x2} L={l:x2} " + $"I={i:x2} R={(byte)r:x2} " - + $"IM={im}"; + + $"IM={im} " + + $"IFF1={(cpu.IFF1 ? 1 : 0)} " + + $"{(cpu.RESET.Lowered() ? "R" : "-")}" + + $"{(cpu.INT.Lowered() ? "I" : "-")}" + + $"{(cpu.HALT.Lowered() ? "H" : "-")}" + + $"{(cpu.NMI.Lowered() ? "N" : "-")}"; } public string Disassemble(Z80 cpu) diff --git a/Z80/Z80.cs b/Z80/Z80.cs index 4c06afd..9ad960d 100644 --- a/Z80/Z80.cs +++ b/Z80/Z80.cs @@ -193,23 +193,31 @@ namespace EightBit { this.displaced = this.prefixCB = this.prefixDD = this.prefixED = false; this.LowerM1(); + var handled = false; if (this.RESET.Lowered()) { this.HandleRESET(); + handled = true; } else if (this.NMI.Lowered()) { this.HandleNMI(); + handled = true; } else if (this.INT.Lowered()) { - this.HandleINT(); + this.RaiseHALT(); + if (handled = this.IFF1) + { + this.HandleINT(); + } } else if (this.HALT.Lowered()) { this.Execute(0); // NOP } - else + + if (!handled) { this.Execute(this.FetchByte()); } @@ -269,26 +277,22 @@ namespace EightBit protected override void HandleINT() { base.HandleINT(); - this.RaiseHALT(); - if (this.IFF1) + this.DisableInterrupts(); + switch (this.IM) { - this.DisableInterrupts(); - switch (this.IM) - { - case 0: // i8080 equivalent - this.Execute(this.Bus.Data); - break; - case 1: - this.Restart(7 << 3); - this.Tick(13); - break; - case 2: - this.Call(this.MEMPTR.Word = new Register16(this.Bus.Data, this.IV).Word); - this.Tick(19); - break; - default: - throw new NotSupportedException("Invalid interrupt mode"); - } + case 0: // i8080 equivalent + this.Execute(this.Bus.Data); + break; + case 1: + this.Restart(7 << 3); + this.Tick(13); + break; + case 2: + this.Call(this.MEMPTR.Word = new Register16(this.Bus.Data, this.IV).Word); + this.Tick(19); + break; + default: + throw new NotSupportedException("Invalid interrupt mode"); } }