Hello all, time for a mega-post.
Intro:I was recently motivated to code something that produces much more than it assumes. Projects like this are usually more egg-headed, like creating programming languages, experimental computation paradigms, cellular automata, and so on. After fiddling with each of these for a while, I settled on something that should have been obvious from the start: binary circuits. After all, these are what computers are made of, so I should be able to simulate these kinds of things on a computer.
Remarks:After deciding on a proper data structure, the evaluation algorithm turned out to be quite simple to code. This thing works for highly parallelized, feedback-ridden, super ugly circuits, as well as pretty circuits. In fact, it's behavior is... dare I say 100% like what you get on a breadboard. I know this because I scoured YouTube for good videos, some of which are linked in this study, for working examples of known circuits. To my delight, the program I've got can easily handle any test I throw it. By "handle", I mean get *exactly* what the real circuit gives.
The reason I gather you here in this thread is not only to show off this program, but to offer a self-teaching crash course in digital electronics. (See the link below.) I had a lot of fun rediscovering precisely how data latches and other computing essentials were done.
More Remarks:So far, I've tested the heck out of "static state" circuits, along with "edge detection" circuits. We all know that *real* electronics depend on some rather subtle principles, yet this program ignores things like capacitance, inductance - even resistance, because we never had to worry about these in the first place. We're strictly making logic circuits, where if you test for voltage at any place, you'll find a 0 or a 1, no exceptions.
The code takes zero shortcuts to simulate circuit state and edge detection - there is no use of the timer, internal variables, cheat variables, loops, recursion, nothing. Everything is done with a minima of components, namely six: AND, OR, NOT, NOR, XOR, and Split.
Example:For one example, of which there are a total sixteen in the program, we simulate the four-bit adder, thereby creating a primitive "computer" out of logic gates. Observe the following schematic and program screenshot:
Manual:To understand what's going on here, it's highly recommended that you read the manual. I drafted this thing in Notepad with no spell check, so it's subject to updates. Anyway, on this page:
http://barnes.x10host.com/pages/Logic-Circuits.php... you'll see how circuits are modeled, how they're evaluated, and how the user interacts with the circuit. This program is exceedingly simple to use, and designing circuits turned out to be not as daunting as initially believed. I'll refrain from further explaining anything here, and defer to the above link for all elaboration.
Closing Remarks:While this program is a perfectly nice breadboard simulator, it begs to be expanded in any number of directions. Surely it needs a GUI. Surely it needs more inputs and outputs. Surely it needs a better way to skirt the arrays-in-types issue. I'm still deciding what the next direction, if any, will be.
Thanks for your attention