1
0
mirror of https://github.com/TASVideos/desmume synced 2024-07-08 20:06:04 +00:00

Cocoa Port: Standardize all Internal cheat direct memory writes (clicking the 'Write Once' button) to write to NDS memory before NDS_exec() is called.

This commit is contained in:
rogerman 2023-07-08 20:28:01 -07:00
parent f240472f5e
commit 0fc3306bfc
4 changed files with 60 additions and 43 deletions

View File

@ -78,6 +78,14 @@ typedef union DesmumeCheatSearchItem DesmumeCheatSearchItem;
typedef std::vector<DesmumeCheatSearchItem> DesmumeCheatSearchResultsList;
struct InternalCheatParam
{
uint32_t address;
uint32_t value;
uint8_t valueLength;
};
typedef struct InternalCheatParam InternalCheatParam;
class ClientCheatItem
{
protected:
@ -242,6 +250,8 @@ protected:
uint32_t _untitledCount;
std::string _currentSessionLastFilePath;
std::vector<InternalCheatParam> _pendingInternalCheatWriteList;
bool _masterNeedsUpdate;
public:
@ -289,9 +299,10 @@ public:
const DesmumeCheatSearchResultsList& GetSearchResults();
size_t GetSearchResultCount() const;
void ApplyInternalCheatAtIndex(size_t index);
static void ApplyInternalCheatWithItem(const ClientCheatItem *cheatItem);
static void ApplyInternalCheatWithParams(uint32_t targetAddress, uint32_t newValue, size_t newValueLength);
void DirectWriteInternalCheatAtIndex(size_t index);
void DirectWriteInternalCheatItem(const ClientCheatItem *cheatItem);
void DirectWriteInternalCheat(uint32_t targetAddress, uint32_t newValue32, size_t newValueLength);
void ApplyPendingInternalCheatWrites();
};
@interface CocoaDSCheatItem : NSObject
@ -374,11 +385,11 @@ public:
- (void) removeAtIndex:(NSUInteger)itemIndex;
- (BOOL) update:(CocoaDSCheatItem *)cocoaCheatItem;
- (BOOL) save;
- (void) applyInternalCheat:(CocoaDSCheatItem *)cocoaCheatItem;
- (void) directWriteInternalCheat:(CocoaDSCheatItem *)cocoaCheatItem;
- (void) loadFromMaster;
- (void) applyToMaster;
- (NSMutableArray *) cheatListFromDatabase:(NSURL *)fileURL errorCode:(NSInteger *)error;
- (NSMutableArray *) databaseListLoadFromFile:(NSURL *)fileURL errorCode:(NSInteger *)error;
- (NSUInteger) databaseAddSelected;
- (NSUInteger) runExactValueSearch:(NSInteger)value byteSize:(UInt8)byteSize signType:(NSInteger)signType;

View File

@ -1139,6 +1139,7 @@ ClientCheatManager::ClientCheatManager()
_currentSessionList = new ClientCheatList;
_currentDatabase = new ClientCheatDatabase;
_currentSearcher = new ClientCheatSearcher;
_pendingInternalCheatWriteList.resize(0);
_selectedItem = NULL;
_selectedItemIndex = 0;
@ -1446,57 +1447,61 @@ size_t ClientCheatManager::GetSearchResultCount() const
return this->_currentSearcher->GetResultCount();
}
void ClientCheatManager::ApplyInternalCheatAtIndex(size_t index)
void ClientCheatManager::DirectWriteInternalCheatAtIndex(size_t index)
{
ClientCheatManager::ApplyInternalCheatWithItem( this->_currentSessionList->GetItemAtIndex(index) );
this->DirectWriteInternalCheatItem( this->_currentSessionList->GetItemAtIndex(index) );
}
void ClientCheatManager::ApplyInternalCheatWithItem(const ClientCheatItem *cheatItem)
void ClientCheatManager::DirectWriteInternalCheatItem(const ClientCheatItem *cheatItem)
{
if ( (cheatItem == NULL) || (cheatItem->GetType() != CheatType_Internal) )
{
return;
}
ClientCheatManager::ApplyInternalCheatWithParams( cheatItem->GetAddress(), cheatItem->GetValue(), cheatItem->GetValueLength() );
this->DirectWriteInternalCheat( cheatItem->GetAddress(), cheatItem->GetValue(), cheatItem->GetValueLength() );
}
void ClientCheatManager::ApplyInternalCheatWithParams(uint32_t targetAddress, uint32_t newValue, size_t newValueLength)
void ClientCheatManager::DirectWriteInternalCheat(uint32_t targetAddress, uint32_t newValue32, size_t newValueLength)
{
targetAddress &= 0x00FFFFFF;
targetAddress |= 0x02000000;
switch (newValueLength)
InternalCheatParam cheatWrite;
cheatWrite.address = targetAddress;
cheatWrite.value = newValue32;
cheatWrite.valueLength = newValueLength;
this->_pendingInternalCheatWriteList.push_back(cheatWrite);
}
void ClientCheatManager::ApplyPendingInternalCheatWrites()
{
bool needsJitReset = false;
const size_t writeListSize = this->_pendingInternalCheatWriteList.size();
if (writeListSize == 0)
{
case 1:
return;
}
for (size_t i = 0; i < writeListSize; i++)
{
const InternalCheatParam cheatWrite = this->_pendingInternalCheatWriteList[i];
const bool shouldResetJit = CHEATS::DirectWrite(cheatWrite.valueLength, ARMCPU_ARM9, cheatWrite.address, cheatWrite.value);
if (shouldResetJit)
{
u8 oneByteValue = (u8)(newValue & 0x000000FF);
_MMU_write08<ARMCPU_ARM9,MMU_AT_DEBUG>(targetAddress, oneByteValue);
break;
needsJitReset = true;
}
case 2:
{
u16 twoByteValue = (u16)(newValue & 0x0000FFFF);
_MMU_write16<ARMCPU_ARM9,MMU_AT_DEBUG>(targetAddress, twoByteValue);
break;
}
case 3:
{
u32 threeByteWithExtraValue = _MMU_read32<ARMCPU_ARM9,MMU_AT_DEBUG>(targetAddress);
threeByteWithExtraValue &= 0xFF000000;
threeByteWithExtraValue |= (newValue & 0x00FFFFFF);
_MMU_write32<ARMCPU_ARM9,MMU_AT_DEBUG>(targetAddress, threeByteWithExtraValue);
break;
}
case 4:
_MMU_write32<ARMCPU_ARM9,MMU_AT_DEBUG>(targetAddress, newValue);
break;
default:
break;
}
this->_pendingInternalCheatWriteList.clear();
if (needsJitReset)
{
CHEATS::JitNeedsReset();
CHEATS::ResetJitIfNeeded();
}
}
@ -2201,14 +2206,14 @@ static NSImage *iconCodeBreaker = nil;
return (error == CheatSystemError_NoError) ? YES : NO;
}
- (void) applyInternalCheat:(CocoaDSCheatItem *)cocoaCheatItem
- (void) directWriteInternalCheat:(CocoaDSCheatItem *)cocoaCheatItem
{
if (cocoaCheatItem == nil)
{
return;
}
ClientCheatManager::ApplyInternalCheatWithItem([cocoaCheatItem clientData]);
_internalCheatManager->DirectWriteInternalCheatItem([cocoaCheatItem clientData]);
}
- (void) loadFromMaster
@ -2244,7 +2249,7 @@ static NSImage *iconCodeBreaker = nil;
_internalCheatManager->ApplyToMaster();
}
- (NSMutableArray *) cheatListFromDatabase:(NSURL *)fileURL errorCode:(NSInteger *)error
- (NSMutableArray *) databaseListLoadFromFile:(NSURL *)fileURL errorCode:(NSInteger *)error
{
if (fileURL == nil)
{

View File

@ -1234,6 +1234,7 @@ static void* RunCoreThread(void *arg)
// Execute the frame and increment the frame counter.
pthread_rwlock_wrlock(&param->rwlockCoreExecute);
cheatManager->ApplyToMaster();
cheatManager->ApplyPendingInternalCheatWrites();
NDS_exec<false>();
SPU_Emulate_user();
execControl->FetchOutputPostNDSExec();

View File

@ -234,7 +234,7 @@
// Force end of editing of any text fields.
[window makeFirstResponder:nil];
[[self cdsCheats] applyInternalCheat:[self workingCheat]];
[[self cdsCheats] directWriteInternalCheat:[self workingCheat]];
}
- (IBAction) applyConfiguration:(id)sender
@ -431,7 +431,7 @@
}
NSInteger error = 0;
NSMutableArray *dbList = [cheatManager cheatListFromDatabase:fileURL errorCode:&error];
NSMutableArray *dbList = [cheatManager databaseListLoadFromFile:fileURL errorCode:&error];
if (dbList != nil)
{
[cheatDatabaseController setContent:dbList];