Earlier this yr, we shared the story of how a basic NES Tetris participant hit the sport’s “kill display screen” for the primary time, activating a crash after an unbelievable 40-minute, 1,511-line efficiency. Now, some gamers are utilizing that kill display screen—and a few sophisticated reminiscence manipulation it permits—to code new behaviors into variations of Tetris operating on unmodified {hardware} and cartridges.
We have lined related “arbitrary code execution” glitches in video games like Tremendous Mario World, Paper Mario, and The Legend of Zelda: Ocarina of Time previously. And the essential methodology for introducing exterior code into NES Tetris has been publicly theorized since no less than 2021 when gamers have been investigating the sport’s decompiled code (HydrantDude, who has gone deep on Tetris crashes previously, additionally says the group has lengthy had a privately identified methodology for the way to take full management of Tetris‘ RAM).
However a latest video from Displaced Players takes the thought from personal concept to public execution, going into painstaking element on the way to get NES Tetris to begin studying the sport’s excessive rating tables as machine code directions.
Enjoyable with controller ports
Taking on a duplicate of NES Tetris is feasible largely because of the particular means the sport crashes. With out going into an excessive amount of element, a crash in NES Tetris occurs when the sport’s rating handler takes too lengthy to calculate a brand new rating between frames, which might occur after degree 155. When this delay happens, a portion of the management code will get interrupted by the brand new frame-writing routine, inflicting it to leap to an unintended portion of the sport’s RAM to search for the subsequent instruction.
Normally, this sudden interrupt leads the code to leap to deal with the very starting of RAM, the place rubbish knowledge will get learn as code and sometimes results in a fast crash. However gamers can manipulate this leap due to a little-known vagary in how Tetris handles potential inputs when operating on the Japanese model of the console, the Famicom.
In contrast to the American Nintendo Leisure System, the Japanese Famicom featured two hard-wired controllers to the unit. Gamers who needed to make use of third-party controllers may plug them in via an growth port on the entrance of the system. The Tetris sport code reads the inputs from this “additional” controller port, which might embody two extra customary NES controllers via using an adapter (that is true though the Famicom obtained a very totally different model of Tetris from Bullet-Proof Software program).
Because it occurs, the realm of RAM that Tetris makes use of to course of this additional controller enter can also be used for the reminiscence location of that leap routine we mentioned earlier. Thus, when that leap routine will get interrupted by a crash, that RAM shall be holding knowledge representing the buttons being pushed on these controllers. This provides gamers a possible solution to management exactly the place the sport code goes after the crash is triggered.
Coding within the high-score desk
For Displaced Players’ jump-control methodology, the participant has to carry down “up” on the third controller and proper, left, and down on the fourth controller (that latter mixture requires some controller fiddling to permit for simultaneous left and proper directional enter). Doing so sends the leap code to an space of RAM that holds the names and scores for the sport’s excessive rating itemizing, giving a good bigger floor of RAM that may be manipulated immediately by the participant.
By placing “(G” within the focused portion of the B-Kind excessive rating desk, we will drive the sport to leap to one other space of the excessive rating desk, the place it’s going to begin studying the names and scores sequentially as what Displaced Players calls “naked steel” code, with the letters and numbers representing opcodes for the NES CPU.
Sadly, there are solely 43 doable symbols that can be utilized within the identify entry space and 10 totally different digits that may be a part of a excessive rating. Which means solely a small portion of the NES’s obtainable opcode directions could be “coded” into the excessive rating desk utilizing the obtainable assault floor.
Regardless of these restrictions, Displaced Players was capable of code a brief, proof-of-concept code snippet that may be translated into high-score desk knowledge (A reputation of '))"-P)'
and a second place rating of 8,575 within the A-Kind sport components prominently, in case you are questioning). This straightforward routine places two zeroes within the prime digits of the sport’s rating, decreasing the rating processing time that will in any other case trigger a crash (although the rating will ultimately attain the “hazard zone” for a crash once more, with continued play).
In fact, the dearth of a battery-backed save system means hackers want to attain these excessive scores manually (and enter these sophisticated names) each time they energy up Tetris on a inventory NES. The restricted area within the excessive rating desk additionally does not depart a lot room for direct coding of advanced packages on prime of Tetris‘s precise code. However there are methods round this limitation; HydrantDude writes of a particular set of high-score names and numbers that “construct[s] one other bootstrapper which builds one other bootstrapper that grants full management over all of RAM.”
With that sort of full management, a top-level participant may theoretically recode NES Tetris to patch out the crash bugs altogether. That may very well be extraordinarily useful for gamers who’re struggling to make it previous degree 255, the place the sport really loops again to the tranquility of Stage 0. Within the meantime, I suppose you may all the time simply observe the lead of Tremendous Mario World speedrunners and rework Tetris into Flappy Chicken.