From 0ad2178653365eb38aebffc5a4ca22c795ac3f83 Mon Sep 17 00:00:00 2001 From: Uri Shaked Date: Tue, 11 Feb 2020 17:01:16 +0200 Subject: fix(demo): browser freezes on edge case --- demo/src/execute.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'demo/src/execute.ts') 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; } } } -- cgit v1.2.3