Skip to content

Commit

Permalink
DEV9: Add ATA commands used by PS2 Linux (#11925)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLastRar authored Oct 20, 2024
1 parent ab21d22 commit 82f741e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pcsx2/DEV9/ATA/ATA.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ class ATA
void HDD_FlushCache();
void HDD_InitDevParameters();
void HDD_ReadVerifySectors(bool isLBA48);
void HDD_Recalibrate();
void HDD_SeekCmd();
void HDD_SetFeatures();
void HDD_SetMultipleMode();
Expand All @@ -264,6 +265,7 @@ class ATA

void HDD_Smart();
void SMART_SetAutoSaveAttribute();
void SMART_SaveAttribute();
void SMART_ExecuteOfflineImmediate();
void SMART_EnableOps(bool enable);
void SMART_ReturnStatus();
Expand Down
22 changes: 22 additions & 0 deletions pcsx2/DEV9/ATA/Commands/ATA_CmdNoData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -65,6 +86,7 @@ void ATA::HDD_SeekCmd()

regStatus &= ~ATA_STAT_SEEK;

lba48 = false;
if (HDD_CanSeek())
{
regStatus |= ATA_STAT_ERR;
Expand Down
8 changes: 8 additions & 0 deletions pcsx2/DEV9/ATA/Commands/ATA_CmdSMART.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -80,6 +81,13 @@ void ATA::SMART_SetAutoSaveAttribute()
PostCmdNoData();
}

void ATA::SMART_SaveAttribute()
{
PreCmd();
// Stub
PostCmdNoData();
}

void ATA::SMART_ExecuteOfflineImmediate()
{
PreCmd();
Expand Down
6 changes: 6 additions & 0 deletions pcsx2/DEV9/ATA/Commands/ATA_Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 82f741e

Please sign in to comment.