From c6b5e3989eafab32a64f64f96be3574c8ae97645 Mon Sep 17 00:00:00 2001 From: Darkress <30271678+DarkressX@users.noreply.github.com> Date: Wed, 7 Jun 2023 21:30:49 +0200 Subject: [PATCH] implemented btfsc Instruction --- de/darkress/pic16f84sim/Main.java | 2 +- de/darkress/pic16f84sim/commands/Btfsc.java | 29 +++++++++++++++++++ .../pic16f84sim/decoder/CommandDecoder.java | 3 +- 3 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 de/darkress/pic16f84sim/commands/Btfsc.java diff --git a/de/darkress/pic16f84sim/Main.java b/de/darkress/pic16f84sim/Main.java index d322631..4a6bda6 100644 --- a/de/darkress/pic16f84sim/Main.java +++ b/de/darkress/pic16f84sim/Main.java @@ -14,7 +14,7 @@ class Main ArrayList program = new ArrayList<>(); Memory.workingRegister = 0x01; Memory.setRegister(0x14, 0xA5); //240 << 224 - program.add(CommandDecoder.decode(0x1594)); + program.add(CommandDecoder.decode(0x1894)); for(int i = 0; i < program.size(); i++) { program.get(ProgramCounter.getPc()).execute(); diff --git a/de/darkress/pic16f84sim/commands/Btfsc.java b/de/darkress/pic16f84sim/commands/Btfsc.java new file mode 100644 index 0000000..4746384 --- /dev/null +++ b/de/darkress/pic16f84sim/commands/Btfsc.java @@ -0,0 +1,29 @@ +package de.darkress.pic16f84sim.commands; + +import de.darkress.pic16f84sim.microcontroller.Memory; +import de.darkress.pic16f84sim.microcontroller.ProgramCounter; + +public class Btfsc extends BitOrientedCommandUtils implements Command +{ + private final int address; + private int bitPlacement; + + public Btfsc(int input) + { + address = input & 0x007F; + bitPlacement = checkBitPlacement(input); + } + + @Override + public void execute() + { + int result = Memory.getRegister(address); + + if((result & (1 << bitPlacement)) == 0) //Test if bit is clear + { + ProgramCounter.incPC(); + } + + ProgramCounter.incPC(); + } +} diff --git a/de/darkress/pic16f84sim/decoder/CommandDecoder.java b/de/darkress/pic16f84sim/decoder/CommandDecoder.java index c1f13c4..816df2e 100644 --- a/de/darkress/pic16f84sim/decoder/CommandDecoder.java +++ b/de/darkress/pic16f84sim/decoder/CommandDecoder.java @@ -61,8 +61,7 @@ public class CommandDecoder case 0x1400: return new Bsf(input); case 0x1800: - //btfsc(); - break; + return new Btfsc(input); case 0x1C00: //btfss(); break;