mirror of
https://github.com/sethm/symon.git
synced 2024-09-29 04:54:53 +00:00
Refactor delay loop
This commit is contained in:
parent
6e8fd40014
commit
84e5c5ad56
@ -58,6 +58,9 @@ public class Cpu implements InstructionTable {
|
|||||||
public static final int IRQ_VECTOR_L = 0xfffe;
|
public static final int IRQ_VECTOR_L = 0xfffe;
|
||||||
public static final int IRQ_VECTOR_H = 0xffff;
|
public static final int IRQ_VECTOR_H = 0xffff;
|
||||||
|
|
||||||
|
// Simulated speed is 1 MHz
|
||||||
|
private static final long CLOCK_IN_NS = 1000;
|
||||||
|
|
||||||
/* Simulated behavior */
|
/* Simulated behavior */
|
||||||
private CpuBehavior behavior;
|
private CpuBehavior behavior;
|
||||||
|
|
||||||
@ -150,6 +153,7 @@ public class Cpu implements InstructionTable {
|
|||||||
*/
|
*/
|
||||||
public void step() throws MemoryAccessException {
|
public void step() throws MemoryAccessException {
|
||||||
opBeginTime = System.nanoTime();
|
opBeginTime = System.nanoTime();
|
||||||
|
|
||||||
// Store the address from which the IR was read, for debugging
|
// Store the address from which the IR was read, for debugging
|
||||||
state.lastPc = state.pc;
|
state.lastPc = state.pc;
|
||||||
|
|
||||||
@ -1330,19 +1334,22 @@ public class Cpu implements InstructionTable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Perform a busy-loop for CLOCK_IN_NS nanoseconds
|
* Perform a busy-loop until the instruction should complete on the wall clock
|
||||||
*/
|
*/
|
||||||
private void delayLoop(int opcode) {
|
private void delayLoop(int opcode) {
|
||||||
int clockSteps = Cpu.instructionClocks[0xff & opcode];
|
int clockSteps = Cpu.instructionClocks[0xff & opcode];
|
||||||
// Just a precaution. This could be better.
|
|
||||||
if (clockSteps == 0) {
|
if (clockSteps == 0) {
|
||||||
clockSteps = 1;
|
logger.warn("Opcode {} has clock step of 0!", opcode);
|
||||||
}
|
return;
|
||||||
long opScheduledEnd = opBeginTime + clockSteps;
|
|
||||||
long now = System.nanoTime();
|
|
||||||
while(now < opScheduledEnd) {
|
|
||||||
now = System.nanoTime();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
long interval = clockSteps * CLOCK_IN_NS;
|
||||||
|
long end;
|
||||||
|
|
||||||
|
do {
|
||||||
|
end = System.nanoTime();
|
||||||
|
} while (opBeginTime + interval >= end);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user