Hoiktronics: Updated Computer + Binary-to-Decimal Converter

DicemanX

Brain of Cthulhu
I present my most complex wiring project to date: an improved in-game computer coupled with an automatic binary-to-decimal converter! It took over a month to figure out how to construct the converter from binary to decimal, which is the most challenging and difficult part of computer construction. I am quite happy with the final result!

This computer is capable of running arithmetic programs. All inputs are in binary (still working on decimal inputs), but the output is auto-converted into decimal and is projected onto a big screen using 7-segment displays.

Video:



Computer + Converter:

lyK06OI.jpg


Wiring:

xrLMHr9.jpg



How the Binary Computer Functions:

The computer consists of three registers:

1) 9-bit Memory Register (output via orange numbers bottom right of the player corridor)
2) 8-bit MQ Register (output via yellow numbers top right of the player corridor)
3) 9-bit Accumulator Register (output via yellow numbers above the player corridor)

The registers hold numbers from 0-255 for the 8-bit register, and 0-511 for the 9-bit registers.

3 levers control the mathematical operations:

1) The M lever (for multiplication, addition, and subtraction)
2) The C lever (complement for subtraction and division)
3) The Q lever (for determining quotients when dividing)

The 0 lever executes the CLEAR command, resetting all registers to 0.


Computer Arithmetic:

The way multiplication works is to take the information stored in the Memory Register and add it to the Accumulator Register. The number of times that the info is added is determined by the MQ Register. For instance, if the Memory Register holds 87, and the MQ register holds 5, then 87 will be added 5 times to the Accumulator Register. After the process of adding is finished, the output in the Accumulator Register will be 87x5 = 435.

Addition is essentially multiplication by 1. The content of the Memory Register is added to the Accumulator Register once. For instance, if the Accumulator Register holds 34, and the Memory Register holds 210, then 210 will be added once to 34 (so long as the MQ Register holds 1) for addition of 210+34 = 244.

Division and subtraction are more complicated, and require taking the complements of numbers. Since this is meant to be a more basic guide, I will instead give the protocols for all arithmetic operations below and let you have the fun of figuring out how everything works.


Programs:

To make the presentation of the programs more user friendly, I will use the the terms "activate" if a lever needs to be pulled, and "set" if a register needs to be set to a certain value (values will be denoted by the variables X, Y, and Z). To execute a program the instructions need to be followed from top to bottom. I will stick to basic programs for the time being, and in a later guide describe more advanced functions.

Multiplication Program:

Activate CLEAR lever
Set MQ Register to X
Set Memory Register to Y
Activate M lever

Result: Accumulator will show the outcome of X times Y.


Addition Program:

Activate CLEAR lever
Set MQ Register to 1
Set Accumulator Register to X
Set Memory Register to Y
Activate M lever

Result: Accumulator will show the outcome of X plus Y. Since the MQ Register is set to 1, the contents of the Memory Register are only added once to the contents of the Accumulator Register.


Subtraction Program:

Activate CLEAR lever
Set MQ Register to 1
Set Accumulator Register to X
Set Memory Register to Y
Activate C lever
Activate M lever

Result: Accumulator will show the outcome of Y minus X. Note that the smaller number in the subtraction should go into the Accumulator Register, and the larger number should go in the Memory Register (i.e. Y > X). This machine can handle negative numbers, but that will be the subject of discussion in a later more comprehensive guide.


Division Program:

Activate CLEAR lever
Set MQ Register to 255
Set Accumulator Register to X
Set Memory Register to Y
Activate C lever
Activate Q lever

Result: The MQ Register will show the outcome of X divided by Y. To keep it simple make sure that X is a multiple of Y to avoid non-integer values. This machine can handle fractions, but again I will describe how in a later guide. Note that the MQ Register always has to be set to its maximum value when doing division, and it's the MQ Register, not the Accumulator Register, that will hold the answer to the division problem.


Conversion from Binary to Decimal:

The converter consists of two mechanisms. The first converts from binary to BCD, and the second converts from BCD to decimal.

The mechanism to convert from binary to BCD is the double dabble mechanism:

http://en.wikipedia.org/wiki/Double_dabble

The algorithm is as follows:
1) if a number greater than 4 is stored in any of the 4-bit BCD displays after the shift, then 3 is added to that number.
2) double the number stored in the register (effectively shifting what's stored in each bit to the left)

Steps 1 and 2 are repeated N times, where N is the number of bits in the original register. Since my build has a 9-bit register, I need to shift 9 times.

Here's how the whole converter is chained:

1) After the skeleton in the computer completes the calculation, it hits a pressure plate at the very end to hoik the character NPC into the converter.
2) The NPC first passes through one of two register transfers, which either transfers the contents of the Accumulator Register to the Converter register (at the end of multiplication, addition, or subtraction), or transfers the contents of the MQ register to the Converter register (at the end of division).
3) The NPC is then teleported into a counter mechanism, which controls how many times the NPC will pass through the binary-to-BCD converter. Since the NPC needs to cycle through the converter 9 times for a 9-bit register, the counter is set up to allow 9 passes through it.
4) From the end of the counter track the NPC is teleported into the first look-up table (for the HUNDREDS BCD display).
5) When the NPC reaches the end of the first look-up table, it teleports into the next look-up table (for the TENS BCD display).
6) When the NPC reaches the end of the second look-up table, it teleports into the final look-up table (for the ONES BCD display).
7) When the NPC reaches the end of the final look-up table, it teleports back to the counter mechanism and the protocol resumes from step 3.
8) Once the NPC completes 9 loops, the tenth time it passes through the counter it gets teleported into the look-up tables for the BCD-to-decimal conversion.

The look-up tables in the binary-to-BCD converter add 3 to any number in the HUNDREDS, TENS, and ONES spot that is 4 or more; in other words, the look-up tables convert 5 to 8, 6 to 9, 7 to 10, 8 to 11, and 9 to 12. The look-up tables in the BCD-to-decimal converter convert the digit in BCD to decimal. The result of the conversion is displayed in the screen with three 7-segment displays.


World Download:

http://www26.zippyshare.com/v/RUPExVrM/file.html


ZeroGravitas' Guide to Hoiktronics:

http://forums.terraria.org/index.php?threads/hoiktronics-what-is-it-guide.8371/
 
Last edited:
The computer is fully expandable, and can be extended past 9-bit easily if constructed and wired this way:

gmy8WLw.jpg


Since some have brought up the question of expansion, my set-up features repeating units that can be easily copied and pasted in TEdit to increase the size of the registers significantly.

Here's a quick example of an expansion:

fJtl1gv.jpg


The computer depicted now has 12-bit accumulator and memory registers, and a 10-bit MQ register.

The only issue with this set-up is the labeling. Those statues take up a ton of space, and there isn't any other good way to number the bits (1, 2, 4 etc.)
 
Last edited:
I added a video tutorial to fully explain how the computer is built:




I also made improvements to the inteface. Now there is no longer a need to pull multiple levers to set up the calculations - one lever pull is enough:

1BC604471CDDA47178A3874EAFF7456036F2F962


The interface now has:

M lever for multiplication
D lever for division
A lever for addition
S lever for subtraction

Division and subtraction both require taking the complement of the number stored in the accumulator register, but now that is automatically triggered when pulling the D and S levers. Also, addition and subtraction required entering 1 into the MQ register, and now that's done automatically as well when the A and S levers are pulled.

Here's the wiring, illustrating how the MDAS levers are connected:

ED90A3F231823C13F42F301A45105033D8F58B3C
 
Last edited:
Looks awsome, I wish I understood binary a bit more, when I do i'll come back and read it all if I remember to.
 
Looks awsome, I wish I understood binary a bit more, when I do i'll come back and read it all if I remember to.

It's a great way to learn about binary numbers, BCD, conversions, and how ALUs function. When I started I didn't know most of this stuff myself, but I learned all about it by trying to build the ALU + converter in Terraria. Who knew that Terraria was going to be so educational in the long run! ;).
 
Back
Top Bottom