Complex Maths... WITH DRAGONS! by Jim Waterman for 1K/4K ZX80 9 April 2020 (in one afternoon, plus early evening debugging) ============================================================= "Burninating the countryside, burninating the peasants, Burninating all the people, and the thatched roofed cottages! THATCHED ROOFED COTTAGES!" - Strong Bad, 13 January 2003 http://homestarrunner.com/sbemail58.html ============================================================= "Improvise, adapt and overcome... and when all else fails, hit it with a big hammer." - "Bowser" Munsen, Scrapheap Challenge, series 3 ============================================================= Context ------- The internet was knocked out for the afternoon. No idea why - but I blame Corona-chan, and you can take revenge on her in the awesome 2020 CSSCGC game, Corona Capers (for the 128K Spectrum models). Anyway, enough self-publicity... this seemed like a good use of my offline time. The 2020 CSSCGC had earlier asked for a ZX80 program (a "game", even) for the old yoghurt pot's 40th birthday in February, but I had no good ideas at the time. I mean, it's not as if there's a lot that can be done on a ZX80, is it? But on the evening of 8th April, I had... an idea. Whether or not it's a good one, you decide. Saga ---- George the ZX80 was miserable. It was 1984, and he was thoroughly obsolete. He'd watched his three younger brothers usurp him - first, Nigel the ZX81, then Bob the Spectrum, and finally Chad the QL, the most arrogant of them all. They all liked to remind George he was as thick as two short planks and good for absolutely nothing. Even Nigel, who'd always been a D-grade student, outperformed George in just about everything. They even had the same horrid membrane keyboard, which Bob and Chad would taunt them both about. To top it all off, it was raining heavily. Well, it would be, because George was wandering the streets of Ebbw Vale - and in Wales, it is never, ever not raining. George was passing the Prince of Wales pub, watching a re-run of that time that Wales took the Grand Slam in the Six Nations, when a Dragon 32 spilled out of the door, quite obviously drunk. "Bore da, boyo!" said George, trying to be friendly to the Welsh computer. "DON'T YOU 'BORE DA' ME!" roared (XRoared?) the Dragon, in an American accent, revealing its true origins for those who didn't know. "THAT THATCHER BROAD CLOSED ALL THE COAL MINES, AND NOW I'M OUTTA WORK! THOSE UNION DUDES TOLD US WE'D HAVE WORK FOR EVER AND EVER AND EVER! LYIN' ASSHOLES! *hic* ANYWAY, WHAT YOU LOOKIN' AT, VARMINT? I KNOW YOU. YOU'RE A ZX80. YOU'RE STOOPID. YOU DON'T EVEN KNOW WHAT A DECIMAL POINT IS. NOW I'MMA OPEN A CAN O' WHOOPASS ON..." George wasn't going to take this lying down. "I challenge you..." he answered, "to a duel of mathematical prowess... with COMPLEX NUMBERS!" With these last two words, his TV modulator almost burst through his flimsy vacuum-formed case. The Dragon wasn't impressed. "You? COMPLEX NUMBERS? Ha! You and whose army?" George pointed to the player who had just downloaded this Crap Game, and typed LOAD, without any quotes, and (after fiddling with the volume for the third or fourth time to get LOAD to work...) RUN. What to do, if it wasn't obvious -------------------------------- You (U) playing the role of George, must slay the Dragon (>) - surely you all saw that coming - by correctly answering 20 sums involving complex numbers. Adding them is no problem, subtracting them requires more careful attention to the sign of all the terms, and multiplication is the hardest, requiring a knowledge of both multiplying out brackets and the definition of i, i.e. i² = -1. The Dragon may have had a point about the ZX80's utter lack of non-integer arithmetic, which would be needed for a fourth game involving complex division. The other three, though, the ZX80 handles with ease, and all it takes is the use of a few variables. Get a sum wrong and the Dragon will advance towards you, get 10 wrong and you will become a light mid-afternoon snack. Input your answer as the real part of the complex number (RE), followed by the imaginary part (IM) - and don't put the "i" on your input the imaginary part as the ZX80 will just sit there with the "S" cursor showing, waiting for you to realise you've been a brainlet. It is so childishly simple to cheat on this game that I'm not even going to bother pointing out how it's done. Suffice to say that if this wasn't a ZX80 and I had use of the VAL function to close that loophole (see, I'm even handing out hints), I would have done so. Development ----------- The bare bones of this was written on a Spectrum (well, BASin, actually) in about half an hour, with addition and subtraction combined into one program. It was then transferred to the ZX80... of course it wouldn't fit into 1K, so it was saved with a 4K RAM pack on. Multiplication was added, so all three functions were in one program. Then, program was split into three almost-equivalent programs, one for each function. The multiplication program - being the most complicated of the three - was pared back further and further until it would run, all variables included, within 1K, then this was modified into the addition and subtraction programs. As there were so many compromises just to fit one arithmetic function into 1K, the original was reloaded and heavily expanded to form the 4K RAM PACK SUPER DELUXE EDITION, for all those who own a real ZX80 4K RAM pack... or an emulator that can crank it up to 16K if necessary. The "U" and "<" are replaced with ultra-realistic graphics depicting George and the Dragon (note: graphics may not be realistic), the complex numbers are printed as they would be in a maths textbook (e.g. "I" rather than "0+1I" or "-6" rather than "-6+0I" - the only remaining flaw being the ZX80's lack of a lower-case "i"), and there is an expanded message the end for anyone bored enough to make it all the way through 20 correct sums. And, of course, "Bowser" Munsen's famous line, which I've quoted endlessly since 2000 when that episode of Scrapheap Challenge was first broadcast, was never too far away from this programming session. This time, I learned that the ZX80 doesn't have the <> token in its 4K ROM (or <=, or >=, but <> was by far the one I missed most). Still, there's nothing a few brackets and NOTs can't fix!