Wires and Pins

Read time: 11 minutes (2988 words)

We looked at the idea of a digital component last time, and briefly mentioned wires and pins. Let’s look more closely at these things now.

Pins

A pin is just an attachment point on the side of our component. We will connect a wire to a pin and a signal of some sort will either arrive at that pin, or be generated by the part owning the pin, and that signal will move to some other place.

We can think of a pin as a simple container holding a signal value at any moment in time. Real pins do not actually hold a value, they are just pieces of metal we can use to connect things inside of the part to those wires. They form part of the piping system used to moves electricity around.

It will prove handy for us to model a pin as a container with a storage place for a signal value to be recorded. We will need to update that value, either by writing to it from inside of the part for output signals, or updating it from a wire from input signals. We will need to read the pin value so we can transfer a signal to the attached wire, or so the part can read the value coming in on a pin.

In addition to holding onto a signal value, we will also need to have a way to indicate that the pin is an input pin or an output pin. Furthermore, it is going to prove very handy to be able to name a pin, so we have some idea what it is being used for. That means our model will need to hold a string in addition to that signal value.

Wires

Wires are a bit more complex. One wire can only be fed from one source (a pin on a part). But a single wire can be attached to to the pins on multiple other parts. The attachments are always to pins set up to receive an input signal. If we tried to hook up two output pins to a single wire, the result would be a mess. Whatever data we were trying to move over the wire would be garbled.

So, our model wire needs to support one input and one or more outputs that we can “attach” somehow to pins.

The purpose of a wire os to transfer a signal coming out of one part to one or more other parts. We normally do not name wires (but we could). We do need to hold onto the signal value to be transferred. We will read the signal arriving on the wire from some part’s output pin, and “move” that signal to a set of input pins on other parts.

Hmmm, I am beginning to see how my simulated computer is going to be constructed.

Here is the basic idea:

Building a Computer

We need three basic classes:

  • A generic component class modeling some component with a set of pins connected to it. The exact number of pins depends on the gadget.
  • A pin class we can associate with a component.
  • A wire class that can be “connected” to a set of pins.

How will we connect things? Easy, We will use C++ pointers. Eeeek! Scary!

Finally, we will need a way to tell each real component we need to build exactly what it will do with those input signals to produce the output signals, and when to do all of that!

The “when” part of this is actually the heart of our simulation. We need to talk about time, and how it figures into our work!