From b408b10cd029f0fe1418b231096bac82ddc73903 Mon Sep 17 00:00:00 2001 From: darkress <30271678+darkressx@users.noreply.github.com> Date: Sat, 17 Jun 2023 22:52:03 +0200 Subject: [PATCH] implemented Clrwdt Instruction (#34) Co-authored-by: Darkress <30271678+DarkressX@users.noreply.github.com> Reviewed-on: https://git.darkress.xyz/darkress/pic16f84-sim/pulls/34 --- de/darkress/pic16f84sim/commands/Clrwdt.java | 24 +++++++++++++++++++ .../pic16f84sim/decoder/CommandDecoder.java | 2 +- .../pic16f84sim/microcontroller/Watchdog.java | 4 ++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 de/darkress/pic16f84sim/commands/Clrwdt.java diff --git a/de/darkress/pic16f84sim/commands/Clrwdt.java b/de/darkress/pic16f84sim/commands/Clrwdt.java new file mode 100644 index 0000000..7f3482e --- /dev/null +++ b/de/darkress/pic16f84sim/commands/Clrwdt.java @@ -0,0 +1,24 @@ +package de.darkress.pic16f84sim.commands; + +import de.darkress.pic16f84sim.microcontroller.*; + +public class Clrwdt extends LiteralCommandUtils implements Command +{ + + public Clrwdt() + { + } + + @Override + public void execute() + { + ProgramCounter.incPC(); + Cycles.incCycles(); + + Memory.setRegister(0x03, Memory.getRegister(0x03) | 0x18); + if(Timer.getPrescalerAssignment()) { + Timer.resetTimeToTimerIncrease(); + Watchdog.resetWatchdogTimer(); + } + } +} diff --git a/de/darkress/pic16f84sim/decoder/CommandDecoder.java b/de/darkress/pic16f84sim/decoder/CommandDecoder.java index 10eea94..0d480d0 100644 --- a/de/darkress/pic16f84sim/decoder/CommandDecoder.java +++ b/de/darkress/pic16f84sim/decoder/CommandDecoder.java @@ -97,7 +97,7 @@ public class CommandDecoder if (input == 0x0064) { - //clrwdt(); + return new Clrwdt(); } if (input == 0x0009) diff --git a/de/darkress/pic16f84sim/microcontroller/Watchdog.java b/de/darkress/pic16f84sim/microcontroller/Watchdog.java index a3db386..ea0b81f 100644 --- a/de/darkress/pic16f84sim/microcontroller/Watchdog.java +++ b/de/darkress/pic16f84sim/microcontroller/Watchdog.java @@ -8,6 +8,10 @@ public class Watchdog return watchdogTimer; } + public static void resetWatchdogTimer() { + watchdogTimer = 18000; + } + public static void decreaseWatchdogTimer() { watchdogTimer--;