This RISC-V CPU Games In Rust From Inside The Game

[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!

14 thoughts on “This RISC-V CPU Games In Rust From Inside The Game

  1. I fear that if one iterates further in this operation, a spontaneous recursion will result in taking us either forward or backward to The Singularity.

    1. Line break? Paragraph break? page break?

      Yeah I read that all the time and wondering why. Maybe it was a podcast and contained a marker for ads? Or was this just a pattern chatgpt picked up and felt that an article isn’t an article without the reference ‘after the break’.
      Or maybe journalists/editors like the term and think it looks cool or are scared people don’t notice the article continues after ads, who knows?

      1. The “break” is a WordPress thing. You insert a break marker so that wordpress knows where the summary (what’s displayed on the main page before you click through) ends. If the HaD article is short and there’s an embedded YouTube video, the editors put a break before the video so it doesn’t show up on the main page. Often there’s more text as well. Hence having to click through to the video “after the break”.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.