cdrom: add open/close tray commands

This commit is contained in:
Brad Parker 2019-07-02 21:35:20 -04:00
parent 31a68fce1b
commit 4cedaaefe1
2 changed files with 93 additions and 0 deletions

View File

@ -662,3 +662,88 @@ int cdrom_read(libretro_vfs_implementation_file *stream, unsigned char min, unsi
return 0;
}
int cdrom_stop(libretro_vfs_implementation_file *stream)
{
/* MMC Command: START STOP UNIT */
unsigned char cdb[] = {0x1B, 0, 0, 0, 0x0, 0};
int rv = cdrom_send_command(stream, DIRECTION_NONE, NULL, 0, cdb, sizeof(cdb), 0);
#ifdef CDROM_DEBUG
printf("stop status code %d\n", rv);
fflush(stdout);
#endif
if (rv)
return 1;
return 0;
}
int cdrom_unlock(libretro_vfs_implementation_file *stream)
{
/* MMC Command: PREVENT ALLOW MEDIUM REMOVAL */
unsigned char cdb[] = {0x1E, 0, 0, 0, 0x2, 0};
int rv = cdrom_send_command(stream, DIRECTION_NONE, NULL, 0, cdb, sizeof(cdb), 0);
#ifdef CDROM_DEBUG
printf("persistent prevent clear status code %d\n", rv);
fflush(stdout);
#endif
if (rv)
return 1;
cdb[4] = 0x0;
rv = cdrom_send_command(stream, DIRECTION_NONE, NULL, 0, cdb, sizeof(cdb), 0);
#ifdef CDROM_DEBUG
printf("prevent clear status code %d\n", rv);
fflush(stdout);
#endif
if (rv)
return 1;
return 0;
}
int cdrom_open_tray(libretro_vfs_implementation_file *stream)
{
/* MMC Command: START STOP UNIT */
unsigned char cdb[] = {0x1B, 0, 0, 0, 0x2, 0};
int rv;
cdrom_unlock(stream);
cdrom_stop(stream);
rv = cdrom_send_command(stream, DIRECTION_NONE, NULL, 0, cdb, sizeof(cdb), 0);
#ifdef CDROM_DEBUG
printf("open tray status code %d\n", rv);
fflush(stdout);
#endif
if (rv)
return 1;
return 0;
}
int cdrom_close_tray(libretro_vfs_implementation_file *stream)
{
/* MMC Command: START STOP UNIT */
unsigned char cdb[] = {0x1B, 0, 0, 0, 0x3, 0};
int rv = cdrom_send_command(stream, DIRECTION_NONE, NULL, 0, cdb, sizeof(cdb), 0);
#ifdef CDROM_DEBUG
printf("close tray status code %d\n", rv);
fflush(stdout);
#endif
if (rv)
return 1;
return 0;
}

View File

@ -79,6 +79,14 @@ int cdrom_read(libretro_vfs_implementation_file *stream, unsigned char min, unsi
int cdrom_set_read_speed(libretro_vfs_implementation_file *stream, unsigned speed);
int cdrom_stop(libretro_vfs_implementation_file *stream);
int cdrom_unlock(libretro_vfs_implementation_file *stream);
int cdrom_open_tray(libretro_vfs_implementation_file *stream);
int cdrom_close_tray(libretro_vfs_implementation_file *stream);
RETRO_END_DECLS
#endif