[Xander Naumenko] has created something truly impressive — a working RISC-V CPU completely contained in a Terraria world. And then for added fun, he wrote the game of pong, playable in real time, from within the game of Terraria. It’s all based on the in-game wiring system, combined with a bit of a hack that uses the faulty lamp mechanic to create a very odd AND gate. In Terraria, the existing logic gates have timing issues that make them a no-go for complicated projects like this one. The faulty lamp is intended to do randomized outputs, by stacking multiple inputs to get a weighted output when a clock signal is applied. The hack is to simply give this device a single input, turning it into a clocked IF gate. Two of them together in series makes a clocked AND gate, and two in parallel make a clocked OR gate.

Why would [Xander] embark on this legendary endeavor? Apparently after over eight thousand hours clocked in game, one gets a bored of killing slimes and building NPC houses. And playing with the game’s wiring system turned on a metaphorical lightbulb, that the system could be used to build interesting systems. A prototype CPU, with a completely custom instruction set came next, and was powerful enough to compute Fibonacci. But that obviously wasn’t enough. Come back after the break for the rest of the story and the impressive video demonstration.

Surprisingly, playing three months playing Terraria has improved my career prospects.

After this prototype worked, the obvious next step was to use the RISC-V specification to build a rv32i processor. And a display. Because the CPU must be able to game. The full version has a problem, though. It’s huge, and Terraria really, really isn’t designed for wiring projects this complicated. So naturally, [Xander] just rolled up his sleeves and re-wrote the Terraria wiring system, in the form of the WireHead mod. By a series of tricks, like looking at wires as a whole, instead of each individual tile, he managed to make the cpu run at a blistering 5 MHz. Fast enough for pong, but slow enough that Conway’s Game of Life has to be watched in fast forward.

The whole thing is very reminiscent of the Nand2Tetris course, as well as the equally impressive Minecraft computers we’ve covered before. And there’s even more fun to come for Computerraria, as a low-res Doom clone is being worked on, as well as video playback for the well known Bad Apple. It’s all open source, and ridiculously well put together, so go take a look!

Source: https://hackaday.com/2023/07/17/this-risc-v-cpu-games-in-rust-from-inside-the-game/