From e3a36bad2a9c8e342525f3b433bd347f25666247 Mon Sep 17 00:00:00 2001 From: Fabio Priuli Date: Tue, 26 Feb 2013 11:33:06 +0000 Subject: [PATCH] (MESS) megadriv.c: added support for Legend of Wukong [Fabio Priuli] --- hash/megadriv.xml | 16 +++++++++- src/mess/drivers/megadriv.c | 1 + src/mess/machine/md_rom.c | 64 +++++++++++++++++++++++++++++++++++++ src/mess/machine/md_rom.h | 21 ++++++++++++ src/mess/machine/md_slot.c | 7 ++++ src/mess/machine/md_slot.h | 1 + 6 files changed, 109 insertions(+), 1 deletion(-) diff --git a/hash/megadriv.xml b/hash/megadriv.xml index c768981775b..cf4eea2f0b7 100644 --- a/hash/megadriv.xml +++ b/hash/megadriv.xml @@ -25747,6 +25747,20 @@ Notice that these are not working on real hardware due to bugged code with VDP i + Legend of Wukong (Euro, USA) + 2008 + Super Fighter Team + + + + + + + + + + + Wu Kong Wai Zhuan (Chi) 1996 Ming @@ -26120,7 +26134,7 @@ Notice that these are not working on real hardware due to bugged code with VDP i - Beggar Prince (USA) + Beggar Prince (Euro, USA) 2005 Super Fighter Team diff --git a/src/mess/drivers/megadriv.c b/src/mess/drivers/megadriv.c index e6a6f997ab9..2c16014ee20 100644 --- a/src/mess/drivers/megadriv.c +++ b/src/mess/drivers/megadriv.c @@ -305,6 +305,7 @@ static SLOT_INTERFACE_START(md_cart) SLOT_INTERFACE_INTERNAL("rom_fram", MD_ROM_FRAM) SLOT_INTERFACE_INTERNAL("rom_hardbl95", MD_ROM_SRAM) SLOT_INTERFACE_INTERNAL("rom_beggar", MD_ROM_SRAM) + SLOT_INTERFACE_INTERNAL("rom_wukong", MD_ROM_WUKONG) // EEPROM handling (not supported fully yet) SLOT_INTERFACE_INTERNAL("rom_eeprom", MD_STD_EEPROM) SLOT_INTERFACE_INTERNAL("rom_nbajam", MD_EEPROM_NBAJAM) diff --git a/src/mess/machine/md_rom.c b/src/mess/machine/md_rom.c index aae29b4f450..d71da785cd4 100644 --- a/src/mess/machine/md_rom.c +++ b/src/mess/machine/md_rom.c @@ -48,6 +48,7 @@ const device_type MD_ROM_REDCL = &device_creator; const device_type MD_ROM_SQUIR = &device_creator; const device_type MD_ROM_TOPF = &device_creator; const device_type MD_ROM_RADICA = &device_creator; +const device_type MD_ROM_WUKONG = &device_creator; md_std_rom_device::md_std_rom_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock) @@ -192,6 +193,11 @@ md_rom_radica_device::md_rom_radica_device(const machine_config &mconfig, const { } +md_rom_wukong_device::md_rom_wukong_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) + : md_std_rom_device(mconfig, MD_ROM_WUKONG, "MD Legend of Wukong", tag, owner, clock) +{ +} + //------------------------------------------------- // device_start - device-specific startup //------------------------------------------------- @@ -286,6 +292,12 @@ void md_rom_radica_device::device_start() save_item(NAME(m_bank)); } +void md_rom_wukong_device::device_start() +{ + m_mode = 0; + save_item(NAME(m_mode)); +} + /*------------------------------------------------- mapper specific handlers -------------------------------------------------*/ @@ -1042,3 +1054,55 @@ READ16_MEMBER(md_rom_radica_device::read_a13) m_bank = offset & 0x3f; return 0; } + + +/*------------------------------------------------- + LEGEND OF WUKONG + This game uses cart which is the same as SEGA_SRAM + + bankswitch mechanism for last 128k of the image: + first 2MB of ROM is loaded in 0-0x200000 and + mirrored in 0x200000-0x400000, but depending on + bit7 of the value written at 0xe00/2 accesses to + 0x200000-0x21ffff go either to the "physical" address + (i.e. last 128K of ROM) or to the "memory" address + (i.e. mirror of first 128K) + -------------------------------------------------*/ + +READ16_MEMBER(md_rom_wukong_device::read) +{ + if (offset >= m_nvram_start/2 && offset <= m_nvram_end/2 && m_nvram_active) + return m_nvram[offset - m_nvram_start/2]; + + // here can access both last 128K of the ROM and the first 128K, depending of bit7 of m_mode + if (offset >= 0x200000/2 && offset < 0x220000/2) + return !m_mode ? m_rom[offset] : m_rom[offset & 0xffff]; + else if (offset < 0x400000/2) + return m_rom[offset & 0xfffff]; + else + return 0xffff; +} + +WRITE16_MEMBER(md_rom_wukong_device::write) +{ + if (offset < 0x100000/2) // it actually writes to 0xe00/2 + m_mode = BIT(data, 7); + + if (offset >= m_nvram_start/2 && offset <= m_nvram_end/2 && m_nvram_active && !m_nvram_readonly) + m_nvram[offset - m_nvram_start/2] = data; +} + +WRITE16_MEMBER(md_rom_wukong_device::write_a13) +{ + if (offset == 0xf0/2) + { + /* unsure if this is actually supposed to toggle or just switch on? yet to encounter game that uses this */ + m_nvram_active = BIT(data, 0); + m_nvram_readonly = BIT(data, 1); + + // since a lot of generic carts ends up here if loaded from fullpath + // we turn on nvram (with m_nvram_handlers_installed) only if they toggle it on by writing here! + if (m_nvram_active) + m_nvram_handlers_installed = 1; + } +} + diff --git a/src/mess/machine/md_rom.h b/src/mess/machine/md_rom.h index 90e643a75af..a5cecd09053 100644 --- a/src/mess/machine/md_rom.h +++ b/src/mess/machine/md_rom.h @@ -483,6 +483,26 @@ private: UINT8 m_bank; }; +// ======================> md_rom_wukong_device + +class md_rom_wukong_device : public md_std_rom_device +{ +public: + // construction/destruction + md_rom_wukong_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); + + // device-level overrides + virtual void device_start(); + virtual void device_config_complete() { m_shortname = "md_rom_wukong"; } + + // reading and writing + virtual DECLARE_READ16_MEMBER(read); + virtual DECLARE_WRITE16_MEMBER(write); + virtual DECLARE_WRITE16_MEMBER(write_a13); + + UINT8 m_mode; +}; + // device type definition @@ -513,5 +533,6 @@ extern const device_type MD_ROM_SSF2; extern const device_type MD_ROM_SQUIR; extern const device_type MD_ROM_TOPF; extern const device_type MD_ROM_RADICA; +extern const device_type MD_ROM_WUKONG; #endif diff --git a/src/mess/machine/md_slot.c b/src/mess/machine/md_slot.c index b0a1ef70d8e..d9a85f447e6 100644 --- a/src/mess/machine/md_slot.c +++ b/src/mess/machine/md_slot.c @@ -241,6 +241,7 @@ static const md_slot slot_list[] = { SEGA_FRAM, "rom_fram" }, { HARDBALL95, "rom_hardbl95" }, { BEGGAR, "rom_beggar"}, + { WUKONG, "rom_wukong"}, { SEGA_EEPROM, "rom_eeprom" }, { NBA_JAM, "rom_nbajam" }, @@ -639,6 +640,12 @@ void base_md_cart_slot_device::setup_nvram() m_cart->m_nvram_active = 1; m_cart->m_nvram_handlers_installed = 1; break; + case WUKONG: + m_cart->m_nvram_start = 0x3c0000; + m_cart->m_nvram_end = m_cart->m_nvram_start + 0x3fff; + m_cart->nvram_alloc(machine(), m_cart->m_nvram_end - m_cart->m_nvram_start + 1); + m_cart->m_nvram_active = 1; + break; } } diff --git a/src/mess/machine/md_slot.h b/src/mess/machine/md_slot.h index c6806b3d068..05ccc138645 100644 --- a/src/mess/machine/md_slot.h +++ b/src/mess/machine/md_slot.h @@ -22,6 +22,7 @@ enum SEGA_SRAM, SEGA_FRAM, HARDBALL95, /* Hardball 95 uses different sram start address */ BEGGAR, /* Beggar Prince / Xin Qigai Wangzi uses different sram start address and has no valid header */ + WUKONG, /* Legend of Wukong uses different sram start address + bankswitch trick for last 128K of ROM */ // EEPROM SEGA_EEPROM, /* Wonder Boy V / Evander Holyfield's Boxing / Greatest Heavyweights of the Ring / Sports Talk Baseball / Megaman */