diff --git a/libretro-common/cdrom/cdrom.c b/libretro-common/cdrom/cdrom.c index b812237c46..a26168b6c4 100644 --- a/libretro-common/cdrom/cdrom.c +++ b/libretro-common/cdrom/cdrom.c @@ -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; +} + diff --git a/libretro-common/include/cdrom/cdrom.h b/libretro-common/include/cdrom/cdrom.h index c751af5658..6d0bdac18e 100644 --- a/libretro-common/include/cdrom/cdrom.h +++ b/libretro-common/include/cdrom/cdrom.h @@ -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