MainbusComponent.cc Source File
Back to the index.
Go to the documentation of this file.
34 , m_memoryMapFailed(false)
35 , m_memoryMapValid(false)
36 , m_currentAddressDataBus(NULL)
54 if (attributeName ==
"description")
55 return "A generic main bus.";
64 m_memoryMapValid =
false;
65 m_memoryMapFailed =
false;
67 m_currentAddressDataBus = NULL;
76 if (!MakeSureMemoryMapExists(gxemul)) {
85 bool MainbusComponent::MakeSureMemoryMapExists(
GXemul* gxemul)
87 if (m_memoryMapFailed)
95 m_memoryMapValid =
true;
96 m_memoryMapFailed =
false;
101 for (
size_t i=0; i<children.size(); ++i) {
106 MemoryMapEntry mmEntry;
107 mmEntry.addressDataBus = bus;
112 children[i]->GetVariable(
"memoryMappedBase");
114 children[i]->GetVariable(
"memoryMappedSize");
116 children[i]->GetVariable(
"memoryMappedAddrMul");
122 if (varAddrMul != NULL)
123 mmEntry.addrMul = varAddrMul->
ToInteger();
126 if (varSize == NULL || varBase == NULL)
130 if (mmEntry.addrMul == 0)
134 if (mmEntry.size == 0)
142 for (
size_t j=0; j<m_memoryMap.size(); ++j) {
143 if (mmEntry.base+mmEntry.size <= m_memoryMap[j].base)
146 if (mmEntry.base >= m_memoryMap[j].base +
153 "Error: the base and/or size of " +
155 " conflicts with another memory mapped "
156 "component on this bus.\n");
159 m_memoryMapValid =
false;
160 m_memoryMapFailed =
true;
165 m_memoryMap.push_back(mmEntry);
180 MakeSureMemoryMapExists();
182 m_currentAddressDataBus = NULL;
184 if (!m_memoryMapValid)
194 for (
size_t i=0; i<m_memoryMap.size(); ++i) {
195 MemoryMapEntry& mmEntry = m_memoryMap[i];
199 if (address >= mmEntry.base &&
200 address < mmEntry.base + mmEntry.size) {
203 m_currentAddressDataBus = mmEntry.addressDataBus;
205 (address - mmEntry.base) / mmEntry.addrMul);
214 if (!MakeSureMemoryMapExists())
217 if (m_currentAddressDataBus != NULL)
218 return m_currentAddressDataBus->
ReadData(
data, endianness);
226 if (!MakeSureMemoryMapExists())
229 if (m_currentAddressDataBus != NULL)
230 return m_currentAddressDataBus->
ReadData(
data, endianness);
238 if (!MakeSureMemoryMapExists())
241 if (m_currentAddressDataBus != NULL)
242 return m_currentAddressDataBus->
ReadData(
data, endianness);
250 if (!MakeSureMemoryMapExists())
253 if (m_currentAddressDataBus != NULL)
254 return m_currentAddressDataBus->
ReadData(
data, endianness);
262 if (!MakeSureMemoryMapExists())
265 if (m_currentAddressDataBus != NULL)
274 if (!MakeSureMemoryMapExists())
277 if (m_currentAddressDataBus != NULL)
286 if (!MakeSureMemoryMapExists())
289 if (m_currentAddressDataBus != NULL)
298 if (!MakeSureMemoryMapExists())
301 if (m_currentAddressDataBus != NULL)
315 static void Test_MainbusComponent_Creatable()
321 "instanciable", !mainbus.
IsNULL());
324 static void Test_MainbusComponent_AddressDataBus()
331 "AddressDataBus interface", bus != NULL);
334 static void Test_MainbusComponent_Simple()
347 uint8_t dataByte = 42;
361 static void Test_MainbusComponent_Remapping()
374 uint8_t dataByte = 123;
385 uint8_t dataByte2 = 99;
389 "cached state should still be in effect!", dataByte2, 18);
400 static void Test_MainbusComponent_Multiple_NonOverlapping()
423 for (
size_t i = 0; i < 0x300; i +=
sizeof(uint16_t)) {
424 uint16_t
data = (uint8_t) i;
429 for (
size_t i = 0; i < 0x300; i +=
sizeof(uint16_t)) {
434 data, (uint16_t) (i << 8));
438 static void Test_MainbusComponent_Simple_With_AddrMul()
452 uint8_t dataByte = 42;
475 "offset 133 had", dataByte, 100);
479 "written to it yet!", dataByte, 0);
493 "written to it yet! [2]", dataByte, 0);
509 "written to it yet! [3]", dataByte, 0);
512 static void Test_MainbusComponent_PreRunCheck()
537 UNITTEST(Test_MainbusComponent_Creatable);
538 UNITTEST(Test_MainbusComponent_AddressDataBus);
541 UNITTEST(Test_MainbusComponent_Simple);
542 UNITTEST(Test_MainbusComponent_Remapping);
543 UNITTEST(Test_MainbusComponent_Multiple_NonOverlapping);
544 UNITTEST(Test_MainbusComponent_Simple_With_AddrMul);
550 UNITTEST(Test_MainbusComponent_PreRunCheck);
bool PreRunCheck(GXemul *gxemul)
Checks the state of this component and all its children, before starting execution.
Components & GetChildren()
Gets pointers to child components.
virtual void FlushCachedStateForComponent()
Resets the cached state of this component.
virtual bool ReadData(uint8_t &data, Endianness endianness=BigEndian)=0
Reads 8-bit data from the currently selected address.
bool IsNULL() const
Checks whether or not an object is referenced by the reference counted pointer.
string GenerateTreeDump(const string &branchTemplate, bool htmlLinksForClassNames=false, string prefixForComponentUrls="") const
Generates an ASCII tree dump of a component tree.
void AddChild(refcount_ptr< Component > childComponent, size_t insertPosition=(size_t) -1)
Adds a reference to a child component.
static refcount_ptr< Component > Create(const ComponentCreateArgs &args)
Creates a MainbusComponent.
static string GetAttribute(const string &attributeName)
Get attribute information about the MainbusComponent class.
virtual void AddressSelect(uint64_t address)
Place an address on the bus.
MainbusComponent()
Constructs a MainbusComponent.
virtual AddressDataBus * AsAddressDataBus()
Returns the component's AddressDataBus interface.
CommandInterpreter & GetCommandInterpreter()
Gets a reference to the CommandInterpreter.
virtual bool PreRunCheckForComponent(GXemul *gxemul)
Checks the state of this component, before starting execution.
StateVariables make up the persistent state of Component objects.
uint64_t ToInteger() const
Returns the variable as an unsignedinteger value.
#define UNITTESTS(class)
Helper for unit test case execution.
virtual bool ReadData(uint8_t &data, Endianness endianness)
Reads 8-bit data from the currently selected address.
refcount_ptr< Component > GetRootComponent()
Gets a pointer to the root configuration component.
#define UNITTEST(functionname)
Helper for unit test case execution.
static void Assert(const string &strFailMessage, bool condition)
Asserts that a boolean condition is correct.
virtual bool WriteData(const uint8_t &data, Endianness endianness=BigEndian)=0
Writes 8-bit data to the currently selected address.
virtual void ShowDebugMessage(const string &msg)=0
Shows a debug message.
virtual void FlushCachedStateForComponent()
Resets the cached state of this component.
virtual bool WriteData(const uint8_t &data, Endianness endianness)
Writes 8-bit data to the currently selected address.
static refcount_ptr< Component > CreateComponent(const string &componentNameAndOptionalArgs, GXemul *gxemul=NULL)
Creates a component given a short component name.
bool SetVariableValue(const string &name, const string &expression)
Sets a variable to a new value.
virtual void AddressSelect(uint64_t address)=0
Place an address on the bus.
string GenerateShortestPossiblePath() const
Generates a short string representation of the path to the Component.
bool RunCommand(const string &command, bool *pSuccess=NULL)
Runs a command, given as a string.
UI * GetUI()
Gets a pointer to the GXemul instance' active UI.
A Component is a node in the configuration tree that makes up an emulation setup.
vector< refcount_ptr< Component > > Components
virtual ~MainbusComponent()
void FlushCachedState()
Resets the cached state of this component and all its children.
An interface for implementing components that read/write data via an address bus.
static string GetAttribute(const string &attributeName)
Creates a Component.
virtual AddressDataBus * AsAddressDataBus()
Returns the component's AddressDataBus interface, if any.
Generated on Tue Aug 25 2020 19:25:06 for GXemul by
1.8.18