Skip to content

Commit 018af8f

Browse files
philips/mcd212: Darken Black Level (#16262)
-cdi: Improvements to color range: [Vincent Halver] * Adjust black level to account for NTSC white-point/black-point range. * Perform range clamping after plane mixing rather than to each plane independently. * Avoid clobbering VSR field in DCR register. * Expand MCD212 color range from 16-240 to 0-255, significantly improving DVC mixing.
1 parent 02342fb commit 018af8f

2 files changed

Lines changed: 36 additions & 21 deletions

File tree

‎src/mame/philips/mcd212.cpp‎

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -250,15 +250,15 @@ void mcd212_device::set_register(uint8_t reg, uint32_t value)
250250
if (Path == 0)
251251
{
252252
LOGMASKED(LOG_REGISTERS, "%s: Scanline %d, Path 0: Weight Factor A = %08x\n", machine().describe_context(), screen().vpos(), value);
253-
m_weight_factor[0][0] = (uint8_t)value;
253+
m_weight_factor[0][0] = value & 0x3f;
254254
update_matte_arrays();
255255
}
256256
break;
257257
case 0xdc: // Weight Factor B
258258
if (Path == 1)
259259
{
260260
LOGMASKED(LOG_REGISTERS, "%s: Scanline %d, Path 1: Weight Factor B = %08x\n", machine().describe_context(), screen().vpos(), value);
261-
m_weight_factor[1][0] = (uint8_t)value;
261+
m_weight_factor[1][0] = value & 0x3f;
262262
update_matte_arrays();
263263
}
264264
break;
@@ -325,10 +325,10 @@ uint32_t mcd212_device::get_backdrop_plane(int x, int y)
325325
uint32_t argb = 0;
326326
if (m_ext_video && m_ext_video->ext_video_pixel(x, y, argb))
327327
return argb;
328-
return s_4bpp_color[0];
328+
return s_4bpp_display_color[0];
329329
}
330330
else
331-
return s_4bpp_color[m_backdrop_color];
331+
return s_4bpp_display_color[m_backdrop_color];
332332
}
333333

334334
void mcd212_device::process_ica()
@@ -659,6 +659,12 @@ const uint32_t mcd212_device::s_4bpp_color[16] =
659659
0xff101010, 0xff1010e6, 0xff10e610, 0xff10e6e6, 0xffe61010, 0xffe610e6, 0xffe6e610, 0xffe6e6e6
660660
};
661661

662+
const uint32_t mcd212_device::s_4bpp_display_color[16] =
663+
{
664+
0xff000000, 0xff00007b, 0xff007b00, 0xff007b7b, 0xff7b0000, 0xff7b007b, 0xff7b7b00, 0xff7b7b7b,
665+
0xff000000, 0xff0000f9, 0xff00f900, 0xff00f9f9, 0xfff90000, 0xfff900f9, 0xfff9f900, 0xfff9f9f9
666+
};
667+
662668
template <bool MosaicA, bool MosaicB, bool OrderAB>
663669
void mcd212_device::mix_lines(uint32_t *plane_a, bool *transparent_a, uint32_t *plane_b, bool *transparent_b, uint32_t *out)
664670
{
@@ -681,10 +687,12 @@ void mcd212_device::mix_lines(uint32_t *plane_a, bool *transparent_a, uint32_t *
681687
// If PAL and 'Standard' bit set, insert a 24px border on the left/right
682688
if (border_width)
683689
{
684-
std::fill_n(out, border_width, s_4bpp_color[0]);
690+
std::fill_n(out, border_width, s_4bpp_display_color[0]);
685691
out += border_width;
686692
}
687693

694+
const uint32_t *limit = m_dyuv_limit_lut + 0x100;
695+
688696
for (int x = 0; x < width; x++)
689697
{
690698
if (transparent_a[x] && transparent_b[x])
@@ -697,20 +705,20 @@ void mcd212_device::mix_lines(uint32_t *plane_a, bool *transparent_a, uint32_t *
697705

698706
if (transparent_a[x])
699707
{
700-
plane_a_cur = 0;
708+
plane_a_cur = s_4bpp_color[0];
701709
}
702710
else if (OrderAB && (m_transparency_control & TCR_DISABLE_MX))
703711
{
704-
plane_b_cur = 0;
712+
plane_b_cur = s_4bpp_color[0];
705713
}
706714

707715
if (transparent_b[x])
708716
{
709-
plane_b_cur = 0;
717+
plane_b_cur = s_4bpp_color[0];
710718
}
711719
else if (!OrderAB && (m_transparency_control & TCR_DISABLE_MX))
712720
{
713-
plane_a_cur = 0;
721+
plane_a_cur = s_4bpp_color[0];
714722
}
715723

716724
const int32_t plane_a_r = 0xff & (plane_a_cur >> 16);
@@ -720,23 +728,27 @@ void mcd212_device::mix_lines(uint32_t *plane_a, bool *transparent_a, uint32_t *
720728
const int32_t plane_b_g = 0xff & (plane_b_cur >> 8);
721729
const int32_t plane_b_b = 0xff & plane_b_cur;
722730

723-
const int32_t weighted_a_r = std::clamp((std::clamp(plane_a_r - 16, 0, 255) * weight_a[x]) >> 6, 0, 255);
724-
const int32_t weighted_a_g = std::clamp((std::clamp(plane_a_g - 16, 0, 255) * weight_a[x]) >> 6, 0, 255);
725-
const int32_t weighted_a_b = std::clamp((std::clamp(plane_a_b - 16, 0, 255) * weight_a[x]) >> 6, 0, 255);
731+
const int32_t weighted_a_r = ((plane_a_r - 16) * weight_a[x]) >> 6;
732+
const int32_t weighted_a_g = ((plane_a_g - 16) * weight_a[x]) >> 6;
733+
const int32_t weighted_a_b = ((plane_a_b - 16) * weight_a[x]) >> 6;
734+
735+
const int32_t weighted_b_r = ((plane_b_r - 16) * weight_b[x]) >> 6;
736+
const int32_t weighted_b_g = ((plane_b_g - 16) * weight_b[x]) >> 6;
737+
const int32_t weighted_b_b = ((plane_b_b - 16) * weight_b[x]) >> 6;
726738

727-
const int32_t weighted_b_r = std::clamp((std::clamp(plane_b_r - 16, 0, 255) * weight_b[x]) >> 6, 0, 255);
728-
const int32_t weighted_b_g = std::clamp((std::clamp(plane_b_g - 16, 0, 255) * weight_b[x]) >> 6, 0, 255);
729-
const int32_t weighted_b_b = std::clamp((std::clamp(plane_b_b - 16, 0, 255) * weight_b[x]) >> 6, 0, 255);
739+
const uint32_t mixed_r = limit[weighted_a_r + weighted_b_r + 16];
740+
const uint32_t mixed_g = limit[weighted_a_g + weighted_b_g + 16];
741+
const uint32_t mixed_b = limit[weighted_a_b + weighted_b_b + 16];
730742

731-
const uint8_t out_r = std::clamp(weighted_a_r + weighted_b_r + 16, 0, 255);
732-
const uint8_t out_g = std::clamp(weighted_a_g + weighted_b_g + 16, 0, 255);
733-
const uint8_t out_b = std::clamp(weighted_a_b + weighted_b_b + 16, 0, 255);
743+
const uint32_t out_r = limit[((int32_t(mixed_r) - 16) * 298 + 128) >> 8];
744+
const uint32_t out_g = limit[((int32_t(mixed_g) - 16) * 298 + 128) >> 8];
745+
const uint32_t out_b = limit[((int32_t(mixed_b) - 16) * 298 + 128) >> 8];
734746
out[x] = 0xff000000 | (out_r << 16) | (out_g << 8) | out_b;
735747
}
736748

737749
if (border_width)
738750
{
739-
std::fill_n(&out[width], border_width, s_4bpp_color[0]);
751+
std::fill_n(&out[width], border_width, s_4bpp_display_color[0]);
740752
}
741753
}
742754

@@ -762,7 +774,7 @@ void mcd212_device::draw_cursor(uint32_t *scanline)
762774

763775
if ((0 <= y) && (y < 16))
764776
{
765-
const uint32_t color = s_4bpp_color[color_index];
777+
const uint32_t color = s_4bpp_display_color[color_index];
766778
const uint8_t resolution = (m_cursor_control & CURCNT_CUW) ? 1 : 2;
767779
for (int x = 0; x < 16; x++)
768780
{
@@ -817,6 +829,7 @@ uint16_t mcd212_device::dcr1_r(offs_t offset, uint16_t mem_mask)
817829
void mcd212_device::dcr1_w(offs_t offset, uint16_t data, uint16_t mem_mask)
818830
{
819831
LOGMASKED(LOG_MAIN_REG_WRITES, "%s: Display Command Register 1 Write: %04x & %08x\n", machine().describe_context(), data, mem_mask);
832+
mem_mask &= 0xff00;
820833
COMBINE_DATA(&m_dcr[0]);
821834
update_frame_geometry(false);
822835
}
@@ -909,6 +922,7 @@ uint16_t mcd212_device::dcr2_r(offs_t offset, uint16_t mem_mask)
909922
void mcd212_device::dcr2_w(offs_t offset, uint16_t data, uint16_t mem_mask)
910923
{
911924
LOGMASKED(LOG_MAIN_REG_WRITES, "%s: Display Command Register 2 Write: %04x & %08x\n", machine().describe_context(), data, mem_mask);
925+
mem_mask &= 0xff00;
912926
COMBINE_DATA(&m_dcr[1]);
913927
}
914928

@@ -1022,7 +1036,7 @@ uint32_t mcd212_device::screen_update(screen_device &screen, bitmap_rgb32 &bitma
10221036
// If PAL and 'Standard' bit set, insert a 20-line border on the top/bottom
10231037
if ((scanline - m_ica_height < 20) || (scanline >= (m_total_height - 20)))
10241038
{
1025-
std::fill_n(out, 768, s_4bpp_color[0]);
1039+
std::fill_n(out, 768, s_4bpp_display_color[0]);
10261040
draw_line = false;
10271041
}
10281042
}

‎src/mame/philips/mcd212.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ class mcd212_device : public device_t,
268268
bool m_blink_active = false;
269269

270270
static const uint32_t s_4bpp_color[16];
271+
static const uint32_t s_4bpp_display_color[16];
271272

272273
uint8_t get_weight_factor(const uint32_t Matte_idx);
273274
uint8_t get_matte_op(const uint32_t Matte_idx);

0 commit comments

Comments
 (0)