Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CD-i: Add RGB Decoding #13246

Merged
merged 3 commits into from
Jan 25, 2025
Merged

CD-i: Add RGB Decoding #13246

merged 3 commits into from
Jan 25, 2025

Conversation

Vincent-Halver
Copy link
Contributor

@Vincent-Halver Vincent-Halver commented Jan 19, 2025

  1. This fix adds RGB decoding and RGB Transparency bit. It disables transparency color keying for RGB.
  2. It fixes an incorrect enum that was foreshadowed in previous revisions.

As with previous pulls, you can validate this using the Validation Disc (Europe) for the CD-i.

RGB Scroll Test

Due to the enum for CLUT8 and RGB being the same, this previously decoded as a CLUT8 image. When ICM flag 1 is used on path 1, it is instead decoded as RGB.
{24B08B2F-8C6C-4F60-B01C-57E3D8EA26F2}

RGB Draw Test

The house is now the right color
{07289C62-1273-4C22-8A7D-13D5680C3CE2}

Color Keying Test

RGB is now decoded correctly. Additionally, RGB does not match color key. Even when matching "red" colors, notice that the line of RGB still shows red. This is correct behavior, as RGB is not allowed to match color keys.
{827BF19D-391A-4880-9AC2-BD8BA927D76E}

Transparency Control (Uncertain Issue)

The implementation of RGB color keying is to always be false. However the spec says that "RGB cannot use color key tests". Since this would be a misconfiguration in practice... I am not sure what a true console would produce. The Transparency Control shows a different behavior. It's not clear from looking at it whether the change is expected or unexpected.
{9EA9127F-762D-4546-9183-4BC508D6BAFB}

Despite the last image, this change is much closer to correct spec behavior and it's recommended to pull. Someone with a real console should at some point run through all visual tests to get proper reference images.

This fix adds RGB decoding and RGB Transparency bit. It disables transparency color keying for RGB.

It fixes an incorrect enum that was foreshadowed in previous revisions.
const bool transp_always = (transp_ctrl_masked == TCR_COND_1);
const bool invert_transp_condition = BIT(transp_ctrl, 3);
const int region_flag_index = 1 - (transp_ctrl_masked & 1);
const bool *region_flags = m_region_flag[region_flag_index];
const bool use_region_flag = (transp_ctrl_masked >= TCR_COND_RF0_1 && transp_ctrl_masked <= TCR_COND_RF1KEY_1);
bool use_color_key = (transp_ctrl_masked == TCR_COND_KEY_1 || transp_ctrl_masked == TCR_COND_RF0KEY_1 || transp_ctrl_masked == TCR_COND_RF1KEY_1);
bool use_color_key = (icm != ICM_DYUV && !(icm == ICM_RGB555 && Path == 1)) && (transp_ctrl_masked == TCR_COND_KEY_1 || transp_ctrl_masked == TCR_COND_RF0KEY_1 || transp_ctrl_masked == TCR_COND_RF1KEY_1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition is starting to grow up excessively out of the sake of respecting enums a bit too much (defeating the purpose of readability).
It also looks something that have performance implications, it looks to me that a Color Key check is done with transp_ctrl_masked bit 0 then bit 3 reverses the meaning?

At bare minimum this needs a // FIXME: because latter doesn't seem implemented anyway.

Copy link
Contributor Author

@Vincent-Halver Vincent-Halver Jan 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reference enum table from the greenbook spec is added to a comment below. Color Key is used only when the control type is 1, 5 or 6 (or 9, 13, or 14 when negated). I'm having trouble coming up with a good way to formulate it. The enum check is probably the clearest.

Hopefully with the variable renaming and logic patch, it's a little bit easier to understand the logic flow.

The FIXME is probably not needed. The original code does reverse it, but it used logic that was indeed both hard to understand, and incorrect for comparison type 13 and 14 (see notes in the patch). As far as I know, the patched version no longer has any known logic issues, unless someone has a reference from a real console.

@angelosa
Copy link
Member

As with previous pulls, you can validate this using the Validation Disc (Europe) for the CD-i.

I gave a cursory glance yesterday, mame cdimono1 valdisc boots disc 1 if you adhere to using hash directory 59194f1

1. Changes the way that negated transparency condition is calculated.
2. Renames COND enums to be easier to read.
3. Renames `transp` variables to be more succinct.
4. Allman Style
@Vincent-Halver
Copy link
Contributor Author

Vincent-Halver commented Jan 20, 2025

Sadly there doesn't seem to be more trivial bit logic, as the enums the core uses are not lined up in a convenient way. Instead, the enums and variables were renamed for readability.

Additionally, I'm including a change to the way that negated transparency is calculated. This was something the spec was not very clear on, however I think it's likely correct now. There are no known tests that check the changed condition, however all tests looks the same so it probably didn't make things worse.

  • Originally: condition 13 was commented as Region Flag 0 = False && Color Key = False
  • NEW: condition 13 is commented (and calculated) as Region Flag 0 = False || Color Key = False

This matches the greenbook definition now.
NOTE: The spec uses "matte" everywhere that the code uses "region". I will fix this naming convention when I submit the changes to the matte calculations in a future change.
{3235971F-ECDF-48D1-9BA8-6A95678B8FBB}

I don't know of any real cases that use this condition. All tests that I checked looked the same as far as I could tell.

@cuavas
Copy link
Member

cuavas commented Jan 20, 2025

@MooglyGuy could you give this a quick look?

@cuavas cuavas merged commit 7cc6ac9 into mamedev:master Jan 25, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants