-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/DML@31 be6c1b03-d731-4111-a574-e37d80d43941
This commit is contained in:
crediar@rypp.net 2012-10-21 21:36:35 +00:00
parent 82602a7ff0
commit a2190e4497
9 changed files with 201 additions and 164 deletions

149
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:
@ -407,6 +437,7 @@ 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 );
@ -424,6 +455,7 @@ 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 )
{
@ -591,18 +624,9 @@ void CARDUpdateRegisters( void )
#ifdef CARDDEBUG
dbgprintf("MC:CARDOpen( \"%s\", 0x%08x )", FileName, FInfo );
#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 )
@ -674,11 +685,6 @@ void CARDUpdateRegisters( void )
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 );
memcpy( (void*)0x1780, &CS, sizeof(CARDStat) );
@ -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:
@ -809,19 +801,9 @@ void CARDUpdateRegisters( void )
#ifdef CARDDEBUG
dbgprintf("MC:CARDFastOpen( %d, 0x%08X )", FileNo, FInfo );
#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:
{
@ -836,13 +818,7 @@ void CARDUpdateRegisters( void )
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);
@ -901,14 +868,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 0xCA:
{
@ -920,13 +880,7 @@ void CARDUpdateRegisters( void )
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,14 +895,19 @@ void CARDUpdateRegisters( void )
#endif
CardRename( NameSrc, NameDst );
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 );
#ifdef CARDDEBUG
dbgprintf(":%d\n", read32( CARD_SRETURN ) );
#endif
} break;
}
if( ConfigGetConfig(DML_CFG_ACTIVITY_LED) )

View File

@ -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,11 +483,15 @@ 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;
@ -739,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

@ -19,7 +19,8 @@ DoCode:
mflr %r0
stw %r0, 4(%sp)
stwu %sp, -0x10(%sp)
stwu %sp, -0x28(%sp)
stmw %r27, 0x14(%sp)
#send cmd to DM
@ -81,8 +82,9 @@ skip_cb:
lwz %r3, 0x2F94(%r7)
mr %r4, %r3
lwz %r0, 0x14(%sp)
addi %sp, %sp, 0x10
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
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
lmw %r27, 0x14(%sp)
lwz %r0, 0x2C(%sp)
addi %sp, %sp, 0x28
mtlr %r0
blr

81
diosmioslite.ld Normal file
View File

@ -0,0 +1,81 @@
OUTPUT_FORMAT("elf32-bigarm")
OUTPUT_ARCH(arm)
ENTRY(_start)
__stack_size = 0x4000;
MEMORY
{
sram : ORIGIN = 0xFFFF0000, LENGTH = 0x10000
stack : ORIGIN = 0xFFFE0000, LENGTH = 0x4000
}
PHDRS
{
sram PT_LOAD AT ( 0xFFFF0000 ) ;
stack PT_LOAD AT ( 0xFFFE0000 ) ;
}
SECTIONS
{
.init :
{
*(.init)
. = ALIGN(4);
} >sram :sram
.text :
{
*(.text*)
*(.text.*)
*(.gnu.warning)
*(.gnu.linkonce.t*)
*(.glue_7)
*(.glue_7t)
. = ALIGN(4);
} >sram :sram
.rodata :
{
*(.rodata)
*all.rodata*(*)
*(.roda)
*(.rodata.*)
*(.gnu.linkonce.r*)
. = ALIGN(4);
} >sram :sram
.data :
{
*(.data)
*(.data.*)
*(.gnu.linkonce.d*)
. = ALIGN(4);
} >sram :sram
.bss :
{
__bss_start = . ;
*(.dynbss)
*(.gnu.linkonce.b*)
*(.bss*)
*(COMMON)
. = ALIGN(4);
__bss_end = . ;
} >sram :sram
.stack :
{
__stack_end = .;
. = . +__stack_size;
. = ALIGN(4);
__stack_addr = .;
} >stack :stack
/DISCARD/ :
{
*(.ARM.exidx*)
*(.ARM.extab*)
}
}

View File

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

View File

@ -362,35 +362,8 @@ void GeckoSendBuffer( char *buffer )
return;
}
extern FIL Log;
//static char buffer[128] ALIGNED(32);
int dbgprintf( const char *fmt, ...)
{
//va_list args;
//
//va_start(args, fmt);
//vsprintf(buffer, fmt, args);
//va_end(args);
//// Only write debug output to usb gecko when possible
//if( read32( 0x0D800070 ) & 1 )
//{
// GeckoSendBuffer( buffer );
//} else {
// u32 read;
// u32 fres = f_open( &Log, "/dm.log", FA_READ|FA_WRITE|FA_OPEN_ALWAYS );
// if( fres != FR_OK )
// {
// write32( 0x0D800070, 1 );
// dbgprintf("f_open():%d\n", fres );
// }
// f_lseek( &Log, Log.fsize );
// f_write( &Log, buffer, strlen(buffer), &read );
// f_close( &Log );
//}
return 1;
}