O frabjous day! We may not have been shortlisted for a British Microthingy Award, but over Easter I received the British SF Association Award for a story in Interzone magazine (plug). What, you ask, has science fiction got to do with Apricot computers? Well, not only is Apricot literature full of glittering, impossible SF concepts like "Xen IBM compatibility", but the SF author Gene Wolfe actually predicted an important feature of our machines in a novel dated 1980. Here the lead character, a professional torturer, mentions a trick of his painful trade: "the excruciation we call two apricots". If that isn't a stunning prediction of the now-famous BIOS incompatibilities, my name's not Nostradamus.
Unauthorized tampering
Everyone talks about the amazing power of DEBUG to patch program files, but the actual details remain obscure. Perhaps those who've mastered the technique don't want to share their lucrative secrets. Perhaps they're afraid of recriminations from software houses (who sometimes object to tinkering)... or from users, who get unreasonably upset when an incautious keystroke in DEBUG wipes a master program file. Nevertheless, here goes.
We start with a popular SuperWriter query: is it possible to correct the program's vile habit of giving dates in American format, with the day and month switched? This happens when you use SuperWriter's \%DATE\ system variable -- also \%CDATE\ (file creation date) and \%MDATE\ (date of last file modification). Yes, we can change all three.
First, the usual precautions. One: don't use your normal working disk. Format a new one, copy the SuperWriter files across to it, and add a copy of DEBUG.COM. Two: while in DEBUG, count slowly from one to 0A (hex) and allow your whole past life to flash before your eyes before you enter a W command. Three: if in doubt, enter Q for Quit and start again. Four: when in spite of all the above you manage to enter W 100 0 0 10 and destroy your Disk A directory, intone this Coptic Apophthegm translated for you by my wife: "These things happen to me because of my sins." (In other words, don't blame me.)
To boldly debug....
If anyone's still reading, here's the routine. Pop the DEBUG plus SuperWriter disk into the default drive, and at the A> prompt type DEBUG SW.COM followed by Return. All DEBUG commands end with Return, so let's not waste our editor's valuable space by repeating this henceforth.
The effect of this command is to load DEBUG and then load SW.COM, the main SuperWriter program, into the workspace. It lies there at your mercy! All you see at first is the DEBUG prompt, a hyphen (in some editions, a > sign). If you type D for Dump you'll see the first 128 bytes of the file, thus:
0100 E9 48 72 53 75 70 65 72-57 72 69 74 65 72 20 28 iHrSuperWriter ( 0110 74 6D 29 0D 0A 43 6F 70-79 72 69 67 68 74 20 31 tm)..Copyright 1 0120 39 38 33 20 20 53 4F 52-43 49 4D 20 0D 0A 53 2F 983 SORCIM ..S/ 0130 4E 2D 30 30 30 30 30 30-2C 20 4D 2D 53 20 44 4F N-000000, M-S DO 0140 53 20 31 2E 30 33 45 31-20 38 34 2F 30 38 2F 30 S 1.03E1 84/08/0 0150 31 20 31 33 3A 34 33 0D-1A 33 33 30 34 41 50 52 1 13:43..3304APR 0160 49 38 30 38 36 20 20 20-20 F1 00 90 C3 90 E9 09 I8086 q..C.i. 0170 00 00 00 90 66 5C 66 E9-F3 72 33 C0 C3 E9 82 03 ....f\fisr3@Ci..This is SuperWriter 1.03; version D1.09 is similar (see below). The numbers on the left are hex addresses: I've omitted the confusing segment information, an extra group like 209A: at the start of each line. Those in the middle are hexadecimal bytes of SW.COM. On the right are ASCII characters represented by these bytes (control codes etc. becoming full stops). The first three bytes are actually a machine-code command, as seen by typing U 100 (U for Unassemble):
0100 E94872 JMP 734B 0103 53 PUSH BX 011C 68 ...rubbish.In other words, SuperWriter starts by "jumping" past the copyright information, constants, variables, subroutines and God knows what, to begin its dirty work at location 734B. A final experiment is to enter R CX (R for Registers) and find what's in the CX register:
CX 7A00 :Hit Return at the semicolon prompt (which is inviting you to change the CX value) and you get back to DEBUG's hyphen. 7A00 hex is 31232 decimal, the size of this SW.COM file. The information is there for DEBUG rather than you -- this is the number of bytes DEBUG will write to SW.COM if you press (take a deep breath) W.
So far, so boring. How do we get from here to a date format modification?
Inside information
Step forward, the wonderful and exceedingly expensive Microsoft MS-DOS Programmer's Reference Manual. The important insight is that SuperWriter has to extract the date from the operating system via an MS-DOS function request -- in other words, an INT 21 call of the sort I discussed in Apricot File Release 1.5. According to the manual, "Get Date" is function call 2A hex, and this returns the month and day as the high and low bytes respectively of the DX register.
Momentarily abandoning SW.COM, let's clear out the DEBUG workspace for a quick experiment: F 100 FFFF 0 ("fill memory from location 100 to location FFFF with zeroes"). It is not a good idea to enter W at this stage.... Instead, using the DEBUG A-for-Assemble option, we can assemble the two instructions which make up a "Get Date" function call:
-a 100 100 MOV AH,2A 102 INT 21 104Entering a blank line (Return only) gets us out of "Assemble"; entering U 100 gives us the hex machine-code translation. With a profound sense of spiritual insight we learn that our two instructions translate to the four bytes B4 2A CD 21.
If we can find this byte sequence in SuperWriter, then with luck we'll have found a "Get Date" request to the operating system. (If you cleared the memory and went through the assembly rigmarole, don't forget to Quit and reload with DEBUG SW.COM at this point.) Happily, DEBUG has a Search function, and the following translates as "search from location 100 to the end of the segment for the pattern stated":
-S 100 FFFF B4 2A CD 211FBE is DEBUG's reply -- omitting the preceding segment number as usual. The obvious witty retort is U 1FBE to have a look at that bit of the program....
1FBE B42A MOV AH,2A 1FC0 CD21 INT 21 1FC2 890E0508 MOV [0805],CX 1FC6 86F2 XCHG DL,DH 1FC8 89160708 MOV [0807],DX 1FCC B42C MOV AH,2C 1FCE CD21 ...and much more.Now this is interesting. The year, from CX, is MOVed into memory location 0805; the month and day, in DX, go to 0807. But in between, presumably in a hasty US-format correction for the Document History, the month and day are swapped! XCHG DL,DH means "swap the low and high bytes of the DX register".
Our next experiment is now obvious. We zap that two-byte XCHG instruction at location 1FC6. Like this:
-A 1FC6 1FC6 NOP 1FC7 NOP 1FC8The blank line is again a Return, leaving 1FC8 untouched.) Since the NOP -- "no operation" -- assembler instruction produces a machine-code byte of 90 hex, you could instead use the E for Edit command:
-E 1FC6 90 90...or, for those with SuperWriter D1.09, where the addresses are slightly different: E 2012 90 90. That done, it only remains to write the altered SW.COM to disk. With nerves of steel you poise your finger over the W key, press it, think again, go back and check with the D or U commands to make sure you did it right... and hit Return. Then finish with Q.
Afterthoughts
The good effect of this patch is that \%DATE\ now inserts the date in proper dd/mm/yy format when you print a SuperWriter document. Of course, nothing's perfect! The day and month will appear the wrong way round on the Document History menu. Conversely, \%FDATE\ and \%MDATE\ will give US-format results with files created before you patched SuperWriter, since they're read and held in the Document History.
Tiny snippet of the month: if you have a printer like the Epson LQ-1500 which has a "letter quality" option not normally accessible from SuperWriter, try the CHARSET embedded format command (as not found in the manual) with a number from 1 to 4. For example, \CHARSET 2 will set letter-quality print on the LQ-1500 when this printer is installed in SuperWriter 1.03. \CHARSET 1 will reset. Other likely printers for this technique are the C.Itoh 8510-A, IBM Graphics, IBM PC Colour, Texas 855, and "letter-quality" Okidata models.
More in our next.