Wednesday, May 3, 2017

There's something in the water

Last time we saw that the Mega Drive has a theoretical limit of 64 colors on screen at any given point. In reality, it's even lower than that. But let's take a look at this screenshot:


If you were to count them, you'd find that there are 68 unique colors in this image alone. So what's going on? Did we find some extra CRAM hidden somewhere? There's no way the hardware is doing the things it is doing.

And in fact, it's not. What's actually happening is that the game is overwriting CRAM while the screen is being drawn. It just so happens the VDP renders left to right, top to bottom like your average CRT television, so if we swap in some wet-looking colors all at once, we end up with a nice translucent water effect which extends all the way to the bottom of the screen.

It's not all roses, though. This is what the water surface looks like in Hydrocity Zone, unchanged from all previous Sonic titles: a set of repeating waves which, given the rate they flicker at, almost look transparent.


A decent visual effect, but one we could surely live without. I mean, the Angel Island screenshot looks fine, right? However, this is what the same scene would look like on actual hardware, if you made the waves invisible.


What are those?

Turns out, the VDP doesn't actually like it if you mess with the colors while it's busy drawing the screen. Every time you write to CRAM, a block of garbage appears over the spot the VDP's proverbial electron beam is aiming at. This is a seldom known "feature" which, to my knowledge, isn't replicated in any emulator as of writing.

The transparent waves are a nice effect, but they were actually introduced to mask the CRAM corruption. The garbage blocks are still there, but it's a lot harder to notice them when all the surrounding pixels are flickering at 60 frames per second.

"But none of the other stages have waves and yet there's no garbage!" Actually, it's still there. By timing the CRAM writes very carefully and spreading them over several lines, Sonic 3's interrupt code manages to trap the garbage pixels in the overscan region left of the screen. This does mean that some colors are invariably copied over much sooner than others, resulting in an uneven water surface.

So why is Hydrocity the only stage not to use the trick? Beats me. Maybe they just thought it looked better that way.

4 comments:

  1. You should try to add that effect on some hack

    ReplyDelete
  2. It's present in Act 1 to make it easier to program the "run on water" feature, avoiding the visible misplacement on the color change (and avoiding to write yet another hack to move the transfer a couple pixels upwards)

    ReplyDelete
    Replies
    1. I dunno, the splash sprite already appears detached from the water surface on every other level, though I suppose it might have looked especially bad here. It's a possibility.

      Delete
  3. Considering this level is all about water, they may have wanted it to be a bit clearer where the water starts. I mean, look at the background in that screenshot. Above and below water don't look all that different(as opposed to Angel Island, where the difference is clear as day) when the level tiles are not on screen. Definitely similar enough that you might not be able to tell at high speeds. Not to mention, since you run on the water's surface, that's another reason to clearly define where the surface is.

    ReplyDelete