Sprite Scaling on the Master System: Building the New on the Ruins of the Old
Sprite scaling. It is the coolest effect of the 2D arcade era, a must-have for games from Space Harrier to Real Bout Fatal Fury Special. Home consoles pretty much lacked it– sorry, Nintendo, but Mode 7 only scales a background, not sprites. So therefore you might be surprised to hear that Sega’s plucky underdog Master System could do it. Well, don’t get your hopes up; this is far too limited– calling it scaling is overstating things. But let’s dig in anyway!
History
The Sega Master System is the direct descendant of Sega’s first console, the SG-1000. In fact, in Japan it was called the “Mark III”; the third redesign, after the SG-1000 II that ditched the hardwired controller. While Sega was a hardware company, there’s pretty much nothing “Sega” about the original SG-1000 design; it’s made of off-the-shelf parts, pairing a Zilog Z80 with Texas Instruments’ SN74689A sound chip and TMS9918A Video Display Processor (VDP).
And that VDP is the starting point here. It was used pretty much everywhere, from TI’s own TI-99/4A computer, to the ColecoVision, the MSX1, the Nichibutsu My Vision, the Tomy Tutor, the CreatiVision… It just keeps going. The TMS9918A introduced the modern concept of “sprites” to home machines.
TMS9918A sprites could be used in any mode except text mode. They were single color, 8x8 or 16x16 pixels, and you had 32 of them at a time, with only four on each scanline. This might seem very limited, but compared to the player/missile/ball of the Atari 2600, it was a game-changer.
The Atari 2600 had the ability to expand the pixels of its movable objects horizontally (of course, on the Atari, everything was horizontal). And the TMS9918A had that capability too, for both horizontal and vertical; the TMS9918A datasheet refers to this bit as “MAG”, for magnification. It expands sprites horizontally and vertically. You can see it used here in Champion Boxing.

Now, “MAG” mode is a single bit in a VDP register. It applies to all sprites on screen at any given time; in Champion Boxing, the reason the boxers aren’t scaled is because they’re actually made of background tiles, not sprites. So this wasn’t the most commonly-used effect, but it’s definitely out there.
Why do I talk about this? Because the VDP on the Sega Master System is a direct descendant of the TMS9918A.
The Sega Master System
The Sega Master System made two major changes to the TMS9918A. The first was that it switched from hard-coded colors to a 6-bit RGB output, producing the infamous compatibility palette I whine about on this blog all the time.
But the second was that it added Mode 4. Mode 4 provided a tilemap made out of 8x8 tiles, 16-color palettes, an an entirely rebuilt sprite system. In a very real sense, Mode 4 is the Sega Master System. Every licensed game used it. Yes, even F-16 Fighting Falcon; it just used it on the title screen, though when actually flying the plane it used TMS9918A modes.

But on the first generation of Master Systems, those that used the Sega 315-5124 VDP (often called “SMS1”), the new mode was built on the ruins of the old. Take, for example, the tilemap mirroring bug. An extra bit, which we call the “mask bit”, in the VDP’s Register 0x02, which is supposed to set the high bits of the tilemap address, ends up interferes with the tilemap scanning instead; if you set this bit to 0, then games using the 315-5124 VDP will repeat the top 12 rows of the tilemap over the bottom 12.

The game Ys relied on this behavior in its Japanese release as part of its status bar. (A full screen status bar in a fixed location at the bottom of the screen is pretty hard on the SMS!) You can see the town looks perfectly normal above, which is on my Japanese Master System. But if I play it on my French Master System 2 instead…

Thankfully, the translated release of Ys no longer relies on this behavior, and every Master System and Mark III sold in Japan had the 315-5124 VDP, so this wasn’t a real issue in practice for this game.
There are all sorts of strange states you can get the SMS1 VDP into by messing with the registers. We actually have Sega’s official Master System documentation, and you can see how they handled this; they basically just told users to always set or unset certain bits, either explicitly, or by only providing valid values with those bits set. One of those bits was MAG, which was ordered to be always set to 0.
Sega Master System sprites
Mode 4 sprites are an entirely new system. There are now 64 possible sprites, not 32. Their arrangement in memory is entirely different. There are only three bytes per sprite attribute table entry instead of four. You can have up to eight sprites per scanline, instead of four. Sprites can still be 8x8 pixels, but the 16x16 sprites are replaced by narrower 8x16 sprites.
But on the 315-5124, the new is based on the ruins of the old. It’s fairly clear to me that Sega or Yamaha’s hardware designers didn’t actually intend for sprite magnification to be a feature of the VDP. But the sprite systems aren’t independent, either. We already know that– the “mask bit” applies to the sprite table register as well. But I don’t know of any games that rely on it; because of the way the memory is laid out, it just limits how many tiles you can use for sprites, which is pointless.
So the sprite magnification bit does work on the SMS1. But there are a few heavy conditions.
First off, only four sprites can be magnified in both directions. Take a look at this dialogue scene from a game I’m working on. Notice that Ava is made up of magnified sprites. But there’s only one character on screen. Ava is made up of magnified 8x16 sprites.

But also, there’s something you can’t see here. Even though Ava is only made up of four sprites per scanline, there are four more sprites on each scanline. They’re just invisible and off-screen. Why would I do that? Do I just like being wasteful? Well, clearly yes, but that’s not relevant here. Because if I don’t have the placeholder sprites, I get this:

The 315-5124 VDP can in fact scale eight sprites per scanline, but only vertically. Horizontally, only the first N-4 out of N sprites on the scanline will be stretched. For example, if I only put two placeholder sprites, I only get two horizontally scaled sprites.

This is kind of a pain to deal with, which is probably why there are no commercial games designed for the 315-5124-capable systems that use sprite scaling. It does create some funky effects, though.
The bare minimum on the Genesis
Sega, in their magnificent wisdom, seems to have completely reimplemented the Master System’s Mode 4 at least twice. The first was for the 1988 Sega Mega Drive, known as the Genesis by me. We’ve already seen a strange bug in the Genesis’ Mode 4 that ALF triggered, but at least in that case, the Genesis VDP also has the capability of sprite collision detections in Genesis mode (“Mode 5”) as well.
Essentially every feature that wasn’t used in Genesis mode is gone in the compatibility Mode 4. While the 315-5124 was built on the ruins of the past, Genesis compatibility is built on the ruins of the future. The TMS9918A modes are gone (sorry, F-16 Fighting Falcon), and the mask bit issues they brought with them are gone too– so this is the one case Japanese users had to run into the bug in Ys.
Magnified sprites on the 315-5124 were a leftover from the TMS9918A, and they’re gone too. For these tests, we’ll be running on my Sega CDX. The Power Base Converter does fit just fine on this, though it looks kind of weird.

If I run my same program from earlier, no matter how many placeholder sprites I have, Ava just explodes.

F-16 Fighting Falcon also doesn’t run, but the title screen works, and few genres have aged as badly as outdated flight simulators anyway. I also don’t have two Master System controllers anyway…

Interestingly, apparently Master System games can trigger Mode 5 by toggling an appropriate bit in the VDP status. I have no idea why anyone would do this, unless you have a grudge against the 68000 and the YM2612 or something, and of course no commercial games did.
A coherent whole
After the Mega Drive, Sega released a cost-reduced model of the Master System, generally called the Master System 2. (But it was the Master System 3 in Brazil) That used, for some reason, a rearchitected VDP, the 315-5246.
Why did they redesign the VDP? I’m not sure, but my suspicion would be that it was because of the Game Gear, which released in 1990 in Japan and 1991 in North America and Europe. The Game Gear is based on the Master System, but has a new mode with a lower resolution and higher color resolution, along with outputting a signal for an LCD rather than a CRT TV.
Whether the 315-5246 is derived from Game Gear work or not (if we had die shots, that might make it clear), it’s clear that it is a new design. Whereas the original SMS VDP was built on the ruins of the past, and the Genesis VDP provided the bare minimum for compatibility, the SMS2 seems to have been designed as a coherent whole. Backwards compatibility with the TMS9918A is still provided in the same colors, which makes me wonder if a Japanese release was planned.
A particularly odd choice on the 315-5246 is that it provides two new graphics modes; 224-line and 240-line variants of Mode 4. (Original Mode 4 is 192-lines, same as the TMS9918A) These have slightly different sprite behavior, and 240-line mode doesn’t work in NTSC or on the Game Gear. In Europe, the SMS2 was by far the most common model, and Codemasters actually used the 224-line mode in some games, like Micro Machines. You can see how my SMS1 can’t handle their absolute brilliance.
Interestingly, it works a little better on the Genesis, and I can get into the game. Where the scrolling is all screwed up, because the Genesis also doesn’t support the 224-line or 240-line modes. (Being an NTSC console probably doesn’t help either) It’s just interpreting all the calls for the usual 192-line mode, and that’s close enough to mostly work on a good day.

But we’re here to talk about sprite scaling. And I’m glad to say that the SMS2 just supports sprite magnification the same way everywhere, treating it as an actual feature of the sprites. All sprites are properly doubled in size. Since all Game Gears use a similar VDP, while Sega’s official documentation for the Game Gear still says not to use it, some games did anyway, like X-Men on the title screen.

Most emulators seem to replicate the Master System 2’s behavior. Sometimes they’ll do both, with double-sized sprites acting like the 315-5246, while also having the older mask bit behavior to make Ys work. And of course, even with no placeholder sprites, Ava shows up just fine.

As a developer…
What does this mean for the homebrew developer? Well, the easiest option is what essentially all commercial game developers for the console did: don’t use TMS9918A modes, and don’t use sprite magnification. Mode 4 is good enough. Zoomed sprites are weird anyway, what with having different sized pixels and all.
Know your market. The 315-5246 was more common in Europe, but the 315-5124 was more common in America as far as I can tell, and pretty much universal in Japan. The Genesis in all its forms is way more common than either, and so a lot of modern homebrew players will be using that to play Master System games too, so you probably don’t want to leave them out. (Similarly, make sure you support the Genesis controller, even if you don’t use the extra buttons) Well, not the Genesis 3.
What am I doing? I’m so glad you asked!
When the game boots up, I detect whether zoomed sprites are supported at all by doing a simple test. Two sprites are set up so they will overlap if zoomed sprites are supported, and if they’re not, they won’t. This works perfectly; the Genesis still supports the collision bit, and I know how to avoid the ALF bug. This is very quick and the screen is blacked out while it happens, so you don’t see anything.
On both Master Systems, I just treat it like it’s using the older 315-5124 VDP. The placeholder sprites don’t do any damage on the SMS2. While this means I can only have one character on screen at a time, it also means that I can use the full sprite palette for one character, which is a fair tradeoff in my book, as it means I can reuse sprites from Space Ava 201 more easily.
What about the Genesis? Well, players there will get to see a full sprite as well. Sorcery? No, just using the full eight sprites, and including a pre-doubled fallback image in the ROM.

This takes four times as much VRAM. So what’s the point? Well, on the Master System, I can use that for four frames of animation. Master System players get a slightly better experience, but the game is still playable on Genesis.
…That being said, there is a possible alternative I’m toying with. The Genesis should be able write to VRAM at the full speed of the Z80 during active display; the Master System VDP in either of its forms can’t. So it’s possible that I might be able to get away with animation by just constantly writing the new frames to VRAM. I’d have to store many more pre-doubled frames in the ROM, though, so even with compression this would be a bit painful, and the doubled-sprites are very large. Maybe I could do some diffing logic as well? My animations are pretty simplistic. Right now it’s not a priority, but watch this space.
