kopia lustrzana https://github.com/maccasoft/z80-tools
More accurate emulator timing
rodzic
58ad0cf425
commit
51f8b2b340
|
@ -55,7 +55,6 @@ public class Machine extends MemIoOps {
|
||||||
Z80 proc;
|
Z80 proc;
|
||||||
Thread thread;
|
Thread thread;
|
||||||
double clockNs;
|
double clockNs;
|
||||||
long tstates;
|
|
||||||
|
|
||||||
public Machine() {
|
public Machine() {
|
||||||
rom = new byte[16384];
|
rom = new byte[16384];
|
||||||
|
@ -108,16 +107,18 @@ public class Machine extends MemIoOps {
|
||||||
|
|
||||||
while (!Thread.interrupted()) {
|
while (!Thread.interrupted()) {
|
||||||
synchronized (proc) {
|
synchronized (proc) {
|
||||||
long current = System.nanoTime();
|
int runTstates = (int) ((System.nanoTime() - ns) / clockNs);
|
||||||
long tstates = getTstates() + (long) ((current - ns) / clockNs);
|
if (runTstates >= 4) {
|
||||||
while (getTstates() < tstates) {
|
long prevTstates = tstates;
|
||||||
proc.execute();
|
while (tstates < (prevTstates + runTstates)) {
|
||||||
|
proc.execute();
|
||||||
|
}
|
||||||
|
ns += (tstates - prevTstates) * clockNs;
|
||||||
}
|
}
|
||||||
ns = current;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Thread.sleep(1);
|
Thread.sleep(1L);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,8 @@ public class MemIoOps {
|
||||||
|
|
||||||
private byte[] z80Ram;
|
private byte[] z80Ram;
|
||||||
private byte[] z80Ports;
|
private byte[] z80Ports;
|
||||||
private long tstates = 0;
|
|
||||||
|
protected long tstates = 0;
|
||||||
|
|
||||||
public MemIoOps() {
|
public MemIoOps() {
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue