aboutsummaryrefslogtreecommitdiff
path: root/src/interrupt.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/interrupt.ts')
-rw-r--r--src/interrupt.ts11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/interrupt.ts b/src/interrupt.ts
new file mode 100644
index 0000000..d833a3a
--- /dev/null
+++ b/src/interrupt.ts
@@ -0,0 +1,11 @@
+import { ICPU } from './cpu';
+
+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);
+ cpu.data[95] &= 0x7f; // clear global interrupt flag
+ cpu.cycles += 2;
+ cpu.pc = addr;
+}