Gh1267 update paging (#1326)

MemGetBankPtr(): simplify with a default arg. (#1262, PR #1326)
. UpdatePaging(): improve comment for page0 & page1 and memdirty
This commit is contained in:
TomCh 2024-08-24 20:18:28 +01:00 committed by GitHub
parent f035a53374
commit 29c02d6bf2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 25 additions and 22 deletions

View File

@ -4493,7 +4493,7 @@ Update_t CmdMemoryLoad (int nArgs)
}
const std::string sLoadSaveFilePath = g_sCurrentDir + g_sMemoryLoadSaveFileName; // TODO: g_sDebugDir
BYTE * const pMemBankBase = bBankSpecified ? MemGetBankPtr(nBank, true) : mem;
BYTE * const pMemBankBase = bBankSpecified ? MemGetBankPtr(nBank) : mem;
if (!pMemBankBase)
{
ConsoleBufferPush( TEXT( "Error: Bank out of range." ) );
@ -4832,7 +4832,7 @@ Update_t CmdMemorySave (int nArgs)
}
sLoadSaveFilePath += g_sMemoryLoadSaveFileName;
const BYTE * const pMemBankBase = bBankSpecified ? MemGetBankPtr(nBank, true) : mem;
const BYTE * const pMemBankBase = bBankSpecified ? MemGetBankPtr(nBank) : mem;
if (!pMemBankBase)
{
ConsoleBufferPush( TEXT( "Error: Bank out of range." ) );

View File

@ -1269,8 +1269,11 @@ static void UpdatePaging(BOOL initialize)
// PAGING SHADOW TABLE
//
// NB. the condition 'loop <= 1' is there because:
// . Page0 (ZP) : memdirty[0] is set when the 6502 CPU does a ZP-write, but perhaps older versions didn't set this flag (eg. the asm version?).
// . Page1 (stack) : memdirty[1] is NOT set when the 6502 CPU writes to this page with JSR, etc.
// . Page0 (ZP) and Page1 (stack) are written to so often that it's almost certain that they'll be dirty every time this function is called.
// Note also that:
// . Page0 (ZP) : memdirty[0] is set when the 6502 CPU writes to ZP.
// . Page1 (stack) : memdirty[1] is NOT set when the 6502 CPU writes to this page with JSR, PHA, etc.
// Ultimately this is an optimisation (due to Page1 writes not setting memdirty[1]) and Page0 could be optimised to also not set memdirty[0].
for (loop = 0x00; loop < 0x100; loop++)
{
@ -1347,19 +1350,6 @@ bool MemCheckINTCXROM()
//===========================================================================
static void BackMainImage(void)
{
for (UINT loop = 0; loop < 256; loop++)
{
if (memshadow[loop] && ((*(memdirty+loop) & 1) || (loop <= 1)))
memcpy(memshadow[loop], mem+(loop << 8), 256);
*(memdirty+loop) &= ~1;
}
}
//===========================================================================
static LPBYTE MemGetPtrBANK1(const WORD offset, const LPBYTE pMemBase)
{
if ((offset & 0xF000) != 0xC000) // Requesting RAM at physical addr $Cxxx (ie. 4K RAM BANK1)
@ -1445,14 +1435,27 @@ LPBYTE MemGetMainPtr(const WORD offset)
//===========================================================================
static void BackMainImage(void)
{
for (UINT loop = 0; loop < 256; loop++)
{
if (memshadow[loop] && ((*(memdirty + loop) & 1) || (loop <= 1)))
memcpy(memshadow[loop], mem + (loop << 8), 256);
*(memdirty + loop) &= ~1;
}
}
//-------------------------------------
// Used by:
// . Savestate: MemSaveSnapshotMemory(), MemLoadSnapshotAux()
// . VidHD : SaveSnapshot(), LoadSnapshot()
// . Debugger : CmdMemorySave(), CmdMemoryLoad()
LPBYTE MemGetBankPtr(const UINT nBank, const bool isSaveSnapshotOrDebugging)
LPBYTE MemGetBankPtr(const UINT nBank, const bool isSaveSnapshotOrDebugging/*=true*/)
{
// Only call BackMainImage() when a consistent 64K bank is needed, eg. for saving snapshot or debugging
// - for snapshot loads it's pointless, and worse it can corrupt pages 0 & 1 for aux banks (GH#1262)
// - for snapshot *loads* it's redundant, and worse it can corrupt pages 0 & 1 for aux banks, so must be avoided (GH#1262)
if (isSaveSnapshotOrDebugging)
BackMainImage(); // Flush any dirty pages to back-buffer
@ -2412,7 +2415,7 @@ static const std::string& MemGetSnapshotAuxMemStructName(void)
static void MemSaveSnapshotMemory(YamlSaveHelper& yamlSaveHelper, bool bIsMainMem, UINT bank=0, UINT size=64*1024)
{
LPBYTE pMemBase = MemGetBankPtr(bank, true);
LPBYTE pMemBase = MemGetBankPtr(bank);
if (bIsMainMem)
{

View File

@ -57,7 +57,7 @@ bool MemCheckSLOTC3ROM();
bool MemCheckINTCXROM();
LPBYTE MemGetAuxPtr(const WORD);
LPBYTE MemGetMainPtr(const WORD);
LPBYTE MemGetBankPtr(const UINT nBank, const bool isSaveSnapshotOrDebugging);
LPBYTE MemGetBankPtr(const UINT nBank, const bool isSaveSnapshotOrDebugging = true);
LPBYTE MemGetCxRomPeripheral();
DWORD GetMemMode(void);
void SetMemMode(DWORD memmode);

View File

@ -210,7 +210,7 @@ void VidHDCard::SaveSnapshot(YamlSaveHelper& yamlSaveHelper)
// Save [$400-$9FFF]
YamlSaveHelper::Label state(yamlSaveHelper, "%s:\n", MemGetSnapshotAuxMemStructName().c_str());
LPBYTE pMemBase = MemGetBankPtr(1, true);
LPBYTE pMemBase = MemGetBankPtr(1);
yamlSaveHelper.SaveMemory(pMemBase, (SHR_MEMORY_END + 1) - TEXT_PAGE1_BEGIN, TEXT_PAGE1_BEGIN);
}
}