-updated to version 2.4-

*Fixed NMM for Mario Kart Double Dash. Saving ghost data works now as well
*Fixed a bug that would sometimes break cheating/debugging unless both were enabled
*Moved the VIConfigure patch to the ARM side which should fix a number of broken titles
*Changed the HDD time out to read a random sector
*Optimised the EHCI reset code
*Optimised the CARD code


git-svn-id: svn://localhost/Users/andi/Downloads/code/trunk@31 be6c1b03-d731-4111-a574-e37d80d43941
This commit is contained in:
crediar@rypp.net 2012-10-21 21:36:35 +00:00
parent 8cebe92a4d
commit 894f641639
11 changed files with 153 additions and 168 deletions

163
Card.c
View File

@ -71,7 +71,31 @@ void CardInit( void )
write32( 0x2FA0, 0 );
}
void LFNfy( char *str )
{
u32 len = strlen(str);
u32 i;
for( i=0; i < len; ++i )
{
switch( str[i] )
{
case '\\':
case '/':
case '*':
case '|':
case '?':
case '<':
case '>':
case '\"':
case ':':
str[i] = ' ';
break;
default:
break;
}
}
}
s32 CardFindFreeEntry( void )
{
CARDStat CStat;
@ -127,6 +151,7 @@ s32 CardOpenFile( char *Filename, CARDFileInfo *CFInfo )
return -4;
}
LFNfy( Filename );
fres = f_open( &savefile, Filename, FA_READ|FA_WRITE|FA_OPEN_EXISTING ) ;
switch( fres )
{
@ -177,6 +202,7 @@ s32 CardFastOpenFile( u32 FileNo, CARDFileInfo *CFInfo )
return 0;
}
LFNfy( CStat.fileName );
fres = f_open( &savefile, CStat.fileName, FA_READ|FA_WRITE|FA_OPEN_EXISTING ) ;
switch( fres )
{
@ -332,7 +358,11 @@ void CardCreateFile( char *Filename, u32 Size, CARDFileInfo *CFInfo )
if( Slot < 0 )
return;
fres = f_open( &savefile, Filename, FA_READ|FA_WRITE|FA_CREATE_NEW );
char FName[32];
memcpy( FName, Filename, 32 );
LFNfy( FName );
fres = f_open( &savefile, FName, FA_READ|FA_WRITE|FA_CREATE_NEW );
switch( fres )
{
case FR_EXIST:
@ -406,7 +436,8 @@ void CardReadFile( u32 FileNo, u8 *Buffer, u32 Length, u32 Offset )
f_lseek( &CardStat, sizeof(CARDStat) * FileNo );
f_read( &CardStat, &CStat, sizeof(CARDStat), &read );
LFNfy( CStat.fileName );
if( f_open( &savefile, CStat.fileName, FA_OPEN_EXISTING | FA_READ ) == FR_OK )
{
f_lseek( &savefile, Offset );
@ -423,7 +454,8 @@ void CardWriteFile( u32 FileNo, u8 *Buffer, u32 Length, u32 Offset )
f_lseek( &CardStat, sizeof(CARDStat) * FileNo );
f_read( &CardStat, &CStat, sizeof(CARDStat), &read );
LFNfy( CStat.fileName );
switch( f_open( &savefile, CStat.fileName, FA_OPEN_EXISTING | FA_WRITE ) )
{
case FR_OK:
@ -523,6 +555,7 @@ void CardUpdateStats( CARDStat *CStat )
void CARDUpdateRegisters( void )
{
u32 read,i;
u32 CARDOK=0;
if( read32(CARD_CONTROL) != 0xdeadbeef )
{
@ -590,19 +623,10 @@ void CARDUpdateRegisters( void )
#ifdef CARDDEBUG
dbgprintf("MC:CARDOpen( \"%s\", 0x%08x )", FileName, FInfo );
#endif
#endif
CardOpenFile( (char*)FileName, (CARDFileInfo*)FInfo );
while( read32(CARD_CONTROL) & 1 )
clear32( CARD_CONTROL, 1 );
while( (read32(CARD_SSTATUS) & 0x10) != 0x10 )
set32( CARD_SSTATUS, 0x10 );
#ifdef CARDDEBUG
dbgprintf(":%d\n", read32( CARD_SRETURN ) );
#endif
CARDOK = 1;
} break;
case 0xC1:
{
@ -616,13 +640,7 @@ void CARDUpdateRegisters( void )
else
write32( CARD_SRETURN, 0 );
while( read32(CARD_SCONTROL) & 1 )
clear32( CARD_SCONTROL, 1 );
set32( CARD_SSTATUS, 0x10 );
#ifdef CARDDEBUG
dbgprintf(":%d\n", read32(CARD_SRETURN) );
#endif
CARDOK = 1;
} break;
case 0xC2:
{
@ -635,25 +653,18 @@ void CARDUpdateRegisters( void )
#ifdef CARDDEBUG
dbgprintf("MC:CARDCreate( \"%s\", 0x%04x, 0x%08x )", FileName, Size, FInfo );
#endif
CardCreateFile( (char*)FileName, Size, (CARDFileInfo*)FInfo );
write32( 0x2FA0, read32(0x2FA0) + CARD_XFER_CREATE );
while( read32(CARD_SCONTROL) & 1 )
clear32( CARD_SCONTROL, 1 );
set32( CARD_SSTATUS, 0x10 );
#ifdef CARDDEBUG
dbgprintf(":%d\n", read32( CARD_SRETURN ) );
#endif
CARDOK = 1;
} break;
case 0xC3:
{
CARDStat CS;
#ifdef CARDDEBUG
// dbgprintf("MC:CARDGetState( %d, 0x%08x, ", read32(CARD_SCMD_1), P2C(read32(CARD_SCMD_2)) );
dbgprintf("MC:CARDGetState( %d, 0x%08x, ", read32(CARD_SCMD_1), P2C(read32(CARD_SCMD_2)) );
#endif
if( read32(CARD_SCMD_1) >= CARD_MAX_FILES )
@ -673,11 +684,6 @@ void CARDUpdateRegisters( void )
#endif
write32( CARD_SRETURN, CARD_NO_FILE );
} else {
#ifdef CARDDEBUG
// dbgprintf("\"%s\")", CS.fileName );
dbgprintf("MC:CARDGetState( %d, 0x%08x, \"%s\"):0", read32(CARD_SCMD_1), P2C(read32(CARD_SCMD_2)), CS.fileName );
#endif
CardUpdateStats( &CS );
@ -711,14 +717,7 @@ void CARDUpdateRegisters( void )
write32( CARD_SRETURN, CARD_SUCCESS );
}
while( read32(CARD_SCONTROL) & 1 )
clear32( CARD_SCONTROL, 1 );
set32( CARD_SSTATUS, 0x10 );
#ifdef CARDDEBUG
// dbgprintf("MC:CARDGetState( %d, 0x%08x, ):%d\n", read32(CARD_SCMD_1), P2C(read32(CARD_SCMD_2)), read32( CARD_SRETURN) );
#endif
CARDOK = 1;
} break;
case 0xC4:
{
@ -727,7 +726,6 @@ void CARDUpdateRegisters( void )
#ifdef CARDDEBUG
dbgprintf("MC:CARDSetState( %d, 0x%08x )", read32(CARD_SCMD_1), P2C(read32(CARD_SCMD_2)) );
#endif
if( read32(CARD_SCMD_1) >= CARD_MAX_FILES )
{
EXIControl(1);
@ -792,13 +790,7 @@ void CARDUpdateRegisters( void )
write32( CARD_SRETURN, CARD_SUCCESS );
}
while( read32(CARD_SCONTROL) & 1 )
clear32( CARD_SCONTROL, 1 );
set32( CARD_SSTATUS, 0x10 );
#ifdef CARDDEBUG
dbgprintf(":1\n");
#endif
CARDOK = 1;
} break;
/* CARDFastOpen( u32 FileNO, CARDFileInfo *CFInfo ) */
case 0xC5:
@ -808,20 +800,10 @@ void CARDUpdateRegisters( void )
#ifdef CARDDEBUG
dbgprintf("MC:CARDFastOpen( %d, 0x%08X )", FileNo, FInfo );
#endif
#endif
CardFastOpenFile( FileNo, (CARDFileInfo*)FInfo );
while( read32(CARD_CONTROL) & 1 )
clear32( CARD_CONTROL, 1 );
while( (read32(CARD_SSTATUS) & 0x10) != 0x10 )
set32( CARD_SSTATUS, 0x10 );
#ifdef CARDDEBUG
dbgprintf(":%d\n", read32( CARD_SRETURN ) );
#endif
CARDOK = 1;
} break;
case 0xC6:
{
@ -835,14 +817,8 @@ void CARDUpdateRegisters( void )
CardDeleteFile( (char*)FileName );
write32( 0x2FA0, read32(0x2FA0) + CARD_XFER_DELETE );
while( read32(CARD_SCONTROL) & 1 )
clear32( CARD_SCONTROL, 1 );
set32( CARD_SSTATUS, 0x10 );
#ifdef CARDDEBUG
dbgprintf(":%d\n", read32( CARD_SRETURN ) );
#endif
CARDOK = 1;
} break;
case 0xC8:
{
@ -854,7 +830,6 @@ void CARDUpdateRegisters( void )
#ifdef CARDDEBUG
dbgprintf("MC:CARDWrite( %d, 0x%08x, 0x%04x, 0x%04x )", FileNo, Buffer, Offset, Length );
#endif
if( FileNo >= CARD_MAX_FILES )
{
EXIControl(1);
@ -868,14 +843,7 @@ void CARDUpdateRegisters( void )
write32( CARD_SRETURN, 0 );
while( read32(CARD_SCONTROL) & 1 )
clear32( CARD_SCONTROL, 1 );
set32( CARD_SSTATUS, 0x10 );
#ifdef CARDDEBUG
dbgprintf(":%u\n", read32(CARD_SRETURN) );
#endif
CARDOK = 1;
} break;
case 0xC9:
{
@ -887,7 +855,6 @@ void CARDUpdateRegisters( void )
#ifdef CARDDEBUG
dbgprintf("MC:CARDRead( %d, 0x%08x, 0x%04x, 0x%04x )", FileNo, Buffer, Offset, Length );
#endif
if( FileNo >= CARD_MAX_FILES )
{
EXIControl(1);
@ -900,15 +867,8 @@ void CARDUpdateRegisters( void )
write32( 0x2FA0, read32(0x2FA0) + Length );
write32( CARD_SRETURN, 0 );
while( read32(CARD_SCONTROL) & 1 )
clear32( CARD_SCONTROL, 1 );
set32( CARD_SSTATUS, 0x10 );
#ifdef CARDDEBUG
dbgprintf(":%u\n", read32(CARD_SRETURN) );
#endif
CARDOK = 1;
} break;
case 0xCA:
{
@ -919,14 +879,8 @@ void CARDUpdateRegisters( void )
CardFastDelete( FileNo );
write32( 0x2FA0, read32(0x2FA0) + CARD_XFER_DELETE );
while( read32(CARD_SCONTROL) & 1 )
clear32( CARD_SCONTROL, 1 );
set32( CARD_SSTATUS, 0x10 );
#ifdef CARDDEBUG
dbgprintf(":%d\n", read32( CARD_SRETURN ) );
#endif
CARDOK = 1;
} break;
case 0xCB:
{
@ -941,16 +895,21 @@ void CARDUpdateRegisters( void )
#endif
CardRename( NameSrc, NameDst );
while( read32(CARD_SCONTROL) & 1 )
clear32( CARD_SCONTROL, 1 );
set32( CARD_SSTATUS, 0x10 );
#ifdef CARDDEBUG
dbgprintf(":%d\n", read32( CARD_SRETURN ) );
#endif
CARDOK = 1;
} break;
}
if(CARDOK)
{
#ifdef CARDDEBUG
dbgprintf(":%d\n", read32( CARD_SRETURN ) );
#endif
while( read32(CARD_SCONTROL) & 1 )
clear32( CARD_SCONTROL, 1 );
set32( CARD_SSTATUS, 0x10 );
}
if( ConfigGetConfig(DML_CFG_ACTIVITY_LED) )
clear32( HW_GPIO_OUT, 1<<5 );
}

5
Card.h
View File

@ -8,9 +8,7 @@
#include "vsprintf.h"
#include "HW.h"
#include "vsprintf.h"
#ifdef TRIFORCE
#include "JVSIOMessage.h"
#endif
#define CARD_MAX_FILES 128
#define CARD_BASE 0x00002F60
@ -45,7 +43,6 @@
#define CARD_XFER_SETATTRIBUTES (1 * 8 * 1024) // CARDSetAttributes[Async]
#define CARD_XFER_WRITE (1 * 8 * 1024) // CARDWrite[Async]
#define CARD_FILENAME_MAX 32
#define CARD_ICON_MAX 8

View File

@ -148,7 +148,7 @@ FuncPattern FPatterns[] =
{ 0x3B0, 87, 13, 27, 17, 25, (u8*)NULL, 0xdead000B, "PADRead C", 2, 0 },
{ 0x334, 78, 7, 20, 17, 19, (u8*)NULL, 0xdead000B, "PADRead D", 2, 0 },
};
};
FuncPattern CPatterns[] =
{
@ -452,11 +452,16 @@ void DoCardPatches( char *ptr, u32 size, u32 SectionOffset )
if( (read32( offset + 0x04 ) & 0x0000F000 ) == 0x00008000 ) // lis
{
write32( offset, read32( offset + 0x0C ) & 0xFBE00000 );
offset += 4;
if( CPatterns[j].Patch == CARDCheckEX )
{
write32( offset, 0x38800000 ); // lis r4,0
offset += 4;
}
//Forge a branch to the async function
offset += 4;
u32 newval = ((u32)ptr + i) - offset;
newval&= 0x03FFFFFC;
newval|= 0x48000000;
@ -478,13 +483,18 @@ void DoCardPatches( char *ptr, u32 size, u32 SectionOffset )
}
}
for( j=0; j < sizeof(CPatterns)/sizeof(FuncPattern); ++j )
{
if( CPatterns[j].Found == 0 )
dbgprintf("Pattern %s not found!\n", CPatterns[j].Name );
}
//if( CardLowestOff )
//{
// for( j=0; j < sizeof(CPatterns)/sizeof(FuncPattern); ++j )
// {
// if( CPatterns[j].Found == 0 )
// dbgprintf("Pattern %s not found!\n", CPatterns[j].Name );
// }
//}
return;
}
void DoPatches( char *ptr, u32 size, u32 SectionOffset )
{
@ -517,9 +527,11 @@ void DoPatches( char *ptr, u32 size, u32 SectionOffset )
write32(0x00003194, 0x48000028);
}
// Reset Found
for( k=0; k < sizeof(FPatterns)/sizeof(FuncPattern); ++k )
FPatterns[k].Found = 0;
FPatterns[k].Found = 0;
if( ConfigGetConfig(DML_CFG_NMM) )
DoCardPatches( ptr, size, SectionOffset );
@ -736,12 +748,25 @@ void DoPatches( char *ptr, u32 size, u32 SectionOffset )
}
}
if( ConfigGetConfig(DML_CFG_CHEATS) )
if( (PatchCount & 64) == 0 )
{
if( PatchCount == 63 )
if( read32( (u32)ptr + i + 0 ) == 0x3C608000 )
{
if( ((read32( (u32)ptr + i + 4 ) & 0xFC1FFFFF ) == 0x800300CC) && ((read32( (u32)ptr + i + 8 ) >> 24) == 0x54 ) )
{
dbgprintf( "Patch:[VIConfgiure] 0x%08X\n", (u32)(ptr+i) );
write32( *(vu32*)(ptr+i+4), 0x5400F0BE | ((read32( (u32)ptr + i + 4 ) & 0x3E00000) >> 5 ) );
PatchCount |= 64;
}
}
}
if( ConfigGetConfig(DML_CFG_CHEATS) || ConfigGetConfig( DML_CFG_DEBUGGER ) )
{
if( PatchCount == 127 )
break;
} else {
if( PatchCount == 47 )
if( PatchCount == 111 )
break;
}
}

View File

@ -66,8 +66,6 @@ typedef struct _gx_rmodeobj {
#define GXNtsc480IntDf 3
#define GXNtsc480Int 4
void PatchGCIPL( void );
void DoPatches( char *ptr, u32 size, u32 SectionOffset );
void DoCardPatches( char *ptr, u32 size, u32 SectionOffset );
void DoPatchesLoader( char *ptr, u32 size );

View File

@ -18,8 +18,9 @@ CARDCreate:
DoCode:
mflr %r0
stw %r0, 4(%sp)
stwu %sp, -0x10(%sp)
stw %r0, 4(%sp)
stwu %sp, -0x28(%sp)
stmw %r27, 0x14(%sp)
#send cmd to DM
@ -80,9 +81,10 @@ skip_cb:
lis %r7, 0xC000
lwz %r3, 0x2F94(%r7)
mr %r4, %r3
lwz %r0, 0x14(%sp)
addi %sp, %sp, 0x10
mtlr %r0
lmw %r27, 0x14(%sp)
lwz %r0, 0x2C(%sp)
addi %sp, %sp, 0x28
mtlr %r0
blr

View File

@ -7,12 +7,12 @@
# r6 offset
# r7 cb
CardWrite:
CardRead:
mflr %r0
stw %r0, 4(%sp)
stwu %sp, -0x20(%sp)
stw %r31, 0x1C(%sp)
stwu %sp, -0x28(%sp)
stmw %r27, 0x14(%sp)
#Update fileinfo
stw %r5, 0x0C(%r3)
@ -66,17 +66,17 @@ wait_loop:
cmpwi %r12, 0
beq skip_cb
mtctr %r12
mtlr %r12
li %r3, 0
li %r4, 0
bctrl
blrl
skip_cb:
li %r3, 0
mr %r4, %r3
lwz %r0, 0x24(%sp)
lwz %r31, 0x1C(%sp)
addi %sp, %sp, 0x20
mtlr %r0
lmw %r27, 0x14(%sp)
lwz %r0, 0x2C(%sp)
addi %sp, %sp, 0x28
mtlr %r0
blr

View File

@ -11,7 +11,8 @@ CardWrite:
mflr %r0
stw %r0, 4(%sp)
stwu %sp, -0x10(%sp)
stwu %sp, -0x28(%sp)
stmw %r27, 0x14(%sp)
#Update fileinfo
stw %r5, 0x0C(%r3)
@ -65,16 +66,17 @@ wait_loop:
cmpwi %r12, 0
beq skip_cb
mtctr %r12
mtlr %r12
li %r3, 0
li %r4, 0
bctrl
blrl
skip_cb:
li %r3, 0
mr %r4, %r3
lwz %r0, 0x14(%sp)
addi %sp, %sp, 0x10
mtlr %r0
lmw %r27, 0x14(%sp)
lwz %r0, 0x2C(%sp)
addi %sp, %sp, 0x28
mtlr %r0
blr

2
dip.c
View File

@ -335,7 +335,7 @@ u32 DIUpdateRegisters( void )
if( (u64)read32(HW_TIMER) >= 2 * 60 * 243000000LL / 128 )
{
USBStorage_Read_Sectors( 23, 1, (void*)0x1000 );
USBStorage_Read_Sectors( (read32(HW_TIMER) << 3) & 0x00FFFFFF, 1, (void*)0x1000 );
write32( HW_TIMER, 0 );
}

48
ehci.c
View File

@ -656,21 +656,20 @@ s32 ehci_bulk_message(struct ehci_device *dev,u8 bEndpoint,u16 wLength,void *rpD
return ret;
}
int ehci_reset_port(int port)
{
u32 __iomem *status_reg = &ehci->regs->port_status[port];
struct ehci_device *dev = &ehci->devices[port];
u32 __iomem *status_reg = &ehci->regs->port_status[port];
struct ehci_device *dev = &ehci->devices[port];
u32 status = ehci_readl(status_reg);
int retval = 0;
dev->id = 0;
if ((PORT_OWNER&status) || !(PORT_CONNECT&status))
if( (PORT_OWNER&status) || !(PORT_CONNECT&status) )
{
int retries = 10;
while (!(PORT_CONNECT&status) && retries > 0)
while( !(PORT_CONNECT&status) && retries > 0 )
{
msleep(1000); // sleep 1 second
status = ehci_readl(status_reg);
@ -680,38 +679,41 @@ int ehci_reset_port(int port)
if( retries <= 0 )
{
ehci_writel( PORT_OWNER, status_reg);
ehci_writel( PORT_OWNER, status_reg );
ehci_dbg ( "EHCI:port %d had no usb2 device connected at startup %X \n", port,ehci_readl(status_reg) );
return -ENODEV;// no USB2 device connected
}
}
ehci_dbg ( "EHCI:port %d has usb2 device connected! reset it...\n", port);
ehci_writel( 0x1803,status_reg);
while ((ehci_readl(status_reg) & 0x1801) != 0x1801)
if( PORT_USB11(ehci_readl(status_reg)) )
{
ehci_dbg ( "EHCI:Waiting for port %d to settle...(%04x)\n", port, ehci_readl(status_reg));
ehci_writel( 0x1803,status_reg);
msleep(500);
}
ehci_dbg("EHCI:Device is USB1.1\n");
}
ehci_writel( 0x1903,status_reg);
//ehci_writel( PORT_OWNER|PORT_POWER|PORT_RESET,status_reg);
msleep(50);// wait 50ms for the reset sequence
ehci_writel( 0x1001,status_reg);
retval = handshake( status_reg, PORT_RESET, 0, 2000);
status = ehci_readl(status_reg);
status|= PORT_RESET;
ehci_writel( status, status_reg );
if (retval != 0)
msleep(50); // wait 50ms for the reset sequence
status = ehci_readl(status_reg);
status ^= PORT_RESET;
ehci_writel( status, status_reg );
retval = handshake( status_reg, PORT_RESET, 0, 2000 );
if(retval != 0)
{
ehci_dbg ( "EHCI:port %d reset error %d\n", port, retval);
return retval;
}
}
ehci_dbg ( "EHCI:port %d reseted status:%04x...\n", port,ehci_readl(status_reg));
msleep(50);
msleep(100);
// now the device has the default device id
retval = ehci_control_message( dev, USB_CTRLTYPE_DIR_DEVICE2HOST, USB_REQ_GETDESCRIPTOR, USB_DT_DEVICE<<8, 0, sizeof(dev->desc), &dev->desc );
retval = ehci_control_message( dev, USB_CTRLTYPE_DIR_DEVICE2HOST, USB_REQ_GETDESCRIPTOR, USB_DT_DEVICE<<8, 0, sizeof(dev->desc), &dev->desc );
if (retval < 0)
{
ehci_dbg("EHCI:unable to get device desc...\n");

View File

@ -15,7 +15,7 @@
#define PADHOOK 1
#define CONFIG_VERSION 0x00000002
#define DM_VERSION 0x00020003
#define DM_VERSION 0x00020004
#define DI_SUCCESS 1
#define DI_ERROR 2

View File

@ -34,7 +34,7 @@ void BUG(void)
void msleep(int msec)
{
udelay(2048*msec);
udelay(msec*1000);
}
extern u32 __exe_start_virt__;
extern u32 __ram_start_virt__;