Permalink
Browse files

Added inverse RS Nand, and JK Flip Flop.

  • Loading branch information...
me4502 committed Jun 29, 2017
1 parent b30c5b4 commit 43b855f2490b3b8f3e0a6d4d22f4064618dff06b
@@ -27,7 +27,9 @@
import com.sk89q.craftbook.sponge.mechanics.ics.chips.logic.FullSubtractor;
import com.sk89q.craftbook.sponge.mechanics.ics.chips.logic.HalfAdder;
import com.sk89q.craftbook.sponge.mechanics.ics.chips.logic.HalfSubtractor;
import com.sk89q.craftbook.sponge.mechanics.ics.chips.logic.InvertedRSNandLatch;
import com.sk89q.craftbook.sponge.mechanics.ics.chips.logic.Inverter;
import com.sk89q.craftbook.sponge.mechanics.ics.chips.logic.JKFlipFlop;
import com.sk89q.craftbook.sponge.mechanics.ics.chips.logic.LevelTriggerDFlipFlop;
import com.sk89q.craftbook.sponge.mechanics.ics.chips.logic.MemoryAccess;
import com.sk89q.craftbook.sponge.mechanics.ics.chips.logic.MemorySetter;
@@ -97,7 +99,8 @@
registerICType(new ICType<>("MC3021", "XNOR", "Xnor Gate", "Outputs high if the inputs are the same", new XnorGate.Factory(), "3ISO"));
registerICType(new ICType<>("MC3030", "RS-NOR", "RS-Nor Latch", "A compact RS-Nor Latch", new RSNorLatch.Factory(), "3ISO"));
registerICType(new ICType<>("MC3031", "INV RS-NAND", "Inverse RS-Nand Latch", "A compact Inverse RS-Nand Latch", new InvertedRSNandLatch.Factory(), "3ISO"));
registerICType(new ICType<>("MC3032", "JK FLIP", "JK Flip Flip", "A compact JK Flip Flop", new JKFlipFlop.Factory(), "3ISO"));
registerICType(new ICType<>("MC3033", "RS-NAND", "RS-Nand Latch", "A compact RS-Nand Latch", new RSNandLatch.Factory(), "3ISO"));
registerICType(new ICType<>("MC3034", "EDGE-D", "Edge-Trigger D Flip Flop", "A compact Edge-D Flip Flop", new EdgeTriggerDFlipFlop.Factory(), "3ISO"));
registerICType(new ICType<>("MC3036", "LEVEL-D", "Level-Trigger D Flip Flop", "A compact Level-D Flip Flop", new LevelTriggerDFlipFlop.Factory(), "3ISO"));
@@ -0,0 +1,71 @@
/*
* CraftBook Copyright (C) 2010-2017 sk89q <http://www.sk89q.com>
* CraftBook Copyright (C) 2011-2017 me4502 <http://www.me4502.com>
* CraftBook Copyright (C) Contributors
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
* License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not,
* see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.craftbook.sponge.mechanics.ics.chips.logic;
import com.sk89q.craftbook.sponge.mechanics.ics.IC;
import com.sk89q.craftbook.sponge.mechanics.ics.factory.ICFactory;
import org.spongepowered.api.world.Location;
import org.spongepowered.api.world.World;
public class InvertedRSNandLatch extends IC {
public InvertedRSNandLatch(InvertedRSNandLatch.Factory factory, Location<World> location) {
super(factory, location);
}
@Override
public void trigger() {
boolean set = !getPinSet().getInput(0, this);
boolean reset = !getPinSet().getInput(1, this);
if (!set && !reset) {
getPinSet().setOutput(0, true, this);
} else if (set && !reset) {
getPinSet().setOutput(0, false, this);
} else if (!set) {
getPinSet().setOutput(0, true, this);
}
}
public static class Factory implements ICFactory<InvertedRSNandLatch> {
@Override
public InvertedRSNandLatch createInstance(Location<World> location) {
return new InvertedRSNandLatch(this, location);
}
@Override
public String[] getLineHelp() {
return new String[] {
"",
""
};
}
@Override
public String[][] getPinHelp() {
return new String[][] {
new String[] {
"Set",
"Reset"
},
new String[] {
"Q"
}
};
}
}
}
@@ -0,0 +1,66 @@
/*
* CraftBook Copyright (C) 2010-2017 sk89q <http://www.sk89q.com>
* CraftBook Copyright (C) 2011-2017 me4502 <http://www.me4502.com>
* CraftBook Copyright (C) Contributors
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
* License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not,
* see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.craftbook.sponge.mechanics.ics.chips.logic;
import com.sk89q.craftbook.sponge.mechanics.ics.IC;
import com.sk89q.craftbook.sponge.mechanics.ics.factory.ICFactory;
import org.spongepowered.api.world.Location;
import org.spongepowered.api.world.World;
public class JKFlipFlop extends IC {
public JKFlipFlop(JKFlipFlop.Factory factory, Location<World> location) {
super(factory, location);
}
@Override
public void trigger() {
boolean j = getPinSet().getInput(1, this); // Set
boolean k = getPinSet().getInput(2, this); // Reset
if (getPinSet().isTriggered(0, this) && !getPinSet().getInput(0, this)) {
if (j && k) {
getPinSet().setOutput(0, !getPinSet().getOutput(0, this), this);
} else if (j) {
getPinSet().setOutput(0, true, this);
} else if (k) {
getPinSet().setOutput(0, false, this);
}
}
}
public static class Factory implements ICFactory<JKFlipFlop> {
@Override
public JKFlipFlop createInstance(Location<World> location) {
return new JKFlipFlop(this, location);
}
@Override
public String[][] getPinHelp() {
return new String[][] {
new String[] {
"Trigger",
"Set",
"Reset"
},
new String[] {
"Output"
}
};
}
}
}

0 comments on commit 43b855f

Please sign in to comment.