mirror of
https://github.com/libretro/beetle-wswan-libretro.git
synced 2024-11-23 07:59:40 +00:00
Merge pull request #64 from jdgleaver/palettes
Add optional WonderSwan 'mono' colourisation palettes
This commit is contained in:
commit
240a116417
90
libretro.c
90
libretro.c
@ -52,6 +52,75 @@ static uint16_t *rotate_buf = NULL;
|
||||
*(out_ptr + y + (((width - 1) - x) * height)) = *(in_ptr + x + (y * width)); \
|
||||
}
|
||||
|
||||
/* Mono palettes */
|
||||
|
||||
struct ws_mono_palette
|
||||
{
|
||||
const char *name;
|
||||
uint32 start;
|
||||
uint32 end;
|
||||
};
|
||||
|
||||
struct ws_mono_palette ws_mono_palettes[] = {
|
||||
{ "default", 0x000000, 0xFFFFFF },
|
||||
{ "wonderswan", 0x3E3D20, 0x9B9D66 },
|
||||
{ "wondeswan_color", 0x1B201E, 0xD7D49D },
|
||||
{ "swancrystal", 0x151108, 0xFFFCCA },
|
||||
{ "gb_dmg", 0x00420C, 0x578200 },
|
||||
{ "gb_pocket", 0x2A3325, 0xA7B19A },
|
||||
{ "gb_light", 0x00778D, 0x01CBDF },
|
||||
{ "blossom_pink", 0x180F0F, 0xF09898 },
|
||||
{ "bubbles_blue", 0x0D1418, 0x88D0F0 },
|
||||
{ "buttercup_green", 0x12160D, 0xB8E088 },
|
||||
{ "digivice", 0x000000, 0x8C8C73 },
|
||||
{ "game_com", 0x000000, 0xA7BF6B },
|
||||
{ "gameking", 0x184221, 0x8CCE94 },
|
||||
{ "game_master", 0x2D2D2B, 0x829FA6 },
|
||||
{ "golden_wild", 0x120F0A, 0xB99F65 },
|
||||
{ "greenscale", 0x0C360C, 0x9CBE0C },
|
||||
{ "hokage_orange", 0x170D08, 0xEA8352 },
|
||||
{ "labo_fawn", 0x15110B, 0xD7AA73 },
|
||||
{ "legendary_super_saiyan", 0x101509, 0xA5DB5A },
|
||||
{ "microvision", 0x303030, 0xA0A0A0 },
|
||||
{ "million_live_gold", 0x141109, 0xCDB261 },
|
||||
{ "odyssey_gold", 0x131000, 0xC2A000 },
|
||||
{ "shiny_sky_blue", 0x0E1216, 0x8CB6DF },
|
||||
{ "slime_blue", 0x040E14, 0x2F8CCC },
|
||||
{ "ti_83", 0x181810, 0x9CA684 },
|
||||
{ "travel_wood", 0x482810, 0xF8D8B0 },
|
||||
{ "virtual_boy", 0x000000, 0xE30000 },
|
||||
{ NULL, 0, 0 },
|
||||
};
|
||||
|
||||
static uint32 mono_pal_start = 0x000000;
|
||||
static uint32 mono_pal_end = 0xFFFFFF;
|
||||
|
||||
static bool find_mono_palette(const char* name,
|
||||
uint32 *start, uint32 *end)
|
||||
{
|
||||
bool palette_found = false;
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; ws_mono_palettes[i].name; i++)
|
||||
{
|
||||
if (!strcmp(ws_mono_palettes[i].name, name))
|
||||
{
|
||||
*start = ws_mono_palettes[i].start;
|
||||
*end = ws_mono_palettes[i].end;
|
||||
palette_found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!palette_found)
|
||||
{
|
||||
*start = 0x000000;
|
||||
*end = 0xFFFFFF;
|
||||
}
|
||||
|
||||
return palette_found;
|
||||
}
|
||||
|
||||
/* Cygne
|
||||
*
|
||||
* Copyright notice for this file:
|
||||
@ -144,7 +213,8 @@ static void Emulate(EmulateSpecStruct *espec, int16_t *sndbuf)
|
||||
espec->DisplayRect.h = 144;
|
||||
|
||||
if(espec->VideoFormatChanged)
|
||||
WSwan_SetPixelFormat(espec->surface->depth);
|
||||
WSwan_SetPixelFormat(espec->surface->depth,
|
||||
mono_pal_start, mono_pal_end);
|
||||
|
||||
if(espec->SoundFormatChanged)
|
||||
WSwan_SetSoundRate(RETRO_SAMPLE_RATE);
|
||||
@ -521,6 +591,8 @@ static void rotate_display(void)
|
||||
static void check_variables(int startup)
|
||||
{
|
||||
struct retro_variable var = {0};
|
||||
uint32 prev_mono_pal_start;
|
||||
uint32 prev_mono_pal_end;
|
||||
|
||||
var.key = "wswan_rotate_display",
|
||||
var.value = NULL;
|
||||
@ -550,6 +622,19 @@ static void check_variables(int startup)
|
||||
rotate_joymap = 2;
|
||||
}
|
||||
|
||||
var.key = "wswan_mono_palette",
|
||||
var.value = NULL;
|
||||
|
||||
prev_mono_pal_start = mono_pal_start;
|
||||
prev_mono_pal_end = mono_pal_end;
|
||||
|
||||
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
|
||||
find_mono_palette(var.value, &mono_pal_start, &mono_pal_end);
|
||||
|
||||
if ((mono_pal_start != prev_mono_pal_start) ||
|
||||
(mono_pal_end != prev_mono_pal_end))
|
||||
WSwan_SetMonoPalette(RETRO_PIX_DEPTH, mono_pal_start, mono_pal_end);
|
||||
|
||||
var.key = "wswan_sound_sample_rate";
|
||||
var.value = NULL;
|
||||
|
||||
@ -707,7 +792,8 @@ bool retro_load_game(const struct retro_game_info *info)
|
||||
|
||||
check_variables(false);
|
||||
|
||||
WSwan_SetPixelFormat(RETRO_PIX_DEPTH);
|
||||
WSwan_SetPixelFormat(RETRO_PIX_DEPTH,
|
||||
mono_pal_start, mono_pal_end);
|
||||
|
||||
update_video = false;
|
||||
update_audio = true;
|
||||
|
@ -72,6 +72,42 @@ struct retro_core_option_definition option_defs_us[] = {
|
||||
},
|
||||
"auto",
|
||||
},
|
||||
{
|
||||
"wswan_mono_palette",
|
||||
"WS Colorization",
|
||||
"Enables colorization of WonderSwan (Mono) games. 'WS' palettes mimic the display of original WonderSwan hardware.",
|
||||
{
|
||||
{ "default", "Greyscale" },
|
||||
{ "wonderswan", "WS - WonderSwan" },
|
||||
{ "wondeswan_color", "WS - WonderSwan Color" },
|
||||
{ "swancrystal", "WS - SwanCrystal" },
|
||||
{ "gb_dmg", "Game Boy DMG" },
|
||||
{ "gb_pocket", "Game Boy Pocket" },
|
||||
{ "gb_light", "Game Boy Light" },
|
||||
{ "blossom_pink", "Blossom Pink" },
|
||||
{ "bubbles_blue", "Bubbles Blue" },
|
||||
{ "buttercup_green", "Buttercup Green" },
|
||||
{ "digivice", "Digivice" },
|
||||
{ "game_com", "Game.com" },
|
||||
{ "gameking", "GameKing" },
|
||||
{ "game_master", "Game Master" },
|
||||
{ "golden_wild", "Golden Wild" },
|
||||
{ "greenscale", "Greenscale" },
|
||||
{ "hokage_orange", "Hokage Orange" },
|
||||
{ "labo_fawn", "Labo Fawn" },
|
||||
{ "legendary_super_saiyan", "Legendary Super Saiyan" },
|
||||
{ "microvision", "Microvision" },
|
||||
{ "million_live_gold", "Million Live Gold" },
|
||||
{ "odyssey_gold", "Odyssey Gold" },
|
||||
{ "shiny_sky_blue", "Shiny Sky Blue" },
|
||||
{ "slime_blue", "Slime Blue" },
|
||||
{ "ti_83", "TI-83" },
|
||||
{ "travel_wood", "Travel Wood" },
|
||||
{ "virtual_boy", "Virtual Boy" },
|
||||
{ NULL, NULL },
|
||||
},
|
||||
"default"
|
||||
},
|
||||
{
|
||||
"wswan_sound_sample_rate",
|
||||
"Sound Output Sample Rate",
|
||||
|
@ -270,9 +270,38 @@ void WSwan_SetLayerEnableMask(uint64 mask)
|
||||
LayerEnabled = mask;
|
||||
}
|
||||
|
||||
void WSwan_SetPixelFormat(int depth)
|
||||
#define LERP_MONO_PALETTE_COLOR(start, end, offset) (uint32)(((float)(((15 - offset) * start) + (offset * end)) / 15.0f) + 0.5f)
|
||||
|
||||
void WSwan_SetMonoPalette(int depth, uint32 mono_start, uint32 mono_end)
|
||||
{
|
||||
unsigned r, g, b, i;
|
||||
unsigned i;
|
||||
|
||||
uint32 r_start = (mono_start >> 16) & 0xFF;
|
||||
uint32 g_start = (mono_start >> 8) & 0xFF;
|
||||
uint32 b_start = (mono_start ) & 0xFF;
|
||||
|
||||
uint32 r_end = (mono_end >> 16) & 0xFF;
|
||||
uint32 g_end = (mono_end >> 8) & 0xFF;
|
||||
uint32 b_end = (mono_end ) & 0xFF;
|
||||
|
||||
for(i = 0; i < 16; i++)
|
||||
{
|
||||
uint32 neo_r = LERP_MONO_PALETTE_COLOR(r_start, r_end, i);
|
||||
uint32 neo_g = LERP_MONO_PALETTE_COLOR(g_start, g_end, i);
|
||||
uint32 neo_b = LERP_MONO_PALETTE_COLOR(b_start, b_end, i);
|
||||
|
||||
switch(depth)
|
||||
{
|
||||
case 15: ColorMapG[i] = MAKECOLOR_15(neo_r, neo_g, neo_b, 0); break;
|
||||
case 16: ColorMapG[i] = MAKECOLOR_16(neo_r, neo_g, neo_b, 0); break;
|
||||
case 24: ColorMapG[i] = MAKECOLOR_24(neo_r, neo_g, neo_b, 0); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WSwan_SetPixelFormat(int depth, uint32 mono_start, uint32 mono_end)
|
||||
{
|
||||
unsigned r, g, b;
|
||||
for(r = 0; r < 16; r++)
|
||||
for(g = 0; g < 16; g++)
|
||||
for(b = 0; b < 16; b++)
|
||||
@ -291,21 +320,7 @@ void WSwan_SetPixelFormat(int depth)
|
||||
}
|
||||
}
|
||||
|
||||
for(i = 0; i < 16; i++)
|
||||
{
|
||||
uint32 neo_r, neo_g, neo_b;
|
||||
|
||||
neo_r = i * 17;
|
||||
neo_g = i * 17;
|
||||
neo_b = i * 17;
|
||||
|
||||
switch(depth)
|
||||
{
|
||||
case 15: ColorMapG[i] = MAKECOLOR_15(neo_r, neo_g, neo_b, 0); break;
|
||||
case 16: ColorMapG[i] = MAKECOLOR_16(neo_r, neo_g, neo_b, 0); break;
|
||||
case 24: ColorMapG[i] = MAKECOLOR_24(neo_r, neo_g, neo_b, 0); break;
|
||||
}
|
||||
}
|
||||
WSwan_SetMonoPalette(depth, mono_start, mono_end);
|
||||
}
|
||||
|
||||
void wsScanline(uint16 *target, int depth)
|
||||
|
@ -26,7 +26,9 @@ void WSWan_TCacheInvalidByAddr(uint32);
|
||||
|
||||
bool wsExecuteLine(MDFN_Surface *surface, bool skip);
|
||||
|
||||
void WSwan_SetPixelFormat(int depth);
|
||||
void WSwan_SetMonoPalette(int depth, uint32 mono_start, uint32 mono_end);
|
||||
|
||||
void WSwan_SetPixelFormat(int depth, uint32 mono_start, uint32 mono_end);
|
||||
|
||||
void WSwan_GfxInit(void);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user