From 259703c38294efa01afc5eff94e64692e52ea841 Mon Sep 17 00:00:00 2001 From: DavidHaywood <28625134+DavidHaywood@users.noreply.github.com> Date: Mon, 29 Jul 2019 15:27:11 +0100 Subject: add a 'post opcode fetch' to spectrum expansion bus so that interface 1 enable / disables work correctly mimics behavior found in other emulators, stops nonsense commands from triggering nonsense save operations with interface1 installed which was caused by the rom banking out too early. --- src/devices/bus/spectrum/exp.cpp | 10 ++++++++++ src/devices/bus/spectrum/exp.h | 2 ++ src/devices/bus/spectrum/intf1.cpp | 17 +++++++++++++++++ src/devices/bus/spectrum/intf1.h | 1 + src/mame/drivers/spec128.cpp | 9 +++++++++ src/mame/drivers/spectrum.cpp | 10 +++++++--- 6 files changed, 46 insertions(+), 3 deletions(-) diff --git a/src/devices/bus/spectrum/exp.cpp b/src/devices/bus/spectrum/exp.cpp index 850b9f88384..51e19bbe2ac 100644 --- a/src/devices/bus/spectrum/exp.cpp +++ b/src/devices/bus/spectrum/exp.cpp @@ -107,6 +107,16 @@ void spectrum_expansion_slot_device::opcode_fetch(offs_t offset) m_card->opcode_fetch(offset); } +//------------------------------------------------- +// fetch_r +//------------------------------------------------- + +void spectrum_expansion_slot_device::opcode_fetch_post(offs_t offset) +{ + if (m_card) + m_card->opcode_fetch_post(offset); +} + //------------------------------------------------- // iorq_r //------------------------------------------------- diff --git a/src/devices/bus/spectrum/exp.h b/src/devices/bus/spectrum/exp.h index aee398d1ab4..71b95b2a213 100644 --- a/src/devices/bus/spectrum/exp.h +++ b/src/devices/bus/spectrum/exp.h @@ -74,6 +74,7 @@ public: auto nmi_handler() { return m_nmi_handler.bind(); } void opcode_fetch(offs_t offset); + void opcode_fetch_post(offs_t offset); uint8_t mreq_r(offs_t offset); void mreq_w(offs_t offset, uint8_t data); uint8_t iorq_r(offs_t offset); @@ -107,6 +108,7 @@ public: // reading and writing virtual void opcode_fetch(offs_t offset) { }; + virtual void opcode_fetch_post(offs_t offset) { }; virtual uint8_t mreq_r(offs_t offset) { return 0xff; } virtual void mreq_w(offs_t offset, uint8_t data) { } virtual uint8_t iorq_r(offs_t offset) { return 0xff; } diff --git a/src/devices/bus/spectrum/intf1.cpp b/src/devices/bus/spectrum/intf1.cpp index 344aaf61841..a5e1859e28a 100644 --- a/src/devices/bus/spectrum/intf1.cpp +++ b/src/devices/bus/spectrum/intf1.cpp @@ -106,6 +106,9 @@ READ_LINE_MEMBER(spectrum_intf1_device::romcs) return m_romcs | m_exp->romcs(); } +// the Interface 1 looks for specific bus conditions to enable / disable the expansion overlay ROM + +// the enable must occur BEFORE the opcode is fetched, as the opcode must be fetched from the expansion ROM void spectrum_intf1_device::opcode_fetch(offs_t offset) { m_exp->opcode_fetch(offset); @@ -117,6 +120,19 @@ void spectrum_intf1_device::opcode_fetch(offs_t offset) case 0x0008: case 0x1708: m_romcs = 1; break; + } + } +} + +// the disable must occur AFTER the opcode fetch, or the incorrect opcode is fetched for 0x0700 +void spectrum_intf1_device::opcode_fetch_post(offs_t offset) +{ + m_exp->opcode_fetch_post(offset); + + if (!machine().side_effects_disabled()) + { + switch (offset) + { case 0x0700: m_romcs = 0; break; @@ -124,6 +140,7 @@ void spectrum_intf1_device::opcode_fetch(offs_t offset) } } + uint8_t spectrum_intf1_device::mreq_r(offs_t offset) { uint8_t data = 0xff; diff --git a/src/devices/bus/spectrum/intf1.h b/src/devices/bus/spectrum/intf1.h index 6b0ddb32804..3a09ca74a0a 100644 --- a/src/devices/bus/spectrum/intf1.h +++ b/src/devices/bus/spectrum/intf1.h @@ -37,6 +37,7 @@ protected: virtual const tiny_rom_entry *device_rom_region() const override; virtual void opcode_fetch(offs_t offset) override; + virtual void opcode_fetch_post(offs_t offset) override; virtual uint8_t mreq_r(offs_t offset) override; virtual void mreq_w(offs_t offset, uint8_t data) override; virtual uint8_t iorq_r(offs_t offset) override; diff --git a/src/mame/drivers/spec128.cpp b/src/mame/drivers/spec128.cpp index b005bb8fae9..4f669d13c1b 100644 --- a/src/mame/drivers/spec128.cpp +++ b/src/mame/drivers/spec128.cpp @@ -169,7 +169,16 @@ READ8_MEMBER(spectrum_state::spectrum_128_opcode_fetch_r) { /* this allows expansion devices to act upon opcode fetches from MEM addresses */ if (BIT(m_port_7ffd_data, 4)) + { + /* this allows expansion devices to act upon opcode fetches from MEM addresses + for example, interface1 detection fetches requires fetches at 0008 / 0708 to + enable paged ROM and then fetches at 0700 to disable it + */ m_exp->opcode_fetch(offset); + uint8_t retval = m_maincpu->space(AS_PROGRAM).read_byte(offset); + m_exp->opcode_fetch_post(offset); + return retval; + } return m_maincpu->space(AS_PROGRAM).read_byte(offset); } diff --git a/src/mame/drivers/spectrum.cpp b/src/mame/drivers/spectrum.cpp index e8e193e63d1..951218cc422 100644 --- a/src/mame/drivers/spectrum.cpp +++ b/src/mame/drivers/spectrum.cpp @@ -293,10 +293,14 @@ SamRam READ8_MEMBER(spectrum_state::opcode_fetch_r) { - /* this allows expansion devices to act upon opcode fetches from MEM addresses */ + /* this allows expansion devices to act upon opcode fetches from MEM addresses + for example, interface1 detection fetches requires fetches at 0008 / 0708 to + enable paged ROM and then fetches at 0700 to disable it + */ m_exp->opcode_fetch(offset); - - return m_maincpu->space(AS_PROGRAM).read_byte(offset); + uint8_t retval = m_maincpu->space(AS_PROGRAM).read_byte(offset); + m_exp->opcode_fetch_post(offset); + return retval; } WRITE8_MEMBER(spectrum_state::spectrum_rom_w) -- cgit v1.2.3