home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / ed8n1t2i / octaldflipflop.java < prev    next >
Encoding:
Java Source  |  1996-08-14  |  5.5 KB  |  113 lines

  1. //****************************************************************************
  2. // ---- version information ----
  3. //
  4. // OctalDFlipFlop.java   v 1.00 b1
  5. // Written by:           I. van Rienen / E-mail ivr@bart.nl
  6. // URL:                  http://www/bart.nl/~ivr
  7. // Initial release:
  8. // Released in public domain:
  9. //
  10. // ---- Description ----
  11. // Java class containing methods for an octal D-flip flop
  12. //
  13. // This program and the Java source is in the public domain.
  14. // Permission to use, copy, modify, and distribute this software
  15. // and its documentation for NON-COMMERCIAL purposes and
  16. // without fee is hereby granted.
  17. //
  18. //    Copyright 1996
  19. //
  20. //    Iwan van Rienen
  21. //    Joan Maetsuyckerstr. 145
  22. //    2593 ZG  The Hague
  23. //    The Netherlands
  24. //
  25. // I am not responsible for any bugs in this program and
  26. // possible damage to hard- or software when using this program.
  27. //****************************************************************************
  28. import java.applet.Applet;
  29. import java.awt.*;
  30. import java.util.Vector;
  31.  
  32. class OctalDFlipFlop extends IntegratedCircuit {
  33.  
  34. //----------------------------------------------------------------------------
  35. // The constructor of a new Octal D flip flop
  36. //----------------------------------------------------------------------------
  37.     public OctalDFlipFlop(Pin PinGrid[][], int x, int y) {
  38.         super (x, y, 10, 15, 3, 1, 4, 13, 10, 8);      // x,y,w,h HitBox x,y,w,h,I,O
  39.         IPin[0] = new InputPin("R", 1, 2, 2, 0, 0, 0, ComponentPin.PIN_NEGATIVE); // name, x, y, w, h, flags
  40.         IPin[1] = new InputPin("C", 1, 4, 2, 0, 0, 0, ComponentPin.PIN_EDGETRIGGERED); // name, x, y, w, h, flags
  41.         IPin[2] = new InputPin("1", 1, 6, 2, 0, 0, 0, ComponentPin.PIN_NOACTION); // name, x, y, w, h, flags
  42.         IPin[3] = new InputPin("2", 1, 7, 2, 0, 0, 0, ComponentPin.PIN_NOACTION); // name, x, y, w, h, flags
  43.         IPin[4] = new InputPin("3", 1, 8, 2, 0, 0, 0, ComponentPin.PIN_NOACTION); // name, x, y, w, h, flags
  44.         IPin[5] = new InputPin("4", 1, 9, 2, 0, 0, 0, ComponentPin.PIN_NOACTION); // name, x, y, w, h, flags
  45.         IPin[6] = new InputPin("5", 1, 10, 2, 0, 0, 0, ComponentPin.PIN_NOACTION); // name, x, y, w, h, flags
  46.         IPin[7] = new InputPin("6", 1, 11, 2, 0, 0, 0, ComponentPin.PIN_NOACTION); // name, x, y, w, h, flags
  47.         IPin[8] = new InputPin("7", 1, 12, 2, 0, 0, 0, ComponentPin.PIN_NOACTION); // name, x, y, w, h, flags
  48.         IPin[9] = new InputPin("8", 1, 13, 2, 0, 0, 0, ComponentPin.PIN_NOACTION); // name, x, y, w, h, flags
  49.  
  50.         OPin[0] = new OutputPin("1", 9, 6, -2, 0, 0, 0, ComponentPin.PIN_NORMAL); // name, x, y, w, h, flags
  51.         OPin[1] = new OutputPin("2", 9, 7, -2, 0, 0, 0, ComponentPin.PIN_NORMAL); // name, x, y, w, h, flags
  52.         OPin[2] = new OutputPin("3", 9, 8, -2, 0, 0, 0, ComponentPin.PIN_NORMAL); // name, x, y, w, h, flags
  53.         OPin[3] = new OutputPin("4", 9, 9, -2, 0, 0, 0, ComponentPin.PIN_NORMAL); // name, x, y, w, h, flags
  54.         OPin[4] = new OutputPin("5", 9, 10, -2, 0, 0, 0, ComponentPin.PIN_NORMAL); // name, x, y, w, h, flags
  55.         OPin[5] = new OutputPin("6", 9, 11, -2, 0, 0, 0, ComponentPin.PIN_NORMAL); // name, x, y, w, h, flags
  56.         OPin[6] = new OutputPin("7", 9, 12, -2, 0, 0, 0, ComponentPin.PIN_NORMAL); // name, x, y, w, h, flags
  57.         OPin[7] = new OutputPin("8", 9, 13, -2, 0, 0, 0, ComponentPin.PIN_NORMAL); // name, x, y, w, h, flags
  58.         ComponentName = "Octal D-flipflop";
  59.         ClassName = "OctalDFlipFlop";
  60.         RegisterPins (PinGrid, x, y);
  61.     }
  62.  
  63. //----------------------------------------------------------------------------
  64. // The constructor of a new octal D flip flop, which is a copy of CompToCopy
  65. //----------------------------------------------------------------------------
  66.     public OctalDFlipFlop (ElectronicComponent CompToCopy, int xo, int yo) {
  67.         super (CompToCopy, xo, yo);
  68.     }
  69.  
  70. //----------------------------------------------------------------------------
  71. // Method for copying this component.
  72. //----------------------------------------------------------------------------
  73.     public ElectronicComponent Copy(int xo, int yo) {
  74.         OctalDFlipFlop NewComponent = new OctalDFlipFlop(this, xo, yo);
  75.         return NewComponent;
  76.     }
  77.  
  78. //----------------------------------------------------------------------------
  79. // Here is the code that's simulating the component
  80. //----------------------------------------------------------------------------
  81.     public void SimulateLogic() {
  82.         int ix;
  83.  
  84.         if (IPin[1].OldLevel == 0 && IPin[1].getLevel() == 5) {
  85.              // Clock transition Low to High
  86.              for (ix = 0; ix < 8; ix++) {
  87.                 OPin[ix].setLevel(IPin[2 + ix].getLevel());
  88.             }
  89.        } else {
  90.             // Nothing happened. Outputs remain unchanged.
  91.             // do setLevel() for modifying OldLevel.
  92.              for (ix = 0; ix < 8; ix++) {
  93.                 OPin[ix].setLevel(OPin[ix].getLevel());
  94.             }
  95.         }
  96.  
  97.         if (IPin[0].getLevel() == 5) {
  98.              // Reset
  99.              for (ix = 0; ix < 8; ix++) {
  100.                 OPin[ix].setLevel(0);
  101.             }
  102.         }
  103.         IPin[1].OldLevel = IPin[1].getLevel();
  104.     }
  105.  
  106. //----------------------------------------------------------------------------
  107. // Inform all components connected to the outputs with the OLD level,
  108. // because this is an edge-triggered component.
  109. //----------------------------------------------------------------------------
  110.     public void Simulate(int id) {
  111.         InformConnectedComponentsOldLevel(id);
  112.     }
  113. }