home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1997 October / PCO1097.ISO / FilesBBS / FREI / DIGSIM.EXE / FourBitBinaryCounter.class (.txt) < prev    next >
Encoding:
Java Class File  |  1996-05-21  |  1.5 KB  |  60 lines

  1. class FourBitBinaryCounter extends IntegratedCircuit {
  2.    int Count;
  3.  
  4.    public FourBitBinaryCounter(Pin[][] var1, int var2, int var3) {
  5.       super(var2, var3, 10, 7, 3, 1, 4, 5, 1, 4);
  6.       super.IPin[0] = new InputPin("C", 1, 3, 2, 0, 0, 0, 0);
  7.       super.OPin[0] = new OutputPin("A", 9, 2, -2, 0, 0, 0, 0);
  8.       super.OPin[1] = new OutputPin("B", 9, 3, -2, 0, 0, 0, 0);
  9.       super.OPin[2] = new OutputPin("C", 9, 4, -2, 0, 0, 0, 0);
  10.       super.OPin[3] = new OutputPin("D", 9, 5, -2, 0, 0, 0, 0);
  11.       super.ComponentName = "4-bit binary counter";
  12.       super.ClassName = "FourBitBinaryCounter";
  13.       ((ElectronicComponent)this).RegisterPins(var1, var2, var3);
  14.    }
  15.  
  16.    public FourBitBinaryCounter(ElectronicComponent var1, int var2, int var3) {
  17.       super(var1, var2, var3);
  18.    }
  19.  
  20.    public ElectronicComponent Copy(int var1, int var2) {
  21.       FourBitBinaryCounter var3 = new FourBitBinaryCounter(this, var1, var2);
  22.       return var3;
  23.    }
  24.  
  25.    public void SimulateLogic() {
  26.       if (super.IPin[0].getOldLevel() == 0 && super.IPin[0].getLevel() == 5) {
  27.          ++this.Count;
  28.          if (this.Count < 0 || this.Count > 15) {
  29.             this.Count = 0;
  30.          }
  31.       }
  32.  
  33.       if ((this.Count & 1) == 1) {
  34.          super.OPin[0].setLevel(5);
  35.       } else {
  36.          super.OPin[0].setLevel(0);
  37.       }
  38.  
  39.       if ((this.Count & 2) == 2) {
  40.          super.OPin[1].setLevel(5);
  41.       } else {
  42.          super.OPin[1].setLevel(0);
  43.       }
  44.  
  45.       if ((this.Count & 4) == 4) {
  46.          super.OPin[2].setLevel(5);
  47.       } else {
  48.          super.OPin[2].setLevel(0);
  49.       }
  50.  
  51.       if ((this.Count & 8) == 8) {
  52.          super.OPin[3].setLevel(5);
  53.       } else {
  54.          super.OPin[3].setLevel(0);
  55.       }
  56.  
  57.       super.IPin[0].OldLevel = super.IPin[0].getLevel();
  58.    }
  59. }
  60.