home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1997 October / PCO1097.ISO / FilesBBS / FREI / DIGSIM.EXE / EightBitParInShiftReg.java < prev    next >
Encoding:
Java Source  |  1996-05-21  |  5.2 KB  |  116 lines

  1. //****************************************************************************
  2. // ---- version information ----
  3. //
  4. // EightBitParInShiftReg.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 parallel in,
  12. // serial 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 EightBitParInShiftReg extends IntegratedCircuit {
  34.     int Mem[];
  35.  
  36. //----------------------------------------------------------------------------
  37. // The constructor of a new Eight bit parallel in serial out shift register
  38. //----------------------------------------------------------------------------
  39.     public EightBitParInShiftReg(Pin PinGrid[][], int x, int y) {
  40.         super (x, y, 10, 17, 3, 1, 4, 15, 11, 2);      // x,y,w,h HitBox x,y,w,h,I,O
  41.         Mem = new int[8];
  42.         IPin[0] = new InputPin("CLK", 1, 2, 2, 0, 0, 0, ComponentPin.PIN_EDGETRIGGERED); // name, x, y, w, h, flags
  43.         IPin[1] = new InputPin("CLR", 1, 4, 2, 0, 0, 0, ComponentPin.PIN_NEGATIVE); // name, x, y, w, h, flags
  44.         IPin[2] = new InputPin("LD", 1, 6, 2, 0, 0, 0, ComponentPin.PIN_NEGATIVE); // name, x, y, w, h, flags
  45.         IPin[3] = new InputPin("1", 1, 8, 2, 0, 0, 0, ComponentPin.PIN_NORMAL); // name, x, y, w, h, flags
  46.         IPin[4] = new InputPin("2", 1, 9, 2, 0, 0, 0, ComponentPin.PIN_NORMAL); // name, x, y, w, h, flags
  47.         IPin[5] = new InputPin("3", 1, 10, 2, 0, 0, 0, ComponentPin.PIN_NORMAL); // name, x, y, w, h, flags
  48.         IPin[6] = new InputPin("4", 1, 11, 2, 0, 0, 0, ComponentPin.PIN_NORMAL); // name, x, y, w, h, flags
  49.         IPin[7] = new InputPin("5", 1, 12, 2, 0, 0, 0, ComponentPin.PIN_NORMAL); // name, x, y, w, h, flags
  50.         IPin[8] = new InputPin("6", 1, 13, 2, 0, 0, 0, ComponentPin.PIN_NORMAL); // name, x, y, w, h, flags
  51.         IPin[9] = new InputPin("7", 1, 14, 2, 0, 0, 0, ComponentPin.PIN_NORMAL); // name, x, y, w, h, flags
  52.         IPin[10] = new InputPin("8", 1, 15, 2, 0, 0, 0, ComponentPin.PIN_NORMAL); // name, x, y, w, h, flags
  53.  
  54.         OPin[0] = new OutputPin("Q", 9, 13, -2, 0, 0, 0, ComponentPin.PIN_NORMAL); // name, x, y, w, h, flags
  55.         OPin[1] = new OutputPin("Q", 9, 15, -2, 0, 0, 0, ComponentPin.PIN_NEGATIVE); // name, x, y, w, h, flags
  56.         ComponentName = "8-bit parallel in shift register";
  57.         ClassName = "EightBitParInShiftReg";
  58.         RegisterPins (PinGrid, x, y);
  59.     }
  60.  
  61. //----------------------------------------------------------------------------
  62. // The constructor of a new shift register, which is a copy of CompToCopy
  63. //----------------------------------------------------------------------------
  64.     public EightBitParInShiftReg (ElectronicComponent CompToCopy, int xo, int yo) {
  65.         super (CompToCopy, xo, yo);
  66.         Mem = new int[8];
  67.     }
  68.  
  69. //----------------------------------------------------------------------------
  70. // Method for copying this component.
  71. //----------------------------------------------------------------------------
  72.     public ElectronicComponent Copy(int xo, int yo) {
  73.         EightBitParInShiftReg NewComponent = new EightBitParInShiftReg(this, xo, yo);
  74.         return NewComponent;
  75.     }
  76.  
  77. //----------------------------------------------------------------------------
  78. // Here is the code that's simulating the component
  79. //----------------------------------------------------------------------------
  80.     public void SimulateLogic() {
  81.         int ix;
  82.  
  83.         if (IPin[2].getLevel() == 5) { // Load
  84.             for (ix = 0; ix < 8 ; ix++) {
  85.                 Mem[ix] = IPin[ix + 3].getLevel();
  86.             }
  87.         }
  88.         if (IPin[1].getLevel() == 5) { // Reset
  89.              // Reset
  90.              for (ix = 0; ix < 8; ix++) {
  91.                 Mem[ix] = 0;
  92.  
  93.             }
  94.         }
  95.  
  96.         if (IPin[0].OldLevel == 0 && IPin[0].getLevel() == 5) {
  97.             // Clock transition Low to High, shift Mem
  98.             for (ix = 7; ix > 0; ix--) {
  99.                 Mem [ix] = Mem[ix-1];
  100.             }
  101.             Mem[0] = 0;
  102.         }
  103.         OPin[0].setLevel(Mem[7]);
  104.         OPin[1].setLevel(Mem[7]);
  105.  
  106.         IPin[0].OldLevel = IPin[0].getLevel();
  107.     }
  108.  
  109. //----------------------------------------------------------------------------
  110. // Inform all components connected to the outputs with the OLD level,
  111. // because this is an edge-triggered component.
  112. //----------------------------------------------------------------------------
  113.     public void Simulate(int id) {
  114.         InformConnectedComponentsOldLevel(id);
  115.     }
  116. }