Programming the Sensational Tetris in 2024

There is no game more important to the gaming industry than Tetris. Since its release in 1985, it has sold over 200 million copies, making it the best-selling game ever. Since its inception, this little game from the USSR has been featured and ported to more consoles than any game in existence, even more than Skyrim. Accolades aside, we will find out how to break Tetris to get further than ever in the game by bypassing areas of code that cause the game to crash. A fair warning: this may get a little technical, but I promise it’ll be a fun journey!

Which Version of Tetris

https://://gty.im/2145151449

For this, we’ll be using the NES version of Tetris. Displaced Gamers outlined how to do this in his video on the subject. He goes through the technical aspect of the game by looking at its Assembly code and what exactly what crashes the game. They’re great videos and took a long time to make, so give the guy some love and watch his videos.

We’re using this version of Tetris because we can more easily manipulate the code using controller inputs and edit ROM addresses using specific name entries in the high score section. We’ll cover that later in this article. Normally, when playing the game, you can make it to about level 150-155 before the game crashes due to how the logic adds up the score. Let’s cover that now!

Crashing Tetris

The crash happens because of how Tetris is programmed, not because it was an oversight but because adding up the score takes too long. Essentially, the math behind the scoring becomes so intense that the CPU can’t handle it, so the logic stops.

There is this section of the code we’ll call the jump handler that will run so many times per cycle. Inside this jump handler is an interrupt where the game stops the logic in order to draw the next frame, once the next frame is done, the CPU returns to the jump handler where it left off. The crash can happen during this interrupt where bites 0 and 1 have different values before and after the interrupt.

The jump handler’s main job is to tell the game where to go next. If the bites are different from before and after the interrupt, the game has a high chance of crashing.

Crash Theory

The Tetris Community has made this nifty little spreadsheet with a calculator that gives you the percent chance of a crash occurring. It has five different types of crashes, including Standard, Press Down (PD) < 7, Press Down  (PD) > 7, No Next Box (NNB), and Clear Count (CLR Count). This document is amazing as it’ll tell you how likely the game is to crash from levels 155-255 based on clearing lines, clearing lines that advance you to the next level, and even something as simple as landing a piece.

The Jump handler is called multiple times per frame, and we want to meet crash criteria. It has to be specific crash criteria, and what we’re looking for is standard. Let’s go over how each one crashes the game. For now, we’ll focus on transitioning from levels 154-155.

While clearing lines isn’t the only to score points, pushing down on the controller to accelerate the piece will also add points to your score. The higher up you press the down button, the more points you score. There are two sections for pushing down in the spreadsheet, and they are separated by whether you score more or less than 7 points. When transitioning from level 154 to 155 there is about an 87% chance to crash the game.

No Next Box is a technique used by players to cancel the next blocks from appearing. By pressing select you can remove this piece from the box. This specific box doesn’t have a chance to crash the game at this point. while you have a 90% crash by clearing lines, pressing select will dodge this crash criteria.

The clear count is the least obvious one. Tetris tracks the types of clears throughout the game, with single, double, triple, and Tetris all being tracked. These counts are not visible to the player because they’re only stored in RAM. You can view these by using an emulator, but that won’t help us when we’re playing on a cartridge. If the count crosses a multiple of 10, it may determine if we crash or not.

However, if we don’t press down, don’t clear the next box, and our clear count doesn’t surpass a multiple of 10, then we’ll get a standard crash with a 100% chance. This is the criteria we’re looking for. How do we achieve it? In the Google sheet I shared above, you’ll notice the boxes are colored. This indicates what part of the code in the jump handler that crash is referring to. So, how do we set this up?

Intervention

Knowing our target crash criteria, all we have to do is set Tetris up to meet our goal. Once we get that figured out, we still need a little help by adding additional controllers. By combining our knowledge of Tetris with extra controllers and specific name entries in the high score section, we can temporarily eliminate any crash coming our way for over 10 levels!

How is this possible? As I mentioned above, you’ll need extra controls, as they play a major part in advising a crash. The button presses on the NES controller are read by memory addresses $4016 and $4017, and most games use a simple loop for reading inputs, storing them in RAM, and finally reading those inputs from RAM. You’ll need an expansion cord to add a controller to the third and fourth ports.

Tetris does it a little differently by adding extra lines of code that shift the bits into a specific memory address. Which one? Well, the game combines both controller inputs and writes that data to RAM addresses  $0 and $1: both RAM addresses used by the jump handler to determine what our destination is. The two very same bites are responsible for our crashes. 2 controllers, 16 presses, and the only question left is, where do you want to go?

Making It All Make Sense

All in thanks to the spreadsheet we know when the crash will happen, we know what memory addresses are affected, and we know how to modify those bits using extra controllers to go wherever we want to go. First we need to know what our controller presses need to be and how to reduce to variables of where we end up. To do that we need to look at the name entry screen for high scores.

The name entry screen on the B-type high score screen actually shares a RAM address with where we want to go. RAM address $727 is, but now we need a look-up address. The one we’re looking for is $719, which also shares memory with a name on the B-type high score table.

Figuring out what controller presses are needed is easy enough. We need to load the bits 7 and 8 into memory. To do this we need to simply press up on controller 3 and hold it, and every press on controller 3 counts as input for controller 1. The next press is a little harder as we’ll need to press down, left, and right at the same time. Anyone who has played on an NES knows this is next to impossible unless you have a particularly worn controller to pull it off.

The good news is that Controller 4 won’t affect gameplay at all. While controller 3 will, pressing up does nothing in Tetris. The bad news is that you’ll either have to build a controller yourself or modify one you have by sanding down the plastic nub the D-pad uses to pivot on. Now that we have that taken care of, let’s talk about how actually to program the game to do something.

Moment of Truth: Programming Tetris

The high score table takes up a large portion of the RAM that we’re trying to read with our controller presses. To do this, you’ll have to play the game and obtain some high scores. From there, you’ll need to input specific characters in certain slots. We want to overwrite slots 2 and 3 on the A-type and slots 1 and 3 on the B-type high score tables.

The names we want to input aren’t anything crazy, fortunately. Let’s start with A type. The first name should be changed to (G as the second and third characters. The second name should say only ))”-P) for all characters; this will be important for later. The third name should be set to GB( as the first three characters. The rest of the characters aren’t relevant to us and aren’t used for our trick.

Finally, we’ll have to write some Assembly code using the B-type high score table, and I promise it won’t be as bad as you think. On the 3rd slot for the name entry, the first three characters don’t matter, but the last three should include 5FG. Doing this will make a jump in the code to the second name entry in the type A high score table. Once all the names have been entered, the second slot in the A table must have a high score of 8,575, which is a steep requirement.

I’m almost done talking about scores, but the last requirement is to obtain a score for the B table. While the name doesn’t matter, the score itself does somewhat. The top third of the score must be 008, and the bottom third must end in 60. The example in the video is 008260.

Summing Up

Tetris

With all the prep work we’ve done, we can finally get past level 155. Using this method should take us to level 169 before the game crashes again. We’ve changed our score using RAM addresses so the game doesn’t crash while calculating the score. This has many more possibilities, but now you have the tools and knowledge to pull it off.

If you’ve made it this far, I commend you! This article took about a week of research to complete, and I didn’t even cover some of the more technical aspects. Tetris, on its surface, is a simple game. By understanding a little bit of the code and how the console handles controller inputs, we can take this game much farther than the developers anticipated. Just because a game has aged doesn’t mean it can’t have something new to offer us.

I know I link Displaced Gamers‘ video above, but I’m going to link it again. The way he explains the whole process is presented in an educational and entertaining way. If you’re into the coding behind games, I strongly urge you to check out his other videos, as he covers a lot of retro games and how they work.

For More Great Content

If you enjoyed a trip down memory road with me, check out how the Game Boy Color made a kid cool! For other content by me, click here. I would greatly appreciate it! For other great tech content, check this out!

Total Apex is an all-encompassing content producer. We provide heavily detailed articles every day on entertainment, gaming, sports, and so much more! Check out all our great sports content at Apex Sports. Check us out on X @TotalApexEandG and our other sites: Total Apex Sports Bets and Total Apex Fantasy Sports.

About the Author

Phillip is an avid gamer and loves football. He loves all types of games ranging from video games, TTRPGs, and board games, and loves to learn about coding and game design. During the football season, he can be found cheering for his favorite football teams, usually with an elevated heart rate and a jersey on. His social media handle is Phillip Bentle on Facebook.

Share this post

More stories from Total Apex Gaming

Total Apex Gaming Sports Entertainment Fantasy Sports Sports Bets is the only destination you'll need for all of your daily content.

Scroll to Top