diff options
Diffstat (limited to 'src/devices/video/ppu2c0x_vt.cpp')
-rw-r--r-- | src/devices/video/ppu2c0x_vt.cpp | 215 |
1 files changed, 145 insertions, 70 deletions
diff --git a/src/devices/video/ppu2c0x_vt.cpp b/src/devices/video/ppu2c0x_vt.cpp index c91092d9ec1..f663d77992f 100644 --- a/src/devices/video/ppu2c0x_vt.cpp +++ b/src/devices/video/ppu2c0x_vt.cpp @@ -12,6 +12,7 @@ #include "emu.h" #include "video/ppu2c0x_vt.h" + /* constant definitions */ #define VISIBLE_SCREEN_WIDTH (32*8) /* Visible screen width */ @@ -19,14 +20,14 @@ DEFINE_DEVICE_TYPE(PPU_VT03, ppu_vt03_device, "ppu_vt03", "VT03 PPU (NTSC)") DEFINE_DEVICE_TYPE(PPU_VT03PAL, ppu_vt03pal_device, "ppu_vt03pal", "VT03 PPU (PAL)") -ppu_vt03_device::ppu_vt03_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock) : +ppu_vt03_device::ppu_vt03_device(const machine_config& mconfig, device_type type, const char* tag, device_t* owner, uint32_t clock) : ppu2c0x_device(mconfig, type, tag, owner, clock), m_is_pal(false), m_is_50hz(false), m_read_bg(*this), m_read_sp(*this) { - for(int i = 0; i < 6; i++) + for (int i = 0; i < 6; i++) m_2012_2017_descramble[i] = 2 + i; } @@ -36,7 +37,7 @@ ppu_vt03_device::ppu_vt03_device(const machine_config& mconfig, const char* tag, } -ppu_vt03pal_device::ppu_vt03pal_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) : +ppu_vt03pal_device::ppu_vt03pal_device(const machine_config& mconfig, const char* tag, device_t* owner, uint32_t clock) : ppu_vt03_device(mconfig, PPU_VT03PAL, tag, owner, clock) { m_scanlines_per_frame = PAL_SCANLINES_PER_FRAME; @@ -70,72 +71,86 @@ void ppu_vt03_device::set_201x_descramble(uint8_t reg0, uint8_t reg1, uint8_t re void ppu_vt03_device::set_new_pen(int i) { - if((i < 0x20) && ((i & 0x3) == 0)) { + if ((i < 0x20) && ((i & 0x3) == 0)) + { set_pen_color(i & 0x7f, rgb_t(0, 0, 0)); - } else { - if(m_pal_mode == PAL_MODE_NEW_RGB) { - uint16_t rgbval = (m_newpal[i&0x7f] & 0xff) | ((m_newpal[(i&0x7f)+0x80] & 0xff)<<8); + } + else + { + if (m_pal_mode == PAL_MODE_NEW_RGB) + { + uint16_t rgbval = (m_newpal[i & 0x7f] & 0xff) | ((m_newpal[(i & 0x7f) + 0x80] & 0xff) << 8); uint8_t blue = (rgbval & 0x001f) << 3; uint8_t green = (rgbval & 0x3e0) >> 2; - uint8_t red = (rgbval & 0x7C00) >> 7; + uint8_t red = (rgbval & 0x7C00) >> 7; set_pen_color(i & 0x7f, rgb_t(red, green, blue)); - } else if(m_pal_mode == PAL_MODE_NEW_RGB12) { - uint16_t rgbval = (m_newpal[i&0x7f] & 0x3f) | ((m_newpal[(i&0x7f)+0x80] & 0x3f)<<6); + } + else if (m_pal_mode == PAL_MODE_NEW_RGB12) + { + uint16_t rgbval = (m_newpal[i & 0x7f] & 0x3f) | ((m_newpal[(i & 0x7f) + 0x80] & 0x3f) << 6); uint8_t red = (rgbval & 0x000f) << 4; uint8_t green = (rgbval & 0x0f0); - uint8_t blue = (rgbval & 0xf00) >> 4; + uint8_t blue = (rgbval & 0xf00) >> 4; set_pen_color(i & 0x7f, rgb_t(red, green, blue)); - } else { + } + else + { // Credit to NewRisingSun - uint16_t palval = (m_newpal[i&0x7f] & 0x3f) | ((m_newpal[(i&0x7f)+0x80] & 0x3f)<<6); - int nPhase = (palval >>0) &0xF; - int nLuma = (palval >>4) &0xF; - int nChroma = (palval >>8) &0xF; + uint16_t palval = (m_newpal[i & 0x7f] & 0x3f) | ((m_newpal[(i & 0x7f) + 0x80] & 0x3f) << 6); + int nPhase = (palval >> 0) & 0xF; + int nLuma = (palval >> 4) & 0xF; + int nChroma = (palval >> 8) & 0xF; float phaseOffset = -11.0; //bool inverted = false; - if ((nLuma < (nChroma+1) >>1 || nLuma > 15 -(nChroma >>1)) && (m_pal_mode != PAL_MODE_NEW_VG)) { + if ((nLuma < (nChroma + 1) >> 1 || nLuma > 15 - (nChroma >> 1)) && (m_pal_mode != PAL_MODE_NEW_VG)) + { //inverted = true; // Strange color number wrap-around. Is this for protection reasons, or a bug of the original hardware? // The VT03 data sheet advises programmers that 4 <= nLuma*2 +nChroma <= 0x1F, which does not correspond exactly to this condition. - static const unsigned char altPhases[16] = { 13, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 0, 14, 15}; - static const float altPhaseOffset[16] = { -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, 0, -5, -5, -5}; // Slight tweak in phase 6 for Z-Dog + static const unsigned char altPhases[16] = { 13, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 0, 14, 15 }; + static const float altPhaseOffset[16] = { -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, 0, -5, -5, -5 }; // Slight tweak in phase 6 for Z-Dog phaseOffset += altPhaseOffset[nPhase]; // These "alternative" colors seem to be slightly shifted in addition to being wrapped-around, at least in EmuVT. nPhase = altPhases[nPhase]; - nChroma = 16 -nChroma; - nLuma = (nLuma -8) &0xF; + nChroma = 16 - nChroma; + nLuma = (nLuma - 8) & 0xF; } - float fLuma = (nLuma-4) /9.625; // Value determined from matching saturation =0 phases 1-12 - float fChroma = nChroma /18.975; // Value determined from matching phases 0 and 13 across all luminance and saturation levels - float fPhase = ((nPhase-2) *30.0 +phaseOffset) *M_PI /180.0; - if(m_pal_mode == PAL_MODE_NEW_VG) { - if(fPhase > 0 && fPhase < 13) { + + float fLuma = (nLuma - 4) / 9.625; // Value determined from matching saturation =0 phases 1-12 + float fChroma = nChroma / 18.975; // Value determined from matching phases 0 and 13 across all luminance and saturation levels + float fPhase = ((nPhase - 2) * 30.0 + phaseOffset) * M_PI / 180.0; + + if (m_pal_mode == PAL_MODE_NEW_VG) + { + if (fPhase > 0 && fPhase < 13) + { fLuma /= 1.5; fChroma /= 2; } } + float Y = fLuma; float C = fChroma; - if (nPhase == 0 || nPhase >12) C =0.0;// Phases 0 and 13-15 are grays + if (nPhase == 0 || nPhase > 12) C = 0.0;// Phases 0 and 13-15 are grays if (nPhase == 0) Y += fChroma; // Phase 0 is the upper bound of the waveform - if (nPhase ==13) Y -= fChroma; // Phase 13 is the lower bound of the waveform - if (nPhase >=14) Y = 0.0; // Phases 14 and 15 always black - - float V = sin(fPhase) *C *1.05; // 1.05 needed to get closer to EmuVT palette's color levels in phases 1-12 - float U = cos(fPhase) *C *1.05; - float R = Y + 1.1400*V + 0.0000*U; - float G = Y - 0.5807*V - 0.3940*U; - float B = Y - 0.0000*V + 2.0290*U; - if (R <0.0) R =0.0; - if (R >1.0) R =1.0; - if (G <0.0) G =0.0; - if (G >1.0) G =1.0; - if (B <0.0) B =0.0; - if (B >1.0) B =1.0; - int RV = R *255.0; - int GV = G *255.0; - int BV = B *255.0; - - set_pen_color(i & 0x7f, rgb_t(RV, GV ,BV)); + if (nPhase == 13) Y -= fChroma; // Phase 13 is the lower bound of the waveform + if (nPhase >= 14) Y = 0.0; // Phases 14 and 15 always black + + float V = sin(fPhase) * C * 1.05; // 1.05 needed to get closer to EmuVT palette's color levels in phases 1-12 + float U = cos(fPhase) * C * 1.05; + float R = Y + 1.1400 * V + 0.0000 * U; + float G = Y - 0.5807 * V - 0.3940 * U; + float B = Y - 0.0000 * V + 2.0290 * U; + if (R < 0.0) R = 0.0; + if (R > 1.0) R = 1.0; + if (G < 0.0) G = 0.0; + if (G > 1.0) G = 1.0; + if (B < 0.0) B = 0.0; + if (B > 1.0) B = 1.0; + int RV = R * 255.0; + int GV = G * 255.0; + int BV = B * 255.0; + + set_pen_color(i & 0x7f, rgb_t(RV, GV, BV)); } } @@ -150,26 +165,84 @@ WRITE8_MEMBER(ppu_vt03_device::palette_write) if (m_201x_regs[0] & pal_mask) { - m_newpal[offset&0xff] = data; + m_newpal[offset & 0xff] = data; set_new_pen(offset); } else { //if(m_pal_mode == PAL_MODE_NEW_VG) // ddrdismx writes the palette before setting the register but doesn't use 'PAL_MODE_NEW_VG', Konami logo is missing if you don't allow writes to be stored for when we switch - m_newpal[offset&0xff] = data; + m_newpal[offset & 0xff] = data; ppu2c0x_device::palette_write(space, offset, data); } } -READ8_MEMBER( ppu_vt03_device::read ) +READ8_MEMBER(ppu_vt03_device::read) { - if(offset <= 0xf) { - return ppu2c0x_device::read(space,offset); - } else if(offset <= 0x1f) { - return get_201x_reg(offset & 0x0f); - } else { - return 0; - } + if (offset <= 0xf) + { + return ppu2c0x_device::read(space, offset); + } + else if (offset <= 0x1f) + { + logerror("%s: read from reg %02x\n", machine().describe_context(), offset); + + switch (offset) + { + case 0x10: + return m_201x_regs[0x0]; + + case 0x11: + return m_201x_regs[0x1]; + + case 0x12: + return m_201x_regs[m_2012_2017_descramble[0]]; + + case 0x13: + return m_201x_regs[m_2012_2017_descramble[1]]; + + case 0x14: + return m_201x_regs[m_2012_2017_descramble[2]]; + + case 0x15: + return m_201x_regs[m_2012_2017_descramble[3]]; + + case 0x16: + return m_201x_regs[m_2012_2017_descramble[4]]; + + case 0x17: + return m_201x_regs[m_2012_2017_descramble[5]]; + + case 0x18: + return m_201x_regs[0x8]; + + case 0x19: + return 0x00; + + case 0x1a: + return m_201x_regs[0xa]; + + case 0x1b: + return 0x00; + + case 0x1c: + return 0x00; + + case 0x1d: + return 0x00; + + case 0x1e: + return 0x00; + + case 0x1f: + return 0x00; + } + } + else + { + return 0x00; + } + + return 0x00; } void ppu_vt03_device::init_palette() @@ -206,11 +279,11 @@ void ppu_vt03_device::device_reset() m_read_bg.resolve_safe(0); m_read_sp.resolve_safe(0); - for (int i = 0;i < 0xff;i++) + for (int i = 0; i < 0xff; i++) m_newpal[i] = 0x0; // todo: what are the actual defaults for these? - for (int i = 0;i < 0x20;i++) + for (int i = 0; i < 0x20; i++) set_201x_reg(i, 0x00); //m_201x_regs[0] = 0x86; // alt fix for ddrdismx would be to set the default palette mode here @@ -249,7 +322,7 @@ void ppu_vt03_device::read_sprite_plane_data(int address) } } -void ppu_vt03_device::make_sprite_pixel_data(uint8_t &pixel_data, int flipx) +void ppu_vt03_device::make_sprite_pixel_data(uint8_t& pixel_data, int flipx) { ppu2c0x_device::make_sprite_pixel_data(pixel_data, flipx); @@ -265,7 +338,8 @@ void ppu_vt03_device::make_sprite_pixel_data(uint8_t &pixel_data, int flipx) m_extplanebuf[0] = m_extplanebuf[0] >> 1; m_extplanebuf[1] = m_extplanebuf[1] >> 1; - if(is16pix) { + if (is16pix) + { uint8_t pix0 = pixel_data & 0x03; uint8_t pix1 = (pixel_data >> 5) & 0x03; pixel_data = pix1 | (pix0 << 5); @@ -280,7 +354,7 @@ void ppu_vt03_device::make_sprite_pixel_data(uint8_t &pixel_data, int flipx) } } -void ppu_vt03_device::draw_sprite_pixel(int sprite_xpos, int color, int pixel, uint8_t pixel_data, bitmap_rgb32 &bitmap) +void ppu_vt03_device::draw_sprite_pixel(int sprite_xpos, int color, int pixel, uint8_t pixel_data, bitmap_rgb32& bitmap) { int is4bpp = get_201x_reg(0x0) & 0x04; int is16pix = get_201x_reg(0x0) & 0x01; @@ -294,11 +368,11 @@ void ppu_vt03_device::draw_sprite_pixel(int sprite_xpos, int color, int pixel, u else { /* this mode makes use of the extra planes to increase sprite width instead - we probably need to split them out again and draw them at xpos+8 with a - cliprect - not seen used yet */ - if((pixel_data & 0x03) != 0) + we probably need to split them out again and draw them at xpos+8 with a + cliprect - not seen used yet */ + if ((pixel_data & 0x03) != 0) bitmap.pix32(m_scanline, sprite_xpos + pixel) = pen((pixel_data & 0x03) + (4 * color)); - if(((pixel_data >> 5) & 0x03) != 0) + if (((pixel_data >> 5) & 0x03) != 0) bitmap.pix32(m_scanline, sprite_xpos + pixel + 8) = pen(((pixel_data >> 5) & 0x03) + (4 * color)); //ppu2c0x_device::draw_sprite_pixel(sprite_xpos, color, pixel, pixel_data & 0x03, bitmap); //ppu2c0x_device::draw_sprite_pixel(sprite_xpos, color, pixel + 8, (pixel_data >> 5) & 0x03, bitmap); @@ -336,7 +410,7 @@ void ppu_vt03_device::read_tile_plane_data(int address, int color) } } -void ppu_vt03_device::shift_tile_plane_data(uint8_t &pix) +void ppu_vt03_device::shift_tile_plane_data(uint8_t& pix) { int is4bpp = get_201x_reg(0x0) & 0x02; @@ -350,7 +424,7 @@ void ppu_vt03_device::shift_tile_plane_data(uint8_t &pix) } } -void ppu_vt03_device::draw_tile_pixel(uint8_t pix, int color, pen_t back_pen, uint32_t *&dest, const pen_t *color_table) +void ppu_vt03_device::draw_tile_pixel(uint8_t pix, int color, pen_t back_pen, uint32_t*& dest, const pen_t* color_table) { int is4bpp = get_201x_reg(0x0) & 0x02; @@ -386,7 +460,7 @@ void ppu_vt03_device::draw_tile_pixel(uint8_t pix, int color, pen_t back_pen, ui void ppu_vt03_device::read_extra_sprite_bits(int sprite_index) { - m_extra_sprite_bits = (m_spriteram[sprite_index + 2] & 0x1c) >>2; + m_extra_sprite_bits = (m_spriteram[sprite_index + 2] & 0x1c) >> 2; } uint8_t ppu_vt03_device::get_speva2_speva0() @@ -409,14 +483,14 @@ void ppu_vt03_device::set_2010_reg(uint8_t data) { if (data & pal_mask) { - for (int i = 0;i < 256;i++) + for (int i = 0; i < 256; i++) { set_new_pen(i); } } else { - for (int i = 0;i < 256;i++) + for (int i = 0; i < 256; i++) { set_pen_indirect(i, i); } @@ -505,3 +579,4 @@ WRITE8_MEMBER(ppu_vt03_device::write) } } } + |