Some performance improvements. Probably not noticable on current

systems, but seems to improve issues on slower computers.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@2745 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2013-05-30 16:07:19 +00:00
parent 3eddecdd01
commit 4c6667f64d
6 changed files with 81 additions and 125 deletions

View File

@ -29,24 +29,25 @@
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CpuDebug::CpuDebug(Debugger& dbg, Console& console) CpuDebug::CpuDebug(Debugger& dbg, Console& console)
: DebuggerSystem(dbg, console) : DebuggerSystem(dbg, console),
my6502(mySystem.m6502())
{ {
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const DebuggerState& CpuDebug::getState() const DebuggerState& CpuDebug::getState()
{ {
myState.PC = mySystem.m6502().PC; myState.PC = my6502.PC;
myState.SP = mySystem.m6502().SP; myState.SP = my6502.SP;
myState.PS = mySystem.m6502().PS(); myState.PS = my6502.PS();
myState.A = mySystem.m6502().A; myState.A = my6502.A;
myState.X = mySystem.m6502().X; myState.X = my6502.X;
myState.Y = mySystem.m6502().Y; myState.Y = my6502.Y;
myState.srcS = mySystem.m6502().lastSrcAddressS(); myState.srcS = my6502.lastSrcAddressS();
myState.srcA = mySystem.m6502().lastSrcAddressA(); myState.srcA = my6502.lastSrcAddressA();
myState.srcX = mySystem.m6502().lastSrcAddressX(); myState.srcX = my6502.lastSrcAddressX();
myState.srcY = mySystem.m6502().lastSrcAddressY(); myState.srcY = my6502.lastSrcAddressY();
Debugger::set_bits(myState.PS, myState.PSbits); Debugger::set_bits(myState.PS, myState.PSbits);
@ -56,17 +57,17 @@ const DebuggerState& CpuDebug::getState()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CpuDebug::saveOldState() void CpuDebug::saveOldState()
{ {
myOldState.PC = mySystem.m6502().PC; myOldState.PC = my6502.PC;
myOldState.SP = mySystem.m6502().SP; myOldState.SP = my6502.SP;
myOldState.PS = mySystem.m6502().PS(); myOldState.PS = my6502.PS();
myOldState.A = mySystem.m6502().A; myOldState.A = my6502.A;
myOldState.X = mySystem.m6502().X; myOldState.X = my6502.X;
myOldState.Y = mySystem.m6502().Y; myOldState.Y = my6502.Y;
myOldState.srcS = mySystem.m6502().lastSrcAddressS(); myOldState.srcS = my6502.lastSrcAddressS();
myOldState.srcA = mySystem.m6502().lastSrcAddressA(); myOldState.srcA = my6502.lastSrcAddressA();
myOldState.srcX = mySystem.m6502().lastSrcAddressX(); myOldState.srcX = my6502.lastSrcAddressX();
myOldState.srcY = mySystem.m6502().lastSrcAddressY(); myOldState.srcY = my6502.lastSrcAddressY();
Debugger::set_bits(myOldState.PS, myOldState.PSbits); Debugger::set_bits(myOldState.PS, myOldState.PSbits);
} }
@ -74,119 +75,119 @@ void CpuDebug::saveOldState()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CpuDebug::setPC(int pc) void CpuDebug::setPC(int pc)
{ {
mySystem.m6502().PC = pc; my6502.PC = pc;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CpuDebug::setSP(int sp) void CpuDebug::setSP(int sp)
{ {
mySystem.m6502().SP = sp; my6502.SP = sp;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CpuDebug::setPS(int ps) void CpuDebug::setPS(int ps)
{ {
mySystem.m6502().PS(ps); my6502.PS(ps);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CpuDebug::setA(int a) void CpuDebug::setA(int a)
{ {
mySystem.m6502().A = a; my6502.A = a;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CpuDebug::setX(int x) void CpuDebug::setX(int x)
{ {
mySystem.m6502().X = x; my6502.X = x;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CpuDebug::setY(int y) void CpuDebug::setY(int y)
{ {
mySystem.m6502().Y = y; my6502.Y = y;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CpuDebug::setN(bool on) void CpuDebug::setN(bool on)
{ {
setPS( Debugger::set_bit(mySystem.m6502().PS(), 7, on) ); my6502.N = on;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CpuDebug::setV(bool on) void CpuDebug::setV(bool on)
{ {
setPS( Debugger::set_bit(mySystem.m6502().PS(), 6, on) ); my6502.V = on;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CpuDebug::setB(bool on) void CpuDebug::setB(bool on)
{ {
setPS( Debugger::set_bit(mySystem.m6502().PS(), 4, on) ); // nop - B is always true
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CpuDebug::setD(bool on) void CpuDebug::setD(bool on)
{ {
setPS( Debugger::set_bit(mySystem.m6502().PS(), 3, on) ); my6502.D = on;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CpuDebug::setI(bool on) void CpuDebug::setI(bool on)
{ {
setPS( Debugger::set_bit(mySystem.m6502().PS(), 2, on) ); my6502.I = on;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CpuDebug::setZ(bool on) void CpuDebug::setZ(bool on)
{ {
setPS( Debugger::set_bit(mySystem.m6502().PS(), 1, on) ); my6502.notZ = !on;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CpuDebug::setC(bool on) void CpuDebug::setC(bool on)
{ {
setPS( Debugger::set_bit(mySystem.m6502().PS(), 0, on) ); my6502.C = on;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CpuDebug::toggleN() void CpuDebug::toggleN()
{ {
setPS( mySystem.m6502().PS() ^ 0x80 ); my6502.N = !my6502.N;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CpuDebug::toggleV() void CpuDebug::toggleV()
{ {
setPS( mySystem.m6502().PS() ^ 0x40 ); my6502.V = !my6502.V;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CpuDebug::toggleB() void CpuDebug::toggleB()
{ {
setPS( mySystem.m6502().PS() ^ 0x10 ); // nop - B is always true
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CpuDebug::toggleD() void CpuDebug::toggleD()
{ {
setPS( mySystem.m6502().PS() ^ 0x08 ); my6502.D = !my6502.D;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CpuDebug::toggleI() void CpuDebug::toggleI()
{ {
setPS( mySystem.m6502().PS() ^ 0x04 ); my6502.I = !my6502.I;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CpuDebug::toggleZ() void CpuDebug::toggleZ()
{ {
setPS( mySystem.m6502().PS() ^ 0x02 ); my6502.notZ = !my6502.notZ;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CpuDebug::toggleC() void CpuDebug::toggleC()
{ {
setPS( mySystem.m6502().PS() ^ 0x01 ); my6502.C = !my6502.C;
} }

View File

@ -94,6 +94,8 @@ class CpuDebug : public DebuggerSystem
void toggleC(); void toggleC();
private: private:
M6502& my6502;
CpuState myState; CpuState myState;
CpuState myOldState; CpuState myOldState;
}; };

View File

@ -23,8 +23,6 @@
#include "bspf.hxx" #include "bspf.hxx"
#include "StellaKeys.hxx" #include "StellaKeys.hxx"
class Event;
/** /**
@author Bradford W. Mott @author Bradford W. Mott
@version $Id$ @version $Id$

View File

@ -126,67 +126,17 @@ void M6502::reset()
myDataAddressForPoke = 0; myDataAddressForPoke = 0;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void M6502::irq()
{
myExecutionStatus |= MaskableInterruptBit;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void M6502::nmi()
{
myExecutionStatus |= NonmaskableInterruptBit;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void M6502::stop()
{
myExecutionStatus |= StopExecutionBit;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt8 M6502::PS() const
{
uInt8 ps = 0x20;
if(N)
ps |= 0x80;
if(V)
ps |= 0x40;
if(B)
ps |= 0x10;
if(D)
ps |= 0x08;
if(I)
ps |= 0x04;
if(!notZ)
ps |= 0x02;
if(C)
ps |= 0x01;
return ps;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void M6502::PS(uInt8 ps)
{
N = ps & 0x80;
V = ps & 0x40;
B = true; // B = ps & 0x10; The 6507's B flag always true
D = ps & 0x08;
I = ps & 0x04;
notZ = !(ps & 0x02);
C = ps & 0x01;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
inline uInt8 M6502::peek(uInt16 address, uInt8 flags) inline uInt8 M6502::peek(uInt16 address, uInt8 flags)
{ {
////////////////////////////////////////////////
// TODO - move this logic directly into CartAR
if(address != myLastAddress) if(address != myLastAddress)
{ {
myNumberOfDistinctAccesses++; myNumberOfDistinctAccesses++;
myLastAddress = address; myLastAddress = address;
} }
////////////////////////////////////////////////
mySystem->incrementCycles(mySystemCyclesPerProcessorCycle); mySystem->incrementCycles(mySystemCyclesPerProcessorCycle);
#ifdef DEBUGGER_SUPPORT #ifdef DEBUGGER_SUPPORT
@ -208,11 +158,14 @@ inline uInt8 M6502::peek(uInt16 address, uInt8 flags)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
inline void M6502::poke(uInt16 address, uInt8 value) inline void M6502::poke(uInt16 address, uInt8 value)
{ {
////////////////////////////////////////////////
// TODO - move this logic directly into CartAR
if(address != myLastAddress) if(address != myLastAddress)
{ {
myNumberOfDistinctAccesses++; myNumberOfDistinctAccesses++;
myLastAddress = address; myLastAddress = address;
} }
////////////////////////////////////////////////
mySystem->incrementCycles(mySystemCyclesPerProcessorCycle); mySystem->incrementCycles(mySystemCyclesPerProcessorCycle);
#ifdef DEBUGGER_SUPPORT #ifdef DEBUGGER_SUPPORT

View File

@ -87,12 +87,12 @@ class M6502 : public Serializable
/** /**
Request a maskable interrupt Request a maskable interrupt
*/ */
void irq(); void irq() { myExecutionStatus |= MaskableInterruptBit; }
/** /**
Request a non-maskable interrupt Request a non-maskable interrupt
*/ */
void nmi(); void nmi() { myExecutionStatus |= NonmaskableInterruptBit; }
/** /**
Execute instructions until the specified number of instructions Execute instructions until the specified number of instructions
@ -109,7 +109,7 @@ class M6502 : public Serializable
method while the processor is executing instructions will stop method while the processor is executing instructions will stop
execution as soon as possible. execution as soon as possible.
*/ */
void stop(); void stop() { myExecutionStatus |= StopExecutionBit; }
/** /**
Answer true iff a fatal error has occured from which the processor Answer true iff a fatal error has occured from which the processor
@ -253,14 +253,34 @@ class M6502 : public Serializable
@return The processor status register @return The processor status register
*/ */
uInt8 PS() const; uInt8 PS() const {
uInt8 ps = 0x20;
if(N) ps |= 0x80;
if(V) ps |= 0x40;
if(B) ps |= 0x10;
if(D) ps |= 0x08;
if(I) ps |= 0x04;
if(!notZ) ps |= 0x02;
if(C) ps |= 0x01;
return ps;
}
/** /**
Change the Processor Status register to correspond to the given value. Change the Processor Status register to correspond to the given value.
@param ps The value to set the processor status register to @param ps The value to set the processor status register to
*/ */
void PS(uInt8 ps); void PS(uInt8 ps) {
N = ps & 0x80;
V = ps & 0x40;
B = true; // B = ps & 0x10; The 6507's B flag always true
D = ps & 0x08;
I = ps & 0x04;
notZ = !(ps & 0x02);
C = ps & 0x01;
}
/** /**
Called after an interrupt has be requested using irq() or nmi() Called after an interrupt has be requested using irq() or nmi()

View File

@ -115,10 +115,7 @@ class System : public Serializable
@return The attached 6502 microprocessor @return The attached 6502 microprocessor
*/ */
M6502& m6502() M6502& m6502() { return *myM6502; }
{
return *myM6502;
}
/** /**
Answer the 6532 processor attached to the system. If a Answer the 6532 processor attached to the system. If a
@ -126,30 +123,21 @@ class System : public Serializable
@return The attached 6532 microprocessor @return The attached 6532 microprocessor
*/ */
M6532& m6532() M6532& m6532() { return *myM6532; }
{
return *myM6532;
}
/** /**
Answer the TIA device attached to the system. Answer the TIA device attached to the system.
@return The attached TIA device @return The attached TIA device
*/ */
TIA& tia() TIA& tia() { return *myTIA; }
{
return *myTIA;
}
/** /**
Answer the random generator attached to the system. Answer the random generator attached to the system.
@return The random generator @return The random generator
*/ */
Random& randGenerator() Random& randGenerator() { return *myRandom; }
{
return *myRandom;
}
/** /**
Get the null device associated with the system. Every system Get the null device associated with the system. Every system
@ -158,10 +146,7 @@ class System : public Serializable
@return The null device associated with the system @return The null device associated with the system
*/ */
NullDevice& nullDevice() NullDevice& nullDevice() { return myNullDevice; }
{
return myNullDevice;
}
/** /**
Get the total number of pages available in the system. Get the total number of pages available in the system.
@ -198,10 +183,7 @@ class System : public Serializable
@param amount The amount to add to the system cycles counter @param amount The amount to add to the system cycles counter
*/ */
void incrementCycles(uInt32 amount) void incrementCycles(uInt32 amount) { myCycles += amount; }
{
myCycles += amount;
}
/** /**
Reset the system cycle count to zero. The first thing that Reset the system cycle count to zero. The first thing that