Bored students can now enjoy Sonic 2 on TI-84 Plus CE calculators, thanks to port

Blast (processing) from the past

Retro interview Just a few weeks ago, Sonic the Hedgehog 2 was ported to the TI-84 Plus CE graphing calculator.

Playing retro games on calculators is nothing new, with Tetris, Breakout, and even Super Mario Bros 3 having fan-made ports to Texas Instruments' popular calculator.

However, no games featuring the blue hedgehog ever made it to the small screen – until now. GitHub user grubbyplaya, who also goes by grubbycoder, ported 1992's Sonic the Hedgehog 2 to the device, making it the first Sonic platformer game we're aware of now available for the calculator. Source and binaries have been released; yes, it's completely unofficial.

The dev was inspired to port it after watching a video by the This Does Not Compute YouTube channel on the history of gaming on calculators. When the mini documentary mentioned that some of TI's calculators used 8-bit Zilog Z80 and 16/32-bit Motorola 68000 CPUs, it caught grubbycoder's attention. Those chips were also used by Sega's Master System and Genesis (or Mega Drive for those outside North America), so porting Sonic from one of those consoles to the TI calculator should be reasonably fun to do.

"That really piqued my interest, since I already knew the processors that Sega's retro game consoles used: The Z80 for the Master System, and the M68K for the Genesis," the programmer said in his documentation of the port.

"Aside from that, I also really wanted to make my own calculator game, or at least port an existing one," grubbycoder told The Register. "Doom's a bit too big to fit into the 84 Plus CE's storage, so that's part of the reason why I stuck with games in the 8-bit to 16-bit range. Of course, I did rule out any 16-bit games later on."

I really wanted to make my own calculator game, or at least port an existing one

However, grubbycoder didn't port the Sega Genesis version of Sonic 2; instead, he used the version made for the 8-bit Sega Master System and Game Gear. This was down to the fact that the biggest TI calculators based on the 68000 CPU didn't have a good enough screen resolution for the 68000-based Genesis version of the game.

By contrast, the TI-84 Plus CE with its Zilog eZ80 chip (which is essentially a 24-bit Z80 with extra bells and whistles) has a 320 by 240 pixel display, which is more than enough for the 8-bit Master System and Game Gear version.

Choosing the TI-84 Plus CE also meant grubbycoder's choices for what Sonic games to port were limited. Today, the only fully disassembled Sonic game on the Master System is Sonic the Hedgehog 2, so that was the one he went with.

"Most of the other games people really want, like Sonic 1 8-bit and Sonic Triple Trouble, only have partial disassemblies," grubbycoder says. "If I were to start porting them, most of my work would just go to reverse-engineering the entire game."

Porting even a disassembled game was a challenge

On paper, it would seem the TI-84 Plus CE is perfect for an 8-bit Sonic game. Its eZ80 clocks in at 48MHz, much higher than the Master System's Z80A at 3.58MHz, and has 256KB of RAM, more than ten times as much as the Master System's combined 8KB of RAM and 16KB of VRAM.

However, those hardware advantages are dinged by wait states that could drag down the eZ80's actual clock speed to 12MHz; a per-file size cap that forces the use of multiple files for any data larger than 64KB; and the complete lack of any console-like graphics acceleration. The extra processing oomph needs to be used on filling those gaps.

Plus, the TI-84 Plus CE will crash if any game code tries to access what it expects to be an I/O port on the Sega console – such as if the game tries to talk to the console's audio system, color palette hardware, and VRAM. Those IO accesses needed to be rerouted and translated on the calculator to prevent a crash and make Sonic 2 play as expected.

Additionally, grubbycoder had to use an assembler for the TI calculator that was different to the one used by the Sonic 2 disassembly project he based his port on, which brought about compatibility hurdles, and he wasn't an expert on the Z80 nor the TI-84 Plus CE.

"At first, I only had a very beginner-level knowledge of Z80 assembly, which meant I made some really stupid decisions with handling some stuff which came back to bite me later," he says.

"As the complexity of emulating features of the Master System grew, I eventually had moderate-level knowledge of how the TI-84 Plus CE works," grubbycoder told us.

Assembling the game from the disassembly source was the first task, and while the TI-friendly SPASM-ng assembler did much of that work, grubbycoder still had to review 20,000 lines of code to make sure everything was compatible with the TI-84 Plus CE.

Getting around the I/O accesses wasn't terribly difficult as it turned out, because the calculator's hardware supports memory-mapped I/O requests. The port just needed tweaking so that its I/O port requests go to the calculator's memory-mapped IO locations, with some glue code to act as a compatibility layer. The game thinks it's running on and talking to Sega hardware, but is actually interacting with a TI calculator.

"It was mostly just a minor inconvenience," grubbycoder says, noting that video color palettes were the most complex to implement at the hardware translation layer.

Unfortunately, there were two parts of the port that really couldn't work they way they did on the Master System. Firstly, the Master System used ROM banking to swap in and out the memory map chunks of data as needed, since the old-school console could only address 64KB of data at any one time and the game is much larger than that. On the TI-84 Plus CE, this is relatively slow because it relies on flash storage to copy data into RAM when needed, since there wasn't enough room, even with 256KB of RAM, to put every single bank into memory all at once.

The other problematic part was the renderer, since the TI-84 Plus CE has no graphics acceleration hardware to speak of. A 16-bit multiplication instruction present in the eZ80 helped speed up sprite and tile plotting in software, in terms of calculating the location of the graphics.

That said, handling the tile-based background was a challenge. Sega's console hardware provides lots of support for rapidly arranging and scrolling Sonic's levels, and that acceleration needed to be emulated on the calculator's eZ80.


Screenshot of the port's graphics software renderer mid-development

Grubbycoder implemented this with a 56KB framebuffer in the TI's VRAM and a caching system that reduced the tile rendering time by a factor of eight, allowing the game to actually be playable.

The intro of Sonic the Hedgehog 2 on the Ti-84 Plus CE.

Starting up the port and getting the intro rendering

While not a perfect conversion, on the whole it runs, it's a cool programming project, and it's not even that different from the original version. "Technically, the 84 Plus CE port retains 90 to 95 percent of the original 8-bit Sonic 2 code," grubbycoder says. 

There's no audio since the calculator doesn't have speakers, and deleting the audio code and materials made the game smaller at least. The framerate is lower than the 60 FPS Master System owners would have enjoyed. "On base 84 Plus CEs, which was the model emulated in testing, the game runs at about 53 percent speed with the normal build," the dev says.

There is a fast model of the game that runs at 74 percent speed, but this version has no enemies, bosses, or even the goalposts that signal the end of levels, meaning even the first level cannot be completed.

"The slowdown is almost entirely due to ROM banking, specifically swapping in banks that contain logic for Sonic, all the Badniks, and every gimmick in the game," grubbycoder says.

"If the calculator didn't have wait states, then it wouldn't be a problem at all, but other solutions include converting those banks to run in the 84 Plus CE's 24-bit mode, so they just be jumped to instead of loading them in all at once."

But technically, if one very bored student with only a calculator to fiddle with wanted to beat Sonic the Hedgehog 2 from start to finish and would tolerate a somewhat bad framerate, it's very possible. Though nowadays high-end calculators equipped with Arm CPU cores, such as the Nspire, can run actual Genesis games, and may be the better option for those looking for the best calculator gaming experience, grubbycoder says.

Still, the developer is looking to add more Sonic games to the 2015-era TI-84 Plus CE. "In the future, I would like to try remaking some more obscure Sonic games for the calculator," he says.

"They wouldn't be the platformers everyone's familiar with, but some of the LCD games by Tiger Electronics and the Sonic Adventure Gamebook series are what I'm mostly interested in remaking." ®

More about


Send us news

Other stories you might like