Cleaned up accessing the TIA from System class. Brian, I'm not sure

if this is needed for anything other than 3E type, but since it
doesn't cause any overhead, I went ahead and did it anyway (after
reading your messages on Stella list).

Please test to make sure it still works, but I don't think there'll
be any problems.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@628 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2005-07-09 12:52:46 +00:00
parent 9f354edb8a
commit 3fabe0ece8
4 changed files with 40 additions and 43 deletions

View File

@ -13,13 +13,14 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: Cart3E.cxx,v 1.4 2005-07-09 00:59:12 urchlay Exp $ // $Id: Cart3E.cxx,v 1.5 2005-07-09 12:52:46 stephena Exp $
//============================================================================ //============================================================================
#include <assert.h> #include <assert.h>
#include "Cart3E.hxx" #include "Cart3E.hxx"
#include "Random.hxx" #include "Random.hxx"
#include "System.hxx" #include "System.hxx"
#include "TIA.hxx"
#include "Serializer.hxx" #include "Serializer.hxx"
#include "Deserializer.hxx" #include "Deserializer.hxx"
#include <iostream> #include <iostream>
@ -133,12 +134,11 @@ void Cartridge3E::poke(uInt16 address, uInt8 value)
bank(value + 256); bank(value + 256);
} }
// Dirty hack alert!
// Pass the poke through to the TIA. In a real Atari, both the cart and the // Pass the poke through to the TIA. In a real Atari, both the cart and the
// TIA see the address lines, and both react accordingly. In Stella, each // TIA see the address lines, and both react accordingly. In Stella, each
// 64-byte chunk of address space is "owned" by only one device. If we // 64-byte chunk of address space is "owned" by only one device. If we
// don't chain the poke to the TIA, then the TIA can't see it... // don't chain the poke to the TIA, then the TIA can't see it...
mySystem->tiaPoke(address, value); mySystem->tia().poke(address, value);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -13,12 +13,13 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: Cart3F.cxx,v 1.8 2005-07-09 00:59:12 urchlay Exp $ // $Id: Cart3F.cxx,v 1.9 2005-07-09 12:52:46 stephena Exp $
//============================================================================ //============================================================================
#include <assert.h> #include <assert.h>
#include "Cart3F.hxx" #include "Cart3F.hxx"
#include "System.hxx" #include "System.hxx"
#include "TIA.hxx"
#include "Serializer.hxx" #include "Serializer.hxx"
#include "Deserializer.hxx" #include "Deserializer.hxx"
#include <iostream> #include <iostream>
@ -118,9 +119,7 @@ void Cartridge3F::poke(uInt16 address, uInt8 value)
bank(value); bank(value);
} }
// pass pokes through to the TIA. This uses a DIRTY HACK which will mySystem->tia().poke(address, value);
// (probably) go away in the future. See System.cxx for details.
mySystem->tiaPoke(address, value);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: System.cxx,v 1.11 2005-07-09 00:59:13 urchlay Exp $ // $Id: System.cxx,v 1.12 2005-07-09 12:52:46 stephena Exp $
//============================================================================ //============================================================================
#include <assert.h> #include <assert.h>
@ -21,7 +21,7 @@
#include "Device.hxx" #include "Device.hxx"
#include "M6502.hxx" #include "M6502.hxx"
#include "TIA.hxx" // FIXME: this is a hack #include "TIA.hxx"
#include "System.hxx" #include "System.hxx"
#include "Serializer.hxx" #include "Serializer.hxx"
#include "Deserializer.hxx" #include "Deserializer.hxx"
@ -34,6 +34,7 @@ System::System(uInt16 n, uInt16 m)
myNumberOfPages(1 << (n - m)), myNumberOfPages(1 << (n - m)),
myNumberOfDevices(0), myNumberOfDevices(0),
myM6502(0), myM6502(0),
myTIA(0),
myCycles(0), myCycles(0),
myDataBusState(0) myDataBusState(0)
{ {
@ -121,6 +122,13 @@ void System::attach(M6502* m6502)
myM6502->install(*this); myM6502->install(*this);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void System::attach(TIA* tia)
{
myTIA = tia;
attach((Device*) tia);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool System::save(Serializer& out) bool System::save(Serializer& out)
{ {
@ -350,23 +358,3 @@ void System::poke(uInt16 addr, uInt8 value)
myDataBusState = value; myDataBusState = value;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// FIXME: dirty hack! This only exists for Cart3E and Cart3F to use, and
// then only until I come up a cleaner way to implement it. Call this method
// at your own peril!
// Note that in some compilers (VC++?) you need to enable RTTI to make the
// dynamic_cast work. In g++, RTTI seems to be on by default. Do not
// compile Stella with -fno-rtti!
// Sorry about the mess. -- B.
void System::tiaPoke(uInt16 addr, uInt8 value)
{
TIA *t;
for(uInt32 i = 0; i < myNumberOfDevices; ++i)
{
if( (t = dynamic_cast<TIA*>(myDevices[i])) )
t->poke(addr, value);
}
}

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: System.hxx,v 1.8 2005-07-09 00:59:13 urchlay Exp $ // $Id: System.hxx,v 1.9 2005-07-09 12:52:46 stephena Exp $
//============================================================================ //============================================================================
#ifndef SYSTEM_HXX #ifndef SYSTEM_HXX
@ -21,6 +21,7 @@
class Device; class Device;
class M6502; class M6502;
class TIA;
class NullDevice; class NullDevice;
class Serializer; class Serializer;
class Deserializer; class Deserializer;
@ -47,7 +48,7 @@ class Deserializer;
dynamic code for that page of memory. dynamic code for that page of memory.
@author Bradford W. Mott @author Bradford W. Mott
@version $Id: System.hxx,v 1.8 2005-07-09 00:59:13 urchlay Exp $ @version $Id: System.hxx,v 1.9 2005-07-09 12:52:46 stephena Exp $
*/ */
class System class System
{ {
@ -106,6 +107,14 @@ class System
*/ */
void attach(M6502* m6502); void attach(M6502* m6502);
/**
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);
/** /**
Saves the current state of Stella to the given file. Calls Saves the current state of Stella to the given file. Calls
save on every device and CPU attached to this system. save on every device and CPU attached to this system.
@ -142,6 +151,16 @@ class System
return *myM6502; return *myM6502;
} }
/**
Answer the TIA device attached to the system.
@return The attached TIA device
*/
TIA& tia()
{
return *myTIA;
}
/** /**
Get the null device associated with the system. Every system Get the null device associated with the system. Every system
has a null device associated with it that's used by pages which has a null device associated with it that's used by pages which
@ -242,18 +261,6 @@ class System
*/ */
void poke(uInt16 address, uInt8 value); void poke(uInt16 address, uInt8 value);
/**
Force a poke to the TIA, bypassing the normal device selection.
This is used by the 3E and 3F bankswitch schemes, which attach
themselves to the address space at $00-$3F and need a way to
pass a poke there through to the TIA.
I don't know what the correct way to do this is, but I'm pretty
certain this ain't it. As soon as I do know, this method goes away.
-- B.
*/
void System::tiaPoke(uInt16 addr, uInt8 value);
public: public:
/** /**
Structure used to specify access methods for a page Structure used to specify access methods for a page
@ -324,6 +331,9 @@ class System
// 6502 processor attached to the system or the null pointer // 6502 processor attached to the system or the null pointer
M6502* myM6502; M6502* myM6502;
// TIA device attached to the system or the null pointer
TIA* myTIA;
// Number of system cycles executed since the last reset // Number of system cycles executed since the last reset
uInt32 myCycles; uInt32 myCycles;