mirror of https://github.com/stella-emu/stella.git
More pointer rearrangment for Console class.
git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@3034 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
parent
a21f3be6e4
commit
5dbb2e4261
|
@ -66,13 +66,11 @@
|
|||
#include "Console.hxx"
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Console::Console(OSystem& osystem, Cartridge& cart, const Properties& props)
|
||||
Console::Console(OSystem& osystem, Cartridge* cart, const Properties& props)
|
||||
: myOSystem(osystem),
|
||||
myCart(cart),
|
||||
myEvent(osystem.eventHandler().event()),
|
||||
myProperties(props),
|
||||
myTIA(0),
|
||||
myCMHandler(0),
|
||||
myCMHandler(nullptr),
|
||||
myDisplayFormat(""), // Unknown TV format @ start
|
||||
myFramerate(0.0), // Unknown framerate @ start
|
||||
myCurrentFormat(0), // Unknown format @ start
|
||||
|
@ -81,31 +79,25 @@ Console::Console(OSystem& osystem, Cartridge& cart, const Properties& props)
|
|||
// Load user-defined palette for this ROM
|
||||
loadUserPalette();
|
||||
|
||||
// Create switches for the console
|
||||
// Create subsystems for the console
|
||||
my6502 = make_ptr<M6502>(myOSystem.settings());
|
||||
myRiot = make_ptr<M6532>(*this, myOSystem.settings());
|
||||
myTIA = make_ptr<TIA>(*this, myOSystem.sound(), myOSystem.settings());
|
||||
myCart = unique_ptr<Cartridge>(cart);
|
||||
mySwitches = make_ptr<Switches>(myEvent, myProperties);
|
||||
|
||||
// Construct the system and components
|
||||
mySystem = make_ptr<System>(osystem);
|
||||
mySystem = make_ptr<System>(osystem, *my6502, *myRiot, *myTIA, *myCart);
|
||||
|
||||
// The real controllers for this console will be added later
|
||||
// For now, we just add dummy joystick controllers, since autodetection
|
||||
// runs the emulation for a while, and this may interfere with 'smart'
|
||||
// controllers such as the AVox and SaveKey
|
||||
// Note that the controllers must be added directly after the system
|
||||
// has been created, and before any other device is added
|
||||
// (particularly the M6532)
|
||||
myControllers[0] = new Joystick(Controller::Left, myEvent, *mySystem);
|
||||
myControllers[1] = new Joystick(Controller::Right, myEvent, *mySystem);
|
||||
|
||||
M6502* m6502 = new M6502(myOSystem.settings());
|
||||
|
||||
myRiot = new M6532(*this, myOSystem.settings());
|
||||
myTIA = new TIA(*this, myOSystem.sound(), myOSystem.settings());
|
||||
|
||||
mySystem->attach(m6502);
|
||||
mySystem->attach(myRiot);
|
||||
mySystem->attach(myTIA);
|
||||
mySystem->attach(&myCart);
|
||||
// We can only initialize after all the devices/components have been created
|
||||
mySystem->initialize();
|
||||
|
||||
// Auto-detect NTSC/PAL mode if it's requested
|
||||
string autodetected = "";
|
||||
|
@ -166,9 +158,9 @@ Console::Console(OSystem& osystem, Cartridge& cart, const Properties& props)
|
|||
myConsoleInfo.CartMD5 = myProperties.get(Cartridge_MD5);
|
||||
myConsoleInfo.Control0 = myControllers[0]->about();
|
||||
myConsoleInfo.Control1 = myControllers[1]->about();
|
||||
myConsoleInfo.BankSwitch = myCart.about();
|
||||
myConsoleInfo.BankSwitch = myCart->about();
|
||||
|
||||
myCart.setRomName(myConsoleInfo.CartName);
|
||||
myCart->setRomName(myConsoleInfo.CartName);
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
@ -471,7 +463,7 @@ void Console::initializeAudio()
|
|||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void Console::fry() const
|
||||
{
|
||||
for (int ZPmem=0; ZPmem<0x100; ZPmem += rand() % 4)
|
||||
for(int ZPmem = 0; ZPmem < 0x100; ZPmem += rand() % 4)
|
||||
mySystem->poke(ZPmem, mySystem->peek(ZPmem) & (uInt8)rand() % 256);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ class Event;
|
|||
class Switches;
|
||||
class System;
|
||||
class TIA;
|
||||
class M6502;
|
||||
class M6532;
|
||||
class Cartridge;
|
||||
class CompuMate;
|
||||
|
@ -68,7 +69,7 @@ class Console : public Serializable
|
|||
@param cart The cartridge to use with this console
|
||||
@param props The properties for the cartridge
|
||||
*/
|
||||
Console(OSystem& osystem, Cartridge& cart, const Properties& props);
|
||||
Console(OSystem& osystem, Cartridge* cart, const Properties& props);
|
||||
|
||||
/**
|
||||
Destructor
|
||||
|
@ -119,7 +120,7 @@ class Console : public Serializable
|
|||
|
||||
@return The cartridge for this console
|
||||
*/
|
||||
Cartridge& cartridge() const { return myCart; }
|
||||
Cartridge& cartridge() const { return *myCart; }
|
||||
|
||||
/**
|
||||
Get the 6532 used by the console
|
||||
|
@ -330,30 +331,33 @@ class Console : public Serializable
|
|||
// Reference to the osystem object
|
||||
OSystem& myOSystem;
|
||||
|
||||
// Pointer to the Cartridge (the debugger needs it)
|
||||
Cartridge& myCart;
|
||||
|
||||
// Reference to the event object to use
|
||||
const Event& myEvent;
|
||||
|
||||
// Properties for the game
|
||||
Properties myProperties;
|
||||
|
||||
// Pointers to the left and right controllers
|
||||
Controller* myControllers[2];
|
||||
|
||||
// Pointer to the TIA object
|
||||
TIA* myTIA;
|
||||
|
||||
// Pointer to the switches on the front of the console
|
||||
unique_ptr<Switches> mySwitches;
|
||||
|
||||
// Pointer to the 6502 based system being emulated
|
||||
unique_ptr<System> mySystem;
|
||||
|
||||
// Pointer to the M6502 CPU
|
||||
unique_ptr<M6502> my6502;
|
||||
|
||||
// Pointer to the 6532 (aka RIOT) (the debugger needs it)
|
||||
// A RIOT of my own! (...with apologies to The Clash...)
|
||||
M6532* myRiot;
|
||||
unique_ptr<M6532> myRiot;
|
||||
|
||||
// Pointer to the TIA object
|
||||
unique_ptr<TIA> myTIA;
|
||||
|
||||
// Pointer to the Cartridge (the debugger needs it)
|
||||
unique_ptr<Cartridge> myCart;
|
||||
|
||||
// Pointer to the switches on the front of the console
|
||||
unique_ptr<Switches> mySwitches;
|
||||
|
||||
// Pointers to the left and right controllers
|
||||
Controller* myControllers[2];
|
||||
|
||||
// Pointer to CompuMate handler (only used in CompuMate ROMs)
|
||||
CompuMate* myCMHandler;
|
||||
|
|
|
@ -573,7 +573,7 @@ Console* OSystem::openConsole(const FilesystemNode& romfile, string& md5,
|
|||
|
||||
// Finally, create the cart with the correct properties
|
||||
if(cart)
|
||||
console = new Console(*this, *cart, props);
|
||||
console = new Console(*this, cart, props);
|
||||
}
|
||||
|
||||
// Free the image since we don't need it any longer
|
||||
|
|
|
@ -24,15 +24,17 @@
|
|||
#include "M6502.hxx"
|
||||
#include "M6532.hxx"
|
||||
#include "TIA.hxx"
|
||||
#include "Cart.hxx"
|
||||
#include "System.hxx"
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
System::System(const OSystem& osystem)
|
||||
System::System(const OSystem& osystem, M6502& m6502, M6532& m6532,
|
||||
TIA& mTIA, Cartridge& mCart)
|
||||
: myOSystem(osystem),
|
||||
myNumberOfDevices(0),
|
||||
myM6502(0),
|
||||
myM6532(0),
|
||||
myTIA(0),
|
||||
myM6502(m6502),
|
||||
myM6532(m6532),
|
||||
myTIA(mTIA),
|
||||
myCart(mCart),
|
||||
myCycles(0),
|
||||
myDataBusState(0),
|
||||
myDataBusLocked(false),
|
||||
|
@ -60,20 +62,21 @@ System::System(const OSystem& osystem)
|
|||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
System::~System()
|
||||
{
|
||||
// Free the devices attached to me, since I own them
|
||||
for(uInt32 i = 0; i < myNumberOfDevices; ++i)
|
||||
{
|
||||
delete myDevices[i];
|
||||
}
|
||||
|
||||
// Free the M6502 that I own
|
||||
delete myM6502;
|
||||
|
||||
// Free my page access table and dirty list
|
||||
delete[] myPageAccessTable;
|
||||
delete[] myPageIsDirtyTable;
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void System::initialize()
|
||||
{
|
||||
// Install all devices
|
||||
myM6532.install(*this);
|
||||
myTIA.install(*this);
|
||||
myCart.install(*this);
|
||||
myM6502.install(*this); // Must always be installed last
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void System::reset(bool autodetect)
|
||||
{
|
||||
|
@ -83,65 +86,23 @@ void System::reset(bool autodetect)
|
|||
// Reset system cycle counter
|
||||
resetCycles();
|
||||
|
||||
// First we reset the devices attached to myself
|
||||
for(uInt32 i = 0; i < myNumberOfDevices; ++i)
|
||||
myDevices[i]->reset();
|
||||
|
||||
// Now we reset the processor if it exists
|
||||
if(myM6502 != 0)
|
||||
myM6502->reset();
|
||||
// Reset all devices
|
||||
myM6532.reset();
|
||||
myTIA.reset();
|
||||
myCart.reset();
|
||||
myM6502.reset(); // Must always be reset last
|
||||
|
||||
// There are no dirty pages upon startup
|
||||
clearDirtyPages();
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void System::attach(Device* device)
|
||||
{
|
||||
assert(myNumberOfDevices < 5);
|
||||
|
||||
// Add device to my collection of devices
|
||||
myDevices[myNumberOfDevices++] = device;
|
||||
|
||||
// Ask the device to install itself
|
||||
device->install(*this);
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void System::attach(M6502* m6502)
|
||||
{
|
||||
// Remember the processor
|
||||
myM6502 = m6502;
|
||||
|
||||
// Ask the processor to install itself
|
||||
myM6502->install(*this);
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void System::attach(M6532* m6532)
|
||||
{
|
||||
// Remember the processor
|
||||
myM6532 = m6532;
|
||||
|
||||
// Attach it as a normal device
|
||||
attach(static_cast<Device*>(m6532));
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void System::attach(TIA* tia)
|
||||
{
|
||||
myTIA = tia;
|
||||
attach(static_cast<Device*>(tia));
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void System::resetCycles()
|
||||
{
|
||||
// First we let all of the device attached to me know about the reset
|
||||
for(uInt32 i = 0; i < myNumberOfDevices; ++i)
|
||||
{
|
||||
myDevices[i]->systemCyclesReset();
|
||||
}
|
||||
myM6532.systemCyclesReset();
|
||||
myTIA.systemCyclesReset();
|
||||
myCart.systemCyclesReset();
|
||||
|
||||
// Now, we reset cycle count to zero
|
||||
myCycles = 0;
|
||||
|
@ -290,13 +251,15 @@ bool System::save(Serializer& out) const
|
|||
out.putInt(myCycles);
|
||||
out.putByte(myDataBusState);
|
||||
|
||||
if(!myM6502->save(out))
|
||||
// Save the state of each device
|
||||
if(!myM6502.save(out))
|
||||
return false;
|
||||
if(!myM6532.save(out))
|
||||
return false;
|
||||
if(!myTIA.save(out))
|
||||
return false;
|
||||
if(!myCart.save(out))
|
||||
return false;
|
||||
|
||||
// Now save the state of each device
|
||||
for(uInt32 i = 0; i < myNumberOfDevices; ++i)
|
||||
if(!myDevices[i]->save(out))
|
||||
return false;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
|
@ -318,14 +281,15 @@ bool System::load(Serializer& in)
|
|||
myCycles = in.getInt();
|
||||
myDataBusState = in.getByte();
|
||||
|
||||
// Next, load state for the CPU
|
||||
if(!myM6502->load(in))
|
||||
// Load the state of each device
|
||||
if(!myM6502.load(in))
|
||||
return false;
|
||||
if(!myM6532.load(in))
|
||||
return false;
|
||||
if(!myTIA.load(in))
|
||||
return false;
|
||||
if(!myCart.load(in))
|
||||
return false;
|
||||
|
||||
// Now load the state of each device
|
||||
for(uInt32 i = 0; i < myNumberOfDevices; ++i)
|
||||
if(!myDevices[i]->load(in))
|
||||
return false;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
|
|
|
@ -52,7 +52,8 @@ class System : public Serializable
|
|||
Create a new system with an addressing space of 2^13 bytes and
|
||||
pages of 2^6 bytes.
|
||||
*/
|
||||
System(const OSystem& osystem);
|
||||
System(const OSystem& osystem, M6502& m6502, M6532& m6532,
|
||||
TIA& mTIA, Cartridge& mCart);
|
||||
|
||||
/**
|
||||
Destructor
|
||||
|
@ -72,6 +73,11 @@ class System : public Serializable
|
|||
static const uInt16 NUM_PAGES = 1 << (13 - PAGE_SHIFT);
|
||||
|
||||
public:
|
||||
/**
|
||||
Initialize system and all attached devices to known state.
|
||||
*/
|
||||
void initialize();
|
||||
|
||||
/**
|
||||
Reset the system cycle counter, the attached devices, and the
|
||||
attached processor of the system.
|
||||
|
@ -85,38 +91,6 @@ class System : public Serializable
|
|||
*/
|
||||
void reset(bool autodetect = false);
|
||||
|
||||
/**
|
||||
Attach the specified device and claim ownership of it. The device
|
||||
will be asked to install itself.
|
||||
|
||||
@param device The device to attach to the system
|
||||
*/
|
||||
void attach(Device* device);
|
||||
|
||||
/**
|
||||
Attach the specified processor and claim ownership of it. The
|
||||
processor will be asked to install itself.
|
||||
|
||||
@param m6502 The 6502 microprocessor to attach to the system
|
||||
*/
|
||||
void attach(M6502* m6502);
|
||||
|
||||
/**
|
||||
Attach the specified processor and claim ownership of it. The
|
||||
processor will be asked to install itself.
|
||||
|
||||
@param m6532 The 6532 microprocessor to attach to the system
|
||||
*/
|
||||
void attach(M6532* m6532);
|
||||
|
||||
/**
|
||||
Attach the specified TIA device and claim ownership of it. The device
|
||||
will be asked to install itself.
|
||||
|
||||
@param tia The TIA device to attach to the system
|
||||
*/
|
||||
void attach(TIA* tia);
|
||||
|
||||
public:
|
||||
/**
|
||||
Answer the 6502 microprocessor attached to the system. If a
|
||||
|
@ -124,7 +98,7 @@ class System : public Serializable
|
|||
|
||||
@return The attached 6502 microprocessor
|
||||
*/
|
||||
M6502& m6502() const { return *myM6502; }
|
||||
M6502& m6502() const { return myM6502; }
|
||||
|
||||
/**
|
||||
Answer the 6532 processor attached to the system. If a
|
||||
|
@ -132,14 +106,14 @@ class System : public Serializable
|
|||
|
||||
@return The attached 6532 microprocessor
|
||||
*/
|
||||
M6532& m6532() const { return *myM6532; }
|
||||
M6532& m6532() const { return myM6532; }
|
||||
|
||||
/**
|
||||
Answer the TIA device attached to the system.
|
||||
|
||||
@return The attached TIA device
|
||||
*/
|
||||
TIA& tia() const { return *myTIA; }
|
||||
TIA& tia() const { return myTIA; }
|
||||
|
||||
/**
|
||||
Answer the random generator attached to the system.
|
||||
|
@ -404,26 +378,17 @@ class System : public Serializable
|
|||
private:
|
||||
const OSystem& myOSystem;
|
||||
|
||||
// Pointer to a dynamically allocated array of PageAccess structures
|
||||
PageAccess* myPageAccessTable;
|
||||
// 6502 processor attached to the system
|
||||
M6502& myM6502;
|
||||
|
||||
// Pointer to a dynamically allocated array for dirty pages
|
||||
bool* myPageIsDirtyTable;
|
||||
// 6532 processor attached to the system
|
||||
M6532& myM6532;
|
||||
|
||||
// Array of all the devices attached to the system
|
||||
Device* myDevices[5];
|
||||
// TIA device attached to the system
|
||||
TIA& myTIA;
|
||||
|
||||
// Number of devices attached to the system
|
||||
uInt32 myNumberOfDevices;
|
||||
|
||||
// 6502 processor attached to the system or the null pointer
|
||||
M6502* myM6502;
|
||||
|
||||
// 6532 processor attached to the system or the null pointer
|
||||
M6532* myM6532;
|
||||
|
||||
// TIA device attached to the system or the null pointer
|
||||
TIA* myTIA;
|
||||
// Cartridge device attached to the system
|
||||
Cartridge& myCart;
|
||||
|
||||
// Number of system cycles executed since the last reset
|
||||
uInt32 myCycles;
|
||||
|
@ -431,6 +396,12 @@ class System : public Serializable
|
|||
// Null device to use for page which are not installed
|
||||
NullDevice myNullDevice;
|
||||
|
||||
// Pointer to a dynamically allocated array of PageAccess structures
|
||||
PageAccess* myPageAccessTable;
|
||||
|
||||
// Pointer to a dynamically allocated array for dirty pages
|
||||
bool* myPageIsDirtyTable;
|
||||
|
||||
// The current state of the Data Bus
|
||||
uInt8 myDataBusState;
|
||||
|
||||
|
|
|
@ -252,8 +252,6 @@ void TIA::install(System& system, Device& device)
|
|||
// Remember which system I'm installed in
|
||||
mySystem = &system;
|
||||
|
||||
mySystem->resetCycles();
|
||||
|
||||
// All accesses are to the given device
|
||||
System::PageAccess access(&device, System::PA_READWRITE);
|
||||
|
||||
|
|
Loading…
Reference in New Issue