aboutsummaryrefslogtreecommitdiff
path: root/demo/src
diff options
context:
space:
mode:
authorUri Shaked2020-02-11 17:01:16 +0200
committerUri Shaked2020-02-11 17:01:16 +0200
commit0ad2178653365eb38aebffc5a4ca22c795ac3f83 (patch)
tree83363cb776229296881626ee7eea3f781285dfd2 /demo/src
parentperf(demo): build for es2018 (diff)
downloadavr8js-0ad2178653365eb38aebffc5a4ca22c795ac3f83.tar.gz
avr8js-0ad2178653365eb38aebffc5a4ca22c795ac3f83.tar.bz2
avr8js-0ad2178653365eb38aebffc5a4ca22c795ac3f83.zip
fix(demo): browser freezes on edge case
Diffstat (limited to '')
-rw-r--r--demo/src/execute.ts5
1 files changed, 4 insertions, 1 deletions
diff --git a/demo/src/execute.ts b/demo/src/execute.ts
index 3a2f162..7b6cae0 100644
--- a/demo/src/execute.ts
+++ b/demo/src/execute.ts
@@ -39,16 +39,19 @@ export class AVRRunner {
async execute(callback: (cpu: CPU) => void) {
this.stopped = false;
+ const workUnitCycles = 500000;
+ let nextTick = this.cpu.cycles + workUnitCycles;
for (;;) {
avrInstruction(this.cpu);
this.timer.tick();
this.usart.tick();
- if (this.cpu.cycles % 500000 === 0) {
+ if (this.cpu.cycles >= nextTick) {
callback(this.cpu);
await new Promise((resolve) => setTimeout(resolve, 0));
if (this.stopped) {
break;
}
+ nextTick += workUnitCycles;
}
}
}