F
ollowing a house move I reinstalled these fridge magnets and found myself organising them by type (noun, verb, adjective etc).
Naturally thoughts turn to writing a program to pick the words at random. As this involves a lot of string handling, it's a perfect candidate for using C and I've been looking for an excuse to try C for my RC2014 and possibly other 8-bit computers too.
I found the z88dk to be perfect, very easy to get up and running, a nice workflow with the zcc command and cpm target.
Here's the very satisfying result after a little work.It occurred to me that the same program should build for other targets that the z88dk supports (which is many)In fact it wasn't that simple. I had to change the code a bit to allow it to run on a Spectrum. But one bonus is that you can choose to build with a proportional font option, which looks really nice on the Speccy and suits this program well.
One of the issues I had was getting something random to seed the rnd function. The built program appears to hijack system interrupts, and so reading the usual counters didn't work, they return the same number each time. Waiting for the user to press a key and updating a counter in the mean time didn't work because the C functions for getting a character wait for the key to be pressed. (If I'm wrong about any of this, please tell me!) I'm sure there must be a neat way to do this that I haven't found yet. So my solution is to ask the user to type something random and randomize using the sum of those characters.That aside I'm really happy with the result and it's good to know that it's easy to write C for these computers, although for control-freak reasons I'll be continuing to use assembly except for certain scenarios like the string handling here.
Comments
Post a Comment