Classic Computer Magazine Archive CREATIVE COMPUTING VOL. 9, NO. 6 / JUNE 1983 / PAGE 240

Conversions are downhill with Upgrade. Gary Grout.

Conversions Are Downhill With Upgrade

If you upgrade your TRS-80 from cassette to disk, you may soon discover a software problem: your old Level II Basic programs won't run on your new disk system. The disk operating system (DOS) overlays Level II Basic programs, effectively erasing them because disk Basic resides higher in memory than does Level II Basic.

Those old Level II programs, good as they are, just won't work. And with this discovery, a disheartening image appears; you see yourself keying in your entire software library again--hours and hours of your time lost.

Unless you have a conversion program like Upgrade.

Upgrade is an assembly language program that moves Level II programs up in memory, resets the line pointers, and allows your old programs to run in disk Basic.

Operating Instructions

If you have an editor/assembler, compile the program and save it on disk. (We'll discuss the assembly language listing later.)

To convert one of your old Level II programs, first load Upgrade into memory while in DOS. With the program successfully loaded, hold down the BREAK key and reset the computer. This transfers you to Level II Basic. Don't worry; the converter program is still in memory and has not been lost.

Next, load your Basic program from tape as you normally do. When READY appears, type SYSTEM and answer the prompt *? by typing /65184. This sets Upgrade into operation; your Level II program is moved into high memory, and the line pointers are reset. You have now moved the old program out of the way so that when you call the disk over your Level II program.

The next thing to do is reboot (press reset) and return to DOS. When the DOS READY appears type BASIC. Once in disk Basic, you type SYSTEM, but this time when you see *?, you enter /65382. Your old Level II program moves down into the disk Basic area, and the pointers are reset. You can now save your old program on disk, and it will work just like new.

Don't run the converted Basic program before you save it or you will.get an error message.

If you don't have an editor/assembler to compile the assembly language program, you can use the Basic program in Listing 1. In disk Basic, type the program as shown. Then you may save it on disk by rebooting and using a DUMP command typed exactly as follows (including the spaces):



In disk Basic, you load and run this Basic program. Then you reset while holding down the BREAK key to transfer to Level II Basic. At this point you load your taped program and perform the procedure described earlier.

The Assembly Language Program

The assembly language conversion program loads at FEA0H which means you will need 48K of memory (BFEAH for 32K). See Listing 2.

The program begins by resetting the line pointers. The first two bytes of every Basic program line contain the address where the next Basic line starts. The two bytes are referred to as a pointer. These addresses must be changed if the program is to be moved up in memory. The code between the labels RENUM and DONE, lines 140 to 300, resets the pointers.

Resetting the pointers is like rebuilding stairs from the bottom up. You fix the first stair, step on it, and use it to fix the next. With line pointers, you get the first address, save it for later reference, fix it by adding an offset, and replace it in the original memory address. You then retrieve the old address you saved, go to that location in memory to find the next pointer, and repeat the process of adding an offset.

The offset is the number of bytes difference between where Level II Basic loads and where disk Basic loads in memory. For the Model I the offset is 273BH and for the Model III, 25F0H.

The only other thing the renumbering routine must do is check for the end of the Basic program. A Basic program ends when the two bytes of a line pointer contain zeros. So the renumbering routine works by checking the line pointer for zeros, renumbering the line pointer by adding an offset, and then going to the next line pointer.

Looking at the assembly language listing, you'll see the line pointer is first loaded into the IX register in line 130. A check is then made to determine if it is the end of the program. The check is performed by transferring the line pointer into the DE register, loading D into A register, and then using the OR statement in line 170. The zero flag will be set only if both D and E are zeros. When the end of the program is reached, we branch from line 180 to 300 labeled DONE.

If the no zero flag is set, then we simply move the line pointer from DE to HL and add the offset contained in BC. HL is then replaced in the original Basic program memory location, and the process begins again with the next line pointer whose address is in DE.

After resetting the pointers, we must move the program to high memory. This is done with a block move. To do a block move you must know the start of the memory section to be moved, the destination address to which it will be moved, and the number of bytes of information to move.

In this case the start of the memory section is 42E9H, the start of Level II Basic. This is stored in the HL register. The destination address is 82E9H (my favorite number above 16K Level II) which is stored in the DE register.

Finally, we must compute the number of bytes to move. We do this by subtracting the start of the program from the end of the program. The start is 42E9H, and son of a gun, the end of the program is still in the IX register after we reset the pointers. So from the label DONE in line 300 to line 380 we do the subtraction and store the result (the length of the program) with the label LEN. Now that we have all the information we need, the program performs the block move.

After the move, the program prints instructions on the screen and falls into an infinite loop awaiting instructions.

Next, you return to disk Basic. All that is left is to move the program down to the proper memory location again. How will we do this? Another block move.

This time, the start of the memory section to be moved is 82E9H. The destination is taken from the start of Basic, vector 40A4H. The length of the program is retrieved from LEN. With 82E9H in HL, 6A24H or %6ad9h/ in DE (depending on whether you have Model I or Model III respectively), and the length of the program in BC, the move is performed again.

Last, we must set the end of the Basic program in memory location 40F9H. And again, the address is still in the HL register after the block move, easy to find and use.

Completing The Conversion

Before you get too excited about all the typing you have saved yourself, you should know that some Level II statements won't run in disk Basic. For example, USR statements in Level II have the form A=USR(0). Disk Basic has expanded the number of USR routines to ten. Because of this expansion, the syntax has changed to A=USR1(0), with a number following the USR in the statement. Where before Level II POKED the start of the USR routine into memory, disk Basic defines the start with a statement such as DEFUSR1=&HFEA0. You will have to add or modify these statements accordingly.

You should also check the POKE statements. If any of these uses an address between 42E9H and 6A24H, it may interfere with the disk operating system. You should probably check any POKE statements that use high memory as well. Because disk Basic is higher in memory than Level II Basic, your old machine language routines may be overwritten by the disk Basic program. Pray they aren't, because you may then have to reassemble them with a new origin.

It is my assumption that with 16K dynamic RAM chips selling below $20 a set you probably have 48K of usable memory. If not, here is one other caution. If your memory is limited to 32K and you assemble Upgrade to fit your computer, your Basic program must not totally use up 16K of Level II Basic. Otherwise the block move will overlay Upgrade and you won't be able to move the Basic program back down in memory. With 48K, however, Upgrade won't be touched. Listing 3 is the Basic program for 32K. To store it on disk, execute the dump command:


I hope this program will help you with your expanded computer system. I am sure that when you bought your disk drive you were probably not concerned with the upward compatibility of programs and may not have anticipated what the conflict between Level II Basic and Disk Basic really meant--hours of retyping. Now that you have Upgrade, however, you have plenty of spare time to devote to mowing the lawn, shopping, fixing the car, doing the laundry . . .

Table: Listing 1. Upgrade Basic program for 48K.

Table: Listing 2. Upgrade assembly language listing.

Table: Listing 3. Upgrade Basic program for 32K.