Relocating Machine Code Programs – TS-2068

Why would one want to relocate machine code? Many machine code programs written for the TS2068 are located in the same area of RAM. Sometimes one might want to use both if they can be used that way. If you relocate one, you may be able to use both. I had previously purchased the Zeal disassembler and found that I couldn’t use my printer driver with it because they both used the same area of RAM to store their machine code. Although the printer interface [I use Tasman] had a driver program to store in the computer’s printer buffer, I found that I couldn’t use that either because something in the Zeal disassembler would wipe that out. I found out that, even after transferring the printer driver to an address below the Zeal disassembler machine code, I still could not use it directly through the Zeal disassembler. I had to use the Tasman screen copy routine to get a printout of the screen. Tasman has two screen copy routines. One is for text only and is stored with the regular printer driver. The other is stored in the computer’s printer buffer and will copy anything on the screen. The computer’s printer buffer location is reverted to normal with NEW. Machine code programs that have been SAVEd on tape or disk are LOADed back into the computer memory with LOAD ” ” CODE or a name can be specified [must be for some disk systems]. With that simple way of ENTERing the code is placed at the same address it was SAVEd from. If you want to relocate it, then you enter LOAD ” ” CODE (address) and it will load in at the address specified. If the code contains only relative jumps and ROM calls, it can be RUN with no changes. If it contains absolute jumps and calls within its own addresses, these will have to be changed for the program to work. I have successfully done this to a few programs and got them to work.

A disassembler program comes in quite handy for accomplishing the changes. I use the Zeal disassembler since it prints out the addresses in decimal. The Zeal disassembler has a set-up to PRINT to a printer but, as far as I can tell, it only supports the TS2040 printer. The Zeal disassembler did give me an option to have the program disassembled in its present location and in its original location, or at any address I choose. If you want, you can get printouts at both locations. In order to get a printout of the Zeal disassembly, it was necessary to break out of the Zeal program with CAPS SHIFT/BREAK and then copy the screen. This was a little tough to do on the first break out but, after that it was no trouble.

If you have made the printouts at both locations, take the two printouts and compare them. One of the things you will notice is that the relative jump addresses are different. This is correct and they do not have to be changed. You will then notice that the absolute jumps and calls are the same in both listings. You will also notice that paired registers are LOADed with numbers. These numbers are equivalent to addresses in the code. Generally, these are the HL register. All the absolute jumps will have to be changed. If the calls and HL numbers are to ROM or (in most cases) to addresses below 26710, they do not need to be changed. If the calls and HL numbers are to addresses in the program, they will have to be changed. What I do in this case is look for the address shown in the original program. Then I find the comparable address in the relocated program and break it down into High Byte and Low Byte (i.e. High byte = INT(address/256) and Low Byte = address – High Byte * 256). Once you have this information you go back to the relocated address that originally listed that address in the mnemonics and POKE the following two addresses with the Low Byte and High Byte in that order. It is a lot of work, but once you have everything changed, you have a relocated program that works like the original. You must re-SAVE the changed program and it will load back in at the new address without specifying the new address. Remember that you must set RAMTOP at one address below the start of the code. Since I now have the Tasman printer driver located at 60000 and the Zeal disassembler LOADed in, I initialize the printer driver with RANDOMIZE USR 60003, and then use RANDOMIZE USR 60000 to make a text only screen copy.

[Figure: Clip-art graduate in cap and gown]

I have used this procedure to move other programs. One of them was the screen copy code that Tasman had supplied. Tasman had listed a number of printers for copy codes they had on the cassette but, they didn’t list any printer (Panasonic) by name. I tried all of them, but, the only one that appeared to work correctly was one called Shin-Wa. These screen copy codes were all stored in the computer’s printer buffer. There is one thing wrong with the code being located in the computer’s printer buffer. When you key NEW, the code is erased. I LOADed in the Zeal, followed by the relocated printer driver, and then the screen copy code. I got a printed copy of the disassembly of the screen copy code. I wanted to relocate to 63000, but since that was in the Zeal code area I chose 53000 to locate it at temporarily and then set the relocation to 63000 (10000 bytes) in the printout. Using the 53000 made it simpler to figure start addresses. I then made a hard copy of the disassembly and went back to the menu and changed the relocation to zero and made a hard copy of the code at 53000. Comparing all three listings, I found that I had to make the changes. After ENTERing the changes at 53000 to 53256, I SAVEd the code. Then, turning off the computer to clear everything out, I turned the computer on again, set RAMTOP at 62999, LOADed the copy code in at 63000. I then re-SAVEd the program at the proper address. I now have a screen copy code that remains in memory after NEW. I think I should mention here that, one of the addresses LOADed into the HL register in the screen copy program is used to contain a number that is used to control the size of the screen copy. That address will contain a 1 for small screen copy and 0 for large screen copy. The large screen copy will not copy the full horizontal screen. It will be a few columns short on the right side. This is an example of the reason for changing the numbers held in the HL register. Although, I do not understand enough to write my own machine code, I understand enough to figure out how to do things like relocating machine code. You can do it too.