Bay 12 Games Forum

Dwarf Fortress => DF Dwarf Mode Discussion => Topic started by: jjdorf on April 23, 2010, 10:07:47 pm

Title: Pre-Triggered Mechanical Logic
Post by: jjdorf on April 23, 2010, 10:07:47 pm
I have been hard at work (in a lazy sort of way), designing a new "ideology" for mechanical logic.  Inspired by Jong's Computer (here (http://www.bay12forums.com/smf/index.php?topic=49641.0)), and with a slight refinement to one of my gates by Dorf3000 (Thanks!), The result is, I believe, a very elegant, and more importantly, water conserving logic system.  It can often use a minimum of power as well, and can be easier to build than the equivalent fluid logic gates; generally fewer mechanisms, less linking, few extra parts such as bridges, floodgates, etc., allowing more of the system to be built by dedicated mechanics dwarves, and only requiring a minimum of other construction labors.  The full Wiki page I am using as a scratchpad for my ideas is here (http://df.magmawiki.com/index.php/User:Jjdorf/Logic_Gates).

The first design ideology to consider is the following: All input signals to a gear are linked to the gear in logical true value.  This means any levers linked should be flipped on by default.  It also means that pressure plates from hybrid mechano-fluid gates are designed to be active on 0-3 water.

The second design ideology is that certain gears are pre-toggled in order to change the semantics of their logic.  This is the key to not requiring any excess power load, such as used by these (http://df.magmawiki.com/index.php/Mechanical_logic) logic gates.  A gear is pre-toggled by constructing a lever, linking it to the gear, flipping the lever, then dismantling the lever.  A pre-toggled gear costs two mechanisms to build (not counting input links).

The third design ideology is that power is truly used as just power, and there are no requirements for calculating how much power the system will need, except for knowing the maximum power draw in a circuit.  No basic mechanical logical gate draws more than 10 power for the functional parts, though power train not linked to a lever or pressure plate may draw more.

At this point, only two basic fluid using gates are part of this ideology.  The first, which is commonly called a rotation sensor, I call a Fluid Logic Buffer (FL Buffer).  It's purpose is simple: take an incoming signal from the result of a mechanical power train, including logical gates, and convert that into a signal from a pressure plate.  This outgoing signal increases the "fan-out" of the signal, by being capable of linking to very many other gears.

The second fluid using gate is a Memory cell, designed as a D-Type flip flop.  What this means is fairly simple.  When the cells has power, it's pressure plate takes on the same signal as the incoming signal, the Data signal.  If the data signal changes while the cell has power, the cell will change.  Since a pressure plate is used, there is a latency of 100 steps when the data signal drops to zero.  While the power is off, the cell retains the same value as the last Data value while it was on.  Further changes at this time to the data signal will not cause the cell to change.

Details on these gates and the design can be found at my wiki page (http://df.magmawiki.com/index.php/User:Jjdorf/Logic_Gates)

Now, however, comes the more interesting part (IMHO).  The mechanical logic gates.  Some will be familiar, others will be new to some of you.  Conventions used in gate diagrams:  Power gear or train is identified with P.  Output gear or train is identified with O.  Input signals are I, A, B, i, a, or b.  An input signal that is lower case must be pre-triggered.

ML Buffer
This is a mechanical buffer.  It takes an incoming signal (Such as from an FL Buffer), a power supply, and outputs power - 5 if the signal is on.
Code: [Select]
PIOMinus the input link, this costs only one mechanism and draws 5 power.

ML Inverter (NOT)
This is much like the buffer, except the signal is inverted.  This is done by pre-toggling the input gear.
Code: [Select]
PiOMinus the input link, this costs only two mechanisms and draws 5 power.

ML AND Gate
This is the same standard gate as most will be used to.  No pre-toggled gears in this one.  It has two input gears, A and B.
Code: [Select]
PABOMinus the input links, this costs only two mechanisms and draws 10 power.

ML OR Gate
Another of the gates most will be used to seeing.  I generally intend to build these vertically on two floors.
Code: [Select]
PA
BO
Minus the input links, this costs only two mechanisms and draws a maximum of 10 power.

ML NOR Gate
This is where the pre-toggling makes things more interesting.  Due to the nature of logic gates, inverting the inputs to an AND gate results in a NOR gate.  This is done by pre-toggling the inputs.
Code: [Select]
PabOMinus the input links, this costs four mechanisms and draws 10 power.

ML NAND Gate
Like the NOR gate, inverting an OR gate's inputs results in a NAND gate, logically speaking.  Again, this is done with pre-toggling.
Code: [Select]
Pa
bO
Minus the input links, this costs four mechanisms and draws a maximum of 10 power.

ML XOR Gate
This gate is deceptively simply, yet quite powerful.  It combines two inputs onto a single gear, which is pre-toggled.  When both inputs are on, or both are off, the gear will be disengaged.  Only when one of the two inputs is on will the gear engage.  This results in an extremely elegant XOR gate.  I cannot take credit for this one.  Thanks, Dorf3000!
Code: [Select]
PiOAgain: Both inputs are linked to the single gear (i).
Minus the input links, this costs two mechanisms and draws 5 power.

I am continuing some research, looking for ways to further my withdrawal from society... I may have taken on a secretive mood.  Or perhaps a fey mood, considering I'm not being particularly secretive (though I am drawing lots of sketches, so to speak).  Has the title of first computer design in DF2010 been claimed yet?
Title: Re: Pre-Triggered Mechanical Logic
Post by: DarthCloakedDwarf on April 23, 2010, 10:09:30 pm
Um...

Er...

I'm sure that post would be profound... if only I could understand the tiniest part of it.
Title: Re: Pre-Triggered Mechanical Logic
Post by: Daenyth on April 23, 2010, 10:35:09 pm
I eagerly await updates on this...
Title: Re: Pre-Triggered Mechanical Logic
Post by: DarthCloakedDwarf on April 23, 2010, 10:37:16 pm
I eagerly await updates on this...
In laymen's terms, preferably.
Title: Re: Pre-Triggered Mechanical Logic
Post by: furrot on April 23, 2010, 10:45:35 pm
I still don't think I'm crazy enough to play this game properly.
Title: Re: Pre-Triggered Mechanical Logic
Post by: jjdorf on April 23, 2010, 11:13:13 pm
I eagerly await updates on this...
In laymen's terms, preferably.
I'm not sure I CAN do layman's terms.  Maybe have a look see at Wikipedia's Logic Gates (http://en.wikipedia.org/wiki/Logic_gate) article?  The "gates" can be used for interesting goals, such as actual practical designs for traps or clocks or traps or automated obsidian makers... or traps...  In case you're wondering the point of all this... I plan on making an artifact computer.  I will probably be decorating my computer with images of Jong's Razorlength fortress...

And if you're going to ask me what the point of the computer is... I'm afraid there really isn't one.  Kind of like the point behind a dorf making an artifact lead flask.  One makes it to point at it and say they made that.  Not because they seriously expect a person to drink booze from a flask made of poisonous material.  Not because they seriously expect a dorfputer to be fast enough to deal with any important calculations in time to do anything useful.  Might be interesting to see if I could program a pong game in it and get dorfs to play it.  But that is in the far future of this lovely artifact computer.

Now I'm off to actually work on a proper data bus architecture...

I know, I know... layman's terms...  :)
Title: Re: Pre-Triggered Mechanical Logic
Post by: Shiv on April 24, 2010, 12:34:47 am
Quote
I still don't think I'm crazy enough to play this game properly.

+1

Fuck it, sigged too.  That was awesome.
Title: Re: Pre-Triggered Mechanical Logic
Post by: jjdorf on April 24, 2010, 01:21:54 am
Quote
I still don't think I'm crazy enough to play this game properly.

+1

Fuck it, sigged too.  That was awesome.

 :D

Okay... so my next bit to tackle, I think, is going to be designing a basic full 1-bit adder in mechanical gears, using as few mechanisms and axles as possible.

First the truth table for addition with A, B input numbers, a Carry input (Z), and two outputs, Carry out (C) and Result Output (O).

Code: [Select]
A B Z C O
0 0 0 0 0
0 1 0 0 1
1 0 0 0 1
1 1 0 1 0
0 0 1 0 1
0 1 1 1 0
1 0 1 1 0
1 1 1 1 1

With a little research, this equates to the following:

O = A XOR B XOR Z
C = (A AND B) OR (Z AND (A XOR B))

The gear assembly to produce O is remarkably simple, and uses a three input XOR gate.

Code: [Select]
PIO
A, B, and Z signals are all linked to the input gear I, which, unlike the two input XOR Gate, is not pre-toggled.  Gear I will be engaged and transferring power from P to O whenever one or three, but not two, of the inputs are true.  This matches the truth table above for O.  Like all other single gear assemblies, this only takes 5 power to run, excluding the power and output trains.

The gear assembly for C is a bit more complex, but still quite doable.

Code: [Select]
PAB
Z C
xCC

A, B, and Z gears are linked solely to their respective inputs.  The gear labeled x is a pre-toggled XOR gate linked to A and B.  The gears marked C provide the output for the Carry output function.  This would require 30 power to run, excluding power and output trains.  However, if built on two levels and properly channeled, this gear train can use two less gears and can be built only one tile wide.  From the side:

Code: [Select]
PAB
ZxC

The tiles that P and B gears rest on need to be channeled to transfer power, but there needs to be a floor between the A and x gears.  The end result is that this gear train only costs 20 power to run, excluding the cost of the power train and output train.

Combined, and still from the side, this can easily result in the following gear train for a complete full carry adder, which will only use 25 power, excluding power and output trains, and which will be exactly one tile wide, five tiles long, and two tiles high:

Code: [Select]
OIPAB
  ZxC

Now to update my wiki page, then figure out how to do look ahead carry, and maybe even have a single shot 8-bit adder unit with only a 100 step delay at most.
Title: Re: Pre-Triggered Mechanical Logic
Post by: Jong on April 24, 2010, 03:11:08 am
I claim the title of first computer design in DF.  ;)

However, I am all for new and improved designs! The more the merrier! After all, I can scarcely claim a monopoly on all the good ideas!

I still can't resist tempting you with the full details of my computer's design on post 1 on my thread. I'll just say here that the problems are not insurmountable! Even carry look ahead!

I recommend you test your output buffer/rotation sensor too. It is very important that it works reliably. I think your concept of a pressure plate that triggers when there is no water is quite interesting. From my experience, the free cycling pumps (that is, pumps where the output drains into the same body of water as the input) don't seem to conserve water, although I'm not sure why.

Title: Re: Pre-Triggered Mechanical Logic
Post by: jjdorf on April 24, 2010, 10:14:20 am
I claim the title of first computer design in DF.  ;)
I'm well aware... it's the inspiration for my madness.  :D
Quote
However, I am all for new and improved designs! The more the merrier! After all, I can scarcely claim a monopoly on all the good ideas!

I still can't resist tempting you with the full details of my computer's design on post 1 on my thread. I'll just say here that the problems are not insurmountable! Even carry look ahead!
I'm afraid that's the major part of your design I don't understand.  Specifically because I don't know what the difference between A0 and a0, etc. is in your diagrams.  Are they a normal and a pre-triggered gear assembly, or are they simply the same links to normal gear assemblies?  Also, from my research, I'm not sure if you're actually using a carry look ahead... it seems like there's not enough circuitry on the side of the most significant bit...

Quote
I recommend you test your output buffer/rotation sensor too. It is very important that it works reliably. I think your concept of a pressure plate that triggers when there is no water is quite interesting. From my experience, the free cycling pumps (that is, pumps where the output drains into the same body of water as the input) don't seem to conserve water, although I'm not sure why.
Yeah, I do need to test it still, specifically in the aspect of ensuring that it never runs out of water.  My expectation, however, is that if it is properly filled to 7/7 water before the pump turns on, it will act like the Dwarven Water Reactor does, and magically transfer the first tile of water from the plate and push it constantly up to the pump output tile.  I'll be doing a step by step test of this, however, verifying that my assumption is indeed fact.  If a 1/7 spot of water is ever visible on the pressure plate while the pump is active, it will not conserve water, though it may take a LONG time to lose it.

So many things to test...
Title: Re: Pre-Triggered Mechanical Logic
Post by: Rotten on April 24, 2010, 10:21:58 am
I audibly laughed when I saw that XOR gate, because it was the exact same design I tested in a logic test fort a week back. Heh.
The problem with it, though, is that it needs pressure plates or a lever to trigger it (I'm working on no water at all logic gates that work with power amounts and gear resistors). I don't know how much water you plan on using, but a single tile for each gate adds up.
Title: Re: Pre-Triggered Mechanical Logic
Post by: tweinst on April 24, 2010, 10:23:24 am
Won't water pressure immediately drop the 7/7 water from the output square back on top of the pressure sensor?
Title: Re: Pre-Triggered Mechanical Logic
Post by: jjdorf on April 24, 2010, 11:25:43 am
I audibly laughed when I saw that XOR gate, because it was the exact same design I tested in a logic test fort a week back. Heh.
The problem with it, though, is that it needs pressure plates or a lever to trigger it (I'm working on no water at all logic gates that work with power amounts and gear resistors). I don't know how much water you plan on using, but a single tile for each gate adds up.
Yes, that is it's downfall, as my research into the 8-bit adder is proving.  It makes it not the most useful design as anything but an input.  Unfortunately, the gear resistor (I like that, btw) design is fidgety and depends on all of the pathways that all power takes through your system.  I may look into using it at certain points of my adder to make it do an instant gear calculation, but I honestly don't like using gear resistors.  (Load gear trains for people looking at the wiki article on mechanical logic)
Won't water pressure immediately drop the 7/7 water from the output square back on top of the pressure sensor?
If my expectation is correct, that water is instantly sucked up by the pump.  I will still need to test, but I believe it will only work when there is exactly 28 units of water in the system.  27 and it should act exactly like you expect, with water falling in then getting sucked up a step later.  This is from my experience with the Dwarven Water Reactor design, which I'll duplicate for you.
Code: [Select]
XXXXX  Bottom Level, 7/7 water in ~ tiles.
X~X~X
X~X~X
X~X~X
XX XX
 XXX

XXXXX  Top level, with 7/7 water magically staying
XW~WX  at the north spots of the water wheels, and
XW^WX  at the ~ tile.  <% is a water pump, pumping
 W%W   north.
  . 
The floors under the water wheels are channeled out.  You begin filling the channels with water.  When the water level is at about 3-4/7, have a pump operator manually start the reactor.  Continue filling it with water until the magic happens, 7/7 water in exactly nine tiles, the water wheel channels, and the north end of the reactor design's top level.  I don't know why, but it works, and will never stop unless you block the pumps input tile with a floor or hatch.  And when it stops it should spill 14 units of water.  Which you'll then need to replace when you start it up again.  This design produces 170 surplus power.  Other variants can be made that will provide different amounts of power.  A mini reactor with just one water wheel can produce 80 power perpetually.  Larger versions add the mini reactor to one side or the other of the above design, and each extension of a pump and waterwheel will provide an additional 80 power.  This is what I plan to power my computer with, though I believe I'm going to plan for a water cistern for all the water I'll be using to fill up these things.  I'll still have to top them off after the fact, but it won't be so mind numbingly bothersome to get the first level of water in the things.
Title: Re: Pre-Triggered Mechanical Logic
Post by: jjdorf on April 24, 2010, 11:26:28 am
Now to update my wiki page, then figure out how to do look ahead carry, and maybe even have a single shot 8-bit adder unit with only a 100 step delay at most.
Okay, from what I've seen, a Carry Look Ahead design needs a changed basic adder unit.  I'm going to start the design here and see how far my insanity takes me.  The adder that is needed is called a partial adder, and it supplies from the inputs of the two input numbers, a propagate value and a generate value.  I'm not going to explain these... because I only slightly understand them.  Suffice to say, this method works.  The propagate value (which I will be diagramming as R, because P is power) is A XOR B.  The generate value (G) is A AND B.  So the partial adder looks like this:
Code: [Select]
rPABIn fact, anywhere we need the Propagate or Generate values, we can simply run power through the pre-toggled A XOR B gear or the normal AB gear train.
Now for the CLU (Carry Look Ahead Unit).  A carry for a given bit position x is defined as follows:
Cx=Gx-1 OR (Rx-1 AND Cx-1)
Gear assemblies for OR values and AND values make this calculation simple enough.  I will diagram Cx as a gear labeled C, and Cx-1 as a gear labeled Z.
Code: [Select]
PAB
rZC
Note, that this diagram is from the side, and the floor is left between the A and Z gears to prevent a connection there, while the floors between P and r, and between B and C, are channeled away.  Also note that this starts with the partial adder circuit, with the r gear rotated to underneath the power input.
The difficulty now comes in the form of that Z gear, which must reflect all the same logic but for the previous bit.  And this is where I am hung up.  One cannot simply connect each stage via axle, as that merely creates an AND relationship.  There are two options: reduplicate the circuitry at the Z location, spreading each additional stage out to account for the new circuitry; or, use a rotation sensor on the end of each stage.  The rotation sensor is needed anyway for the final calculation, but it will introduce a ripple effect, causing the same slow response that a basic ripple adder would cause, making this whole concept pointless.

I will have to continue researching this...  Jong... Any help?
Title: Re: Pre-Triggered Mechanical Logic
Post by: Jong on April 24, 2010, 11:43:45 am
I'm afraid that's the major part of your design I don't understand.  Specifically because I don't know what the difference between A0 and a0, etc. is in your diagrams.  Are they a normal and a pre-triggered gear assembly, or are they simply the same links to normal gear assemblies?  Also, from my research, I'm not sure if you're actually using a carry look ahead... it seems like there's not enough circuitry on the side of the most significant bit...

Hmm.. I think my convention is opposite to yours. The capital letter labelled gears are by default off, which means they are pretoggled in your terminology. Most of the gears in my computer have been pretoggled as shown by the massive preponderance of orthoclase gears in my build.

As for my carry circuit, I worked out a scheme to recycle the output of the previous (less significant) bit's carry calculation.
(http://img69.imageshack.us/img69/4012/carrycircuit.png)
The blank gears in the middle are the output collecters to power C1 but they also double up as an input into the next carry calculation.

I worked out this method by using Boolean Algebra to simplify the more complex systems used in real life carry look ahead systems. I found that the basic logic is ridiculously simple.

Essentially, a carry signal is only produced in 4 cases: when A and B are 1, when A and B and the previous carry are 1, when either A or B is 1 and the previous carry is 1. My final design is optimized to occupy the minimum amount of space, so the logic pathways aren't immediately obvious but this system is equivalent.

Code: [Select]
o=o=o=o=Cout
A A A a
B B b B
c C C C
P P P P

In this manner I found I could ditch all the propagate and generate signals that need to be calculated.

As for optimization, the first two logic pathways are redundant and I reduced them to simply A AND B. I also only need 1 C and P for the remaining two pathways and I can redistribute the power after that. Also, oppositely toggled gears of the same input can be placed next to each other without fear of power transmission.

The OR logic cannot be compacted down however, because I chose to directly hook the output power of the previous carry circuit as the input power supply of the subsequent carry circuit. I need to retain the lower case gears to avoid reverse power transmission, if A and B are both active.

Directly hooking the output of the previous carry circuit to the next carry circuit removes the need for any rippling sort of effect, so this system generates all the carry bits instantaneously and simultaneously.

Wow... you post quickly, hang on while I read your new posts....
Ok, I think I answered your question.
Title: Re: Pre-Triggered Mechanical Logic
Post by: jjdorf on April 24, 2010, 12:01:12 pm
Wow... you post quickly...
Nah, just had that second post ready to go, the forum futzed on me a bit, and I answered with the previous post before pasting the last post in and posting.  I'll be studying your design now to see what I can make of it.  It may end up that your ALU is the ALU to use, mechanically speaking.  Hope you don't mind.  ;)
Title: Re: Pre-Triggered Mechanical Logic
Post by: Shinziril on April 24, 2010, 12:08:17 pm
If you look carefully at Jong's carry-look-ahead circuit, what it seems to be doing is taking the input of the adder and calculating *all* the carries in a row by using the previous carry in addition to the input signals, separate from the main adder.  It then reroutes the carry-outputs into the main addition circuit in the appropriate places simultaneously, allowing it to calculate the correct value instantly.  I think I'll mess around with designs for this myself . . . we'll see if I come up with anything useful.

EDIT: I also noticed a slight problem with the design for the rotation sensor.  It should work as specified when filled to 7/7 water in all tiles; however, dwarfs filling a pond zone will only fill it up to 6/7 water*.  This can be overcome by designating the pond zone on the level above and then carefully monitoring the amount of water that has been input until it is exactly full, then deleting the pond zone. 

*That is, they will keep dumping buckets of water into the hole until the tile directly below the hole is at 6/7 water.  Thus, if the hole is an extra z-level above what you are actually filling, they will happily dump buckets into it forever, or until you tell them to stop.
Title: Re: Pre-Triggered Mechanical Logic
Post by: wallie79r on April 24, 2010, 02:56:27 pm
Oh, gods no. Its finals week, and now I'm stuck considering alternate design theories for basic mechanical logic. Cease your siren call, dwarven wrench!
Title: Re: Pre-Triggered Mechanical Logic
Post by: Meteorswarm on April 24, 2010, 03:33:06 pm
Two things:

I've designed a 32-bit carry-lookahead adder in electric gates for a class (broken into 4-bit tiers for sanity), so if you want to look at my circuitry, I'll be happy to share it, but since there's no gate delay with gears and you figured out how to pass the signals, a ripple-carry adder will be just as good.

But, I'm skeptical of the operability of your pre-toggling.  With doors and floodgates and bridges, pre-toggling has no effect; the first signal is ignored, and then they revert to their normal operation, which is why you need to use floodgates AND bridges in fluid logic designs, since their neutral states have opposite logical meanings.

Have you tested your designs physically?  If they work, I'll be very excited, since it means we can feasibly create real circuits, particularly your adder is much more convenient than usual adders are.

If only there were a way to do all of this without linkages, though, or to have linkages triggered by power.
Title: Re: Pre-Triggered Mechanical Logic
Post by: Shinziril on April 24, 2010, 04:07:48 pm
Pre-toggling *only* works in the mechanical logic, as you mention.  You just use the "rotation sensor", possibly with the pressure plate inverted from its normal sense, at the end of the line, in order to convert it into the correct signals to various other components.  Essentially, the ability of gears to "toggle" rather than be state-based is the reason we are using mechanical logic with fluid logic "buffer" gates rather than simply using fluid logic for everything. 
Title: Re: Pre-Triggered Mechanical Logic
Post by: jjdorf on April 24, 2010, 04:50:00 pm
EDIT: I also noticed a slight problem with the design for the rotation sensor.  It should work as specified when filled to 7/7 water in all tiles; however, dwarfs filling a pond zone will only fill it up to 6/7 water*.  This can be overcome by designating the pond zone on the level above and then carefully monitoring the amount of water that has been input until it is exactly full, then deleting the pond zone. 

*That is, they will keep dumping buckets of water into the hole until the tile directly below the hole is at 6/7 water.  Thus, if the hole is an extra z-level above what you are actually filling, they will happily dump buckets into it forever, or until you tell them to stop.
Yes... I've seen this also.  I'll have to take the dwarven insistence that 6/7 is full with pond orders into account in my build plans.  Also, at work today (while dead and no business coming in, ugh) I had time to look at and truly understand Jong's solution.  I am IMPRESSED.  It works perfectly as the CLU in a two stage adder circuit.  I tried making the adder one stage only, with direct outputs, but, unfortunately, this is impossible.  A fluid Buffer is necessary per bit of operation.  However, my concept of a triple input XOR gear is more elegant than the equivalent triple input XOR (needed for the final calculation of A + B + Carry) he uses.  Simply, link those inputs to a single gear and have it drive the final output sensor.  I also intend to design a specialized version of the Adder for use in my program counter circuitry, so that I don't have to co-opt the ALU for moving to the next instruction in memory.

I also learned four things:

First, my original plan for an XOR circuit is just as important as the plan currently on my wiki page, since it demonstrates that an XOR can be built of more fundamental gates.  This is what I was not understanding about Jong's adder diagrams.

Second, Gears should be thought of as being of three types:  Driven by an input and non-toggled, Driven by an input and pre-toggled, and Undriven.  Undriven gears are not linked to any lever or pressure plate.  They will always pass power if there is a path.  Driven gears will only pass power if their input source is true (for non-toggled driven gears), or false (for pre-toggled driven gears).

Third, Two gears, both driven by the same input, adjacent, with one pre-toggled, but not the other, will NEVER transmit power from one to the other.  I am going to call this arrangement as being "out of phase", because when one is engaged, the other is disengaged... ALWAYS.

Fourth, To fully understand a gear circuit on paper, make copies.  For each copy, set the values of driven gears appropriately for a given set of inputs to 1 or 0 (by replacing the gear in the diagram).  A gear must be non-toggled and have an input of 1, or pre-toggled and have an input of 0, in order to have a 1 as its value; all other driven gears are 0.  Then, start at the power gear(s) and replace that with a 1 to indicate the circuit has power.  Follow the path of the 1 gears orthogonally until there are no more paths to take.  You cannot transfer power from a 1 gear to a 0 gear.  You cannot transfer power from a 1 gear that is isolated from a power source, i.e.: you must be able to trace back to a power gear.  If an output gear is reached, its output will be 1, no matter what.  If an output gear is never reached, its value is 0.  This allows a person to test and verify a PTML circuit before and without ever building it.

To demonstrate the third and fourth principles listed here, I will diagram and demonstrate an XOR chain.
Code: [Select]
PAb
BaO
P is power, A is non-toggled linked to input 1, B is non-toggled linked to input 2, a is pre-toggled linked to input 1, b is pre-toggled linked to input 2, and O is the output gear.  Note that the A and a gears are out of phase, and thus, will never transfer power to each other.

AB = 00
Code: [Select]
PAb  P01  101
BaO  01O  010

AB = 01
Code: [Select]
PAb  P00  100
BaO  11O  111

AB = 10
Code: [Select]
PAb  P11  111
BaO  00O  001

AB = 11
Code: [Select]
PAb  P10  110
BaO  10O  100

Two things:

I've designed a 32-bit carry-lookahead adder in electric gates for a class (broken into 4-bit tiers for sanity), so if you want to look at my circuitry, I'll be happy to share it, but since there's no gate delay with gears and you figured out how to pass the signals, a ripple-carry adder will be just as good.
No need.  In actual fact, contrary to the nature of electronics, Jong's design is perfect and works even better than the electronic equivalent.  One can easily build an n-bit CLU from his design with minimal complexity.  This is what threw me, as I was expecting to see a great amount of circuitry growing even more towards the MSB of the adder.  With gear logic, more circuitry is not needed.  And what's more important is that the result is a guaranteed two phase process.  The first 100 steps accumulates the carry values all at once.  The second 100 steps adds those values and the original AB inputs.
Quote
But, I'm skeptical of the operability of your pre-toggling.  With doors and floodgates and bridges, pre-toggling has no effect; the first signal is ignored, and then they revert to their normal operation, which is why you need to use floodgates AND bridges in fluid logic designs, since their neutral states have opposite logical meanings.
PTML never touches doors, floodgates, bridges, etc., unless you want the end result, say of a computer's GPIO block, to affect the status of such constructions.  And when that happens you are using a truth value from the end result, not from halfway through the calculation.  I think Shinziril may explain this better than I do, too.
Quote
Have you tested your designs physically?  If they work, I'll be very excited, since it means we can feasibly create real circuits, particularly your adder is much more convenient than usual adders are.

If only there were a way to do all of this without linkages, though, or to have linkages triggered by power.
Yes, I have tested enough of these designs to know for a fact that they work, and using my methodology for tracing the truth value in a PTML circuit, anyone can verify that a design works, without ever needing to build it in game to be certain.  This methodology is how I verified to myself that Jong's CLU circuitry does function exactly as needed.
Oh, gods no. Its finals week, and now I'm stuck considering alternate design theories for basic mechanical logic. Cease your siren call, dwarven wrench!
:D  Sorry... I think?

Coming soon:  The full design for my 8 bit adder unit, including details for implementing subtraction.
Title: Re: Pre-Triggered Mechanical Logic
Post by: jjdorf on April 24, 2010, 05:27:31 pm
The 8-bit Adder Module, including optional subtraction of input B.

This takes two 8 bit numbers, A and B, and an additional input Z.  Z is false if we are adding, true if we are subtracting.

First, we need the initial carry value as an "endcap":
Code: [Select]
  *ZP

Each bit in the adder is built with the following circuitry, and each A, B, a, and b are for the current incoming bits:
Code: [Select]
  CC
PBAa  PS
  bB
Note that the C gears are undriven, and one is used as the input to a rotation sensor.  Also note that the b and B gears have a second input, Z, the initial carry value.  The final sum gear, S, is non-toggled and linked to the output of the rotation sensor connected to the corresponding C gear, the A input, the B input, and the Z input.  It is, essentially a four input XOR gate.

The complete design, excluding the rotation sensors, is as follows:
Code: [Select]
  CC
PBAa  PS
  bB
  CC
PBAa  PS
  bB
  CC
PBAa  PS
  bB
  CC
PBAa  PS
  bB
  CC
PBAa  PS
  bB
  CC
PBAa  PS
  bB
  CC
PBAa  PS
  bB
  CC
PBAa  PS
  bB
  *ZP
There will be rotation sensors under one of every pair of C gears, and under each S gear.  The sensors under the S gears provide the added value.  Subtraction of B is enabled any time the Z input is on.  This is done because in binary numbers, the negative of a number is the logical inverse plus one.  Thus, any instruction set using this assembly needs to ensure that the opcode for adding uses a zero in a bit that the opcode for subtraction has a one at.  This bit in the opcode can then be used to enable or disable subtraction from just one bit of the opcode.  Jong's instruction set in the Razorlength computer has this feature, and mine will as well.
One can plainly see that this adder can be extended to any number of bits by simply constructing more bits of the CLU and final Summer.  This design could add 1024-bit numbers as easily and swiftly as it adds 8-bit numbers, with respect to the number of frames used.  The actual game, however, would slow down, obviously.

I still have to finalize my idea for a data bus, which, for my design will be 8 bit data, 8 bit address, a power supply line and a read/write signal.  The clock will be co-opted into the power supply line.  I am debating whether I am going to have one quarter of the memory be utilized by CPU registers, or if I am going to leave them off of the data bus.  That's where I'm at at the moment.  A preliminary diagram of a connection to the data bus for the curious:

Code: [Select]
||||||||||||||||||
|D|D|D|D|D|D|D|D|P
A|A|A|A|A|A|A|A|W|
||||||||||||||||||

Funny how it turns out to look similar to the staggered pinout on an actual AGP card....

One of the potential benefits of the data bus will be that I can build a smaller amount of memory initially for testing purposes, then add more to it, by using a sequence of AND gates on the higher portion of the address lines to enable or disable reads and writes.

Something like the following:
Code: [Select]
   __
P7654E
Where the numbers with lines over them are pre-toggled.  The boolean equation for this would be, P AND 7 AND 6 AND NOT 5 AND NOT 4.  Meaning the power would only transfer if we are addressing memory module number 12 of 16.  This AND-chain would be needed on each incoming and outgoing bus line to a device.  Come to think of it.... I may simply eliminate the address lines for the higher bits that address the correct module... nope.  I'll have to.  Now I'm just rambling aloud.  I really should withdraw from society again...
Title: Re: Pre-Triggered Mechanical Logic
Post by: Shinziril on April 24, 2010, 05:41:18 pm
Here's (http://mkv25.net/dfma/map-8582-woundrider) a link to my constructed version of that adder (I was working on it at the same time, and apparently came up with the same idea you did).  It's not fully complete yet, and I think I managed to mess up the subtract-selector logic somehow (it seems to be giving me the bitwise inverse of the correct answer), but you can see how I set up the "support framework" around the logic and kept it as compact as possible.  I also like that I managed to use a single powertrain to power the entire assembly. 

If you're having trouble comprehending it due to the fact that all the gears look the same, take the diagram for Jong's carry logic unit and rotate it counterclockwise 90°.  The top three rows of gears are oriented in exactly that pattern, and the bottom row is the triple-XOR combiner unit. 
Title: Re: Pre-Triggered Mechanical Logic
Post by: jjdorf on April 24, 2010, 07:10:13 pm
Here's (http://mkv25.net/dfma/map-8582-woundrider) a link to my constructed version of that adder (I was working on it at the same time, and apparently came up with the same idea you did).  It's not fully complete yet, and I think I managed to mess up the subtract-selector logic somehow (it seems to be giving me the bitwise inverse of the correct answer), but you can see how I set up the "support framework" around the logic and kept it as compact as possible.  I also like that I managed to use a single powertrain to power the entire assembly. 

If you're having trouble comprehending it due to the fact that all the gears look the same, take the diagram for Jong's carry logic unit and rotate it counterclockwise 90°.  The top three rows of gears are oriented in exactly that pattern, and the bottom row is the triple-XOR combiner unit.
The biggest problem with DFMA maps is that you cannot tell what gear is linked to what, sometimes even when you use multi-colored gears.  This makes such maps extremely difficult to decipher, even more so than my current method of diagramming.

I'm still trying to decide on my data bus idea.  Three things I need to decide.  First, how many bits of the 8-bit address will reference a memory module.  I'm hovering at choosing 2 or 3 bits, making an address into VVAAAAAA or VVVAAAAA, where the V bits are device selectors and the A bits are address selectors within a device.  The second decision:  Whether I want to include the device selection bits in the data bus physically, or whether they should only be included in AND gates at each bus input section, pre-wired for correct operation.  The third decision:  Whether the CPU internal registers will be memory addressable (though not writable by the memory writing instruction).  If they are memory addressable, I will need extra logic for read/write selections internally.  If they are hardwired and not visible to memory, then they won't be a part of the data bus in any way.

I'm fairly certain that the data bus itself is going to end up as a stack of gears and vertical axles, with devices alternating on either side of the bus structure.  Two device bits will mean the bus will only have four devices allowed.  The bus would end up being at least 4 z-levels high, with the bottom two levels being shared by two devices and the top two levels being shared by the other two devices.  The "connectors" could be spaced apart and even extended if necessary.  Considering this, I'm going to go with a two bit device identifier.  This leaves 6 address bits for device internal memory, and means each device on the bus will have 64 addressable bytes of data.  I think one of the devices I'm going to develop is going to be a display adapter, monochrome.  It will be a 32 by 16 pixel display, where every pixel is a colored floor hatch.  Each row will be 4 bytes.

My first draft design for the data bus is as follows:

8 bits of data, driven through axles and gears.
6 bits of device address, driven through axles and gears.
1 write enable, driven through axles and gears.
1 read enable, driven through axles and gears.
2 bits of device selector, as pressure plate links to the device selector circuitry.

The layers of a bus connection will look like this (with + being a vertical axle, which can be dropped on either the top or the bottom of the bus, depending on where the "driver" of the bus is):
Code: [Select]
y y y y y y y y
X X X X X X X X
D+D+D+D+D+D+D+D+
X X X X X X X X
Y Y Y Y Y Y Y Y

 y y y y y y y y
 X X X X X X X X
+A+A+A+A+A+A+R+W
 X X X X X X X X
 Y Y Y Y Y Y Y Y
This view shows how the device selectors will work.  X and Y inputs are the device selection inputs.  Since the north side of the bus uses X and y gears, it will enable when the device selected is device 10, or 2.  The south side of the bus uses X and Y gears, so it corresponds to device 11, or 3.  The other two devices would use xY and xy gears to enable.  I have dropped my idea for power supply via the data bus.  Instead, I am doing what I needed to do, make separate Read and Write enable lines.
Title: Re: Pre-Triggered Mechanical Logic
Post by: jjdorf on April 24, 2010, 08:02:54 pm
A big Major notice to everyone following along.  I just tested the rotation sensor.  Not only does it function, but it conserves water completely when primed with 7/7 water in the bottom layer as I specify in the design.  When the pump gets turned on, the tile where the pressure plate goes gets zero water.  None at all.  Exactly as intended.  I let it run for well long enough to verify that no frames ever allow any water in that tile.  It's as if the pump makes a wall of water right at the edge there.  In fact, just as I planned, you could do maintenance on the pressure plate while powering the pump.  Because there isn't any water in the tile when the pump is on.  I have a movie if anyone is interested in seeing it in action, though my test leaves out the pressure plate as unnecessary.

Edit:  Changed "my design" to "the design", since I actually did not originate this idea.
Title: Re: Pre-Triggered Mechanical Logic
Post by: jjdorf on April 24, 2010, 10:00:32 pm
This view shows how the device selectors will work.  X and Y inputs are the device selection inputs.  Since the north side of the bus uses X and y gears, it will enable when the device selected is device 10, or 2.  The south side of the bus uses X and Y gears, so it corresponds to device 11, or 3.  The other two devices would use xY and xy gears to enable.  I have dropped my idea for power supply via the data bus.  Instead, I am doing what I needed to do, make separate Read and Write enable lines.

In retrospect, the read and write lines are also not physically needed.  This will be controlled via another FL Buffer operated signal, which will fan out to all of the devices.  The new design:

Code: [Select]
y y y y y y y y
X X X X X X X X
D+D+D+D+D+D+D D
X X X X X X X X
Y Y Y Y Y Y Y Y

 y y y y y y
 X X X X X X
+A+A+A+A+A+A+ +
 X X X X X X
 Y Y Y Y Y Y

Each input group (the XY gear assemblies) can be moved further from the bus when necessary to make logic work.  Specifically, this will be needed for the data lines if Read/Write access to the module is necessary.  From the side, a data line with Read/Write access will look something like this:

Code: [Select]
D--EXYR
     r
The floor between the Y gear (whether it is pre-toggled or not, based on the device selection) and the lower r gear is channeled out.  On a positive Read signal, the R gear will engage and the r gear will disengage.  When memory access for either write or read is disabled, the E signal, which controls the E gear, will be off.  This will disengage the E gear and prevent writing to the memory bus when not needed.

I am considering, still, whether the bus can/should be used for accessing internal registers.  Though, at this point I am certain I do not want the registers to be readable through the memory address space, I wonder if this bus circuitry is better suited to enabling writes and reads to the registers.
Title: Re: Pre-Triggered Mechanical Logic
Post by: Jong on April 25, 2010, 05:24:49 am
The idea of linking multiple inputs to a single gear is really brilliant. You must direct me to the post where it was first mentioned.

Anyway I was inspired to create a scheme for a single stage carry look ahead adder. The idea was that I could rearrange the gears in the sum circuit such that the C gears were at the root of the logic tree, or in other words closest to the power source. In this manner, the availability of the power supply can substitute for the triggered gear. So I could directly hook up the adder to the output of the carry logic circuit.

However this necessitates the inclusion of an inverse carry logic circuit so that the inverse c gears can also be similarly substituted.

This was the result.

(http://img219.imageshack.us/img219/7431/singlestageadder.png)

I used a colouring convention here to indicate the default state of the gear, which also indicates whether it is pretoggled or not. The light coloured gears are by default disengaged so they are the pretoggled ones.

I was reading your posts a little more carefully because I was wondering how your adder worked. Then I realized that the single gear labeled S was a triple input gear that substituted for the whole adder. I was pretty astounded.

So I was inspired once again to replace most of my adder's logic with double input gears. The amount of optimization is really staggering.

(http://img519.imageshack.us/img519/41/singlestageadder2.png)

This modified circuit is identical in function to the previous one and has far fewer gears.

The gears marked A/B # are your pretoggled double input XOR gates. The gears marked AB # are the same but they are not pretoggled. I discovered that this configuration combines an AND gate and a NOR gate, which just so happens to be applied in the adder.

 I believe I have really outdone myself this time.

EDIT: I found the post! Hmm.. I think in most cases it won't be necessary for the inputs to arrive at exactly the same moment. Here's something you can try to see if it breaks. You can link a lever multiple times to the same object before the first link job is completed. I tried linking a gear twice to the same lever to see what would happen. Pulling it didn't do anything as expected. You could try it with more linkings and see if the relationship holds up.
Title: Re: Pre-Triggered Mechanical Logic
Post by: se5a on April 25, 2010, 06:18:15 am
Cease your siren call, dwarven wrench!

I see what you did there.


Man, I wish I had the patience to do a full out dwarven computer.
I've messed around (in my head, don't think I got around to creating it) with AND and OR gates, for just simple water level on a waterfall control.
Title: Re: Pre-Triggered Mechanical Logic
Post by: Jong on April 25, 2010, 08:41:41 am
I noticed you intend to create a display device. 32x16 right?

My concern is that with only 8-bits you may have insufficient memory to store an image to display. I'm not entirely sure how your data scheme works but my computer was also 8-bits and it faces a number of constraints.

The 8-bit instruction size allowed for 8 instructions and 32 memory addresses. With 8-bits each, this comes to a grand total of 256 bits. A 32x16 display has 512 pixels! If you cut down the number of instructions to 4 and the addresses to 64, that comes to 512 bits of memory, at the cost of a truncated instruction set and having no room for programs!

Well I think your computer's architecture is rather unusual. Your bus design seems to incorporate separate paths for data and address/instructions I think, which doesn't fit into the Von Neumann model my computer used. Could you elaborate on your overall computer design?

However adding even more memory is a big challenge. My design for memory cells is still a tremendous real estate hog. This is mainly because it uses pumps in its operation. I was thinking a fluid logic inspired system could potentially be more efficient, as it could use hatches or doors, which could take much less space. Its all about the management of the water sitting on the pressure plate, which is just a single tile.
Title: Re: Pre-Triggered Mechanical Logic
Post by: jjdorf on April 25, 2010, 11:42:19 am
The idea of linking multiple inputs to a single gear is really brilliant. You must direct me to the post where it was first mentioned.
Thank Dorf3000 for this idea.

Quote
Anyway I was inspired to create a scheme for a single stage carry look ahead adder. The idea was that I could rearrange the gears in the sum circuit such that the C gears were at the root of the logic tree, or in other words closest to the power source. In this manner, the availability of the power supply can substitute for the triggered gear. So I could directly hook up the adder to the output of the carry logic circuit.

However this necessitates the inclusion of an inverse carry logic circuit so that the inverse c gears can also be similarly substituted.

This was the result.

(Big Intimidating Image)

I used a colouring convention here to indicate the default state of the gear, which also indicates whether it is pretoggled or not. The light coloured gears are by default disengaged so they are the pretoggled ones.

I was reading your posts a little more carefully because I was wondering how your adder worked. Then I realized that the single gear labeled S was a triple input gear that substituted for the whole adder. I was pretty astounded.
Yes, I liked that part too...
Quote
So I was inspired once again to replace most of my adder's logic with double input gears. The amount of optimization is really staggering.

(Smaller Intimidating Image)

This modified circuit is identical in function to the previous one and has far fewer gears.

The gears marked A/B # are your pretoggled double input XOR gates. The gears marked AB # are the same but they are not pretoggled. I discovered that this configuration combines an AND gate and a NOR gate, which just so happens to be applied in the adder.

 I believe I have really outdone myself this time.
Yes.  Yes you have.  Fewer gears and single stage adding is awesome.  It means my computer architecture will be even safer.  I plan on using a four phase cycle for it: Instruction fetch, Operand Fetch, Instruction Pointer Increment, then Execute.  A single stage adder means all of the things I'm planning on pre-calculating while the timer is progressing through the fetch and increment stages will be completely guaranteed to be done by the execute phase is reached.  More on this later on...

Quote
EDIT: I found the post! Hmm.. I think in most cases it won't be necessary for the inputs to arrive at exactly the same moment. Here's something you can try to see if it breaks. You can link a lever multiple times to the same object before the first link job is completed. I tried linking a gear twice to the same lever to see what would happen. Pulling it didn't do anything as expected. You could try it with more linkings and see if the relationship holds up.
Yeah, that was just me worried that the gear might not toggle if two signals are received at the exact same time step.  I tested and verified that the gear toggles correctly, though I never thought to just use a doubly linked lever.
I noticed you intend to create a display device. 32x16 right?
Yup.  In a bit I'll show off the instruction set, the register set, the memory's address space, and my timing cycle.

Quote
My concern is that with only 8-bits you may have insufficient memory to store an image to display. I'm not entirely sure how your data scheme works but my computer was also 8-bits and it faces a number of constraints.

The 8-bit instruction size allowed for 8 instructions and 32 memory addresses. With 8-bits each, this comes to a grand total of 256 bits. A 32x16 display has 512 pixels! If you cut down the number of instructions to 4 and the addresses to 64, that comes to 512 bits of memory, at the cost of a truncated instruction set and having no room for programs!
My instructions will be 8 bits for the opcode, and some instructions will have an additional 8-bit operand.  Specifically, memory addresses will be 8, not 5, bits.  This gives me 256 addressable bytes, or 2048 bits of addressable memory.  I do notplan on constructing every last one of these immediately.  Thus I needed to have the bus designed and constructed so that I could, like real memory chips, "plug in" a new bank of memory when I decided to make more.  It also means one of the bus devices will be a 512 bit monochrome display.  Initially, I'm going to place the display in bank 11, and have only one bank of RAM at 00.  That first bank of RAM will actually be slightly special, too, as it will also have a couple General Purpose Input bytes and a couple General Purpose Output bytes.  GPI will be linkable to any lever or pressure plate anywhere.  Such as a lever for controlling the computer.  It'll be like a custom configurable keyboard, of sorts.  The GPO will be used for general operation of hatches, bridges, doors, etc.  I'm putting these in for completeness, more than any other reason.  More on the structure later.

Quote
Well I think your computer's architecture is rather unusual. Your bus design seems to incorporate separate paths for data and address/instructions I think, which doesn't fit into the Von Neumann model my computer used. Could you elaborate on your overall computer design?

However adding even more memory is a big challenge. My design for memory cells is still a tremendous real estate hog. This is mainly because it uses pumps in its operation. I was thinking a fluid logic inspired system could potentially be more efficient, as it could use hatches or doors, which could take much less space. Its all about the management of the water sitting on the pressure plate, which is just a single tile.
Yeah, real estate is going to be the big problem on this one.  I'll be upping the z-levels between layers greatly in my world-gen when I actually move out of design and into building.  I'll probably end up wanting a good 20 layers of solid rock available to play with.  I'll also be turning off HFS for this.  Now that I think about it, isolated from everything but dwarves would also be a good idea, though that usually results in untamed wilds, and knowing DF2010's military hit and miss bugginess, I want as little fighting to do as possible.

Now... The Instruction Set (Preliminary, not QUITE set in stone yet)
One Byte Instructions
NOP:00000000 - No Operation (WE:-, RE:-,Length:1)
HLT:00000001 - Halt Computer (WE:-, RE:-,Length:1)
SHL:0x000010 - Shift Left Logical (x2) (WE:R0, RE:RSLT,Length:1)
SHR:0x000011 - Shift Right Arithmetic (/2) (WE:R0, RE:RSLT,Length:1)
NOT:0x000100 - Bitwise Not (WE:R0, RE:RSLT,Length:1)
AND:0x000101 - Bitwise And (WE:R0, RE:RSLT,Length:1)
OR:0x000110 - Bitwise Or (WE:R0, RE:RSLT,Length:1)
XOR:0x000111 - Bitwise Xor (WE:R0, RE:RSLT,Length:1)
ADD:0x001000 - Add, R0 = R0 + R1 (WE:R0, RE:RSLT,Length:1)
SUB:0x001001 - Subtract, R0 = R0 – R1 (WE:R0, RE:RSLT,Length:1)
SWP:0x001010 - Swap Registers, R0, R1 = R1, R0 (WE:-, RE:-,Length:1)
NNC:00001011 - Increment Index Register (WE:N, RE:NP,Length:1)
NDC:00001100 - Decrement Index Register (WE:N, RE:NM,Length:1)
Machine Code including x as the second bit disables the WE and RE signals for that operation, which turns ALU commands into test commands that do not subsequently affect the final product of R0.
Two Byte Instructions
LDR [mem]:10000001 [m] - Load Register From Memory (WE:R0, RE:MEM[OP],Length:2)
STR [mem]:10000010 [m] - Store Register To Memory (WE:MEM[OP], RE:R0,Length:2)
LDI [mem]:10000101 [m] - Load Indexed Register From Memory (WE:R0, RE:MEM[OP+N],Length:2)
STI [mem]:10000110 [m] - Store Indexed Register To Memory (WE:MEM[OP+N], RE:R0,Length:2)
LDC [const]:10001000 [c] - Load Register From Constant (WE:R0, RE:OP,Length:2)
NDX [const]:10001001 [c] - Load Index From Constant (WE:N, RE:OP,Length:2)
JMP [m]:11000000 [m] - Jump, IP <= OP (WE:IP, RE:OP,Length:2)
JN [m]:11000001 [m] - Jump Negative, R0 < 0 ? IP <= OP (WE:IP, RE:OP,Length:2)
JZ [m]:11000010 [m] - Jump Zero, R0 = 0 ? IP <= OP (WE:IP, RE:OP,Length:2)
Note that Jumping instructions that test for a condition have an extra requirement for the RE and WE to occur, specifically that the test passes.  If it doesn't pass, the jump instruction will be a glorified NOP, as expected.

Now for the registers:
IP - Instruction Pointer, 8-bit, Memory Access Code: 00, points at the next instruction to fetch in memory
IP+1 - Instruction Pointer +1, 8-bit, Memory Access Code: 01, Virtual register always maintained at IP+1 via a dedicated Adder.
IPI - Instruction Pointer Incremented, 8-bit, Virtual register always maintained at IP+L, where L = Instruction Length.
N - Index Register, 8-bit, used for indexed memory access.
NP - Index Plus One, 8-bit, Virtual register always maintained at N+1 via a dedicated adder.
NM - Index Minus One, 8-bit, Virtual register always maintained at N-1 via a dedicated adder.
IR - Instruction Register, 8-bit, Contains the Opcode of the current instruction to execute.
OP - Operand Register, 8-bit, Memory Access Code: 10, Contains the operand of the current instruction to execute.
OP+N - Indexed Operand, 8-bit, Memory Access Code: 11, Virtual register always maintained at OP+N via a dedicated adder.
R0 - Register Zero, 8-bit, used directly by the ALU, can be semantically swapped with R1 via a simple logic gate.
R1 - Register One, 8-bit, used directly by the ALU, can be semantically swapped with R0 via a simple logic gate.
RSLT - Result Register, 8-bit, Virtual register maintained by the ALU to be the correct result of ALU instructions.
NFLAG - Negative Flag, 1-bit, Virtual "register" maintained by the ALU to be whether the result < 0.  Equal to RSLT's MSB.
ZFLAG - Zero Flag, 1-bit, Virtual "register" maintained by the ALU to be whether the result = 0.  Done with an 8 input NOR gate.

Registers with a Memory Access Code are registers that can be used to address memory.  Addresses are 8-bits.
Virtual registers are Read Only, and can never be selected for a WE with any instruction.  They are maintained by special circuitry to perform their useful functions.

Memory Structure:
Bus Device 00
0-31: DPROM - Dwarf Programmable Read Only Memory.  Essentially a bank of 32 levers properly hooked up to the memory system.
31-59: RAM - Standard Random Access Memory.  Hybrid Logic Memory Cells hooked into the memory system.
60-61: GPI - General Purpose Input.  Reprogrammable buffers that can be hooked up to any desired input signal (lever, plate).
62-63: GPO - General Purpose Output.  Hybrid Logic Cells Driving additional Buffers that can be reprogrammed to control arbitrary mechanisms.
Bus Device 01
64-127: RAM - Initially will be unused.
Bus Device 10
128-191: RAM - Initially will be unused.
Bus Device 11
192-255: MGA - Monochrome Graphics Adapter.  Hybrid Logic Memory Cells preconfigured to drive a set of colored hatches for monochrome display.  Arranged in rows, 4 bytes per row, 16 rows.  32x16 pixel.

Timing Cycle
As stated earlier, the timing cycle will be 4 phase to allow for operation as fast as possible.

IR < MEM[IP]
OP < MEM[IP+1]
IP < IPI
EXECUTE

The Execute phase branches out, based on what opcode is in IR.  For instructions with a RE and WE specified, this is activated here, like so:

{WE} < {RE}

This works because every section of the CPU is running constantly.  Specifically, all virtual registers are updated as soon as possible, and the ALU updates values the moment either R0 or R1 changes, either due to the ALU R0 < RSLT bus write, or due to the SWP instruction.  The design of the ALU does not update RSLT if IR contains a jump instruction.  By the time the updated register is needed, it has been pre-calculated.
Title: Re: Pre-Triggered Mechanical Logic
Post by: jjdorf on April 25, 2010, 11:49:58 am
Well I think your computer's architecture is rather unusual. Your bus design seems to incorporate separate paths for data and address/instructions I think, which doesn't fit into the Von Neumann model my computer used. Could you elaborate on your overall computer design?
Oh yeah, the data bus.  Forgot to elaborate on that.  The bus will have data lines running to the memory banks, and to each register.  The address lines only run to the memory banks, since only they need them.  The RE and WE of the instruction set and basic timing are used by the control circuit to transfer data on the bus at each time step exactly as needed.  The select which of each membor of the bus drives the data lines, and which one writes those driven data lines to their storage.  Virtual Registers are on the bus, but do not respond to/have WE circuitry.

This includes enabling the correct Memory Access Register to the data bus as well.  I will have to do some special logic to make this work swiftly for the device selector.  If anything, right now, that little chunk of circuitry is the most vital.  Maybe I can devise a scheme to select the memory access code before it is needed.
Title: Re: Pre-Triggered Mechanical Logic
Post by: Shinziril on April 25, 2010, 11:53:38 am
Here's a diagram for a fluid logic memory cell, using only doors. 

Spoiler (click to show/hide)

The red squares are the Input doors, hooked up to whatever input pressure plates you are using. 
The green squares are the Write Enable doors, which should be hooked up to the write decoder. 
The magenta squares are, of course, pressure plates (which should be hooked up to something like Jong's "write condenser", so that the additional hardware needed for selective reading can be placed elsewhere). 
The gray squares are unlinked doors, meant to allow access to the various hardware, with a down-stair for access. 
The white row on the bottom is a row of floor with an up stair on the left- this is the water input pipe.  The z-level above this should have a pipe supplying pressurized water. 
The white squares on the top are channel-drains.  This is the water output, and it requires an output collection pipe on the z-level below it. 

I find that the most effective method for the water delivery system is to pump water from a stream into a cistern for pressure (using a fairly wide pump-stack), and have the output pumped back into the river *upstream* of the intake pump stack (to allow recirculation, while ensuring it will never overflow).  You will of course probably want a lever-controlled hatch as the cistern output, and toggleable gears for the pump stacks, so you can shut it down if you need to. 
Title: Re: Pre-Triggered Mechanical Logic
Post by: jjdorf on April 25, 2010, 12:06:30 pm
Here's a diagram for a fluid logic memory cell, using only doors.
Interesting... Definitely nice for saving space on the memory bank floor.  I'm just dead set on having a closed system, and that means no infinite water source.  I WOULD be interested in any memory cell that conserves water, requires very little water, and takes up a minimum of space.  I think my Hybrid Logic memory cell is the closest we can get to it, though.

Also, after studying a bit of my timing cycle, I now know that there will need to be one more register, one I was hoping to get rid of:

MAR - Memory Access Register, 8-bit, Virtual register always maintained one step ahead of when it is needed.  This register, like the ALU flags, is not attached to the data bus.  It must be enabled completely by the time a memory op on the bus is occurring.  Thus, each stage that needs a memory access primes this register on the stage preceding it.
Title: Re: Pre-Triggered Mechanical Logic
Post by: jjdorf on April 25, 2010, 01:23:18 pm
In preparation of designing the layout in my 3D program, I have discovered something amusing.  A block of 64 bytes (one of four memory devices) will take 16 z-levels, and at least 56 by 35 tiles.  I plan on having room for four of these, plus the other computer circuitry.  I'm gonna need a big embark.  :D
Title: Re: Pre-Triggered Mechanical Logic
Post by: jjdorf on April 25, 2010, 02:45:48 pm
I have finished my design for the four stage timing circuit.  Diagrammed from bottom level to top level:
Code: [Select]
XXXXXX
D1XX2D
XXXXXX
XXXXXX
D4XX3D
XXXXXX

XXDXXX
X#%>#X
X^XX%D
D%XXvX
X#<%#X
XXXDXX

   1
 4***P
  | 2
  3
The pressure plates numbered 1-4 on the bottom layer are set for 0-3 water.  They connect to the gears labeled 1-4 on the top layer.  These numbered gears are pre-toggled.  After linking the pressure plates to the gears and to the timing circuitry of the computer itself, you turn off the power.  Then fill the 1 pressure plate tile with water.  4/7 will do, but I like it to be full at 7/7.  Turn the power back on and watch as your water visits each pressure plate for 100 steps each, round and round, til you turn off the power.  Water is fully conserved in this setup.  Note... the logic from the pressure plates is as follows:
Code: [Select]
t 1 2 3 4
1 0 1 1 1
2 1 0 1 1
3 1 1 0 1
4 1 1 1 0
Which means logic that activates on the timer needs to flip the toggle state of any gear using the signal if it expects the signal to be active-on.
Title: Re: Pre-Triggered Mechanical Logic
Post by: Jong on April 25, 2010, 08:15:31 pm
I see that your timing cycle is pretty short. You need to be careful to avoid conflicts in the various data transfers throughout the CPU, but I see that you have a large number of registers prepared for this. One problem with memory cells currently is that it takes 100 steps to write a zero to a non-empty memory cell.

And your timing circuit has some problems. One thing I discovered when building my computer's clock was that pumps do not turn off instantly when their power is cut. That is bad. Plus, because of the 100 step delay for pressure plates to reset, most of the time when your circuit is in operation, 2 pressure plates will be active. My clock used some null cells to hold the water while the active pressure plate reset.
Title: Re: Pre-Triggered Mechanical Logic
Post by: jjdorf on April 25, 2010, 09:14:34 pm
I see that your timing cycle is pretty short. You need to be careful to avoid conflicts in the various data transfers throughout the CPU, but I see that you have a large number of registers prepared for this. One problem with memory cells currently is that it takes 100 steps to write a zero to a non-empty memory cell.
I am accounting for that in the registers.  They should be ready by or before the cycle they are needed at.

Quote
And your timing circuit has some problems. One thing I discovered when building my computer's clock was that pumps do not turn off instantly when their power is cut. That is bad. Plus, because of the 100 step delay for pressure plates to reset, most of the time when your circuit is in operation, 2 pressure plates will be active. My clock used some null cells to hold the water while the active pressure plate reset.
Actually, I constructed and tested my timing system.  I have a save, and can provide a video if you want.  However, just to state, there is never more than one pump on at a time, and the pumps only activate for about 6 steps total.  The key to the timer is that the plates are on when empty and the gears controlling the pumps are pre-toggled to invert this signal.  This is the reverse logic that most people expect, however, it is easily accounted for by pre-toggling whatever the signal coming from a stage goes to.  Gears are beautiful things.  To give a run down of how it works, I'll take it step by step.

Step 1: Finish building that timer assembly, including linking the pressure plates to pre-toggled gears for the control circuit.  All pump gears are off because there is no water in the system yet.  Also the power itself is off.
Step 2: Fill timer cell 1 to 7/7 water.  The gear for the next pump in line is engaged, but is still providing no power because the power itself is off.
Step 3: Turn on the power.  The first pump moves all the water into the next cell.  Cell 1 plate turns on, immediately turning off the first pump.
Step 4: After 100 steps, plate 2 turns off.  This turns pump 2 on, draining cell 2 into cell 3.  Pump 2 then immediately shuts off.
Step 5: After 100 steps, plate 3 turns off.  This turns pump 3 on, draining cell 3 into cell 4.  Pump 3 then immediately shuts off.
Step 6: After 100 steps, plate 4 turns off.  This turns pump 4 on, draining cell 4 into cell 1.  Pump 4 then immediately shuts off.
Step 7: After 100 steps, plate 1 turns off.  This turns pump 1 on, draining cell 1 into cell 2.  Pump 1 then immediately shuts off.
Step 8: This continues until we pull the power lever and no pump is capable of getting power.  Unless the power is lost at exactly the right time, water stays in the cell it currently resides in.

Now obviously there is some potential for the timer to get one cell ahead of stage 1, though I think it's about a 1 in 100 chance.  The key to dealing with this is my NOP instruction.  That will be the instruction that is always first in the Instruction Register after power is turned on, so if the system starts after time cycle stage 1, all it does is a null operation, causing the timer to resynchronize and then start from memory address 0.

I think I'll figure out how to upload my timer video.  Be right back.
Title: Re: Pre-Triggered Mechanical Logic
Post by: jjdorf on April 25, 2010, 09:22:36 pm
I think I'll figure out how to upload my timer video.  Be right back.
Hmmm... Doesn't seem to like my video.  Is DFMA not compatible with DF2010 movies?
Title: Re: Pre-Triggered Mechanical Logic
Post by: Mawootad on April 25, 2010, 11:52:47 pm
Though it would massively increase space and (in a number of respects) material usage, you could probably build an ultra-high-response computer using waterwheels for triggers instead of pressure plates.  I'm currently working on basic designs.  Due to the large space of the individual gates and difficulty in containing fluid, I'm not 100% sure if it's even possible, but I'm looking into it atm.
Title: Re: Pre-Triggered Mechanical Logic
Post by: jjdorf on April 26, 2010, 01:06:20 am
Though it would massively increase space and (in a number of respects) material usage, you could probably build an ultra-high-response computer using waterwheels for triggers instead of pressure plates.  I'm currently working on basic designs.  Due to the large space of the individual gates and difficulty in containing fluid, I'm not 100% sure if it's even possible, but I'm looking into it atm.
:o

Waterwheels?  I'm intrigued... not that I'll end up using them, but any more varieties of logic is a good thing.  Even borg logic is good, since it gets people thinking about a mile outside the proverbial box.  I'd love to see a basic whaterwheel logic design.
Title: Re: Pre-Triggered Mechanical Logic
Post by: Jong on April 26, 2010, 01:31:31 am
Hmm.. Since waterwheels are a kind of "flow sensor" and they output power rather than trigger signals, it could possibly be done if the waterwheels provide barely enough power to operate the logic mechanisms. Also, pumps would be the sole source of input/output control as there won't be toggled gears, doors, hatches, floodgates or other traditional staples of dwarven logic as pressure plates are out.
Title: Re: Pre-Triggered Mechanical Logic
Post by: Core Xii on April 26, 2010, 05:28:57 am
Even if you didn't have enough memory to store an entire picture for the display, you could just generate one procedurally! Dwarven fractals, anyone?

I did think that the gear resistor designs on the wiki were ridiculous, but I didn't actually realize you could do this. It's carved in stone in my head that levers don't toggle, I guess. Thank Toady that gears are the exception to this rule, yes? :D

Now the real biggest problem here is a practical application for computers in DF. It's cool and all but it's a hell of a lot of work for no real end. Then again, it is a sandbox game...

By the way, I couldn't get heads or tails from your data bus diagrams. It would be advisable to always label such charts whether they are top-down or side-view.

Also, using the teletype (tt) tags instead of code you can include underlines to denote floors while maintaining a monospace font (you can also use colors!):

(side view)
PAB
rZC


Oh, one last thing: For pre-triggering gears, you can link ALL of them to a single lever to flip, and save N-1 mechanisms for constructing all the temporary levers.
Title: Re: Pre-Triggered Mechanical Logic
Post by: Jong on April 26, 2010, 05:45:38 am
Oh, one last thing: For pre-triggering gears, you can link ALL of them to a single lever to flip, and save N-1 mechanisms for constructing all the temporary levers.

You can always deconstruct the levers to get them back!

Besides, its a pain when you can only have 10 jobs in the queue.
Title: Re: Pre-Triggered Mechanical Logic
Post by: jjdorf on April 26, 2010, 02:55:12 pm
Even if you didn't have enough memory to store an entire picture for the display, you could just generate one procedurally! Dwarven fractals, anyone?
Not sure how that would work.  I know I could limit the display to a text only display, but that would require a memory bank for the text font.  That bank may, however, not be needed within the Accessible RAM... instead it could just be used by the display circuitry.  Then instead of 32x16, it would be 4x2 or 8x1, or whatever, and an 8x8 block of pixels could be flipped in one instruction instead of 8.  Considering how fast things run, this may even be a better choice.  Since the "video" out is far off in the future for me, I'll be giving this some thought.

Quote
I did think that the gear resistor designs on the wiki were ridiculous, but I didn't actually realize you could do this. It's carved in stone in my head that levers don't toggle, I guess. Thank Toady that gears are the exception to this rule, yes? :D
Yup.  One of the coolest things about gears is the fact that, with the limitation that a gear can't directly toggle another gear, you can build any circuit you can imagine.
Quote
Now the real biggest problem here is a practical application for computers in DF. It's cool and all but it's a hell of a lot of work for no real end. Then again, it is a sandbox game...
I've thought about this over and over again, and all I come up with is a devious and insidious trap system that constantly keeps victims running for the exit that changes over and over again.  An evil maze that changes randomly, but always has an exit.  Pit the victim and watch them dance in misery.  Other than that... yeah, it's probably just a big bragging rights parade.  :D

Quote
By the way, I couldn't get heads or tails from your data bus diagrams. It would be advisable to always label such charts whether they are top-down or side-view.
True.  But then, my data bus design isn't 100% set in stone, so to speak.  I'm still figuring out the kinks and timing and delays and other irritations.

Quote
Also, using the teletype (tt) tags instead of code you can include underlines to denote floors while maintaining a monospace font (you can also use colors!):

(side view)
PAB
rZC

Okay.... Now that I LIKE.  I'll have to keep that in mind.  Is there an easy equivalent for the Wiki?

Quote
Oh, one last thing: For pre-triggering gears, you can link ALL of them to a single lever to flip, and save N-1 mechanisms for constructing all the temporary levers.
Yup.  And you only have to flip it once.  The only thing that matters is that the gear is pre-toggled, not how exactly it is done.  You could, if you were nutty enough, do it with a pressure plate.

Also, earlier Jong brought up the question of my timing circuit, and I dismissed, for a bit, his assertion that it needs extra time.  He is, to some extent, correct.  Thus, I'm adding a delay circuit to my design.  The point of this one is that it will always be delayed by a small amount of time (the duration that 7/7 floats in the air before it drops down to the lower z-level, which I've seen take between 4 and 13 steps).  The Read Enable circuitry will go through the delayed timer.  The Write Enable circuitry will be directly driven by the primary timer.  The end result is that Writes will be guaranteed to complete before the next Read Enable, and that read enable will always be delayed at least one step, and likely no longer than around 13 steps.

The delayed timer will use power from the same source as the primary timer, but the gears powering the pumps will be driven by the primary timer's pressure plates.  I'll have to take a look and get this designed and fully functional, but I think this, the jump control circuitry, and the big huge confusing memory bus architecture are the final kinks to work out before I strike the earth.
Title: Re: Pre-Triggered Mechanical Logic
Post by: Core Xii on April 27, 2010, 05:45:10 am
Okay.... Now that I LIKE.  I'll have to keep that in mind.  Is there an easy equivalent for the Wiki?

Not familiar with wiki markup I'm afraid.
Title: Re: Pre-Triggered Mechanical Logic
Post by: Shinziril on May 02, 2010, 02:04:11 am
I implemented an 8-bit adder-subtractor using Jong's logic design (http://dffd.wimbli.com/file.php?id=2282).  It works very nicely.
Title: Re: Pre-Triggered Mechanical Logic
Post by: mstram on November 29, 2017, 01:59:09 pm
I implemented an 8-bit adder-subtractor using Jong's logic design (http://dffd.wimbli.com/file.php?id=2282).  It works very nicely.

How do you operate it ?

I see some screw pumps on level 150 and doors on level 149.

Are they supposed to be manually activated ?
Title: Re: Pre-Triggered Mechanical Logic
Post by: MoonyTheHuman on November 29, 2017, 03:47:58 pm
This is a post from 7 years ago, that user is no longer active. Y U Revive?
Title: Re: Pre-Triggered Mechanical Logic
Post by: mstram on November 29, 2017, 03:57:45 pm
This is a post from 7 years ago, that user is no longer active. Y U Revive?

1) Yes I see it was 7 yrs ago.  The file is still on the "dffd" site, and it still works.

2) According to his profile (Shinziril) was active yesterday.    Why do you say he's no longer active?
Title: Re: Pre-Triggered Mechanical Logic
Post by: mstram on December 02, 2017, 01:21:15 pm
Well I "found" the "camouflaged" levers off to the right of the main structure.

But without dfhack-etc, purely trial and error (fun ?) now to figure out what lever does what