More accurate emulator timing

master
Marco Maccaferri 2019-05-01 09:53:37 +02:00
rodzic 58ad0cf425
commit 51f8b2b340
2 zmienionych plików z 10 dodań i 8 usunięć

Wyświetl plik

@ -55,7 +55,6 @@ public class Machine extends MemIoOps {
Z80 proc;
Thread thread;
double clockNs;
long tstates;
public Machine() {
rom = new byte[16384];
@ -108,16 +107,18 @@ public class Machine extends MemIoOps {
while (!Thread.interrupted()) {
synchronized (proc) {
long current = System.nanoTime();
long tstates = getTstates() + (long) ((current - ns) / clockNs);
while (getTstates() < tstates) {
proc.execute();
int runTstates = (int) ((System.nanoTime() - ns) / clockNs);
if (runTstates >= 4) {
long prevTstates = tstates;
while (tstates < (prevTstates + runTstates)) {
proc.execute();
}
ns += (tstates - prevTstates) * clockNs;
}
ns = current;
}
try {
Thread.sleep(1);
Thread.sleep(1L);
} catch (InterruptedException e) {
break;
}

Wyświetl plik

@ -13,7 +13,8 @@ public class MemIoOps {
private byte[] z80Ram;
private byte[] z80Ports;
private long tstates = 0;
protected long tstates = 0;
public MemIoOps() {