This page introduces some futile attempts to simulate digital logic circuitry with OpenTTD.
Very simple. A track signaling segment has the logical value of 1 if it occupied, 0 if not. Input signals come in via a single track, and so do outputs. Advantages: less tracks, less clutter, less complex; disadvantages: as far as I've been able to figure out, needs the clocking signals to tell the circuits when to move.
not/nand Case
Following pictures are screen captures of the not and nand
functions. The railway segments marked with signs A, B are the inputs,
not A and A nand B are the outputs (there are signals placed to show the value).
The Wclk lines (unintuitively) control reading the inputs: set it to 0 for a
sufficiently long time, and the circuits
assume the correct output values.
The Rclk lines (combined in the picture) are used to reset the gates: set to 0
after the outputs have been read.
waitingpositions; first +nand: a0b0_resetting_1.png, then +not: a0b0_resetting_2.png.
Transparent buildingsoption helps visibility: a1b1_trans.png.
Signals are carried with two tracks. Occupation of one track signifies a 0, occupation of the other is 1. The value is undefined if both or none of the tracks are occupied. Advantages: no need for clock signals; disadvantages: takes up a lot of space (due to bridge-crossings), complexity increases.
nor prototype
The pictures contain a very crude
gate. It seems to require the NPF (New Pathfinding)
patch found in newest OpenTTD versions. (Not in the 0.4.0.1 release, though, or so I've read.)
The are lots of bridges, mainly because lots of connections are required to norrelease
the train
after the state of the input lines change.
Let's take a closer look at it, shall we?
reads the inputsagain.
Now here's an useful construction: a generic two-input logic gate. You have at the Output switchboard
4 tracks, labeled An,Bm (where n, m ∈ {0, 1}), for both the Out=0 and Out=1 output lines.
Then you just connect the desired input combinations to either one of the lines. A nand gate
is pictured in the image.
Obviously it is self-evident how it works, but just for the record: the active train starts at the _gate waypoint, forks first according to A, then according to B, and ends up in one of the spots labeled A=n,B=m. There it waits for either one of the selected lines A=n and B=m to clear. When one does, the train loops back to _gate.
The image is rather big: a 1450x708px PNG. gate.png. In the picture both inputs are 0, so the train waits at A=0,B=0 and Out=1 is occupied.
Using the previous two-input gate, it is relatively easy to build a four-bit ripple-carry adder. The inputs are An for the four-bit number A, Bn for B, and output signals are Sumn for the four-bit sum, and C for carry. The circuit looks like this:
Half adder:
-----------
[Sum, C] = hadd(A, B) {
Sum = A xor B
C = A and B
}
Full adder:
-----------
[Sum, Cout] = fadd(A, B, Cin) {
[sum1, c1] = hadd(A, B)
[S, c2] = hadd(sum1, Cin)
Cout = c1 or c2
}
4-bit ripple-carry adder:
-------------------------
[Sum0, Sum1, Sum2, Sum3, C] = 4add(A0, A1, A2, A3, B0, B1, B2, B3) {
[Sum0, c0] = hadd(A0, B0)
[Sum1, c1] = fadd(A1, B1, c0)
[Sum2, c2] = fadd(A2, B2, c1)
[Sum3, C] = fadd(A3, B3, c2)
}
Putting this all together, we get a really ugly diagram.
Obviously this can be realized with 17 copies of the two-input logic gate described earlier. Which is just what I did, after adding a copy-paste kludge to OpenTTD. It does work, although it takes about two months of game-time for the carry information to ripple down. There is a picture of it, but it's... rather large: 3.3 MB, 9136 x 5504 pixels. ttd_4adder.png.
OpenTTD is not really a very good platform to simulate digital logic circuits on. Thanks to the pre-signals, it's infinitely better than original TTD (or TT), but it's still not very good. Obviously it is possible, though.