Real life demands attention, particularly during the week. So, I haven't been able to concentrate much on Fahrfall for a few days. However, I did find some time to figure-out how to read the joystick -- that should be handy!
The CoCo uses analog joysticks that return separate analog voltages for both X and Y axes of rotation. The values of these voltages range from 0-5 Volts, with the value corresponding to how far in the left/right (or up/down) direction the joystick is pointing. These voltages feed into one half of the CoCo's analog multiplexor. From there they can be routed individually to one side of the CoCo's analog comparator.
The button on the joystick is a digital signal, and once it is read it needs no conversion. But the analog values coming from the joystick need to be transformed into digital values in order to be useful to the computer. The CoCo has no Analog-Digital Converter (ADC) hardware. So, how is this handled?
The other side of the CoCo's analog comparator is connected to the output of the CoCo's Digital-Analog Converter (DAC). The output of the comparator feeds into one of the PIA ports. So all the CoCo has to do is route the desired joystick axis to the comparator, cleverly manipulate the DAC values, check the comparator result, and interpret the results in order to generate an approximation of the joystick's position. Simple, right?
At least one of the decades-old programming references I have for the CoCo actually recommends walking through all 64 possible DAC values in order to perform the analog-digital conversion. I suspect that a binary search starting with the MSB of the DAC would be much more efficient (~6 iterations). But I think my way is even better than that!
Get To The Point
Analog joysticks are fine for flight simulation, "precision" pointing, and maybe some other applications. But most people seem to prefer digital joysticks for arcade-style games, since what you really want to indicate is direction rather than position. I can't make the CoCo use digital joysticks, but I can make it treat the joysticks as if they are digital.
The algorithm that I am using divides each axis into three zones, one at each end with a "dead" zone in the middle. This allows me to find all the information I need for each axis with only two comparator cycles. For now I am using a 40/20/40% split for the zones. This leaves a dead zone that roughly corresponds to the width of the "trim" adjustments on the self-centering "deluxe" joysticks Tandy offered for the CoCo back in the day. This gives good sensitivity without much chance of leaving a joystick unadjustably off-center.
I haven't made much progress on Fahrfall this week. But I did put together a little demo to go with this post. The demo just reads the joystick and sets flag bits for each direction and the button status. The display portion of the code reads the flags and paints a corresponding red box on the screen for each bit set in the flags. It isn't much, but it proves the point. :-)
Well, that's all for now! Stay tuned for more info about the CoCo and further progress reports on Fahrfall!