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

  1. //****************************************************************************
  2. // ---- version information ----
  3. //
  4. // FourBitBinaryCounter.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 creating and maintaining a
  12. // 4-bit binary counter
  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 FourBitBinaryCounter extends IntegratedCircuit {
  34.     int Count = 0;
  35.  
  36. //----------------------------------------------------------------------------
  37. // The constructor of a new 4-bit binary counter
  38. //----------------------------------------------------------------------------
  39.     public FourBitBinaryCounter(Pin PinGrid[][], int x, int y) {
  40.         super (x, y, 10, 7 , 3, 1, 4, 5, 1, 4);      // x,y,w,h HitBox x,y,w,h,I,O
  41.         IPin[0] = new InputPin("C", 1, 3, 2, 0, 0, 0, ComponentPin.PIN_NORMAL); // name, x, y, w, h, inv
  42.  
  43.         OPin[0] = new OutputPin("A", 9, 2, -2, 0, 0, 0, ComponentPin.PIN_NORMAL); // name, x, y, w, h, inv
  44.         OPin[1] = new OutputPin("B", 9, 3, -2, 0, 0, 0, ComponentPin.PIN_NORMAL); // name, x, y, w, h, inv
  45.         OPin[2] = new OutputPin("C", 9, 4, -2, 0, 0, 0, ComponentPin.PIN_NORMAL); // name, x, y, w, h, inv
  46.         OPin[3] = new OutputPin("D", 9, 5, -2, 0, 0, 0, ComponentPin.PIN_NORMAL); // name, x, y, w, h, inv
  47.  
  48.         ComponentName = "4-bit binary counter";
  49.         ClassName = "FourBitBinaryCounter";
  50.         RegisterPins (PinGrid, x, y);
  51.     }
  52.  
  53. //----------------------------------------------------------------------------
  54. // The constructor of a new counter, which is a copy of CompToCopy
  55. //----------------------------------------------------------------------------
  56.     public FourBitBinaryCounter (ElectronicComponent CompToCopy, int xo, int yo) {
  57.         super (CompToCopy, xo, yo);
  58.     }
  59.  
  60. //----------------------------------------------------------------------------
  61. // Method for copying this component.
  62. //----------------------------------------------------------------------------
  63.     public ElectronicComponent Copy(int xo, int yo) {
  64.         FourBitBinaryCounter NewComponent = new FourBitBinaryCounter(this, xo, yo);
  65.         return NewComponent;
  66.     }
  67.  
  68. //----------------------------------------------------------------------------
  69. // Here is the code that's simulating the component
  70. //----------------------------------------------------------------------------
  71.     public void SimulateLogic() {
  72.          if (IPin[0].getOldLevel() == 0 && IPin[0].getLevel() == 5) {
  73.             Count++;
  74.             if (Count < 0 || Count > 15) Count = 0;
  75.         }
  76.         if ((Count & 0x01) == 0x01) {
  77.             OPin[0].setLevel (5);
  78.         } else {
  79.             OPin[0].setLevel (0);
  80.         }
  81.         if ((Count & 0x02) == 0x02) {
  82.             OPin[1].setLevel (5);
  83.         } else {
  84.             OPin[1].setLevel (0);
  85.         }
  86.         if ((Count & 0x04) == 0x04) {
  87.             OPin[2].setLevel (5);
  88.         } else {
  89.             OPin[2].setLevel (0);
  90.         }
  91.         if ((Count & 0x08) == 0x08) {
  92.             OPin[3].setLevel (5);
  93.         } else {
  94.             OPin[3].setLevel (0);
  95.         }
  96.         IPin[0].OldLevel = IPin[0].getLevel();
  97.     }
  98. }