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

  1. //****************************************************************************
  2. // ---- version information ----
  3. //
  4. // GatedSRLatch.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 a Gated set / reset latch
  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 GatedSRLatch extends IntegratedCircuit {
  33.  
  34. //----------------------------------------------------------------------------
  35. // The constructor of a new Gated SR latch
  36. //----------------------------------------------------------------------------
  37.     public GatedSRLatch(Pin PinGrid[][], int x, int y) {
  38.         super (x, y, 10, 6, 3, 1, 4, 4, 3, 2);      // x,y,w,h HitBox x,y,w,h,I,O
  39.         IPin[0] = new InputPin("S", 1, 2, 2, 0, 0, 0, ComponentPin.PIN_NORMAL); // name, x, y, w, h, inv
  40.         IPin[1] = new InputPin("C", 1, 3, 2, 0, 0, 0, ComponentPin.PIN_NORMAL); // name, x, y, w, h, inv
  41.         IPin[2] = new InputPin("R", 1, 4, 2, 0, 0, 0, ComponentPin.PIN_NORMAL); // name, x, y, w, h, inv
  42.         OPin[0] = new OutputPin("Q", 9, 2, -2, 0, 0, 0, ComponentPin.PIN_NORMAL); // name, x, y, w, h, inv
  43.         OPin[1] = new OutputPin("Q", 9, 4, -2, 0, 0, 0, ComponentPin.PIN_NEGATIVE); // name, x, y, w, h, inv
  44.         ComponentName = "gated SR-latch";
  45.         ClassName = "GatedSRLatch";
  46.         RegisterPins (PinGrid, x, y);
  47.     }
  48.  
  49. //----------------------------------------------------------------------------
  50. // The constructor of a new gated SR latch, which is a copy of CompToCopy
  51. //----------------------------------------------------------------------------
  52.     public GatedSRLatch (ElectronicComponent CompToCopy, int xo, int yo) {
  53.         super (CompToCopy, xo, yo);
  54.     }
  55.  
  56. //----------------------------------------------------------------------------
  57. // Method for copying this component.
  58. //----------------------------------------------------------------------------
  59.     public ElectronicComponent Copy(int xo, int yo) {
  60.         GatedSRLatch NewComponent = new GatedSRLatch(this, xo, yo);
  61.         return NewComponent;
  62.     }
  63.  
  64. //----------------------------------------------------------------------------
  65. // Here is the code that's simulating the component
  66. //----------------------------------------------------------------------------
  67.     public void SimulateLogic() {
  68.         if (IPin[1].getLevel() == 5) {              // clock
  69.             if (IPin[0].getLevel() == 5) {          // set
  70.                 OPin[0].Level = OPin[1].Level = 5;
  71.             }
  72.             if (IPin[2].getLevel() == 5) {          // reset
  73.                 OPin[0].Level = OPin[1].Level = 0;
  74.             }
  75.         }
  76.     }
  77. }