mirror of
https://github.com/AppleWin/AppleWin.git
synced 2024-12-26 20:30:16 +00:00
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:
parent
f035a53374
commit
29c02d6bf2
@ -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." ) );
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user