2020-06-05 01:22:31 +01:00
|
|
|
// /***************************************************************************
|
|
|
|
|
// Aaru Data Preservation Suite
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : MiniDisc.cs
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
//
|
|
|
|
|
// Component : MiniDisc vendor commands.
|
|
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Contains vendor commands for MiniDisc drives.
|
|
|
|
|
//
|
|
|
|
|
// --[ License ] --------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// This library is free software; you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU Lesser General Public License as
|
|
|
|
|
// published by the Free Software Foundation; either version 2.1 of the
|
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// This library is distributed in the hope that it will be useful, but
|
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
|
//
|
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
// License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2024-05-01 04:17:32 +01:00
|
|
|
// Copyright © 2011-2024 Natalia Portillo
|
2020-06-05 01:22:31 +01:00
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
2021-08-17 13:56:05 +01:00
|
|
|
// ReSharper disable InconsistentNaming
|
2020-06-05 01:22:31 +01:00
|
|
|
|
2022-03-07 07:36:44 +00:00
|
|
|
using Aaru.Console;
|
|
|
|
|
|
2023-10-05 01:05:23 +01:00
|
|
|
// ReSharper disable UnusedMember.Global
|
|
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
namespace Aaru.Devices;
|
|
|
|
|
|
2022-03-26 18:31:04 +00:00
|
|
|
public partial class Device
|
2020-06-05 01:22:31 +01:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <summary>Reads the data TOC from an MD-DATA</summary>
|
|
|
|
|
/// <param name="buffer">Buffer where the response will be stored</param>
|
|
|
|
|
/// <param name="senseBuffer">Sense buffer.</param>
|
|
|
|
|
/// <param name="timeout">Timeout in seconds.</param>
|
|
|
|
|
/// <param name="duration">Duration in milliseconds it took for the device to execute the command.</param>
|
|
|
|
|
/// <returns><c>true</c> if the command failed and <paramref name="senseBuffer" /> contains the sense buffer.</returns>
|
|
|
|
|
public bool MiniDiscReadDataTOC(out byte[] buffer, out byte[] senseBuffer, uint timeout, out double duration)
|
2020-06-05 01:22:31 +01:00
|
|
|
{
|
2022-11-13 20:08:10 +00:00
|
|
|
const ushort transferLength = 2336;
|
2022-03-06 13:29:38 +00:00
|
|
|
senseBuffer = new byte[64];
|
2023-10-03 23:12:01 +01:00
|
|
|
var cdb = new byte[10];
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
cdb[0] = (byte)ScsiCommands.MiniDiscReadDTOC;
|
2020-06-05 01:22:31 +01:00
|
|
|
|
2022-11-14 01:28:21 +00:00
|
|
|
cdb[7] = (transferLength & 0xFF00) >> 8;
|
|
|
|
|
cdb[8] = transferLength & 0xFF;
|
2020-06-05 01:22:31 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
buffer = new byte[transferLength];
|
2020-06-05 01:22:31 +01:00
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
LastError = SendScsiCommand(cdb,
|
|
|
|
|
ref buffer,
|
|
|
|
|
out senseBuffer,
|
|
|
|
|
timeout,
|
|
|
|
|
ScsiDirection.In,
|
|
|
|
|
out duration,
|
2022-03-06 13:29:38 +00:00
|
|
|
out bool sense);
|
2020-06-05 01:22:31 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
Error = LastError != 0;
|
2020-06-05 01:22:31 +01:00
|
|
|
|
2023-10-03 17:28:12 +01:00
|
|
|
AaruConsole.DebugWriteLine(SCSI_MODULE_NAME, Localization.MINIDISC_READ_DTOC_took_0_ms, duration);
|
2020-06-05 01:22:31 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
return sense;
|
|
|
|
|
}
|
2020-06-05 01:22:31 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <summary>Reads the user TOC from an MD-DATA</summary>
|
|
|
|
|
/// <param name="buffer">Buffer where the response will be stored</param>
|
|
|
|
|
/// <param name="senseBuffer">Sense buffer.</param>
|
|
|
|
|
/// <param name="sector">TOC sector to read</param>
|
|
|
|
|
/// <param name="timeout">Timeout in seconds.</param>
|
|
|
|
|
/// <param name="duration">Duration in milliseconds it took for the device to execute the command.</param>
|
|
|
|
|
/// <returns><c>true</c> if the command failed and <paramref name="senseBuffer" /> contains the sense buffer.</returns>
|
|
|
|
|
public bool MiniDiscReadUserTOC(out byte[] buffer, out byte[] senseBuffer, uint sector, uint timeout,
|
|
|
|
|
out double duration)
|
|
|
|
|
{
|
2022-11-13 20:08:10 +00:00
|
|
|
const ushort transferLength = 2336;
|
2022-03-06 13:29:38 +00:00
|
|
|
senseBuffer = new byte[64];
|
2023-10-03 23:12:01 +01:00
|
|
|
var cdb = new byte[10];
|
2020-06-05 01:22:31 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
cdb[0] = (byte)ScsiCommands.MiniDiscReadUTOC;
|
2020-06-05 01:22:31 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
cdb[2] = (byte)((sector & 0xFF000000) >> 24);
|
|
|
|
|
cdb[3] = (byte)((sector & 0xFF0000) >> 16);
|
|
|
|
|
cdb[4] = (byte)((sector & 0xFF00) >> 8);
|
2022-11-14 01:28:21 +00:00
|
|
|
cdb[5] = (byte)(sector & 0xFF);
|
|
|
|
|
cdb[7] = (transferLength & 0xFF00) >> 8;
|
|
|
|
|
cdb[8] = transferLength & 0xFF;
|
2020-06-05 01:22:31 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
buffer = new byte[transferLength];
|
2020-06-05 01:22:31 +01:00
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
LastError = SendScsiCommand(cdb,
|
|
|
|
|
ref buffer,
|
|
|
|
|
out senseBuffer,
|
|
|
|
|
timeout,
|
|
|
|
|
ScsiDirection.In,
|
|
|
|
|
out duration,
|
2022-03-06 13:29:38 +00:00
|
|
|
out bool sense);
|
2020-06-05 01:22:31 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
Error = LastError != 0;
|
2020-06-05 01:22:31 +01:00
|
|
|
|
2023-10-03 17:28:12 +01:00
|
|
|
AaruConsole.DebugWriteLine(SCSI_MODULE_NAME, Localization.MINIDISC_READ_UTOC_took_0_ms, duration);
|
2020-06-05 01:22:31 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
return sense;
|
|
|
|
|
}
|
2020-06-05 01:22:31 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <summary>Sends a D5h command to a MD-DATA drive (harmless)</summary>
|
|
|
|
|
/// <param name="buffer">Buffer where the response will be stored</param>
|
|
|
|
|
/// <param name="senseBuffer">Sense buffer.</param>
|
|
|
|
|
/// <param name="timeout">Timeout in seconds.</param>
|
|
|
|
|
/// <param name="duration">Duration in milliseconds it took for the device to execute the command.</param>
|
|
|
|
|
/// <returns><c>true</c> if the command failed and <paramref name="senseBuffer" /> contains the sense buffer.</returns>
|
|
|
|
|
public bool MiniDiscD5(out byte[] buffer, out byte[] senseBuffer, uint timeout, out double duration)
|
|
|
|
|
{
|
2022-11-13 20:08:10 +00:00
|
|
|
const ushort transferLength = 4;
|
2022-03-06 13:29:38 +00:00
|
|
|
senseBuffer = new byte[64];
|
2023-10-03 23:12:01 +01:00
|
|
|
var cdb = new byte[10];
|
2020-06-05 01:22:31 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
cdb[0] = (byte)ScsiCommands.MiniDiscD5;
|
2020-06-05 01:22:31 +01:00
|
|
|
|
2022-11-15 01:35:06 +00:00
|
|
|
cdb[7] = 0;
|
2022-11-14 01:28:21 +00:00
|
|
|
cdb[8] = transferLength & 0xFF;
|
2020-06-05 01:22:31 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
buffer = new byte[transferLength];
|
2020-06-05 01:22:31 +01:00
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
LastError = SendScsiCommand(cdb,
|
|
|
|
|
ref buffer,
|
|
|
|
|
out senseBuffer,
|
|
|
|
|
timeout,
|
|
|
|
|
ScsiDirection.In,
|
|
|
|
|
out duration,
|
2022-03-06 13:29:38 +00:00
|
|
|
out bool sense);
|
2020-06-05 01:22:31 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
Error = LastError != 0;
|
2020-06-05 01:22:31 +01:00
|
|
|
|
2023-10-03 17:28:12 +01:00
|
|
|
AaruConsole.DebugWriteLine(SCSI_MODULE_NAME, Localization.MINIDISC_command_D5h_took_0_ms, duration);
|
2020-06-05 01:22:31 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
return sense;
|
|
|
|
|
}
|
2020-06-05 01:22:31 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <summary>Stops playing MiniDisc audio from an MD-DATA drive</summary>
|
|
|
|
|
/// <param name="buffer">Buffer where the response will be stored</param>
|
|
|
|
|
/// <param name="senseBuffer">Sense buffer.</param>
|
|
|
|
|
/// <param name="timeout">Timeout in seconds.</param>
|
|
|
|
|
/// <param name="duration">Duration in milliseconds it took for the device to execute the command.</param>
|
|
|
|
|
/// <returns><c>true</c> if the command failed and <paramref name="senseBuffer" /> contains the sense buffer.</returns>
|
|
|
|
|
public bool MiniDiscStopPlaying(out byte[] buffer, out byte[] senseBuffer, uint timeout, out double duration)
|
|
|
|
|
{
|
|
|
|
|
senseBuffer = new byte[64];
|
2023-10-03 23:12:01 +01:00
|
|
|
var cdb = new byte[10];
|
2020-06-05 01:22:31 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
cdb[0] = (byte)ScsiCommands.MiniDiscStopPlay;
|
2020-06-05 01:22:31 +01:00
|
|
|
|
2024-05-01 04:39:38 +01:00
|
|
|
buffer = [];
|
2020-06-05 01:22:31 +01:00
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
LastError = SendScsiCommand(cdb,
|
|
|
|
|
ref buffer,
|
|
|
|
|
out senseBuffer,
|
|
|
|
|
timeout,
|
|
|
|
|
ScsiDirection.None,
|
|
|
|
|
out duration,
|
2022-03-06 13:29:38 +00:00
|
|
|
out bool sense);
|
2020-06-05 01:22:31 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
Error = LastError != 0;
|
2020-06-05 01:22:31 +01:00
|
|
|
|
2023-10-03 17:28:12 +01:00
|
|
|
AaruConsole.DebugWriteLine(SCSI_MODULE_NAME, Localization.MINIDISC_STOP_PLAY_took_0_ms, duration);
|
2020-06-05 01:22:31 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
return sense;
|
|
|
|
|
}
|
2020-06-05 01:22:31 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <summary>Gets current position while playing MiniDisc audio from an MD-DATA drive</summary>
|
|
|
|
|
/// <param name="buffer">Buffer where the response will be stored</param>
|
|
|
|
|
/// <param name="senseBuffer">Sense buffer.</param>
|
|
|
|
|
/// <param name="timeout">Timeout in seconds.</param>
|
|
|
|
|
/// <param name="duration">Duration in milliseconds it took for the device to execute the command.</param>
|
|
|
|
|
/// <returns><c>true</c> if the command failed and <paramref name="senseBuffer" /> contains the sense buffer.</returns>
|
|
|
|
|
public bool MiniDiscReadPosition(out byte[] buffer, out byte[] senseBuffer, uint timeout, out double duration)
|
|
|
|
|
{
|
2022-11-13 20:08:10 +00:00
|
|
|
const ushort transferLength = 4;
|
2022-03-06 13:29:38 +00:00
|
|
|
senseBuffer = new byte[64];
|
2023-10-03 23:12:01 +01:00
|
|
|
var cdb = new byte[10];
|
2020-06-05 01:22:31 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
cdb[0] = (byte)ScsiCommands.MiniDiscReadPosition;
|
2020-06-05 01:22:31 +01:00
|
|
|
|
2022-11-15 01:35:06 +00:00
|
|
|
cdb[7] = 0;
|
2022-11-14 01:28:21 +00:00
|
|
|
cdb[8] = transferLength & 0xFF;
|
2020-06-05 01:22:31 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
buffer = new byte[transferLength];
|
2020-06-05 01:22:31 +01:00
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
LastError = SendScsiCommand(cdb,
|
|
|
|
|
ref buffer,
|
|
|
|
|
out senseBuffer,
|
|
|
|
|
timeout,
|
|
|
|
|
ScsiDirection.In,
|
|
|
|
|
out duration,
|
2022-03-06 13:29:38 +00:00
|
|
|
out bool sense);
|
2020-06-05 01:22:31 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
Error = LastError != 0;
|
2020-06-05 01:22:31 +01:00
|
|
|
|
2023-10-03 17:28:12 +01:00
|
|
|
AaruConsole.DebugWriteLine(SCSI_MODULE_NAME, Localization.MINIDISC_READ_POSITION_took_0_ms, duration);
|
2020-06-05 01:22:31 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
return sense;
|
|
|
|
|
}
|
2020-06-05 01:22:31 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <summary>Gets MiniDisc type from an MD-DATA drive</summary>
|
|
|
|
|
/// <param name="buffer">Buffer where the response will be stored</param>
|
|
|
|
|
/// <param name="senseBuffer">Sense buffer.</param>
|
|
|
|
|
/// <param name="timeout">Timeout in seconds.</param>
|
|
|
|
|
/// <param name="duration">Duration in milliseconds it took for the device to execute the command.</param>
|
|
|
|
|
/// <returns><c>true</c> if the command failed and <paramref name="senseBuffer" /> contains the sense buffer.</returns>
|
|
|
|
|
public bool MiniDiscGetType(out byte[] buffer, out byte[] senseBuffer, uint timeout, out double duration)
|
|
|
|
|
{
|
2022-11-13 20:08:10 +00:00
|
|
|
const ushort transferLength = 8;
|
2022-03-06 13:29:38 +00:00
|
|
|
senseBuffer = new byte[64];
|
2023-10-03 23:12:01 +01:00
|
|
|
var cdb = new byte[10];
|
2020-06-05 01:22:31 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
cdb[0] = (byte)ScsiCommands.MiniDiscGetType;
|
2020-06-05 01:22:31 +01:00
|
|
|
|
2022-11-15 01:35:06 +00:00
|
|
|
cdb[7] = 0;
|
2022-11-14 01:28:21 +00:00
|
|
|
cdb[8] = transferLength & 0xFF;
|
2020-06-05 01:22:31 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
buffer = new byte[transferLength];
|
2020-06-05 01:22:31 +01:00
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
LastError = SendScsiCommand(cdb,
|
|
|
|
|
ref buffer,
|
|
|
|
|
out senseBuffer,
|
|
|
|
|
timeout,
|
|
|
|
|
ScsiDirection.In,
|
|
|
|
|
out duration,
|
2022-03-06 13:29:38 +00:00
|
|
|
out bool sense);
|
2020-06-05 01:22:31 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
Error = LastError != 0;
|
2020-06-05 01:22:31 +01:00
|
|
|
|
2023-10-03 17:28:12 +01:00
|
|
|
AaruConsole.DebugWriteLine(SCSI_MODULE_NAME, Localization.MINIDISC_GET_TYPE_took_0_ms, duration);
|
2020-06-05 01:22:31 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
return sense;
|
2020-06-05 01:22:31 +01:00
|
|
|
}
|
|
|
|
|
}
|