diff options
Diffstat (limited to 'src/devices/bus/megadrive/jcart.cpp')
-rw-r--r-- | src/devices/bus/megadrive/jcart.cpp | 148 |
1 files changed, 59 insertions, 89 deletions
diff --git a/src/devices/bus/megadrive/jcart.cpp b/src/devices/bus/megadrive/jcart.cpp index 76f38ff0dd3..d8cad677e52 100644 --- a/src/devices/bus/megadrive/jcart.cpp +++ b/src/devices/bus/megadrive/jcart.cpp @@ -3,25 +3,20 @@ /*********************************************************************************************************** - MegaDrive / Genesis J-Cart (+SEPROM) emulation + MegaDrive / Genesis J-Cart + I2C EEPROM emulation - Emulation based on earlier researches by ElBarto + Emulation based on earlier research by ElBarto and Eke-Eke - i2c games mapping table: + I2C games mapping table: - game name | SDA_IN | SDA_OUT | SCL | SIZE_MASK | PAGE_MASK | - ----------------------------------|------------|------------|------------|----------------|-----------| - Micro Machines 2 | 0x380001-7 | 0x300000-0*| 0x300000-1*| 0x03ff (24C08) | 0x0f | - Micro Machines Military | 0x380001-7 | 0x300000-0*| 0x300000-1*| 0x03ff (24C08) | 0x0f | - Micro Machines 96 | 0x380001-7 | 0x300000-0*| 0x300000-1*| 0x07ff (24C16) | 0x0f | - ----------------------------------|------------|------------|------------|----------------|-----------| - - * Notes: check these - - - TODO: proper SEPROM emulation, still not worked on (just hooked up the I2C device) + Game Name | SDA_IN | SDA_OUT | SCL | SIZE_MASK | PAGE_MASK | WORKS | + ----------------------------------|------------|------------|------------|----------------|-----------|-------| + Micro Machines 2 | 0x380001-7 | 0x300000-0*| 0x300000-1*| 0x03ff (24C08) | 0x0f | Yes | + Micro Machines Military | 0x380001-7 | 0x300000-0*| 0x300000-1*| 0x03ff (24C08) | 0x0f | Yes | + Micro Machines 96 | 0x380001-7 | 0x300000-0*| 0x300000-1*| 0x07ff (24C16) | 0x0f | Yes | + ----------------------------------|------------|------------|------------|----------------|-----------|-------| ***********************************************************************************************************/ @@ -30,6 +25,8 @@ #include "emu.h" #include "jcart.h" +#include "bus/sms_ctrl/controllers.h" + //------------------------------------------------- // md_rom_device - constructor @@ -43,8 +40,7 @@ DEFINE_DEVICE_TYPE(MD_SEPROM_MM96, md_seprom_mm96_device, "md_seprom_mm9 md_jcart_device::md_jcart_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock) : device_t(mconfig, type, tag, owner, clock) , device_md_cart_interface(mconfig, *this) - , m_jcart3(*this, "JCART3") - , m_jcart4(*this, "JCART4") + , m_ctrl_ports(*this, "control%u", 3U) { } @@ -81,60 +77,52 @@ md_seprom_mm96_device::md_seprom_mm96_device(const machine_config &mconfig, cons // device_add_mconfig - add device configuration //------------------------------------------------- +void md_jcart_device::device_add_mconfig(machine_config &config) +{ + SMS_CONTROL_PORT(config, m_ctrl_ports[0], sms_control_port_devices, SMS_CTRL_OPTION_MD_PAD); + m_ctrl_ports[0]->th_handler().set(FUNC(md_jcart_device::th_in<0>)); + + SMS_CONTROL_PORT(config, m_ctrl_ports[1], sms_control_port_devices, SMS_CTRL_OPTION_MD_PAD); + m_ctrl_ports[1]->th_handler().set(FUNC(md_jcart_device::th_in<1>)); +} + void md_seprom_codemast_device::device_add_mconfig(machine_config &config) { + md_jcart_device::device_add_mconfig(config); + I2C_24C08(config, m_i2cmem); } void md_seprom_mm96_device::device_add_mconfig(machine_config &config) { - I2C_24C16A(config, m_i2cmem); -} - - -static INPUT_PORTS_START( jcart_ipt ) + md_jcart_device::device_add_mconfig(config); - PORT_START("JCART3") /* Joypad 3 on J-Cart (3 button + start) */ - PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_PLAYER(3) - PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_PLAYER(3) - PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_PLAYER(3) - PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_PLAYER(3) - PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(3) PORT_NAME("P3 B") - PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(3) PORT_NAME("P3 C") - PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(3) PORT_NAME("P3 A") - PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_START ) PORT_PLAYER(3) - - PORT_START("JCART4") /* Joypad 4 on J-Cart (3 button + start) */ - PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_PLAYER(4) - PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_PLAYER(4) - PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_PLAYER(4) - PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_PLAYER(4) - PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(4) PORT_NAME("P4 B") - PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(4) PORT_NAME("P4 C") - PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(4) PORT_NAME("P4 A") - PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_START ) PORT_PLAYER(4) + I2C_24C16(config, m_i2cmem); // 24C16A +} -INPUT_PORTS_END -ioport_constructor md_jcart_device::device_input_ports() const +void md_jcart_device::device_resolve_objects() { - return INPUT_PORTS_NAME( jcart_ipt ); + m_th_in[0] = m_th_in[1] = 0x40; + m_th_out = 0x40; } void md_jcart_device::device_start() { - save_item(NAME(m_jcart_io_data)); + save_item(NAME(m_th_in)); + save_item(NAME(m_th_out)); } void md_jcart_device::device_reset() { - m_jcart_io_data[0] = 0; - m_jcart_io_data[1] = 0; + // TODO: does this cause the TH outputs to reset to high? } void md_seprom_codemast_device::device_start() { + md_jcart_device::device_start(); + save_item(NAME(m_i2c_mem)); save_item(NAME(m_i2c_clk)); save_item(NAME(m_jcart_io_data)); @@ -142,6 +130,8 @@ void md_seprom_codemast_device::device_start() void md_seprom_codemast_device::device_reset() { + md_jcart_device::device_reset(); + m_i2c_mem = 0; m_i2c_clk = 0; m_jcart_io_data[0] = 0; @@ -157,24 +147,13 @@ void md_seprom_codemast_device::device_reset() J-CART ONLY (Pete Sampras Tennis) -------------------------------------------------*/ -READ16_MEMBER(md_jcart_device::read) +uint16_t md_jcart_device::read(offs_t offset) { if (offset == 0x38fffe/2) { - uint8_t joy[2]; - - if (m_jcart_io_data[0] & 0x40) - { - joy[0] = m_jcart3.read_safe(0); - joy[1] = m_jcart4.read_safe(0); - return (m_jcart_io_data[0] & 0x40) | joy[0] | (joy[1] << 8); - } - else - { - joy[0] = ((m_jcart3.read_safe(0) & 0xc0) >> 2) | (m_jcart3.read_safe(0) & 0x03); - joy[1] = ((m_jcart4.read_safe(0) & 0xc0) >> 2) | (m_jcart4.read_safe(0) & 0x03); - return (m_jcart_io_data[0] & 0x40) | joy[0] | (joy[1] << 8); - } + uint16_t const ctrl3 = (m_ctrl_ports[0]->in_r() & 0x3f) | (m_th_in[0] & m_th_out) | 0x80; + uint16_t const ctrl4 = (m_ctrl_ports[1]->in_r() & 0x3f) | (m_th_in[1] & m_th_out) | 0x80; + return ctrl3 | (ctrl4 << 8); } if (offset < 0x400000/2) return m_rom[MD_ADDR(offset)]; @@ -182,61 +161,52 @@ READ16_MEMBER(md_jcart_device::read) return 0xffff; } -WRITE16_MEMBER(md_jcart_device::write) +void md_jcart_device::write(offs_t offset, uint16_t data, uint16_t mem_mask) { if (offset == 0x38fffe/2) { - m_jcart_io_data[0] = (data & 1) << 6; - m_jcart_io_data[1] = (data & 1) << 6; + // assume TH only actively driven low + m_th_out = BIT(data, 0) << 6; + m_ctrl_ports[0]->out_w(m_th_out | 0x3f, ~m_th_out & 0x40); + m_ctrl_ports[1]->out_w(m_th_out | 0x3f, ~m_th_out & 0x40); } } +template <unsigned N> +void md_jcart_device::th_in(int state) +{ + m_th_in[N] = state ? 0x40 : 0x00; +} + + /*------------------------------------------------- J-CART + SEPROM -------------------------------------------------*/ -READ16_MEMBER(md_seprom_codemast_device::read) +uint16_t md_seprom_codemast_device::read(offs_t offset) { if (offset == 0x380000/2) { m_i2c_mem = m_i2cmem->read_sda(); return (m_i2c_mem & 1) << 7; } - if (offset == 0x38fffe/2) + else { - uint8_t joy[2]; - - if (m_jcart_io_data[0] & 0x40) - { - joy[0] = m_jcart3.read_safe(0); - joy[1] = m_jcart4.read_safe(0); - return (m_jcart_io_data[0] & 0x40) | joy[0] | (joy[1] << 8); - } - else - { - joy[0] = ((m_jcart3.read_safe(0) & 0xc0) >> 2) | (m_jcart3.read_safe(0) & 0x03); - joy[1] = ((m_jcart4.read_safe(0) & 0xc0) >> 2) | (m_jcart4.read_safe(0) & 0x03); - return (m_jcart_io_data[0] & 0x40) | joy[0] | (joy[1] << 8); - } + return md_jcart_device::read(offset); } - if (offset < 0x400000/2) - return m_rom[MD_ADDR(offset)]; - else - return 0xffff; } -WRITE16_MEMBER(md_seprom_codemast_device::write) +void md_seprom_codemast_device::write(offs_t offset, uint16_t data, uint16_t mem_mask) { - if (offset == 0x380000/2) + if (offset == 0x300000/2) { m_i2c_clk = BIT(data, 9); m_i2c_mem = BIT(data, 8); m_i2cmem->write_scl(m_i2c_clk); m_i2cmem->write_sda(m_i2c_mem); } - if (offset == 0x38fffe/2) + else { - m_jcart_io_data[0] = (data & 1) << 6; - m_jcart_io_data[1] = (data & 1) << 6; + md_jcart_device::write(offset, data, mem_mask); } } |