Skip to content

Commit

Permalink
-made triforce games globally be in free play mode even without segab…
Browse files Browse the repository at this point in the history
…oot by copying the needed memory block into its place, removed all the hardcoded coin patches because of this change

-removed several other hardcoded triforce patches by adding a dynamic patch for all triforce games to fake our type
-removed the segaboot hardcoded free play patches since that memory block is now always in place anyways
  • Loading branch information
FIX94 committed Jun 19, 2016
1 parent 803e651 commit 1aff60c
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 103 deletions.
2 changes: 1 addition & 1 deletion common/include/NintendontVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define __NINTENDONT_VERSION_H__

#define NIN_MAJOR_VERSION 4
#define NIN_MINOR_VERSION 408
#define NIN_MINOR_VERSION 409

#define NIN_VERSION ((NIN_MAJOR_VERSION << 16) | NIN_MINOR_VERSION)

Expand Down
6 changes: 3 additions & 3 deletions kernel/DI.c
Original file line number Diff line number Diff line change
Expand Up @@ -553,18 +553,18 @@ void DIUpdateRegisters( void )
// Progress in %
*(u32*)(MediaBuffer+8) = bswap32(100);
break;
// Media board version: 3.03
// Media board version: 13.05
case 0x101:
// Version
*(u16*)(MediaBuffer+4) = 0x0303;
*(u16*)(MediaBuffer+4) = bswap16(0x1305);
// Unknown
*(u16*)(MediaBuffer+6) = 0x01;
*(u32*)(MediaBuffer+8) = 1;
*(u32*)(MediaBuffer+16)= 0xFFFFFFFF;
break;
// System flags
case 0x102:
// 1: GD-ROM
// 1: GD-ROM
MediaBuffer[4] = 1;
MediaBuffer[5] = 0;
// enable development mode (Sega Boot)
Expand Down
38 changes: 36 additions & 2 deletions kernel/EXI.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,17 @@ static u32 TRIBackupOffset= 0;
static u32 EXI2IRQ = 0;
static u32 EXI2IRQStatus = 0;

static u8 *ambbBackupMem;

void EXIInit( void )
{
dbgprintf("EXIInit Start\r\n");
u32 wrote, ret;

//some important memory for triforce
ambbBackupMem = malloca(0x10000, 0x40);
memset32(ambbBackupMem, 0xFF, 0x10000);

memset32((void*)EXI_BASE, 0, 0x20);
sync_after_write((void*)EXI_BASE, 0x20);

Expand Down Expand Up @@ -585,7 +591,7 @@ u32 EXIDeviceSP1( u8 *Data, u32 Length, u32 Mode )
} break;
case 0x02:
{
MCard[TRIBackupOffset] = ((u32)Data >> 16) & 0xFF;
ambbBackupMem[TRIBackupOffset] = ((u32)Data >> 16) & 0xFF;
EXICommand = AMBB_BACKUP_WRITE;
} break;
case 0x03:
Expand Down Expand Up @@ -663,7 +669,7 @@ u32 EXIDeviceSP1( u8 *Data, u32 Length, u32 Mode )
/* 0x03 */
case AMBB_BACKUP_READ:
{
write32( EXI_CMD_1, 0x0100 | MCard[TRIBackupOffset] );
write32( EXI_CMD_1, 0x0100 | ambbBackupMem[TRIBackupOffset] );
} break;
/* 0x87 */
case AMBB_IMR_WRITE:
Expand Down Expand Up @@ -869,3 +875,31 @@ void EXIReadFontFile(u8* Data, u32 Length)
memcpy(Data, FontBuf + IPLReadOffset - IPL_ROM_FONT_SJIS, Length);
sync_after_write(Data, Length);
}

//SegaBoot 3.11 with Free Play enabled
unsigned int sb311block[54] =
{
0x41434255, 0x30303031, 0x007D0512, 0x01000000, 0x00000311, 0x53424C4B,
0x00000000, 0x63090400, 0x01010A01, 0x01010001, 0x01010101, 0x01010101,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001,
0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000000,
0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000001,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x200E1AFF,
0xFFFF0000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
} ;

static bool TRIGameStarted = false;
//make sure ambbBackupMem is filled correctly
void EXIPrepareTRIGameStart()
{
if(TRIGameStarted)
return;
dbgprintf("TRI:Setting up AMBB memory\r\n");
memset32(ambbBackupMem, 0, 0x400);
memcpy(ambbBackupMem, sb311block, sizeof(sb311block));
memcpy(ambbBackupMem + 0x200, sb311block, sizeof(sb311block));
memset32(ambbBackupMem + 0x400, 0xFF, 0x10000 - 0x400);
TRIGameStarted = true;
}
1 change: 1 addition & 0 deletions kernel/EXI.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ void EXIShutdown( void );
void EXISaveCard(void);
bool EXICheckCard(void);
void EXIReadFontFile(u8* Data, u32 Length);
void EXIPrepareTRIGameStart();

#endif

Expand Down
12 changes: 2 additions & 10 deletions kernel/JVSIO.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ extern vu32 m_ptr;
extern vu8 m_msg[0x80];

extern vu32 TRIGame;
vu32 TRICoinOffset = 0;
vu32 AXTimerOffset = 0;
void *TRICoinOffsetAligned = 0;
static const char *TRI_SegaChar = "SEGA ENTERPRISES,LTD.;I/O BD JVS;837-13551;Ver1.00";
static const char *TRI_NamcoChar = "namco ltd.;FCA-1;Ver1.01;JPN,Multipurpose + Rotary Encoder";
static const u32 TRI_DefaultCoinCount = 9;
Expand All @@ -45,12 +43,6 @@ void JVSIOCommand( char *DataIn, char *DataOut )
// DataIn[DataPos+6],
// DataIn[DataPos+7] );

if(TRICoinOffset)
{
sync_before_read( TRICoinOffsetAligned, 0x20 );
write32( TRICoinOffset, TRI_DefaultCoinCount );
sync_after_write( TRICoinOffsetAligned, 0x20 );
}
if(AXTimerOffset)
{
sync_before_read( (void*)AXTimerOffset, 0x20 );
Expand Down Expand Up @@ -164,12 +156,12 @@ void JVSIOCommand( char *DataIn, char *DataOut )
} break;
default:
{
// 1 Player (15bit), 1 Coin slot, 3 Analog-in, CARD, 8bit GPO
// 1 Player (15bit), 1 Coin slot, 3 Analog-in, 1 CARD, 1 Driver-out
addDataBuffer((void *)"\x01\x01\x0F\x00", 4);
addDataBuffer((void *)"\x02\x01\x00\x00", 4);
addDataBuffer((void *)"\x03\x03\x00\x00", 4);
addDataBuffer((void *)"\x10\x01\x00\x00", 4);
addDataBuffer((void *)"\x12\x08\x00\x00", 4);
addDataBuffer((void *)"\x12\x01\x00\x00", 4);
addDataBuffer((void *)"\x00\x00\x00\x00", 4);
} break;
}
Expand Down
12 changes: 12 additions & 0 deletions kernel/Patch.c
Original file line number Diff line number Diff line change
Expand Up @@ -2557,6 +2557,18 @@ void DoPatches( char *Buffer, u32 Length, u32 DiscOffset )
else
CurPatterns[j].Found = 0; // False hit
} break;
case FCODE_IsTriforceType3:
{
if(read32(FOffset + 0x290) == 0x5460063F && read32(FOffset + 0x2C8) == 0x2C030000)
{
/* Fake 0x29 DI CMD version to prevent freezes on newer triforce games */
write32( FOffset + 0x290, 0x2C040000 ); //fake compare result to continue
write32( FOffset + 0x2C4, 0x38600000 ); //dont change type, just return ok
printpatchfound(CurPatterns[j].Name, CurPatterns[j].Type, FOffset);
}
else
CurPatterns[j].Found = 0; // False hit
} break;
case FCODE_GCAMSendCommand:
{
if(read32(FOffset + 0x2C) == 0x38C40080)
Expand Down
Loading

0 comments on commit 1aff60c

Please sign in to comment.