diff options
Diffstat (limited to '')
| -rw-r--r-- | src/peripherals/eeprom.ts | 22 |
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); - } - } } |
