aboutsummaryrefslogtreecommitdiff
path: root/src/peripherals/eeprom.ts
diff options
context:
space:
mode:
authorUri Shaked2020-12-09 15:46:53 +0200
committerUri Shaked2020-12-09 15:49:41 +0200
commit9c1288f18889ae3bd10869a9f6ebc53defa3024b (patch)
tree1857fe48d3e2d32a39cfe810a0dfdd7d96526b3a /src/peripherals/eeprom.ts
parentrefactor: central interrupt handling #38 (diff)
downloadavr8js-9c1288f18889ae3bd10869a9f6ebc53defa3024b.tar.gz
avr8js-9c1288f18889ae3bd10869a9f6ebc53defa3024b.tar.bz2
avr8js-9c1288f18889ae3bd10869a9f6ebc53defa3024b.zip
perf!: centeral timekeeping
This should improve performance, especially when running simulations with multiple peripherals. For instance, the demo project now runs at ~322%, up from ~185% in AVR8js 0.13.1. BREAKING CHANGE: `tick()` methods were removed from individual peripherals. You now need to call `cpu.tick()` instead.
Diffstat (limited to '')
-rw-r--r--src/peripherals/eeprom.ts22
1 files changed, 10 insertions, 12 deletions
diff --git a/src/peripherals/eeprom.ts b/src/peripherals/eeprom.ts
index bc386ca..d492aa7 100644
--- a/src/peripherals/eeprom.ts
+++ b/src/peripherals/eeprom.ts
@@ -95,7 +95,11 @@ export class AVREEPROM {
}
if (eecr & EEMPE) {
- this.writeEnabledCycles = this.cpu.cycles + 4;
+ const eempeCycles = 4;
+ this.writeEnabledCycles = this.cpu.cycles + eempeCycles;
+ this.cpu.addClockEvent(() => {
+ this.cpu.data[EECR] &= ~EEMPE;
+ }, eempeCycles);
}
// Read
@@ -134,6 +138,11 @@ export class AVREEPROM {
}
this.cpu.data[EECR] |= EEPE;
+
+ this.cpu.addClockEvent(() => {
+ this.cpu.setInterruptFlag(this.EER);
+ }, this.writeCompleteCycles - this.cpu.cycles);
+
// When EEPE has been set, the CPU is halted for two cycles before the
// next instruction is executed.
this.cpu.cycles += 2;
@@ -143,15 +152,4 @@ export class AVREEPROM {
return false;
};
}
-
- tick() {
- const { EECR } = this.config;
-
- if (this.writeEnabledCycles && this.cpu.cycles > this.writeEnabledCycles) {
- this.cpu.data[EECR] &= ~EEMPE;
- }
- if (this.writeCompleteCycles && this.cpu.cycles > this.writeCompleteCycles) {
- this.cpu.setInterruptFlag(this.EER);
- }
- }
}