mirror of
https://github.com/AppleWin/AppleWin.git
synced 2025-01-09 05:32:05 +00:00
Refactor: consolidate 'modechanging' optimisations into a single function
This commit is contained in:
parent
42c58f54e7
commit
6fb5b3b0e8
@ -85,22 +85,8 @@ BYTE __stdcall LanguageCardUnit::IO(WORD PC, WORD uAddr, BYTE bWrite, BYTE uValu
|
||||
|
||||
//
|
||||
|
||||
if (IS_APPLE2E)
|
||||
{
|
||||
// IF THE EMULATED PROGRAM HAS JUST UPDATED THE MEMORY WRITE MODE AND IS
|
||||
// ABOUT TO UPDATE THE MEMORY READ MODE, HOLD OFF ON ANY PROCESSING UNTIL
|
||||
// IT DOES SO.
|
||||
//
|
||||
// NB. A 6502 interrupt occurring between these memory write & read updates could lead to incorrect behaviour.
|
||||
// - although any data-race is probably a bug in the 6502 code too.
|
||||
if ((PC < 0xC000) &&
|
||||
(((*(LPDWORD)(mem+PC) & 0x00FFFEFF) == 0x00C0048D) || // Next: STA $C004 or STA $C005
|
||||
((*(LPDWORD)(mem+PC) & 0x00FFFEFF) == 0x00C0028D))) // Next: STA $C002 or STA $C003
|
||||
{
|
||||
SetModeChanging(1);
|
||||
return bWrite ? 0 : MemReadFloatingBus(nExecutedCycles);
|
||||
}
|
||||
}
|
||||
if (MemOptimizeForModeChanging(PC, uAddr))
|
||||
return bWrite ? 0 : MemReadFloatingBus(nExecutedCycles);
|
||||
|
||||
// IF THE MEMORY PAGING MODE HAS CHANGED, UPDATE OUR MEMORY IMAGES AND
|
||||
// WRITE TABLES.
|
||||
|
@ -972,11 +972,6 @@ static bool IsCardInSlot(const UINT uSlot)
|
||||
|
||||
//===========================================================================
|
||||
|
||||
void SetModeChanging(BOOL value)
|
||||
{
|
||||
modechanging = value;
|
||||
}
|
||||
|
||||
DWORD GetMemMode(void)
|
||||
{
|
||||
return memmode;
|
||||
@ -1953,21 +1948,8 @@ BYTE __stdcall MemSetPaging(WORD programcounter, WORD address, BYTE write, BYTE
|
||||
}
|
||||
}
|
||||
|
||||
if (IS_APPLE2E)
|
||||
{
|
||||
// IF THE EMULATED PROGRAM HAS JUST UPDATED THE MEMORY WRITE MODE AND IS
|
||||
// ABOUT TO UPDATE THE MEMORY READ MODE, HOLD OFF ON ANY PROCESSING UNTIL
|
||||
// IT DOES SO.
|
||||
//
|
||||
// NB. A 6502 interrupt occurring between these memory write & read updates could lead to incorrect behaviour.
|
||||
// - although any data-race is probably a bug in the 6502 code too.
|
||||
if ((address >= 4) && (address <= 5) &&
|
||||
((*(LPDWORD)(mem+programcounter) & 0x00FFFEFF) == 0x00C0028D)) // Next: STA $C002 or STA $C003
|
||||
{
|
||||
modechanging = 1;
|
||||
return 0; // For $C004 & $C005: entry to this func is always via a write to $C004 or $C005
|
||||
}
|
||||
}
|
||||
if (MemOptimizeForModeChanging(programcounter, address))
|
||||
return write ? 0 : MemReadFloatingBus(nExecutedCycles);
|
||||
|
||||
// IF THE MEMORY PAGING MODE HAS CHANGED, UPDATE OUR MEMORY IMAGES AND
|
||||
// WRITE TABLES.
|
||||
@ -2012,6 +1994,37 @@ BYTE __stdcall MemSetPaging(WORD programcounter, WORD address, BYTE write, BYTE
|
||||
|
||||
//===========================================================================
|
||||
|
||||
bool MemOptimizeForModeChanging(WORD programcounter, WORD address)
|
||||
{
|
||||
if (IS_APPLE2E)
|
||||
{
|
||||
// IF THE EMULATED PROGRAM HAS JUST UPDATED THE MEMORY WRITE MODE AND IS
|
||||
// ABOUT TO UPDATE THE MEMORY READ MODE, HOLD OFF ON ANY PROCESSING UNTIL
|
||||
// IT DOES SO.
|
||||
//
|
||||
// NB. A 6502 interrupt occurring between these memory write & read updates could lead to incorrect behaviour.
|
||||
// - although any data-race is probably a bug in the 6502 code too.
|
||||
if ((address >= 4) && (address <= 5) && // Now: RAMWRTOFF or RAMWRTON
|
||||
((*(LPDWORD)(mem+programcounter) & 0x00FFFEFF) == 0x00C0028D)) // Next: STA $C002(RAMRDOFF) or STA $C003(RAMRDON)
|
||||
{
|
||||
modechanging = 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((address >= 0x80) && (address <= 0x8F) && (programcounter < 0xC000) && // Now: LC
|
||||
(((*(LPDWORD)(mem+programcounter) & 0x00FFFEFF) == 0x00C0048D) || // Next: STA $C004(RAMWRTOFF) or STA $C005(RAMWRTON)
|
||||
((*(LPDWORD)(mem+programcounter) & 0x00FFFEFF) == 0x00C0028D))) // or STA $C002(RAMRDOFF) or STA $C003(RAMRDON)
|
||||
{
|
||||
modechanging = 1;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
|
||||
LPVOID MemGetSlotParameters(UINT uSlot)
|
||||
{
|
||||
_ASSERT(uSlot < NUM_SLOTS);
|
||||
|
@ -66,7 +66,7 @@ LPBYTE MemGetBankPtr(const UINT nBank);
|
||||
LPBYTE MemGetCxRomPeripheral();
|
||||
DWORD GetMemMode(void);
|
||||
void SetMemMode(DWORD memmode);
|
||||
void SetModeChanging(BOOL value);
|
||||
bool MemOptimizeForModeChanging(WORD programcounter, WORD address);
|
||||
bool MemIsAddrCodeMemory(const USHORT addr);
|
||||
void MemInitialize ();
|
||||
void MemInitializeROM(void);
|
||||
|
Loading…
Reference in New Issue
Block a user