make Platform stuff pull the right EmuInstance.

FUCK THIS IS ATROCIOUS FUCK FUCK FUCK FUCK FUCK FUCK FUCK FUCK
This commit is contained in:
Arisotura 2024-06-03 23:31:30 +02:00
parent 1e9326bf85
commit 5378be51c4
20 changed files with 231 additions and 204 deletions

View File

@ -90,8 +90,8 @@ const u32 NDMAModes[] =
{
}*/
DSi::DSi(DSiArgs&& args) noexcept :
NDS(std::move(args), 1),
DSi::DSi(DSiArgs&& args, void* userdata) noexcept :
NDS(std::move(args), 1, userdata),
NDMAs {
DSi_NDMA(0, 0, *this),
DSi_NDMA(0, 1, *this),

View File

@ -130,7 +130,7 @@ public:
void ARM7IOWrite32(u32 addr, u32 val) override;
public:
DSi(DSiArgs&& args) noexcept;
DSi(DSiArgs&& args, void* userdata = nullptr) noexcept;
//DSi() noexcept;
~DSi() noexcept override;
DSi(const DSi&) = delete;

View File

@ -410,7 +410,7 @@ void DSi_Camera::DoSavestate(Savestate* file)
void DSi_Camera::Reset()
{
Platform::Camera_Stop(Num);
Platform::Camera_Stop(Num, DSi.UserData);
DataPos = 0;
RegAddr = 0;
@ -435,7 +435,7 @@ void DSi_Camera::Reset()
void DSi_Camera::Stop()
{
Platform::Camera_Stop(Num);
Platform::Camera_Stop(Num, DSi.UserData);
}
bool DSi_Camera::IsActivated() const
@ -474,7 +474,7 @@ void DSi_Camera::StartTransfer()
FrameFormat = 0;
}
Platform::Camera_CaptureFrame(Num, FrameBuffer, 640, 480, true);
Platform::Camera_CaptureFrame(Num, FrameBuffer, 640, 480, true, DSi.UserData);
}
bool DSi_Camera::TransferDone() const
@ -655,8 +655,8 @@ void DSi_Camera::I2C_WriteReg(u16 addr, u16 val)
StandbyCnt = val;
//printf("CAM%d STBCNT=%04X (%04X)\n", Num, StandbyCnt, val);
bool isactive = IsActivated();
if (isactive && !wasactive) Platform::Camera_Start(Num);
else if (wasactive && !isactive) Platform::Camera_Stop(Num);
if (isactive && !wasactive) Platform::Camera_Start(Num, DSi.UserData);
else if (wasactive && !isactive) Platform::Camera_Stop(Num, DSi.UserData);
}
return;
case 0x001A:
@ -665,8 +665,8 @@ void DSi_Camera::I2C_WriteReg(u16 addr, u16 val)
MiscCnt = val & 0x0B7B;
//printf("CAM%d MISCCNT=%04X (%04X)\n", Num, MiscCnt, val);
bool isactive = IsActivated();
if (isactive && !wasactive) Platform::Camera_Start(Num);
else if (wasactive && !isactive) Platform::Camera_Stop(Num);
if (isactive && !wasactive) Platform::Camera_Start(Num, DSi.UserData);
else if (wasactive && !isactive) Platform::Camera_Stop(Num, DSi.UserData);
}
return;

View File

@ -1334,7 +1334,7 @@ void DSi_NWifi::WMI_SendPacket(u16 len)
}
printf("\n");*/
Platform::LAN_SendPacket(LANBuffer, lan_len);
Platform::LAN_SendPacket(LANBuffer, lan_len, DSi.UserData);
}
void DSi_NWifi::SendWMIEvent(u8 ep, u16 id, u8* data, u32 len)
@ -1442,7 +1442,7 @@ void DSi_NWifi::CheckRX()
if (!Mailbox[8].CanFit(2048))
return;
int rxlen = Platform::LAN_RecvPacket(LANBuffer);
int rxlen = Platform::LAN_RecvPacket(LANBuffer, DSi.UserData);
if (rxlen > 0)
{
//printf("WMI packet recv %04X %04X %04X\n", *(u16*)&LANBuffer[0], *(u16*)&LANBuffer[2], *(u16*)&LANBuffer[4]);

View File

@ -95,17 +95,18 @@ u32 CartCommon::GetSaveMemoryLength() const
return 0;
}
CartGame::CartGame(const u8* rom, u32 len, const u8* sram, u32 sramlen, GBACart::CartType type) :
CartGame(CopyToUnique(rom, len), len, CopyToUnique(sram, sramlen), sramlen, type)
CartGame::CartGame(const u8* rom, u32 len, const u8* sram, u32 sramlen, void* userdata, GBACart::CartType type) :
CartGame(CopyToUnique(rom, len), len, CopyToUnique(sram, sramlen), sramlen, userdata, type)
{
}
CartGame::CartGame(std::unique_ptr<u8[]>&& rom, u32 len, std::unique_ptr<u8[]>&& sram, u32 sramlen, GBACart::CartType type) :
CartGame::CartGame(std::unique_ptr<u8[]>&& rom, u32 len, std::unique_ptr<u8[]>&& sram, u32 sramlen, void* userdata, GBACart::CartType type) :
CartCommon(type),
ROM(std::move(rom)),
ROMLength(len),
SRAM(std::move(sram)),
SRAMLength(sramlen)
SRAMLength(sramlen),
UserData(userdata)
{
if (SRAM && SRAMLength)
{
@ -170,7 +171,7 @@ void CartGame::DoSavestate(Savestate* file)
file->Var8((u8*)&SRAMType);
if ((!file->Saving) && SRAM)
Platform::WriteGBASave(SRAM.get(), SRAMLength, 0, SRAMLength);
Platform::WriteGBASave(SRAM.get(), SRAMLength, 0, SRAMLength, UserData);
}
void CartGame::SetupSave(u32 type)
@ -223,7 +224,7 @@ void CartGame::SetSaveMemory(const u8* savedata, u32 savelen)
u32 len = std::min(savelen, SRAMLength);
memcpy(SRAM.get(), savedata, len);
Platform::WriteGBASave(savedata, len, 0, len);
Platform::WriteGBASave(savedata, len, 0, len, UserData);
}
u16 CartGame::ROMRead(u32 addr) const
@ -464,7 +465,7 @@ void CartGame::SRAMWrite_FLASH(u32 addr, u8 val)
u32 start_addr = addr + 0x10000 * SRAMFlashState.bank;
memset((u8*)&SRAM[start_addr], 0xFF, 0x1000);
Platform::WriteGBASave(SRAM.get(), SRAMLength, start_addr, 0x1000);
Platform::WriteGBASave(SRAM.get(), SRAMLength, start_addr, 0x1000, UserData);
}
SRAMFlashState.state = 0;
SRAMFlashState.cmd = 0;
@ -523,18 +524,18 @@ void CartGame::SRAMWrite_SRAM(u32 addr, u8 val)
*(u8*)&SRAM[addr] = val;
// TODO: optimize this!!
Platform::WriteGBASave(SRAM.get(), SRAMLength, addr, 1);
Platform::WriteGBASave(SRAM.get(), SRAMLength, addr, 1, UserData);
}
}
CartGameSolarSensor::CartGameSolarSensor(const u8* rom, u32 len, const u8* sram, u32 sramlen) :
CartGameSolarSensor(CopyToUnique(rom, len), len, CopyToUnique(sram, sramlen), sramlen)
CartGameSolarSensor::CartGameSolarSensor(const u8* rom, u32 len, const u8* sram, u32 sramlen, void* userdata) :
CartGameSolarSensor(CopyToUnique(rom, len), len, CopyToUnique(sram, sramlen), sramlen, userdata)
{
}
CartGameSolarSensor::CartGameSolarSensor(std::unique_ptr<u8[]>&& rom, u32 len, std::unique_ptr<u8[]>&& sram, u32 sramlen) :
CartGame(std::move(rom), len, std::move(sram), sramlen, CartType::GameSolarSensor)
CartGameSolarSensor::CartGameSolarSensor(std::unique_ptr<u8[]>&& rom, u32 len, std::unique_ptr<u8[]>&& sram, u32 sramlen, void* userdata) :
CartGame(std::move(rom), len, std::move(sram), sramlen, userdata, CartType::GameSolarSensor)
{
}
@ -680,7 +681,7 @@ void CartRAMExpansion::ROMWrite(u32 addr, u16 val)
}
}
GBACartSlot::GBACartSlot(std::unique_ptr<CartCommon>&& cart) noexcept : Cart(std::move(cart))
GBACartSlot::GBACartSlot(melonDS::NDS& nds, std::unique_ptr<CartCommon>&& cart) noexcept : NDS(nds), Cart(std::move(cart))
{
}
@ -723,24 +724,24 @@ void GBACartSlot::DoSavestate(Savestate* file) noexcept
if (Cart) Cart->DoSavestate(file);
}
std::unique_ptr<CartCommon> ParseROM(std::unique_ptr<u8[]>&& romdata, u32 romlen)
std::unique_ptr<CartCommon> ParseROM(std::unique_ptr<u8[]>&& romdata, u32 romlen, void* userdata)
{
return ParseROM(std::move(romdata), romlen, nullptr, 0);
return ParseROM(std::move(romdata), romlen, nullptr, 0, userdata);
}
std::unique_ptr<CartCommon> ParseROM(const u8* romdata, u32 romlen, const u8* sramdata, u32 sramlen)
std::unique_ptr<CartCommon> ParseROM(const u8* romdata, u32 romlen, const u8* sramdata, u32 sramlen, void* userdata)
{
auto [romcopy, romcopylen] = PadToPowerOf2(romdata, romlen);
return ParseROM(std::move(romcopy), romcopylen, CopyToUnique(sramdata, sramlen), sramlen);
return ParseROM(std::move(romcopy), romcopylen, CopyToUnique(sramdata, sramlen), sramlen, userdata);
}
std::unique_ptr<CartCommon> ParseROM(const u8* romdata, u32 romlen)
std::unique_ptr<CartCommon> ParseROM(const u8* romdata, u32 romlen, void* userdata)
{
return ParseROM(romdata, romlen, nullptr, 0);
return ParseROM(romdata, romlen, nullptr, 0, userdata);
}
std::unique_ptr<CartCommon> ParseROM(std::unique_ptr<u8[]>&& romdata, u32 romlen, std::unique_ptr<u8[]>&& sramdata, u32 sramlen)
std::unique_ptr<CartCommon> ParseROM(std::unique_ptr<u8[]>&& romdata, u32 romlen, std::unique_ptr<u8[]>&& sramdata, u32 sramlen, void* userdata)
{
if (romdata == nullptr)
{
@ -773,9 +774,9 @@ std::unique_ptr<CartCommon> ParseROM(std::unique_ptr<u8[]>&& romdata, u32 romlen
std::unique_ptr<CartCommon> cart;
if (solarsensor)
cart = std::make_unique<CartGameSolarSensor>(std::move(cartrom), cartromsize, std::move(sramdata), sramlen);
cart = std::make_unique<CartGameSolarSensor>(std::move(cartrom), cartromsize, std::move(sramdata), sramlen, userdata);
else
cart = std::make_unique<CartGame>(std::move(cartrom), cartromsize, std::move(sramdata), sramlen);
cart = std::make_unique<CartGame>(std::move(cartrom), cartromsize, std::move(sramdata), sramlen, userdata);
cart->Reset();

View File

@ -72,8 +72,8 @@ private:
class CartGame : public CartCommon
{
public:
CartGame(const u8* rom, u32 len, const u8* sram, u32 sramlen, GBACart::CartType type = GBACart::CartType::Game);
CartGame(std::unique_ptr<u8[]>&& rom, u32 len, std::unique_ptr<u8[]>&& sram, u32 sramlen, GBACart::CartType type = GBACart::CartType::Game);
CartGame(const u8* rom, u32 len, const u8* sram, u32 sramlen, void* userdata, GBACart::CartType type = GBACart::CartType::Game);
CartGame(std::unique_ptr<u8[]>&& rom, u32 len, std::unique_ptr<u8[]>&& sram, u32 sramlen, void* userdata, GBACart::CartType type = GBACart::CartType::Game);
~CartGame() override;
u32 Checksum() const override;
@ -104,6 +104,8 @@ protected:
u8 SRAMRead_SRAM(u32 addr);
void SRAMWrite_SRAM(u32 addr, u8 val);
void* UserData;
std::unique_ptr<u8[]> ROM;
u32 ROMLength;
@ -147,8 +149,8 @@ private:
class CartGameSolarSensor : public CartGame
{
public:
CartGameSolarSensor(const u8* rom, u32 len, const u8* sram, u32 sramlen);
CartGameSolarSensor(std::unique_ptr<u8[]>&& rom, u32 len, std::unique_ptr<u8[]>&& sram, u32 sramlen);
CartGameSolarSensor(const u8* rom, u32 len, const u8* sram, u32 sramlen, void* userdata);
CartGameSolarSensor(std::unique_ptr<u8[]>&& rom, u32 len, std::unique_ptr<u8[]>&& sram, u32 sramlen, void* userdata);
void Reset() override;
@ -197,7 +199,7 @@ enum
class GBACartSlot
{
public:
GBACartSlot(std::unique_ptr<CartCommon>&& cart = nullptr) noexcept;
GBACartSlot(melonDS::NDS& nds, std::unique_ptr<CartCommon>&& cart = nullptr) noexcept;
~GBACartSlot() noexcept = default;
void Reset() noexcept;
void DoSavestate(Savestate* file) noexcept;
@ -258,6 +260,7 @@ public:
/// if a cart is loaded and supports SRAM, otherwise zero.
[[nodiscard]] u32 GetSaveMemoryLength() const noexcept { return Cart ? Cart->GetSaveMemoryLength() : 0; }
private:
melonDS::NDS& NDS;
std::unique_ptr<CartCommon> Cart = nullptr;
u16 OpenBusDecay = 0;
};
@ -270,9 +273,9 @@ private:
/// @param romlen The length of the ROM data in bytes.
/// @returns A \c GBACart::CartCommon object representing the parsed ROM,
/// or \c nullptr if the ROM data couldn't be parsed.
std::unique_ptr<CartCommon> ParseROM(const u8* romdata, u32 romlen);
std::unique_ptr<CartCommon> ParseROM(std::unique_ptr<u8[]>&& romdata, u32 romlen);
std::unique_ptr<CartCommon> ParseROM(const u8* romdata, u32 romlen, const u8* sramdata, u32 sramlen);
std::unique_ptr<CartCommon> ParseROM(const u8* romdata, u32 romlen, void* userdata = nullptr);
std::unique_ptr<CartCommon> ParseROM(std::unique_ptr<u8[]>&& romdata, u32 romlen, void* userdata = nullptr);
std::unique_ptr<CartCommon> ParseROM(const u8* romdata, u32 romlen, const u8* sramdata, u32 sramlen, void* userdata = nullptr);
/// @param romdata The ROM data to parse. Will be moved-from.
/// @param romlen Length of romdata in bytes.
@ -282,7 +285,7 @@ std::unique_ptr<CartCommon> ParseROM(const u8* romdata, u32 romlen, const u8* sr
/// May be zero, in which case the cart will have no save data.
/// @return Unique pointer to the parsed GBA cart,
/// or \c nullptr if there was an error.
std::unique_ptr<CartCommon> ParseROM(std::unique_ptr<u8[]>&& romdata, u32 romlen, std::unique_ptr<u8[]>&& sramdata, u32 sramlen);
std::unique_ptr<CartCommon> ParseROM(std::unique_ptr<u8[]>&& romdata, u32 romlen, std::unique_ptr<u8[]>&& sramdata, u32 sramlen, void* userdata = nullptr);
}

View File

@ -89,8 +89,9 @@ NDS::NDS() noexcept :
{
}
NDS::NDS(NDSArgs&& args, int type) noexcept :
NDS::NDS(NDSArgs&& args, int type, void* userdata) noexcept :
ConsoleType(type),
UserData(userdata),
ARM7BIOS(*args.ARM7BIOS),
ARM9BIOS(*args.ARM9BIOS),
ARM7BIOSNative(CRC32(ARM7BIOS.data(), ARM7BIOS.size()) == ARM7BIOSCRC32),
@ -102,7 +103,7 @@ NDS::NDS(NDSArgs&& args, int type) noexcept :
RTC(*this),
Wifi(*this),
NDSCartSlot(*this, std::move(args.NDSROM)),
GBACartSlot(type == 1 ? nullptr : std::move(args.GBAROM)),
GBACartSlot(*this, type == 1 ? nullptr : std::move(args.GBAROM)),
AREngine(*this),
ARM9(*this, args.GDB, args.JIT.has_value()),
ARM7(*this, args.GDB, args.JIT.has_value()),
@ -574,7 +575,7 @@ void NDS::Stop(Platform::StopReason reason)
Log(level, "Stopping emulated console (Reason: %s)\n", StopReasonName(reason));
Running = false;
Platform::SignalStop(reason);
Platform::SignalStop(reason, UserData);
GPU.Stop();
SPU.Stop();
}

View File

@ -229,6 +229,8 @@ private:
#endif
public: // TODO: Encapsulate the rest of these members
void* UserData;
int ConsoleType;
int CurCPU;
@ -522,7 +524,7 @@ private:
template <bool EnableJIT>
u32 RunFrame();
public:
NDS(NDSArgs&& args) noexcept : NDS(std::move(args), 0) {}
NDS(NDSArgs&& args, void* userdata = nullptr) noexcept : NDS(std::move(args), 0, userdata) {}
NDS() noexcept;
virtual ~NDS() noexcept;
NDS(const NDS&) = delete;
@ -532,7 +534,7 @@ public:
// The frontend should set and unset this manually after creating and destroying the NDS object.
[[deprecated("Temporary workaround until JIT code generation is revised to accommodate multiple NDS objects.")]] static NDS* Current;
protected:
explicit NDS(NDSArgs&& args, int type) noexcept;
explicit NDS(NDSArgs&& args, int type, void* userdata) noexcept;
virtual void DoSavestateExtra(Savestate* file) {}
};

View File

@ -173,17 +173,18 @@ void NDSCartSlot::Key2_Encrypt(const u8* data, u32 len) noexcept
}
CartCommon::CartCommon(const u8* rom, u32 len, u32 chipid, bool badDSiDump, ROMListEntry romparams, melonDS::NDSCart::CartType type) :
CartCommon(CopyToUnique(rom, len), len, chipid, badDSiDump, romparams, type)
CartCommon::CartCommon(const u8* rom, u32 len, u32 chipid, bool badDSiDump, ROMListEntry romparams, melonDS::NDSCart::CartType type, void* userdata) :
CartCommon(CopyToUnique(rom, len), len, chipid, badDSiDump, romparams, type, userdata)
{
}
CartCommon::CartCommon(std::unique_ptr<u8[]>&& rom, u32 len, u32 chipid, bool badDSiDump, ROMListEntry romparams, melonDS::NDSCart::CartType type) :
CartCommon::CartCommon(std::unique_ptr<u8[]>&& rom, u32 len, u32 chipid, bool badDSiDump, ROMListEntry romparams, melonDS::NDSCart::CartType type, void* userdata) :
ROM(std::move(rom)),
ROMLength(len),
ChipID(chipid),
ROMParams(romparams),
CartType(type)
CartType(type),
UserData(userdata)
{
memcpy(&Header, ROM.get(), sizeof(Header));
IsDSi = Header.IsDSi() && !badDSiDump;
@ -375,13 +376,13 @@ const NDSBanner* CartCommon::Banner() const
return nullptr;
}
CartRetail::CartRetail(const u8* rom, u32 len, u32 chipid, bool badDSiDump, ROMListEntry romparams, std::unique_ptr<u8[]>&& sram, u32 sramlen, melonDS::NDSCart::CartType type) :
CartRetail(CopyToUnique(rom, len), len, chipid, badDSiDump, romparams, std::move(sram), sramlen, type)
CartRetail::CartRetail(const u8* rom, u32 len, u32 chipid, bool badDSiDump, ROMListEntry romparams, std::unique_ptr<u8[]>&& sram, u32 sramlen, void* userdata, melonDS::NDSCart::CartType type) :
CartRetail(CopyToUnique(rom, len), len, chipid, badDSiDump, romparams, std::move(sram), sramlen, userdata, type)
{
}
CartRetail::CartRetail(std::unique_ptr<u8[]>&& rom, u32 len, u32 chipid, bool badDSiDump, ROMListEntry romparams, std::unique_ptr<u8[]>&& sram, u32 sramlen, melonDS::NDSCart::CartType type) :
CartCommon(std::move(rom), len, chipid, badDSiDump, romparams, type)
CartRetail::CartRetail(std::unique_ptr<u8[]>&& rom, u32 len, u32 chipid, bool badDSiDump, ROMListEntry romparams, std::unique_ptr<u8[]>&& sram, u32 sramlen, void* userdata, melonDS::NDSCart::CartType type) :
CartCommon(std::move(rom), len, chipid, badDSiDump, romparams, type, userdata)
{
u32 savememtype = ROMParams.SaveMemType <= 10 ? ROMParams.SaveMemType : 0;
constexpr int sramlengths[] =
@ -469,7 +470,7 @@ void CartRetail::DoSavestate(Savestate* file)
file->Var8(&SRAMStatus);
if ((!file->Saving) && SRAM)
Platform::WriteNDSSave(SRAM.get(), SRAMLength, 0, SRAMLength);
Platform::WriteNDSSave(SRAM.get(), SRAMLength, 0, SRAMLength, UserData);
}
void CartRetail::SetSaveMemory(const u8* savedata, u32 savelen)
@ -478,7 +479,7 @@ void CartRetail::SetSaveMemory(const u8* savedata, u32 savelen)
u32 len = std::min(savelen, SRAMLength);
memcpy(SRAM.get(), savedata, len);
Platform::WriteNDSSave(savedata, len, 0, len);
Platform::WriteNDSSave(savedata, len, 0, len, UserData);
}
int CartRetail::ROMCommandStart(NDS& nds, NDSCart::NDSCartSlot& cartslot, const u8* cmd, u8* data, u32 len)
@ -594,7 +595,8 @@ u8 CartRetail::SRAMWrite_EEPROMTiny(u8 val, u32 pos, bool last)
{
SRAMStatus &= ~(1<<1);
Platform::WriteNDSSave(SRAM.get(), SRAMLength,
(SRAMFirstAddr + ((SRAMCmd==0x0A)?0x100:0)) & 0x1FF, SRAMAddr-SRAMFirstAddr);
(SRAMFirstAddr + ((SRAMCmd==0x0A)?0x100:0)) & 0x1FF, SRAMAddr-SRAMFirstAddr,
UserData);
}
return 0;
@ -658,7 +660,8 @@ u8 CartRetail::SRAMWrite_EEPROM(u8 val, u32 pos, bool last)
{
SRAMStatus &= ~(1<<1);
Platform::WriteNDSSave(SRAM.get(), SRAMLength,
SRAMFirstAddr & (SRAMLength-1), SRAMAddr-SRAMFirstAddr);
SRAMFirstAddr & (SRAMLength-1), SRAMAddr-SRAMFirstAddr,
UserData);
}
return 0;
@ -715,7 +718,8 @@ u8 CartRetail::SRAMWrite_FLASH(u8 val, u32 pos, bool last)
{
SRAMStatus &= ~(1<<1);
Platform::WriteNDSSave(SRAM.get(), SRAMLength,
SRAMFirstAddr & (SRAMLength-1), SRAMAddr-SRAMFirstAddr);
SRAMFirstAddr & (SRAMLength-1), SRAMAddr-SRAMFirstAddr,
UserData);
}
return 0;
@ -752,7 +756,8 @@ u8 CartRetail::SRAMWrite_FLASH(u8 val, u32 pos, bool last)
{
SRAMStatus &= ~(1<<1);
Platform::WriteNDSSave(SRAM.get(), SRAMLength,
SRAMFirstAddr & (SRAMLength-1), SRAMAddr-SRAMFirstAddr);
SRAMFirstAddr & (SRAMLength-1), SRAMAddr-SRAMFirstAddr,
UserData);
}
return 0;
@ -798,7 +803,8 @@ u8 CartRetail::SRAMWrite_FLASH(u8 val, u32 pos, bool last)
{
SRAMStatus &= ~(1<<1);
Platform::WriteNDSSave(SRAM.get(), SRAMLength,
SRAMFirstAddr & (SRAMLength-1), SRAMAddr-SRAMFirstAddr);
SRAMFirstAddr & (SRAMLength-1), SRAMAddr-SRAMFirstAddr,
UserData);
}
return 0;
@ -821,7 +827,8 @@ u8 CartRetail::SRAMWrite_FLASH(u8 val, u32 pos, bool last)
{
SRAMStatus &= ~(1<<1);
Platform::WriteNDSSave(SRAM.get(), SRAMLength,
SRAMFirstAddr & (SRAMLength-1), SRAMAddr-SRAMFirstAddr);
SRAMFirstAddr & (SRAMLength-1), SRAMAddr-SRAMFirstAddr,
UserData);
}
return 0;
@ -832,13 +839,13 @@ u8 CartRetail::SRAMWrite_FLASH(u8 val, u32 pos, bool last)
}
}
CartRetailNAND::CartRetailNAND(const u8* rom, u32 len, u32 chipid, ROMListEntry romparams, std::unique_ptr<u8[]>&& sram, u32 sramlen) :
CartRetailNAND(CopyToUnique(rom, len), len, chipid, romparams, std::move(sram), sramlen)
CartRetailNAND::CartRetailNAND(const u8* rom, u32 len, u32 chipid, ROMListEntry romparams, std::unique_ptr<u8[]>&& sram, u32 sramlen, void* userdata) :
CartRetailNAND(CopyToUnique(rom, len), len, chipid, romparams, std::move(sram), sramlen, userdata)
{
}
CartRetailNAND::CartRetailNAND(std::unique_ptr<u8[]>&& rom, u32 len, u32 chipid, ROMListEntry romparams, std::unique_ptr<u8[]>&& sram, u32 sramlen) :
CartRetail(std::move(rom), len, chipid, false, romparams, std::move(sram), sramlen, CartType::RetailNAND)
CartRetailNAND::CartRetailNAND(std::unique_ptr<u8[]>&& rom, u32 len, u32 chipid, ROMListEntry romparams, std::unique_ptr<u8[]>&& sram, u32 sramlen, void* userdata) :
CartRetail(std::move(rom), len, chipid, false, romparams, std::move(sram), sramlen, userdata, CartType::RetailNAND)
{
BuildSRAMID();
}
@ -908,7 +915,7 @@ int CartRetailNAND::ROMCommandStart(NDS& nds, NDSCart::NDSCartSlot& cartslot, co
if (SRAMLength && SRAMAddr < (SRAMBase+SRAMLength-0x20000))
{
memcpy(&SRAM[SRAMAddr - SRAMBase], SRAMWriteBuffer, 0x800);
Platform::WriteNDSSave(SRAM.get(), SRAMLength, SRAMAddr - SRAMBase, 0x800);
Platform::WriteNDSSave(SRAM.get(), SRAMLength, SRAMAddr - SRAMBase, 0x800, UserData);
}
SRAMAddr = 0;
@ -1064,8 +1071,8 @@ void CartRetailNAND::BuildSRAMID()
}
CartRetailIR::CartRetailIR(const u8* rom, u32 len, u32 chipid, u32 irversion, bool badDSiDump, ROMListEntry romparams, std::unique_ptr<u8[]>&& sram, u32 sramlen) :
CartRetailIR(CopyToUnique(rom, len), len, chipid, irversion, badDSiDump, romparams, std::move(sram), sramlen)
CartRetailIR::CartRetailIR(const u8* rom, u32 len, u32 chipid, u32 irversion, bool badDSiDump, ROMListEntry romparams, std::unique_ptr<u8[]>&& sram, u32 sramlen, void* userdata) :
CartRetailIR(CopyToUnique(rom, len), len, chipid, irversion, badDSiDump, romparams, std::move(sram), sramlen, userdata)
{
}
@ -1077,9 +1084,10 @@ CartRetailIR::CartRetailIR(
bool badDSiDump,
ROMListEntry romparams,
std::unique_ptr<u8[]>&& sram,
u32 sramlen
u32 sramlen,
void* userdata
) :
CartRetail(std::move(rom), len, chipid, badDSiDump, romparams, std::move(sram), sramlen, CartType::RetailIR),
CartRetail(std::move(rom), len, chipid, badDSiDump, romparams, std::move(sram), sramlen, userdata, CartType::RetailIR),
IRVersion(irversion)
{
}
@ -1122,13 +1130,13 @@ u8 CartRetailIR::SPIWrite(u8 val, u32 pos, bool last)
return 0;
}
CartRetailBT::CartRetailBT(const u8* rom, u32 len, u32 chipid, ROMListEntry romparams, std::unique_ptr<u8[]>&& sram, u32 sramlen) :
CartRetailBT(CopyToUnique(rom, len), len, chipid, romparams, std::move(sram), sramlen)
CartRetailBT::CartRetailBT(const u8* rom, u32 len, u32 chipid, ROMListEntry romparams, std::unique_ptr<u8[]>&& sram, u32 sramlen, void* userdata) :
CartRetailBT(CopyToUnique(rom, len), len, chipid, romparams, std::move(sram), sramlen, userdata)
{
}
CartRetailBT::CartRetailBT(std::unique_ptr<u8[]>&& rom, u32 len, u32 chipid, ROMListEntry romparams, std::unique_ptr<u8[]>&& sram, u32 sramlen) :
CartRetail(std::move(rom), len, chipid, false, romparams, std::move(sram), sramlen, CartType::RetailBT)
CartRetailBT::CartRetailBT(std::unique_ptr<u8[]>&& rom, u32 len, u32 chipid, ROMListEntry romparams, std::unique_ptr<u8[]>&& sram, u32 sramlen, void* userdata) :
CartRetail(std::move(rom), len, chipid, false, romparams, std::move(sram), sramlen, userdata, CartType::RetailBT)
{
Log(LogLevel::Info,"POKETYPE CART\n");
}
@ -1150,12 +1158,12 @@ u8 CartRetailBT::SPIWrite(u8 val, u32 pos, bool last)
}
CartSD::CartSD(const u8* rom, u32 len, u32 chipid, ROMListEntry romparams, std::optional<FATStorage>&& sdcard) :
CartSD(CopyToUnique(rom, len), len, chipid, romparams, std::move(sdcard))
CartSD::CartSD(const u8* rom, u32 len, u32 chipid, ROMListEntry romparams, void* userdata, std::optional<FATStorage>&& sdcard) :
CartSD(CopyToUnique(rom, len), len, chipid, romparams, userdata, std::move(sdcard))
{}
CartSD::CartSD(std::unique_ptr<u8[]>&& rom, u32 len, u32 chipid, ROMListEntry romparams, std::optional<FATStorage>&& sdcard) :
CartCommon(std::move(rom), len, chipid, false, romparams, CartType::Homebrew),
CartSD::CartSD(std::unique_ptr<u8[]>&& rom, u32 len, u32 chipid, ROMListEntry romparams, void* userdata, std::optional<FATStorage>&& sdcard) :
CartCommon(std::move(rom), len, chipid, false, romparams, CartType::Homebrew, userdata),
SD(std::move(sdcard))
{
sdcard = std::nullopt;
@ -1306,12 +1314,12 @@ void CartSD::ReadROM_B7(u32 addr, u32 len, u8* data, u32 offset) const
memcpy(data+offset, ROM.get()+addr, len);
}
CartHomebrew::CartHomebrew(const u8* rom, u32 len, u32 chipid, ROMListEntry romparams, std::optional<FATStorage>&& sdcard) :
CartSD(rom, len, chipid, romparams, std::move(sdcard))
CartHomebrew::CartHomebrew(const u8* rom, u32 len, u32 chipid, ROMListEntry romparams, void* userdata, std::optional<FATStorage>&& sdcard) :
CartSD(rom, len, chipid, romparams, userdata, std::move(sdcard))
{}
CartHomebrew::CartHomebrew(std::unique_ptr<u8[]>&& rom, u32 len, u32 chipid, ROMListEntry romparams, std::optional<FATStorage>&& sdcard) :
CartSD(std::move(rom), len, chipid, romparams, std::move(sdcard))
CartHomebrew::CartHomebrew(std::unique_ptr<u8[]>&& rom, u32 len, u32 chipid, ROMListEntry romparams, void* userdata, std::optional<FATStorage>&& sdcard) :
CartSD(std::move(rom), len, chipid, romparams, userdata, std::move(sdcard))
{}
CartHomebrew::~CartHomebrew() = default;
@ -1565,12 +1573,12 @@ void NDSCartSlot::DecryptSecureArea(u8* out) noexcept
}
}
std::unique_ptr<CartCommon> ParseROM(const u8* romdata, u32 romlen, std::optional<NDSCartArgs>&& args)
std::unique_ptr<CartCommon> ParseROM(const u8* romdata, u32 romlen, void* userdata, std::optional<NDSCartArgs>&& args)
{
return ParseROM(CopyToUnique(romdata, romlen), romlen, std::move(args));
return ParseROM(CopyToUnique(romdata, romlen), romlen, userdata, std::move(args));
}
std::unique_ptr<CartCommon> ParseROM(std::unique_ptr<u8[]>&& romdata, u32 romlen, std::optional<NDSCartArgs>&& args)
std::unique_ptr<CartCommon> ParseROM(std::unique_ptr<u8[]>&& romdata, u32 romlen, void* userdata, std::optional<NDSCartArgs>&& args)
{
if (romdata == nullptr)
{
@ -1659,21 +1667,21 @@ std::unique_ptr<CartCommon> ParseROM(std::unique_ptr<u8[]>&& romdata, u32 romlen
if (homebrew)
{
std::optional<FATStorage> sdcard = args && args->SDCard ? std::make_optional<FATStorage>(std::move(*args->SDCard)) : std::nullopt;
cart = std::make_unique<CartHomebrew>(std::move(cartrom), cartromsize, cartid, romparams, std::move(sdcard));
cart = std::make_unique<CartHomebrew>(std::move(cartrom), cartromsize, cartid, romparams, userdata, std::move(sdcard));
}
else if (gametitle[0] == 0 && !strncmp("SD/TF-NDS", gametitle + 1, 9) && gamecode == 0x414D5341)
{
std::optional<FATStorage> sdcard = args && args->SDCard ? std::make_optional<FATStorage>(std::move(*args->SDCard)) : std::nullopt;
cart = std::make_unique<CartR4>(std::move(cartrom), cartromsize, cartid, romparams, CartR4TypeR4, CartR4LanguageEnglish, std::move(sdcard));
cart = std::make_unique<CartR4>(std::move(cartrom), cartromsize, cartid, romparams, CartR4TypeR4, CartR4LanguageEnglish, userdata, std::move(sdcard));
}
else if (cartid & 0x08000000)
cart = std::make_unique<CartRetailNAND>(std::move(cartrom), cartromsize, cartid, romparams, std::move(sram), sramlen);
cart = std::make_unique<CartRetailNAND>(std::move(cartrom), cartromsize, cartid, romparams, std::move(sram), sramlen, userdata);
else if (irversion != 0)
cart = std::make_unique<CartRetailIR>(std::move(cartrom), cartromsize, cartid, irversion, badDSiDump, romparams, std::move(sram), sramlen);
cart = std::make_unique<CartRetailIR>(std::move(cartrom), cartromsize, cartid, irversion, badDSiDump, romparams, std::move(sram), sramlen, userdata);
else if ((gamecode & 0xFFFFFF) == 0x505A55) // UZPx
cart = std::make_unique<CartRetailBT>(std::move(cartrom), cartromsize, cartid, romparams, std::move(sram), sramlen);
cart = std::make_unique<CartRetailBT>(std::move(cartrom), cartromsize, cartid, romparams, std::move(sram), sramlen, userdata);
else
cart = std::make_unique<CartRetail>(std::move(cartrom), cartromsize, cartid, badDSiDump, romparams, std::move(sram), sramlen);
cart = std::make_unique<CartRetail>(std::move(cartrom), cartromsize, cartid, badDSiDump, romparams, std::move(sram), sramlen, userdata);
args = std::nullopt;
return cart;

View File

@ -76,8 +76,8 @@ struct NDSCartArgs
class CartCommon
{
public:
CartCommon(const u8* rom, u32 len, u32 chipid, bool badDSiDump, ROMListEntry romparams, CartType type);
CartCommon(std::unique_ptr<u8[]>&& rom, u32 len, u32 chipid, bool badDSiDump, ROMListEntry romparams, CartType type);
CartCommon(const u8* rom, u32 len, u32 chipid, bool badDSiDump, ROMListEntry romparams, CartType type, void* userdata);
CartCommon(std::unique_ptr<u8[]>&& rom, u32 len, u32 chipid, bool badDSiDump, ROMListEntry romparams, CartType type, void* userdata);
virtual ~CartCommon();
[[nodiscard]] u32 Type() const { return CartType; };
@ -111,6 +111,8 @@ public:
protected:
void ReadROM(u32 addr, u32 len, u8* data, u32 offset) const;
void* UserData;
std::unique_ptr<u8[]> ROM = nullptr;
u32 ROMLength = 0;
u32 ChipID = 0;
@ -139,6 +141,7 @@ public:
ROMListEntry romparams,
std::unique_ptr<u8[]>&& sram,
u32 sramlen,
void* userdata,
melonDS::NDSCart::CartType type = CartType::Retail
);
CartRetail(
@ -148,6 +151,7 @@ public:
ROMListEntry romparams,
std::unique_ptr<u8[]>&& sram,
u32 sramlen,
void* userdata,
melonDS::NDSCart::CartType type = CartType::Retail
);
~CartRetail() override;
@ -187,8 +191,8 @@ protected:
class CartRetailNAND : public CartRetail
{
public:
CartRetailNAND(const u8* rom, u32 len, u32 chipid, ROMListEntry romparams, std::unique_ptr<u8[]>&& sram, u32 sramlen);
CartRetailNAND(std::unique_ptr<u8[]>&& rom, u32 len, u32 chipid, ROMListEntry romparams, std::unique_ptr<u8[]>&& sram, u32 sramlen);
CartRetailNAND(const u8* rom, u32 len, u32 chipid, ROMListEntry romparams, std::unique_ptr<u8[]>&& sram, u32 sramlen, void* userdata);
CartRetailNAND(std::unique_ptr<u8[]>&& rom, u32 len, u32 chipid, ROMListEntry romparams, std::unique_ptr<u8[]>&& sram, u32 sramlen, void* userdata);
~CartRetailNAND() override;
void Reset() override;
@ -216,8 +220,8 @@ private:
class CartRetailIR : public CartRetail
{
public:
CartRetailIR(const u8* rom, u32 len, u32 chipid, u32 irversion, bool badDSiDump, ROMListEntry romparams, std::unique_ptr<u8[]>&& sram, u32 sramlen);
CartRetailIR(std::unique_ptr<u8[]>&& rom, u32 len, u32 chipid, u32 irversion, bool badDSiDump, ROMListEntry romparams, std::unique_ptr<u8[]>&& sram, u32 sramlen);
CartRetailIR(const u8* rom, u32 len, u32 chipid, u32 irversion, bool badDSiDump, ROMListEntry romparams, std::unique_ptr<u8[]>&& sram, u32 sramlen, void* userdata);
CartRetailIR(std::unique_ptr<u8[]>&& rom, u32 len, u32 chipid, u32 irversion, bool badDSiDump, ROMListEntry romparams, std::unique_ptr<u8[]>&& sram, u32 sramlen, void* userdata);
~CartRetailIR() override;
void Reset() override;
@ -235,8 +239,8 @@ private:
class CartRetailBT : public CartRetail
{
public:
CartRetailBT(const u8* rom, u32 len, u32 chipid, ROMListEntry romparams, std::unique_ptr<u8[]>&& sram, u32 sramlen);
CartRetailBT(std::unique_ptr<u8[]>&& rom, u32 len, u32 chipid, ROMListEntry romparams, std::unique_ptr<u8[]>&& sram, u32 sramlen);
CartRetailBT(const u8* rom, u32 len, u32 chipid, ROMListEntry romparams, std::unique_ptr<u8[]>&& sram, u32 sramlen, void* userdata);
CartRetailBT(std::unique_ptr<u8[]>&& rom, u32 len, u32 chipid, ROMListEntry romparams, std::unique_ptr<u8[]>&& sram, u32 sramlen, void* userdata);
~CartRetailBT() override;
u8 SPIWrite(u8 val, u32 pos, bool last) override;
@ -246,8 +250,8 @@ public:
class CartSD : public CartCommon
{
public:
CartSD(const u8* rom, u32 len, u32 chipid, ROMListEntry romparams, std::optional<FATStorage>&& sdcard = std::nullopt);
CartSD(std::unique_ptr<u8[]>&& rom, u32 len, u32 chipid, ROMListEntry romparams, std::optional<FATStorage>&& sdcard = std::nullopt);
CartSD(const u8* rom, u32 len, u32 chipid, ROMListEntry romparams, void* userdata, std::optional<FATStorage>&& sdcard = std::nullopt);
CartSD(std::unique_ptr<u8[]>&& rom, u32 len, u32 chipid, ROMListEntry romparams, void* userdata, std::optional<FATStorage>&& sdcard = std::nullopt);
~CartSD() override;
[[nodiscard]] const std::optional<FATStorage>& GetSDCard() const noexcept { return SD; }
@ -288,8 +292,8 @@ protected:
class CartHomebrew : public CartSD
{
public:
CartHomebrew(const u8* rom, u32 len, u32 chipid, ROMListEntry romparams, std::optional<FATStorage>&& sdcard = std::nullopt);
CartHomebrew(std::unique_ptr<u8[]>&& rom, u32 len, u32 chipid, ROMListEntry romparams, std::optional<FATStorage>&& sdcard = std::nullopt);
CartHomebrew(const u8* rom, u32 len, u32 chipid, ROMListEntry romparams, void* userdata, std::optional<FATStorage>&& sdcard = std::nullopt);
CartHomebrew(std::unique_ptr<u8[]>&& rom, u32 len, u32 chipid, ROMListEntry romparams, void* userdata, std::optional<FATStorage>&& sdcard = std::nullopt);
~CartHomebrew() override;
void Reset() override;
@ -322,7 +326,7 @@ enum CartR4Language
class CartR4 : public CartSD
{
public:
CartR4(std::unique_ptr<u8[]>&& rom, u32 len, u32 chipid, ROMListEntry romparams, CartR4Type ctype, CartR4Language clanguage,
CartR4(std::unique_ptr<u8[]>&& rom, u32 len, u32 chipid, ROMListEntry romparams, CartR4Type ctype, CartR4Language clanguage, void* userdata,
std::optional<FATStorage>&& sdcard = std::nullopt);
~CartR4() override;
@ -461,8 +465,8 @@ private:
/// If not given, the cart will not have an SD card.
/// @returns A \c NDSCart::CartCommon object representing the parsed ROM,
/// or \c nullptr if the ROM data couldn't be parsed.
std::unique_ptr<CartCommon> ParseROM(const u8* romdata, u32 romlen, std::optional<NDSCartArgs>&& args = std::nullopt);
std::unique_ptr<CartCommon> ParseROM(std::unique_ptr<u8[]>&& romdata, u32 romlen, std::optional<NDSCartArgs>&& args = std::nullopt);
std::unique_ptr<CartCommon> ParseROM(const u8* romdata, u32 romlen, void* userdata = nullptr, std::optional<NDSCartArgs>&& args = std::nullopt);
std::unique_ptr<CartCommon> ParseROM(std::unique_ptr<u8[]>&& romdata, u32 romlen, void* userdata = nullptr, std::optional<NDSCartArgs>&& args = std::nullopt);
}
#endif

View File

@ -67,9 +67,9 @@ static void DecryptR4Sector(u8* dest, u8* src, u16 key1)
}
}
CartR4::CartR4(std::unique_ptr<u8[]>&& rom, u32 len, u32 chipid, ROMListEntry romparams, CartR4Type ctype, CartR4Language clanguage,
CartR4::CartR4(std::unique_ptr<u8[]>&& rom, u32 len, u32 chipid, ROMListEntry romparams, CartR4Type ctype, CartR4Language clanguage, void* userdata,
std::optional<FATStorage>&& sdcard)
: CartSD(std::move(rom), len, chipid, romparams, std::move(sdcard))
: CartSD(std::move(rom), len, chipid, romparams, userdata, std::move(sdcard))
{
InitStatus = 0;
R4CartType = ctype;

View File

@ -69,7 +69,7 @@ enum StopReason {
* Frontends should not call this directly;
* use \c NDS::Stop instead.
*/
void SignalStop(StopReason reason);
void SignalStop(StopReason reason, void* userdata);
/**
@ -271,41 +271,41 @@ void Sleep(u64 usecs);
// functions called when the NDS or GBA save files need to be written back to storage
// savedata and savelen are always the entire save memory buffer and its full length
// writeoffset and writelen indicate which part of the memory was altered
void WriteNDSSave(const u8* savedata, u32 savelen, u32 writeoffset, u32 writelen);
void WriteGBASave(const u8* savedata, u32 savelen, u32 writeoffset, u32 writelen);
void WriteNDSSave(const u8* savedata, u32 savelen, u32 writeoffset, u32 writelen, void* userdata);
void WriteGBASave(const u8* savedata, u32 savelen, u32 writeoffset, u32 writelen, void* userdata);
/// Called when the firmware needs to be written back to storage,
/// after one of the supported write commands finishes execution.
/// @param firmware The firmware that was just written.
/// @param writeoffset The offset of the first byte that was written to firmware.
/// @param writelen The number of bytes that were written to firmware.
void WriteFirmware(const Firmware& firmware, u32 writeoffset, u32 writelen);
void WriteFirmware(const Firmware& firmware, u32 writeoffset, u32 writelen, void* userdata);
// called when the RTC date/time is changed and the frontend might need to take it into account
void WriteDateTime(int year, int month, int day, int hour, int minute, int second);
void WriteDateTime(int year, int month, int day, int hour, int minute, int second, void* userdata);
// local multiplayer comm interface
// packet type: DS-style TX header (12 bytes) + original 802.11 frame
bool MP_Init();
void MP_DeInit();
void MP_Begin();
void MP_End();
int MP_SendPacket(u8* data, int len, u64 timestamp);
int MP_RecvPacket(u8* data, u64* timestamp);
int MP_SendCmd(u8* data, int len, u64 timestamp);
int MP_SendReply(u8* data, int len, u64 timestamp, u16 aid);
int MP_SendAck(u8* data, int len, u64 timestamp);
int MP_RecvHostPacket(u8* data, u64* timestamp);
u16 MP_RecvReplies(u8* data, u64 timestamp, u16 aidmask);
bool MP_Init(void* userdata);
void MP_DeInit(void* userdata);
void MP_Begin(void* userdata);
void MP_End(void* userdata);
int MP_SendPacket(u8* data, int len, u64 timestamp, void* userdata);
int MP_RecvPacket(u8* data, u64* timestamp, void* userdata);
int MP_SendCmd(u8* data, int len, u64 timestamp, void* userdata);
int MP_SendReply(u8* data, int len, u64 timestamp, u16 aid, void* userdata);
int MP_SendAck(u8* data, int len, u64 timestamp, void* userdata);
int MP_RecvHostPacket(u8* data, u64* timestamp, void* userdata);
u16 MP_RecvReplies(u8* data, u64 timestamp, u16 aidmask, void* userdata);
// LAN comm interface
// packet type: Ethernet (802.3)
bool LAN_Init();
void LAN_DeInit();
int LAN_SendPacket(u8* data, int len);
int LAN_RecvPacket(u8* data);
bool LAN_Init(void* userdata);
void LAN_DeInit(void* userdata);
int LAN_SendPacket(u8* data, int len, void* userdata);
int LAN_RecvPacket(u8* data, void* userdata);
// interface for camera emulation
@ -313,9 +313,9 @@ int LAN_RecvPacket(u8* data);
// 0 = DSi outer camera
// 1 = DSi inner camera
// other values reserved for future camera addon emulation
void Camera_Start(int num);
void Camera_Stop(int num);
void Camera_CaptureFrame(int num, u32* frame, int width, int height, bool yuv);
void Camera_Start(int num, void* userdata);
void Camera_Stop(int num, void* userdata);
void Camera_CaptureFrame(int num, u32* frame, int width, int height, bool yuv, void* userdata);
struct DynamicLibrary;

View File

@ -602,7 +602,7 @@ void RTC::SaveDateTime()
{
int y, m, d, h, i, s;
GetDateTime(y, m, d, h, i, s);
Platform::WriteDateTime(y, m, d, h, i, s);
Platform::WriteDateTime(y, m, d, h, i, s, NDS.UserData);
}
void RTC::CmdRead()

View File

@ -260,7 +260,7 @@ void FirmwareMem::Release()
// Request that the start of the Wi-fi/userdata settings region
// through the end of the firmware blob be flushed to disk
Platform::WriteFirmware(FirmwareData, wifioffset, FirmwareData.Length() - wifioffset);
Platform::WriteFirmware(FirmwareData, wifioffset, FirmwareData.Length() - wifioffset, NDS.UserData);
}
SPIDevice::Release();

View File

@ -96,21 +96,21 @@ Wifi::Wifi(melonDS::NDS& nds) : NDS(nds)
//MPInited = false;
//LANInited = false;
Platform::MP_Init();
Platform::MP_Init(NDS.UserData);
MPInited = true;
Platform::LAN_Init();
Platform::LAN_Init(NDS.UserData);
LANInited = true;
WifiAP = new class WifiAP(this);
WifiAP = new class WifiAP(this, NDS.UserData);
}
Wifi::~Wifi()
{
if (MPInited)
Platform::MP_DeInit();
Platform::MP_DeInit(NDS.UserData);
if (LANInited)
Platform::LAN_DeInit();
Platform::LAN_DeInit(NDS.UserData);
delete WifiAP; WifiAP = nullptr;
@ -368,7 +368,7 @@ void Wifi::UpdatePowerOn()
ScheduleTimer(true);
Platform::MP_Begin();
Platform::MP_Begin(NDS.UserData);
}
else
{
@ -376,7 +376,7 @@ void Wifi::UpdatePowerOn()
NDS.CancelEvent(Event_Wifi);
Platform::MP_End();
Platform::MP_End(NDS.UserData);
}
}
@ -664,23 +664,23 @@ void Wifi::TXSendFrame(const TXSlot* slot, int num)
case 0:
case 2:
case 3:
Platform::MP_SendPacket(TXBuffer, 12+len, USTimestamp);
Platform::MP_SendPacket(TXBuffer, 12+len, USTimestamp, NDS.UserData);
if (!IsMP) WifiAP->SendPacket(TXBuffer, 12+len);
break;
case 1:
*(u16*)&TXBuffer[12 + 24+2] = MPClientMask;
Platform::MP_SendCmd(TXBuffer, 12+len, USTimestamp);
Platform::MP_SendCmd(TXBuffer, 12+len, USTimestamp, NDS.UserData);
break;
case 5:
IncrementTXCount(slot);
Platform::MP_SendReply(TXBuffer, 12+len, USTimestamp, IOPORT(W_AIDLow));
Platform::MP_SendReply(TXBuffer, 12+len, USTimestamp, IOPORT(W_AIDLow), NDS.UserData);
break;
case 4:
*(u64*)&TXBuffer[0xC + 24] = USCounter;
Platform::MP_SendPacket(TXBuffer, 12+len, USTimestamp);
Platform::MP_SendPacket(TXBuffer, 12+len, USTimestamp, NDS.UserData);
break;
}
}
@ -836,7 +836,7 @@ void Wifi::SendMPDefaultReply()
*(u16*)&reply[0xC + 0x16] = IOPORT(W_TXSeqNo) << 4;
*(u32*)&reply[0xC + 0x18] = 0;
int txlen = Platform::MP_SendReply(reply, 12+28, USTimestamp, IOPORT(W_AIDLow));
int txlen = Platform::MP_SendReply(reply, 12+28, USTimestamp, IOPORT(W_AIDLow), NDS.UserData);
WIFI_LOG("wifi: sent %d/40 bytes of MP default reply\n", txlen);
}
@ -946,7 +946,7 @@ void Wifi::SendMPAck(u16 cmdcount, u16 clientfail)
*(u32*)&ack[0] = PreambleLen(TXSlots[1].Rate);
}
int txlen = Platform::MP_SendAck(ack, 12+32, USTimestamp);
int txlen = Platform::MP_SendAck(ack, 12+32, USTimestamp, NDS.UserData);
WIFI_LOG("wifi: sent %d/44 bytes of MP ack, %d %d\n", txlen, ComStatus, RXTime);
}
@ -1069,7 +1069,7 @@ bool Wifi::ProcessTX(TXSlot* slot, int num)
u16 res = 0;
if (MPClientMask)
res = Platform::MP_RecvReplies(MPClientReplies, USTimestamp, MPClientMask);
res = Platform::MP_RecvReplies(MPClientReplies, USTimestamp, MPClientMask, NDS.UserData);
MPClientFail &= ~res;
// TODO: 112 likely includes the ack preamble, which needs adjusted
@ -1508,7 +1508,7 @@ void Wifi::FinishRX()
// in the case this client wasn't ready to send a reply
// TODO: also send this if we have RX disabled
Platform::MP_SendReply(nullptr, 0, USTimestamp, 0);
Platform::MP_SendReply(nullptr, 0, USTimestamp, 0, NDS.UserData);
}
}
else if ((rxflags & 0x800F) == 0x8001)
@ -1592,13 +1592,13 @@ bool Wifi::CheckRX(int type) // 0=regular 1=MP replies 2=MP host frames
if (type == 0)
{
rxlen = Platform::MP_RecvPacket(RXBuffer, &timestamp);
rxlen = Platform::MP_RecvPacket(RXBuffer, &timestamp, NDS.UserData);
if ((rxlen <= 0) && (!IsMP))
rxlen = WifiAP->RecvPacket(RXBuffer);
}
else
{
rxlen = Platform::MP_RecvHostPacket(RXBuffer, &timestamp);
rxlen = Platform::MP_RecvHostPacket(RXBuffer, &timestamp, NDS.UserData);
if (rxlen < 0)
{
// host is gone

View File

@ -71,7 +71,7 @@ bool MACEqual(const u8* a, const u8* b);
bool MACIsBroadcast(const u8* a);
WifiAP::WifiAP(Wifi* client) : Client(client)
WifiAP::WifiAP(Wifi* client, void* userdata) : Client(client), UserData(userdata)
{
}
@ -301,7 +301,7 @@ int WifiAP::SendPacket(const u8* data, int len)
*(u16*)&LANBuffer[12] = *(u16*)&data[30]; // type
memcpy(&LANBuffer[14], &data[32], lan_len - 14);
Platform::LAN_SendPacket(LANBuffer, lan_len);
Platform::LAN_SendPacket(LANBuffer, lan_len, UserData);
}
}
return len;
@ -368,7 +368,7 @@ int WifiAP::RecvPacket(u8* data)
if (ClientStatus < 2) return 0;
int rxlen = Platform::LAN_RecvPacket(LANBuffer);
int rxlen = Platform::LAN_RecvPacket(LANBuffer, UserData);
if (rxlen > 0)
{
// check destination MAC

View File

@ -28,7 +28,7 @@ class Wifi;
class WifiAP
{
public:
WifiAP(Wifi* client);
WifiAP(Wifi* client, void* userdata);
~WifiAP();
void Reset();
@ -44,6 +44,7 @@ public:
private:
Wifi* Client;
void* UserData;
u64 USCounter;

View File

@ -1127,9 +1127,9 @@ bool EmuInstance::updateConsole(UpdateConsoleNDSArgs&& _ndsargs, UpdateConsoleGB
if (nds) delete nds;
if (consoletype == 1)
nds = new DSi(std::move(dsiargs.value()));
nds = new DSi(std::move(dsiargs.value()), this);
else
nds = new NDS(std::move(ndsargs));
nds = new NDS(std::move(ndsargs), this);
NDS::Current = nds;
nds->Reset();
@ -1676,7 +1676,7 @@ bool EmuInstance::loadROM(QStringList filepath, bool reset)
.SRAMLength = savelen,
};
auto cart = NDSCart::ParseROM(std::move(filedata), filelen, std::move(cartargs));
auto cart = NDSCart::ParseROM(std::move(filedata), filelen, this, std::move(cartargs));
if (!cart)
{
// If we couldn't parse the ROM...
@ -1812,7 +1812,7 @@ bool EmuInstance::loadGBAROM(QStringList filepath)
CloseFile(sav);
}
auto cart = GBACart::ParseROM(std::move(filedata), filelen, std::move(savedata), savelen);
auto cart = GBACart::ParseROM(std::move(filedata), filelen, std::move(savedata), savelen, this);
if (!cart)
{
QMessageBox::critical(mainWindow, "melonDS", "Failed to load the GBA ROM.");

View File

@ -50,9 +50,6 @@
extern CameraManager* camManager[2];
// REMOVE ME
extern EmuInstance* testinst;
void emuStop();
// TEMP
@ -63,8 +60,9 @@ void emuStop();
namespace melonDS::Platform
{
void SignalStop(StopReason reason)
void SignalStop(StopReason reason, void* userdata)
{
EmuInstance* inst = (EmuInstance*)userdata;
emuStop();
switch (reason)
{
@ -412,23 +410,23 @@ void Sleep(u64 usecs)
}
void WriteNDSSave(const u8* savedata, u32 savelen, u32 writeoffset, u32 writelen)
void WriteNDSSave(const u8* savedata, u32 savelen, u32 writeoffset, u32 writelen, void* userdata)
{
EmuInstance* inst = testinst;
EmuInstance* inst = (EmuInstance*)userdata;
if (inst->ndsSave)
inst->ndsSave->RequestFlush(savedata, savelen, writeoffset, writelen);
}
void WriteGBASave(const u8* savedata, u32 savelen, u32 writeoffset, u32 writelen)
void WriteGBASave(const u8* savedata, u32 savelen, u32 writeoffset, u32 writelen, void* userdata)
{
EmuInstance* inst = testinst;
EmuInstance* inst = (EmuInstance*)userdata;
if (inst->gbaSave)
inst->gbaSave->RequestFlush(savedata, savelen, writeoffset, writelen);
}
void WriteFirmware(const Firmware& firmware, u32 writeoffset, u32 writelen)
void WriteFirmware(const Firmware& firmware, u32 writeoffset, u32 writelen, void* userdata)
{
EmuInstance* inst = testinst;
EmuInstance* inst = (EmuInstance*)userdata;
if (!inst->firmwareSave)
return;
@ -458,72 +456,81 @@ void WriteFirmware(const Firmware& firmware, u32 writeoffset, u32 writelen)
}
void WriteDateTime(int year, int month, int day, int hour, int minute, int second)
void WriteDateTime(int year, int month, int day, int hour, int minute, int second, void* userdata)
{
EmuInstance* inst = (EmuInstance*)userdata;
QDateTime hosttime = QDateTime::currentDateTime();
QDateTime time = QDateTime(QDate(year, month, day), QTime(hour, minute, second));
auto& cfg = testinst->getLocalConfig();
auto& cfg = inst->getLocalConfig();
cfg.SetInt64("RTC.Offset", hosttime.secsTo(time));
Config::Save();
}
bool MP_Init()
bool MP_Init(void* userdata)
{
return LocalMP::Init();
//return LocalMP::Init();
return true;
}
void MP_DeInit()
void MP_DeInit(void* userdata)
{
return LocalMP::DeInit();
//return LocalMP::DeInit();
}
void MP_Begin()
void MP_Begin(void* userdata)
{
return LocalMP::Begin();
//return LocalMP::Begin();
}
void MP_End()
void MP_End(void* userdata)
{
return LocalMP::End();
//return LocalMP::End();
}
int MP_SendPacket(u8* data, int len, u64 timestamp)
int MP_SendPacket(u8* data, int len, u64 timestamp, void* userdata)
{
return LocalMP::SendPacket(data, len, timestamp);
//return LocalMP::SendPacket(data, len, timestamp);
return 0;
}
int MP_RecvPacket(u8* data, u64* timestamp)
int MP_RecvPacket(u8* data, u64* timestamp, void* userdata)
{
return LocalMP::RecvPacket(data, timestamp);
//return LocalMP::RecvPacket(data, timestamp);
return 0;
}
int MP_SendCmd(u8* data, int len, u64 timestamp)
int MP_SendCmd(u8* data, int len, u64 timestamp, void* userdata)
{
return LocalMP::SendCmd(data, len, timestamp);
//return LocalMP::SendCmd(data, len, timestamp);
return 0;
}
int MP_SendReply(u8* data, int len, u64 timestamp, u16 aid)
int MP_SendReply(u8* data, int len, u64 timestamp, u16 aid, void* userdata)
{
return LocalMP::SendReply(data, len, timestamp, aid);
//return LocalMP::SendReply(data, len, timestamp, aid);
return 0;
}
int MP_SendAck(u8* data, int len, u64 timestamp)
int MP_SendAck(u8* data, int len, u64 timestamp, void* userdata)
{
return LocalMP::SendAck(data, len, timestamp);
//return LocalMP::SendAck(data, len, timestamp);
return 0;
}
int MP_RecvHostPacket(u8* data, u64* timestamp)
int MP_RecvHostPacket(u8* data, u64* timestamp, void* userdata)
{
return LocalMP::RecvHostPacket(data, timestamp);
//return LocalMP::RecvHostPacket(data, timestamp);
return 0;
}
u16 MP_RecvReplies(u8* data, u64 timestamp, u16 aidmask)
u16 MP_RecvReplies(u8* data, u64 timestamp, u16 aidmask, void* userdata)
{
return LocalMP::RecvReplies(data, timestamp, aidmask);
//return LocalMP::RecvReplies(data, timestamp, aidmask);
return 0;
}
bool LAN_Init()
bool LAN_Init(void* userdata)
{
/*if (testinst->getGlobalConfig().GetBool("LAN.DirectMode"))
{
@ -539,7 +546,7 @@ bool LAN_Init()
return true;
}
void LAN_DeInit()
void LAN_DeInit(void* userdata)
{
// checkme. blarg
//if (Config::DirectLAN)
@ -550,7 +557,7 @@ void LAN_DeInit()
LAN_Socket::DeInit();*/
}
int LAN_SendPacket(u8* data, int len)
int LAN_SendPacket(u8* data, int len, void* userdata)
{
/*if (testinst->getGlobalConfig().GetBool("LAN.DirectMode"))
return LAN_PCap::SendPacket(data, len);
@ -559,7 +566,7 @@ int LAN_SendPacket(u8* data, int len)
return 0;
}
int LAN_RecvPacket(u8* data)
int LAN_RecvPacket(u8* data, void* userdata)
{
/*if (testinst->getGlobalConfig().GetBool("LAN.DirectMode"))
return LAN_PCap::RecvPacket(data);
@ -569,17 +576,17 @@ int LAN_RecvPacket(u8* data)
}
void Camera_Start(int num)
void Camera_Start(int num, void* userdata)
{
return camManager[num]->start();
}
void Camera_Stop(int num)
void Camera_Stop(int num, void* userdata)
{
return camManager[num]->stop();
}
void Camera_CaptureFrame(int num, u32* frame, int width, int height, bool yuv)
void Camera_CaptureFrame(int num, u32* frame, int width, int height, bool yuv, void* userdata)
{
return camManager[num]->captureFrame(frame, width, height, yuv);
}

View File

@ -1831,8 +1831,8 @@ void MainWindow::onOpenWifiSettings()
void MainWindow::onWifiSettingsFinished(int res)
{
Platform::LAN_DeInit();
Platform::LAN_Init();
//Platform::LAN_DeInit();
//Platform::LAN_Init();
if (WifiSettingsDialog::needsReset)
onReset();