remove old cruft

This commit is contained in:
Arisotura
2022-01-06 21:57:30 +01:00
parent 004c13dc7e
commit 43b551b042
6 changed files with 0 additions and 426 deletions

View File

@ -36,7 +36,6 @@ add_library(core STATIC
melonDLDI.h
NDS.cpp
NDSCart.cpp
NDSCart_SRAMManager.cpp
Platform.h
ROMList.h
ROMSource.h

View File

@ -32,7 +32,6 @@
#include "Wifi.h"
#include "AREngine.h"
#include "Platform.h"
#include "NDSCart_SRAMManager.h"
#include "FreeBIOS.h"
#ifdef JIT_ENABLED

View File

@ -1,184 +0,0 @@
/*
Copyright 2016-2021 Arisotura
This file is part of melonDS.
melonDS is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option)
any later version.
melonDS is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with melonDS. If not, see http://www.gnu.org/licenses/.
*/
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <time.h>
#include <atomic>
#include "NDSCart_SRAMManager.h"
#include "Platform.h"
namespace NDSCart_SRAMManager
{
Platform::Thread* FlushThread;
std::atomic_bool FlushThreadRunning;
Platform::Mutex* SecondaryBufferLock;
char Path[1024];
u8* Buffer;
u32 Length;
u8* SecondaryBuffer;
u32 SecondaryBufferLength;
time_t TimeAtLastFlushRequest;
// We keep versions in case the user closes the application before
// a flush cycle is finished.
u32 PreviousFlushVersion;
u32 FlushVersion;
void FlushThreadFunc();
bool Init()
{
SecondaryBufferLock = Platform::Mutex_Create();
return true;
}
void DeInit()
{
if (FlushThreadRunning)
{
FlushThreadRunning = false;
Platform::Thread_Wait(FlushThread);
Platform::Thread_Free(FlushThread);
FlushSecondaryBuffer();
}
if (SecondaryBuffer) delete[] SecondaryBuffer;
SecondaryBuffer = NULL;
Platform::Mutex_Free(SecondaryBufferLock);
}
void Setup(const char* path, u8* buffer, u32 length)
{
// Flush SRAM in case there is unflushed data from previous state.
FlushSecondaryBuffer();
Platform::Mutex_Lock(SecondaryBufferLock);
strncpy(Path, path, 1023);
Path[1023] = '\0';
Buffer = buffer;
Length = length;
if (SecondaryBuffer) delete[] SecondaryBuffer; // Delete secondary buffer, there might be previous state.
SecondaryBuffer = new u8[length];
SecondaryBufferLength = length;
FlushVersion = 0;
PreviousFlushVersion = 0;
TimeAtLastFlushRequest = 0;
Platform::Mutex_Unlock(SecondaryBufferLock);
if (path[0] != '\0' && !FlushThreadRunning)
{
FlushThread = Platform::Thread_Create(FlushThreadFunc);
FlushThreadRunning = true;
}
else if (path[0] == '\0' && FlushThreadRunning)
{
FlushThreadRunning = false;
Platform::Thread_Wait(FlushThread);
Platform::Thread_Free(FlushThread);
}
}
void RequestFlush()
{
Platform::Mutex_Lock(SecondaryBufferLock);
printf("NDS SRAM: Flush requested\n");
memcpy(SecondaryBuffer, Buffer, Length);
FlushVersion++;
TimeAtLastFlushRequest = time(NULL);
Platform::Mutex_Unlock(SecondaryBufferLock);
}
void FlushThreadFunc()
{
for (;;)
{
Platform::Sleep(100 * 1000); // 100ms
if (!FlushThreadRunning) return;
// We debounce for two seconds after last flush request to ensure that writing has finished.
if (TimeAtLastFlushRequest == 0 || difftime(time(NULL), TimeAtLastFlushRequest) < 2)
{
continue;
}
FlushSecondaryBuffer();
}
}
void FlushSecondaryBuffer(u8* dst, s32 dstLength)
{
// When flushing to a file, there's no point in re-writing the exact same data.
if (!dst && !NeedsFlush()) return;
// When flushing to memory, we don't know if dst already has any data so we only check that we CAN flush.
if (dst && dstLength < SecondaryBufferLength) return;
Platform::Mutex_Lock(SecondaryBufferLock);
if (dst)
{
memcpy(dst, SecondaryBuffer, SecondaryBufferLength);
}
else
{
FILE* f = Platform::OpenFile(Path, "wb");
if (f)
{
printf("NDS SRAM: Written\n");
fwrite(SecondaryBuffer, SecondaryBufferLength, 1, f);
fclose(f);
}
}
PreviousFlushVersion = FlushVersion;
TimeAtLastFlushRequest = 0;
Platform::Mutex_Unlock(SecondaryBufferLock);
}
bool NeedsFlush()
{
return FlushVersion != PreviousFlushVersion;
}
void UpdateBuffer(u8* src, s32 srcLength)
{
if (!src || srcLength != Length) return;
// should we create a lock for the primary buffer? this method is not intended to be called from a secondary thread in the way Flush is
memcpy(Buffer, src, srcLength);
Platform::Mutex_Lock(SecondaryBufferLock);
memcpy(SecondaryBuffer, src, srcLength);
Platform::Mutex_Unlock(SecondaryBufferLock);
PreviousFlushVersion = FlushVersion;
}
}

View File

@ -1,39 +0,0 @@
/*
Copyright 2016-2021 Arisotura
This file is part of melonDS.
melonDS is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option)
any later version.
melonDS is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with melonDS. If not, see http://www.gnu.org/licenses/.
*/
#ifndef NDSCART_SRAMMANAGER_H
#define NDSCART_SRAMMANAGER_H
#include "types.h"
namespace NDSCart_SRAMManager
{
extern u32 SecondaryBufferLength;
bool Init();
void DeInit();
void Setup(const char* path, u8* buffer, u32 length);
void RequestFlush();
bool NeedsFlush();
void FlushSecondaryBuffer(u8* dst = NULL, s32 dstLength = 0);
void UpdateBuffer(u8* src, s32 srcLength);
}
#endif // NDSCART_SRAMMANAGER_H

View File

@ -1,200 +0,0 @@
/*
Copyright 2016-2021 Arisotura
This file is part of melonDS.
melonDS is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option)
any later version.
melonDS is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with melonDS. If not, see http://www.gnu.org/licenses/.
*/
#include <stdio.h>
#include <string.h>
#include <string>
#include <utility>
#ifdef ARCHIVE_SUPPORT_ENABLED
#include "ArchiveUtil.h"
#endif
#include "FrontendUtil.h"
#include "SharedConfig.h"
#include "Platform.h"
#include "NDS.h"
#include "DSi.h"
#include "GBACart.h"
#include "AREngine.h"
namespace Frontend
{
bool SavestateLoaded;
// SAVESTATE TODO
// * configurable paths. not everyone wants their ROM directory to be polluted, I guess.
/*
std::string GetSavestateName(int slot)
{
std::string filename;
if (ROMPath[ROMSlot_NDS].empty()) // running firmware, no ROM
{
filename = "firmware";
}
else
{
std::string rompath;
std::string ext = ROMPath[ROMSlot_NDS].substr(ROMPath[ROMSlot_NDS].length() - 4);
std::transform(ext.begin(), ext.end(), ext.begin(), tolower);
// TODO!!! MORE SHIT THAT IS GONNA ASPLODE
if (ext == ".nds" || ext == ".srl" || ext == ".dsi")
rompath = ROMPath[ROMSlot_NDS];
else
rompath = SRAMPath[ROMSlot_NDS]; // If archive, construct ssname from sram file
filename = rompath.substr(0, rompath.rfind('.'));
}
filename += ".ml";
filename += ('0'+slot);
return filename;
}
bool SavestateExists(int slot)
{
std::string ssfile = GetSavestateName(slot);
return Platform::FileExists(ssfile);
}
bool LoadState(std::string filename)
{
u32 oldGBACartCRC = GBACart::CartCRC;
// backup
Savestate* backup = new Savestate("timewarp.mln", true);
NDS::DoSavestate(backup);
delete backup;
bool failed = false;
Savestate* state = new Savestate(filename, false);
if (state->Error)
{
delete state;
//uiMsgBoxError(MainWindow, "Error", "Could not load savestate file.");
// current state might be crapoed, so restore from sane backup
state = new Savestate("timewarp.mln", false);
failed = true;
}
NDS::DoSavestate(state);
delete state;
if (!failed)
{
if (Config::SavestateRelocSRAM && !ROMPath[ROMSlot_NDS].empty())
{
PrevSRAMPath[ROMSlot_NDS] = SRAMPath[ROMSlot_NDS];
// TODO: how should this interact with custom paths?
SRAMPath[ROMSlot_NDS] = filename + ".sav";
// NDS::RelocateSave(SRAMPath[ROMSlot_NDS].c_str(), false);
}
bool loadedPartialGBAROM = false;
// in case we have a GBA cart inserted, and the GBA ROM changes
// due to having loaded a save state, we do not want to reload
// the previous cartridge on reset, or commit writes to any
// loaded save file. therefore, their paths are "nulled".
if (GBACart::CartInserted && GBACart::CartCRC != oldGBACartCRC)
{
ROMPath[ROMSlot_GBA] = "";
SRAMPath[ROMSlot_GBA] = "";
loadedPartialGBAROM = true;
}
// TODO forward this to user in a meaningful way!!
/*char msg[64];
if (slot > 0) sprintf(msg, "State loaded from slot %d%s",
slot, loadedPartialGBAROM ? " (GBA ROM header only)" : "");
else sprintf(msg, "State loaded from file%s",
loadedPartialGBAROM ? " (GBA ROM header only)" : "");
OSD::AddMessage(0, msg);*-/
SavestateLoaded = true;
}
return !failed;
}
bool SaveState(std::string filename)
{
Savestate* state = new Savestate(filename, true);
if (state->Error)
{
delete state;
return false;
}
else
{
NDS::DoSavestate(state);
delete state;
if (Config::SavestateRelocSRAM && !ROMPath[ROMSlot_NDS].empty())
{
// TODO: how should this interact with custom paths?
SRAMPath[ROMSlot_NDS] = filename + ".sav";
// NDS::RelocateSave(SRAMPath[ROMSlot_NDS].c_str(), true);
}
}
return true;
}
void UndoStateLoad()
{
if (!SavestateLoaded) return;
// pray that this works
// what do we do if it doesn't???
// but it should work.
Savestate* backup = new Savestate("timewarp.mln", false);
NDS::DoSavestate(backup);
delete backup;
if (!ROMPath[ROMSlot_NDS].empty())
{
SRAMPath[ROMSlot_NDS] = PrevSRAMPath[ROMSlot_NDS];
// NDS::RelocateSave(SRAMPath[ROMSlot_NDS].c_str(), false);
}
}*/
}

View File

@ -31,7 +31,6 @@ SET(SOURCES_QT_SDL
ArchiveUtil.h
ArchiveUtil.cpp
../Util_ROM.cpp
../Util_Video.cpp
../Util_Audio.cpp
../FrontendUtil.h