diff --git a/.gitattributes b/.gitattributes index 495c43cba21..40f7939fb7b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1001,6 +1001,8 @@ src/emu/bus/msx_cart/fmpac.c svneol=native#text/plain src/emu/bus/msx_cart/fmpac.h svneol=native#text/plain src/emu/bus/msx_cart/hfox.c svneol=native#text/plain src/emu/bus/msx_cart/hfox.h svneol=native#text/plain +src/emu/bus/msx_cart/holy_quran.c svneol=native#text/plain +src/emu/bus/msx_cart/holy_quran.h svneol=native#text/plain src/emu/bus/msx_cart/konami.c svneol=native#text/plain src/emu/bus/msx_cart/konami.h svneol=native#text/plain src/emu/bus/msx_cart/korean.c svneol=native#text/plain diff --git a/hash/msx1_cart.xml b/hash/msx1_cart.xml index 308d9a5538d..c651ad8f89e 100644 --- a/hash/msx1_cart.xml +++ b/hash/msx1_cart.xml @@ -15242,18 +15242,17 @@ legacy FM implementations cannot find it. - - + The Holy Quran 1987 Al Alamiah - - + - + + diff --git a/src/emu/bus/bus.mak b/src/emu/bus/bus.mak index 284d034d31a..f78f71be838 100644 --- a/src/emu/bus/bus.mak +++ b/src/emu/bus/bus.mak @@ -412,6 +412,7 @@ BUSOBJS += $(BUSOBJ)/msx_cart/cartridge.o BUSOBJS += $(BUSOBJ)/msx_cart/crossblaim.o BUSOBJS += $(BUSOBJ)/msx_cart/fmpac.o BUSOBJS += $(BUSOBJ)/msx_cart/hfox.o +BUSOBJS += $(BUSOBJ)/msx_cart/holy_quran.o BUSOBJS += $(BUSOBJ)/msx_cart/konami.o BUSOBJS += $(BUSOBJ)/msx_cart/korean.o BUSOBJS += $(BUSOBJ)/msx_cart/majutsushi.o diff --git a/src/emu/bus/msx_cart/cartridge.c b/src/emu/bus/msx_cart/cartridge.c index 4ef5d178c7c..b9361f9cc2f 100644 --- a/src/emu/bus/msx_cart/cartridge.c +++ b/src/emu/bus/msx_cart/cartridge.c @@ -5,6 +5,7 @@ #include "crossblaim.h" #include "fmpac.h" #include "hfox.h" +#include "holy_quran.h" #include "konami.h" #include "korean.h" #include "majutsushi.h" @@ -45,6 +46,7 @@ SLOT_INTERFACE_START(msx_cart) SLOT_INTERFACE_INTERNAL("super_swangi", MSX_CART_SUPER_SWANGI) SLOT_INTERFACE_INTERNAL("hfox", MSX_CART_HFOX) SLOT_INTERFACE_INTERNAL("keyboard_master", MSX_CART_KEYBOARD_MASTER) + SLOT_INTERFACE_INTERNAL("holy_quran", MSX_CART_HOLY_QURAN) SLOT_INTERFACE_END diff --git a/src/emu/bus/msx_cart/holy_quran.c b/src/emu/bus/msx_cart/holy_quran.c new file mode 100644 index 00000000000..424cf3b5315 --- /dev/null +++ b/src/emu/bus/msx_cart/holy_quran.c @@ -0,0 +1,118 @@ +#include "emu.h" +#include "holy_quran.h" + + +const device_type MSX_CART_HOLY_QURAN = &device_creator; + + +msx_cart_holy_quran::msx_cart_holy_quran(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) + : device_t(mconfig, MSX_CART_HOLY_QURAN, "MSX Cartridge - Holy Quran", tag, owner, clock, "msx_cart_holy_quran", __FILE__) + , msx_cart_interface(mconfig, *this) + , m_decrypt(false) +{ + for (int i = 0; i < 4; i++) + { + m_selected_bank[i] = 0; + m_bank_base[i] = NULL; + } + + /* 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_start() +{ + save_item(NAME(m_selected_bank)); + save_item(NAME(m_decrypt)); + + machine().save().register_postload(save_prepost_delegate(FUNC(msx_cart_holy_quran::restore_banks), this)); +} + + +void msx_cart_holy_quran::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_reset() +{ + for (int i = 0; i < 4; i++) + { + m_selected_bank[i] = 0; + } +} + + +void msx_cart_holy_quran::initialize_cartridge() +{ + if (get_rom_size() != 0x100000) + { + fatalerror("holy_quran: Invalid ROM size\n"); + } + + restore_banks(); +} + + +READ8_MEMBER(msx_cart_holy_quran::read_cart) +{ + if (offset >= 0x4000 && offset < 0xc000) + { + UINT8 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. + if (offset == ((m_rom[3] << 8) | m_rom[2]) && !space.debugger_access()) + { + m_decrypt = true; + } + + return data; + } + return 0xff; +} + + +WRITE8_MEMBER(msx_cart_holy_quran::write_cart) +{ + 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; + restore_banks(); + break; + default: + logerror("msx_cart_holy_quran: unhandled write %02x to %04x\n", data, offset); + break; + } +} + diff --git a/src/emu/bus/msx_cart/holy_quran.h b/src/emu/bus/msx_cart/holy_quran.h new file mode 100644 index 00000000000..2a7fb0204d1 --- /dev/null +++ b/src/emu/bus/msx_cart/holy_quran.h @@ -0,0 +1,35 @@ +#ifndef __MSX_CART_HOLY_QURAN_H +#define __MSX_CART_HOLY_QURAN_H + +#include "bus/msx_cart/cartridge.h" + + +extern const device_type MSX_CART_HOLY_QURAN; + + +class msx_cart_holy_quran : public device_t + , public msx_cart_interface +{ +public: + msx_cart_holy_quran(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); + + // device-level overrides + virtual void device_start(); + virtual void device_reset(); + + virtual void initialize_cartridge(); + + virtual DECLARE_READ8_MEMBER(read_cart); + virtual DECLARE_WRITE8_MEMBER(write_cart); + + void restore_banks(); + +private: + UINT8 m_lookup_prot[256]; + UINT8 m_selected_bank[4]; + UINT8 *m_bank_base[4]; + bool m_decrypt; +}; + + +#endif