From a40ecafcea71e091a75af635e258a7770417b3d4 Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Thu, 15 Sep 2022 06:51:59 +1000 Subject: bus/gameboy/mbc.cpp: Added support for HK0701 and HK0819 bootlegs. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit New working software list additions ---------------------- gbcolor.xml: Guàishòu Go! Go! Ⅱ (China) [taizou, Vas Crabb] gbcolor.xml: Kǒudài Guàishòu - Dòngzuò Piān (China) [taizou, Vas Crabb] --- hash/gbcolor.xml | 40 +++++++++++-- src/devices/bus/gameboy/carts.cpp | 2 + src/devices/bus/gameboy/carts.h | 1 + src/devices/bus/gameboy/gbslot.cpp | 11 ++-- src/devices/bus/gameboy/gbxfile.h | 1 + src/devices/bus/gameboy/mbc.cpp | 112 +++++++++++++++++++++++++++++++++++++ src/devices/bus/gameboy/mbc.h | 3 + 7 files changed, 162 insertions(+), 8 deletions(-) diff --git a/hash/gbcolor.xml b/hash/gbcolor.xml index 81f6bdc35c2..0ce6903da6a 100644 --- a/hash/gbcolor.xml +++ b/hash/gbcolor.xml @@ -26290,8 +26290,7 @@ license:CC0 - - + @@ -26329,6 +26328,7 @@ license:CC0 Vast Fame + @@ -26336,6 +26336,37 @@ license:CC0 + + + + Kǒudài Guàishòu - Dòngzuò Piān (China) + 200? + <unknown> + + + + + + + + + + + + + Guàishòu Go! Go! Ⅱ (China) + 200? + <unknown> + + + + + + + + + + E Mo Dao (China, ripped from 8 in 1 multicart) 200? @@ -26414,10 +26445,11 @@ license:CC0 - Koudai Guaishou - Lanbaoshi (China) + Kǒudài Guàishòu - Lánbǎoshí (China) 200? Sintax - + + diff --git a/src/devices/bus/gameboy/carts.cpp b/src/devices/bus/gameboy/carts.cpp index 8cb00dc0692..e783d11c9c9 100644 --- a/src/devices/bus/gameboy/carts.cpp +++ b/src/devices/bus/gameboy/carts.cpp @@ -50,6 +50,7 @@ char const *const GB_CAMERA = "rom_camera"; char const *const GB_SINTAX = "rom_sintax"; char const *const GB_CHONGWU = "rom_chong"; char const *const GB_LICHENG = "rom_licheng"; +char const *const GB_NEWGBCHK = "rom_newgbchk"; char const *const GB_VF001 = "rom_vf001"; char const *const GB_DIGIMON = "rom_digimon"; @@ -91,6 +92,7 @@ void gameboy_cartridges(device_slot_interface &device) device.option_add_internal(slotoptions::GB_SINTAX, GB_ROM_SINTAX); device.option_add_internal(slotoptions::GB_CHONGWU, GB_ROM_CHONGWU); device.option_add_internal(slotoptions::GB_LICHENG, GB_ROM_LICHENG); + device.option_add_internal(slotoptions::GB_NEWGBCHK, GB_ROM_NEWGBCHK); device.option_add_internal(slotoptions::GB_VF001, GB_ROM_VF001); device.option_add_internal(slotoptions::GB_DIGIMON, GB_ROM_DIGIMON); } diff --git a/src/devices/bus/gameboy/carts.h b/src/devices/bus/gameboy/carts.h index 2d330f104ff..e4660129be9 100644 --- a/src/devices/bus/gameboy/carts.h +++ b/src/devices/bus/gameboy/carts.h @@ -44,6 +44,7 @@ extern char const *const GB_TAMA5; extern char const *const GB_SINTAX; extern char const *const GB_CHONGWU; extern char const *const GB_LICHENG; +extern char const *const GB_NEWGBCHK; extern char const *const GB_VF001; extern char const *const GB_DIGIMON; diff --git a/src/devices/bus/gameboy/gbslot.cpp b/src/devices/bus/gameboy/gbslot.cpp index fb1dff850b0..c81b307f06a 100644 --- a/src/devices/bus/gameboy/gbslot.cpp +++ b/src/devices/bus/gameboy/gbslot.cpp @@ -722,20 +722,23 @@ std::optional probe_gbx_footer(std::string_view tag, util::random_ case gbxfile::TYPE_MMM01: result = slotoptions::GB_MMM01; break; + case gbxfile::TYPE_CAMERA: + result = slotoptions::GB_CAMERA; + break; case gbxfile::TYPE_HUC1: result = slotoptions::GB_HUC1; break; case gbxfile::TYPE_HUC3: result = slotoptions::GB_HUC3; break; - case gbxfile::TYPE_CAMERA: - result = slotoptions::GB_CAMERA; + case gbxfile::TYPE_SINTAX: + result = slotoptions::GB_SINTAX; break; case gbxfile::TYPE_LICHENG: result = slotoptions::GB_LICHENG; break; - case gbxfile::TYPE_SINTAX: - result = slotoptions::GB_SINTAX; + case gbxfile::TYPE_NEWGBCHK: + result = slotoptions::GB_NEWGBCHK; break; case gbxfile::TYPE_VF001: result = slotoptions::GB_VF001; diff --git a/src/devices/bus/gameboy/gbxfile.h b/src/devices/bus/gameboy/gbxfile.h index 39ef74e5d17..ca752f56cf6 100644 --- a/src/devices/bus/gameboy/gbxfile.h +++ b/src/devices/bus/gameboy/gbxfile.h @@ -62,6 +62,7 @@ enum : u32 TYPE_MBC5 = 0x4d424335, // 'MBC5' TYPE_MBC7 = 0x4d424337, // 'MBC7' TYPE_MMM01 = 0x4d4d4d31, // 'MMM1' + TYPE_NEWGBCHK = 0x4e47484b, // 'NGHK' TYPE_ROCKET = 0x524f434b, // 'ROCK' TYPE_PLAIN = 0x524f4d00, // 'ROM\0' TYPE_SACHEN1 = 0x53414d31, // 'SAM1' diff --git a/src/devices/bus/gameboy/mbc.cpp b/src/devices/bus/gameboy/mbc.cpp index e35c1916edc..4cdd7e6a4ec 100644 --- a/src/devices/bus/gameboy/mbc.cpp +++ b/src/devices/bus/gameboy/mbc.cpp @@ -80,6 +80,8 @@ - MBC30 supposedly has 8 ROM bank outputs, but the one game using it only needs 7. * MBC5 logo spoofing class implements several strategies. It's likely not all carts using it use all the strategies. Strategies implemented by each cartridge should be identified. + * HK0701 and HK0819 seem to differ in that HK0819 fully decodes ROM addresses while HK0701 mirrors - we + should probably emulated the difference at some point. * Digimon 2 mapper doesn't work ***********************************************************************************************************/ @@ -1453,6 +1455,115 @@ public: +//************************************************************************** +// New Game Boy Color cartridges with HK0701 and HK0819 boards +//************************************************************************** + +class ngbchk_device : public rom_mbc_device_base +{ +public: + ngbchk_device(machine_config const &mconfig, char const *tag, device_t *owner, u32 clock) : + rom_mbc_device_base(mconfig, GB_ROM_NEWGBCHK, tag, owner, clock), + m_view_prot(*this, "protection") + { + } + + virtual image_init_result load(std::string &message) override ATTR_COLD + { + // TODO: ROM addresses seem to be fully decoded with HK0819 (rather than mirroring) + + // set up ROM and RAM + // TODO: how many RAM bank outputs are actually present? + if (!install_memory(message, 2, 7)) + return image_init_result::FAIL; + + // install handlers + cart_space()->install_write_handler( + 0x0000, 0x1fff, + write8smo_delegate(*this, FUNC(ngbchk_device::enable_ram))); + cart_space()->install_write_handler( + 0x2000, 0x3fff, + write8smo_delegate(*this, FUNC(ngbchk_device::bank_switch_fine))); + cart_space()->install_write_handler( + 0x4000, 0x5fff, + write8smo_delegate(*this, FUNC(ngbchk_device::bank_switch_coarse))); + + // install protection over the top of high ROM bank + cart_space()->install_view( + 0x4000, 0x7fff, + m_view_prot); + m_view_prot[0].install_read_handler( + 0x4000, 0x4fff, 0x0ff0, 0x0000, 0x0000, + read8sm_delegate(*this, FUNC(ngbchk_device::protection))); + m_view_prot[0].unmap_read(0x5000, 0x7fff); + + // all good + return image_init_result::PASS; + } + +protected: + virtual void device_reset() override ATTR_COLD + { + rom_mbc_device_base::device_reset(); + + // TODO: proper reset state + set_bank_rom_coarse(0); + set_bank_rom_fine(0); + set_ram_enable(false); + + m_view_prot.disable(); + } + +private: + void enable_ram(u8 data) + { + // TODO: how many bits are checked? + set_ram_enable(0x0a == data); + } + + void bank_switch_fine(u8 data) + { + set_bank_rom_fine(data & 0x7f); + LOG("Protection read %s\n", BIT(data, 7) ? "enabled" : "disabled"); + if (BIT(data, 7)) + m_view_prot.select(0); + else + m_view_prot.disable(); + } + + u8 protection(offs_t offset) + { + offset >>= 4; + switch (offset & 0x007) + { + default: // just to shut up dumb compilers + case 0x000: + return offset; + case 0x001: + return offset ^ 0xaa; + case 0x002: + return offset ^ 0xaa; + case 0x003: + return (offset >> 1) | (offset << 7); + case 0x004: + return (offset << 1) | (offset >> 7); + case 0x05: + return bitswap<8>(offset, 0, 1, 2, 3, 4, 5, 6, 7); + case 0x06: + return + (bitswap<4>(offset | (offset >> 1), 6, 4, 2, 0) << 4) | + bitswap<4>(offset & (offset >> 1), 6, 4, 2, 0); + case 0x07: + return + (bitswap<4>(offset ^ (~offset >> 1), 6, 4, 2, 0) << 4) | + bitswap<4>(offset ^ (offset >> 1), 6, 4, 2, 0); + } + } + + memory_view m_view_prot; +}; + + //************************************************************************** // Fast Fame VF001 MBC5 variant with protection //************************************************************************** @@ -1786,5 +1897,6 @@ DEFINE_DEVICE_TYPE_PRIVATE(GB_ROM_MBC5, device_gb_cart_interface, bus::gameb DEFINE_DEVICE_TYPE_PRIVATE(GB_ROM_SINTAX, device_gb_cart_interface, bus::gameboy::sintax_device, "gb_rom_sintax", "Game Boy Sintax MBC5 Cartridge") DEFINE_DEVICE_TYPE_PRIVATE(GB_ROM_CHONGWU, device_gb_cart_interface, bus::gameboy::chongwu_device, "gb_rom_chongwu", "Game Boy Chongwu Xiao Jingling Pokemon Pikecho Cartridge") DEFINE_DEVICE_TYPE_PRIVATE(GB_ROM_LICHENG, device_gb_cart_interface, bus::gameboy::licheng_device, "gb_rom_licheng", "Game Boy Li Cheng MBC5 Cartridge") +DEFINE_DEVICE_TYPE_PRIVATE(GB_ROM_NEWGBCHK, device_gb_cart_interface, bus::gameboy::ngbchk_device, "gb_rom_ngbchk", "Game Boy HK0701/HK0819 Cartridge") DEFINE_DEVICE_TYPE_PRIVATE(GB_ROM_VF001, device_gb_cart_interface, bus::gameboy::vf001_device, "gb_rom_vf001", "Game Boy Vast Fame VF001 Cartridge") DEFINE_DEVICE_TYPE_PRIVATE(GB_ROM_DIGIMON, device_gb_cart_interface, bus::gameboy::digimon_device, "gb_rom_digimon", "Game Boy Digimon 2 Cartridge") diff --git a/src/devices/bus/gameboy/mbc.h b/src/devices/bus/gameboy/mbc.h index ef48d215480..f7e7301a5c3 100644 --- a/src/devices/bus/gameboy/mbc.h +++ b/src/devices/bus/gameboy/mbc.h @@ -3,6 +3,8 @@ #ifndef MAME_BUS_GAMEBOY_MBC_H #define MAME_BUS_GAMEBOY_MBC_H +#pragma once + #include "slot.h" @@ -13,6 +15,7 @@ DECLARE_DEVICE_TYPE(GB_ROM_MMM01, device_gb_cart_interface) DECLARE_DEVICE_TYPE(GB_ROM_SINTAX, device_gb_cart_interface) DECLARE_DEVICE_TYPE(GB_ROM_CHONGWU, device_gb_cart_interface) DECLARE_DEVICE_TYPE(GB_ROM_LICHENG, device_gb_cart_interface) +DECLARE_DEVICE_TYPE(GB_ROM_NEWGBCHK, device_gb_cart_interface) DECLARE_DEVICE_TYPE(GB_ROM_VF001, device_gb_cart_interface) DECLARE_DEVICE_TYPE(GB_ROM_DIGIMON, device_gb_cart_interface) -- cgit v1.2.3