Skip to content

Commit

Permalink
(hack) expose ps1 semi-transparent bit, previews lie less
Browse files Browse the repository at this point in the history
  • Loading branch information
y-ack committed Jan 16, 2023
1 parent e30baca commit 222710f
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 14 deletions.
58 changes: 58 additions & 0 deletions palmod/ColorSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ namespace ColorSystem
case ColMode::COLMODE_GRB555_LE:
case ColMode::COLMODE_BRG555_LE:
case ColMode::COLMODE_RGB666_NEOGEO:
case ColMode::COLMODE_BGR555STB_LE:
return 2;

case ColMode::COLMODE_BGR888:
Expand Down Expand Up @@ -117,6 +118,7 @@ namespace ColorSystem
{ "BRG888", ColMode::COLMODE_BRG888 },
{ "xBGR555LE", ColMode::COLMODE_xBGR555_LE }, // Different packing used by Asura Buster / Fuuki
{ "BRG555LE", ColMode::COLMODE_BRG555_LE }, // BRG555 little endian, used by Fists of Fury
{ "BGR555STB_LE", ColMode::COLMODE_BGR555STB_LE },
};

bool GetColorFormatForColorFormatString(LPCSTR paszColorString, ColMode& cmColorMode)
Expand Down Expand Up @@ -253,6 +255,7 @@ namespace ColorSystem
case ColMode::COLMODE_GRB555_LE:
case ColMode::COLMODE_BRG555_LE:
case ColMode::COLMODE_RGB555_SHARP:
case ColMode::COLMODE_BGR555STB_LE:
return k_nRGBPlaneAmtForRGB555;

case ColMode::COLMODE_RGB666_NEOGEO:
Expand Down Expand Up @@ -418,6 +421,61 @@ namespace ColorSystem
return (((auxr >> 3) & 31) | (((auxg >> 3) & 31) << 5) | (((auxb >> 3) & 31) << 10)) | (auxa << 15);
}

uint32_t CONV_BGR555STBLE_32(uint16_t inCol)
{
if (inCol == 0x0000) {
return 0x00000000;
} else if (inCol == 0x8000) {
return 0xFF000000;
}

uint32_t red = (inCol & 31) << 3;
uint32_t green = ((inCol >> 5) & 31) << 3;
uint32_t blue = ((inCol >> 10) & 31) << 3;
uint32_t alpha = ((inCol >> 15) & 1) << 3;

// account for rounding
red += red / 32;
green += green / 32;
blue += blue / 32;

if (alpha == 0x8)
{
alpha = 0x7F;
}
else
{
alpha = 0xFF;
}

return ((alpha << 24) | (blue << 16) | (green << 8) | (red));
}

uint16_t CONV_32_BGR555STBLE(uint32_t inCol)
{
if (inCol == 0x00000000) {
return 0x0000;
} else if (inCol == 0xFF000000) {
return 0x8000;
}

uint16_t auxa = ((inCol & 0xFF000000) >> 24);
uint16_t auxb = ((inCol & 0x00FF0000) >> 16);
uint16_t auxg = ((inCol & 0x0000FF00) >> 8);
uint16_t auxr = ((inCol & 0x000000FF));

if (CurrAlphaMode == AlphaMode::GameDoesNotUseAlpha)
{
auxa = 0;
}
else
{
auxa = (auxa == 0x7F) ? 0x1 : 0;
}

return (((auxr >> 3) & 31) | (((auxg >> 3) & 31) << 5) | (((auxb >> 3) & 31) << 10)) | (auxa << 15);
}

uint32_t CONV_BGR555BE_32(uint16_t inCol)
{
return CONV_BGR555LE_32(_byteswap_ushort(inCol));
Expand Down
4 changes: 4 additions & 0 deletions palmod/ColorSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ enum class ColMode

COLMODE_BRG555_LE, // used by Fists of Fury

COLMODE_BGR555STB_LE, // semi-transparency bit for ps1

COLMODE_LAST,
};

Expand Down Expand Up @@ -105,6 +107,8 @@ namespace ColorSystem
uint32_t CONV_GRB555LE_32(uint16_t inCol);
uint16_t CONV_32_BRG555LE(uint32_t inCol);
uint32_t CONV_BRG555LE_32(uint16_t inCol);
uint16_t CONV_32_BGR555STBLE(uint32_t inCol);
uint32_t CONV_BGR555STBLE_32(uint16_t inCol);

// Lookup tables
uint16_t CONV_32_RGB666NeoGeo(uint32_t inCol);
Expand Down
9 changes: 7 additions & 2 deletions palmod/Game/GameClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ bool CGameClass::_UpdateColorSteps(ColMode NewMode)
{
bool fSuccess = true;

static_assert((ColMode)28 == ColMode::COLMODE_LAST, "New color formats require updating the color steps code.");
static_assert((ColMode)29 == ColMode::COLMODE_LAST, "New color formats require updating the color steps code.");

switch (NewMode)
{
Expand Down Expand Up @@ -165,6 +165,7 @@ bool CGameClass::_UpdateColorSteps(ColMode NewMode)
break;

case ColMode::COLMODE_BGR555_LE:
case ColMode::COLMODE_BGR555STB_LE:
case ColMode::COLMODE_BGR555_BE:
case ColMode::COLMODE_xBGR555_LE:
case ColMode::COLMODE_RGB555_LE:
Expand Down Expand Up @@ -272,7 +273,7 @@ bool CGameClass::_UpdateColorConverters(ColMode NewMode)
{
bool fSuccess = true;

static_assert((ColMode)28 == ColMode::COLMODE_LAST, "New color formats require updating the color converter code.");
static_assert((ColMode)29 == ColMode::COLMODE_LAST, "New color formats require updating the color converter code.");

switch (NewMode)
{
Expand Down Expand Up @@ -314,6 +315,10 @@ bool CGameClass::_UpdateColorConverters(ColMode NewMode)
ConvPal16 = &ColorSystem::CONV_BGR555LE_32;
ConvCol16 = &ColorSystem::CONV_32_BGR555LE;
break;
case ColMode::COLMODE_BGR555STB_LE:
ConvPal16 = &ColorSystem::CONV_BGR555STBLE_32;
ConvCol16 = &ColorSystem::CONV_32_BGR555STBLE;
break;
case ColMode::COLMODE_BGR555_BE:
ConvPal16 = &ColorSystem::CONV_BGR555BE_32;
ConvCol16 = &ColorSystem::CONV_32_BGR555BE;
Expand Down
3 changes: 3 additions & 0 deletions palmod/Game/GameDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ enum SupportedGamesList
DUMMY_RGBA8881 = 85,
DUMMY_RGBA8888_LE = 86,

DUMMY_BGR555STB_LE,

NUM_GAMES // This needs to be last
};

Expand Down Expand Up @@ -151,6 +153,7 @@ const wchar_t g_GameFriendlyName[][64] =
L"",
L"DUMMY_RGBA8881",
L"DUMMY_RGB8888LE",
L"DUMMY_BGR555STB_LE"
};

static_assert(ARRAYSIZE(g_GameFriendlyName) == NUM_GAMES, "The gameId enum and the descriptors in g_GameFriendlyName must match length.");
Expand Down
4 changes: 3 additions & 1 deletion palmod/Game/Game_DevMode_DIR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -628,11 +628,12 @@ bool CGame_DevMode_DIR::SetAlphaAndColorModeInternal(ColMode NewMode, AlphaMode
// ID_COLORFORMAT_BGR555_BE
// ID_COLORFORMAT_xBGR555_LE
// ID_COLORFORMAT_BRG555_LE
// ID_COLORFORMAT_BGR555STB_LE
// I am explicitly and needlessly listing out all of those string IDs because Visual Studio search sometimes misses the color modes below,
// and we have to add explicit color handling here so that people can change to that color mode in Unknown Game mode

// Update this check once you've decided whether to expose the new color or not.
static_assert((ColMode)28 == ColMode::COLMODE_LAST, "New color formats usually mean updating color selectability in the Developer Mode support.");
static_assert((ColMode)29 == ColMode::COLMODE_LAST, "New color formats usually mean updating color selectability in the Developer Mode support.");

switch (NewMode)
{
Expand Down Expand Up @@ -660,6 +661,7 @@ bool CGame_DevMode_DIR::SetAlphaAndColorModeInternal(ColMode NewMode, AlphaMode
case ColMode::COLMODE_RGB555_LE:
case ColMode::COLMODE_xBGR555_LE:
case ColMode::COLMODE_RGB555_BE:
case ColMode::COLMODE_BGR555STB_LE:
cbRequiredColorSize = 2;
suggestedAlphaSetting = AlphaMode::GameUsesFixedAlpha;
m_fGameUsesAlphaValue = true;
Expand Down
8 changes: 5 additions & 3 deletions palmod/Game/Game_LandMaker_P.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@ class CGame_LandMaker_P : public CGameClassPerUnitPerFile
LandMaker_P_IMGIDS_USED,
{ NO_SPECIAL_OPTIONS, PALWriteOutputOptions::WRITE_MAX },
eImageOutputSpriteDisplay::DISPLAY_SPRITES_LEFTTORIGHT,
AlphaMode::GameDoesNotUseAlpha,
ColMode::COLMODE_BGR555_LE,
AlphaMode::GameUsesVariableAlpha,
ColMode::COLMODE_BGR555STB_LE,
LandMaker_P_CharacterData,
PaletteArrangementStyle::OneButtonLabelEntryPerEachNode,
0x40,
};


public:
CGame_LandMaker_P(uint32_t nConfirmedROMSize) { InitializeGame(nConfirmedROMSize, m_sCoreGameData); };
CGame_LandMaker_P(uint32_t nConfirmedROMSize) { InitializeGame(nConfirmedROMSize, m_sCoreGameData);
AllowTransparencyEdits(TRUE);
};
~CGame_LandMaker_P() { ClearDataBuffer(); FlushChangeTrackingArray(); };

static sFileRule GetRule(uint32_t nRuleId) { return CGameClassPerUnitPerFile::GetRule(nRuleId, LandMaker_P_CharacterData);
Expand Down
4 changes: 3 additions & 1 deletion palmod/Game/Game_NEOGEO_A.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,12 @@ bool CGame_NEOGEO_A::SetAlphaAndColorModeInternal(ColMode NewMode, AlphaMode Cur
// ID_COLORFORMAT_BGR555_BE
// ID_COLORFORMAT_xBGR555_LE
// ID_COLORFORMAT_BRG555_LE
// ID_COLORFORMAT_BGR555STB_LE
// I am explicitly and needlessly listing out all of those string IDs because Visual Studio search sometimes misses the color modes below,
// and we have to add explicit color handling here so that people can change to that color mode in Unknown Game mode

// Update this check once you've decided whether to expose the new color or not.
static_assert((ColMode)28 == ColMode::COLMODE_LAST, "New color formats usually mean updating color selectability in the Developer Mode support.");
static_assert((ColMode)29 == ColMode::COLMODE_LAST, "New color formats usually mean updating color selectability in the Developer Mode support.");

switch (NewMode)
{
Expand Down Expand Up @@ -191,6 +192,7 @@ bool CGame_NEOGEO_A::SetAlphaAndColorModeInternal(ColMode NewMode, AlphaMode Cur
case ColMode::COLMODE_RGB555_LE:
case ColMode::COLMODE_xBGR555_LE:
case ColMode::COLMODE_RGB555_BE:
case ColMode::COLMODE_BGR555STB_LE:
cbRequiredColorSize = 2;
suggestedAlphaSetting = AlphaMode::GameUsesFixedAlpha;
m_fGameUsesAlphaValue = true;
Expand Down
3 changes: 2 additions & 1 deletion palmod/PalMod.rc
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,8 @@ BEGIN
MENUITEM "RGB444 (big endian for CPS1/CPS2)", ID_COLORFORMAT_RGB444_BE
MENUITEM "RGB444 (little endian for SF2/SFA 30th)", ID_COLORFORMAT_RGB444_LE
MENUITEM SEPARATOR
MENUITEM "BGR555 (little endian for GBA, most PSX, SNES)", ID_COLORFORMAT_BGR555_LE
MENUITEM "BGR555 (little endian for GBA, SNES)", ID_COLORFORMAT_BGR555_LE
MENUITEM "BGR555 (little endian for most PSX)", ID_COLORFORMAT_BGR555STB_LE
MENUITEM "BGR555 (little endian for Fuuki)", ID_COLORFORMAT_xBGR555_LE
MENUITEM "BGR555 (big endian for Motorola 68000)", ID_COLORFORMAT_BGR555_BE
MENUITEM "BRG555 (little endian)", ID_COLORFORMAT_BRG555_LE
Expand Down
5 changes: 3 additions & 2 deletions palmod/PalModDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void CPalModDlg::DoDataExchange(CDataExchange* pDX)
#pragma warning( push )
#pragma warning( disable : 26454 ) // bug in Microsoft headers

static_assert((ColMode)28 == ColMode::COLMODE_LAST, "New color formats need menu command handlers added to the message map.");
static_assert((ColMode)29 == ColMode::COLMODE_LAST, "New color formats need menu command handlers added to the message map.");

// CPalModDlg message handlers
BEGIN_MESSAGE_MAP(CPalModDlg, CDialog)
Expand Down Expand Up @@ -207,7 +207,8 @@ BEGIN_MESSAGE_MAP(CPalModDlg, CDialog)
ON_COMMAND(ID_COLORFORMAT_RGB555_LE, &CPalModDlg::SetColorFormatToRGB555_LE)
ON_COMMAND(ID_COLORFORMAT_RGB555_BE, &CPalModDlg::SetColorFormatToRGB555_BE)
ON_COMMAND(ID_COLORFORMAT_xBGR555_LE, &CPalModDlg::SetColorFormatToxBGR555_LE)

ON_COMMAND(ID_COLORFORMAT_BGR555STB_LE, &CPalModDlg::SetColorFormatToBGR555STB_LE)


ON_COMMAND(ID_COLORFORMAT_RGB666, &CPalModDlg::SetColorFormatToNEOGEO)
ON_COMMAND(ID_COLORFORMAT_SHARPRGB, &CPalModDlg::SetColorFormatToSharpRGB)
Expand Down
3 changes: 2 additions & 1 deletion palmod/PalModDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class CPalModDlg : public CDialog
void SetColorsPerLineTo16();
void SetColorFormatTo(ColMode newColMode);

static_assert((ColMode)28 == ColMode::COLMODE_LAST, "New color formats need functions backing their menu command added here.");
static_assert((ColMode)29 == ColMode::COLMODE_LAST, "New color formats need functions backing their menu command added here.");

void SetColorFormatToBGR333() { SetColorFormatTo(ColMode::COLMODE_BGR333); };
void SetColorFormatToRBG333() { SetColorFormatTo(ColMode::COLMODE_RBG333); };
Expand All @@ -128,6 +128,7 @@ class CPalModDlg : public CDialog
void SetColorFormatToRGB555_BE() { SetColorFormatTo(ColMode::COLMODE_RGB555_BE); };
void SetColorFormatToRGB555_LE() { SetColorFormatTo(ColMode::COLMODE_RGB555_LE); };
void SetColorFormatToxBGR555_LE() { SetColorFormatTo(ColMode::COLMODE_xBGR555_LE); };
void SetColorFormatToBGR555STB_LE() { SetColorFormatTo(ColMode::COLMODE_BGR555STB_LE); };

void SetColorFormatToNEOGEO() { SetColorFormatTo(ColMode::COLMODE_RGB666_NEOGEO); };
void SetColorFormatToSharpRGB() { SetColorFormatTo(ColMode::COLMODE_RGB555_SHARP); };
Expand Down
6 changes: 4 additions & 2 deletions palmod/PalModDlg_File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ void CPalModDlg::UpdateColorFormatMenu()
PALWriteOutputOptions currWriteMode = GetHost()->GetCurrGame()->GetMaximumWritePerEachTransparency();
canChangeAlpha = canChangeFormat = GetHost()->GetCurrGame()->AllowUpdatingColorFormatForGame();

static_assert((ColMode)28 == ColMode::COLMODE_LAST, "New color formats need checking/unchecking in the menus here.");
static_assert((ColMode)29 == ColMode::COLMODE_LAST, "New color formats need checking/unchecking in the menus here.");
pSettMenu->CheckMenuItem(ID_COLORFORMAT_BGR333, MF_BYCOMMAND | ((currColMode == ColMode::COLMODE_BGR333) ? MF_CHECKED : MF_UNCHECKED));
pSettMenu->CheckMenuItem(ID_COLORFORMAT_RBG333, MF_BYCOMMAND | ((currColMode == ColMode::COLMODE_RBG333) ? MF_CHECKED : MF_UNCHECKED));
pSettMenu->CheckMenuItem(ID_COLORFORMAT_RGB333_BE, MF_BYCOMMAND | ((currColMode == ColMode::COLMODE_RGB333) ? MF_CHECKED : MF_UNCHECKED));
Expand All @@ -307,6 +307,7 @@ void CPalModDlg::UpdateColorFormatMenu()
pSettMenu->CheckMenuItem(ID_COLORFORMAT_xBGR555_LE, MF_BYCOMMAND | ((currColMode == ColMode::COLMODE_xBGR555_LE) ? MF_CHECKED : MF_UNCHECKED));
pSettMenu->CheckMenuItem(ID_COLORFORMAT_RGB555_BE, MF_BYCOMMAND | ((currColMode == ColMode::COLMODE_RGB555_BE) ? MF_CHECKED : MF_UNCHECKED));
pSettMenu->CheckMenuItem(ID_COLORFORMAT_BGR555_LE, MF_BYCOMMAND | ((currColMode == ColMode::COLMODE_BGR555_LE) ? MF_CHECKED : MF_UNCHECKED));
pSettMenu->CheckMenuItem(ID_COLORFORMAT_BGR555STB_LE, MF_BYCOMMAND | ((currColMode == ColMode::COLMODE_BGR555STB_LE) ? MF_CHECKED : MF_UNCHECKED));
pSettMenu->CheckMenuItem(ID_COLORFORMAT_BGR555_BE, MF_BYCOMMAND | ((currColMode == ColMode::COLMODE_BGR555_BE) ? MF_CHECKED : MF_UNCHECKED));
pSettMenu->CheckMenuItem(ID_COLORFORMAT_SHARPRGB, MF_BYCOMMAND | ((currColMode == ColMode::COLMODE_RGB555_SHARP) ? MF_CHECKED : MF_UNCHECKED));
pSettMenu->CheckMenuItem(ID_COLORFORMAT_BRG555_LE, MF_BYCOMMAND | ((currColMode == ColMode::COLMODE_BRG555_LE) ? MF_CHECKED : MF_UNCHECKED));
Expand Down Expand Up @@ -376,7 +377,7 @@ void CPalModDlg::UpdateColorFormatMenu()
}
}

static_assert((ColMode)28 == ColMode::COLMODE_LAST, "New color formats need enabling/disabling in the menus here.");
static_assert((ColMode)29 == ColMode::COLMODE_LAST, "New color formats need enabling/disabling in the menus here.");
pSettMenu->EnableMenuItem(ID_COLORFORMAT_BGR333, canChangeFormat ? MF_ENABLED : MF_DISABLED);
pSettMenu->EnableMenuItem(ID_COLORFORMAT_RBG333, canChangeFormat ? MF_ENABLED : MF_DISABLED);
pSettMenu->EnableMenuItem(ID_COLORFORMAT_RGB333_BE, canChangeFormat ? MF_ENABLED : MF_DISABLED);
Expand All @@ -388,6 +389,7 @@ void CPalModDlg::UpdateColorFormatMenu()
pSettMenu->EnableMenuItem(ID_COLORFORMAT_RGB444_LE, canChangeFormat ? MF_ENABLED : MF_DISABLED);

pSettMenu->EnableMenuItem(ID_COLORFORMAT_BGR555_LE, canChangeFormat ? MF_ENABLED : MF_DISABLED);
pSettMenu->EnableMenuItem(ID_COLORFORMAT_BGR555STB_LE, canChangeFormat ? MF_ENABLED : MF_DISABLED);
pSettMenu->EnableMenuItem(ID_COLORFORMAT_BGR555_BE, canChangeFormat ? MF_ENABLED : MF_DISABLED);
pSettMenu->EnableMenuItem(ID_COLORFORMAT_BRG555_LE, canChangeFormat ? MF_ENABLED : MF_DISABLED);
pSettMenu->EnableMenuItem(ID_COLORFORMAT_GRB555_LE, canChangeFormat ? MF_ENABLED : MF_DISABLED);
Expand Down
3 changes: 2 additions & 1 deletion palmod/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -366,13 +366,14 @@
#define ID_COLORFORMAT_BRG555_LE 32944
#define ID_LD_GGXXACP_Wii 32945
#define ID_LD_LANDMAKER_P 32946
#define ID_COLORFORMAT_BGR555STB_LE 32947

// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 149
#define _APS_NEXT_COMMAND_VALUE 32947
#define _APS_NEXT_COMMAND_VALUE 32948
#define _APS_NEXT_CONTROL_VALUE 1091
#define _APS_NEXT_SYMED_VALUE 104
#endif
Expand Down

0 comments on commit 222710f

Please sign in to comment.