Multiplayer Games and Floating Point

Multiplayer games are quite popular. That statement is not likely to be controversial. What might be controversial is my assertion that game developers are implementing network based multiplayer incorrectly. The sheer number of bugs related to desynchronization, especially between players on different platforms, on some games I’ve been familiar with over the years leads me to believe this is a much harder problem for many developers than it would seem on the surface. Here, I’m going to discuss one major source of problems: floating point numbers.

Continue reading “Multiplayer Games and Floating Point”

CPU Operations: Registers

Now that I have a clock source of some sort, I can move on to making components of the processor. Of course, there will be other bits required as well. Notably some sort of memory module and some sort of I/O system. However, those are not useful until I can actually do something with them so I’m going to focus on the stuff that does things, which is, unsurprisingly, the processor.

The processor will have multiple parts. These include components that handle addition, subtraction, boolean operations, and others, collectively known as an ALU or Arithmetic Logic Unit. It also includes little bits of storage where numbers are stored temporarily in order to do these operations. (There are a few other bits that will be needed but I’ll get to those later when they’re actually relevant.) Those bits of storage are called registers and that is exactly what I am going to look at next.

At the most basic, a register is just a small bit of memory, say 8 bits. Each bit of a the register can be built from four NAND gates taking a “set enable” signal and a data input signal, and providing a data output signal. Putting eight of those together with the “set enable” signals tied together gives an 8 bit register. This simple register has a level triggered set input. More complex logic can provide an edge triggered set signal. Conveniently, this simple design allows creating each bit from the four NAND gates on a 74LS00 chip so the 8 bit register can be created from 8 74LS00 chips. A schematic of such a design is below.

Simple NAND Gate Register

That’s rather frightening, isn’t it? It’s also more complication than I’m willing to put up with, however, given that there is a handy 74LS173 chip that provides a 4 bit register in a much more compact package which also supports edge triggered setting. Two of these chips can easily be combined to make an 8 bit register.

But the storage of bits is not the whole story. I also need to get data into the register. And also feed the data from the register to the ALU for operations to be accomplished. To figure out how to do that, a brief description of an ALU is needed.

At its most generic, which is all that is important at this stage, an ALU takes one or two inputs, performs an operation on them, and generates an output. Unary operations like shifts only need a single operand. Binary operations like addition require two operands. To avoid conflicts, three sets of data lines need to be connected to the ALU: two inputs and one output. You may be tempted to try to combine the output with one of the inputs. That way lies madness.

Ben Eater’s design uses two registers called A and B which feed directly into the ALU inputs and has the ALU output directly to the system data bus. (A bus is just a collection of lines, say 8 data lines, that are all related and run together through a portion of a system.) In his design, the ALU output is always showing the result of the selected operation based on the contents of his A and B registers. In that design, the A register connects to one input of the ALU and the B register to the other. That is a perfectly serviceable design, of course. However, I am looking for something slightly more flexible. (While I want something with similar capabilities to the 6809, I also want some additional capabilities.)

Instead of the above design, I want to be able to feed the contents of any register into the ALU on either input. That means I’m going to need *two* data buses, one for each ALU input, that the registers can all be selectively connected to. That is in addition to the bus that will connect to the output side of the ALU which will need to also connect to the input side of each register so the results of calculations can be stored back in a register. What this means is that we need a way to feed two operands into the ALU.

There are two ways we can do this. We can have a single bus that connects all the registers. In this case, we would need some sort of input operand storage in the ALU so that both operands of a binary operand can be fed into it. The first operand would get stored in, say, a latch, and then the operation would be done on the value in the latch and the value on the bus. This method has the advantage that it only needs a single data bus between the output of the registers and the ALU. On the other hand, it means an extra clock cycle to do binary operations since the first operand has to be sent down to the ALU first, taking one clock cycle, and then the operation can be done on the next clock cycle.

The other option is to have two data buses connecting the registers and the ALU. This requires a lot more support electronics including a second bus driver for each register. On the other hand, it also means that binary operations can be done in a single clock cycle since both operands will be available immediately.

In the interest of minimizing the amount of wiring and breadboard space requirements for everything, I have opted for a single input bus to the ALU. The disadvantage of requiring two clock cycles to transfer the operands into the ALU can be avoided with a higher clock speed. (Indeed, it is likely that the CPU will end up running an internal clock at a multiple of the external bus clock.)

Now that I’ve arrived at the design requirements for a register in this processor, I can take the 74LS173 chips and add some additional hardware to make the whole thing work. Because I want to have readouts of the current register value, the register outputs have to be permanently enabled. That means I can’t rely on the ‘173s tristate output capability (tristate logic has a third state which is “high impedence”, essentially meaning that the line is disconnected from the circuit; this is useful for shared bus situations). Instead, the outputs can be permanently enabled and fed into a 74LS245 octal bus transceiver which is also connected to the ALU input bus. It may also make sense to put another 74LS245 on the input side of the register to reduce the number of devices directly connected to that bus. However, that is not included in this initial design.

I will create the register contents redout using an LED bar graph chip (10 segment, all independent) because I have some and the bar graph chips fit nicely onto a breadboard and take minimal space, unlike the complications of placing individual LEDs. This is easy enough since it will just have 8 LEDs connected to the 8 output lines of the ‘173s which will be active all the time anyway. These will, of course, be connected to ground with the usual current limiting resistors. The readout is, of course, optional, but it’s useful for debugging and also, who doesn’t like a bunch of blinkenlights. If you want to leave out the readout, you can also leave out the 74LS245 and instead connect the output enable input to the ‘173s directly.

With all that sorted, I now have a design for each general register. There will be several special purpose registers that I will get to later. That gives the schematic shown below.

Register Schematic

Constructed on a breadboard, that gives the rat’s nest of wires in the picture below. Missing from the photo are the bus connections. The input connection will be on the left and the output connection on the right. You can see there is space on the left to add a ‘245 bus transceiver should it prove necessary. In the photo, the register has been loaded with decimal 255 (all bits set). As a variance from the schematic, I have left a space in the middle of the LEDs to group the bits in groups of four which makes it visually easier to read.

Register on Breadboard

Exciting, isn’t it? Now I just need to build at least one more of those.

The Clock Module

As noted previously, I’m working on a project similar to Ben Eater’s 8 bit breadboard project (see This time around, time keeping.

While it’s probably possible to build a computer without a clock and have it work, it’s quite a lot easier to keep things from going off the rails with some sort of time keeping. To do that, I need a clock module. The design of this one is essentially Ben’s design with some adjustments. (Edit: do take a look at MiaM’s comment below for a rather significant pitfall depending on your use case.)

Basically, it has four main parts. First is a push button with a 555 timer used to debounce it. Second is a variable rate automatic clock run by, get this, a 555 timer. Then there is a slide switch to select between manual and automatic modes running through another 555 timer. This is pretty much exactly Ben’s design. Finally, there is some glue logic that leads to two outputs: CLK (positive clock) and !CLK (negative clock). There is also an input, HALT, which when high will stop the clock.

The Clock Module

In the image above, the pushbutton and associated 555 timer is on the left. The adjustable oscilator and its associated timer are next to it. Then the mode slide switch and its 555 timer. The remaining three chips are a 74LS04 Hex Inverter, of which 3 gates are used, a 74LS08 Quad And gate which is fully used, and a 74LS32 Quad Or gate of which 1 gate is used. You can see the decoupling capacitors for each chip overtop of the chips themselves. The blue LED will show the state of the CLK output.

The CLK output is fed through an And gate with both inputs tied together. This is a quick way to create a buffer for the output which should ensure a clean output signal to the bus. It also adds a gate delay similar to the inverter on the !CLK output, which should also ensure a clean output signal. The two clock outputs are the jumpers that are not connected. The jumper connected across to ground is the HALT input. CLK and !CLK will be fed to the bus which HALT is a control signal that will ultimately be provided by the control logic when it is created. There is no significance to the colour of the wires.

I have included a schematic of the module below (assuming I didn’t make any errors creating the schematic). It’s in SVG format so you should be able to scale it up to read it. As far as I can determine, it works though I haven’t put a scope on CLK output to see how clean it is.

Embarking on a Breadboard Adventure

A couple of years ago, I encountered the breadboard computer project by Ben Eater over at I found the idea interesting so I purchased his kits for the 8 bit breadboard computer project. I then embarked on the project and put together all the modules. It “worked” for some value of “work” but there were clearly some issues with it. Given the complexity of it and the number of bits where it violates good design practices (it’s a hobby learning project), I was unable to definitively trace the problems. I have some theories, however.

I have now decided to embark on a new project. I’m still going to build a breadboard computer with an 8 bit processor. However, I’m going to build my own design rather than Ben’s. His was fun, but it’s my hobby so why not?

So, I have a couple of rules for this project:

  • All ICs get decoupling capacitors. In the worst case, that does nothing but it should help a lot with instability.
  • All unused inputs on logic gates get tied high or low. A similar situation for other types of chips where it makes sense. Basically, avoid floating inputs.
  • Lines should be buffered between a module and a bus to avoid feedback and other complications. Where possible and practicable, high impedence (tri-state) should be used. This is to minimize the load for anything driving the bus.
  • Components are mostly limited to basic parts (resistors, capacitors, diodes), 74-series logic (and other) chips, and items where appropriate (RAM for instance). Components used should not be listed as “obsolete”.

The overall goal is to create a computer that has roughly the capabilities of a MC6809 CPU. That’s a long way down the road, however. What that means, however, is that there will be an 8 bit data bus and a 16 bit address bus between the processor and the memory and any memory mapped I/O devices. What the internal connections within the processor look like is undetermined at this time.

My general plan is to add entries here as I work through the project. As we all know, however, I’m likely to forget or get bored with entries so if they stop, well, maybe poke me and see what’s going on.

The next post will be about the actual build.

Alberta Government Health Records Site is Worthless

So I thought it would be cool to be able to log in to the Alberta government’s “MyHealth” site to get access to various health records. I mean, it sounds useful to be able to see that stuff, right? Well, it might be. If it worked.

Well, I went through the steps to authenticate which involved waiting for a code in the mail and a few other things. That part worked well enough and logging took me to some sort of dashboard with a great big widget to click on to access my health records. So I clicked on it.

I watched my browser step through loading a number of things which isn’t particularly unusual for single sign on type things like a government account thing. And then it landed on a page that proudly proclaimed “OOPS! There is a problem” and noted that I was signed out. It then suggested I should be using Firefox or Chrome or Edge or Safari. Well, I was using Firefox. Okay then. So I tried Chrome. Same thing. So I tried Edge. Same thing. I can’t try Safari since I’m not on a Mac.

The text says “MyHealth Records does not work with your current borwser or operating system.” Okay. So I’ve ruled out the browser being the issue. That leaves operating system. (I’m not using Windows either.) Okay, pop quiz: what the fuck does my operating system have to do with a web site? If you answered anything other than “nothing”, you’re part of the problem.

So. The Alberta government has created a site that’s meant to make accessing health records easy. And they’ve fucked it up to the point that unless you’re using Windows or Mac (as far as I can tell), it doesn’t work.

If you’re reading this and you’re responsible for a major web site, go check your site on an operating system other than Windows or Mac. If it doesn’t work on, say, a modern version of Linux like Ubuntu or Mint, rip your web developers a new one. There’s no excuse for that. Period. And, no. You do not ever need anything that is operating system dependent on your web site. Ever. Especially if your organization is part of a government agency.

US Election Results

So as of this writing, it looks like Biden has won out over Trump to take over as President of the United States in January. Overall, I think this is a bad result for the United States as a whole, but that’s not why I wanted to write this. I have a few points I want to make here which don’t form any sort of narrative or support either side of the race.

  • The pollsters were wrong about the results. Yes, most of them correctly (as of this writing) identified Biden as the winner. However, they were predicting a substantially wider margin. Substantially. This suggests some underlying bias in methodology or other flaws in the polling. Perhaps Trump voters didn’t want to admit to anyone who they supported for fear of violent reprisals or worse. Or perhaps the polls had leading questions. Or failed to achieve a proper representative sample. Still, they were wrong about the magnitude of the win and that’s important when analyzing polls.
  • There are allegations of election tampering from various states won by the Democrats. Some of these allegations include Republican voters being given pre-spoiled ballots or given the wrong implements to mark them, thus guaranteeing them to be counted as spoiled. There are also allegations that more votes were cast than there are eligible voters in one state with a very narrow margin. There are additional allegations that Republican observers were not permitted to observe from a location where they could actually observe anything. Regardless how credible you think these allegations are, because of how close the electoral college is, and which states have these allegations in play, it is important that they are investigated thoroughly and quickly. It could potentially, lead to the results flipping in Trump’s favour depending on the outcome.
  • It’s not likely that either Trump or Biden had anything to do with any shenanigans related to the individual state elections. If either “side” is guilty of anything, it will be local officials or citizens who undertook whatever shenanigans occurred.
  • The election isn’t actually complete until the electoral college meets and does its job in December. It’s still possible, though extremely unlikely, that electors may disregard their state’s vote and vote for Trump (or vice versa). Faithless electors (as they are called) have occurred in the past and they are not strictly forbidden, either. No, I don’t think the result of the election will change based on faithless electors, but it’s not impossible.
  • Lest anyone think any legal chaos or challenges will lead to having no legitimate president come inauguration in January, there actually is a failsafe built into the procedure: if the election results fail to be certified appropriately, Congress makes a final decision. That could still lead a deadlock since it isn’t a simple majority vote, but in the event that there is too much uncertainty, Congress gets to choose a winner.
  • The United States could stand some electoral reform with respect to the process of actual voting. I am specifically not referring to the electoral college because that is actualy working as designed regardless what people actually think. No, I’m referring to how voting itself is handled. There needs to be a consistent set of election rules across the entire nation and the processes need to be as immune to tampering as possible. In my not so humble opinion, that means paper ballots with a clear marking on them placed in boxes with paper based controls against duplicate votes. Identification requirements are probably reasonable. Counting needs to be done with scrutineers representing all candicates allowed to be present and those scrutineers need to be able to examine all the ballots being counted. No fancy voting machines with punch cards or the like. Absolutely no electronic voting machines. Do it the old fashioned manual way. It’s about as immune to tampering as it’s possible to get.

That’s about all I have to say at the moment. Just some random thoughts related to the US Presidential election.

Is COVID-19 Worse Than Influenza?

Ever since COVID-19 appeared, the doomsayers and their ilk have been banging on about how this is the worst health crisis in the history of humanity. Well, maybe most haven’t been going quite that far, but there’s definitely a cadre who do. But is it really worse than other endemic respiratory infections such as influenza? I’ll be honest: I don’t actually know. And neither do you. Here’s why.

Since COVID-19 appeared, we’ve been doing crazy levels of surveillance for it. And, in many cases, erring in the direction of assuming COVID-19 even without positive tests to back up the assertion. Some jurisdictions have done better with their reporting than others. Alberta, for instance, seems to have a somewhat better approach than much of the United States, for instance, by virtue of having ramped up testing far faster and sooner than most. Naturally, with the heightened level of surveillance, we find a lot of infections that would otherwise not be known due to people having very mild symptoms or even none at all.

So how does this compare with influenza? Well, we don’t actually know. We don’t do anywhere near the same level of surveillance for influenza as we currently do for COVID-19. We also don’t panic and institute massive lockdowns and quarrantine periods when a case of influenza is discovered. Nor do we obsess and panic over elderly patients dying from complications from influenza. Nobody reports the statistics for the number of cases of influenza nor the deaths from those cases. Maybe the health authorities do have that information, or have information that is somewhat comparable, but I doubt it. Without a similar testing regime for influenza, we can’t know what the actual case counts for it are. Without the same level of testing, we won’t know how many “colds” were actually influenza. We won’t know how many people had a strain of influenza without getting sick at all.

Of course, that comparison isn’t quite fair. “Influenza” is a class of virus, much like “coronavirus” is a class of virus. It would be far more fair to compare individual strains of influenza against COVID-19. But we aren’t doing that sort of testing so we don’t have the numbers. At least not publicly. But we also need to remember that there are other coronaviruses that don’t do much more than cause the common cold. (Colds are caused by other viruses than coronavirus, too. Like rhinovirus and RSV.)

Also it’s important to note that COVID-19 is problematic because it’s new and, thus, nobody had any immunity to it prior to this pandemic. At least ostensibly. I’m not personally convinced by that. It is at least theoretically possible to have some level of resistance due to having a variation of coronavirus that is somewhat similar to COVID-19. It’s also possible that COVID-19 was moving through the population for some time before flaring up like it did and it was simply not noticed. Even so, it’s clear that there has been a large scale increase in infections.

What is not clear, due to lack of reliable information about other endemic respiratory diseases, is whether the fraction of servere outcomes for COVID-19 is particularly high compared to, say, “ordinary” pandemic influenza. Clearly, given the lack of panic over other endemic respiratory diseases, we do not generally find the incidence of severe outcomes from them worrying. So it follows that if the rate of such outcomes with COVID-19 isn’t actually significantly different, then we probably shouldn’t be panicking about COVID-19, either.

Basically, the point of this is that health officials need to start releasing comparable statistics for all extant respiratory diseases. And, to get those comparable statistics, we need to be doing the same level of testing and analysis for those diseases as we currently do for COVID-19. Maybe we are doing that level of surveillance and the information isn’t shared, but I somehow doubt it. Regardless, without that information, it’s impossible to make a properly informed choice about what to do about COVID-19 and it allows COVID-19 to be used as a convenient issue to push whatever agenda any particular person or group has. So let’s call on health officials to drown us in accurate numbers for everything. Not just COVID-19. Seems to me that if they do that, at the very least COVID-19 won’t seem quite so bad as it does when its statistics are reported in isolation.

Racism and Black Lives Matter

Okay, now that click bait has been achieved, let me start by being perfectly clear: I do not condone racism of any kind, period. Making assumptions about a person based on the colour of their skin or the shape of their eyes or whatever is plain wrong. I had originally written a lengthy diatribe about how Black Lives Matter (BLM) is racist itself among other things but it read like an angry rant so I decided to spare everyone that. Instead, I have a couple of points about the current landscape.

Continue reading “Racism and Black Lives Matter”