mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-08 23:25:40 +12:00
Introduce 2 methods of resetting the emulator; with and without reload
This commit is contained in:
parent
effc9543b3
commit
b352309290
2 changed files with 13 additions and 6 deletions
|
@ -61,12 +61,18 @@ class Emulator {
|
||||||
std::optional<std::filesystem::path> romPath = std::nullopt;
|
std::optional<std::filesystem::path> romPath = std::nullopt;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
// Decides whether to reload or not reload the ROM when resetting. We use enum class over a plain bool for clarity.
|
||||||
|
// If NoReload is selected, the emulator will not reload its selected ROM. This is useful for things like booting up the emulator, or resetting to
|
||||||
|
// change ROMs. If Reload is selected, the emulator will reload its selected ROM. This is useful for eg a "reset" button that keeps the current ROM
|
||||||
|
// and just resets the emu
|
||||||
|
enum class ReloadOption { NoReload, Reload };
|
||||||
|
|
||||||
Emulator();
|
Emulator();
|
||||||
~Emulator();
|
~Emulator();
|
||||||
|
|
||||||
void step();
|
void step();
|
||||||
void render();
|
void render();
|
||||||
void reset();
|
void reset(ReloadOption reload);
|
||||||
void run();
|
void run();
|
||||||
void runFrame();
|
void runFrame();
|
||||||
|
|
||||||
|
|
|
@ -53,12 +53,12 @@ Emulator::Emulator() : kernel(cpu, memory, gpu), cpu(memory, kernel), gpu(memory
|
||||||
}
|
}
|
||||||
|
|
||||||
config.load(std::filesystem::current_path() / "config.toml");
|
config.load(std::filesystem::current_path() / "config.toml");
|
||||||
reset();
|
reset(ReloadOption::NoReload);
|
||||||
}
|
}
|
||||||
|
|
||||||
Emulator::~Emulator() { config.save(std::filesystem::current_path() / "config.toml"); }
|
Emulator::~Emulator() { config.save(std::filesystem::current_path() / "config.toml"); }
|
||||||
|
|
||||||
void Emulator::reset() {
|
void Emulator::reset(ReloadOption reload) {
|
||||||
cpu.reset();
|
cpu.reset();
|
||||||
gpu.reset();
|
gpu.reset();
|
||||||
memory.reset();
|
memory.reset();
|
||||||
|
@ -69,8 +69,9 @@ void Emulator::reset() {
|
||||||
// Otherwise resetting the kernel or cpu might nuke them
|
// Otherwise resetting the kernel or cpu might nuke them
|
||||||
cpu.setReg(13, VirtualAddrs::StackTop); // Set initial SP
|
cpu.setReg(13, VirtualAddrs::StackTop); // Set initial SP
|
||||||
|
|
||||||
// If a ROM is active and we reset, reload it. This is necessary to set up stack, executable memory, .data/.rodata/.bss all over again
|
// If a ROM is active and we reset, with the reload option enabled then reload it.
|
||||||
if (romType != ROMType::None && romPath.has_value()) {
|
// This is necessary to set up stack, executable memory, .data/.rodata/.bss all over again
|
||||||
|
if (reload == ReloadOption::Reload && romType != ROMType::None && romPath.has_value()) {
|
||||||
bool success = loadROM(romPath.value());
|
bool success = loadROM(romPath.value());
|
||||||
if (!success) {
|
if (!success) {
|
||||||
romType = ROMType::None;
|
romType = ROMType::None;
|
||||||
|
@ -335,7 +336,7 @@ void Emulator::runFrame() { cpu.runFrame(); }
|
||||||
bool Emulator::loadROM(const std::filesystem::path& path) {
|
bool Emulator::loadROM(const std::filesystem::path& path) {
|
||||||
// Reset the emulator if we've already loaded a ROM
|
// Reset the emulator if we've already loaded a ROM
|
||||||
if (romType != ROMType::None) {
|
if (romType != ROMType::None) {
|
||||||
reset();
|
reset(ReloadOption::NoReload);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get path for saving files (AppData on Windows, /home/user/.local/share/ApplcationName on Linux, etc)
|
// Get path for saving files (AppData on Windows, /home/user/.local/share/ApplcationName on Linux, etc)
|
||||||
|
|
Loading…
Add table
Reference in a new issue