aboutsummaryrefslogtreecommitdiff
path: root/src/cpu
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/cpu/cpu.ts11
-rw-r--r--src/cpu/instruction.ts2
2 files changed, 12 insertions, 1 deletions
diff --git a/src/cpu/cpu.ts b/src/cpu/cpu.ts
index de5b294..7a518b8 100644
--- a/src/cpu/cpu.ts
+++ b/src/cpu/cpu.ts
@@ -35,6 +35,7 @@ export interface ICPU {
readData(addr: u16): u8;
writeData(addr: u16, value: u8, mask?: u8): void;
+ onWatchdogReset(): void;
}
export type CPUMemoryHook = (value: u8, oldValue: u8, addr: u16, mask: u8) => boolean | void;
@@ -80,6 +81,14 @@ export class CPU implements ICPU {
readonly gpioPorts = new Set<AVRIOPort>();
readonly gpioByPort: AVRIOPort[] = [];
+ /**
+ * This function is called by the WDR instruction. The Watchdog peripheral attaches
+ * to it to listen for WDR (watchdog reset).
+ */
+ onWatchdogReset = () => {
+ /* empty by default */
+ };
+
pc: u32 = 0;
cycles: u32 = 0;
nextInterrupt: i16 = -1;
@@ -91,8 +100,10 @@ export class CPU implements ICPU {
reset() {
this.data.fill(0);
this.SP = this.data.length - 1;
+ this.pc = 0;
this.pendingInterrupts.splice(0, this.pendingInterrupts.length);
this.nextInterrupt = -1;
+ this.nextClockEvent = null;
}
readData(addr: number) {
diff --git a/src/cpu/instruction.ts b/src/cpu/instruction.ts
index c3cdb92..9937ec9 100644
--- a/src/cpu/instruction.ts
+++ b/src/cpu/instruction.ts
@@ -783,7 +783,7 @@ export function avrInstruction(cpu: ICPU) {
cpu.data[d] = ((15 & i) << 4) | ((240 & i) >>> 4);
} else if (opcode === 0x95a8) {
/* WDR, 1001 0101 1010 1000 */
- /* not implemented */
+ cpu.onWatchdogReset();
} else if ((opcode & 0xfe0f) === 0x9204) {
/* XCH, 1001 001r rrrr 0100 */
const r = (opcode & 0x1f0) >> 4;