(from Your Spectrum 14, May 1985)
This article must be read in conjunction with "Running Repairs"
in issue 8.


PATCHING UP THE 'DRIVES

Faulty files are now a thing of the past! Using this second instalment
of code, Andrew Pennell shows you how to recover unloadable files from
that Microdrive cartridge that's giving you hassle. Take it away,
Andrew ...

In issue 8 of our most illustrious magazine, I got about half-way
through devising a Microdrive repair kit that could smell out faulty
files in an article called Running Repairs. Now, to finish it off, I
have evolved a way of allowing the recovery of unloadable files from
cartridge.


SORRY!

But first, an apology. Part one of this article, Running Repairs, was
not quite the pristine job it might have been, and those with sharp
eyes will have spotted the odd buglet or two; the pity is, I can't
even lay the blame on our poor ol' Ed (Poor yes, but less of the
'old'. Ed.). The problem is that we get a sector list that's minus
some of the necessary data ... indeed, there are quite a few sectors
missing. As it stands, this produces incorrect results in the 'check
file' section.

Anyway, I've modified the code to improve the performance and,
although it's still not perfect - some sectors that do exist may not
be found on very full cartridges, and some will be marked as 'bad'
when they're not - this is not so much of a problem now because one of
the functions of the extra code given in this issue, is for it to act
as an individual sector read, and this achieves perfect results.

Another problem in Running Repairs was the code's position in memory -
RAMtop at 30000 proved too low for the extra Basic. Thus, I've
provided a relocator program that'll shift the code for you - that'll
teach me to hand in part one of an article before working out part
two!


GETTING UNDER WAY!

So, before you enter this issue's section of code, you'll need to use
the listing given to slightly alter the data you've already got in
order to accommodate that given here. The relocator program achieves
its object and corrects the problems described above; it then goes on
to save the new code under the name "SLC.2". Once you've entered this
little goodie, move RAMtop up to, say, 32768 to allow room for the new
bytes shown in the second listing. (A word of warning - there's
insufficient memory to allow both of these programs to be present
simultaneously!)

The second program given here reads in "SLC.2", adds the extra code to
it and then saves it out as "SLC.3". In fact, it was while entering
this listing myself that I discovered the low memory bug that still
remains in the third version of the Interface 1 ROM. I tried a CAT
command as soon as I realised that memory was running out and the
system crashed in the most spectacular of fashions. But, as long as
you don't get RAMtop below the value in line 100, you shouldn't have
any problem on any of the Interface ROMs.

When you've sorted the machine code to rights, do a RANDOMIZE USR
32816 to allow the extra commands to be accepted by the syntax
checker. Now enter the third listing given, saving it so that it
starts at line 9000. It's an extended version of the first part's
Basic.


INTO ACTION

The menu has been extended to cover the extra operations; probably the
most useful of these is 'Examine sector', which searches a cartridge
for a given sector, and loads it (corrupted or not) into RAM for
inspection. Lines 6000 onwards load the sector into locations 60000
on, revealing various details about it. Most important here are the
checksums; if either of these are incorrect it means that the file of
which it is a part will probably not load, and the sector should be
repaired - which is exactly what option 6 does. You can usually tell
if tape is physically damaged, because the checksum result will give a
different value every time you read it.

A sector is repaired by it being read to address 60000 onwards; this
is then written out on to the next available sector, with the
checksums re-calculated. It's not, of course, written back on to the
same sector as there's every chance that the actual tape is damaged at
this point.

Once a sector has been fixed in this way, the 'bad' version should be
'removed' from the cartridge; there's not much point in freeing the
faulty sector for further use. Option 7 achieves this by marking it
with a strange filename full of CHR$ 0s. That done, the next time you
ask for a sector list of the cartridge you'll get a bad sector with
the name "??????????"; this is normal, so don't try to delete it
again. The strange name will not show up in a normal CAT. As much of
the utility is in Basic, you can reconfigure it to suit, using the
extra commands provided; check out the table of commands given with
this article.


CODE CONSIDERATIONS

For those blessed with an assembler, it's obviously a bit easier to
enter the assembly listing, rather than the accompanying Hex. The
listing, in fact, is a bit strange for two reasons. First, it's
fragmented, consisting initially of the modifications made to the code
in Running Repairs. As the original line numbers were chopped from my
listing (ha! - at last something I can blame on someone else) the
position of each modification may not be clear. To help, I've included
at least one label in each block. The only one that's a bit vague is
the main extra section ... it should go directly after TEMPA in the
code in Running Repairs. The '*L+' commands in the listing are
assembler directives, and should be ignored.

The second odd thing about the listing is that it uses a 'macro'. I've
used one called OLD to make it clearer when calling 16K ROM routines
with the 8K ROM in place. The usual way to call a routine is with two
instructions - namely a RST#10 followed by a DEFW - and this is not
exactly crystal clear; with the macro defined, a much clearer command
(such as OLD#20) can be used. Currently, the only assembler that
allows macros is the one from Hisoft - if you use another, simply
replace it with the more long-winded version. (I cannot claim any
originality for this idea. The shadow ROMs were written by Sinclair
Research using a similar macro, named OLDCAL, but the Hisoft assembler
doesn't allow long macro names.)

And now for the code itself. To begin with, there's a mod allowing the
additional routines to be accessed - by alteration of the JP
instruction. The other mods are to do with getting around the 'missing
sector' problem, and the DEFB 0s are there to pad out the code so that
it ends up pretty much like the code you saw in Running Repairs.

If you have a look at the code, you'll see the macro definition, and
that's followed by the new syntax checker. Check out the listing
itself for further documentation.

Anyway, that's about it. With this little lot, you should be able to
reclaim at least some of your unloadable files. The existing program
does not alter corrupt data from sectors - only the checksums - and
you could add a nice little editor around line 6020 to do just that.
Sorry for the long wait between the two parts of this article ...
let's hope I don't have to wait so long for you to come up with an
editor at line 6020!
