Click here to Skip to main content
15,848,684 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am writing an emulator for a small 8 bit computer. It's a kind of prototyping and debugging tool for the real thing I have on a breadboard. It already can emulate highly timing sensitive code and give me information about what is going on inside the processor., so that is not the issue.

However, I need to have a more flexible model of the memory map of the system and the devices that are attached to the processor's bus. Emulating is faster than wiring it all on a breadboard. To get that flexibility, almost nothing is hard coded. Instead I have lists of objects (the processor, memory blocks and devices) that are 'wired up' by object references and events. A complete configuration is not some orderly tree, it's more like everything can be connected to everything else. Circular references not a rare thing at all. For example, one of the processor's output ports is hooked up to a parallel port device, which in turn provides the page address of a paged memory block, which again references the CPU in order to provide it with data from memory.

Of course I need something to reconfigure this as needed. In the past I have used XML or XAML to edit and serialize/deserialize such configurations, but I'm not sure about using it here. In a small computer the CPU is the source and also the destination of almost everything going on, leading to such circular definitions.

What I have tried:

As staded above, I used XML or XAML in the past, however the presence of circular references of events does not make this appear to be a good idea here. I'm looking for an alternative that offers similar convenience, but also can deal with circular definitions.
Posted
Updated 3-Jul-23 0:11am
Comments
Gerry Schmitz 26-Jun-23 12:14pm    
You can control which fields are serialized via attributes. Serialize one side. Circular object references can be rebuilt during deserialization. If it's more complicated than that, there's a design problem; nothing is that complex.
CodeWraith 26-Jun-23 12:48pm    
Thanks. Any actual configuration probably really is not that complex, but it's a Lego world with many different possibilities to put the Legos together. All of them are as valid as any other. Hard to find any reasonable place to make any sort of compromise. Another example would be devices that act as DMA devices when the processor is in a certain operating mode, but are attached to the processor's input and output ports in another operating mode. Both ways must be configured and available, plus some way to decide at any time which of the two options is to be used.
Gerry Schmitz 26-Jun-23 17:17pm    
Run time decisions; that's where I do my "functional" programming: public something TheThing => xxx ? aaaa : bbbb;
jekin77 27-Jun-23 12:58pm    
Try with INIs . Instead De-/Serialize XML just read a INI-File with you settings
For more see : https://blog.stephencleary.com/2009/05/ini-file-reader-in-c.html

1 solution

Well, I have found a solution. It's a little bit of work, but it will do the job.

As I now see it, there are two concerns that should be separated. One thing is the configuration, which I want to be serializable, the other thing are the emulator objects at runtime that do not have to be serializable.

The configuration basically is little more than a list of definitions of the components I want to emulate and how they are connected. A class factory takes this configuration list and constructs the runtime objects as specified and 'wires' them up. Problem solved.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900