Skip to content

Commit

Permalink
Fixed ALU74181
Browse files Browse the repository at this point in the history
  • Loading branch information
kristian committed Mar 4, 2020
1 parent 2bf35d0 commit 193227b
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 59 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.*
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>lc.kra.jds</groupId>
<artifactId>jds</artifactId>
<version>2.0.2</version>
<version>2.0.3</version>

<name>JDigitalSimulator</name>
<url>http://kra.lc/projects/jdigitalsimulator/</url>
Expand Down
116 changes: 60 additions & 56 deletions src/main/java/lc/kra/jds/components/buildin/alu/ALU74181.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand All @@ -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
}

Expand All @@ -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++) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/lc/kra/jds/gui/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,15 @@
/**
* JDigitalSimulator
* @author Kristian Kraljic
* @version 2.0.2
* @version 2.0.3
*/
public class Application extends JFrame {
private static final long serialVersionUID = -4693271310855486553L;

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"},
Expand Down

0 comments on commit 193227b

Please sign in to comment.