We need to get these all on the wiki one of these days.
Ashbad, speak to me at some point about this if you'd be willing to help me organize them onto it.

void CopySpriteMaskedAlpha(const void*datar, int x, int y, int width, int height, int maskcolor, int alpha) {
color_t*data = (color_t*) datar;
color_t* VRAM = (color_t*)0xA8000000;
VRAM += LCD_WIDTH_PX*y + x;
alpha %= 32;
for(int j=y; j<y+height; j++) {
for(int i=x; i<x+width; i++) {
if (*(data) != maskcolor) {
*(VRAM) = (color_t)((((int)(*data & 0xf81f) * alpha + (int)(*VRAM & 0xf81f) * (32-alpha) + 0x8010) >> 5) & 0xf81f) |
(color_t)((((int)(*data & 0x07e0) * alpha + (int)(*VRAM & 0x07e0) * (32-alpha) + 0x0400) >> 6) & 0x07e0);
VRAM++; data++;
} else { VRAM++; data++; }
}
VRAM += LCD_WIDTH_PX-width;
}
}
typedef struct {
union {
unsigned int : 24;
struct {
unsigned int r : 5;
unsigned int g : 6;
unsigned int b : 5;
unsigned int a : 5;
unsigned int x : 3;
};
};
} color_t_rgbax;
void CopySpriteMasked5655(const void*datar, int x, int y, int width, int height, int maskcolor) {
color_t_rgbax*data = (color_t*) datar;
color_t* VRAM = (color_t*)0xA8000000;
VRAM += LCD_WIDTH_PX*y + x;
for(int j=y; j<y+height; j++) {
for(int i=x; i<x+width; i++) {
if ((color_t)*(data) != maskcolor) {
int alpha = *data & 0x0000F8;
*(VRAM) = (color_t)((((int)((*data>>8) & 0xf81f) * alpha + (int)(*VRAM & 0xf81f) * (32-alpha) + 0x8010) >> 5) & 0xf81f) |
(color_t)((((int)((*data>>8) & 0x07e0) * alpha + (int)(*VRAM & 0x07e0) * (32-alpha) + 0x0400) >> 6) & 0x07e0);
VRAM++; data++;
} else { VRAM++; data++; }
}
VRAM += LCD_WIDTH_PX-width;
}
}
int PrintMiniFix( int x, int y, const char*Msg, const int flags, const short color, const short bcolor ){
int i = 0, dx;
unsigned short width;
void*p;
while ( Msg[ i ] ){
p = GetMiniGlyphPtr( Msg[ i ], &width );
dx = ( 12 - width ) / 2;
if ( dx > 0 ) {
PrintMiniGlyph( x, y, (void*)empty, flags, dx, 0, 0, 0, 0, color, bcolor, 0 );
}else dx = 0;
PrintMiniGlyph( x+dx, y, p, flags, width, 0, 0, 0, 0, color, bcolor, 0 );
if ( width+dx < 12 ){
PrintMiniGlyph( x+width+dx, y, (void*)empty, flags, 12-width-dx, 0, 0, 0, 0, color, bcolor, 0 );
}
x += 12;
i++;
}
return x;
}
PrintMiniFix(0, 175,
"Oh look a string at the bottom of the screen.",
0, COLOR_WHITE, COLOR_BLACK);
const short empty[18] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
short unsigned int heightcolor(float z, float z_min, float z_max) {
float frac = ((z-z_min)/(z_max-z_min));
//color!
float r = (0.25f)-frac;
float g = (0.5f)-frac;
float b = (0.75f)-frac;
//calculate the R/G/B values
r = (r>0.f)?r:-r; g = (g>0.f)?g:-g; b = (b>0.f)?b:-b; //absolute value
r = (0.25f)-r; g = (1.f/3.f)-g; b = (0.25f)-b; //invert
r = (r>0.f)?(6.f*r):0.f; g = (g>0.f)?(6.f*g):0.f; b = (b>0.f)?(6.f*b):0.f; //scale the chromatic triangles
r = (r>1.f)?1.f:r; g = (g>1.f)?1.f:g; b = (b>1.f)?1.f:b; //clip the top of the chromatic triangles
if (frac < 0.25f) r = (r+1.f)/2.f; //adjust the bottom end of the scale so that z_min is red, not black
if (frac > 0.75f) b = (b+1.f)/2.f; //adjust the top end of the scale so that z_max is blue, not black
return (short unsigned int)(0x0000ffff & (((int)(31.f*r) << 11) | ((int)(63.f*g) << 5) | ((int)(31.f*b)))); //put the bits together
}
/* Awesome color routine from Kerm!! */
private Color getColor(float z, float z_min, float z_max) {
float frac = ((z-z_min)/(z_max-z_min));
//color!
float r = (0.25f)-frac;
float g = (0.5f)-frac;
float b = (0.75f)-frac;
//calculate the R/G/B values
r = (r>0.f)?r:-r; g = (g>0.f)?g:-g; b = (b>0.f)?b:-b; //absolute value
r = (0.25f)-r; g = (1.f/3.f)-g; b = (0.25f)-b; //invert
r = (r>0.f)?(6.f*r):0.f; g = (g>0.f)?(6.f*g):0.f; b = (b>0.f)?(6.f*b):0.f; //scale the chromatic triangles
r = (r>1.f)?1.f:r; g = (g>1.f)?1.f:g; b = (b>1.f)?1.f:b; //clip the top of the chromatic triangles
if (frac < 0.25f) r = (r+1.f)/2.f; //adjust the bottom end of the scale so that z_min is red, not black
if (frac > 0.75f) b = (b+1.f)/2.f; //adjust the top end of the scale so that z_max is blue, not black
return new Color(r, g, b);
//return (short unsigned int)(0x0000ffff & (((int)(31.f*r) << 11) | ((int)(63.f*g) << 5) | ((int)(31.f*b)))); //put the bits together
}
return getColor((float)iteration, (float)0, 200.0f);
Advertisement