summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author MooglyGuy <MooglyGuy@users.noreply.github.com>2021-03-24 16:52:02 +0100
committer GitHub <noreply@github.com>2021-03-25 02:52:02 +1100
commitfe4b519b23a2783ec62a2b4608ba5f5577a95cc9 (patch)
tree68da4f4a1cee48c122a79a8343e95389d92154ab
parentd0262f7f7de5c0b15e5ad1531274583be72e1d5d (diff)
bus/megadrive: Improved Sonic & Knuckles "lock on" slot handling. [Ryan Holtz]
* Fixed saving in Sonic 3 & Knuckles. * Made all MD cartridge types able to be locked on.
-rw-r--r--src/devices/bus/megadrive/sk.cpp60
-rw-r--r--src/devices/bus/megadrive/sk.h4
2 files changed, 49 insertions, 15 deletions
diff --git a/src/devices/bus/megadrive/sk.cpp b/src/devices/bus/megadrive/sk.cpp
index 02cf46b0151..5e0a970c320 100644
--- a/src/devices/bus/megadrive/sk.cpp
+++ b/src/devices/bus/megadrive/sk.cpp
@@ -5,19 +5,15 @@
Sonic & Knuckles pass-thorugh cart emulation
-
- TODO: currently we only support loading of base carts with no bankswitch or protection...
- shall we support other as well?
+ TODO: This could potentially make use of memory views. Investigate.
***********************************************************************************************************/
-
-
-
#include "emu.h"
#include "sk.h"
#include "rom.h"
+#include "md_carts.h"
//-------------------------------------------------
@@ -31,6 +27,7 @@ md_rom_sk_device::md_rom_sk_device(const machine_config &mconfig, device_type ty
: device_t(mconfig, type, tag, owner, clock)
, device_md_cart_interface(mconfig, *this)
, m_exp(*this, "subslot")
+ , m_map_upper(false)
{
}
@@ -42,16 +39,33 @@ md_rom_sk_device::md_rom_sk_device(const machine_config &mconfig, const char *ta
void md_rom_sk_device::device_start()
{
+ save_item(NAME(m_map_upper));
}
+
+void md_rom_sk_device::device_reset()
+{
+ m_map_upper = false;
+}
+
+
/*-------------------------------------------------
mapper specific handlers
-------------------------------------------------*/
uint16_t md_rom_sk_device::read(offs_t offset)
{
- if (m_exp->m_cart != nullptr && m_exp->m_cart->get_rom_base() != nullptr && offset >= 0x200000/2 && offset < (0x200000 + m_exp->m_cart->get_rom_size())/2)
- return m_exp->m_cart->m_rom[offset - 0x200000/2];
+ if (m_map_upper)
+ {
+ if (offset >= 0x300000/2)
+ return m_rom[MD_ADDR(offset)]; // Sonic 2 patch ROM
+ else if (m_exp->m_cart != nullptr && m_exp->m_cart->get_rom_base() != nullptr && offset >= 0x200000/2)
+ return m_exp->m_cart->read(offset); // Sonic 3 ROM pass-through or FRAM
+ }
+
+ if (m_exp->m_cart != nullptr && m_exp->m_cart->get_rom_base() != nullptr && offset >= 0x200000/2)
+ return m_exp->m_cart->read(offset - 0x200000/2);
+
if (offset < 0x400000/2)
return m_rom[MD_ADDR(offset)];
else
@@ -60,18 +74,34 @@ uint16_t md_rom_sk_device::read(offs_t offset)
void md_rom_sk_device::write(offs_t offset, uint16_t data, uint16_t mem_mask)
{
- // TODO: implement pass-through NVRAM accessing for Sonic 3 cart, for Sonic 3 & Knuckles saving feature
+ if (m_exp->m_cart == nullptr || m_exp->m_cart->get_rom_base() == nullptr)
+ return;
+
+ if (m_map_upper)
+ m_exp->m_cart->write(offset, data, mem_mask);
+ else if (offset >= 0x200000/2)
+ m_exp->m_cart->write(offset - 0x200000/2, data, mem_mask);
+}
+
+uint16_t md_rom_sk_device::read_a13(offs_t offset)
+{
+ if (m_exp->m_cart != nullptr && m_exp->m_cart->get_rom_base() != nullptr)
+ return m_exp->m_cart->read_a13(offset);
+ return 0xffff;
}
+void md_rom_sk_device::write_a13(offs_t offset, uint16_t data)
+{
+ if (m_exp->m_cart != nullptr && m_exp->m_cart->get_rom_base() != nullptr)
+ m_exp->m_cart->write_a13(offset, data);
+ if (offset == 0xf0/2)
+ m_map_upper = BIT(data, 0);
+}
static void sk_sub_cart(device_slot_interface &device)
{
- device.option_add_internal("rom", MD_STD_ROM);
- device.option_add_internal("rom_svp", MD_STD_ROM);
- device.option_add_internal("rom_sram", MD_ROM_SRAM);
- device.option_add_internal("rom_sramsafe", MD_ROM_SRAM);
- device.option_add_internal("rom_fram", MD_ROM_FRAM);
-// add all types??
+ // Inherit all cartridge types; cartridges <= 2 megabytes in size are mirrored into the upper 2 megabytes by the Sonic & Knuckles cartridge.
+ md_cart(device);
}
diff --git a/src/devices/bus/megadrive/sk.h b/src/devices/bus/megadrive/sk.h
index cd297c41a7f..c51abce9430 100644
--- a/src/devices/bus/megadrive/sk.h
+++ b/src/devices/bus/megadrive/sk.h
@@ -21,6 +21,7 @@ protected:
md_rom_sk_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock);
virtual void device_start() override;
+ virtual void device_reset() override;
// device-level overrides
virtual void device_add_mconfig(machine_config &config) override;
@@ -28,9 +29,12 @@ protected:
// reading and writing
virtual uint16_t read(offs_t offset) override;
virtual void write(offs_t offset, uint16_t data, uint16_t mem_mask = ~0) override;
+ virtual uint16_t read_a13(offs_t offset) override;
+ virtual void write_a13(offs_t offset, uint16_t data) override;
private:
required_device<md_cart_slot_device> m_exp;
+ bool m_map_upper;
};