How MD201509 works

This post has come a little later than expected, but a few people have asked about it so lets have a quick prod around behind the scenes of MD201509. There are two parts so, unsurprisingly, we’ll start with the intro.

This part is more complex than it initially appears, using cycle-accurate splits for the colour for each letter in the logo; the diagonal tilt comes from a split on each scanline that writes to the horizontal scroll register but it’s not possible to change colours midway across a badline… but that line is where the top bevel of the little bias relief tiles sit so the colour changes wouldn’t be visible anyway! Instead the routine pushes out new colour values six times per scanline for six of the eight lines (since the lower bevel doesn’t need a split either) and sets the colour to grey for the other two.

The same basic technique is used for the colour splits under the scroller and swinging text line, with the routine loading two registers with colour values at the start of each scanline and alternating between writing them across the screen. The badline here just happens to be where both colour gradients are white, so a single change is needed at the start of that line rather than multiple writes during it. Both split routines are unrolled code and built as subroutines so they can be called twice per frame.

In the main part, thirty seven of the colour splits aren’t actually colour splits! The first column is done traditionally by changing the background colour once per scanline with a sprite masking the two character columns to the left of it, but the rest are FLI with a memory- and processor-intensive, unrolled routine rewriting all of the colour data for them once per frame; this routine was what the entire demo was built around so everything else is pushed into the gaps it leaves and there are even a couple of changes for the masking sprites during the bitmap embedded within that chunk of code. A simple bitmap dissolve changes the FLI area back and forth between $55 and $aa (the colour data has a blue gradient value in one nybble and its equivalent from the brown gradient in the other), executing on runtime wherever the interrupts aren’t hogging the processor.

There are a few more colour splits under the scroller which are only slightly different to the ones in the intro and the badline is avoided completely so they’re just seven pixels high. There’s also a hardware sprite at the left side of the scroller because the entire screen is in forty column mode and there would be a character wide gap there without it.

Finally we get to the bitmap filling the majority of the screen. There’s been some talk on MD201509‘s CSDb entry about how it was done that make it seem complicated, but the black parts of the image are just set bits in the bitmap whilst all of the coloured areas are unset. Move some sprites around with the priority set so they’re behind the picture and they’ll only appear over the coloured parts; there are a few more sprites underlaid to add colour where it wasn’t possible to use attributes due to clash, but those are the higher-numbered sprites so the moving ones have priority. The only remaining feature is another routine on runtime that goes through the circles in “random” order, fading them to white and back down to one of the darker colours in the palette, this uses a subroutine for each circle and a jump table to select which is currently being called.

So there we go, the basics of how MD201509 works… if anyone wants to ask questions just fire away and I’ll do my best to answer. If there’s enough interest I might be brave enough to open a Github repository to publicly display my spaghetti-like source code!

Tags: , , , , , , ,

2 Responses to “How MD201509 works”

  1. aNdy says:

    Thanks for sharing that. Clears some stuff up.

    Obviously, I’m no coder, but would be interested to see the source – as long as it’s well commented, I may even understand 5% of it… 😉

  2. Jason says:

    There ARE comments but they’re quite sparse so i’d have to add more before releasing it… and i had to use quite a bit of self-modifying code too (all of the logo colours in the, the real split and the routine that flashes the circles in the main part, text fetching for the scrollers) so it might still be a bit iffy to read!