diff options
| author | Apexo | 2026-04-01 16:30:11 +0200 |
|---|---|---|
| committer | Apexo | 2026-04-01 16:30:13 +0200 |
| commit | 3a0741213e573f96d828c2c044caff23d41f2a9e (patch) | |
| tree | 5e6ad43c35843baf797f1f45bb4d6ec807c2975b /src/lights | |
| parent | fix slpctrl (diff) | |
| download | anduril-sim-3a0741213e573f96d828c2c044caff23d41f2a9e.tar.gz anduril-sim-3a0741213e573f96d828c2c044caff23d41f2a9e.tar.bz2 anduril-sim-3a0741213e573f96d828c2c044caff23d41f2a9e.zip | |
improve main loop
- call cpu.tick() first, when we enter the loop; external events (which
may cause an interrupt) can only happen when the loop is not running,
so it makes sense to first check for interrupts before executing
other instructions
- don't go to sleep if an interrupt is pending
Diffstat (limited to 'src/lights')
| -rw-r--r-- | src/lights/d3aa.ts | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/lights/d3aa.ts b/src/lights/d3aa.ts index 9b8b0ba..29dc249 100644 --- a/src/lights/d3aa.ts +++ b/src/lights/d3aa.ts @@ -169,17 +169,20 @@ export class D3AA { /** Run the CPU for the given number of cycles */ step(cycles: number) { const target = this.cpu.cycles + cycles; + while (this.cpu.cycles < target) { + this.cpu.tick(); + const before = this.cpu.cycles; + this.slpctrl.sleepUntil = 0; avrInstruction(this.cpu); const mult = this.clkctrl.cycleMultiplier; if (mult > 1) { this.cpu.cycles += (this.cpu.cycles - before) * (mult - 1); } - if (this.slpctrl.sleepUntil > this.cpu.cycles) { + if (this.slpctrl.sleepUntil > this.cpu.cycles && this.cpu.nextInterrupt < 0) { this.cpu.cycles = Math.min(this.slpctrl.sleepUntil, target); } - this.cpu.tick(); } } |
