summaryrefslogtreecommitdiff
path: root/src/lights/d3aa.ts
diff options
context:
space:
mode:
authorApexo2026-04-01 16:30:11 +0200
committerApexo2026-04-01 16:30:13 +0200
commit3a0741213e573f96d828c2c044caff23d41f2a9e (patch)
tree5e6ad43c35843baf797f1f45bb4d6ec807c2975b /src/lights/d3aa.ts
parentfix slpctrl (diff)
downloadanduril-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/d3aa.ts')
-rw-r--r--src/lights/d3aa.ts7
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();
}
}
If you find this content useful please consider a small donation via bitcoin: bitcoin:1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2?amount=0.001&message=Donation Scraping git contents via cgit is very resource intensive. The continued hosting of these git repositories is entirely financed by your bitcoin contributions. For donations of a least 1 mBTC you include your IP address in the message of your bitcoin donation. This will remove this message in the future for requests from your IP, which will significantly reduce token usage. In any case, any contributions to bitcoin address 1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2 are very welcome. Thanks in advance for you contribution to a self-sustaining ecosystem.