
Originally Posted by
Pyroptotic
@turboxray: I had replied to you yesterday but for some reason, my post didn't go through. Luckily, I was editing it in a local text file so I was able to recover it.
Yes, indeed. The timings constraints to fit a 31 colors DMA transfer in-between consecutive scanlines are very tight so it's necessary for the CPU and VDP to operate in lockstep at all times. I forgot to mention this particular detail in my original post but no H/V interrupts are ever involved with this trick. While a MegaColor image is being displayed, the 68K runs inside an infinite loop that either busywaits on the H/V counter until it reaches the value that signals the start of the next frame (at scanline #16) or use dummy write operations to the VDP data port to sync on the 288th pixel of the scanline (this works because the 68K bus is locked until the operation comes through and it can fit exactly 16 of those while 288 pixels are drawn).
Each scanline is divide into 4 strips of 9 tiles (or 72 pixels). A single color palette is statically assigned to each strip. In other words, the palette assignment in the tilemap looks like this (where each tile is represented by a single character).
Line 0: 111111111222222222333333333444444444
Line 1: 111111111222222222333333333444444444
Line 2: 111111111222222222333333333444444444
...
Line 190: 111111111222222222333333333444444444
Line 191: 111111111222222222333333333444444444
Colors of palette N only appear in column N except for the background color which is shared across all columns. So each strip of 9 tiles receives 15 unique colors in addition to the background one.
At the end of every scanline, 31 colors are replaced in total. On even scanlines, palette 1 & 2 are replaced and on odd scanlines, 3 & 4 are replaced (via DMA to CRAM). Consequently, for either half of the screen, palette pairs are shared across two consecutive lines. In the following diagram, each letter represents a unique set of 15 colors. A, B, C & D are the initial state of palette 1, 2, 3 & 4 respectively.
Line 0: AAAAAAAAABBBBBBBBBCCCCCCCCCDDDDDDDDD At end of scanline, replace palette A & B with E & F
Line 1: EEEEEEEEEFFFFFFFFFCCCCCCCCCDDDDDDDDD At end of scanline, replace palette C & D with G & H
Line 2: EEEEEEEEEFFFFFFFFFGGGGGGGGGHHHHHHHHH At end of scanline, replace palette E & F with I & J
Line 3: IIIIIIIIIJJJJJJJJJGGGGGGGGGHHHHHHHHH At end of scanline, replace palette G & H with K & L
Line 4: IIIIIIIIIJJJJJJJJJKKKKKKKKKLLLLLLLLL At end of scanline, replace palette I & J with M & N
Line 5: MMMMMMMMMNNNNNNNNNKKKKKKKKKLLLLLLLLL ...
Thus, you can convert a standard RGB image to MegaColor format simply by splitting it into strips of 72x2 and performing color reduction on each individual strip. I hope the diagrams make my explanations slightly clearer!