Xander Naumenko's Computerraria Implements a Fully-Functional RISC-V Computer in Terraria

RV32-I CPU runs entirely in-game, thanks to Terraria's integrated 'wiring' capabilities — and can even host a raycasting 3D engine.

Gareth Halfacree
12 months agoGaming / HW101

Canadian engineering physics student Xander Naumenko has spent more than half a year in Re-Logic's action-adventure sandbox Terraria, but not to explore or build a base: he's spent that time building a functional 32-bit RISC-V processor entirely in-game.

"I've been working on this for over six months now," Naumenko explains of his unusual project, "and thought it's cool enough that other's might be interested in learning about it. By emulating a complete RV32-I instruction set inside the wiring system of Terraria, we push back speeds to the early '70s era."

A 32-bit RISC-V CPU has been built inside sandbox title Terraria, using the game's built-in 'wiring' system. (📹: Xander Naumenko)

Terraria is Re-Logic's popular sandbox game, in which the player is thrown into a procedurally generated world with little more than their wits and a friendly guide and given the job of survival — exploring the planet, researching new technologies, mining for resources, and crafting objects. Those objects, of course, are normally of use in-game — but what Naumenko has crafted is something very different.

"Inside the game there's a mechanic called 'wiring' which lets you trigger certain tiles such as opening doors or activating traps. When I say I've 'created a computer in Terraria' what I mean is that I've completely simulated the inner workings of a regular computer, except instead of electronics I did it inside of a video game world."

The resulting computer effectively simulates a 32-bit implementation of the free and open source RISC-V instruction set architecture, and is Turing-complete — meaning that, given enough time and resources, it can technically execute any program that a traditional computer can execute. To prove it, Naumenko has written software to run atop his processor — including a simple clone of Atari's Pong and a 3D rendering engine which, admittedly, takes 45 seconds per frame.

The RISC-V implementation allows for code to run atop the computer, including games like this Pong clone. (📹: Xander Naumenko)

"In real world circuits, when a circuit is on it stays on," Naumenko explains of one of the biggest challenges faced in the project. "But in Terraria everything is just sent in pulses. This means it behaves completely differently, and a lot of traditional circuits have to be redesigned in this new paradigm."

This is, of course, not the first time a game has been used to create a functional computer: redstone blocks in Minecraft have long been used to create logic elements which can work together to form surprisingly complex CPUs, while late last year Danny Spencer became the first to build a functioning calculator in Id Software's classic first-person shooter Doom.

Compared to a RISC-V core running in a traditional simulator, the Terraria version isn't exactly a speed demon — even when a game mod vastly accelerates the operation of the wiring system: "Running without the [WireHead] accelerator mod, the computer runs at around 0.1 instructions per second," Naumenko admits. "When using the mod I get around 5,000 instructions per second."

More details on the project are available in Naumenko's video above, while everything you need to replicate the simulator in your own copy of Terraria is available on the Computerraria GitHub repository under an unspecified open source license.

Gareth Halfacree
Freelance journalist, technical author, hacker, tinkerer, erstwhile sysadmin. For hire: freelance@halfacree.co.uk.
Latest articles
Sponsored articles
Related articles
Latest articles
Read more
Related articles