diff --git a/README.md b/README.md index 6fad769..0704893 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,11 @@ To be decided, but at this moment this code is open source and free to use for n ## Changelog +### 0.3.7 + +* Added 4 bit display! Currently shows hex format +* Fixed a bug with flip flop save states for connections + ### 0.3.6 * Fixed a bug where flip flops weren't firing output changes when only !Q changed. diff --git a/js/elements.js b/js/elements.js index 1766427..c485dc4 100644 --- a/js/elements.js +++ b/js/elements.js @@ -1,11 +1,13 @@ let ElementReferenceTable = new Array(); let ElementCategory_Inputs = new ElementCatalog_Category("Inputs",""); +let ElementCategory_Outputs = new ElementCatalog_Category("Outputs",""); let ElementCategory_LOGIC = new ElementCatalog_Category("Logic" ,""); let ElementCategory_FlipFlop = new ElementCatalog_Category("Flip-Flops" ,""); let ElementCategory_Timing = new ElementCatalog_Category("Timing" ,""); let ElementCategory_ICs = new ElementCatalog_Category("ICs" ,""); let elementCatalog = new ElementCatalog([ElementCategory_Inputs, + ElementCategory_Outputs, ElementCategory_LOGIC, ElementCategory_FlipFlop, ElementCategory_Timing, @@ -1067,6 +1069,59 @@ let ElementCatalog_DELAY = new ElementCatalog_Element("Delay","The delay element ElementReferenceTable.push(ElementCatalog_DELAY); ElementCategory_Timing.addElement(ElementCatalog_DELAY); +class output4bitDisplay extends Element { + constructor(RestoreData = null,logicengine) { + super(RestoreData,logicengine,4); + this.Name = "4B Display"; + this.Output = false; + this.OutputChar = "0"; + this.NoOutput = true; + this.Width = 100; + this.Height = 100; + this.Inputs = [0,0,0,0]; + this.removeProperty("Inputs"); + } + + setInput(Input, Value) { + this.Inputs[Input] = (Value) ? 1 : 0; + let outchar = (this.Inputs[0] << 3) + (this.Inputs[1] << 2) + (this.Inputs[2] << 1) + (this.Inputs[3]); + + this.OutputChar = (outchar); + switch (outchar) { + case 10: + this.OutputChar = 'A'; + break; + case 11: + this.OutputChar = 'B'; + break; + case 12: + this.OutputChar = 'C'; + break; + case 13: + this.OutputChar = 'D'; + break; + case 14: + this.OutputChar = 'E'; + break; + case 15: + this.OutputChar = 'F'; + break; + } + + } + + drawElement(x, y, ctx) { + this.drawBorderBox(ctx, x+20,y,this.Width-40,this.Height); + this.drawTextCentered(ctx,x,y,this.Width,this.Height,this.OutputChar,"72px Console"); + this.drawInputs(ctx,x,y); + } +} + +let ElementCatalog_Output_4BDisplay = new ElementCatalog_Element("4B Display","A display! Takes a 4 bit input and shows hex value of the input.","[8]",output4bitDisplay,[]); +ElementReferenceTable.push(ElementCatalog_Output_4BDisplay); +ElementCategory_Outputs.addElement(ElementCatalog_Output_4BDisplay); + + class inputElement extends Element { constructor(RestoreData = null,logicengine) { super(RestoreData,logicengine,0); @@ -1179,14 +1234,14 @@ class FlipFlopJK extends Element { this.Height = 80; if (RestoreData) { - this.Outputs = RestoreData.Outputs; + this.Outputs = RestoreData.OutputStates; } } toJSON(key) { let $superjson = super.toJSON(key); - $superjson.Outputs = this.Outputs; + $superjson.OutputStates = this.Outputs; return $superjson; } @@ -1241,14 +1296,14 @@ class FlipFlopSR extends Element { this.Height = 80; if (RestoreData) { - this.Outputs = RestoreData.Outputs; + this.Outputs = RestoreData.OutputStates; } } toJSON(key) { let $superjson = super.toJSON(key); - $superjson.Outputs = this.Outputs; + $superjson.OutputStates = this.Outputs; return $superjson; } @@ -1299,14 +1354,14 @@ class FlipFlopT extends Element { this.Height = 80; if (RestoreData) { - this.Outputs = RestoreData.Outputs; + this.Outputs = RestoreData.OutputStates; } } toJSON(key) { let $superjson = super.toJSON(key); - $superjson.Outputs = this.Outputs; + $superjson.OutputStates = this.Outputs; return $superjson; } @@ -1350,14 +1405,14 @@ class FlipFlopD extends Element { this.Height = 80; if (RestoreData) { - this.Outputs = RestoreData.Outputs; + this.Outputs = RestoreData.OutputStates; } } toJSON(key) { let $superjson = super.toJSON(key); - $superjson.Outputs = this.Outputs; + $superjson.OutputStates = this.Outputs; return $superjson; } diff --git a/js/main.js b/js/main.js index facb955..a6ffbb8 100644 --- a/js/main.js +++ b/js/main.js @@ -2,7 +2,7 @@ MatCat BrowserLogic Simulator */ -let Version = "0.3.6"; +let Version = "0.3.7"; let spanVersion = document.getElementById("version"); spanVersion.innerText = Version; // get the canvas and get the engine object going