1
0
mirror of https://github.com/sethm/symon.git synced 2024-06-07 19:29:27 +00:00

Add NMI flag to CPU

This commit is contained in:
Seth Morabito 2014-01-25 20:02:17 -08:00
parent 0c5035fc56
commit b6cc480919
3 changed files with 62 additions and 20 deletions

View File

@ -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();
}
}

View File

@ -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.

View File

@ -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);
}
}