Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions core/input/gamepad.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,26 @@ enum DreamcastKey
EMU_BTN_ESCAPE,
EMU_BTN_LOADSTATE,
EMU_BTN_SAVESTATE,
EMU_BTN_LOADSTATE_SLOT1,
EMU_BTN_LOADSTATE_SLOT2,
EMU_BTN_LOADSTATE_SLOT3,
EMU_BTN_LOADSTATE_SLOT4,
EMU_BTN_LOADSTATE_SLOT5,
EMU_BTN_LOADSTATE_SLOT6,
EMU_BTN_LOADSTATE_SLOT7,
EMU_BTN_LOADSTATE_SLOT8,
EMU_BTN_LOADSTATE_SLOT9,
EMU_BTN_LOADSTATE_SLOT10,
EMU_BTN_SAVESTATE_SLOT1,
EMU_BTN_SAVESTATE_SLOT2,
EMU_BTN_SAVESTATE_SLOT3,
EMU_BTN_SAVESTATE_SLOT4,
EMU_BTN_SAVESTATE_SLOT5,
EMU_BTN_SAVESTATE_SLOT6,
EMU_BTN_SAVESTATE_SLOT7,
EMU_BTN_SAVESTATE_SLOT8,
EMU_BTN_SAVESTATE_SLOT9,
EMU_BTN_SAVESTATE_SLOT10,
EMU_BTN_BYPASS_KB,
EMU_BTN_SCREENSHOT,
EMU_BTN_SRVMODE, // used internally by virtual gamepad
Expand Down
20 changes: 20 additions & 0 deletions core/input/gamepad_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,26 @@ bool GamepadDevice::handleButtonInput(int port, DreamcastKey key, bool pressed)
if (pressed)
gui_saveState();
break;
case EMU_BTN_LOADSTATE_SLOT1: if (pressed) gui_loadState(0); break;
case EMU_BTN_LOADSTATE_SLOT2: if (pressed) gui_loadState(1); break;
case EMU_BTN_LOADSTATE_SLOT3: if (pressed) gui_loadState(2); break;
case EMU_BTN_LOADSTATE_SLOT4: if (pressed) gui_loadState(3); break;
case EMU_BTN_LOADSTATE_SLOT5: if (pressed) gui_loadState(4); break;
case EMU_BTN_LOADSTATE_SLOT6: if (pressed) gui_loadState(5); break;
case EMU_BTN_LOADSTATE_SLOT7: if (pressed) gui_loadState(6); break;
case EMU_BTN_LOADSTATE_SLOT8: if (pressed) gui_loadState(7); break;
case EMU_BTN_LOADSTATE_SLOT9: if (pressed) gui_loadState(8); break;
case EMU_BTN_LOADSTATE_SLOT10: if (pressed) gui_loadState(9); break;
case EMU_BTN_SAVESTATE_SLOT1: if (pressed) gui_saveState(0); break;
case EMU_BTN_SAVESTATE_SLOT2: if (pressed) gui_saveState(1); break;
case EMU_BTN_SAVESTATE_SLOT3: if (pressed) gui_saveState(2); break;
case EMU_BTN_SAVESTATE_SLOT4: if (pressed) gui_saveState(3); break;
case EMU_BTN_SAVESTATE_SLOT5: if (pressed) gui_saveState(4); break;
case EMU_BTN_SAVESTATE_SLOT6: if (pressed) gui_saveState(5); break;
case EMU_BTN_SAVESTATE_SLOT7: if (pressed) gui_saveState(6); break;
case EMU_BTN_SAVESTATE_SLOT8: if (pressed) gui_saveState(7); break;
case EMU_BTN_SAVESTATE_SLOT9: if (pressed) gui_saveState(8); break;
case EMU_BTN_SAVESTATE_SLOT10: if (pressed) gui_saveState(9); break;
case EMU_BTN_SCREENSHOT:
if (pressed)
gui_takeScreenshot();
Expand Down
20 changes: 20 additions & 0 deletions core/input/mapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,26 @@ button_list[] =
{ DC_BTN_INSERT_CARD, "emulator", "insert_card" },
{ EMU_BTN_LOADSTATE, "emulator", "btn_jump_state" },
{ EMU_BTN_SAVESTATE, "emulator", "btn_quick_save" },
{ EMU_BTN_LOADSTATE_SLOT1, "emulator", "btn_slot1_jump_state" },
{ EMU_BTN_SAVESTATE_SLOT1, "emulator", "btn_slot1_quick_save" },
{ EMU_BTN_LOADSTATE_SLOT2, "emulator", "btn_slot2_jump_state" },
{ EMU_BTN_SAVESTATE_SLOT2, "emulator", "btn_slot2_quick_save" },
{ EMU_BTN_LOADSTATE_SLOT3, "emulator", "btn_slot3_jump_state" },
{ EMU_BTN_SAVESTATE_SLOT3, "emulator", "btn_slot3_quick_save" },
{ EMU_BTN_LOADSTATE_SLOT4, "emulator", "btn_slot4_jump_state" },
{ EMU_BTN_SAVESTATE_SLOT4, "emulator", "btn_slot4_quick_save" },
{ EMU_BTN_LOADSTATE_SLOT5, "emulator", "btn_slot5_jump_state" },
{ EMU_BTN_SAVESTATE_SLOT5, "emulator", "btn_slot5_quick_save" },
{ EMU_BTN_LOADSTATE_SLOT6, "emulator", "btn_slot6_jump_state" },
{ EMU_BTN_SAVESTATE_SLOT6, "emulator", "btn_slot6_quick_save" },
{ EMU_BTN_LOADSTATE_SLOT7, "emulator", "btn_slot7_jump_state" },
{ EMU_BTN_SAVESTATE_SLOT7, "emulator", "btn_slot7_quick_save" },
{ EMU_BTN_LOADSTATE_SLOT8, "emulator", "btn_slot8_jump_state" },
{ EMU_BTN_SAVESTATE_SLOT8, "emulator", "btn_slot8_quick_save" },
{ EMU_BTN_LOADSTATE_SLOT9, "emulator", "btn_slot9_jump_state" },
{ EMU_BTN_SAVESTATE_SLOT9, "emulator", "btn_slot9_quick_save" },
{ EMU_BTN_LOADSTATE_SLOT10, "emulator", "btn_slot10_jump_state" },
{ EMU_BTN_SAVESTATE_SLOT10, "emulator", "btn_slot10_quick_save" },
{ EMU_BTN_BYPASS_KB, "emulator", "btn_bypass_kb" },
{ EMU_BTN_SCREENSHOT, "emulator", "btn_screenshot" },
};
Expand Down
14 changes: 14 additions & 0 deletions core/sdl/sdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1353,3 +1353,17 @@ void sdl_displayHapticStats()
ImGui::End();
}
#endif

bool sdl_is_fullscreen()
{
#if !defined(__ANDROID__) && !defined(TARGET_IPHONE) && !defined(TARGET_UWP) && !defined(__SWITCH__)
if (!window)
return false;

Uint32 flags = SDL_GetWindowFlags(window);
return (flags & SDL_WINDOW_FULLSCREEN) ||
(flags & SDL_WINDOW_FULLSCREEN_DESKTOP);
#else
return false;
#endif
}
1 change: 1 addition & 0 deletions core/sdl/sdl.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ void sdl_window_create();
void sdl_window_destroy();
bool sdl_recreate_window(u32 flags);
void sdl_fix_steamdeck_dpi(SDL_Window *window);
bool sdl_is_fullscreen();
37 changes: 26 additions & 11 deletions core/ui/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -604,12 +604,13 @@ static void getScreenshot(std::vector<u8>& data, int width = 0)
stbi_write_png_to_func(appendVectorData, &data, width, height, 3, &rawData[0], 0);
}

static void savestate()
static void savestate(int slotIndex = -1)
{
// TODO save state async: png compression, savestate file compression/write
if (slotIndex < 0) slotIndex = config::SavestateSlot;
std::vector<u8> pngData;
getScreenshot(pngData, 640);
dc_savestate(config::SavestateSlot, pngData.empty() ? nullptr : &pngData[0], pngData.size());
dc_savestate(slotIndex, pngData.empty() ? nullptr : &pngData[0], pngData.size());
ImguiStateTexture savestatePic;
savestatePic.invalidate();
}
Expand Down Expand Up @@ -1020,10 +1021,13 @@ static void gui_display_content()

static ImGuiTextFilter filter;
const float settingsBtnW = iconButtonWidth(ICON_FA_GEAR, "Settings");
const float exitBtnW = ImGui::GetStyle().ItemSpacing.x + iconButtonWidth(ICON_FA_POWER_OFF, "Exit");
const bool isFullscreen_PC = sdl_is_fullscreen();
const float exitBtnW_PC = isFullscreen_PC ? exitBtnW : 0;
#if !defined(__ANDROID__) && !defined(TARGET_IPHONE) && !defined(TARGET_UWP) && !defined(__SWITCH__)
ImGui::SameLine(0, uiScaled(32));
filter.Draw("Filter", ImGui::GetContentRegionAvail().x - ImGui::GetStyle().ItemSpacing.x - uiScaled(32)
- settingsBtnW - ImGui::GetStyle().ItemSpacing.x);
- settingsBtnW - exitBtnW_PC - ImGui::GetStyle().ItemSpacing.x);
#endif
if (gui_state != GuiState::SelectDisk)
{
Expand All @@ -1033,17 +1037,26 @@ static void gui_display_content()
if (ImGui::Button("Load..."))
gui_load_game();
ImGui::SameLine();
if (iconButton(ICON_FA_GEAR, "Settings"))
gui_setState(GuiState::Settings);
#elif defined(__SWITCH__)
ImGui::SameLine(ImGui::GetContentRegionMax().x - settingsBtnW
- ImGui::GetStyle().ItemSpacing.x - iconButtonWidth(ICON_FA_POWER_OFF, "Exit"));
ImGui::SameLine(ImGui::GetContentRegionMax().x - settingsBtnW - exitBtnW);
if (iconButton(ICON_FA_POWER_OFF, "Exit"))
dc_exit();
ImGui::SameLine();
if (iconButton(ICON_FA_GEAR, "Settings"))
gui_setState(GuiState::Settings);
#else
ImGui::SameLine(ImGui::GetContentRegionMax().x - settingsBtnW);
#endif
ImGui::SameLine(ImGui::GetContentRegionMax().x - settingsBtnW - exitBtnW_PC);
if (iconButton(ICON_FA_GEAR, "Settings"))
gui_setState(GuiState::Settings);
if (isFullscreen_PC)
{
ImGui::SameLine();
if (iconButton(ICON_FA_POWER_OFF, "Exit"))
dc_exit();
}
#endif
}
else
{
Expand Down Expand Up @@ -1685,30 +1698,32 @@ void gui_error(const std::string& what) {
error_msg = what;
}

void gui_loadState()
void gui_loadState(int slotIndex)
{
if (slotIndex < 0) slotIndex = config::SavestateSlot;
const LockGuard lock(guiMutex);
if (gui_state == GuiState::Closed && savestateAllowed())
{
try {
emu.stop();
dc_loadstate(config::SavestateSlot);
dc_loadstate(slotIndex);
emu.start();
} catch (const FlycastException& e) {
gui_stop_game(e.what());
}
}
}

void gui_saveState(bool stopRestart)
void gui_saveState(int slotIndex, bool stopRestart)
{
if (slotIndex < 0) slotIndex = config::SavestateSlot;
const LockGuard lock(guiMutex);
if ((gui_state == GuiState::Closed || !stopRestart) && savestateAllowed())
{
try {
if (stopRestart)
emu.stop();
savestate();
savestate(slotIndex);
if (stopRestart)
emu.start();
} catch (const FlycastException& e) {
Expand Down
4 changes: 2 additions & 2 deletions core/ui/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ void gui_stop_game(const std::string& message = "");
void gui_start_game(const std::string& path);
void gui_error(const std::string& what);
void gui_setOnScreenKeyboardCallback(void (*callback)(bool show));
void gui_loadState();
void gui_saveState(bool stopRestart = true);
void gui_loadState(int slotIndex = -1);
void gui_saveState(int slotIndex = -1, bool stopRestart = true);
std::string gui_getCurGameBoxartUrl();
void gui_takeScreenshot();
void gui_runOnUiThread(std::function<void()> function);
Expand Down
88 changes: 64 additions & 24 deletions core/ui/settings_controls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,25 +157,25 @@ struct Mapping {

static const Mapping dcButtons[] = {
{ EMU_BTN_NONE, "Directions" },
{ DC_DPAD_UP, "Up" },
{ DC_DPAD_DOWN, "Down" },
{ DC_DPAD_LEFT, "Left" },
{ DC_DPAD_RIGHT, "Right" },
{ DC_DPAD_UP, "DPad Up" },
{ DC_DPAD_DOWN, "DPad Down" },
{ DC_DPAD_LEFT, "DPad Left" },
{ DC_DPAD_RIGHT, "DPad Right" },

{ DC_AXIS_UP, "Thumbstick Up" },
{ DC_AXIS_DOWN, "Thumbstick Down" },
{ DC_AXIS_LEFT, "Thumbstick Left" },
{ DC_AXIS_RIGHT, "Thumbstick Right" },
{ DC_AXIS_UP, "L.Thumbstick Up" },
{ DC_AXIS_DOWN, "L.Thumbstick Down" },
{ DC_AXIS_LEFT, "L.Thumbstick Left" },
{ DC_AXIS_RIGHT, "L.Thumbstick Right" },

{ DC_AXIS2_UP, "R.Thumbstick Up" },
{ DC_AXIS2_DOWN, "R.Thumbstick Down" },
{ DC_AXIS2_LEFT, "R.Thumbstick Left" },
{ DC_AXIS2_RIGHT, "R.Thumbstick Right" },

{ DC_AXIS3_UP, "Axis 3 Up" },
{ DC_AXIS3_DOWN, "Axis 3 Down" },
{ DC_AXIS3_LEFT, "Axis 3 Left" },
{ DC_AXIS3_RIGHT, "Axis 3 Right" },
{ DC_AXIS3_UP, "Axis3 Up" },
{ DC_AXIS3_DOWN, "Axis3 Down" },
{ DC_AXIS3_LEFT, "Axis3 Left" },
{ DC_AXIS3_RIGHT, "Axis3 Right" },

{ DC_DPAD2_UP, "DPad2 Up" },
{ DC_DPAD2_DOWN, "DPad2 Down" },
Expand Down Expand Up @@ -205,8 +205,28 @@ static const Mapping dcButtons[] = {
{ EMU_BTN_MENU, "Menu" },
{ EMU_BTN_ESCAPE, "Exit" },
{ EMU_BTN_FFORWARD, "Fast-forward" },
{ EMU_BTN_LOADSTATE, "Load State" },
{ EMU_BTN_SAVESTATE, "Save State" },
{ EMU_BTN_LOADSTATE, "Load State (Current Slot)" },
{ EMU_BTN_SAVESTATE, "Save State (Current Slot)" },
{ EMU_BTN_LOADSTATE_SLOT1, "Load State (Slot 1)" },
{ EMU_BTN_SAVESTATE_SLOT1, "Save State (Slot 1)" },
{ EMU_BTN_LOADSTATE_SLOT2, "Load State (Slot 2)" },
{ EMU_BTN_SAVESTATE_SLOT2, "Save State (Slot 2)" },
{ EMU_BTN_LOADSTATE_SLOT3, "Load State (Slot 3)" },
{ EMU_BTN_SAVESTATE_SLOT3, "Save State (Slot 3)" },
{ EMU_BTN_LOADSTATE_SLOT4, "Load State (Slot 4)" },
{ EMU_BTN_SAVESTATE_SLOT4, "Save State (Slot 4)" },
{ EMU_BTN_LOADSTATE_SLOT5, "Load State (Slot 5)" },
{ EMU_BTN_SAVESTATE_SLOT5, "Save State (Slot 5)" },
{ EMU_BTN_LOADSTATE_SLOT6, "Load State (Slot 6)" },
{ EMU_BTN_SAVESTATE_SLOT6, "Save State (Slot 6)" },
{ EMU_BTN_LOADSTATE_SLOT7, "Load State (Slot 7)" },
{ EMU_BTN_SAVESTATE_SLOT7, "Save State (Slot 7)" },
{ EMU_BTN_LOADSTATE_SLOT8, "Load State (Slot 8)" },
{ EMU_BTN_SAVESTATE_SLOT8, "Save State (Slot 8)" },
{ EMU_BTN_LOADSTATE_SLOT9, "Load State (Slot 9)" },
{ EMU_BTN_SAVESTATE_SLOT9, "Save State (Slot 9)" },
{ EMU_BTN_LOADSTATE_SLOT10, "Load State (Slot 10)" },
{ EMU_BTN_SAVESTATE_SLOT10, "Save State (Slot 10)" },
{ EMU_BTN_BYPASS_KB, "Bypass Emulated Keyboard" },
{ EMU_BTN_SCREENSHOT, "Save Screenshot" },

Expand All @@ -215,15 +235,15 @@ static const Mapping dcButtons[] = {

static const Mapping arcadeButtons[] = {
{ EMU_BTN_NONE, "Directions" },
{ DC_DPAD_UP, "Up" },
{ DC_DPAD_DOWN, "Down" },
{ DC_DPAD_LEFT, "Left" },
{ DC_DPAD_RIGHT, "Right" },
{ DC_DPAD_UP, "DPad Up" },
{ DC_DPAD_DOWN, "DPad Down" },
{ DC_DPAD_LEFT, "DPad Left" },
{ DC_DPAD_RIGHT, "DPad Right" },

{ DC_AXIS_UP, "Thumbstick Up" },
{ DC_AXIS_DOWN, "Thumbstick Down" },
{ DC_AXIS_LEFT, "Thumbstick Left" },
{ DC_AXIS_RIGHT, "Thumbstick Right" },
{ DC_AXIS_UP, "L.Thumbstick Up" },
{ DC_AXIS_DOWN, "L.Thumbstick Down" },
{ DC_AXIS_LEFT, "L.Thumbstick Left" },
{ DC_AXIS_RIGHT, "L.Thumbstick Right" },

{ DC_AXIS2_UP, "R.Thumbstick Up" },
{ DC_AXIS2_DOWN, "R.Thumbstick Down" },
Expand Down Expand Up @@ -259,8 +279,28 @@ static const Mapping arcadeButtons[] = {
{ EMU_BTN_MENU, "Menu" },
{ EMU_BTN_ESCAPE, "Exit" },
{ EMU_BTN_FFORWARD, "Fast-forward" },
{ EMU_BTN_LOADSTATE, "Load State" },
{ EMU_BTN_SAVESTATE, "Save State" },
{ EMU_BTN_LOADSTATE, "Load State (Current Slot)" },
{ EMU_BTN_SAVESTATE, "Save State (Current Slot)" },
{ EMU_BTN_LOADSTATE_SLOT1, "Load State (Slot 1)" },
{ EMU_BTN_SAVESTATE_SLOT1, "Save State (Slot 1)" },
{ EMU_BTN_LOADSTATE_SLOT2, "Load State (Slot 2)" },
{ EMU_BTN_SAVESTATE_SLOT2, "Save State (Slot 2)" },
{ EMU_BTN_LOADSTATE_SLOT3, "Load State (Slot 3)" },
{ EMU_BTN_SAVESTATE_SLOT3, "Save State (Slot 3)" },
{ EMU_BTN_LOADSTATE_SLOT4, "Load State (Slot 4)" },
{ EMU_BTN_SAVESTATE_SLOT4, "Save State (Slot 4)" },
{ EMU_BTN_LOADSTATE_SLOT5, "Load State (Slot 5)" },
{ EMU_BTN_SAVESTATE_SLOT5, "Save State (Slot 5)" },
{ EMU_BTN_LOADSTATE_SLOT6, "Load State (Slot 6)" },
{ EMU_BTN_SAVESTATE_SLOT6, "Save State (Slot 6)" },
{ EMU_BTN_LOADSTATE_SLOT7, "Load State (Slot 7)" },
{ EMU_BTN_SAVESTATE_SLOT7, "Save State (Slot 7)" },
{ EMU_BTN_LOADSTATE_SLOT8, "Load State (Slot 8)" },
{ EMU_BTN_SAVESTATE_SLOT8, "Save State (Slot 8)" },
{ EMU_BTN_LOADSTATE_SLOT9, "Load State (Slot 9)" },
{ EMU_BTN_SAVESTATE_SLOT9, "Save State (Slot 9)" },
{ EMU_BTN_LOADSTATE_SLOT10, "Load State (Slot 10)" },
{ EMU_BTN_SAVESTATE_SLOT10, "Save State (Slot 10)" },
{ EMU_BTN_BYPASS_KB, "Bypass Emulated Keyboard" },
{ EMU_BTN_SCREENSHOT, "Save Screenshot" },

Expand Down