aboutsummaryrefslogtreecommitdiff
path: root/src/interrupt.ts
blob: d833a3ababca35018f512998839e5e0fbcfb4295 (plain)
1
2
3
4
5
6
7
8
9
10
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;
}