diff --git a/src/Platform.h b/src/Platform.h index c502e10b..55a8e9cc 100644 --- a/src/Platform.h +++ b/src/Platform.h @@ -32,6 +32,9 @@ void DeInit(); void StopEmu(); +// instance ID, for local multiplayer +int InstanceID(); + // configuration values enum ConfigEntry diff --git a/src/SPI.cpp b/src/SPI.cpp index 6ecb86c4..8d15656f 100644 --- a/src/SPI.cpp +++ b/src/SPI.cpp @@ -385,24 +385,23 @@ void Reset() *(u16*)&Firmware[userdata+0x72] = CRC16(&Firmware[userdata], 0x70, 0xFFFF); - if (firmoverride) + //if (firmoverride) { u8 mac[6]; - bool rep; + bool rep = false; - if (Platform::GetConfigBool(Platform::Firm_RandomizeMAC)) - { - mac[0] = 0x00; - mac[1] = 0x09; - mac[2] = 0xBF; - mac[3] = rand()&0xFF; - mac[4] = rand()&0xFF; - mac[5] = rand()&0xFF; - rep = true; - } - else - { + memcpy(mac, &Firmware[0x36], 6); + + if (firmoverride) 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) diff --git a/src/Wifi.cpp b/src/Wifi.cpp index b69e5632..5b700e76 100644 --- a/src/Wifi.cpp +++ b/src/Wifi.cpp @@ -1778,9 +1778,6 @@ u16 Read(u32 addr) if (activeread) { 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]; rdaddr += 2; diff --git a/src/frontend/qt_sdl/LocalMP.cpp b/src/frontend/qt_sdl/LocalMP.cpp index 96ad6e3e..cd6eafb4 100644 --- a/src/frontend/qt_sdl/LocalMP.cpp +++ b/src/frontend/qt_sdl/LocalMP.cpp @@ -235,7 +235,7 @@ void SemReset(int num) bool Init() { - MPQueue = new QSharedMemory("melonNIFI_FIFO"); + MPQueue = new QSharedMemory("melonNIFI"); if (!MPQueue->attach()) { diff --git a/src/frontend/qt_sdl/Platform.cpp b/src/frontend/qt_sdl/Platform.cpp index 63f5a147..8f2163ec 100644 --- a/src/frontend/qt_sdl/Platform.cpp +++ b/src/frontend/qt_sdl/Platform.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include "Platform.h" #include "Config.h" @@ -44,6 +45,55 @@ void emuStop(); 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<unlock(); + + printf("IPC: instance ID %d\n", IPCInstanceID); +} + +void IPCDeInit() +{ + if (IPCBuffer) delete IPCBuffer; + IPCBuffer = nullptr; +} + + void Init(int argc, char** argv) { #if defined(__WIN32__) || defined(PORTABLE) @@ -77,10 +127,13 @@ void Init(int argc, char** argv) confdir = config.absolutePath() + "/melonDS/"; EmuDirectory = confdir.toStdString(); #endif + + IPCInit(); } void DeInit() { + IPCDeInit(); } @@ -90,6 +143,12 @@ void StopEmu() } +int InstanceID() +{ + return IPCInstanceID; +} + + int GetConfigInt(ConfigEntry entry) { const int imgsizes[] = {0, 256, 512, 1024, 2048, 4096}; diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 040e4457..ceb19b5f 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -647,7 +647,11 @@ void EmuThread::run() if (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); } } @@ -662,7 +666,11 @@ void EmuThread::run() 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); SDL_Delay(75);