Автор: Andrew Pennell
Год: 1984
Издатели: Your Spectrum
Языки:
Английский
Формат:
TAP лента
Требования:
ZX Spectrum 48K
Ссылки:
Страница на ZXArt
Страница на World Of Spectrum
Страница на Spectrum Computing
Год: 1984
Издатели: Your Spectrum
Языки:
Формат:
Требования:
Ссылки:
(from Your Spectrum 8, October 1984)
This article must be read in conjunction with "Patching Up The 'Drives"
in issue 14.
RUNNING REPAIRS
Hands up those who've lost files on a Microdrive cartridge. Well, for
goodness sake, don't throw it away because Andrew Pennell's beginning
to solve the problem. Presented here is a way of examining and
printing up the suspect sectors ... and there's more to come.
Good as the ZX Microdrives are, like all forms of media, they're not
perfect. Every once in a while, faults occur that result in a 'File
not found' message and, of course, Murphy's Law determines that this
only happens to those that have not been backed-up.
The program I'm presenting is designed to enable 'repairs' to be made
to corrupted and unloadable files. It's in two parts. The first
(presented here) allows you to examine the cartridge for faults, and
print out all damaged and suspect sectors. The second, to be included
in a forthcoming issue, will allow individual sectors to be read in -
even if faulty - corrected, then written out, so you can still recover
the file. It won't be perfect, because badly corrupted files can be
impossible to fix; however, it'll work for many.
SAVE YOUR SECTORS
Before delving into the program, let's examine first why sectors
become unreadable. Usually, it's due to some mechanical or magnetic
abuse that results in some part of the tape losing bits of data. Thus,
when the Spectrum tries to read the affected sector, the data is
altered and the checksum saved with it no longer matches - so loading
fails to take place. What our section of machine code does is scan the
cartridge, reading each sector (whether corrupted or not) and storing
its particulars in a Basic array, z$. Given the sorted array, the
Basic part then uses the information to calculate which sectors are
damaged or missing altogether; the second stage uses this information
to allow access to individual sectors, in order to re-create them.
Our first move will be to enter the 500-odds bytes of machine code.
Those without an assembler will have to use the Hex loader given;
enter the code correctly, then save it on to cartridge with:
SAVE *"m";1;"SL.CODE" CODE 30000,500
Next, enter the main program, and save it with:
SAVE *"m";1;"repair" LINE 9000
Note that line 130 will only be accepted with the machine code
entered, and activated by RAND USR 30000.
CODE ANALYSIS
The code works by adding a command '*L' which scans a given cartridge,
storing its details in the array z$(200,13); then it sorts the data
using a bubble sort. NEWVEC is the additional syntax checker, which
okays the statement, gets the 'drive number, alters it to suit the
ROM, then does the actual work. Routine WATROM is similar to the one
detailed in All Change (see the August issue), altering the CALLs in
the program to suit whichever shadow ROM is in place. FIND is the main
entry point. It starts by creating an 'm' area in CHANS, and putting
the motor on; each sector is read in, and its checksum calculated to
see if it has corrupted. The ROM checksum routine cannot be used as it
alters the checksum byte - which makes it impractical for part two. If
the sector is used, its name, record number and sector number are
stored in z$, along with a flag that shows if it's an EOF sector - and
whether it's corrupted or not. The code at NEXT ensures the whole
cartridge has been read, before closing the 'm' channel. The border is
made green, and the sort routine entered.
SORT is a not very amazing bubble- sort routine. It sorts the elements
of z$ into order, using the crudest sort of algorithm possible. I
chose it for simplicity, not speed - though it is, of course, many
times faster than anything in Basic. The routine can take up to a
minute to sort a full cartridge; those feeling nervous are allowed to
break into it while it sorts.
Routine NXHDBF, the most important one of all gets down to the
business of scanning the tape, doing its checksum, and seeing if it's
used or not. CHKSUM is basically the same as the one in the ROM, but
with an instruction at the end removed. Finally, FINDZ$ is responsible
for searching the variables area for the array z$, and finding the
location of the first element. Note that no checks are made on the
dimensions or size of the array, only its existence. If z$ is not the
proper size, then Basic may crash - so beware.
ROUTINE ACTION
The business of examining the sector data is carried out in Basic -
because it's easier to change, and speed is not relevant. After the
'*L', each element of z$ contains 13 bytes of data: bytes one to 10
are the file-name, byte 11 the record number, byte 12 the sector, and
byte 13 the flag. Option 1 prints all the file names, like CAT but
including CHR$ 0 file names. While using it, you may get strange file
names at the top of the catalogue; don't worry - all cartridges have a
couple of strangely-named sectors on them (as a by-product of the
FORMAT routine) all starting with CHR$ 0. Option 2 prints a sector
list, which consists of each used sector, its file name record number,
sector number, and type. From this, you can work out what's missing
from it, as record numbers should rise from zero up to one with EOF
against it. It also tells you if any are corrupted, though you don't
have to scan lines of information to find the faults; Option 3 prints
all the corrupted sectors, while Option 4 will examine all the sectors
of a given file and tell you if any are missing or corrupted. As it's
in Basic, you can change it to suit your needs.
All this allows you to find the faults in your cartridges; watch out
for part two where you'll discover how to fix them.
This article must be read in conjunction with "Patching Up The 'Drives"
in issue 14.
RUNNING REPAIRS
Hands up those who've lost files on a Microdrive cartridge. Well, for
goodness sake, don't throw it away because Andrew Pennell's beginning
to solve the problem. Presented here is a way of examining and
printing up the suspect sectors ... and there's more to come.
Good as the ZX Microdrives are, like all forms of media, they're not
perfect. Every once in a while, faults occur that result in a 'File
not found' message and, of course, Murphy's Law determines that this
only happens to those that have not been backed-up.
The program I'm presenting is designed to enable 'repairs' to be made
to corrupted and unloadable files. It's in two parts. The first
(presented here) allows you to examine the cartridge for faults, and
print out all damaged and suspect sectors. The second, to be included
in a forthcoming issue, will allow individual sectors to be read in -
even if faulty - corrected, then written out, so you can still recover
the file. It won't be perfect, because badly corrupted files can be
impossible to fix; however, it'll work for many.
SAVE YOUR SECTORS
Before delving into the program, let's examine first why sectors
become unreadable. Usually, it's due to some mechanical or magnetic
abuse that results in some part of the tape losing bits of data. Thus,
when the Spectrum tries to read the affected sector, the data is
altered and the checksum saved with it no longer matches - so loading
fails to take place. What our section of machine code does is scan the
cartridge, reading each sector (whether corrupted or not) and storing
its particulars in a Basic array, z$. Given the sorted array, the
Basic part then uses the information to calculate which sectors are
damaged or missing altogether; the second stage uses this information
to allow access to individual sectors, in order to re-create them.
Our first move will be to enter the 500-odds bytes of machine code.
Those without an assembler will have to use the Hex loader given;
enter the code correctly, then save it on to cartridge with:
SAVE *"m";1;"SL.CODE" CODE 30000,500
Next, enter the main program, and save it with:
SAVE *"m";1;"repair" LINE 9000
Note that line 130 will only be accepted with the machine code
entered, and activated by RAND USR 30000.
CODE ANALYSIS
The code works by adding a command '*L' which scans a given cartridge,
storing its details in the array z$(200,13); then it sorts the data
using a bubble sort. NEWVEC is the additional syntax checker, which
okays the statement, gets the 'drive number, alters it to suit the
ROM, then does the actual work. Routine WATROM is similar to the one
detailed in All Change (see the August issue), altering the CALLs in
the program to suit whichever shadow ROM is in place. FIND is the main
entry point. It starts by creating an 'm' area in CHANS, and putting
the motor on; each sector is read in, and its checksum calculated to
see if it has corrupted. The ROM checksum routine cannot be used as it
alters the checksum byte - which makes it impractical for part two. If
the sector is used, its name, record number and sector number are
stored in z$, along with a flag that shows if it's an EOF sector - and
whether it's corrupted or not. The code at NEXT ensures the whole
cartridge has been read, before closing the 'm' channel. The border is
made green, and the sort routine entered.
SORT is a not very amazing bubble- sort routine. It sorts the elements
of z$ into order, using the crudest sort of algorithm possible. I
chose it for simplicity, not speed - though it is, of course, many
times faster than anything in Basic. The routine can take up to a
minute to sort a full cartridge; those feeling nervous are allowed to
break into it while it sorts.
Routine NXHDBF, the most important one of all gets down to the
business of scanning the tape, doing its checksum, and seeing if it's
used or not. CHKSUM is basically the same as the one in the ROM, but
with an instruction at the end removed. Finally, FINDZ$ is responsible
for searching the variables area for the array z$, and finding the
location of the first element. Note that no checks are made on the
dimensions or size of the array, only its existence. If z$ is not the
proper size, then Basic may crash - so beware.
ROUTINE ACTION
The business of examining the sector data is carried out in Basic -
because it's easier to change, and speed is not relevant. After the
'*L', each element of z$ contains 13 bytes of data: bytes one to 10
are the file-name, byte 11 the record number, byte 12 the sector, and
byte 13 the flag. Option 1 prints all the file names, like CAT but
including CHR$ 0 file names. While using it, you may get strange file
names at the top of the catalogue; don't worry - all cartridges have a
couple of strangely-named sectors on them (as a by-product of the
FORMAT routine) all starting with CHR$ 0. Option 2 prints a sector
list, which consists of each used sector, its file name record number,
sector number, and type. From this, you can work out what's missing
from it, as record numbers should rise from zero up to one with EOF
against it. It also tells you if any are corrupted, though you don't
have to scan lines of information to find the faults; Option 3 prints
all the corrupted sectors, while Option 4 will examine all the sectors
of a given file and tell you if any are missing or corrupted. As it's
in Basic, you can change it to suit your needs.
All this allows you to find the faults in your cartridges; watch out
for part two where you'll discover how to fix them.