From 6c0257b1a1ea81647338d081858123c9c25fcf81 Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Sat, 12 Nov 2022 03:39:21 +1100 Subject: bus/gameboy: Added support for Liebao Technology cartridges. gameboy.xml: Changed default NVRAM fill for dbzgeki to 0xff - this will cause it to treat the three save files as empty rather than starting in a glitchy state. New working software list items ------------------------------- Dragon Ball Z English [lana_chan_, taizou] --- hash/gameboy.xml | 19 +++++ scripts/src/bus.lua | 2 + src/devices/bus/gameboy/carts.cpp | 3 + src/devices/bus/gameboy/carts.h | 1 + src/devices/bus/gameboy/gbslot.cpp | 3 + src/devices/bus/gameboy/gbxfile.h | 3 +- src/devices/bus/gameboy/liebao.cpp | 159 +++++++++++++++++++++++++++++++++++++ src/devices/bus/gameboy/liebao.h | 18 +++++ 8 files changed, 207 insertions(+), 1 deletion(-) create mode 100644 src/devices/bus/gameboy/liebao.cpp create mode 100644 src/devices/bus/gameboy/liebao.h diff --git a/hash/gameboy.xml b/hash/gameboy.xml index 3cfd9c6e528..5c8375b4bd8 100644 --- a/hash/gameboy.xml +++ b/hash/gameboy.xml @@ -5851,6 +5851,25 @@ license:CC0 + + + + + + + + Dragon Ball Z English + 2001 + Liebao Technology? + + + + + + + + + diff --git a/scripts/src/bus.lua b/scripts/src/bus.lua index 35a2a066228..a4db57aad6c 100644 --- a/scripts/src/bus.lua +++ b/scripts/src/bus.lua @@ -3719,6 +3719,8 @@ if (BUSES["GAMEBOY"]~=null) then MAME_DIR .. "src/devices/bus/gameboy/huc1.h", MAME_DIR .. "src/devices/bus/gameboy/huc3.cpp", MAME_DIR .. "src/devices/bus/gameboy/huc3.h", + MAME_DIR .. "src/devices/bus/gameboy/liebao.cpp", + MAME_DIR .. "src/devices/bus/gameboy/liebao.h", MAME_DIR .. "src/devices/bus/gameboy/mbc.cpp", MAME_DIR .. "src/devices/bus/gameboy/mbc.h", MAME_DIR .. "src/devices/bus/gameboy/mbc2.cpp", diff --git a/src/devices/bus/gameboy/carts.cpp b/src/devices/bus/gameboy/carts.cpp index 42a6e87fc19..a1341314fc6 100644 --- a/src/devices/bus/gameboy/carts.cpp +++ b/src/devices/bus/gameboy/carts.cpp @@ -13,6 +13,7 @@ #include "gbck003.h" #include "huc1.h" #include "huc3.h" +#include "liebao.h" #include "mbc.h" #include "mbc2.h" #include "mbc3.h" @@ -55,6 +56,7 @@ 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_LIEBAO = "rom_liebao"; char const *const GB_NTNEW = "rom_ntnew"; char const *const GB_SLMULTI = "rom_slmulti"; char const *const GB_GBCK003 = "rom_gbck003"; @@ -98,6 +100,7 @@ void gameboy_cartridges(device_slot_interface &device) 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_LIEBAO, GB_ROM_LIEBAO); device.option_add_internal(slotoptions::GB_NTNEW, GB_ROM_NTNEW); device.option_add_internal(slotoptions::GB_SLMULTI, GB_ROM_SLMULTI); device.option_add_internal(slotoptions::GB_GBCK003, GB_ROM_GBCK003); diff --git a/src/devices/bus/gameboy/carts.h b/src/devices/bus/gameboy/carts.h index 1f7107c074c..ddf1d174665 100644 --- a/src/devices/bus/gameboy/carts.h +++ b/src/devices/bus/gameboy/carts.h @@ -45,6 +45,7 @@ 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_LIEBAO; extern char const *const GB_NTNEW; extern char const *const GB_SLMULTI; extern char const *const GB_GBCK003; diff --git a/src/devices/bus/gameboy/gbslot.cpp b/src/devices/bus/gameboy/gbslot.cpp index e45406ae49d..9cd95a59441 100644 --- a/src/devices/bus/gameboy/gbslot.cpp +++ b/src/devices/bus/gameboy/gbslot.cpp @@ -746,6 +746,9 @@ std::optional probe_gbx_footer(std::string_view tag, util::random_ case gbxfile::TYPE_VF001: result = slotoptions::GB_VF001; break; + case gbxfile::TYPE_LIEBAO: + result = slotoptions::GB_LIEBAO; + break; case gbxfile::TYPE_NTNEW: result = slotoptions::GB_NTNEW; break; diff --git a/src/devices/bus/gameboy/gbxfile.h b/src/devices/bus/gameboy/gbxfile.h index 1e35e605c42..2be34583ff0 100644 --- a/src/devices/bus/gameboy/gbxfile.h +++ b/src/devices/bus/gameboy/gbxfile.h @@ -24,7 +24,7 @@ * Program ROM size in bytes (4 bytes). * Cartridge RAM size in bytes (4 bytes). - There is additional data between the leader and trailer that contains + There is additional data between the leader and trailer that can hold additional wiring or configuration details for the cartridge if necessary. In general, it's 32 bytes long, and unused portions are filled with 0x00. It seems to be entirely unused for most cartridge types. @@ -55,6 +55,7 @@ enum : u32 TYPE_HUC3 = 0x48554333, // 'HUC3' TYPE_SLMULTI = 0x4c424d43, // 'LBMC' TYPE_LICHENG = 0x4c494348, // 'LICH' + TYPE_LIEBAO = 0x4c494241, // 'LIBA' TYPE_M161 = 0x4d313631, // 'M161' TYPE_MBC1_COLL = 0x4d42314d, // 'MB1M' TYPE_MBC1 = 0x4d424331, // 'MBC1' diff --git a/src/devices/bus/gameboy/liebao.cpp b/src/devices/bus/gameboy/liebao.cpp new file mode 100644 index 00000000000..f9bd8cafcc1 --- /dev/null +++ b/src/devices/bus/gameboy/liebao.cpp @@ -0,0 +1,159 @@ +// license:BSD-3-Clause +// copyright-holders:Vas Crabb +/*************************************************************************** + + Memory controller used by Liebao Technology + + Supports switching 8 KiB pages at 0x4000 and 0x6000 independently. Only + even pages can be mapped at 0x4000, and only odd pages can be mapped at + 0x6000. Everything here is guesswork based on the behaviour of a single + game. + + ***************************************************************************/ + +#include "emu.h" +#include "liebao.h" + +#include "cartbase.ipp" + +//#define VERBOSE 1 +//#define LOG_OUTPUT_FUNC osd_printf_info +#include "logmacro.h" + + +namespace bus::gameboy { + +namespace { + +class liebao_device : public mbc_ram_device_base +{ +public: + liebao_device(machine_config const &mconfig, char const *tag, device_t *owner, u32 clock); + + virtual image_init_result load(std::string &message) override ATTR_COLD; + +protected: + virtual void device_start() override ATTR_COLD; + virtual void device_reset() override ATTR_COLD; + +private: + void enable_ram(offs_t offset, u8 data); + void bank_switch_rom(offs_t offset, u8 data); + void bank_switch_ram(u8 data); + void bank_switch_rom_high(offs_t offset, u8 data); + + memory_view m_view_ram; + + u8 m_bank_high_set; +}; + + +liebao_device::liebao_device( + machine_config const &mconfig, + char const *tag, + device_t *owner, + u32 clock) : + mbc_ram_device_base(mconfig, GB_ROM_LIEBAO, tag, owner, clock), + m_view_ram(*this, "ram"), + m_bank_high_set(0U) +{ +} + + +image_init_result liebao_device::load(std::string &message) +{ + // set up ROM and RAM + set_bank_bits_rom(9); + set_bank_bits_ram(4); + if (!check_rom(message) || !check_ram(message)) + return image_init_result::FAIL; + cart_space()->install_view(0xa000, 0xbfff, m_view_ram); + install_rom(*cart_space(), *cart_space(), *cart_space()); + install_ram(m_view_ram[0]); + + // install handlers + cart_space()->install_write_handler( + 0x0000, 0x1fff, + write8sm_delegate(*this, FUNC(liebao_device::enable_ram))); + cart_space()->install_write_handler( + 0x2000, 0x2fff, + write8sm_delegate(*this, FUNC(liebao_device::bank_switch_rom))); + cart_space()->install_write_handler( + 0x4000, 0x5fff, + write8smo_delegate(*this, FUNC(liebao_device::bank_switch_ram))); + cart_space()->install_write_handler( + 0x7000, 0x7fff, + write8sm_delegate(*this, FUNC(liebao_device::bank_switch_rom_high))); + + // all good + return image_init_result::PASS; +} + + +void liebao_device::device_start() +{ + mbc_ram_device_base::device_start(); + + save_item(NAME(m_bank_high_set)); +} + + +void liebao_device::device_reset() +{ + mbc_ram_device_base::device_reset(); + + m_view_ram.disable(); + m_bank_high_set = 0U; + + set_bank_rom_low(2); + set_bank_rom_high(3); + set_bank_ram(0); +} + + +void liebao_device::enable_ram(offs_t offset, u8 data) +{ + // TODO: how many bits are checked? + bool const enable = 0x0a == (data & 0x0f); + LOG( + "%s: Cartridge RAM %s\n", + machine().describe_context(), + enable ? "enabled" : "disabled"); + if (enable) + m_view_ram.select(0); + else + m_view_ram.disable(); +} + + +void liebao_device::bank_switch_rom(offs_t offset, u8 data) +{ + set_bank_rom_low(u16(data) << 1); + if (m_bank_high_set || ((offset & 0x00ff) == 0x00d2)) + m_bank_high_set = 0U; + else + set_bank_rom_high((u16(data) << 1) | 0x01); +} + + +void liebao_device::bank_switch_ram(u8 data) +{ + set_bank_ram(data & 0x0f); +} + + +void liebao_device::bank_switch_rom_high(offs_t offset, u8 data) +{ + if ((offset & 0x00ff) == 0x00d2) + { + m_bank_high_set = 1U; + set_bank_rom_high((u16(data) << 1) | 0x01); + } +} + +} // anonymous namespace + +} // namespace bus::gameboy + + +DEFINE_DEVICE_TYPE_PRIVATE(GB_ROM_LIEBAO, device_gb_cart_interface, bus::gameboy::liebao_device, "gb_rom_liebao", "Game Boy Liebao Technology Cartridge") diff --git a/src/devices/bus/gameboy/liebao.h b/src/devices/bus/gameboy/liebao.h new file mode 100644 index 00000000000..ba1c67f25a4 --- /dev/null +++ b/src/devices/bus/gameboy/liebao.h @@ -0,0 +1,18 @@ +// license:BSD-3-Clause +// copyright-holders:Vas Crabb +/*************************************************************************** + + Memory controller used by Liebao Technology + + ***************************************************************************/ +#ifndef MAME_BUS_GAMEBOY_LIEBAO_H +#define MAME_BUS_GAMEBOY_LIEBAO_H + +#pragma once + +#include "slot.h" + + +DECLARE_DEVICE_TYPE(GB_ROM_LIEBAO, device_gb_cart_interface) + +#endif // MAME_BUS_GAMEBOY_LIEBAO_H -- cgit v1.2.3