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 ==
"stable")
57 if (attributeName ==
"description")
58 return "A generic main bus.";
67 m_memoryMapValid =
false;
68 m_memoryMapFailed =
false;
70 m_currentAddressDataBus = NULL;
79 if (!MakeSureMemoryMapExists(gxemul)) {
88 bool MainbusComponent::MakeSureMemoryMapExists(
GXemul* gxemul)
90 if (m_memoryMapFailed)
98 m_memoryMapValid =
true;
99 m_memoryMapFailed =
false;
104 for (
size_t i=0; i<children.size(); ++i) {
109 MemoryMapEntry mmEntry;
110 mmEntry.addressDataBus = bus;
115 children[i]->GetVariable(
"memoryMappedBase");
117 children[i]->GetVariable(
"memoryMappedSize");
119 children[i]->GetVariable(
"memoryMappedAddrMul");
125 if (varAddrMul != NULL)
126 mmEntry.addrMul = varAddrMul->
ToInteger();
129 if (varSize == NULL || varBase == NULL)
133 if (mmEntry.addrMul == 0)
137 if (mmEntry.size == 0)
145 for (
size_t j=0; j<m_memoryMap.size(); ++j) {
146 if (mmEntry.base+mmEntry.size <= m_memoryMap[j].base)
149 if (mmEntry.base >= m_memoryMap[j].base +
156 "Error: the base and/or size of " +
158 " conflicts with another memory mapped "
159 "component on this bus.\n");
162 m_memoryMapValid =
false;
163 m_memoryMapFailed =
true;
168 m_memoryMap.push_back(mmEntry);
183 MakeSureMemoryMapExists();
185 m_currentAddressDataBus = NULL;
187 if (!m_memoryMapValid)
197 for (
size_t i=0; i<m_memoryMap.size(); ++i) {
198 MemoryMapEntry& mmEntry = m_memoryMap[i];
202 if (address >= mmEntry.base &&
203 address < mmEntry.base + mmEntry.size) {
206 m_currentAddressDataBus = mmEntry.addressDataBus;
208 (address - mmEntry.base) / mmEntry.addrMul);
217 if (!MakeSureMemoryMapExists())
220 if (m_currentAddressDataBus != NULL)
221 return m_currentAddressDataBus->
ReadData(
data, endianness);
229 if (!MakeSureMemoryMapExists())
232 if (m_currentAddressDataBus != NULL)
233 return m_currentAddressDataBus->
ReadData(
data, endianness);
241 if (!MakeSureMemoryMapExists())
244 if (m_currentAddressDataBus != NULL)
245 return m_currentAddressDataBus->
ReadData(
data, endianness);
253 if (!MakeSureMemoryMapExists())
256 if (m_currentAddressDataBus != NULL)
257 return m_currentAddressDataBus->
ReadData(
data, endianness);
265 if (!MakeSureMemoryMapExists())
268 if (m_currentAddressDataBus != NULL)
277 if (!MakeSureMemoryMapExists())
280 if (m_currentAddressDataBus != NULL)
289 if (!MakeSureMemoryMapExists())
292 if (m_currentAddressDataBus != NULL)
301 if (!MakeSureMemoryMapExists())
304 if (m_currentAddressDataBus != NULL)
318 static void Test_MainbusComponent_IsStable()
324 static void Test_MainbusComponent_Creatable()
330 "instanciable", !mainbus.
IsNULL());
333 static void Test_MainbusComponent_AddressDataBus()
340 "AddressDataBus interface", bus != NULL);
343 static void Test_MainbusComponent_Simple()
356 uint8_t dataByte = 42;
370 static void Test_MainbusComponent_Remapping()
383 uint8_t dataByte = 123;
394 uint8_t dataByte2 = 99;
398 "cached state should still be in effect!", dataByte2, 18);
409 static void Test_MainbusComponent_Multiple_NonOverlapping()
432 for (
size_t i = 0; i < 0x300; i +=
sizeof(uint16_t)) {
433 uint16_t
data = (uint8_t) i;
438 for (
size_t i = 0; i < 0x300; i +=
sizeof(uint16_t)) {
443 data, (uint16_t) (i << 8));
447 static void Test_MainbusComponent_Simple_With_AddrMul()
461 uint8_t dataByte = 42;
484 "offset 133 had", dataByte, 100);
488 "written to it yet!", dataByte, 0);
502 "written to it yet! [2]", dataByte, 0);
518 "written to it yet! [3]", dataByte, 0);
521 static void Test_MainbusComponent_PreRunCheck()
546 UNITTEST(Test_MainbusComponent_IsStable);
547 UNITTEST(Test_MainbusComponent_Creatable);
548 UNITTEST(Test_MainbusComponent_AddressDataBus);
551 UNITTEST(Test_MainbusComponent_Simple);
552 UNITTEST(Test_MainbusComponent_Remapping);
553 UNITTEST(Test_MainbusComponent_Multiple_NonOverlapping);
554 UNITTEST(Test_MainbusComponent_Simple_With_AddrMul);
560 UNITTEST(Test_MainbusComponent_PreRunCheck);
bool PreRunCheck(GXemul *gxemul)
Checks the state of this component and all its children, before starting execution.
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.
#define UNITTEST(functionname)
Helper for unit test case execution.
static void Assert(const string &strFailMessage, bool condition)
Asserts that a boolean condition is correct.
Components & GetChildren()
Gets pointers to child components.
virtual bool WriteData(const uint8_t &data, Endianness endianness=BigEndian)=0
Writes 8-bit data to the currently selected address.
refcount_ptr< Component > GetRootComponent()
Gets a pointer to the root configuration component.
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()
static bool HasAttribute(const string &name, const string &attributeName)
Checks if a component has a specific attribute.
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 Mar 24 2020 14:04:48 for GXemul by
1.8.17