As the new owner of a Cambridge Z88 laptop, I needed a way to transfer files to and from the QL. I did not have enough memory to use Z88COM and I wanted to use the built in Import/Export utility.
Transferring files from the Z88 to the QL was easy. Enter COPY SER2 TO RAM1_FILE_EXT, connect the Z88 on SER2, and have the Z88 send the file. Once the Z88 was done, I’d just hit CTRL-SPACE to break the COPY. Getting files to the Z88 would be more difficult.
A direct copy would not not work. I was able to get a SuperBasic program from Dave Bennett that sort of worked. I found that I had to open the serial port as SER2IR. I did see that the program has a PAUSE between sending characters. Since SuperBasic does not have a byte input command, the program would read in a string at a time (ended with a LF). But files with no LF would cause problems. Time to move to C.
The C program is fairly simple. My first version only prompted for a file name, the later version added the ability to set the baud rate and convert all LF’s to CR’s (the Z88 uses Cr’s for EOL’s). Once the serial port is opened right, the file is opened and, byte by byte, is sent to the Z88. I tried the program with out a pause between bytes, but it did not work, hence the FOR loop for a pause.
In keeping with the Z88 Import/Export protocal, I send an ESC for end of file and ESC for end of batch. If the file came from the Z88 it has the filename in the file. One can then send the file to the Z88 in batch mode without telling the Z88 what the file name is. If it’s not needed, the ESC’s will go to the bit bucket.
The program was written for Small-C but should compile fine with C68 with only a few modifications.
/* File: QLtoZ88_c
Author: Timothy Swenson
Send files to the Z88 from the QL
This program will send any file to a Z88.
It has an option to translate all Line Feeds (LF)
(QL End-Of-Line markers) to Carriage Return (CR)
(Z88 End-Of-Line markers).
At the end of each file it will send an End Of File
escape command. It will the send an End of Batch
escape sequence. Since Z88 files store the filename
with in the file (when transfered out of Import-
Export) the Batch Recieve can be used to send a
file without explicitly telling the Z88 the
filename.
*/
#define TRUE 1
#define FALSE 0
/* #define CR 13 defined in STDIO_H */
/* #define LF 10 defined in STDIO_H */
#define ESC 27
#include <stdio_h>
main() {
char c, file[30];
int i, convert, baud_rate, fd1, fd2;
printf(" QL To Z88 \n");
printf(" By Tim Swenson\n\n");
printf("Enter Input File Name : \n");
gets(file);
fd1 = fopen(file,"r");
if (fd1 == NULL) {
printf("Did not open file: %s",file);
abort(1);
}
printf("\nConvert LF to CR? (Y/N)");
getchar(c);
convert = FALSE; /* default */
if ( c == 'Y' || c == 'y' )
convert = TRUE;
printf("\nSelect Baud Rate: \n");
printf(" 1 - 300\n");
printf(" 2 - 1200\n");
printf(" 3 - 2400\n");
printf(" 4 - 9600\n");
printf("Default of 1200\n");
getchar(c);
baud_rate = 1200; /* default */
if ( c == '1' ) baud_rate = 300;
if ( c == '2' ) baud_rate = 1200;
if ( c == '3' ) baud_rate = 2400;
if ( c == '4' ) baud_rate = 9600;
fd2 = fopen("ser2ir","w");
if (fd2 == NULL) {
printf("Could not open Serial 2\n");
abort(1);
}
baud(baud_rate);
while (( c = getc(fd1)) != EOF) {
if ( convert == TRUE && c == LF )
putc(CR,fd2);
else
putc(c,fd2);
/* Pause in sending */
for ( i = 1; i < 500; i++)
;
}
/* Send ESC E to signal End of File */
/* ( Z88 Protocal ) */
putc(ESC,fd2);
putc('E',fd2);
/* add another pause */
for ( i = 1; i < 500; i++ )
;
/* Send ESC Z to signal End of Batch */
putc(ESC,fd2);
putc('Z',fd2);
fclose(fd1);
fclose(fd2);
}
One small problem with Z88 ASCII files on the QL was the fact that the Z88 used CR instead of LF to mark EOL. I wrote a very short program that will read in a file, convert all instances of CR to LF and output the file. It’s fairly trivial but I’ve added here for the beginning C users out there.
/* File: CRtoLF_c
Author: Timothy Swenson
Converts all CR's to LF's
This program will take a file that came
from the Z88 with CR's for End-Of-Line
markers and convert them to LF's (QL
End-OF-Line markers).
*/
/* #define CR 13 defined in STDIO_H */
/* #define LF 10 defined in STDIO_H */
#include <stdio_h>
main() {
char c, file[30];
int fd1, fd2;
printf("Enter Input File Name : \n");
gets(file);
fd1 = fopen(file,"r");
if (fd1 == NULL) {
printf("Did not open input file: %s",file);
abort(1);
}
printf("Enter Output File Name : \n");
gets(file);
fd2 = fopen(file,"w");
if (fd2 == NULL) {
printf("Could not open output file: %s\n",file);
abort(1);
}
while (( c = getc(fd1)) != EOF) {
if ( c == CR )
putc(LF,fd2);
else
putc(c,fd2);
}
fclose(fd1);
fclose(fd2);
}