Dr. Jim's BASIC dumping ground

Show us what you're working on, (preferably with screenshots).
User avatar
TMD2003
Manic Miner
Posts: 278
Joined: Fri Apr 10, 2020 9:23 am
Location: Airstrip One
Contact:

Re: Dr. Jim's BASIC dumping ground

Post by TMD2003 »

Image

This is a program I've had kicking around since at least 2002, and I've occasionally added to it since then (though not since 2006). It generates UK number plates, in white and yellow.

So I picked it up again (after watching a lot of HubNut videos, if you must know), and over the last couple of days I streamlined the BASIC - cleaning up variables, subroutines and the like that were a bit of a mess - and got that working with very few visual changes to what it was 14 years ago. Here's what it generates:
- 2001-present style plates up to the "20" series (i.e. AB20CDE)
- 1963-1983 suffix plates (i.e. ABC123A) and 1983-2001 prefix plates (i.e. A123ABC), including Q prefixes for kit cars
- Basic Northern Ireland plates with the most recent three letters, four numbers combination (e.g. ABZ1234, AIB1234)

The screenshot above is what I did today, making as good an approximation as I can get of the Charles Wright Narrow font that fits into two character squares. Letters are defined using capitals for the top half and lower case for the bottom half, numbers use their standard character for the top half and "CODE minus 176" (space to closed bracket) for the bottom half, most of which correspond to SYMBOL SHIFT plus the number.

There are a few "quirks and features", as Doug DeMuro would say, where I've done as much as I think I can to make the plates realistic:
- Plates up to a J suffix (31 July 1971) always appear as white on black.
- The Doovla specifies "undesirable" three-letter combinations that it will never issue (e.g. SEX, GOD, JEW and some odd ones like ABF) that I've held in a DATA statement - these are excluded, and so are the Manx three-letter combinations MAN and *MN.
- Likewise, "undesirable" two-letter combinations in 2001 plates (e.g. FU, NF) or others set aside for special use (e.g. GO, DR) as well as the J*, T*, U* and XG-XY combinations that were not assigned to regions have been excluded.
- Also excluded were the number combinations from prefix plates that were set aside for special use (i.e. 1-20, and all multiples of 10, 11, 100 and 111). Such numbers on suffix plates are fine, as the Doovla hadn't yet worked out there was money to be made that way.
- There are other oddities such as the abolition of X* as regional identifiers in the 1963-2001 plates after 1974 (and some had already been scrapped in 1964). I've taken this into account in a compromised way, in that *X* combinations can only occur on a black plate. Hence, you'll never see Richard's Rover SD3 from early episodes of Keeping Up Appearances (D541EXL, which is invalid), but you might see its replacement when the BBC realised their mistake (D541EFL) or the 1966 reverse version (EXL541D, which is valid and would appear white on black).
- Some regional identifiers were scrapped (e.g. *SY) or never used, but even though a table of these is available it's far too much hassle to implement it correctly so I haven't bothered. Plus it would slow down the program far too much more than it already is.
- Northern Ireland plates only show regional identifiers that have been used in Northern Ireland with the current system (three letters, four numbers) - so it's not just a random I or Z thrown into the second or third letter. For example: Belfast uses or has used *OI, *XI, *AZ, *CZ, *EZ, *FZ and *GZ as the second and third of the three letters; reverse combinations with a Z in the middle, for instance, were all used in the Republic of Ireland before the 1987 reform and are not included here. There's no way of knowing how far the current registrations have progressed, so I've allowed any combination from the current series (i.e. anything from AGZ1001, which is almost certain to have been issued, through to YGZ9998, which has not). The only recent combination I missed out was *YZ, used in County Londonderry (careful now) since January 2020, so there are barely any of them out there.

It's unlikely anyone will want to see this program in action, and besides I've got a bigger plan for it, so I'm not putting it on general release just yet, unless anyone wants to ask for a copy.
2 x
Spectribution: Dr. Jim's Sinclair computing pages.
Features my own programs, modified type-ins, RZXs, character sets & UDGs, and QL type-ins... so far!

User avatar
TMD2003
Manic Miner
Posts: 278
Joined: Fri Apr 10, 2020 9:23 am
Location: Airstrip One
Contact:

Re: Dr. Jim's BASIC dumping ground

Post by TMD2003 »

(Potentially) useful utility time!

This is a short(ish) program that I found I needed when trying to grab data from the display file and dump it elsewhere. For instance, for any given PRINT AT position, what are the eight addresses for the eight rows in the display file, and what address are the attributes held at?

I didn't have such a program, so I wrote it, with a lot of fiddling around with a spreadsheet. It also has PLOT positions thrown in for good measure.

Input PRINT AT coordinates (including the use of rows 22 and 23, i.e. the INPUT area) and the program returns the range of PLOT values in that square, the eight addresses for the display file, and the attribute address. PLOT coordinates will not be given for the INPUT area.

Input PLOT coordinates and the program returns the PRINT AT square the pixel is located in, the eight addresses for the display file, the attribute address, and a POKE for the display file that will insert a pixel at that position. Note that multiple pixels on the same row will require the values for the POKE to be added together - but you all know how the display file works, don't you?

Input a display file address and the program will first check to see if it is where pixels or attributes are stored. The program returns the PRINT AT coordinates, the PLOT range for that square, all eight display file addresses for that square, and - if the input is in the pixel range - the attribute address.

Image Image

Image Image

GET IT HERE, said Blackadder one day in a fit of desperation...
2 x
Spectribution: Dr. Jim's Sinclair computing pages.
Features my own programs, modified type-ins, RZXs, character sets & UDGs, and QL type-ins... so far!

User avatar
PeterJ
Site Admin
Posts: 3014
Joined: Thu Nov 09, 2017 7:19 pm
Location: Surrey, UK

Re: Dr. Jim's BASIC dumping ground

Post by PeterJ »

This looks excellent @TMD2003. Thank you for sharing.
0 x
Rate your favourite games with Spectrum Computing

All Ratings (With Filters)
Top 100 Titles (5+ Votes)
Bottom 100 Titles (5+ Votes)

Click here for the Spectrum Emulator Features Spreadsheet - Feel free to request edit rights to contribute

User avatar
TMD2003
Manic Miner
Posts: 278
Joined: Fri Apr 10, 2020 9:23 am
Location: Airstrip One
Contact:

Re: Dr. Jim's BASIC dumping ground

Post by TMD2003 »

See this thread for more details...

Here's the original C64/PET program - "Computer Haiku" by Commodore Educational Software, 1983

Once I'd discovered the original program was written in BASIC I thought I'd examine the listing and convert it for the Spectrum. Obviously, all the colours were going to be different and the layout was probably going to be different seeing as the Commie can handle 40 columns at a time.

Most of the original code was discarded as the Bread Bin has no PRINT AT or colour commands, and uses massive strings of system variables, POKEs and control characters instead - so the title screen, menu and instructions sections were all rewritten to make them look like the original, just in different colours. More system variables and control characters had to be worked round from line 1000 in the original (660 in this version), to make the haiku appear as it should. Generating it in the first place was more complicated on the Commie as - for reasons only known to the original programmer - the random number generator was set by the system timer. I thought it unnecessary to PEEK 23672 (the Spectrum's equivalent) and translate that - it's just using RANDOMIZE at the start of the program and then taking whatever comes from then onwards. The second line had to be generated first, so that the length of the line could be checked and junked if it was over 32 characters - one place the Commie had an advantage. I think my introduction and exit screens are far better than the original, though.

The original was full of error-checking routines which were unnecessary on the C64 but which would stop the program in its tracks if it was run on a PET that couldn't handle it. (There was probably a VIC-20 version as well, but with its horrifically limited text screen, everything would spill over onto two lines.) None of these were needed - all I had to do was condense the program after I found out it couldn't be loaded on a 16K Spectrum (see that as the equivalent of a PET in this case). This involved removing all the REM statements - which I've shown below just in case anyone wants to examine the structure of the program and make it easier - but it also meant wheeling out the old 1K ZX81 trick of using NOT PI, SGN PI, INT PI and a ton of VALs every time a numerical value appeared... and there were a lot of them. Still, that meant plenty of bytes were saved, and the program would run on the smallest Spectrum with ease. It now looks like a complete mess, but at least on a Spectrum the memory-saving tricks don't slow the process down anywhere near as noticeably as they did on a ZX81.

Image Image

Download the program
Write computing-based haiku
You have much honour.
3 x
Spectribution: Dr. Jim's Sinclair computing pages.
Features my own programs, modified type-ins, RZXs, character sets & UDGs, and QL type-ins... so far!

User avatar
TMD2003
Manic Miner
Posts: 278
Joined: Fri Apr 10, 2020 9:23 am
Location: Airstrip One
Contact:

Re: Dr. Jim's BASIC dumping ground

Post by TMD2003 »

In the beginning (28th March 2020), there was the Spectrum Hexadecimal Fraction Converter. A day later (and definitely not a dollar shorter), it spawned a slightly cut-down (and a lot slower) ZX81 version.

Later, in August 2020, a Dozenal Fraction Converter for both machines joined the Hexadecimal counterparts.

And now... it's time to unleash the awesome thromping power of... THE QUANTUM LEAP.

Image Image

Image

Image Image

Image

I've combined both programs, and converted them for the QL. Look at the result, there, in all its majesty.

The reasons 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 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

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. Think of Edith in 'Allo! 'Allo! and you'll get the idea. But despite its sonic shortcomings, this package does come with information about QL emulators and loading instructions for the raw beginner, which I was until April this year.
0 x
Spectribution: Dr. Jim's Sinclair computing pages.
Features my own programs, modified type-ins, RZXs, character sets & UDGs, and QL type-ins... so far!

User avatar
TMD2003
Manic Miner
Posts: 278
Joined: Fri Apr 10, 2020 9:23 am
Location: Airstrip One
Contact:

Re: Dr. Jim's BASIC dumping ground

Post by TMD2003 »

There's an F.A. Cup simulation from ZX Computing in 1983, which I typed in back in the day. This is its original version, though I've spotted a bug in the listing, and whoever typed it in thought "aha, I've fixed a bug!" but actually introduced one instead. I'll get that corrected soon enough. I've also modified it quite heavily, improved the sounds, tidied up the colours, and added a 42-character print routine (the one I was trying to find the origin of the other day) so that the teams could have 18 characters in their name.

However, for this season, Hampton & Richmond Borough have come all the way through the qualifying rounds to reach the First Round proper. And with 26 characters in their name, they're going to need a bigger boat... I mean, screen.

lrun mdv1_dr_jim_writes_for_the_ql_again_bas

Image Image

Of course, the QL comes to the rescue. There were a few slightly annoying roadblocks in converting this program to QL SuperBASIC, but I reckon it's all there. The QL isn't known for its colours in Mode 4 but I thought green for one season and red for the other would suffice - and I've included the teams from the 1982-83 season, i.e. when this program was first written, and 2020-21, where we are now. The fortunes of some of the teams have changed - not least Notts County, who were in the old Division One for the 1982-83 season, but aren't even involved in the 2020-21 First Round as some of their players tested positive for the Chinese-Bubonic-Plague-meets-Ebola-meets-Leprosy and they had to withdraw - but given that they should never have found themselves in the position they are now, in the National League, they really only have themselves (and their catastrophic mismanagement) to blame. (King's Lynn Town are in their place, which should make Martin Brundle and George Russell happy, at least.)

The same restriction applies to this QL version as in the original - that multiple replays always result in the teams being reversed from the original replay, i.e the home team in the original draw will always be the away team in all the replays. Then again, this was a type-in, not a commercial release. Other than that, I wonder if the QL has a different way of generating random numbers; even accounting for the built-in (and intended) bias towards home teams and the difference between the divisions, the first time I ran this simulation with the 2020-21 teams, Harrogate Town - newly-promoted into the Football League this season - beat Blackburn Rovers in the final. (The second run saw Chelsea win, which is more realistic, but still, anything's possible here).

And despite the QL's horrifically wobbly sound capability (in SuperBASIC at least - machine code may be able to do a lot better), I've made it beep out an off-key version of Back Home, which was resurrected int he mid-1990s as the theme tune from Frank Skinner & David Baddiel's Fantasy Football League. This is a Fantasy Football Cup, but let's not argue over small differences. All together now: "Saint aaaaaaaand Greavsie talk about the Endsleigh League, as if it's iiiiiiiiimportaaaaaant..."

Download the QL F.A. Cup - includes detailed loading instructions for QL noobs.
1 x
Spectribution: Dr. Jim's Sinclair computing pages.
Features my own programs, modified type-ins, RZXs, character sets & UDGs, and QL type-ins... so far!

Post Reply