void TRIBackupSettings() { if(TRISettingsName == (char*)0 || TRISettingsLoc == 0 || TRISettingsSize == 0) return; void *GameSettingsLoc = (TRIGame == TRI_AX || TRIGame == TRI_YAK) ? (void*)TRISettingsLoc : (void*)P2C(read32(TRISettingsLoc)); sync_before_read_align32(GameSettingsLoc, TRISettingsSize); sync_before_read_align32(OUR_SETTINGS_LOC, TRISettingsSize); if((memcmp(OUR_SETTINGS_LOC, GameSettingsLoc, TRISettingsSize) != 0) && (memcmp(GameSettingsLoc, "SB", 2) == 0)) { dbgprintf("TRI:Writing Settings\r\n"); memcpy(OUR_SETTINGS_LOC, GameSettingsLoc, TRISettingsSize); FIL backup; if(f_open_char(&backup, TRISettingsName, FA_WRITE | FA_CREATE_ALWAYS) == FR_OK) { u32 wrote; f_write(&backup, OUR_SETTINGS_LOC, TRISettingsSize, &wrote); f_close(&backup); } sync_after_write_align32(OUR_SETTINGS_LOC, TRISettingsSize); TRI_BackupAvailable = 1; } }
void TRIReadSettings() { if(TRISettingsName == (char*)0 || TRISettingsSize == 0) return; FIL backup; if (f_open_char(&backup, TRISettingsName, FA_OPEN_EXISTING | FA_READ) == FR_OK) { if(backup.obj.objsize == TRISettingsSize) { u32 read; u8 sbuf[TRISettingsSize]; f_read(&backup, sbuf, TRISettingsSize, &read); if(memcmp(sbuf, "SB", 2) == 0) { dbgprintf("TRI:Reading Settings\r\n"); memcpy(OUR_SETTINGS_LOC, sbuf, TRISettingsSize); sync_after_write_align32(OUR_SETTINGS_LOC, TRISettingsSize); TRI_BackupAvailable = 1; } } f_close(&backup); } }
void GCAMUpdateRegisters( void ) { u32 i; u32 *GInterface = (u32*)(GCAM_BASE); u32 *GInterfaceS = (u32*)(GCAM_SHADOW); sync_before_read( (void*)GCAM_BASE, 0x40 ); if( read32(GCAM_CONTROL) != 0xdeadbeef ) { if( read32( GCAM_CONTROL ) & (~3) ) { write32( GCAM_CONTROL, 0xdeadbeef ); sync_after_write( (void*)GCAM_BASE, 0x40 ); return; } /*write32( GCAM_SCONTROL, read32(GCAM_CONTROL) & 3 ); clear32( GCAM_SSTATUS, 0x14 ); write32( GCAM_CONTROL, 0xdeadbeef ); write32( GCAM_RETURN, 0xdeadbeef ); write32( GCAM_STATUS, 0xdeadbeef ); sync_after_write( (void*)GCAM_BASE, 0x40 );*/ for( i=0; i < 5; ++i ) { if( GInterface[i] != 0xdeadbeef ) { GInterfaceS[i] = GInterface[i]; GInterface[i] = 0xdeadbeef; } } switch( read32(GCAM_SCMD) >> 24 ) { case 0x00: { //dbgprintf("CARD:Warning unknown command!\n"); } break; case 0x50: { char *datain = (char*)P2C( read32(GCAM_SCMD_1) ); u32 lenin = read32(GCAM_SCMD_2); char *dataout = (char*)P2C( read32(GCAM_SCMD_3) ); u32 lenout = read32(GCAM_SCMD_4); #ifdef DEBUG_GCAM dbgprintf("SI:Transfer( %p, %u, %p, %u )\n", datain, lenin, dataout, lenout ); hexdump( datain, lenin ); #endif sync_before_read_align32(datain, lenin); switch( datain[0] ) { // dbgprintf("[%02X]", datain[0] ); case 0x00: { W32( (u32)dataout, 0x10110800 ); // dbgprintf("Reset(0x%p)\n", dataout ); } break; default: // CMD_DIRECT case 0x40: // CMD_ORIGIN case 0x41: // CMD_RECALIBRATE case 0x42: { memset( dataout, 0, lenout ); } break; } sync_after_write_align32(dataout, lenout); //hexdump( dataout, lenout ); //while( read32(GCAM_CONTROL) & 1 ) // clear32( GCAM_CONTROL, 1 ); //while( (read32(GCAM_SSTATUS) & 0x10) != 0x10 ) // set32( GCAM_SSTATUS, 0x10 ); } break; case 0x70: { char *datain = (char*)P2C( read32(GCAM_SCMD_1) ); char *dataout = (char*)P2C( read32(GCAM_SCMD_2) ); //dbgprintf("GC-AM:Command( %p, %u, %p, %u )\n", datain, 0x80, dataout, 0x80 ); sync_before_read_align32(datain, 0x80); memcpy( Bufi, datain, 0x80 ); GCAMCommand( Bufi, Buf ); if( FirstCMD == 0 ) { memset32( dataout, 0, 0x80 ); FirstCMD = 1; } else { memcpy( dataout, Bufo, 0x80 ); memcpy( Bufo, Buf, 0x80 ); } sync_after_write_align32(dataout, 0x80); //hexdump( dataout, 0x10 ); //while( read32(GCAM_CONTROL) & 1 ) // clear32( GCAM_CONTROL, 1 ); //while( (read32(GCAM_SSTATUS) & 0x10) != 0x10 ) // set32( GCAM_SSTATUS, 0x10 ); } break; default: { dbgprintf("Unhandled cmd:%02X\n", read32(GCAM_SCMD) ); Shutdown(); } break; } //to be 100% sure we dont ever read a still cached block in ppc write32( GCAM_CONTROL, 0xdeadbeef ); sync_after_write( (void*)GCAM_BASE, 0x40 ); } }