From 82f741e1dc7d3159103e61cae786cacf1db8b3e7 Mon Sep 17 00:00:00 2001 From: TheLastRar Date: Sun, 20 Oct 2024 01:05:34 +0100 Subject: [PATCH] DEV9: Add ATA commands used by PS2 Linux (#11925) --- pcsx2/DEV9/ATA/ATA.h | 2 ++ pcsx2/DEV9/ATA/Commands/ATA_CmdNoData.cpp | 22 ++++++++++++++++++++++ pcsx2/DEV9/ATA/Commands/ATA_CmdSMART.cpp | 8 ++++++++ pcsx2/DEV9/ATA/Commands/ATA_Command.cpp | 6 ++++++ 4 files changed, 38 insertions(+) diff --git a/pcsx2/DEV9/ATA/ATA.h b/pcsx2/DEV9/ATA/ATA.h index b4b8d2d150..a18d64c670 100644 --- a/pcsx2/DEV9/ATA/ATA.h +++ b/pcsx2/DEV9/ATA/ATA.h @@ -244,6 +244,7 @@ private: void HDD_FlushCache(); void HDD_InitDevParameters(); void HDD_ReadVerifySectors(bool isLBA48); + void HDD_Recalibrate(); void HDD_SeekCmd(); void HDD_SetFeatures(); void HDD_SetMultipleMode(); @@ -264,6 +265,7 @@ private: void HDD_Smart(); void SMART_SetAutoSaveAttribute(); + void SMART_SaveAttribute(); void SMART_ExecuteOfflineImmediate(); void SMART_EnableOps(bool enable); void SMART_ReturnStatus(); diff --git a/pcsx2/DEV9/ATA/Commands/ATA_CmdNoData.cpp b/pcsx2/DEV9/ATA/Commands/ATA_CmdNoData.cpp index 97d5aa0f69..218cbeaf82 100644 --- a/pcsx2/DEV9/ATA/Commands/ATA_CmdNoData.cpp +++ b/pcsx2/DEV9/ATA/Commands/ATA_CmdNoData.cpp @@ -57,6 +57,27 @@ void ATA::HDD_ReadVerifySectors(bool isLBA48) PostCmdNoData(); } +void ATA::HDD_Recalibrate() +{ + if (!PreCmd()) + return; + DevCon.WriteLn("DEV9: HDD_Recalibrate"); + + lba48 = false; + // Report minimum address (LBA 0 or CHS 0/0/1). + // SetLBA currently only supports LBA, so set the regs directly. + regSelect = regSelect & 0xf0; + regHcyl = 0; + regLcyl = 0; + regSector = (regSelect & 0x40) ? 0 : 1; + + // If recalibrate fails, we would set ATA_STAT_ERR in regStatus and ATA_ERR_TRACK0 in regError. + // we will never fail, so set ATA_STAT_SEEK in regStatus to indicate we finished seeking. + regStatus |= ATA_STAT_SEEK; + + PostCmdNoData(); +} + void ATA::HDD_SeekCmd() { if (!PreCmd()) @@ -65,6 +86,7 @@ void ATA::HDD_SeekCmd() regStatus &= ~ATA_STAT_SEEK; + lba48 = false; if (HDD_CanSeek()) { regStatus |= ATA_STAT_ERR; diff --git a/pcsx2/DEV9/ATA/Commands/ATA_CmdSMART.cpp b/pcsx2/DEV9/ATA/Commands/ATA_CmdSMART.cpp index aa03c7076b..195b7468bf 100644 --- a/pcsx2/DEV9/ATA/Commands/ATA_CmdSMART.cpp +++ b/pcsx2/DEV9/ATA/Commands/ATA_CmdSMART.cpp @@ -35,6 +35,7 @@ void ATA::HDD_Smart() SMART_SetAutoSaveAttribute(); return; case 0xD3: //SMART_ATTR_SAVE + SMART_SaveAttribute(); return; case 0xDA: //SMART_STATUS (is fault in disk?) SMART_ReturnStatus(); @@ -80,6 +81,13 @@ void ATA::SMART_SetAutoSaveAttribute() PostCmdNoData(); } +void ATA::SMART_SaveAttribute() +{ + PreCmd(); + // Stub + PostCmdNoData(); +} + void ATA::SMART_ExecuteOfflineImmediate() { PreCmd(); diff --git a/pcsx2/DEV9/ATA/Commands/ATA_Command.cpp b/pcsx2/DEV9/ATA/Commands/ATA_Command.cpp index a7b6b08ac4..c3d44a8c31 100644 --- a/pcsx2/DEV9/ATA/Commands/ATA_Command.cpp +++ b/pcsx2/DEV9/ATA/Commands/ATA_Command.cpp @@ -11,6 +11,9 @@ void ATA::IDE_ExecCmd(u16 value) case 0x00: HDD_Nop(); break; + case 0x10: + HDD_Recalibrate(); + break; case 0x20: HDD_ReadSectors(false); break; @@ -50,6 +53,9 @@ void ATA::IDE_ExecCmd(u16 value) case 0xC4: HDD_ReadMultiple(false); break; + case 0xC6: + HDD_SetMultipleMode(); + break; case 0xC8: HDD_ReadDMA(false); break;