Authors
Publication
Pub Details
Date
Pages
After a few modifications, you can run most ZX81 BASIC programs on our IBM PC or clone. This article will discuss one setup of hardware, software, and “sweatware,” which will do the job.
To begin with, of course, your program must be written only in BASIC. Machine code subroutines, e.g., those buried in REMs, will not run on the PC or clone, as it has a completely different set of hardware (8086 microprocessor vs. Z80, etc.). You will find, however, that the logic, and often the actual code lines of your program, will probably work under Microsoft BASIC. See page 373.
As a practical example, I have taken a 168 line program (about 4K of code), which I use at work and downloaded it to a PC. Of the 168 lines, only about 10 required “pre-editing” before being accepted by MS BASIC, another 15 or so needed syntax changes, and about a dozen graphic statements (PLOTs) needed to be converted (to DRAWs). I had been running the program, which calculates label sizes for my company’s products, but found the setup of the ZX81, just for this one program, a trifle tedious. Further, as others in the office all had PCs on their desks, it seemed to make more sense to move the software to their machines than set up the ZX81 each time it was needed.
Assuming your ZX81 program is all BASIC then, let us look at the uploading process. ZX81 files are stored in Sinclair BASIC, which uses non-standard character codes. Our first job, then, is to convert the text of the program to ASCII. Most ZXers probably already have hardware and software to do that. The hardware is the TS2068 (Timex) and the software is the Public Domain program FirstLoadR (also sold as Upload 2000). The program and a detailed description of its use can be found in the January 1985 issue of Syntax magazine. Briefly, FirstLoadR, is loaded into the 2068, the ZX81 BASIC program is then loaded in after executing a USR call to the MC (Machine Code) portion of FirstLoadR. The process takes some time, and loading levels are quite twitchy (remember you are loading a ZX81 tape into the TX2068’s circuits). At this point, as I am sure most readers know, you will have an uploaded program but it probably will not run correctly. This is because of some syntax differences between ZX81 BASIC and 2068 BASIC. These are not terribly serious, but do take time (“sweat- ware”) to find and correct. Since we are trying to get our program to run on an IBM PC, there is really no point in making any corrections to the listing at this stage. Save the program several times to tape.
Now things get a littler tougher. We have an uploaded BASIC file which is now in ASCIl format, but we still have not transferred it into the PC. One very standard way to do this is to use an RS232 port. There are a number of different implementations of these ports, but for our purposes, we will discuss the use of the Sinclair Interface One (IF1).
Again, since we really do not care whether the program runs at this stage, the differences between ZX Spectrum BASIC and 2068 BASIC are moot. Simply load the previously saved 2068 program into your Spectrum (this can be the same 2068 outfitted with a twistor and IF1), and enter the following in direct mode:
FORMAT “*” ; 110 OPEN #3 ; “t”
These commands will set your “t” channel up to transmit the program to the PC as a text file. We will use LLIST to do this, so you will lose any hidden variables and arrays. If your program has a lot of these you will have to use the “b” channel. This can be set up the same way but will require some fancy software at the other end, to recover the variables. Such a program is beyond the scope of this article. Rest assured, however, that it can be done. The MS BASIC program to do so would have to discount the systems variables area and the program variables, since both can contain “illegal” ASCII characters (like 26, or Control Z), which can make even EDLIN (IBM’s line editor) go crazy.
The “Spectrum” end of your “London Bridge” is now ready to go, but the bridge itself is going to require some finagling. Sinclair Research, in their infinite wisdom, has made their RS232 port a non-standard DTE (Data Terminal) port. The IBM PCs ASYNC card is also configured as DTE. This means that both systems are set up to talk to Modem’s but not other terminals. To get around this problem, we need a “null-modem.” This is a device which, simply put, “twists” the communication lines so that the receiving line of one device (RD) is connected to the transmit (TD) line of the other. Some handshaking lines are also switched in the null modem adapter. See Page 373.
With a null modem adapter on the end of your IF1 cable, you might think you are all set, however, at this point you have probably noticed that both the PC and your cable end have male plugs (pins instead of sockets). The next item you will need is a F-to-F DB25 “gender changer.” These are wired straight through and can be obtained from a number of supply houses, or home made. Just a hint, buying the parts to make a F-to-F adapter from Radio Shack is not cost effective. Gender changers can be bought for as little as $4.00 (Computer Expert in NYC) whereas RS sells the bare female connectors (you need two for $2.29 each. A better deal here is to build the null-modem and gender adapter into one shell).
Under normal circumstances, your hardware connections should be complete at this point. However, if you plug the adapter and cables together, you will probably find that, even at 110 BPS, you get garbled transmission, or none at all. In my first attempt this occurred primarily because my null-modem was of the non-handshaking type.
One more adapter, to the rescue. This little heardware adapter is an item called “test adapter”. Quite frankly, I bought this item simply because I did not know what it did. It is a very simple device which passes all the RS232 lines thru, but also references them all to ground thru diodes. In effect, it provides a “logic” circuit that lets you get away with some sloppy handshaking procedures.
Rough schematics for all three adapters are shown in Figure 2. Note that while I use 3 separate adapters, all three could be built into one shell or a small project box. To upload your program, all that is left is some communications and file handling software at the PC end. If you have access to a package like CrossTalk, PC Talk or Smartcom, then you need only load and run those. If not, the short MS BASIC program below will do the job (Enter this program into your PC in BASIC).
10 CLS
20 DEFINT A-Z
30 OPEN "coml:110,N,8,1" AS #1
40 COM(1) ON
50 OPEN "a:program" FOR OUTPUT AS 2
60 CLS: LOCATE,,1
70 PRINT "Working"
80 ON COM(1) GOSUB 150
90 PRINT "Loading block:" ;L
100 IF L>40 THEN 120
110 GOTO 60
120 CLOSE #1
130 CLOSE #2
140 END
150 LET L=LOC(1)
160 A$ = INPUT$(1,#1)
170 PRINT #2;A$;
180 RETURN
This program is admittedly crude (no error or EOF trapping) but it will put your file onto an MSDOS formatted diskette, as an ASCII file. To make the actual transfer:
- Run the program on your PC.
- If it stops with a “Device Timeout” error, simply run it again.
- Make sure you have a formatted diskette in Drive A:
- Enter LLIST on your “Spectrum.”
- Watch the Spectrum screen. When data transfer is complete (this can take ten minutes for a 4-5K program), you will get the 0 O.K. message. The disk drive on your PC will come on and go off several times during the transfer, as it adds blocks of data to the file.
- Close #1 and Close #2 on your PC.
- Type SYSTEM on your PC.
- Type Dir. You should see the temporary file “TEMP” listed. The byte count should be close to the number of bytes in your Spectrum program (do a header reader on the 2068 version as a cross check.).
- The big moment has arrived: Type in: Type TEMP and enter it. You should see a listing of the ASCII file which looks like a workable BASIC program.
- Begin editing of the TEMP file. From DOS, get your EDLIN utility (or other similar program-even some word processors will work) and look for blank lines. Put REM on the line after the line #, or simply delete it. Also look for CR/LF’s (carriage return/line feeds) in the middle of long text lines. This will be interpreted as “Direct Statements” in your file and rejected by the MS BASIC interpreter. Get rid of these and you are ready to test the file in BASIC.
- After exiting from EDLIN, copy the program as a BASIC file: Copy TEMP TEMP BAS
- Enter BASIC again
- Load “TEMP.” The program will probably load at this stage. If not, an error message should tell you what to look for.
- Try to run the program. You will get syntax errors if you have statements like Print AT, PLOT, PAUSE or use graphics characters. Edit these to conform to MS BASIC use LOCATE for PRINT AT; DRAW, for PLOT, etc.). You will Find graphics especially annoying since Microsoft uses the silly “upside down” Y axis convention.
- eep editing and running your program. Make frequent saves TEMPI, TEMP2,……TEMP50), so hat you can recover from fatal changes. I have found that most math functions and logical operators work fine. Watch out for PI. you must specify it to MS BASIC (PI = 3.141533) as it is not built in. “Before” and “After” sections of my label program are included in Figure 3.
And that is it. You should now have that ZX81 program running on your PC or clone. In fact, you may even find that, as you review the logic of your original program, it may improve during the translation process. A final result which to many of us is better than what we would get from rubbing a lamp.