Deadcode elimination in M6502 emulation.

A minor improvement, but every little bit counts.
This commit is contained in:
Stephen Anthony 2019-12-22 23:33:20 -03:30
parent 8bbabe3c5d
commit 5a283a0140
3 changed files with 92 additions and 44 deletions

View File

@ -328,13 +328,13 @@ inline void M6502::_execute(uInt64 cycles, DispatchResult& result)
mySystem->cart().clearAllRAMAccesses();
#endif // DEBUGGER_SUPPORT
uInt16 operandAddress = 0, intermediateAddress = 0;
uInt8 operand = 0;
// Reset the peek/poke address pointers
myLastPeekAddress = myLastPokeAddress = myDataAddressForPoke = 0;
try {
uInt16 operandAddress = 0, intermediateAddress = 0;
uInt8 operand = 0;
icycles = 0;
#ifdef DEBUGGER_SUPPORT
uInt16 oldPC = PC;

View File

@ -255,6 +255,16 @@
@ -425,7 +435,7 @@ case 0x7d:
intermediateAddress = high | uInt8(low + X);
if((low + X) > 0xFF)
{
operand = peek(intermediateAddress, DISASM_NONE);
peek(intermediateAddress, DISASM_NONE);
intermediateAddress = (high | low) + X;
operand = peek(intermediateAddress, DISASM_DATA);
}
@ -473,7 +483,7 @@ case 0x79:
intermediateAddress = high | uInt8(low + Y);
if((low + Y) > 0xFF)
{
operand = peek(intermediateAddress, DISASM_NONE);
peek(intermediateAddress, DISASM_NONE);
intermediateAddress = (high | low) + Y;
operand = peek(intermediateAddress, DISASM_DATA);
}
@ -563,7 +573,7 @@ case 0x71:
intermediateAddress = high | uInt8(low + Y);
if((low + Y) > 0xFF)
{
operand = peek(intermediateAddress, DISASM_NONE);
peek(intermediateAddress, DISASM_NONE);
intermediateAddress = (high | low) + Y;
operand = peek(intermediateAddress, DISASM_DATA);
}
@ -697,7 +707,7 @@ case 0x3d:
intermediateAddress = high | uInt8(low + X);
if((low + X) > 0xFF)
{
operand = peek(intermediateAddress, DISASM_NONE);
peek(intermediateAddress, DISASM_NONE);
intermediateAddress = (high | low) + X;
operand = peek(intermediateAddress, DISASM_DATA);
}
@ -720,7 +730,7 @@ case 0x39:
intermediateAddress = high | uInt8(low + Y);
if((low + Y) > 0xFF)
{
operand = peek(intermediateAddress, DISASM_NONE);
peek(intermediateAddress, DISASM_NONE);
intermediateAddress = (high | low) + Y;
operand = peek(intermediateAddress, DISASM_DATA);
}
@ -760,7 +770,7 @@ case 0x31:
intermediateAddress = high | uInt8(low + Y);
if((low + Y) > 0xFF)
{
operand = peek(intermediateAddress, DISASM_NONE);
peek(intermediateAddress, DISASM_NONE);
intermediateAddress = (high | low) + Y;
operand = peek(intermediateAddress, DISASM_DATA);
}
@ -1229,7 +1239,7 @@ case 0xdd:
intermediateAddress = high | uInt8(low + X);
if((low + X) > 0xFF)
{
operand = peek(intermediateAddress, DISASM_NONE);
peek(intermediateAddress, DISASM_NONE);
intermediateAddress = (high | low) + X;
operand = peek(intermediateAddress, DISASM_DATA);
}
@ -1254,7 +1264,7 @@ case 0xd9:
intermediateAddress = high | uInt8(low + Y);
if((low + Y) > 0xFF)
{
operand = peek(intermediateAddress, DISASM_NONE);
peek(intermediateAddress, DISASM_NONE);
intermediateAddress = (high | low) + Y;
operand = peek(intermediateAddress, DISASM_DATA);
}
@ -1298,7 +1308,7 @@ case 0xd1:
intermediateAddress = high | uInt8(low + Y);
if((low + Y) > 0xFF)
{
operand = peek(intermediateAddress, DISASM_NONE);
peek(intermediateAddress, DISASM_NONE);
intermediateAddress = (high | low) + Y;
operand = peek(intermediateAddress, DISASM_DATA);
}
@ -1697,7 +1707,7 @@ case 0x5d:
intermediateAddress = high | uInt8(low + X);
if((low + X) > 0xFF)
{
operand = peek(intermediateAddress, DISASM_NONE);
peek(intermediateAddress, DISASM_NONE);
intermediateAddress = (high | low) + X;
operand = peek(intermediateAddress, DISASM_DATA);
}
@ -1720,7 +1730,7 @@ case 0x59:
intermediateAddress = high | uInt8(low + Y);
if((low + Y) > 0xFF)
{
operand = peek(intermediateAddress, DISASM_NONE);
peek(intermediateAddress, DISASM_NONE);
intermediateAddress = (high | low) + Y;
operand = peek(intermediateAddress, DISASM_DATA);
}
@ -1760,7 +1770,7 @@ case 0x51:
intermediateAddress = high | uInt8(low + Y);
if((low + Y) > 0xFF)
{
operand = peek(intermediateAddress, DISASM_NONE);
peek(intermediateAddress, DISASM_NONE);
intermediateAddress = (high | low) + Y;
operand = peek(intermediateAddress, DISASM_DATA);
}
@ -2209,7 +2219,7 @@ case 0xbb:
intermediateAddress = high | uInt8(low + Y);
if((low + Y) > 0xFF)
{
operand = peek(intermediateAddress, DISASM_NONE);
peek(intermediateAddress, DISASM_NONE);
intermediateAddress = (high | low) + Y;
operand = peek(intermediateAddress, DISASM_DATA);
}
@ -2251,7 +2261,7 @@ case 0xbf:
intermediateAddress = high | uInt8(low + Y);
if((low + Y) > 0xFF)
{
operand = peek(intermediateAddress, DISASM_NONE);
peek(intermediateAddress, DISASM_NONE);
intermediateAddress = (high | low) + Y;
operand = peek(intermediateAddress, DISASM_DATA);
}
@ -2329,7 +2339,7 @@ case 0xb3:
intermediateAddress = high | uInt8(low + Y);
if((low + Y) > 0xFF)
{
operand = peek(intermediateAddress, DISASM_NONE);
peek(intermediateAddress, DISASM_NONE);
intermediateAddress = (high | low) + Y;
operand = peek(intermediateAddress, DISASM_DATA);
}
@ -2413,7 +2423,7 @@ case 0xbd:
intermediateAddress = high | uInt8(low + X);
if((low + X) > 0xFF)
{
operand = peek(intermediateAddress, DISASM_NONE);
peek(intermediateAddress, DISASM_NONE);
intermediateAddress = (high | low) + X;
operand = peek(intermediateAddress, DISASM_DATA);
}
@ -2437,7 +2447,7 @@ case 0xb9:
intermediateAddress = high | uInt8(low + Y);
if((low + Y) > 0xFF)
{
operand = peek(intermediateAddress, DISASM_NONE);
peek(intermediateAddress, DISASM_NONE);
intermediateAddress = (high | low) + Y;
operand = peek(intermediateAddress, DISASM_DATA);
}
@ -2479,7 +2489,7 @@ case 0xb1:
intermediateAddress = high | uInt8(low + Y);
if((low + Y) > 0xFF)
{
operand = peek(intermediateAddress, DISASM_NONE);
peek(intermediateAddress, DISASM_NONE);
intermediateAddress = (high | low) + Y;
operand = peek(intermediateAddress, DISASM_DATA);
}
@ -2561,7 +2571,7 @@ case 0xbe:
intermediateAddress = high | uInt8(low + Y);
if((low + Y) > 0xFF)
{
operand = peek(intermediateAddress, DISASM_NONE);
peek(intermediateAddress, DISASM_NONE);
intermediateAddress = (high | low) + Y;
operand = peek(intermediateAddress, DISASM_DATA);
}
@ -2643,7 +2653,7 @@ case 0xbc:
intermediateAddress = high | uInt8(low + X);
if((low + X) > 0xFF)
{
operand = peek(intermediateAddress, DISASM_NONE);
peek(intermediateAddress, DISASM_NONE);
intermediateAddress = (high | low) + X;
operand = peek(intermediateAddress, DISASM_DATA);
}
@ -2795,7 +2805,7 @@ case 0x89:
case 0xc2:
case 0xe2:
{
operand = peek(PC++, DISASM_CODE);
peek(PC++, DISASM_CODE);
}
{
}
@ -2806,7 +2816,7 @@ case 0x44:
case 0x64:
{
intermediateAddress = peek(PC++, DISASM_CODE);
operand = peek(intermediateAddress, DISASM_DATA);
peek(intermediateAddress, DISASM_DATA);
}
{
}
@ -2822,7 +2832,7 @@ case 0xf4:
intermediateAddress = peek(PC++, DISASM_CODE);
peek(intermediateAddress, DISASM_NONE);
intermediateAddress += X;
operand = peek(intermediateAddress, DISASM_DATA);
peek(intermediateAddress, DISASM_DATA);
}
{
}
@ -2832,7 +2842,7 @@ case 0x0c:
{
intermediateAddress = peek(PC++, DISASM_CODE);
intermediateAddress |= (uInt16(peek(PC++, DISASM_CODE)) << 8);
operand = peek(intermediateAddress, DISASM_DATA);
peek(intermediateAddress, DISASM_DATA);
}
{
}
@ -2850,13 +2860,13 @@ case 0xfc:
intermediateAddress = high | uInt8(low + X);
if((low + X) > 0xFF)
{
operand = peek(intermediateAddress, DISASM_NONE);
peek(intermediateAddress, DISASM_NONE);
intermediateAddress = (high | low) + X;
operand = peek(intermediateAddress, DISASM_DATA);
peek(intermediateAddress, DISASM_DATA);
}
else
{
operand = peek(intermediateAddress, DISASM_DATA);
peek(intermediateAddress, DISASM_DATA);
}
}
{
@ -2927,7 +2937,7 @@ case 0x1d:
intermediateAddress = high | uInt8(low + X);
if((low + X) > 0xFF)
{
operand = peek(intermediateAddress, DISASM_NONE);
peek(intermediateAddress, DISASM_NONE);
intermediateAddress = (high | low) + X;
operand = peek(intermediateAddress, DISASM_DATA);
}
@ -2951,7 +2961,7 @@ case 0x19:
intermediateAddress = high | uInt8(low + Y);
if((low + Y) > 0xFF)
{
operand = peek(intermediateAddress, DISASM_NONE);
peek(intermediateAddress, DISASM_NONE);
intermediateAddress = (high | low) + Y;
operand = peek(intermediateAddress, DISASM_DATA);
}
@ -2993,7 +3003,7 @@ case 0x11:
intermediateAddress = high | uInt8(low + Y);
if((low + Y) > 0xFF)
{
operand = peek(intermediateAddress, DISASM_NONE);
peek(intermediateAddress, DISASM_NONE);
intermediateAddress = (high | low) + Y;
operand = peek(intermediateAddress, DISASM_DATA);
}
@ -3973,7 +3983,7 @@ case 0xfd:
intermediateAddress = high | uInt8(low + X);
if((low + X) > 0xFF)
{
operand = peek(intermediateAddress, DISASM_NONE);
peek(intermediateAddress, DISASM_NONE);
intermediateAddress = (high | low) + X;
operand = peek(intermediateAddress, DISASM_DATA);
}
@ -4018,7 +4028,7 @@ case 0xf9:
intermediateAddress = high | uInt8(low + Y);
if((low + Y) > 0xFF)
{
operand = peek(intermediateAddress, DISASM_NONE);
peek(intermediateAddress, DISASM_NONE);
intermediateAddress = (high | low) + Y;
operand = peek(intermediateAddress, DISASM_DATA);
}
@ -4102,7 +4112,7 @@ case 0xf1:
intermediateAddress = high | uInt8(low + Y);
if((low + Y) > 0xFF)
{
operand = peek(intermediateAddress, DISASM_NONE);
peek(intermediateAddress, DISASM_NONE);
intermediateAddress = (high | low) + Y;
operand = peek(intermediateAddress, DISASM_DATA);
}

View File

@ -61,12 +61,22 @@ define(M6502_IMMEDIATE_READ, `{
operand = peek(PC++, DISASM_CODE);
}')
define(M6502_IMMEDIATE_READ_DISCARD_OPERAND, `{
peek(PC++, DISASM_CODE);
}')
define(M6502_ABSOLUTE_READ, `{
intermediateAddress = peek(PC++, DISASM_CODE);
intermediateAddress |= (uInt16(peek(PC++, DISASM_CODE)) << 8);
operand = peek(intermediateAddress, DISASM_DATA);
}')
define(M6502_ABSOLUTE_READ_DISCARD_OPERAND, `{
intermediateAddress = peek(PC++, DISASM_CODE);
intermediateAddress |= (uInt16(peek(PC++, DISASM_CODE)) << 8);
peek(intermediateAddress, DISASM_DATA);
}')
define(M6502_ABSOLUTE_WRITE, `{
operandAddress = peek(PC++, DISASM_CODE);
operandAddress |= (uInt16(peek(PC++, DISASM_CODE)) << 8);
@ -85,7 +95,7 @@ define(M6502_ABSOLUTEX_READ, `{
intermediateAddress = high | uInt8(low + X);
if((low + X) > 0xFF)
{
operand = peek(intermediateAddress, DISASM_NONE);
peek(intermediateAddress, DISASM_NONE);
intermediateAddress = (high | low) + X;
operand = peek(intermediateAddress, DISASM_DATA);
}
@ -95,6 +105,22 @@ define(M6502_ABSOLUTEX_READ, `{
}
}')
define(M6502_ABSOLUTEX_READ_DISCARD_OPERAND, `{
uInt16 low = peek(PC++, DISASM_CODE);
uInt16 high = (uInt16(peek(PC++, DISASM_CODE)) << 8);
intermediateAddress = high | uInt8(low + X);
if((low + X) > 0xFF)
{
peek(intermediateAddress, DISASM_NONE);
intermediateAddress = (high | low) + X;
peek(intermediateAddress, DISASM_DATA);
}
else
{
peek(intermediateAddress, DISASM_DATA);
}
}')
define(M6502_ABSOLUTEX_WRITE, `{
uInt16 low = peek(PC++, DISASM_CODE);
uInt16 high = (uInt16(peek(PC++, DISASM_CODE)) << 8);
@ -117,7 +143,7 @@ define(M6502_ABSOLUTEY_READ, `{
intermediateAddress = high | uInt8(low + Y);
if((low + Y) > 0xFF)
{
operand = peek(intermediateAddress, DISASM_NONE);
peek(intermediateAddress, DISASM_NONE);
intermediateAddress = (high | low) + Y;
operand = peek(intermediateAddress, DISASM_DATA);
}
@ -148,6 +174,11 @@ define(M6502_ZERO_READ, `{
operand = peek(intermediateAddress, DISASM_DATA);
}')
define(M6502_ZERO_READ_DISCARD_OPERAND, `{
intermediateAddress = peek(PC++, DISASM_CODE);
peek(intermediateAddress, DISASM_DATA);
}')
define(M6502_ZERO_WRITE, `{
operandAddress = peek(PC++, DISASM_CODE);
}')
@ -165,6 +196,13 @@ define(M6502_ZEROX_READ, `{
operand = peek(intermediateAddress, DISASM_DATA);
}')
define(M6502_ZEROX_READ_DISCARD_OPERAND, `{
intermediateAddress = peek(PC++, DISASM_CODE);
peek(intermediateAddress, DISASM_NONE);
intermediateAddress += X;
peek(intermediateAddress, DISASM_DATA);
}')
define(M6502_ZEROX_WRITE, `{
operandAddress = peek(PC++, DISASM_CODE);
peek(operandAddress, DISASM_NONE);
@ -245,7 +283,7 @@ define(M6502_INDIRECTY_READ, `{
intermediateAddress = high | uInt8(low + Y);
if((low + Y) > 0xFF)
{
operand = peek(intermediateAddress, DISASM_NONE);
peek(intermediateAddress, DISASM_NONE);
intermediateAddress = (high | low) + Y;
operand = peek(intermediateAddress, DISASM_DATA);
}
@ -1750,14 +1788,14 @@ case 0x82:
case 0x89:
case 0xc2:
case 0xe2:
M6502_IMMEDIATE_READ
M6502_IMMEDIATE_READ_DISCARD_OPERAND
M6502_NOP
break;
case 0x04:
case 0x44:
case 0x64:
M6502_ZERO_READ
M6502_ZERO_READ_DISCARD_OPERAND
M6502_NOP
break;
@ -1767,12 +1805,12 @@ case 0x54:
case 0x74:
case 0xd4:
case 0xf4:
M6502_ZEROX_READ
M6502_ZEROX_READ_DISCARD_OPERAND
M6502_NOP
break;
case 0x0c:
M6502_ABSOLUTE_READ
M6502_ABSOLUTE_READ_DISCARD_OPERAND
M6502_NOP
break;
@ -1782,7 +1820,7 @@ case 0x5c:
case 0x7c:
case 0xdc:
case 0xfc:
M6502_ABSOLUTEX_READ
M6502_ABSOLUTEX_READ_DISCARD_OPERAND
M6502_NOP
break;