0.4.11: Copy and Paste, added PRE and CLR (active low) inputs to flipflops

This commit is contained in:
MatCat 2021-03-13 20:47:22 -08:00
parent 7d0807d30c
commit d04fc3bb91
3 changed files with 50 additions and 14 deletions

View File

@ -16,7 +16,8 @@ LZ-String, Copyright 2013 pieroxy under MIT license https://github.com/pieroxy/l
### 0.4.11
* Copy and Paste
* Copy and Paste, note that Paste in the menu may not work on some browsers because of security permissions, but standard keyboard shortcuts will work.
* Added !PRE and !CLR to flipflops, these are ACTIVE LOW inputs so you must make them high to use the flipflop.
### 0.4.10

View File

@ -1,12 +1,12 @@
class FlipFlopJK extends Element {
constructor(_Container, RestoreData = null, logicengine) {
super(_Container, RestoreData,logicengine,3);
super(_Container, RestoreData,logicengine,5);
this.Name = "JK-FF";
this.Outputs = new Array(2);
this.InputLabels = new Array("J","CLK","K");
this.InputLabels = new Array("J","CLK","K","!PRE", "!CLR");
this.OutputLabels = new Array("Q","~Q");
this.removeProperty("Inputs");
this.Height = 80;
this.Height = 140;
if (RestoreData) {
this.Outputs = RestoreData.OutputStates;
@ -43,6 +43,14 @@ class FlipFlopJK extends Element {
this.Outputs[1] = !this.Outputs[0];
}
}
if (!this.Inputs[3]) {
this.Outputs[0] = true;
this.Outputs[1] = false;
}
if (!this.Inputs[4]) {
this.Outputs[0] = false;
this.Outputs[1] = true;
}
if (oldOutput != this.getOutput(0) || oldOutput2 != this.getOutput(1)) {
this.setConnections();
}
@ -71,13 +79,13 @@ ElementCategory_FlipFlop.addElement(ElementCatalog_JKFlipFlop);
class FlipFlopSR extends Element {
constructor(_Container, RestoreData = null, logicengine) {
super(_Container, RestoreData,logicengine,3);
super(_Container, RestoreData,logicengine,5);
this.Name = "SR-FF";
this.Outputs = new Array(2);
this.InputLabels = new Array("S","CLK","R");
this.InputLabels = new Array("S","CLK","R","!PRE", "!CLR");
this.OutputLabels = new Array("Q","~Q");
this.removeProperty("Inputs");
this.Height = 80;
this.Height = 140;
if (RestoreData) {
this.Outputs = RestoreData.OutputStates;
@ -111,6 +119,15 @@ class FlipFlopSR extends Element {
this.Outputs[1] = false;
}
}
if (!this.Inputs[3]) {
this.Outputs[0] = true;
this.Outputs[1] = false;
}
if (!this.Inputs[4]) {
this.Outputs[0] = false;
this.Outputs[1] = true;
}
if (oldOutput != this.getOutput(0) || oldOutput2 != this.getOutput(1)) {
this.setConnections();
}
@ -139,13 +156,13 @@ ElementCategory_FlipFlop.addElement(ElementCatalog_SRFlipFlop);
class FlipFlopT extends Element {
constructor(_Container, RestoreData = null, logicengine) {
super(_Container, RestoreData,logicengine,2);
super(_Container, RestoreData,logicengine,4);
this.Name = "T-FF";
this.Outputs = new Array(2);
this.InputLabels = new Array("T","CLK");
this.InputLabels = new Array("T","CLK","!PRE","!CLR");
this.OutputLabels = new Array("Q","~Q");
this.removeProperty("Inputs");
this.Height = 80;
this.Height = 120;
if (RestoreData) {
this.Outputs = RestoreData.OutputStates;
@ -172,6 +189,16 @@ class FlipFlopT extends Element {
this.Outputs[0] = !this.Outputs[0];
this.Outputs[1] = !this.Outputs[0];
}
if (!this.Inputs[2]) {
this.Outputs[0] = true;
this.Outputs[1] = false;
}
if (!this.Inputs[3]) {
this.Outputs[0] = false;
this.Outputs[1] = true;
}
if (oldOutput != this.getOutput(0) || oldOutput2 != this.getOutput(1)) {
this.setConnections();
}
@ -200,13 +227,13 @@ ElementCategory_FlipFlop.addElement(ElementCatalog_TFlipFlop);
class FlipFlopD extends Element {
constructor(_Container, RestoreData = null, logicengine) {
super(_Container, RestoreData,logicengine,2);
super(_Container, RestoreData,logicengine,4);
this.Name = "D-FF";
this.Outputs = new Array(2);
this.InputLabels = new Array("D","CLK");
this.InputLabels = new Array("D","CLK","!PRE","!CLR");
this.OutputLabels = new Array("Q","~Q");
this.removeProperty("Inputs");
this.Height = 80;
this.Height = 120;
if (RestoreData) {
this.Outputs = RestoreData.OutputStates;
@ -234,6 +261,14 @@ class FlipFlopD extends Element {
this.Outputs[0] = this.Inputs[0];
this.Outputs[1] = !this.Outputs[0];
}
if (!this.Inputs[2]) {
this.Outputs[0] = true;
this.Outputs[1] = false;
}
if (!this.Inputs[3]) {
this.Outputs[0] = false;
this.Outputs[1] = true;
}
if (oldOutput != this.getOutput(0) || oldOutput2 != this.getOutput(1)) {
this.setConnections();
}

View File

@ -260,7 +260,7 @@ class LogicEngine {
}
Mouse_Down(evt) {
if (evt.which === 1) {
if (evt.which === 1 && !this.MultiSelectStart.InProgress) {
let mousePos = getMousePos(this.Canvas, evt);
this.MouseDownTime = performance.now();
let element = this.ActiveContainer.checkMouseBounds(mousePos);