Unverified Commit 14a7544e authored by cayce-msx's avatar cayce-msx Committed by GitHub
Browse files

Optionally load <game>.pal, automatically (was introduced in fMSX 4.0) (#80)

parent 2ab0c266
Pipeline #69731 passed with stages
in 8 minutes and 31 seconds
......@@ -154,26 +154,51 @@ fMSX emulates PSG, SCC and FM-PAC.
Framerate: NTSC (US/JP) implies 60Hz - thus 60FPS, PAL (EU) implies 50Hz (=50FPS). Gameplay and audio actually becomes 17% slower when switching from NTSC to PAL - just like on a real MSX.
### MSX1 colour palette
This is how fMSX implements it by default:
* 0 : 000000
* 1 : 000000
* 2 : 20C020
* 3 : 60E060
* 4 : 2020E0
* 5 : 4060E0
* 6 : A02020
* 7 : 40C0E0
* 8 : E02020
* 9 : E06060
* A : C0C020
* B : C0C080
* C : 208020
* D : C040A0
* E : A0A0A0
* F : E0E0E0
Note: there is some discussion about the 'right' mapping of TMS9918 colours to RGB. This is how fMSX does it.
"To make a custom palette for `Game.rom`, create `Game.pal` [in the same directory] containing 16 #RRGGBB hex values, one per line.
This palette file will be loaded automatically." ([fMSX site](https://fms.komkon.org/fMSX/fMSX.html#LABB), section "New in fMSX 4.0")
The fMSX default:
```
#000000
#000000
#20C020
#60E060
#2020E0
#4060E0
#A02020
#40C0E0
#E02020
#E06060
#C0C020
#C0C080
#208020
#C040A0
#A0A0A0
#E0E0E0
```
Note: [there is some discussion](https://github.com/openMSX/openMSX/issues/1024) about the 'right' mapping of TMS9918 colours to RGB. This is how fMSX does it.
An [example alternative palette](https://paulwratt.github.io/programmers-palettes/HW-MSX/HW-MSX.html) with less vibrant colours is:
```
#000000
#010101
#3eb849
#74d07d
#5955e0
#8076f1
#b95e51
#65dbef
#db6559
#ff897d
#ccc35e
#ded087
#3aa241
#b766b5
#cccccc
#ffffff
```
## Developers
Some information for developers wanting to upgrade to newer fMSX versions, or improve this port.
......
......@@ -21,6 +21,7 @@ static unsigned image_buffer_height;
static uint16_t XPal[80];
static uint16_t BPal[256];
static uint16_t XPal0;
static byte PaletteFrozen=0;
static char FntName_buffer[1024];
......@@ -642,12 +643,23 @@ void set_image_buffer_size(byte screen_mode)
GenericSetVideo(&fMSX_image,0,0,image_buffer_width,image_buffer_height);
}
void replace_ext(char *fname, const char *ext)
{
char *end = fname + strlen(fname);
char *cur = end;
while (cur > fname && *cur != '.') --cur;
if (*cur == '.' && end - cur > strlen(ext)) {
strcpy(cur+1, ext);
}
}
bool retro_load_game(const struct retro_game_info *info)
{
int i;
static char ROMName_buffer[MAXCARTS][1024];
static char DSKName_buffer[MAXDRIVES][1024];
static char CasName_buffer[1024];
static char PalName_buffer[1024];
enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_RGB565;
if (!environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt))
......@@ -686,6 +698,17 @@ bool retro_load_game(const struct retro_game_info *info)
strcpy(CasName_buffer, info->path);
CasName=CasName_buffer;
}
/* Try loading as palette: <basename>.pal */
strncpy(PalName_buffer, info->path, sizeof(PalName_buffer)-1);
PalName_buffer[sizeof(PalName_buffer)-1]=0;
replace_ext(PalName_buffer, "pal");
if(filestream_exists(PalName_buffer) && LoadPAL(PalName_buffer) == 16) PaletteFrozen=1;
else
{
replace_ext(PalName_buffer, "PAL");
if(filestream_exists(PalName_buffer) && LoadPAL(PalName_buffer) == 16) PaletteFrozen=1;
}
}
else
{
......@@ -718,6 +741,7 @@ bool retro_load_game(const struct retro_game_info *info)
void SetColor(byte N,byte R,byte G,byte B)
{
if(PaletteFrozen && N<16) return;
if(N)
XPal[N]=PIXEL(R,G,B);
else
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment