Construct a new circuit bus.
The fixed width of the bus. All values set with setValue must be of exactly this width, unless no value is set.
An array of other buses which are directly connected to this bus. When the value changes on this bus, it will be propagated to all of these other buses as well.
Connect another bus to this one, so that when the value changes on this bus, it will be propagated to this one as well.
The bus to connect to this one.
The instance of the bus this method was called on, for method chaining.
Connect an element to this bus. Whenever the value on this bus changes, it will be propagated to this element. This method primarily exists so that the simulation engine can collect a list of all elements which might be affected by a bus change, but it will do further filtering to determine if the elements actually are affected. See getElements, the method called internally by the simulator.
The element that is supposed to be connected to this bus.
The instance of the bus this method was called on, for method chaining.
Retrieve all buses which are connected to this one. Buses are connected either in the constructor or with the connect method.
An array of CircuitBuses.
Retrieve all of the elements that are connected to this bus in some capacity, either as an input or an output, it doesn't matter at this point.
An array of all the elements connected to this bus in some capacity.
Get the simulation timestamp that this bus was last updated. It is intended to be used in comparisons with other timestamps only; it is unlikely that the value by itself will be meaningful in any way outside the simulation.
The last update timestamp. See setLastUpdate
Get the fixed width of this circuit bus.
This method may seem redundant because it also exists on BitString,
but you can't always call BitString.getWidth if there is no BitString
value set on this bus. That is, getValue().getWidth()
may not work because
getValue()
could potentially be undefined. This method, however, will always return
the width of the bus even if there is no value on it.
When the bus does have a value, it is guaranteed that
getValue().getWidth() === getWidth()
, thanks to the behavior of setValue.
The width of the bus, in the number of bits.
The simulation engine requires information about when buses were last updated for efficiently evaluating circuits. It uses this information particularly for tricky elements which may be bi-directional, and it allows elements to query when a bus was last updated to determine which direction to propagate.
The timestamp, which should be greater than or equal to the last timestamp, unless the simulation is being reset; then it should be set to -1.
Set a BitString value on this bus, propagating it to all other buses connected to this one.
The bit string value to set on this bus. The width of this value must be less than or equal to the width of the bus. If the value is too wide, the bus will throw an exception. If it is too low, the value will be automatically zero-padded to ensure that the width matches what connected elements are expecting.
Optional
lastUpdate: numberAn optional last update timestamp. See setLastUpdate for details.
A circuit bus is simply a wire or collection of wires. A bus is commonly called a "wire" or a "node" in other simulators, but the concept is identical. A bus carries one or more bits between CircuitElements. Buses have a width, which is the number of physical wires bundled within the bus, so they can transport bit values of any size.
Circuit buses exist exclusively to connect CircuitElements together and communicate BitStrings between them. One element will set a BitString value on its output bus, and another which is connected to that same bus as an input will read that BitString value as its input.
Circuit buses are not required to have a value on them. It is very possible for the bus to be in a "floating" state where the value will be returned as
null
because it is indeterminate. Take caution in all circuit element implementations to ensure that indeterminate bus values are handled properly.