begin work on proper multiplayer UI shito.

for now, determine a global instance ID, and derivate the system MAC from it. remove 'randomize MAC' option.
This commit is contained in:
Arisotura 2022-09-15 21:22:10 +02:00
parent 139fe5a045
commit 648bf9fa7f
6 changed files with 86 additions and 20 deletions

View File

@ -32,6 +32,9 @@ void DeInit();
void StopEmu(); void StopEmu();
// instance ID, for local multiplayer
int InstanceID();
// configuration values // configuration values
enum ConfigEntry enum ConfigEntry

View File

@ -385,24 +385,23 @@ void Reset()
*(u16*)&Firmware[userdata+0x72] = CRC16(&Firmware[userdata], 0x70, 0xFFFF); *(u16*)&Firmware[userdata+0x72] = CRC16(&Firmware[userdata], 0x70, 0xFFFF);
if (firmoverride) //if (firmoverride)
{ {
u8 mac[6]; u8 mac[6];
bool rep; bool rep = false;
if (Platform::GetConfigBool(Platform::Firm_RandomizeMAC)) memcpy(mac, &Firmware[0x36], 6);
{
mac[0] = 0x00; if (firmoverride)
mac[1] = 0x09;
mac[2] = 0xBF;
mac[3] = rand()&0xFF;
mac[4] = rand()&0xFF;
mac[5] = rand()&0xFF;
rep = true;
}
else
{
rep = Platform::GetConfigArray(Platform::Firm_MAC, mac); rep = Platform::GetConfigArray(Platform::Firm_MAC, mac);
int inst = Platform::InstanceID();
if (inst > 0)
{
rep = true;
mac[3] += inst;
mac[4] += inst*0x44;
mac[5] += inst*0x10;
} }
if (rep) if (rep)

View File

@ -1778,9 +1778,6 @@ u16 Read(u32 addr)
if (activeread) if (activeread)
{ {
u32 rdaddr = IOPORT(W_RXBufReadAddr); u32 rdaddr = IOPORT(W_RXBufReadAddr);
//if (*(u16*)&RAM[(rdaddr - 0x1C) & 0x1FFE] == 0x0228)
// printf("READ SHITTY CMD HEADER %08X\n", NDS::GetPC(1));
u16 ret = *(u16*)&RAM[rdaddr]; u16 ret = *(u16*)&RAM[rdaddr];
rdaddr += 2; rdaddr += 2;

View File

@ -235,7 +235,7 @@ void SemReset(int num)
bool Init() bool Init()
{ {
MPQueue = new QSharedMemory("melonNIFI_FIFO"); MPQueue = new QSharedMemory("melonNIFI");
if (!MPQueue->attach()) if (!MPQueue->attach())
{ {

View File

@ -28,6 +28,7 @@
#include <QSemaphore> #include <QSemaphore>
#include <QMutex> #include <QMutex>
#include <QOpenGLContext> #include <QOpenGLContext>
#include <QSharedMemory>
#include "Platform.h" #include "Platform.h"
#include "Config.h" #include "Config.h"
@ -44,6 +45,55 @@ void emuStop();
namespace Platform namespace Platform
{ {
QSharedMemory* IPCBuffer = nullptr;
int IPCInstanceID;
void IPCInit()
{
IPCInstanceID = 0;
IPCBuffer = new QSharedMemory("melonIPC");
if (!IPCBuffer->attach())
{
printf("IPC sharedmem doesn't exist. creating\n");
if (!IPCBuffer->create(4096))
{
printf("IPC sharedmem create failed :(\n");
delete IPCBuffer;
IPCBuffer= nullptr;
return;
}
IPCBuffer->lock();
memset(IPCBuffer->data(), 0, IPCBuffer->size());
IPCBuffer->unlock();
}
IPCBuffer->lock();
u8* data = (u8*)IPCBuffer->data();
u16 mask = *(u16*)&data[0];
for (int i = 0; i < 16; i++)
{
if (!(mask & (1<<i)))
{
IPCInstanceID = i;
*(u16*)&data[0] |= (1<<i);
break;
}
}
IPCBuffer->unlock();
printf("IPC: instance ID %d\n", IPCInstanceID);
}
void IPCDeInit()
{
if (IPCBuffer) delete IPCBuffer;
IPCBuffer = nullptr;
}
void Init(int argc, char** argv) void Init(int argc, char** argv)
{ {
#if defined(__WIN32__) || defined(PORTABLE) #if defined(__WIN32__) || defined(PORTABLE)
@ -77,10 +127,13 @@ void Init(int argc, char** argv)
confdir = config.absolutePath() + "/melonDS/"; confdir = config.absolutePath() + "/melonDS/";
EmuDirectory = confdir.toStdString(); EmuDirectory = confdir.toStdString();
#endif #endif
IPCInit();
} }
void DeInit() void DeInit()
{ {
IPCDeInit();
} }
@ -90,6 +143,12 @@ void StopEmu()
} }
int InstanceID()
{
return IPCInstanceID;
}
int GetConfigInt(ConfigEntry entry) int GetConfigInt(ConfigEntry entry)
{ {
const int imgsizes[] = {0, 256, 512, 1024, 2048, 4096}; const int imgsizes[] = {0, 256, 512, 1024, 2048, 4096};

View File

@ -647,7 +647,11 @@ void EmuThread::run()
if (winUpdateFreq < 1) if (winUpdateFreq < 1)
winUpdateFreq = 1; winUpdateFreq = 1;
sprintf(melontitle, "[%d/%.0f] melonDS " MELONDS_VERSION, fps, fpstarget); int inst = Platform::InstanceID();
if (inst == 0)
sprintf(melontitle, "[%d/%.0f] melonDS " MELONDS_VERSION, fps, fpstarget);
else
sprintf(melontitle, "[%d/%.0f] melonDS (%d)", fps, fpstarget, inst+1);
changeWindowTitle(melontitle); changeWindowTitle(melontitle);
} }
} }
@ -662,7 +666,11 @@ void EmuThread::run()
EmuStatus = EmuRunning; EmuStatus = EmuRunning;
sprintf(melontitle, "melonDS " MELONDS_VERSION); int inst = Platform::InstanceID();
if (inst == 0)
sprintf(melontitle, "melonDS " MELONDS_VERSION);
else
sprintf(melontitle, "melonDS (%d)", inst+1);
changeWindowTitle(melontitle); changeWindowTitle(melontitle);
SDL_Delay(75); SDL_Delay(75);