<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://dwarffortresswiki.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Jong</id>
	<title>Dwarf Fortress Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://dwarffortresswiki.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Jong"/>
	<link rel="alternate" type="text/html" href="https://dwarffortresswiki.org/index.php/Special:Contributions/Jong"/>
	<updated>2026-05-21T14:59:21Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.35.11</generator>
	<entry>
		<id>https://dwarffortresswiki.org/index.php?title=v0.31_Talk:Computing&amp;diff=101119</id>
		<title>v0.31 Talk:Computing</title>
		<link rel="alternate" type="text/html" href="https://dwarffortresswiki.org/index.php?title=v0.31_Talk:Computing&amp;diff=101119"/>
		<updated>2010-04-30T10:02:13Z</updated>

		<summary type="html">&lt;p&gt;Jong: Created page with 'I don't see why the examples from the previous version were not included. Generally, designs for fluid and mechanical logic should still work in the current version as there hasn…'&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;I don't see why the examples from the previous version were not included. Generally, designs for fluid and mechanical logic should still work in the current version as there hasn't been any relevant changes in those areas.&lt;br /&gt;
[[User:Jong|Jong]] 10:02, 30 April 2010 (UTC)&lt;/div&gt;</summary>
		<author><name>Jong</name></author>
	</entry>
	<entry>
		<id>https://dwarffortresswiki.org/index.php?title=v0.31:Computing&amp;diff=101114</id>
		<title>v0.31:Computing</title>
		<link rel="alternate" type="text/html" href="https://dwarffortresswiki.org/index.php?title=v0.31:Computing&amp;diff=101114"/>
		<updated>2010-04-30T09:54:41Z</updated>

		<summary type="html">&lt;p&gt;Jong: Scooped up the examples from the 40d page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{av}}&lt;br /&gt;
{{human}}&lt;br /&gt;
Computing in dwarf fortress is the practice of setting up complex constructions to perform logical operations and calculations, ideally to control some functionality of your fortress. Even if it isn't a young concept anymore, there is still lots of room for improvement and development. One reason is that there are many ways to solve one problem. Innovation and invention is encouraged.&lt;br /&gt;
=== Binary information ===&lt;br /&gt;
Binary information can have one of two possible states: true or false, respectively 1 or 0. In dwarf fortress they can be represented by different entities:&lt;br /&gt;
* on/off state or signal of a {{l|trigger|trigger}} (pressure plate, lever)&lt;br /&gt;
* power or connection state of a {{l|machine component|machine component}}&lt;br /&gt;
* open or closed state of a {{l|door|door}} or similar buildings&lt;br /&gt;
* {{l|pressure plate|low/high}} or {{l|flow|flowing/standing}} {{l|water|fluid}}&lt;br /&gt;
* present {{l|creature|creature}}s and {{l|dwarf|borgs}}&lt;br /&gt;
&lt;br /&gt;
Electronic devices and computers base on this elementary form of information, and if you want to go into computing, you’ll have to familiarize yourself with it. [http://en.wikipedia.org/wiki/Propositional_calculus propositional calculus]&lt;br /&gt;
=== Input/Output ===&lt;br /&gt;
Input can be any device which can be linked to another device with mechanisms, such as {{l|lever|levers}} or {{l|pressure plate|pressure plates}}. Pressure plates can measure water, magma, or creature weight, and can be set to react to your own dwarves if measuring creature weight. If measuring water or magma you specify the minimum and maximum levels at which it should output 'on', and at all other levels it will output an 'off' signal. Regardless of the actual amount of water, magma, or creature weight on your pressure plate, the plate can only output an 'on' or 'off' signal (1 or 0) to whatever devices it is linked to. So everything you build will have a binary base.&lt;br /&gt;
&lt;br /&gt;
====Input elements====&lt;br /&gt;
* manual: {{l|lever|lever}} -&amp;gt; binary on/off signal&lt;br /&gt;
* triggered: {{l|pressure plate|pressure plate}} -&amp;gt; binary on/off signal&lt;br /&gt;
&lt;br /&gt;
According to input, output can be anything that is able to react to an on/off signal. This can be doors, bridges, floodgates allowing or stopping flow, gears controlling pumps and much more. In some special configurations - when {{l|mechanical logic|mechanical logic}} is involved - output may not be a on/off signal but power, thus running or not running a machine component.&lt;br /&gt;
&lt;br /&gt;
Currently to convert from power to an on/off signal, the only way is to use a screw pump connected to that power source with an unlimited amount of water and drainage at the output, and a pressure plate to measure whether water is being pumped out by the pump.&lt;br /&gt;
&lt;br /&gt;
====Output elements====&lt;br /&gt;
* signal: {{l|pressure plate|pressure plate}} -&amp;gt; binary on/off signal -&amp;gt; linkable Object(s)&lt;br /&gt;
* power: {{l|gear assembly|gear assembly}} -&amp;gt; binary power on/power off -&amp;gt; machine&lt;br /&gt;
&lt;br /&gt;
=== Binary logic ===&lt;br /&gt;
Basic binary logic takes one or two input bits and creates an output based on them. The devices that perform these operations are commonly called '''logic gates'''.&amp;lt;br /&amp;gt;&lt;br /&gt;
* NOT - takes one input and returns the opposite of the input&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=1&lt;br /&gt;
|-&lt;br /&gt;
! input A &lt;br /&gt;
! NOT&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
|}&amp;lt;br /&amp;gt;&lt;br /&gt;
* AND - takes two inputs and returns true if both inputs are true&lt;br /&gt;
* OR - takes two inputs and returns true if at least one input is true&lt;br /&gt;
* XOR - takes two inputs and returns true if exactly one input is true&lt;br /&gt;
* NAND - takes two inputs and returns true if either input is false&lt;br /&gt;
* NOR - takes two inputs and returns true if both inputs are false&lt;br /&gt;
* NXOR - takes two inputs and returns true if both inputs are identical&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=1&lt;br /&gt;
|-&lt;br /&gt;
! input A&lt;br /&gt;
! input B&lt;br /&gt;
! AND&lt;br /&gt;
! OR&lt;br /&gt;
! XOR&lt;br /&gt;
! NAND&lt;br /&gt;
! NOR&lt;br /&gt;
! NXOR&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
|}&amp;lt;br /&amp;gt;&lt;br /&gt;
The most human-understandable logic system requires NOT, AND and OR gates, but having a design for either a NAND or a NOR gate is enough to build any of the other gates. Some gates are easier to create or need fewer components than others depending on what discipline your logic relies on. Designing each individual gate that you will need (or using designs that had each individual gate designed) rather than building a gate out of multiple NAND gates or the like will generally result in your dorfputer reacting faster and using less resources (power, water, kittens, construction materials, what-have-you).&lt;br /&gt;
&lt;br /&gt;
=== Complex gates ===&lt;br /&gt;
* {{l|Latch|Latch}} - storing and reading a single binary value&lt;br /&gt;
* {{l|Repeater|Repeater}} - sending a repeating signal&lt;br /&gt;
* {{l|Counter|Counter}}/{{l|Adder|Adder}} - binary calculation&lt;br /&gt;
&lt;br /&gt;
== Disciplines ==&lt;br /&gt;
Historically, prior to DF2010 there have been 3 main disciplines of dwarfputing, depending on what would drive the dwarfputer. Each of them had its assets and drawbacks. So far, DF2010 at 0.31.01 appears to be essentially the same as far as power transmission goes, barring some differences with pump vertical power transmission (they don't without the floor between being channeled, apparently). Science! will determine what, if anything, differs as far as water flow, falling, and animal pathfinding.&lt;br /&gt;
&lt;br /&gt;
The three disciplines are:&lt;br /&gt;
=== Fluid logic ===&lt;br /&gt;
{{l|Infinite flow fluid logic|Infinite flow fluid logic}} is controlling the ''flow of fluid'' over different pressure plates. Fluid logic can be easily constructed and every known logic gate in dwarf fortress has already been built with it. On the other hand this discipline depends on a somehow unlimited source of the used fluid to deal with its {{l|evaporation|evaporation}} and {{L|Water#Water in Fortress Mode|destruction}}.&lt;br /&gt;
=== Mechanical logic ===&lt;br /&gt;
{{l|Mechanical logic|Mechanical logic}} uses systems of axles and {{l|gear assemblies|gear assemblies}} to build logical gates. Mechanical logic reacts very fast and can be easily constructed, except for the need for a fluid-pump-based power-&amp;gt;signal converter in every gate. Since every gear can itself be linked to a trigger (or multiple triggers), and automatically connect to adjacent gears for transferring either power or load, mechanical logic gates are very flexible and don't require anywhere near the number of different devices that tend to be used in fluid logic gates (except, again, for the requirement for a fluid-pump-based power-&amp;gt;signal converter in every gate, unless you intend to use it to control a pump). On the other hand this discipline uses a LOT of mechanical power, and due to the lack of a power-&amp;gt;signal converter, also referred to as a &amp;quot;rotation sensor&amp;quot; (a device to convert from power to on/off link signals), you need to build one using fluid logic components if you want to connect multiple mechanical logic gates together or connect a mechanical logic gate to any output other than a pump.  There is, however, now a fully functional fluid preserving rotation sensor design.  So, in truth, current mechanical logic is more correctly termed mechanical-fluid hybrid logic, as you need some source of fluid to &amp;quot;prime&amp;quot; the rotation sensors your design will need.  Along with new techniques to construct logic gates by &amp;quot;pre-toggling&amp;quot; a gear assembly (see {{l|Pre-Toggled Mechanical Logic|Pre-Toggled Mechanical Logic}}), any logical circuit can be built, given enough space in the game to do it.&lt;br /&gt;
=== Animal logic ===&lt;br /&gt;
{{l|Animal logic|Animal logic}} places animals in an enclosed room, with a door blocking the path to where they desire to go, and a pressure plate below a hatch, with obstacles which are controlled by triggers. The animal thinks it can walk through the door, and if it has a path to the door will walk up to it and stand on the hatch. When the hatch is opened by a trigger, it falls onto the pressure plate. As long as the hatch is open, or other obstacles block its path to the door it remains on the pressure plate and the output is 'on'. Once it sees a path to the door it will leave the pressure plate. Generally this is made possibly by the fact that animals try to go to their parent while they're children, or to the meeting area. There are also be designs which use captured hostiles.&lt;br /&gt;
&lt;br /&gt;
There was a fourth, theoretical, discipline, Borg Logic, but there was never any reported success inventing any functioning and useful borg logic systems.&lt;br /&gt;
&lt;br /&gt;
===Examples of things you could do with logic gates===&lt;br /&gt;
* Repeater: Repeatedly toggling hatches open and closed, or spikes up and down.&lt;br /&gt;
* Latch: Making resettable one-use pressure plates which are reset by a lever.&lt;br /&gt;
* NOT gate: Reversing the effect of a switch or creature-sensing pressure plate, generally linked to a latch device. You can, of course, mod the latch device to send the opposite signal instead of using a NOT gate.&lt;br /&gt;
* AND gate: Requiring more than one condition to be true for something to occur. For instance, you could have a group of AND gates, with a system on/off switch, and and other triggers, with each trigger linked to a different AND gate with the system on/off switch linked to the the second input on all the AND gates, so that when the system on/off switch is OFF the output will be OFF on all the AND gates.&lt;br /&gt;
* OR gate: You could link two 1-7 water sensors to an OR gate, and link that to a NOT gate, and link that to some floodgates or doors which act as emergency bulkheads, closing when water is detected in the area. Or, link the OR gate to bridges which raise instead (but you may crush things, and bridges are slower than doors).&lt;br /&gt;
* XOR gate: You could use pressure plates hooked to latches at different points in your fort to detect enemy intrusion, and set them up to seal off the area with both an interior and exterior bulkhead when the intrusion occurs, but hook your latches up with an XOR gate and hook the output to the interior bulkhead to unseal that one if your pressure plates have detected that the enemy has gotten past it.&lt;br /&gt;
* NOR gate: A NOR gate returns TRUE (ON) only if both inputs are FALSE. Instead of using the OR gate example with a NOT gate, you could use a NOR gate linked to two 1-7 water sensors, whose output goes to doors or floodgates. When the pressure plates are both waterless, the floodgates will be open. When one detects water, the floodgates close. (If you used 0-0 pressure plates with an OR, you would get an OFF signal if both plates detected water, or an ON signal otherwise (which is the same as 1-7 NAND 1-7))&lt;br /&gt;
* NAND gate: A NAND gate returns TRUE (ON) whenever both inputs are not both TRUE (e.g. ON NAND ON is OFF, but every other combination is ON). Instead of the OR NOT or NOR example, you could link two 0-0 water sensors to a NAND gate, and link the NAND gate's output to raising bridges. 0-0 NAND 0-0 is the same as 1-7 OR 1-7. If there is no water on both pressure plates, the NAND gate will output an OFF signal. If, however, either has water, it will output an ON signal.&lt;br /&gt;
&lt;br /&gt;
* And here's a more complicated example, omitting the details of what gates to use: An automated swimming training room, where you pull a lever to close exit doors and open hatches to drop water into it, then pressure plates detect when there's enough water and close the hatches, and after a certain amount of time (using a very slow repeater, for instance), drains and exit doors open and the system resets until you pull the lever again. Or, the lever could be taken out entirely and the system could be made fully automatic (with dwarves set to train in the room, for instance) using the repeater.&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
There are few examples of a really useful dwarfputer and some concepts which have the potential to become useful for others. But in most cases they are made just for fun. What doesn't mean to diminish their designers achievements, because these are in general the more complex ones.&amp;lt;br /&amp;gt;At the moment there are no known examples of animal or borg logic.&lt;br /&gt;
=== Useful ===&lt;br /&gt;
* Magma trap&lt;br /&gt;
** This is an example of a useful dwarfputer controlling a magma trap. It automatically floods an area with lava, cleans up and resets afterwards. The timing is perfectly adjusted to let the victims vanish only leaving their valuable metal behind.&amp;lt;br /&amp;gt;video: http://mkv25.net/dfma/movie-1808-perfectmagmatrap&amp;lt;br /&amp;gt;design: http://i576.photobucket.com/albums/ss208/kanddak/magmatrap.png&lt;br /&gt;
&lt;br /&gt;
=== Concepts ===&lt;br /&gt;
* repeater&lt;br /&gt;
** mechanical logic http://mkv25.net/dfma/movie-1370-pump-basedautorepeater&lt;br /&gt;
* adding machine&lt;br /&gt;
** mechanical logic, 6-bit: http://mkv25.net/dfma/movie-1561-addingmachine&lt;br /&gt;
** fluid logic, 8-bit: http://mkv25.net/dfma/movie-1084-numberabbeydemonstration&lt;br /&gt;
=== Such a doddle ===&lt;br /&gt;
* decimal display for 4-bit binary input&lt;br /&gt;
** mechanical logic, decimal with overflow-bit: http://mkv25.net/dfma/movie-1745-dwarfputerv01&lt;br /&gt;
** probably fluid logic: http://mkv25.net/dfma/movie-1657-7segmentlcddisplay&lt;br /&gt;
** fluid logic, hexadecimal: http://mkv25.net/dfma/movie-1092-7-segmentdisplaydemonstration&lt;br /&gt;
* tic tac toe&lt;br /&gt;
** mechanical logic http://mkv25.net/dfma/movie-1813-tictactoev10simple&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Related user pages ==&lt;br /&gt;
*[[User:BaronW]] - The Almighty Dwarven Calculator&lt;br /&gt;
*[[User:Jong]] - The first fully programmable digital Dwarven Computer&lt;br /&gt;
*[[User:SL/Logic Gates]] - These use mechanisms for connecting gates and devices and so forth, but fluid for logic. They're built on top of a body of water, and require power (for a pump or two per gate).&lt;br /&gt;
*[[User:Kyace/Adder]] - A full adder built using fluid logic, with a video of a rough prototype. Trivial to combine 8 of these to make a fluid device capable of adding two 8 bit numbers together.&lt;br /&gt;
*[[User:Soundandfury#Logic_Gates]] - These have a water supply reservoir above and a drain below.  The drained water can be pumped back to the supply reservoir.&lt;br /&gt;
*[[User:Bidok]] - Animal logic with all gates, memory, repeater and counter. All powered by kittens.&lt;br /&gt;
*[[User:LordOOTFD#Animal_Logic]] - Animal logic with fast complex gates, building upon Bidok's kitten powered systems.&lt;br /&gt;
*[[User:Hussell#Assorted_Devices]] - Fluid logic&lt;br /&gt;
*[[User:Gammon]] - Fluid logic. Very detailed CMOS gates.&lt;br /&gt;
&lt;br /&gt;
{{buildings}}&lt;/div&gt;</summary>
		<author><name>Jong</name></author>
	</entry>
	<entry>
		<id>https://dwarffortresswiki.org/index.php?title=User:Jong/Dwarven_Computer&amp;diff=101113</id>
		<title>User:Jong/Dwarven Computer</title>
		<link rel="alternate" type="text/html" href="https://dwarffortresswiki.org/index.php?title=User:Jong/Dwarven_Computer&amp;diff=101113"/>
		<updated>2010-04-30T09:38:19Z</updated>

		<summary type="html">&lt;p&gt;Jong: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page documents the design of my Dwarven Computer. A number of designs were modified for the final implementation.&lt;br /&gt;
&lt;br /&gt;
Adapted from my GoogleDocs [http://docs.google.com/Doc?docid=0AdISzBuNg6ZWZGd0d2t4YjlfMjJ0ejlzc2dnaA&amp;amp;hl=en manuscript]&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&lt;br /&gt;
Toggled gear assemblies are designed as though they are off in when untriggered. However they are constructed in the on position. This means that you need to build and link a lever to toggle it to the off state.&lt;br /&gt;
&lt;br /&gt;
==Power sensor (output device)==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  # %&amp;gt;^ #     &lt;br /&gt;
 ~ ~ ~ ~#      Power sensor side view&lt;br /&gt;
&lt;br /&gt;
In order to do useful things, such as toggling gears assemblies, opening doors, etc., mechanical power signals need to be converted to a trigger signal. There are only 2 trigger signal generators in dwarf fortress. One is the lever, which cannot be linked to machine power. The other is a pressure plate, which can.&lt;br /&gt;
&lt;br /&gt;
The basic operation of this component is simple. Power operates the pump, pushing water over the pressure plate, generating a signal. When the pump is not powered, the water drains, switching the pressure plate off after at least 100 steps.&lt;br /&gt;
&lt;br /&gt;
The smooth operation of this unit depends on several factors:&lt;br /&gt;
1. Adequate supply of water in the input tile so that the pump can maintain 7/7 or 6/7 water levels on the pressure plate. Can be done by providing more water tiles adjacent to the input tile.&lt;br /&gt;
2. Fast drainage to minimize the time needed for the plate to switch off. Just make sure that the level below the pumps is not completely full.&lt;br /&gt;
3. Since the minimum recovery time of the pressure plate is 100 steps, it can take a good long time for a 0-bit to reach the end of a chain of output units.&lt;br /&gt;
&lt;br /&gt;
==Design for a memory cell for use in registers/memory unit==&lt;br /&gt;
&lt;br /&gt;
 ###&lt;br /&gt;
 #H#&lt;br /&gt;
 #^#PRoO&lt;br /&gt;
 #%#&lt;br /&gt;
 #%WIP&lt;br /&gt;
 #~#&lt;br /&gt;
 ###&lt;br /&gt;
&lt;br /&gt;
This design is based on plans found at User:SL/Logic_Gates on the wiki. For this design, the write-in signal is linked to gear W and hatch H, while the read-out signal is linked to gear R. Gear o is linked to the pressure plate ^ and represents the state of the cell. Big O represents to output signal and I represents the input signal. P represents a power source. The hatch prevents the water from draining thus preserving the data.&lt;br /&gt;
&lt;br /&gt;
In order to act as a memory cell, this unit must do 3 things:&lt;br /&gt;
1. Output its state when told to read-out&lt;br /&gt;
2. Change state to match an input when told to write-in&lt;br /&gt;
3. Maintain its state when not told to do anything&lt;br /&gt;
&lt;br /&gt;
Let's check this by examining the operation of this unit. &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=1 style=&amp;quot;text-align:center&amp;quot; cellpadding=&amp;quot;2&amp;quot; cellspacing=&amp;quot;0&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|R&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|W&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|I&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|State&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|O&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| Ignored&lt;br /&gt;
| Unchanged&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| Ignored&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| Ignored&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
|}&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When both read and write are turned on, the device will act as a power sensor for the input. This could be a problem if the input and output are linked.&lt;br /&gt;
&lt;br /&gt;
One point of concern is that the unit may not contain sufficient water to trigger the plate because the amount of water in the square above the hatch may not be 7 when it closes. &lt;br /&gt;
&lt;br /&gt;
The plate could be set to trigger at a lower threshold, which would slightly slow down response time, or a door could be used instead of a hatch and the unit extended by one tile to provide space for the drain. This would have the downside of destroying some water after every write operation.&lt;br /&gt;
&lt;br /&gt;
Another method is to use another pump to drain the water from the holding tile. This pump will only activate when W is 1 and I is 0. &lt;br /&gt;
&lt;br /&gt;
==Computer registers==&lt;br /&gt;
&lt;br /&gt;
The dwarven computer prototype is going to have an 8-bit instruction length, a 3-bit operon and a 5-bit address space. Why? The best reason for this is that other designs of Very Simple Computers (VSC) on the Internet are also only 8-bit and I am basing the design of the prototype dwarven computer off several of them. Naturally a bigger computer is better in many ways but the current goal is to produce an operational one. Now its not clear to me why a VSC shouldn't be smaller, but I suppose it doesn't matter.&lt;br /&gt;
&lt;br /&gt;
8-bit words need 8-bit registers. Fortunately this just means stacking 8 memory units up and making sure they receive the same read/write signals.&lt;br /&gt;
&lt;br /&gt;
[[image:memreg.png|Schematic of an 8-bit register]]&lt;br /&gt;
&lt;br /&gt;
The lines in the diagram don't actually represent physical connections but imaginary ones. After all, the write signal must be sent remotely.&lt;br /&gt;
&lt;br /&gt;
Now we consider the most compact designs for such an array. Let us assume that the output signals will be sent remotely. For clarity, the arrays ought to be rectangular.&lt;br /&gt;
&lt;br /&gt;
 ##### ##### ##### ##### ##### ##### ##### ##### &lt;br /&gt;
 #H#.# #H#.# #H#.# #H#.# #H#.# #H#.# #H#.# #H#.# &lt;br /&gt;
 #^#^# #^#^# #^#^# #^#^# #^#^# #^#^# #^#^# #^#^# &lt;br /&gt;
 #%#%# #%#%# #%#%# #%#%# #%#%# #%#%# #%#%# #%#%# &lt;br /&gt;
 W%`%o W%`%o W%`%o W%`%o W%`%o W%`%o W%`%o W%`%o &lt;br /&gt;
 I~`~RPI~`~RPI~`~RPI~`~RPI~`~RPI~`~RPI~`~RPI~`~R&lt;br /&gt;
 P`````````````````````````````````````````````P&lt;br /&gt;
Note that the O is omitted since it was a placeholder for the output device.&lt;br /&gt;
&lt;br /&gt;
Not all registers in the computer are 8 bit registers. For example the memory address register is 5 bits.&lt;br /&gt;
&lt;br /&gt;
==Memory unit==&lt;br /&gt;
&lt;br /&gt;
Since there are only 5 bits of address space, I only need 256 memory cells. It should be fine if I don't use complicated column and row addressing schemes. I shall simply have 32 8-bit registers sticking somewhere. In order for the memory unit to work, I need a decoder to change the 5-bit address into 32 outputs. This will enable the memory unit to read and write from any register. I guess this makes it random access memory.&lt;br /&gt;
&lt;br /&gt;
===Decoder===&lt;br /&gt;
&lt;br /&gt;
This type of decoder is called an n to 2^n decoder, since it converts n inputs into 2^n outputs, in this case 5 to 32(2^5).&lt;br /&gt;
&lt;br /&gt;
To illustrate the design for this unit, let us consider a simpler example where n=2. There will be 2  binary inputs which will be converted into 4 unique outputs, 1 for each memory address.&lt;br /&gt;
&lt;br /&gt;
Here is the truth table for the operation:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=1 style=&amp;quot;text-align:center&amp;quot; cellpadding=&amp;quot;2&amp;quot; cellspacing=&amp;quot;0&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|2^0 (1)&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|2^1 (2)&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|O0&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|O1&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|O2&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|O3&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
|}&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now let us examine the implementation into the dwarfputer. Remember that gear assemblies are toggleable. I can implement a NOT operation by simply reversing the default state of a triggered gear (which is OFF in this system).&lt;br /&gt;
&lt;br /&gt;
Let us represent the 2^0 gear as A when it is default OFF and as a when it is default ON, and represent the 2^1 gear as B and b. O0 to O3 represent output devices.&lt;br /&gt;
&lt;br /&gt;
 P  P  P  P&lt;br /&gt;
 a  A  a  A&lt;br /&gt;
 b  b  B  B&lt;br /&gt;
 O0 O1 O2 O3&lt;br /&gt;
&lt;br /&gt;
This is the easiest to understand implementation. Looking at O0, we see that O0 is powered only when a and b are active. This corresponds to the state when 2^0 and 2^1 are both 0. Examining all the devices reveals that this arrangement obeys the truth table detailed above. Further examination would reveal that this arrangement also follows a pattern. Basically, the full set of columns represent every single possible combination of a, A, b, and B. Therefore we can easily see how to expand this system to n=5.&lt;br /&gt;
&lt;br /&gt;
However, this implementation is not the most efficient one. I can also arrange the gears like so:&lt;br /&gt;
&lt;br /&gt;
 O3A AO1&lt;br /&gt;
   BPb&lt;br /&gt;
 O2a aO0&lt;br /&gt;
&lt;br /&gt;
This arrangement uses 7 gears while the first arrangement uses 12 gears (including power gears). I put B and b closest to the power supply to obtain an orderly arrangement of O0 to O3 although this isn't strictly necessary.&lt;br /&gt;
&lt;br /&gt;
Schematically this arrangement looks like this:&lt;br /&gt;
&lt;br /&gt;
[[Image:2nscheme.png|Schematic of a 2 to 4 decoder]]&lt;br /&gt;
&lt;br /&gt;
Which is just some sort of tree diagram. I can easily expand this to n=5 which is what I want.&lt;br /&gt;
&lt;br /&gt;
[[Image:5nscheme.png|Schematic of a 5 to 32 decoder]]&lt;br /&gt;
&lt;br /&gt;
I drew this diagram in rectangular form so that I can better see how to construct the decoder. The outputs of the decoder will be in a 4x8 grid. Since the output units are longer in one direction than the other, I will align their long axis along the short axis of the diagram. It is probably best to place all the mechanisms for the decoder in the level above the outputs.&lt;br /&gt;
&lt;br /&gt;
===Memory unit registers===&lt;br /&gt;
&lt;br /&gt;
The registers in the memory unit need some modification to work correctly. Only the register indicated in the memory address register ought to respond to read write signals. Therefore each of the 32 registers needs to be connected to one of the outputs from the decoder.&lt;br /&gt;
&lt;br /&gt;
In this example, the register only responds when 00000 is in the memory address register.&lt;br /&gt;
&lt;br /&gt;
 ##### ##### ##### ##### ##### ##### ##### ##### &lt;br /&gt;
 #H#.# #H#.# #H#.# #H#.# #H#.# #H#.# #H#.# #H#.# &lt;br /&gt;
 #^#^# #^#^# #^#^# #^#^# #^#^# #^#^# #^#^# #^#^# &lt;br /&gt;
 #%#%# #%#%# #%#%# #%#%# #%#%# #%#%# #%#%# #%#%# &lt;br /&gt;
 W%`%o W%`%o W%`%o W%`%o W%`%o W%`%o W%`%o W%`%o &lt;br /&gt;
 I~`~RCI~`~RCI~`~RCI~`~RCI~`~RCI~`~RCI~`~RCI~`~R&lt;br /&gt;
 CP```P`````P`````P`````P`````P`````P`````P```PC&lt;br /&gt;
&lt;br /&gt;
C in this diagram represents the output O0. I believe this is called the chip select signal in real computers.&lt;br /&gt;
&lt;br /&gt;
It may be possible to wire the decoder directly to the power supply of the memory, which would remove the need for an output device. &lt;br /&gt;
&lt;br /&gt;
===Memory unit architecture===&lt;br /&gt;
&lt;br /&gt;
Right, I based the design of the memory unit off a java applet simulator I found on the Internet. &lt;br /&gt;
&lt;br /&gt;
[[Image:Memarchi.png|Schematic of the memory unit's architecture]]&lt;br /&gt;
&lt;br /&gt;
What this diagram is supposed to illustrate is that ALL the memory cells are linked to respond to the same read-out signal and the same write-in signal. Similarly, all the corresponding cells respond to same input, and all output to the same place. However, they will do none of these things unless they get a signal from the decoder, and only one register will get the signal as indicated in the memory address register. &lt;br /&gt;
&lt;br /&gt;
Now the input and output buffers shown here may not be in the final blueprints, depending on the design of the rest of the computer.&lt;br /&gt;
&lt;br /&gt;
==Machine language design==&lt;br /&gt;
&lt;br /&gt;
The machine language is the set of instructions the computer will be able to execute. What these instructions are will define the design of the remaining components. For example, the Arithmetic Logic Unit needs to be able to perform the various operations listed in these instructions.&lt;br /&gt;
&lt;br /&gt;
Ideally this language should be complete, that is, any function can be simulated as a combination of these instructions. I also want to be as simple as possible, to minimize the complexity of the ALU. It is worth restating that I am basing the overall design for the computer on a design for a VSC off the Internet.&lt;br /&gt;
&lt;br /&gt;
Since the opcode for this computer is 3-bits long, there can only be 8 instructions.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=1 style=&amp;quot;text-align:center&amp;quot; cellpadding=&amp;quot;2&amp;quot; cellspacing=&amp;quot;0&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Opcode&lt;br /&gt;
!Function&lt;br /&gt;
!Operand&lt;br /&gt;
|-&lt;br /&gt;
| 000&lt;br /&gt;
| Load Accumulator from memory (indirectly)&lt;br /&gt;
| Memory Address&lt;br /&gt;
|-&lt;br /&gt;
| 001&lt;br /&gt;
| Store Accumulator to memory&lt;br /&gt;
| Memory Address&lt;br /&gt;
|-&lt;br /&gt;
| 010&lt;br /&gt;
| Add&lt;br /&gt;
| Memory Address&lt;br /&gt;
|-&lt;br /&gt;
| 011&lt;br /&gt;
| Subtract&lt;br /&gt;
| Memory Address&lt;br /&gt;
|-&lt;br /&gt;
| 100&lt;br /&gt;
| Jump to address if accumulator is not negative&lt;br /&gt;
| Memory Address&lt;br /&gt;
|-&lt;br /&gt;
| 101&lt;br /&gt;
| Binary shift left (*2) (input 0 as LSB)&lt;br /&gt;
| Memory Address&lt;br /&gt;
|-&lt;br /&gt;
| 110&lt;br /&gt;
| Binary shift right (/2) (retain MSB)&lt;br /&gt;
| Memory Address&lt;br /&gt;
|-&lt;br /&gt;
| 111&lt;br /&gt;
| Halt&lt;br /&gt;
| None&lt;br /&gt;
|}&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Arithmetic Logic Unit (ALU)==&lt;br /&gt;
&lt;br /&gt;
Now I know that the ALU needs to be able to perform 4 functions: Add, subtract, shift left and shift right. The unit needs to do one of these functions based on one of 4 input signals it may receive.&lt;br /&gt;
&lt;br /&gt;
The ALU will receive 2 8-bit inputs and produce 1 8-bit output. It will require 3 systems, the adder-subtractor, bitshift left and bitshift right. These systems would be integrated to form the ALU.&lt;br /&gt;
&lt;br /&gt;
===Half adder===&lt;br /&gt;
&lt;br /&gt;
While there are existing dwarven adder designs out there, they do not come with schematics detailing the links between their components. Therefore I feel the need to design from scratch.&lt;br /&gt;
&lt;br /&gt;
A simple half adder would take 2 inputs, and produce an output and an overflow output called a carry.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=1 style=&amp;quot;text-align:center&amp;quot; cellpadding=&amp;quot;2&amp;quot; cellspacing=&amp;quot;0&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|A&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|B&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|C&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|O&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
|}&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &lt;br /&gt;
 Carry out circuit  C==ABP&lt;br /&gt;
&lt;br /&gt;
                       aBP&lt;br /&gt;
 Output circuit     O==o&lt;br /&gt;
                       bAP&lt;br /&gt;
&lt;br /&gt;
                  C===A&lt;br /&gt;
 Combined circuit    aBP&lt;br /&gt;
                  O==obA&lt;br /&gt;
&lt;br /&gt;
This schematic shows a dwarven half adder that obeys the above truth table. In this diagram, the o represents a normal gear assembly and = represents axles. This design rests on the assumption that axles do not receive power except from their end tiles. It also takes advantage of the assumption that a matched pair of gears will not transmit information across their connection (here it is the B and b gear)&lt;br /&gt;
&lt;br /&gt;
I believe this design uses the minimum number of gear assemblies, although I am not sure.&lt;br /&gt;
&lt;br /&gt;
===Full adder===&lt;br /&gt;
&lt;br /&gt;
In order for an adder to work properly, it must also receive the carry bit in addition to the 2 inputs. Ultimately, even the first adder in the final adder-subtracter must be able to receive a carry bit to operate successfully, which is why I didn't draw up a full plan for the half adder.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=1 style=&amp;quot;text-align:center&amp;quot; cellpadding=&amp;quot;2&amp;quot; cellspacing=&amp;quot;0&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|A&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|B&lt;br /&gt;
!C (carry in)&lt;br /&gt;
!O2 (carry out)&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|O1&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
|}&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 PB&lt;br /&gt;
 CAo==O2       Carry Out Circuit&lt;br /&gt;
 oBo&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 o=o=o=o==O1   Output Circuit&lt;br /&gt;
 C c c C&lt;br /&gt;
 B b B b&lt;br /&gt;
 A A a a&lt;br /&gt;
 P P P P&lt;br /&gt;
&lt;br /&gt;
     O1 O2     Combined Circuit&lt;br /&gt;
  oo=oo |&lt;br /&gt;
  Cc cC oo&lt;br /&gt;
  Bb BbBAB&lt;br /&gt;
 PAo oaPCo&lt;br /&gt;
&lt;br /&gt;
Now that looks pretty monstrous. Undoubtedly the arrangement of gears could be changed here and there depending on the exact dimensions you need the array to be, but hopefully this diagram illustrates methods that can be used to minimize the complexity of the device. Note that where there are adjacent identical gears directly connected to the power source, one of them can be replaced by an ordinary gear, which will remove a linking task for that gear.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   `````   oCBAP&lt;br /&gt;
   ````    ocbo&lt;br /&gt;
 #####   ``|``&lt;br /&gt;
 #.#.#`  ``ocBo&lt;br /&gt;
 #^#^#`  `ooCba     Hypothetical implementation&lt;br /&gt;
 #%#%#`  `o``BP&lt;br /&gt;
 `%`%``  ```oAC&lt;br /&gt;
 `~`~``  ```oBo&lt;br /&gt;
 `````   `````&lt;br /&gt;
  lvlz     lvlz+1&lt;br /&gt;
&lt;br /&gt;
The above diagram details a hypothetical implementation for a full adder. The ```s represent the shadow of the mechanisms above and below the level. The left power sensor produces the output signal while the right power sensor produces the carry signal to be relayed to the next adder. The total footprint of the unit is 6x9. In an array, the units can overlap one tile so the total footprint of an 8-bit adder would be 41x9. Maximum operational power draw is 131x8(1048) units of power.&lt;br /&gt;
&lt;br /&gt;
===8-bit ripple-carry adder-subtracter===&lt;br /&gt;
&lt;br /&gt;
[[Image:Rippleaddersubtracter.png|Schematic of an 8-bit ripple-carry adder-subtractor]]&lt;br /&gt;
&lt;br /&gt;
In order to build a full 8-bit adder-subtracter, all you need to do is to stack up 8 full adders next to each other and ensure that all the gears have been linked to the appropriate plates.&lt;br /&gt;
&lt;br /&gt;
Now to get the adder-subtracter to subtract, all you have to do is to link up every single A and a (or B and b) gear assembly to the pressure plate sending the subtract signal. When the signal is sent, all the gears linked to a register will toggle. This will have the effect of inverting whatever input the register is sending. Finally the signal also needs to activate the carry in gears in the first adder, which will have the effect of adding 1 to the resulting sum (difference), giving the correct answer in two's complement representation.&lt;br /&gt;
&lt;br /&gt;
===Carry-look-ahead adder===&lt;br /&gt;
&lt;br /&gt;
I did some research into carry-look-ahead adders to see if it was worth implementing. Carry-look-ahead adders are faster than ripple-carry adders as ripple carry adders have to wait for the carry bit to 'ripple' through the chain of adders before getting the correct result. This is most significant for users of fluid logic, as fluid logic adders need to wait n*100 steps (n being the number of bits) for the carry to ripple all the way to the end. (Floodgates and bridges have a 100 step delay before activating or deactivating)&lt;br /&gt;
&lt;br /&gt;
I found that I could easily design a carry-look-ahead adder using mechanical logic that calculates the carry in bit for all bits in a single step. I would also like to point out that real carry-look-ahead adders are more complicated because they don't have teleporting switch signals. &lt;br /&gt;
&lt;br /&gt;
Firstly, looking at the carry-out circuit for the full adder, I see that not only can it exist independently from the sum circuit, the C gear is directly attached to the power source. I can take advantage of this by separating the carry bit calculation circuits from the adder and attaching them to each other like so. &lt;br /&gt;
&lt;br /&gt;
[[Image:Carrycircuit.png|Schematic of a carry calculation circuit for a carry-look-ahead adder]]&lt;br /&gt;
&lt;br /&gt;
Then for the summing part of the adder, I simply build only the output circuit, which I can now simplify like this&lt;br /&gt;
&lt;br /&gt;
     O1     Output Circuit&lt;br /&gt;
  oo=oo&lt;br /&gt;
  Cc cC&lt;br /&gt;
  Bb Bb&lt;br /&gt;
  oAPao&lt;br /&gt;
&lt;br /&gt;
Or I can make it long instead of square so that it will tile better with the output buffers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    O1&lt;br /&gt;
    |&lt;br /&gt;
 oBCoCbo&lt;br /&gt;
 AbcocBa&lt;br /&gt;
 P     P&lt;br /&gt;
&lt;br /&gt;
I could construct these directly above the output buffers and they would all tile a lot better. Not only that, it fits almost perfectly within the footprint of a bank of output buffers. There is also no cost of increased complexity, only spatial separation between the summation unit and the carry unit, plus providing all the advantages of the carry-look-ahead system.&lt;br /&gt;
&lt;br /&gt;
Since this system is superior in all ways to the ripple-carry system, this will be the one going into the final dwarven computer.&lt;br /&gt;
&lt;br /&gt;
===Bitshifting operations===&lt;br /&gt;
&lt;br /&gt;
Setting up a bitshifting operation is relatively simple. I simply wire the inputs directly into slightly different outputs as illustrated in the following diagrams (source: Wikipedia http://en.wikipedia.org/wiki/Bitwise_operation#Arithmetic_shift).&lt;br /&gt;
&lt;br /&gt;
[[Image:175px-Rotate right arithmetically.svg.png|Bitshift Right]]&lt;br /&gt;
&lt;br /&gt;
[[Image:Rotate left logically.svg.png|Bitshift Left]]&lt;br /&gt;
&lt;br /&gt;
Ideally all these operations would be linked into the same bank of output buffers in the assembled ALU, which will be the subject of the next section.&lt;br /&gt;
&lt;br /&gt;
===ALU architecture===&lt;br /&gt;
&lt;br /&gt;
[[Image:Aluarchi.png|Schematic of the ALU architecture]]&lt;br /&gt;
&lt;br /&gt;
This diagram illustrates the various signals moving around the ALU. I decided that I ought to dragoon the ALU into incrementing the program counter as well, but I'm not sure whether that will work or not. We'll see in the later sections.&lt;br /&gt;
&lt;br /&gt;
I defined the inputs from AR1 to be A since there are fewer A and a gears in the current designs and they all have to be toggled by the subtract signal. The operations listed on the right are signals generated by the control unit and they tell the ALU which operation to perform and transfer to the output buffer banks. The component critical to this function is the multiplexer. &lt;br /&gt;
&lt;br /&gt;
The concept of the multiplexer is quite simple, suppose I had 2 inputs I and J, and I wanted to choose which one to pass based on signals Q and R, I would have to build something like this&lt;br /&gt;
&lt;br /&gt;
 PQIoJRP&lt;br /&gt;
    |&lt;br /&gt;
    O&lt;br /&gt;
&lt;br /&gt;
Adding a multiplexer onto the output circuit would require an additional z-level if the tiling efficiency is to be maintained. &lt;br /&gt;
&lt;br /&gt;
[[Image:ALUmulti.png|Schematic of a ALU multiplexer implementation]]&lt;br /&gt;
&lt;br /&gt;
This diagram illustrates a hypothetical implementation of the multiplexer, as well as the bitshifting logic. I don't think I need a support axle on z+2 as it should be supported by O1.&lt;br /&gt;
&lt;br /&gt;
==Bus design==&lt;br /&gt;
&lt;br /&gt;
I've decided to ditch the plan for a bus, which would have been the conduit for data transfers between registers throughout the computer. Initially there were 2 methods, one had a output buffer attached to the end of the bus while the other the bus directly supplied power to the inputs of the appropriate registers. &lt;br /&gt;
&lt;br /&gt;
Method 2 would not work on memory cells that used an active pump for bit-clearing. Method 1 would have worked but the output buffers had to be overwritten every step and that could cause cascading delays throughout the computer. Since this computer is relatively simple, I opted for hard wiring everything instead.&lt;br /&gt;
&lt;br /&gt;
[[Image:Datatransfers.png|Schematic of the data transfers within the CPU]]&lt;br /&gt;
&lt;br /&gt;
This diagram illustrates the data transfers that occur throughout the computer. The red arrows depict confirmed hard-wired connections, while the blue arrows would have been routed through a bus. I've decide AR1 is superfluous so I got rid of it. As you can see, each register has at most 2 inputs or 2 outputs going through the bus, so hardwiring is feasible.&lt;br /&gt;
&lt;br /&gt;
==Timing circuit==&lt;br /&gt;
&lt;br /&gt;
Before the computer can execute its instructions, it needs to perform some operations first.&lt;br /&gt;
&lt;br /&gt;
#Transfer the contents of the accumulator to AR2. Dump instruction register and memory address register.&amp;lt;br&amp;gt;&lt;br /&gt;
#Transfer the program counter to the memory address register. Also, activate the program counter incrementation system in the ALU and transfer the results into program counter +1.&amp;lt;br&amp;gt;&lt;br /&gt;
#Load the data from memory at the specified address into the instruction register.&amp;lt;br&amp;gt;&lt;br /&gt;
#Transfer the data from program counter +1 to the program counter. Also, dump the memory address register&amp;lt;br&amp;gt;&lt;br /&gt;
#Load the last 5 digits of the instruction register into the memory address register. Also, dump program counter +1.&amp;lt;br&amp;gt;&lt;br /&gt;
#Execution (write accumulator, memory or program counter, read instruction register, memory, AR2)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There needs to be a 100 step delay from the time a memory cell is written (or dumped, if it is pre-dumped) and when it is read, or it may cause cascading delays. The writing process is practically instantaneous, but 100 steps are needed before the correct result can be read if the memory was not cleared to begin with. Of course this point is entirely moot if the computer is running automatically, in which case every step will last at least 100 steps anyway and the prime consideration is to ensure that every step can be performed in 100 steps.&lt;br /&gt;
&lt;br /&gt;
==Oscillator==&lt;br /&gt;
&lt;br /&gt;
A typical mechanical oscillator is unsatisfactory because it will usually be sending out 2 on signals at once, one from the pressure plate the water is on and the other from the pressure plate waiting to reset.&lt;br /&gt;
&lt;br /&gt;
 0%%6%%0%%5%%0%%4&lt;br /&gt;
 %              %&lt;br /&gt;
 %              %&lt;br /&gt;
 1%%0%%2%%0%%3%%0&lt;br /&gt;
&lt;br /&gt;
This diagram shows a 12 step 6 signal oscillator. At the locations marked 0, there are no pressure plates. A lever operates the mechanism. When the lever is in the ON position, the #%%0 pumps activate, and when the lever is in the OFF position, the 0%%# pumps activate. The oscillator can also be fully automated by using the pressure plates themselves to replace the lever function. The oscillator's power supply also needs to be cut if a halt signal is received from the control unit. &lt;br /&gt;
&lt;br /&gt;
===Oscillator link table===&lt;br /&gt;
&lt;br /&gt;
#Read accumulator, write AR2, write IR, write MAR&amp;lt;br&amp;gt;&lt;br /&gt;
#Read PC, write MAR, activate ALU (adder select, C0=1), write PC+1&amp;lt;br&amp;gt;&lt;br /&gt;
#Read MEM, read MAR. activate decoder, write IR&amp;lt;br&amp;gt;&lt;br /&gt;
#Read PC+1, write PC, write MAR&amp;lt;br&amp;gt;&lt;br /&gt;
#Read IR, write MAR, write PC+1&amp;lt;br&amp;gt;&lt;br /&gt;
#Execution (read IR, turn on control unit)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A dump operation can be performed by telling the memory register to write when its linked inputs are inactive, effectively writing 0s. &lt;br /&gt;
&lt;br /&gt;
==Control unit==&lt;br /&gt;
&lt;br /&gt;
The control unit can be implemented simply as a 3-8 decoder with appropriately linked pressure plates. The execute signal controlled gear assembly is located at the root of the decoder. &lt;br /&gt;
&lt;br /&gt;
===Control unit link table===&lt;br /&gt;
&lt;br /&gt;
:O0. Read memory, read MAR, activate decoder, write accumulator, select transfer&amp;lt;br&amp;gt;&lt;br /&gt;
:O1. Read accumulator, write memory, read MAR, activate decoder&amp;lt;br&amp;gt;&lt;br /&gt;
:O2. Read memory, read MAR, activate decoder, read AR2, Send Add signal to ALU (adder select), write accumulator&amp;lt;br&amp;gt;&lt;br /&gt;
:O3. Read memory, read MAR, activate decoder, read AR2, Send Subtract signal to ALU (adder select, C0=1, invert input A), write accumulator&amp;lt;br&amp;gt;&lt;br /&gt;
:O4. Read IR, write PC if ACC7=0&amp;lt;br&amp;gt;&lt;br /&gt;
:O5. Read memory, read MAR, activate decoder, Send Shift left signal to ALU (SHL select), write accumulator&amp;lt;br&amp;gt;&lt;br /&gt;
:O6. Read memory, read MAR, activate decoder, Send Shift right signal to ALU (SHR select), write accumulator&amp;lt;br&amp;gt;&lt;br /&gt;
:O7. Cut power to oscillator.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
[[DF2010:Computing|Computing]]&lt;br /&gt;
&lt;br /&gt;
==External links==&lt;br /&gt;
*[http://docs.google.com/Doc?docid=0AdISzBuNg6ZWZGd0d2t4YjlfMjJ0ejlzc2dnaA&amp;amp;hl=en GoogleDocs Design Manuscript]&lt;br /&gt;
*[http://www.bay12forums.com/smf/index.php?topic=49641.0 Bay12 Forums thread] - Includes discussion on modifications and testing results&lt;br /&gt;
*[http://mkv25.net/dfma/map-8269 Map at DF Map Archive]&lt;br /&gt;
*[http://dffd.wimbli.com/file.php?id=1929 Save File at DF File Depot]&lt;/div&gt;</summary>
		<author><name>Jong</name></author>
	</entry>
	<entry>
		<id>https://dwarffortresswiki.org/index.php?title=v0.31:Computing&amp;diff=101112</id>
		<title>v0.31:Computing</title>
		<link rel="alternate" type="text/html" href="https://dwarffortresswiki.org/index.php?title=v0.31:Computing&amp;diff=101112"/>
		<updated>2010-04-30T09:36:27Z</updated>

		<summary type="html">&lt;p&gt;Jong: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{av}}&lt;br /&gt;
{{human}}&lt;br /&gt;
Computing in dwarf fortress is the practice of setting up complex constructions to perform logical operations and calculations, ideally to control some functionality of your fortress. Even if it isn't a young concept anymore, there is still lots of room for improvement and development. One reason is that there are many ways to solve one problem. Innovation and invention is encouraged.&lt;br /&gt;
=== Binary information ===&lt;br /&gt;
Binary information can have one of two possible states: true or false, respectively 1 or 0. In dwarf fortress they can be represented by different entities:&lt;br /&gt;
* on/off state or signal of a {{l|trigger|trigger}} (pressure plate, lever)&lt;br /&gt;
* power or connection state of a {{l|machine component|machine component}}&lt;br /&gt;
* open or closed state of a {{l|door|door}} or similar buildings&lt;br /&gt;
* {{l|pressure plate|low/high}} or {{l|flow|flowing/standing}} {{l|water|fluid}}&lt;br /&gt;
* present {{l|creature|creature}}s and {{l|dwarf|borgs}}&lt;br /&gt;
&lt;br /&gt;
Electronic devices and computers base on this elementary form of information, and if you want to go into computing, you’ll have to familiarize yourself with it. [http://en.wikipedia.org/wiki/Propositional_calculus propositional calculus]&lt;br /&gt;
=== Input/Output ===&lt;br /&gt;
Input can be any device which can be linked to another device with mechanisms, such as {{l|lever|levers}} or {{l|pressure plate|pressure plates}}. Pressure plates can measure water, magma, or creature weight, and can be set to react to your own dwarves if measuring creature weight. If measuring water or magma you specify the minimum and maximum levels at which it should output 'on', and at all other levels it will output an 'off' signal. Regardless of the actual amount of water, magma, or creature weight on your pressure plate, the plate can only output an 'on' or 'off' signal (1 or 0) to whatever devices it is linked to. So everything you build will have a binary base.&lt;br /&gt;
&lt;br /&gt;
====Input elements====&lt;br /&gt;
* manual: {{l|lever|lever}} -&amp;gt; binary on/off signal&lt;br /&gt;
* triggered: {{l|pressure plate|pressure plate}} -&amp;gt; binary on/off signal&lt;br /&gt;
&lt;br /&gt;
According to input, output can be anything that is able to react to an on/off signal. This can be doors, bridges, floodgates allowing or stopping flow, gears controlling pumps and much more. In some special configurations - when {{l|mechanical logic|mechanical logic}} is involved - output may not be a on/off signal but power, thus running or not running a machine component.&lt;br /&gt;
&lt;br /&gt;
Currently to convert from power to an on/off signal, the only way is to use a screw pump connected to that power source with an unlimited amount of water and drainage at the output, and a pressure plate to measure whether water is being pumped out by the pump.&lt;br /&gt;
&lt;br /&gt;
====Output elements====&lt;br /&gt;
* signal: {{l|pressure plate|pressure plate}} -&amp;gt; binary on/off signal -&amp;gt; linkable Object(s)&lt;br /&gt;
* power: {{l|gear assembly|gear assembly}} -&amp;gt; binary power on/power off -&amp;gt; machine&lt;br /&gt;
&lt;br /&gt;
=== Binary logic ===&lt;br /&gt;
Basic binary logic takes one or two input bits and creates an output based on them. The devices that perform these operations are commonly called '''logic gates'''.&amp;lt;br /&amp;gt;&lt;br /&gt;
* NOT - takes one input and returns the opposite of the input&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=1&lt;br /&gt;
|-&lt;br /&gt;
! input A &lt;br /&gt;
! NOT&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
|}&amp;lt;br /&amp;gt;&lt;br /&gt;
* AND - takes two inputs and returns true if both inputs are true&lt;br /&gt;
* OR - takes two inputs and returns true if at least one input is true&lt;br /&gt;
* XOR - takes two inputs and returns true if exactly one input is true&lt;br /&gt;
* NAND - takes two inputs and returns true if either input is false&lt;br /&gt;
* NOR - takes two inputs and returns true if both inputs are false&lt;br /&gt;
* NXOR - takes two inputs and returns true if both inputs are identical&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=1&lt;br /&gt;
|-&lt;br /&gt;
! input A&lt;br /&gt;
! input B&lt;br /&gt;
! AND&lt;br /&gt;
! OR&lt;br /&gt;
! XOR&lt;br /&gt;
! NAND&lt;br /&gt;
! NOR&lt;br /&gt;
! NXOR&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
|}&amp;lt;br /&amp;gt;&lt;br /&gt;
The most human-understandable logic system requires NOT, AND and OR gates, but having a design for either a NAND or a NOR gate is enough to build any of the other gates. Some gates are easier to create or need fewer components than others depending on what discipline your logic relies on. Designing each individual gate that you will need (or using designs that had each individual gate designed) rather than building a gate out of multiple NAND gates or the like will generally result in your dorfputer reacting faster and using less resources (power, water, kittens, construction materials, what-have-you).&lt;br /&gt;
&lt;br /&gt;
=== Complex gates ===&lt;br /&gt;
* {{l|Latch|Latch}} - storing and reading a single binary value&lt;br /&gt;
* {{l|Repeater|Repeater}} - sending a repeating signal&lt;br /&gt;
* {{l|Counter|Counter}}/{{l|Adder|Adder}} - binary calculation&lt;br /&gt;
&lt;br /&gt;
== Disciplines ==&lt;br /&gt;
Historically, prior to DF2010 there have been 3 main disciplines of dwarfputing, depending on what would drive the dwarfputer. Each of them had its assets and drawbacks. So far, DF2010 at 0.31.01 appears to be essentially the same as far as power transmission goes, barring some differences with pump vertical power transmission (they don't without the floor between being channeled, apparently). Science! will determine what, if anything, differs as far as water flow, falling, and animal pathfinding.&lt;br /&gt;
&lt;br /&gt;
The three disciplines are:&lt;br /&gt;
=== Fluid logic ===&lt;br /&gt;
{{l|Infinite flow fluid logic|Infinite flow fluid logic}} is controlling the ''flow of fluid'' over different pressure plates. Fluid logic can be easily constructed and every known logic gate in dwarf fortress has already been built with it. On the other hand this discipline depends on a somehow unlimited source of the used fluid to deal with its {{l|evaporation|evaporation}} and {{L|Water#Water in Fortress Mode|destruction}}.&lt;br /&gt;
=== Mechanical logic ===&lt;br /&gt;
{{l|Mechanical logic|Mechanical logic}} uses systems of axles and {{l|gear assemblies|gear assemblies}} to build logical gates. Mechanical logic reacts very fast and can be easily constructed, except for the need for a fluid-pump-based power-&amp;gt;signal converter in every gate. Since every gear can itself be linked to a trigger (or multiple triggers), and automatically connect to adjacent gears for transferring either power or load, mechanical logic gates are very flexible and don't require anywhere near the number of different devices that tend to be used in fluid logic gates (except, again, for the requirement for a fluid-pump-based power-&amp;gt;signal converter in every gate, unless you intend to use it to control a pump). On the other hand this discipline uses a LOT of mechanical power, and due to the lack of a power-&amp;gt;signal converter, also referred to as a &amp;quot;rotation sensor&amp;quot; (a device to convert from power to on/off link signals), you need to build one using fluid logic components if you want to connect multiple mechanical logic gates together or connect a mechanical logic gate to any output other than a pump.  There is, however, now a fully functional fluid preserving rotation sensor design.  So, in truth, current mechanical logic is more correctly termed mechanical-fluid hybrid logic, as you need some source of fluid to &amp;quot;prime&amp;quot; the rotation sensors your design will need.  Along with new techniques to construct logic gates by &amp;quot;pre-toggling&amp;quot; a gear assembly (see {{l|Pre-Toggled Mechanical Logic|Pre-Toggled Mechanical Logic}}), any logical circuit can be built, given enough space in the game to do it.&lt;br /&gt;
=== Animal logic ===&lt;br /&gt;
{{l|Animal logic|Animal logic}} places animals in an enclosed room, with a door blocking the path to where they desire to go, and a pressure plate below a hatch, with obstacles which are controlled by triggers. The animal thinks it can walk through the door, and if it has a path to the door will walk up to it and stand on the hatch. When the hatch is opened by a trigger, it falls onto the pressure plate. As long as the hatch is open, or other obstacles block its path to the door it remains on the pressure plate and the output is 'on'. Once it sees a path to the door it will leave the pressure plate. Generally this is made possibly by the fact that animals try to go to their parent while they're children, or to the meeting area. There are also be designs which use captured hostiles.&lt;br /&gt;
&lt;br /&gt;
There was a fourth, theoretical, discipline, Borg Logic, but there was never any reported success inventing any functioning and useful borg logic systems.&lt;br /&gt;
&lt;br /&gt;
===Examples of things you could do with logic gates===&lt;br /&gt;
* Repeater: Repeatedly toggling hatches open and closed, or spikes up and down.&lt;br /&gt;
* Latch: Making resettable one-use pressure plates which are reset by a lever.&lt;br /&gt;
* NOT gate: Reversing the effect of a switch or creature-sensing pressure plate, generally linked to a latch device. You can, of course, mod the latch device to send the opposite signal instead of using a NOT gate.&lt;br /&gt;
* AND gate: Requiring more than one condition to be true for something to occur. For instance, you could have a group of AND gates, with a system on/off switch, and and other triggers, with each trigger linked to a different AND gate with the system on/off switch linked to the the second input on all the AND gates, so that when the system on/off switch is OFF the output will be OFF on all the AND gates.&lt;br /&gt;
* OR gate: You could link two 1-7 water sensors to an OR gate, and link that to a NOT gate, and link that to some floodgates or doors which act as emergency bulkheads, closing when water is detected in the area. Or, link the OR gate to bridges which raise instead (but you may crush things, and bridges are slower than doors).&lt;br /&gt;
* XOR gate: You could use pressure plates hooked to latches at different points in your fort to detect enemy intrusion, and set them up to seal off the area with both an interior and exterior bulkhead when the intrusion occurs, but hook your latches up with an XOR gate and hook the output to the interior bulkhead to unseal that one if your pressure plates have detected that the enemy has gotten past it.&lt;br /&gt;
* NOR gate: A NOR gate returns TRUE (ON) only if both inputs are FALSE. Instead of using the OR gate example with a NOT gate, you could use a NOR gate linked to two 1-7 water sensors, whose output goes to doors or floodgates. When the pressure plates are both waterless, the floodgates will be open. When one detects water, the floodgates close. (If you used 0-0 pressure plates with an OR, you would get an OFF signal if both plates detected water, or an ON signal otherwise (which is the same as 1-7 NAND 1-7))&lt;br /&gt;
* NAND gate: A NAND gate returns TRUE (ON) whenever both inputs are not both TRUE (e.g. ON NAND ON is OFF, but every other combination is ON). Instead of the OR NOT or NOR example, you could link two 0-0 water sensors to a NAND gate, and link the NAND gate's output to raising bridges. 0-0 NAND 0-0 is the same as 1-7 OR 1-7. If there is no water on both pressure plates, the NAND gate will output an OFF signal. If, however, either has water, it will output an ON signal.&lt;br /&gt;
&lt;br /&gt;
* And here's a more complicated example, omitting the details of what gates to use: An automated swimming training room, where you pull a lever to close exit doors and open hatches to drop water into it, then pressure plates detect when there's enough water and close the hatches, and after a certain amount of time (using a very slow repeater, for instance), drains and exit doors open and the system resets until you pull the lever again. Or, the lever could be taken out entirely and the system could be made fully automatic (with dwarves set to train in the room, for instance) using the repeater.&lt;br /&gt;
&lt;br /&gt;
{{buildings}}&lt;br /&gt;
&lt;br /&gt;
== Related user pages ==&lt;br /&gt;
*[[User:BaronW]] - The Almighty Dwarven Calculator&lt;br /&gt;
*[[User:Jong]] - The first fully programmable digital Dwarven Computer&lt;/div&gt;</summary>
		<author><name>Jong</name></author>
	</entry>
	<entry>
		<id>https://dwarffortresswiki.org/index.php?title=User:Jong&amp;diff=101111</id>
		<title>User:Jong</title>
		<link rel="alternate" type="text/html" href="https://dwarffortresswiki.org/index.php?title=User:Jong&amp;diff=101111"/>
		<updated>2010-04-30T09:32:55Z</updated>

		<summary type="html">&lt;p&gt;Jong: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Dwarven Computer==&lt;br /&gt;
[[Image:DCOverview.png|thumb|Overview of the Dwarven Computer]]&lt;br /&gt;
{{Main|User:Jong/Dwarven_Computer}}&lt;br /&gt;
&lt;br /&gt;
I successfully built first fully programmable digital computer in Dwarf Fortress! It has been tested and works as expected, although incredibly slow.&lt;br /&gt;
&lt;br /&gt;
I did make a few changes from the documented design in the final implementation, but the basic design is sound and should only have a few bugs. &lt;br /&gt;
&lt;br /&gt;
==Single-Stage carry-look-ahead adder==&lt;br /&gt;
&lt;br /&gt;
In another [http://www.bay12forums.com/smf/index.php?topic=55380.0 thread] on the official forums, I came up with an improved design for a carry-look-ahead adder. [[Image:Single stage adder.png|thumb|Single Stage Adder]]&lt;br /&gt;
&lt;br /&gt;
It directly attaches the output gears of the carry calculation circuit to the root of the sum circuit's gear tree, where the carry-in gears would have been. This allows the power availability, which is determined by the carry circuit, to substitute for a toggled gear and thus making the whole adder single stage.&lt;br /&gt;
&lt;br /&gt;
I further optimized the design by replacing most of the simple single-input gears with double input gears that were mentioned in that thread as well. This greatly reduced the complexity of the adder. &lt;br /&gt;
&lt;br /&gt;
==Binary Multiplier==&lt;br /&gt;
&lt;br /&gt;
===Multiple Input Adder===&lt;br /&gt;
&lt;br /&gt;
Given the efficiency of my new adder design, and multiple input design, I have been considering the problem of creating an efficient multiple input adder, which could be used as a component of a binary multiplier. &lt;br /&gt;
&lt;br /&gt;
It turns out that the sum calculation circuit needs no modification at all, as it simply determines whether the total of the inputs and the carry is odd or even, producing a result when it is odd.&lt;br /&gt;
&lt;br /&gt;
However the carry calculation could become very complex, as the quantity of the carry is variable depending on the total number of inputs. For example 1+1+1+1 gives 100, which is 2 units down the row.&lt;/div&gt;</summary>
		<author><name>Jong</name></author>
	</entry>
	<entry>
		<id>https://dwarffortresswiki.org/index.php?title=File:Single_stage_adder.png&amp;diff=101110</id>
		<title>File:Single stage adder.png</title>
		<link rel="alternate" type="text/html" href="https://dwarffortresswiki.org/index.php?title=File:Single_stage_adder.png&amp;diff=101110"/>
		<updated>2010-04-30T09:19:49Z</updated>

		<summary type="html">&lt;p&gt;Jong: Schematic of a single-stage carry-look ahead adder.

The gears indicated by the lighter circles are disengaged by default while the gears indicated by th bold coloured circles are engaged by default.

Gears labeled with multiple letters indicates that mul&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Schematic of a single-stage carry-look ahead adder.&lt;br /&gt;
&lt;br /&gt;
The gears indicated by the lighter circles are disengaged by default while the gears indicated by th bold coloured circles are engaged by default.&lt;br /&gt;
&lt;br /&gt;
Gears labeled with multiple letters indicates that multiple inputs are linked to the gear.&lt;/div&gt;</summary>
		<author><name>Jong</name></author>
	</entry>
	<entry>
		<id>https://dwarffortresswiki.org/index.php?title=File:DCOverview.png&amp;diff=101109</id>
		<title>File:DCOverview.png</title>
		<link rel="alternate" type="text/html" href="https://dwarffortresswiki.org/index.php?title=File:DCOverview.png&amp;diff=101109"/>
		<updated>2010-04-30T09:07:23Z</updated>

		<summary type="html">&lt;p&gt;Jong: Overview of the Dwarven Computer&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Overview of the Dwarven Computer&lt;/div&gt;</summary>
		<author><name>Jong</name></author>
	</entry>
	<entry>
		<id>https://dwarffortresswiki.org/index.php?title=User:Jong/Dwarven_Computer&amp;diff=101106</id>
		<title>User:Jong/Dwarven Computer</title>
		<link rel="alternate" type="text/html" href="https://dwarffortresswiki.org/index.php?title=User:Jong/Dwarven_Computer&amp;diff=101106"/>
		<updated>2010-04-30T08:56:11Z</updated>

		<summary type="html">&lt;p&gt;Jong: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page documents the design of my Dwarven Computer. A number of designs were modified for the final implementation.&lt;br /&gt;
&lt;br /&gt;
Adapted from my GoogleDocs [http://docs.google.com/Doc?docid=0AdISzBuNg6ZWZGd0d2t4YjlfMjJ0ejlzc2dnaA&amp;amp;hl=en manuscript]&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&lt;br /&gt;
Toggled gear assemblies are designed as though they are off in when untriggered. However they are constructed in the on position. This means that you need to build and link a lever to toggle it to the off state.&lt;br /&gt;
&lt;br /&gt;
==Power sensor (output device)==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  # %&amp;gt;^ #     &lt;br /&gt;
 ~ ~ ~ ~#      Power sensor side view&lt;br /&gt;
&lt;br /&gt;
In order to do useful things, such as toggling gears assemblies, opening doors, etc., mechanical power signals need to be converted to a trigger signal. There are only 2 trigger signal generators in dwarf fortress. One is the lever, which cannot be linked to machine power. The other is a pressure plate, which can.&lt;br /&gt;
&lt;br /&gt;
The basic operation of this component is simple. Power operates the pump, pushing water over the pressure plate, generating a signal. When the pump is not powered, the water drains, switching the pressure plate off after at least 100 steps.&lt;br /&gt;
&lt;br /&gt;
The smooth operation of this unit depends on several factors:&lt;br /&gt;
1. Adequate supply of water in the input tile so that the pump can maintain 7/7 or 6/7 water levels on the pressure plate. Can be done by providing more water tiles adjacent to the input tile.&lt;br /&gt;
2. Fast drainage to minimize the time needed for the plate to switch off. Just make sure that the level below the pumps is not completely full.&lt;br /&gt;
3. Since the minimum recovery time of the pressure plate is 100 steps, it can take a good long time for a 0-bit to reach the end of a chain of output units.&lt;br /&gt;
&lt;br /&gt;
==Design for a memory cell for use in registers/memory unit==&lt;br /&gt;
&lt;br /&gt;
 ###&lt;br /&gt;
 #H#&lt;br /&gt;
 #^#PRoO&lt;br /&gt;
 #%#&lt;br /&gt;
 #%WIP&lt;br /&gt;
 #~#&lt;br /&gt;
 ###&lt;br /&gt;
&lt;br /&gt;
This design is based on plans found at User:SL/Logic_Gates on the wiki. For this design, the write-in signal is linked to gear W and hatch H, while the read-out signal is linked to gear R. Gear o is linked to the pressure plate ^ and represents the state of the cell. Big O represents to output signal and I represents the input signal. P represents a power source. The hatch prevents the water from draining thus preserving the data.&lt;br /&gt;
&lt;br /&gt;
In order to act as a memory cell, this unit must do 3 things:&lt;br /&gt;
1. Output its state when told to read-out&lt;br /&gt;
2. Change state to match an input when told to write-in&lt;br /&gt;
3. Maintain its state when not told to do anything&lt;br /&gt;
&lt;br /&gt;
Let's check this by examining the operation of this unit. &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=1 style=&amp;quot;text-align:center&amp;quot; cellpadding=&amp;quot;2&amp;quot; cellspacing=&amp;quot;0&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|R&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|W&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|I&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|State&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|O&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| Ignored&lt;br /&gt;
| Unchanged&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| Ignored&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| Ignored&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
|}&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When both read and write are turned on, the device will act as a power sensor for the input. This could be a problem if the input and output are linked.&lt;br /&gt;
&lt;br /&gt;
One point of concern is that the unit may not contain sufficient water to trigger the plate because the amount of water in the square above the hatch may not be 7 when it closes. &lt;br /&gt;
&lt;br /&gt;
The plate could be set to trigger at a lower threshold, which would slightly slow down response time, or a door could be used instead of a hatch and the unit extended by one tile to provide space for the drain. This would have the downside of destroying some water after every write operation.&lt;br /&gt;
&lt;br /&gt;
Another method is to use another pump to drain the water from the holding tile. This pump will only activate when W is 1 and I is 0. &lt;br /&gt;
&lt;br /&gt;
==Computer registers==&lt;br /&gt;
&lt;br /&gt;
The dwarven computer prototype is going to have an 8-bit instruction length, a 3-bit operon and a 5-bit address space. Why? The best reason for this is that other designs of Very Simple Computers (VSC) on the Internet are also only 8-bit and I am basing the design of the prototype dwarven computer off several of them. Naturally a bigger computer is better in many ways but the current goal is to produce an operational one. Now its not clear to me why a VSC shouldn't be smaller, but I suppose it doesn't matter.&lt;br /&gt;
&lt;br /&gt;
8-bit words need 8-bit registers. Fortunately this just means stacking 8 memory units up and making sure they receive the same read/write signals.&lt;br /&gt;
&lt;br /&gt;
[[image:memreg.png|Schematic of an 8-bit register]]&lt;br /&gt;
&lt;br /&gt;
The lines in the diagram don't actually represent physical connections but imaginary ones. After all, the write signal must be sent remotely.&lt;br /&gt;
&lt;br /&gt;
Now we consider the most compact designs for such an array. Let us assume that the output signals will be sent remotely. For clarity, the arrays ought to be rectangular.&lt;br /&gt;
&lt;br /&gt;
 ##### ##### ##### ##### ##### ##### ##### ##### &lt;br /&gt;
 #H#.# #H#.# #H#.# #H#.# #H#.# #H#.# #H#.# #H#.# &lt;br /&gt;
 #^#^# #^#^# #^#^# #^#^# #^#^# #^#^# #^#^# #^#^# &lt;br /&gt;
 #%#%# #%#%# #%#%# #%#%# #%#%# #%#%# #%#%# #%#%# &lt;br /&gt;
 W%`%o W%`%o W%`%o W%`%o W%`%o W%`%o W%`%o W%`%o &lt;br /&gt;
 I~`~RPI~`~RPI~`~RPI~`~RPI~`~RPI~`~RPI~`~RPI~`~R&lt;br /&gt;
 P`````````````````````````````````````````````P&lt;br /&gt;
Note that the O is omitted since it was a placeholder for the output device.&lt;br /&gt;
&lt;br /&gt;
Not all registers in the computer are 8 bit registers. For example the memory address register is 5 bits.&lt;br /&gt;
&lt;br /&gt;
==Memory unit==&lt;br /&gt;
&lt;br /&gt;
Since there are only 5 bits of address space, I only need 256 memory cells. It should be fine if I don't use complicated column and row addressing schemes. I shall simply have 32 8-bit registers sticking somewhere. In order for the memory unit to work, I need a decoder to change the 5-bit address into 32 outputs. This will enable the memory unit to read and write from any register. I guess this makes it random access memory.&lt;br /&gt;
&lt;br /&gt;
===Decoder===&lt;br /&gt;
&lt;br /&gt;
This type of decoder is called an n to 2^n decoder, since it converts n inputs into 2^n outputs, in this case 5 to 32(2^5).&lt;br /&gt;
&lt;br /&gt;
To illustrate the design for this unit, let us consider a simpler example where n=2. There will be 2  binary inputs which will be converted into 4 unique outputs, 1 for each memory address.&lt;br /&gt;
&lt;br /&gt;
Here is the truth table for the operation:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=1 style=&amp;quot;text-align:center&amp;quot; cellpadding=&amp;quot;2&amp;quot; cellspacing=&amp;quot;0&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|2^0 (1)&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|2^1 (2)&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|O0&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|O1&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|O2&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|O3&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
|}&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now let us examine the implementation into the dwarfputer. Remember that gear assemblies are toggleable. I can implement a NOT operation by simply reversing the default state of a triggered gear (which is OFF in this system).&lt;br /&gt;
&lt;br /&gt;
Let us represent the 2^0 gear as A when it is default OFF and as a when it is default ON, and represent the 2^1 gear as B and b. O0 to O3 represent output devices.&lt;br /&gt;
&lt;br /&gt;
 P  P  P  P&lt;br /&gt;
 a  A  a  A&lt;br /&gt;
 b  b  B  B&lt;br /&gt;
 O0 O1 O2 O3&lt;br /&gt;
&lt;br /&gt;
This is the easiest to understand implementation. Looking at O0, we see that O0 is powered only when a and b are active. This corresponds to the state when 2^0 and 2^1 are both 0. Examining all the devices reveals that this arrangement obeys the truth table detailed above. Further examination would reveal that this arrangement also follows a pattern. Basically, the full set of columns represent every single possible combination of a, A, b, and B. Therefore we can easily see how to expand this system to n=5.&lt;br /&gt;
&lt;br /&gt;
However, this implementation is not the most efficient one. I can also arrange the gears like so:&lt;br /&gt;
&lt;br /&gt;
 O3A AO1&lt;br /&gt;
   BPb&lt;br /&gt;
 O2a aO0&lt;br /&gt;
&lt;br /&gt;
This arrangement uses 7 gears while the first arrangement uses 12 gears (including power gears). I put B and b closest to the power supply to obtain an orderly arrangement of O0 to O3 although this isn't strictly necessary.&lt;br /&gt;
&lt;br /&gt;
Schematically this arrangement looks like this:&lt;br /&gt;
&lt;br /&gt;
[[Image:2nscheme.png|Schematic of a 2 to 4 decoder]]&lt;br /&gt;
&lt;br /&gt;
Which is just some sort of tree diagram. I can easily expand this to n=5 which is what I want.&lt;br /&gt;
&lt;br /&gt;
[[Image:5nscheme.png|Schematic of a 5 to 32 decoder]]&lt;br /&gt;
&lt;br /&gt;
I drew this diagram in rectangular form so that I can better see how to construct the decoder. The outputs of the decoder will be in a 4x8 grid. Since the output units are longer in one direction than the other, I will align their long axis along the short axis of the diagram. It is probably best to place all the mechanisms for the decoder in the level above the outputs.&lt;br /&gt;
&lt;br /&gt;
===Memory unit registers===&lt;br /&gt;
&lt;br /&gt;
The registers in the memory unit need some modification to work correctly. Only the register indicated in the memory address register ought to respond to read write signals. Therefore each of the 32 registers needs to be connected to one of the outputs from the decoder.&lt;br /&gt;
&lt;br /&gt;
In this example, the register only responds when 00000 is in the memory address register.&lt;br /&gt;
&lt;br /&gt;
 ##### ##### ##### ##### ##### ##### ##### ##### &lt;br /&gt;
 #H#.# #H#.# #H#.# #H#.# #H#.# #H#.# #H#.# #H#.# &lt;br /&gt;
 #^#^# #^#^# #^#^# #^#^# #^#^# #^#^# #^#^# #^#^# &lt;br /&gt;
 #%#%# #%#%# #%#%# #%#%# #%#%# #%#%# #%#%# #%#%# &lt;br /&gt;
 W%`%o W%`%o W%`%o W%`%o W%`%o W%`%o W%`%o W%`%o &lt;br /&gt;
 I~`~RCI~`~RCI~`~RCI~`~RCI~`~RCI~`~RCI~`~RCI~`~R&lt;br /&gt;
 CP```P`````P`````P`````P`````P`````P`````P```PC&lt;br /&gt;
&lt;br /&gt;
C in this diagram represents the output O0. I believe this is called the chip select signal in real computers.&lt;br /&gt;
&lt;br /&gt;
It may be possible to wire the decoder directly to the power supply of the memory, which would remove the need for an output device. &lt;br /&gt;
&lt;br /&gt;
===Memory unit architecture===&lt;br /&gt;
&lt;br /&gt;
Right, I based the design of the memory unit off a java applet simulator I found on the Internet. &lt;br /&gt;
&lt;br /&gt;
[[Image:Memarchi.png|Schematic of the memory unit's architecture]]&lt;br /&gt;
&lt;br /&gt;
What this diagram is supposed to illustrate is that ALL the memory cells are linked to respond to the same read-out signal and the same write-in signal. Similarly, all the corresponding cells respond to same input, and all output to the same place. However, they will do none of these things unless they get a signal from the decoder, and only one register will get the signal as indicated in the memory address register. &lt;br /&gt;
&lt;br /&gt;
Now the input and output buffers shown here may not be in the final blueprints, depending on the design of the rest of the computer.&lt;br /&gt;
&lt;br /&gt;
==Machine language design==&lt;br /&gt;
&lt;br /&gt;
The machine language is the set of instructions the computer will be able to execute. What these instructions are will define the design of the remaining components. For example, the Arithmetic Logic Unit needs to be able to perform the various operations listed in these instructions.&lt;br /&gt;
&lt;br /&gt;
Ideally this language should be complete, that is, any function can be simulated as a combination of these instructions. I also want to be as simple as possible, to minimize the complexity of the ALU. It is worth restating that I am basing the overall design for the computer on a design for a VSC off the Internet.&lt;br /&gt;
&lt;br /&gt;
Since the opcode for this computer is 3-bits long, there can only be 8 instructions.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=1 style=&amp;quot;text-align:center&amp;quot; cellpadding=&amp;quot;2&amp;quot; cellspacing=&amp;quot;0&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Opcode&lt;br /&gt;
!Function&lt;br /&gt;
!Operand&lt;br /&gt;
|-&lt;br /&gt;
| 000&lt;br /&gt;
| Load Accumulator from memory (indirectly)&lt;br /&gt;
| Memory Address&lt;br /&gt;
|-&lt;br /&gt;
| 001&lt;br /&gt;
| Store Accumulator to memory&lt;br /&gt;
| Memory Address&lt;br /&gt;
|-&lt;br /&gt;
| 010&lt;br /&gt;
| Add&lt;br /&gt;
| Memory Address&lt;br /&gt;
|-&lt;br /&gt;
| 011&lt;br /&gt;
| Subtract&lt;br /&gt;
| Memory Address&lt;br /&gt;
|-&lt;br /&gt;
| 100&lt;br /&gt;
| Jump to address if accumulator is not negative&lt;br /&gt;
| Memory Address&lt;br /&gt;
|-&lt;br /&gt;
| 101&lt;br /&gt;
| Binary shift left (*2) (input 0 as LSB)&lt;br /&gt;
| Memory Address&lt;br /&gt;
|-&lt;br /&gt;
| 110&lt;br /&gt;
| Binary shift right (/2) (retain MSB)&lt;br /&gt;
| Memory Address&lt;br /&gt;
|-&lt;br /&gt;
| 111&lt;br /&gt;
| Halt&lt;br /&gt;
| None&lt;br /&gt;
|}&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Arithmetic Logic Unit (ALU)==&lt;br /&gt;
&lt;br /&gt;
Now I know that the ALU needs to be able to perform 4 functions: Add, subtract, shift left and shift right. The unit needs to do one of these functions based on one of 4 input signals it may receive.&lt;br /&gt;
&lt;br /&gt;
The ALU will receive 2 8-bit inputs and produce 1 8-bit output. It will require 3 systems, the adder-subtractor, bitshift left and bitshift right. These systems would be integrated to form the ALU.&lt;br /&gt;
&lt;br /&gt;
===Half adder===&lt;br /&gt;
&lt;br /&gt;
While there are existing dwarven adder designs out there, they do not come with schematics detailing the links between their components. Therefore I feel the need to design from scratch.&lt;br /&gt;
&lt;br /&gt;
A simple half adder would take 2 inputs, and produce an output and an overflow output called a carry.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=1 style=&amp;quot;text-align:center&amp;quot; cellpadding=&amp;quot;2&amp;quot; cellspacing=&amp;quot;0&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|A&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|B&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|C&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|O&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
|}&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &lt;br /&gt;
 Carry out circuit  C==ABP&lt;br /&gt;
&lt;br /&gt;
                       aBP&lt;br /&gt;
 Output circuit     O==o&lt;br /&gt;
                       bAP&lt;br /&gt;
&lt;br /&gt;
                  C===A&lt;br /&gt;
 Combined circuit    aBP&lt;br /&gt;
                  O==obA&lt;br /&gt;
&lt;br /&gt;
This schematic shows a dwarven half adder that obeys the above truth table. In this diagram, the o represents a normal gear assembly and = represents axles. This design rests on the assumption that axles do not receive power except from their end tiles. It also takes advantage of the assumption that a matched pair of gears will not transmit information across their connection (here it is the B and b gear)&lt;br /&gt;
&lt;br /&gt;
I believe this design uses the minimum number of gear assemblies, although I am not sure.&lt;br /&gt;
&lt;br /&gt;
===Full adder===&lt;br /&gt;
&lt;br /&gt;
In order for an adder to work properly, it must also receive the carry bit in addition to the 2 inputs. Ultimately, even the first adder in the final adder-subtracter must be able to receive a carry bit to operate successfully, which is why I didn't draw up a full plan for the half adder.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=1 style=&amp;quot;text-align:center&amp;quot; cellpadding=&amp;quot;2&amp;quot; cellspacing=&amp;quot;0&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|A&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|B&lt;br /&gt;
!C (carry in)&lt;br /&gt;
!O2 (carry out)&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|O1&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
|}&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 PB&lt;br /&gt;
 CAo==O2       Carry Out Circuit&lt;br /&gt;
 oBo&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 o=o=o=o==O1   Output Circuit&lt;br /&gt;
 C c c C&lt;br /&gt;
 B b B b&lt;br /&gt;
 A A a a&lt;br /&gt;
 P P P P&lt;br /&gt;
&lt;br /&gt;
     O1 O2     Combined Circuit&lt;br /&gt;
  oo=oo |&lt;br /&gt;
  Cc cC oo&lt;br /&gt;
  Bb BbBAB&lt;br /&gt;
 PAo oaPCo&lt;br /&gt;
&lt;br /&gt;
Now that looks pretty monstrous. Undoubtedly the arrangement of gears could be changed here and there depending on the exact dimensions you need the array to be, but hopefully this diagram illustrates methods that can be used to minimize the complexity of the device. Note that where there are adjacent identical gears directly connected to the power source, one of them can be replaced by an ordinary gear, which will remove a linking task for that gear.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   `````   oCBAP&lt;br /&gt;
   ````    ocbo&lt;br /&gt;
 #####   ``|``&lt;br /&gt;
 #.#.#`  ``ocBo&lt;br /&gt;
 #^#^#`  `ooCba     Hypothetical implementation&lt;br /&gt;
 #%#%#`  `o``BP&lt;br /&gt;
 `%`%``  ```oAC&lt;br /&gt;
 `~`~``  ```oBo&lt;br /&gt;
 `````   `````&lt;br /&gt;
  lvlz     lvlz+1&lt;br /&gt;
&lt;br /&gt;
The above diagram details a hypothetical implementation for a full adder. The ```s represent the shadow of the mechanisms above and below the level. The left power sensor produces the output signal while the right power sensor produces the carry signal to be relayed to the next adder. The total footprint of the unit is 6x9. In an array, the units can overlap one tile so the total footprint of an 8-bit adder would be 41x9. Maximum operational power draw is 131x8(1048) units of power.&lt;br /&gt;
&lt;br /&gt;
===8-bit ripple-carry adder-subtracter===&lt;br /&gt;
&lt;br /&gt;
[[Image:Rippleaddersubtracter.png|Schematic of an 8-bit ripple-carry adder-subtractor]]&lt;br /&gt;
&lt;br /&gt;
In order to build a full 8-bit adder-subtracter, all you need to do is to stack up 8 full adders next to each other and ensure that all the gears have been linked to the appropriate plates.&lt;br /&gt;
&lt;br /&gt;
Now to get the adder-subtracter to subtract, all you have to do is to link up every single A and a (or B and b) gear assembly to the pressure plate sending the subtract signal. When the signal is sent, all the gears linked to a register will toggle. This will have the effect of inverting whatever input the register is sending. Finally the signal also needs to activate the carry in gears in the first adder, which will have the effect of adding 1 to the resulting sum (difference), giving the correct answer in two's complement representation.&lt;br /&gt;
&lt;br /&gt;
===Carry-look-ahead adder===&lt;br /&gt;
&lt;br /&gt;
I did some research into carry-look-ahead adders to see if it was worth implementing. Carry-look-ahead adders are faster than ripple-carry adders as ripple carry adders have to wait for the carry bit to 'ripple' through the chain of adders before getting the correct result. This is most significant for users of fluid logic, as fluid logic adders need to wait n*100 steps (n being the number of bits) for the carry to ripple all the way to the end. (Floodgates and bridges have a 100 step delay before activating or deactivating)&lt;br /&gt;
&lt;br /&gt;
I found that I could easily design a carry-look-ahead adder using mechanical logic that calculates the carry in bit for all bits in a single step. I would also like to point out that real carry-look-ahead adders are more complicated because they don't have teleporting switch signals. &lt;br /&gt;
&lt;br /&gt;
Firstly, looking at the carry-out circuit for the full adder, I see that not only can it exist independently from the sum circuit, the C gear is directly attached to the power source. I can take advantage of this by separating the carry bit calculation circuits from the adder and attaching them to each other like so. &lt;br /&gt;
&lt;br /&gt;
[[Image:Carrycircuit.png|Schematic of a carry calculation circuit for a carry-look-ahead adder]]&lt;br /&gt;
&lt;br /&gt;
Then for the summing part of the adder, I simply build only the output circuit, which I can now simplify like this&lt;br /&gt;
&lt;br /&gt;
     O1     Output Circuit&lt;br /&gt;
  oo=oo&lt;br /&gt;
  Cc cC&lt;br /&gt;
  Bb Bb&lt;br /&gt;
  oAPao&lt;br /&gt;
&lt;br /&gt;
Or I can make it long instead of square so that it will tile better with the output buffers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    O1&lt;br /&gt;
    |&lt;br /&gt;
 oBCoCbo&lt;br /&gt;
 AbcocBa&lt;br /&gt;
 P     P&lt;br /&gt;
&lt;br /&gt;
I could construct these directly above the output buffers and they would all tile a lot better. Not only that, it fits almost perfectly within the footprint of a bank of output buffers. There is also no cost of increased complexity, only spatial separation between the summation unit and the carry unit, plus providing all the advantages of the carry-look-ahead system.&lt;br /&gt;
&lt;br /&gt;
Since this system is superior in all ways to the ripple-carry system, this will be the one going into the final dwarven computer.&lt;br /&gt;
&lt;br /&gt;
===Bitshifting operations===&lt;br /&gt;
&lt;br /&gt;
Setting up a bitshifting operation is relatively simple. I simply wire the inputs directly into slightly different outputs as illustrated in the following diagrams (source: Wikipedia http://en.wikipedia.org/wiki/Bitwise_operation#Arithmetic_shift).&lt;br /&gt;
&lt;br /&gt;
[[Image:175px-Rotate right arithmetically.svg.png|Bitshift Right]]&lt;br /&gt;
&lt;br /&gt;
[[Image:Rotate left logically.svg.png|Bitshift Left]]&lt;br /&gt;
&lt;br /&gt;
Ideally all these operations would be linked into the same bank of output buffers in the assembled ALU, which will be the subject of the next section.&lt;br /&gt;
&lt;br /&gt;
===ALU architecture===&lt;br /&gt;
&lt;br /&gt;
[[Image:Aluarchi.png|Schematic of the ALU architecture]]&lt;br /&gt;
&lt;br /&gt;
This diagram illustrates the various signals moving around the ALU. I decided that I ought to dragoon the ALU into incrementing the program counter as well, but I'm not sure whether that will work or not. We'll see in the later sections.&lt;br /&gt;
&lt;br /&gt;
I defined the inputs from AR1 to be A since there are fewer A and a gears in the current designs and they all have to be toggled by the subtract signal. The operations listed on the right are signals generated by the control unit and they tell the ALU which operation to perform and transfer to the output buffer banks. The component critical to this function is the multiplexer. &lt;br /&gt;
&lt;br /&gt;
The concept of the multiplexer is quite simple, suppose I had 2 inputs I and J, and I wanted to choose which one to pass based on signals Q and R, I would have to build something like this&lt;br /&gt;
&lt;br /&gt;
 PQIoJRP&lt;br /&gt;
    |&lt;br /&gt;
    O&lt;br /&gt;
&lt;br /&gt;
Adding a multiplexer onto the output circuit would require an additional z-level if the tiling efficiency is to be maintained. &lt;br /&gt;
&lt;br /&gt;
[[Image:ALUmulti.png|Schematic of a ALU multiplexer implementation]]&lt;br /&gt;
&lt;br /&gt;
This diagram illustrates a hypothetical implementation of the multiplexer, as well as the bitshifting logic. I don't think I need a support axle on z+2 as it should be supported by O1.&lt;br /&gt;
&lt;br /&gt;
==Bus design==&lt;br /&gt;
&lt;br /&gt;
I've decided to ditch the plan for a bus, which would have been the conduit for data transfers between registers throughout the computer. Initially there were 2 methods, one had a output buffer attached to the end of the bus while the other the bus directly supplied power to the inputs of the appropriate registers. &lt;br /&gt;
&lt;br /&gt;
Method 2 would not work on memory cells that used an active pump for bit-clearing. Method 1 would have worked but the output buffers had to be overwritten every step and that could cause cascading delays throughout the computer. Since this computer is relatively simple, I opted for hard wiring everything instead.&lt;br /&gt;
&lt;br /&gt;
[[Image:Datatransfers.png|Schematic of the data transfers within the CPU]]&lt;br /&gt;
&lt;br /&gt;
This diagram illustrates the data transfers that occur throughout the computer. The red arrows depict confirmed hard-wired connections, while the blue arrows would have been routed through a bus. I've decide AR1 is superfluous so I got rid of it. As you can see, each register has at most 2 inputs or 2 outputs going through the bus, so hardwiring is feasible.&lt;br /&gt;
&lt;br /&gt;
==Timing circuit==&lt;br /&gt;
&lt;br /&gt;
Before the computer can execute its instructions, it needs to perform some operations first.&lt;br /&gt;
&lt;br /&gt;
#Transfer the contents of the accumulator to AR2. Dump instruction register and memory address register.&amp;lt;br&amp;gt;&lt;br /&gt;
#Transfer the program counter to the memory address register. Also, activate the program counter incrementation system in the ALU and transfer the results into program counter +1.&amp;lt;br&amp;gt;&lt;br /&gt;
#Load the data from memory at the specified address into the instruction register.&amp;lt;br&amp;gt;&lt;br /&gt;
#Transfer the data from program counter +1 to the program counter. Also, dump the memory address register&amp;lt;br&amp;gt;&lt;br /&gt;
#Load the last 5 digits of the instruction register into the memory address register. Also, dump program counter +1.&amp;lt;br&amp;gt;&lt;br /&gt;
#Execution (write accumulator, memory or program counter, read instruction register, memory, AR2)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There needs to be a 100 step delay from the time a memory cell is written (or dumped, if it is pre-dumped) and when it is read, or it may cause cascading delays. The writing process is practically instantaneous, but 100 steps are needed before the correct result can be read if the memory was not cleared to begin with. Of course this point is entirely moot if the computer is running automatically, in which case every step will last at least 100 steps anyway and the prime consideration is to ensure that every step can be performed in 100 steps.&lt;br /&gt;
&lt;br /&gt;
==Oscillator==&lt;br /&gt;
&lt;br /&gt;
A typical mechanical oscillator is unsatisfactory because it will usually be sending out 2 on signals at once, one from the pressure plate the water is on and the other from the pressure plate waiting to reset.&lt;br /&gt;
&lt;br /&gt;
 0%%6%%0%%5%%0%%4&lt;br /&gt;
 %              %&lt;br /&gt;
 %              %&lt;br /&gt;
 1%%0%%2%%0%%3%%0&lt;br /&gt;
&lt;br /&gt;
This diagram shows a 12 step 6 signal oscillator. At the locations marked 0, there are no pressure plates. A lever operates the mechanism. When the lever is in the ON position, the #%%0 pumps activate, and when the lever is in the OFF position, the 0%%# pumps activate. The oscillator can also be fully automated by using the pressure plates themselves to replace the lever function. The oscillator's power supply also needs to be cut if a halt signal is received from the control unit. &lt;br /&gt;
&lt;br /&gt;
===Oscillator link table===&lt;br /&gt;
&lt;br /&gt;
#Read accumulator, write AR2, write IR, write MAR&amp;lt;br&amp;gt;&lt;br /&gt;
#Read PC, write MAR, activate ALU (adder select, C0=1), write PC+1&amp;lt;br&amp;gt;&lt;br /&gt;
#Read MEM, read MAR. activate decoder, write IR&amp;lt;br&amp;gt;&lt;br /&gt;
#Read PC+1, write PC, write MAR&amp;lt;br&amp;gt;&lt;br /&gt;
#Read IR, write MAR, write PC+1&amp;lt;br&amp;gt;&lt;br /&gt;
#Execution (read IR, turn on control unit)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A dump operation can be performed by telling the memory register to write when its linked inputs are inactive, effectively writing 0s. &lt;br /&gt;
&lt;br /&gt;
==Control unit==&lt;br /&gt;
&lt;br /&gt;
The control unit can be implemented simply as a 3-8 decoder with appropriately linked pressure plates. The execute signal controlled gear assembly is located at the root of the decoder. &lt;br /&gt;
&lt;br /&gt;
===Control unit link table===&lt;br /&gt;
&lt;br /&gt;
:O0. Read memory, read MAR, activate decoder, write accumulator, select transfer&amp;lt;br&amp;gt;&lt;br /&gt;
:O1. Read accumulator, write memory, read MAR, activate decoder&amp;lt;br&amp;gt;&lt;br /&gt;
:O2. Read memory, read MAR, activate decoder, read AR2, Send Add signal to ALU (adder select), write accumulator&amp;lt;br&amp;gt;&lt;br /&gt;
:O3. Read memory, read MAR, activate decoder, read AR2, Send Subtract signal to ALU (adder select, C0=1, invert input A), write accumulator&amp;lt;br&amp;gt;&lt;br /&gt;
:O4. Read IR, write PC if ACC7=0&amp;lt;br&amp;gt;&lt;br /&gt;
:O5. Read memory, read MAR, activate decoder, Send Shift left signal to ALU (SHL select), write accumulator&amp;lt;br&amp;gt;&lt;br /&gt;
:O6. Read memory, read MAR, activate decoder, Send Shift right signal to ALU (SHR select), write accumulator&amp;lt;br&amp;gt;&lt;br /&gt;
:O7. Cut power to oscillator.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
[[DF2010:Computing|Computing]]&lt;br /&gt;
&lt;br /&gt;
==External links==&lt;br /&gt;
*[http://docs.google.com/Doc?docid=0AdISzBuNg6ZWZGd0d2t4YjlfMjJ0ejlzc2dnaA&amp;amp;hl=en GoogleDocs Design Manuscript]&lt;br /&gt;
*[http://www.bay12forums.com/smf/index.php?topic=49641.0 Bay12 Forums thread]&lt;br /&gt;
*[http://mkv25.net/dfma/map-8269 Map at DF Map Archive]&lt;br /&gt;
*[http://dffd.wimbli.com/file.php?id=1929 Save File at DF File Depot]&lt;/div&gt;</summary>
		<author><name>Jong</name></author>
	</entry>
	<entry>
		<id>https://dwarffortresswiki.org/index.php?title=User:Jong/Dwarven_Computer&amp;diff=101105</id>
		<title>User:Jong/Dwarven Computer</title>
		<link rel="alternate" type="text/html" href="https://dwarffortresswiki.org/index.php?title=User:Jong/Dwarven_Computer&amp;diff=101105"/>
		<updated>2010-04-30T08:54:38Z</updated>

		<summary type="html">&lt;p&gt;Jong: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page documents the design of my Dwarven Computer. A number of designs were modified for the final implementation.&lt;br /&gt;
&lt;br /&gt;
Adapted from my GoogleDocs [http://docs.google.com/Doc?docid=0AdISzBuNg6ZWZGd0d2t4YjlfMjJ0ejlzc2dnaA&amp;amp;hl=en manuscript]&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&lt;br /&gt;
Toggled gear assemblies are designed as though they are off in when untriggered. However they are constructed in the on position. This means that you need to build and link a lever to toggle it to the off state.&lt;br /&gt;
&lt;br /&gt;
==Power sensor (output device)==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  # %&amp;gt;^ #     &lt;br /&gt;
 ~ ~ ~ ~#      Power sensor side view&lt;br /&gt;
&lt;br /&gt;
In order to do useful things, such as toggling gears assemblies, opening doors, etc., mechanical power signals need to be converted to a trigger signal. There are only 2 trigger signal generators in dwarf fortress. One is the lever, which cannot be linked to machine power. The other is a pressure plate, which can.&lt;br /&gt;
&lt;br /&gt;
The basic operation of this component is simple. Power operates the pump, pushing water over the pressure plate, generating a signal. When the pump is not powered, the water drains, switching the pressure plate off after at least 100 steps.&lt;br /&gt;
&lt;br /&gt;
The smooth operation of this unit depends on several factors:&lt;br /&gt;
1. Adequate supply of water in the input tile so that the pump can maintain 7/7 or 6/7 water levels on the pressure plate. Can be done by providing more water tiles adjacent to the input tile.&lt;br /&gt;
2. Fast drainage to minimize the time needed for the plate to switch off. Just make sure that the level below the pumps is not completely full.&lt;br /&gt;
3. Since the minimum recovery time of the pressure plate is 100 steps, it can take a good long time for a 0-bit to reach the end of a chain of output units.&lt;br /&gt;
&lt;br /&gt;
==Design for a memory cell for use in registers/memory unit==&lt;br /&gt;
&lt;br /&gt;
 ###&lt;br /&gt;
 #H#&lt;br /&gt;
 #^#PRoO&lt;br /&gt;
 #%#&lt;br /&gt;
 #%WIP&lt;br /&gt;
 #~#&lt;br /&gt;
 ###&lt;br /&gt;
&lt;br /&gt;
This design is based on plans found at User:SL/Logic_Gates on the wiki. For this design, the write-in signal is linked to gear W and hatch H, while the read-out signal is linked to gear R. Gear o is linked to the pressure plate ^ and represents the state of the cell. Big O represents to output signal and I represents the input signal. P represents a power source. The hatch prevents the water from draining thus preserving the data.&lt;br /&gt;
&lt;br /&gt;
In order to act as a memory cell, this unit must do 3 things:&lt;br /&gt;
1. Output its state when told to read-out&lt;br /&gt;
2. Change state to match an input when told to write-in&lt;br /&gt;
3. Maintain its state when not told to do anything&lt;br /&gt;
&lt;br /&gt;
Let's check this by examining the operation of this unit. &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=1 style=&amp;quot;text-align:center&amp;quot; cellpadding=&amp;quot;2&amp;quot; cellspacing=&amp;quot;0&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|R&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|W&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|I&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|State&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|O&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| Ignored&lt;br /&gt;
| Unchanged&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| Ignored&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| Ignored&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
|}&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When both read and write are turned on, the device will act as a power sensor for the input. This could be a problem if the input and output are linked.&lt;br /&gt;
&lt;br /&gt;
One point of concern is that the unit may not contain sufficient water to trigger the plate because the amount of water in the square above the hatch may not be 7 when it closes. &lt;br /&gt;
&lt;br /&gt;
The plate could be set to trigger at a lower threshold, which would slightly slow down response time, or a door could be used instead of a hatch and the unit extended by one tile to provide space for the drain. This would have the downside of destroying some water after every write operation.&lt;br /&gt;
&lt;br /&gt;
Another method is to use another pump to drain the water from the holding tile. This pump will only activate when W is 1 and I is 0. &lt;br /&gt;
&lt;br /&gt;
==Computer registers==&lt;br /&gt;
&lt;br /&gt;
The dwarven computer prototype is going to have an 8-bit instruction length, a 3-bit operon and a 5-bit address space. Why? The best reason for this is that other designs of Very Simple Computers (VSC) on the Internet are also only 8-bit and I am basing the design of the prototype dwarven computer off several of them. Naturally a bigger computer is better in many ways but the current goal is to produce an operational one. Now its not clear to me why a VSC shouldn't be smaller, but I suppose it doesn't matter.&lt;br /&gt;
&lt;br /&gt;
8-bit words need 8-bit registers. Fortunately this just means stacking 8 memory units up and making sure they receive the same read/write signals.&lt;br /&gt;
&lt;br /&gt;
[[image:memreg.png|Schematic of an 8-bit register]]&lt;br /&gt;
&lt;br /&gt;
The lines in the diagram don't actually represent physical connections but imaginary ones. After all, the write signal must be sent remotely.&lt;br /&gt;
&lt;br /&gt;
Now we consider the most compact designs for such an array. Let us assume that the output signals will be sent remotely. For clarity, the arrays ought to be rectangular.&lt;br /&gt;
&lt;br /&gt;
 ##### ##### ##### ##### ##### ##### ##### ##### &lt;br /&gt;
 #H#.# #H#.# #H#.# #H#.# #H#.# #H#.# #H#.# #H#.# &lt;br /&gt;
 #^#^# #^#^# #^#^# #^#^# #^#^# #^#^# #^#^# #^#^# &lt;br /&gt;
 #%#%# #%#%# #%#%# #%#%# #%#%# #%#%# #%#%# #%#%# &lt;br /&gt;
 W%`%o W%`%o W%`%o W%`%o W%`%o W%`%o W%`%o W%`%o &lt;br /&gt;
 I~`~RPI~`~RPI~`~RPI~`~RPI~`~RPI~`~RPI~`~RPI~`~R&lt;br /&gt;
 P`````````````````````````````````````````````P&lt;br /&gt;
Note that the O is omitted since it was a placeholder for the output device.&lt;br /&gt;
&lt;br /&gt;
Not all registers in the computer are 8 bit registers. For example the memory address register is 5 bits.&lt;br /&gt;
&lt;br /&gt;
==Memory unit==&lt;br /&gt;
&lt;br /&gt;
Since there are only 5 bits of address space, I only need 256 memory cells. It should be fine if I don't use complicated column and row addressing schemes. I shall simply have 32 8-bit registers sticking somewhere. In order for the memory unit to work, I need a decoder to change the 5-bit address into 32 outputs. This will enable the memory unit to read and write from any register. I guess this makes it random access memory.&lt;br /&gt;
&lt;br /&gt;
===Decoder===&lt;br /&gt;
&lt;br /&gt;
This type of decoder is called an n to 2^n decoder, since it converts n inputs into 2^n outputs, in this case 5 to 32(2^5).&lt;br /&gt;
&lt;br /&gt;
To illustrate the design for this unit, let us consider a simpler example where n=2. There will be 2  binary inputs which will be converted into 4 unique outputs, 1 for each memory address.&lt;br /&gt;
&lt;br /&gt;
Here is the truth table for the operation:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=1 style=&amp;quot;text-align:center&amp;quot; cellpadding=&amp;quot;2&amp;quot; cellspacing=&amp;quot;0&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|2^0 (1)&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|2^1 (2)&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|O0&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|O1&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|O2&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|O3&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
|}&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now let us examine the implementation into the dwarfputer. Remember that gear assemblies are toggleable. I can implement a NOT operation by simply reversing the default state of a triggered gear (which is OFF in this system).&lt;br /&gt;
&lt;br /&gt;
Let us represent the 2^0 gear as A when it is default OFF and as a when it is default ON, and represent the 2^1 gear as B and b. O0 to O3 represent output devices.&lt;br /&gt;
&lt;br /&gt;
 P  P  P  P&lt;br /&gt;
 a  A  a  A&lt;br /&gt;
 b  b  B  B&lt;br /&gt;
 O0 O1 O2 O3&lt;br /&gt;
&lt;br /&gt;
This is the easiest to understand implementation. Looking at O0, we see that O0 is powered only when a and b are active. This corresponds to the state when 2^0 and 2^1 are both 0. Examining all the devices reveals that this arrangement obeys the truth table detailed above. Further examination would reveal that this arrangement also follows a pattern. Basically, the full set of columns represent every single possible combination of a, A, b, and B. Therefore we can easily see how to expand this system to n=5.&lt;br /&gt;
&lt;br /&gt;
However, this implementation is not the most efficient one. I can also arrange the gears like so:&lt;br /&gt;
&lt;br /&gt;
 O3A AO1&lt;br /&gt;
   BPb&lt;br /&gt;
 O2a aO0&lt;br /&gt;
&lt;br /&gt;
This arrangement uses 7 gears while the first arrangement uses 12 gears (including power gears). I put B and b closest to the power supply to obtain an orderly arrangement of O0 to O3 although this isn't strictly necessary.&lt;br /&gt;
&lt;br /&gt;
Schematically this arrangement looks like this:&lt;br /&gt;
&lt;br /&gt;
[[Image:2nscheme.png|Schematic of a 2 to 4 decoder]]&lt;br /&gt;
&lt;br /&gt;
Which is just some sort of tree diagram. I can easily expand this to n=5 which is what I want.&lt;br /&gt;
&lt;br /&gt;
[[Image:5nscheme.png|Schematic of a 5 to 32 decoder]]&lt;br /&gt;
&lt;br /&gt;
I drew this diagram in rectangular form so that I can better see how to construct the decoder. The outputs of the decoder will be in a 4x8 grid. Since the output units are longer in one direction than the other, I will align their long axis along the short axis of the diagram. It is probably best to place all the mechanisms for the decoder in the level above the outputs.&lt;br /&gt;
&lt;br /&gt;
===Memory unit registers===&lt;br /&gt;
&lt;br /&gt;
The registers in the memory unit need some modification to work correctly. Only the register indicated in the memory address register ought to respond to read write signals. Therefore each of the 32 registers needs to be connected to one of the outputs from the decoder.&lt;br /&gt;
&lt;br /&gt;
In this example, the register only responds when 00000 is in the memory address register.&lt;br /&gt;
&lt;br /&gt;
 ##### ##### ##### ##### ##### ##### ##### ##### &lt;br /&gt;
 #H#.# #H#.# #H#.# #H#.# #H#.# #H#.# #H#.# #H#.# &lt;br /&gt;
 #^#^# #^#^# #^#^# #^#^# #^#^# #^#^# #^#^# #^#^# &lt;br /&gt;
 #%#%# #%#%# #%#%# #%#%# #%#%# #%#%# #%#%# #%#%# &lt;br /&gt;
 W%`%o W%`%o W%`%o W%`%o W%`%o W%`%o W%`%o W%`%o &lt;br /&gt;
 I~`~RCI~`~RCI~`~RCI~`~RCI~`~RCI~`~RCI~`~RCI~`~R&lt;br /&gt;
 CP```P`````P`````P`````P`````P`````P`````P```PC&lt;br /&gt;
&lt;br /&gt;
C in this diagram represents the output O0. I believe this is called the chip select signal in real computers.&lt;br /&gt;
&lt;br /&gt;
It may be possible to wire the decoder directly to the power supply of the memory, which would remove the need for an output device. &lt;br /&gt;
&lt;br /&gt;
===Memory unit architecture===&lt;br /&gt;
&lt;br /&gt;
Right, I based the design of the memory unit off a java applet simulator I found on the Internet. &lt;br /&gt;
&lt;br /&gt;
[[Image:Memarchi.png|Schematic of the memory unit's architecture]]&lt;br /&gt;
&lt;br /&gt;
What this diagram is supposed to illustrate is that ALL the memory cells are linked to respond to the same read-out signal and the same write-in signal. Similarly, all the corresponding cells respond to same input, and all output to the same place. However, they will do none of these things unless they get a signal from the decoder, and only one register will get the signal as indicated in the memory address register. &lt;br /&gt;
&lt;br /&gt;
Now the input and output buffers shown here may not be in the final blueprints, depending on the design of the rest of the computer.&lt;br /&gt;
&lt;br /&gt;
==Machine language design==&lt;br /&gt;
&lt;br /&gt;
The machine language is the set of instructions the computer will be able to execute. What these instructions are will define the design of the remaining components. For example, the Arithmetic Logic Unit needs to be able to perform the various operations listed in these instructions.&lt;br /&gt;
&lt;br /&gt;
Ideally this language should be complete, that is, any function can be simulated as a combination of these instructions. I also want to be as simple as possible, to minimize the complexity of the ALU. It is worth restating that I am basing the overall design for the computer on a design for a VSC off the Internet.&lt;br /&gt;
&lt;br /&gt;
Since the opcode for this computer is 3-bits long, there can only be 8 instructions.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=1 style=&amp;quot;text-align:center&amp;quot; cellpadding=&amp;quot;2&amp;quot; cellspacing=&amp;quot;0&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Opcode&lt;br /&gt;
!Function&lt;br /&gt;
!Operand&lt;br /&gt;
|-&lt;br /&gt;
| 000&lt;br /&gt;
| Load Accumulator from memory (indirectly)&lt;br /&gt;
| Memory Address&lt;br /&gt;
|-&lt;br /&gt;
| 001&lt;br /&gt;
| Store Accumulator to memory&lt;br /&gt;
| Memory Address&lt;br /&gt;
|-&lt;br /&gt;
| 010&lt;br /&gt;
| Add&lt;br /&gt;
| Memory Address&lt;br /&gt;
|-&lt;br /&gt;
| 011&lt;br /&gt;
| Subtract&lt;br /&gt;
| Memory Address&lt;br /&gt;
|-&lt;br /&gt;
| 100&lt;br /&gt;
| Jump to address if accumulator is not negative&lt;br /&gt;
| Memory Address&lt;br /&gt;
|-&lt;br /&gt;
| 101&lt;br /&gt;
| Binary shift left (*2) (input 0 as LSB)&lt;br /&gt;
| Memory Address&lt;br /&gt;
|-&lt;br /&gt;
| 110&lt;br /&gt;
| Binary shift right (/2) (retain MSB)&lt;br /&gt;
| Memory Address&lt;br /&gt;
|-&lt;br /&gt;
| 111&lt;br /&gt;
| Halt&lt;br /&gt;
| None&lt;br /&gt;
|}&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Arithmetic Logic Unit (ALU)==&lt;br /&gt;
&lt;br /&gt;
Now I know that the ALU needs to be able to perform 4 functions: Add, subtract, shift left and shift right. The unit needs to do one of these functions based on one of 4 input signals it may receive.&lt;br /&gt;
&lt;br /&gt;
The ALU will receive 2 8-bit inputs and produce 1 8-bit output. It will require 3 systems, the adder-subtractor, bitshift left and bitshift right. These systems would be integrated to form the ALU.&lt;br /&gt;
&lt;br /&gt;
===Half adder===&lt;br /&gt;
&lt;br /&gt;
While there are existing dwarven adder designs out there, they do not come with schematics detailing the links between their components. Therefore I feel the need to design from scratch.&lt;br /&gt;
&lt;br /&gt;
A simple half adder would take 2 inputs, and produce an output and an overflow output called a carry.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=1 style=&amp;quot;text-align:center&amp;quot; cellpadding=&amp;quot;2&amp;quot; cellspacing=&amp;quot;0&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|A&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|B&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|C&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|O&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
|}&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &lt;br /&gt;
 Carry out circuit  C==ABP&lt;br /&gt;
&lt;br /&gt;
                       aBP&lt;br /&gt;
 Output circuit     O==o&lt;br /&gt;
                       bAP&lt;br /&gt;
&lt;br /&gt;
                  C===A&lt;br /&gt;
 Combined circuit    aBP&lt;br /&gt;
                  O==obA&lt;br /&gt;
&lt;br /&gt;
This schematic shows a dwarven half adder that obeys the above truth table. In this diagram, the o represents a normal gear assembly and = represents axles. This design rests on the assumption that axles do not receive power except from their end tiles. It also takes advantage of the assumption that a matched pair of gears will not transmit information across their connection (here it is the B and b gear)&lt;br /&gt;
&lt;br /&gt;
I believe this design uses the minimum number of gear assemblies, although I am not sure.&lt;br /&gt;
&lt;br /&gt;
===Full adder===&lt;br /&gt;
&lt;br /&gt;
In order for an adder to work properly, it must also receive the carry bit in addition to the 2 inputs. Ultimately, even the first adder in the final adder-subtracter must be able to receive a carry bit to operate successfully, which is why I didn't draw up a full plan for the half adder.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=1 style=&amp;quot;text-align:center&amp;quot; cellpadding=&amp;quot;2&amp;quot; cellspacing=&amp;quot;0&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|A&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|B&lt;br /&gt;
!C (carry in)&lt;br /&gt;
!O2 (carry out)&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|O1&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
|}&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 PB&lt;br /&gt;
 CAo==O2       Carry Out Circuit&lt;br /&gt;
 oBo&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 o=o=o=o==O1   Output Circuit&lt;br /&gt;
 C c c C&lt;br /&gt;
 B b B b&lt;br /&gt;
 A A a a&lt;br /&gt;
 P P P P&lt;br /&gt;
&lt;br /&gt;
     O1 O2     Combined Circuit&lt;br /&gt;
  oo=oo |&lt;br /&gt;
  Cc cC oo&lt;br /&gt;
  Bb BbBAB&lt;br /&gt;
 PAo oaPCo&lt;br /&gt;
&lt;br /&gt;
Now that looks pretty monstrous. Undoubtedly the arrangement of gears could be changed here and there depending on the exact dimensions you need the array to be, but hopefully this diagram illustrates methods that can be used to minimize the complexity of the device. Note that where there are adjacent identical gears directly connected to the power source, one of them can be replaced by an ordinary gear, which will remove a linking task for that gear.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   `````   oCBAP&lt;br /&gt;
   ````    ocbo&lt;br /&gt;
 #####   ``|``&lt;br /&gt;
 #.#.#`  ``ocBo&lt;br /&gt;
 #^#^#`  `ooCba     Hypothetical implementation&lt;br /&gt;
 #%#%#`  `o``BP&lt;br /&gt;
 `%`%``  ```oAC&lt;br /&gt;
 `~`~``  ```oBo&lt;br /&gt;
 `````   `````&lt;br /&gt;
  lvlz     lvlz+1&lt;br /&gt;
&lt;br /&gt;
The above diagram details a hypothetical implementation for a full adder. The ```s represent the shadow of the mechanisms above and below the level. The left power sensor produces the output signal while the right power sensor produces the carry signal to be relayed to the next adder. The total footprint of the unit is 6x9. In an array, the units can overlap one tile so the total footprint of an 8-bit adder would be 41x9. Maximum operational power draw is 131x8(1048) units of power.&lt;br /&gt;
&lt;br /&gt;
===8-bit ripple-carry adder-subtracter===&lt;br /&gt;
&lt;br /&gt;
[[Image:Rippleaddersubtracter.png|Schematic of an 8-bit ripple-carry adder-subtractor]]&lt;br /&gt;
&lt;br /&gt;
In order to build a full 8-bit adder-subtracter, all you need to do is to stack up 8 full adders next to each other and ensure that all the gears have been linked to the appropriate plates.&lt;br /&gt;
&lt;br /&gt;
Now to get the adder-subtracter to subtract, all you have to do is to link up every single A and a (or B and b) gear assembly to the pressure plate sending the subtract signal. When the signal is sent, all the gears linked to a register will toggle. This will have the effect of inverting whatever input the register is sending. Finally the signal also needs to activate the carry in gears in the first adder, which will have the effect of adding 1 to the resulting sum (difference), giving the correct answer in two's complement representation.&lt;br /&gt;
&lt;br /&gt;
===Carry-look-ahead adder===&lt;br /&gt;
&lt;br /&gt;
I did some research into carry-look-ahead adders to see if it was worth implementing. Carry-look-ahead adders are faster than ripple-carry adders as ripple carry adders have to wait for the carry bit to 'ripple' through the chain of adders before getting the correct result. This is most significant for users of fluid logic, as fluid logic adders need to wait n*100 steps (n being the number of bits) for the carry to ripple all the way to the end. (Floodgates and bridges have a 100 step delay before activating or deactivating)&lt;br /&gt;
&lt;br /&gt;
I found that I could easily design a carry-look-ahead adder using mechanical logic that calculates the carry in bit for all bits in a single step. I would also like to point out that real carry-look-ahead adders are more complicated because they don't have teleporting switch signals. &lt;br /&gt;
&lt;br /&gt;
Firstly, looking at the carry-out circuit for the full adder, I see that not only can it exist independently from the sum circuit, the C gear is directly attached to the power source. I can take advantage of this by separating the carry bit calculation circuits from the adder and attaching them to each other like so. &lt;br /&gt;
&lt;br /&gt;
[[Image:Carrycircuit.png|Schematic of a carry calculation circuit for a carry-look-ahead adder]]&lt;br /&gt;
&lt;br /&gt;
Then for the summing part of the adder, I simply build only the output circuit, which I can now simplify like this&lt;br /&gt;
&lt;br /&gt;
     O1     Output Circuit&lt;br /&gt;
  oo=oo&lt;br /&gt;
  Cc cC&lt;br /&gt;
  Bb Bb&lt;br /&gt;
  oAPao&lt;br /&gt;
&lt;br /&gt;
Or I can make it long instead of square so that it will tile better with the output buffers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    O1&lt;br /&gt;
    |&lt;br /&gt;
 oBCoCbo&lt;br /&gt;
 AbcocBa&lt;br /&gt;
 P     P&lt;br /&gt;
&lt;br /&gt;
I could construct these directly above the output buffers and they would all tile a lot better. Not only that, it fits almost perfectly within the footprint of a bank of output buffers. There is also no cost of increased complexity, only spatial separation between the summation unit and the carry unit, plus providing all the advantages of the carry-look-ahead system.&lt;br /&gt;
&lt;br /&gt;
Since this system is superior in all ways to the ripple-carry system, this will be the one going into the final dwarven computer.&lt;br /&gt;
&lt;br /&gt;
===Bitshifting operations===&lt;br /&gt;
&lt;br /&gt;
Setting up a bitshifting operation is relatively simple. I simply wire the inputs directly into slightly different outputs as illustrated in the following diagrams (source: Wikipedia http://en.wikipedia.org/wiki/Bitwise_operation#Arithmetic_shift).&lt;br /&gt;
&lt;br /&gt;
[[Image:175px-Rotate right arithmetically.svg.png|Bitshift Right]]&lt;br /&gt;
&lt;br /&gt;
[[Image:Rotate left logically.svg.png|Bitshift Left]]&lt;br /&gt;
&lt;br /&gt;
Ideally all these operations would be linked into the same bank of output buffers in the assembled ALU, which will be the subject of the next section.&lt;br /&gt;
&lt;br /&gt;
===ALU architecture===&lt;br /&gt;
&lt;br /&gt;
[[Image:Aluarchi.png|Schematic of the ALU architecture]]&lt;br /&gt;
&lt;br /&gt;
This diagram illustrates the various signals moving around the ALU. I decided that I ought to dragoon the ALU into incrementing the program counter as well, but I'm not sure whether that will work or not. We'll see in the later sections.&lt;br /&gt;
&lt;br /&gt;
I defined the inputs from AR1 to be A since there are fewer A and a gears in the current designs and they all have to be toggled by the subtract signal. The operations listed on the right are signals generated by the control unit and they tell the ALU which operation to perform and transfer to the output buffer banks. The component critical to this function is the multiplexer. &lt;br /&gt;
&lt;br /&gt;
The concept of the multiplexer is quite simple, suppose I had 2 inputs I and J, and I wanted to choose which one to pass based on signals Q and R, I would have to build something like this&lt;br /&gt;
&lt;br /&gt;
 PQIoJRP&lt;br /&gt;
    |&lt;br /&gt;
    O&lt;br /&gt;
&lt;br /&gt;
Adding a multiplexer onto the output circuit would require an additional z-level if the tiling efficiency is to be maintained. &lt;br /&gt;
&lt;br /&gt;
[[Image:ALUmulti.png|Schematic of a ALU multiplexer implementation]]&lt;br /&gt;
&lt;br /&gt;
This diagram illustrates a hypothetical implementation of the multiplexer, as well as the bitshifting logic. I don't think I need a support axle on z+2 as it should be supported by O1.&lt;br /&gt;
&lt;br /&gt;
==Bus design==&lt;br /&gt;
&lt;br /&gt;
I've decided to ditch the plan for a bus, which would have been the conduit for data transfers between registers throughout the computer. Initially there were 2 methods, one had a output buffer attached to the end of the bus while the other the bus directly supplied power to the inputs of the appropriate registers. &lt;br /&gt;
&lt;br /&gt;
Method 2 would not work on memory cells that used an active pump for bit-clearing. Method 1 would have worked but the output buffers had to be overwritten every step and that could cause cascading delays throughout the computer. Since this computer is relatively simple, I opted for hard wiring everything instead.&lt;br /&gt;
&lt;br /&gt;
[[Image:Datatransfers.png|Schematic of the data transfers within the CPU]]&lt;br /&gt;
&lt;br /&gt;
This diagram illustrates the data transfers that occur throughout the computer. The red arrows depict confirmed hard-wired connections, while the blue arrows would have been routed through a bus. I've decide AR1 is superfluous so I got rid of it. As you can see, each register has at most 2 inputs or 2 outputs going through the bus, so hardwiring is feasible.&lt;br /&gt;
&lt;br /&gt;
==Timing circuit==&lt;br /&gt;
&lt;br /&gt;
Before the computer can execute its instructions, it needs to perform some operations first.&lt;br /&gt;
&lt;br /&gt;
#Transfer the contents of the accumulator to AR2. Dump instruction register and memory address register.&amp;lt;br&amp;gt;&lt;br /&gt;
#Transfer the program counter to the memory address register. Also, activate the program counter incrementation system in the ALU and transfer the results into program counter +1.&amp;lt;br&amp;gt;&lt;br /&gt;
#Load the data from memory at the specified address into the instruction register.&amp;lt;br&amp;gt;&lt;br /&gt;
#Transfer the data from program counter +1 to the program counter. Also, dump the memory address register&amp;lt;br&amp;gt;&lt;br /&gt;
#Load the last 5 digits of the instruction register into the memory address register. Also, dump program counter +1.&amp;lt;br&amp;gt;&lt;br /&gt;
#Execution (write accumulator, memory or program counter, read instruction register, memory, AR2)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There needs to be a 100 step delay from the time a memory cell is written (or dumped, if it is pre-dumped) and when it is read, or it may cause cascading delays. The writing process is practically instantaneous, but 100 steps are needed before the correct result can be read if the memory was not cleared to begin with. Of course this point is entirely moot if the computer is running automatically, in which case every step will last at least 100 steps anyway and the prime consideration is to ensure that every step can be performed in 100 steps.&lt;br /&gt;
&lt;br /&gt;
==Oscillator==&lt;br /&gt;
&lt;br /&gt;
A typical mechanical oscillator is unsatisfactory because it will usually be sending out 2 on signals at once, one from the pressure plate the water is on and the other from the pressure plate waiting to reset.&lt;br /&gt;
&lt;br /&gt;
 0%%6%%0%%5%%0%%4&lt;br /&gt;
 %              %&lt;br /&gt;
 %              %&lt;br /&gt;
 1%%0%%2%%0%%3%%0&lt;br /&gt;
&lt;br /&gt;
This diagram shows a 12 step 6 signal oscillator. At the locations marked 0, there are no pressure plates. A lever operates the mechanism. When the lever is in the ON position, the #%%0 pumps activate, and when the lever is in the OFF position, the 0%%# pumps activate. The oscillator can also be fully automated by using the pressure plates themselves to replace the lever function. The oscillator's power supply also needs to be cut if a halt signal is received from the control unit. &lt;br /&gt;
&lt;br /&gt;
===Oscillator link table===&lt;br /&gt;
&lt;br /&gt;
#Read accumulator, write AR2, write IR, write MAR&amp;lt;br&amp;gt;&lt;br /&gt;
#Read PC, write MAR, activate ALU (adder select, C0=1), write PC+1&amp;lt;br&amp;gt;&lt;br /&gt;
#Read MEM, read MAR. activate decoder, write IR&amp;lt;br&amp;gt;&lt;br /&gt;
#Read PC+1, write PC, write MAR&amp;lt;br&amp;gt;&lt;br /&gt;
#Read IR, write MAR, write PC+1&amp;lt;br&amp;gt;&lt;br /&gt;
#Execution (read IR, turn on control unit)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A dump operation can be performed by telling the memory register to write when its linked inputs are inactive, effectively writing 0s. &lt;br /&gt;
&lt;br /&gt;
==Control unit==&lt;br /&gt;
&lt;br /&gt;
The control unit can be implemented simply as a 3-8 decoder with appropriately linked pressure plates. The execute signal controlled gear assembly is located at the root of the decoder. &lt;br /&gt;
&lt;br /&gt;
===Control unit link table===&lt;br /&gt;
&lt;br /&gt;
:O0. Read memory, read MAR, activate decoder, write accumulator, select transfer&amp;lt;br&amp;gt;&lt;br /&gt;
:O1. Read accumulator, write memory, read MAR, activate decoder&amp;lt;br&amp;gt;&lt;br /&gt;
:O2. Read memory, read MAR, activate decoder, read AR2, Send Add signal to ALU (adder select), write accumulator&amp;lt;br&amp;gt;&lt;br /&gt;
:O3. Read memory, read MAR, activate decoder, read AR2, Send Subtract signal to ALU (adder select, C0=1, invert input A), write accumulator&amp;lt;br&amp;gt;&lt;br /&gt;
:O4. Read IR, write PC if ACC7=0&amp;lt;br&amp;gt;&lt;br /&gt;
:O5. Read memory, read MAR, activate decoder, Send Shift left signal to ALU (SHL select), write accumulator&amp;lt;br&amp;gt;&lt;br /&gt;
:O6. Read memory, read MAR, activate decoder, Send Shift right signal to ALU (SHR select), write accumulator&amp;lt;br&amp;gt;&lt;br /&gt;
:O7. Cut power to oscillator.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
[[DF2010:Computing]]&lt;br /&gt;
&lt;br /&gt;
==External links==&lt;br /&gt;
*[http://docs.google.com/Doc?docid=0AdISzBuNg6ZWZGd0d2t4YjlfMjJ0ejlzc2dnaA&amp;amp;hl=en GoogleDocs Design Manuscript]&lt;br /&gt;
*[http://www.bay12forums.com/smf/index.php?topic=49641.0 Bay12 Forums thread]&lt;br /&gt;
*[http://mkv25.net/dfma/map-8269 Map at DF Map Archive]&lt;br /&gt;
*[http://dffd.wimbli.com/file.php?id=1929 Save File at DF File Depot]&lt;/div&gt;</summary>
		<author><name>Jong</name></author>
	</entry>
	<entry>
		<id>https://dwarffortresswiki.org/index.php?title=File:Datatransfers.png&amp;diff=101104</id>
		<title>File:Datatransfers.png</title>
		<link rel="alternate" type="text/html" href="https://dwarffortresswiki.org/index.php?title=File:Datatransfers.png&amp;diff=101104"/>
		<updated>2010-04-30T08:36:15Z</updated>

		<summary type="html">&lt;p&gt;Jong: Schematic of the data transfers within the CPU&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Schematic of the data transfers within the CPU&lt;/div&gt;</summary>
		<author><name>Jong</name></author>
	</entry>
	<entry>
		<id>https://dwarffortresswiki.org/index.php?title=File:ALUmulti.png&amp;diff=101103</id>
		<title>File:ALUmulti.png</title>
		<link rel="alternate" type="text/html" href="https://dwarffortresswiki.org/index.php?title=File:ALUmulti.png&amp;diff=101103"/>
		<updated>2010-04-30T08:34:28Z</updated>

		<summary type="html">&lt;p&gt;Jong: Schematic of a ALU multiplexer implementation&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Schematic of a ALU multiplexer implementation&lt;/div&gt;</summary>
		<author><name>Jong</name></author>
	</entry>
	<entry>
		<id>https://dwarffortresswiki.org/index.php?title=File:Aluarchi.png&amp;diff=101101</id>
		<title>File:Aluarchi.png</title>
		<link rel="alternate" type="text/html" href="https://dwarffortresswiki.org/index.php?title=File:Aluarchi.png&amp;diff=101101"/>
		<updated>2010-04-30T08:32:46Z</updated>

		<summary type="html">&lt;p&gt;Jong: Schematic of the ALU architecture&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Schematic of the ALU architecture&lt;/div&gt;</summary>
		<author><name>Jong</name></author>
	</entry>
	<entry>
		<id>https://dwarffortresswiki.org/index.php?title=File:Rotate_left_logically.svg.png&amp;diff=101099</id>
		<title>File:Rotate left logically.svg.png</title>
		<link rel="alternate" type="text/html" href="https://dwarffortresswiki.org/index.php?title=File:Rotate_left_logically.svg.png&amp;diff=101099"/>
		<updated>2010-04-30T08:31:16Z</updated>

		<summary type="html">&lt;p&gt;Jong: Bitshift Left (adapted from Wikipedia http://en.wikipedia.org/wiki/File:Rotate_left_logically.svg)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Bitshift Left (adapted from Wikipedia http://en.wikipedia.org/wiki/File:Rotate_left_logically.svg)&lt;/div&gt;</summary>
		<author><name>Jong</name></author>
	</entry>
	<entry>
		<id>https://dwarffortresswiki.org/index.php?title=File:175px-Rotate_right_arithmetically.svg.png&amp;diff=101097</id>
		<title>File:175px-Rotate right arithmetically.svg.png</title>
		<link rel="alternate" type="text/html" href="https://dwarffortresswiki.org/index.php?title=File:175px-Rotate_right_arithmetically.svg.png&amp;diff=101097"/>
		<updated>2010-04-30T08:29:07Z</updated>

		<summary type="html">&lt;p&gt;Jong: Bitshift right (adapted from Wikipedia http://en.wikipedia.org/wiki/File:Rotate_right_logically.svg)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Bitshift right (adapted from Wikipedia http://en.wikipedia.org/wiki/File:Rotate_right_logically.svg)&lt;/div&gt;</summary>
		<author><name>Jong</name></author>
	</entry>
	<entry>
		<id>https://dwarffortresswiki.org/index.php?title=File:Carrycircuit.png&amp;diff=101095</id>
		<title>File:Carrycircuit.png</title>
		<link rel="alternate" type="text/html" href="https://dwarffortresswiki.org/index.php?title=File:Carrycircuit.png&amp;diff=101095"/>
		<updated>2010-04-30T08:26:27Z</updated>

		<summary type="html">&lt;p&gt;Jong: Schematic of a carry calculation circuit for a carry-look-ahead adder&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Schematic of a carry calculation circuit for a carry-look-ahead adder&lt;/div&gt;</summary>
		<author><name>Jong</name></author>
	</entry>
	<entry>
		<id>https://dwarffortresswiki.org/index.php?title=File:Rippleaddersubtracter.png&amp;diff=101093</id>
		<title>File:Rippleaddersubtracter.png</title>
		<link rel="alternate" type="text/html" href="https://dwarffortresswiki.org/index.php?title=File:Rippleaddersubtracter.png&amp;diff=101093"/>
		<updated>2010-04-30T08:23:24Z</updated>

		<summary type="html">&lt;p&gt;Jong: Schematic of an 8-bit ripple-carry adder-subtractor&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Schematic of an 8-bit ripple-carry adder-subtractor&lt;/div&gt;</summary>
		<author><name>Jong</name></author>
	</entry>
	<entry>
		<id>https://dwarffortresswiki.org/index.php?title=File:Memarchi.png&amp;diff=101092</id>
		<title>File:Memarchi.png</title>
		<link rel="alternate" type="text/html" href="https://dwarffortresswiki.org/index.php?title=File:Memarchi.png&amp;diff=101092"/>
		<updated>2010-04-30T08:19:52Z</updated>

		<summary type="html">&lt;p&gt;Jong: Schematic of the memory unit's architecture&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Schematic of the memory unit's architecture&lt;/div&gt;</summary>
		<author><name>Jong</name></author>
	</entry>
	<entry>
		<id>https://dwarffortresswiki.org/index.php?title=File:5nscheme.png&amp;diff=101091</id>
		<title>File:5nscheme.png</title>
		<link rel="alternate" type="text/html" href="https://dwarffortresswiki.org/index.php?title=File:5nscheme.png&amp;diff=101091"/>
		<updated>2010-04-30T08:17:58Z</updated>

		<summary type="html">&lt;p&gt;Jong: Schematic of a 5 to 32 decoder&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Schematic of a 5 to 32 decoder&lt;/div&gt;</summary>
		<author><name>Jong</name></author>
	</entry>
	<entry>
		<id>https://dwarffortresswiki.org/index.php?title=File:2nscheme.png&amp;diff=101090</id>
		<title>File:2nscheme.png</title>
		<link rel="alternate" type="text/html" href="https://dwarffortresswiki.org/index.php?title=File:2nscheme.png&amp;diff=101090"/>
		<updated>2010-04-30T08:15:21Z</updated>

		<summary type="html">&lt;p&gt;Jong: Schematic of a 2 to 4 decoder&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Schematic of a 2 to 4 decoder&lt;/div&gt;</summary>
		<author><name>Jong</name></author>
	</entry>
	<entry>
		<id>https://dwarffortresswiki.org/index.php?title=File:Memreg.png&amp;diff=101089</id>
		<title>File:Memreg.png</title>
		<link rel="alternate" type="text/html" href="https://dwarffortresswiki.org/index.php?title=File:Memreg.png&amp;diff=101089"/>
		<updated>2010-04-30T08:10:56Z</updated>

		<summary type="html">&lt;p&gt;Jong: Schematic of an 8-bit register&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Schematic of an 8-bit register&lt;/div&gt;</summary>
		<author><name>Jong</name></author>
	</entry>
	<entry>
		<id>https://dwarffortresswiki.org/index.php?title=User:Jong&amp;diff=101088</id>
		<title>User:Jong</title>
		<link rel="alternate" type="text/html" href="https://dwarffortresswiki.org/index.php?title=User:Jong&amp;diff=101088"/>
		<updated>2010-04-30T08:08:27Z</updated>

		<summary type="html">&lt;p&gt;Jong: Replaced content with '==Dwarven Computer==
User:Jong/Dwarven_Computer'&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Dwarven Computer==&lt;br /&gt;
[[User:Jong/Dwarven_Computer]]&lt;/div&gt;</summary>
		<author><name>Jong</name></author>
	</entry>
	<entry>
		<id>https://dwarffortresswiki.org/index.php?title=User:Jong/Dwarven_Computer&amp;diff=101087</id>
		<title>User:Jong/Dwarven Computer</title>
		<link rel="alternate" type="text/html" href="https://dwarffortresswiki.org/index.php?title=User:Jong/Dwarven_Computer&amp;diff=101087"/>
		<updated>2010-04-30T08:08:08Z</updated>

		<summary type="html">&lt;p&gt;Jong: Dwarven Computer Design&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Adapted from http://docs.google.com/Doc?docid=0AdISzBuNg6ZWZGd0d2t4YjlfMjJ0ejlzc2dnaA&amp;amp;hl=en&lt;br /&gt;
&lt;br /&gt;
Need to wikify it.&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Toggled gear assemblies are designed as though they are off in when untriggered. However they are constructed in the on position. This means that you need to build and link a lever to toggle it to the off state.&lt;br /&gt;
&lt;br /&gt;
==Designs for power sensor (output device)==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  # %&amp;gt;^ #     &lt;br /&gt;
 ~ ~ ~ ~#      Power sensor side view&lt;br /&gt;
&lt;br /&gt;
In order to do useful things, such as toggling gears assemblies, opening doors, etc., mechanical power signals need to be converted to a trigger signal. There are only 2 trigger signal generators in dwarf fortress. One is the lever, which cannot be linked to machine power. The other is a pressure plate, which can.&lt;br /&gt;
&lt;br /&gt;
The basic operation of this component is simple. Power operates the pump, pushing water over the pressure plate, generating a signal. When the pump is not powered, the water drains, switching the pressure plate off after at least 100 steps.&lt;br /&gt;
&lt;br /&gt;
The smooth operation of this unit depends on several factors:&lt;br /&gt;
1. Adequate supply of water in the input tile so that the pump can maintain 7/7 or 6/7 water levels on the pressure plate. Can be done by providing more water tiles adjacent to the input tile.&lt;br /&gt;
2. Fast drainage to minimize the time needed for the plate to switch off. Just make sure that the level below the pumps is not completely full.&lt;br /&gt;
3. Since the minimum recovery time of the pressure plate is 100 steps, it can take a good long time for a 0-bit to reach the end of a chain of output units.&lt;br /&gt;
&lt;br /&gt;
==Design for a memory cell for use in registers/memory unit==&lt;br /&gt;
&lt;br /&gt;
 ###&lt;br /&gt;
 #H#&lt;br /&gt;
 #^#PRoO&lt;br /&gt;
 #%#&lt;br /&gt;
 #%WIP&lt;br /&gt;
 #~#&lt;br /&gt;
 ###&lt;br /&gt;
&lt;br /&gt;
This design is based on plans found at User:SL/Logic_Gates on the wiki. For this design, the write-in signal is linked to gear W and hatch H, while the read-out signal is linked to gear R. Gear o is linked to the pressure plate ^ and represents the state of the cell. Big O represents to output signal and I represents the input signal. P represents a power source. The hatch prevents the water from draining thus preserving the data.&lt;br /&gt;
&lt;br /&gt;
In order to act as a memory cell, this unit must do 3 things:&lt;br /&gt;
1. Output its state when told to read-out&lt;br /&gt;
2. Change state to match an input when told to write-in&lt;br /&gt;
3. Maintain its state when not told to do anything&lt;br /&gt;
&lt;br /&gt;
Let's check this by examining the operation of this unit. &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=1 style=&amp;quot;text-align:center&amp;quot; cellpadding=&amp;quot;2&amp;quot; cellspacing=&amp;quot;0&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|R&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|W&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|I&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|State&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|O&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| Ignored&lt;br /&gt;
| Unchanged&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| Ignored&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| Ignored&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
|}&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When both read and write are turned on, the device will act as a power sensor for the input. This could be a problem if the input and output are linked.&lt;br /&gt;
&lt;br /&gt;
One point of concern is that the unit may not contain sufficient water to trigger the plate because the amount of water in the square above the hatch may not be 7 when it closes. &lt;br /&gt;
&lt;br /&gt;
The plate could be set to trigger at a lower threshold, which would slightly slow down response time, or a door could be used instead of a hatch and the unit extended by one tile to provide space for the drain. This would have the downside of destroying some water after every write operation.&lt;br /&gt;
&lt;br /&gt;
Another method is to use another pump to drain the water from the holding tile. This pump will only activate when W is 1 and I is 0. &lt;br /&gt;
&lt;br /&gt;
==Design for the computer registers==&lt;br /&gt;
&lt;br /&gt;
The dwarven computer prototype is going to have an 8-bit instruction length, a 3-bit operon and a 5-bit address space. Why? The best reason for this is that other designs of Very Simple Computers (VSC) on the Internet are also only 8-bit and I am basing the design of the prototype dwarven computer off several of them. Naturally a bigger computer is better in many ways but the current goal is to produce an operational one. Now its not clear to me why a VSC shouldn't be smaller, but I suppose it doesn't matter.&lt;br /&gt;
&lt;br /&gt;
8-bit words need 8-bit registers. Fortunately this just means stacking 8 memory units up and making sure they receive the same read/write signals.&lt;br /&gt;
&lt;br /&gt;
The lines in the diagram don't actually represent physical connections but imaginary ones. After all, the write signal must be sent remotely.&lt;br /&gt;
&lt;br /&gt;
Now we consider the most compact designs for such an array. Let us assume that the output signals will be sent remotely. For clarity, the arrays ought to be rectangular.&lt;br /&gt;
&lt;br /&gt;
 ##### ##### ##### ##### ##### ##### ##### ##### &lt;br /&gt;
 #H#.# #H#.# #H#.# #H#.# #H#.# #H#.# #H#.# #H#.# &lt;br /&gt;
 #^#^# #^#^# #^#^# #^#^# #^#^# #^#^# #^#^# #^#^# &lt;br /&gt;
 #%#%# #%#%# #%#%# #%#%# #%#%# #%#%# #%#%# #%#%# &lt;br /&gt;
 W%`%o W%`%o W%`%o W%`%o W%`%o W%`%o W%`%o W%`%o &lt;br /&gt;
 I~`~RPI~`~RPI~`~RPI~`~RPI~`~RPI~`~RPI~`~RPI~`~R&lt;br /&gt;
 P`````````````````````````````````````````````P&lt;br /&gt;
Note that the O is omitted since it was a placeholder for the output device.&lt;br /&gt;
&lt;br /&gt;
Not all registers in the computer are 8 bit registers. For example the memory address register is 5 bits.&lt;br /&gt;
&lt;br /&gt;
==Design for the Memory Unit==&lt;br /&gt;
&lt;br /&gt;
Since there are only 5 bits of address space, I only need 256 memory cells. It should be fine if I don't use complicated column and row addressing schemes. I shall simply have 32 8-bit registers sticking somewhere. In order for the memory unit to work, I need a decoder to change the 5-bit address into 32 outputs. This will enable the memory unit to read and write from any register. I guess this makes it random access memory.&lt;br /&gt;
&lt;br /&gt;
===Design for a decoder===&lt;br /&gt;
&lt;br /&gt;
This type of decoder is called an n to 2^n decoder, since it converts n inputs into 2^n outputs, in this case 5 to 32(2^5).&lt;br /&gt;
&lt;br /&gt;
To illustrate the design for this unit, let us consider a simpler example where n=2. There will be 2  binary inputs which will be converted into 4 unique outputs, 1 for each memory address.&lt;br /&gt;
&lt;br /&gt;
Here is the truth table for the operation:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=1 style=&amp;quot;text-align:center&amp;quot; cellpadding=&amp;quot;2&amp;quot; cellspacing=&amp;quot;0&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|2^0 (1)&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|2^1 (2)&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|O0&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|O1&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|O2&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|O3&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
|}&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now let us examine the implementation into the dwarfputer. Remember that gear assemblies are toggleable. I can implement a NOT operation by simply reversing the default state of a triggered gear (which is OFF in this system).&lt;br /&gt;
&lt;br /&gt;
Let us represent the 2^0 gear as A when it is default OFF and as a when it is default ON, and represent the 2^1 gear as B and b. O0 to O3 represent output devices.&lt;br /&gt;
&lt;br /&gt;
 P  P  P  P&lt;br /&gt;
 a  A  a  A&lt;br /&gt;
 b  b  B  B&lt;br /&gt;
 O0 O1 O2 O3&lt;br /&gt;
&lt;br /&gt;
This is the easiest to understand implementation. Looking at O0, we see that O0 is powered only when a and b are active. This corresponds to the state when 2^0 and 2^1 are both 0. Examining all the devices reveals that this arrangement obeys the truth table detailed above. Further examination would reveal that this arrangement also follows a pattern. Basically, the full set of columns represent every single possible combination of a, A, b, and B. Therefore we can easily see how to expand this system to n=5.&lt;br /&gt;
&lt;br /&gt;
However, this implementation is not the most efficient one. I can also arrange the gears like so:&lt;br /&gt;
&lt;br /&gt;
 O3A AO1&lt;br /&gt;
   BPb&lt;br /&gt;
 O2a aO0&lt;br /&gt;
&lt;br /&gt;
This arrangement uses 7 gears while the first arrangement uses 12 gears (including power gears). I put B and b closest to the power supply to obtain an orderly arrangement of O0 to O3 although this isn't strictly necessary.&lt;br /&gt;
&lt;br /&gt;
Schematically this arrangement looks like this:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Which is just some sort of tree diagram. I can easily expand this to n=5 which is what I want.&lt;br /&gt;
&lt;br /&gt;
I drew this diagram in rectangular form so that I can better see how to construct the decoder. The outputs of the decoder will be in a 4x8 grid. Since the output units are longer in one direction than the other, I will align their long axis along the short axis of the diagram. It is probably best to place all the mechanisms for the decoder in the level above the outputs.&lt;br /&gt;
&lt;br /&gt;
===Design for Memory Unit Registers===&lt;br /&gt;
&lt;br /&gt;
The registers in the memory unit need some modification to work correctly. Only the register indicated in the memory address register ought to respond to read write signals. Therefore each of the 32 registers needs to be connected to one of the outputs from the decoder.&lt;br /&gt;
&lt;br /&gt;
In this example, the register only responds when 00000 is in the memory address register.&lt;br /&gt;
&lt;br /&gt;
 ##### ##### ##### ##### ##### ##### ##### ##### &lt;br /&gt;
 #H#.# #H#.# #H#.# #H#.# #H#.# #H#.# #H#.# #H#.# &lt;br /&gt;
 #^#^# #^#^# #^#^# #^#^# #^#^# #^#^# #^#^# #^#^# &lt;br /&gt;
 #%#%# #%#%# #%#%# #%#%# #%#%# #%#%# #%#%# #%#%# &lt;br /&gt;
 W%`%o W%`%o W%`%o W%`%o W%`%o W%`%o W%`%o W%`%o &lt;br /&gt;
 I~`~RCI~`~RCI~`~RCI~`~RCI~`~RCI~`~RCI~`~RCI~`~R&lt;br /&gt;
 CP```P`````P`````P`````P`````P`````P`````P```PC&lt;br /&gt;
&lt;br /&gt;
C in this diagram represents the output O0. I believe this is called the chip select signal in real computers.&lt;br /&gt;
&lt;br /&gt;
It may be possible to wire the decoder directly to the power supply of the memory, which would remove the need for an output device. &lt;br /&gt;
&lt;br /&gt;
===Memory Unit Architecture===&lt;br /&gt;
&lt;br /&gt;
Right, I based the design of the memory unit off a java applet simulator I found on the Internet. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
What this diagram is supposed to illustrate is that ALL the memory cells are linked to respond to the same read-out signal and the same write-in signal. Similarly, all the corresponding cells respond to same input, and all output to the same place. However, they will do none of these things unless they get a signal from the decoder, and only one register will get the signal as indicated in the memory address register. &lt;br /&gt;
&lt;br /&gt;
Now the input and output buffers shown here may not be in the final blueprints, depending on the design of the rest of the computer.&lt;br /&gt;
&lt;br /&gt;
==Designing the machine language==&lt;br /&gt;
&lt;br /&gt;
The machine language is the set of instructions the computer will be able to execute. What these instructions are will define the design of the remaining components. For example, the Arithmetic Logic Unit needs to be able to perform the various operations listed in these instructions.&lt;br /&gt;
&lt;br /&gt;
Ideally this language should be complete, that is, any function can be simulated as a combination of these instructions. I also want to be as simple as possible, to minimize the complexity of the ALU. It is worth restating that I am basing the overall design for the computer on a design for a VSC off the Internet.&lt;br /&gt;
&lt;br /&gt;
Since the opcode for this computer is 3-bits long, there can only be 8 instructions.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=1 style=&amp;quot;text-align:center&amp;quot; cellpadding=&amp;quot;2&amp;quot; cellspacing=&amp;quot;0&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Opcode&lt;br /&gt;
!Function&lt;br /&gt;
!Operand&lt;br /&gt;
|-&lt;br /&gt;
| 000&lt;br /&gt;
| Load Accumulator from memory (indirectly)&lt;br /&gt;
| Memory Address&lt;br /&gt;
|-&lt;br /&gt;
| 001&lt;br /&gt;
| Store Accumulator to memory&lt;br /&gt;
| Memory Address&lt;br /&gt;
|-&lt;br /&gt;
| 010&lt;br /&gt;
| Add&lt;br /&gt;
| Memory Address&lt;br /&gt;
|-&lt;br /&gt;
| 011&lt;br /&gt;
| Subtract&lt;br /&gt;
| Memory Address&lt;br /&gt;
|-&lt;br /&gt;
| 100&lt;br /&gt;
| Jump to address if accumulator is not negative&lt;br /&gt;
| Memory Address&lt;br /&gt;
|-&lt;br /&gt;
| 101&lt;br /&gt;
| Binary shift left (*2) (input 0 as LSB)&lt;br /&gt;
| Memory Address&lt;br /&gt;
|-&lt;br /&gt;
| 110&lt;br /&gt;
| Binary shift right (/2) (retain MSB)&lt;br /&gt;
| Memory Address&lt;br /&gt;
|-&lt;br /&gt;
| 111&lt;br /&gt;
| Halt&lt;br /&gt;
| None&lt;br /&gt;
|}&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design for the Arithmetic Logic Unit (ALU)==&lt;br /&gt;
&lt;br /&gt;
Now I know that the ALU needs to be able to perform 4 functions: Add, subtract, shift left and shift right. The unit needs to do one of these functions based on one of 4 input signals it may receive.&lt;br /&gt;
&lt;br /&gt;
The ALU will receive 2 8-bit inputs and produce 1 8-bit output. It will require 3 systems, the adder-subtractor, bitshift left and bitshift right. These systems would be integrated to form the ALU.&lt;br /&gt;
&lt;br /&gt;
===Design for a half adder===&lt;br /&gt;
&lt;br /&gt;
While there are existing dwarven adder designs out there, they do not come with schematics detailing the links between their components. Therefore I feel the need to design from scratch.&lt;br /&gt;
&lt;br /&gt;
A simple half adder would take 2 inputs, and produce an output and an overflow output called a carry.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=1 style=&amp;quot;text-align:center&amp;quot; cellpadding=&amp;quot;2&amp;quot; cellspacing=&amp;quot;0&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|A&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|B&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|C&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|O&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
|}&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &lt;br /&gt;
 Carry out circuit  C==ABP&lt;br /&gt;
&lt;br /&gt;
                       aBP&lt;br /&gt;
 Output circuit     O==o&lt;br /&gt;
                       bAP&lt;br /&gt;
&lt;br /&gt;
                  C===A&lt;br /&gt;
 Combined circuit    aBP&lt;br /&gt;
                  O==obA&lt;br /&gt;
&lt;br /&gt;
This schematic shows a dwarven half adder that obeys the above truth table. In this diagram, the o represents a normal gear assembly and = represents axles. This design rests on the assumption that axles do not receive power except from their end tiles. It also takes advantage of the assumption that a matched pair of gears will not transmit information across their connection (here it is the B and b gear)&lt;br /&gt;
&lt;br /&gt;
I believe this design uses the minimum number of gear assemblies, although I am not sure.&lt;br /&gt;
&lt;br /&gt;
===Design for a full adder===&lt;br /&gt;
&lt;br /&gt;
In order for an adder to work properly, it must also receive the carry bit in addition to the 2 inputs. Ultimately, even the first adder in the final adder-subtracter must be able to receive a carry bit to operate successfully, which is why I didn't draw up a full plan for the half adder.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=1 style=&amp;quot;text-align:center&amp;quot; cellpadding=&amp;quot;2&amp;quot; cellspacing=&amp;quot;0&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|A&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|B&lt;br /&gt;
!C (carry in)&lt;br /&gt;
!O2 (carry out)&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|O1&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
|}&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 PB&lt;br /&gt;
 CAo==O2       Carry Out Circuit&lt;br /&gt;
 oBo&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 o=o=o=o==O1   Output Circuit&lt;br /&gt;
 C c c C&lt;br /&gt;
 B b B b&lt;br /&gt;
 A A a a&lt;br /&gt;
 P P P P&lt;br /&gt;
&lt;br /&gt;
     O1 O2     Combined Circuit&lt;br /&gt;
  oo=oo |&lt;br /&gt;
  Cc cC oo&lt;br /&gt;
  Bb BbBAB&lt;br /&gt;
 PAo oaPCo&lt;br /&gt;
&lt;br /&gt;
Now that looks pretty monstrous. Undoubtedly the arrangement of gears could be changed here and there depending on the exact dimensions you need the array to be, but hopefully this diagram illustrates methods that can be used to minimize the complexity of the device. Note that where there are adjacent identical gears directly connected to the power source, one of them can be replaced by an ordinary gear, which will remove a linking task for that gear.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   `````   oCBAP&lt;br /&gt;
   ````    ocbo&lt;br /&gt;
 #####   ``|``&lt;br /&gt;
 #.#.#`  ``ocBo&lt;br /&gt;
 #^#^#`  `ooCba     Hypothetical implementation&lt;br /&gt;
 #%#%#`  `o``BP&lt;br /&gt;
 `%`%``  ```oAC&lt;br /&gt;
 `~`~``  ```oBo&lt;br /&gt;
 `````   `````&lt;br /&gt;
  lvlz     lvlz+1&lt;br /&gt;
&lt;br /&gt;
The above diagram details a hypothetical implementation for a full adder. The ```s represent the shadow of the mechanisms above and below the level. The left power sensor produces the output signal while the right power sensor produces the carry signal to be relayed to the next adder. The total footprint of the unit is 6x9. In an array, the units can overlap one tile so the total footprint of an 8-bit adder would be 41x9. Maximum operational power draw is 131x8(1048) units of power.&lt;br /&gt;
&lt;br /&gt;
===Design for an 8-bit ripple carry adder-subtracter===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to build a full 8-bit adder-subtracter, all you need to do is to stack up 8 full adders next to each other and ensure that all the gears have been linked to the appropriate plates.&lt;br /&gt;
&lt;br /&gt;
Now to get the adder-subtracter to subtract, all you have to do is to link up every single A and a (or B and b) gear assembly to the pressure plate sending the subtract signal. When the signal is sent, all the gears linked to a register will toggle. This will have the effect of inverting whatever input the register is sending. Finally the signal also needs to activate the carry in gears in the first adder, which will have the effect of adding 1 to the resulting sum (difference), giving the correct answer in two's complement representation.&lt;br /&gt;
&lt;br /&gt;
===Design for a carry-look-ahead adder===&lt;br /&gt;
&lt;br /&gt;
I did some research into carry-look-ahead adders to see if it was worth implementing. Carry-look-ahead adders are faster than ripple-carry adders as ripple carry adders have to wait for the carry bit to 'ripple' through the chain of adders before getting the correct result. This is most significant for users of fluid logic, as fluid logic adders need to wait n*100 steps (n being the number of bits) for the carry to ripple all the way to the end. (Floodgates and bridges have a 100 step delay before activating or deactivating)&lt;br /&gt;
&lt;br /&gt;
I found that I could easily design a carry-look-ahead adder using mechanical logic that calculates the carry in bit for all bits in a single step. I would also like to point out that real carry-look-ahead adders are more complicated because they don't have teleporting switch signals. &lt;br /&gt;
&lt;br /&gt;
Firstly, looking at the carry-out circuit for the full adder, I see that not only can it exist independently from the sum circuit, the C gear is directly attached to the power source. I can take advantage of this by separating the carry bit calculation circuits from the adder and attaching them to each other like so. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then for the summing part of the adder, I simply build only the output circuit, which I can now simplify like this&lt;br /&gt;
&lt;br /&gt;
     O1     Output Circuit&lt;br /&gt;
  oo=oo&lt;br /&gt;
  Cc cC&lt;br /&gt;
  Bb Bb&lt;br /&gt;
  oAPao&lt;br /&gt;
&lt;br /&gt;
Or I can make it long instead of square so that it will tile better with the output buffers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    O1&lt;br /&gt;
    |&lt;br /&gt;
 oBCoCbo&lt;br /&gt;
 AbcocBa&lt;br /&gt;
 P     P&lt;br /&gt;
&lt;br /&gt;
I could construct these directly above the output buffers and they would all tile a lot better. Not only that, it fits almost perfectly within the footprint of a bank of output buffers. There is also no cost of increased complexity, only spatial separation between the summation unit and the carry unit, plus providing all the advantages of the carry-look-ahead system.&lt;br /&gt;
&lt;br /&gt;
Since this system is superior in all ways to the ripple-carry system, this will be the one going into the final dwarven computer.&lt;br /&gt;
&lt;br /&gt;
===Design for bitshifting operations===&lt;br /&gt;
&lt;br /&gt;
Setting up a bitshifting operation is relatively simple. I simply wire the inputs directly into slightly different outputs as illustrated in the following diagrams (source: Wikipedia http://en.wikipedia.org/wiki/Bitwise_operation#Arithmetic_shift).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ideally all these operations would be linked into the same bank of output buffers in the assembled ALU, which will be the subject of the next section.&lt;br /&gt;
&lt;br /&gt;
===Design for ALU architecture===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This diagram illustrates the various signals moving around the ALU. I decided that I ought to dragoon the ALU into incrementing the program counter as well, but I'm not sure whether that will work or not. We'll see in the later sections.&lt;br /&gt;
&lt;br /&gt;
I defined the inputs from AR1 to be A since there are fewer A and a gears in the current designs and they all have to be toggled by the subtract signal. The operations listed on the right are signals generated by the control unit and they tell the ALU which operation to perform and transfer to the output buffer banks. The component critical to this function is the multiplexer. &lt;br /&gt;
&lt;br /&gt;
The concept of the multiplexer is quite simple, suppose I had 2 inputs I and J, and I wanted to choose which one to pass based on signals Q and R, I would have to build something like this&lt;br /&gt;
&lt;br /&gt;
 PQIoJRP&lt;br /&gt;
    |&lt;br /&gt;
    O&lt;br /&gt;
&lt;br /&gt;
Adding a multiplexer onto the output circuit would require an additional z-level if the tiling efficiency is to be maintained. &lt;br /&gt;
&lt;br /&gt;
This diagram illustrates a hypothetical implementation of the multiplexer, as well as the bitshifting logic. I don't think I need a support axle on z+2 as it should be supported by O1.&lt;br /&gt;
&lt;br /&gt;
==Design of the bus==&lt;br /&gt;
&lt;br /&gt;
I've decided to ditch the plan for a bus, which would have been the conduit for data transfers between registers throughout the computer. Initially there were 2 methods, one had a output buffer attached to the end of the bus while the other the bus directly supplied power to the inputs of the appropriate registers. &lt;br /&gt;
&lt;br /&gt;
Method 2 would not work on memory cells that used an active pump for bit-clearing. Method 1 would have worked but the output buffers had to be overwritten every step and that could cause cascading delays throughout the computer. Since this computer is relatively simple, I opted for hard wiring everything instead.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This diagram illustrates the data transfers that occur throughout the computer. The red arrows depict confirmed hard-wired connections, while the blue arrows would have been routed through a bus. I've decide AR1 is superfluous so I got rid of it. As you can see, each register has at most 2 inputs or 2 outputs going through the bus, so hardwiring is feasible.&lt;br /&gt;
&lt;br /&gt;
==Design of the timing circuit==&lt;br /&gt;
&lt;br /&gt;
Before the computer can execute its instructions, it needs to perform some operations first.&lt;br /&gt;
&lt;br /&gt;
#Transfer the contents of the accumulator to AR2. Dump instruction register and memory address register.&amp;lt;br&amp;gt;&lt;br /&gt;
#Transfer the program counter to the memory address register. Also, activate the program counter incrementation system in the ALU and transfer the results into program counter +1.&amp;lt;br&amp;gt;&lt;br /&gt;
#Load the data from memory at the specified address into the instruction register.&amp;lt;br&amp;gt;&lt;br /&gt;
#Transfer the data from program counter +1 to the program counter. Also, dump the memory address register&amp;lt;br&amp;gt;&lt;br /&gt;
#Load the last 5 digits of the instruction register into the memory address register. Also, dump program counter +1.&amp;lt;br&amp;gt;&lt;br /&gt;
#Execution (write accumulator, memory or program counter, read instruction register, memory, AR2)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There needs to be a 100 step delay from the time a memory cell is written (or dumped, if it is pre-dumped) and when it is read, or it may cause cascading delays. The writing process is practically instantaneous, but 100 steps are needed before the correct result can be read if the memory was not cleared to begin with. Of course this point is entirely moot if the computer is running automatically, in which case every step will last at least 100 steps anyway and the prime consideration is to ensure that every step can be performed in 100 steps.&lt;br /&gt;
&lt;br /&gt;
==Design of the oscillator==&lt;br /&gt;
&lt;br /&gt;
A typical mechanical oscillator is unsatisfactory because it will usually be sending out 2 on signals at once, one from the pressure plate the water is on and the other from the pressure plate waiting to reset.&lt;br /&gt;
&lt;br /&gt;
 0%%6%%0%%5%%0%%4&lt;br /&gt;
 %              %&lt;br /&gt;
 %              %&lt;br /&gt;
 1%%0%%2%%0%%3%%0&lt;br /&gt;
&lt;br /&gt;
This diagram shows a 12 step 6 signal oscillator. At the locations marked 0, there are no pressure plates. A lever operates the mechanism. When the lever is in the ON position, the #%%0 pumps activate, and when the lever is in the OFF position, the 0%%# pumps activate. The oscillator can also be fully automated by using the pressure plates themselves to replace the lever function. The oscillator's power supply also needs to be cut if a halt signal is received from the control unit. &lt;br /&gt;
&lt;br /&gt;
===Oscillator Link table===&lt;br /&gt;
&lt;br /&gt;
#Read accumulator, write AR2, write IR, write MAR&amp;lt;br&amp;gt;&lt;br /&gt;
#Read PC, write MAR, activate ALU (adder select, C0=1), write PC+1&amp;lt;br&amp;gt;&lt;br /&gt;
#Read MEM, read MAR. activate decoder, write IR&amp;lt;br&amp;gt;&lt;br /&gt;
#Read PC+1, write PC, write MAR&amp;lt;br&amp;gt;&lt;br /&gt;
#Read IR, write MAR, write PC+1&amp;lt;br&amp;gt;&lt;br /&gt;
#Execution (read IR, turn on control unit)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A dump operation can be performed by telling the memory register to write when its linked inputs are inactive, effectively writing 0s. &lt;br /&gt;
&lt;br /&gt;
==Design of the control unit==&lt;br /&gt;
&lt;br /&gt;
The control unit can be implemented simply as a 3-8 decoder with appropriately linked pressure plates. The execute signal controlled gear assembly is located at the root of the decoder. &lt;br /&gt;
&lt;br /&gt;
===Control unit link table===&lt;br /&gt;
&lt;br /&gt;
:O0. Read memory, read MAR, activate decoder, write accumulator, select transfer&amp;lt;br&amp;gt;&lt;br /&gt;
:O1. Read accumulator, write memory, read MAR, activate decoder&amp;lt;br&amp;gt;&lt;br /&gt;
:O2. Read memory, read MAR, activate decoder, read AR2, Send Add signal to ALU (adder select), write accumulator&amp;lt;br&amp;gt;&lt;br /&gt;
:O3. Read memory, read MAR, activate decoder, read AR2, Send Subtract signal to ALU (adder select, C0=1, invert input A), write accumulator&amp;lt;br&amp;gt;&lt;br /&gt;
:O4. Read IR, write PC if ACC7=0&amp;lt;br&amp;gt;&lt;br /&gt;
:O5. Read memory, read MAR, activate decoder, Send Shift left signal to ALU (SHL select), write accumulator&amp;lt;br&amp;gt;&lt;br /&gt;
:O6. Read memory, read MAR, activate decoder, Send Shift right signal to ALU (SHR select), write accumulator&amp;lt;br&amp;gt;&lt;br /&gt;
:O7. Cut power to oscillator.&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jong</name></author>
	</entry>
	<entry>
		<id>https://dwarffortresswiki.org/index.php?title=User:Jong&amp;diff=101086</id>
		<title>User:Jong</title>
		<link rel="alternate" type="text/html" href="https://dwarffortresswiki.org/index.php?title=User:Jong&amp;diff=101086"/>
		<updated>2010-04-30T08:05:03Z</updated>

		<summary type="html">&lt;p&gt;Jong: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Adapted from http://docs.google.com/Doc?docid=0AdISzBuNg6ZWZGd0d2t4YjlfMjJ0ejlzc2dnaA&amp;amp;hl=en&lt;br /&gt;
&lt;br /&gt;
Need to wikify it.&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Toggled gear assemblies are designed as though they are off in when untriggered. However they are constructed in the on position. This means that you need to build and link a lever to toggle it to the off state.&lt;br /&gt;
&lt;br /&gt;
==Designs for power sensor (output device)==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  # %&amp;gt;^ #     &lt;br /&gt;
 ~ ~ ~ ~#      Power sensor side view&lt;br /&gt;
&lt;br /&gt;
In order to do useful things, such as toggling gears assemblies, opening doors, etc., mechanical power signals need to be converted to a trigger signal. There are only 2 trigger signal generators in dwarf fortress. One is the lever, which cannot be linked to machine power. The other is a pressure plate, which can.&lt;br /&gt;
&lt;br /&gt;
The basic operation of this component is simple. Power operates the pump, pushing water over the pressure plate, generating a signal. When the pump is not powered, the water drains, switching the pressure plate off after at least 100 steps.&lt;br /&gt;
&lt;br /&gt;
The smooth operation of this unit depends on several factors:&lt;br /&gt;
1. Adequate supply of water in the input tile so that the pump can maintain 7/7 or 6/7 water levels on the pressure plate. Can be done by providing more water tiles adjacent to the input tile.&lt;br /&gt;
2. Fast drainage to minimize the time needed for the plate to switch off. Just make sure that the level below the pumps is not completely full.&lt;br /&gt;
3. Since the minimum recovery time of the pressure plate is 100 steps, it can take a good long time for a 0-bit to reach the end of a chain of output units.&lt;br /&gt;
&lt;br /&gt;
==Design for a memory cell for use in registers/memory unit==&lt;br /&gt;
&lt;br /&gt;
 ###&lt;br /&gt;
 #H#&lt;br /&gt;
 #^#PRoO&lt;br /&gt;
 #%#&lt;br /&gt;
 #%WIP&lt;br /&gt;
 #~#&lt;br /&gt;
 ###&lt;br /&gt;
&lt;br /&gt;
This design is based on plans found at User:SL/Logic_Gates on the wiki. For this design, the write-in signal is linked to gear W and hatch H, while the read-out signal is linked to gear R. Gear o is linked to the pressure plate ^ and represents the state of the cell. Big O represents to output signal and I represents the input signal. P represents a power source. The hatch prevents the water from draining thus preserving the data.&lt;br /&gt;
&lt;br /&gt;
In order to act as a memory cell, this unit must do 3 things:&lt;br /&gt;
1. Output its state when told to read-out&lt;br /&gt;
2. Change state to match an input when told to write-in&lt;br /&gt;
3. Maintain its state when not told to do anything&lt;br /&gt;
&lt;br /&gt;
Let's check this by examining the operation of this unit. &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=1 style=&amp;quot;text-align:center&amp;quot; cellpadding=&amp;quot;2&amp;quot; cellspacing=&amp;quot;0&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|R&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|W&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|I&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|State&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|O&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| Ignored&lt;br /&gt;
| Unchanged&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| Ignored&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| Ignored&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
|}&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When both read and write are turned on, the device will act as a power sensor for the input. This could be a problem if the input and output are linked.&lt;br /&gt;
&lt;br /&gt;
One point of concern is that the unit may not contain sufficient water to trigger the plate because the amount of water in the square above the hatch may not be 7 when it closes. &lt;br /&gt;
&lt;br /&gt;
The plate could be set to trigger at a lower threshold, which would slightly slow down response time, or a door could be used instead of a hatch and the unit extended by one tile to provide space for the drain. This would have the downside of destroying some water after every write operation.&lt;br /&gt;
&lt;br /&gt;
Another method is to use another pump to drain the water from the holding tile. This pump will only activate when W is 1 and I is 0. &lt;br /&gt;
&lt;br /&gt;
==Design for the computer registers==&lt;br /&gt;
&lt;br /&gt;
The dwarven computer prototype is going to have an 8-bit instruction length, a 3-bit operon and a 5-bit address space. Why? The best reason for this is that other designs of Very Simple Computers (VSC) on the Internet are also only 8-bit and I am basing the design of the prototype dwarven computer off several of them. Naturally a bigger computer is better in many ways but the current goal is to produce an operational one. Now its not clear to me why a VSC shouldn't be smaller, but I suppose it doesn't matter.&lt;br /&gt;
&lt;br /&gt;
8-bit words need 8-bit registers. Fortunately this just means stacking 8 memory units up and making sure they receive the same read/write signals.&lt;br /&gt;
&lt;br /&gt;
The lines in the diagram don't actually represent physical connections but imaginary ones. After all, the write signal must be sent remotely.&lt;br /&gt;
&lt;br /&gt;
Now we consider the most compact designs for such an array. Let us assume that the output signals will be sent remotely. For clarity, the arrays ought to be rectangular.&lt;br /&gt;
&lt;br /&gt;
 ##### ##### ##### ##### ##### ##### ##### ##### &lt;br /&gt;
 #H#.# #H#.# #H#.# #H#.# #H#.# #H#.# #H#.# #H#.# &lt;br /&gt;
 #^#^# #^#^# #^#^# #^#^# #^#^# #^#^# #^#^# #^#^# &lt;br /&gt;
 #%#%# #%#%# #%#%# #%#%# #%#%# #%#%# #%#%# #%#%# &lt;br /&gt;
 W%`%o W%`%o W%`%o W%`%o W%`%o W%`%o W%`%o W%`%o &lt;br /&gt;
 I~`~RPI~`~RPI~`~RPI~`~RPI~`~RPI~`~RPI~`~RPI~`~R&lt;br /&gt;
 P`````````````````````````````````````````````P&lt;br /&gt;
Note that the O is omitted since it was a placeholder for the output device.&lt;br /&gt;
&lt;br /&gt;
Not all registers in the computer are 8 bit registers. For example the memory address register is 5 bits.&lt;br /&gt;
&lt;br /&gt;
==Design for the Memory Unit==&lt;br /&gt;
&lt;br /&gt;
Since there are only 5 bits of address space, I only need 256 memory cells. It should be fine if I don't use complicated column and row addressing schemes. I shall simply have 32 8-bit registers sticking somewhere. In order for the memory unit to work, I need a decoder to change the 5-bit address into 32 outputs. This will enable the memory unit to read and write from any register. I guess this makes it random access memory.&lt;br /&gt;
&lt;br /&gt;
===Design for a decoder===&lt;br /&gt;
&lt;br /&gt;
This type of decoder is called an n to 2^n decoder, since it converts n inputs into 2^n outputs, in this case 5 to 32(2^5).&lt;br /&gt;
&lt;br /&gt;
To illustrate the design for this unit, let us consider a simpler example where n=2. There will be 2  binary inputs which will be converted into 4 unique outputs, 1 for each memory address.&lt;br /&gt;
&lt;br /&gt;
Here is the truth table for the operation:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=1 style=&amp;quot;text-align:center&amp;quot; cellpadding=&amp;quot;2&amp;quot; cellspacing=&amp;quot;0&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|2^0 (1)&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|2^1 (2)&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|O0&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|O1&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|O2&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|O3&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
|}&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now let us examine the implementation into the dwarfputer. Remember that gear assemblies are toggleable. I can implement a NOT operation by simply reversing the default state of a triggered gear (which is OFF in this system).&lt;br /&gt;
&lt;br /&gt;
Let us represent the 2^0 gear as A when it is default OFF and as a when it is default ON, and represent the 2^1 gear as B and b. O0 to O3 represent output devices.&lt;br /&gt;
&lt;br /&gt;
 P  P  P  P&lt;br /&gt;
 a  A  a  A&lt;br /&gt;
 b  b  B  B&lt;br /&gt;
 O0 O1 O2 O3&lt;br /&gt;
&lt;br /&gt;
This is the easiest to understand implementation. Looking at O0, we see that O0 is powered only when a and b are active. This corresponds to the state when 2^0 and 2^1 are both 0. Examining all the devices reveals that this arrangement obeys the truth table detailed above. Further examination would reveal that this arrangement also follows a pattern. Basically, the full set of columns represent every single possible combination of a, A, b, and B. Therefore we can easily see how to expand this system to n=5.&lt;br /&gt;
&lt;br /&gt;
However, this implementation is not the most efficient one. I can also arrange the gears like so:&lt;br /&gt;
&lt;br /&gt;
 O3A AO1&lt;br /&gt;
   BPb&lt;br /&gt;
 O2a aO0&lt;br /&gt;
&lt;br /&gt;
This arrangement uses 7 gears while the first arrangement uses 12 gears (including power gears). I put B and b closest to the power supply to obtain an orderly arrangement of O0 to O3 although this isn't strictly necessary.&lt;br /&gt;
&lt;br /&gt;
Schematically this arrangement looks like this:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Which is just some sort of tree diagram. I can easily expand this to n=5 which is what I want.&lt;br /&gt;
&lt;br /&gt;
I drew this diagram in rectangular form so that I can better see how to construct the decoder. The outputs of the decoder will be in a 4x8 grid. Since the output units are longer in one direction than the other, I will align their long axis along the short axis of the diagram. It is probably best to place all the mechanisms for the decoder in the level above the outputs.&lt;br /&gt;
&lt;br /&gt;
===Design for Memory Unit Registers===&lt;br /&gt;
&lt;br /&gt;
The registers in the memory unit need some modification to work correctly. Only the register indicated in the memory address register ought to respond to read write signals. Therefore each of the 32 registers needs to be connected to one of the outputs from the decoder.&lt;br /&gt;
&lt;br /&gt;
In this example, the register only responds when 00000 is in the memory address register.&lt;br /&gt;
&lt;br /&gt;
 ##### ##### ##### ##### ##### ##### ##### ##### &lt;br /&gt;
 #H#.# #H#.# #H#.# #H#.# #H#.# #H#.# #H#.# #H#.# &lt;br /&gt;
 #^#^# #^#^# #^#^# #^#^# #^#^# #^#^# #^#^# #^#^# &lt;br /&gt;
 #%#%# #%#%# #%#%# #%#%# #%#%# #%#%# #%#%# #%#%# &lt;br /&gt;
 W%`%o W%`%o W%`%o W%`%o W%`%o W%`%o W%`%o W%`%o &lt;br /&gt;
 I~`~RCI~`~RCI~`~RCI~`~RCI~`~RCI~`~RCI~`~RCI~`~R&lt;br /&gt;
 CP```P`````P`````P`````P`````P`````P`````P```PC&lt;br /&gt;
&lt;br /&gt;
C in this diagram represents the output O0. I believe this is called the chip select signal in real computers.&lt;br /&gt;
&lt;br /&gt;
It may be possible to wire the decoder directly to the power supply of the memory, which would remove the need for an output device. &lt;br /&gt;
&lt;br /&gt;
===Memory Unit Architecture===&lt;br /&gt;
&lt;br /&gt;
Right, I based the design of the memory unit off a java applet simulator I found on the Internet. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
What this diagram is supposed to illustrate is that ALL the memory cells are linked to respond to the same read-out signal and the same write-in signal. Similarly, all the corresponding cells respond to same input, and all output to the same place. However, they will do none of these things unless they get a signal from the decoder, and only one register will get the signal as indicated in the memory address register. &lt;br /&gt;
&lt;br /&gt;
Now the input and output buffers shown here may not be in the final blueprints, depending on the design of the rest of the computer.&lt;br /&gt;
&lt;br /&gt;
==Designing the machine language==&lt;br /&gt;
&lt;br /&gt;
The machine language is the set of instructions the computer will be able to execute. What these instructions are will define the design of the remaining components. For example, the Arithmetic Logic Unit needs to be able to perform the various operations listed in these instructions.&lt;br /&gt;
&lt;br /&gt;
Ideally this language should be complete, that is, any function can be simulated as a combination of these instructions. I also want to be as simple as possible, to minimize the complexity of the ALU. It is worth restating that I am basing the overall design for the computer on a design for a VSC off the Internet.&lt;br /&gt;
&lt;br /&gt;
Since the opcode for this computer is 3-bits long, there can only be 8 instructions.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=1 style=&amp;quot;text-align:center&amp;quot; cellpadding=&amp;quot;2&amp;quot; cellspacing=&amp;quot;0&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Opcode&lt;br /&gt;
!Function&lt;br /&gt;
!Operand&lt;br /&gt;
|-&lt;br /&gt;
| 000&lt;br /&gt;
| Load Accumulator from memory (indirectly)&lt;br /&gt;
| Memory Address&lt;br /&gt;
|-&lt;br /&gt;
| 001&lt;br /&gt;
| Store Accumulator to memory&lt;br /&gt;
| Memory Address&lt;br /&gt;
|-&lt;br /&gt;
| 010&lt;br /&gt;
| Add&lt;br /&gt;
| Memory Address&lt;br /&gt;
|-&lt;br /&gt;
| 011&lt;br /&gt;
| Subtract&lt;br /&gt;
| Memory Address&lt;br /&gt;
|-&lt;br /&gt;
| 100&lt;br /&gt;
| Jump to address if accumulator is not negative&lt;br /&gt;
| Memory Address&lt;br /&gt;
|-&lt;br /&gt;
| 101&lt;br /&gt;
| Binary shift left (*2) (input 0 as LSB)&lt;br /&gt;
| Memory Address&lt;br /&gt;
|-&lt;br /&gt;
| 110&lt;br /&gt;
| Binary shift right (/2) (retain MSB)&lt;br /&gt;
| Memory Address&lt;br /&gt;
|-&lt;br /&gt;
| 111&lt;br /&gt;
| Halt&lt;br /&gt;
| None&lt;br /&gt;
|}&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design for the Arithmetic Logic Unit (ALU)==&lt;br /&gt;
&lt;br /&gt;
Now I know that the ALU needs to be able to perform 4 functions: Add, subtract, shift left and shift right. The unit needs to do one of these functions based on one of 4 input signals it may receive.&lt;br /&gt;
&lt;br /&gt;
The ALU will receive 2 8-bit inputs and produce 1 8-bit output. It will require 3 systems, the adder-subtractor, bitshift left and bitshift right. These systems would be integrated to form the ALU.&lt;br /&gt;
&lt;br /&gt;
===Design for a half adder===&lt;br /&gt;
&lt;br /&gt;
While there are existing dwarven adder designs out there, they do not come with schematics detailing the links between their components. Therefore I feel the need to design from scratch.&lt;br /&gt;
&lt;br /&gt;
A simple half adder would take 2 inputs, and produce an output and an overflow output called a carry.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=1 style=&amp;quot;text-align:center&amp;quot; cellpadding=&amp;quot;2&amp;quot; cellspacing=&amp;quot;0&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|A&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|B&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|C&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|O&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
|}&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &lt;br /&gt;
 Carry out circuit  C==ABP&lt;br /&gt;
&lt;br /&gt;
                       aBP&lt;br /&gt;
 Output circuit     O==o&lt;br /&gt;
                       bAP&lt;br /&gt;
&lt;br /&gt;
                  C===A&lt;br /&gt;
 Combined circuit    aBP&lt;br /&gt;
                  O==obA&lt;br /&gt;
&lt;br /&gt;
This schematic shows a dwarven half adder that obeys the above truth table. In this diagram, the o represents a normal gear assembly and = represents axles. This design rests on the assumption that axles do not receive power except from their end tiles. It also takes advantage of the assumption that a matched pair of gears will not transmit information across their connection (here it is the B and b gear)&lt;br /&gt;
&lt;br /&gt;
I believe this design uses the minimum number of gear assemblies, although I am not sure.&lt;br /&gt;
&lt;br /&gt;
===Design for a full adder===&lt;br /&gt;
&lt;br /&gt;
In order for an adder to work properly, it must also receive the carry bit in addition to the 2 inputs. Ultimately, even the first adder in the final adder-subtracter must be able to receive a carry bit to operate successfully, which is why I didn't draw up a full plan for the half adder.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=1 style=&amp;quot;text-align:center&amp;quot; cellpadding=&amp;quot;2&amp;quot; cellspacing=&amp;quot;0&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|A&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|B&lt;br /&gt;
!C (carry in)&lt;br /&gt;
!O2 (carry out)&lt;br /&gt;
!width=&amp;quot;40&amp;quot;|O1&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
|}&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 PB&lt;br /&gt;
 CAo==O2       Carry Out Circuit&lt;br /&gt;
 oBo&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 o=o=o=o==O1   Output Circuit&lt;br /&gt;
 C c c C&lt;br /&gt;
 B b B b&lt;br /&gt;
 A A a a&lt;br /&gt;
 P P P P&lt;br /&gt;
&lt;br /&gt;
     O1 O2     Combined Circuit&lt;br /&gt;
  oo=oo |&lt;br /&gt;
  Cc cC oo&lt;br /&gt;
  Bb BbBAB&lt;br /&gt;
 PAo oaPCo&lt;br /&gt;
&lt;br /&gt;
Now that looks pretty monstrous. Undoubtedly the arrangement of gears could be changed here and there depending on the exact dimensions you need the array to be, but hopefully this diagram illustrates methods that can be used to minimize the complexity of the device. Note that where there are adjacent identical gears directly connected to the power source, one of them can be replaced by an ordinary gear, which will remove a linking task for that gear.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   `````   oCBAP&lt;br /&gt;
   ````    ocbo&lt;br /&gt;
 #####   ``|``&lt;br /&gt;
 #.#.#`  ``ocBo&lt;br /&gt;
 #^#^#`  `ooCba     Hypothetical implementation&lt;br /&gt;
 #%#%#`  `o``BP&lt;br /&gt;
 `%`%``  ```oAC&lt;br /&gt;
 `~`~``  ```oBo&lt;br /&gt;
 `````   `````&lt;br /&gt;
  lvlz     lvlz+1&lt;br /&gt;
&lt;br /&gt;
The above diagram details a hypothetical implementation for a full adder. The ```s represent the shadow of the mechanisms above and below the level. The left power sensor produces the output signal while the right power sensor produces the carry signal to be relayed to the next adder. The total footprint of the unit is 6x9. In an array, the units can overlap one tile so the total footprint of an 8-bit adder would be 41x9. Maximum operational power draw is 131x8(1048) units of power.&lt;br /&gt;
&lt;br /&gt;
===Design for an 8-bit ripple carry adder-subtracter===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to build a full 8-bit adder-subtracter, all you need to do is to stack up 8 full adders next to each other and ensure that all the gears have been linked to the appropriate plates.&lt;br /&gt;
&lt;br /&gt;
Now to get the adder-subtracter to subtract, all you have to do is to link up every single A and a (or B and b) gear assembly to the pressure plate sending the subtract signal. When the signal is sent, all the gears linked to a register will toggle. This will have the effect of inverting whatever input the register is sending. Finally the signal also needs to activate the carry in gears in the first adder, which will have the effect of adding 1 to the resulting sum (difference), giving the correct answer in two's complement representation.&lt;br /&gt;
&lt;br /&gt;
===Design for a carry-look-ahead adder===&lt;br /&gt;
&lt;br /&gt;
I did some research into carry-look-ahead adders to see if it was worth implementing. Carry-look-ahead adders are faster than ripple-carry adders as ripple carry adders have to wait for the carry bit to 'ripple' through the chain of adders before getting the correct result. This is most significant for users of fluid logic, as fluid logic adders need to wait n*100 steps (n being the number of bits) for the carry to ripple all the way to the end. (Floodgates and bridges have a 100 step delay before activating or deactivating)&lt;br /&gt;
&lt;br /&gt;
I found that I could easily design a carry-look-ahead adder using mechanical logic that calculates the carry in bit for all bits in a single step. I would also like to point out that real carry-look-ahead adders are more complicated because they don't have teleporting switch signals. &lt;br /&gt;
&lt;br /&gt;
Firstly, looking at the carry-out circuit for the full adder, I see that not only can it exist independently from the sum circuit, the C gear is directly attached to the power source. I can take advantage of this by separating the carry bit calculation circuits from the adder and attaching them to each other like so. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then for the summing part of the adder, I simply build only the output circuit, which I can now simplify like this&lt;br /&gt;
&lt;br /&gt;
     O1     Output Circuit&lt;br /&gt;
  oo=oo&lt;br /&gt;
  Cc cC&lt;br /&gt;
  Bb Bb&lt;br /&gt;
  oAPao&lt;br /&gt;
&lt;br /&gt;
Or I can make it long instead of square so that it will tile better with the output buffers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    O1&lt;br /&gt;
    |&lt;br /&gt;
 oBCoCbo&lt;br /&gt;
 AbcocBa&lt;br /&gt;
 P     P&lt;br /&gt;
&lt;br /&gt;
I could construct these directly above the output buffers and they would all tile a lot better. Not only that, it fits almost perfectly within the footprint of a bank of output buffers. There is also no cost of increased complexity, only spatial separation between the summation unit and the carry unit, plus providing all the advantages of the carry-look-ahead system.&lt;br /&gt;
&lt;br /&gt;
Since this system is superior in all ways to the ripple-carry system, this will be the one going into the final dwarven computer.&lt;br /&gt;
&lt;br /&gt;
===Design for bitshifting operations===&lt;br /&gt;
&lt;br /&gt;
Setting up a bitshifting operation is relatively simple. I simply wire the inputs directly into slightly different outputs as illustrated in the following diagrams (source: Wikipedia http://en.wikipedia.org/wiki/Bitwise_operation#Arithmetic_shift).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ideally all these operations would be linked into the same bank of output buffers in the assembled ALU, which will be the subject of the next section.&lt;br /&gt;
&lt;br /&gt;
===Design for ALU architecture===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This diagram illustrates the various signals moving around the ALU. I decided that I ought to dragoon the ALU into incrementing the program counter as well, but I'm not sure whether that will work or not. We'll see in the later sections.&lt;br /&gt;
&lt;br /&gt;
I defined the inputs from AR1 to be A since there are fewer A and a gears in the current designs and they all have to be toggled by the subtract signal. The operations listed on the right are signals generated by the control unit and they tell the ALU which operation to perform and transfer to the output buffer banks. The component critical to this function is the multiplexer. &lt;br /&gt;
&lt;br /&gt;
The concept of the multiplexer is quite simple, suppose I had 2 inputs I and J, and I wanted to choose which one to pass based on signals Q and R, I would have to build something like this&lt;br /&gt;
&lt;br /&gt;
 PQIoJRP&lt;br /&gt;
    |&lt;br /&gt;
    O&lt;br /&gt;
&lt;br /&gt;
Adding a multiplexer onto the output circuit would require an additional z-level if the tiling efficiency is to be maintained. &lt;br /&gt;
&lt;br /&gt;
This diagram illustrates a hypothetical implementation of the multiplexer, as well as the bitshifting logic. I don't think I need a support axle on z+2 as it should be supported by O1.&lt;br /&gt;
&lt;br /&gt;
==Design of the bus==&lt;br /&gt;
&lt;br /&gt;
I've decided to ditch the plan for a bus, which would have been the conduit for data transfers between registers throughout the computer. Initially there were 2 methods, one had a output buffer attached to the end of the bus while the other the bus directly supplied power to the inputs of the appropriate registers. &lt;br /&gt;
&lt;br /&gt;
Method 2 would not work on memory cells that used an active pump for bit-clearing. Method 1 would have worked but the output buffers had to be overwritten every step and that could cause cascading delays throughout the computer. Since this computer is relatively simple, I opted for hard wiring everything instead.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This diagram illustrates the data transfers that occur throughout the computer. The red arrows depict confirmed hard-wired connections, while the blue arrows would have been routed through a bus. I've decide AR1 is superfluous so I got rid of it. As you can see, each register has at most 2 inputs or 2 outputs going through the bus, so hardwiring is feasible.&lt;br /&gt;
&lt;br /&gt;
==Design of the timing circuit==&lt;br /&gt;
&lt;br /&gt;
Before the computer can execute its instructions, it needs to perform some operations first.&lt;br /&gt;
&lt;br /&gt;
#Transfer the contents of the accumulator to AR2. Dump instruction register and memory address register.&amp;lt;br&amp;gt;&lt;br /&gt;
#Transfer the program counter to the memory address register. Also, activate the program counter incrementation system in the ALU and transfer the results into program counter +1.&amp;lt;br&amp;gt;&lt;br /&gt;
#Load the data from memory at the specified address into the instruction register.&amp;lt;br&amp;gt;&lt;br /&gt;
#Transfer the data from program counter +1 to the program counter. Also, dump the memory address register&amp;lt;br&amp;gt;&lt;br /&gt;
#Load the last 5 digits of the instruction register into the memory address register. Also, dump program counter +1.&amp;lt;br&amp;gt;&lt;br /&gt;
#Execution (write accumulator, memory or program counter, read instruction register, memory, AR2)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There needs to be a 100 step delay from the time a memory cell is written (or dumped, if it is pre-dumped) and when it is read, or it may cause cascading delays. The writing process is practically instantaneous, but 100 steps are needed before the correct result can be read if the memory was not cleared to begin with. Of course this point is entirely moot if the computer is running automatically, in which case every step will last at least 100 steps anyway and the prime consideration is to ensure that every step can be performed in 100 steps.&lt;br /&gt;
&lt;br /&gt;
==Design of the oscillator==&lt;br /&gt;
&lt;br /&gt;
A typical mechanical oscillator is unsatisfactory because it will usually be sending out 2 on signals at once, one from the pressure plate the water is on and the other from the pressure plate waiting to reset.&lt;br /&gt;
&lt;br /&gt;
 0%%6%%0%%5%%0%%4&lt;br /&gt;
 %              %&lt;br /&gt;
 %              %&lt;br /&gt;
 1%%0%%2%%0%%3%%0&lt;br /&gt;
&lt;br /&gt;
This diagram shows a 12 step 6 signal oscillator. At the locations marked 0, there are no pressure plates. A lever operates the mechanism. When the lever is in the ON position, the #%%0 pumps activate, and when the lever is in the OFF position, the 0%%# pumps activate. The oscillator can also be fully automated by using the pressure plates themselves to replace the lever function. The oscillator's power supply also needs to be cut if a halt signal is received from the control unit. &lt;br /&gt;
&lt;br /&gt;
===Oscillator Link table===&lt;br /&gt;
&lt;br /&gt;
#Read accumulator, write AR2, write IR, write MAR&amp;lt;br&amp;gt;&lt;br /&gt;
#Read PC, write MAR, activate ALU (adder select, C0=1), write PC+1&amp;lt;br&amp;gt;&lt;br /&gt;
#Read MEM, read MAR. activate decoder, write IR&amp;lt;br&amp;gt;&lt;br /&gt;
#Read PC+1, write PC, write MAR&amp;lt;br&amp;gt;&lt;br /&gt;
#Read IR, write MAR, write PC+1&amp;lt;br&amp;gt;&lt;br /&gt;
#Execution (read IR, turn on control unit)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A dump operation can be performed by telling the memory register to write when its linked inputs are inactive, effectively writing 0s. &lt;br /&gt;
&lt;br /&gt;
==Design of the control unit==&lt;br /&gt;
&lt;br /&gt;
The control unit can be implemented simply as a 3-8 decoder with appropriately linked pressure plates. The execute signal controlled gear assembly is located at the root of the decoder. &lt;br /&gt;
&lt;br /&gt;
===Control unit link table===&lt;br /&gt;
&lt;br /&gt;
:O0. Read memory, read MAR, activate decoder, write accumulator, select transfer&amp;lt;br&amp;gt;&lt;br /&gt;
:O1. Read accumulator, write memory, read MAR, activate decoder&amp;lt;br&amp;gt;&lt;br /&gt;
:O2. Read memory, read MAR, activate decoder, read AR2, Send Add signal to ALU (adder select), write accumulator&amp;lt;br&amp;gt;&lt;br /&gt;
:O3. Read memory, read MAR, activate decoder, read AR2, Send Subtract signal to ALU (adder select, C0=1, invert input A), write accumulator&amp;lt;br&amp;gt;&lt;br /&gt;
:O4. Read IR, write PC if ACC7=0&amp;lt;br&amp;gt;&lt;br /&gt;
:O5. Read memory, read MAR, activate decoder, Send Shift left signal to ALU (SHL select), write accumulator&amp;lt;br&amp;gt;&lt;br /&gt;
:O6. Read memory, read MAR, activate decoder, Send Shift right signal to ALU (SHR select), write accumulator&amp;lt;br&amp;gt;&lt;br /&gt;
:O7. Cut power to oscillator.&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jong</name></author>
	</entry>
	<entry>
		<id>https://dwarffortresswiki.org/index.php?title=User:Jong&amp;diff=101083</id>
		<title>User:Jong</title>
		<link rel="alternate" type="text/html" href="https://dwarffortresswiki.org/index.php?title=User:Jong&amp;diff=101083"/>
		<updated>2010-04-30T07:05:37Z</updated>

		<summary type="html">&lt;p&gt;Jong: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Adapted from http://docs.google.com/Doc?docid=0AdISzBuNg6ZWZGd0d2t4YjlfMjJ0ejlzc2dnaA&amp;amp;hl=en&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Toggled gear assemblies are designed as though they are off in when untriggered. However they are constructed in the on position. This means that you need to build and link a lever to toggle it to the off state.&lt;br /&gt;
&lt;br /&gt;
==Designs for power sensor (output device)==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  # %&amp;gt;^ #     &lt;br /&gt;
 ~ ~ ~ ~#      Power sensor side view&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to do useful things, such as toggling gears assemblies, opening doors, etc., mechanical power signals need to be converted to a trigger signal. There are only 2 trigger signal generators in dwarf fortress. One is the lever, which cannot be linked to machine power. The other is a pressure plate, which can.&lt;br /&gt;
&lt;br /&gt;
The basic operation of this component is simple. Power operates the pump, pushing water over the pressure plate, generating a signal. When the pump is not powered, the water drains, switching the pressure plate off after at least 100 steps.&lt;br /&gt;
&lt;br /&gt;
The smooth operation of this unit depends on several factors:&lt;br /&gt;
1. Adequate supply of water in the input tile so that the pump can maintain 7/7 or 6/7 water levels on the pressure plate. Can be done by providing more water tiles adjacent to the input tile.&lt;br /&gt;
2. Fast drainage to minimize the time needed for the plate to switch off. Just make sure that the level below the pumps is not completely full.&lt;br /&gt;
3. Since the minimum recovery time of the pressure plate is 100 steps, it can take a good long time for a 0-bit to reach the end of a chain of output units.&lt;br /&gt;
&lt;br /&gt;
==Design for a memory cell for use in registers/memory unit==&lt;br /&gt;
&lt;br /&gt;
 ###&lt;br /&gt;
 #H#&lt;br /&gt;
 #^#PRoO&lt;br /&gt;
 #%#&lt;br /&gt;
 #%WIP&lt;br /&gt;
 #~#&lt;br /&gt;
 ###&lt;br /&gt;
&lt;br /&gt;
This design is based on plans found at User:SL/Logic_Gates on the wiki. For this design, the write-in signal is linked to gear W and hatch H, while the read-out signal is linked to gear R. Gear o is linked to the pressure plate ^ and represents the state of the cell. Big O represents to output signal and I represents the input signal. P represents a power source. The hatch prevents the water from draining thus preserving the data.&lt;br /&gt;
&lt;br /&gt;
In order to act as a memory cell, this unit must do 3 things:&lt;br /&gt;
1. Output its state when told to read-out&lt;br /&gt;
2. Change state to match an input when told to write-in&lt;br /&gt;
3. Maintain its state when not told to do anything&lt;br /&gt;
&lt;br /&gt;
Let's check this by examining the operation of this unit. &lt;br /&gt;
&lt;br /&gt;
R	W	I	State	O&lt;br /&gt;
0	0	Ignored	Unchanged	0&lt;br /&gt;
1	0	Ignored	0	0&lt;br /&gt;
1	0	Ignored	1	1&lt;br /&gt;
0	1	1	1	0&lt;br /&gt;
0	1	0	0	0&lt;br /&gt;
1	1	1	1	1&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! R&lt;br /&gt;
! W&lt;br /&gt;
! I&lt;br /&gt;
! State&lt;br /&gt;
! O&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| Ignored&lt;br /&gt;
| Unchanged&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| Ignored&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| Ignored&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
When both read and write are turned on, the device will act as a power sensor for the input. This could be a problem if the input and output are linked.&lt;br /&gt;
&lt;br /&gt;
One point of concern is that the unit may not contain sufficient water to trigger the plate because the amount of water in the square above the hatch may not be 7 when it closes. &lt;br /&gt;
&lt;br /&gt;
The plate could be set to trigger at a lower threshold, which would slightly slow down response time, or a door could be used instead of a hatch and the unit extended by one tile to provide space for the drain. This would have the downside of destroying some water after every write operation.&lt;br /&gt;
&lt;br /&gt;
Another method is to use another pump to drain the water from the holding tile. This pump will only activate when W is 1 and I is 0. &lt;br /&gt;
&lt;br /&gt;
Design for the computer registers&lt;br /&gt;
&lt;br /&gt;
The dwarven computer prototype is going to have an 8-bit instruction length, a 3-bit operon and a 5-bit address space. Why? The best reason for this is that other designs of Very Simple Computers (VSC) on the Internet are also only 8-bit and I am basing the design of the prototype dwarven computer off several of them. Naturally a bigger computer is better in many ways but the current goal is to produce an operational one. Now its not clear to me why a VSC shouldn't be smaller, but I suppose it doesn't matter.&lt;br /&gt;
&lt;br /&gt;
8-bit words need 8-bit registers. Fortunately this just means stacking 8 memory units up and making sure they receive the same read/write signals.&lt;br /&gt;
&lt;br /&gt;
The lines in the diagram don't actually represent physical connections but imaginary ones. After all, the write signal must be sent remotely.&lt;br /&gt;
&lt;br /&gt;
Now we consider the most compact designs for such an array. Let us assume that the output signals will be sent remotely. For clarity, the arrays ought to be rectangular.&lt;br /&gt;
&lt;br /&gt;
##### ##### ##### ##### ##### ##### ##### ##### &lt;br /&gt;
#H#.# #H#.# #H#.# #H#.# #H#.# #H#.# #H#.# #H#.# &lt;br /&gt;
#^#^# #^#^# #^#^# #^#^# #^#^# #^#^# #^#^# #^#^# &lt;br /&gt;
#%#%# #%#%# #%#%# #%#%# #%#%# #%#%# #%#%# #%#%# &lt;br /&gt;
W%`%o W%`%o W%`%o W%`%o W%`%o W%`%o W%`%o W%`%o &lt;br /&gt;
I~`~RPI~`~RPI~`~RPI~`~RPI~`~RPI~`~RPI~`~RPI~`~R&lt;br /&gt;
P`````````````````````````````````````````````P&lt;br /&gt;
Note that the O is omitted since it was a placeholder for the output device.&lt;br /&gt;
&lt;br /&gt;
Not all registers in the computer are 8 bit registers. For example the memory address register is 5 bits.&lt;br /&gt;
&lt;br /&gt;
Design for the Memory Unit&lt;br /&gt;
&lt;br /&gt;
Since there are only 5 bits of address space, I only need 256 memory cells. It should be fine if I don't use complicated column and row addressing schemes. I shall simply have 32 8-bit registers sticking somewhere. In order for the memory unit to work, I need a decoder to change the 5-bit address into 32 outputs. This will enable the memory unit to read and write from any register. I guess this makes it random access memory.&lt;br /&gt;
&lt;br /&gt;
Design for a decoder&lt;br /&gt;
&lt;br /&gt;
This type of decode is called an n to 2^n decoder, since it converts n inputs into 2^n outputs, in this case 5 to 32(2^5).&lt;br /&gt;
&lt;br /&gt;
To illustrate the design for this unit, let us consider a simpler example where n=2. There will be 2  binary inputs which will be converted into 4 unique outputs, 1 for each memory address.&lt;br /&gt;
&lt;br /&gt;
Here is the truth table for the operation:&lt;br /&gt;
&lt;br /&gt;
2^0 (1)	2^1 (2)	O0	O1	O2	O3&lt;br /&gt;
0	0	1	0	0	0&lt;br /&gt;
1	0	0	1	0	0&lt;br /&gt;
0	1	0	0	1	0&lt;br /&gt;
1	1	0	0	0	1&lt;br /&gt;
&lt;br /&gt;
Now let us examine the implementation into the dwarfputer. Remember that gear assemblies are toggleable. I can implement a NOT operation by simply reversing the default state of a triggered gear (which is OFF in this system).&lt;br /&gt;
&lt;br /&gt;
Let us represent the 2^0 gear as A when it is default OFF and as a when it is default ON, and represent the 2^1 gear as B and b. O0 to O3 represent output devices.&lt;br /&gt;
&lt;br /&gt;
P  P  P  P&lt;br /&gt;
a  A  a  A&lt;br /&gt;
b  b  B  B&lt;br /&gt;
O0 O1 O2 O3&lt;br /&gt;
&lt;br /&gt;
This is the easiest to understand implementation. Looking at O0, we see that O0 is powered only when a and b are active. This corresponds to the state when 2^0 and 2^1 are both 0. Examining all the devices reveals that this arrangement obeys the truth table detailed above. Further examination would reveal that this arrangement also follows a pattern. Basically, the full set of columns represent every single possible combination of a, A, b, and B. Therefore we can easily see how to expand this system to n=5.&lt;br /&gt;
&lt;br /&gt;
However, this implementation is not the most efficient one. I can also arrange the gears like so:&lt;br /&gt;
&lt;br /&gt;
O3A AO1&lt;br /&gt;
  BPb&lt;br /&gt;
O2a aO0&lt;br /&gt;
&lt;br /&gt;
This arrangement uses 7 gears while the first arrangement uses 12 gears (including power gears). I put B and b closest to the power supply to obtain an orderly arrangement of O0 to O3 although this isn't strictly necessary.&lt;br /&gt;
&lt;br /&gt;
Schematically this arrangement looks like this:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Which is just some sort of tree diagram. I can easily expand this to n=5 which is what I want.&lt;br /&gt;
&lt;br /&gt;
I drew this diagram in rectangular form so that I can better see how to construct the decoder. The outputs of the decoder will be in a 4x8 grid. Since the output units are longer in one direction than the other, I will align their long axis along the short axis of the diagram. It is probably best to place all the mechanisms for the decoder in the level above the outputs.&lt;br /&gt;
&lt;br /&gt;
Design for Memory Unit Registers&lt;br /&gt;
&lt;br /&gt;
The registers in the memory unit need some modification to work correctly. Only the register indicated in the memory address register ought to respond to read write signals. Therefore each of the 32 registers needs to be connected to one of the outputs from the decoder.&lt;br /&gt;
&lt;br /&gt;
In this example, the register only responds when 00000 is in the memory address register.&lt;br /&gt;
&lt;br /&gt;
##### ##### ##### ##### ##### ##### ##### ##### &lt;br /&gt;
#H#.# #H#.# #H#.# #H#.# #H#.# #H#.# #H#.# #H#.# &lt;br /&gt;
#^#^# #^#^# #^#^# #^#^# #^#^# #^#^# #^#^# #^#^# &lt;br /&gt;
#%#%# #%#%# #%#%# #%#%# #%#%# #%#%# #%#%# #%#%# &lt;br /&gt;
W%`%o W%`%o W%`%o W%`%o W%`%o W%`%o W%`%o W%`%o &lt;br /&gt;
I~`~RCI~`~RCI~`~RCI~`~RCI~`~RCI~`~RCI~`~RCI~`~R&lt;br /&gt;
CP```P`````P`````P`````P`````P`````P`````P```PC&lt;br /&gt;
&lt;br /&gt;
C in this diagram represents the output O0. I believe this is called the chip select signal in real computers.&lt;br /&gt;
&lt;br /&gt;
It may be possible to wire the decoder directly to the power supply of the memory, which would remove the need for an output device. &lt;br /&gt;
&lt;br /&gt;
Memory Unit Architecture&lt;br /&gt;
&lt;br /&gt;
Right, I based the design of the memory unit off a java applet simulator I found on the Internet. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
What this diagram is supposed to illustrate is that ALL the memory cells are linked to respond to the same read-out signal and the same write-in signal. Similarly, all the corresponding cells respond to same input, and all output to the same place. However, they will do none of these things unless they get a signal from the decoder, and only one register will get the signal as indicated in the memory address register. &lt;br /&gt;
&lt;br /&gt;
Now the input and output buffers shown here may not be in the final blueprints, depending on the design of the rest of the computer.&lt;br /&gt;
&lt;br /&gt;
Designing the machine language &lt;br /&gt;
&lt;br /&gt;
The machine language is the set of instructions the computer will be able to execute. What these instructions are will define the design of the remaining components. For example, the Arithmetic Logic Unit needs to be able to perform the various operations listed in these instructions.&lt;br /&gt;
&lt;br /&gt;
Ideally this language should be complete, that is, any function can be simulated as a combination of these instructions. I also want to be as simple as possible, to minimize the complexity of the ALU. It is worth restating that I am basing the overall design for the computer on a design for a VSC off the Internet.&lt;br /&gt;
&lt;br /&gt;
Since the opcode for this computer is 3-bits long, there can only be 8 instructions.&lt;br /&gt;
&lt;br /&gt;
Opcode	Function	Operand&lt;br /&gt;
000	Load Accumulator from memory (indirectly)	Memory Address&lt;br /&gt;
001	Store Accumulator to memory	Memory Address&lt;br /&gt;
010	Add	Memory Address&lt;br /&gt;
011	Subtract	Memory Address&lt;br /&gt;
100	Jump to address if accumulator is not negative	Memory Address&lt;br /&gt;
101	Binary shift left (*2) (input 0 as LSB)	Memory Address&lt;br /&gt;
110	Binary shift right (/2) (retain MSB)	Memory Address&lt;br /&gt;
111	Halt	Irrelevant&lt;br /&gt;
&lt;br /&gt;
Design for the Arithmetic Logic Unit (ALU)&lt;br /&gt;
&lt;br /&gt;
Now I know that the ALU needs to be able to perform 4 functions: Add, subtract, shift left and shift right. The unit needs to do one of these functions based on one of 4 input signals it may receive.&lt;br /&gt;
&lt;br /&gt;
The ALU will receive 2 8-bit inputs and produce 1 8-bit output. It will require 3 systems, the adder-subtractor, bitshift left and bitshift right. These systems would be integrated to form the ALU.&lt;br /&gt;
&lt;br /&gt;
Design for a half adder&lt;br /&gt;
&lt;br /&gt;
While there are existing dwarven adder designs out there, they do not come with schematics detailing the links between their components. Therefore I feel the need to design from scratch.&lt;br /&gt;
&lt;br /&gt;
A simple half adder would take 2 inputs, and produce an output and an overflow output called a carry.&lt;br /&gt;
&lt;br /&gt;
A	B	C	O&lt;br /&gt;
0	0	0	0&lt;br /&gt;
1	0	0	1&lt;br /&gt;
0	1	0	1&lt;br /&gt;
1	1	1	0&lt;br /&gt;
&lt;br /&gt;
  &lt;br /&gt;
Carry out circuit  C==ABP&lt;br /&gt;
&lt;br /&gt;
                      aBP&lt;br /&gt;
Output circuit     O==o&lt;br /&gt;
                      bAP&lt;br /&gt;
&lt;br /&gt;
C===A&lt;br /&gt;
   aBP&lt;br /&gt;
O==obA&lt;br /&gt;
Combined circuit&lt;br /&gt;
&lt;br /&gt;
This schematic shows a dwarven half adder that obeys the above truth table. In this diagram, the o represents a normal gear assembly and = represents axles. This design rests on the assumption that axles do not receive power except from their end tiles. It also takes advantage of the assumption that a matched pair of gears will not transmit information across their connection (here it is the B and b gear)&lt;br /&gt;
&lt;br /&gt;
I believe this design uses the minimum number of gear assemblies, although I am not sure.&lt;br /&gt;
&lt;br /&gt;
Design for a full adder&lt;br /&gt;
&lt;br /&gt;
In order for an adder to work properly, it must also receive the carry bit in addition to the 2 inputs. Ultimately, even the first adder in the final adder-subtracter must be able to receive a carry bit to operate successfully, which is why I didn't draw up a full plan for the half adder.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A	B	C (carry in)	O2 (carry out)	O1&lt;br /&gt;
0	0	0	0	0&lt;br /&gt;
1	0	0	0	1&lt;br /&gt;
0	1	0	0	1&lt;br /&gt;
1	1	0	1	0&lt;br /&gt;
0	0	1	0	1&lt;br /&gt;
1	0	1	1	0&lt;br /&gt;
0	1	1	1	0&lt;br /&gt;
1	1	1	1	1&lt;br /&gt;
&lt;br /&gt;
PB&lt;br /&gt;
CAo==O2       Carry Out Circuit&lt;br /&gt;
oBo&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
o=o=o=o==O1   Output Circuit&lt;br /&gt;
C c c C&lt;br /&gt;
B b B b&lt;br /&gt;
A A a a&lt;br /&gt;
P P P P&lt;br /&gt;
&lt;br /&gt;
    O1 O2     Combined Circuit&lt;br /&gt;
 oo=oo |&lt;br /&gt;
 Cc cC oo&lt;br /&gt;
 Bb BbBAB&lt;br /&gt;
PAo oaPCo&lt;br /&gt;
&lt;br /&gt;
Now that looks pretty monstrous. Undoubtedly the arrangement of gears could be changed here and there depending on the exact dimensions you need the array to be, but hopefully this diagram illustrates methods that can be used to minimize the complexity of the device. Note that where there are adjacent identical gears directly connected to the power source, one of them can be replaced by an ordinary gear, which will remove a linking task for that gear.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  `````   oCBAP&lt;br /&gt;
  ````    ocbo&lt;br /&gt;
#####   ``|``&lt;br /&gt;
#.#.#`  ``ocBo&lt;br /&gt;
#^#^#`  `ooCba     Hypothetical implementation&lt;br /&gt;
#%#%#`  `o``BP&lt;br /&gt;
`%`%``  ```oAC&lt;br /&gt;
`~`~``  ```oBo&lt;br /&gt;
`````   `````&lt;br /&gt;
 lvlz     lvlz+1&lt;br /&gt;
&lt;br /&gt;
The above diagram details a hypothetical implementation for a full adder. The ```s represent the shadow of the mechanisms above and below the level. The left power sensor produces the output signal while the right power sensor produces the carry signal to be relayed to the next adder. The total footprint of the unit is 6x9. In an array, the units can overlap one tile so the total footprint of an 8-bit adder would be 41x9. Maximum operational power draw is 131x8(1048) units of power.&lt;br /&gt;
&lt;br /&gt;
Design for an 8-bit ripple carry adder-subtracter&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to build a full 8-bit adder-subtracter, all you need to do is to stack up 8 full adders next to each other and ensure that all the gears have been linked to the appropriate plates.&lt;br /&gt;
&lt;br /&gt;
 Now to get the adder-subtracter to subtract, all you have to do is to link up every single A and a (or B and b) gear assembly to the pressure plate sending the subtract signal. When the signal is sent, all the gears linked to a register will toggle. This will have the effect of inverting whatever input the register is sending. Finally the signal also needs to activate the carry in gears in the first adder, which will have the effect of adding 1 to the resulting sum (difference), giving the correct answer in two's complement representation.&lt;br /&gt;
&lt;br /&gt;
Design for a carry-look-ahead adder&lt;br /&gt;
&lt;br /&gt;
I did some research into carry-look-ahead adders to see if it was worth implementing. Carry-look-ahead adders are faster than ripple-carry adders as ripple carry adders have to wait for the carry bit to 'ripple' through the chain of adders before getting the correct result. This is most significant for users of fluid logic, as fluid logic adders need to wait n*100 steps (n being the number of bits) for the carry to ripple all the way to the end. (Floodgates and bridges have a 100 step delay before activating or deactivating)&lt;br /&gt;
&lt;br /&gt;
I found that I could easily design a carry-look-ahead adder using mechanical logic that calculates the carry in bit for all bits in a single step. I would also like to point out that real carry-look-ahead adders are more complicated because they don't have teleporting switch signals. &lt;br /&gt;
&lt;br /&gt;
Firstly, looking at the carry-out circuit for the full adder, I see that not only can it exist independently from the sum circuit, the C gear is directly attached to the power source. I can take advantage of this by separating the carry bit calculation circuits from the adder and attaching them to each other like so. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then for the summing part of the adder, I simply build only the output circuit, which I can now simplify like this&lt;br /&gt;
&lt;br /&gt;
    O1     Output Circuit&lt;br /&gt;
 oo=oo&lt;br /&gt;
 Cc cC&lt;br /&gt;
 Bb Bb&lt;br /&gt;
 oAPao&lt;br /&gt;
&lt;br /&gt;
Or I can make it long instead of square so that it will tile better with the output buffers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   O1&lt;br /&gt;
   |&lt;br /&gt;
oBCoCbo&lt;br /&gt;
AbcocBa&lt;br /&gt;
P     P&lt;br /&gt;
&lt;br /&gt;
I could construct these directly above the output buffers and they would all tile a lot better. Not only that, it fits almost perfectly within the footprint of a bank of output buffers. There is also no cost of increased complexity, only spatial separation between the summation unit and the carry unit, plus providing all the advantages of the carry-look-ahead system.&lt;br /&gt;
&lt;br /&gt;
Since this system is superior in all ways to the ripple-carry system, this will be the one going into the final dwarven computer.&lt;br /&gt;
&lt;br /&gt;
Design for bitshifting operations&lt;br /&gt;
&lt;br /&gt;
Setting up a bitshifting operation is relatively simple. I simply wire the inputs directly into slightly different outputs as illustrated in the following diagrams (source: Wikipedia http://en.wikipedia.org/wiki/Bitwise_operation#Arithmetic_shift).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ideally all these operations would be linked into the same bank of output buffers in the assembled ALU, which will be the subject of the next section.&lt;br /&gt;
&lt;br /&gt;
Design for ALU architecture&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This diagram illustrates the various signals moving around the ALU. I decided that I ought to dragoon the ALU into incrementing the program counter as well, but I'm not sure whether that will work or not. We'll see in the later sections.&lt;br /&gt;
&lt;br /&gt;
I defined the inputs from AR1 to be A since there are fewer A and a gears in the current designs and they all have to be toggled by the subtract signal. The operations listed on the right are signals generated by the control unit and they tell the ALU which operation to perform and transfer to the output buffer banks. The component critical to this function is the multiplexer. &lt;br /&gt;
&lt;br /&gt;
The concept of the multiplexer is quite simple, suppose I had 2 inputs I and J, and I wanted to choose which one to pass based on signals Q and R, I would have to build something like this&lt;br /&gt;
&lt;br /&gt;
PQIoJRP&lt;br /&gt;
   |&lt;br /&gt;
   O&lt;br /&gt;
&lt;br /&gt;
Adding a multiplexer onto the output circuit would require an additional z-level if the tiling efficiency is to be maintained. &lt;br /&gt;
&lt;br /&gt;
This diagram illustrates a hypothetical implementation of the multiplexer, as well as the bitshifting logic. I don't think I need a support axle on z+2 as it should be supported by O1.&lt;br /&gt;
&lt;br /&gt;
Design of the bus&lt;br /&gt;
&lt;br /&gt;
I've decided to ditch the plan for a bus, which would have been the conduit for data transfers between registers throughout the computer. Initially there were 2 methods, one had a output buffer attached to the end of the bus while the other the bus directly supplied power to the inputs of the appropriate registers. &lt;br /&gt;
&lt;br /&gt;
Method 2 would not work on memory cells that used an active pump for bit-clearing. Method 1 would have worked but the output buffers had to be overwritten every step and that could cause cascading delays throughout the computer. Since this computer is relatively simple, I opted for hard wiring everything instead.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This diagram illustrates the data transfers that occur throughout the computer. The red arrows depict confirmed hard-wired connections, while the blue arrows would have been routed through a bus. I've decide AR1 is superfluous so I got rid of it. As you can see, each register has at most 2 inputs or 2 outputs going through the bus, so hardwiring is feasible.&lt;br /&gt;
&lt;br /&gt;
Design of the timing circuit&lt;br /&gt;
&lt;br /&gt;
Before the computer can execute its instructions, it needs to perform some operations first.&lt;br /&gt;
&lt;br /&gt;
Transfer the contents of the accumulator to AR2. Dump instruction register and memory address register.&lt;br /&gt;
Transfer the program counter to the memory address register. Also, activate the program counter incrementation system in the ALU and transfer the results into program counter +1.&lt;br /&gt;
Load the data from memory at the specified address into the instruction register.&lt;br /&gt;
Transfer the data from program counter +1 to the program counter. Also, dump the memory address register&lt;br /&gt;
Load the last 5 digits of the instruction register into the memory address register. Also, dump program counter +1.&lt;br /&gt;
Execution (write accumulator, memory or program counter, read instruction register, memory, AR2)&lt;br /&gt;
&lt;br /&gt;
There needs to be a 100 step delay from the time a memory cell is written (or dumped, if it is pre-dumped) and when it is read, or it may cause cascading delays. The writing process is practically instantaneous, but 100 steps are needed before the correct result can be read if the memory was not cleared to begin with. Of course this point is entirely moot if the computer is running automatically, in which case every step will last at least 100 steps anyway and the prime consideration is to ensure that every step can be performed in 100 steps.&lt;br /&gt;
&lt;br /&gt;
Design of the oscillator&lt;br /&gt;
&lt;br /&gt;
A typical mechanical oscillator is unsatisfactory because it will usually be sending out 2 on signals at once, one from the pressure plate the water is on and the other from the pressure plate waiting to reset.&lt;br /&gt;
&lt;br /&gt;
0%%6%%0%%5%%0%%4&lt;br /&gt;
%              %&lt;br /&gt;
%              %&lt;br /&gt;
1%%0%%2%%0%%3%%0&lt;br /&gt;
&lt;br /&gt;
This diagram shows a 12 step 6 signal oscillator. At the locations marked 0, there are no pressure plates. A lever operates the mechanism. When the lever is in the ON position, the #%%0 pumps activate, and when the lever is in the OFF position, the 0%%# pumps activate. The oscillator can also be fully automated by using the pressure plates themselves to replace the lever function. The oscillator's power supply also needs to be cut if a halt signal is received from the control unit. &lt;br /&gt;
&lt;br /&gt;
Oscillator Link table&lt;br /&gt;
&lt;br /&gt;
Read accumulator, write AR2, write IR, write MAR&lt;br /&gt;
Read PC, write MAR, activate ALU (adder select, C0=1), write PC+1&lt;br /&gt;
Read MEM, read MAR. activate decoder, write IR&lt;br /&gt;
Read PC+1, write PC, write MAR&lt;br /&gt;
Read IR, write MAR, write PC+1&lt;br /&gt;
Execution (read IR, turn on control unit)&lt;br /&gt;
&lt;br /&gt;
A dump operation can be performed by telling the memory register to write when its linked inputs are inactive, effectively writing 0s. &lt;br /&gt;
&lt;br /&gt;
Design of the control unit&lt;br /&gt;
&lt;br /&gt;
The control unit can be implemented simply as a 3-8 decoder with appropriately linked pressure plates. The execute signal controlled gear assembly is located at the root of the decoder. &lt;br /&gt;
&lt;br /&gt;
Control unit link table&lt;br /&gt;
&lt;br /&gt;
O0. Read memory, read MAR, activate decoder, write accumulator, select transfer&lt;br /&gt;
O1. Read accumulator, write memory, read MAR, activate decoder&lt;br /&gt;
O2. Read memory, read MAR, activate decoder, read AR2, Send Add signal to ALU (adder select), write accumulator&lt;br /&gt;
O3. Read memory, read MAR, activate decoder, read AR2, Send Subtract signal to ALU (adder select, C0=1, invert input A), write accumulator&lt;br /&gt;
O4. Read IR, write PC if ACC7=0&lt;br /&gt;
O5. Read memory, read MAR, activate decoder, Send Shift left signal to ALU (SHL select), write accumulator&lt;br /&gt;
O6. Read memory, read MAR, activate decoder, Send Shift right signal to ALU (SHR select), write accumulator&lt;br /&gt;
O7. Cut power to oscillator.&lt;/div&gt;</summary>
		<author><name>Jong</name></author>
	</entry>
	<entry>
		<id>https://dwarffortresswiki.org/index.php?title=User:Jong&amp;diff=101080</id>
		<title>User:Jong</title>
		<link rel="alternate" type="text/html" href="https://dwarffortresswiki.org/index.php?title=User:Jong&amp;diff=101080"/>
		<updated>2010-04-30T06:50:18Z</updated>

		<summary type="html">&lt;p&gt;Jong: Created page with 'Notes  Toggled gear assemblies are designed as though they are off in when untriggered. However they are constructed in the on position. This means that you need to build and lin…'&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Notes&lt;br /&gt;
&lt;br /&gt;
Toggled gear assemblies are designed as though they are off in when untriggered. However they are constructed in the on position. This means that you need to build and link a lever to toggle it to the off state.&lt;br /&gt;
&lt;br /&gt;
Designs for power sensor (output device)&lt;br /&gt;
&lt;br /&gt;
 # %&amp;gt;^ #     &lt;br /&gt;
06:50, 30 April 2010 (UTC)~~#    &lt;br /&gt;
&lt;br /&gt;
Power sensor side view.&lt;br /&gt;
&lt;br /&gt;
In order to do useful things, such as toggling gears assemblies, opening doors, etc., mechanical power signals need to be converted to a trigger signal. There are only 2 trigger signal generators in dwarf fortress. One is the lever, which cannot be linked to machine power. The other is a pressure plate, which can.&lt;br /&gt;
&lt;br /&gt;
The basic operation of this component is simple. Power operates the pump, pushing water over the pressure plate, generating a signal. When the pump is not powered, the water drains, switching the pressure plate off after at least 100 steps.&lt;br /&gt;
&lt;br /&gt;
The smooth operation of this unit depends on several factors:&lt;br /&gt;
1. Adequate supply of water in the input tile so that the pump can maintain 7/7 or 6/7 water levels on the pressure plate. Can be done by providing more water tiles adjacent to the input tile.&lt;br /&gt;
2. Fast drainage to minimize the time needed for the plate to switch off. Just make sure that the level below the pumps is not completely full.&lt;br /&gt;
3. Since the minimum recovery time of the pressure plate is 100 steps, it can take a good long time for a 0-bit to reach the end of a chain of output units.&lt;br /&gt;
&lt;br /&gt;
Design for a memory cell for use in registers/memory unit&lt;br /&gt;
&lt;br /&gt;
###&lt;br /&gt;
#H#&lt;br /&gt;
#^#PRoO&lt;br /&gt;
#%#&lt;br /&gt;
#%WIP&lt;br /&gt;
#~#&lt;br /&gt;
###&lt;br /&gt;
&lt;br /&gt;
This design is based on plans found at User:SL/Logic_Gates on the wiki. For this design, the write-in signal is linked to gear W and hatch H, while the read-out signal is linked to gear R. Gear o is linked to the pressure plate ^ and represents the state of the cell. Big O represents to output signal and I represents the input signal. P represents a power source. The hatch prevents the water from draining thus preserving the data.&lt;br /&gt;
&lt;br /&gt;
In order to act as a memory cell, this unit must do 3 things:&lt;br /&gt;
1. Output its state when told to read-out&lt;br /&gt;
2. Change state to match an input when told to write-in&lt;br /&gt;
3. Maintain its state when not told to do anything&lt;br /&gt;
&lt;br /&gt;
Let's check this by examining the operation of this unit. &lt;br /&gt;
&lt;br /&gt;
R	W	I	State	O&lt;br /&gt;
0	0	Ignored	Unchanged	0&lt;br /&gt;
1	0	Ignored	0	0&lt;br /&gt;
1	0	Ignored	1	1&lt;br /&gt;
0	1	1	1	0&lt;br /&gt;
0	1	0	0	0&lt;br /&gt;
1	1	1	1	1&lt;br /&gt;
&lt;br /&gt;
When both read and write are turned on, the device will act as a power sensor for the input. This could be a problem if the input and output are linked.&lt;br /&gt;
&lt;br /&gt;
One point of concern is that the unit may not contain sufficient water to trigger the plate because the amount of water in the square above the hatch may not be 7 when it closes. &lt;br /&gt;
&lt;br /&gt;
The plate could be set to trigger at a lower threshold, which would slightly slow down response time, or a door could be used instead of a hatch and the unit extended by one tile to provide space for the drain. This would have the downside of destroying some water after every write operation.&lt;br /&gt;
&lt;br /&gt;
Another method is to use another pump to drain the water from the holding tile. This pump will only activate when W is 1 and I is 0. &lt;br /&gt;
&lt;br /&gt;
Design for the computer registers&lt;br /&gt;
&lt;br /&gt;
The dwarven computer prototype is going to have an 8-bit instruction length, a 3-bit operon and a 5-bit address space. Why? The best reason for this is that other designs of Very Simple Computers (VSC) on the Internet are also only 8-bit and I am basing the design of the prototype dwarven computer off several of them. Naturally a bigger computer is better in many ways but the current goal is to produce an operational one. Now its not clear to me why a VSC shouldn't be smaller, but I suppose it doesn't matter.&lt;br /&gt;
&lt;br /&gt;
8-bit words need 8-bit registers. Fortunately this just means stacking 8 memory units up and making sure they receive the same read/write signals.&lt;br /&gt;
&lt;br /&gt;
The lines in the diagram don't actually represent physical connections but imaginary ones. After all, the write signal must be sent remotely.&lt;br /&gt;
&lt;br /&gt;
Now we consider the most compact designs for such an array. Let us assume that the output signals will be sent remotely. For clarity, the arrays ought to be rectangular.&lt;br /&gt;
&lt;br /&gt;
##### ##### ##### ##### ##### ##### ##### ##### &lt;br /&gt;
#H#.# #H#.# #H#.# #H#.# #H#.# #H#.# #H#.# #H#.# &lt;br /&gt;
#^#^# #^#^# #^#^# #^#^# #^#^# #^#^# #^#^# #^#^# &lt;br /&gt;
#%#%# #%#%# #%#%# #%#%# #%#%# #%#%# #%#%# #%#%# &lt;br /&gt;
W%`%o W%`%o W%`%o W%`%o W%`%o W%`%o W%`%o W%`%o &lt;br /&gt;
I~`~RPI~`~RPI~`~RPI~`~RPI~`~RPI~`~RPI~`~RPI~`~R&lt;br /&gt;
P`````````````````````````````````````````````P&lt;br /&gt;
Note that the O is omitted since it was a placeholder for the output device.&lt;br /&gt;
&lt;br /&gt;
Not all registers in the computer are 8 bit registers. For example the memory address register is 5 bits.&lt;br /&gt;
&lt;br /&gt;
Design for the Memory Unit&lt;br /&gt;
&lt;br /&gt;
Since there are only 5 bits of address space, I only need 256 memory cells. It should be fine if I don't use complicated column and row addressing schemes. I shall simply have 32 8-bit registers sticking somewhere. In order for the memory unit to work, I need a decoder to change the 5-bit address into 32 outputs. This will enable the memory unit to read and write from any register. I guess this makes it random access memory.&lt;br /&gt;
&lt;br /&gt;
Design for a decoder&lt;br /&gt;
&lt;br /&gt;
This type of decode is called an n to 2^n decoder, since it converts n inputs into 2^n outputs, in this case 5 to 32(2^5).&lt;br /&gt;
&lt;br /&gt;
To illustrate the design for this unit, let us consider a simpler example where n=2. There will be 2  binary inputs which will be converted into 4 unique outputs, 1 for each memory address.&lt;br /&gt;
&lt;br /&gt;
Here is the truth table for the operation:&lt;br /&gt;
&lt;br /&gt;
2^0 (1)	2^1 (2)	O0	O1	O2	O3&lt;br /&gt;
0	0	1	0	0	0&lt;br /&gt;
1	0	0	1	0	0&lt;br /&gt;
0	1	0	0	1	0&lt;br /&gt;
1	1	0	0	0	1&lt;br /&gt;
&lt;br /&gt;
Now let us examine the implementation into the dwarfputer. Remember that gear assemblies are toggleable. I can implement a NOT operation by simply reversing the default state of a triggered gear (which is OFF in this system).&lt;br /&gt;
&lt;br /&gt;
Let us represent the 2^0 gear as A when it is default OFF and as a when it is default ON, and represent the 2^1 gear as B and b. O0 to O3 represent output devices.&lt;br /&gt;
&lt;br /&gt;
P  P  P  P&lt;br /&gt;
a  A  a  A&lt;br /&gt;
b  b  B  B&lt;br /&gt;
O0 O1 O2 O3&lt;br /&gt;
&lt;br /&gt;
This is the easiest to understand implementation. Looking at O0, we see that O0 is powered only when a and b are active. This corresponds to the state when 2^0 and 2^1 are both 0. Examining all the devices reveals that this arrangement obeys the truth table detailed above. Further examination would reveal that this arrangement also follows a pattern. Basically, the full set of columns represent every single possible combination of a, A, b, and B. Therefore we can easily see how to expand this system to n=5.&lt;br /&gt;
&lt;br /&gt;
However, this implementation is not the most efficient one. I can also arrange the gears like so:&lt;br /&gt;
&lt;br /&gt;
O3A AO1&lt;br /&gt;
  BPb&lt;br /&gt;
O2a aO0&lt;br /&gt;
&lt;br /&gt;
This arrangement uses 7 gears while the first arrangement uses 12 gears (including power gears). I put B and b closest to the power supply to obtain an orderly arrangement of O0 to O3 although this isn't strictly necessary.&lt;br /&gt;
&lt;br /&gt;
Schematically this arrangement looks like this:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Which is just some sort of tree diagram. I can easily expand this to n=5 which is what I want.&lt;br /&gt;
&lt;br /&gt;
I drew this diagram in rectangular form so that I can better see how to construct the decoder. The outputs of the decoder will be in a 4x8 grid. Since the output units are longer in one direction than the other, I will align their long axis along the short axis of the diagram. It is probably best to place all the mechanisms for the decoder in the level above the outputs.&lt;br /&gt;
&lt;br /&gt;
Design for Memory Unit Registers&lt;br /&gt;
&lt;br /&gt;
The registers in the memory unit need some modification to work correctly. Only the register indicated in the memory address register ought to respond to read write signals. Therefore each of the 32 registers needs to be connected to one of the outputs from the decoder.&lt;br /&gt;
&lt;br /&gt;
In this example, the register only responds when 00000 is in the memory address register.&lt;br /&gt;
&lt;br /&gt;
##### ##### ##### ##### ##### ##### ##### ##### &lt;br /&gt;
#H#.# #H#.# #H#.# #H#.# #H#.# #H#.# #H#.# #H#.# &lt;br /&gt;
#^#^# #^#^# #^#^# #^#^# #^#^# #^#^# #^#^# #^#^# &lt;br /&gt;
#%#%# #%#%# #%#%# #%#%# #%#%# #%#%# #%#%# #%#%# &lt;br /&gt;
W%`%o W%`%o W%`%o W%`%o W%`%o W%`%o W%`%o W%`%o &lt;br /&gt;
I~`~RCI~`~RCI~`~RCI~`~RCI~`~RCI~`~RCI~`~RCI~`~R&lt;br /&gt;
CP```P`````P`````P`````P`````P`````P`````P```PC&lt;br /&gt;
&lt;br /&gt;
C in this diagram represents the output O0. I believe this is called the chip select signal in real computers.&lt;br /&gt;
&lt;br /&gt;
It may be possible to wire the decoder directly to the power supply of the memory, which would remove the need for an output device. &lt;br /&gt;
&lt;br /&gt;
Memory Unit Architecture&lt;br /&gt;
&lt;br /&gt;
Right, I based the design of the memory unit off a java applet simulator I found on the Internet. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
What this diagram is supposed to illustrate is that ALL the memory cells are linked to respond to the same read-out signal and the same write-in signal. Similarly, all the corresponding cells respond to same input, and all output to the same place. However, they will do none of these things unless they get a signal from the decoder, and only one register will get the signal as indicated in the memory address register. &lt;br /&gt;
&lt;br /&gt;
Now the input and output buffers shown here may not be in the final blueprints, depending on the design of the rest of the computer.&lt;br /&gt;
&lt;br /&gt;
Designing the machine language &lt;br /&gt;
&lt;br /&gt;
The machine language is the set of instructions the computer will be able to execute. What these instructions are will define the design of the remaining components. For example, the Arithmetic Logic Unit needs to be able to perform the various operations listed in these instructions.&lt;br /&gt;
&lt;br /&gt;
Ideally this language should be complete, that is, any function can be simulated as a combination of these instructions. I also want to be as simple as possible, to minimize the complexity of the ALU. It is worth restating that I am basing the overall design for the computer on a design for a VSC off the Internet.&lt;br /&gt;
&lt;br /&gt;
Since the opcode for this computer is 3-bits long, there can only be 8 instructions.&lt;br /&gt;
&lt;br /&gt;
Opcode	Function	Operand&lt;br /&gt;
000	Load Accumulator from memory (indirectly)	Memory Address&lt;br /&gt;
001	Store Accumulator to memory	Memory Address&lt;br /&gt;
010	Add	Memory Address&lt;br /&gt;
011	Subtract	Memory Address&lt;br /&gt;
100	Jump to address if accumulator is not negative	Memory Address&lt;br /&gt;
101	Binary shift left (*2) (input 0 as LSB)	Memory Address&lt;br /&gt;
110	Binary shift right (/2) (retain MSB)	Memory Address&lt;br /&gt;
111	Halt	Irrelevant&lt;br /&gt;
&lt;br /&gt;
Design for the Arithmetic Logic Unit (ALU)&lt;br /&gt;
&lt;br /&gt;
Now I know that the ALU needs to be able to perform 4 functions: Add, subtract, shift left and shift right. The unit needs to do one of these functions based on one of 4 input signals it may receive.&lt;br /&gt;
&lt;br /&gt;
The ALU will receive 2 8-bit inputs and produce 1 8-bit output. It will require 3 systems, the adder-subtractor, bitshift left and bitshift right. These systems would be integrated to form the ALU.&lt;br /&gt;
&lt;br /&gt;
Design for a half adder&lt;br /&gt;
&lt;br /&gt;
While there are existing dwarven adder designs out there, they do not come with schematics detailing the links between their components. Therefore I feel the need to design from scratch.&lt;br /&gt;
&lt;br /&gt;
A simple half adder would take 2 inputs, and produce an output and an overflow output called a carry.&lt;br /&gt;
&lt;br /&gt;
A	B	C	O&lt;br /&gt;
0	0	0	0&lt;br /&gt;
1	0	0	1&lt;br /&gt;
0	1	0	1&lt;br /&gt;
1	1	1	0&lt;br /&gt;
&lt;br /&gt;
  &lt;br /&gt;
Carry out circuit  C==ABP&lt;br /&gt;
&lt;br /&gt;
                      aBP&lt;br /&gt;
Output circuit     O==o&lt;br /&gt;
                      bAP&lt;br /&gt;
&lt;br /&gt;
C===A&lt;br /&gt;
   aBP&lt;br /&gt;
O==obA&lt;br /&gt;
Combined circuit&lt;br /&gt;
&lt;br /&gt;
This schematic shows a dwarven half adder that obeys the above truth table. In this diagram, the o represents a normal gear assembly and = represents axles. This design rests on the assumption that axles do not receive power except from their end tiles. It also takes advantage of the assumption that a matched pair of gears will not transmit information across their connection (here it is the B and b gear)&lt;br /&gt;
&lt;br /&gt;
I believe this design uses the minimum number of gear assemblies, although I am not sure.&lt;br /&gt;
&lt;br /&gt;
Design for a full adder&lt;br /&gt;
&lt;br /&gt;
In order for an adder to work properly, it must also receive the carry bit in addition to the 2 inputs. Ultimately, even the first adder in the final adder-subtracter must be able to receive a carry bit to operate successfully, which is why I didn't draw up a full plan for the half adder.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A	B	C (carry in)	O2 (carry out)	O1&lt;br /&gt;
0	0	0	0	0&lt;br /&gt;
1	0	0	0	1&lt;br /&gt;
0	1	0	0	1&lt;br /&gt;
1	1	0	1	0&lt;br /&gt;
0	0	1	0	1&lt;br /&gt;
1	0	1	1	0&lt;br /&gt;
0	1	1	1	0&lt;br /&gt;
1	1	1	1	1&lt;br /&gt;
&lt;br /&gt;
PB&lt;br /&gt;
CAo==O2       Carry Out Circuit&lt;br /&gt;
oBo&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
o=o=o=o==O1   Output Circuit&lt;br /&gt;
C c c C&lt;br /&gt;
B b B b&lt;br /&gt;
A A a a&lt;br /&gt;
P P P P&lt;br /&gt;
&lt;br /&gt;
    O1 O2     Combined Circuit&lt;br /&gt;
 oo=oo |&lt;br /&gt;
 Cc cC oo&lt;br /&gt;
 Bb BbBAB&lt;br /&gt;
PAo oaPCo&lt;br /&gt;
&lt;br /&gt;
Now that looks pretty monstrous. Undoubtedly the arrangement of gears could be changed here and there depending on the exact dimensions you need the array to be, but hopefully this diagram illustrates methods that can be used to minimize the complexity of the device. Note that where there are adjacent identical gears directly connected to the power source, one of them can be replaced by an ordinary gear, which will remove a linking task for that gear.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  `````   oCBAP&lt;br /&gt;
  ````    ocbo&lt;br /&gt;
#####   ``|``&lt;br /&gt;
#.#.#`  ``ocBo&lt;br /&gt;
#^#^#`  `ooCba     Hypothetical implementation&lt;br /&gt;
#%#%#`  `o``BP&lt;br /&gt;
`%`%``  ```oAC&lt;br /&gt;
`~`~``  ```oBo&lt;br /&gt;
`````   `````&lt;br /&gt;
 lvlz     lvlz+1&lt;br /&gt;
&lt;br /&gt;
The above diagram details a hypothetical implementation for a full adder. The ```s represent the shadow of the mechanisms above and below the level. The left power sensor produces the output signal while the right power sensor produces the carry signal to be relayed to the next adder. The total footprint of the unit is 6x9. In an array, the units can overlap one tile so the total footprint of an 8-bit adder would be 41x9. Maximum operational power draw is 131x8(1048) units of power.&lt;br /&gt;
&lt;br /&gt;
Design for an 8-bit ripple carry adder-subtracter&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to build a full 8-bit adder-subtracter, all you need to do is to stack up 8 full adders next to each other and ensure that all the gears have been linked to the appropriate plates.&lt;br /&gt;
&lt;br /&gt;
 Now to get the adder-subtracter to subtract, all you have to do is to link up every single A and a (or B and b) gear assembly to the pressure plate sending the subtract signal. When the signal is sent, all the gears linked to a register will toggle. This will have the effect of inverting whatever input the register is sending. Finally the signal also needs to activate the carry in gears in the first adder, which will have the effect of adding 1 to the resulting sum (difference), giving the correct answer in two's complement representation.&lt;br /&gt;
&lt;br /&gt;
Design for a carry-look-ahead adder&lt;br /&gt;
&lt;br /&gt;
I did some research into carry-look-ahead adders to see if it was worth implementing. Carry-look-ahead adders are faster than ripple-carry adders as ripple carry adders have to wait for the carry bit to 'ripple' through the chain of adders before getting the correct result. This is most significant for users of fluid logic, as fluid logic adders need to wait n*100 steps (n being the number of bits) for the carry to ripple all the way to the end. (Floodgates and bridges have a 100 step delay before activating or deactivating)&lt;br /&gt;
&lt;br /&gt;
I found that I could easily design a carry-look-ahead adder using mechanical logic that calculates the carry in bit for all bits in a single step. I would also like to point out that real carry-look-ahead adders are more complicated because they don't have teleporting switch signals. &lt;br /&gt;
&lt;br /&gt;
Firstly, looking at the carry-out circuit for the full adder, I see that not only can it exist independently from the sum circuit, the C gear is directly attached to the power source. I can take advantage of this by separating the carry bit calculation circuits from the adder and attaching them to each other like so. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then for the summing part of the adder, I simply build only the output circuit, which I can now simplify like this&lt;br /&gt;
&lt;br /&gt;
    O1     Output Circuit&lt;br /&gt;
 oo=oo&lt;br /&gt;
 Cc cC&lt;br /&gt;
 Bb Bb&lt;br /&gt;
 oAPao&lt;br /&gt;
&lt;br /&gt;
Or I can make it long instead of square so that it will tile better with the output buffers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   O1&lt;br /&gt;
   |&lt;br /&gt;
oBCoCbo&lt;br /&gt;
AbcocBa&lt;br /&gt;
P     P&lt;br /&gt;
&lt;br /&gt;
I could construct these directly above the output buffers and they would all tile a lot better. Not only that, it fits almost perfectly within the footprint of a bank of output buffers. There is also no cost of increased complexity, only spatial separation between the summation unit and the carry unit, plus providing all the advantages of the carry-look-ahead system.&lt;br /&gt;
&lt;br /&gt;
Since this system is superior in all ways to the ripple-carry system, this will be the one going into the final dwarven computer.&lt;br /&gt;
&lt;br /&gt;
Design for bitshifting operations&lt;br /&gt;
&lt;br /&gt;
Setting up a bitshifting operation is relatively simple. I simply wire the inputs directly into slightly different outputs as illustrated in the following diagrams (source: Wikipedia http://en.wikipedia.org/wiki/Bitwise_operation#Arithmetic_shift).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ideally all these operations would be linked into the same bank of output buffers in the assembled ALU, which will be the subject of the next section.&lt;br /&gt;
&lt;br /&gt;
Design for ALU architecture&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This diagram illustrates the various signals moving around the ALU. I decided that I ought to dragoon the ALU into incrementing the program counter as well, but I'm not sure whether that will work or not. We'll see in the later sections.&lt;br /&gt;
&lt;br /&gt;
I defined the inputs from AR1 to be A since there are fewer A and a gears in the current designs and they all have to be toggled by the subtract signal. The operations listed on the right are signals generated by the control unit and they tell the ALU which operation to perform and transfer to the output buffer banks. The component critical to this function is the multiplexer. &lt;br /&gt;
&lt;br /&gt;
The concept of the multiplexer is quite simple, suppose I had 2 inputs I and J, and I wanted to choose which one to pass based on signals Q and R, I would have to build something like this&lt;br /&gt;
&lt;br /&gt;
PQIoJRP&lt;br /&gt;
   |&lt;br /&gt;
   O&lt;br /&gt;
&lt;br /&gt;
Adding a multiplexer onto the output circuit would require an additional z-level if the tiling efficiency is to be maintained. &lt;br /&gt;
&lt;br /&gt;
This diagram illustrates a hypothetical implementation of the multiplexer, as well as the bitshifting logic. I don't think I need a support axle on z+2 as it should be supported by O1.&lt;br /&gt;
&lt;br /&gt;
Design of the bus&lt;br /&gt;
&lt;br /&gt;
I've decided to ditch the plan for a bus, which would have been the conduit for data transfers between registers throughout the computer. Initially there were 2 methods, one had a output buffer attached to the end of the bus while the other the bus directly supplied power to the inputs of the appropriate registers. &lt;br /&gt;
&lt;br /&gt;
Method 2 would not work on memory cells that used an active pump for bit-clearing. Method 1 would have worked but the output buffers had to be overwritten every step and that could cause cascading delays throughout the computer. Since this computer is relatively simple, I opted for hard wiring everything instead.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This diagram illustrates the data transfers that occur throughout the computer. The red arrows depict confirmed hard-wired connections, while the blue arrows would have been routed through a bus. I've decide AR1 is superfluous so I got rid of it. As you can see, each register has at most 2 inputs or 2 outputs going through the bus, so hardwiring is feasible.&lt;br /&gt;
&lt;br /&gt;
Design of the timing circuit&lt;br /&gt;
&lt;br /&gt;
Before the computer can execute its instructions, it needs to perform some operations first.&lt;br /&gt;
&lt;br /&gt;
Transfer the contents of the accumulator to AR2. Dump instruction register and memory address register.&lt;br /&gt;
Transfer the program counter to the memory address register. Also, activate the program counter incrementation system in the ALU and transfer the results into program counter +1.&lt;br /&gt;
Load the data from memory at the specified address into the instruction register.&lt;br /&gt;
Transfer the data from program counter +1 to the program counter. Also, dump the memory address register&lt;br /&gt;
Load the last 5 digits of the instruction register into the memory address register. Also, dump program counter +1.&lt;br /&gt;
Execution (write accumulator, memory or program counter, read instruction register, memory, AR2)&lt;br /&gt;
&lt;br /&gt;
There needs to be a 100 step delay from the time a memory cell is written (or dumped, if it is pre-dumped) and when it is read, or it may cause cascading delays. The writing process is practically instantaneous, but 100 steps are needed before the correct result can be read if the memory was not cleared to begin with. Of course this point is entirely moot if the computer is running automatically, in which case every step will last at least 100 steps anyway and the prime consideration is to ensure that every step can be performed in 100 steps.&lt;br /&gt;
&lt;br /&gt;
Design of the oscillator&lt;br /&gt;
&lt;br /&gt;
A typical mechanical oscillator is unsatisfactory because it will usually be sending out 2 on signals at once, one from the pressure plate the water is on and the other from the pressure plate waiting to reset.&lt;br /&gt;
&lt;br /&gt;
0%%6%%0%%5%%0%%4&lt;br /&gt;
%              %&lt;br /&gt;
%              %&lt;br /&gt;
1%%0%%2%%0%%3%%0&lt;br /&gt;
&lt;br /&gt;
This diagram shows a 12 step 6 signal oscillator. At the locations marked 0, there are no pressure plates. A lever operates the mechanism. When the lever is in the ON position, the #%%0 pumps activate, and when the lever is in the OFF position, the 0%%# pumps activate. The oscillator can also be fully automated by using the pressure plates themselves to replace the lever function. The oscillator's power supply also needs to be cut if a halt signal is received from the control unit. &lt;br /&gt;
&lt;br /&gt;
Oscillator Link table&lt;br /&gt;
&lt;br /&gt;
Read accumulator, write AR2, write IR, write MAR&lt;br /&gt;
Read PC, write MAR, activate ALU (adder select, C0=1), write PC+1&lt;br /&gt;
Read MEM, read MAR. activate decoder, write IR&lt;br /&gt;
Read PC+1, write PC, write MAR&lt;br /&gt;
Read IR, write MAR, write PC+1&lt;br /&gt;
Execution (read IR, turn on control unit)&lt;br /&gt;
&lt;br /&gt;
A dump operation can be performed by telling the memory register to write when its linked inputs are inactive, effectively writing 0s. &lt;br /&gt;
&lt;br /&gt;
Design of the control unit&lt;br /&gt;
&lt;br /&gt;
The control unit can be implemented simply as a 3-8 decoder with appropriately linked pressure plates. The execute signal controlled gear assembly is located at the root of the decoder. &lt;br /&gt;
&lt;br /&gt;
Control unit link table&lt;br /&gt;
&lt;br /&gt;
O0. Read memory, read MAR, activate decoder, write accumulator, select transfer&lt;br /&gt;
O1. Read accumulator, write memory, read MAR, activate decoder&lt;br /&gt;
O2. Read memory, read MAR, activate decoder, read AR2, Send Add signal to ALU (adder select), write accumulator&lt;br /&gt;
O3. Read memory, read MAR, activate decoder, read AR2, Send Subtract signal to ALU (adder select, C0=1, invert input A), write accumulator&lt;br /&gt;
O4. Read IR, write PC if ACC7=0&lt;br /&gt;
O5. Read memory, read MAR, activate decoder, Send Shift left signal to ALU (SHL select), write accumulator&lt;br /&gt;
O6. Read memory, read MAR, activate decoder, Send Shift right signal to ALU (SHR select), write accumulator&lt;br /&gt;
O7. Cut power to oscillator.&lt;br /&gt;
&lt;br /&gt;
Adapted from http://docs.google.com/Doc?docid=0AdISzBuNg6ZWZGd0d2t4YjlfMjJ0ejlzc2dnaA&amp;amp;hl=en&lt;/div&gt;</summary>
		<author><name>Jong</name></author>
	</entry>
</feed>