ui: Add runtime disc eject & load actions

This commit is contained in:
Matt Borgerson 2020-06-02 21:28:24 -07:00
parent 382d6e383d
commit 89734ca828
3 changed files with 73 additions and 15 deletions

View File

@ -547,7 +547,6 @@ private:
char flash_path[MAX_STRING_LEN];
char bootrom_path[MAX_STRING_LEN];
char hdd_path[MAX_STRING_LEN];
char dvd_path[MAX_STRING_LEN];
char eeprom_path[MAX_STRING_LEN];
int memory_idx;
bool short_animation;
@ -562,7 +561,6 @@ public:
flash_path[0] = '\0';
bootrom_path[0] = '\0';
hdd_path[0] = '\0';
dvd_path[0] = '\0';
eeprom_path[0] = '\0';
memory_idx = 0;
short_animation = false;
@ -593,11 +591,6 @@ public:
assert(len < MAX_STRING_LEN);
strncpy(hdd_path, tmp, sizeof(hdd_path));
xemu_settings_get_string(XEMU_SETTINGS_SYSTEM_DVD_PATH, &tmp);
len = strlen(tmp);
assert(len < MAX_STRING_LEN);
strncpy(dvd_path, tmp, sizeof(dvd_path));
xemu_settings_get_string(XEMU_SETTINGS_SYSTEM_EEPROM_PATH, &tmp);
len = strlen(tmp);
assert(len < MAX_STRING_LEN);
@ -617,7 +610,6 @@ public:
xemu_settings_set_string(XEMU_SETTINGS_SYSTEM_FLASH_PATH, flash_path);
xemu_settings_set_string(XEMU_SETTINGS_SYSTEM_BOOTROM_PATH, bootrom_path);
xemu_settings_set_string(XEMU_SETTINGS_SYSTEM_HDD_PATH, hdd_path);
xemu_settings_set_string(XEMU_SETTINGS_SYSTEM_DVD_PATH, dvd_path);
xemu_settings_set_string(XEMU_SETTINGS_SYSTEM_EEPROM_PATH, eeprom_path);
xemu_settings_set_int(XEMU_SETTINGS_SYSTEM_MEMORY, 64+memory_idx*64);
xemu_settings_set_bool(XEMU_SETTINGS_SYSTEM_SHORTANIM, short_animation);
@ -659,7 +651,6 @@ public:
}
const char *rom_file_filters = ".bin Files\0*.bin\0.rom Files\0*.rom\0All Files\0*.*\0";
const char *iso_file_filters = ".iso Files\0*.iso\0All Files\0*.*\0";
const char *qcow_file_filters = ".qcow2 Files\0*.qcow2\0All Files\0*.*\0";
ImGui::Columns(2, "", false);
@ -684,12 +675,6 @@ public:
FilePicker("###HDD", hdd_path, sizeof(hdd_path), qcow_file_filters);
ImGui::NextColumn();
ImGui::Text("DVD Image File");
ImGui::NextColumn();
ImGui::SetNextItemWidth(picker_width);
FilePicker("###DVD", dvd_path, sizeof(dvd_path), iso_file_filters);
ImGui::NextColumn();
ImGui::Text("EEPROM File");
ImGui::NextColumn();
ImGui::SetNextItemWidth(picker_width);
@ -1237,6 +1222,28 @@ static bool is_shortcut_key_pressed(int scancode)
return is_shortcut_key && io.KeysDown[scancode] && (io.KeysDownDuration[scancode] == 0.0);
}
static void action_eject_disc(void)
{
xemu_settings_set_string(XEMU_SETTINGS_SYSTEM_DVD_PATH, "");
xemu_settings_save();
xemu_eject_disc();
}
static void action_load_disc(void)
{
const char *iso_file_filters = ".iso Files\0*.iso\0All Files\0*.*\0";
const char *current_disc_path;
xemu_settings_get_string(XEMU_SETTINGS_SYSTEM_DVD_PATH, &current_disc_path);
const char *new_disc_path = noc_file_dialog_open(NOC_FILE_DIALOG_OPEN, iso_file_filters, current_disc_path, NULL);
if (new_disc_path == NULL) {
/* Cancelled */
return;
}
xemu_settings_set_string(XEMU_SETTINGS_SYSTEM_DVD_PATH, new_disc_path);
xemu_settings_save();
xemu_load_disc(new_disc_path);
}
static void action_toggle_pause(void)
{
if (runstate_is_running()) {
@ -1258,6 +1265,14 @@ static void action_shutdown(void)
static void process_keyboard_shortcuts(void)
{
if (is_shortcut_key_pressed(SDL_SCANCODE_E)) {
action_eject_disc();
}
if (is_shortcut_key_pressed(SDL_SCANCODE_O)) {
action_load_disc();
}
if (is_shortcut_key_pressed(SDL_SCANCODE_P)) {
action_toggle_pause();
}
@ -1285,10 +1300,21 @@ static void ShowMainMenu()
{
if (ImGui::BeginMenu("Machine"))
{
if (ImGui::MenuItem("Eject Disc", SHORTCUT_MENU_TEXT(E))) {
action_eject_disc();
}
if (ImGui::MenuItem("Load Disc...", SHORTCUT_MENU_TEXT(O))) {
action_load_disc();
}
ImGui::Separator();
ImGui::MenuItem("Input", NULL, &input_window.is_open);
ImGui::MenuItem("Network", NULL, &network_window.is_open);
ImGui::MenuItem("Settings", NULL, &settings_window.is_open);
ImGui::Separator();
if (ImGui::MenuItem(running ? "Pause" : "Run", SHORTCUT_MENU_TEXT(P))) {
action_toggle_pause();
}

View File

@ -34,6 +34,8 @@ extern int scaling_mode;
int xemu_is_fullscreen(void);
void xemu_monitor_init(void);
void xemu_toggle_fullscreen(void);
void xemu_eject_disc(void);
void xemu_load_disc(const char *path);
// Implemented in xemu_hud.cc
void xemu_hud_init(SDL_Window *window, void *sdl_gl_context);

View File

@ -43,6 +43,12 @@
#include "xemu-shaders.h"
#include "hw/xbox/nv2a/gl/gloffscreen.h" // FIXME
#include "qemu-common.h"
#include "qapi/error.h"
#include "qapi/qapi-commands-block.h"
#include "qapi/qmp/qdict.h"
#include "hw/xbox/smbus.h" // For eject, drive tray
// #define DEBUG_XEMU_C
#ifdef DEBUG_XEMU_C
@ -1440,3 +1446,27 @@ int main(int argc, char **argv)
sdl2_gl_refresh(&sdl2_console[0].dcl);
}
}
void xemu_eject_disc(void)
{
xbox_smc_eject_button();
// Xbox software may request that the drive open, but do it now anyway
Error *err = NULL;
qmp_eject(true, "ide0-cd1", false, NULL, true, false, &err);
xbox_smc_update_tray_state();
}
void xemu_load_disc(const char *path)
{
// Ensure an eject sequence is always triggered so Xbox software reloads
xbox_smc_eject_button();
Error *err = NULL;
qmp_blockdev_change_medium(true, "ide0-cd1", false, NULL, path,
false, "", false, 0,
&err);
xbox_smc_update_tray_state();
}