- v50 information can now be added to pages in the main namespace. v0.47 information can still be found in the DF2014 namespace. See here for more details on the new versioning policy.
- Use this page to report any issues related to the migration.
v0.31:Pre-Toggled Mechanical Logic
This article is about an older version of DF. |
Recently some research on mechanical logic offered a new viewpoint of dealing with the limitations of this variety of logic. By including a concept called pre-toggling, one can construct nearly any conceivable logic circuit, with surmountable exceptions. From this, Pre-Toggled Mechanical Logic (PTML) was born. Due to the nature of gear assemblies, circuitry using this method can be exceptionally fast for certain purposes, and can be made 100% fluid conserving in all cases, allowing it to be isolated from an infinite water supply.
Design Guidelines
There are a few guidelines for working with PTML circuits.
- Levers and pressure plates should be linked to a gear assembly in the on state. For reference, a lever is off when built.
- A gear may be designated as undriven, non-toggled, or pre-toggled.
- Undriven gears are never linked to. They merely transfer what power is available to them.
- Non-toggled gears are linked to by a lever or pressure plate, and left alone. They transfer power when their truth state is true.
- Pre-toggled gears are linked to by a lever or pressure plate, then pre-toggled. To pre-toggle a gear, you build a lever, link it to the gear to pre-toggle, then flip the lever and dismantle it. As such, pre-toggled gears cost an extra mechanism. Pre-toggled gears flip the logical truth state of their inputs.
- Two gears are considered directly connected if they are either adjacent, above one another without an intervening floor, or if they are separated by only axles and/or undriven gears.
- Two driven connected gears form an AND gate. Power can flow through an AND gate only if both driven gears are in the true truth state.
- A single gear connected to two or more driven input gears forms an OR gate. Power will flow through this gear if at least one of the driven source gears is in the true truth state. If the gear is undriven, it forms a simple OR gate. If, however, it is driven, its input is ANDed with whatever the output of the OR expression is.
- A single gear can be driven by multiple inputs to form an XOR or NXOR gate. For even numbers of inputs, the gear must be pre-toggled to form an XOR gate, non-toggled to form an NXOR gate. For odd numbers of inputs, the gear must be non-toggled to form an XOR gate, pre-toggled to form an NXOR gate. Power will flow through this gear only if it is in the true truth state.
- Two connected driven gears, both having identical input links, with one being non-toggled, and the other being pre-toggled, are called out-of-phase. Out-of-phase gears will never transfer power through their connections.
- Determining the qualities of a PTML circuit can be done on paper or in a spreadsheet. Truth formulas for each gear can be devised to determine whether they are engaged or disengaged. This need only be done for driven gears. Power can only flow through engaged gears, i.e. gears whose truth state is true. An output undriven gear will have power if an orthogonal line can be drawn from the power through any series of engaged gears. This does not require the circuit to be built in game to verify that it works.
- Hybrid circuitry exists to allow the output of a gear train to be used to toggle other gears, or to open or close mechanically linked buildings, such as drawbridges, doors, floodgates, etc. This hybrid circuitry uses water and pressure plates as a rotation sensor. A design for a water preserving sensor exists, as does a design for a water preserving fluid memory cell.
Diagram conventions
In diagrams, gear assemblies are typically given a letter to represent them. If uppercase, the gear is non-toggled. If lowercase, the gear is pre-toggled.
Sample Logic Chains
OR Gate
PA BO
Power, supplied at the gear labeled P, will flow through either gear A or gear B to gear O, if at least one of the signals is on.
AND Gate
PABO
Power, supplied at the gear labeled P, will flow through gear A and gear B to gear O, if both of the signals are on.
NAND Gate
Pa bO
Power, supplied at the gear labeled P, will flow through gear a or gear b to gear O, if either or both of the signals is off.
NOR Gate
PabO
Power, supplied at the gear labeled P, will flow through gear a and gear b to gear O, if both of the signals are off.
NXOR Gate
PIO
Power, supplied at the gear labeled P, will flow through gear I, which is non-toggled and linked to inputs A and B, if both signals are either off or on, but not if only one of the two signals is on.
XOR Gate
PiO
Power, supplied at the gear labeled P, will flow through gear i, which is pre-toggled and linked to inputs A and B, if one, but not both, of the signals is on.
NOT Gate
PiO
Power, supplied at the gear labeled P, will flow through gear i, which is pre-toggled and linked to your input. It will transmit power if the signal is off.
Variants
XOR and NXOR gates can be built using multiple input gears. This may be wasteful when only a simple XOR gate is needed, but when more complex gates are needed, knowing how to build an XOR or NXOR gate can be helpful.
PAb BaO
The above is the equivalent of an XOR gate. To see how, you can reconfigure the diagram to make it easier to understand.
P A b PBaO
You can see here that this is two AND gates and a single OR gate. Thus, A XOR B is equivalent to (A AND NOT B) OR (NOT A AND B). Similarly, an NXOR gate can be built in more complex form:
PAB baO
Reconfigured:
P A B PbaO
So here you can see that the equivalent of A NXOR B is (A AND B) OR (NOT A AND NOT B).
Reversed Power
A given diagram is simply a path for power to flow through. As such, Power and Output gears can be exchanged at will. Thus:
PAb BaO
Is equivalent to:
OAb BaP
The only difference is where power enters the system at.
Complex Gear Chains
As an example, the following gear chain demonstrates a complex calculation using a number of inputs and some XOR and NXOR gates. The inputs are A, B, C, and S. Gear D is S NXOR B, a gear linked to A and B inputs, and non-toggled. Gear d is S XOR B, a gear linked to A and B inputs, and pre-toggled. Gear e is A XOR C, a gear linked to A and C inputs, and pre-toggled. Gear A is non-toggled, and linked to input A. Gear a is pre-toggled and linked to input A. P, as per convention, is the source of power, and O is the output gear of the chain.
PAd DaeO
To decipher this gear chain, reduce it to known paths. P, being only a source of constant power with respect to a gear chain, can be split or joined as necessary.
P A d PDaeO
At this point, we can know that the e gear will form an OR gate, because it has two input gears. The A and d gates and the D and a gates both form AND gates. The final formula is as follows: (A AND (S XOR B)) OR (NOT A AND (S NXOR B)) AND (A XOR C) With Boolean algebra, this can be reduced to: (A NXOR (S XOR B)) AND (A XOR C).