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

  1. //****************************************************************************
  2. // ---- version information ----
  3. //
  4. // ThreeToEightLineDecoder.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. // 3-to 8-line decoder/multiplexer, inverting (74hct138)
  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 ThreeToEightLineDecoder extends IntegratedCircuit {
  34.  
  35. //----------------------------------------------------------------------------
  36. // The constructor of a new 3- to 8-line decoder
  37. //----------------------------------------------------------------------------
  38.     public ThreeToEightLineDecoder(Pin PinGrid[][], int x, int y) {
  39.         super (x, y, 10, 11 , 3, 1, 4, 9, 6, 8);      // x,y,w,h HitBox x,y,w,h,I,O
  40.         IPin[0] = new InputPin("0", 1, 2, 2, 0, 0, 0, ComponentPin.PIN_NORMAL); // name, x, y, w, h, inv
  41.         IPin[1] = new InputPin("1", 1, 3, 2, 0, 0, 0, ComponentPin.PIN_NORMAL); // name, x, y, w, h, inv
  42.         IPin[2] = new InputPin("2", 1, 4, 2, 0, 0, 0, ComponentPin.PIN_NORMAL); // name, x, y, w, h, inv
  43.  
  44.         IPin[3] = new InputPin("EN1", 1, 7, 2, 0, 0, 0, ComponentPin.PIN_NEGATIVE | ComponentPin.PIN_TEXT_INVISIBLE); // name, x, y, w, h, inv
  45.         IPin[4] = new InputPin("EN2", 1, 8, 2, 0, 0, 0, ComponentPin.PIN_NEGATIVE | ComponentPin.PIN_TEXT_INVISIBLE); // name, x, y, w, h, inv
  46.         IPin[5] = new InputPin("EN3", 1, 9, 2, 0, 0, 0, ComponentPin.PIN_TEXT_INVISIBLE); // name, x, y, w, h, inv
  47.  
  48.         OPin[0] = new OutputPin("0", 9, 2, -2, 0, 0, 0, ComponentPin.PIN_NEGATIVE); // name, x, y, w, h, inv
  49.         OPin[1] = new OutputPin("1", 9, 3, -2, 0, 0, 0, ComponentPin.PIN_NEGATIVE); // name, x, y, w, h, inv
  50.         OPin[2] = new OutputPin("2", 9, 4, -2, 0, 0, 0, ComponentPin.PIN_NEGATIVE); // name, x, y, w, h, inv
  51.         OPin[3] = new OutputPin("3", 9, 5, -2, 0, 0, 0, ComponentPin.PIN_NEGATIVE); // name, x, y, w, h, inv
  52.         OPin[4] = new OutputPin("4", 9, 6, -2, 0, 0, 0, ComponentPin.PIN_NEGATIVE); // name, x, y, w, h, inv
  53.         OPin[5] = new OutputPin("5", 9, 7, -2, 0, 0, 0, ComponentPin.PIN_NEGATIVE); // name, x, y, w, h, inv
  54.         OPin[6] = new OutputPin("6", 9, 8, -2, 0, 0, 0, ComponentPin.PIN_NEGATIVE); // name, x, y, w, h, inv
  55.         OPin[7] = new OutputPin("7", 9, 9, -2, 0, 0, 0, ComponentPin.PIN_NEGATIVE); // name, x, y, w, h, inv
  56.  
  57.         ComponentName = "3- to 8-line decoder";
  58.         ClassName = "ThreeToEightLineDecoder";
  59.         RegisterPins (PinGrid, x, y);
  60.     }
  61.  
  62. //----------------------------------------------------------------------------
  63. // The constructor of a new decoder, which is a copy of CompToCopy
  64. //----------------------------------------------------------------------------
  65.     public ThreeToEightLineDecoder (ElectronicComponent CompToCopy, int xo, int yo) {
  66.         super (CompToCopy, xo, yo);
  67.     }
  68.  
  69. //----------------------------------------------------------------------------
  70. // Method for copying this component.
  71. //----------------------------------------------------------------------------
  72.     public ElectronicComponent Copy(int xo, int yo) {
  73.         ThreeToEightLineDecoder NewComponent = new ThreeToEightLineDecoder(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, o = 0;
  82.         if (IPin[3].getLevel() == 0 ||  // EN1
  83.             IPin[4].getLevel() == 0 ||  // EN2
  84.             IPin[5].getLevel() == 0 ) { // EN3
  85.             // IC NOT enabled, All outputs high.
  86.             for (ix = 0; ix < 8; ix++) {
  87.                 OPin[ix].Level = 0;
  88.             }
  89.             return;
  90.         }
  91.         if (IPin[0].getLevel() == 5) o |= 1;
  92.         if (IPin[1].getLevel() == 5) o |= 2;
  93.         if (IPin[2].getLevel() == 5) o |= 4;
  94.         for (ix = 0; ix < 8; ix++) {
  95.             if (ix != o) {
  96.                 OPin[ix].Level = 0;
  97.             } else {
  98.                 OPin[ix].Level = 5;
  99.             }
  100.         }
  101.     }
  102.  
  103. //----------------------------------------------------------------------------
  104. // Do some additional drawing
  105. //----------------------------------------------------------------------------
  106.     public void draw(Graphics g, int xp, int yp, int gs) {
  107.         super.draw (g, xp, yp, gs);
  108.         int x = Pos.x - xp;
  109.         int y = Pos.y - yp;
  110.  
  111.         // Draw the body
  112.         g.setColor (ComponentColor);
  113.         g.drawLine ((x + 3) * gs, (int)((y + 6.5) * gs), (x + 5) * gs, (int)((y + 6.5) * gs));
  114.         g.drawLine ((x + 5) * gs, (int)((y + 6.5) * gs), (x + 5) * gs, (int)((y + 9.5) * gs));
  115.         g.drawLine ((x + 3) * gs, (int)((y + 9.5) * gs), (x + 5) * gs, (int)((y + 9.5) * gs));
  116.     }
  117. }