Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 2 [3] 4

Author Topic: Programmable Dwarven Computer. With Minecarts.  (Read 16183 times)

Max™

  • Bay Watcher
  • [CULL:SQUARE]
    • View Profile
Re: Programmable Dwarven Computer. With Minecarts.
« Reply #30 on: January 28, 2015, 12:44:43 am »

So you suggest building a fortress to build a computer to build an automated goblin processing factory, walls and all?

I love every part of that sentence.
Logged

Larix

  • Bay Watcher
    • View Profile
Re: Programmable Dwarven Computer. With Minecarts.
« Reply #31 on: January 28, 2015, 08:12:43 am »

One interesting application could be automatic drawbridges that open only twice per trade season. (or once, with exit route through cavern layer?)

Simple, completely accurate minecart clock:
http://mkv25.net/dfma/movie-2669-eternityclock
Just hook up a few pressure plates and you can trigger/untrigger stuff on any particular day of the year/decade/century/what-have-you.

Using werebeasts seems rather like complication for its own sake.

Thing is that seasonal procedures and reactions to invaders would be faster and usually more effective for less effort using special-purpose logic gate arrays.

Another problem is that to the best of my knowledge, invader movement is very irregular - they often end up standing in place for a few days and then sprint across half the map in a few hours. Pressure plates can't distinguish between one goblin standing on a plate for two days, a pack of dingoes camping on top of it, and a horde of twenty gobbos charging your fort. And they suck at determining movement directions, too. Highly specific reactions to specific activated plates are rarely useful, most of the time i find i need a blanket "start the auto-smasher/release the dogs" latch to make sure the issue is actually dealt with. Finesse commonly translates to complicated ways of shooting one's own foot. There are some building destroyer/trapavoider/lockpicker peculiarities that could be exploited in .34.11, but i haven't seen how and if they still work in .40, with jumping and climbing (using your own dwarfs as creature logic processors is pretty much dead due to climbing).

Quote
Again, there's also the possibility of using the computer for additive CNC construction of a megaproject, like a detailed statue cast out of obsidian.

Hmm, a computer-controlled 3D-printer? That's an interesting idea. The big point of course would be to make a machine that does the printing by itself, working off a blueprint you entered (or procedurally creating one? Is there a simple algorithm to make crude fractals or other geometric patterns?). It especially should make sure that all newly-cast tiles are properly supported...
Logged

wierd

  • Bay Watcher
  • I like to eat small children.
    • View Profile
Re: Programmable Dwarven Computer. With Minecarts.
« Reply #32 on: January 28, 2015, 12:44:05 pm »

yup. Means needing to have some basic strategem, and a fault detection routine of some sort (if using generated fractals-- faults in the pattern regarding support that is, prior to printing the layer.)

As a general strategy, starting in the center of the build tank and spiralling outward would help ensure that the edges have horizontal support. Ensuring the start point at the center is always printed will ensure each level has vertical suport at at least one location. After that, it is just sanity checks for horizontal continuity as it spiral prints each layer.

The logic to accomplish this should be pretty small, and can probably be integrated into the fractal generator routine. 

It would be kinda cool to have DF proceeduraly generate a masterwork 3D fractal fortress this way.
Logged

taptap

  • Bay Watcher
    • View Profile
Re: Programmable Dwarven Computer. With Minecarts.
« Reply #33 on: January 28, 2015, 01:45:42 pm »

You win an adamantine minecart.

Don't think "speed" as in comparing DF with Minecraft gamesteps or out of game time is all that relevant. (If DF had an empty world creative mode with hardly anything calculated  between steps it would run faster as well. But DF isn't complete without the pathing of the zombie ravens above its computers.)

What I would love to build myself is an automatic invader separator / sorter, where they end in individual holding cells pending further processing.

Sadrice

  • Bay Watcher
  • Yertle et al
    • View Profile
Re: Programmable Dwarven Computer. With Minecarts.
« Reply #34 on: January 28, 2015, 01:54:55 pm »

You've done rather a lot with fiddly diagonal movement of minecarts.  Perhaps you could use that to selectively bombard any point on the map from a central tower, using your computer to calculate trajectories. 

As for invader sensors, I seem to recall there being something useful with having an animal in a pasture behind a window, and when it sees enemies it tries to flee, moving onto a pressure plate.  This would give you a much wider detection window from a single plate, and also detects trapavoid enemies.  Cats behind locked doors will wait by the door, attempting to path to meeting zones and vermin, right?  You could use that to have them automatically reset themselves, rather than requiring a dwarf to manually repasture the animal.

If you space your detectors close enough, you could have your computer pay attention to enemy movement, and if an enemy leaves one detection zone and moves to another quickly enough, it will predict which zone they will move to next to try to lead the shots.

Of course, there are far more practical way to handle the computation needed for this than using a programmable computer, but somehow I don't think practicality was a major consideration when you decided to build a minecart computer.
Logged

Larix

  • Bay Watcher
    • View Profile
Re: Programmable Dwarven Computer. With Minecarts.
« Reply #35 on: February 27, 2015, 10:09:41 am »

Latest update:

Now you can program dwarven computers, too!
http://dffd.bay12games.com/file.php?id=10624

I uploaded a slightly cleaned-up save to the DFFD.

General notes:
the game version is 0.34.11. If you don't have it installed (anymore), you can download it here.

the biome is temperate. With normal weather, all machinery will be frozen about two months each winter; this can cause unfreezing problems. Best to avoid it by setting [TEMPERATURE:NO] in d_init.txt.

the fort has no defences. It's probably best to keep invaders switched off.

changes/usage notes:

I expanded the two counter registers. While the counting functionality is still strictly six-bit, four additional storage bits have been added, so the registers can be used to store a ten-bit datum each when not used for counting.

The "program tape" has been added. It's a sequential, single-use ROM-like memory array. Each position can hold a full module (eight six-bit words) of program and the total number of positions is conceptionally unlimited (of course it's limited by the total space on site, but it could still fit close to a megabit, at the cost of several hundred thousand carts and mechanisms).

In the uploaded save, i relabelled the main controls (hotkey F2) in english.

To see the thing in action, you can simply pull the main operation lever (with the special note sign). A demo program is resident, which just calculates an endless fibonacci series, doing a simple check to occasionally count up when the ten-bit registers overflow. It's actually long-winded enough that the safety off will probably engage before the program finishes (~1200 program steps, takes around a year to happen. You can always abort earlier.).

To enter data into the main registers, you need to set up the exact bit pattern you want by activating the correct "on" and "off" levers. Once that's done, pull the lever for the register you wish to load. Loading happens when the lever is switched on, the mechanism will disengage by itself (but you need to switch the lever back off before you turn it back on, so you still need a double pull). Once the register is loaded, re-set all bit levers you engaged to off.

When entering a program, you can only set "positive" bits at will. To clear undesired bits, you need to clear the entire program by the "clear program" lever in the south - one pull (or double-pull if already in "on" position) clears all program bits. Once that's done, pull the levers corresponding to the bits you want set (pattern should be clear enough) and once that's done, pull (or double-pull, as usual) the "load program" lever in the north of the programming chamber. Once again, after entering a program, it's best to reset all levers to off.

Entering a program of 110 nnn allows you to directly load one of the modules in the ROM. Normally, you are served the appropriate module from 1-8, depending on the "nnn" argument; if you set the "register bank" bit to "on" or enter 111 100 as first command before the module load, the computer will load a module from 9-16.

The easiest way to get a module loaded, however, is through the "load module one" lever a bit east of the main operation lever. It loads the "starter" module directly into program memory.

To run the starting module, you must first set the "write target" bit to "on" (writes to program). Status bits are set or cleared (set lever to the left, clear to the right) by a battery of levers in the east of the main control room. You have to pull the lever, wait a few steps for the signal to take, then pull the lever again so the switch devices are in "neutral" (off) state again - they can be operated by various inputs during program execution, and hatches/doors that remain open after a lever-operated set/clear can mess up reactions.

The program will first wait for an input. You need to enter a number into the Buffer register, one of (top four bits are irrelevant)
(xxxx) 101 100
(xxxx) 101 101
(xxxx) 101 110

This can be entered either at the normal data entry station or at the extra lever array just north, which is only accessible when input is required. You need to go through all the steps - set up the bit pattern you want, pull the load lever, reset all bit levers. Then you have to pull the operation lever again (the whole thing's just a fancied-up "halt"). The program will then jump to the given location and load other modules from there, leading to the actual programs.

Those are:
101 100: sort three numbers. You'll need to block the data tape recycle loop (another lever in the main operation room) for that, requests are too close to each other and would lead to colliding carts.

101 101: square root of an arbitrarily chosen number. The program pulls the current top number from the data tape and calculates its square root by approximation

101 110: Hello Urist. The computer slowly displays awful pixel graphics that can with a lot of good will be deciphered as a greeting.

Once a program has run, you usually need to return the program counter to the first position for the next use of the computer. For this end, there's a "reset" lever, which does just that. It also resets all status bits to zero, so take care if you need a set status bit for your program (like in the startup program, where "write to program" must be pre-set).

Bonus content: since the programs present only take up fourteen of the sixteen ROM slots, i banged together two more:
Self-programming, found in module 15
Enter (xxxx) 010 000 into the buffer
Access by entering program:
111 100 (switch ROM banK)
110 110 (load seventh module in the bank)
The program increments the only actual command it executes on each pass. Since i ordered it wrong, it'll get stuck in an infinite loop once it reaches 100 000 (test if B>C, skip next instruction if not), but it'll advance through all options of the adder and several of the counting machinery.

Fibonacci overflow
Access by program:
111 100 (switch ROM bank)
110 111 (load eighth module)
That's just the shown sample program. You must have _something_ in the buffer (one is nice), or you get two zeroes and the program will pointlessly loop around adding them together.

If you want to properly program on this computer, please consult the instruction listing in the second post. If you have ideas for a feasible program but can't handle the interface, you could describe/list it and i could see if i can implement it.
« Last Edit: March 10, 2015, 11:42:06 am by Larix »
Logged

orbcontrolled

  • Bay Watcher
    • View Profile
Re: Programmable Dwarven Computer. With Minecarts.
« Reply #36 on: March 01, 2015, 11:43:07 pm »

♪ In places deep ♪
♪ Where strange things beep ♪
♪ In hollow halls beneath the cells ♪
Logged

Larix

  • Bay Watcher
    • View Profile
Re: Programmable Dwarven Computer. With Minecarts.
« Reply #37 on: June 11, 2015, 02:53:39 pm »

I produced a writeup for this computer (dubbed Mark Lumberjack. Because it can skip and jump :P ), mainly trying to put it in perspective with respect to real-world computation; what it does differently, what it does similarly. Trawling through computing pioneering efforts, i even found a real-world computer that's somewhat similar in "power".

Essay concerning the Mk. L.

The Mark Lumberjack is an extremely compact and primitive dwarven computer.
The "program store" consists of a mere eight instructions of six bits each. Six data registers can hold numbers of ten bits each. In spite of these tiny ressources, some basic computational abilities are implemented and have been demonstrated successfully: the four arithmetic operations, rudimentary in-/output, conditional branching, nested loops and the conceptional capability to access (but not address) unbounded data and program memory.

Differences from standard electronic computers:

1. Program counter
In contrast to most real-world computers, program flow in the Mk. L. is not controlled by storing the "current" position's address in a dedicated memory register. Instead, a ring counter is used. This counter also only sends signals once per counting step, by a pressure plate that is quickly passed by a minecart, limiting the time from "on" to "off" signal to barely over 100 steps. The counter is completely inactive between counting steps, no signals are sent or held. The "current" program position is saved as the position of the cart resting on one of several inactive rollers.

Each signal activating the counter provides temporary power to the rollers, causing the the device to advance by exactly one position. During this advancement of the minecart to the next roller in line, the appropriate signal is triggered to evaluate and execute the current instruction. Without additional machinery, this simple advancement is all the counter can do, for refined program flow, further machinery must be added. In order to "write" a new position into the counter, a switchable branch off the normal advancement path is needed so the cart can leave the main ring, get sorted onto the branch for the "jump target" and "inserted" at the desired position. Similarly, the conditional "skipping" of an instruction is  implemented by letting the cart advance one position, but leashing it around the normal "evaluation" pressure plate.

N.B. : there's no strict connection between the positions the "jump" machinery can send a cart to and the number and order of positions in the ring counter. The number of ring positions can be higher (or lower) than the number of jump addresses available. It's entirely thinkable to have a jump selector that can only send carts to eight positions, four each of which are contained in one of two twenty-position ring counters. The jump-selectable positions could also be sorted in ascending order in one ring, in descending order in the other. Such a design, where only few of the program positions are actually reachable through jumps, could be used to greatly expand the possible program length without needing to analogously expand the "program address" size that the computer must be capable of handling as an actual memory/instruction feature. How effective such a design can be evidently depends on how many actual jumps/program segments are required - when you can only jump into eight program positions, a program requiring more than eight proper jumps cannot be executed.

Relative jumps would be theoretically possible, but only reasonably in the normal counting direction. Even then, it'd probably get ugly - since the current position is not held as a computable datum, advancement would need to be done either by consecutive one-position advancements with blocked/bypassed evaluation (very slow) or by disabling the "stepping" mechanism and using a delay to achieve the proper activity time for the desired number of advancements (complicated and prone to disturbances). A computer with a dedicated program counter could perform relative jumps fairly easily, by adding the desired offset to the current value stored in the counter. AFAIK Jong's dwarven computer could not extract current status of PC as normal datum for computation and storing back, but it wouldn't have been very difficult to implement.
The "compare" operations of the Mk. L. make the following operation conditional. This is implemented by forcing the cart to advance one position without triggering execution when the condition is not met, i.e. it could be viewed as a conditional relative jump with fixed offset (one position).

Advantages of the ring counter:
- low requirement of machinery
- advancement is quick and uncomplicated
- no need to calculate the next program location as digital datum, which would imply an additional dedicated adder if you don't want to go through the main adder (which could expose you to the von-Neumann-bottleneck simply to read out PC status and transfer back the value PC+1).
- the number of program positions is not limited by the "address space" of the machine, since the latter only limits the number of positions you can jump to, not the number of positions you can cram into a ring.

Disadvantages:
- the logic of a ring counter is likely very different from the logic of signal-based memory and the ALU. Different design may cause compatibility issues.
- the current program place is not saved as datum available for computations - v. relative jumps - and if the "large ring with few insertion points" logic is followed it may in fact not be feasible to save/derive the location anyway. This precludes some programming techniques common in real-world computers.

Possibilities:
as mentioned above, program stretches seemingly too long for the processor's address space can be built. My design with a three-bit jump address selector could have been built with a 32-position ring where only every fourth position would have been targettable by jumps. If necessary, NOPs would be used to buffer segment lengths. The Maple 6/6 uses a variation on this concept, by only allowing jumps from and to five locations on a "tape" with a bit over 30 positions.

Complicated but common routines could be realised by sticking them into their own sub-rings, using dedicated instructions to halt the main ring, activate the sub-ring until done and handing execution back to the main program. That'd be a fairly intuitive way to emulate sub-routines or microcode.

2. Timing control

In many locations, the Mk. L. takes measures to minimise signal latency and to line up signals during operations so that they follow each other closely but without interference.

The great attention for these issues is born of the fact that the basic "clock rate" is very low: a signal cycle takes at least 100 steps, usually a few more, and the game itself runs at best at a few hundred FPS, but with substantial mechanical installations, it's likely to be in the range of 10-50. And of course, the signal cycle time is not the speed at which a logical machinery will sustainably operate, it will more likely be in the range of several hundred to over a thousand steps per operation, giving us computation speeds in the 20-100 mIPS (milli-Instructions Per Second) range. The fewer steps consumed per instruction, the more instructions can be executed in a given amount of time and the more meaningful computations can actually be performed before the overseer gives up in boredom.

The 100-step signal remanence applies to any signal used, and when a signal enables the repeated triggering of a resultant signal generator, that generator will only stop refreshing its signal after the input has turned off - the output will remain active a hundred steps after that. It's easy to run into escalating signal remanence this way. Consequently, the Mk. L. avoids such remanence stacking wherever possible. Most signals used are generated by a single passage of a cart over a pressure plate. This is fairly easy to achieve with powered carts. A notable exception are the reading processes of the registers: each cart is evaluated by a hatch cover allowing it onto a minimal-length track end with a pressure plate. The cart refreshes the signal until the hatch cover closes, resulting in a remanence of 190-240 (somewhat randomly) steps. This enforces a kind of baseline for instruction length - any operation requires an instruction read, many also require a data register read, which sets a hard lower limit of these 240 steps.

A further issue with the minecart circuits used are signal latencies - carts take a while to send output after the input-driven furniture or power has switched. In the powerless systems, latency is both fairly long and in the case of constantly-moving carts also quite variable. Powered circuits and powerless circuits in which the cart is usually at rest (e.g. sitting atop a hatch while the circuit is inactive) can have constant latencies; latencies can even be tuned to useful "delay" values by regulating cart speeds and distance travelled before the output gets triggered. In contrast to fluid logic, almost any imaginable delay can be constructed with powered minecarts, with absolute precision and reliability.

A notable example of carefully designed timing circuits would be the "indirect" read/write activation circuits. They have a fixed latency of 26 steps, a signal remanence of 102 steps and return to their dormant readiness state by themselves without having to wait for their input to turn off.

Another successful design are the dedicated read/write "rails" for the counters and the powered memory register. Since those memory stores keep their "high" outputs active constantly, this permanent output must be converted into temporary signals for use by the main buffer. Similarly, the counter registers have no "enable" functionality, so they need a dedicated "translation" circuit that's only run when a write to the registers is desired. These circuits consist of nothing but bifurcation switches, switched via retracting bridges. The obvious difficulties are that bridges take quite a while to react to a signal, and that a cart takes a substantial time to run a circuit with ten bifurcations (and enough intervening path to send all the necessary trigger signals to counter or buffer). The circuit evaluating the buffer state has to wait for the reading process of the buffer to show its results: 25 latency for the buffer-read trigger + 2-30 steps latency for the buffer carts to react, + 100 steps for bridges in the translator circuit to react. A pretty substantial wait. Similarly, when reading the value of the data registers by read rail and writing the result to the buffer, the reading run takes about 90 steps from the first to the last triggering of an output signal. Each of these signals lasts about 103 steps, just like the opening time of the enable doors in the buffer register. And all output signals must have sufficient overlap with the opening time of the door (which begins with a latency of 26 steps). The write-to-buffer must be triggered after about one third of the circuit has been finished.

Looking at alternatives, cart+door-logic should allow much tighter timing optimisation: latencies can be quite short - no more than five steps to trigger a direct response - and run-times of longer circuits can be fairly short, thanks to the high movement speeds: a four-bit decoder could send its result after about fifteen steps. Remanence would typically be 100 steps precisely. Similarly fast memory cells are possible.

It's fairly easy to optimise hard-wired tape machines like the Maple 6/6 for extreme operation speed. About 120 steps per actual operation were realised with this machine. The Mk. L. achieves one instruction per ~400 steps. Reducing the time consumption would be possible, but cutting out more than 50 steps would become quite difficult, what with the up to 240 steps remanence of register accesses. A CDL computer with complicated logic might allow speeds of 150 to 250 steps per instruction.

A constant-period system clock (something that was thought about but never realised for Jong's dwarven computer) would need to keep its rate slow enough to accomodate the slowest "atomic" processes of the fetch-/execute cycle. Since Jong's computer was built before minecarts, the only reliably automatable delays would likely be multiples of 100 steps; it would likely have been necessary to expand several steps to double length to avoid data collisions, suggesting an overall operation speed of about 900 steps per instruction. Sorting processes and maybe re-building some of the control logic, a hydromechanical computer from 0.31.25 might have been optimisable down a few hundred steps, to 500 per instruction or so.

3. Addressing conventions and memory

The Mk. L. is at heart a no-address-machine, i.e. it has no actual "address" arguments in its instructions - all parameters of each operation are implicit. While several functions access one of an encoded number of target circuits, this information is used by no other function. Only the reading and writing triggers of some registers are accessed by multiple operations, but never in a unified "addressed" way. As an example, the accesses to the adder don't follow a unified address logic but rather perform one of eight fully specified operations, using four different combinations of input registers and a choice of two different output registers.

Since the command word is merely six bits long, identification of the operation parameters uses no more than three bits of an instruction, allowing to address all of eight circuits.

The "program ROM" holds not eight but sixteen modules, while the command that loads a module is still limited to a three-bit identifier. This "address space" expansion is achieved through use of a "control bit" that switches the module loader between two banks of eight modules each. The bit can be set or toggled by program instructions. A fully machine-operated program could use all sixteen modules, needing no dwarven input to perform the "bank switch".
The Mk. L. also contains two sources of non-addressable information - one data and one program "tape", read-only devices that can only be used sequentially and in which the individual datum has no definite identity. While this allows providing the machine with a theoretically unbounded stream of data and program information, it doesn't make it turing-equivalent, since retrieved information is unidentifiable and unaddressable. Furthermore, no extended write access would be provided: the Mk. L. could still only write ten-bit data to its six data registers.

A more substantial step towards turing-completeness with such a limited computer architecture would probably require going beyond mere "bank switching" - building a multi-level nested memory with operations that switch access between the various memory levels. Conceptionally, unbounded memory could become addressable this way, but expectedly, access to "deep memory" would soon take exorbitant amounts of time. This would be a "merely" practical, not a theoretical concern, which is largely irrelevant when talking about the purely theoretical "true" turing completeness, which is not a property of actual computers - the required infinite memory makes it practically impossible not only because it itself is infinite, even the memory addresses or access times would of necessity be infinite and thus outside of the physical realm.

This idea of nested memory has been brought up by user/dwarfgineer Vasiln in his treatise on goblin logic: http://dwarffortresswiki.org/index.php/User:Vasiln/Goblin_Logic_3#Feedback:_Memory_multiplexing

Demonstrated features seen in real-world computers

Harvard-like architecture:

program and data memory are strictly separated. Operations are retrieved only from the program memory, only the content of the data registers is used for calculations. Somewhat arbitrarily, different bit widths were chosen for program (6 bit) and data (10 bit). The separation allows relatively fast execution, since signal remanence only interferes with the next same-type memory accesses - data can be read long before operation signals have timed out and vice versa. Consequently, the average time per operation is quite a bit less than twice maximum signal remanence of the standard memory cell (240 steps maximum remanence, observed execution speed one operation per 390 steps). Operations are largely hard-wired with little overlap which again helps timing management.

A bus-based architecture would certainly be useful when handling significantly more information, but it'd require a core design with much shorter latencies and remanences. Cart+door-logic might be a good choice for such a project.
If stored information is intended to be usable both as instruction and as datum, there's always the risk of interference between signals. A possible solution would be to use a similar logic to the double-sided memory cells in the Mk. L. - have two pieces of furniture enabling reading which can be operated independently. The easiest case would be to have "opposed" read branches, one of which sends an output if the bit is "on", one if the bit is "off". It should be possible to build the connected logic so that it only uses the presence/absence of one signal as input. Thus, the data-processing machinery could process only the "on" signals from memory (interpreting absent signals as "off"), while the control logic would only process the "off" signals (applying negative logic, if you will). This should help limiting trouble with the von-Neumann-bottleneck. This is presumably also be possible (albeit perhaps not very practical?) in real-world computers, since memory cells usually can be constructed with two complementary outputs.

Use of status bits/flags:

The Mark L. uses four status bits.

At - the "jump inhibitor" prevents jumps ordered by the "jump" instruction when set. This makes jumps conditional. The bit is usually set as outcome of a "count" operation: counting can test either whether the counting result is zero or whether it is an even number. The bit is not linked to the current state of a register, the two counting registers can be set to zero without setting the At bit, they can be set to non-zero numbers without clearing the bit. The bit can also be set by writing the buffer's contents directly to the "status register"; the At bit will take on the value of the lowest bit.

Write target - when set, the writing operation will store the buffer contents in the identified program location, otherwise it goes to the given data register. This notionally allows a program to re-write itself. The bit value can be set by writing to the status register and toggled by a dedicated operation.

Module bank - switches between the two banks of eight program modules each. As above, set- and toggleable by the computer itself.

I/O switch - switches between two input/output configurations. One takes input by halting the computer (awaiting input to the buffer) and sends output to the 5x7 pixel "display", the other configuration interfaces the buffer with an extra register controlling a few pumps and a hatch. In the built computer, this is just used as a right-shift-by-one operation, but it could evaluate input from environment-sensing pressure plates (e.g. activated by liquid or non-fort creatures) and take ...measures in response. Controlled like the write target and module bank bits above.

Hardwired constants:

loading data from the notional addresses "000" and "111" doesn't consult an actual built register but simply clears (000) or sets (111) all bits in the buffer register. This facilitates simple tasks like clearing a register or inverting bit values in a register. These constants can also be used to set status bits to specific values (toggling a few of them afterwards if needed) and could in theory allow setting registers to specific values - that'd be an exceedingly labourious process when looking at any number above ten, though.

Hello World:

The I/O commands allow outputting the contents of six program registers to a 5x7 pixel "screen". While this is quite clumsy, it allows displaying primitive text-graphics, at a rate of two letters per complete module. Together with the ability to operate machinery through the alternative I/O register, it demonstrates a rudimentary ability of the computer to interact with its surroundings as result of a program.

Program flow:

The Mk. L. dedicates two full operations to conditionalised program flow and another to an unconditional control function.

The classical jump operation is conditional - "jump when no bit". The bit is typically set by an increment or decrement operation, most commonly when a count reaches zero.

The "compare" operation triggers an immediate skipping of the next instruction without even consulting it when the compare condition is not met. This makes the operation (any operation) directly behind a compare instruction conditional.

All "module load" operations overwrite the current contents of the program store with the contents of the chosen module and sends the cart to program position one, making the operation an unconditional jump to the first instruction of the module.

Since the ring counter is in fact closed, operation will always return from position eight to position one automatically if  the eighth instruction isn't a jump somewhere else, which means an unconditional program loop is already built into the machine.

On the whole, the Mk. L. has 64 instructions (80 including the extra options realised through status/control bits). It dedicates of those
20 to data transfer
14 to data processing
28 to control flow
2 to input/output

Typical features also found in real-world programs:

Counting loops - using the increment/decrement function, testing for zero
Conditional loops - using "compare" operations so that the jump back is skipped once the loop condition is no longer met, and/or so that a "break" triggers once an abort condition is met
Unconditional jumps - module load
Increment/decrement - one of the core instructions, even updates the jump inhibitor bit automatically
Bit shift - shift left by addition (add two copies of the number together), shift right by writing to, then reading from the i/o register
Most of these are used in the square root calculation program.

***

For a real-world example of a similarly "powerful" computer, one has to look at the very earliest, largely experimental designs. The Manchester SSEM ("Baby") is a fairly good comparison, with its six operations (plus stop) and a total memory of 32 32-bit words, i.e. 1024 bits overall. Of course, the Manchester Baby could read/write to all words and didn't need to swap in extra information from ROM - the Mark L. has only 60 bits of writeable memory (although it has about 110 words of effective program storage).
Logged

NW_Kohaku

  • Bay Watcher
  • [ETHIC:SCIENCE_FOR_FUN: REQUIRED]
    • View Profile
Re: Programmable Dwarven Computer. With Minecarts.
« Reply #38 on: June 11, 2015, 10:55:56 pm »

By Armok's bloody beard...

I was going to sit and try to figure this out, but it's late at night, my eyes are already blurry, and even trying to make sense of some of this honestly made me feel nauseous. 

Let me just pass all my hard-earned SCIENCE socks to you and call it a night...
Logged
Personally, I like [DF] because after climbing the damned learning cliff, I'm too elitist to consider not liking it.
"And no Frankenstein-esque body part stitching?"
"Not yet"

Improved Farming
Class Warfare

angelious

  • Bay Watcher
    • View Profile
Re: Programmable Dwarven Computer. With Minecarts.
« Reply #39 on: June 12, 2015, 06:35:13 am »

wasnt this already done a couple of times?


first one had a clock that could keep up with real time. and second one could do basic calculations.
Logged

miauw62

  • Bay Watcher
  • Every time you get ahead / it's just another hit
    • View Profile
Re: Programmable Dwarven Computer. With Minecarts.
« Reply #40 on: June 12, 2015, 06:46:34 am »

We've had dwarven calculators, but afaik never a full-blown programmable computer.
Logged

Quote from: NW_Kohaku
they wouldn't be able to tell the difference between the raving confessions of a mass murdering cannibal from a recipe to bake a pie.
Knowing Belgium, everyone will vote for themselves out of mistrust for anyone else, and some kind of weird direct democracy coalition will need to be formed from 11 million or so individuals.

Larix

  • Bay Watcher
    • View Profile
Re: Programmable Dwarven Computer. With Minecarts.
« Reply #41 on: June 12, 2015, 07:13:04 am »

Jong's dwarven computer was freely programmable, but had no system clock, so each step of the fetch/execute cycle (six per instruction) had to be individually ordered as a pump command; consequently, the only recorded use of it was a function test.

The Mark Lumberjack has successfully executed basic programs - square root calculation by approximation (iterative division), sorting numbers by size, output access (the "Hello Urist!" message is the output of a "print to screen" program). The first two would have been possible on Jong's computer, but would have been deeply impractical to actually run (have fun ordering ~2000 pump actions for a square root calculation, instead of a solitary lever pull).

I had been practicing on a freeware "computer simulator" using an extremely restricted instruction set, which needs to be coded in machine language as well: http://sourceforge.net/projects/johnnysimulator/ (site requires cookie permission)
This experience had some influence on the instruction set choices in the Mk. L. and made me much less afraid of the programming tasks. (On the simulator, you can even write a "virus" - a program that just produces copies of itself.)

And yes, an actual programmable computer is a whole different beast from a precise clock or a simple adder, you have to stick several levels of logic on top of one another and make sure they all play nice with each other.
« Last Edit: June 12, 2015, 07:23:01 am by Larix »
Logged

angelious

  • Bay Watcher
    • View Profile
Re: Programmable Dwarven Computer. With Minecarts.
« Reply #42 on: June 12, 2015, 07:39:44 am »

Jong's dwarven computer was freely programmable, but had no system clock, so each step of the fetch/execute cycle (six per instruction) had to be individually ordered as a pump command; consequently, the only recorded use of it was a function test.

The Mark Lumberjack has successfully executed basic programs - square root calculation by approximation (iterative division), sorting numbers by size, output access (the "Hello Urist!" message is the output of a "print to screen" program). The first two would have been possible on Jong's computer, but would have been deeply impractical to actually run (have fun ordering ~2000 pump actions for a square root calculation, instead of a solitary lever pull).

I had been practicing on a freeware "computer simulator" using an extremely restricted instruction set, which needs to be coded in machine language as well: http://sourceforge.net/projects/johnnysimulator/ (site requires cookie permission)
This experience had some influence on the instruction set choices in the Mk. L. and made me much less afraid of the programming tasks. (On the simulator, you can even write a "virus" - a program that just produces copies of itself.)

And yes, an actual programmable computer is a whole different beast from a precise clock or a simple adder, you have to stick several levels of logic on top of one another and make sure they all play nice with each other.


just make sure there is a failsafe.


i think out of all the possible apocalypse scenarios. world taken over by a dwarf fortress ai would be the worst.
Logged

NW_Kohaku

  • Bay Watcher
  • [ETHIC:SCIENCE_FOR_FUN: REQUIRED]
    • View Profile
Re: Programmable Dwarven Computer. With Minecarts.
« Reply #43 on: June 12, 2015, 09:34:51 am »

just make sure there is a failsafe.


i think out of all the possible apocalypse scenarios. world taken over by a dwarf fortress ai would be the worst.

Isn't the failsafe that it's incredibly delicate, large, and completely immobile?  It's like being afraid of your wristwatch.  (And Java once bragged about how its code was so universal, even a wristwatch could run it...)

But still, as it is minecart based, I suppose a "doomsday squad" of giant keas could be released to steal all the mincarts it needs to think...
Logged
Personally, I like [DF] because after climbing the damned learning cliff, I'm too elitist to consider not liking it.
"And no Frankenstein-esque body part stitching?"
"Not yet"

Improved Farming
Class Warfare

angelious

  • Bay Watcher
    • View Profile
Re: Programmable Dwarven Computer. With Minecarts.
« Reply #44 on: June 12, 2015, 10:01:23 am »

just make sure there is a failsafe.


i think out of all the possible apocalypse scenarios. world taken over by a dwarf fortress ai would be the worst.

Isn't the failsafe that it's incredibly delicate, large, and completely immobile?  It's like being afraid of your wristwatch.  (And Java once bragged about how its code was so universal, even a wristwatch could run it...)

But still, as it is minecart based, I suppose a "doomsday squad" of giant keas could be released to steal all the mincarts it needs to think...

just about every ai is immobile.and depending on the host. it may be large. and most all computer programs are pretty delicate.
Logged
Pages: 1 2 [3] 4