diff options
author | Olivier Galibert <galibert@pobox.com> | 2020-11-23 16:34:39 +0100 |
---|---|---|
committer | Olivier Galibert <galibert@pobox.com> | 2020-11-23 16:34:53 +0100 |
commit | f33be6072f531d25cd2d3440ed98b586e1fd872b (patch) | |
tree | 4cf690fcc52679efa9b8c9135dad99f9ecdf059e /src/mame | |
parent | 4f01783c9f014bd8aabc57423d433f344b72cbe7 (diff) |
Fix hard drivin', a bad combination of wrong width memory and wrong-sized allocation. The palette was working by sheer luck (and memory block size rounding)
Diffstat (limited to 'src/mame')
-rw-r--r-- | src/mame/drivers/harddriv.cpp | 44 | ||||
-rw-r--r-- | src/mame/includes/harddriv.h | 12 | ||||
-rw-r--r-- | src/mame/video/harddriv.cpp | 47 |
3 files changed, 60 insertions, 43 deletions
diff --git a/src/mame/drivers/harddriv.cpp b/src/mame/drivers/harddriv.cpp index 2578413f51e..189eb91897a 100644 --- a/src/mame/drivers/harddriv.cpp +++ b/src/mame/drivers/harddriv.cpp @@ -388,8 +388,8 @@ harddriv_state::harddriv_state(const machine_config &mconfig, device_type type, m_gsp_vram(*this, "gsp_vram"), m_gsp_control_lo(*this, "gsp_control_lo"), m_gsp_control_hi(*this, "gsp_control_hi"), - m_gsp_paletteram_lo(*this, "gsp_palram_lo"), - m_gsp_paletteram_hi(*this, "gsp_palram_hi"), + m_gsp_paletteram_lo(*this, "gsp_palram_lo", 1024*2, ENDIANNESS_LITTLE), + m_gsp_paletteram_hi(*this, "gsp_palram_hi", 1024*2, ENDIANNESS_LITTLE), m_in0(*this, "IN0"), m_sw1(*this, "SW1"), m_a80000(*this, "a80000"), @@ -565,8 +565,8 @@ void harddriv_state::driver_gsp_map(address_map &map) map(0x02000000, 0x0207ffff).rw(FUNC(harddriv_state::hdgsp_vram_2bpp_r), FUNC(harddriv_state::hdgsp_vram_1bpp_w)); map(0xf4000000, 0xf40000ff).rw(FUNC(harddriv_state::hdgsp_control_lo_r), FUNC(harddriv_state::hdgsp_control_lo_w)).share("gsp_control_lo"); map(0xf4800000, 0xf48000ff).rw(FUNC(harddriv_state::hdgsp_control_hi_r), FUNC(harddriv_state::hdgsp_control_hi_w)).share("gsp_control_hi"); - map(0xf5000000, 0xf5000fff).rw(FUNC(harddriv_state::hdgsp_paletteram_lo_r), FUNC(harddriv_state::hdgsp_paletteram_lo_w)).share("gsp_palram_lo"); - map(0xf5800000, 0xf5800fff).rw(FUNC(harddriv_state::hdgsp_paletteram_hi_r), FUNC(harddriv_state::hdgsp_paletteram_hi_w)).share("gsp_palram_hi"); + map(0xf5000000, 0xf5000fff).rw(FUNC(harddriv_state::hdgsp_paletteram_lo_r), FUNC(harddriv_state::hdgsp_paletteram_lo_w)); + map(0xf5800000, 0xf5800fff).rw(FUNC(harddriv_state::hdgsp_paletteram_hi_r), FUNC(harddriv_state::hdgsp_paletteram_hi_w)); map(0xff800000, 0xffffffff).ram().share("gsp_vram"); } @@ -614,8 +614,8 @@ void harddriv_state::multisync_gsp_map(address_map &map) map(0x02000000, 0x020fffff).rw(FUNC(harddriv_state::hdgsp_vram_2bpp_r), FUNC(harddriv_state::hdgsp_vram_2bpp_w)); map(0xf4000000, 0xf40000ff).rw(FUNC(harddriv_state::hdgsp_control_lo_r), FUNC(harddriv_state::hdgsp_control_lo_w)).share("gsp_control_lo"); map(0xf4800000, 0xf48000ff).rw(FUNC(harddriv_state::hdgsp_control_hi_r), FUNC(harddriv_state::hdgsp_control_hi_w)).share("gsp_control_hi"); - map(0xf5000000, 0xf5000fff).rw(FUNC(harddriv_state::hdgsp_paletteram_lo_r), FUNC(harddriv_state::hdgsp_paletteram_lo_w)).share("gsp_palram_lo"); - map(0xf5800000, 0xf5800fff).rw(FUNC(harddriv_state::hdgsp_paletteram_hi_r), FUNC(harddriv_state::hdgsp_paletteram_hi_w)).share("gsp_palram_hi"); + map(0xf5000000, 0xf5000fff).rw(FUNC(harddriv_state::hdgsp_paletteram_lo_r), FUNC(harddriv_state::hdgsp_paletteram_lo_w)); + map(0xf5800000, 0xf5800fff).rw(FUNC(harddriv_state::hdgsp_paletteram_hi_r), FUNC(harddriv_state::hdgsp_paletteram_hi_w)); map(0xff800000, 0xffbfffff).mirror(0x0400000).ram().share("gsp_vram"); } @@ -655,8 +655,8 @@ void harddriv_state::multisync2_gsp_map(address_map &map) map(0x02000000, 0x020fffff).rw(FUNC(harddriv_state::hdgsp_vram_2bpp_r), FUNC(harddriv_state::hdgsp_vram_2bpp_w)); map(0xf4000000, 0xf40000ff).rw(FUNC(harddriv_state::hdgsp_control_lo_r), FUNC(harddriv_state::hdgsp_control_lo_w)).share("gsp_control_lo"); map(0xf4800000, 0xf48000ff).rw(FUNC(harddriv_state::hdgsp_control_hi_r), FUNC(harddriv_state::hdgsp_control_hi_w)).share("gsp_control_hi"); - map(0xf5000000, 0xf5000fff).rw(FUNC(harddriv_state::hdgsp_paletteram_lo_r), FUNC(harddriv_state::hdgsp_paletteram_lo_w)).share("gsp_palram_lo"); - map(0xf5800000, 0xf5800fff).rw(FUNC(harddriv_state::hdgsp_paletteram_hi_r), FUNC(harddriv_state::hdgsp_paletteram_hi_w)).share("gsp_palram_hi"); + map(0xf5000000, 0xf5000fff).rw(FUNC(harddriv_state::hdgsp_paletteram_lo_r), FUNC(harddriv_state::hdgsp_paletteram_lo_w)); + map(0xf5800000, 0xf5800fff).rw(FUNC(harddriv_state::hdgsp_paletteram_hi_r), FUNC(harddriv_state::hdgsp_paletteram_hi_w)); map(0xff800000, 0xffffffff).ram().share("gsp_vram"); } @@ -4993,8 +4993,8 @@ void harddriv_state::init_harddriv() m_gsp->space(AS_PROGRAM).install_write_handler(0xfffcfc00, 0xfffcfc0f, write16s_delegate(*this, FUNC(harddriv_state::hdgsp_speedup2_w))); m_gsp->space(AS_PROGRAM).install_read_handler(0xfff9fc00, 0xfff9fc0f, read16sm_delegate(*this, FUNC(harddriv_state::hdgsp_speedup_r))); m_gsp_speedup_pc = 0xffc00f10; - m_gsp_speedup_addr[0] = (uint16_t *)&m_gsp_vram[(0xfff9fc00 - 0xff800000) >> 3]; // Addresses are in bits. Really. - m_gsp_speedup_addr[1] = (uint16_t *)&m_gsp_vram[(0xfffcfc00 - 0xff800000) >> 3]; + m_gsp_speedup_addr[0] = &m_gsp_vram[(0xfff9fc00 - 0xff800000) >> 4]; // Addresses are in bits. Really. + m_gsp_speedup_addr[1] = &m_gsp_vram[(0xfffcfc00 - 0xff800000) >> 4]; /* set up msp speedup handler */ m_msp->space(AS_PROGRAM).install_write_handler(0x00751b00, 0x00751b0f, write16s_delegate(*this, FUNC(harddriv_state::hdmsp_speedup_w))); @@ -5019,8 +5019,8 @@ void harddriv_state::init_harddrivc() m_gsp->space(AS_PROGRAM).install_write_handler(0xfffcfc00, 0xfffcfc0f, write16s_delegate(*this, FUNC(harddriv_state::hdgsp_speedup2_w))); m_gsp->space(AS_PROGRAM).install_read_handler(0xfff9fc00, 0xfff9fc0f, read16sm_delegate(*this, FUNC(harddriv_state::hdgsp_speedup_r))); m_gsp_speedup_pc = 0xfff40ff0; - m_gsp_speedup_addr[0] = (uint16_t *)&m_gsp_vram[(0xfff9fc00 - 0xffc00000) >> 3]; // Addresses are in bits. Really. - m_gsp_speedup_addr[1] = (uint16_t *)&m_gsp_vram[(0xfffcfc00 - 0xffc00000) >> 3]; + m_gsp_speedup_addr[0] = &m_gsp_vram[(0xfff9fc00 - 0xffc00000) >> 4]; // Addresses are in bits. Really. + m_gsp_speedup_addr[1] = &m_gsp_vram[(0xfffcfc00 - 0xffc00000) >> 4]; /* set up msp speedup handler */ m_msp->space(AS_PROGRAM).install_write_handler(0x00751b00, 0x00751b0f, write16s_delegate(*this, FUNC(harddriv_state::hdmsp_speedup_w))); @@ -5044,8 +5044,8 @@ void harddriv_state::init_stunrun() m_gsp->space(AS_PROGRAM).install_write_handler(0xfffcfc00, 0xfffcfc0f, write16s_delegate(*this, FUNC(harddriv_state::hdgsp_speedup2_w))); m_gsp->space(AS_PROGRAM).install_read_handler(0xfff9fc00, 0xfff9fc0f, read16sm_delegate(*this, FUNC(harddriv_state::hdgsp_speedup_r))); m_gsp_speedup_pc = 0xfff41070; - m_gsp_speedup_addr[0] = (uint16_t *)&m_gsp_vram[(0xfff9fc00 - 0xffc00000) >> 3]; // Addresses are in bits. Really. - m_gsp_speedup_addr[1] = (uint16_t *)&m_gsp_vram[(0xfffcfc00 - 0xffc00000) >> 3]; + m_gsp_speedup_addr[0] = &m_gsp_vram[(0xfff9fc00 - 0xffc00000) >> 4]; // Addresses are in bits. Really. + m_gsp_speedup_addr[1] = &m_gsp_vram[(0xfffcfc00 - 0xffc00000) >> 4]; /* set up adsp speedup handlers */ m_adsp->space(AS_DATA).install_read_handler(0x1fff, 0x1fff, read16smo_delegate(*this, FUNC(harddriv_state::hdadsp_speedup_r))); @@ -5098,13 +5098,13 @@ void harddriv_state::racedrivc_init_common(offs_t gsp_protection) /* set up protection hacks */ m_gsp->space(AS_PROGRAM).install_write_handler(gsp_protection, gsp_protection + 0x0f, write16smo_delegate(*this, FUNC(harddriv_state::hdgsp_protection_w))); - m_gsp_protection = (uint16_t *)&m_gsp_vram[(gsp_protection - 0xffc00000) >> 3]; + m_gsp_protection = &m_gsp_vram[(gsp_protection - 0xffc00000) >> 4]; /* set up gsp speedup handler */ m_gsp->space(AS_PROGRAM).install_write_handler(0xfff76f60, 0xfff76f6f, write16s_delegate(*this, FUNC(harddriv_state::rdgsp_speedup1_w))); m_gsp->space(AS_PROGRAM).install_read_handler(0xfff76f60, 0xfff76f6f, read16sm_delegate(*this, FUNC(harddriv_state::rdgsp_speedup1_r))); m_gsp_speedup_pc = 0xfff43a00; - m_gsp_speedup_addr[0] = (uint16_t *)&m_gsp_vram[(0xfff76f60 - 0xffc00000) >> 3]; + m_gsp_speedup_addr[0] = &m_gsp_vram[(0xfff76f60 - 0xffc00000) >> 4]; /* set up adsp speedup handlers */ m_adsp->space(AS_DATA).install_read_handler(0x1fff, 0x1fff, read16smo_delegate(*this, FUNC(harddriv_state::hdadsp_speedup_r))); @@ -5127,13 +5127,13 @@ void harddriv_state::init_racedrivc_panorama_side() /* set up protection hacks */ m_gsp->space(AS_PROGRAM).install_write_handler(gsp_protection, gsp_protection + 0x0f, write16smo_delegate(*this, FUNC(harddriv_state::hdgsp_protection_w))); - m_gsp_protection = (uint16_t *)&m_gsp_vram[(gsp_protection - 0xffc00000) >> 3]; + m_gsp_protection = &m_gsp_vram[(gsp_protection - 0xffc00000) >> 4]; /* set up gsp speedup handler (todo, work these out) */ // m_gsp->space(AS_PROGRAM).install_write_handler(0xfff76f60, 0xfff76f6f, write16s_delegate(*this, FUNC(harddriv_state::rdgsp_speedup1_w))); // m_gsp->space(AS_PROGRAM).install_read_handler(0xfff76f60, 0xfff76f6f, read16s_delegate(*this, FUNC(harddriv_state::rdgsp_speedup1_r))); // m_gsp_speedup_pc = 0xfff43a00; -// m_gsp_speedup_addr[0] = (uint16_t *)&m_gsp_vram[(0xfff76f60 - 0xffc00000) >> 3)]; +// m_gsp_speedup_addr[0] = &m_gsp_vram[(0xfff76f60 - 0xffc00000) >> 4)]; /* set up adsp speedup handlers */ m_adsp->space(AS_DATA).install_read_handler(0x1fff, 0x1fff, read16smo_delegate(*this, FUNC(harddriv_state::hdadsp_speedup_r))); @@ -5185,7 +5185,7 @@ void harddriv_state::steeltal_init_common(offs_t ds3_transfer_pc, int proto_sloo /* set up protection hacks */ m_gsp->space(AS_PROGRAM).install_write_handler(0xfff965d0, 0xfff965df, write16smo_delegate(*this, FUNC(harddriv_state::hdgsp_protection_w))); - m_gsp_protection = (uint16_t *)&m_gsp_vram[(0xfff965d0 - 0xffc00000) >> 3]; + m_gsp_protection = &m_gsp_vram[(0xfff965d0 - 0xffc00000) >> 4]; /* set up adsp speedup handlers */ m_adsp->space(AS_DATA).install_read_handler(0x1fff, 0x1fff, read16smo_delegate(*this, FUNC(harddriv_state::hdadsp_speedup_r))); @@ -5235,7 +5235,7 @@ void harddriv_state::init_strtdriv() /* set up protection hacks */ m_gsp->space(AS_PROGRAM).install_write_handler(0xfff960a0, 0xfff960af, write16smo_delegate(*this, FUNC(harddriv_state::hdgsp_protection_w))); - m_gsp_protection = (uint16_t *)&m_gsp_vram[(0xfff960a0 - 0xffc00000) >> 3]; + m_gsp_protection = &m_gsp_vram[(0xfff960a0 - 0xffc00000) >> 4]; /* set up adsp speedup handlers */ m_adsp->space(AS_DATA).install_read_handler(0x1fff, 0x1fff, read16smo_delegate(*this, FUNC(harddriv_state::hdadsp_speedup_r))); @@ -5263,7 +5263,7 @@ void harddriv_state::init_hdrivair() /* set up protection hacks */ m_gsp->space(AS_PROGRAM).install_write_handler(0xfff960a0, 0xfff960af, write16smo_delegate(*this, FUNC(harddriv_state::hdgsp_protection_w))); - m_gsp_protection = (uint16_t *)&m_gsp_vram[(0xfff960a0 - 0xffc00000) >> 3]; + m_gsp_protection = &m_gsp_vram[(0xfff960a0 - 0xffc00000) >> 4]; /* set up adsp speedup handlers */ m_adsp->space(AS_DATA).install_read_handler(0x1fff, 0x1fff, read16smo_delegate(*this, FUNC(harddriv_state::hdadsp_speedup_r))); @@ -5291,7 +5291,7 @@ void harddriv_state::init_hdrivairp() /* set up protection hacks */ m_gsp->space(AS_PROGRAM).install_write_handler(0xfff916c0, 0xfff916cf, write16smo_delegate(*this, FUNC(harddriv_state::hdgsp_protection_w))); - m_gsp_protection = (uint16_t *)&m_gsp_vram[(0xfff916c0 - 0xffc00000) >> 3]; + m_gsp_protection = &m_gsp_vram[(0xfff916c0 - 0xffc00000) >> 4]; /* set up adsp speedup handlers */ m_adsp->space(AS_DATA).install_read_handler(0x1fff, 0x1fff, read16smo_delegate(*this, FUNC(harddriv_state::hdadsp_speedup_r))); diff --git a/src/mame/includes/harddriv.h b/src/mame/includes/harddriv.h index 35f1d0dbee9..1e13053556d 100644 --- a/src/mame/includes/harddriv.h +++ b/src/mame/includes/harddriv.h @@ -351,11 +351,11 @@ protected: uint32_t m_adsp_speedup_count[4]; uint8_t m_gsp_multisync; - optional_shared_ptr<uint8_t> m_gsp_vram; - optional_shared_ptr<uint16_t> m_gsp_control_lo; - optional_shared_ptr<uint16_t> m_gsp_control_hi; - optional_shared_ptr<uint16_t> m_gsp_paletteram_lo; - optional_shared_ptr<uint16_t> m_gsp_paletteram_hi; + optional_shared_ptr<uint16_t> m_gsp_vram; + optional_shared_ptr<uint16_t> m_gsp_control_lo; + optional_shared_ptr<uint16_t> m_gsp_control_hi; + memory_share_creator<uint16_t> m_gsp_paletteram_lo; + memory_share_creator<uint16_t> m_gsp_paletteram_hi; required_ioport m_in0; optional_ioport m_sw1; @@ -450,7 +450,7 @@ protected: uint8_t m_shiftreg_enable; uint32_t m_mask_table[65536 * 4]; - uint8_t * m_gsp_shiftreg_source; + uint16_t * m_gsp_shiftreg_source; int8_t m_gfx_finescroll; uint8_t m_gfx_palettebank; diff --git a/src/mame/video/harddriv.cpp b/src/mame/video/harddriv.cpp index b8277e1d88d..a1281fb14ec 100644 --- a/src/mame/video/harddriv.cpp +++ b/src/mame/video/harddriv.cpp @@ -86,7 +86,7 @@ void harddriv_state::init_video() } /* init VRAM pointers */ - m_vram_mask = m_gsp_vram.bytes() - 1; + m_vram_mask = m_gsp_vram.bytes()/2 - 1; } @@ -103,9 +103,9 @@ TMS340X0_TO_SHIFTREG_CB_MEMBER(harddriv_state::hdgsp_write_to_shiftreg) if (address >= 0x02000000 && address <= 0x020fffff) { address -= 0x02000000; - address >>= m_gsp_multisync; + address >>= m_gsp_multisync + 1; address &= m_vram_mask; - address &= ~((512*8 >> m_gsp_multisync) - 1); + address &= ~((256*8 >> m_gsp_multisync) - 1); m_gsp_shiftreg_source = &m_gsp_vram[address]; } @@ -113,9 +113,9 @@ TMS340X0_TO_SHIFTREG_CB_MEMBER(harddriv_state::hdgsp_write_to_shiftreg) else if (address >= 0xff800000 && address <= 0xffffffff) { address -= 0xff800000; - address /= 8; + address /= 16; address &= m_vram_mask; - address &= ~511; + address &= ~255; m_gsp_shiftreg_source = &m_gsp_vram[address]; } else @@ -132,9 +132,9 @@ TMS340X0_FROM_SHIFTREG_CB_MEMBER(harddriv_state::hdgsp_read_from_shiftreg) if (address >= 0x02000000 && address <= 0x020fffff) { address -= 0x02000000; - address >>= m_gsp_multisync; + address >>= m_gsp_multisync + 1; address &= m_vram_mask; - address &= ~((512*8 >> m_gsp_multisync) - 1); + address &= ~((256*8 >> m_gsp_multisync) - 1); memmove(&m_gsp_vram[address], m_gsp_shiftreg_source, 512*8 >> m_gsp_multisync); } @@ -142,9 +142,9 @@ TMS340X0_FROM_SHIFTREG_CB_MEMBER(harddriv_state::hdgsp_read_from_shiftreg) else if (address >= 0xff800000 && address <= 0xffffffff) { address -= 0xff800000; - address /= 8; + address /= 16; address &= m_vram_mask; - address &= ~511; + address &= ~255; memmove(&m_gsp_vram[address], m_gsp_shiftreg_source, 512); } else @@ -270,7 +270,7 @@ uint16_t harddriv_state::hdgsp_vram_2bpp_r() void harddriv_state::hdgsp_vram_1bpp_w (offs_t offset, uint16_t data) { - uint32_t *dest = (uint32_t *)&m_gsp_vram[offset * 16]; + uint32_t *dest = (uint32_t *)&m_gsp_vram[offset * 8]; uint32_t *mask = &m_mask_table[data * 4]; uint32_t color = m_gsp_control_lo[0] & 0xff; uint32_t curmask; @@ -298,7 +298,7 @@ void harddriv_state::hdgsp_vram_1bpp_w (offs_t offset, uint16_t data) void harddriv_state::hdgsp_vram_2bpp_w(offs_t offset, uint16_t data) { - uint32_t *dest = (uint32_t *)&m_gsp_vram[offset * 8]; + uint32_t *dest = (uint32_t *)&m_gsp_vram[offset * 4]; uint32_t *mask = &m_mask_table[data * 2]; uint32_t color = m_gsp_control_lo[0]; uint32_t curmask; @@ -410,13 +410,22 @@ static void display_speedups(void) TMS340X0_SCANLINE_IND16_CB_MEMBER(harddriv_state::scanline_driver) { if (!m_gsp_vram) return; - uint8_t const *const vram_base = &m_gsp_vram[(params->rowaddr << 12) & m_vram_mask]; + uint16_t const *const vram_base = &m_gsp_vram[(params->rowaddr << 11) & m_vram_mask]; uint16_t *const dest = &bitmap.pix(scanline); int coladdr = (params->yoffset << 9) + ((params->coladdr & 0xff) << 4) - 15 + (m_gfx_finescroll & 0x0f); for (int x = params->heblnk; x < params->hsblnk; x++) - dest[x] = m_gfx_palettebank * 256 + vram_base[BYTE_XOR_LE(coladdr++ & 0xfff)]; + { + int coloridx = coladdr++ & 0xfff; + uint8_t color; + if(coloridx & 1) + color = vram_base[coloridx >> 1] >> 8; + else + color = vram_base[coloridx >> 1]; + + dest[x] = m_gfx_palettebank * 256 + color; + } if (scanline == screen.visible_area().bottom()) display_speedups(); @@ -426,13 +435,21 @@ TMS340X0_SCANLINE_IND16_CB_MEMBER(harddriv_state::scanline_driver) TMS340X0_SCANLINE_IND16_CB_MEMBER(harddriv_state::scanline_multisync) { if (!m_gsp_vram) return; - uint8_t const *const vram_base = &m_gsp_vram[(params->rowaddr << 11) & m_vram_mask]; + uint16_t const *const vram_base = &m_gsp_vram[(params->rowaddr << 10) & m_vram_mask]; uint16_t *const dest = &bitmap.pix(scanline); int coladdr = (params->yoffset << 9) + ((params->coladdr & 0xff) << 3) - 7 + (m_gfx_finescroll & 0x07); for (int x = params->heblnk; x < params->hsblnk; x++) - dest[x] = m_gfx_palettebank * 256 + vram_base[BYTE_XOR_LE(coladdr++ & 0x7ff)]; + { + int coloridx = coladdr++ & 0x7ff; + uint8_t color; + if(coloridx & 1) + color = vram_base[coloridx >> 1] >> 8; + else + color = vram_base[coloridx >> 1]; + dest[x] = m_gfx_palettebank * 256 + color; + } if (scanline == screen.visible_area().bottom()) display_speedups(); |