1
0
mirror of https://github.com/sethm/symon.git synced 2024-11-10 17:08:55 +00:00

Add interrupt flag to CPU

This commit is contained in:
Seth Morabito 2014-01-25 19:53:53 -08:00
parent 3d36cd5460
commit 0c5035fc56
3 changed files with 151 additions and 102 deletions

View File

@ -151,6 +151,18 @@ public class Bus {
throw new MemoryAccessException("Bus write failed. No device at address " + String.format("$%04X", address)); throw new MemoryAccessException("Bus write failed. No device at address " + String.format("$%04X", address));
} }
public void assertInterrupt() {
if (cpu != null) {
cpu.assertInterrupt();
}
}
public void clearInterrupt() {
if (cpu != null) {
cpu.clearInterrupt();
}
}
public SortedSet<Device> getDevices() { public SortedSet<Device> getDevices() {
// Expose a copy of the device list, not the original // Expose a copy of the device list, not the original
return new TreeSet<Device>(devices); return new TreeSet<Device>(devices);

View File

@ -113,7 +113,9 @@ public class Cpu implements InstructionTable {
* Reset the CPU to known initial values. * Reset the CPU to known initial values.
*/ */
public void reset() throws MemoryAccessException { public void reset() throws MemoryAccessException {
// Registers /* TODO: In reality, the stack pointer could be anywhere
on the stack after reset. This non-deterministic behavior might be
worth while to simulate. */
state.sp = 0xff; state.sp = 0xff;
// Set the PC to the address stored in the reset vector // Set the PC to the address stored in the reset vector
@ -131,6 +133,8 @@ public class Cpu implements InstructionTable {
state.overflowFlag = false; state.overflowFlag = false;
state.negativeFlag = false; state.negativeFlag = false;
state.interruptAsserted = false;
// Clear illegal opcode trap. // Clear illegal opcode trap.
state.opTrap = false; state.opTrap = false;
@ -1161,6 +1165,20 @@ public class Cpu implements InstructionTable {
return state.getStatusFlag(); return state.getStatusFlag();
} }
/**
* Simulate transition from logic-high to logic-low on the INT line.
*/
public void assertInterrupt() {
state.interruptAsserted = true;
}
/**
* Simulate transition from logic-low to logic-high of the INT line.
*/
public void clearInterrupt() {
state.interruptAsserted = false;
}
/** /**
* Push an item onto the stack, and decrement the stack counter. * Push an item onto the stack, and decrement the stack counter.
* Will wrap-around if already at the bottom of the stack (This * Will wrap-around if already at the bottom of the stack (This
@ -1305,6 +1323,8 @@ public class Cpu implements InstructionTable {
public int[] args = new int[2]; public int[] args = new int[2];
public int instSize; public int instSize;
public boolean opTrap; public boolean opTrap;
/* True if the INT line was held low */
public boolean interruptAsserted;
/* Status Flag Register bits */ /* Status Flag Register bits */
public boolean carryFlag; public boolean carryFlag;
@ -1341,6 +1361,7 @@ public class Cpu implements InstructionTable {
this.args[1] = s.args[1]; this.args[1] = s.args[1];
this.instSize = s.instSize; this.instSize = s.instSize;
this.opTrap = s.opTrap; this.opTrap = s.opTrap;
this.interruptAsserted = s.interruptAsserted;
this.carryFlag = s.carryFlag; this.carryFlag = s.carryFlag;
this.negativeFlag = s.negativeFlag; this.negativeFlag = s.negativeFlag;
this.zeroFlag = s.zeroFlag; this.zeroFlag = s.zeroFlag;

View File

@ -119,4 +119,20 @@ public class BusTest extends TestCase {
assertTrue("Address space should have been complete!", b.isComplete()); assertTrue("Address space should have been complete!", b.isComplete());
} }
public void testSetAndClearInterrupt() throws Exception {
Bus b = new Bus(0x0000, 0xffff);
Cpu c = new Cpu();
b.addCpu(c);
assertFalse(c.getCpuState().interruptAsserted);
b.assertInterrupt();
assertTrue(c.getCpuState().interruptAsserted);
b.clearInterrupt();
assertFalse(c.getCpuState().interruptAsserted);
}
} }