From b6cc4809192d2eed4d4162e51f845d19ef9d2445 Mon Sep 17 00:00:00 2001 From: Seth Morabito Date: Sat, 25 Jan 2014 20:02:17 -0800 Subject: [PATCH] Add NMI flag to CPU --- src/main/java/com/loomcom/symon/Bus.java | 20 +++++++++--- src/main/java/com/loomcom/symon/Cpu.java | 34 ++++++++++++++------ src/test/java/com/loomcom/symon/BusTest.java | 28 ++++++++++++---- 3 files changed, 62 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/loomcom/symon/Bus.java b/src/main/java/com/loomcom/symon/Bus.java index 429853b..650df3c 100644 --- a/src/main/java/com/loomcom/symon/Bus.java +++ b/src/main/java/com/loomcom/symon/Bus.java @@ -151,15 +151,27 @@ public class Bus { throw new MemoryAccessException("Bus write failed. No device at address " + String.format("$%04X", address)); } - public void assertInterrupt() { + public void assertIrq() { if (cpu != null) { - cpu.assertInterrupt(); + cpu.assertIrq(); } } - public void clearInterrupt() { + public void clearIrq() { if (cpu != null) { - cpu.clearInterrupt(); + cpu.clearIrq(); + } + } + + public void assertNmi() { + if (cpu != null) { + cpu.assertNmi(); + } + } + + public void clearNmi() { + if (cpu != null) { + cpu.clearNmi(); } } diff --git a/src/main/java/com/loomcom/symon/Cpu.java b/src/main/java/com/loomcom/symon/Cpu.java index c5ab304..85a6cba 100644 --- a/src/main/java/com/loomcom/symon/Cpu.java +++ b/src/main/java/com/loomcom/symon/Cpu.java @@ -133,7 +133,7 @@ public class Cpu implements InstructionTable { state.overflowFlag = false; state.negativeFlag = false; - state.interruptAsserted = false; + state.irqAsserted = false; // Clear illegal opcode trap. state.opTrap = false; @@ -154,7 +154,7 @@ public class Cpu implements InstructionTable { } /** - * Performs an individual machine cycle. + * Performs an individual instruction cycle. */ public void step() throws MemoryAccessException { // Store the address from which the IR was read, for debugging @@ -1168,15 +1168,29 @@ public class Cpu implements InstructionTable { /** * Simulate transition from logic-high to logic-low on the INT line. */ - public void assertInterrupt() { - state.interruptAsserted = true; + public void assertIrq() { + state.irqAsserted = true; } /** * Simulate transition from logic-low to logic-high of the INT line. */ - public void clearInterrupt() { - state.interruptAsserted = false; + public void clearIrq() { + state.irqAsserted = false; + } + + /** + * Simulate transition from logic-high to logic-low on the NMI line. + */ + public void assertNmi() { + state.nmiAsserted = true; + } + + /** + * Simulate transition from logic-low to logic-high of the NMI line. + */ + public void clearNmi() { + state.nmiAsserted = false; } /** @@ -1323,8 +1337,8 @@ public class Cpu implements InstructionTable { public int[] args = new int[2]; public int instSize; public boolean opTrap; - /* True if the INT line was held low */ - public boolean interruptAsserted; + public boolean irqAsserted; + public boolean nmiAsserted; /* Status Flag Register bits */ public boolean carryFlag; @@ -1361,7 +1375,7 @@ public class Cpu implements InstructionTable { this.args[1] = s.args[1]; this.instSize = s.instSize; this.opTrap = s.opTrap; - this.interruptAsserted = s.interruptAsserted; + this.irqAsserted = s.irqAsserted; this.carryFlag = s.carryFlag; this.negativeFlag = s.negativeFlag; this.zeroFlag = s.zeroFlag; @@ -1370,7 +1384,7 @@ public class Cpu implements InstructionTable { this.breakFlag = s.breakFlag; this.overflowFlag = s.overflowFlag; this.stepCounter = s.stepCounter; - } + } /** * Returns a string formatted for the trace log. diff --git a/src/test/java/com/loomcom/symon/BusTest.java b/src/test/java/com/loomcom/symon/BusTest.java index f2eb35a..b4a8a9a 100644 --- a/src/test/java/com/loomcom/symon/BusTest.java +++ b/src/test/java/com/loomcom/symon/BusTest.java @@ -119,20 +119,36 @@ public class BusTest extends TestCase { assertTrue("Address space should have been complete!", b.isComplete()); } - public void testSetAndClearInterrupt() throws Exception { + public void testSetAndClearIrq() throws Exception { Bus b = new Bus(0x0000, 0xffff); Cpu c = new Cpu(); b.addCpu(c); - assertFalse(c.getCpuState().interruptAsserted); + assertFalse(c.getCpuState().irqAsserted); - b.assertInterrupt(); + b.assertIrq(); - assertTrue(c.getCpuState().interruptAsserted); + assertTrue(c.getCpuState().irqAsserted); - b.clearInterrupt(); + b.clearIrq(); - assertFalse(c.getCpuState().interruptAsserted); + assertFalse(c.getCpuState().irqAsserted); + } + + public void testSetAndClearNmi() throws Exception { + Bus b = new Bus(0x0000, 0xffff); + Cpu c = new Cpu(); + b.addCpu(c); + + assertFalse(c.getCpuState().nmiAsserted); + + b.assertNmi(); + + assertTrue(c.getCpuState().nmiAsserted); + + b.clearNmi(); + + assertFalse(c.getCpuState().nmiAsserted); } }