Replace network code with new tcp implementation

This commit is contained in:
Ian Curtis 2020-06-16 11:55:38 +00:00
parent 8071efbf79
commit daef27be37
9 changed files with 106 additions and 131 deletions

View file

@ -78,7 +78,7 @@ const char *CJTAG::s_state[] =
static void SaveBitRegister(CBlockFile *SaveState, const Util::BitRegister &reg) static void SaveBitRegister(CBlockFile *SaveState, const Util::BitRegister &reg)
{ {
uint16_t size = reg.Size() + 1; // include null terminator uint16_t size = (uint16_t)reg.Size() + 1; // include null terminator
SaveState->Write(&size, sizeof(size)); SaveState->Write(&size, sizeof(size));
SaveState->Write(reg.ToBinaryString()); SaveState->Write(reg.ToBinaryString());
} }

View file

@ -2471,9 +2471,6 @@ void CModel3::DumpTimings(void)
timings.syncTicks, (timings.syncTicks > 1 ? '!' : ','), timings.syncTicks, (timings.syncTicks > 1 ? '!' : ','),
timings.sndTicks, (timings.sndTicks > 10 ? '!' : ','), timings.sndTicks, (timings.sndTicks > 10 ? '!' : ','),
timings.drvTicks, (timings.drvTicks > 10 ? '!' : ','), timings.drvTicks, (timings.drvTicks > 10 ? '!' : ','),
#ifdef NET_BOARD
timings.netTicks, (timings.netTicks > 10 ? '!' : ','), // TODO fix this line 'printf' : too many arguments passed for format string
#endif
timings.frameTicks, (timings.frameTicks > 16 ? '!' : ' ')); timings.frameTicks, (timings.frameTicks > 16 ? '!' : ' '));
} }
@ -3125,7 +3122,6 @@ bool CModel3::Init(void)
#ifdef NET_BOARD #ifdef NET_BOARD
netRAM = &memoryPool[OFFSET_NETRAM]; netRAM = &memoryPool[OFFSET_NETRAM];
netBuffer = &memoryPool[OFFSET_NETBUFFER]; netBuffer = &memoryPool[OFFSET_NETBUFFER];
m_runNetBoard = m_game.stepping != "1.0" && (NetBoard.IsAttached() && (m_config["EmulateNet"].ValueAs<bool>()));
#endif #endif
SetCROMBank(0xFF); SetCROMBank(0xFF);
@ -3143,8 +3139,11 @@ bool CModel3::Init(void)
if (OKAY != SoundBoard.Init(soundROM,sampleROM)) if (OKAY != SoundBoard.Init(soundROM,sampleROM))
return FAIL; return FAIL;
#ifdef NET_BOARD #ifdef NET_BOARD
if (OKAY != NetBoard.Init(netRAM, netBuffer)) if (OKAY != NetBoard.Init(netRAM, netBuffer)) {
return FAIL; return FAIL;
}
m_runNetBoard = m_game.stepping != "1.0" && (NetBoard.IsAttached() && (m_config["EmulateNet"].ValueAs<bool>()));
#endif #endif
PCIBridge.AttachPCIBus(&PCIBus); PCIBridge.AttachPCIBus(&PCIBus);

View file

@ -6,7 +6,7 @@
// Irq implementation check, timer for irq5 or at every frame? Where to put irq2 (mame says at every register writes), irq4, irq6. // Irq implementation check, timer for irq5 or at every frame? Where to put irq2 (mame says at every register writes), irq4, irq6.
// check all, lol :) // check all, lol :)
// obsolete : ring network code is blocking, this cause the program to not responding when quit because it enter in receive fonction // obsolete : ring network code is blocking, this cause the program to not responding when quit because it enter in receive fonction
// this also leads to a forcing synchro between cabs, not acting like a real hardware // this also leads to a forcing synchro between cabs, not acting like a real hardware
// Changing to Ian's udp code. It is non blocking. Now the sync between instance could not be get each time (bug), because 1st data may be not the sync (thread vs sequential code) as the old blocking recv // Changing to Ian's udp code. It is non blocking. Now the sync between instance could not be get each time (bug), because 1st data may be not the sync (thread vs sequential code) as the old blocking recv
// ---> setting pause, moving window make lost connection now and bug the game // ---> setting pause, moving window make lost connection now and bug the game
// ---> crash when quit. Assumption : may be supermodel close while udp thread running ? // ---> crash when quit. Assumption : may be supermodel close while udp thread running ?
@ -76,9 +76,8 @@
#include "NetBoard.h" #include "NetBoard.h"
#include "Util/Format.h" #include "Util/Format.h"
#include "Util/ByteSwap.h" #include "Util/ByteSwap.h"
#include <thread> #include "TCPSend.h"
#include "UDPSend.h" #include "TCPReceive.h"
#include "UDPReceive.h"
// few macros to make debugging a bit less painful // few macros to make debugging a bit less painful
// if NET_DEBUG is defined, printf works normally, otherwise it's compiled to nothing (ie removed) // if NET_DEBUG is defined, printf works normally, otherwise it's compiled to nothing (ie removed)
@ -98,8 +97,6 @@
#define SAFE_ARRAY_DELETE(x) delete[] x; x = NULL; #define SAFE_ARRAY_DELETE(x) delete[] x; x = NULL;
#endif #endif
using namespace SMUDP;
static int(*Runnet68kCB)(int cycles); static int(*Runnet68kCB)(int cycles);
static void(*Intnet68kCB)(int irq); static void(*Intnet68kCB)(int irq);
@ -148,7 +145,7 @@ UINT8 CNetBoard::Read8(UINT32 a)
{ {
case 0x0: case 0x0:
//printf("Netboard R8\tRAM[%x]=%x\n", a,RAM[a]); //printf("Netboard R8\tRAM[%x]=%x\n", a,RAM[a]);
if (a > 0x0ffff) if (a > 0x0ffff)
{ {
printf("OUT OF RANGE RAM[%x]\n", a); printf("OUT OF RANGE RAM[%x]\n", a);
MessageBox(NULL, "Out of Range", NULL, MB_OK); MessageBox(NULL, "Out of Range", NULL, MB_OK);
@ -167,7 +164,7 @@ UINT8 CNetBoard::Read8(UINT32 a)
switch (a & 0xff) switch (a & 0xff)
{ {
case 0x0: case 0x0:
DPRINTF("Netboard R8\tctrlrw[%x]=%x\tcommbank = %x\n", a & 0xff, ctrlrw[a & 0xff], commbank); DPRINTF("Netboard R8\tctrlrw[%x]=%x\tcommbank = %x\n", a & 0xff, ctrlrw[a & 0xff], commbank);
return ctrlrw[a&0xff];//commbank; return ctrlrw[a&0xff];//commbank;
break; break;
@ -199,14 +196,14 @@ UINT8 CNetBoard::Read8(UINT32 a)
MessageBox(NULL, "Out of Range", NULL, MB_OK); MessageBox(NULL, "Out of Range", NULL, MB_OK);
//MessageBeep(MB_ICONWARNING); //MessageBeep(MB_ICONWARNING);
} }
switch (a & 0xff) switch (a & 0xff)
{ {
case 0x11: // ioreg[c0011] case 0x11: // ioreg[c0011]
DPRINTF("Netboard R8\tioreg[%x]=%x\t\treceive result status\n", a & 0xff, ioreg[a & 0xff]); DPRINTF("Netboard R8\tioreg[%x]=%x\t\treceive result status\n", a & 0xff, ioreg[a & 0xff]);
//return 0x5; /////////////////////////////////// pure hack for spikofe - must have the pure hack spikeout enable too /////////////////////////////////////////////////////// //return 0x5; /////////////////////////////////// pure hack for spikofe - must have the pure hack spikeout enable too ///////////////////////////////////////////////////////
if (Gameinfo.name.compare("spikeofe") == 0) return 0x5; if (Gameinfo.name.compare("spikeofe") == 0) return 0x5;
return ioreg[a&0xff]; return ioreg[a&0xff];
break; break;
case 0x19: // ioreg[c0019] case 0x19: // ioreg[c0019]
@ -278,7 +275,7 @@ UINT16 CNetBoard::Read16(UINT32 a)
//MessageBeep(MB_ICONWARNING); //MessageBeep(MB_ICONWARNING);
MessageBox(NULL, "Out of Range", NULL, MB_OK); MessageBox(NULL, "Out of Range", NULL, MB_OK);
} }
switch (a & 0xff) switch (a & 0xff)
{ {
case 0x0: case 0x0:
@ -316,7 +313,7 @@ UINT16 CNetBoard::Read16(UINT32 a)
MessageBox(NULL, "Out of Range", NULL, MB_OK); MessageBox(NULL, "Out of Range", NULL, MB_OK);
//MessageBeep(MB_ICONWARNING); //MessageBeep(MB_ICONWARNING);
} }
switch (a & 0xff) switch (a & 0xff)
{ {
case 0x88: // ioreg[c0088] case 0x88: // ioreg[c0088]
@ -420,7 +417,7 @@ void CNetBoard::Write8(UINT32 a, UINT8 d)
switch ((a >> 16) & 0xF) switch ((a >> 16) & 0xF)
{ {
case 0x0: case 0x0:
//printf("Netboard Write8 (0x0) \tRAM[%x] <- %x\n", a, d); //printf("Netboard Write8 (0x0) \tRAM[%x] <- %x\n", a, d);
if (a > 0x0ffff) if (a > 0x0ffff)
{ {
printf("OUT OF RANGE RAM[%x]\n", a); printf("OUT OF RANGE RAM[%x]\n", a);
@ -472,7 +469,7 @@ void CNetBoard::Write8(UINT32 a, UINT8 d)
break; break;
} }
break; break;
case 0x8: // dirt devils case 0x8: // dirt devils
@ -513,11 +510,11 @@ void CNetBoard::Write8(UINT32 a, UINT8 d)
ioreg[a & 0xff] = d; ioreg[a & 0xff] = d;
DPRINTF("Netboard W8\tioreg[%x] <- %x\n", a & 0xff, d); DPRINTF("Netboard W8\tioreg[%x] <- %x\n", a & 0xff, d);
break; break;
/*case 0x15: // 0x00 0x01 0x80 // ioreg[c0015] /*case 0x15: // 0x00 0x01 0x80 // ioreg[c0015]
ioreg[a & 0xff] = d; ioreg[a & 0xff] = d;
printf("Netboard W8\tioreg[%x] <- %x\t\t", a & 0xff, d); printf("Netboard W8\tioreg[%x] <- %x\t\t", a & 0xff, d);
if ((d & 0xFF) != 0x80) if ((d & 0xFF) != 0x80)
{ {
if ((d & 0xFF) == 0x01) if ((d & 0xFF) == 0x01)
@ -547,7 +544,7 @@ void CNetBoard::Write8(UINT32 a, UINT8 d)
{ {
printf("receive enable off=%x size=%x\n", recv_offset, recv_size); printf("receive enable off=%x size=%x\n", recv_offset, recv_size);
printf("receiving : "); printf("receiving : ");
recv_size = recv_size & 0x7fff; recv_size = recv_size & 0x7fff;
receive2(CommRAM + recv_offset, recv_size, recv_offset); receive2(CommRAM + recv_offset, recv_size, recv_offset);
@ -585,7 +582,7 @@ void CNetBoard::Write8(UINT32 a, UINT8 d)
// 15 and 17 = receive part // 15 and 17 = receive part
// master starts with 1b 15 17 (set id node) 1d // master starts with 1b 15 17 (set id node) 1d
// slave follow with 15 17 then (set id node) 1b 1d // slave follow with 15 17 then (set id node) 1b 1d
case 0x15: // 0x00 0x01 0x80 // ioreg[c0015] case 0x15: // 0x00 0x01 0x80 // ioreg[c0015]
ioreg[a & 0xff] = d; ioreg[a & 0xff] = d;
DPRINTF("Netboard W8\tioreg[%x] <- %x\t\t", a & 0xff, d); DPRINTF("Netboard W8\tioreg[%x] <- %x\t\t", a & 0xff, d);
@ -594,7 +591,7 @@ void CNetBoard::Write8(UINT32 a, UINT8 d)
{ {
case 0x80: case 0x80:
DPRINTF("\nreceiving : \n"); DPRINTF("\nreceiving : \n");
//if (recv_offset > 0x1000) //if (recv_offset > 0x1000)
if (recv_size < 0x0019) // must find a better condition if (recv_size < 0x0019) // must find a better condition
{ {
@ -602,15 +599,10 @@ void CNetBoard::Write8(UINT32 a, UINT8 d)
//printf("-> nb recu : %x\n", recv_data.size()); //printf("-> nb recu : %x\n", recv_data.size());
//memcpy(CommRAM + recv_offset, recv_data.data(), recv_data.size()); //memcpy(CommRAM + recv_offset, recv_data.data(), recv_data.size());
//DPRINTF("receive enable off=%x size=%x\n", recv_offset, recv_size); //DPRINTF("receive enable off=%x size=%x\n", recv_offset, recv_size);
UINT16 s = 0;
std::vector <uint8_t> recv_data;
do DPRINTF("receive enable off=%x size=%x\n", recv_offset, recv_size);
{ auto &recv_data = netr->Receive();
recv_data = udpReceive.ReadData(500);
DPRINTF("-> nb recu : %x\n", recv_data.size());
s = recv_data.size();
DPRINTF("receive enable off=%x size=%x\n", recv_offset, recv_size);
} while (s == 0);
memcpy(CommRAM + recv_offset, recv_data.data(), recv_data.size()); memcpy(CommRAM + recv_offset, recv_data.data(), recv_data.size());
} }
else else
@ -629,7 +621,8 @@ void CNetBoard::Write8(UINT32 a, UINT8 d)
//printf("receive enable off=%x size=%x slot=%x\n", recv_offset, recv_size, slot); //printf("receive enable off=%x size=%x slot=%x\n", recv_offset, recv_size, slot);
auto recv_data = udpReceive.ReadData(5000); //auto recv_data = udpReceive.ReadData(5000);
auto &recv_data = netr->Receive();
DPRINTF("-> nb recu : %x\n", recv_data.size()); DPRINTF("-> nb recu : %x\n", recv_data.size());
memcpy(CommRAM + recv_offset, recv_data.data(), recv_data.size()); memcpy(CommRAM + recv_offset, recv_data.data(), recv_data.size());
} }
@ -701,14 +694,15 @@ void CNetBoard::Write8(UINT32 a, UINT8 d)
case 0x1b: // 0x80 // ioreg[c001b] case 0x1b: // 0x80 // ioreg[c001b]
ioreg[a & 0xff] = d; ioreg[a & 0xff] = d;
DPRINTF("Netboard W8\tioreg[%x] <- %x\t\t\n", a & 0xff, d); DPRINTF("Netboard W8\tioreg[%x] <- %x\t\t\n", a & 0xff, d);
switch (d & 0xff) switch (d & 0xff)
{ {
case 0x80: case 0x80:
//if (send_offset > 0x1000) //if (send_offset > 0x1000)
if (send_size < 0x0011) // must find a better condition if (send_size < 0x0011) // must find a better condition
{ {
udpSend.SendAsync(addr_out.data(), port_out, send_size, (const char*)CommRAM + send_offset, 1000); //udpSend.SendAsync(addr_out.data(), port_out, send_size, (const char*)CommRAM + send_offset, 1000);
nets->Send((const char*)CommRAM + send_offset, send_size);
DPRINTF("send enable off=%x size=%x\n", send_offset, send_size); DPRINTF("send enable off=%x size=%x\n", send_offset, send_size);
} }
@ -738,7 +732,8 @@ void CNetBoard::Write8(UINT32 a, UINT8 d)
} }
send_offset = (send_offset << 8) | (send_offset >> 8); send_offset = (send_offset << 8) | (send_offset >> 8);
udpSend.SendAsync(addr_out.data(), port_out, send_size, (const char*)CommRAM + send_offset, 1000); //udpSend.SendAsync(addr_out.data(), port_out, send_size, (const char*)CommRAM + send_offset, 1000);
nets->Send((const char*)CommRAM + send_offset, send_size);
DPRINTF("send enable off=%x size=%x slot=%x\n", send_offset, send_size, slot); DPRINTF("send enable off=%x size=%x slot=%x\n", send_offset, send_size, slot);
} }
@ -761,11 +756,11 @@ void CNetBoard::Write8(UINT32 a, UINT8 d)
printf("\n"); printf("\n");
#endif #endif
break; break;
case 0x00: case 0x00:
DPRINTF("??? transmit disable\n"); DPRINTF("??? transmit disable\n");
break; break;
default: default:
printf("1b : other value %x\n", d & 0xff); printf("1b : other value %x\n", d & 0xff);
break; break;
@ -779,7 +774,7 @@ void CNetBoard::Write8(UINT32 a, UINT8 d)
switch (d & 0xff) switch (d & 0xff)
{ {
case 0x8c: case 0x8c:
M68KSetIRQ(6); //obligatoire (pas de irq4, pas de ack, pas de cycle) irq4 : harley master other board not ready or... M68KSetIRQ(6); //obligatoire (pas de irq4, pas de ack, pas de cycle) irq4 : harley master other board not ready or...
M68KRun(10000); M68KRun(10000);
break; break;
@ -797,7 +792,7 @@ void CNetBoard::Write8(UINT32 a, UINT8 d)
ioreg[a & 0xff] = d; ioreg[a & 0xff] = d;
DPRINTF("Netboard W8\tioreg[%x] <- %x\n", a & 0xff, d); DPRINTF("Netboard W8\tioreg[%x] <- %x\n", a & 0xff, d);
break; break;
case 0x2f: // 0x00 or 0x00->0x40->0x00 or 0x82// ioreg[c002f] case 0x2f: // 0x00 or 0x00->0x40->0x00 or 0x82// ioreg[c002f]
ioreg[a & 0xff] = d; ioreg[a & 0xff] = d;
DPRINTF("Netboard W8\tioreg[%x] <- %x\n", a & 0xff, d); DPRINTF("Netboard W8\tioreg[%x] <- %x\n", a & 0xff, d);
@ -907,7 +902,7 @@ void CNetBoard::Write8(UINT32 a, UINT8 d)
DPRINTF("Netboard W8\tioreg[%x] <- %x\n", a & 0xff, d); DPRINTF("Netboard W8\tioreg[%x] <- %x\n", a & 0xff, d);
break; break;
case 0x89: // ioreg[c0089] // dayto2pe loops with values 00 01 02 during type 2 trame case 0x89: // ioreg[c0089] // dayto2pe loops with values 00 01 02 during type 2 trame
ioreg[a & 0xff] = d; ioreg[a & 0xff] = d;
//CommRAM[4] = d; /////////////////////////////////// pure hack for spikeout ///////////////////////////////////////////////////////////////////////////////////////////// //CommRAM[4] = d; /////////////////////////////////// pure hack for spikeout /////////////////////////////////////////////////////////////////////////////////////////////
if (Gameinfo.name.compare("spikeout") == 0 || Gameinfo.name.compare("spikeofe") == 0) CommRAM[4] = d; if (Gameinfo.name.compare("spikeout") == 0 || Gameinfo.name.compare("spikeofe") == 0) CommRAM[4] = d;
@ -938,7 +933,7 @@ void CNetBoard::Write8(UINT32 a, UINT8 d)
default: default:
printf("NetBoard 68K: Unknown W8 (%x) %06X<-%02X\n", (a >> 16) & 0xF, a, d); printf("NetBoard 68K: Unknown W8 (%x) %06X<-%02X\n", (a >> 16) & 0xF, a, d);
MessageBox(NULL, "Unknown W8", NULL, MB_OK); MessageBox(NULL, "Unknown W8", NULL, MB_OK);
//MessageBeep(MB_ICONWARNING); //MessageBeep(MB_ICONWARNING);
break; break;
} }
@ -958,7 +953,7 @@ void CNetBoard::Write16(UINT32 a, UINT16 d)
} }
*(UINT16 *)&RAM[a] = d; *(UINT16 *)&RAM[a] = d;
break; break;
case 0x4: case 0x4:
//printf("Netboard W16\tctrlrw[%x] <- %x\t", a&0xff, d); //printf("Netboard W16\tctrlrw[%x] <- %x\t", a&0xff, d);
if ((a & 0xfff) > 0xff) if ((a & 0xfff) > 0xff)
@ -993,7 +988,7 @@ void CNetBoard::Write16(UINT32 a, UINT16 d)
case 0x40: case 0x40:
*(UINT16 *)&ctrlrw[a & 0xff] = d; *(UINT16 *)&ctrlrw[a & 0xff] = d;
DPRINTF("Netboard W16\tctrlrw[%x] <- %x\t\tIRQ 5 ack\n", a & 0xff, d); DPRINTF("Netboard W16\tctrlrw[%x] <- %x\t\tIRQ 5 ack\n", a & 0xff, d);
NetIRQAck(5); NetIRQAck(5);
M68KSetIRQ(4); // ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????? M68KSetIRQ(4); // ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????
//M68KRun(10000); //M68KRun(10000);
@ -1002,7 +997,7 @@ void CNetBoard::Write16(UINT32 a, UINT16 d)
*(UINT16 *)&ctrlrw[a & 0xff] = d; *(UINT16 *)&ctrlrw[a & 0xff] = d;
*(UINT8 *)&ioreg[0] = *(UINT8 *)&ioreg[0] | 0x01; // Do I force this myself or is it automatic, need investigation, bad init way actually ? *(UINT8 *)&ioreg[0] = *(UINT8 *)&ioreg[0] | 0x01; // Do I force this myself or is it automatic, need investigation, bad init way actually ?
DPRINTF("Netboard W16\tctrlrw[%x] <-%x\t\tIRQ 2 ack\n", a & 0xff, d); DPRINTF("Netboard W16\tctrlrw[%x] <-%x\t\tIRQ 2 ack\n", a & 0xff, d);
NetIRQAck(2); NetIRQAck(2);
//NetIRQAck(0); //NetIRQAck(0);
break; break;
@ -1033,7 +1028,7 @@ void CNetBoard::Write16(UINT32 a, UINT16 d)
if ((a & 0x3ffff) > 0xffff) if ((a & 0x3ffff) > 0xffff)
{ {
printf("OUT OF RANGE CommRAM[%x]\n", a); printf("OUT OF RANGE CommRAM[%x]\n", a);
MessageBox(NULL, "Out of Range", NULL, MB_OK); MessageBox(NULL, "Out of Range", NULL, MB_OK);
//MessageBeep(MB_ICONWARNING); //MessageBeep(MB_ICONWARNING);
} }
*(UINT16 *)&CommRAM[a & 0xffff] = d; *(UINT16 *)&CommRAM[a & 0xffff] = d;
@ -1047,18 +1042,18 @@ void CNetBoard::Write16(UINT32 a, UINT16 d)
MessageBox(NULL, "Out of Range", NULL, MB_OK); MessageBox(NULL, "Out of Range", NULL, MB_OK);
//MessageBeep(MB_ICONWARNING); //MessageBeep(MB_ICONWARNING);
} }
switch (a & 0xff) switch (a & 0xff)
{ {
case 0x88: // ioreg[c0088] case 0x88: // ioreg[c0088]
// register value change, do I made something special here ???? // register value change, do I made something special here ????
if (d == 0) if (d == 0)
{ {
*(UINT16 *)&ioreg[a & 0xff] = d; *(UINT16 *)&ioreg[a & 0xff] = d;
DPRINTF("Netboard W16\tioreg[%x] <- %x\t\t", a & 0xff, d); DPRINTF("Netboard W16\tioreg[%x] <- %x\t\t", a & 0xff, d);
} }
if (d == 1) if (d == 1)
{ {
*(UINT16 *)&ioreg[a & 0xff] = d; *(UINT16 *)&ioreg[a & 0xff] = d;
DPRINTF("Netboard W16\tioreg[%x] <- %x\t\t", a & 0xff, d); DPRINTF("Netboard W16\tioreg[%x] <- %x\t\t", a & 0xff, d);
@ -1070,19 +1065,19 @@ void CNetBoard::Write16(UINT32 a, UINT16 d)
DPRINTF("Netboard W16\tioreg[%x] <- %x\t\t", a & 0xff, d); DPRINTF("Netboard W16\tioreg[%x] <- %x\t\t", a & 0xff, d);
} }
if (d > 2) if (d > 2)
{ {
DPRINTF("d=%x\n", d); DPRINTF("d=%x\n", d);
*(UINT16 *)&ioreg[a & 0xff] = d; *(UINT16 *)&ioreg[a & 0xff] = d;
//MessageBox(NULL, "d > 1", NULL, MB_OK); //MessageBox(NULL, "d > 1", NULL, MB_OK);
//MessageBeep(MB_ICONWARNING); //MessageBeep(MB_ICONWARNING);
} }
DPRINTF("d = %x \n",d); DPRINTF("d = %x \n",d);
M68KSetIRQ(4); // network error if removed M68KSetIRQ(4); // network error if removed
M68KRun(1000); // 1000 is enough M68KRun(1000); // 1000 is enough
M68KSetIRQ(2); // oui sinon pas de trame, pas de cycle sinon crash M68KSetIRQ(2); // oui sinon pas de trame, pas de cycle sinon crash
break; break;
case 0x8a: // ioreg[c008a] case 0x8a: // ioreg[c008a]
@ -1098,13 +1093,13 @@ void CNetBoard::Write16(UINT32 a, UINT16 d)
break; break;
} }
//M68KSetIRQ(2); // oui sinon pas de trame, pas de cycle sinon crash //M68KSetIRQ(2); // oui sinon pas de trame, pas de cycle sinon crash
//M68KRun(40000); //M68KRun(40000);
break; break;
default: default:
printf("NetBoard 68K: Unknown W16 (%x) %06X<-%04X\n", (a >> 16) & 0xF,a, d); printf("NetBoard 68K: Unknown W16 (%x) %06X<-%04X\n", (a >> 16) & 0xF,a, d);
MessageBox(NULL, "Unknown W16", NULL, MB_OK); MessageBox(NULL, "Unknown W16", NULL, MB_OK);
//MessageBeep(MB_ICONWARNING); //MessageBeep(MB_ICONWARNING);
break; break;
} }
@ -1168,7 +1163,7 @@ void CNetBoard::Write32(UINT32 a, UINT32 d)
default: default:
printf("NetBoard 68K: Unknown W32 (%x) %08X<-%08X\n", (a >> 16) & 0xF,a, d); printf("NetBoard 68K: Unknown W32 (%x) %08X<-%08X\n", (a >> 16) & 0xF,a, d);
MessageBox(NULL, "Unknown W32", NULL, MB_OK); MessageBox(NULL, "Unknown W32", NULL, MB_OK);
//MessageBeep(MB_ICONWARNING); //MessageBeep(MB_ICONWARNING);
break; break;
} }
@ -1227,10 +1222,10 @@ bool CNetBoard::Init(UINT8 * netRAMPtr, UINT8 *netBufferPtr)
Buffer = CommRAM; // for swap test Buffer = CommRAM; // for swap test
ioreg = netBuffer + 0x10000; ioreg = netBuffer + 0x10000;
ctrlrw = ct; ctrlrw = ct;
printf("Init netboard netbuffer=%x netram=%x CommRAM=%x ioreg=%x ctrlrw=%x bank=%x\n", netBuffer, netRAM, CommRAM, ioreg, ctrlrw,bank); printf("Init netboard\n");
// Initialize 68K core // Initialize 68K core
@ -1247,7 +1242,15 @@ bool CNetBoard::Init(UINT8 * netRAMPtr, UINT8 *netBufferPtr)
port_in = m_config["port_in"].ValueAs<unsigned>(); port_in = m_config["port_in"].ValueAs<unsigned>();
port_out = m_config["port_out"].ValueAs<unsigned>(); port_out = m_config["port_out"].ValueAs<unsigned>();
addr_out = m_config["addr_out"].ValueAs<std::string>(); addr_out = m_config["addr_out"].ValueAs<std::string>();
udpReceive.Bind(port_in);
nets = std::make_unique<TCPSend>(addr_out, port_out);
netr = std::make_unique<TCPReceive>(port_in);
while (!nets->Connect()) {
printf("Connecting to %s:%i ..\n", addr_out.c_str(), port_out);
}
printf("Successfully connected.\n");
return OKAY; return OKAY;
} }
@ -1284,7 +1287,7 @@ CNetBoard::~CNetBoard(void)
CommRAM = NULL; CommRAM = NULL;
ioreg = NULL; ioreg = NULL;
ctrlrw = NULL; ctrlrw = NULL;
/*if (int5 == true) /*if (int5 == true)
{ {
int5 = false; int5 = false;
@ -1306,16 +1309,16 @@ bool CNetBoard::RunFrame(void)
{ {
return true; return true;
} }
M68KSetContext(&M68K); M68KSetContext(&M68K);
/*if (int5 == false) /*if (int5 == false)
{ {
int5 = true; int5 = true;
interrupt5 = std::thread([this] { inter5(); }); interrupt5 = std::thread([this] { inter5(); });
}*/ }*/
M68KSetIRQ(5); // apparently, must be called every xx milli secondes or every frames or 3-4 in a frame M68KSetIRQ(5); // apparently, must be called every xx milli secondes or every frames or 3-4 in a frame
/*if (test_irq == 0 || test_irq<2) /*if (test_irq == 0 || test_irq<2)
{ {
@ -1330,12 +1333,12 @@ bool CNetBoard::RunFrame(void)
M68KRun((4000000 / 60)); // original M68KRun((4000000 / 60)); // original
//M68KRun((4000000 / 60)*3); // 12Mhz //M68KRun((4000000 / 60)*3); // 12Mhz
//printf("NetBoard PC=%06X\n", M68KGetPC()); //printf("NetBoard PC=%06X\n", M68KGetPC());
//M68KSetIRQ(6); //M68KSetIRQ(6);
//M68KRun(10000); //M68KRun(10000);
// 3 times more avoid network error canceled on certain games (certainly due to irq5 that would be calling 3-4 times in a frame) // 3 times more avoid network error canceled on certain games (certainly due to irq5 that would be calling 3-4 times in a frame)
M68KSetIRQ(5); M68KSetIRQ(5);
M68KRun((4000000 / 60)); M68KRun((4000000 / 60));
@ -1352,14 +1355,14 @@ bool CNetBoard::RunFrame(void)
void CNetBoard::Reset(void) void CNetBoard::Reset(void)
{ {
/*********************************************************************************************/ /*********************************************************************************************/
commbank = 0; commbank = 0;
recv_offset=0; recv_offset=0;
recv_size=0; recv_size=0;
send_offset=0; send_offset=0;
send_size=0; send_size=0;
// uncomment to dump network memory for analyse with IDA or 68k disasm // uncomment to dump network memory for analyse with IDA or 68k disasm
/*FILE *test; /*FILE *test;
Util::FlipEndian16(netRAM, 0x8000); //flip endian for IDA dump only Util::FlipEndian16(netRAM, 0x8000); //flip endian for IDA dump only
@ -1368,13 +1371,13 @@ void CNetBoard::Reset(void)
fclose(test); fclose(test);
Util::FlipEndian16(netRAM, 0x8000);*/ Util::FlipEndian16(netRAM, 0x8000);*/
M68KSetContext(&M68K); M68KSetContext(&M68K);
printf("RESET NetBoard PC=%06X\n", M68KGetPC()); printf("RESET NetBoard PC=%06X\n", M68KGetPC());
M68KReset(); M68KReset();
M68KGetContext(&M68K); M68KGetContext(&M68K);
} }
M68KCtx * CNetBoard::GetM68K(void) M68KCtx * CNetBoard::GetM68K(void)

View file

@ -6,9 +6,9 @@
#include "OSD/Thread.h" #include "OSD/Thread.h"
#include <winsock2.h> #include <winsock2.h>
#include <ws2tcpip.h> #include <ws2tcpip.h>
#include <thread> #include <memory>
#include "UDPSend.h" #include "TCPSend.h"
#include "UDPReceive.h" #include "TCPReceive.h"
//#define NET_BUF_SIZE 32800 // 16384 not enough //#define NET_BUF_SIZE 32800 // 16384 not enough
@ -36,7 +36,7 @@ public:
bool CodeReady; bool CodeReady;
bool Init(UINT8 *netRAMPtr, UINT8 *netBufferPtr); bool Init(UINT8 *netRAMPtr, UINT8 *netBufferPtr);
void GetGame(Game); void GetGame(Game);
CNetBoard(const Util::Config::Node &config); CNetBoard(const Util::Config::Node &config);
@ -72,8 +72,8 @@ private:
UINT16 port_out = 0; UINT16 port_out = 0;
std::string addr_out = ""; std::string addr_out = "";
SMUDP::UDPSend udpSend; std::unique_ptr<TCPSend> nets;
SMUDP::UDPReceive udpReceive; std::unique_ptr<TCPReceive> netr;
//game info //game info
Game Gameinfo; Game Gameinfo;

View file

@ -3,6 +3,13 @@
using namespace std::chrono_literals; using namespace std::chrono_literals;
#if defined(_DEBUG)
#include <stdio.h>
#define DPRINTF printf
#else
#define DPRINTF(a, ...)
#endif
TCPReceive::TCPReceive(int port) : TCPReceive::TCPReceive(int port) :
m_listenSocket(nullptr), m_listenSocket(nullptr),
m_receiveSocket(nullptr) m_receiveSocket(nullptr)
@ -45,7 +52,7 @@ TCPReceive::~TCPReceive()
std::vector<char>& TCPReceive::Receive() std::vector<char>& TCPReceive::Receive()
{ {
if (!m_receiveSocket) { if (!m_receiveSocket) {
printf("return here because no socket\n"); DPRINTF("Can't receive because no socket.\n");
m_recBuffer.clear(); m_recBuffer.clear();
return m_recBuffer; return m_recBuffer;
} }
@ -54,7 +61,7 @@ std::vector<char>& TCPReceive::Receive()
int result = 0; int result = 0;
result = SDLNet_TCP_Recv(m_receiveSocket, &size, sizeof(int)); result = SDLNet_TCP_Recv(m_receiveSocket, &size, sizeof(int));
printf("received %i\n", result); DPRINTF("Received %i bytes\n", result);
if (result <= 0) { if (result <= 0) {
SDLNet_TCP_Close(m_receiveSocket); SDLNet_TCP_Close(m_receiveSocket);
m_receiveSocket = nullptr; m_receiveSocket = nullptr;
@ -66,7 +73,7 @@ std::vector<char>& TCPReceive::Receive()
while (size) { while (size) {
result = SDLNet_TCP_Recv(m_receiveSocket, m_recBuffer.data() + (m_recBuffer.size() - size), size); result = SDLNet_TCP_Recv(m_receiveSocket, m_recBuffer.data() + (m_recBuffer.size() - size), size);
printf("received %i\n", result); DPRINTF("Received %i bytes\n", result);
if (result <= 0) { if (result <= 0) {
SDLNet_TCP_Close(m_receiveSocket); SDLNet_TCP_Close(m_receiveSocket);
m_receiveSocket = nullptr; m_receiveSocket = nullptr;
@ -90,7 +97,7 @@ void TCPReceive::ListenFunc()
if (socket) { if (socket) {
m_receiveSocket = socket; m_receiveSocket = socket;
printf("accepted a connectio\n"); DPRINTF("Accepted connection.\n");
} }
} }

View file

@ -1,11 +1,17 @@
#include "TCPSend.h" #include "TCPSend.h"
#if defined(_DEBUG)
#include <stdio.h>
#define DPRINTF printf
#else
#define DPRINTF(a, ...)
#endif
static const int RETRY_COUNT = 10; // shrugs static const int RETRY_COUNT = 10; // shrugs
TCPSend::TCPSend(std::string& ip, int port) : TCPSend::TCPSend(std::string& ip, int port) :
m_ip(ip), m_ip(ip),
m_port(port), m_port(port),
m_tryCount(0),
m_socket(nullptr) m_socket(nullptr)
{ {
SDLNet_Init(); SDLNet_Init();
@ -23,19 +29,14 @@ TCPSend::~TCPSend()
bool TCPSend::Send(const void * data, int length) bool TCPSend::Send(const void * data, int length)
{ {
printf("trying to send data %i\n", length);
// If we aren't connected make a connection
if (!Connected()) {
Connect();
printf("trying to connect\n");
}
// If we failed bail out // If we failed bail out
if (!Connected()) { if (!Connected()) {
printf("not connected\n"); DPRINTF("Not connected\n");
return false; return false;
} }
DPRINTF("Sending %i bytes\n", length);
if (!length) { if (!length) {
return true; // 0 sized packet will blow our connex return true; // 0 sized packet will blow our connex
} }
@ -50,7 +51,7 @@ bool TCPSend::Send(const void * data, int length)
m_socket = nullptr; m_socket = nullptr;
} }
return false; return true;
} }
bool TCPSend::Connected() bool TCPSend::Connected()
@ -58,12 +59,8 @@ bool TCPSend::Connected()
return m_socket != 0; return m_socket != 0;
} }
void TCPSend::Connect() bool TCPSend::Connect()
{ {
if (m_tryCount >= RETRY_COUNT) {
return; // already tried and failed so bail out. We do this as instances might load diff times
}
IPaddress ip; IPaddress ip;
int result = SDLNet_ResolveHost(&ip, m_ip.c_str(), m_port); int result = SDLNet_ResolveHost(&ip, m_ip.c_str(), m_port);
@ -71,5 +68,5 @@ void TCPSend::Connect()
m_socket = SDLNet_TCP_Open(&ip); m_socket = SDLNet_TCP_Open(&ip);
} }
m_tryCount++; return Connected();
} }

View file

@ -11,15 +11,12 @@ public:
~TCPSend(); ~TCPSend();
bool Send(const void* data, int length); bool Send(const void* data, int length);
bool Connect();
bool Connected(); bool Connected();
private: private:
void Connect();
std::string m_ip; std::string m_ip;
int m_port; int m_port;
bool m_connected;
int m_tryCount;
TCPsocket m_socket; // sdl socket TCPsocket m_socket; // sdl socket
}; };

View file

@ -341,9 +341,6 @@ xcopy /D /Y "$(ProjectDir)..\Config\*" "$(TargetDir)Config"</Command>
<ClCompile Include="..\Src\Network\NetBoard.cpp" /> <ClCompile Include="..\Src\Network\NetBoard.cpp" />
<ClCompile Include="..\Src\Network\TCPReceive.cpp" /> <ClCompile Include="..\Src\Network\TCPReceive.cpp" />
<ClCompile Include="..\Src\Network\TCPSend.cpp" /> <ClCompile Include="..\Src\Network\TCPSend.cpp" />
<ClCompile Include="..\Src\Network\UDPReceive.cpp" />
<ClCompile Include="..\Src\Network\UDPSend.cpp" />
<ClCompile Include="..\Src\Network\WinSockWrap.cpp" />
<ClCompile Include="..\Src\OSD\Logger.cpp" /> <ClCompile Include="..\Src\OSD\Logger.cpp" />
<ClCompile Include="..\Src\OSD\Outputs.cpp" /> <ClCompile Include="..\Src\OSD\Outputs.cpp" />
<ClCompile Include="..\Src\OSD\SDL\Audio.cpp" /> <ClCompile Include="..\Src\OSD\SDL\Audio.cpp" />
@ -515,10 +512,6 @@ xcopy /D /Y "$(ProjectDir)..\Config\*" "$(TargetDir)Config"</Command>
<ClInclude Include="..\Src\Network\NetBoard.h" /> <ClInclude Include="..\Src\Network\NetBoard.h" />
<ClInclude Include="..\Src\Network\TCPReceive.h" /> <ClInclude Include="..\Src\Network\TCPReceive.h" />
<ClInclude Include="..\Src\Network\TCPSend.h" /> <ClInclude Include="..\Src\Network\TCPSend.h" />
<ClInclude Include="..\Src\Network\UDPPacket.h" />
<ClInclude Include="..\Src\Network\UDPReceive.h" />
<ClInclude Include="..\Src\Network\UDPSend.h" />
<ClInclude Include="..\Src\Network\WinSockWrap.h" />
<ClInclude Include="..\Src\OSD\Audio.h" /> <ClInclude Include="..\Src\OSD\Audio.h" />
<ClInclude Include="..\Src\OSD\Logger.h" /> <ClInclude Include="..\Src\OSD\Logger.h" />
<ClInclude Include="..\Src\OSD\Outputs.h" /> <ClInclude Include="..\Src\OSD\Outputs.h" />

View file

@ -416,15 +416,6 @@
<ClCompile Include="..\Src\Model3\JTAG.cpp"> <ClCompile Include="..\Src\Model3\JTAG.cpp">
<Filter>Source Files\Model3</Filter> <Filter>Source Files\Model3</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\Src\Network\UDPReceive.cpp">
<Filter>Source Files\Network</Filter>
</ClCompile>
<ClCompile Include="..\Src\Network\UDPSend.cpp">
<Filter>Source Files\Network</Filter>
</ClCompile>
<ClCompile Include="..\Src\Network\WinSockWrap.cpp">
<Filter>Source Files\Network</Filter>
</ClCompile>
<ClCompile Include="..\Src\Network\NetBoard.cpp"> <ClCompile Include="..\Src\Network\NetBoard.cpp">
<Filter>Source Files\Network</Filter> <Filter>Source Files\Network</Filter>
</ClCompile> </ClCompile>
@ -778,18 +769,6 @@
<ClInclude Include="..\Src\Util\BitRegister.h"> <ClInclude Include="..\Src\Util\BitRegister.h">
<Filter>Header Files\Util</Filter> <Filter>Header Files\Util</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\Src\Network\UDPPacket.h">
<Filter>Header Files\Network</Filter>
</ClInclude>
<ClInclude Include="..\Src\Network\UDPReceive.h">
<Filter>Header Files\Network</Filter>
</ClInclude>
<ClInclude Include="..\Src\Network\UDPSend.h">
<Filter>Header Files\Network</Filter>
</ClInclude>
<ClInclude Include="..\Src\Network\WinSockWrap.h">
<Filter>Header Files\Network</Filter>
</ClInclude>
<ClInclude Include="..\Src\Network\NetBoard.h"> <ClInclude Include="..\Src\Network\NetBoard.h">
<Filter>Header Files\Network</Filter> <Filter>Header Files\Network</Filter>
</ClInclude> </ClInclude>