From 689aeea1ab1662f784061cb74dbde24187785de2 Mon Sep 17 00:00:00 2001 From: hap Date: Wed, 14 Sep 2022 13:43:51 +0200 Subject: msx holy_quran: small cleanup --- src/devices/bus/msx_cart/easi_speech.cpp | 10 +++- src/devices/bus/msx_cart/holy_quran.cpp | 97 +++++++++++++------------------- src/devices/bus/msx_cart/holy_quran.h | 2 +- 3 files changed, 47 insertions(+), 62 deletions(-) diff --git a/src/devices/bus/msx_cart/easi_speech.cpp b/src/devices/bus/msx_cart/easi_speech.cpp index 893a7c175e9..0a9d2d5551d 100644 --- a/src/devices/bus/msx_cart/easi_speech.cpp +++ b/src/devices/bus/msx_cart/easi_speech.cpp @@ -42,9 +42,12 @@ void msx_cart_easispeech_device::device_add_mconfig(machine_config &config) uint8_t msx_cart_easispeech_device::read_cart(offs_t offset) { - if (offset >= 0x4000 && offset < 0x6000) + // standard ROM + if (offset >= 0x4000 && offset < 0x8000) return get_rom_base()[offset & 0x1fff]; - if (offset >= 0x8000 && offset < 0xa000) + + // d7: SP0256 LRQ + if (offset == 0x8000) return m_speech->lrq_r() << 7; return 0xff; @@ -52,6 +55,7 @@ uint8_t msx_cart_easispeech_device::read_cart(offs_t offset) void msx_cart_easispeech_device::write_cart(offs_t offset, uint8_t data) { - if (offset >= 0x8000 && offset < 0xa000) + // d2-d7: SP0256 A + if (offset == 0x8000) m_speech->ald_w(bitswap<6>(data,3,5,7,6,4,2)); } diff --git a/src/devices/bus/msx_cart/holy_quran.cpp b/src/devices/bus/msx_cart/holy_quran.cpp index 046ed194502..fbfb799fad5 100644 --- a/src/devices/bus/msx_cart/holy_quran.cpp +++ b/src/devices/bus/msx_cart/holy_quran.cpp @@ -1,5 +1,14 @@ // license:BSD-3-Clause // copyright-holders:Wilbert Pol +/****************************************************************************** + +Al-Alamiah Al-Qur'an Al-Karim +Only works on Arabian MSXes. + +GCMK-16X PCB, 2 ROM chips, Yamaha XE297A0 mapper chip. + +******************************************************************************/ + #include "emu.h" #include "holy_quran.h" @@ -10,53 +19,25 @@ DEFINE_DEVICE_TYPE(MSX_CART_HOLY_QURAN, msx_cart_holy_quran_device, "msx_cart_ho msx_cart_holy_quran_device::msx_cart_holy_quran_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) : device_t(mconfig, MSX_CART_HOLY_QURAN, tag, owner, clock) , msx_cart_interface(mconfig, *this) - , m_selected_bank{ 0, 0, 0, 0 } - , m_bank_base{ nullptr, nullptr, nullptr, nullptr } - , m_decrypt(false) { - /* protection uses a simple rotation on databus, some lines inverted: - D0 D4 D4 D5 - D1 ~ D3 D5 ~ D2 - D2 ~ D6 D6 D7 - D3 ~ D0 D7 D1 */ - for (int i=0; i < 0x100; i++) - { - m_lookup_prot[i] = (((i << 4) & 0x50) | ((i >> 3) & 5) | ((i << 1) & 0xa0) | ((i << 2) & 8) | ((i >> 6) & 2)) ^ 0x4d; - } } - void msx_cart_holy_quran_device::device_start() { + // zerofill + m_decrypt = false; + std::fill_n(&m_selected_bank[0], 4, 0); + std::fill_n(&m_bank_base[0], 4, nullptr); + + // register for savestates save_item(NAME(m_selected_bank)); save_item(NAME(m_decrypt)); -} - -void msx_cart_holy_quran_device::device_post_load() -{ - restore_banks(); + // protection uses a simple rotation on databus, some lines inverted + for (int i = 0; i < 0x100; i++) + m_lookup_prot[i] = bitswap<8>(i,6,2,4,0,1,5,7,3) ^ 0x4d; } - -void msx_cart_holy_quran_device::restore_banks() -{ - m_bank_base[0] = get_rom_base() + (m_selected_bank[0] & 0x7f) * 0x2000; - m_bank_base[1] = get_rom_base() + (m_selected_bank[1] & 0x7f) * 0x2000; - m_bank_base[2] = get_rom_base() + (m_selected_bank[2] & 0x7f) * 0x2000; - m_bank_base[3] = get_rom_base() + (m_selected_bank[3] & 0x7f) * 0x2000; -} - - -void msx_cart_holy_quran_device::device_reset() -{ - for (auto & elem : m_selected_bank) - { - elem = 0; - } -} - - void msx_cart_holy_quran_device::initialize_cartridge() { if (get_rom_size() != 0x100000) @@ -67,6 +48,22 @@ void msx_cart_holy_quran_device::initialize_cartridge() restore_banks(); } +void msx_cart_holy_quran_device::device_reset() +{ + m_decrypt = false; + + std::fill_n(&m_selected_bank[0], 4, 0); + restore_banks(); +} + +void msx_cart_holy_quran_device::restore_banks() +{ + for (int i = 0; i < 4; i++) + m_bank_base[i] = get_rom_base() + (m_selected_bank[i] & 0x7f) * 0x2000; +} + + +// mapper interface uint8_t msx_cart_holy_quran_device::read_cart(offs_t offset) { @@ -75,43 +72,27 @@ uint8_t msx_cart_holy_quran_device::read_cart(offs_t offset) uint8_t data = m_bank_base[(offset - 0x4000) >> 13][offset & 0x1fff]; if (m_decrypt) - { return m_lookup_prot[data]; - } - // The decryption should actually start working after the first M1 cycle executing something - // from the cartridge. + // The decryption should actually start working after the first M1 cycle executing something from the cartridge. if (offset == ((m_rom[3] << 8) | m_rom[2]) && !machine().side_effects_disabled()) - { m_decrypt = true; - } return data; } + return 0xff; } - void msx_cart_holy_quran_device::write_cart(offs_t offset, uint8_t data) { switch (offset) { - case 0x5000: - m_selected_bank[0] = data; - restore_banks(); - break; - case 0x5400: - m_selected_bank[1] = data; - restore_banks(); - break; - case 0x5800: - m_selected_bank[2] = data; - restore_banks(); - break; - case 0x5c00: - m_selected_bank[3] = data; + case 0x5000: case 0x5400: case 0x5800: case 0x5c00: + m_selected_bank[offset >> 10 & 3] = data; restore_banks(); break; + default: logerror("msx_cart_holy_quran_device: unhandled write %02x to %04x\n", data, offset); break; diff --git a/src/devices/bus/msx_cart/holy_quran.h b/src/devices/bus/msx_cart/holy_quran.h index 8d63a8271d9..25b1ddf8f50 100644 --- a/src/devices/bus/msx_cart/holy_quran.h +++ b/src/devices/bus/msx_cart/holy_quran.h @@ -25,7 +25,7 @@ protected: // device-level overrides virtual void device_start() override; virtual void device_reset() override; - virtual void device_post_load() override; + virtual void device_post_load() override { restore_banks(); } void restore_banks(); -- cgit v1.2.3