From fa89faa979bfd131219695b7a94c45d5a2ead183 Mon Sep 17 00:00:00 2001 From: darkress <30271678+darkressx@users.noreply.github.com> Date: Wed, 7 Jun 2023 20:50:48 +0200 Subject: [PATCH] implemented bcfInstruction (#25) Co-authored-by: Darkress <30271678+DarkressX@users.noreply.github.com> Reviewed-on: https://git.darkress.xyz/darkress/pic16f84-sim/pulls/25 --- de/darkress/pic16f84sim/Main.java | 2 +- de/darkress/pic16f84sim/commands/Bcf.java | 26 +++++++++++++++++++ .../commands/BitOrientedCommandUtils.java | 11 ++++++++ .../pic16f84sim/decoder/CommandDecoder.java | 3 +-- 4 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 de/darkress/pic16f84sim/commands/Bcf.java create mode 100644 de/darkress/pic16f84sim/commands/BitOrientedCommandUtils.java diff --git a/de/darkress/pic16f84sim/Main.java b/de/darkress/pic16f84sim/Main.java index 74f4780..a9df39d 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(0x0694)); + program.add(CommandDecoder.decode(0x1114)); for(int i = 0; i < program.size(); i++) { program.get(ProgramCounter.getPc()).execute(); diff --git a/de/darkress/pic16f84sim/commands/Bcf.java b/de/darkress/pic16f84sim/commands/Bcf.java new file mode 100644 index 0000000..9d30604 --- /dev/null +++ b/de/darkress/pic16f84sim/commands/Bcf.java @@ -0,0 +1,26 @@ +package de.darkress.pic16f84sim.commands; + +import de.darkress.pic16f84sim.microcontroller.Memory; +import de.darkress.pic16f84sim.microcontroller.ProgramCounter; + +public class Bcf extends BitOrientedCommandUtils implements Command +{ + private final int address; + private int bitPlacement; + + public Bcf(int input) + { + address = input & 0x007F; + bitPlacement = checkBitPlacement(input); + } + + @Override + public void execute() + { + int result = Memory.getRegister(address); + result &= ~(1 << bitPlacement); //Mask n-th bit with 0 + + Memory.setRegister(address, result); + ProgramCounter.incPC(); + } +} diff --git a/de/darkress/pic16f84sim/commands/BitOrientedCommandUtils.java b/de/darkress/pic16f84sim/commands/BitOrientedCommandUtils.java new file mode 100644 index 0000000..d0b0443 --- /dev/null +++ b/de/darkress/pic16f84sim/commands/BitOrientedCommandUtils.java @@ -0,0 +1,11 @@ +package de.darkress.pic16f84sim.commands; + +import de.darkress.pic16f84sim.microcontroller.Memory; + +public class BitOrientedCommandUtils +{ + protected int checkBitPlacement(int input) + { + return ((input & 0x0380) >>7); + } +} diff --git a/de/darkress/pic16f84sim/decoder/CommandDecoder.java b/de/darkress/pic16f84sim/decoder/CommandDecoder.java index 9c2bf34..fa59768 100644 --- a/de/darkress/pic16f84sim/decoder/CommandDecoder.java +++ b/de/darkress/pic16f84sim/decoder/CommandDecoder.java @@ -57,8 +57,7 @@ public class CommandDecoder switch(input & 0x3C00) { case 0x1000: - //bcf(); - break; + return new Bcf(input); case 0x1400: //bsf(); break;