Skip to content

Commit

Permalink
Emulator and misc updates
Browse files Browse the repository at this point in the history
* Imagine: Add overloaded constructor for DynArray using std::make_unique_for_overwrite() to optimize case where memory is immediately overwritten
* EmuFramework: Add system reset actions to key bindings
* EmuFramework: Allow inexact state sizes in uncompressGzipState()
* GBA.emu: Update core to VBA-M GIT 64d8cff (2023.11.16)
* NES.emu: Update core to FCEUX GIT 5a5faa7 (2023.10.26)
* Snes9x EX+: Update core to Snes9x GIT d30060c (2023.11.03)
  • Loading branch information
Robert Broglia committed Nov 17, 2023
1 parent 71bcd12 commit ce75bd1
Show file tree
Hide file tree
Showing 46 changed files with 992 additions and 463 deletions.
6 changes: 6 additions & 0 deletions EmuFramework/include/emuframework/AppKeyCode.hh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ enum class AppKeyCode : KeyCode
turboModifier,
exitApp,
rewind,
softReset,
hardReset,
resetMenu,
};

constexpr struct AppKeys
Expand All @@ -61,6 +64,9 @@ constexpr struct AppKeys
rewind = KeyInfo::appKey(AppKeyCode::rewind),
takeScreenshot = KeyInfo::appKey(AppKeyCode::takeScreenshot),
turboModifier = KeyInfo::appKey(AppKeyCode::turboModifier),
softReset = KeyInfo::appKey(AppKeyCode::softReset),
hardReset = KeyInfo::appKey(AppKeyCode::hardReset),
resetMenu = KeyInfo::appKey(AppKeyCode::resetMenu),
exitApp = KeyInfo::appKey(AppKeyCode::exitApp);

constexpr const KeyInfo *data() const { return &openMenu; }
Expand Down
7 changes: 6 additions & 1 deletion EmuFramework/include/emuframework/EmuSystem.hh
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ struct SaveStateFlags
uint8_t uncompressed:1{};
};

struct UncompressStateFlags
{
uint8_t estimatedExpectedSize:1{};
};

class EmuSystem
{
public:
Expand Down Expand Up @@ -247,7 +252,7 @@ public:
void loadState(EmuApp &, CStringView uri);
void saveState(CStringView uri);
DynArray<uint8_t> saveState();
DynArray<uint8_t> uncompressGzipState(std::span<uint8_t> buff, size_t expectedSize);
DynArray<uint8_t> uncompressGzipState(std::span<uint8_t> buff, size_t expectedSize, UncompressStateFlags flags = {});
bool stateExists(int slot) const;
static std::string_view stateSlotName(int slot);
std::string_view stateSlotName() { return stateSlotName(stateSlot()); }
Expand Down
24 changes: 24 additions & 0 deletions EmuFramework/src/EmuApp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <emuframework/FilePathOptionView.hh>
#include <emuframework/AppKeyCode.hh>
#include "gui/AutosaveSlotView.hh"
#include "gui/ResetAlertView.hh"
#include "InputDeviceData.hh"
#include "WindowData.hh"
#include "configFile.hh"
Expand Down Expand Up @@ -1383,6 +1384,29 @@ bool EmuApp::handleAppActionKeyInput(InputAction action, const Input::Event &src
postMessage(3, false, "Please set rewind states in Options➔System");
break;
}
case softReset:
{
if(!isPushed)
break;
syncEmulationThread();
system().reset(*this, EmuSystem::ResetMode::SOFT);
break;
}
case hardReset:
{
if(!isPushed)
break;
syncEmulationThread();
system().reset(*this, EmuSystem::ResetMode::HARD);
break;
}
case resetMenu:
{
if(!isPushed)
break;
viewController().pushAndShowModal(resetAlertView(attachParams(), *this), srcEvent, false);
break;
}
}
return false;
}
Expand Down
3 changes: 3 additions & 0 deletions EmuFramework/src/EmuInput.cc
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,9 @@ std::string_view toString(AppKeyCode code)
case AppKeyCode::slowMotion: return "Slow-motion";
case AppKeyCode::toggleSlowMotion: return "Toggle Slow-motion";
case AppKeyCode::rewind: return "Rewind";
case AppKeyCode::softReset: return "Soft Reset";
case AppKeyCode::hardReset: return "Hard Reset";
case AppKeyCode::resetMenu: return "Open Reset Menu";
};
return "";
}
Expand Down
8 changes: 4 additions & 4 deletions EmuFramework/src/EmuSystem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,19 @@ void EmuSystem::saveState(CStringView uri)

DynArray<uint8_t> EmuSystem::saveState()
{
DynArray<uint8_t> stateArr{stateSize()};
auto stateArr = dynArrayForOverwrite<uint8_t>(stateSize());
stateArr.trim(writeState(stateArr));
return stateArr;
}

DynArray<uint8_t> EmuSystem::uncompressGzipState(std::span<uint8_t> buff, size_t expectedSize)
DynArray<uint8_t> EmuSystem::uncompressGzipState(std::span<uint8_t> buff, size_t expectedSize, UncompressStateFlags flags)
{
assert(expectedSize);
auto uncompArr = DynArray<uint8_t>{expectedSize};
auto uncompArr = dynArrayForOverwrite<uint8_t>(expectedSize);
auto size = uncompressGzip(uncompArr, buff);
if(!size)
throw std::runtime_error("Error uncompressing state");
if(size != expectedSize)
if(!flags.estimatedExpectedSize && size != expectedSize)
throw std::runtime_error("Invalid state size");
return uncompArr;
}
Expand Down
75 changes: 75 additions & 0 deletions EmuFramework/src/gui/ResetAlertView.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/* This file is part of EmuFramework.
Imagine 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.
Imagine 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 EmuFramework. If not, see <http://www.gnu.org/licenses/> */

#include <imagine/gui/AlertView.hh>
#include <emuframework/EmuApp.hh>
#include <emuframework/EmuSystem.hh>

namespace EmuEx
{

class ResetAlertView : public BaseAlertView
{
public:
ResetAlertView(ViewAttachParams attach, UTF16Convertible auto &&label, EmuApp &app):
BaseAlertView{attach, IG_forward(label), items},
items
{
TextMenuItem
{
"Soft Reset", &defaultFace(),
[this, &app]()
{
app.system().reset(app, EmuSystem::ResetMode::SOFT);
app.showEmulation();
}
},
TextMenuItem
{
"Hard Reset", &defaultFace(),
[this, &app]()
{
app.system().reset(app, EmuSystem::ResetMode::HARD);
app.showEmulation();
}
},
TextMenuItem{"Cancel", &defaultFace(), [](){}}
} {}

protected:
std::array<TextMenuItem, 3> items;
};

inline std::unique_ptr<View> resetAlertView(ViewAttachParams attachParams, EmuApp &app)
{
if(EmuSystem::hasResetModes)
{
return std::make_unique<ResetAlertView>(attachParams, "Really reset?", app);
}
else
{
return std::make_unique<YesNoAlertView>(attachParams, "Really reset?",
YesNoAlertView::Delegates
{
.onYes = [&app]
{
app.system().reset(app, EmuSystem::ResetMode::SOFT);
app.showEmulation();
}
});
}
}

}
56 changes: 4 additions & 52 deletions EmuFramework/src/gui/SystemActionsView.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <emuframework/InputManagerView.hh>
#include <emuframework/BundledGamesView.hh>
#include "AutosaveSlotView.hh"
#include <imagine/gui/AlertView.hh>
#include "ResetAlertView.hh"
#include <imagine/gui/TextEntry.hh>
#include <imagine/base/ApplicationContext.hh>
#include <imagine/util/format.hh>
Expand All @@ -32,38 +32,6 @@
namespace EmuEx
{

class ResetAlertView : public BaseAlertView, public EmuAppHelper<ResetAlertView>
{
public:
ResetAlertView(ViewAttachParams attach, UTF16Convertible auto &&label, EmuSystem &sys):
BaseAlertView{attach, IG_forward(label), items},
items
{
TextMenuItem
{
"Soft Reset", &defaultFace(),
[this, &sys]()
{
sys.reset(app(), EmuSystem::ResetMode::SOFT);
app().showEmulation();
}
},
TextMenuItem
{
"Hard Reset", &defaultFace(),
[this, &sys]()
{
sys.reset(app(), EmuSystem::ResetMode::HARD);
app().showEmulation();
}
},
TextMenuItem{"Cancel", &defaultFace(), [](){}}
} {}

protected:
std::array<TextMenuItem, 3> items;
};

static auto autoSaveName(EmuApp &app)
{
return std::format("Autosave Slot ({})", app.autosaveManager().slotFullName());
Expand Down Expand Up @@ -96,25 +64,9 @@ SystemActionsView::SystemActionsView(ViewAttachParams attach, bool customMenu):
"Reset", &defaultFace(),
[this](const Input::Event &e)
{
if(system().hasContent())
{
if(EmuSystem::hasResetModes)
{
pushAndShowModal(makeView<ResetAlertView>("Really reset?", system()), e);
}
else
{
pushAndShowModal(makeView<YesNoAlertView>("Really reset?",
YesNoAlertView::Delegates
{
.onYes = [this]
{
system().reset(app(), EmuSystem::ResetMode::SOFT);
app().showEmulation();
}
}), e);
}
}
if(!system().hasContent())
return;
pushAndShowModal(resetAlertView(attachParams(), app()), e);
}
},
autosaveSlot
Expand Down
29 changes: 16 additions & 13 deletions EmuFramework/src/vcontrols/VController.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,24 @@ static void updateTexture(const EmuApp &app, VControllerElement &e, Gfx::Rendere
using enum AppKeyCode;
switch(AppKeyCode(btn.key.codes[0]))
{
case openMenu: return app.asset(AssetID::more); break;
case openContent: return app.asset(AssetID::openFile); break;
case saveState: return app.asset(AssetID::save); break;
case loadState: return app.asset(AssetID::load); break;
case decStateSlot: return app.asset(AssetID::leftSwitch); break;
case incStateSlot: return app.asset(AssetID::rightSwitch); break;
case openMenu: return app.asset(AssetID::more);
case openContent: return app.asset(AssetID::openFile);
case saveState: return app.asset(AssetID::save);
case loadState: return app.asset(AssetID::load);
case decStateSlot: return app.asset(AssetID::leftSwitch);
case incStateSlot: return app.asset(AssetID::rightSwitch);
case fastForward:
case toggleFastForward: return app.asset(AssetID::fast); break;
case takeScreenshot: return app.asset(AssetID::screenshot); break;
case openSystemActions: return app.asset(AssetID::menu); break;
case turboModifier: return app.asset(AssetID::speed); break;
case exitApp: return app.asset(AssetID::close); break;
case toggleFastForward: return app.asset(AssetID::fast);
case takeScreenshot: return app.asset(AssetID::screenshot);
case openSystemActions: return app.asset(AssetID::menu);
case turboModifier: return app.asset(AssetID::speed);
case exitApp: return app.asset(AssetID::close);
case slowMotion:
case toggleSlowMotion: return app.asset(AssetID::slow); break;
case rewind: return app.asset(AssetID::rewind); break;
case toggleSlowMotion: return app.asset(AssetID::slow);
case rewind: return app.asset(AssetID::rewind);
case softReset:
case hardReset:
case resetMenu: return app.asset(AssetID::arrow);
}
return app.asset(AssetID::more);
}());
Expand Down
86 changes: 44 additions & 42 deletions GBA.emu/src/vbam/NLS.h
Original file line number Diff line number Diff line change
@@ -1,45 +1,47 @@
#define N_(String) (String)

#define MSG_UNSUPPORTED_VBA_SGM 1
#define MSG_CANNOT_LOAD_SGM 2
#define MSG_SAVE_GAME_NOT_USING_BIOS 3
#define MSG_SAVE_GAME_USING_BIOS 4
#define MSG_UNSUPPORTED_SAVE_TYPE 5
#define MSG_CANNOT_OPEN_FILE 6
#define MSG_BAD_ZIP_FILE 7
#define MSG_NO_IMAGE_ON_ZIP 8
#define MSG_ERROR_OPENING_IMAGE 9
#define MSG_ERROR_READING_IMAGE 10
#define MSG_UNSUPPORTED_BIOS_FUNCTION 11
#define MSG_INVALID_BIOS_FILE_SIZE 12
#define MSG_INVALID_CHEAT_CODE 13
#define MSG_UNKNOWN_ARM_OPCODE 14
#define MSG_UNKNOWN_THUMB_OPCODE 15
#define MSG_ERROR_CREATING_FILE 16
#define MSG_FAILED_TO_READ_SGM 17
#define MSG_FAILED_TO_READ_RTC 18
#define MSG_UNSUPPORTED_VB_SGM 19
#define MSG_CANNOT_LOAD_SGM_FOR 20
#define MSG_ERROR_OPENING_IMAGE_FROM 21
#define MSG_ERROR_READING_IMAGE_FROM 22
#define MSG_UNSUPPORTED_ROM_SIZE 23
#define MSG_UNSUPPORTED_RAM_SIZE 24
#define MSG_UNKNOWN_CARTRIDGE_TYPE 25
#define MSG_MAXIMUM_NUMBER_OF_CHEATS 26
#define MSG_INVALID_GAMESHARK_CODE 27
#define MSG_INVALID_GAMEGENIE_CODE 28
#define MSG_INVALID_CHEAT_TO_REMOVE 29
#define MSG_INVALID_CHEAT_CODE_ADDRESS 30
#define MSG_UNSUPPORTED_VBA_SGM 1
#define MSG_CANNOT_LOAD_SGM 2
#define MSG_SAVE_GAME_NOT_USING_BIOS 3
#define MSG_SAVE_GAME_USING_BIOS 4
#define MSG_UNSUPPORTED_SAVE_TYPE 5
#define MSG_CANNOT_OPEN_FILE 6
#define MSG_BAD_ZIP_FILE 7
#define MSG_NO_IMAGE_ON_ZIP 8
#define MSG_ERROR_OPENING_IMAGE 9
#define MSG_ERROR_READING_IMAGE 10
#define MSG_UNSUPPORTED_BIOS_FUNCTION 11
#define MSG_INVALID_BIOS_FILE_SIZE 12
#define MSG_INVALID_CHEAT_CODE 13
#define MSG_UNKNOWN_ARM_OPCODE 14
#define MSG_UNKNOWN_THUMB_OPCODE 15
#define MSG_ERROR_CREATING_FILE 16
#define MSG_FAILED_TO_READ_SGM 17
#define MSG_FAILED_TO_READ_RTC 18
#define MSG_UNSUPPORTED_VB_SGM 19
#define MSG_CANNOT_LOAD_SGM_FOR 20
#define MSG_ERROR_OPENING_IMAGE_FROM 21
#define MSG_ERROR_READING_IMAGE_FROM 22
#define MSG_UNSUPPORTED_ROM_SIZE 23
#define MSG_UNSUPPORTED_RAM_SIZE 24
#define MSG_UNKNOWN_CARTRIDGE_TYPE 25
#define MSG_MAXIMUM_NUMBER_OF_CHEATS 26
#define MSG_INVALID_GAMESHARK_CODE 27
#define MSG_INVALID_GAMEGENIE_CODE 28
#define MSG_INVALID_CHEAT_TO_REMOVE 29
#define MSG_INVALID_CHEAT_CODE_ADDRESS 30
#define MSG_UNSUPPORTED_CHEAT_LIST_VERSION 31
#define MSG_UNSUPPORTED_CHEAT_LIST_TYPE 32
#define MSG_INVALID_GSA_CODE 33
#define MSG_CANNOT_IMPORT_SNAPSHOT_FOR 34
#define MSG_UNSUPPORTED_SNAPSHOT_FILE 35
#define MSG_UNSUPPORTED_ARM_MODE 36
#define MSG_UNSUPPORTED_CODE_FILE 37
#define MSG_GBA_CODE_WARNING 38
#define MSG_INVALID_CBA_CODE 39
#define MSG_CBA_CODE_WARNING 40
#define MSG_OUT_OF_MEMORY 41
#define MSG_WRONG_GAMESHARK_CODE 42
#define MSG_UNSUPPORTED_GAMESHARK_CODE 43
#define MSG_UNSUPPORTED_CHEAT_LIST_TYPE 32
#define MSG_INVALID_GSA_CODE 33
#define MSG_CANNOT_IMPORT_SNAPSHOT_FOR 34
#define MSG_UNSUPPORTED_SNAPSHOT_FILE 35
#define MSG_UNSUPPORTED_ARM_MODE 36
#define MSG_UNSUPPORTED_CODE_FILE 37
#define MSG_GBA_CODE_WARNING 38
#define MSG_INVALID_CBA_CODE 39
#define MSG_CBA_CODE_WARNING 40
#define MSG_OUT_OF_MEMORY 41
#define MSG_WRONG_GAMESHARK_CODE 42
#define MSG_UNSUPPORTED_GAMESHARK_CODE 43
#define MSG_INVALID_GAME_BOY_NINTENDO_LOGO 44
#define MSG_INVALID_HEADER_CHECKSUM 45

0 comments on commit ce75bd1

Please sign in to comment.