[ 3 / biz / cgl / ck / diy / fa / ic / jp / lit / sci / vr / vt ] [ index / top / reports ] [ become a patron ] [ status ]

/vr/ - Retro Games

Search:


View post   

>> No.2496098 [View]
File: 110 KB, 448x750, 1357636612724.jpg [View same] [iqdb] [saucenao] [google]
2496098

>>2495035
Short answer: 'cause that's how I programmed it.

Long answer: to perform a constant color addition (what's used to make the gradient) I have to write to register $2132 COLDATA. COLDATA is a 1-byte register that has the following form:

BGRCCCCC

where B, G, and R are bits that control what color channel you're writing to (RGB), and CCCCC is the color that is written.

This register is a little quirky, in that you specify the RGB channel and data in the same byte. For instance, to write a value of 5 to Red and Green, and then 3 to Blue, you'd have to write 0x65 = 01100101 then 0x83. No other register works quite like it; others generally require you to write to an address register, then write to a data register. Also other colors registers work on data that encodes all colors in one 2-byte word.

To make the gradient work, I linearly interpolate a color from the top of the screen down to the color at the bottom (c(y)=(c1-c0)/240*y+c0, where c0 is the top color, c1 is the bottom, y is the scanline, and c(y) is the interpolated color at scanline y) . I set just the 2 colors, and then call Draw.Gradient() to fill in the middle and map it to HDMA (perscan line data transfer that, in this case, updates COLDATA during H-Blank).

I only coded up blue initially, but simple copy and paste with small modifications or a loop extend it to green and red too. Essentially if I get it working for blue, than I also get red and green for (almost) free. And then I passed out.

One cool thing is since the colors can be interpolated independently, I can fade from any one hue to any other smoothly with my code (eg blue to red). But you know what? I dig the blue.

Navigation
View posts[+24][+48][+96]