Skip to content

Commit

Permalink
Merge pull request #58 from AdmiralCurtiss/hotkeys
Browse files Browse the repository at this point in the history
Add configurable hotkeys for opening the emulator menus and temporarily disabling the framelimiter.
  • Loading branch information
bubble2k16 authored Nov 3, 2017
2 parents 7379702 + b22f2ca commit e549dd1
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 5 deletions.
5 changes: 4 additions & 1 deletion source/3dsinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
#include <3ds.h>
#include "3dsimpl.h"
#include "3dsgpu.h"
#include "3dssettings.h"

static u32 currKeysHeld = 0;
static u32 lastKeysHeld = 0;

extern S9xSettings3DS settings3DS;

//int adjustableValue = 0x70;

//---------------------------------------------------------
Expand Down Expand Up @@ -60,7 +63,7 @@ u32 input3dsScanInputForEmulation()
// -----------------------------------------------
#endif

if (keysDown & KEY_TOUCH)
if (keysDown & KEY_TOUCH || settings3DS.ButtonHotkeyOpenMenu.IsHeld(keysDown))
{
impl3dsTouchScreenPressed();

Expand Down
29 changes: 25 additions & 4 deletions source/3dsmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ void LoadDefaultSettings() {
settings3DS.PaletteFix = 0;
settings3DS.SRAMSaveInterval = 0;
settings3DS.ForceSRAMWriteOnPause = 0;
settings3DS.ButtonHotkeyOpenMenu.SetSingleMapping(0);
settings3DS.ButtonHotkeyDisableFramelimit.SetSingleMapping(0);
}


Expand Down Expand Up @@ -523,6 +525,20 @@ std::vector<SMenuItem> makeControlsMenu() {

}

AddMenuPicker( items, "Open Emulator Menu", ""s, makeOptionsForButtonMapping(), settings3DS.ButtonHotkeyOpenMenu.MappingBitmasks[0], DIALOGCOLOR_CYAN, true,
[]( int val ) {
uint32 v = static_cast<uint32>(val);
CheckAndUpdate( settings3DS.ButtonHotkeyOpenMenu.MappingBitmasks[0], v, settings3DS.Changed );
}
);

AddMenuPicker( items, "Disable Framelimit", ""s, makeOptionsForButtonMapping(), settings3DS.ButtonHotkeyDisableFramelimit.MappingBitmasks[0], DIALOGCOLOR_CYAN, true,
[]( int val ) {
uint32 v = static_cast<uint32>(val);
CheckAndUpdate( settings3DS.ButtonHotkeyDisableFramelimit.MappingBitmasks[0], v, settings3DS.Changed );
}
);

return items;
}

Expand Down Expand Up @@ -727,6 +743,9 @@ bool settingsReadWriteFullListByGame(bool writeMode)
}
}

config3dsReadWriteBitmask("ButtonMappingDisableFramelimitHold_0=%d\n", &settings3DS.ButtonHotkeyDisableFramelimit.MappingBitmasks[0]);
config3dsReadWriteBitmask("ButtonMappingOpenEmulatorMenu_0=%d\n", &settings3DS.ButtonHotkeyOpenMenu.MappingBitmasks[0]);

// All new options should come here!

config3dsCloseFile();
Expand Down Expand Up @@ -1522,10 +1541,12 @@ void emulatorLoop()
snesFrameTotalAccurateTicks = 0;
snesFramesSkipped = 0;

if (settings3DS.ForceFrameRate == EmulatedFramerate::Match3DS) {
gspWaitForVBlank();
} else {
svcSleepThread ((long)(timeDiffInMilliseconds * 1000));
if (!settings3DS.ButtonHotkeyDisableFramelimit.IsHeld(input3dsGetCurrentKeysHeld())) {
if (settings3DS.ForceFrameRate == EmulatedFramerate::Match3DS) {
gspWaitForVBlank();
} else {
svcSleepThread ((long)(timeDiffInMilliseconds * 1000));
}
}

skipDrawingFrame = false;
Expand Down
38 changes: 38 additions & 0 deletions source/3dssettings.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <array>

enum class EmulatedFramerate {
UseRomRegion = 0,
Expand All @@ -7,6 +8,39 @@ enum class EmulatedFramerate {
Count = 4
};

template <int Count>
struct ButtonMapping {
std::array<uint32, Count> MappingBitmasks;

bool IsHeld(uint32 held3dsButtons) const {
for (uint32 mapping : MappingBitmasks) {
if (mapping != 0 && (mapping & held3dsButtons) == mapping) {
return true;
}
}

return false;
}

void SetSingleMapping(uint32 mapping) {
SetDoubleMapping(mapping, 0);
}

void SetDoubleMapping(uint32 mapping0, uint32 mapping1) {
if constexpr (Count > 0) {
MappingBitmasks[0] = mapping0;
}
if constexpr (Count > 1) {
MappingBitmasks[1] = mapping1;
}
if constexpr (Count > 2) {
for (size_t i = 2; i < MappingBitmasks.size(); ++i) {
MappingBitmasks[i] = 0;
}
}
}
};

typedef struct
{
int MaxFrameSkips = 1; // 0 - disable,
Expand Down Expand Up @@ -64,6 +98,10 @@ typedef struct
int GlobalButtonMapping[8][4] = {{0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}};
int ButtonMapping[8][4] = {{0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}};

::ButtonMapping<1> ButtonHotkeyOpenMenu; // Stores button that can be held to open the menu.

::ButtonMapping<1> ButtonHotkeyDisableFramelimit; // Stores button that can be held to disable the frame limit.

bool Changed = false; // Stores whether the configuration has been changed and should be written.

int UseGlobalButtonMappings = 0; // Use global button mappings for all games
Expand Down

0 comments on commit e549dd1

Please sign in to comment.