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

  1. //****************************************************************************
  2. // ---- version information ----
  3. //
  4. // EdgeTriggeredTFlipFlop.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 Edge Triggered T 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 EdgeTriggeredTFlipFlop extends IntegratedCircuit {
  33.  
  34. //----------------------------------------------------------------------------
  35. // The constructor of a new Edge-triggered toggle flipflop.
  36. //----------------------------------------------------------------------------
  37.     public EdgeTriggeredTFlipFlop(Pin PinGrid[][], int x, int y) {
  38.         super (x, y, 10, 6, 3, 1, 4, 4, 2, 2);      // x,y,w,h HitBox x,y,w,h,I,O
  39.         IPin[0] = new InputPin("T", 1, 2, 2, 0, 0, 0, ComponentPin.PIN_NOACTION); // 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.         OPin[0] = new OutputPin("Q", 9, 2, -2, 0, 0, 0, ComponentPin.PIN_NORMAL); // name, x, y, w, h, flags
  42.         OPin[1] = new OutputPin("Q", 9, 4, -2, 0, 0, 0, ComponentPin.PIN_NEGATIVE); // name, x, y, w, h, flags
  43.         ComponentName = "Edge triggered T-flipflop";
  44.         ClassName = "EdgeTriggeredTFlipFlop";
  45.         RegisterPins (PinGrid, x, y);
  46.     }
  47.  
  48. //----------------------------------------------------------------------------
  49. // The constructor of a new T-flip flop, which is a copy of CompToCopy
  50. //----------------------------------------------------------------------------
  51.     public EdgeTriggeredTFlipFlop (ElectronicComponent CompToCopy, int xo, int yo) {
  52.         super (CompToCopy, xo, yo);
  53.     }
  54.  
  55. //----------------------------------------------------------------------------
  56. // Method for copying this component.
  57. //----------------------------------------------------------------------------
  58.     public ElectronicComponent Copy(int xo, int yo) {
  59.         EdgeTriggeredTFlipFlop NewComponent = new EdgeTriggeredTFlipFlop(this, xo, yo);
  60.         return NewComponent;
  61.     }
  62.  
  63. //----------------------------------------------------------------------------
  64. // Here is the code that's simulating the component
  65. //----------------------------------------------------------------------------
  66.     public void SimulateLogic() {
  67. //      System.out.println ("Edge triggered TFlipFlop SimulateLogic()");
  68.  
  69.          if (IPin[1].getOldLevel() == 0 && IPin[1].getLevel() == 5) {
  70. //          System.out.println ("**** Edge triggered");
  71.             if (IPin[0].getLevel() == 5) {
  72.                 // Toggle output
  73.                 if (OPin[0].getLevel() == 0) {
  74.                     OPin[0].setLevel (5);
  75.                     OPin[1].setLevel (5);
  76.                 } else {
  77.                     OPin[0].setLevel (0);
  78.                     OPin[1].setLevel (0);
  79.                 }
  80.             }
  81.         } else {
  82.             // Nothing happened. Outputs remain unchanged.
  83.             // do setLevel() for modifying OldLevel.
  84.             OPin[0].setLevel (OPin[0].getLevel());
  85.             OPin[1].setLevel (OPin[0].getLevel());
  86.         }
  87.  
  88.  
  89.         IPin[1].OldLevel = IPin[1].getLevel();
  90.     }
  91.  
  92. //----------------------------------------------------------------------------
  93. // When this Simulate() method is called, Inform all conneced components
  94. // with the OLD level of the output port. This because it's an edge-
  95. // triggered component.
  96. //----------------------------------------------------------------------------
  97.     public void Simulate(int id) {
  98.         InformConnectedComponentsOldLevel(id);
  99.     }
  100.  
  101. }