From 193227bc7f99509205ff1e58ba93bd76d767a020 Mon Sep 17 00:00:00 2001 From: Kristian Kraljic Date: Wed, 4 Mar 2020 20:43:17 +0100 Subject: [PATCH] Fixed ALU74181 --- CHANGELOG.md | 4 + pom.xml | 2 +- .../jds/components/buildin/alu/ALU74181.java | 116 +++++++++--------- src/main/java/lc/kra/jds/gui/Application.java | 4 +- 4 files changed, 67 insertions(+), 59 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e99cb0..9153689 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.0.3 (20120-03-04) +### Fixed + - Fixed the (very buggy) 74181 ALU, thanks to Frank Möbius + ## 2.0.2 (2017-05-31) ### Added - Added support to load JDigitalSimulator simulations stored with version 1.* diff --git a/pom.xml b/pom.xml index 106a43d..72d4fbc 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ lc.kra.jds jds - 2.0.2 + 2.0.3 JDigitalSimulator http://kra.lc/projects/jdigitalsimulator/ diff --git a/src/main/java/lc/kra/jds/components/buildin/alu/ALU74181.java b/src/main/java/lc/kra/jds/components/buildin/alu/ALU74181.java index fca1517..0b88f64 100644 --- a/src/main/java/lc/kra/jds/components/buildin/alu/ALU74181.java +++ b/src/main/java/lc/kra/jds/components/buildin/alu/ALU74181.java @@ -53,7 +53,7 @@ public class ALU74181 extends Component implements Sociable { private Dimension size; private InputContact[] inputs, inputsA, inputsB, inputsS; - private transient boolean m, cn, a[], b[], s[], f[]; + private transient boolean m, nc, a[], b[], s[], f[]; private OutputContact[] outputs, outputsF; private Contact[] contacts; @@ -108,16 +108,21 @@ public ALU74181() { graphics.setFont(graphics.getFont().deriveFont(8f)); graphics.drawString("M", 10, 56); graphics.drawString("Cn", 10, 64); + graphics.drawString("\u00af", size.width-14, 19); graphics.drawString("P", size.width-14, 20); - graphics.drawString("G", size.width-14, 28); + graphics.drawString("\u00af", size.width-14, 28); + graphics.drawString("G", size.width-14, 29); graphics.drawString("Cn+4", size.width-28, 46); graphics.drawString("A=B", size.width-24, 64); for(int number=0;number<=3;number++) { int top = 75+number*20; graphics.drawRect(5, top, size.width-10, 20); - graphics.drawString("A"+number, 11, top+8); + graphics.drawString("\u00af", 11, top+9); + graphics.drawString("A"+number, 11, top+9); + graphics.drawString("\u00af", 11, top+17); graphics.drawString("B"+number, 11, top+18); graphics.drawString("S"+number, 10, 12+number*10); + graphics.drawString("\u00af", size.width-18, top+12); graphics.drawString("F"+number, size.width-18, top+13); } ContactUtilities.paintSolderingJoints(graphics, contacts); @@ -126,58 +131,57 @@ public ALU74181() { @Override public Dimension getSize() { return size; } @Override public Contact[] getContacts() { return contacts; } @Override public void calculate() { - boolean h[] = new boolean[8], m=!inputs[0].isCharged(), cn=inputs[1].isCharged(); - boolean c = m!=this.m|cn!=this.cn; this.m = m; this.cn = cn; + boolean h[] = new boolean[8], nm=!inputs[0].isCharged(), cn=inputs[1].isCharged(); + + /* first check if there was any change to the inputs, reduces calculation! */ + boolean c = nm!=this.m|cn!=this.nc; this.m = nm; this.nc = cn; for(int i=0;i<4;i++) { - boolean a = !inputsA[i].isCharged(); if(a!=this.a[i]) { this.a[i] = a; c = true; } - boolean b = !inputsB[i].isCharged(); if(b!=this.b[i]) { this.b[i] = b; c = true; } - boolean s = inputsS[i].isCharged(); if(s!=this.s[i]) { this.s[i] = s; c = true; } - } if(!c) return; //no change - - h[0] = !(( b[3]& s[3]& a[3])| - ( a[3]& s[2]&!b[3])); - h[1] = !((!b[3]& s[1])| - ( s[0]& b[3])| - ( a[3])); - - h[2] = !(( b[2]& s[3]& a[2])| - ( a[2]& s[2]&!b[2])); - h[3] = !((!b[2]& s[1])| - ( s[0]& b[2])| - ( a[2])); - - h[4] = !(( b[1]& s[3]& a[1])| - ( a[1]& s[2]&!b[1])); - h[5] = !((!b[1]& s[1])| - ( s[0]& b[1])| - ( a[1])); - - h[6] = !(( b[0]& s[3]& a[0])| - ( a[0]& s[2]&!b[0])); - h[7] = !((!b[0]& s[1])| - ( s[0]& b[0])| - ( a[0])); - - f[0] = ((h[6]^h[7])^ - (!(m&cn))); - f[1] = ((h[4]^h[5])^ - (!((cn&h[6]&m)|(h[7]&m)))); - f[2] = ((h[2]^h[3])^ - (!((h[4]&h[6]&cn&m)|(h[4]&h[7]&m)|(h[5]&m)))); - f[3] = ((h[0]^h[1])^ - (!((h[2]&h[4]&h[6]&cn&m)|(h[2]&h[4]&h[7]&m)|(h[2]&h[5]&m)|(h[3]&m)))); - outputsF[0].setCharged(!f[0]); //F1 (instead of ^F1) - outputsF[1].setCharged(!f[1]); //F2 (instead of ^F2) - outputsF[2].setCharged(!f[2]); //F3 (instead of ^F3) - outputsF[3].setCharged(!f[3]); //F4 (instead of ^F4) - - outputs[0].setCharged(!(h[0]&h[2]&h[4]&h[6])); //P (instead of ^P) - boolean g = !((h[1])| - (h[0]&h[2])| - (h[0]&h[2]&h[5])| - (h[0]&h[2]&h[4]&h[7])); - outputs[1].setCharged(!g); //G (instead of ^G) - outputs[2].setCharged(((!g)|(h[0]&h[2]&h[4]&h[6]&cn))); //Cn+4 + boolean a = inputsA[i].isCharged(); if(a!=this.a[i]) { this.a[i] = a; c = true; } + boolean b = inputsB[i].isCharged(); if(b!=this.b[i]) { this.b[i] = b; c = true; } + boolean s = inputsS[i].isCharged(); if(s!=this.s[i]) { this.s[i] = s; c = true; } + } //if(!c) return; // no change + + h[0] = !( ( b[3]& s[3] & a[3]) | + ( a[3]& s[2] &!b[3]) ); + h[1] = !( (!b[3]& s[1]) | + ( s[0]& b[3]) | + ( a[3]) ); + + h[2] = !( ( b[2]& s[3]& a[2]) | + ( a[2]& s[2]&!b[2]) ); + h[3] = !( (!b[2]& s[1]) | + ( s[0]& b[2]) | + ( a[2]) ); + + h[4] = !( ( b[1]& s[3]& a[1]) | + ( a[1]& s[2]&!b[1]) ); + h[5] = !( (!b[1]& s[1]) | + ( s[0]& b[1]) | + ( a[1]) ); + + h[6] = !( ( b[0]& s[3]& a[0]) | + ( a[0]& s[2]&!b[0]) ); + h[7] = !( (!b[0]& s[1]) | + ( s[0]& b[0]) | + ( a[0]) ); + + f[0] = ( h[6]&!h[7]) ^ + (!(nm&cn)); + f[1] = ( h[4]&!h[5]) ^ + (!((cn&h[6]&nm)|(h[7]&nm)) ); + f[2] = ( h[2]&!h[3]) ^ + (!( (h[4]&h[6]&cn&nm) | (h[4]&h[7]&nm) | (h[5]&nm) ) ); + f[3] = ( (h[0]&!h[1]) ^ + (!( (h[2]&h[4]&h[6]&cn&nm) | (h[2]&h[4]&h[7]&nm) | (h[2]&h[5]&nm) | (h[3]&nm)))); + outputsF[0].setCharged(f[0]); + outputsF[1].setCharged(f[1]); + outputsF[2].setCharged(f[2]); + outputsF[3].setCharged(f[3]); + + outputs[0].setCharged((h[0]&h[2]&h[4]&h[6])); //^P + boolean g = ((h[1]) | (h[0]&h[3]) | (h[0]&h[2]&h[5]) | (h[0]&h[2]&h[4]&h[7])); + outputs[1].setCharged(g); //^G + outputs[2].setCharged(((!g)|(!(h[0]&h[2]&h[4]&h[6]&cn)))); //Cn+4 outputs[3].setCharged(f[0]&f[1]&f[2]&f[3]); //A=B } @@ -189,14 +193,14 @@ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundE private void makeShape() { shape = new Polygon(new int[]{9 , 9 , 5 , 5, size.width-5, size.width-5, size.width-9, size.width-9}, - new int[]{75, 70, 70, 0, 0 , 70 , 70 , 75 }, 8); + new int[]{75, 70, 70, 0, 0, 70, 70, 75}, 8); } protected void setContactLocations() { inputs[0].setLocation(new Point(0, 52)); //M inputs[1].setLocation(new Point(0, 60)); //Cn outputs[0].setLocation(new Point(size.width, 17)); //P - outputs[1].setLocation(new Point(size.width, 25)); //G + outputs[1].setLocation(new Point(size.width, 26)); //G outputs[2].setLocation(new Point(size.width, 43)); //Cn+4 outputs[3].setLocation(new Point(size.width, 61)); //A=B for(int number=0;number<4;number++) { diff --git a/src/main/java/lc/kra/jds/gui/Application.java b/src/main/java/lc/kra/jds/gui/Application.java index 7ae0424..fb719fc 100644 --- a/src/main/java/lc/kra/jds/gui/Application.java +++ b/src/main/java/lc/kra/jds/gui/Application.java @@ -140,7 +140,7 @@ /** * JDigitalSimulator * @author Kristian Kraljic - * @version 2.0.2 + * @version 2.0.3 */ public class Application extends JFrame { private static final long serialVersionUID = -4693271310855486553L; @@ -148,7 +148,7 @@ public class Application extends JFrame { public static final String FILE_EXTENSION = "jdsim"; public static File pluginDirectory, currentDirectory; - private static final String VERSION = "2.0.2", COPYRIGHT = "2010-2017", LINES_OF_CODE = "9.509", WORDS_OF_CODE = "36.133", PAGES_OF_CODE = "245"; + private static final String VERSION = "2.0.3", COPYRIGHT = "2010-2020", LINES_OF_CODE = "9.509", WORDS_OF_CODE = "36.133", PAGES_OF_CODE = "245"; private static final String[] TOOLBAR_FRAME_FOCUS = new String[]{"save", "print", "print_level", "simulate", "left", "right", "up", "down", "grid", "secure", "zoom_default", "zoom", "zoom_in", "zoom_out"},