Sinclair ASCII Text to IBM Text File Transfer Utility

Author(s): David Solly
Publication: ZXir QLive Alive!
Pub Details: ZXir QLive Alive! v12 n2 (Volume 12, Issue 2)
Date: Summer 2002
Pages: 7-11
Photo of David Solly
Photo of David Solly

This program is written in HiSoft Pascal, version 1.7M for the ZX Spectrum and designed to be run under “Z80”, the ZX Spectrum Emulator for DOS, version 3.0 or higher, created by Gerton Lunter (henceforth referred to as “the Emulator”). This utility will quickly transfer the contents of a Sinclair ASCII text file[i] to an IBM text file[ii] directly from cassette tapes or from *.TAP or *.MDR files by way of the Emulator’s RS232 output to IBM text file feature.

The program is intended for the transfer of raw text from one file format to another. It will not expand Sinclair tokens nor will it interpret imbedded text processor formatting commands. The resulting IBM text files, however, can be processed using such PC editing and word processing packages as MS-DOS Editor, WordPerfect, Microsoft Word, Word Pad and similar programs.

There are several advantages to transferring text in this manner.

  • A Timex/Sinclair 2068 or a ZX Spectrum computer is not required. Files stored on cassettes can be loaded by means of a simple Tape to PC interface.
  • HiSoft Pascal programs are compiled and run as machine code. Therefore, transferring files is very fast.
  • It does not require having the software that created the Sinclair ASCII text files.
  • The file transfer utility auto-detects the length of each file being transferred.[iii] This saves the user some additional steps plus it speeds up the transfer of short files.

Creating the Program

Step 1: Creating A Clean Slate

Because the Emulator’s RAM usually contains some random garbage, it is necessary to create a clean slate in the section of RAM that the transfer utility uses as its document buffer before each Sinclair ASCII text file is loaded. The transfer utility achieves this by first loading into the document buffer a large array containing nothing but null characters. The null character also doubles as a signal to the transfer utility that the end of the current file has been reached and to stop transferring data to the IBM text file.

This first program creates the required character array, fills it with nulls, then saves the array to an MDR file on microdrive 1 as NopArr.A$. A document buffer of 16,700 bytes was chosen because it is the largest text file that can be created using M-Script. It is also near the limit of the size of file capture and transfer buffers found in most telecommunication programs.

Listing For The Auxiliary Program

NOPARRAY

{$C-} {Shut off keyboard checks}
PROGRAM NOPARRAY;

Null Array Generator Requirements

HiSoft Pascal 1.7M for the ZX Spectrum, Z80 (ZX Spectrum Emulator for DOS created by Gerton Lunter), version 3.0 or higher.

The function of this program is to create a large array of null characters that will be used to clear a similar array in the Sinclair text file to IBM text file conversion program.

The program displays which element is clearing in the array as it progresses. When the array has been cleared, it is saved to the microdrive as NopArr.A$ and a “End of program” message is displayed. Program by:

David Solly
Bibliotheca Sagittarii
Ottawa, Ontario
Canada
27 October 1998

***********************************
CONST
NOP = CHR(0); {Null character}

VAR

I, J {Loop counters}
: INTEGER;

AR {Character array}
: ARRAY[1..16700] OF CHAR;
BEGIN {MAIN PROGRAM}

PAGE; {Clear the screen}

FOR I := 1 TO 16700 DO
BEGIN
WRITELN('Working on element ',
I:5:H);
AR[I] := NOP;
END; {FOR I}

{Transfer the array to the
microdrive}

TOUT('1:NopArr.A$',ADDR(AR),SIZE(AR
));

WRITELN;
WRITELN;
WRITELN('Character array NopArr.A$
is now saved to microdrive');
WRITELN;
WRITELN('End of program.');

END.

Step 2: Entering Compiling the Transfer Utility Program

Once the null array has been generated and stored as a microdrive file, the utility program is entered in 51 column mode and compiled. The listing is pretty straight forward and self explanatory. The source code and compiled program should be saved on the same microdrive file as the null array generation program. Be careful to type the file names used in the TIN() and TOUT() commands just as shown otherwise the program will stop with the run time error “file not found”.

{$L-} {Makes for faster
compilations}
PROGRAM SinclairTextToIBMText;

**********************************

Transfer Utility Program:

Sinclair Text files to IBM text files

Requirements:

HiSoft Pascal 1.7M for the ZX Spectrum, Z80 (ZX Spectrum Emulator by Gerton Lunter), version 3.0 or higher

Use 51 column mode for compiling this program.

The function of this program is to create IBM text files from Sinclair Text files such as those created by M-Script and other ZX Spectrum and Timex/Sinclair 2068 programs.

Program by:

David Solly
Bibliotheca Sagittarii
Ottawa, Ontario
Canada
27 October 1998

***********************************
CONST
MAXBYTES = 16700; {Largest file
possible}
NOP = CHR(0); {Null character}

TYPE
{Special type for file names}
FNTYPE = ARRAY[1..12] OF CHAR;

VAR
DOCBUFF : ARRAY[1..MAXBYTES] OF
CHAR;
{Document buffer array}
FILENAME : FNTYPE;
DOCSTART : INTEGER;
ANS : CHAR;
PROCEDURE SPOUT(C : CHAR);
{SPOUT outputs a character directly
through the
ROM's RST #10 routine, avoiding
any trapping by
Pascal of the value output. See
the manual
page 80 for details.}

BEGIN
INLINE(#FD, #21, #3A, #5C, #DD,
#7E,
#02, #D7);
END;

PROCEDURE GOTOXY(X, Y : INTEGER);
{Places the cursor at a specified
X,Y location
on the screen}

BEGIN
SPOUT(CHR(22));
SPOUT(CHR(Y));
SPOUT(CHR(X));
END;

PROCEDURE CLRSCR;
{Clears the screen and places the
cursor at the
top left hand side of the screen}

BEGIN
PAGE;
SPOUT(CHR(22));
SPOUT(CHR(0));
SPOUT(CHR(0));
END;

PROCEDURE BANNER;

{Clears the screen and prints the
banner}

BEGIN
CLRSCR; {Clear the screen}
GOTOXY(17, 1);
WRITE('Transfer Utility');
GOTOXY(5, 2);
WRITE('Sinclair ASCII Text File
To IBM Text File');
WRITELN;
WRITELN;
END;

PROCEDURE SUMMARY(C : INTEGER; FN :
FNTYPE);

{Summarizes the file transfer
statistics}

BEGIN
BANNER;
GOTOXY(0, 11);
WRITELN('File transferred: ',
FILENAME);
WRITELN('Number of bytes
transferred: ',
C - 1:5);

WRITELN;
WRITELN;
WRITE('Transfer another file?
(Y/N) > ');
READLN;
READ(ANS);

END;

Procedure Songanddance

{Introduction to the program}

BEGIN

BANNER;
WRITELN('This utility is for
transferring the data from');
WRITELN('Sinclair ASCII text
files to IBM standard');
WRITELN('text files through the
RS232 interface feature in');
WRITELN('Gerton Lunter''s ZX
Spectrum emulator.');

WRITELN;

WRITELN('For this program to
work, you must first execute');
WRITELN('the command OPEN#3,"T"
in BASIC and redirect the');
WRITELN('output of the RS232
interface to an IBM text file.');

GOTOXY(14, 22);
WRITELN('Hit Any Key To
Continue');

READLN;

END;

PROCEDURE CLEANDOCUMENT;

{This procedure clears out any pre-
existing
garbage from the document buffer
by loading an array of Nuls.}

BEGIN
BANNER;
GOTOXY(20, 11);
WRITE('Setting Up!');
{Load the array of nuls saved on
the microdrive}
TIN('1:NopArr.A$', DOCSTART);

END;

PROCEDURE LOADDOC;

{Loads the document to be
transferred from a
cassette tape or from an emulator
*.TAP
file.}

BEGIN
BANNER;
GOTOXY(0, 10);
WRITELN('Enter the name of the
file to load');
WRITELN('Pad out the stars with
spaces, if needed');
GOTOXY(0, 13);
WRITE('************'); {12 stars}
GOTOXY(0, 13);
READLN;
READ(FILENAME);

BANNER;
WRITELN('Searching for: ',
FILENAME);
WRITELN('Start tape!');
{The "tape" may be either a
cassette tape or
a *.TAP file. Be sure to set
the emulator
options accordingly.}
WRITELN;
WRITELN;
TIN(FILENAME, DOCSTART);

END;

PROCEDURE MAKEIBM;

{This procedure transfers the Sinclair Text file to an
IBM text file.}

VAR
COUNTER : INTEGER;

BEGIN
BANNER;
COUNTER := 1;
WRITELN('Transferring ',
FILENAME, 'To IBM Text File');
GOTOXY(17, 11);
WRITELN('Bytes Transferred');
WRITELN;

{WORK LOOP}
WHILE (COUNTER <= MAXBYTES) AND
(DOCBUFF[COUNTER] <> NOP) DO
BEGIN
GOTOXY(23, 9); {Place
cursor on screen}
WRITE(COUNTER:5); {Display
current count }
WRITE(CHR(16)); {Open
printer stream }
WRITE(DOCBUFF[COUNTER]);
{Transmit character}
WRITE(CHR(16)); {Close
printer stream }
COUNTER := COUNTER + 1;
{Augment counter }
END; {WHILE}

SUMMARY(COUNTER, FILENAME);

END; {MAKEIBM}

(*====== MAIN PROGAM ======*)

BEGIN

SONGANDDANCE;
DOCSTART := ADDR(DOCBUFF);

REPEAT
CLEANDOCUMENT;
LOADDOC;
MAKEIBM;
UNTIL NOT (ANS IN ['Y', 'y']);

CLRSCR;
GOTOXY(20, 5);
WRITELN('Program By');
GOTOXY(20, 6);
WRITELN('David Solly');
GOTOXY(14, 7);
WRITELN('Bibliotheca
Sagittarii');
GOTOXY(18, 8);
WRITELN('Ottawa, Canada');
GOTOXY(18, 9);
WRITELN('22 May 2002');

END.

Step 3: Using The Transfer Utility Program

The first thing that must be done before starting the program is to redirect the print stream to the RS232 interface. This is done in BASIC by typing: OPEN #3,”B”. The best way not to forget this step is to include it in the load and launch program thus:

10  OPEN #3, "B": BORDER 1: INK 6:
PAPER 1: CLS: LOAD *M;1;"ibm.C1"
CODE
20 RANDOMIZE USR 24700
30 NEW

The next step is to assign an output file for the IBM text that the program generates. To do this select F4 “Change Settings”, O “Change RS232 output channel”, D “Disk”. At this point you will be prompted to enter a suitable name for the IBM text file.

When the program starts, it will prompt you for the name of the Sinclair ASCII text file. The program can come from a file on cassette, from a *.TAP file or an *.MDR file. For a file saved on a microdrive, one simply adds the drive number in front of the file name thus: 1:MyFile.

After the transfer of files is completed, the IBM file has to be closed. To do this go back to the RS232 output options. Select X “Close file”. It is also a good idea to return the output to LPT 1 otherwise you risk locking up the Emulator.


[i] Examples of such text files are buffer captures from online sessions, files created in M-Script (as it was modified for standard Timex/Sinclair cassette I/O by Jack Dohany), or text files created by the LK DOS program listing to Sinclair ASCII file utility and from similar sources.

[ii] Another description of an “IBM text file” is an “MS-DOS ASCII text file”.

[iii] The maximum document size is 16,700 bytes. It might be possible to create a buffer as large as 20,000 bytes but this is close to the limits of HiSoft Pascal’s “compile and test” mode. The better approach would be to break up large text files into more manageable pieces.

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.