M1COMM, M2COMM, S32COMM: Updates to simulation (#3369)

* M1COMM: update simulation based on real firmware (nw)

- read partial frames correctly now
- added VSYNC packets (framesync currently disabled as this can cause
MAME to freeze and we have no way to tell if the socket is still open)

* M2COMM: update simulation (nw)

- read partial frames correctly now
- added VSYNC packets (framesync currently disabled as this can cause
MAME to freeze and we have no way to tell if the socket is still open)

* M1COMM, M2COMM: add config option to sync frames over network (nw)

* M2COMM: another update to the simulation.

- added relay mode (used by stcc)
- added "connection loss"

* M1COMM: update to simulation (nw)

- better sync
- detect lost connection

* M2COMM: use osd_file rather than emu_file for better control (nw)

* M2COMM: handle connection loss in a a more elegant way (nw)

* M1COMM: use osd_file rather than emu_file for better control (nw)

* S32COMM: updated simulation (nw)

- handle connection loss
- use osd_file rather than emu_file for better control
This commit is contained in:
Ariane Fugmann 2018-03-21 18:34:39 +01:00 committed by R. Belmont
parent 0883f01e66
commit c32176f2bb
8 changed files with 1137 additions and 782 deletions

View File

@ -187,6 +187,7 @@ const options_entry emu_options::s_option_entries[] =
{ OPTION_COMM_LOCAL_PORT, "15112", OPTION_STRING, "local port to bind to" }, { OPTION_COMM_LOCAL_PORT, "15112", OPTION_STRING, "local port to bind to" },
{ OPTION_COMM_REMOTE_HOST, "127.0.0.1", OPTION_STRING, "remote address to connect to" }, { OPTION_COMM_REMOTE_HOST, "127.0.0.1", OPTION_STRING, "remote address to connect to" },
{ OPTION_COMM_REMOTE_PORT, "15112", OPTION_STRING, "remote port to connect to" }, { OPTION_COMM_REMOTE_PORT, "15112", OPTION_STRING, "remote port to connect to" },
{ OPTION_COMM_FRAME_SYNC, "0", OPTION_BOOLEAN, "sync frames" },
// misc options // misc options
{ nullptr, nullptr, OPTION_HEADER, "CORE MISC OPTIONS" }, { nullptr, nullptr, OPTION_HEADER, "CORE MISC OPTIONS" },

View File

@ -177,6 +177,7 @@
#define OPTION_COMM_LOCAL_PORT "comm_localport" #define OPTION_COMM_LOCAL_PORT "comm_localport"
#define OPTION_COMM_REMOTE_HOST "comm_remotehost" #define OPTION_COMM_REMOTE_HOST "comm_remotehost"
#define OPTION_COMM_REMOTE_PORT "comm_remoteport" #define OPTION_COMM_REMOTE_PORT "comm_remoteport"
#define OPTION_COMM_FRAME_SYNC "comm_framesync"
#define OPTION_CONFIRM_QUIT "confirm_quit" #define OPTION_CONFIRM_QUIT "confirm_quit"
#define OPTION_UI_MOUSE "ui_mouse" #define OPTION_UI_MOUSE "ui_mouse"
@ -456,6 +457,7 @@ public:
const char *comm_localport() const { return value(OPTION_COMM_LOCAL_PORT); } const char *comm_localport() const { return value(OPTION_COMM_LOCAL_PORT); }
const char *comm_remotehost() const { return value(OPTION_COMM_REMOTE_HOST); } const char *comm_remotehost() const { return value(OPTION_COMM_REMOTE_HOST); }
const char *comm_remoteport() const { return value(OPTION_COMM_REMOTE_PORT); } const char *comm_remoteport() const { return value(OPTION_COMM_REMOTE_PORT); }
bool comm_framesync() const { return bool_value(OPTION_COMM_FRAME_SYNC); }
bool confirm_quit() const { return bool_value(OPTION_CONFIRM_QUIT); } bool confirm_quit() const { return bool_value(OPTION_CONFIRM_QUIT); }

View File

@ -123,9 +123,7 @@ const tiny_rom_entry *m1comm_device::device_rom_region() const
m1comm_device::m1comm_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) : m1comm_device::m1comm_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
device_t(mconfig, M1COMM, tag, owner, clock), device_t(mconfig, M1COMM, tag, owner, clock),
m_commcpu(*this, Z80_TAG), m_commcpu(*this, Z80_TAG)
m_line_rx(OPEN_FLAG_WRITE | OPEN_FLAG_CREATE ),
m_line_tx(OPEN_FLAG_READ)
{ {
// prepare localhost "filename" // prepare localhost "filename"
m_localhost[0] = 0; m_localhost[0] = 0;
@ -140,6 +138,8 @@ m1comm_device::m1comm_device(const machine_config &mconfig, const char *tag, dev
strcat(m_remotehost, mconfig.options().comm_remotehost()); strcat(m_remotehost, mconfig.options().comm_remotehost());
strcat(m_remotehost, ":"); strcat(m_remotehost, ":");
strcat(m_remotehost, mconfig.options().comm_remoteport()); strcat(m_remotehost, mconfig.options().comm_remoteport());
m_framesync = mconfig.options().comm_framesync() ? 0x01 : 0x00;
} }
//------------------------------------------------- //-------------------------------------------------
@ -318,7 +318,6 @@ void m1comm_device::comm_tick()
int frameOffset = 0x0000; int frameOffset = 0x0000;
int frameSize = 0x01c4; int frameSize = 0x01c4;
int dataSize = frameSize + 1; int dataSize = frameSize + 1;
int togo = 0;
int recv = 0; int recv = 0;
int idx = 0; int idx = 0;
@ -326,38 +325,42 @@ void m1comm_device::comm_tick()
bool isSlave = (m_shared[1] == 0x02); bool isSlave = (m_shared[1] == 0x02);
bool isRelay = (m_shared[1] == 0x00); bool isRelay = (m_shared[1] == 0x00);
// if link not yet established... if (m_linkalive == 0x02)
if (m_linkalive == 0x00)
{ {
// waiting... // link failed...
m_shared[0] = 0xff;
return;
}
else if (m_linkalive == 0x00)
{
// link not yet established...
m_shared[0] = 0x05; m_shared[0] = 0x05;
// check rx socket // check rx socket
if (!m_line_rx.is_open()) if (!m_line_rx)
{ {
osd_printf_verbose("M1COMM: listen on %s\n", m_localhost); osd_printf_verbose("M1COMM: listen on %s\n", m_localhost);
m_line_rx.open(m_localhost); uint64_t filesize; // unused
osd_file::open(m_localhost, OPEN_FLAG_CREATE, m_line_rx, filesize);
} }
// check tx socket // check tx socket
if (!m_line_tx.is_open()) if (!m_line_tx)
{ {
osd_printf_verbose("M1COMM: connect to %s\n", m_remotehost); osd_printf_verbose("M1COMM: connect to %s\n", m_remotehost);
m_line_tx.open(m_remotehost); uint64_t filesize; // unused
osd_file::open(m_remotehost, 0, m_line_tx, filesize);
} }
// if both sockets are there check ring // if both sockets are there check ring
if ((m_line_rx.is_open()) && (m_line_tx.is_open())) if (m_line_rx && m_line_tx)
{ {
// try to read one messages // try to read one message
recv = m_line_rx.read(m_buffer, dataSize); recv = read_frame(dataSize);
while (recv != 0) while (recv > 0)
{ {
// check if complete message // check message id
if (recv == dataSize) idx = m_buffer0[0];
{
// check if message id
idx = m_buffer[0];
// 0xFF - link id // 0xFF - link id
if (idx == 0xff) if (idx == 0xff)
@ -366,20 +369,20 @@ void m1comm_device::comm_tick()
{ {
// master gets first id and starts next state // master gets first id and starts next state
m_linkid = 0x01; m_linkid = 0x01;
m_linkcount = m_buffer[1]; m_linkcount = m_buffer0[1];
m_linktimer = 0x01; m_linktimer = 0x00;
} }
else if (isSlave || isRelay) else
{ {
// slave gets own id // slave get own id, relay does nothing
if (isSlave) if (isSlave)
{ {
m_buffer[1]++; m_buffer0[1]++;
m_linkid = m_buffer[1]; m_linkid = m_buffer0[1];
} }
// slave and relay forward message // forward message to other nodes
m_line_tx.write(m_buffer, dataSize); send_frame(dataSize);
} }
} }
@ -388,10 +391,10 @@ void m1comm_device::comm_tick()
{ {
if (isSlave || isRelay) if (isSlave || isRelay)
{ {
m_linkcount = m_buffer[1]; m_linkcount = m_buffer0[1];
// slave and relay forward message // forward message to other nodes
m_line_tx.write(m_buffer, dataSize); send_frame(dataSize);
} }
// consider it done // consider it done
@ -404,21 +407,10 @@ void m1comm_device::comm_tick()
m_shared[2] = m_linkid; m_shared[2] = m_linkid;
m_shared[3] = m_linkcount; m_shared[3] = m_linkcount;
} }
}
else
{
// got only part of a message - read the rest (and drop it)
// TODO: combine parts and push to "ring buffer"
togo = dataSize - recv;
while (togo > 0){
recv = m_line_rx.read(m_buffer, togo);
togo -= recv;
}
osd_printf_verbose("M1COMM: dropped a message...\n");
}
if (m_linkalive == 0x00) if (m_linkalive == 0x00)
recv = m_line_rx.read(m_buffer, dataSize); recv = read_frame(dataSize);
else else
recv = 0; recv = 0;
} }
@ -427,19 +419,19 @@ void m1comm_device::comm_tick()
if (isMaster && (m_linkalive == 0x00)) if (isMaster && (m_linkalive == 0x00))
{ {
// send first packet // send first packet
if (m_linktimer == 0x00) if (m_linktimer == 0x01)
{ {
m_buffer[0] = 0xff; m_buffer0[0] = 0xff;
m_buffer[1] = 0x01; m_buffer0[1] = 0x01;
m_line_tx.write(m_buffer, dataSize); send_frame(dataSize);
} }
// send second packet // send second packet
else if (m_linktimer == 0x01) else if (m_linktimer == 0x00)
{ {
m_buffer[0] = 0xfe; m_buffer0[0] = 0xfe;
m_buffer[1] = m_linkcount; m_buffer0[1] = m_linkcount;
m_line_tx.write(m_buffer, dataSize); send_frame(dataSize);
// consider it done // consider it done
osd_printf_verbose("M1COMM: link established - id %02x of %02x\n", m_linkid, m_linkcount); osd_printf_verbose("M1COMM: link established - id %02x of %02x\n", m_linkid, m_linkcount);
@ -452,104 +444,197 @@ void m1comm_device::comm_tick()
m_shared[3] = m_linkcount; m_shared[3] = m_linkcount;
} }
else if (m_linktimer > 0x02) else if (m_linktimer > 0x01)
{ {
// decrease delay timer // decrease delay timer
m_linktimer--; m_linktimer--;
if (m_linktimer == 0x02)
m_linktimer = 0x00;
} }
} }
} }
} }
// update "ring buffer" if link established
if (m_linkalive == 0x01) if (m_linkalive == 0x01)
{ {
int togo = 0; // link established
// try to read one messages do
int recv = m_line_rx.read(m_buffer, dataSize);
while (recv != 0)
{ {
// check if complete message // try to read a message
if (recv == dataSize) recv = read_frame(dataSize);
while (recv > 0)
{ {
// check if valid id // check if valid id
int idx = m_buffer[0]; idx = m_buffer0[0];
if (idx > 0 && idx <= m_linkcount) { if (idx > 0 && idx <= m_linkcount)
// if not our own message {
// if not own message
if (idx != m_linkid) if (idx != m_linkid)
{ {
// save message to "ring buffer" // save message to "ring buffer"
frameOffset = frameStart + (idx * frameSize); frameOffset = frameStart + (idx * frameSize);
for (int j = 0x00 ; j < frameSize ; j++) for (int j = 0x00 ; j < frameSize ; j++)
{ {
m_shared[frameOffset + j] = m_buffer[1 + j]; m_shared[frameOffset + j] = m_buffer0[1 + j];
} }
// forward message to other nodes // forward message to other nodes
m_line_tx.write(m_buffer, dataSize); send_frame(dataSize);
}
} else {
if (!isMaster && idx == 0xf0){
// 0xF0 - master addional bytes
for (int j = 0x06 ; j < 0x10 ; j++)
{
m_shared[j] = m_buffer[1 + j];
}
// forward message to other nodes
m_line_tx.write(m_buffer, dataSize);
}
} }
} }
else else
{ {
// got only part of a message - read the rest (and drop it) if (idx == 0xfc)
// TODO: combine parts and push to "ring buffer" {
togo = dataSize - recv; // 0xFC - VSYNC
while (togo > 0){ m_linktimer = 0x00;
recv = m_line_rx.read(m_buffer, togo); if (!isMaster)
togo -= recv; // forward message to other nodes
send_frame(dataSize);
} }
osd_printf_verbose("M1COMM: dropped a message...\n"); if (idx == 0xfd)
{
// 0xFD - master addional bytes
if (!isMaster)
{
// save message to "ring buffer"
frameOffset = 0x06;
for (int j = 0x00 ; j < 0x0a ; j++)
{
m_shared[frameOffset + j] = m_buffer0[1 + j];
} }
recv = m_line_rx.read(m_buffer, dataSize);
// forward message to other nodes
send_frame(dataSize);
} }
}
}
// try to read another message
recv = read_frame(dataSize);
}
}
while (m_linktimer == 0x01);
// enable wait for vsync
m_linktimer = m_framesync;
// update "ring buffer" if link established // update "ring buffer" if link established
// live relay does not send data // live relay does not send data
if (m_linkid != 0x00 && m_shared[4] != 0x00) if (m_linkid != 0x00)
{ {
m_buffer[0] = m_linkid; // check ready-to-send flag
if (m_shared[4] != 0x00)
{
send_data(m_linkid, frameStart, frameSize, dataSize);
// save message to "ring buffer"
frameOffset = frameStart + (m_linkid * frameSize); frameOffset = frameStart + (m_linkid * frameSize);
for (int j = 0x00 ; j < frameSize ; j++) for (int j = 0x00 ; j < frameSize ; j++)
{ {
// push message to "ring buffer" m_shared[frameOffset + j] = m_buffer0[1 + j];
m_shared[frameOffset + j] = m_shared[frameStart + j]; }
m_buffer[1 + j] = m_shared[frameStart + j];
} }
// push message to other nodes
m_line_tx.write(m_buffer, dataSize);
// master sends some additional status bytes if (isMaster)
if (isMaster){
m_buffer[0] = 0xf0;
for (int j = 0x00 ; j < frameSize ; j++)
{ {
m_buffer[1 + j] = 0x00; // master sends additional status bytes
} send_data(0xfd, 0x06, 0x0a, dataSize);
for (int j = 0x06 ; j < 0x10 ; j++)
{ // send vsync
m_buffer[1 + j] = m_shared[j]; m_buffer0[0] = 0xfc;
} m_buffer0[1] = 0x01;
// push message to other nodes send_frame(dataSize);
m_line_tx.write(m_buffer, dataSize);
} }
} }
// clear 05 // clear 05
m_shared[5] = 0x00; m_shared[5] = 0x00;
} }
} }
} }
int m1comm_device::read_frame(int dataSize)
{
if (!m_line_rx)
return 0;
// try to read a message
std::uint32_t recv = 0;
osd_file::error filerr = m_line_rx->read(m_buffer0, 0, dataSize, recv);
if (recv > 0)
{
// check if message complete
if (recv != dataSize)
{
// only part of a message - read on
std::uint32_t togo = dataSize - recv;
int offset = recv;
while (togo > 0)
{
filerr = m_line_rx->read(m_buffer1, 0, togo, recv);
if (recv > 0)
{
for (int i = 0 ; i < recv ; i++)
{
m_buffer0[offset + i] = m_buffer1[i];
}
togo -= recv;
offset += recv;
}
else if (filerr == osd_file::error::NONE && recv == 0)
{
togo = 0;
}
}
}
}
else if (filerr == osd_file::error::NONE && recv == 0)
{
if (m_linkalive == 0x01)
{
osd_printf_verbose("M1COMM: rx connection lost\n");
m_linkalive = 0x02;
m_linktimer = 0x00;
m_shared[0] = 0xff;
m_line_rx.reset();
m_line_tx.reset();
}
}
return recv;
}
void m1comm_device::send_data(uint8_t frameType, int frameStart, int frameSize, int dataSize)
{
m_buffer0[0] = frameType;
for (int i = 0x00 ; i < frameSize ; i++)
{
m_buffer0[1 + i] = m_shared[frameStart + i];
}
send_frame(dataSize);
}
void m1comm_device::send_frame(int dataSize){
if (!m_line_tx)
return;
osd_file::error filerr;
std::uint32_t written;
filerr = m_line_tx->write(&m_buffer0, 0, dataSize, written);
if (filerr != osd_file::error::NONE)
{
if (m_linkalive == 0x01)
{
osd_printf_verbose("M1COMM: tx connection lost\n");
m_linkalive = 0x02;
m_linktimer = 0x00;
m_shared[0] = 0xff;
m_line_rx.reset();
m_line_tx.reset();
}
}
}
#endif #endif

View File

@ -7,6 +7,7 @@
#define M1COMM_SIMULATION #define M1COMM_SIMULATION
#include "osdcore.h"
#include "cpu/z80/z80.h" #include "cpu/z80/z80.h"
#define MCFG_M1COMM_ADD(_tag ) \ #define MCFG_M1COMM_ADD(_tag ) \
@ -75,11 +76,13 @@ private:
uint8_t m_cn; // bit0 is used to enable/disable the comm board uint8_t m_cn; // bit0 is used to enable/disable the comm board
uint8_t m_fg; // flip gate? purpose unknown, bit0 is stored, bit7 is connected to ZFG bit 0 uint8_t m_fg; // flip gate? purpose unknown, bit0 is stored, bit7 is connected to ZFG bit 0
emu_file m_line_rx; // rx line - can be either differential, simple serial or toslink osd_file::ptr m_line_rx; // rx line - can be either differential, simple serial or toslink
emu_file m_line_tx; // tx line - is differential, simple serial and toslink osd_file::ptr m_line_tx; // tx line - is differential, simple serial and toslink
char m_localhost[256]; char m_localhost[256];
char m_remotehost[256]; char m_remotehost[256];
uint8_t m_buffer[0x1000]; uint8_t m_buffer0[0x200];
uint8_t m_buffer1[0x200];
uint8_t m_framesync;
#ifdef M1COMM_SIMULATION #ifdef M1COMM_SIMULATION
uint8_t m_linkenable; uint8_t m_linkenable;
@ -89,6 +92,9 @@ private:
uint8_t m_linkcount; uint8_t m_linkcount;
void comm_tick(); void comm_tick();
int read_frame(int dataSize);
void send_data(uint8_t frameType, int frameStart, int frameSize, int dataSize);
void send_frame(int dataSize);
#endif #endif
}; };

View File

@ -194,9 +194,7 @@ MACHINE_CONFIG_END
//------------------------------------------------- //-------------------------------------------------
m2comm_device::m2comm_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) : m2comm_device::m2comm_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
device_t(mconfig, M2COMM, tag, owner, clock), device_t(mconfig, M2COMM, tag, owner, clock)
m_line_rx(OPEN_FLAG_WRITE | OPEN_FLAG_CREATE ),
m_line_tx(OPEN_FLAG_READ)
{ {
// prepare localhost "filename" // prepare localhost "filename"
m_localhost[0] = 0; m_localhost[0] = 0;
@ -211,6 +209,8 @@ m2comm_device::m2comm_device(const machine_config &mconfig, const char *tag, dev
strcat(m_remotehost, mconfig.options().comm_remotehost()); strcat(m_remotehost, mconfig.options().comm_remotehost());
strcat(m_remotehost, ":"); strcat(m_remotehost, ":");
strcat(m_remotehost, mconfig.options().comm_remoteport()); strcat(m_remotehost, mconfig.options().comm_remoteport());
m_framesync = mconfig.options().comm_framesync() ? 0x01 : 0x00;
} }
//------------------------------------------------- //-------------------------------------------------
@ -296,6 +296,7 @@ WRITE8_MEMBER(m2comm_device::cn_w)
m_shared[i] = 0x00; m_shared[i] = 0x00;
} }
m_shared[0x01] = 0x02;
// TODO - check EPR-16726 on Daytona USA and Sega Rally Championship // TODO - check EPR-16726 on Daytona USA and Sega Rally Championship
// EPR-18643(A) - these are accessed by VirtuaON and Sega Touring Car Championship // EPR-18643(A) - these are accessed by VirtuaON and Sega Touring Car Championship
@ -314,6 +315,9 @@ WRITE8_MEMBER(m2comm_device::cn_w)
READ8_MEMBER(m2comm_device::fg_r) READ8_MEMBER(m2comm_device::fg_r)
{ {
#ifdef M2COMM_SIMULATION
read_fg();
#endif
return m_fg | (~m_zfg << 7) | 0x7e; return m_fg | (~m_zfg << 7) | 0x7e;
} }
@ -335,55 +339,60 @@ void m2comm_device::comm_tick()
{ {
if (m_linkenable == 0x01) if (m_linkenable == 0x01)
{ {
m_zfg ^= 1; int frameStart = 0x2000;
int frameSize = m_shared[0x13] << 8 | m_shared[0x12]; int frameSize = m_shared[0x13] << 8 | m_shared[0x12];
int frameOffset = m_shared[0x15] << 8 | m_shared[0x14]; int frameOffset = frameStart | m_shared[0x15] << 8 | m_shared[0x14];
int dataSize = frameSize + 1; int dataSize = frameSize + 1;
int togo = 0;
int recv = 0; int recv = 0;
int idx = 0; int idx = 0;
// EPR-16726 uses m_fg for Master/Slave // EPR-16726 uses m_fg for Master/Slave
// EPR-18643(A) seems to check m_shared[1], with a fallback to m_fg // 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 isMaster = (m_fg == 0x01 || m_shared[1] == 0x01);
bool isSlave = !isMaster && (m_fg == 0x00); bool isSlave = (m_fg == 0x00 && m_shared[1] == 0x02);
bool isRelay = (m_fg == 0x00 && m_shared[1] == 0x00);
// if link not yet established... if (m_linkalive == 0x02)
if (m_linkalive == 0x00)
{ {
// waiting... // link failed...
m_shared[0] = 0xff;
return;
}
else if (m_linkalive == 0x00)
{
// link not yet established...
m_shared[0] = 0x00; m_shared[0] = 0x00;
m_shared[2] = 0xff; m_shared[2] = 0xff;
m_shared[3] = 0xff; m_shared[3] = 0xff;
// check rx socket // check rx socket
if (!m_line_rx.is_open()) if (!m_line_rx)
{ {
osd_printf_verbose("M2COMM: listen on %s\n", m_localhost); osd_printf_verbose("M2COMM: listen on %s\n", m_localhost);
m_line_rx.open(m_localhost); uint64_t filesize; // unused
osd_file::open(m_localhost, OPEN_FLAG_CREATE, m_line_rx, filesize);
} }
// check tx socket // check tx socket
if (!m_line_tx.is_open()) if (!m_line_tx)
{ {
osd_printf_verbose("M2COMM: connect to %s\n", m_remotehost); osd_printf_verbose("M2COMM: connect to %s\n", m_remotehost);
m_line_tx.open(m_remotehost); uint64_t filesize; // unused
osd_file::open(m_remotehost, 0, m_line_tx, filesize);
} }
// if both sockets are there check ring // if both sockets are there check ring
if ((m_line_rx.is_open()) && (m_line_tx.is_open())) if (m_line_rx && m_line_tx)
{ {
// try to read one messages m_zfg ^= 0x01;
recv = m_line_rx.read(m_buffer, dataSize);
while (recv != 0) // try to read one message
{ recv = read_frame(dataSize);
// check if complete message while (recv > 0)
if (recv == dataSize)
{ {
// check if message id // check if message id
idx = m_buffer[0]; idx = m_buffer0[0];
// 0xFF - link id // 0xFF - link id
if (idx == 0xff) if (idx == 0xff)
@ -392,16 +401,19 @@ void m2comm_device::comm_tick()
{ {
// master gets first id and starts next state // master gets first id and starts next state
m_linkid = 0x01; m_linkid = 0x01;
m_linkcount = m_buffer[1]; m_linkcount = m_buffer0[1];
m_linktimer = 0x01; m_linktimer = 0x00;
} }
else if (isSlave) else
{ {
// increase linkcount // slave get own id, relay does nothing
m_buffer[1]++; if (isSlave)
{
m_buffer0[1]++;
}
// forward message // forward message to other nodes
m_line_tx.write(m_buffer, dataSize); send_frame(dataSize);
} }
} }
@ -410,40 +422,36 @@ void m2comm_device::comm_tick()
{ {
if (isSlave) if (isSlave)
{ {
// fetch linkcount and linkid, then decrease linkid // fetch linkid and linkcount, then decrease linkid
m_linkcount = m_buffer[1]; m_linkid = m_buffer0[1];
m_linkid = m_buffer[2]; m_linkcount = m_buffer0[2];
m_buffer[2]--; m_buffer0[1]--;
// forward message // forward message to other nodes
m_line_tx.write(m_buffer, dataSize); send_frame(dataSize);
}
else if (isRelay)
{
// fetch linkid and linkcount, then decrease linkid
m_linkid = 0x00;
m_linkcount = m_buffer0[2];
// forward message to other nodes
send_frame(dataSize);
} }
// consider it done // consider it done
osd_printf_verbose("M2COMM: link established - id %02x of %02x\n", m_linkid, m_linkcount); osd_printf_verbose("M2COMM: link established - id %02x of %02x\n", m_linkid, m_linkcount);
m_linkalive = 0x01; m_linkalive = 0x01;
m_linktimer = 0x01;
// write to shared mem // write to shared mem
m_shared[0] = 0x01; m_shared[0] = 0x01;
m_shared[2] = m_linkid; m_shared[2] = m_linkid;
m_shared[3] = m_linkcount; m_shared[3] = m_linkcount;
} }
}
else
{
// got only part of a message - read the rest (and drop it)
// TODO: combine parts and push to "ring buffer"
togo = dataSize - recv;
while (togo > 0){
recv = m_line_rx.read(m_buffer, togo);
togo -= recv;
}
osd_printf_verbose("M2COMM: dropped a message...\n");
}
if (m_linkalive == 0x00) if (m_linkalive == 0x00)
recv = m_line_rx.read(m_buffer, dataSize); recv = read_frame(dataSize);
else else
recv = 0; recv = 0;
} }
@ -452,27 +460,25 @@ void m2comm_device::comm_tick()
if (isMaster && (m_linkalive == 0x00)) if (isMaster && (m_linkalive == 0x00))
{ {
// send first packet // send first packet
if (m_linktimer == 0x00) if (m_linktimer == 0x01)
{ {
m_buffer[0] = 0xff; m_buffer0[0] = 0xff;
m_buffer[1] = 0x01; m_buffer0[1] = 0x01;
m_buffer[2] = 0x00; m_buffer0[2] = 0x00;
m_line_tx.write(m_buffer, dataSize); send_frame(dataSize);
m_linktimer = 0x00e8; // 58 fps * 4s
} }
// send second packet // send second packet
else if (m_linktimer == 0x01) else if (m_linktimer == 0x00)
{ {
m_buffer[0] = 0xfe; m_buffer0[0] = 0xfe;
m_buffer[1] = m_linkcount; m_buffer0[1] = m_linkcount;
m_buffer[2] = m_linkcount; m_buffer0[2] = m_linkcount;
m_line_tx.write(m_buffer, dataSize); send_frame(dataSize);
// consider it done // consider it done
osd_printf_verbose("M2COMM: link established - id %02x of %02x\n", m_linkid, m_linkcount); osd_printf_verbose("M2COMM: link established - id %02x of %02x\n", m_linkid, m_linkcount);
m_linkalive = 0x01; m_linkalive = 0x01;
m_linktimer = 0x00;
// write to shared mem // write to shared mem
m_shared[0] = 0x01; m_shared[0] = 0x01;
@ -480,63 +486,216 @@ void m2comm_device::comm_tick()
m_shared[3] = m_linkcount; m_shared[3] = m_linkcount;
} }
else if (m_linktimer > 0x02) else if (m_linktimer > 0x01)
{ {
// decrease delay timer // decrease delay timer
m_linktimer--; m_linktimer--;
if (m_linktimer == 0x02)
m_linktimer = 0x00;
} }
} }
} }
} }
// update "ring buffer" if link established // if link established
if (m_linkalive == 0x01) if (m_linkalive == 0x01)
{ {
int togo = 0; do
// try to read one messages
int recv = m_line_rx.read(m_buffer, dataSize);
while (recv != 0)
{ {
m_linktimer = 0x00; // try to read a message
// check if complete message recv = read_frame(dataSize);
if (recv == dataSize) while (recv > 0)
{ {
// check if valid id // check if valid id
int idx = m_buffer[0]; idx = m_buffer0[0];
if (idx >= 0 && idx <= m_linkcount) { if (idx >= 0 && idx <= m_linkcount)
{
// save message to "ring buffer"
for (int j = 0x00 ; j < frameSize ; j++) for (int j = 0x00 ; j < frameSize ; j++)
{ {
m_shared[0x2000 + frameOffset + j] = m_buffer[1 + j]; m_shared[frameOffset + j] = m_buffer0[1 + j];
}
} }
m_zfg ^= 0x01;
if (isSlave)
send_data(m_linkid, frameStart, frameSize, dataSize);
else if (isRelay)
send_frame(dataSize);
} }
else else
{ {
// got only part of a message - read the rest (and drop it) if (idx == 0xfc)
// TODO: combine parts and push to "ring buffer" {
togo = dataSize - recv; // 0xFC - VSYNC
while (togo > 0){ m_linktimer = 0x00;
recv = m_line_rx.read(m_buffer, togo);
togo -= recv; if (!isMaster)
// forward message to other nodes
send_frame(dataSize);
} }
osd_printf_verbose("M2COMM: dropped a message...\n");
}
recv = m_line_rx.read(m_buffer, dataSize);
} }
if (m_linktimer == 0x00) // try to read another message
recv = read_frame(dataSize);
}
}
while (m_linktimer == 0x01);
// enable wait for vsync
m_linktimer = m_framesync;
if (isMaster)
{ {
// push message to other nodes // update "ring buffer" if link established
m_buffer[0] = m_linkid; send_data(m_linkid, frameStart, frameSize, dataSize);
// send vsync
m_buffer0[0] = 0xfc;
m_buffer0[1] = 0x01;
send_frame(dataSize);
}
m_zfg_delay = 0x02;
}
}
}
void m2comm_device::read_fg()
{
if (m_zfg_delay > 0x00)
{
m_zfg_delay--;
return;
}
if (m_linkalive == 0x01)
{
int frameStart = 0x2000;
int frameSize = m_shared[0x13] << 8 | m_shared[0x12];
int frameOffset = frameStart | m_shared[0x15] << 8 | m_shared[0x14];
int dataSize = frameSize + 1;
int recv = 0;
int idx = 0;
// 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 = (m_fg == 0x00 && m_shared[1] == 0x02);
bool isRelay = (m_fg == 0x00 && m_shared[1] == 0x00);
do
{
// try to read a message
recv = read_frame(dataSize);
while (recv > 0)
{
// check if valid id
idx = m_buffer0[0];
if (idx >= 0 && idx <= m_linkcount)
{
// save message to "ring buffer"
for (int j = 0x00 ; j < frameSize ; j++) for (int j = 0x00 ; j < frameSize ; j++)
{ {
m_buffer[1 + j] = m_shared[0x2000 + j]; m_shared[frameOffset + j] = m_buffer0[1 + j];
} }
m_line_tx.write(m_buffer, dataSize); m_zfg ^= 0x01;
m_linktimer = 0x01; if (isSlave)
send_data(m_linkid, frameStart, frameSize, dataSize);
else if (isRelay)
send_frame(dataSize);
} }
else
{
if (idx == 0xfc)
{
// 0xFC - VSYNC
m_linktimer = 0x00;
if (!isMaster)
// forward message to other nodes
send_frame(dataSize);
}
}
// try to read another message
recv = read_frame(dataSize);
}
}
while (m_linktimer == 0x01);
}
}
int m2comm_device::read_frame(int dataSize)
{
if (!m_line_rx)
return 0;
// try to read a message
std::uint32_t recv = 0;
osd_file::error filerr = m_line_rx->read(m_buffer0, 0, dataSize, recv);
if (recv > 0)
{
// check if message complete
if (recv != dataSize)
{
// only part of a message - read on
std::uint32_t togo = dataSize - recv;
int offset = recv;
while (togo > 0)
{
filerr = m_line_rx->read(m_buffer1, 0, togo, recv);
if (recv > 0)
{
for (int i = 0 ; i < recv ; i++)
{
m_buffer0[offset + i] = m_buffer1[i];
}
togo -= recv;
offset += recv;
}
else if (filerr == osd_file::error::NONE && recv == 0)
{
togo = 0;
}
}
}
}
else if (filerr == osd_file::error::NONE && recv == 0)
{
if (m_linkalive == 0x01)
{
osd_printf_verbose("M2COMM: rx connection lost\n");
m_linkalive = 0x02;
m_linktimer = 0x00;
m_line_rx.reset();
}
}
return recv;
}
void m2comm_device::send_data(uint8_t frameType, int frameStart, int frameSize, int dataSize)
{
m_buffer0[0] = frameType;
for (int i = 0x0000 ; i < frameSize ; i++)
{
m_buffer0[1 + i] = m_shared[frameStart + i];
}
send_frame(dataSize);
}
void m2comm_device::send_frame(int dataSize){
if (!m_line_tx)
return;
osd_file::error filerr;
std::uint32_t written;
filerr = m_line_tx->write(&m_buffer0, 0, dataSize, written);
if (filerr != osd_file::error::NONE)
{
if (m_linkalive == 0x01)
{
osd_printf_verbose("M2COMM: tx connection lost\n");
m_linkalive = 0x02;
m_linktimer = 0x00;
m_line_tx.reset();
} }
} }
} }

View File

@ -7,6 +7,7 @@
#define M2COMM_SIMULATION #define M2COMM_SIMULATION
#include "osdcore.h"
#define MCFG_M2COMM_ADD(_tag ) \ #define MCFG_M2COMM_ADD(_tag ) \
MCFG_DEVICE_ADD(_tag, M2COMM, 0) MCFG_DEVICE_ADD(_tag, M2COMM, 0)
@ -56,11 +57,13 @@ private:
uint8_t m_cn; // bit0 is used to enable/disable the comm board uint8_t m_cn; // bit0 is used to enable/disable the comm board
uint8_t m_fg; // i960 flip gate - bit0 is stored, bit7 is connected to ZFG bit 0 uint8_t m_fg; // i960 flip gate - bit0 is stored, bit7 is connected to ZFG bit 0
emu_file m_line_rx; // rx line - can be either differential, simple serial or toslink osd_file::ptr m_line_rx; // rx line - can be either differential, simple serial or toslink
emu_file m_line_tx; // tx line - is differential, simple serial and toslink osd_file::ptr m_line_tx; // tx line - is differential, simple serial and toslink
char m_localhost[256]; char m_localhost[256];
char m_remotehost[256]; char m_remotehost[256];
uint8_t m_buffer[0x4000]; uint8_t m_buffer0[0x1000];
uint8_t m_buffer1[0x1000];
uint8_t m_framesync;
#ifdef M2COMM_SIMULATION #ifdef M2COMM_SIMULATION
uint8_t m_linkenable; uint8_t m_linkenable;
@ -68,8 +71,13 @@ private:
uint8_t m_linkalive; uint8_t m_linkalive;
uint8_t m_linkid; uint8_t m_linkid;
uint8_t m_linkcount; uint8_t m_linkcount;
uint8_t m_zfg_delay;
void comm_tick(); void comm_tick();
void read_fg();
int read_frame(int dataSize);
void send_data(uint8_t frameType, int frameStart, int frameSize, int dataSize);
void send_frame(int dataSize);
#endif #endif
}; };

File diff suppressed because it is too large Load Diff

View File

@ -7,6 +7,8 @@
#define S32COMM_SIMULATION #define S32COMM_SIMULATION
#include "osdcore.h"
#define MCFG_S32COMM_ADD(_tag ) \ #define MCFG_S32COMM_ADD(_tag ) \
MCFG_DEVICE_ADD(_tag, S32COMM, 0) MCFG_DEVICE_ADD(_tag, S32COMM, 0)
@ -59,11 +61,13 @@ private:
uint8_t m_cn; // bit0 is used to enable/disable the comm board uint8_t m_cn; // bit0 is used to enable/disable the comm board
uint8_t m_fg; // flip gate? purpose unknown, bit0 is stored, bit7 is connected to ZFG bit 0 uint8_t m_fg; // flip gate? purpose unknown, bit0 is stored, bit7 is connected to ZFG bit 0
emu_file m_line_rx; // rx line - can be either differential, simple serial or toslink osd_file::ptr m_line_rx; // rx line - can be either differential, simple serial or toslink
emu_file m_line_tx; // tx line - is differential, simple serial and toslink osd_file::ptr m_line_tx; // tx line - is differential, simple serial and toslink
char m_localhost[256]; char m_localhost[256];
char m_remotehost[256]; char m_remotehost[256];
uint8_t m_buffer[0x800]; uint8_t m_buffer0[0x100];
uint8_t m_buffer1[0x100];
uint8_t m_framesync;
#ifdef S32COMM_SIMULATION #ifdef S32COMM_SIMULATION
uint8_t m_linkenable; uint8_t m_linkenable;
@ -71,10 +75,12 @@ private:
uint8_t m_linkalive; uint8_t m_linkalive;
uint8_t m_linkid; uint8_t m_linkid;
uint8_t m_linkcount; uint8_t m_linkcount;
uint16_t m_linktype; uint16_t m_linktype;
void comm_tick(); void comm_tick();
int read_frame(int dataSize);
void send_data(uint8_t frameType, int frameStart, int frameSize, int dataSize);
void send_frame(int dataSize);
void comm_tick_14084(); void comm_tick_14084();
void comm_tick_15033(); void comm_tick_15033();