aboutsummaryrefslogtreecommitdiff
path: root/src/cpu/interrupt.ts
diff options
context:
space:
mode:
authorUri Shaked2020-09-02 15:37:34 +0300
committerUri Shaked2020-09-02 15:37:34 +0300
commit09f2385282b0c98a3fdc4b89091d0c62b61725f5 (patch)
treec5e25b45fc7aad682cb0d8fcbe8af712767b8500 /src/cpu/interrupt.ts
parentfix(instruction): EICALL is broken (diff)
downloadavr8js-09f2385282b0c98a3fdc4b89091d0c62b61725f5.tar.gz
avr8js-09f2385282b0c98a3fdc4b89091d0c62b61725f5.tar.bz2
avr8js-09f2385282b0c98a3fdc4b89091d0c62b61725f5.zip
fix(interrupt): broken on ATmega2560
close #58
Diffstat (limited to '')
-rw-r--r--src/cpu/interrupt.ts5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/cpu/interrupt.ts b/src/cpu/interrupt.ts
index 1c7d835..1bfa035 100644
--- a/src/cpu/interrupt.ts
+++ b/src/cpu/interrupt.ts
@@ -12,7 +12,10 @@ export function avrInterrupt(cpu: ICPU, addr: number) {
const sp = cpu.dataView.getUint16(93, true);
cpu.data[sp] = cpu.pc & 0xff;
cpu.data[sp - 1] = (cpu.pc >> 8) & 0xff;
- cpu.dataView.setUint16(93, sp - 2, true);
+ if (cpu.pc22Bits) {
+ cpu.data[sp - 2] = (cpu.pc >> 16) & 0xff;
+ }
+ cpu.dataView.setUint16(93, sp - (cpu.pc22Bits ? 3 : 2), true);
cpu.data[95] &= 0x7f; // clear global interrupt flag
cpu.cycles += 2;
cpu.pc = addr;