From 5fba45b0bc24fe41c75c334156a2ee4a5918c4c5 Mon Sep 17 00:00:00 2001 From: AJR Date: Sun, 5 Nov 2017 21:49:27 -0500 Subject: [PATCH] v9938, v9958: Convert to use RGB32 bitmaps - Palette has been retained mostly for the sake of the palette viewer, and now reflects the actual programmed values, rather than being a fixed RRRGGGBBB encoding plus a hacky mess for the V9958's YJK colors. - V9938-on-V9938 transparent overlay is fixed for meritm.cpp (was broken a few releases ago). --- src/devices/bus/a2bus/ezcgi.cpp | 2 - src/devices/video/v9938.cpp | 250 +++++++++++++------------------- src/devices/video/v9938.h | 67 +++++---- src/emu/divideo.cpp | 4 +- src/emu/drawgfx.cpp | 12 ++ src/emu/drawgfx.h | 4 +- src/emu/drawgfxm.h | 15 ++ src/mame/drivers/meritm.cpp | 8 +- 8 files changed, 173 insertions(+), 189 deletions(-) diff --git a/src/devices/bus/a2bus/ezcgi.cpp b/src/devices/bus/a2bus/ezcgi.cpp index e7e3a693fd6..f1d782a80bc 100644 --- a/src/devices/bus/a2bus/ezcgi.cpp +++ b/src/devices/bus/a2bus/ezcgi.cpp @@ -59,7 +59,6 @@ MACHINE_CONFIG_MEMBER( a2bus_ezcgi_9938_device::device_add_mconfig ) MCFG_SCREEN_UPDATE_DEVICE(TMS_TAG, v9938_device, screen_update) MCFG_SCREEN_SIZE(MSX2_TOTAL_XRES_PIXELS, 262*2) MCFG_SCREEN_VISIBLE_AREA(MSX2_XBORDER_PIXELS - MSX2_VISIBLE_XBORDER_PIXELS, MSX2_TOTAL_XRES_PIXELS - MSX2_XBORDER_PIXELS + MSX2_VISIBLE_XBORDER_PIXELS - 1, MSX2_YBORDER_PIXELS - MSX2_VISIBLE_YBORDER_PIXELS, MSX2_TOTAL_YRES_PIXELS - MSX2_YBORDER_PIXELS + MSX2_VISIBLE_YBORDER_PIXELS - 1) - MCFG_SCREEN_PALETTE(TMS_TAG) MACHINE_CONFIG_END MACHINE_CONFIG_MEMBER( a2bus_ezcgi_9958_device::device_add_mconfig ) @@ -73,7 +72,6 @@ MACHINE_CONFIG_MEMBER( a2bus_ezcgi_9958_device::device_add_mconfig ) MCFG_SCREEN_UPDATE_DEVICE(TMS_TAG, v9938_device, screen_update) MCFG_SCREEN_SIZE(MSX2_TOTAL_XRES_PIXELS, 262*2) MCFG_SCREEN_VISIBLE_AREA(MSX2_XBORDER_PIXELS - MSX2_VISIBLE_XBORDER_PIXELS, MSX2_TOTAL_XRES_PIXELS - MSX2_XBORDER_PIXELS + MSX2_VISIBLE_XBORDER_PIXELS - 1, MSX2_YBORDER_PIXELS - MSX2_VISIBLE_YBORDER_PIXELS, MSX2_TOTAL_YRES_PIXELS - MSX2_YBORDER_PIXELS + MSX2_VISIBLE_YBORDER_PIXELS - 1) - MCFG_SCREEN_PALETTE(TMS_TAG) MACHINE_CONFIG_END //************************************************************************** diff --git a/src/devices/video/v9938.cpp b/src/devices/video/v9938.cpp index f5925cf1f48..ef202e914d4 100644 --- a/src/devices/video/v9938.cpp +++ b/src/devices/video/v9938.cpp @@ -240,21 +240,24 @@ void v99x8_device::configure_pal_ntsc() } +#ifdef UNUSED_FUNCTION /* Not really right... won't work with sprites in graphics 7 and with palette updated mid-screen */ -int v99x8_device::get_transpen() +pen_t v99x8_device::get_transpen() const { if (m_mode == V9938_MODE_GRAPHIC7) { - return m_pal_ind256[0]; + return pen256(0); } else { - return m_pal_ind16[0]; + return pen16(0); } } +#endif + /* Driver-specific function: update the vdp mouse state @@ -309,11 +312,6 @@ b0 is set if b2 and b1 are set (remember, color bus is 3 bits) void v9938_device::palette_init() { - int i; - - // create the full 512 colour palette - for (i=0;i<512;i++) - set_pen_color(i, pal3bit(i >> 6), pal3bit(i >> 3), pal3bit(i >> 0)); } /* @@ -327,23 +325,15 @@ to emulate this. Also it keeps the palette a reasonable size. :) */ -uint16_t v99x8_device::s_pal_indYJK[0x20000]; +uint32_t v99x8_device::s_pal_indYJK[0x20000]; void v9958_device::palette_init() { - int r,g,b,y,j,k,i,k0,j0,n; - uint8_t pal[19268*3]; - - // init v9938 512-color palette - for (i=0;i<512;i++) - set_pen_color(i, pal3bit(i >> 6), pal3bit(i >> 3), pal3bit(i >> 0)); - - if (entries() != 19780) - fatalerror("V9958: not enough palette, must be 19780"); + int r,g,b,y,j,k,k0,j0; // set up YJK table LOG("Building YJK table for V9958 screens, may take a while ... \n"); - i = 0; + for (y=0;y<32;y++) for (k=0;k<64;k++) for (j=0;j<64;j++) { // calculate the color @@ -356,38 +346,11 @@ void v9958_device::palette_init() if (g < 0) g = 0; else if (g > 31) g = 31; if (b < 0) b = 0; else if (b > 31) b = 31; - //r = (r << 3) | (r >> 2); - //b = (b << 3) | (b >> 2); - //g = (g << 3) | (g >> 2); - // have we seen this one before? - n = 0; - while (n < i) - { - if (pal[n*3+0] == r && pal[n*3+1] == g && pal[n*3+2] == b) - { - v99x8_device::s_pal_indYJK[y | j << 5 | k << (5 + 6)] = n + 512; - break; - } - n++; - } - - if (i == n) - { - // so we haven't; add it - pal[i*3+0] = r; - pal[i*3+1] = g; - pal[i*3+2] = b; - set_pen_color(i+512, rgb_t(pal5bit(r), pal5bit(g), pal5bit(b))); - v99x8_device::s_pal_indYJK[y | j << 5 | k << (5 + 6)] = i + 512; - i++; - } + v99x8_device::s_pal_indYJK[y | j << 5 | k << (5 + 6)] = uint32_t(rgb_t(pal5bit(r), pal5bit(g), pal5bit(b))); } - - if (i != 19268) - LOG("Table creation failed - %d colours out of 19286 created\n", i); } -uint32_t v99x8_device::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect) +uint32_t v99x8_device::screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect) { copybitmap(bitmap, m_bitmap, 0, 0, 0, 0, cliprect); return 0; @@ -530,10 +493,9 @@ void v99x8_device::palette_w(uint8_t data) indexp = m_cont_reg[0x10] & 15; m_pal_reg[indexp*2] = m_pal_write & 0x77; m_pal_reg[indexp*2+1] = data & 0x07; + // update palette - m_pal_ind16[indexp] = (((int)m_pal_write << 2) & 0x01c0) | - (((int)data << 3) & 0x0038) | - ((int)m_pal_write & 0x0007); + set_pen16(indexp, uint32_t(rgb_t(pal3bit((m_pal_write & 0x70) >> 4), pal3bit(data & 0x07), pal3bit(m_pal_write & 0x07)))); m_cont_reg[0x10] = (m_cont_reg[0x10] + 1) & 15; m_pal_write_first = 0; @@ -668,8 +630,6 @@ void v99x8_device::device_start() save_item(NAME(m_mx_delta)); save_item(NAME(m_my_delta)); save_item(NAME(m_button_state)); - save_item(NAME(m_pal_ind16)); - save_item(NAME(m_pal_ind256)); save_item(NAME(m_mmc.SX)); save_item(NAME(m_mmc.SY)); save_item(NAME(m_mmc.DX)); @@ -755,7 +715,7 @@ void v99x8_device::reset_palette() 5, 5, 5, // 14: gray 7, 7, 7 // 15: white }; - int i, red, ind; + int i, red; for (i=0;i<16;i++) { @@ -763,18 +723,15 @@ void v99x8_device::reset_palette() m_pal_reg[i*2+0] = pal16[i*3+1] << 4 | pal16[i*3+2]; m_pal_reg[i*2+1] = pal16[i*3]; // set the reference table - m_pal_ind16[i] = pal16[i*3+1] << 6 | pal16[i*3] << 3 | pal16[i*3+2]; + set_pen16(i, uint32_t(rgb_t(pal3bit(pal16[i*3+1]), pal3bit(pal16[i*3]), pal3bit(pal16[i*3+2])))); } // set internal palette GRAPHIC 7 for (i=0;i<256;i++) { - ind = (i << 4) & 0x01c0; - ind |= (i >> 2) & 0x0038; red = (i << 1) & 6; if (red == 6) red++; - ind |= red; - m_pal_ind256[i] = ind; + set_pen256(i, uint32_t(rgb_t(pal3bit((i & 0x1c) >> 2), pal3bit((i & 0xe0) >> 5), pal3bit(red)))); } } @@ -938,39 +895,39 @@ inline bool v99x8_device::v9938_second_field() } -void v99x8_device::default_border(uint16_t *ln) +void v99x8_device::default_border(uint32_t *ln) { pen_t pen; int i; - pen = this->pen(m_pal_ind16[m_cont_reg[7] & 0x0f]); + pen = pen16(m_cont_reg[7] & 0x0f); i = LONG_WIDTH; while (i--) *ln++ = pen; } -void v99x8_device::graphic7_border(uint16_t *ln) +void v99x8_device::graphic7_border(uint32_t *ln) { pen_t pen; int i; - pen = this->pen(m_pal_ind256[m_cont_reg[7]]); + pen = pen256(m_cont_reg[7]); i = LONG_WIDTH; while (i--) *ln++ = pen; } -void v99x8_device::graphic5_border(uint16_t *ln) +void v99x8_device::graphic5_border(uint32_t *ln) { int i; pen_t pen0; pen_t pen1; - pen1 = pen(m_pal_ind16[m_cont_reg[7] & 0x03]); - pen0 = pen(m_pal_ind16[(m_cont_reg[7] >> 2) & 0x03]); + pen1 = pen16(m_cont_reg[7] & 0x03); + pen0 = pen16((m_cont_reg[7] >> 2) & 0x03); i = LONG_WIDTH / 2; while (i--) { *ln++ = pen0; *ln++ = pen1; } } -void v99x8_device::mode_text1(uint16_t *ln, int line) +void v99x8_device::mode_text1(uint32_t *ln, int line) { int pattern, x, xx, name, xxx; pen_t fg, bg, pen; @@ -979,12 +936,12 @@ void v99x8_device::mode_text1(uint16_t *ln, int line) patterntbl_addr = m_cont_reg[4] << 11; nametbl_addr = m_cont_reg[2] << 10; - fg = this->pen(m_pal_ind16[m_cont_reg[7] >> 4]); - bg = this->pen(m_pal_ind16[m_cont_reg[7] & 15]); + fg = pen16(m_cont_reg[7] >> 4); + bg = pen16(m_cont_reg[7] & 15); name = (line/8)*40; - pen = this->pen(m_pal_ind16[m_cont_reg[7] & 0x0f]); + pen = pen16(m_cont_reg[7] & 0x0f); xxx = (m_offset_x + 8) * 2; while (xxx--) *ln++ = pen; @@ -1007,7 +964,7 @@ void v99x8_device::mode_text1(uint16_t *ln, int line) while (xxx--) *ln++ = pen; } -void v99x8_device::mode_text2(uint16_t *ln, int line) +void v99x8_device::mode_text2(uint32_t *ln, int line) { int pattern, x, charcode, name, xxx, patternmask, colourmask; pen_t fg, bg, fg0, bg0, pen; @@ -1023,15 +980,15 @@ void v99x8_device::mode_text2(uint16_t *ln, int line) nametbl_addr = ((m_cont_reg[2] & 0xfc) << 10); patternmask = ((m_cont_reg[2] & 3) << 10) | 0x3ff; /* seems correct */ - fg = this->pen(m_pal_ind16[m_cont_reg[7] >> 4]); - bg = this->pen(m_pal_ind16[m_cont_reg[7] & 15]); - fg0 = this->pen(m_pal_ind16[m_cont_reg[12] >> 4]); - bg0 = this->pen(m_pal_ind16[m_cont_reg[12] & 15]); + fg = pen16(m_cont_reg[7] >> 4); + bg = pen16(m_cont_reg[7] & 15); + fg0 = pen16(m_cont_reg[12] >> 4); + bg0 = pen16(m_cont_reg[12] & 15); name = (line/8)*80; xxx = (m_offset_x + 8) * 2; - pen = this->pen(m_pal_ind16[m_cont_reg[7] & 0x0f]); + pen = pen16(m_cont_reg[7] & 0x0f); while (xxx--) *ln++ = pen; for (x=0;x<80;x++) @@ -1074,7 +1031,7 @@ void v99x8_device::mode_text2(uint16_t *ln, int line) while (xxx--) *ln++ = pen; } -void v99x8_device::mode_multi(uint16_t *ln, int line) +void v99x8_device::mode_multi(uint32_t *ln, int line) { int nametbl_addr, patterntbl_addr, colour; int name, line2, x, xx; @@ -1086,14 +1043,14 @@ void v99x8_device::mode_multi(uint16_t *ln, int line) line2 = (line - m_cont_reg[23]) & 255; name = (line2/8)*32; - pen_bg = this->pen(m_pal_ind16[m_cont_reg[7] & 0x0f]); + pen_bg = pen16(m_cont_reg[7] & 0x0f); xx = m_offset_x * 2; while (xx--) *ln++ = pen_bg; for (x=0;x<32;x++) { colour = m_vram_space->read_byte(patterntbl_addr + (m_vram_space->read_byte(nametbl_addr + name) * 8) + ((line2/4)&7)); - pen = this->pen(m_pal_ind16[colour >> 4]); + pen = pen16(colour >> 4); /* eight pixels */ *ln++ = pen; *ln++ = pen; @@ -1103,7 +1060,7 @@ void v99x8_device::mode_multi(uint16_t *ln, int line) *ln++ = pen; *ln++ = pen; *ln++ = pen; - pen = this->pen(m_pal_ind16[colour & 15]); + pen = pen16(colour & 15); /* eight pixels */ *ln++ = pen; *ln++ = pen; @@ -1120,7 +1077,7 @@ void v99x8_device::mode_multi(uint16_t *ln, int line) while (xx--) *ln++ = pen_bg; } -void v99x8_device::mode_graphic1(uint16_t *ln, int line) +void v99x8_device::mode_graphic1(uint32_t *ln, int line) { pen_t fg, bg, pen; int nametbl_addr, patterntbl_addr, colourtbl_addr; @@ -1134,7 +1091,7 @@ void v99x8_device::mode_graphic1(uint16_t *ln, int line) name = (line2/8)*32; - pen = this->pen(m_pal_ind16[m_cont_reg[7] & 0x0f]); + pen = pen16(m_cont_reg[7] & 0x0f); xxx = m_offset_x * 2; while (xxx--) *ln++ = pen; @@ -1142,8 +1099,8 @@ void v99x8_device::mode_graphic1(uint16_t *ln, int line) { charcode = m_vram_space->read_byte(nametbl_addr + name); colour = m_vram_space->read_byte(colourtbl_addr + charcode/8); - fg = this->pen(m_pal_ind16[colour >> 4]); - bg = this->pen(m_pal_ind16[colour & 15]); + fg = pen16(colour >> 4); + bg = pen16(colour & 15); pattern = m_vram_space->read_byte(patterntbl_addr + (charcode * 8 + (line2 & 7))); for (xx=0;xx<8;xx++) @@ -1159,7 +1116,7 @@ void v99x8_device::mode_graphic1(uint16_t *ln, int line) while (xx--) *ln++ = pen; } -void v99x8_device::mode_graphic23(uint16_t *ln, int line) +void v99x8_device::mode_graphic23(uint32_t *ln, int line) { pen_t fg, bg, pen; int nametbl_addr, patterntbl_addr, colourtbl_addr; @@ -1176,7 +1133,7 @@ void v99x8_device::mode_graphic23(uint16_t *ln, int line) line2 = (line + m_cont_reg[23]) & 255; name = (line2/8)*32; - pen = this->pen(m_pal_ind16[m_cont_reg[7] & 0x0f]); + pen = pen16(m_cont_reg[7] & 0x0f); xxx = m_offset_x * 2; while (xxx--) *ln++ = pen; @@ -1185,8 +1142,8 @@ void v99x8_device::mode_graphic23(uint16_t *ln, int line) charcode = m_vram_space->read_byte(nametbl_addr + name) + (line2&0xc0)*4; colour = m_vram_space->read_byte(colourtbl_addr + ((charcode&colourmask)*8+(line2&7))); pattern = m_vram_space->read_byte(patterntbl_addr + ((charcode&patternmask)*8+(line2&7))); - fg = this->pen(m_pal_ind16[colour >> 4]); - bg = this->pen(m_pal_ind16[colour & 15]); + fg = pen16(colour >> 4); + bg = pen16(colour & 15); for (xx=0;xx<8;xx++) { *ln++ = (pattern & 0x80) ? fg : bg; @@ -1200,7 +1157,7 @@ void v99x8_device::mode_graphic23(uint16_t *ln, int line) while (xx--) *ln++ = pen; } -void v99x8_device::mode_graphic4(uint16_t *ln, int line) +void v99x8_device::mode_graphic4(uint32_t *ln, int line) { int nametbl_addr, colour; int line2, linemask, x, xx; @@ -1214,17 +1171,17 @@ void v99x8_device::mode_graphic4(uint16_t *ln, int line) if ( (m_cont_reg[2] & 0x20) && v9938_second_field() ) nametbl_addr += 0x8000; - pen_bg = this->pen(m_pal_ind16[m_cont_reg[7] & 0x0f]); + pen_bg = pen16(m_cont_reg[7] & 0x0f); xx = m_offset_x * 2; while (xx--) *ln++ = pen_bg; for (x=0;x<128;x++) { colour = m_vram_space->read_byte(nametbl_addr++); - pen = this->pen(m_pal_ind16[colour >> 4]); + pen = pen16(colour >> 4); *ln++ = pen; *ln++ = pen; - pen = this->pen(m_pal_ind16[colour & 15]); + pen = pen16(colour & 15); *ln++ = pen; *ln++ = pen; } @@ -1233,7 +1190,7 @@ void v99x8_device::mode_graphic4(uint16_t *ln, int line) while (xx--) *ln++ = pen_bg; } -void v99x8_device::mode_graphic5(uint16_t *ln, int line) +void v99x8_device::mode_graphic5(uint32_t *ln, int line) { int nametbl_addr, colour; int line2, linemask, x, xx; @@ -1248,8 +1205,8 @@ void v99x8_device::mode_graphic5(uint16_t *ln, int line) if ( (m_cont_reg[2] & 0x20) && v9938_second_field() ) nametbl_addr += 0x8000; - pen_bg1[0] = this->pen(m_pal_ind16[m_cont_reg[7] & 0x03]); - pen_bg0[0] = this->pen(m_pal_ind16[(m_cont_reg[7] >> 2) & 0x03]); + pen_bg1[0] = pen16(m_cont_reg[7] & 0x03); + pen_bg0[0] = pen16((m_cont_reg[7] >> 2) & 0x03); xx = m_offset_x; while (xx--) { *ln++ = pen_bg0[0]; *ln++ = pen_bg1[0]; } @@ -1258,8 +1215,8 @@ void v99x8_device::mode_graphic5(uint16_t *ln, int line) for (;x<4;x++) { - pen_bg0[x] = this->pen(m_pal_ind16[x]); - pen_bg1[x] = this->pen(m_pal_ind16[x]); + pen_bg0[x] = pen16(x); + pen_bg1[x] = pen16(x); } for (x=0;x<128;x++) @@ -1272,13 +1229,13 @@ void v99x8_device::mode_graphic5(uint16_t *ln, int line) *ln++ = pen_bg1[(colour&3)]; } - pen_bg1[0] = this->pen(m_pal_ind16[m_cont_reg[7] & 0x03]); - pen_bg0[0] = this->pen(m_pal_ind16[(m_cont_reg[7] >> 2) & 0x03]); + pen_bg1[0] = pen16(m_cont_reg[7] & 0x03); + pen_bg0[0] = pen16((m_cont_reg[7] >> 2) & 0x03); xx = 16 - m_offset_x; while (xx--) { *ln++ = pen_bg0[0]; *ln++ = pen_bg1[0]; } } -void v99x8_device::mode_graphic6(uint16_t *ln, int line) +void v99x8_device::mode_graphic6(uint32_t *ln, int line) { uint8_t colour; int line2, linemask, x, xx, nametbl_addr; @@ -1293,7 +1250,7 @@ void v99x8_device::mode_graphic6(uint16_t *ln, int line) if ( (m_cont_reg[2] & 0x20) && v9938_second_field() ) nametbl_addr += 0x10000; - pen_bg = pen(m_pal_ind16[m_cont_reg[7] & 0x0f]); + pen_bg = pen16(m_cont_reg[7] & 0x0f); xx = m_offset_x * 2; while (xx--) *ln++ = pen_bg; @@ -1303,8 +1260,8 @@ void v99x8_device::mode_graphic6(uint16_t *ln, int line) { nametbl_addr++; colour = m_vram_space->read_byte(((nametbl_addr&1) << 16) | (nametbl_addr>>1)); - fg0 = pen(m_pal_ind16[colour >> 4]); - fg1 = pen(m_pal_ind16[colour & 15]); + fg0 = pen16(colour >> 4); + fg1 = pen16(colour & 15); *ln++ = fg0; *ln++ = fg1; *ln++ = fg0; *ln++ = fg1; *ln++ = fg0; *ln++ = fg1; *ln++ = fg0; *ln++ = fg1; *ln++ = fg0; *ln++ = fg1; *ln++ = fg0; *ln++ = fg1; @@ -1317,8 +1274,8 @@ void v99x8_device::mode_graphic6(uint16_t *ln, int line) for (x=0;x<256;x++) { colour = m_vram_space->read_byte(((nametbl_addr&1) << 16) | (nametbl_addr>>1)); - *ln++ = pen(m_pal_ind16[colour >> 4]); - *ln++ = pen(m_pal_ind16[colour & 15]); + *ln++ = pen16(colour >> 4); + *ln++ = pen16(colour & 15); nametbl_addr++; } } @@ -1327,7 +1284,7 @@ void v99x8_device::mode_graphic6(uint16_t *ln, int line) while (xx--) *ln++ = pen_bg; } -void v99x8_device::mode_graphic7(uint16_t *ln, int line) +void v99x8_device::mode_graphic7(uint32_t *ln, int line) { uint8_t colour; int line2, linemask, x, xx, nametbl_addr; @@ -1341,7 +1298,7 @@ void v99x8_device::mode_graphic7(uint16_t *ln, int line) if ( (m_cont_reg[2] & 0x20) && v9938_second_field() ) nametbl_addr += 0x10000; - pen_bg = this->pen(m_pal_ind256[m_cont_reg[7]]); + pen_bg = pen256(m_cont_reg[7]); xx = m_offset_x * 2; while (xx--) *ln++ = pen_bg; @@ -1396,17 +1353,17 @@ void v99x8_device::mode_graphic7(uint16_t *ln, int line) ind = (colour[0] & 7) << 11 | (colour[1] & 7) << 14 | (colour[2] & 7) << 5 | (colour[3] & 7) << 8; - *ln++ = colour[0] & 8 ? m_pal_ind16[colour[0] >> 4] : s_pal_indYJK[ind | ((colour[0] >> 3) & 30)]; - *ln++ = colour[0] & 8 ? m_pal_ind16[colour[0] >> 4] : s_pal_indYJK[ind | ((colour[0] >> 3) & 30)]; + *ln++ = colour[0] & 8 ? pen16(colour[0] >> 4) : s_pal_indYJK[ind | ((colour[0] >> 3) & 30)]; + *ln++ = colour[0] & 8 ? pen16(colour[0] >> 4) : s_pal_indYJK[ind | ((colour[0] >> 3) & 30)]; - *ln++ = colour[1] & 8 ? m_pal_ind16[colour[1] >> 4] : s_pal_indYJK[ind | ((colour[1] >> 3) & 30)]; - *ln++ = colour[1] & 8 ? m_pal_ind16[colour[1] >> 4] : s_pal_indYJK[ind | ((colour[1] >> 3) & 30)]; + *ln++ = colour[1] & 8 ? pen16(colour[1] >> 4) : s_pal_indYJK[ind | ((colour[1] >> 3) & 30)]; + *ln++ = colour[1] & 8 ? pen16(colour[1] >> 4) : s_pal_indYJK[ind | ((colour[1] >> 3) & 30)]; - *ln++ = colour[2] & 8 ? m_pal_ind16[colour[2] >> 4] : s_pal_indYJK[ind | ((colour[2] >> 3) & 30)]; - *ln++ = colour[2] & 8 ? m_pal_ind16[colour[2] >> 4] : s_pal_indYJK[ind | ((colour[2] >> 3) & 30)]; + *ln++ = colour[2] & 8 ? pen16(colour[2] >> 4) : s_pal_indYJK[ind | ((colour[2] >> 3) & 30)]; + *ln++ = colour[2] & 8 ? pen16(colour[2] >> 4) : s_pal_indYJK[ind | ((colour[2] >> 3) & 30)]; - *ln++ = colour[3] & 8 ? m_pal_ind16[colour[3] >> 4] : s_pal_indYJK[ind | ((colour[3] >> 3) & 30)]; - *ln++ = colour[3] & 8 ? m_pal_ind16[colour[3] >> 4] : s_pal_indYJK[ind | ((colour[3] >> 3) & 30)]; + *ln++ = colour[3] & 8 ? pen16(colour[3] >> 4) : s_pal_indYJK[ind | ((colour[3] >> 3) & 30)]; + *ln++ = colour[3] & 8 ? pen16(colour[3] >> 4) : s_pal_indYJK[ind | ((colour[3] >> 3) & 30)]; nametbl_addr++; } @@ -1417,7 +1374,7 @@ void v99x8_device::mode_graphic7(uint16_t *ln, int line) { nametbl_addr++; colour = m_vram_space->read_byte(((nametbl_addr&1) << 16) | (nametbl_addr>>1)); - pen = this->pen(m_pal_ind256[colour]); + pen = pen256(colour); *ln++ = pen; *ln++ = pen; *ln++ = pen; *ln++ = pen; *ln++ = pen; *ln++ = pen; @@ -1434,7 +1391,7 @@ void v99x8_device::mode_graphic7(uint16_t *ln, int line) for (x=0;x<256;x++) { colour = m_vram_space->read_byte(((nametbl_addr&1) << 16) | (nametbl_addr>>1)); - pen = this->pen(m_pal_ind256[colour]); + pen = pen256(colour); *ln++ = pen; *ln++ = pen; nametbl_addr++; @@ -1445,13 +1402,13 @@ void v99x8_device::mode_graphic7(uint16_t *ln, int line) while (xx--) *ln++ = pen_bg; } -void v99x8_device::mode_unknown(uint16_t *ln, int line) +void v99x8_device::mode_unknown(uint32_t *ln, int line) { pen_t fg, bg; int x; - fg = pen(m_pal_ind16[m_cont_reg[7] >> 4]); - bg = pen(m_pal_ind16[m_cont_reg[7] & 15]); + fg = pen16(m_cont_reg[7] >> 4); + bg = pen16(m_cont_reg[7] & 15); x = m_offset_x * 2; while (x--) *ln++ = bg; @@ -1463,7 +1420,7 @@ void v99x8_device::mode_unknown(uint16_t *ln, int line) while (x--) *ln++ = bg; } -void v99x8_device::default_draw_sprite(uint16_t *ln, uint8_t *col) +void v99x8_device::default_draw_sprite(uint32_t *ln, uint8_t *col) { int i; ln += m_offset_x * 2; @@ -1472,8 +1429,8 @@ void v99x8_device::default_draw_sprite(uint16_t *ln, uint8_t *col) { if (col[i] & 0x80) { - *ln++ = pen(m_pal_ind16[col[i] & 0x0f]); - *ln++ = pen(m_pal_ind16[col[i] & 0x0f]); + *ln++ = pen16(col[i] & 0x0f); + *ln++ = pen16(col[i] & 0x0f); } else { @@ -1482,7 +1439,7 @@ void v99x8_device::default_draw_sprite(uint16_t *ln, uint8_t *col) } } -void v99x8_device::graphic5_draw_sprite(uint16_t *ln, uint8_t *col) +void v99x8_device::graphic5_draw_sprite(uint32_t *ln, uint8_t *col) { int i; ln += m_offset_x * 2; @@ -1491,8 +1448,8 @@ void v99x8_device::graphic5_draw_sprite(uint16_t *ln, uint8_t *col) { if (col[i] & 0x80) { - *ln++ = pen(m_pal_ind16[(col[i] >> 2) & 0x03]); - *ln++ = pen(m_pal_ind16[col[i] & 0x03]); + *ln++ = pen16((col[i] >> 2) & 0x03); + *ln++ = pen16(col[i] & 0x03); } else { @@ -1502,7 +1459,7 @@ void v99x8_device::graphic5_draw_sprite(uint16_t *ln, uint8_t *col) } -void v99x8_device::graphic7_draw_sprite(uint16_t *ln, uint8_t *col) +void v99x8_device::graphic7_draw_sprite(uint32_t *ln, uint8_t *col) { static const uint16_t g7_ind16[16] = { 0, 2, 192, 194, 48, 50, 240, 242, @@ -1515,8 +1472,9 @@ void v99x8_device::graphic7_draw_sprite(uint16_t *ln, uint8_t *col) { if (col[i] & 0x80) { - *ln++ = pen(g7_ind16[col[i] & 0x0f]); - *ln++ = pen(g7_ind16[col[i] & 0x0f]); + rgb_t color = rgb_t(pal3bit(g7_ind16[col[i] & 0x0f] >> 6), pal3bit(g7_ind16[col[i] & 0x0f] >> 3), pal3bit(g7_ind16[col[i] & 0x0f])); + *ln++ = uint32_t(color); + *ln++ = uint32_t(color); } else { @@ -1858,60 +1816,60 @@ void v99x8_device::set_mode() m_mode = i; } -void v99x8_device::refresh_16(int line) +void v99x8_device::refresh_32(int line) { bool double_lines = false; uint8_t col[256]; - uint16_t *ln, *ln2 = nullptr; + uint32_t *ln, *ln2 = nullptr; if (m_cont_reg[9] & 0x08) { - ln = &m_bitmap.pix16(m_scanline*2+((m_stat_reg[2]>>1)&1)); + ln = &m_bitmap.pix32(m_scanline*2+((m_stat_reg[2]>>1)&1)); } else { - ln = &m_bitmap.pix16(m_scanline*2); - ln2 = &m_bitmap.pix16(m_scanline*2+1); + ln = &m_bitmap.pix32(m_scanline*2); + ln2 = &m_bitmap.pix32(m_scanline*2+1); double_lines = true; } if ( !(m_cont_reg[1] & 0x40) || (m_stat_reg[2] & 0x40) ) { - (this->*s_modes[m_mode].border_16)(ln); + (this->*s_modes[m_mode].border_32)(ln); } else { - (this->*s_modes[m_mode].visible_16)(ln, line); + (this->*s_modes[m_mode].visible_32)(ln, line); if (s_modes[m_mode].sprites) { (this->*s_modes[m_mode].sprites)(line, col); - (this->*s_modes[m_mode].draw_sprite_16)(ln, col); + (this->*s_modes[m_mode].draw_sprite_32)(ln, col); } } if (double_lines) - memcpy(ln2, ln, (512 + 32) * 2); + memcpy(ln2, ln, (512 + 32) * sizeof(*ln)); } void v99x8_device::refresh_line(int line) { - int ind16, ind256; + pen_t ind16, ind256; - ind16 = m_pal_ind16[0]; - ind256 = m_pal_ind256[0]; + ind16 = pen16(0); + ind256 = pen256(0); if ( !(m_cont_reg[8] & 0x20) && (m_mode != V9938_MODE_GRAPHIC5) ) { - m_pal_ind16[0] = m_pal_ind16[(m_cont_reg[7] & 0x0f)]; - m_pal_ind256[0] = m_pal_ind256[m_cont_reg[7]]; + set_pen16(0, pen16(m_cont_reg[7] & 0x0f)); + set_pen256(0, pen256(m_cont_reg[7])); } - refresh_16 (line); + refresh_32(line); if ( !(m_cont_reg[8] & 0x20) && (m_mode != V9938_MODE_GRAPHIC5) ) { - m_pal_ind16[0] = ind16; - m_pal_ind256[0] = ind256; + set_pen16(0, ind16); + set_pen256(0, ind256); } } diff --git a/src/devices/video/v9938.h b/src/devices/video/v9938.h index a177e7daa6e..deb656939a9 100644 --- a/src/devices/video/v9938.h +++ b/src/devices/video/v9938.h @@ -36,8 +36,7 @@ v99x8_device::VTOTAL_NTSC * 2, \ v99x8_device::VERTICAL_ADJUST * 2, \ v99x8_device::VVISIBLE_NTSC * 2 - 1 - v99x8_device::VERTICAL_ADJUST * 2) \ - MCFG_SCREEN_UPDATE_DEVICE(_v9938_tag, v9938_device, screen_update) \ - MCFG_SCREEN_PALETTE(_v9938_tag) + MCFG_SCREEN_UPDATE_DEVICE(_v9938_tag, v9938_device, screen_update) #define MCFG_V99X8_SCREEN_ADD_PAL(_screen_tag, _v9938_tag, _clock) \ MCFG_SCREEN_ADD(_screen_tag, RASTER) \ @@ -48,8 +47,7 @@ v99x8_device::VTOTAL_PAL * 2, \ v99x8_device::VERTICAL_ADJUST * 2, \ v99x8_device::VVISIBLE_PAL * 2 - 1 - v99x8_device::VERTICAL_ADJUST * 2) \ - MCFG_SCREEN_UPDATE_DEVICE(_v9938_tag, v9938_device, screen_update) \ - MCFG_SCREEN_PALETTE(_v9938_tag) + MCFG_SCREEN_UPDATE_DEVICE(_v9938_tag, v9938_device, screen_update) #define MCFG_V99X8_INTERRUPT_CALLBACK(_irq) \ devcb = &downcast(device)->set_interrupt_callback(DEVCB_##_irq); @@ -78,11 +76,11 @@ class v99x8_device : public device_t, { public: template devcb_base &set_interrupt_callback(Object &&irq) { return m_int_callback.set_callback(std::forward(irq)); } - int get_transpen(); - bitmap_ind16 &get_bitmap() { return m_bitmap; } + //pen_t get_transpen() const; + bitmap_rgb32 &get_bitmap() { return m_bitmap; } void update_mouse_state(int mx_delta, int my_delta, int button_state); - uint32_t screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); + uint32_t screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect); DECLARE_READ8_MEMBER( read ); DECLARE_WRITE8_MEMBER( write ); @@ -132,12 +130,18 @@ protected: virtual space_config_vector memory_space_config() const override; virtual void palette_init() = 0; + virtual u32 palette_entries() const override { return 16 + 256; } void configure_pal_ntsc(); void set_screen_parameters(); private: // internal helpers + pen_t pen16(int index) const { return uint32_t(pen_color(index)); } + pen_t pen256(int index) const { return uint32_t(pen_color(index + 16)); } + void set_pen16(int index, pen_t pen) { set_pen_color(index, rgb_t(pen).set_a(index != 0 ? 0xff : 0x00)); } + void set_pen256(int index, pen_t pen) { set_pen_color(index + 16, rgb_t(pen).set_a(index != 0 ? 0xff : 0x00)); } + inline int position_offset(uint8_t value) { value &= 0x0f; return (value < 8) ? -value : 16 - value; } void reset_palette(); void vram_write(int offset, int data); @@ -145,29 +149,29 @@ private: void check_int(); void register_write(int reg, int data); - void default_border(uint16_t *ln); - void graphic7_border(uint16_t *ln); - void graphic5_border(uint16_t *ln); - void mode_text1(uint16_t *ln, int line); - void mode_text2(uint16_t *ln, int line); - void mode_multi(uint16_t *ln, int line); - void mode_graphic1(uint16_t *ln, int line); - void mode_graphic23(uint16_t *ln, int line); - void mode_graphic4(uint16_t *ln, int line); - void mode_graphic5(uint16_t *ln, int line); - void mode_graphic6(uint16_t *ln, int line); - void mode_graphic7(uint16_t *ln, int line); + void default_border(uint32_t *ln); + void graphic7_border(uint32_t *ln); + void graphic5_border(uint32_t *ln); + void mode_text1(uint32_t *ln, int line); + void mode_text2(uint32_t *ln, int line); + void mode_multi(uint32_t *ln, int line); + void mode_graphic1(uint32_t *ln, int line); + void mode_graphic23(uint32_t *ln, int line); + void mode_graphic4(uint32_t *ln, int line); + void mode_graphic5(uint32_t *ln, int line); + void mode_graphic6(uint32_t *ln, int line); + void mode_graphic7(uint32_t *ln, int line); // template void mode_yae(_PixelType *ln, int line); // template void mode_yjk(_PixelType *ln, int line); - void mode_unknown(uint16_t *ln, int line); - void default_draw_sprite(uint16_t *ln, uint8_t *col); - void graphic5_draw_sprite(uint16_t *ln, uint8_t *col); - void graphic7_draw_sprite(uint16_t *ln, uint8_t *col); + void mode_unknown(uint32_t *ln, int line); + void default_draw_sprite(uint32_t *ln, uint8_t *col); + void graphic5_draw_sprite(uint32_t *ln, uint8_t *col); + void graphic7_draw_sprite(uint32_t *ln, uint8_t *col); void sprite_mode1(int line, uint8_t *col); void sprite_mode2(int line, uint8_t *col); void set_mode(); - void refresh_16(int line); + void refresh_32(int line); void refresh_line(int line); void interrupt_start_vblank(); @@ -233,11 +237,8 @@ private: uint8_t m_mx_delta, m_my_delta; // mouse & lightpen uint8_t m_button_state; - // palette - uint16_t m_pal_ind16[16]; - uint16_t m_pal_ind256[256]; // render bitmap - bitmap_ind16 m_bitmap; + bitmap_rgb32 m_bitmap; // Command unit struct { int SX,SY; @@ -257,10 +258,10 @@ private: struct v99x8_mode { uint8_t m; - void (v99x8_device::*visible_16)(uint16_t*, int); - void (v99x8_device::*border_16)(uint16_t*); + void (v99x8_device::*visible_32)(uint32_t*, int); + void (v99x8_device::*border_32)(uint32_t*); void (v99x8_device::*sprites)(int, uint8_t*); - void (v99x8_device::*draw_sprite_16)(uint16_t*, uint8_t*); + void (v99x8_device::*draw_sprite_32)(uint32_t*, uint8_t*); } ; static const v99x8_mode s_modes[]; emu_timer *m_line_timer; @@ -270,7 +271,7 @@ private: int m_scanline_max; int m_height; protected: - static uint16_t s_pal_indYJK[0x20000]; + static uint32_t s_pal_indYJK[0x20000]; }; @@ -281,7 +282,6 @@ public: protected: virtual void palette_init() override; - virtual u32 palette_entries() const override { return 512; } }; class v9958_device : public v99x8_device @@ -291,7 +291,6 @@ public: protected: virtual void palette_init() override; - virtual u32 palette_entries() const override { return 19780; } }; diff --git a/src/emu/divideo.cpp b/src/emu/divideo.cpp index 4abe607dab3..d0e68e36460 100644 --- a/src/emu/divideo.cpp +++ b/src/emu/divideo.cpp @@ -137,8 +137,8 @@ void device_video_interface::interface_pre_start() // resolve the palette for the sake of register_screen_bitmap m_screen->resolve_palette(); - // no other palette may be specified (FIXME: breaks meritm.cpp) - if (0 && m_screen->has_palette() && palintf != &m_screen->palette()) + // no other palette may be specified + if (m_screen->has_palette() && palintf != &m_screen->palette()) throw emu_fatalerror("Device '%s' cannot control screen '%s' with palette '%s'", device().tag(), m_screen_tag, m_screen->palette().device().tag()); } } diff --git a/src/emu/drawgfx.cpp b/src/emu/drawgfx.cpp index edbfa1ec306..eff4e46f2cf 100644 --- a/src/emu/drawgfx.cpp +++ b/src/emu/drawgfx.cpp @@ -1919,6 +1919,18 @@ void copybitmap_trans(bitmap_rgb32 &dest, const bitmap_rgb32 &src, int flipx, in } +/*------------------------------------------------- + copybitmap_transalphpa - copy from one bitmap + to another, copying all unclipped pixels except + those with an alpha value of zero +-------------------------------------------------*/ + +void copybitmap_transalpha(bitmap_rgb32 &dest, const bitmap_rgb32 &src, int flipx, int flipy, s32 destx, s32 desty, const rectangle &cliprect) +{ + DECLARE_NO_PRIORITY; + COPYBITMAP_CORE(u32, PIXEL_OP_COPY_TRANSALPHA, NO_PRIORITY); +} + /*************************************************************************** COPYSCROLLBITMAP IMPLEMENTATIONS diff --git a/src/emu/drawgfx.h b/src/emu/drawgfx.h index fe5cb7679df..e9833de4a30 100644 --- a/src/emu/drawgfx.h +++ b/src/emu/drawgfx.h @@ -352,6 +352,8 @@ void copybitmap(bitmap_rgb32 &dest, const bitmap_rgb32 &src, int flipx, int flip void copybitmap_trans(bitmap_ind16 &dest, const bitmap_ind16 &src, int flipx, int flipy, s32 destx, s32 desty, const rectangle &cliprect, u32 transpen); void copybitmap_trans(bitmap_rgb32 &dest, const bitmap_rgb32 &src, int flipx, int flipy, s32 destx, s32 desty, const rectangle &cliprect, u32 transpen); +void copybitmap_transalpha(bitmap_rgb32 &dest, const bitmap_rgb32 &src, int flipx, int flipy, s32 destx, s32 desty, const rectangle &cliprect); + /* Copy a bitmap onto another with scroll and wraparound. These functions support multiple independently scrolling rows/columns. @@ -429,7 +431,7 @@ constexpr u32 alpha_blend_r16(u32 d, u32 s, u8 level) //------------------------------------------------- -// alpha_blend_r16 - alpha blend two 32-bit +// alpha_blend_r32 - alpha blend two 32-bit // 8-8-8 RGB pixels //------------------------------------------------- diff --git a/src/emu/drawgfxm.h b/src/emu/drawgfxm.h index 325ce0e974c..1bef8e15237 100644 --- a/src/emu/drawgfxm.h +++ b/src/emu/drawgfxm.h @@ -94,6 +94,21 @@ do } \ while (0) +/*------------------------------------------------- + PIXEL_OP_COPY_TRANSALPHA - render all pixels + except those with an alpha of zero, copying + directly +-------------------------------------------------*/ + +#define PIXEL_OP_COPY_TRANSALPHA(DEST, PRIORITY, SOURCE) \ +do \ +{ \ + u32 srcdata = (SOURCE); \ + if ((srcdata & 0xff000000) != 0) \ + (DEST) = SOURCE; \ +} \ +while (0) + /*------------------------------------------------- PIXEL_OP_REMAP_OPAQUE - render all pixels regardless of pen, mapping the pen via the diff --git a/src/mame/drivers/meritm.cpp b/src/mame/drivers/meritm.cpp index 83ac0ab720f..c603e03e1a7 100644 --- a/src/mame/drivers/meritm.cpp +++ b/src/mame/drivers/meritm.cpp @@ -258,7 +258,7 @@ public: DECLARE_MACHINE_START(meritm_crt250_crt252_crt258); DECLARE_MACHINE_START(meritm_crt260); DECLARE_MACHINE_START(merit_common); - uint32_t screen_update_meritm(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); + uint32_t screen_update_meritm(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect); TIMER_DEVICE_CALLBACK_MEMBER(vblank_start_tick); TIMER_DEVICE_CALLBACK_MEMBER(vblank_end_tick); void meritm_crt250_switch_banks( ); @@ -334,7 +334,7 @@ void meritm_state::video_start() save_item(NAME(m_interrupt_vdp1_state)); } -uint32_t meritm_state::screen_update_meritm(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect) +uint32_t meritm_state::screen_update_meritm(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect) { if(machine().input().code_pressed_once(KEYCODE_Q)) { @@ -347,7 +347,7 @@ uint32_t meritm_state::screen_update_meritm(screen_device &screen, bitmap_ind16 popmessage("Layer 1 %sabled",m_layer1_enabled ? "en" : "dis"); } - bitmap.fill(m_v9938_0->black_pen(), cliprect); + bitmap.fill(rgb_t::black(), cliprect); if ( m_layer0_enabled ) { @@ -356,7 +356,7 @@ uint32_t meritm_state::screen_update_meritm(screen_device &screen, bitmap_ind16 if ( m_layer1_enabled ) { - copybitmap_trans(bitmap, m_v9938_1->get_bitmap(), 0, 0, -6, -12, cliprect, m_v9938_1->get_transpen()); + copybitmap_transalpha(bitmap, m_v9938_1->get_bitmap(), 0, 0, -6, -12, cliprect); } return 0; }