First pass at CpuDebug. In adding this class, I realized that it's just

a reimplementation of D6502.  So D6502 will disappear soon.  The reason
Debugger class has been getting so big is that there was only D6502 defined,
when there should have been also DTia, DRam, etc.  The DebuggerSystem
classes are now providing that functionality.

The codebase may be broken over the next few days because of this, but
it's better to do it properly (I get the feeling it may never be fixed if
we don't do it now).


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@616 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2005-07-07 18:56:41 +00:00
parent c3fab46791
commit 8aff84f2c3
8 changed files with 186 additions and 21 deletions

View File

@ -0,0 +1,101 @@
//============================================================================
//
// SSSS tt lll lll
// SS SS tt ll ll
// SS tttttt eeee ll ll aaaa
// SSSS tt ee ee ll ll aa
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
// SS SS tt ee ll ll aa aa
// SSSS ttt eeeee llll llll aaaaa
//
// Copyright (c) 1995-2005 by Bradford W. Mott and the Stella team
//
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: CpuDebug.cxx,v 1.1 2005-07-07 18:56:40 stephena Exp $
//============================================================================
#include "Array.hxx"
#include "M6502.hxx"
#include "CpuDebug.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CpuDebug::CpuDebug(Console* console)
: DebuggerSystem(console),
mySystem(&(console->system()))
{
saveOldState();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
DebuggerState& CpuDebug::getState()
{
myState.PC = mySystem->m6502().PC;
myState.SP = mySystem->m6502().SP;
myState.PS = mySystem->m6502().PS();
myState.A = mySystem->m6502().A;
myState.X = mySystem->m6502().X;
myState.Y = mySystem->m6502().Y;
myState.PSbits.clear();
for(int i = 0; i < 8; ++i)
{
if(myState.PS & (1<<(7-i)))
myState.PSbits.push_back(true);
else
myState.PSbits.push_back(false);
}
return myState;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CpuDebug::saveOldState()
{
myOldState.PC = mySystem->m6502().PC;
myOldState.SP = mySystem->m6502().SP;
myOldState.PS = mySystem->m6502().PS();
myOldState.A = mySystem->m6502().A;
myOldState.X = mySystem->m6502().X;
myOldState.Y = mySystem->m6502().Y;
myOldState.PSbits.clear();
for(int i = 0; i < 8; ++i)
{
if(myOldState.PS & (1<<(7-i)))
myOldState.PSbits.push_back(true);
else
myOldState.PSbits.push_back(false);
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CpuDebug::setPC(int pc)
{
mySystem->m6502().PC = pc;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CpuDebug::setSP(int sp)
{
mySystem->m6502().SP = sp;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CpuDebug::setA(int a)
{
mySystem->m6502().A = a;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CpuDebug::setX(int x)
{
mySystem->m6502().X = x;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CpuDebug::setY(int y)
{
mySystem->m6502().Y = y;
}

View File

@ -0,0 +1,58 @@
//============================================================================
//
// SSSS tt lll lll
// SS SS tt ll ll
// SS tttttt eeee ll ll aaaa
// SSSS tt ee ee ll ll aa
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
// SS SS tt ee ll ll aa aa
// SSSS ttt eeeee llll llll aaaaa
//
// Copyright (c) 1995-2005 by Bradford W. Mott and the Stella team
//
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: CpuDebug.hxx,v 1.1 2005-07-07 18:56:41 stephena Exp $
//============================================================================
#ifndef CPU_DEBUG_HXX
#define CPU_DEBUG_HXX
class System;
#include "Array.hxx"
#include "Console.hxx"
#include "DebuggerSystem.hxx"
class CpuState : public DebuggerState
{
public:
int PC, SP, PS, A, X, Y;
BoolArray PSbits;
};
class CpuDebug : public DebuggerSystem
{
public:
CpuDebug(Console* console);
DebuggerState& getState();
DebuggerState& getOldState() { return myOldState; }
void saveOldState();
void setA(int a);
void setX(int x);
void setY(int y);
void setSP(int sp);
void setPC(int pc);
private:
CpuState myState;
CpuState myOldState;
System* mySystem;
};
#endif

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: Debugger.cxx,v 1.53 2005-07-07 15:18:55 stephena Exp $
// $Id: Debugger.cxx,v 1.54 2005-07-07 18:56:41 stephena Exp $
//============================================================================
#include "bspf.hxx"
@ -128,7 +128,7 @@ void Debugger::setConsole(Console* console)
// Create debugger subsystems
delete myRamDebug;
myRamDebug = new RamDebug(this);
myRamDebug = new RamDebug(myConsole);
// Create a new TIA debugger for this console
// This code is somewhat ugly, since we derive a TIA from the MediaSource

View File

@ -13,13 +13,13 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: DebuggerSystem.hxx,v 1.1 2005-07-07 15:18:58 stephena Exp $
// $Id: DebuggerSystem.hxx,v 1.2 2005-07-07 18:56:41 stephena Exp $
//============================================================================
#ifndef DEBUGGER_SYSTEM_HXX
#define DEBUGGER_SYSTEM_HXX
#include "Debugger.hxx"
#include "Console.hxx"
/**
The DebuggerState class is used as a base class for state in all
@ -41,16 +41,13 @@ class DebuggerState
class DebuggerSystem
{
public:
DebuggerSystem(Debugger* dbg) { myDebugger = dbg; }
virtual ~DebuggerSystem() { };
DebuggerSystem(Console* console) { }
virtual ~DebuggerSystem() { }
virtual DebuggerState& getState() = 0;
virtual DebuggerState& getOldState() = 0;
virtual void saveOldState() = 0;
protected:
Debugger* myDebugger;
};
#endif

View File

@ -13,15 +13,17 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: RamDebug.cxx,v 1.1 2005-07-07 15:18:58 stephena Exp $
// $Id: RamDebug.cxx,v 1.2 2005-07-07 18:56:41 stephena Exp $
//============================================================================
#include "Array.hxx"
#include "System.hxx"
#include "RamDebug.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
RamDebug::RamDebug(Debugger* dbg)
: DebuggerSystem(dbg)
RamDebug::RamDebug(Console* console)
: DebuggerSystem(console),
mySystem(&(console->system()))
{
saveOldState();
}
@ -31,7 +33,7 @@ DebuggerState& RamDebug::getState()
{
myState.ram.clear();
for(int i=0; i<0x80; i++)
myState.ram.push_back(myDebugger->readRAM(i));
myState.ram.push_back(read(i));
return myState;
}
@ -41,19 +43,19 @@ void RamDebug::saveOldState()
{
myOldState.ram.clear();
for(int i=0; i<0x80; i++)
myOldState.ram.push_back(myDebugger->readRAM(i));
myOldState.ram.push_back(read(i));
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
int RamDebug::read(int offset)
{
offset &= 0x7f; // there are only 128 bytes
return myDebugger->mySystem->peek(offset + 0x80);
return mySystem->peek(offset + 0x80);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void RamDebug::write(int offset, int value)
{
offset &= 0x7f; // there are only 128 bytes
myDebugger->mySystem->poke(offset + 0x80, value);
mySystem->poke(offset + 0x80, value);
}

View File

@ -13,12 +13,14 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: RamDebug.hxx,v 1.1 2005-07-07 15:18:58 stephena Exp $
// $Id: RamDebug.hxx,v 1.2 2005-07-07 18:56:41 stephena Exp $
//============================================================================
#ifndef RAM_DEBUG_HXX
#define RAM_DEBUG_HXX
class System;
#include "Array.hxx"
#include "DebuggerSystem.hxx"
@ -31,7 +33,7 @@ class RamState : public DebuggerState
class RamDebug : public DebuggerSystem
{
public:
RamDebug(Debugger* dbg);
RamDebug(Console* console);
DebuggerState& getState();
DebuggerState& getOldState() { return myOldState; }
@ -44,6 +46,8 @@ class RamDebug : public DebuggerSystem
private:
RamState myState;
RamState myOldState;
System* mySystem;
};
#endif

View File

@ -5,6 +5,7 @@ MODULE_OBJS := \
src/debugger/DebuggerParser.o \
src/debugger/EquateList.o \
src/debugger/PackedBitArray.o \
src/debugger/CpuDebug.o \
src/debugger/RamDebug.o \
src/debugger/TIADebug.o

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: M6502.hxx,v 1.7 2005-07-01 04:22:37 urchlay Exp $
// $Id: M6502.hxx,v 1.8 2005-07-07 18:56:41 stephena Exp $
//============================================================================
#ifndef M6502_HXX
@ -24,6 +24,7 @@ class M6502;
class Serializer;
class Deserializer;
class Debugger;
class CpuDebug;
#include "bspf.hxx"
#include "System.hxx"
@ -35,7 +36,7 @@ class Debugger;
has a 64K addressing space.
@author Bradford W. Mott
@version $Id: M6502.hxx,v 1.7 2005-07-01 04:22:37 urchlay Exp $
@version $Id: M6502.hxx,v 1.8 2005-07-07 18:56:41 stephena Exp $
*/
class M6502
{
@ -43,7 +44,8 @@ class M6502
/**
The 6502 debugger class is a friend who needs special access
*/
friend class D6502;
friend class D6502; // FIXME - remove
friend class CpuDebug;
public:
/**