A little bit of an obsession

      No Comments on A little bit of an obsession

So I wrote this Python program to allow me to carry out certain kinds of calculations on binary numbers — you know, AND, OR, XOR and that kind of thing. It’s an absolutely essential tool for anyone who, you know, needs to NAND two 12-bit binary numbers. And happens to own a PiDP PDP-8 replica.

Okay, so that’s a very select group. A group that probably contains just me. If that.

But it was fun to write. And, to be honest, being able to see the bits for both the operands and the result displayed on the PiDP’s LEDs really helps you to understand what’s going on with bitwise operators. (The full list is AND, OR, XOR, NAND and NOR. It also adds and subtracts with LEDs providing carry and negative flags).

I figured it would be useful to have all the data displayed on a screen too. You have to have some sort of display — either a monitor attached to the PiDP or a remote session (serial terminal or SSH session) in order to run the program. I mostly use my HMV1950 project — and old radio repurposed as a Raspberry Pi case — to SSH in to the PiDP. It’s convenient because the PiDP sits on top of the HMV1950.

So I had all numbers — the one you’re keying in via the front panel switches, the two stored operands and the result — displayed on-screen in binary, octal, hex and decimal formats. Originally, I just had these print to STDOUT whenever there was a significant change. So the numbers just scrolled up the screen. And I convinced myself this was good, because it was like a printing calculator.

But I’m a control freak. A little bit OCD. Is there a way, I mused, to display the data in a more controlled fashion? Of course! Curses!

Fortunately, Python has an easy to use Curses library. It didn’t take long to adapt the bincalc.py program to bincalc_curses.py. Nor did it take long to find myself in a very familiar place — obsessing over the precise placement of each piece of data. Wouldn’t it be nice if this lined up with that. And I’d get to a point where I thought it was finished and think, ‘hmm, the top line, containing the data being entered, would be more readable if it was in inverse video’. And then a little later, ‘it would be more readable still with a blank line above and below’.

None of this matters, of course. Not for a program that, perhaps, three people will ever use. So where does the pleasure come from? Because there’s no doubt that these tiny improvements are weirdly satisfying. And it took me back to the days of coding in Basic on the BBC Micro. I spent many happy hours selecting the right mode with the right colours and just the right screen positioning for my programs. It’s amazing the different that adding a line can make.

Maybe this is why I like coding. It enables me to indulge my inclination towards obsession. And what’s so bad about that?

By the way, the photos on this page are already out of date. That’s right — I’ve already tweaked the code again.

You’ll find the latest versions of all the code, including the Python 3 library, here –>

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.