

                        T A P E F I X  v1.00

                  ZX Spectrum Tape Recovery Tools

                        (c) 1996  Busy Bytes
                         by Arsen Torbarina
   

                   ...Revive your memories!!!...










Contents:

   1.   INTRODUCTION, REGISTRATION INFORMATION
   1.1. What the program does?
   1.2. Included files
   1.3. Software & hardware requirements
   1.4. Shareware version's restriction
   1.5. Ordering your registered copy of the 'TAPEFIX v1.00'
   1.6. User support

   2.   TECHNICAL OVERVIEW
   2.1. How does the Spectrum store data to a tape?
   2.2. Common deviations of the recordings
   2.3. How does the TAPEFIX work?
   2.4. TAP file format

   3.   USING THE TAPEFIX PROGRAM
   3.1. Overview
   3.2. Making a sample
   3.3. Processing the sample
   3.3.1.  Specifying input and output files
   3.3.2.  INI files
   3.3.3.  LOG files
   3.3.4.  Saving the info-boxes
   3.3.5.  Specifying the destination filter file
   3.3.6.  Sample parameters
   3.3.7.  Filter parameters 
   3.3.8.  Signals frequency definition
   3.3.9.  Various options
   3.3.10. Troubleshooting with the Advisor

   4.   TAP2WAV UTILITY
   4.1. Usage
   4.2. Saving a sample via music card



1.   INTRODUCTION, REGISTRATION INFORMATION

1.1. What the program does?

    ...And they've been telling me that this was impossible!...

   Do you still have some dusty ZX Spectrum tapes with those good
   old simple games, or perhaps there are some programs of yours
   that you were proud of ten years ago ... And now you are keen to
   load them again, but they just seem not to be readable anymore!

   IF YOU THOUGHT THAT THOSE RECORDINGS ARE IMPOSSIBLE TO READ -- YOU
   WERE AWFULLY WRONG!!! TAPEFIX WILL RECOVER ALMOST ANY OLD RECORDING
   THAT IS DUE TO THE DAMAGES OR SIGNAL LOSS CAUSED BY AGING, IMPOSSIBLE
   TO LOAD IN THE ORDINARY WAY. RECOVERED DATA WILL BE SAVED EITHER BACK
   TO TAPE, OR IN THE WELL KNOWN "Z80" EMULATOR'S TAP FILE.

   Version 1.00 requires as input a 16-bit WAV or RAW sample. After
   the filtering, the data will be read, and then written to a TAP
   file, that (in case you don't own the "Z80" Emulator) can be
   transformed back to a WAV sample and then played back to tape.
   The whole process performed on a 486 computer, supplied with the
   SmartDrive, takes less than the ordinary loading.
   
   TAPEFIX uses specially developed digital filtering methods to
   separate the useful signal from noise and errors. Although the
   default filter settings and included INI setups are quite enough
   for most of the recordings, sometimes it will require some
   experimenting before the recording is successfully processed.




1.2. Included files

a) The registered version comes in one TFIX-100.ZIP file consisted
   of the following parts:

   TAPEFIX.EXE    Main program - registered version
   TAP2WAV.EXE    Utility that converts TAP files to WAV samples
   TAPEFIX.TXT    Manual (English)
   READ.ME        Preface (English)
   ORDER.TXT      Ordering information (English)
   FILE_ID.DIZ    Package description
   *.INI          Several INI files with various settings

   TAPEFIX.CRO    Manual (Croatian)
   PROCITAJ.ME    Preface (Croatian)
   NARUDZBA.CRO   Ordering information (Croatian)

   TFIX100S.ZIP   Shareware version package



b) The shareware version comes in one TFIX100S.ZIP file consisted
   of the following parts:

   TAPEFIX.EXE    Main program - shareware version
   TAP2WAV.EXE    Utility that converts TAP files to WAV samples
   TAPEFIX.TXT    Manual (English)
   READ.ME        Preface (English)
   ORDER.TXT      Ordering information (English)
   FILE_ID.DIZ    Package description
   *.INI          Several INI files with various settings
   EXAMPLE.WAV    Short sample of a recording (only in the SW package)

   TAPEFIX.CRO    Manual (Croatian)
   PROCITAJ.ME    Preface (Croatian)
   NARUDZBA.CRO   Ordering information (Croatian)




1.3. Software & hardware requirements

    Although the program will run even on an old 286, it is
     strongly suggested at least a 386 or 486 with a math
     co-processor, and a fast hard disk.
    It is also advisable the use of SMARTDRIVE or some other disk
     cache.
    Better speed performance will be gained if the program is run
     from the Windows' DOS prompt with 32-bit   file and/or disk
     access.
    A 16-bit sound card (sorry folks, that's really necessary)!
    A good wave editor (that doesn't clicks when playing a long
     sample) -- e.g., GoldWave, CoolEdit, Creative WaveStudio...




1.4. Shareware version's restriction

   The shareware version is made only for evaluation purposes
   and has one major limitation: it will handle only files up to
   2000 long. However, longer files will be analyzed (but not
   saved) so you could know whether they could be recovered with
   the registered version. 




1.5. Ordering your registered copy of the 'TAPEFIX v1.00'

   By ordering a registered copy, you get the following:

       Fully functional program without the restrictions
        of the shareware version;

       Complete user support;

       All the 1.xx versions you will get free of charges (except the
        delivery costs when NOT ordering by E-mail);

       50% discount on all further versions.


   There are two ways of delivering the program, plus one if you
   live in Croatia:


   a) Via E-mail that is absolutely the best and fastest way, since
      it does not require additional costs, and you get your copy
      as soon as the money arrives.

      Please send in an envelope GB7, US$10 or DEM 15 with your
      full name, your post address, and your E-MAIL address to the
      following address:

               Arsen Torbarina
               Al.Blaza Jurisica 65
               10040 Zagreb
               CROATIA

      (Please place the money in a folded sheet of paper, and fix
      the coins with a piece of adhesive tape).

      The program will be delivered to you on your E-mail address,
      as a file attached to a letter.



   b) Via air-mail which requires additional fee for the delivery

      Please send in an envelope GB9, US$13, or DEM 20 with your
      full name and your post address to the address written above.

      You will receive your registered copy via air-mail, on a 3.5"
      HD disk in the shortest possible time.



   c) THIS OPTION IS POSSIBLE ONLY IF YOU LIVE IN CROATIA

      Daklem, obzirom da smo si svoji, za sve sunarodnjake cijena
      je sljedeca:

      c1) 35 kuna ako zelite dostavu putem E-maila (ne zaboravite
          navesti svoje puno ime, postansku adresu, te E-mail
          adresu, s time da posebno istaknete da zelite dostavu
          putem E-maila)

      c2) 50 kuna ako zelite dostavu preporucenom posiljkom na
          3.5" HD disketi.


   NOTE: The source is not available.



1.6. User support

   If you are a registered user, and you have any problems or questions
   regarding the usage of the TAPEFIX, you can write to the following
   E-mail addresses, and you will receive the answer in the shortest
   possible time.

       arsen.torbarina@bug-zg.fido.hr
       arsen.torbarina@fer.hr


   NOTE: User support is available only for registered users, so do not
         forget to write your name and the serial number of your copy!!!



2.   TECHNICAL OVERVIEW

2.1. How does the Spectrum store data to a tape?

   For saving data to a tape, Spectrum uses a very primitive method
   called frequency modulation. Each byte is saved to tape bit by
   bit, where the most significant bit comes first, and the least
   significant one comes last. "0" is coded with an impulse of the
   frequency of 2044 Hz, and "1" is coded with an impulse of the
   frequency of 1022 Hz. It results in 1500 bits per second in the
   case of equal numbers of "ones" and "zeros".

   In order to ease the search for the block start, it is
   necessary to have on the beginning of each one a leader tone
   (808 Hz) that lasts from 3 to 5 seconds. It is followed by a
   short impulse (about 2500 Hz) called synchro impulse, that
   specify the start of the data block. The synchro impulse has
   the positive half-period that is a bit longer than the negative
   one, which results in a slight elevation of the signal, on the
   very beginning of the block.

   The very first byte written after the synchro impulse, present
   the flag byte -- that is the contents of the A register, that
   specifies the block type. Usually 0 stands for headers, and 255
   for data blocks.
   
   The following bytes represent the saved data, and the last one
   is the checksum parity byte. The loading routine ends as soon as
   it gets the last of N+2 bytes it has been expected (where N is
   the number of data bytes).


   Figure A: Frequency modulation


      Ŀ        Ŀ        ĿĿ  Ŀ  Ŀ      
   ...                           

              807 Hz            807 Hz        1022Hz 1022Hz   2044 Hz
       <><><><><><>
          Leader tone (last 2 impulses)  "Sync" "0"   "0"       "1"





2.2. Common deviations of the recordings

   When the signal is saved to tape, due to the characteristics
   of the recording hardware, all the sharp edges are smoothed,
   resulting an ordinary sine wave. On good high-frequency
   performance tapes, such as metal and Cr02 tapes, the signals are
   often found with sharp peaks on the front edge. Those peaks
   usually make problems during the loading, and thus have to be
   eliminated by a selective filter.

   Another, more often cause of loading errors, is the loss of the
   signal intensity, often followed by impulse merging, caused by
   the tape aging. This means that the impulse for "0" (which due
   to its shorter duration also has a lower amplitude), is melted
   to the first following signal. This problem, impossible to
   handle in the ordinary way, now can easily be solved using the
   TAPEFIX sophisticated methods of digital filtering.

   Short gaps and peaks caused by the tape deformations -- normally
   impossible to handle -- will be successfully smoothed.

   Frequency deviation is also one of the most common deviations
   caused by using a bad tape recorder. The standard loading
   routine is very non-tolerant to any frequency variation, but
   TAPEFIX can be set to accept any frequency range you want!

   High noise level will also be easily overridden.




2.3. How does the TAPEFIX work?

   There are several mechanisms that the TAPEFIX uses to decipher
   the recordings. The simplest one is the frequency tolerance
   boundaries, that can be set to almost any value. The frequencies
   can be given in two ways: either by specifying the values given
   in Hz, or by specifying the period length given in samples.

   There are also two sophisticated filters, specially modified for
   this purpose;

   A filter called "deriving filter" eliminates all the low
   frequency noises, and separates merged signals. It is meant to be
   used only once -- usually in the first pass of the processing.

   A modified version of the Butterworth 1st order low-pass filter
   solves all the problems caused by noise and signals shape
   deformations. It will also smooth up all the shorter gaps and
   peaks in the signal.

   The parameter of the Butterworth filter is the LOWPASS cutoff
   frequency. By default, it is set to 2100 Hz and it should do for
   most of the cases. In case of a sharp, edgy signal, even 2 or 3
   passes of the low-pass filter should be performed!




2.4. TAP file format

   TAP format is a format used for the tape emulation in the "Z80"
   Spectrum emulator. The following text is quoted from the original
   G.A.Lunter's manual:

   
   "The .TAP files contain blocks of tape-saved data. All blocks
   start with two bytes specifying how many bytes will follow (not
   counting the two length bytes). Then raw tape data follows,
   including the flag and checksum bytes. The checksum is the bitwise
   XOR of all bytes including the flag byte. For example, when you
   execute the line SAVE "ROM" CODE 0,2 this will result:

         |------ Spectrum-generated data -------|       |---------|
   13 00 00 03 52 4F 4D 7X20 02 00 00 00 00 80 F1 04 00 FF F3 AF A3

   ^^^^^...... first block is 19 bytes (flag + 17 bytes + checksum)
         ^^... flag byte (A reg, 00 for headers, FF for data blocks)
            ^^ first byte of header, indicating a code block
   file name ..^^^^^^^^^^^^^
   header info ..............^^^^^^^^^^^^^^^^^
   checksum of header .........................^^
   length of second block ........................^^^^^
   flag byte ............................................^^
   first two bytes of ROM .................................^^^^^
   checksum (checkbittoggle would be a better name!).............^^"

 (end of quotation).




   
3.   USING THE TAPEFIX PROGRAM

3.1. Overview

   The usage is very simple -- all you have to do is make a sample
   and run the TAPEFIX.

   After the sample is filtered, the loading begins block by block.
   For each loaded block, an info-box is displayed, containing some basic
   information on the block such as block type, length, flag byte and its
   position in the sample. The position is specified with the following:

       Leader start 
       Data block start
       Data block end
       Data block break (Break-point)

   NOTE: The position is given in two measures: in number of bytes from
   the beginning, and in number of samples (in mono 16-bit recordings, the
   number of bytes is twice the number of samples).

   When a block is successfully loaded, its header-info box appears
   on the screen, containing all the basic information related to
   that block. If the checksum is OK, the box appears in blue. If
   an error occurs, the box appears in red. Finally, a TAP file
   that is created, can be either loaded to the "Z80" emulator, or
   using TAP2WAV utility converted to a WAV or RAW sample, and
   played back to tape.




3.2. Making a sample

   Version 1.00 requires for input a WAV or RAW sample file. Using
   a good sample recorder/editor, record the program you would like
   to recover. You can use either GoldWave, CoolEdit, Creative
   WaveStudio -- the important thing is that it does not produce
   clicks and pauses on longer samples!

   Always use 16-bit recording. Stereo mode should be used only if
   the recording is obviously damaged and there is no other way to
   gain a satisfying result, since the processing of a stereo
   recording takes twice longer.

   For the standard recordings, made on normal speed, sampling
   frequency of 11025 Hz should do just fine. Higher sampling
   frequency should be the last resort!

   Speed-locked recordings should be sampled on higher frequencies,
   depending of the used speed (e.g., for 3000 bd. use 22050 Hz
   sampling).

   CAUTION: When recording a sample, be careful not to put the
   volume level too high since otherwise your music card will
   clip the signal, which will corrupt the recording even more.




3.3. Processing the sample

   The allowed syntax is as follows:

   TAPEFIX <sample> [TAPfile] [<INIfiles>] [LOGfile]
           [<params>] > outfile


3.3.1. Specifying input and output files

   When starting the TAPEFIX program, the name of the sample has
   to be specified in the command-line. E.g.:

      tapefix sample.wav

   This way, the processing will be done using the default
   parameter setting stored in the program itself, and those
   stored in TAPEFIX.INI file (if there is one). In the above
   example, the results will be stored in the SAMPLE.TAP file. This
   can be changed by giving another TAP file name in the command-
   line. E.g.:

      tapefix sample.wav tape.tap

   If there is an existing TAP file, it will be overwritten, unless
   you want to append the new data to it, using the /APPEND switch.
   When /APPEND is set, a "+" sign appears to the right of the TAP
   file-name in the status-window. /NEW switch cancels this option.


3.3.2. INI files

   INI files are plain text files, where you can store various
   parameters settings. If specified, the INI files (there can be
   more than one specified) will be loaded in order of appearance,
   just after the program is started, and BEFORE the setting from the
   command-line is read. Switches in an INI file are written row by
   row -- not two or more in one row!

   TAPEFIX.INI will be loaded first, sure -- if there is one.


3.3.3. LOG files

   In order to have better view on the processing, you can create a
   LOG file, where all the happenings, such as position of each
   byte and leader tracing are written to line by line. The first
   number in each line specifies the position of the current event,
   given in samples.

   NOTE: This number, when referring to a byte or a synchro impulse,
   specifies its END, not the beginning!   
   

3.3.4. Saving the info-boxes

   If the info-boxes of the blocks read fly too fast across the
   screen, you can send them all to an output header file, for
   later analysis. E.g.:

      tapefix sample.wav > headers.txt

   NOTE: When the output is redirected, the displaying on the
   screen will continue the same!


3.3.5.  Specifying the destination filter file

   You can specify the name that will be given to a temporary
   work-file that is used to store the filtered input. By
   default, this file is opened in the TEMP or TMP directory,
   and after processing will automatically be removed! If you
   specify its name using the /FILT parameter, the file will be
   kept even after the processing is completed. This file later can
   be used as input, in order to cascade the filters. E.g.;

      tapefix sample.wav /NOLOAD /LOWPASS=2100 /FILT=pass_1.wav
      tapefix pass_1.wav /NODERIV /LOWPASS=1500

   The first command performs one pass of the deriving filter and
   one pass of the low-pass filter at 2100 Hz, and store the
   filtered signal in PASS_1.WAV, skipping the blocks loading.
   The second one reads the sample from PASS_1.WAV, skips the
   deriving (since it has to be performed only once), and uses the
   low-pass filter at 1500 Hz. The result is finally stored in
   PASS_1.TAP.


3.3.6. Sample parameters

   If a RAW file is used as input, the following parameters have
   to be set:

      /RATE=f   Set input sample rate to f Hz (default = 11025)
      /STEREO   Input file is a STEREO recording
      /MONO     Input file is a MONO recording

   On the stereo recordings, only left, right or both channels can
   be enabled:

      /CHANNEL=[L|R|B]     (Default = Both)


3.3.7. Filter parameters 

   The following switches are used to control the filters:

      /DERIV[=n]       Enable deriving filter only on the n-th pass
      /NODERIV         Disable deriving filter (same as /DERIV=0)
      /LOWPASS         Enable lowpass filter
      /NOLOWPASS       Disable lowpass filter
      /PASSES=n        Number of passes of the low-pass filter (cascades)
      /LOWPASS=[f|OFF] Set low-pass cutoff frequency to f Hz or
                       disable the low-pass filter
      /NOFILT          Skip filtering
      /THRESH=n        Amplitude threshold


3.3.8. Signals frequency definition

   /SLEAD[MIN|MAX]=n   Set MIN or MAX period of the LEAD tone to n samples
   /SSYNC[MIN|MAX]=n   Set MIN or MAX pariod of the SYNC tone to n samples
   /SBIT0[MIN|MAX]=n   Set MIN or MAX period of the BIT0 tone to n samples
   /SBIT1[MIN|MAX]=n   Set MIN or MAX period of the BIT1 tone to n samples

   /FLEAD[MIN|MAX]=f   Set MIN or MAX frequency of the LEAD tone to f Hz
   /FSYNC[MIN|MAX]=f   Set MIN or MAX frequency of the SYNC tone to f Hz
   /FBIT0[MIN|MAX]=f   Set MIN or MAX frequency of the BIT0 tone to f Hz
   /FBIT1[MIN|MAX]=f   Set MIN or MAX frequency of the BIT1 tone to f Hz


   NOTE 1: The frequencies can be given in two ways: either by specifying
   the values given in Hz, or by specifying the number of samples it
   takes.
   Note also that /FxxxxMIN=f is equivalent to /SxxxxMAX=n, where the
   correlation between n and f is:

                         n=RATE/f, and  f=RATE/n,

   where RATE is the sampling frequency.


   NOTE 2: If you change only SBIT0MAX, the value SBIT1MIN will be
   automatically set to the first higher integer and vice versa.


3.3.9. Various options

   /MINLEADS=n   Set minimum acceptable number of sequent LEADER impulses
   [NO]LOAD      Disable/Enable loading
   /ENDERR       Stop loading after first bad block (checksum error)
   /CONTERR      Continue loading even after a bad block
   /25           Set 25-rows display
   /50           Set 50-rows display
   /?            Quick help. You can also redirect help to a file.


3.3.10. Troubleshooting with the Advisor

   If an error occurs, a built-in feature called "automatic
   advisor" will tell you what to do. Basically, there are several
   parameters that you should modify in that case, and it would be
   the best to do what the advisor tells you to.

   /[NO]ADV      Disable/Enable automatic advisor. If enabled, the advisor
                 will suggest you what to do if an error occurs.

   And if the Advisor doesn't manage to help you solving the problem,
   you can always write to the User Support Service, and you will get
   the answer as soon as possible. (See "1.6. User support")




4.   TAP2WAV UTILITY

4.1. Usage

   TAP2WAV is a utility that will convert the contents of a TAP file to
   a WAV sample that can be played back to tape and loaded into a real
   Spectrum.

   The allowed syntax is as follows:

      TAP2WAV source[.TAP] [destination[.WAV |.RAW]] [options]

      /FREQ=f   Set output sampling frequency to f Hz (Default = 8180)
      /PAUSE=x  Set pause between two blocks to x ms  (Default = 100)

   NOTE: To obtain the lowest frequency distorsion, output sampling
         frequency should be N*4090 where N is an integer greater than 1.



4.2. Saving a sample via music card

   The sample can be played back to tape, using a good sample player,
   that doesn't make clicks when playing longer samples.

   When playing the sample back to tape, set TREBLE on your sound card to
   zero, to reduce the peaks on the first edge that will appear, due to
   the characteristics of the card.


