Skip to content

Commit

Permalink
Update M3U/Disk Swap functions
Browse files Browse the repository at this point in the history
- Assign FDD its own individual tray closed/open state variables
- Prevent switching through disk index from auto-inserting disks when drive is in ejected state.
- Fix to Load New Disk, disks can now be added to existing m3u without causing crash.
- Show a list of image paths when loading .M3U (for troubleshooting when needed)
- Show arguments passed to core, which includes paths of images to be loaded and how many disks drives
  are gonna be used.
- Disk Control should now only call its own related variables instead of running all available core options
  • Loading branch information
negativeExponent committed Jan 21, 2020
1 parent 7aaa64e commit 885baea
Showing 1 changed file with 50 additions and 23 deletions.
73 changes: 50 additions & 23 deletions libretro.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,52 @@ struct retro_disk_control_callback dskcb;
unsigned disk_index = 0;
unsigned disk_images = 0;
char disk_paths[10][MAX_PATH];
bool disk_inserted = false;
bool disk_inserted[2] = { false, false };
unsigned disk_drive = 1;

static void update_disk_drive_swap(void)
{
struct retro_variable var =
{
"px68k_disk_drive",
NULL
};

if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
if (strcmp(var.value, "FDD0") == 0)
disk_drive = 0;
else
disk_drive = 1;
}
}

bool set_eject_state(bool ejected)
{
if(disk_index == disk_images)
{
//retroarch is trying to set "no disk in tray"
return true;
}

if (ejected)
{
FDD_EjectFD(disk_drive);
Config.FDDImage[disk_drive][0] = '\0';
}
disk_inserted = !ejected;
else
{
strcpy(Config.FDDImage[disk_drive], disk_paths[disk_index]);
FDD_SetFD(disk_drive, Config.FDDImage[disk_drive], 0);
}
disk_inserted[disk_drive] = !ejected;
return true;
}

bool get_eject_state(void)
{
return !disk_inserted;
update_disk_drive_swap();
return !disk_inserted[disk_drive];
}

unsigned get_image_index(void)
Expand All @@ -106,15 +135,6 @@ unsigned get_image_index(void)
bool set_image_index(unsigned index)
{
disk_index = index;
if(disk_index == disk_images)
{
//retroarch is trying to set "no disk in tray"
return true;
}

update_variables();
FDD_SetFD(disk_drive, disk_paths[disk_index], 0);
strcpy(Config.FDDImage[disk_drive], disk_paths[disk_index]);
return true;
}

Expand Down Expand Up @@ -284,6 +304,7 @@ int pre_main(const char *argv)
{
int i = 0;
int Only1Arg;
int isM3U = 0;

for (i = 0; i < 64; i++)
xargv_cmd[i] = NULL;
Expand Down Expand Up @@ -311,8 +332,10 @@ int pre_main(const char *argv)
if(disk_images > 1)
{
sprintf((char*)argv, "%s \"%s\"", argv, disk_paths[1]);
disk_inserted[1] = true;
}
disk_inserted = true;
disk_inserted[0] = true;
isM3U = 1;
attach_disk_swap_interface();
}
}
Expand Down Expand Up @@ -359,6 +382,19 @@ int pre_main(const char *argv)
xargv_cmd[i] = (char*)(XARGV[i]);
}

/* Log successfully loaded paths when loading from m3u */
if (isM3U)
{
p6logd("%s\n", "Loading from an m3u file ...");
for (i = 0; i < disk_images; i++)
p6logd("index %d: %s\n", i + 1, disk_paths[i]);
}

/* List arguments to be passed to core */
p6logd("%s\n", "Parsing arguments ...");
for (i = 0; i < PARAMCOUNT; i++)
p6logd("%d : %s\n", i, xargv_cmd[i]);

run_pmain:
pmain(PARAMCOUNT, (char **)xargv_cmd);

Expand Down Expand Up @@ -698,16 +734,7 @@ static void update_variables(void)
}
#endif

var.key = "px68k_disk_drive";
var.value = NULL;

if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
if (strcmp(var.value, "FDD0") == 0)
disk_drive = 0;
else
disk_drive = 1;
}
update_disk_drive_swap();

var.key = "px68k_menufontsize";
var.value = NULL;
Expand Down

0 comments on commit 885baea

Please sign in to comment.