Saturday, 5 November 2011

My Work in Print: 1985

I've previously written about the very competitive crafting of optimum machine code programs for Personal Computer World magazine's 1980s Sub Set series, here and there. In 1985, the incumbent series editor David Barrow convinced Century Communications to publish two books of the best submissions. According to the descriptions on their publication history pages, these books were "Edited and produced working directly from the author's word-processor by NWL Editorial Services, Rushley, High Ham, Somerset" - a huge novelty in the publishing world at the time. Book geeks: note the cool adjacent ISBNs!

Best of PCW Assembler Routines for the Z80

Although the first IBM PC with its 8-bit Intel 8088 chip had already been available for about four years, still most business software was based on the CP/M operating system, and the more powerful, backward compatible Zilog Z80. Joined to legion Sinclair hobbyists, these users constituted quite an army. Here is the index of my contributions to the Z80 edition:
  • ECAL - Calculate error correction byte; pp. 70-71.
  • EFIX - Validate data with error correction byte; pp. 71-72.
  • NEWPC - Anticipate PC contents after next instruction; pp. 78-82.
  • RDM32 - 32-bit pseudo-random number generator; pp. 147-149.
  • SQR31 - Square root of 32-bit signed (positive) value; pp. 169-170.
  • SQR32 - Square root of 32-bit unsigned (absolute) value; pp. 169-170.
  • CURT16 - Cube Root of a 16-bit unsigned integer value; pp. 170-174.
  • CURT32 - Cube Root of a 32-bit unsigned integer value; pp. 174-176.
  • SDIV4 - 4-byte signed integer division; pp. 183-185.
Barrow, David (editor)
Best of Personal Computer World Assembler Routines for the Z-80
Century Communications Ltd
1985
ISBN 0 7126 0506 1

Best of PCW Assembler Routines for the 6502

While businessmen cycled their Z80s, many hobbyists with an aversion to dead-flesh rubber keyboards were devouring Commodore VIC-20s and 64s, and Acorn's BBC Micro. All of these used the MOS Technology 6502 processor. Here is the index of my contributions to the 6502 edition:
  • RINXY - Register Indirect addressing mode emulator; pp. 20-22.
  • ECAL - Calculate error correction byte; pp. 88-90.
  • EFIX - Validate data with error correction byte; pp. 90-91.
  • SQR15 - Square root of 16-bit signed (positive) value; pp. 125-127.
  • SQR16 - Square root of 16-bit unsigned (absolute) value; pp. 125-127.
  • SQR31 - Square root of 32-bit signed (positive) value; pp. 127-129.
  • SQR32 - Square root of 32-bit unsigned (absolute) value; pp. 127-129.
  • CURT16 - Cube Root of a 16-bit unsigned integer value; pp. 129-134.
  • CURT32 - Cube Root of a 32-bit unsigned integer value; pp. 134-137.
Barrow, David (editor)
Best of Personal Computer World Assembler Routines for the 6502
Century Communications Ltd
1985
ISBN 0 7126 0507 X

A Disassembler in ~1KB


Colleague C keeps reminding me that The SUBSET editor David Barrow was able to trim only one byte from John Kerr's compact code. What the hell is he talking about? The quote comes from this ZX Spectrum Utility, whose author explains: The stated aim was to write a Z80 disassembly routine in as short a space as possible and, at just over 1K (1090 bytes), it is a rather incredible program.

Unfortunately my DISZ80 routine was submitted too late - by about two years - for inclusion in the book, and I no longer have the magazine that it appeared in. At the risk of sounding a bit JR Hartley, if anyone out there has that 1987 issue, it would be good to be able to restore the line comments to the utility. I work in self-documenting, high level languages now, eschewing comments almost universally. But part of the strict Sub Set documentation standard insisted that every single machine code instruction got fully commented. Oh, and it would also be nice to see exactly where Dave Barrow's one-byte optimization appeared!

[Update 30 April 2012: This has now been done, many thanks to my new best friends Geoff Wearmouth and Stephen Parry-Thomas! See comments below, and also My Work in Print: 1987]

Cube Root Algorithm

I derived the method of cube root extraction used in both books, by applying a kind of induction by analogy to the existing square root algorithm. Dave thought my description of the process sufficiently interesting to publish it. Click for readability:



Next time: 1987

3 comments:

  1. Cool, where can I get the code?

    Why not assemble prints and code in a nice downloadable package :)

    ReplyDelete
  2. Hello John,
    My apologies to you and Colleague C. I think it was you who trimmed a byte from David Barrow's HEX print routine by using one DAA instruction instead of two.
    I am Geoff Wearmouth gwearmouth@gmail.com who typed your code into a real ZX Spectrum 25 years ago.
    I lost my magazines in 1993 and always intended to add the comments.
    A friend has located the MAY 1987 PCW and scanned the three pages that contain the bulk of your code. The rest is in the FEB/MAR/APR issues. He is on the case at the moment.
    Drop me a line and I will mail the scans to you.
    I shed a tear to see the pages again and I only half-inched the code.
    Although written on your CPC6128, it squeezed neatly into the bottom eight text lines of a ZX Spectrum and can disassemble any program or ROM.
    Cheers, Geoff Wearmouth

    ReplyDelete
  3. Hi Geoff,

    Good to hear from you, and great to know there are still others working to preserve all this old material. These have of course been particularly nostalgic recent days, with the Spectrum's 30th birthday just passed. As you rightly surmise, I would be ecstatic to become reacquainted with those code scans.

    "My CPC6128" - that made me laugh! My development system was an A4 notepad (ruled narrow feint & margin). Although my friend did have a CPC464, I don't think I ever did any kind of testing on it, DISZ80 was only ever debugged on paper. The CPC6128 was a fiction, designed to give the Sub Set editors some confidence in my code, so they'd publish it and send me a little money.

    Regards,

    John.

    ReplyDelete