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

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