Add support for different GBA slot configurations

This commit is contained in:
Rafael Caetano 2024-06-27 19:23:22 +01:00
parent fe50a17109
commit dc44fa17f9
3 changed files with 81 additions and 19 deletions

View File

@ -56,9 +56,7 @@ namespace MelonDSAndroid
// Variables used to keep the current state so that emulation can be reset
char* currentRomPath = NULL;
char* currentSramPath = NULL;
char* currentGbaRomPath = NULL;
char* currentGbaSramPath = NULL;
bool currentLoadGbaRom;
RomGbaSlotConfig* currentGbaSlotConfig = nullptr;
RunMode currentRunMode;
void setupAudioOutputStream(int audioLatency, int volume);
@ -67,6 +65,7 @@ namespace MelonDSAndroid
void resetAudioOutputStream();
bool setupOpenGlContext();
void cleanupOpenGlContext();
void updateCurrentGbaSlotConfig(RomGbaSlotConfig* newConfig);
void copyString(char** dest, const char* source);
/**
@ -259,13 +258,11 @@ namespace MelonDSAndroid
currentConfiguration = emulatorConfiguration;
}
int loadRom(char* romPath, char* sramPath, bool loadGbaRom, char* gbaRom, char* gbaSram)
int loadRom(char* romPath, char* sramPath, RomGbaSlotConfig* gbaSlotConfig)
{
copyString(&currentRomPath, romPath);
copyString(&currentSramPath, sramPath);
copyString(&currentGbaRomPath, gbaRom);
copyString(&currentGbaSramPath, gbaSram);
currentLoadGbaRom = loadGbaRom;
updateCurrentGbaSlotConfig(gbaSlotConfig);
currentRunMode = ROM;
bool loaded = ROMManager::LoadROM(romPath, sramPath, true);
@ -273,10 +270,18 @@ namespace MelonDSAndroid
return 2;
// Slot 2 is not supported in DSi
if (loadGbaRom && NDS::ConsoleType == 0)
if (NDS::ConsoleType == 0)
{
if (!ROMManager::LoadGBAROM(gbaRom, gbaSram))
return 1;
if (gbaSlotConfig->type == GBA_ROM)
{
RomGbaSlotConfigGbaRom* gbaRomConfig = (RomGbaSlotConfigGbaRom*) gbaSlotConfig;
if (!ROMManager::LoadGBAROM(gbaRomConfig->romPath, gbaRomConfig->savePath))
return 1;
}
else if (gbaSlotConfig->type == MEMORY_EXPANSION)
{
ROMManager::LoadGBAAddon(NDS::GBAAddon_RAMExpansion);
}
}
NDS::Start();
@ -410,7 +415,7 @@ namespace MelonDSAndroid
if (currentRunMode == ROM) {
RetroAchievements::Reset();
NDS::Reset();
int result = loadRom(currentRomPath, currentSramPath, currentLoadGbaRom, currentGbaRomPath, currentGbaSramPath);
int result = loadRom(currentRomPath, currentSramPath, currentGbaSlotConfig);
if (result != 2 && arCodeFile != NULL) {
AREngine::SetCodeFile(arCodeFile);
}
@ -567,12 +572,8 @@ namespace MelonDSAndroid
free(currentRomPath);
free(currentSramPath);
free(currentGbaRomPath);
free(currentGbaSramPath);
currentRomPath = NULL;
currentSramPath = NULL;
currentGbaRomPath = NULL;
currentGbaSramPath = NULL;
cleanupAudioOutputStream();
cleanupOpenGlContext();
@ -592,6 +593,12 @@ namespace MelonDSAndroid
arCodeFile = NULL;
}
if (currentGbaSlotConfig != NULL)
{
delete currentGbaSlotConfig;
currentGbaSlotConfig = NULL;
}
assetManager = NULL;
textureBuffer = NULL;
}
@ -725,6 +732,29 @@ namespace MelonDSAndroid
openGlContext = nullptr;
}
void updateCurrentGbaSlotConfig(RomGbaSlotConfig* newConfig)
{
if (currentGbaSlotConfig != nullptr)
delete currentGbaSlotConfig;
if (newConfig->type == RomGbaSlotConfigType::GBA_ROM)
{
RomGbaSlotConfigGbaRom* gbaRomConfig = new RomGbaSlotConfigGbaRom;
gbaRomConfig->romPath = ((RomGbaSlotConfigGbaRom*) newConfig)->romPath;
gbaRomConfig->savePath = ((RomGbaSlotConfigGbaRom*) newConfig)->savePath;
currentGbaSlotConfig = (RomGbaSlotConfig*) gbaRomConfig;
}
else if (newConfig->type == RomGbaSlotConfigType::MEMORY_EXPANSION)
{
currentGbaSlotConfig = (RomGbaSlotConfig*) new RomGbaSlotConfigMemoryExpansion;
}
else
{
currentGbaSlotConfig = (RomGbaSlotConfig*) new RomGbaSlotConfigNone;
}
}
void copyString(char** dest, const char* source)
{
if (source == nullptr)

View File

@ -5,6 +5,7 @@
#include "AndroidFileHandler.h"
#include "AndroidCameraHandler.h"
#include "RewindManager.h"
#include "RomGbaSlotConfig.h"
#include "retroachievements/RAAchievement.h"
#include "retroachievements/RACallback.h"
#include "../types.h"
@ -84,13 +85,11 @@ namespace MelonDSAndroid {
*
* @param romPath The path to the NDS rom
* @param sramPath The path to the rom's SRAM file
* @param loadGbaRom If a GBA ROM must also be loaded
* @param gbaRom The path to the GBA ROM
* @param gbaSram The path to the GBA rom's SRAM file
* @param gbaSlotConfig The config to be used for the GBA slot
* @return The load result. 0 if everything was loaded successfully, 1 if the NDS ROM was loaded but the GBA ROM
* failed to load, 2 if the NDS ROM failed to load
*/
extern int loadRom(char* romPath, char* sramPath, bool loadGbaRom, char* gbaRom, char* gbaSram);
extern int loadRom(char* romPath, char* sramPath, RomGbaSlotConfig* gbaSlotConfig);
extern int bootFirmware();
extern void start();
extern u32 loop();

View File

@ -0,0 +1,33 @@
#ifndef ROMGBASLOTCONFIG_H
#define ROMGBASLOTCONFIG_H
#include <string>
namespace MelonDSAndroid
{
enum RomGbaSlotConfigType {
NONE = 0,
GBA_ROM = 1,
MEMORY_EXPANSION = 2
} ;
struct RomGbaSlotConfig {
RomGbaSlotConfigType type;
};
struct RomGbaSlotConfigNone {
RomGbaSlotConfig _base = { .type = RomGbaSlotConfigType::NONE };
};
struct RomGbaSlotConfigGbaRom {
RomGbaSlotConfig _base = { .type = RomGbaSlotConfigType::GBA_ROM };
std::string romPath;
std::string savePath;
};
struct RomGbaSlotConfigMemoryExpansion {
RomGbaSlotConfig _base = { .type = RomGbaSlotConfigType::MEMORY_EXPANSION };
};
}
#endif //ROMGBASLOTCONFIG_H