Well, I've done it. Sound the trumpets long and loud - though preferably with some device that uses an AY-3-8912 - because I've completed my first QL program! It's a combination and conversion of the
Hexadecimal and
Dozenal Fraction Converters I've been hosting on Spectribution.
Here's some screenshots for comparison. And if you want the QL screenshots (four of them) in the correct aspect ratio,
see this page.
The reasons for doing all this are obvious: the Spectrum's accuracy for conversion was limited by the number of digits after the radix point that could be kept on screen at any one time, if we want to see the computer show its working. The Spectrum could handle 30 digits, by cunning use of user-defined graphics for the numbers 10 to 15 (as well as those for "dek" and "el" in the dozenal system). The ZX81 had no such facility, so had to sacrifice one of those digits. The QL, in Mode 4, can display 85 digits across its screen. So there's only four colours available - but colour isn't important, this is all about accuracy. Knowing that there would need to be space for two digits in front of the radix point, this meant that it could accommodate 82 digits after the radix point - giving us a level of accuracy that still won't trouble WolframAlpha (where do you think I found all the values of the constants in two non-decimal number bases?) but will blow the Spectrum into the weeds.
The principle is exactly the same as before - take the string of numbers after the radix point, multiply the block by 16 or 12, the digit that appears before the radix point becomes the next digit in the final sequence, then this is subtracted to leave only the digits after the radix point, and the process repeats. As with the Spectrum and ZX81 versions, it's all shown on screen.
The other reason for converting this program to the QL was to get to grips with its far more convoluted user-defined graphics. The QL's character set has a whole load of foreign characters and symbols between CHR$ 128 and 190, all of which can be redefined if you know what you're doing, though the process is more similar to redefining an entire character set on the Spectrum, in that if one character is redefined, the rest disappear into oblivion. So even though I only needed two characters - for the dozenal "dek" and "el", I had to redefine the down-arrow, pi and phi symbols, and threw in an empty box for good measure. It look a long, hard, frustrating amount of battling with POKEs and PEEKs and channel pointers to understand it, and members of the QL Forum are trying to tell me I'm doing it the hard way, and these days with QL Toolkit II there's a CHAR_USE command which allows easy access to custom characters on multiple channels. Well, in the words of Frank Sinatra, I did it my way.
Or, rather, I did it David Nowotnik's way, because the routine I used is based heavily on the "Lunar Lander" program from his "QL Characteristics" article in the October/November 1985 issue of ZX Computing. By starting out with a routine that would print
his UDGs in window #3, I eventually managed to get them to be defined to any channel from 0 to 8, and then start defining the block from a character other than CHR$ 128 (161 is an ideal start point, so that the characters are produced by CTRL+SHIFT+A, CTRL+SHIFT+B, and so on).
The QL is a faster computer than the Spectrum, but it has 82 digits to contend with rather than 30, so it isn't too surprising that it takes a chunky 13 minutes, 24 seconds to produce a full answer. Here's the comparison below with the real values, as well as how the QL measures up against its older Z80-based siblings.
And a bonus point - this program also showed me I had made a mistake in the value of pi in the Spectrum and ZX81 programs, so these have all been updated to version 1.1 and the accuracy of their calculations has been corrected accordingly! And, strangest of all - the ZX81 was MORE accurate than the Spectrum for both hexadecimal and dozenal calculations of pi!)
Download the all-singing*, all-dancing Hexadecimal & Dozenal Fraction Converter for the QL
* NOTE: may not be "all-singing", or if it is, it'll all be off-key due to the QL's horrific implementation of sound in SuperBASIC.
And if you want the originals:
Download the NEW version 1.1 of the Hexadecimal Fraction Converters for the Spectrum & ZX81
Download the NEW version 1.1 of the Dozenal Fraction Converters for the Spectrum & ZX81