mirror of
https://github.com/rafaelvcaetano/melonDS-android-lib.git
synced 2025-02-17 03:47:38 +00:00
Add support for different GBA slot configurations
This commit is contained in:
parent
fe50a17109
commit
dc44fa17f9
@ -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(¤tRomPath, romPath);
|
||||
copyString(¤tSramPath, sramPath);
|
||||
copyString(¤tGbaRomPath, gbaRom);
|
||||
copyString(¤tGbaSramPath, 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)
|
||||
|
@ -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();
|
||||
|
33
src/android/RomGbaSlotConfig.h
Normal file
33
src/android/RomGbaSlotConfig.h
Normal 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
|
Loading…
x
Reference in New Issue
Block a user