trunk/src/emu/bus/msx_cart/holy_quran.c
| r0 | r30834 | |
| 1 | #include "emu.h" |
| 2 | #include "holy_quran.h" |
| 3 | |
| 4 | |
| 5 | const device_type MSX_CART_HOLY_QURAN = &device_creator<msx_cart_holy_quran>; |
| 6 | |
| 7 | |
| 8 | msx_cart_holy_quran::msx_cart_holy_quran(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 9 | : device_t(mconfig, MSX_CART_HOLY_QURAN, "MSX Cartridge - Holy Quran", tag, owner, clock, "msx_cart_holy_quran", __FILE__) |
| 10 | , msx_cart_interface(mconfig, *this) |
| 11 | , m_decrypt(false) |
| 12 | { |
| 13 | for (int i = 0; i < 4; i++) |
| 14 | { |
| 15 | m_selected_bank[i] = 0; |
| 16 | m_bank_base[i] = NULL; |
| 17 | } |
| 18 | |
| 19 | /* protection uses a simple rotation on databus, some lines inverted: |
| 20 | D0 D4 D4 D5 |
| 21 | D1 ~ D3 D5 ~ D2 |
| 22 | D2 ~ D6 D6 D7 |
| 23 | D3 ~ D0 D7 D1 */ |
| 24 | for (int i=0; i < 0x100; i++) |
| 25 | { |
| 26 | m_lookup_prot[i] = (((i << 4) & 0x50) | ((i >> 3) & 5) | ((i << 1) & 0xa0) | ((i << 2) & 8) | ((i >> 6) & 2)) ^ 0x4d; |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | |
| 31 | void msx_cart_holy_quran::device_start() |
| 32 | { |
| 33 | save_item(NAME(m_selected_bank)); |
| 34 | save_item(NAME(m_decrypt)); |
| 35 | |
| 36 | machine().save().register_postload(save_prepost_delegate(FUNC(msx_cart_holy_quran::restore_banks), this)); |
| 37 | } |
| 38 | |
| 39 | |
| 40 | void msx_cart_holy_quran::restore_banks() |
| 41 | { |
| 42 | m_bank_base[0] = get_rom_base() + (m_selected_bank[0] & 0x7f) * 0x2000; |
| 43 | m_bank_base[1] = get_rom_base() + (m_selected_bank[1] & 0x7f) * 0x2000; |
| 44 | m_bank_base[2] = get_rom_base() + (m_selected_bank[2] & 0x7f) * 0x2000; |
| 45 | m_bank_base[3] = get_rom_base() + (m_selected_bank[3] & 0x7f) * 0x2000; |
| 46 | } |
| 47 | |
| 48 | |
| 49 | void msx_cart_holy_quran::device_reset() |
| 50 | { |
| 51 | for (int i = 0; i < 4; i++) |
| 52 | { |
| 53 | m_selected_bank[i] = 0; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | |
| 58 | void msx_cart_holy_quran::initialize_cartridge() |
| 59 | { |
| 60 | if (get_rom_size() != 0x100000) |
| 61 | { |
| 62 | fatalerror("holy_quran: Invalid ROM size\n"); |
| 63 | } |
| 64 | |
| 65 | restore_banks(); |
| 66 | } |
| 67 | |
| 68 | |
| 69 | READ8_MEMBER(msx_cart_holy_quran::read_cart) |
| 70 | { |
| 71 | if (offset >= 0x4000 && offset < 0xc000) |
| 72 | { |
| 73 | UINT8 data = m_bank_base[(offset - 0x4000) >> 13][offset & 0x1fff]; |
| 74 | |
| 75 | if (m_decrypt) |
| 76 | { |
| 77 | return m_lookup_prot[data]; |
| 78 | } |
| 79 | |
| 80 | // The decryption should actually start working after the first M1 cycle executing something |
| 81 | // from the cartridge. |
| 82 | if (offset == ((m_rom[3] << 8) | m_rom[2]) && !space.debugger_access()) |
| 83 | { |
| 84 | m_decrypt = true; |
| 85 | } |
| 86 | |
| 87 | return data; |
| 88 | } |
| 89 | return 0xff; |
| 90 | } |
| 91 | |
| 92 | |
| 93 | WRITE8_MEMBER(msx_cart_holy_quran::write_cart) |
| 94 | { |
| 95 | switch (offset) |
| 96 | { |
| 97 | case 0x5000: |
| 98 | m_selected_bank[0] = data; |
| 99 | restore_banks(); |
| 100 | break; |
| 101 | case 0x5400: |
| 102 | m_selected_bank[1] = data; |
| 103 | restore_banks(); |
| 104 | break; |
| 105 | case 0x5800: |
| 106 | m_selected_bank[2] = data; |
| 107 | restore_banks(); |
| 108 | break; |
| 109 | case 0x5c00: |
| 110 | m_selected_bank[3] = data; |
| 111 | restore_banks(); |
| 112 | break; |
| 113 | default: |
| 114 | logerror("msx_cart_holy_quran: unhandled write %02x to %04x\n", data, offset); |
| 115 | break; |
| 116 | } |
| 117 | } |
| 118 | |
trunk/src/emu/bus/msx_cart/holy_quran.h
| r0 | r30834 | |
| 1 | #ifndef __MSX_CART_HOLY_QURAN_H |
| 2 | #define __MSX_CART_HOLY_QURAN_H |
| 3 | |
| 4 | #include "bus/msx_cart/cartridge.h" |
| 5 | |
| 6 | |
| 7 | extern const device_type MSX_CART_HOLY_QURAN; |
| 8 | |
| 9 | |
| 10 | class msx_cart_holy_quran : public device_t |
| 11 | , public msx_cart_interface |
| 12 | { |
| 13 | public: |
| 14 | msx_cart_holy_quran(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); |
| 15 | |
| 16 | // device-level overrides |
| 17 | virtual void device_start(); |
| 18 | virtual void device_reset(); |
| 19 | |
| 20 | virtual void initialize_cartridge(); |
| 21 | |
| 22 | virtual DECLARE_READ8_MEMBER(read_cart); |
| 23 | virtual DECLARE_WRITE8_MEMBER(write_cart); |
| 24 | |
| 25 | void restore_banks(); |
| 26 | |
| 27 | private: |
| 28 | UINT8 m_lookup_prot[256]; |
| 29 | UINT8 m_selected_bank[4]; |
| 30 | UINT8 *m_bank_base[4]; |
| 31 | bool m_decrypt; |
| 32 | }; |
| 33 | |
| 34 | |
| 35 | #endif |
trunk/hash/msx1_cart.xml
| r30833 | r30834 | |
| 15242 | 15242 | </part> |
| 15243 | 15243 | </software> |
| 15244 | 15244 | |
| 15245 | | <!-- FIXME: proper HOLYQURAN mapper needs to be implemented! --> |
| 15246 | | <software name="quran" supported="no"> |
| 15245 | <software name="quran"> |
| 15247 | 15246 | <description>The Holy Quran</description> |
| 15248 | 15247 | <year>1987</year> |
| 15249 | 15248 | <publisher>Al Alamiah</publisher> |
| 15250 | 15249 | <info name="serial" value="R052" /> |
| 15251 | 15250 | <info name="usage" value="Requires an Arabic MSX" /> |
| 15252 | 15251 | <part name="cart" interface="msx_cart"> |
| 15253 | | <feature name="slot" value="ascii16" /> |
| 15254 | | <feature name="mapper" value="M60002-0125SP-16" /> <!-- WRONG MAPPER (but in this way no crash of the emulator) --> |
| 15252 | <feature name="slot" value="holy_quran" /> |
| 15255 | 15253 | <dataarea name="rom" size="1048576"> |
| 15256 | | <rom name="holyquran.rom" size="1048576" crc="83f28ad3" sha1="0dbc7defd96b71c1fe2d63cbc725f5e58aea2db0" offset="0x0000" /> |
| 15254 | <!-- there are 2 ROMs on the cartridge --> |
| 15255 | <rom name="holyquran.rom" size="1048576" crc="3b003e5c" sha1="7d439080b43d94385fd4c426d4f6fee884bc2926" status="baddump" offset="0x0000" /> |
| 15257 | 15256 | </dataarea> |
| 15258 | 15257 | </part> |
| 15259 | 15258 | </software> |