| 1 |
#include "driver.h" |
| 2 |
#include "state.h" |
| 3 |
|
| 4 |
#define VERBOSE 0 |
| 5 |
|
| 6 |
|
| 7 |
static UINT8 *game_palette; /* RGB palette as set by the driver */ |
| 8 |
static UINT8 *actual_palette; /* actual RGB palette after brightness adjustments */ |
| 9 |
static double *brightness; |
| 10 |
|
| 11 |
|
| 12 |
static int colormode; |
| 13 |
enum |
| 14 |
{ |
| 15 |
PALETTIZED_16BIT, |
| 16 |
DIRECT_15BIT, |
| 17 |
DIRECT_32BIT |
| 18 |
}; |
| 19 |
static int total_colors; |
| 20 |
static double shadow_factor,highlight_factor; |
| 21 |
static int palette_initialized; |
| 22 |
|
| 23 |
UINT32 direct_rgb_components[3]; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
UINT16 *palette_shadow_table; |
| 28 |
|
| 29 |
|
| 30 |
static void palette_reset_32_direct(void); |
| 31 |
static void palette_reset_15_direct(void); |
| 32 |
static void palette_reset_16_palettized(void); |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
int palette_start(void) |
| 37 |
{ |
| 38 |
int i; |
| 39 |
|
| 40 |
if ((Machine->drv->video_attributes & VIDEO_RGB_DIRECT) && |
| 41 |
Machine->drv->color_table_len) |
| 42 |
{ |
| 43 |
logerror("Error: VIDEO_RGB_DIRECT requires color_table_len to be 0.\n"); |
| 44 |
return 1; |
| 45 |
} |
| 46 |
|
| 47 |
total_colors = Machine->drv->total_colors; |
| 48 |
if (Machine->drv->video_attributes & VIDEO_HAS_SHADOWS) |
| 49 |
total_colors += Machine->drv->total_colors; |
| 50 |
if (Machine->drv->video_attributes & VIDEO_HAS_HIGHLIGHTS) |
| 51 |
total_colors += Machine->drv->total_colors; |
| 52 |
if (total_colors > 65536) |
| 53 |
{ |
| 54 |
logerror("Error: palette has more than 65536 colors.\n"); |
| 55 |
return 1; |
| 56 |
} |
| 57 |
shadow_factor = PALETTE_DEFAULT_SHADOW_FACTOR; |
| 58 |
highlight_factor = PALETTE_DEFAULT_HIGHLIGHT_FACTOR; |
| 59 |
|
| 60 |
game_palette = malloc(3 * total_colors); |
| 61 |
actual_palette = malloc(3 * total_colors); |
| 62 |
brightness = malloc(sizeof(*brightness) * Machine->drv->total_colors); |
| 63 |
|
| 64 |
if (Machine->color_depth == 15) |
| 65 |
colormode = DIRECT_15BIT; |
| 66 |
else if (Machine->color_depth == 32) |
| 67 |
colormode = DIRECT_32BIT; |
| 68 |
else |
| 69 |
colormode = PALETTIZED_16BIT; |
| 70 |
|
| 71 |
Machine->pens = malloc(total_colors * sizeof(*Machine->pens)); |
| 72 |
Machine->palette = malloc(total_colors * sizeof(*Machine->palette)); |
| 73 |
Machine->debug_pens = malloc(DEBUGGER_TOTAL_COLORS * sizeof(*Machine->debug_pens)); |
| 74 |
|
| 75 |
if (Machine->drv->color_table_len) |
| 76 |
{ |
| 77 |
Machine->game_colortable = malloc(Machine->drv->color_table_len * sizeof(*Machine->game_colortable)); |
| 78 |
Machine->remapped_colortable = malloc(Machine->drv->color_table_len * sizeof(*Machine->remapped_colortable)); |
| 79 |
} |
| 80 |
else |
| 81 |
{ |
| 82 |
Machine->game_colortable = 0; |
| 83 |
Machine->remapped_colortable = Machine->pens; /* straight 1:1 mapping from palette to colortable */ |
| 84 |
} |
| 85 |
Machine->debug_remapped_colortable = malloc(2*DEBUGGER_TOTAL_COLORS*DEBUGGER_TOTAL_COLORS * sizeof(*Machine->debug_remapped_colortable)); |
| 86 |
|
| 87 |
if (colormode == PALETTIZED_16BIT) |
| 88 |
{ |
| 89 |
/* we allocate a full 65536 entries table, to prevent memory corruption |
| 90 |
* bugs should the tilemap contains pens >= total_colors |
| 91 |
* (e.g. Machine->uifont->colortable[0] as returned by get_black_pen()) |
| 92 |
*/ |
| 93 |
palette_shadow_table = malloc(65536 * sizeof(*palette_shadow_table)); |
| 94 |
if (palette_shadow_table == 0) |
| 95 |
{ |
| 96 |
palette_stop(); |
| 97 |
return 1; |
| 98 |
} |
| 99 |
for (i = 0;i < 65536;i++) |
| 100 |
{ |
| 101 |
palette_shadow_table[i] = i; |
| 102 |
if ((Machine->drv->video_attributes & VIDEO_HAS_SHADOWS) && i < Machine->drv->total_colors) |
| 103 |
palette_shadow_table[i] += Machine->drv->total_colors; |
| 104 |
} |
| 105 |
} |
| 106 |
else |
| 107 |
palette_shadow_table = NULL; |
| 108 |
|
| 109 |
if ((Machine->drv->color_table_len && (Machine->game_colortable == 0 || Machine->remapped_colortable == 0)) |
| 110 |
|| game_palette == 0 || actual_palette == 0 || brightness == 0 |
| 111 |
|| Machine->pens == 0 || Machine->debug_pens == 0 || Machine->debug_remapped_colortable == 0) |
| 112 |
{ |
| 113 |
palette_stop(); |
| 114 |
return 1; |
| 115 |
} |
| 116 |
|
| 117 |
for (i = 0;i < Machine->drv->total_colors;i++) |
| 118 |
brightness[i] = 1.0; |
| 119 |
|
| 120 |
|
| 121 |
state_save_register_UINT8("palette", 0, "colors", game_palette, total_colors*3); |
| 122 |
state_save_register_UINT8("palette", 0, "actual_colors", actual_palette, total_colors*3); |
| 123 |
state_save_register_double("palette", 0, "brightness", brightness, Machine->drv->total_colors); |
| 124 |
switch (colormode) |
| 125 |
{ |
| 126 |
case PALETTIZED_16BIT: |
| 127 |
state_save_register_func_postload(palette_reset_16_palettized); |
| 128 |
break; |
| 129 |
case DIRECT_15BIT: |
| 130 |
state_save_register_func_postload(palette_reset_15_direct); |
| 131 |
break; |
| 132 |
case DIRECT_32BIT: |
| 133 |
state_save_register_func_postload(palette_reset_32_direct); |
| 134 |
break; |
| 135 |
} |
| 136 |
|
| 137 |
return 0; |
| 138 |
} |
| 139 |
|
| 140 |
void palette_stop(void) |
| 141 |
{ |
| 142 |
free(game_palette); |
| 143 |
game_palette = 0; |
| 144 |
free(actual_palette); |
| 145 |
actual_palette = 0; |
| 146 |
free(brightness); |
| 147 |
brightness = 0; |
| 148 |
if (Machine->game_colortable) |
| 149 |
{ |
| 150 |
free(Machine->game_colortable); |
| 151 |
Machine->game_colortable = 0; |
| 152 |
/* remapped_colortable is malloc()ed only when game_colortable is, */ |
| 153 |
/* otherwise it just points to Machine->pens */ |
| 154 |
free(Machine->remapped_colortable); |
| 155 |
} |
| 156 |
Machine->remapped_colortable = 0; |
| 157 |
free(Machine->debug_remapped_colortable); |
| 158 |
Machine->debug_remapped_colortable = 0; |
| 159 |
free(Machine->pens); |
| 160 |
Machine->pens = 0; |
| 161 |
free(Machine->debug_pens); |
| 162 |
Machine->debug_pens = 0; |
| 163 |
free(palette_shadow_table); |
| 164 |
palette_shadow_table = 0; |
| 165 |
|
| 166 |
palette_initialized = 0; |
| 167 |
} |
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
int palette_init(void) |
| 172 |
{ |
| 173 |
int i; |
| 174 |
UINT8 *debug_palette; |
| 175 |
pen_t *debug_pens; |
| 176 |
|
| 177 |
#ifdef MAME_DEBUG |
| 178 |
if (mame_debug) |
| 179 |
{ |
| 180 |
debug_palette = debugger_palette; |
| 181 |
debug_pens = Machine->debug_pens; |
| 182 |
} |
| 183 |
else |
| 184 |
#endif |
| 185 |
{ |
| 186 |
debug_palette = NULL; |
| 187 |
debug_pens = NULL; |
| 188 |
} |
| 189 |
|
| 190 |
/* We initialize the palette and colortable to some default values so that */ |
| 191 |
/* drivers which dynamically change the palette don't need an init_palette() */ |
| 192 |
/* function (provided the default color table fits their needs). */ |
| 193 |
|
| 194 |
for (i = 0;i < total_colors;i++) |
| 195 |
{ |
| 196 |
game_palette[3*i + 0] = actual_palette[3*i + 0] = ((i & 1) >> 0) * 0xff; |
| 197 |
game_palette[3*i + 1] = actual_palette[3*i + 1] = ((i & 2) >> 1) * 0xff; |
| 198 |
game_palette[3*i + 2] = actual_palette[3*i + 2] = ((i & 4) >> 2) * 0xff; |
| 199 |
} |
| 200 |
|
| 201 |
/* Preload the colortable with a default setting, following the same */ |
| 202 |
/* order of the palette. The driver can overwrite this in */ |
| 203 |
/* init_palette() */ |
| 204 |
for (i = 0;i < Machine->drv->color_table_len;i++) |
| 205 |
Machine->game_colortable[i] = i % total_colors; |
| 206 |
|
| 207 |
/* now the driver can modify the default values if it wants to. */ |
| 208 |
if (Machine->drv->init_palette) |
| 209 |
(*Machine->drv->init_palette)(Machine->game_colortable,memory_region(REGION_PROMS)); |
| 210 |
|
| 211 |
|
| 212 |
switch (colormode) |
| 213 |
{ |
| 214 |
case PALETTIZED_16BIT: |
| 215 |
{ |
| 216 |
if (osd_allocate_colors(total_colors,game_palette,NULL,debug_palette,debug_pens)) |
| 217 |
return 1; |
| 218 |
|
| 219 |
for (i = 0;i < total_colors;i++) |
| 220 |
Machine->pens[i] = i; |
| 221 |
|
| 222 |
/* refresh the palette to support shadows in PROM games */ |
| 223 |
for (i = 0;i < Machine->drv->total_colors;i++) |
| 224 |
palette_set_color(i,game_palette[3*i + 0],game_palette[3*i + 1],game_palette[3*i + 2]); |
| 225 |
} |
| 226 |
break; |
| 227 |
|
| 228 |
case DIRECT_15BIT: |
| 229 |
{ |
| 230 |
const UINT8 rgbpalette[3*3] = { 0xff,0x00,0x00, 0x00,0xff,0x00, 0x00,0x00,0xff }; |
| 231 |
|
| 232 |
if (osd_allocate_colors(3,rgbpalette,direct_rgb_components,debug_palette,debug_pens)) |
| 233 |
return 1; |
| 234 |
|
| 235 |
for (i = 0;i < total_colors;i++) |
| 236 |
Machine->pens[i] = |
| 237 |
(game_palette[3*i + 0] >> 3) * (direct_rgb_components[0] / 0x1f) + |
| 238 |
(game_palette[3*i + 1] >> 3) * (direct_rgb_components[1] / 0x1f) + |
| 239 |
(game_palette[3*i + 2] >> 3) * (direct_rgb_components[2] / 0x1f); |
| 240 |
|
| 241 |
break; |
| 242 |
} |
| 243 |
|
| 244 |
case DIRECT_32BIT: |
| 245 |
{ |
| 246 |
const UINT8 rgbpalette[3*3] = { 0xff,0x00,0x00, 0x00,0xff,0x00, 0x00,0x00,0xff }; |
| 247 |
|
| 248 |
if (osd_allocate_colors(3,rgbpalette,direct_rgb_components,debug_palette,debug_pens)) |
| 249 |
return 1; |
| 250 |
|
| 251 |
for (i = 0;i < total_colors;i++) |
| 252 |
Machine->pens[i] = |
| 253 |
game_palette[3*i + 0] * (direct_rgb_components[0] / 0xff) + |
| 254 |
game_palette[3*i + 1] * (direct_rgb_components[1] / 0xff) + |
| 255 |
game_palette[3*i + 2] * (direct_rgb_components[2] / 0xff); |
| 256 |
|
| 257 |
break; |
| 258 |
} |
| 259 |
} |
| 260 |
|
| 261 |
for (i = 0;i < Machine->drv->color_table_len;i++) |
| 262 |
{ |
| 263 |
pen_t color = Machine->game_colortable[i]; |
| 264 |
|
| 265 |
/* check for invalid colors set by Machine->drv->init_palette */ |
| 266 |
if (color < total_colors) |
| 267 |
Machine->remapped_colortable[i] = Machine->pens[color]; |
| 268 |
else |
| 269 |
usrintf_showmessage("colortable[%d] (=%d) out of range (total_colors = %d)", |
| 270 |
i,color,total_colors); |
| 271 |
} |
| 272 |
|
| 273 |
for (i = 0;i < DEBUGGER_TOTAL_COLORS*DEBUGGER_TOTAL_COLORS;i++) |
| 274 |
{ |
| 275 |
Machine->debug_remapped_colortable[2*i+0] = Machine->debug_pens[i / DEBUGGER_TOTAL_COLORS]; |
| 276 |
Machine->debug_remapped_colortable[2*i+1] = Machine->debug_pens[i % DEBUGGER_TOTAL_COLORS]; |
| 277 |
} |
| 278 |
|
| 279 |
palette_initialized = 1; |
| 280 |
|
| 281 |
return 0; |
| 282 |
} |
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
INLINE void palette_set_color_15_direct(pen_t color,UINT8 red,UINT8 green,UINT8 blue) |
| 287 |
{ |
| 288 |
if ( actual_palette[3*color + 0] == red && |
| 289 |
actual_palette[3*color + 1] == green && |
| 290 |
actual_palette[3*color + 2] == blue) |
| 291 |
return; |
| 292 |
actual_palette[3*color + 0] = red; |
| 293 |
actual_palette[3*color + 1] = green; |
| 294 |
actual_palette[3*color + 2] = blue; |
| 295 |
Machine->pens[color] = |
| 296 |
(red >> 3) * (direct_rgb_components[0] / 0x1f) + |
| 297 |
(green >> 3) * (direct_rgb_components[1] / 0x1f) + |
| 298 |
(blue >> 3) * (direct_rgb_components[2] / 0x1f); |
| 299 |
} |
| 300 |
|
| 301 |
static void palette_reset_15_direct(void) |
| 302 |
{ |
| 303 |
pen_t color; |
| 304 |
for(color = 0; color < total_colors; color++) |
| 305 |
Machine->pens[color] = |
| 306 |
(game_palette[3*color + 0]>>3) * (direct_rgb_components[0] / 0x1f) + |
| 307 |
(game_palette[3*color + 1]>>3) * (direct_rgb_components[1] / 0x1f) + |
| 308 |
(game_palette[3*color + 2]>>3) * (direct_rgb_components[2] / 0x1f); |
| 309 |
} |
| 310 |
|
| 311 |
INLINE void palette_set_color_32_direct(pen_t color,UINT8 red,UINT8 green,UINT8 blue) |
| 312 |
{ |
| 313 |
if ( actual_palette[3*color + 0] == red && |
| 314 |
actual_palette[3*color + 1] == green && |
| 315 |
actual_palette[3*color + 2] == blue) |
| 316 |
return; |
| 317 |
actual_palette[3*color + 0] = red; |
| 318 |
actual_palette[3*color + 1] = green; |
| 319 |
actual_palette[3*color + 2] = blue; |
| 320 |
Machine->pens[color] = |
| 321 |
red * (direct_rgb_components[0] / 0xff) + |
| 322 |
green * (direct_rgb_components[1] / 0xff) + |
| 323 |
blue * (direct_rgb_components[2] / 0xff); |
| 324 |
} |
| 325 |
|
| 326 |
static void palette_reset_32_direct(void) |
| 327 |
{ |
| 328 |
pen_t color; |
| 329 |
for(color = 0; color < total_colors; color++) |
| 330 |
Machine->pens[color] = |
| 331 |
game_palette[3*color + 0] * (direct_rgb_components[0] / 0xff) + |
| 332 |
game_palette[3*color + 1] * (direct_rgb_components[1] / 0xff) + |
| 333 |
game_palette[3*color + 2] * (direct_rgb_components[2] / 0xff); |
| 334 |
} |
| 335 |
|
| 336 |
INLINE void palette_set_color_16_palettized(pen_t color,UINT8 red,UINT8 green,UINT8 blue) |
| 337 |
{ |
| 338 |
if ( actual_palette[3*color + 0] == red && |
| 339 |
actual_palette[3*color + 1] == green && |
| 340 |
actual_palette[3*color + 2] == blue) |
| 341 |
return; |
| 342 |
|
| 343 |
actual_palette[3*color + 0] = red; |
| 344 |
actual_palette[3*color + 1] = green; |
| 345 |
actual_palette[3*color + 2] = blue; |
| 346 |
|
| 347 |
if (palette_initialized) |
| 348 |
osd_modify_pen(Machine->pens[color],red,green,blue); |
| 349 |
} |
| 350 |
|
| 351 |
static void palette_reset_16_palettized(void) |
| 352 |
{ |
| 353 |
if (palette_initialized) |
| 354 |
{ |
| 355 |
pen_t color; |
| 356 |
for (color=0; color<total_colors; color++) |
| 357 |
osd_modify_pen(Machine->pens[color], |
| 358 |
game_palette[3*color + 0], |
| 359 |
game_palette[3*color + 1], |
| 360 |
game_palette[3*color + 2]); |
| 361 |
} |
| 362 |
} |
| 363 |
|
| 364 |
|
| 365 |
INLINE void adjust_shadow(UINT8 *r,UINT8 *g,UINT8 *b,double factor) |
| 366 |
{ |
| 367 |
if (factor > 1) |
| 368 |
{ |
| 369 |
int max = *r; |
| 370 |
if (*g > max) max = *g; |
| 371 |
if (*b > max) max = *b; |
| 372 |
|
| 373 |
if ((int)(max * factor + 0.5) >= 256) |
| 374 |
factor = 255.0 / max; |
| 375 |
} |
| 376 |
|
| 377 |
*r = *r * factor + 0.5; |
| 378 |
*g = *g * factor + 0.5; |
| 379 |
*b = *b * factor + 0.5; |
| 380 |
} |
| 381 |
|
| 382 |
void palette_set_color(pen_t color,UINT8 r,UINT8 g,UINT8 b) |
| 383 |
{ |
| 384 |
if (color >= total_colors) |
| 385 |
{ |
| 386 |
logerror("error: palette_set_color() called with color %d, but only %d allocated.\n",color,total_colors); |
| 387 |
return; |
| 388 |
} |
| 389 |
|
| 390 |
game_palette[3*color + 0] = r; |
| 391 |
game_palette[3*color + 1] = g; |
| 392 |
game_palette[3*color + 2] = b; |
| 393 |
|
| 394 |
if (color < Machine->drv->total_colors && brightness[color] != 1.0) |
| 395 |
{ |
| 396 |
r = r * brightness[color] + 0.5; |
| 397 |
g = g * brightness[color] + 0.5; |
| 398 |
b = b * brightness[color] + 0.5; |
| 399 |
} |
| 400 |
|
| 401 |
Machine->palette[color] = MAKE_RGB(r,g,b); |
| 402 |
|
| 403 |
switch (colormode) |
| 404 |
{ |
| 405 |
case PALETTIZED_16BIT: |
| 406 |
palette_set_color_16_palettized(color,r,g,b); |
| 407 |
break; |
| 408 |
case DIRECT_15BIT: |
| 409 |
palette_set_color_15_direct(color,r,g,b); |
| 410 |
break; |
| 411 |
case DIRECT_32BIT: |
| 412 |
palette_set_color_32_direct(color,r,g,b); |
| 413 |
break; |
| 414 |
} |
| 415 |
|
| 416 |
if (color < Machine->drv->total_colors) |
| 417 |
{ |
| 418 |
/* automatically create darker shade for shadow handling */ |
| 419 |
if (Machine->drv->video_attributes & VIDEO_HAS_SHADOWS) |
| 420 |
{ |
| 421 |
UINT8 nr=r,ng=g,nb=b; |
| 422 |
|
| 423 |
adjust_shadow(&nr,&ng,&nb,shadow_factor); |
| 424 |
|
| 425 |
color += Machine->drv->total_colors; /* carry this change over to highlight handling */ |
| 426 |
palette_set_color(color,nr,ng,nb); |
| 427 |
} |
| 428 |
|
| 429 |
/* automatically create brighter shade for highlight handling */ |
| 430 |
if (Machine->drv->video_attributes & VIDEO_HAS_HIGHLIGHTS) |
| 431 |
{ |
| 432 |
UINT8 nr=r,ng=g,nb=b; |
| 433 |
|
| 434 |
adjust_shadow(&nr,&ng,&nb,highlight_factor); |
| 435 |
|
| 436 |
color += Machine->drv->total_colors; |
| 437 |
palette_set_color(color,nr,ng,nb); |
| 438 |
} |
| 439 |
} |
| 440 |
} |
| 441 |
|
| 442 |
void palette_get_color(pen_t color,UINT8 *r,UINT8 *g,UINT8 *b) |
| 443 |
{ |
| 444 |
if (color == get_black_pen()) |
| 445 |
{ |
| 446 |
*r = *g = *b = 0; |
| 447 |
} |
| 448 |
else if (color >= total_colors) |
| 449 |
{ |
| 450 |
usrintf_showmessage("palette_get_color() out of range"); |
| 451 |
} |
| 452 |
else |
| 453 |
{ |
| 454 |
*r = game_palette[3*color + 0]; |
| 455 |
*g = game_palette[3*color + 1]; |
| 456 |
*b = game_palette[3*color + 2]; |
| 457 |
} |
| 458 |
} |
| 459 |
|
| 460 |
void palette_set_brightness(pen_t color,double bright) |
| 461 |
{ |
| 462 |
if (brightness[color] != bright) |
| 463 |
{ |
| 464 |
brightness[color] = bright; |
| 465 |
|
| 466 |
palette_set_color(color,game_palette[3*color + 0],game_palette[3*color + 1],game_palette[3*color + 2]); |
| 467 |
} |
| 468 |
} |
| 469 |
|
| 470 |
void palette_set_shadow_factor(double factor) |
| 471 |
{ |
| 472 |
if (shadow_factor != factor) |
| 473 |
{ |
| 474 |
int i; |
| 475 |
|
| 476 |
shadow_factor = factor; |
| 477 |
|
| 478 |
if (palette_initialized) |
| 479 |
{ |
| 480 |
for (i = 0;i < Machine->drv->total_colors;i++) |
| 481 |
palette_set_color(i,game_palette[3*i + 0],game_palette[3*i + 1],game_palette[3*i + 2]); |
| 482 |
} |
| 483 |
} |
| 484 |
} |
| 485 |
|
| 486 |
void palette_set_highlight_factor(double factor) |
| 487 |
{ |
| 488 |
if (highlight_factor != factor) |
| 489 |
{ |
| 490 |
int i; |
| 491 |
|
| 492 |
highlight_factor = factor; |
| 493 |
|
| 494 |
for (i = 0;i < Machine->drv->total_colors;i++) |
| 495 |
palette_set_color(i,game_palette[3*i + 0],game_palette[3*i + 1],game_palette[3*i + 2]); |
| 496 |
} |
| 497 |
} |
| 498 |
|
| 499 |
|
| 500 |
pen_t get_black_pen(void) |
| 501 |
{ |
| 502 |
return Machine->uifont->colortable[0]; |
| 503 |
} |
| 504 |
|
| 505 |
|
| 506 |
/****************************************************************************** |
| 507 |
|
| 508 |
Commonly used palette RAM handling functions |
| 509 |
|
| 510 |
******************************************************************************/ |
| 511 |
|
| 512 |
data8_t *paletteram; |
| 513 |
data8_t *paletteram_2; /* use when palette RAM is split in two parts */ |
| 514 |
data16_t *paletteram16; |
| 515 |
data16_t *paletteram16_2; |
| 516 |
data32_t *paletteram32; |
| 517 |
|
| 518 |
READ_HANDLER( paletteram_r ) |
| 519 |
{ |
| 520 |
return paletteram[offset]; |
| 521 |
} |
| 522 |
|
| 523 |
READ_HANDLER( paletteram_2_r ) |
| 524 |
{ |
| 525 |
return paletteram_2[offset]; |
| 526 |
} |
| 527 |
|
| 528 |
READ16_HANDLER( paletteram16_word_r ) |
| 529 |
{ |
| 530 |
return paletteram16[offset]; |
| 531 |
} |
| 532 |
|
| 533 |
READ16_HANDLER( paletteram16_2_word_r ) |
| 534 |
{ |
| 535 |
return paletteram16_2[offset]; |
| 536 |
} |
| 537 |
|
| 538 |
READ32_HANDLER( paletteram32_r ) |
| 539 |
{ |
| 540 |
return paletteram32[offset]; |
| 541 |
} |
| 542 |
|
| 543 |
WRITE_HANDLER( paletteram_RRRGGGBB_w ) |
| 544 |
{ |
| 545 |
int r,g,b; |
| 546 |
int bit0,bit1,bit2; |
| 547 |
|
| 548 |
|
| 549 |
paletteram[offset] = data; |
| 550 |
|
| 551 |
/* red component */ |
| 552 |
bit0 = (data >> 5) & 0x01; |
| 553 |
bit1 = (data >> 6) & 0x01; |
| 554 |
bit2 = (data >> 7) & 0x01; |
| 555 |
r = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2; |
| 556 |
/* green component */ |
| 557 |
bit0 = (data >> 2) & 0x01; |
| 558 |
bit1 = (data >> 3) & 0x01; |
| 559 |
bit2 = (data >> 4) & 0x01; |
| 560 |
g = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2; |
| 561 |
/* blue component */ |
| 562 |
bit0 = 0; |
| 563 |
bit1 = (data >> 0) & 0x01; |
| 564 |
bit2 = (data >> 1) & 0x01; |
| 565 |
b = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2; |
| 566 |
|
| 567 |
palette_set_color(offset,r,g,b); |
| 568 |
} |
| 569 |
|
| 570 |
WRITE_HANDLER( paletteram_BBBGGGRR_w ) |
| 571 |
{ |
| 572 |
int r,g,b; |
| 573 |
int bit0,bit1,bit2; |
| 574 |
|
| 575 |
paletteram[offset] = data; |
| 576 |
|
| 577 |
/* blue component */ |
| 578 |
bit0 = (data >> 5) & 0x01; |
| 579 |
bit1 = (data >> 6) & 0x01; |
| 580 |
bit2 = (data >> 7) & 0x01; |
| 581 |
b = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2; |
| 582 |
/* green component */ |
| 583 |
bit0 = (data >> 2) & 0x01; |
| 584 |
bit1 = (data >> 3) & 0x01; |
| 585 |
bit2 = (data >> 4) & 0x01; |
| 586 |
g = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2; |
| 587 |
/* blue component */ |
| 588 |
bit0 = (data >> 0) & 0x01; |
| 589 |
bit1 = (data >> 1) & 0x01; |
| 590 |
r = 0x55 * bit0 + 0xaa * bit1; |
| 591 |
|
| 592 |
palette_set_color(offset,r,g,b); |
| 593 |
} |
| 594 |
|
| 595 |
WRITE_HANDLER( paletteram_BBGGGRRR_w ) |
| 596 |
{ |
| 597 |
int r,g,b; |
| 598 |
int bit0,bit1,bit2; |
| 599 |
|
| 600 |
|
| 601 |
paletteram[offset] = data; |
| 602 |
|
| 603 |
/* red component */ |
| 604 |
bit0 = (data >> 0) & 0x01; |
| 605 |
bit1 = (data >> 1) & 0x01; |
| 606 |
bit2 = (data >> 2) & 0x01; |
| 607 |
r = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2; |
| 608 |
/* green component */ |
| 609 |
bit0 = (data >> 3) & 0x01; |
| 610 |
bit1 = (data >> 4) & 0x01; |
| 611 |
bit2 = (data >> 5) & 0x01; |
| 612 |
g = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2; |
| 613 |
/* blue component */ |
| 614 |
bit0 = 0; |
| 615 |
bit1 = (data >> 6) & 0x01; |
| 616 |
bit2 = (data >> 7) & 0x01; |
| 617 |
b = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2; |
| 618 |
|
| 619 |
palette_set_color(offset,r,g,b); |
| 620 |
} |
| 621 |
|
| 622 |
|
| 623 |
WRITE_HANDLER( paletteram_IIBBGGRR_w ) |
| 624 |
{ |
| 625 |
int r,g,b,i; |
| 626 |
|
| 627 |
|
| 628 |
paletteram[offset] = data; |
| 629 |
|
| 630 |
i = (data >> 6) & 0x03; |
| 631 |
/* red component */ |
| 632 |
r = (data << 2) & 0x0c; |
| 633 |
if (r) r |= i; |
| 634 |
r *= 0x11; |
| 635 |
/* green component */ |
| 636 |
g = (data >> 0) & 0x0c; |
| 637 |
if (g) g |= i; |
| 638 |
g *= 0x11; |
| 639 |
/* blue component */ |
| 640 |
b = (data >> 2) & 0x0c; |
| 641 |
if (b) b |= i; |
| 642 |
b *= 0x11; |
| 643 |
|
| 644 |
palette_set_color(offset,r,g,b); |
| 645 |
} |
| 646 |
|
| 647 |
|
| 648 |
WRITE_HANDLER( paletteram_BBGGRRII_w ) |
| 649 |
{ |
| 650 |
int r,g,b,i; |
| 651 |
|
| 652 |
|
| 653 |
paletteram[offset] = data; |
| 654 |
|
| 655 |
i = (data >> 0) & 0x03; |
| 656 |
/* red component */ |
| 657 |
r = (((data >> 0) & 0x0c) | i) * 0x11; |
| 658 |
/* green component */ |
| 659 |
g = (((data >> 2) & 0x0c) | i) * 0x11; |
| 660 |
/* blue component */ |
| 661 |
b = (((data >> 4) & 0x0c) | i) * 0x11; |
| 662 |
|
| 663 |
palette_set_color(offset,r,g,b); |
| 664 |
} |
| 665 |
|
| 666 |
|
| 667 |
INLINE void changecolor_xxxxBBBBGGGGRRRR(pen_t color,int data) |
| 668 |
{ |
| 669 |
int r,g,b; |
| 670 |
|
| 671 |
|
| 672 |
r = (data >> 0) & 0x0f; |
| 673 |
g = (data >> 4) & 0x0f; |
| 674 |
b = (data >> 8) & 0x0f; |
| 675 |
|
| 676 |
r = (r << 4) | r; |
| 677 |
g = (g << 4) | g; |
| 678 |
b = (b << 4) | b; |
| 679 |
|
| 680 |
palette_set_color(color,r,g,b); |
| 681 |
} |
| 682 |
|
| 683 |
WRITE_HANDLER( paletteram_xxxxBBBBGGGGRRRR_w ) |
| 684 |
{ |
| 685 |
paletteram[offset] = data; |
| 686 |
changecolor_xxxxBBBBGGGGRRRR(offset / 2,paletteram[offset & ~1] | (paletteram[offset | 1] << 8)); |
| 687 |
} |
| 688 |
|
| 689 |
WRITE_HANDLER( paletteram_xxxxBBBBGGGGRRRR_swap_w ) |
| 690 |
{ |
| 691 |
paletteram[offset] = data; |
| 692 |
changecolor_xxxxBBBBGGGGRRRR(offset / 2,paletteram[offset | 1] | (paletteram[offset & ~1] << 8)); |
| 693 |
} |
| 694 |
|
| 695 |
WRITE_HANDLER( paletteram_xxxxBBBBGGGGRRRR_split1_w ) |
| 696 |
{ |
| 697 |
paletteram[offset] = data; |
| 698 |
changecolor_xxxxBBBBGGGGRRRR(offset,paletteram[offset] | (paletteram_2[offset] << 8)); |
| 699 |
} |
| 700 |
|
| 701 |
WRITE_HANDLER( paletteram_xxxxBBBBGGGGRRRR_split2_w ) |
| 702 |
{ |
| 703 |
paletteram_2[offset] = data; |
| 704 |
changecolor_xxxxBBBBGGGGRRRR(offset,paletteram[offset] | (paletteram_2[offset] << 8)); |
| 705 |
} |
| 706 |
|
| 707 |
WRITE16_HANDLER( paletteram16_xxxxBBBBGGGGRRRR_word_w ) |
| 708 |
{ |
| 709 |
COMBINE_DATA(&paletteram16[offset]); |
| 710 |
changecolor_xxxxBBBBGGGGRRRR(offset,paletteram16[offset]); |
| 711 |
} |
| 712 |
|
| 713 |
|
| 714 |
INLINE void changecolor_xxxxBBBBRRRRGGGG(pen_t color,int data) |
| 715 |
{ |
| 716 |
int r,g,b; |
| 717 |
|
| 718 |
|
| 719 |
r = (data >> 4) & 0x0f; |
| 720 |
g = (data >> 0) & 0x0f; |
| 721 |
b = (data >> 8) & 0x0f; |
| 722 |
|
| 723 |
r = (r << 4) | r; |
| 724 |
g = (g << 4) | g; |
| 725 |
b = (b << 4) | b; |
| 726 |
|
| 727 |
palette_set_color(color,r,g,b); |
| 728 |
} |
| 729 |
|
| 730 |
WRITE_HANDLER( paletteram_xxxxBBBBRRRRGGGG_w ) |
| 731 |
{ |
| 732 |
paletteram[offset] = data; |
| 733 |
changecolor_xxxxBBBBRRRRGGGG(offset / 2,paletteram[offset & ~1] | (paletteram[offset | 1] << 8)); |
| 734 |
} |
| 735 |
|
| 736 |
WRITE_HANDLER( paletteram_xxxxBBBBRRRRGGGG_swap_w ) |
| 737 |
{ |
| 738 |
paletteram[offset] = data; |
| 739 |
changecolor_xxxxBBBBRRRRGGGG(offset / 2,paletteram[offset | 1] | (paletteram[offset & ~1] << 8)); |
| 740 |
} |
| 741 |
|
| 742 |
WRITE_HANDLER( paletteram_xxxxBBBBRRRRGGGG_split1_w ) |
| 743 |
{ |
| 744 |
paletteram[offset] = data; |
| 745 |
changecolor_xxxxBBBBRRRRGGGG(offset,paletteram[offset] | (paletteram_2[offset] << 8)); |
| 746 |
} |
| 747 |
|
| 748 |
WRITE_HANDLER( paletteram_xxxxBBBBRRRRGGGG_split2_w ) |
| 749 |
{ |
| 750 |
paletteram_2[offset] = data; |
| 751 |
changecolor_xxxxBBBBRRRRGGGG(offset,paletteram[offset] | (paletteram_2[offset] << 8)); |
| 752 |
} |
| 753 |
|
| 754 |
|
| 755 |
INLINE void changecolor_xxxxRRRRBBBBGGGG(pen_t color,int data) |
| 756 |
{ |
| 757 |
int r,g,b; |
| 758 |
|
| 759 |
|
| 760 |
r = (data >> 8) & 0x0f; |
| 761 |
g = (data >> 0) & 0x0f; |
| 762 |
b = (data >> 4) & 0x0f; |
| 763 |
|
| 764 |
r = (r << 4) | r; |
| 765 |
g = (g << 4) | g; |
| 766 |
b = (b << 4) | b; |
| 767 |
|
| 768 |
palette_set_color(color,r,g,b); |
| 769 |
} |
| 770 |
|
| 771 |
WRITE_HANDLER( paletteram_xxxxRRRRBBBBGGGG_split1_w ) |
| 772 |
{ |
| 773 |
paletteram[offset] = data; |
| 774 |
changecolor_xxxxRRRRBBBBGGGG(offset,paletteram[offset] | (paletteram_2[offset] << 8)); |
| 775 |
} |
| 776 |
|
| 777 |
WRITE_HANDLER( paletteram_xxxxRRRRBBBBGGGG_split2_w ) |
| 778 |
{ |
| 779 |
paletteram_2[offset] = data; |
| 780 |
changecolor_xxxxRRRRBBBBGGGG(offset,paletteram[offset] | (paletteram_2[offset] << 8)); |
| 781 |
} |
| 782 |
|
| 783 |
|
| 784 |
INLINE void changecolor_xxxxRRRRGGGGBBBB(pen_t color,int data) |
| 785 |
{ |
| 786 |
int r,g,b; |
| 787 |
|
| 788 |
|
| 789 |
r = (data >> 8) & 0x0f; |
| 790 |
g = (data >> 4) & 0x0f; |
| 791 |
b = (data >> 0) & 0x0f; |
| 792 |
|
| 793 |
r = (r << 4) | r; |
| 794 |
g = (g << 4) | g; |
| 795 |
b = (b << 4) | b; |
| 796 |
|
| 797 |
palette_set_color(color,r,g,b); |
| 798 |
} |
| 799 |
|
| 800 |
WRITE_HANDLER( paletteram_xxxxRRRRGGGGBBBB_w ) |
| 801 |
{ |
| 802 |
paletteram[offset] = data; |
| 803 |
changecolor_xxxxRRRRGGGGBBBB(offset / 2,paletteram[offset & ~1] | (paletteram[offset | 1] << 8)); |
| 804 |
} |
| 805 |
|
| 806 |
WRITE_HANDLER( paletteram_xxxxRRRRGGGGBBBB_swap_w ) |
| 807 |
{ |
| 808 |
paletteram[offset] = data; |
| 809 |
changecolor_xxxxRRRRGGGGBBBB(offset / 2,paletteram[offset | 1] | (paletteram[offset & ~1] << 8)); |
| 810 |
} |
| 811 |
|
| 812 |
WRITE16_HANDLER( paletteram16_xxxxRRRRGGGGBBBB_word_w ) |
| 813 |
{ |
| 814 |
COMBINE_DATA(&paletteram16[offset]); |
| 815 |
changecolor_xxxxRRRRGGGGBBBB(offset,paletteram16[offset]); |
| 816 |
} |
| 817 |
|
| 818 |
|
| 819 |
INLINE void changecolor_RRRRGGGGBBBBxxxx(pen_t color,int data) |
| 820 |
{ |
| 821 |
int r,g,b; |
| 822 |
|
| 823 |
|
| 824 |
r = (data >> 12) & 0x0f; |
| 825 |
g = (data >> 8) & 0x0f; |
| 826 |
b = (data >> 4) & 0x0f; |
| 827 |
|
| 828 |
r = (r << 4) | r; |
| 829 |
g = (g << 4) | g; |
| 830 |
b = (b << 4) | b; |
| 831 |
|
| 832 |
palette_set_color(color,r,g,b); |
| 833 |
} |
| 834 |
|
| 835 |
WRITE_HANDLER( paletteram_RRRRGGGGBBBBxxxx_swap_w ) |
| 836 |
{ |
| 837 |
paletteram[offset] = data; |
| 838 |
changecolor_RRRRGGGGBBBBxxxx(offset / 2,paletteram[offset | 1] | (paletteram[offset & ~1] << 8)); |
| 839 |
} |
| 840 |
|
| 841 |
WRITE_HANDLER( paletteram_RRRRGGGGBBBBxxxx_split1_w ) |
| 842 |
{ |
| 843 |
paletteram[offset] = data; |
| 844 |
changecolor_RRRRGGGGBBBBxxxx(offset,paletteram[offset] | (paletteram_2[offset] << 8)); |
| 845 |
} |
| 846 |
|
| 847 |
WRITE_HANDLER( paletteram_RRRRGGGGBBBBxxxx_split2_w ) |
| 848 |
{ |
| 849 |
paletteram_2[offset] = data; |
| 850 |
changecolor_RRRRGGGGBBBBxxxx(offset,paletteram[offset] | (paletteram_2[offset] << 8)); |
| 851 |
} |
| 852 |
|
| 853 |
WRITE16_HANDLER( paletteram16_RRRRGGGGBBBBxxxx_word_w ) |
| 854 |
{ |
| 855 |
COMBINE_DATA(&paletteram16[offset]); |
| 856 |
changecolor_RRRRGGGGBBBBxxxx(offset,paletteram16[offset]); |
| 857 |
} |
| 858 |
|
| 859 |
|
| 860 |
INLINE void changecolor_BBBBGGGGRRRRxxxx(pen_t color,int data) |
| 861 |
{ |
| 862 |
int r,g,b; |
| 863 |
|
| 864 |
|
| 865 |
r = (data >> 4) & 0x0f; |
| 866 |
g = (data >> 8) & 0x0f; |
| 867 |
b = (data >> 12) & 0x0f; |
| 868 |
|
| 869 |
r = (r << 4) | r; |
| 870 |
g = (g << 4) | g; |
| 871 |
b = (b << 4) | b; |
| 872 |
|
| 873 |
palette_set_color(color,r,g,b); |
| 874 |
} |
| 875 |
|
| 876 |
WRITE_HANDLER( paletteram_BBBBGGGGRRRRxxxx_swap_w ) |
| 877 |
{ |
| 878 |
paletteram[offset] = data; |
| 879 |
changecolor_BBBBGGGGRRRRxxxx(offset / 2,paletteram[offset | 1] | (paletteram[offset & ~1] << 8)); |
| 880 |
} |
| 881 |
|
| 882 |
WRITE_HANDLER( paletteram_BBBBGGGGRRRRxxxx_split1_w ) |
| 883 |
{ |
| 884 |
paletteram[offset] = data; |
| 885 |
changecolor_BBBBGGGGRRRRxxxx(offset,paletteram[offset] | (paletteram_2[offset] << 8)); |
| 886 |
} |
| 887 |
|
| 888 |
WRITE_HANDLER( paletteram_BBBBGGGGRRRRxxxx_split2_w ) |
| 889 |
{ |
| 890 |
paletteram_2[offset] = data; |
| 891 |
changecolor_BBBBGGGGRRRRxxxx(offset,paletteram[offset] | (paletteram_2[offset] << 8)); |
| 892 |
} |
| 893 |
|
| 894 |
WRITE16_HANDLER( paletteram16_BBBBGGGGRRRRxxxx_word_w ) |
| 895 |
{ |
| 896 |
COMBINE_DATA(&paletteram16[offset]); |
| 897 |
changecolor_BBBBGGGGRRRRxxxx(offset,paletteram16[offset]); |
| 898 |
} |
| 899 |
|
| 900 |
|
| 901 |
INLINE void changecolor_xBBBBBGGGGGRRRRR(pen_t color,int data) |
| 902 |
{ |
| 903 |
int r,g,b; |
| 904 |
|
| 905 |
|
| 906 |
r = (data >> 0) & 0x1f; |
| 907 |
g = (data >> 5) & 0x1f; |
| 908 |
b = (data >> 10) & 0x1f; |
| 909 |
|
| 910 |
r = (r << 3) | (r >> 2); |
| 911 |
g = (g << 3) | (g >> 2); |
| 912 |
b = (b << 3) | (b >> 2); |
| 913 |
|
| 914 |
palette_set_color(color,r,g,b); |
| 915 |
} |
| 916 |
|
| 917 |
WRITE_HANDLER( paletteram_xBBBBBGGGGGRRRRR_w ) |
| 918 |
{ |
| 919 |
paletteram[offset] = data; |
| 920 |
changecolor_xBBBBBGGGGGRRRRR(offset / 2,paletteram[offset & ~1] | (paletteram[offset | 1] << 8)); |
| 921 |
} |
| 922 |
|
| 923 |
WRITE_HANDLER( paletteram_xBBBBBGGGGGRRRRR_swap_w ) |
| 924 |
{ |
| 925 |
paletteram[offset] = data; |
| 926 |
changecolor_xBBBBBGGGGGRRRRR(offset / 2,paletteram[offset | 1] | (paletteram[offset & ~1] << 8)); |
| 927 |
} |
| 928 |
|
| 929 |
WRITE_HANDLER( paletteram_xBBBBBGGGGGRRRRR_split1_w ) |
| 930 |
{ |
| 931 |
paletteram[offset] = data; |
| 932 |
changecolor_xBBBBBGGGGGRRRRR(offset,paletteram[offset] | (paletteram_2[offset] << 8)); |
| 933 |
} |
| 934 |
|
| 935 |
WRITE_HANDLER( paletteram_xBBBBBGGGGGRRRRR_split2_w ) |
| 936 |
{ |
| 937 |
paletteram_2[offset] = data; |
| 938 |
changecolor_xBBBBBGGGGGRRRRR(offset,paletteram[offset] | (paletteram_2[offset] << 8)); |
| 939 |
} |
| 940 |
|
| 941 |
WRITE16_HANDLER( paletteram16_xBBBBBGGGGGRRRRR_word_w ) |
| 942 |
{ |
| 943 |
COMBINE_DATA(&paletteram16[offset]); |
| 944 |
changecolor_xBBBBBGGGGGRRRRR(offset,paletteram16[offset]); |
| 945 |
} |
| 946 |
|
| 947 |
|
| 948 |
INLINE void changecolor_xRRRRRGGGGGBBBBB(pen_t color,int data) |
| 949 |
{ |
| 950 |
int r,g,b; |
| 951 |
|
| 952 |
|
| 953 |
r = (data >> 10) & 0x1f; |
| 954 |
g = (data >> 5) & 0x1f; |
| 955 |
b = (data >> 0) & 0x1f; |
| 956 |
|
| 957 |
r = (r << 3) | (r >> 2); |
| 958 |
g = (g << 3) | (g >> 2); |
| 959 |
b = (b << 3) | (b >> 2); |
| 960 |
|
| 961 |
palette_set_color(color,r,g,b); |
| 962 |
} |
| 963 |
|
| 964 |
WRITE_HANDLER( paletteram_xRRRRRGGGGGBBBBB_w ) |
| 965 |
{ |
| 966 |
paletteram[offset] = data; |
| 967 |
changecolor_xRRRRRGGGGGBBBBB(offset / 2,paletteram[offset & ~1] | (paletteram[offset | 1] << 8)); |
| 968 |
} |
| 969 |
|
| 970 |
WRITE16_HANDLER( paletteram16_xRRRRRGGGGGBBBBB_word_w ) |
| 971 |
{ |
| 972 |
COMBINE_DATA(&paletteram16[offset]); |
| 973 |
changecolor_xRRRRRGGGGGBBBBB(offset,paletteram16[offset]); |
| 974 |
} |
| 975 |
|
| 976 |
|
| 977 |
INLINE void changecolor_xGGGGGRRRRRBBBBB(pen_t color,int data) |
| 978 |
{ |
| 979 |
int r,g,b; |
| 980 |
|
| 981 |
|
| 982 |
r = (data >> 5) & 0x1f; |
| 983 |
g = (data >> 10) & 0x1f; |
| 984 |
b = (data >> 0) & 0x1f; |
| 985 |
|
| 986 |
r = (r << 3) | (r >> 2); |
| 987 |
g = (g << 3) | (g >> 2); |
| 988 |
b = (b << 3) | (b >> 2); |
| 989 |
|
| 990 |
palette_set_color(color,r,g,b); |
| 991 |
} |
| 992 |
|
| 993 |
WRITE16_HANDLER( paletteram16_xGGGGGRRRRRBBBBB_word_w ) |
| 994 |
{ |
| 995 |
COMBINE_DATA(&paletteram16[offset]); |
| 996 |
changecolor_xGGGGGRRRRRBBBBB(offset,paletteram16[offset]); |
| 997 |
} |
| 998 |
|
| 999 |
|
| 1000 |
INLINE void changecolor_RRRRRGGGGGBBBBBx(pen_t color,int data) |
| 1001 |
{ |
| 1002 |
int r,g,b; |
| 1003 |
|
| 1004 |
|
| 1005 |
r = (data >> 11) & 0x1f; |
| 1006 |
g = (data >> 6) & 0x1f; |
| 1007 |
b = (data >> 1) & 0x1f; |
| 1008 |
|
| 1009 |
r = (r << 3) | (r >> 2); |
| 1010 |
g = (g << 3) | (g >> 2); |
| 1011 |
b = (b << 3) | (b >> 2); |
| 1012 |
|
| 1013 |
palette_set_color(color,r,g,b); |
| 1014 |
} |
| 1015 |
|
| 1016 |
WRITE_HANDLER( paletteram_RRRRRGGGGGBBBBBx_w ) |
| 1017 |
{ |
| 1018 |
paletteram[offset] = data; |
| 1019 |
changecolor_RRRRRGGGGGBBBBBx(offset / 2,paletteram[offset & ~1] | (paletteram[offset | 1] << 8)); |
| 1020 |
} |
| 1021 |
|
| 1022 |
WRITE16_HANDLER( paletteram16_RRRRRGGGGGBBBBBx_word_w ) |
| 1023 |
{ |
| 1024 |
COMBINE_DATA(&paletteram16[offset]); |
| 1025 |
changecolor_RRRRRGGGGGBBBBBx(offset,paletteram16[offset]); |
| 1026 |
} |
| 1027 |
|
| 1028 |
|
| 1029 |
INLINE void changecolor_IIIIRRRRGGGGBBBB(pen_t color,int data) |
| 1030 |
{ |
| 1031 |
int i,r,g,b; |
| 1032 |
|
| 1033 |
|
| 1034 |
static const int ztable[16] = |
| 1035 |
{ 0x0, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0x10, 0x11 }; |
| 1036 |
|
| 1037 |
i = ztable[(data >> 12) & 15]; |
| 1038 |
r = ((data >> 8) & 15) * i; |
| 1039 |
g = ((data >> 4) & 15) * i; |
| 1040 |
b = ((data >> 0) & 15) * i; |
| 1041 |
|
| 1042 |
palette_set_color(color,r,g,b); |
| 1043 |
|
| 1044 |
if (!(Machine->drv->video_attributes & VIDEO_NEEDS_6BITS_PER_GUN)) |
| 1045 |
usrintf_showmessage("driver should use VIDEO_NEEDS_6BITS_PER_GUN flag"); |
| 1046 |
} |
| 1047 |
|
| 1048 |
WRITE16_HANDLER( paletteram16_IIIIRRRRGGGGBBBB_word_w ) |
| 1049 |
{ |
| 1050 |
COMBINE_DATA(&paletteram16[offset]); |
| 1051 |
changecolor_IIIIRRRRGGGGBBBB(offset,paletteram16[offset]); |
| 1052 |
} |
| 1053 |
|
| 1054 |
|
| 1055 |
INLINE void changecolor_RRRRGGGGBBBBIIII(pen_t color,int data) |
| 1056 |
{ |
| 1057 |
int i,r,g,b; |
| 1058 |
|
| 1059 |
|
| 1060 |
static const int ztable[16] = |
| 1061 |
{ 0x0, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0x10, 0x11 }; |
| 1062 |
|
| 1063 |
i = ztable[(data >> 0) & 15]; |
| 1064 |
r = ((data >> 12) & 15) * i; |
| 1065 |
g = ((data >> 8) & 15) * i; |
| 1066 |
b = ((data >> 4) & 15) * i; |
| 1067 |
|
| 1068 |
palette_set_color(color,r,g,b); |
| 1069 |
|
| 1070 |
if (!(Machine->drv->video_attributes & VIDEO_NEEDS_6BITS_PER_GUN)) |
| 1071 |
usrintf_showmessage("driver should use VIDEO_NEEDS_6BITS_PER_GUN flag"); |
| 1072 |
} |
| 1073 |
|
| 1074 |
WRITE16_HANDLER( paletteram16_RRRRGGGGBBBBIIII_word_w ) |
| 1075 |
{ |
| 1076 |
COMBINE_DATA(&paletteram16[offset]); |
| 1077 |
changecolor_RRRRGGGGBBBBIIII(offset,paletteram16[offset]); |
| 1078 |
} |
| 1079 |
|
| 1080 |
|
| 1081 |
WRITE16_HANDLER( paletteram16_xrgb_word_w ) |
| 1082 |
{ |
| 1083 |
int r, g, b; |
| 1084 |
data16_t data0, data1; |
| 1085 |
|
| 1086 |
COMBINE_DATA(paletteram16 + offset); |
| 1087 |
|
| 1088 |
offset &= ~1; |
| 1089 |
|
| 1090 |
data0 = paletteram16[offset]; |
| 1091 |
data1 = paletteram16[offset + 1]; |
| 1092 |
|
| 1093 |
r = data0 & 0xff; |
| 1094 |
g = data1 >> 8; |
| 1095 |
b = data1 & 0xff; |
| 1096 |
|
| 1097 |
palette_set_color(offset>>1, r, g, b); |
| 1098 |
|
| 1099 |
if (!(Machine->drv->video_attributes & VIDEO_NEEDS_6BITS_PER_GUN)) |
| 1100 |
usrintf_showmessage("driver should use VIDEO_NEEDS_6BITS_PER_GUN flag"); |
| 1101 |
} |
| 1102 |
|
| 1103 |
|
| 1104 |
INLINE void changecolor_RRRRGGGGBBBBRGBx(pen_t color,int data) |
| 1105 |
{ |
| 1106 |
int r,g,b; |
| 1107 |
|
| 1108 |
r = ((data >> 11) & 0x1e) | ((data>>3) & 0x01); |
| 1109 |
g = ((data >> 7) & 0x1e) | ((data>>2) & 0x01); |
| 1110 |
b = ((data >> 3) & 0x1e) | ((data>>1) & 0x01); |
| 1111 |
r = (r<<3) | (r>>2); |
| 1112 |
g = (g<<3) | (g>>2); |
| 1113 |
b = (b<<3) | (b>>2); |
| 1114 |
|
| 1115 |
palette_set_color(color,r,g,b); |
| 1116 |
} |
| 1117 |
|
| 1118 |
WRITE16_HANDLER( paletteram16_RRRRGGGGBBBBRGBx_word_w ) |
| 1119 |
{ |
| 1120 |
COMBINE_DATA(&paletteram16[offset]); |
| 1121 |
changecolor_RRRRGGGGBBBBRGBx(offset,paletteram16[offset]); |
| 1122 |
} |
| 1123 |
|
| 1124 |
|
| 1125 |
|
| 1126 |
/****************************************************************************** |
| 1127 |
|
| 1128 |
Commonly used color PROM handling functions |
| 1129 |
|
| 1130 |
******************************************************************************/ |
| 1131 |
|
| 1132 |
/*************************************************************************** |
| 1133 |
|
| 1134 |
This assumes the commonly used resistor values: |
| 1135 |
|
| 1136 |
bit 3 -- 220 ohm resistor -- RED/GREEN/BLUE |
| 1137 |
-- 470 ohm resistor -- RED/GREEN/BLUE |
| 1138 |
-- 1 kohm resistor -- RED/GREEN/BLUE |
| 1139 |
bit 0 -- 2.2kohm resistor -- RED/GREEN/BLUE |
| 1140 |
|
| 1141 |
***************************************************************************/ |
| 1142 |
PALETTE_INIT( RRRR_GGGG_BBBB ) |
| 1143 |
{ |
| 1144 |
int i; |
| 1145 |
|
| 1146 |
|
| 1147 |
for (i = 0;i < Machine->drv->total_colors;i++) |
| 1148 |
{ |
| 1149 |
int bit0,bit1,bit2,bit3,r,g,b; |
| 1150 |
|
| 1151 |
/* red component */ |
| 1152 |
bit0 = (color_prom[i] >> 0) & 0x01; |
| 1153 |
bit1 = (color_prom[i] >> 1) & 0x01; |
| 1154 |
bit2 = (color_prom[i] >> 2) & 0x01; |
| 1155 |
bit3 = (color_prom[i] >> 3) & 0x01; |
| 1156 |
r = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3; |
| 1157 |
/* green component */ |
| 1158 |
bit0 = (color_prom[i + Machine->drv->total_colors] >> 0) & 0x01; |
| 1159 |
bit1 = (color_prom[i + Machine->drv->total_colors] >> 1) & 0x01; |
| 1160 |
bit2 = (color_prom[i + Machine->drv->total_colors] >> 2) & 0x01; |
| 1161 |
bit3 = (color_prom[i + Machine->drv->total_colors] >> 3) & 0x01; |
| 1162 |
g = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3; |
| 1163 |
/* blue component */ |
| 1164 |
bit0 = (color_prom[i + 2*Machine->drv->total_colors] >> 0) & 0x01; |
| 1165 |
bit1 = (color_prom[i + 2*Machine->drv->total_colors] >> 1) & 0x01; |
| 1166 |
bit2 = (color_prom[i + 2*Machine->drv->total_colors] >> 2) & 0x01; |
| 1167 |
bit3 = (color_prom[i + 2*Machine->drv->total_colors] >> 3) & 0x01; |
| 1168 |
b = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3; |
| 1169 |
|
| 1170 |
palette_set_color(i,r,g,b); |
| 1171 |
} |
| 1172 |
} |