Skip to content

Commit

Permalink
Added a workaround for bad GameStar compatible adaptors into ATAD.
Browse files Browse the repository at this point in the history
  • Loading branch information
sp193 authored and Liu Woon Yung committed Jan 11, 2018
1 parent ea60bff commit 6d2cb98
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
7 changes: 7 additions & 0 deletions iop/dev9/atad/Makefile
Expand Up @@ -15,6 +15,9 @@ ATA_MWDMA_MODES ?= 0
#Enable to enable support for PIO modes 0-4 (as in early ATAD modules), instead of just PIO mode 0.
ATA_ALL_PIO_MODES ?= 0

#Disable to disable the workaround for bad GameStar compatible adaptors.
ATA_GAMESTAR_WORKAROUND ?= 1

IOP_BIN ?= ps2atad.irx

IOP_INCS += -I$(PS2SDKSRC)/iop/dev9/dev9/include
Expand All @@ -32,6 +35,10 @@ ifeq ($(ATA_ALL_PIO_MODES),1)
IOP_CFLAGS += -DATA_ALL_PIO_MODES=1
endif

ifeq ($(ATA_GAMESTAR_WORKAROUND),1)
IOP_CFLAGS += -DATA_GAMESTAR_WORKAROUND=1
endif

include $(PS2SDKSRC)/Defs.make
include $(PS2SDKSRC)/iop/Rules.bin.make
include $(PS2SDKSRC)/iop/Rules.make
Expand Down
23 changes: 23 additions & 0 deletions iop/dev9/atad/src/ps2atad.c
Expand Up @@ -54,6 +54,9 @@ static int ata_evflg = -1;

//Workarounds
static u8 ata_disable_lba48 = 0; //Please read the comments in _start().
#ifdef ATA_GAMESTAR_WORKAROUND
static u8 ata_gamestar_workaround = 0;
#endif

/* Local device info kept for drives 0 and 1. */
static ata_devinfo_t atad_devinfo[2];
Expand Down Expand Up @@ -223,6 +226,12 @@ int _start(int argc, char *argv[])
The obvious workaround here would be to disable 48-bit LBA support when ATAD is loaded on a PSX. */
ata_disable_lba48 = (SPD_REG16(SPD_R_REV_3) & SPD_CAPS_DVR)?1:0;

#ifdef ATA_GAMESTAR_WORKAROUND
/* A GameStar masquerades as a SCPH-10281, but malfunctions if transfers are not done according to the old ps2atad design.
All official adaptors appear to have different values for these two registers, but not the GameStar. */
ata_gamestar_workaround = (SPD_REG16(SPD_R_REV) == SPD_REG16(SPD_R_REV_1));
#endif

if ((ata_evflg = ata_create_event_flag()) < 0) {
M_PRINTF("Couldn't create event flag, exiting.\n");
res = 1;
Expand Down Expand Up @@ -798,6 +807,11 @@ int ata_device_sector_io(int device, void *buf, u32 lba, u32 nsectors, int dir)
u16 sector, lcyl, hcyl, select, command, len;

while (res == 0 && nsectors > 0) {
#ifdef ATA_GAMESTAR_WORKAROUND
if (ata_gamestar_workaround)
ata_set_dir(dir);
#endif

/* Variable lba is only 32 bits so no change for lcyl and hcyl. */
lcyl = (lba >> 8) & 0xff;
hcyl = (lba >> 16) & 0xff;
Expand Down Expand Up @@ -826,8 +840,13 @@ int ata_device_sector_io(int device, void *buf, u32 lba, u32 nsectors, int dir)
if ((res = ata_io_start(buf, len, 0, len, sector, lcyl, hcyl, select, command)) != 0)
break;

#ifdef ATA_GAMESTAR_WORKAROUND
if (!ata_gamestar_workaround)
ata_set_dir(dir);
#else
/* Set up (part of) the transfer here. In v1.04, this was called at the top of the outer loop. */
ata_set_dir(dir);
#endif

res = ata_io_finish();

Expand Down Expand Up @@ -1060,7 +1079,11 @@ static void ata_set_dir(int dir)
val = SPD_REG16(SPD_R_IF_CTRL) & 1;
val |= (dir == ATA_DIR_WRITE) ? 0x4c : 0x4e;
SPD_REG16(SPD_R_IF_CTRL) = val;
#ifdef ATA_GAMESTAR_WORKAROUND
SPD_REG16(SPD_R_XFR_CTRL) = dir | (ata_gamestar_workaround ? 0x86 : 0x6);
#else
SPD_REG16(SPD_R_XFR_CTRL) = dir | 0x6; //In v1.04, DMA was enabled here (0x86 instead of 0x6)
#endif
}

static void ata_pio_mode(int mode)
Expand Down

0 comments on commit 6d2cb98

Please sign in to comment.