diff options
| author | Uri Shaked | 2020-02-11 17:01:16 +0200 |
|---|---|---|
| committer | Uri Shaked | 2020-02-11 17:01:16 +0200 |
| commit | 0ad2178653365eb38aebffc5a4ca22c795ac3f83 (patch) | |
| tree | 83363cb776229296881626ee7eea3f781285dfd2 | |
| parent | perf(demo): build for es2018 (diff) | |
| download | avr8js-0ad2178653365eb38aebffc5a4ca22c795ac3f83.tar.gz avr8js-0ad2178653365eb38aebffc5a4ca22c795ac3f83.tar.bz2 avr8js-0ad2178653365eb38aebffc5a4ca22c795ac3f83.zip | |
fix(demo): browser freezes on edge case
| -rw-r--r-- | demo/src/execute.ts | 5 |
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; } } } |
