From 2ce018ae9c41d4967cda1182faadeaf5cc9ac8fc Mon Sep 17 00:00:00 2001 From: Ariane Fugmann Date: Tue, 21 Jun 2016 21:13:48 +0200 Subject: [PATCH 1/4] M2COMM: hook up comm board in model2 (W.I.P.) --- scripts/target/mame/arcade.lua | 2 ++ src/mame/drivers/model2.cpp | 14 +++++++++++++- src/mame/includes/model2.h | 3 +++ src/mame/machine/m2comm.cpp | 2 ++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/scripts/target/mame/arcade.lua b/scripts/target/mame/arcade.lua index b2d06ebc5b6..4ff951f8eea 100644 --- a/scripts/target/mame/arcade.lua +++ b/scripts/target/mame/arcade.lua @@ -3043,6 +3043,8 @@ files { MAME_DIR .. "src/mame/machine/s32comm.h", MAME_DIR .. "src/mame/machine/m1comm.cpp", MAME_DIR .. "src/mame/machine/m1comm.h", + MAME_DIR .. "src/mame/machine/m2comm.cpp", + MAME_DIR .. "src/mame/machine/m2comm.h", MAME_DIR .. "src/mame/audio/dsbz80.cpp", MAME_DIR .. "src/mame/audio/dsbz80.h", MAME_DIR .. "src/mame/drivers/model2.cpp", diff --git a/src/mame/drivers/model2.cpp b/src/mame/drivers/model2.cpp index f25666833f0..0755a89b557 100644 --- a/src/mame/drivers/model2.cpp +++ b/src/mame/drivers/model2.cpp @@ -1507,7 +1507,9 @@ static ADDRESS_MAP_START( model2_base_mem, AS_PROGRAM, 32, model2_state ) AM_RANGE(0x01800000, 0x01803fff) AM_READWRITE16(model2_palette_r,model2_palette_w,0xffffffff) AM_RANGE(0x01810000, 0x0181bfff) AM_RAM AM_SHARE("colorxlat") AM_RANGE(0x0181c000, 0x0181c003) AM_WRITE(model2_3d_zclip_w) - AM_RANGE(0x01a10000, 0x01a1ffff) AM_READWRITE(network_r, network_w) + AM_RANGE(0x01a10000, 0x01a13fff) AM_DEVREADWRITE8("m2comm", m2comm_device, share_r, share_w, 0xffffffff) + AM_RANGE(0x01a14000, 0x01a14003) AM_DEVREADWRITE8("m2comm", m2comm_device, cn_r, cn_w, 0x000000ff) + AM_RANGE(0x01a14000, 0x01a14003) AM_DEVREADWRITE8("m2comm", m2comm_device, fg_r, fg_w, 0x00ff0000) AM_RANGE(0x01d00000, 0x01d03fff) AM_RAM AM_SHARE("backup1") // Backup sram AM_RANGE(0x02000000, 0x03ffffff) AM_ROM AM_REGION("user1", 0) @@ -2229,6 +2231,8 @@ TIMER_DEVICE_CALLBACK_MEMBER(model2_state::model2_interrupt) if(m_intena & 1<<0) m_maincpu->set_input_line(I960_IRQ0, ASSERT_LINE); model2_check_irq_state(); + if (m_m2comm != nullptr) + m_m2comm->check_vint_irq(); } else if(scanline == 0) { @@ -2418,6 +2422,8 @@ static MACHINE_CONFIG_START( model2o, model2_state ) MCFG_VIDEO_START_OVERRIDE(model2_state,model2) MCFG_SEGAM1AUDIO_ADD("m1audio") + + MCFG_M2COMM_ADD("m2comm") MACHINE_CONFIG_END /* 2A-CRX */ @@ -2469,6 +2475,8 @@ static MACHINE_CONFIG_START( model2a, model2_state ) MCFG_SCSP_IRQ_CB(WRITE8(model2_state,scsp_irq)) MCFG_SOUND_ROUTE(0, "lspeaker", 2.0) MCFG_SOUND_ROUTE(0, "rspeaker", 2.0) + + MCFG_M2COMM_ADD("m2comm") MACHINE_CONFIG_END static MACHINE_CONFIG_DERIVED( manxttdx, model2a ) /* Includes a Model 1 Sound board for additional sounds - Deluxe version only */ @@ -2584,6 +2592,8 @@ static MACHINE_CONFIG_START( model2b, model2_state ) MCFG_SCSP_IRQ_CB(WRITE8(model2_state,scsp_irq)) MCFG_SOUND_ROUTE(0, "lspeaker", 2.0) MCFG_SOUND_ROUTE(0, "rspeaker", 2.0) + + MCFG_M2COMM_ADD("m2comm") MACHINE_CONFIG_END @@ -2647,6 +2657,8 @@ static MACHINE_CONFIG_START( model2c, model2_state ) MCFG_SCSP_IRQ_CB(WRITE8(model2_state, scsp_irq)) MCFG_SOUND_ROUTE(0, "lspeaker", 2.0) MCFG_SOUND_ROUTE(0, "rspeaker", 2.0) + + MCFG_M2COMM_ADD("m2comm") MACHINE_CONFIG_END static MACHINE_CONFIG_DERIVED( stcc, model2c ) diff --git a/src/mame/includes/model2.h b/src/mame/includes/model2.h index 1330c1245e2..f660ef419e1 100644 --- a/src/mame/includes/model2.h +++ b/src/mame/includes/model2.h @@ -8,6 +8,7 @@ #include "sound/scsp.h" #include "machine/315-5881_crypt.h" #include "machine/315-5838_317-0229_comp.h" +#include "machine/m2comm.h" class model2_renderer; struct raster_state; @@ -30,6 +31,7 @@ public: m_maincpu(*this,"maincpu"), m_dsbz80(*this, DSBZ80_TAG), m_m1audio(*this, "m1audio"), + m_m2comm(*this, "m2comm"), m_audiocpu(*this, "audiocpu"), m_tgp(*this, "tgp"), m_dsp(*this, "dsp"), @@ -58,6 +60,7 @@ public: required_device m_maincpu; optional_device m_dsbz80; // Z80-based MPEG Digital Sound Board optional_device m_m1audio; // Model 1 standard sound board + optional_device m_m2comm; // Model 2 communication board optional_device m_audiocpu; optional_device m_tgp; optional_device m_dsp; diff --git a/src/mame/machine/m2comm.cpp b/src/mame/machine/m2comm.cpp index 4c45669076c..a8afc14a773 100644 --- a/src/mame/machine/m2comm.cpp +++ b/src/mame/machine/m2comm.cpp @@ -163,6 +163,8 @@ Sega PC BD MODEL2 C-CRX COMMUNICATION 837-12839 18643A.7 Sega Touring Car Championship */ +#include "emu.h" +#include "emuopts.h" #include "machine/m2comm.h" //#define __M2COMM_VERBOSE__ From 3663ba7a25ad90963869bce298f76c1c063e1016 Mon Sep 17 00:00:00 2001 From: Ariane Fugmann Date: Wed, 22 Jun 2016 00:56:59 +0200 Subject: [PATCH 2/4] M2COMM: fix EPR-16726 node numbering --- src/mame/drivers/model2.cpp | 2 + src/mame/machine/m2comm.cpp | 79 +++++++++---------------------------- 2 files changed, 20 insertions(+), 61 deletions(-) diff --git a/src/mame/drivers/model2.cpp b/src/mame/drivers/model2.cpp index 0755a89b557..a553a4f8fe2 100644 --- a/src/mame/drivers/model2.cpp +++ b/src/mame/drivers/model2.cpp @@ -2254,6 +2254,8 @@ TIMER_DEVICE_CALLBACK_MEMBER(model2_state::model2c_interrupt) if(m_intena & 1<<0) m_maincpu->set_input_line(I960_IRQ0, ASSERT_LINE); model2_check_irq_state(); + if (m_m2comm != nullptr) + m_m2comm->check_vint_irq(); } else if(scanline == 0) // 384 { diff --git a/src/mame/machine/m2comm.cpp b/src/mame/machine/m2comm.cpp index a8afc14a773..fadbb698930 100644 --- a/src/mame/machine/m2comm.cpp +++ b/src/mame/machine/m2comm.cpp @@ -351,11 +351,9 @@ void m2comm_device::comm_tick_16726() { if (m_linkenable == 0x01) { - m_zfg ^= 1; - - int frameStart = 0x2000; - int frameOffset = 0x0000; - int frameSize = 0x01c0; + int frameTX = 0x2000; + int frameRX = 0x21c0; + int frameSize = 0x01c0 * 8; int dataSize = frameSize + 1; int togo = 0; int recv = 0; @@ -412,7 +410,6 @@ void m2comm_device::comm_tick_16726() else if (isSlave) { m_buffer[1]++; - m_linkid = m_buffer[1]; // forward message m_line_tx.write(m_buffer, dataSize); @@ -425,6 +422,8 @@ void m2comm_device::comm_tick_16726() if (isSlave) { m_linkcount = m_buffer[1]; + m_linkid = m_buffer[2]; + m_buffer[2]--; // forward message m_line_tx.write(m_buffer, dataSize); @@ -433,6 +432,7 @@ void m2comm_device::comm_tick_16726() // consider it done printf("M2COMM: link established - id %02x of %02x\n", m_linkid, m_linkcount); m_linkalive = 0x01; + m_linktimer = 0x01; // write to shared mem m_shared[0] = 0x01; @@ -466,6 +466,7 @@ void m2comm_device::comm_tick_16726() { m_buffer[0] = 0xff; m_buffer[1] = 0x01; + m_buffer[2] = 0x00; m_line_tx.write(m_buffer, dataSize); } @@ -474,11 +475,13 @@ void m2comm_device::comm_tick_16726() { m_buffer[0] = 0xfe; m_buffer[1] = m_linkcount; + m_buffer[2] = m_linkcount; m_line_tx.write(m_buffer, dataSize); // consider it done printf("M2COMM: link established - id %02x of %02x\n", m_linkid, m_linkcount); m_linkalive = 0x01; + m_linktimer = 0x00; // write to shared mem m_shared[0] = 0x01; @@ -511,47 +514,12 @@ void m2comm_device::comm_tick_16726() // check if valid id int idx = m_buffer[0]; if (idx > 0 && idx <= m_linkcount) { - int slotFrom = m_linkid - idx; - int slotDest = slotFrom + m_linkcount; - while (slotDest < 9) { - slotDest += m_linkcount; - } - while (slotDest - m_linkcount > 0) { - slotFrom = slotDest - m_linkcount; - if (slotDest < 9) { - int frameOffset1 = frameStart + slotFrom * frameSize; - int frameOffset2 = frameStart + slotDest * frameSize; - for (int j = 0x00 ; j < frameSize ; j++) - { - m_shared[frameOffset2 + j] = m_shared[frameOffset1 + j]; - } - } - slotDest -= m_linkcount; - } - if (slotDest > 0) { - // save message to "ring buffer" - frameOffset = frameStart + (slotDest * frameSize); - for (int j = 0x00 ; j < frameSize ; j++) - { - m_shared[frameOffset + j] = m_buffer[1 + j]; - } - } - if (idx != m_linkid) + for (int j = 0x00 ; j < frameSize ; j++) { - // forward message to other nodes - m_line_tx.write(m_buffer, dataSize); - } - } else { - if (!isMaster && idx == 0xF0){ - // 0xF0 - master addional bytes - for (int j = 0x05 ; j < 0x10 ; j++) - { - m_shared[j] = m_buffer[1 + j]; - } - - // forward message to other nodes - m_line_tx.write(m_buffer, dataSize); + m_shared[frameRX + j] = m_buffer[1 + j]; } + m_zfg ^= 1; + m_linktimer = 0x00; } } else @@ -568,27 +536,16 @@ void m2comm_device::comm_tick_16726() recv = m_line_rx.read(m_buffer, dataSize); } - // push message to other nodes - m_buffer[0] = m_linkid; - for (int j = 0x00 ; j < frameSize ; j++) + if (m_linktimer == 0x00) { - m_buffer[1 + j] = m_shared[frameStart + j]; - } - m_line_tx.write(m_buffer, dataSize); - - // master sends some additional status bytes - if (isMaster){ - m_buffer[0] = 0xF0; + // push message to other nodes + m_buffer[0] = m_linkid; for (int j = 0x00 ; j < frameSize ; j++) { - m_buffer[1 + j] = 0x00; + m_buffer[1 + j] = m_shared[frameTX + j]; } - for (int j = 0x05 ; j < 0x10 ; j++) - { - m_buffer[1 + j] = m_shared[j]; - } - // push message to other nodes m_line_tx.write(m_buffer, dataSize); + m_linktimer = 0x01; } } From e776cdf0e98bfc3f6d75aa6390d4a7af31205cd7 Mon Sep 17 00:00:00 2001 From: Ariane Fugmann Date: Wed, 22 Jun 2016 23:34:13 +0200 Subject: [PATCH 3/4] M2COMM: unified simulation code for all EPROM revisions. --- src/mame/machine/m2comm.cpp | 63 +++++++++++++++++-------------------- src/mame/machine/m2comm.h | 3 +- 2 files changed, 29 insertions(+), 37 deletions(-) diff --git a/src/mame/machine/m2comm.cpp b/src/mame/machine/m2comm.cpp index fadbb698930..f5c7036f2f4 100644 --- a/src/mame/machine/m2comm.cpp +++ b/src/mame/machine/m2comm.cpp @@ -79,6 +79,7 @@ Sega PC BD MODEL2 A-CRX COMMUNICATION 837-11525 EEPROM: 16726.7 Sega Rally Championship + 18643.7 ManxTT 18643A.7 ManxTT @@ -230,7 +231,6 @@ void m2comm_device::device_start() void m2comm_device::device_reset() { - set_linktype(16726); m_zfg = 0; m_cn = 0; m_fg = 0; @@ -297,8 +297,9 @@ WRITE8_MEMBER(m2comm_device::cn_w) m_linkid = 0x00; m_linkalive = 0x00; m_linkcount = 0x00; - m_linktimer = 0x04; //0x00E8; // 58 fps * 4s + m_linktimer = 0x00E8; // 58 fps * 4s + comm_init(); comm_tick(); } #endif @@ -323,44 +324,38 @@ void m2comm_device::check_vint_irq() } #ifdef __M2COMM_SIMULATION__ -void m2comm_device::set_linktype(UINT16 linktype) +void m2comm_device::comm_init() { - m_linktype = linktype; + // TODO - check EPR-16726 on Daytona USA and Sega Rally Championship + // EPR-18643(A) - these are accessed by VirtuaON and Sega Touring Car Championship + + // frameSize - 0xe00 + m_shared[0x12] = 0x00; + m_shared[0x13] = 0x0e; - switch (m_linktype) - { - case 16726: - // Daytona USA / Sega Rally Championship - printf("M2COMM: set mode 'EPR-16726 - Daytona USA'\n"); - break; - } + // frameOffset - 0x1c0 + m_shared[0x14] = 0xc0; + m_shared[0x15] = 0x01; } void m2comm_device::comm_tick() -{ - switch (m_linktype) - { - case 16726: - // Daytona USA / Sega Rally Championship - comm_tick_16726(); - break; - } -} - -void m2comm_device::comm_tick_16726() { if (m_linkenable == 0x01) { - int frameTX = 0x2000; - int frameRX = 0x21c0; - int frameSize = 0x01c0 * 8; + m_zfg ^= 1; + + int frameSize = m_shared[0x13] << 8 | m_shared[0x12]; + int frameOffset = m_shared[0x15] << 8 | m_shared[0x14]; + int dataSize = frameSize + 1; int togo = 0; int recv = 0; int idx = 0; - bool isMaster = (m_fg == 0x01); - bool isSlave = (m_fg == 0x00); + // EPR-16726 uses m_fg for Master/Slave + // EPR-18643(A) seems to check m_shared[1], with a fallback to m_fg + bool isMaster = (m_fg == 0x01 || m_shared[1] == 0x01); + bool isSlave = !isMaster && (m_fg == 0x00); // if link not yet established... if (m_linkalive == 0x00) @@ -409,6 +404,7 @@ void m2comm_device::comm_tick_16726() } else if (isSlave) { + // increase linkcount m_buffer[1]++; // forward message @@ -421,6 +417,7 @@ void m2comm_device::comm_tick_16726() { if (isSlave) { + // fetch linkcount and linkid, then decrease linkid m_linkcount = m_buffer[1]; m_linkid = m_buffer[2]; m_buffer[2]--; @@ -508,18 +505,17 @@ void m2comm_device::comm_tick_16726() int recv = m_line_rx.read(m_buffer, dataSize); while (recv != 0) { + m_linktimer = 0x00; // check if complete message if (recv == dataSize) { // check if valid id int idx = m_buffer[0]; - if (idx > 0 && idx <= m_linkcount) { + if (idx >= 0 && idx <= m_linkcount) { for (int j = 0x00 ; j < frameSize ; j++) { - m_shared[frameRX + j] = m_buffer[1 + j]; + m_shared[0x2000 + frameOffset + j] = m_buffer[1 + j]; } - m_zfg ^= 1; - m_linktimer = 0x00; } } else @@ -542,15 +538,12 @@ void m2comm_device::comm_tick_16726() m_buffer[0] = m_linkid; for (int j = 0x00 ; j < frameSize ; j++) { - m_buffer[1 + j] = m_shared[frameTX + j]; + m_buffer[1 + j] = m_shared[0x2000 + j]; } m_line_tx.write(m_buffer, dataSize); m_linktimer = 0x01; } } - - // clear 03 - //TODO:m_shared[3] = 0x00; } } #endif diff --git a/src/mame/machine/m2comm.h b/src/mame/machine/m2comm.h index 8566f2cdd33..020ac38fbb2 100644 --- a/src/mame/machine/m2comm.h +++ b/src/mame/machine/m2comm.h @@ -77,9 +77,8 @@ private: UINT16 m_linktype; + void comm_init(); void comm_tick(); - - void comm_tick_16726(); #endif }; From 79fa9bbaad4982ac2120065167f0e3884dfd6351 Mon Sep 17 00:00:00 2001 From: Ariane Fugmann Date: Thu, 23 Jun 2016 08:20:49 +0200 Subject: [PATCH 4/4] M2COMM: commented out jaleco custom handlers (nw) --- src/mame/drivers/model2.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mame/drivers/model2.cpp b/src/mame/drivers/model2.cpp index efe7c7e1c98..7e972516973 100644 --- a/src/mame/drivers/model2.cpp +++ b/src/mame/drivers/model2.cpp @@ -5967,7 +5967,7 @@ DRIVER_INIT_MEMBER(model2_state,sgt24h) { // DRIVER_INIT_CALL(genprot); - m_maincpu->space(AS_PROGRAM).install_readwrite_handler(0x01a10000, 0x01a1ffff, read32_delegate(FUNC(model2_state::jaleco_network_r),this), write32_delegate(FUNC(model2_state::jaleco_network_w),this)); + //m_maincpu->space(AS_PROGRAM).install_readwrite_handler(0x01a10000, 0x01a1ffff, read32_delegate(FUNC(model2_state::jaleco_network_r),this), write32_delegate(FUNC(model2_state::jaleco_network_w),this)); UINT32 *ROM = (UINT32 *)memregion("maincpu")->base(); ROM[0x56578/4] = 0x08000004; @@ -5976,7 +5976,7 @@ DRIVER_INIT_MEMBER(model2_state,sgt24h) DRIVER_INIT_MEMBER(model2_state,overrev) { - m_maincpu->space(AS_PROGRAM).install_readwrite_handler(0x01a10000, 0x01a1ffff, read32_delegate(FUNC(model2_state::jaleco_network_r),this), write32_delegate(FUNC(model2_state::jaleco_network_w),this)); + //m_maincpu->space(AS_PROGRAM).install_readwrite_handler(0x01a10000, 0x01a1ffff, read32_delegate(FUNC(model2_state::jaleco_network_r),this), write32_delegate(FUNC(model2_state::jaleco_network_w),this)); }