home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / self / contrib.lha / contrib / simulator / levels.self < prev    next >
Encoding:
Text File  |  1991-03-04  |  9.7 KB  |  266 lines

  1. "$ Revision: 1.0 $"
  2. "Copyright 1990:
  3.     Jecel Mattos de Assumpcao Jr.
  4.     LSI - EPSUP, Sao Paulo, SP, Brasil"
  5.  
  6.     "Simulator Logic Levels "
  7.  
  8.     "traits <simulation> resolution"
  9.     "Algorithm for resolution between different levels"
  10.  
  11.     "<prototypes simulation levels> unknown"
  12.     "21 unknown states used in the simulator"
  13.  
  14.     "oddballs <simulation levels> drivenHigh"
  15.     "oddballs <simulation levels> weakHigh"
  16.     "oddballs <simulation levels> chargeHigh"
  17.     "oddballs <simulation levels> highImpedance"
  18.     "oddballs <simulation levels> chargeLow"
  19.     "oddballs <simulation levels> weaklow"
  20.     "oddballs <simulation levels> drivenLow"
  21.     "7 logic levels used in the simulator"
  22.  
  23. traits _DefineSlots: ( |
  24.     simulation* = ( |
  25.         resolution = ( |
  26.             resolve: aValue = (
  27.                 ( weakest > aValue strongest )
  28.                    ifTrue: [ self ]
  29.                    False: [ 
  30.                      ( strongest < aValue weakest )
  31.                        ifTrue: [ aValue ]
  32.                        False: [ 
  33.                          == aValue
  34.                            ifTrue: [ self ]
  35.                            False: [
  36.                              oddballs simulation levels unknown 
  37.                                merge: highest
  38.                                   To: lowest
  39.                                 With: aValue highest
  40.                                   To: aValue lowest
  41.                            ].
  42.                        ].
  43.                    ].
  44.             ).
  45.         | ).
  46.     | ).
  47. | )
  48.  
  49. prototypes _DefineSlots: ( |
  50.     simulation* = ( |
  51.         levels* = ( |
  52.             unknown = ( |
  53.                 parent** = traits clonable.
  54.                 operation* = traits simulation resolution.
  55.                 lowest.
  56.                 highest.
  57.                 position = ( error: 'unknown does not have a position' ).
  58.                 == x = ( ( lowest == x lowest ) && ( highest == x highest ) ).
  59.                 unknown: v1 To: v2 = ( 
  60.                     v1 == v2 ifFalse: [ | c |
  61.                                          c: copy.
  62.                                          c lowest: v2. 
  63.                                          c highest: v1.
  64.                                          c ]
  65.                              True: [ v1 ].
  66.                 ).
  67.                 merge: v1 To: v2 With: v3 To: v4 = ( | p1. p2. p3. p4 |
  68.                     p1: v1 position.
  69.                     p2: v2 position.
  70.                     p3: v3 position.
  71.                     p4: v4 position.
  72.                     ( p2 >= 0 ) && ( p4 >= 0 )
  73.                     ifTrue: [
  74.                       unknown: ( p1 > p3
  75.                                    ifTrue: [ v1 ]
  76.                                    False: [ v3 ] )
  77.                            To: ( p2 > p4
  78.                                    ifTrue: [ v2 ]
  79.                                    False: [ v4 ] )
  80.                     ]
  81.                     False: [
  82.                       ( p1 <= 0 ) && ( p3 <= 0 )
  83.                         ifTrue: [
  84.                           unknown: ( p1 > p3
  85.                                        ifTrue: [ v3 ]
  86.                                        False: [ v1 ] )
  87.                                To: ( p2 > p4
  88.                                        ifTrue: [ v4 ]
  89.                                        False: [ v2 ] )
  90.                         ]
  91.                         False: [
  92.                           unknown: ( p1 > p3
  93.                                      ifTrue: [ v1 ]
  94.                                      False: [ v3 ] )
  95.                                To: ( p2 > p4
  96.                                      ifTrue: [ v4 ]
  97.                                      False: [ v2 ] )
  98.                         ].
  99.                     ].
  100.                 ).
  101.                 level = ( lowest level == highest level
  102.                               ifTrue: [ lowest level ]
  103.                               False: [ 2 ].
  104.                 ).
  105.                 strength = ( lowest level max: highest level ).
  106.                 weaker = ( copy unknown: highest weaker To: lowest weaker ).
  107.                 stronger = ( copy unknown: highest stronger To: lowest stronger ).
  108.                 weakest = ( lowest strength min: highest strength ).
  109.                 strongest = ( lowest strength max: highest strength ).
  110.                 isHigh = false.
  111.                 isLow = false.
  112.                 isUnknown = true.
  113.                 isDisconnected = false.
  114.                 thisObjectPrints = true.
  115.                 printString = 'x'.
  116.                 drawOn: bitmap From: p1 To: p2 = (
  117.                     bitmap xorLine: p1 To: p2 x @ p1 y.
  118.                     bitmap xorLine: p1 x @ p2 y To: p2.
  119.                 ).
  120.                 drive = ( copy unknown: highest drive To: lowest drive ).
  121.                 not = ( drive ).
  122.                 || v = ( v level == 2 ifTrue: [ v drive ] False: [ v || self ] ).
  123.                 && v = ( v level == 2 ifTrue: [ v drive ] False: [ v && self ] ).
  124.             | ).
  125.         | ).
  126.     | ).
  127. | )
  128.  
  129. oddballs _DefineSlots: ( |
  130.     simulation* = ( |
  131.         levels* = ( |
  132.             drivenHigh = ( |
  133.                 parent** = traits oddball.
  134.                 operation* = traits simulation resolution.
  135.                 position = 3.
  136.                 weaker = ( oddballs simulation levels weakHigh ).
  137.                 stronger = ( self ).
  138.                 thisObjectPrints = true.
  139.                 logic* = ( |
  140.                     level = 1.
  141.                     isHigh = true.
  142.                     isLow = false.
  143.                     isUnknown = false.
  144.                     isDisconnected = false.
  145.                     printString = 'h'.
  146.                     drawOn: bitmap From: p1 To: p2 = (
  147.                         bitmap xorLine: p1 To: p2 x @ p1 y.
  148.                     ).
  149.                     strength = ( position absoluteValue ).
  150.                     drive = ( oddballs simulation levels drivenHigh ).
  151.                     not = ( oddballs simulation levels drivenLow ).
  152.                     || v = ( drive ).
  153.                     && v = ( v drive ).
  154.                     lowest = ( self ).
  155.                     highest = ( self ).
  156.                     weakest = ( strength ).
  157.                     strongest = ( strength ).
  158.                 | ).
  159.             | ).
  160.             drivenLow = ( |
  161.                 parent** = traits oddball.
  162.                 operation* = traits simulation resolution.
  163.                 position = -3.
  164.                 weaker = ( oddballs simulation levels weakLow ).
  165.                 stronger = ( self ).
  166.                 thisObjectPrints = true.
  167.                 logic* = ( |
  168.                     level = 0.
  169.                     isHigh = false.
  170.                     isLow = true.
  171.                     isUnknown = false.
  172.                     isDisconnected = false.
  173.                     printString = 'l'.
  174.                     drawOn: bitmap From: p1 To: p2 = (
  175.                         bitmap xorLine: p1 x @ p2 y To: p2.
  176.                     ).
  177.                     strength = ( position absoluteValue ).
  178.                     drive = ( oddballs simulation levels drivenLow ).
  179.                     not = ( oddballs simulation levels drivenHigh ).
  180.                     || v = ( v drive).
  181.                     && v = ( drive ).
  182.                     lowest = ( self ).
  183.                     highest = ( self ).
  184.                     weakest = ( strength ).
  185.                     strongest = ( strength ).
  186.                 | ).
  187.             | ).
  188.             unknown = ( unknown: drivenHigh To: drivenLow
  189.             ).
  190.             unknown: v1 To: v2 = ( 
  191.                 ( v1 == v2 ) ifFalse: [
  192.                 v1 "v1 has access to the lobby" 
  193.                 prototypes simulation levels unknown copy
  194.                                        unknown: v1 To: v2.
  195.                 ] True: [ v1 ].
  196.             ).
  197.         | ).
  198.     | ).
  199. | )
  200.  
  201. oddballs simulation levels _DefineSlots: ( |
  202.     weakHigh = ( |
  203.         parent** = traits oddball.
  204.         operation* = traits simulation resolution.
  205.         position = 2.
  206.         weaker = ( self ).
  207.         stronger = ( oddballs simulation levels drivenHigh ).
  208.         thisObjectPrints = true.
  209.         logic* = oddballs simulation levels drivenHigh logic.
  210.     | ).
  211.     weakLow = ( |
  212.         parent** = traits oddball.
  213.         operation* = traits simulation resolution.
  214.         position = -2.
  215.         weaker = ( self ).
  216.         stronger = ( oddballs simulation levels drivenLow ).
  217.         thisObjectPrints = true.
  218.         logic* = oddballs simulation levels drivenLow logic.
  219.     | ).
  220.     chargeHigh = ( |
  221.         parent** = traits oddball.
  222.         operation* = traits simulation resolution.
  223.         position = 1.
  224.         weaker = ( self ).
  225.         stronger = ( self ).
  226.         thisObjectPrints = true.
  227.         logic* = oddballs simulation levels drivenHigh logic.
  228.     | ).
  229.     chargeLow = ( |
  230.         parent** = traits oddball.
  231.         operation* = traits simulation resolution.
  232.         position = -1.
  233.         weaker = ( self ).
  234.         stronger = ( self ).
  235.         thisObjectPrints = true.
  236.         logic* = oddballs simulation levels drivenLow logic.
  237.     | ).
  238.     highImpedance = ( |
  239.          parent** = traits oddball.
  240.          operation* = traits simulation resolution.
  241.          level = 0.5.
  242.          strength = 0.
  243.          position = 0.
  244.          weaker = ( self ).
  245.          stronger = ( self ).
  246.          drive = ( oddballs simulation levels unknown ).
  247.          isHigh = false.
  248.          isLow = false.
  249.          isUnknown = false.
  250.          isDisconnected = true.
  251.          thisObjectPrints = true.
  252.          printString = 'z'.
  253.          drawOn: bitmap From: p1 To: p2 = ( | y |
  254.              y: ((p1 y) + (p2 y)) / 2.
  255.              bitmap xorLine: p1 x @ y To: p2 x @ y.
  256.          ).
  257.          not = ( oddballs simulation levels unknown ).
  258.          || v = ( oddballs simulation levels unknown ).
  259.          && v = ( oddballs simulation levels unknown ).
  260.          lowest = ( self ).
  261.          highest = ( self ).
  262.          weakest = ( strength ).
  263.          strongest = ( strength ).
  264.     | ).
  265. | )
  266.