Refactor out disk swapping functions.
This commit is contained in:
parent
6871d42ee9
commit
9eda39417f
|
@ -702,6 +702,8 @@ void rarch_check_overlay(void);
|
|||
void rarch_init_rewind(void);
|
||||
void rarch_deinit_rewind(void);
|
||||
void rarch_set_fullscreen(bool fullscreen);
|
||||
void rarch_disk_control_set_eject(bool state, bool log);
|
||||
void rarch_disk_control_set_index(unsigned index);
|
||||
|
||||
void rarch_load_state(void);
|
||||
void rarch_save_state(void);
|
||||
|
|
82
retroarch.c
82
retroarch.c
|
@ -2415,24 +2415,16 @@ static void check_cheats(void)
|
|||
old_pressed_toggle = pressed_toggle;
|
||||
}
|
||||
|
||||
static void check_disk(void)
|
||||
void rarch_disk_control_set_eject(bool new_state, bool log)
|
||||
{
|
||||
const struct retro_disk_control_callback *control = &g_extern.system.disk_control;
|
||||
if (!control->get_num_images)
|
||||
return;
|
||||
|
||||
static bool old_pressed_eject;
|
||||
static bool old_pressed_next;
|
||||
|
||||
bool pressed_eject = input_key_pressed_func(RARCH_DISK_EJECT_TOGGLE);
|
||||
bool pressed_next = input_key_pressed_func(RARCH_DISK_NEXT);
|
||||
bool error = false;
|
||||
char msg[256];
|
||||
*msg = '\0';
|
||||
|
||||
if (pressed_eject && !old_pressed_eject)
|
||||
{
|
||||
bool new_state = !control->get_eject_state();
|
||||
if (control->set_eject_state(new_state))
|
||||
snprintf(msg, sizeof(msg), "%s virtual disk tray.", new_state ? "Ejected" : "Closed");
|
||||
else
|
||||
|
@ -2440,15 +2432,34 @@ static void check_disk(void)
|
|||
error = true;
|
||||
snprintf(msg, sizeof(msg), "Failed to %s virtual disk tray.", new_state ? "eject" : "close");
|
||||
}
|
||||
|
||||
if (*msg)
|
||||
{
|
||||
if (error)
|
||||
RARCH_ERR("%s\n", msg);
|
||||
else
|
||||
RARCH_LOG("%s\n", msg);
|
||||
|
||||
// Only noise in RGUI.
|
||||
if (log)
|
||||
{
|
||||
msg_queue_clear(g_extern.msg_queue);
|
||||
msg_queue_push(g_extern.msg_queue, msg, 1, 180);
|
||||
}
|
||||
else if (pressed_next && !old_pressed_next)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
void rarch_disk_control_set_index(unsigned next_index)
|
||||
{
|
||||
const struct retro_disk_control_callback *control = &g_extern.system.disk_control;
|
||||
if (!control->get_num_images)
|
||||
return;
|
||||
|
||||
bool error = false;
|
||||
char msg[256];
|
||||
*msg = '\0';
|
||||
|
||||
unsigned num_disks = control->get_num_images();
|
||||
unsigned current = control->get_image_index();
|
||||
if (num_disks && num_disks != UINT_MAX)
|
||||
{
|
||||
// Use "no disk" state when index == num_disks.
|
||||
unsigned next_index = current >= num_disks ? 0 : ((current + 1) % (num_disks + 1));
|
||||
if (control->set_image_index(next_index))
|
||||
{
|
||||
if (next_index < num_disks)
|
||||
|
@ -2464,13 +2475,6 @@ static void check_disk(void)
|
|||
snprintf(msg, sizeof(msg), "Failed to remove disk from tray.");
|
||||
error = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf(msg, sizeof(msg), "Got invalid disk index from libretro.");
|
||||
error = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (*msg)
|
||||
{
|
||||
|
@ -2481,6 +2485,38 @@ static void check_disk(void)
|
|||
msg_queue_clear(g_extern.msg_queue);
|
||||
msg_queue_push(g_extern.msg_queue, msg, 1, 180);
|
||||
}
|
||||
}
|
||||
|
||||
static void check_disk(void)
|
||||
{
|
||||
const struct retro_disk_control_callback *control = &g_extern.system.disk_control;
|
||||
if (!control->get_num_images)
|
||||
return;
|
||||
|
||||
static bool old_pressed_eject;
|
||||
static bool old_pressed_next;
|
||||
|
||||
bool pressed_eject = input_key_pressed_func(RARCH_DISK_EJECT_TOGGLE);
|
||||
bool pressed_next = input_key_pressed_func(RARCH_DISK_NEXT);
|
||||
|
||||
if (pressed_eject && !old_pressed_eject)
|
||||
{
|
||||
bool new_state = !control->get_eject_state();
|
||||
rarch_disk_control_set_eject(new_state, true);
|
||||
}
|
||||
else if (pressed_next && !old_pressed_next)
|
||||
{
|
||||
unsigned num_disks = control->get_num_images();
|
||||
unsigned current = control->get_image_index();
|
||||
if (num_disks && num_disks != UINT_MAX)
|
||||
{
|
||||
// Use "no disk" state when index == num_disks.
|
||||
unsigned next_index = current >= num_disks ? 0 : ((current + 1) % (num_disks + 1));
|
||||
rarch_disk_control_set_index(next_index);
|
||||
}
|
||||
else
|
||||
RARCH_ERR("Got invalid disk index from libretro.\n");
|
||||
}
|
||||
|
||||
old_pressed_eject = pressed_eject;
|
||||
old_pressed_next = pressed_next;
|
||||
|
|
Loading…
Reference in New Issue