Building a Minecraft Computer Taught Me More About CPUs Than University Did

ReFruity1 pts0 comments

Building a Minecraft Computer Taught Me More About CPUs Than University Did

I am a CS bachelor and an experienced software engineer. I want to tell you about one of my hobbies, or even obsessions, which I never imagined would be so much fun. This hobby is building computers in Minecraft, and also writing software for them. This is a very niche area, so with this article, I hope to excite more people about computational redstone and maybe inspire them to build cool projects.<br>My Story<br>I played Minecraft since its early Alpha, and fell in love with building redstone circuits back in school. Stuff like automatic farms or piston doors in survival. But only much later did I discover how powerful redstone can be. For example, you can make a fully functional CPU and Atari-like games for this CPU: Space Invaders, Tetris, or Breakout. Just like with the real game console, your hardware is the same, and the only thing that's different is the program you load in.<br>One day in 2020, I randomly decided I wanted to build a CPU in Minecraft because I had seen some videos of people doing that on YouTube before. I never imagined how deep that rabbit hole takes you, and how engaging it is. I finished the CPU; it was enormous and not very powerful: the most it could do was a Fibonacci program. [1]<br>Not enough memory for sorting, not to mention games.<br>My first nameless CPUThen I thought: "There must be a better way to do this."<br>And, of course, there was. Take a look at "CHUNGUS II" CPU from Sammyuri. I suggest you watch this cool video presentation. [2]<br>CHUNGUS II made by SammyuriThese builds were a breath of inspiration for many people, including me.<br>Why Minecraft?<br>Mainly because it's really fun. There is something special about making builds in this computer game. The visual component plays a big role.<br>In Minecraft, when you are using redstone, you can see the logic behind your computations unfold before your eyes in 3D space. You can trace a signal back to its origin or follow it to the destination. And then see the lamps on the display light up or a wall open itself like a big door. It is a highly dynamic medium.<br>In real-life circuits on a breadboard, the inner workings are hidden from you. You don't even see outputs without a multimeter or a dedicated lamp. In Minecraft, it's different: you can see every signal and how it travels in real time.<br>You learn a lot while building, and you have to plan ahead. Building a CPU is impossible without knowledge of redstone mechanics, logic, binary, ISA design, some building tools, and more.<br>Building a CPU is a complex task because you have to keep a mental model of the CPU in your brain and understand how high-level components work together at every moment. However, these high-level components consist of very simple primitives.<br>Primitives<br>Logic Gate AND<br>Let's take a look at an AND gate and its differences from the real-world counterpart. In a real circuit, you will have a ground node, which is used as a point of reference for voltages. Usually, high voltage encodes 1, and low voltage encodes 0.<br>In Minecraft, you do not have voltage; instead, you have signal strength. This is a value between 0 and 15. Some components can emit a signal. Some components can be triggered by this signal.<br>0:00/<br>1×<br>AND GateAs you can see on the video above, the Out is only ON when both inputs A and B are ON.<br>XOR Gate<br>Only ON when exactly one input is ON.<br>0:00/<br>1×<br>Memory Latch<br>This is the base for almost all rewritable memory in CPUs. For example, RAM and registers store bits like this. Notice how when the top lever is ON, the bit value inside the repeater becomes locked.<br>0:00/<br>1×<br>Barrels<br>Depending on the number of items in the barrel, it can encode a signal strength from 0 to 15. That is 16 possible valies, so they are used to store 4 bits of data. Usually a comparator is used to extract the 4-bit value from the barrel.<br>Barrel storing signal strength 7Carry Cancel Adder<br>The arithmetic logic unit, or ALU for short, is the circuit inside a CPU that behaves like a small calculator. It can add, subtract, and do bitwise logic for two 8-bit numbers.<br>The adder is the base of any ALU. Unlike modern high-performance processors that usually use some type of parallel prefix adders, the most common adder used in Minecraft CPUs is the Carry Cancel Adder (CCA). [3]<br>0:00/<br>1×<br>CCA calculating 127 + 1 = 128ALU<br>The CCA is then modified to support calculating bitwise operations like AND/NAND. Sometimes the right shift operation is also added if the CPU ISA requires it. The result is an ALU.<br>ALU calculating 3 XOR 5 = 6Registers<br>Registers are the fastest memory inside CPU. Together with ALU they form a "Dataloop", the main part of CPU which executes read/calculate/write data cycles.<br>Usually CPUs have more than 1 register, so it makes sense to put them together in one "Register file". You can see my latest Nori CPU's register file on the picture below. In the middle we input number 5 with levers, then read it on both left and right...

minecraft building like signal cpus redstone

Related Articles