Monday, 30 April 2012

My Work in Print: 1987

Previously: 1985

DISZ80 - a Z80 Disassembler

Delighted today, to receive a comment from Geoff Wearmouth on that previous Personal Computer World: Sub Set article. Geoff it was, who first typed my 1094-byte Z80 disassembler DISZ80 into a Sinclair Spectrum some quarter century ago. His site gathers Sinclair ZX Spectrum ROMs, as well as emulation tools for the related ZX80, ZX81, and the eternally awe-inducing Jupiter Cantab Ace.

Geoff's own Spectrum Globeplotter, featured in The Register Hardware's Basic Instinct last week, and itself more than a quarter century old, proves us to be PCW stablemates. Whilst presented as a BASIC listing, this spinning-sphere-transpoising, sinusoidal-Mercator-projecting screen plotter actually employs untold amounts of custom crafted machine code.

Some ten years ago, Geoff made appeals in comp.sys.sinclair for any further information about PCW back issues. And just today, Stephen Parry-Thomas of has replied, with full scans of Sub Set from February-May 1987. At last, the extensive line comments can be restored to my crusty old utility!

February 1987

Click to big. In "Z80 Radix Conversion" David Barrow starts off with CONVHL, which is used at various points within the main disassembler to convert 16-bit integers to various bases (binary, octal, decimal, hex) for readable output. He remarks upon the "quite ingenious" optimised method used to convert raw digits to ASCII.

I remember being quite happy with the way David had split out the various modular components of the program. Publishing these in multiple datasheets over several months resulted in a steady stream of payments, giving a pleasant illusion of gainfully paid employment!

March 1987

March saw the publication of routine XTRACT, designed to read and print strings from a table. As David correctly notes, this too is pathologically storage space optimised, for both code and data table size.

April 1987

The I/O fest continued in April with a set of five connected utilities dealing with the output of hex data and addresses. This is the point at which David, having correctly diagnosed my space optimisation compulsion, shows where I could have saved one program byte, two stack bytes and 14 clock cycles. Though 25 years later I've still to validate the assertion, respect for David's manifest expertise compels me to believe it, albeit truculently.

May 1987

The May edition was given over to just the two remaining big routines, spread across five new datasheets / appendices, and completing the 1094-byte Z80 disassembler.

So, once again: hooge thanks to the guys, Geoff Wearmouth and Stephen Parry-Thomas, who got these page scans to me - I do hope you'll both understand and forgive the indecent haste with which I've posted them here.

Try It Out!

Finally, Geoff's just been in touch again to tell me that DISZ80 is actually live online, and has been for years, embedded in his ZX Spectrum Emulator. How cool is that? Click here to run it. I just tried it out using Internet Explorer 8, 64-bit (!) version. Click the "screen" then press Enter for instructions. The Disassembler itself can be disassembled (!!) by typing the address $5100 then pressing Enter. The code you see starting at that address is actually the DISZ80 entry point, as illustrated in the first of the May 1987 pages above. Mind = Blown!

Sunday, 29 April 2012

April in Embo

Photo Essay: Easter Break Snaps

Look mum! The sand's back.

Eek! A periscope.

The Russians have been watching this place for years.

Home from home: the new Linnhe caravan (6-8), introduced just this year. With sun deck! (Sun not included)

Look at those bananas. Just look at them.

The neighbours.

This is the life.

Some nice weather.

Garden fence conversation.

Handy for the beach.

Moody, broody, old North Sea.

The old pier, no longer accessible - officially. Thanks, HSE!

The view towards Portmahomack. Wonder if we'll ever find that lighthouse?

More neighbours: the Loch Fleet seals basking at low tide.

Dornoch International Airport.

Windsock action closeup.

Dunrobin Castle, Golspie.


More grounds.

Still more grounds.

Clynelish Distillery.

Clynelish Distillate!

Day trip to Ullapool.

Encore en route.

High art concept shot!

Are you lookin' at me?

Are you lookin' at me?

Arrival at sunny Ullapool.

The obligatory scenic diversion to Achiltibuie.

More scenic ridgery.

We found it! It's in Tarbat Ness (we love lighthouses).

Photos copyright © 2012 by Linda Kerr, except those containing Linda, which are copyright © 2012 by me.

Friday, 13 April 2012

Tri-State Logic in C#

First, a Story About Trees

Certain friends and colleagues, asking me about the origin of my "Stanislaw" Facebook persona, have already been introduced to the shady night dweller "Stanislaw the Philosopher". Found in and around 1980 sweating over some maths and engineering textbooks in the wee small hours, listening to Mike McLean Through the Night on Radio Clyde, and occasionally sending in record links in the form of unbearably awful puns. Like this:
The king's gardener feared for his life. Long and hard he had toiled in the royal grounds, trying desperately to make the castle's fir trees thrive in the dry, dusty and too-barren earth. Nothing would work to save them. And now that his life was forfeit, he had begun to see ghosts during his nightly rounds. One of these came up to him, holding forth a small cloth pouch, and saying "These are the droppings of the kestrel hawk. Lime for this climate, bone for these flora. You must feed it to their roots, one and all. For either you and they shall die, or else neither."

The gardener did as he was bid. Three nights later, walking through the grounds in the dark of an otherwise still night, he now sensed those trees rising up before and around him, moment by moment blocking off a little more of the violet horizon. Was this truly and solely an imagination? Then too, he began hearing something wholly unaccustomed and chilling on the air, what was that sound? The raising of a distant breeze, the creaking of old bones and branches, the arrival of some new monster unseen?

Or kestrel manure firs in the dark?

On another occasion, Stanislaw the Philosopher posed a riddle from Raymond Smullyan's book of logical puzzles, What Is The Name Of This Book? The hardback book itself was sent to the radio station as a prize. Stanislaw then sent in the correct answer under the guise of his good friend Tom, who was subsequently baffled to receive such a book, from a radio station he never listened to, as a prize in a competition he'd never heard of.

But Seriously...

This whole confession is prompted by Eric Lippert's blog Fabulous Adventures in Coding, and in particular by today's entry, null is not false, part two. Eric starts off by using Dr Smullyan's deductive logic puzzle books to introduce the concept of multi-valued logic systems, including the nullable boolean. This 3-state scheme has the possible values: true, false, and null.

The rules of null are quite straightforward and obvious, if you think of replacing it everywhere with "unknown". So for example in arithmetic, we would have
X + null = null,
which translates as the self-evident "Anything plus unknown, equals unknown." Now in our 3-term logic,
false AND Y = false,
since whatever the second term might represent (including null), the first false makes the expression false. But this also implies that
X AND false = false,
which can be a problem for computer languages featuring short-circuit boolean evaluation. Eric considers the cases of the C# operators && and ||, which are specified as strictly short-circuiting operators, and asks the question, how should we evaluate
X && Y
when X is null? The truth table gives unambiguous answers: false if Y is false, otherwise null. But to obtain that answer we had to violate the specification that Y is only evaluated when X is true. Eric closes by saying "...either we sometimes evaluate Y when we shouldn't, or we sometimes return a value that does not match the value that X&Y would have produced. The way out of this dilemma is to cut the feature entirely."

So, the operators && and || are not "lifted to nullable". That seems a shame! I'd have preferred the alternative way out of that dilemma, where we allow nullable overrides of these operators, and simply replace the pair of statements
In the expression X && Y we evaluate Y if and only if X is true
In the expression X || Y we evaluate Y if and only if X is false
In the expression X && Y we evaluate Y if and only if X isn't false
In the expression X || Y we evaluate Y if and only if X isn't true