Thursday, September 11, 2008

Code Downloads!

Downloads of all softHARDsoft code can now be found here: http://downloads.softhardsoft.com/

Reminder: the license I'm releasing the code under is Creative Commons: Attribution-Share Alike 3.0 Unported

The page will remain pretty Spartan but functional. Enjoy!

Zen of a Virtual Circuit

In How to make a machine "think" we considered a basic logic where:
  • Any piece's output can be another's input.
  • Use only 0 and 1 (boolean: TRUE and FALSE).
By meeting our second requirement (ie: by only passing around boolean values), we also satisfy our first requirement. If some items only accepted numbers, some only letters, and if outputs were similarly varied, then we'd have to specialize families of circuits right off the bat. As it is, all inputs and outputs are of the same type: boolean. Need the output of an OR gate to be the input to a transistor? No problem. Any output can go to any input as-is.

We now have the foundation for an infinitely modular system -- Logic LEGOS!*

So what is a circuit?

In a general sense, any piece of logical hardware can be a circuit. Any collection of circuits can also be considered a circuit:
  • transistor
  • inverter
  • full adder
  • Pentium processor
This is the beauty of our modular, LEGO-like architechture. With "circuit" being such a flexable term, we can build any manner of abstraction, and to us it's still just a circuit. It can still connect with any other circuit irrespective of how work is being done inside each one.

Not that there aren't differences. Never mind the stuff inside. The outsides are very different too. Transistors have 2 inputs and 1 output. Inverters: 1 in, 1 out. Full adders: 3 in, 2 out. The Pentium processor, lots of each. Obviously we won't be able to statically define how many inputs and output a circuit can have. But we do now have some basic definitions for our first interfaces:

Circuit: has some number of inputs and some number of outputs
Input: accepts a boolean value
Output: each emits a boolean value

All of our circuits, no matter how simple or complex, will boil down to this. They'll have some number of inputs, some outputs, and stuff hidden in the middle to turn inputs into outputs.

That's about all there is to say about this layer of the onion. Next we'll dig deeper on how our inputs and outputs need to relate to each other.


* From wikipedia: "The word LEGO® is a brand name and is very special to all of us in the LEGO Group Companies. We would sincerely like your help in keeping it special. Please always refer to our bricks as 'LEGO Bricks or Toys' and not 'LEGOS.'"

Yeah, well build a bridge and get over it. I've never met anyone who calls them "LEGO Bricks or Toys." Like it or not, everyone outside of that company calls them "LEGOS." I have nothing but the greatest admiration for these toys, but I have no use for their PR pride.

Wednesday, September 10, 2008

Art Imitating Life

In Transistors: Our Lowly Beginnings, I said:
I'm going to spend as much time as necessary getting a rock solid transistor emulator working.
I really meant not so much the emulation of the transistor proper, but rather the infrastructure that will be the foundation for the whole project. The first decision to be made about our architecture is:

How do we want circuits to work?

In circuitry schematics (which is to say: in real circuits): electricity travels in a closed loop. If the loop is opened (ie: interrupted, broken), then the electricity ceases to flow. The electricity always has to come from somewhere and go to somewhere. If we put a wire against a battery's terminal and touch the other end to a light bulb, the bulb stays dark. If we use another wire to go from the bulb's other terminal back to the battery's unused terminal, the bulb lights up.

In logic diagrams: there's a linear source/input and destination/output. The output is not required to go anywhere. If you connect a lamp to the output of a circuit yielding "on" (alternately: "high", "1"), then the lamp lights up.

Either choice would be acceptable. Creating a viable circuit would involve creating not only transistors, but also resistors and all other electrical components that make the physical processor function. softHARDsoft is ambitious enough without starting out that complex. In fact, I very much doubt we'll ever get that complex: at the beginning or otherwise.

The assumption behind our goals so far has been: we'll make a program that simulates a computer's logic at the most fundamental level. To this end, let's model our circuits not on real circuitry, but on logic flow. Let's use a non-looping system.

Tuesday, August 12, 2008

The August of Crickets

Man, it's so dead on this blog you can almost hear crickets. What happened? Are we running out of ideas? Did we lose ambition? Was it the car wreck?

No. There are 3 reasons why softHARDsoft has been so dead lately:
  1. Time is being split between this project and another one.
  2. Work has been stupidly overbearing and exhausting.
  3. sHs is now starting to move beyond casual blog posts and into the realm of real planning (so writing would be less frequent anyway).
sHs has certainly not been abandoned nor forgotten about. It just needs to take a back seat for a short time. We'll be back in full swing soon enough. To our few readers at this point: thanks for staying with us so far, and we promise to be back as soon as we can!

Friday, July 25, 2008

Transistors: Our Lowly Beginnings

The lowest level that softHARDsoft will implement is transistors. They work on pure physics and going any more basic than that seems a bit silly for our purposes.

Transistors can be used as amplifiers or switches. They are the bedrock of the rapid advancement of electronics over the last 60 years. These tiny wonders can be used to amplify signals (as they are used in transistor radios and hearing aids) and can act as on/off switches (as is the basis for computer logic).

In Transistor choice, it was explained that we'll start with bipolar junction transistors (BJT transistors). These have the most basic construction of all transistors and for our purposes, they'll work as well as any of the others. In fact, they'll work better than the others because they'll be the easiest for which to to write emulation software. I'm going to spend as much time as necessary getting a rock solid transistor emulator working. It cannot be emphasized enough that all computer logic comes back to transistors. Everything.

Anatomy
A BJT transistor has 3 regions: emitter, base, and collector. Here's how an NPN* BJT transistor works: When current is available at the collector, applying a tiny current to the base causes the emitter to emit an amount of current equal to the sum of the other 2. The sum of the currents is how amplification occurs. More importantly to us: the transistor acts as an on/off switch when we add power to or remove power from the base.

Now that we have a switch that is activated by electricity, we can use electricity to take action on other switches.

* There are 2 types of BJT transistors: NPN and PNP. The choice for which to use is arbitrary so we're using NPN.

Friday, July 18, 2008

How to make a machine "think"

Logic
I know we've really already predicted the answer to the question "what do we need?": we need the parts that make up a computer. But we haven't determined why those parts the most appropriate? Why transistors? What benefit do we gain from them? What will they allow a computer to do? For that matter, what do we need our computer to do in the first place?

What computers do is obvious. It's right there in the name. They compute. They take input data, make decisions, and give output data. To make decisions, there needs to be some kind of predictable logic.

What kind of logic can a machine use? This logic needs to be a type that a non-thinking thing can do on its own. There needs to be well-defined concrete input data. If we want to make complex decisions then we need a type of logic where the output data from one decision can be the input to another. To that end, no output can be undefined. If it were so, then we could have undefined input which we've already said we don't want. Our options for well-defined input/output is seemingly limitless: letters, numbers, words, etc. Is one type of input more useful than another?

Conveniently enough there is an existing logic we can turn to for help. This type of logic is well established, is fundamental in math and language, has very few rules, and the rules it does have are all simple: Boolean logic (also known as binary logic).

In Boolean logic, data can be either TRUE or FALSE (alternatively: 1 or 0, on or off). Our TRUE and FALSE can relate to each other in a small number of rules that resemble pre-algebra. In keeping with the obvious minimalist theme of this logic, there are only a few relationships (aka: operations) and each is based on only 1 or 2 inputs at a time. With the NOT operation, you can turn one input into its opposite. You can also see if two inputs are the same as each other (XNOR), if both inputs are true (AND), if at least 1 is true (OR), or if one is true but not the other (XOR). Really, XOR and XNOR can be derived from the other 3, so there are only 3 fundamental operations.

That's it. There's 100% of the basics of Boolean logic.

Although this feels very limiting compared to the possibility of using numbers and words, this is in fact all we need. For now please trust me. It'll be more apparent later.

Switches
Enough with the theoretical stuff, how do we get a machine to implement binary logic? Obviously, the on/off state of our data calls to mind light bulbs and light switches. All that remains is to figure out how to implement the 3 logical operations mentioned previously (NOT, AND, OR).

It turns out that the key to implementing the logical operations with electricity is just a matter of using switches wired up certain ways. If you want an AND situation, hook up 2 switches in serial. For OR, hook up 2 in parallel. For NOT, just change the switch's current position.

Electronic Switches: FINALLY, Our 1st hardware
Unless you want to sit there manually toggling switches all day, we need a way to have that part done for us automatically. We want switches that themselves can be controlled by electricity.

Enter: transistors.

And that's where we'll pick up next time.

Tuesday, July 15, 2008

Transistor choice

As I said in I know nothing, the inspiration for softHARDsoft comes from Charles Petzold's Code: The Hidden Language of Computer Hardware and Software. Throughout the book, Petzold designs a computer out of relays. Toward the very end of the book he reveals that transistors and not relays make real computers these days.

Although I knew this fact, what I didn't know until fairly recently is that the transistors of modern computers are not just the common BJT transistors* described in hobbyist electronics books. In actual processors, MOSFET transistors are used. Especially when MOSFET transistors are arranged in CMOS logic, there are significant gains in electricity usage and heat released. These are huge concerns when you're stuffing a few hundred million of these jokers into a couple of square inches. Not such a concern for sHs where all hardware is virtual.

However, that leaves me with a dilemma: do I try to really emulate a processor by creating the internals of my logic gates using MOSFET+CMOS logic, or just plain old BJT-styled transistors? For now I'm going to do the latter and revisit the issue later if I feel like it. I feel I can justify this choice because I am in fact looking at design a computer. It doesn't have to be accurate to modern computers. In fact, this whole project is ambitious enough without trying to hold myself to such standards; especially at the beginning.

* I realize that "BJT transistor" is redundant since the T stands for "transistor." But to amateur ears like mine, the sentence flows better than calling them "BJTs." Likewise with "MOSFET transistors" vs. "MOSFETs."